Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
geodemo.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_geom
3/// GUI to draw the geometry shapes.
4///
5/// \macro_code
6///
7/// \author Andrei Gheata
8
9#include "TMath.h"
10#include "TControlBar.h"
11#include "TRandom3.h"
12#include "TROOT.h"
13#include "TSystem.h"
14#include "TVirtualPad.h"
15#include "TCanvas.h"
16#include "TVirtualGeoPainter.h"
17#include "TGeoManager.h"
18#include "TGeoNode.h"
19#include "TView.h"
20#include "TPaveText.h"
21#include "TGeoBBox.h"
22#include "TGeoPara.h"
23#include "TGeoTube.h"
24#include "TGeoCone.h"
25#include "TGeoEltu.h"
26#include "TGeoSphere.h"
27#include "TGeoTorus.h"
28#include "TGeoTrd1.h"
29#include "TGeoTrd2.h"
30#include "TGeoParaboloid.h"
31#include "TGeoHype.h"
32#include "TGeoPcon.h"
33#include "TGeoPgon.h"
34#include "TGeoArb8.h"
35#include "TGeoXtru.h"
36#include "TGeoCompositeShape.h"
37#include "TGeoTessellated.h"
38#include "TGeoPhysicalNode.h"
39
43Bool_t axis = kTRUE;
44
45//______________________________________________________________________________
46void MakePicture()
47{
48 TView *view = gPad->GetView();
49 if (view) {
50// view->RotateView(248,66);
51 if (axis) view->ShowAxis();
52 }
56 gPad->Modified();
57 gPad->Update();
58 }
59}
60
61//______________________________________________________________________________
62void AddMemberInfo(TPaveText *pave, const char *datamember, Double_t value, const char *comment)
63{
65 while (line.Length() < 10) line.Append(" ");
66 line.Append(TString::Format("= %5.2f => %s", value, comment));
67 TText *text = pave->AddText(line.Data());
68// text->SetTextColor(4);
69 text->SetTextAlign(12);//12
70}
71
72//______________________________________________________________________________
73void AddMemberInfo(TPaveText *pave, const char *datamember, Int_t value, const char *comment)
74{
76 while (line.Length() < 10) line.Append(" ");
77 line.Append(TString::Format("= %5d => %s", value, comment));
78 TText *text = pave->AddText(line.Data());
79// text->SetTextColor(4);
80 text->SetTextAlign(12);
81}
82
83//______________________________________________________________________________
85{
86 TGeoPatternFinder *finder = dynamic_cast<TGeoPatternFinder *>(pf);
87 if (!pave || !pf || !iaxis) return;
88 TGeoVolume *volume = finder->GetVolume();
89 TGeoShape *sh = volume->GetShape();
90 TText *text = pave->AddText(TString::Format("Division of %s on axis %d (%s)", volume->GetName(), iaxis, sh->GetAxisName(iaxis)));
91 text->SetTextColor(3);
92 text->SetTextAlign(12);
93 AddMemberInfo(pave, "fNdiv", finder->GetNdiv(), "number of divisions");
94 AddMemberInfo(pave, "fStart", finder->GetStart(), "start divisioning position");
95 AddMemberInfo(pave, "fStep", finder->GetStep(), "division step");
96}
97
98//______________________________________________________________________________
99void AddExecInfo(TPaveText *pave, const char *name = nullptr, const char *axisinfo = nullptr)
100{
101 if (name && axisinfo) {
102 auto text = pave->AddText(TString::Format("Execute: %s(iaxis, ndiv, start, step) to divide this.", name));
103 text->SetTextColor(4);
104 pave->AddText(TString::Format("----- IAXIS can be %s", axisinfo));
105 pave->AddText("----- NDIV must be a positive integer");
106 pave->AddText("----- START must be a valid axis offset within shape range on divided axis");
107 pave->AddText("----- STEP is the division step. START+NDIV*STEP must be in range also");
108 pave->AddText("----- If START and STEP are omitted, all range of the axis will be divided");
109 pave->SetAllWith("-----","color",2);
110 pave->SetAllWith("-----","font",72);
111 pave->SetAllWith("-----","size",0.04);
112 } else if (name) {
113 auto text = pave->AddText(TString::Format("Execute: %s()", name));
114 text->SetTextColor(4);
115 }
116
117 pave->AddText(" ");
118 pave->SetTextSize(0.044);
119 pave->SetTextAlign(12);
120}
121
122
123//______________________________________________________________________________
124void SavePicture(const char *name, TObject *objcanvas, TObject *objvol, Int_t iaxis, Double_t step)
125{
128 if (!c || !vol) return;
129 c->cd();
131 if (iaxis == 0)
132 fname.Form("t_%s.gif",name);
133 else if (step == 0)
134 fname.Form("t_%sdiv%s.gif", name, vol->GetShape()->GetAxisName(iaxis));
135 else
136 fname.Form("t_%sdivstep%s.gif", name, vol->GetShape()->GetAxisName(iaxis));
137
138 c->Print(fname.Data());
139}
140
141//______________________________________________________________________________
143{
144 Double_t color = 7.*gRandom->Rndm();
145 return (1+Int_t(color));
146}
147
148//______________________________________________________________________________
149void raytrace() {
151 if (gGeoManager && gPad) {
152 auto top = gGeoManager->GetTopVolume();
153 bool drawn = gPad->GetListOfPrimitives()->FindObject(top);
154 if (drawn) top->SetVisRaytrace(raytracing);
155 gPad->Modified();
156 gPad->Update();
157 }
158}
159
160//______________________________________________________________________________
161void help() {
162
163 auto c =(TCanvas *) gROOT->GetListOfCanvases()->FindObject("geom_help");
164 if (c) {
165 c->Clear();
166 c->Update();
167 c->cd();
168 } else {
169 c = new TCanvas("geom_help","Help to run demos",200,10,700,600);
170 }
171
172 TPaveText *welcome = new TPaveText(.1,.8,.9,.97);
173 welcome->AddText("Welcome to the new geometry package");
174 welcome->SetTextFont(32);
175 welcome->SetTextColor(4);
176 welcome->SetFillColor(24);
177 welcome->Draw();
178
179 TPaveText *hdemo = new TPaveText(.05,.05,.95,.7);
180 hdemo->SetTextAlign(12);
181 hdemo->SetTextFont(52);
182 hdemo->AddText("- Demo for building TGeo basic shapes and simple geometry. Shape parameters are");
183 hdemo->AddText(" displayed in the right pad");
184 hdemo->AddText("- Click left mouse button to execute one demo");
185 hdemo->AddText("- While pointing the mouse to the pad containing the geometry, do:");
186 hdemo->AddText("- .... click-and-move to rotate");
187 hdemo->AddText("- .... press j/k to zoom/unzoom");
188 hdemo->AddText("- .... press l/h/u/i to move the view center around");
189 hdemo->AddText("- Click Ray-trace ON/OFF to toggle ray-tracing");
190 hdemo->AddText("- Use <View with x3d> from the <View> menu to get an x3d view");
191 hdemo->AddText("- .... same methods to rotate/zoom/move the view");
192 hdemo->AddText("- Execute box(1,8) to divide a box in 8 equal slices along X");
193 hdemo->AddText("- Most shapes can be divided on X,Y,Z,Rxy or Phi :");
194 hdemo->AddText("- .... root[0] <shape>(IAXIS, NDIV, START, STEP);");
195 hdemo->AddText(" .... IAXIS = 1,2,3 meaning (X,Y,Z) or (Rxy, Phi, Z)");
196 hdemo->AddText(" .... NDIV = number of slices");
197 hdemo->AddText(" .... START = start slicing position");
198 hdemo->AddText(" .... STEP = division step");
199 hdemo->AddText("- Click Comments ON/OFF to toggle comments");
200 hdemo->AddText("- Click Ideal/Align geometry to see how alignment works");
201 hdemo->AddText(" ");
202 hdemo->SetAllWith("....","color",2);
203 hdemo->SetAllWith("....","font",72);
204 hdemo->SetAllWith("....","size",0.03);
205
206 hdemo->Draw();
207
208 c->Update();
209}
210
211//______________________________________________________________________________
212void autorotate()
213{
214 grotate = !grotate;
215 if (!grotate) {
216 gROOT->SetInterrupt(kTRUE);
217 return;
218 }
219 if (!gPad) return;
220 TView *view = gPad->GetView();
221 if (!view) return;
222 if (!gGeoManager) return;
224 if (!painter) return;
225 Double_t longit = view->GetLongitude();
226// Double_t lat = view->GetLatitude();
227// Double_t psi = view->GetPsi();
228 Double_t dphi = 1.;
229 Int_t irep;
231 gROOT->SetInterrupt(kFALSE);
232 while (grotate) {
233 if (timer->ProcessEvents()) break;
234 if (gROOT->IsInterrupted()) break;
235 longit += dphi;
236 if (longit>360) longit -= 360.;
237 if (!gPad) {
238 grotate = kFALSE;
239 return;
240 }
241 view = gPad->GetView();
242 if (!view) {
243 grotate = kFALSE;
244 return;
245 }
246 view->SetView(longit,view->GetLatitude(),view->GetPsi(),irep);
247 gPad->Modified();
248 gPad->Update();
249 }
250 delete timer;
251}
252
253//______________________________________________________________________________
254void axes()
255{
256 axis = !axis;
257 TView *view = gPad ? gPad->GetView() : nullptr;
258 if(view)
259 view->ShowAxis();
260}
261
262//______________________________________________________________________________
263TCanvas *create_canvas(const char *title)
264{
265 auto c = (TCanvas *) gROOT->GetListOfCanvases()->FindObject("geom_draw");
266 if (c) {
267 c->Clear();
268 c->Update();
269 c->SetTitle(title);
270 } else {
271 c = new TCanvas("geom_draw", title, 700,1000);
272 }
273 if (comments) {
274 c->Divide(1,2,0,0);
275 c->GetPad(2)->SetPad(0,0,1,0.4);
276 c->GetPad(1)->SetPad(0,0.4,1,1);
277 c->cd(1);
278 }
279
280 return c;
281}
282
283//______________________________________________________________________________
284void box(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
285{
286 auto c = create_canvas("A simple box");
287
288 if (gGeoManager) delete gGeoManager;
289 new TGeoManager("box", "A simple box");
290 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
291 TGeoMedium *med = new TGeoMedium("MED",1,mat);
292 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
294 TGeoVolume *vol = gGeoManager->MakeBox("BOX",med, 20,30,40);
296 vol->SetLineWidth(2);
297 top->AddNode(vol,1);
298 if ((iaxis > 0) && (iaxis < 4)) {
299 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
300 if (!slice) return;
301 slice->SetLineColor(randomColor());
302 }
305
306 top->Draw();
307
308 MakePicture();
309 if (!comments) return;
310 c->cd(2);
311 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
312 pt->SetLineColor(1);
313 TGeoBBox *box = (TGeoBBox *) vol->GetShape();
314 TText *text = pt->AddText("TGeoBBox - box class");
315 text->SetTextColor(2);
316 AddMemberInfo(pt, "fDX", box->GetDX(), "half length in X");
317 AddMemberInfo(pt, "fDY", box->GetDY(), "half length in Y");
318 AddMemberInfo(pt, "fDZ", box->GetDZ(), "half length in Z");
319 AddMemberInfo(pt, "fOrigin[0]", (box->GetOrigin())[0], "box origin on X");
320 AddMemberInfo(pt, "fOrigin[1]", (box->GetOrigin())[1], "box origin on Y");
321 AddMemberInfo(pt, "fOrigin[2]", (box->GetOrigin())[2], "box origin on Z");
323 AddExecInfo(pt, "box", "1, 2 or 3 (X, Y, Z)");
324 pt->Draw();
325// SavePicture("box",c,vol,iaxis,step);
326 c->cd(1);
327}
328
329//______________________________________________________________________________
330void para(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
331{
332 auto c = create_canvas("A parallelepiped");
333
334 if (gGeoManager) delete gGeoManager;
335 new TGeoManager("para", "A parallelepiped");
336 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
337 TGeoMedium *med = new TGeoMedium("MED",1,mat);
338 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
340 TGeoVolume *vol = gGeoManager->MakePara("PARA",med, 20,30,40,30,15,30);
342 vol->SetLineWidth(2);
343 top->AddNode(vol,1);
344 if ((iaxis > 0) && (iaxis < 4)) {
345 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
346 if (!slice) return;
347 slice->SetLineColor(randomColor());
348 } else if (iaxis) {
349 printf("Wrong division axis %d. Allowed range is 1-3.\n", iaxis);
350 return;
351 }
354
355 top->Draw();
356
357 MakePicture();
358 if (!comments) return;
359 c->cd(2);
360 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
361 pt->SetLineColor(1);
362 TGeoPara *para = (TGeoPara *) vol->GetShape();
363 TText *text = pt->AddText("TGeoPara - parallelepiped class");
364 text->SetTextColor(2);
365 AddMemberInfo(pt, "fX", para->GetX(), "half length in X");
366 AddMemberInfo(pt, "fY", para->GetY(), "half length in Y");
367 AddMemberInfo(pt, "fZ", para->GetZ(), "half length in Z");
368 AddMemberInfo(pt, "fAlpha", para->GetAlpha(), "angle about Y of the Z bases");
369 AddMemberInfo(pt, "fTheta", para->GetTheta(), "inclination of para axis about Z");
370 AddMemberInfo(pt, "fPhi", para->GetPhi(), "phi angle of para axis");
372 AddExecInfo(pt, "para", "1, 2 or 3 (X, Y, Z)");
373 pt->Draw();
374 c->cd(1);
375// SavePicture("para",c,vol,iaxis,step);
376}
377
378//______________________________________________________________________________
379void tube(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
380{
381 auto c = create_canvas("A tube");
382
383 if (gGeoManager) delete gGeoManager;
384 new TGeoManager("tube", "poza2");
385 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
386 TGeoMedium *med = new TGeoMedium("MED",1,mat);
387 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
389 TGeoVolume *vol = gGeoManager->MakeTube("TUBE",med, 20,30,40);
391 vol->SetLineWidth(2);
392 top->AddNode(vol,1);
393 if ((iaxis > 0) && (iaxis < 4)) {
394 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
395 if (!slice) return;
396 slice->SetLineColor(randomColor());
397 } else if (iaxis) {
398 printf("Wrong division axis %d. Allowed range is 1-3.\n", iaxis);
399 return;
400 }
403
404 top->Draw();
405
406 MakePicture();
407 if (!comments) return;
408 c->cd(2);
409 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
410 pt->SetLineColor(1);
411 TGeoTube *tube = (TGeoTube*)(vol->GetShape());
412 TText *text = pt->AddText("TGeoTube - tube class");
413 text->SetTextColor(2);
414 AddMemberInfo(pt,"fRmin",tube->GetRmin(),"minimum radius");
415 AddMemberInfo(pt,"fRmax",tube->GetRmax(),"maximum radius");
416 AddMemberInfo(pt,"fDZ", tube->GetDZ(), "half length in Z");
418 AddExecInfo(pt, "tube", "1, 2 or 3 (Rxy, Phi, Z)");
419 pt->Draw();
420 c->cd(1);
421// SavePicture("tube",c,vol,iaxis,step);
422}
423
424//______________________________________________________________________________
425void tubeseg(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
426{
427 auto c = create_canvas("A tube segment");
428
429 if (gGeoManager) delete gGeoManager;
430 new TGeoManager("tubeseg", "poza3");
431 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
432 TGeoMedium *med = new TGeoMedium("MED",1,mat);
433 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
435 TGeoVolume *vol = gGeoManager->MakeTubs("TUBESEG",med, 20,30,40,-30,270);
437 if ((iaxis > 0) && (iaxis < 4)) {
438 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
439 if (!slice) return;
440 slice->SetLineColor(randomColor());
441 } else if (iaxis) {
442 printf("Wrong division axis %d. Allowed range is 1-3.\n", iaxis);
443 return;
444 }
445
446 vol->SetLineWidth(2);
447 top->AddNode(vol,1);
450
451 top->Draw();
452
453 MakePicture();
454 if (!comments) return;
455 c->cd(2);
456 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
457 pt->SetLineColor(1);
459 TText *text = pt->AddText("TGeoTubeSeg - tube segment class");
460 text->SetTextColor(2);
461 AddMemberInfo(pt,"fRmin",tubeseg->GetRmin(),"minimum radius");
462 AddMemberInfo(pt,"fRmax",tubeseg->GetRmax(),"maximum radius");
463 AddMemberInfo(pt,"fDZ", tubeseg->GetDZ(), "half length in Z");
464 AddMemberInfo(pt,"fPhi1",tubeseg->GetPhi1(),"first phi limit");
465 AddMemberInfo(pt,"fPhi2",tubeseg->GetPhi2(),"second phi limit");
467 AddExecInfo(pt, "tubeseg", "1, 2 or 3 (Rxy, Phi, Z)");
468 pt->Draw();
469 c->cd(1);
470// SavePicture("tubeseg",c,vol,iaxis,step);
471}
472
473//______________________________________________________________________________
474void ctub(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
475{
476 auto c = create_canvas("A cut tube segment");
477
478 if (gGeoManager) delete gGeoManager;
479 new TGeoManager("ctub", "poza3");
480 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
481 TGeoMedium *med = new TGeoMedium("MED",1,mat);
482 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
484 Double_t theta = 160.*TMath::Pi()/180.;
485 Double_t phi = 30.*TMath::Pi()/180.;
486 Double_t nlow[3];
487 nlow[0] = TMath::Sin(theta)*TMath::Cos(phi);
488 nlow[1] = TMath::Sin(theta)*TMath::Sin(phi);
489 nlow[2] = TMath::Cos(theta);
490 theta = 20.*TMath::Pi()/180.;
491 phi = 60.*TMath::Pi()/180.;
492 Double_t nhi[3];
493 nhi[0] = TMath::Sin(theta)*TMath::Cos(phi);
494 nhi[1] = TMath::Sin(theta)*TMath::Sin(phi);
495 nhi[2] = TMath::Cos(theta);
496 TGeoVolume *vol = gGeoManager->MakeCtub("CTUB",med, 20,30,40,-30,250, nlow[0], nlow[1], nlow[2], nhi[0],nhi[1],nhi[2]);
498 if (iaxis == 1 || iaxis == 2) {
499 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
500 if (!slice) return;
501 slice->SetLineColor(randomColor());
502 } else if (iaxis) {
503 printf("Wrong division axis %d. Allowed range is 1-2.\n", iaxis);
504 return;
505 }
506
507 vol->SetLineWidth(2);
508 top->AddNode(vol,1);
511
512 top->Draw();
513
514 MakePicture();
515 if (!comments) return;
516 c->cd(2);
517 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
518 pt->SetLineColor(1);
520 TText *text = pt->AddText("TGeoTubeSeg - tube segment class");
521 text->SetTextColor(2);
522 AddMemberInfo(pt,"fRmin",tubeseg->GetRmin(),"minimum radius");
523 AddMemberInfo(pt,"fRmax",tubeseg->GetRmax(),"maximum radius");
524 AddMemberInfo(pt,"fDZ", tubeseg->GetDZ(), "half length in Z");
525 AddMemberInfo(pt,"fPhi1",tubeseg->GetPhi1(),"first phi limit");
526 AddMemberInfo(pt,"fPhi2",tubeseg->GetPhi2(),"second phi limit");
528 AddExecInfo(pt, "ctub", "1 or 2");
529 pt->Draw();
530 c->cd(1);
531// SavePicture("tubeseg",c,vol,iaxis,step);
532}
533
534//______________________________________________________________________________
535void cone(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
536{
537 auto c = create_canvas("A cone");
538
539 if (gGeoManager) delete gGeoManager;
540 new TGeoManager("cone", "poza4");
541 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
542 TGeoMedium *med = new TGeoMedium("MED",1,mat);
543 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
545 TGeoVolume *vol = gGeoManager->MakeCone("CONE",med, 40,10,20,35,45);
547 vol->SetLineWidth(2);
548 if (iaxis == 2 || iaxis == 3) {
549 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
550 if (!slice) return;
551 slice->SetLineColor(randomColor());
552 } else if (iaxis) {
553 printf("Wrong division axis %d. Allowed range is 2-3.\n", iaxis);
554 return;
555 }
556 top->AddNode(vol,1);
559
560 top->Draw();
561
562 MakePicture();
563 if (!comments) return;
564 c->cd(2);
565 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
566 pt->SetLineColor(1);
567 TGeoCone *cone = (TGeoCone*)(vol->GetShape());
568 TText *text = pt->AddText("TGeoCone - cone class");
569 text->SetTextColor(2);
570 AddMemberInfo(pt,"fDZ", cone->GetDZ(), "half length in Z");
571 AddMemberInfo(pt,"fRmin1",cone->GetRmin1(),"inner radius at -dz");
572 AddMemberInfo(pt,"fRmax1",cone->GetRmax1(),"outer radius at -dz");
573 AddMemberInfo(pt,"fRmin2",cone->GetRmin2(),"inner radius at +dz");
574 AddMemberInfo(pt,"fRmax2",cone->GetRmax2(),"outer radius at +dz");
576 AddExecInfo(pt, "cone", "2 or 3 (Phi, Z)");
577 pt->Draw();
578 c->cd(1);
579// SavePicture("cone",c,vol,iaxis,step);
580}
581
582//______________________________________________________________________________
583void coneseg(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
584{
585 auto c = create_canvas("A cone segment");
586
587 if (gGeoManager) delete gGeoManager;
588 new TGeoManager("coneseg", "poza5");
589 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
590 TGeoMedium *med = new TGeoMedium("MED",1,mat);
591 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
593 TGeoVolume *vol = gGeoManager->MakeCons("CONESEG",med, 40,30,40,10,20,-30,250);
595// vol->SetLineWidth(2);
596 top->AddNode(vol,1);
597 if (iaxis >= 2 && iaxis <= 3) {
598 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
599 if (!slice) return;
600 slice->SetLineColor(randomColor());
601 } else if (iaxis) {
602 printf("Wrong division axis %d. Allowed range is 2-3.\n", iaxis);
603 return;
604 }
607
608 top->Draw();
609
610 MakePicture();
611 if (!comments) return;
612 c->cd(2);
613 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
614 pt->SetLineColor(1);
616 TText *text = pt->AddText("TGeoConeSeg - coneseg class");
617 text->SetTextColor(2);
618 AddMemberInfo(pt, "fDZ", coneseg->GetDZ(), "half length in Z");
619 AddMemberInfo(pt, "fRmin1", coneseg->GetRmin1(), "inner radius at -dz");
620 AddMemberInfo(pt, "fRmax1", coneseg->GetRmax1(), "outer radius at -dz");
621 AddMemberInfo(pt, "fRmin2", coneseg->GetRmin1(), "inner radius at +dz");
622 AddMemberInfo(pt, "fRmax2", coneseg->GetRmax1(), "outer radius at +dz");
623 AddMemberInfo(pt, "fPhi1", coneseg->GetPhi1(), "first phi limit");
624 AddMemberInfo(pt, "fPhi2", coneseg->GetPhi2(), "second phi limit");
626 AddExecInfo(pt, "coneseg", "2 or 3 (Phi, Z)");
627 pt->Draw();
628 c->cd(1);
629// SavePicture("coneseg",c,vol,iaxis,step);
630}
631
632//______________________________________________________________________________
633void eltu(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
634{
635 auto c = create_canvas("An Elliptical tube");
636
637 if (gGeoManager) delete gGeoManager;
638 new TGeoManager("eltu", "poza6");
639 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
640 TGeoMedium *med = new TGeoMedium("MED",1,mat);
641 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
643 TGeoVolume *vol = gGeoManager->MakeEltu("ELTU",med, 30,10,40);
645// vol->SetLineWidth(2);
646 top->AddNode(vol,1);
647 if (iaxis >= 2 && iaxis <= 3) {
648 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
649 if (!slice) return;
650 slice->SetLineColor(randomColor());
651 } else if (iaxis) {
652 printf("Wrong division axis %d. Allowed range is 2-3.\n", iaxis);
653 return;
654 }
657
658 top->Draw();
659
660 MakePicture();
661 if (!comments) return;
662 c->cd(2);
663 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
664 pt->SetLineColor(1);
665 TGeoEltu *eltu = (TGeoEltu*)(vol->GetShape());
666 TText *text = pt->AddText("TGeoEltu - eltu class");
667 text->SetTextColor(2);
668 AddMemberInfo(pt,"fA",eltu->GetA(), "semi-axis along x");
669 AddMemberInfo(pt,"fB",eltu->GetB(), "semi-axis along y");
670 AddMemberInfo(pt,"fDZ", eltu->GetDZ(), "half length in Z");
672 AddExecInfo(pt, "eltu", "2 or 3 (Phi, Z)");
673 pt->Draw();
674 c->cd(1);
675// SavePicture("eltu",c,vol,iaxis,step);
676}
677
678//______________________________________________________________________________
679void sphere()
680{
681 auto c = create_canvas("A spherical sector");
682
683 if (gGeoManager) delete gGeoManager;
684 new TGeoManager("sphere", "poza7");
685 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
686 TGeoMedium *med = new TGeoMedium("MED",1,mat);
687 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
689 TGeoVolume *vol = gGeoManager->MakeSphere("SPHERE",med, 30,40,60,120,30,240);
691 vol->SetLineWidth(2);
692 top->AddNode(vol,1);
695
696 top->Draw();
697
698 MakePicture();
699 if (!comments) return;
700 c->cd(2);
701 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
702 pt->SetLineColor(1);
703 TGeoSphere *sphere = (TGeoSphere*)(vol->GetShape());
704 TText *text = pt->AddText("TGeoSphere- sphere class");
705 text->SetTextColor(2);
706 AddMemberInfo(pt, "fRmin", sphere->GetRmin(), "inner radius");
707 AddMemberInfo(pt, "fRmax", sphere->GetRmax(), "outer radius");
708 AddMemberInfo(pt, "fTheta1", sphere->GetTheta1(), "lower theta limit");
709 AddMemberInfo(pt, "fTheta2", sphere->GetTheta2(), "higher theta limit");
710 AddMemberInfo(pt, "fPhi1", sphere->GetPhi1(), "lower phi limit");
711 AddMemberInfo(pt, "fPhi2", sphere->GetPhi2(), "higher phi limit");
712 AddExecInfo(pt, "sphere");
713 pt->Draw();
714 c->cd(1);
715// SavePicture("sphere",c,vol,iaxis,step);
716}
717
718//______________________________________________________________________________
719void torus()
720{
721 auto c = create_canvas("A toroidal segment");
722
723 if (gGeoManager) delete gGeoManager;
724 new TGeoManager("torus", "poza2");
725 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
726 TGeoMedium *med = new TGeoMedium("MED",1,mat);
727 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
729 TGeoVolume *vol = gGeoManager->MakeTorus("TORUS",med, 40,20,25,0,270);
731 top->AddNode(vol,1);
734
735 top->Draw();
736
737 MakePicture();
738 if (!comments) return;
739 c->cd(2);
740 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
741 pt->SetLineColor(1);
742 TGeoTorus *tor = (TGeoTorus*)(vol->GetShape());
743 TText *text = pt->AddText("TGeoTorus - torus class");
744 text->SetTextColor(2);
745 AddMemberInfo(pt, "fR", tor->GetR(), "radius of the ring");
746 AddMemberInfo(pt, "fRmin", tor->GetRmin(), "minimum radius");
747 AddMemberInfo(pt, "fRmax", tor->GetRmax(), "maximum radius");
748 AddMemberInfo(pt, "fPhi1", tor->GetPhi1(), "starting phi angle");
749 AddMemberInfo(pt, "fDphi", tor->GetDphi(), "phi range");
750 AddExecInfo(pt, "torus");
751 pt->Draw();
752 c->cd(1);
753}
754
755//______________________________________________________________________________
756void trd1(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
757{
758 auto c = create_canvas("A trapezoid with dX varying");
759
760 if (gGeoManager) delete gGeoManager;
761 new TGeoManager("trd1", "poza8");
762 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
763 TGeoMedium *med = new TGeoMedium("MED",1,mat);
764 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
766 TGeoVolume *vol = gGeoManager->MakeTrd1("Trd1",med, 10,20,30,40);
768 vol->SetLineWidth(2);
769 top->AddNode(vol,1);
770 if (iaxis == 2 || iaxis == 3) {
771 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
772 if (!slice) return;
773 slice->SetLineColor(randomColor());
774 } else if (iaxis) {
775 printf("Wrong division axis %d. Allowed range is 2-3.\n", iaxis);
776 return;
777 }
780
781 top->Draw();
782
783 MakePicture();
784 if (!comments) return;
785 c->cd(2);
786 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
787 pt->SetLineColor(1);
788 TGeoTrd1 *trd1 = (TGeoTrd1 *) vol->GetShape();
789 TText *text = pt->AddText("TGeoTrd1 - Trd1 class");
790 text->SetTextColor(2);
791 AddMemberInfo(pt,"fDx1",trd1->GetDx1(),"half length in X at lower Z surface(-dz)");
792 AddMemberInfo(pt,"fDx2",trd1->GetDx2(),"half length in X at higher Z surface(+dz)");
793 AddMemberInfo(pt,"fDy",trd1->GetDy(),"half length in Y");
794 AddMemberInfo(pt,"fDz",trd1->GetDz(),"half length in Z");
796 AddExecInfo(pt, "trd1", "2 or 3 (Y, Z)");
797 pt->Draw();
798 c->cd(1);
799// SavePicture("trd1",c,vol,iaxis,step);
800}
801
802//______________________________________________________________________________
803void parab()
804{
805 auto c = create_canvas("A paraboloid segment");
806
807 if (gGeoManager) delete gGeoManager;
808 new TGeoManager("parab", "paraboloid");
809 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
810 TGeoMedium *med = new TGeoMedium("MED",1,mat);
811 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
813 TGeoVolume *vol = gGeoManager->MakeParaboloid("PARAB",med,0, 40, 50);
814 TGeoParaboloid *par = (TGeoParaboloid*)vol->GetShape();
816 vol->SetLineWidth(2);
817 top->AddNode(vol,1);
820
821 top->Draw();
822
823 MakePicture();
824 if (!comments) return;
825 c->cd(2);
826 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
827 pt->SetLineColor(1);
828 TText *text = pt->AddText("TGeoParaboloid - Paraboloid class");
829 text->SetTextColor(2);
830 AddMemberInfo(pt,"fRlo",par->GetRlo(),"radius at Z=-dz");
831 AddMemberInfo(pt,"fRhi",par->GetRhi(),"radius at Z=+dz");
832 AddMemberInfo(pt,"fDz",par->GetDz(),"half-length on Z axis");
833 pt->AddText("----- A paraboloid is described by the equation:");
834 pt->AddText("----- z = a*r*r + b; where: r = x*x + y*y");
835 pt->AddText("----- Create with: TGeoParaboloid *parab = new TGeoParaboloid(rlo, rhi, dz);");
836 pt->AddText("----- dz: half-length in Z (range from -dz to +dz");
837 pt->AddText("----- rlo: radius at z=-dz given by: -dz = a*rlo*rlo + b");
838 pt->AddText("----- rhi: radius at z=+dz given by: dz = a*rhi*rhi + b");
839 pt->AddText("----- rlo != rhi; both >= 0");
840 AddExecInfo(pt, "parab");
841 pt->Draw();
842 c->cd(1);
843}
844
845//______________________________________________________________________________
846void hype()
847{
848 auto c = create_canvas("A hyperboloid");
849
850 if (gGeoManager) delete gGeoManager;
851 new TGeoManager("hype", "hyperboloid");
852 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
853 TGeoMedium *med = new TGeoMedium("MED",1,mat);
854 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
856 TGeoVolume *vol = gGeoManager->MakeHype("HYPE",med,10, 45 ,20,45,40);
857 TGeoHype *hype = (TGeoHype*)vol->GetShape();
859 vol->SetLineWidth(2);
860 top->AddNode(vol,1);
863
864 top->Draw();
865
866 MakePicture();
867 if (!comments) return;
868 c->cd(2);
869 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
870 pt->SetLineColor(1);
871 TText *text = pt->AddText("TGeoHype - Hyperboloid class");
872 text->SetTextColor(2);
873 AddMemberInfo(pt, "fRmin", hype->GetRmin(), "minimum inner radius");
874 AddMemberInfo(pt, "fStIn", hype->GetStIn(), "inner surface stereo angle [deg]");
875 AddMemberInfo(pt, "fRmax", hype->GetRmax(), "minimum outer radius");
876 AddMemberInfo(pt, "fStOut",hype->GetStOut(),"outer surface stereo angle [deg]");
877 AddMemberInfo(pt, "fDz", hype->GetDz(), "half-length on Z axis");
878 pt->AddText("----- A hyperboloid is described by the equation:");
879 pt->AddText("----- r^2 - (tan(stereo)*z)^2 = rmin^2; where: r = x*x + y*y");
880 pt->AddText("----- Create with: TGeoHype *hype = new TGeoHype(rin, stin, rout, stout, dz);");
881 pt->AddText("----- rin < rout; rout > 0");
882 pt->AddText("----- rin = 0; stin > 0 => inner surface conical");
883 pt->AddText("----- stin/stout = 0 => corresponding surface cylindrical");
884 AddExecInfo(pt, "hype");
885 pt->Draw();
886 c->cd(1);
887}
888
889//______________________________________________________________________________
890void pcon(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
891{
892 auto c = create_canvas("A polycone");
893
894 if (gGeoManager) delete gGeoManager;
895 new TGeoManager("pcon", "poza10");
896 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
897 TGeoMedium *med = new TGeoMedium("MED",1,mat);
898 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
900 TGeoVolume *vol = gGeoManager->MakePcon("PCON",med, -30.0,300,4);
901 TGeoPcon *pcon = (TGeoPcon*)(vol->GetShape());
902 pcon->DefineSection(0,0,15,20);
903 pcon->DefineSection(1,20,15,20);
904 pcon->DefineSection(2,20,15,25);
905 pcon->DefineSection(3,50,15,20);
907 vol->SetLineWidth(2);
908 top->AddNode(vol,1);
909 if (iaxis == 2 || iaxis == 3) {
910 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
911 if (!slice) return;
912 slice->SetLineColor(randomColor());
913 } if (iaxis) {
914 printf("Wrong division axis %d. Allowed range is 2-3.\n", iaxis);
915 return;
916 }
919
920 top->Draw();
921
922 MakePicture();
923 if (!comments) return;
924 c->cd(2);
925 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
926 pt->SetLineColor(1);
927 TText *text = pt->AddText("TGeoPcon - pcon class");
928 text->SetTextColor(2);
929 AddMemberInfo(pt,"fPhi1",pcon->GetPhi1(),"lower phi limit");
930 AddMemberInfo(pt,"fDphi",pcon->GetDphi(),"phi range");
931 AddMemberInfo(pt,"fNz",pcon->GetNz(),"number of z planes");
932 for (Int_t j=0; j<pcon->GetNz(); j++) {
933 auto line = TString::Format(
934 "fZ[%i]=%5.2f fRmin[%i]=%5.2f fRmax[%i]=%5.2f",
935 j,pcon->GetZ()[j],j,pcon->GetRmin()[j],j,pcon->GetRmax()[j]);
936 text = pt->AddText(line.Data());
937 text->SetTextColor(4);
938 text->SetTextAlign(12);
939 }
941 AddExecInfo(pt, "pcon", "2 or 3 (Phi, Z)");
942 pt->Draw();
943 c->cd(1);
944// SavePicture("pcon",c,vol,iaxis,step);
945}
946
947//______________________________________________________________________________
948void pgon(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
949{
950 auto c = create_canvas("A polygone");
951
952 if (gGeoManager) delete gGeoManager;
953 new TGeoManager("pgon", "poza11");
954 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
955 TGeoMedium *med = new TGeoMedium("MED",1,mat);
956 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,150,150,100);
958 TGeoVolume *vol = gGeoManager->MakePgon("PGON",med, -45.0,270.0,4,4);
959 TGeoPgon *pgon = (TGeoPgon*)(vol->GetShape());
960 pgon->DefineSection(0,-70,45,50);
961 pgon->DefineSection(1,0,35,40);
962 pgon->DefineSection(2,0,30,35);
963 pgon->DefineSection(3,70,90,100);
965 vol->SetLineWidth(2);
966 top->AddNode(vol,1);
967 if (iaxis == 2 || iaxis == 3) {
968 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
969 if (!slice) return;
970 slice->SetLineColor(randomColor());
971 } if (iaxis) {
972 printf("Wrong division axis %d. Allowed range is 2-3.\n", iaxis);
973 return;
974 }
977
978 top->Draw();
979
980 MakePicture();
981 if (!comments) return;
982 c->cd(2);
983 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
984 pt->SetLineColor(1);
985 TText *text = pt->AddText("TGeoPgon - pgon class");
986 text->SetTextColor(2);
987 AddMemberInfo(pt, "fPhi1", pgon->GetPhi1(), "lower phi limit");
988 AddMemberInfo(pt, "fDphi", pgon->GetDphi(), "phi range");
989 AddMemberInfo(pt, "fNedges",pgon->GetNedges(),"number of edges");
990 AddMemberInfo(pt, "fNz", pgon->GetNz(), "number of z planes");
991 for (Int_t j=0; j<pgon->GetNz(); j++) {
992 auto line = TString::Format(
993 "fZ[%i]=%5.2f fRmin[%i]=%5.2f fRmax[%i]=%5.2f",
994 j,pgon->GetZ()[j],j,pgon->GetRmin()[j],j,pgon->GetRmax()[j]);
995 text = pt->AddText(line.Data());
996 text->SetTextColor(4);
997 text->SetTextAlign(12);
998 }
1000 AddExecInfo(pt, "pgon", "2 or 3 (Phi, Z)");
1001 pt->Draw();
1002 c->cd(1);
1003// SavePicture("pgon",c,vol,iaxis,step);
1004}
1005
1006//______________________________________________________________________________
1007void arb8()
1008{
1009 auto c = create_canvas("An arbitrary polyhedron");
1010
1011 if (gGeoManager) delete gGeoManager;
1012 new TGeoManager("arb8", "poza12");
1013 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
1014 TGeoMedium *med = new TGeoMedium("MED",1,mat);
1015 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
1017 TGeoArb8 *arb = new TGeoArb8(20);
1018 arb->SetVertex(0,-30,-25);
1019 arb->SetVertex(1,-25,25);
1020 arb->SetVertex(2,5,25);
1021 arb->SetVertex(3,25,-25);
1022 arb->SetVertex(4,-28,-23);
1023 arb->SetVertex(5,-23,27);
1024 arb->SetVertex(6,-23,27);
1025 arb->SetVertex(7,13,-27);
1026 TGeoVolume *vol = new TGeoVolume("ARB8",arb,med);
1027 vol->SetLineColor(randomColor());
1028 vol->SetLineWidth(2);
1029 top->AddNode(vol,1);
1032
1033 top->Draw();
1034
1035 MakePicture();
1036 if (!comments) return;
1037 c->cd(2);
1038 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
1039 pt->SetLineColor(1);
1040 TText *text = pt->AddText("TGeoArb8 - arb8 class");
1041 text->SetTextColor(2);
1042 AddMemberInfo(pt,"fDz",arb->GetDz(),"Z half length");
1043 Double_t *vert = arb->GetVertices();
1044 text = pt->AddText("Vertices on lower Z plane:");
1045 text->SetTextColor(3);
1046 for (Int_t i=0; i<4; i++) {
1047 text = pt->AddText(TString::Format(" fXY[%d] = (%5.2f, %5.2f)", i, vert[2*i], vert[2*i+1]));
1048 text->SetTextSize(0.043);
1049 text->SetTextColor(4);
1050 }
1051 text = pt->AddText("Vertices on higher Z plane:");
1052 text->SetTextColor(3);
1053 for (Int_t i=4; i<8; i++) {
1054 text = pt->AddText(TString::Format(" fXY[%d] = (%5.2f, %5.2f)", i, vert[2*i], vert[2*i+1]));
1055 text->SetTextSize(0.043);
1056 text->SetTextColor(4);
1057 }
1058
1059 AddExecInfo(pt, "arb8");
1060 pt->Draw();
1061 c->cd(1);
1062// SavePicture("arb8",c,vol,iaxis,step);
1063}
1064
1065//______________________________________________________________________________
1066void trd2(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
1067{
1068 auto c = create_canvas("A trapezoid with dX and dY varying with Z");
1069
1070 if (gGeoManager) delete gGeoManager;
1071 new TGeoManager("trd2", "poza9");
1072 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
1073 TGeoMedium *med = new TGeoMedium("MED",1,mat);
1074 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
1076 TGeoVolume *vol = gGeoManager->MakeTrd2("Trd2",med, 10,20,30,10,40);
1077 vol->SetLineColor(randomColor());
1078 vol->SetLineWidth(2);
1079 top->AddNode(vol,1);
1080 if (iaxis == 3) {
1081 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
1082 if (!slice) return;
1083 slice->SetLineColor(randomColor());
1084 } else if (iaxis) {
1085 printf("Wrong division axis %d. Allowed is only 3.\n", iaxis);
1086 return;
1087 }
1090
1091 top->Draw();
1092
1093 MakePicture();
1094 if (!comments) return;
1095 c->cd(2);
1096 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
1097 pt->SetLineColor(1);
1098 TGeoTrd2 *trd2 = (TGeoTrd2*)(vol->GetShape());
1099 TText *text = pt->AddText("TGeoTrd2 - Trd2 class");
1100 text->SetTextColor(2);
1101 AddMemberInfo(pt,"fDx1",trd2->GetDx1(),"half length in X at lower Z surface(-dz)");
1102 AddMemberInfo(pt,"fDx2",trd2->GetDx2(),"half length in X at higher Z surface(+dz)");
1103 AddMemberInfo(pt,"fDy1",trd2->GetDy1(),"half length in Y at lower Z surface(-dz)");
1104 AddMemberInfo(pt,"fDy2",trd2->GetDy2(),"half length in Y at higher Z surface(-dz)");
1105 AddMemberInfo(pt,"fDz",trd2->GetDz(),"half length in Z");
1106 AddFinderInfo(pt, vol->GetFinder(), iaxis);
1107 AddExecInfo(pt, "trd2", "only 3 (Z)");
1108 pt->Draw();
1109 c->cd(1);
1110// SavePicture("trd2",c,vol,iaxis,step);
1111}
1112
1113//______________________________________________________________________________
1114void trap(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
1115{
1116 auto c = create_canvas("A more general trapezoid");
1117
1118 if (gGeoManager) delete gGeoManager;
1119 new TGeoManager("trap", "poza10");
1120 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
1121 TGeoMedium *med = new TGeoMedium("MED",1,mat);
1122 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
1124 TGeoVolume *vol = gGeoManager->MakeTrap("Trap",med, 30,15,30,20,10,15,0,20,10,15,0);
1125 vol->SetLineColor(randomColor());
1126 vol->SetLineWidth(2);
1127 top->AddNode(vol,1);
1128 if (iaxis == 3) {
1129 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
1130 if (!slice) return;
1131 slice->SetLineColor(randomColor());
1132 } else if (iaxis) {
1133 printf("Wrong division axis %d. Allowed is only 3.\n", iaxis);
1134 return;
1135 }
1138
1139 top->Draw();
1140
1141 MakePicture();
1142 if (!comments) return;
1143 c->cd(2);
1144 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
1145 pt->SetLineColor(1);
1146 TGeoTrap *trap = (TGeoTrap*)(vol->GetShape());
1147 TText *text = pt->AddText("TGeoTrap - Trapezoid class");
1148 text->SetTextColor(2);
1149 AddMemberInfo(pt,"fDz",trap->GetDz(),"half length in Z");
1150 AddMemberInfo(pt,"fTheta",trap->GetTheta(),"theta angle of trapezoid axis");
1151 AddMemberInfo(pt,"fPhi",trap->GetPhi(),"phi angle of trapezoid axis");
1152 AddMemberInfo(pt,"fH1",trap->GetH1(),"half length in y at -fDz");
1153 AddMemberInfo(pt,"fAlpha1",trap->GetAlpha1(),"angle between centers of x edges and y axis at -fDz");
1154 AddMemberInfo(pt,"fBl1",trap->GetBl1(),"half length in x at -dZ and y=-fH1");
1155 AddMemberInfo(pt,"fTl1",trap->GetTl1(),"half length in x at -dZ and y=+fH1");
1156 AddMemberInfo(pt,"fH2",trap->GetH2(),"half length in y at +fDz");
1157 AddMemberInfo(pt,"fBl2",trap->GetBl2(),"half length in x at +dZ and y=-fH1");
1158 AddMemberInfo(pt,"fTl2",trap->GetTl2(),"half length in x at +dZ and y=+fH1");
1159 AddMemberInfo(pt,"fAlpha2",trap->GetAlpha2(),"angle between centers of x edges and y axis at +fDz");
1160 AddFinderInfo(pt, vol->GetFinder(), iaxis);
1161 AddExecInfo(pt, "trap", "only 3 (Z)");
1162 pt->Draw();
1163 c->cd(1);
1164// SavePicture("trap",c,vol,iaxis,step);
1165}
1166
1167//______________________________________________________________________________
1168void gtra(Int_t iaxis=0, Int_t ndiv=8, Double_t start=0, Double_t step=0)
1169{
1170 auto c = create_canvas("A twisted trapezoid");
1171
1172 if (gGeoManager) delete gGeoManager;
1173 new TGeoManager("gtra", "poza11");
1174 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
1175 TGeoMedium *med = new TGeoMedium("MED",1,mat);
1176 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
1178 TGeoVolume *vol = gGeoManager->MakeGtra("Gtra",med, 30,15,30,30,20,10,15,0,20,10,15,0);
1179 vol->SetLineColor(randomColor());
1180 vol->SetLineWidth(2);
1181 top->AddNode(vol,1);
1182 if (iaxis == 3) {
1183 TGeoVolume *slice = vol->Divide("SLICE",iaxis,ndiv,start,step);
1184 if (!slice) return;
1185 slice->SetLineColor(randomColor());
1186 } else if (iaxis) {
1187 printf("Wrong division axis %d. Allowed is only 3.\n", iaxis);
1188 return;
1189 }
1192
1193 top->Draw();
1194
1195 MakePicture();
1196 if (!comments) return;
1197 c->cd(2);
1198 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
1199 pt->SetLineColor(1);
1200 TGeoGtra *trap = (TGeoGtra*)(vol->GetShape());
1201 TText *text = pt->AddText("TGeoGtra - Twisted trapezoid class");
1202 text->SetTextColor(2);
1203 AddMemberInfo(pt,"fDz",trap->GetDz(),"half length in Z");
1204 AddMemberInfo(pt,"fTheta",trap->GetTheta(),"theta angle of trapezoid axis");
1205 AddMemberInfo(pt,"fPhi",trap->GetPhi(),"phi angle of trapezoid axis");
1206 AddMemberInfo(pt,"fTwist",trap->GetTwistAngle(), "twist angle");
1207 AddMemberInfo(pt,"fH1",trap->GetH1(),"half length in y at -fDz");
1208 AddMemberInfo(pt,"fAlpha1",trap->GetAlpha1(),"angle between centers of x edges and y axis at -fDz");
1209 AddMemberInfo(pt,"fBl1",trap->GetBl1(),"half length in x at -dZ and y=-fH1");
1210 AddMemberInfo(pt,"fTl1",trap->GetTl1(),"half length in x at -dZ and y=+fH1");
1211 AddMemberInfo(pt,"fH2",trap->GetH2(),"half length in y at +fDz");
1212 AddMemberInfo(pt,"fBl2",trap->GetBl2(),"half length in x at +dZ and y=-fH1");
1213 AddMemberInfo(pt,"fTl2",trap->GetTl2(),"half length in x at +dZ and y=+fH1");
1214 AddMemberInfo(pt,"fAlpha2",trap->GetAlpha2(),"angle between centers of x edges and y axis at +fDz");
1215 AddFinderInfo(pt, vol->GetFinder(), iaxis);
1216 AddExecInfo(pt, "gtra", "only 3 (Z)");
1217 pt->Draw();
1218 c->cd(1);
1219// SavePicture("gtra",c,vol,iaxis,step);
1220}
1221
1222//______________________________________________________________________________
1223void xtru()
1224{
1225 auto c = create_canvas("A twisted trapezoid");
1226
1227 if (gGeoManager) delete gGeoManager;
1228 new TGeoManager("xtru", "poza12");
1229 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
1230 TGeoMedium *med = new TGeoMedium("MED",1,mat);
1231 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
1233 TGeoVolume *vol = gGeoManager->MakeXtru("XTRU",med,4);
1234 TGeoXtru *xtru = (TGeoXtru*)vol->GetShape();
1235 Double_t x[8] = {-30,-30,30,30,15,15,-15,-15};
1236 Double_t y[8] = {-30,30,30,-30,-30,15,15,-30};
1237 xtru->DefinePolygon(8,x,y);
1238 xtru->DefineSection(0,-40, -20., 10., 1.5);
1239 xtru->DefineSection(1, 10, 0., 0., 0.5);
1240 xtru->DefineSection(2, 10, 0., 0., 0.7);
1241 xtru->DefineSection(3, 40, 10., 20., 0.9);
1242 vol->SetLineColor(randomColor());
1243 vol->SetLineWidth(2);
1244 top->AddNode(vol,1);
1247
1248 top->Draw();
1249
1250 MakePicture();
1251 if (!comments) return;
1252 c->cd(2);
1253 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
1254 pt->SetLineColor(1);
1255 TText *text = pt->AddText("TGeoXtru - Polygonal extrusion class");
1256 text->SetTextColor(2);
1257 AddMemberInfo(pt,"fNvert",xtru->GetNvert(),"number of polygone vertices");
1258 AddMemberInfo(pt,"fNz",xtru->GetNz(),"number of Z sections");
1259 pt->AddText("----- Any Z section is an arbitrary polygone");
1260 pt->AddText("----- The shape can have an arbitrary number of Z sections, as for pcon/pgon");
1261 pt->AddText("----- Create with: TGeoXtru *xtru = new TGeoXtru(nz);");
1262 pt->AddText("----- Define the blueprint polygon :");
1263 pt->AddText("----- Double_t x[8] = {-30,-30,30,30,15,15,-15,-15};");
1264 pt->AddText("----- Double_t y[8] = {-30,30,30,-30,-30,15,15,-30};");
1265 pt->AddText("----- xtru->DefinePolygon(8,x,y);");
1266 pt->AddText("----- Define translations/scales of the blueprint for Z sections :");
1267 pt->AddText("----- xtru->DefineSection(i, Zsection, x0, y0, scale);");
1268 pt->AddText("----- Sections have to be defined in increasing Z order");
1269 pt->AddText("----- 2 sections can be defined at same Z (not for first/last sections)");
1270 AddExecInfo(pt, "xtru");
1271 pt->Draw();
1272 c->cd(1);
1273}
1274
1275//______________________________________________________________________________
1276void tessellated()
1277{
1278 // Create a [triacontahedron solid](https://en.wikipedia.org/wiki/Rhombic_triacontahedron)
1279
1280 auto c = create_canvas("A tessellated shape");
1281
1282 if (gGeoManager) delete gGeoManager;
1283 new TGeoManager("tessellated", "tessellated");
1284 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
1285 TGeoMedium *med = new TGeoMedium("MED",1,mat);
1286 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,10,10,10);
1288 TGeoTessellated *tsl = new TGeoTessellated("triaconthaedron", 30);
1289 const Double_t sqrt5 = TMath::Sqrt(5.);
1290 std::vector<Tessellated::Vertex_t> vert;
1291 vert.reserve(120);
1292 vert.emplace_back(0, 0.5 * (1 + sqrt5), -1); vert.emplace_back(0, 0.5 * (-1 + sqrt5), 0.5 * (-1 - sqrt5)); vert.emplace_back(-1, 0, 0.5 * (-1 - sqrt5)); vert.emplace_back(-1, 1, -1);
1293 vert.emplace_back(1, 1, -1); vert.emplace_back(0, 0.5 * (1 + sqrt5), -1); vert.emplace_back(0, 0.5 * (-1 + sqrt5), 0.5 * (-1 - sqrt5)); vert.emplace_back(1, 0, 0.5 * (-1 - sqrt5));
1294 vert.emplace_back(1, 1, -1); vert.emplace_back(0, 0.5 * (1 + sqrt5), -1); vert.emplace_back(0.5 * (-1 + sqrt5), 0.5 * (1 + sqrt5), 0); vert.emplace_back(0.5 * (1 + sqrt5), 1, 0);
1295 vert.emplace_back(0.5 * (1 - sqrt5), 0.5 * (1 + sqrt5), 0); vert.emplace_back(0, 0.5 * (1 + sqrt5), -1); vert.emplace_back(0.5 * (-1 + sqrt5), 0.5 * (1 + sqrt5), 0); vert.emplace_back(0, 0.5 * (1 + sqrt5), 1);
1296 vert.emplace_back(0.5 * (1 - sqrt5), 0.5 * (1 + sqrt5), 0); vert.emplace_back(0, 0.5 * (1 + sqrt5), -1); vert.emplace_back(-1, 1, -1); vert.emplace_back(0.5 * (-1 - sqrt5), 1, 0);
1297 vert.emplace_back(1, 1, -1); vert.emplace_back(0.5 * (1 + sqrt5), 1, 0); vert.emplace_back(0.5 * (1 + sqrt5), 0, 0.5 * (1 - sqrt5)); vert.emplace_back(1, 0, 0.5 * (-1 - sqrt5));
1298 vert.emplace_back(0.5 * (1 + sqrt5), 0, 0.5 * (1 - sqrt5)); vert.emplace_back(0.5 * (1 + sqrt5), -1, 0); vert.emplace_back(1, -1, -1); vert.emplace_back(1, 0, 0.5 * (-1 - sqrt5));
1299 vert.emplace_back(1, -1, -1); vert.emplace_back(0, 0.5 * (-1 - sqrt5), -1); vert.emplace_back(0, 0.5 * (1 - sqrt5), 0.5 * (-1 - sqrt5)); vert.emplace_back(1, 0, 0.5 * (-1 - sqrt5));
1300 vert.emplace_back(1, 0, 0.5 * (-1 - sqrt5)); vert.emplace_back(0, 0.5 * (-1 + sqrt5), 0.5 * (-1 - sqrt5)); vert.emplace_back(-1, 0, 0.5 * (-1 - sqrt5)); vert.emplace_back(0, 0.5 * (1 - sqrt5), 0.5 * (-1 - sqrt5));
1301 vert.emplace_back(0.5 * (-1 + sqrt5), 0.5 * (1 + sqrt5), 0); vert.emplace_back(0.5 * (1 + sqrt5), 1, 0); vert.emplace_back(1, 1, 1); vert.emplace_back(0, 0.5 * (1 + sqrt5), 1);
1302 vert.emplace_back(0.5 * (1 + sqrt5), 1, 0); vert.emplace_back(1, 1, 1); vert.emplace_back(1, 0, 0.5 * (1 + sqrt5)); vert.emplace_back(0.5 * (1 + sqrt5), 0, 0.5 * (-1 + sqrt5));
1303 vert.emplace_back(0.5 * (1 + sqrt5), 0, 0.5 * (1 - sqrt5)); vert.emplace_back(0.5 * (1 + sqrt5), 1, 0); vert.emplace_back(0.5 * (1 + sqrt5), 0, 0.5 * (-1 + sqrt5)); vert.emplace_back(0.5 * (1 + sqrt5), -1, 0);
1304 vert.emplace_back(0.5 * (1 - sqrt5), 0.5 * (1 + sqrt5), 0); vert.emplace_back(0, 0.5 * (1 + sqrt5), 1); vert.emplace_back(-1, 1, 1); vert.emplace_back(0.5 * (-1 - sqrt5), 1, 0);
1305 vert.emplace_back(0, 0.5 * (1 + sqrt5), 1); vert.emplace_back(0, 0.5 * (-1 + sqrt5), 0.5 * (1 + sqrt5)); vert.emplace_back(-1, 0, 0.5 * (1 + sqrt5)); vert.emplace_back(-1, 1, 1);
1306 vert.emplace_back(1, 1, 1); vert.emplace_back(0, 0.5 * (1 + sqrt5), 1); vert.emplace_back(0, 0.5 * (-1 + sqrt5), 0.5 * (1 + sqrt5)); vert.emplace_back(1, 0, 0.5 * (1 + sqrt5));
1307 vert.emplace_back(0, 0.5 * (1 - sqrt5), 0.5 * (1 + sqrt5)); vert.emplace_back(-1, 0, 0.5 * (1 + sqrt5)); vert.emplace_back(0, 0.5 * (-1 + sqrt5), 0.5 * (1 + sqrt5)); vert.emplace_back(1, 0, 0.5 * (1 + sqrt5));
1308 vert.emplace_back(0, 0.5 * (1 - sqrt5), 0.5 * (1 + sqrt5)); vert.emplace_back(1, 0, 0.5 * (1 + sqrt5)); vert.emplace_back(1, -1, 1); vert.emplace_back(0, 0.5 * (-1 - sqrt5), 1);
1309 vert.emplace_back(0.5 * (1 + sqrt5), 0, 0.5 * (-1 + sqrt5)); vert.emplace_back(0.5 * (1 + sqrt5), -1, 0); vert.emplace_back(1, -1, 1); vert.emplace_back(1, 0, 0.5 * (1 + sqrt5));
1310 vert.emplace_back(-1, 0, 0.5 * (1 + sqrt5)); vert.emplace_back(-1, 1, 1); vert.emplace_back(0.5 * (-1 - sqrt5), 1, 0); vert.emplace_back(0.5 * (-1 - sqrt5), 0, 0.5 * (-1 + sqrt5));
1311 vert.emplace_back(-1, -1, 1); vert.emplace_back(-1, 0, 0.5 * (1 + sqrt5)); vert.emplace_back(0.5 * (-1 - sqrt5), 0, 0.5 * (-1 + sqrt5)); vert.emplace_back(0.5 * (-1 - sqrt5), -1, 0);
1312 vert.emplace_back(0, 0.5 * (1 - sqrt5), 0.5 * (1 + sqrt5)); vert.emplace_back(-1, 0, 0.5 * (1 + sqrt5)); vert.emplace_back(-1, -1, 1); vert.emplace_back(0, 0.5 * (-1 - sqrt5), 1);
1313 vert.emplace_back(0.5 * (-1 - sqrt5), -1, 0); vert.emplace_back(0.5 * (-1 - sqrt5), 0, 0.5 * (1 - sqrt5)); vert.emplace_back(0.5 * (-1 - sqrt5), 1, 0); vert.emplace_back(0.5 * (-1 - sqrt5), 0, 0.5 * (-1 + sqrt5));
1314 vert.emplace_back(0.5 * (-1 - sqrt5), -1, 0); vert.emplace_back(0.5 * (-1 - sqrt5), 0, 0.5 * (1 - sqrt5)); vert.emplace_back(-1, 0, 0.5 * (-1 - sqrt5)); vert.emplace_back(-1, -1, -1);
1315 vert.emplace_back(0, 0.5 * (-1 - sqrt5), -1); vert.emplace_back(0.5 * (1 - sqrt5), 0.5 * (-1 - sqrt5), 0); vert.emplace_back(0.5 * (-1 - sqrt5), -1, 0); vert.emplace_back(-1, -1, -1);
1316 vert.emplace_back(0.5 * (1 - sqrt5), 0.5 * (-1 - sqrt5), 0); vert.emplace_back(0.5 * (-1 - sqrt5), -1, 0); vert.emplace_back(-1, -1, 1); vert.emplace_back(0, 0.5 * (-1 - sqrt5), 1);
1317 vert.emplace_back(-1, 1, -1); vert.emplace_back(-1, 0, 0.5 * (-1 - sqrt5)); vert.emplace_back(0.5 * (-1 - sqrt5), 0, 0.5 * (1 - sqrt5)); vert.emplace_back(0.5 * (-1 - sqrt5), 1, 0);
1318 vert.emplace_back(0, 0.5 * (-1 - sqrt5), -1); vert.emplace_back(0, 0.5 * (1 - sqrt5), 0.5 * (-1 - sqrt5)); vert.emplace_back(-1, 0, 0.5 * (-1 - sqrt5)); vert.emplace_back(-1, -1, -1);
1319 vert.emplace_back(0, 0.5 * (-1 - sqrt5), -1); vert.emplace_back(0.5 * (1 - sqrt5), 0.5 * (-1 - sqrt5), 0); vert.emplace_back(0, 0.5 * (-1 - sqrt5), 1); vert.emplace_back(0.5 * (-1 + sqrt5), 0.5 * (-1 - sqrt5), 0);
1320 vert.emplace_back(1, -1, -1); vert.emplace_back(0.5 * (1 + sqrt5), -1, 0); vert.emplace_back(0.5 * (-1 + sqrt5), 0.5 * (-1 - sqrt5), 0); vert.emplace_back(0, 0.5 * (-1 - sqrt5), -1);
1321 vert.emplace_back(0.5 * (1 + sqrt5), -1, 0); vert.emplace_back(1, -1, 1); vert.emplace_back(0, 0.5 * (-1 - sqrt5), 1); vert.emplace_back(0.5 * (-1 + sqrt5), 0.5 * (-1 - sqrt5), 0);
1322
1323 tsl->AddFacet(vert[0], vert[1], vert[2], vert[3]);
1324 tsl->AddFacet(vert[4], vert[7], vert[6], vert[5]);
1325 tsl->AddFacet(vert[8], vert[9], vert[10], vert[11]);
1326 tsl->AddFacet(vert[12], vert[15], vert[14], vert[13]);
1327 tsl->AddFacet(vert[16], vert[17], vert[18], vert[19]);
1328 tsl->AddFacet(vert[20], vert[21], vert[22], vert[23]);
1329 tsl->AddFacet(vert[24], vert[25], vert[26], vert[27]);
1330 tsl->AddFacet(vert[28], vert[29], vert[30], vert[31]);
1331 tsl->AddFacet(vert[32], vert[35], vert[34], vert[33]);
1332 tsl->AddFacet(vert[36], vert[39], vert[38], vert[37]);
1333 tsl->AddFacet(vert[40], vert[41], vert[42], vert[43]);
1334 tsl->AddFacet(vert[44], vert[45], vert[46], vert[47]);
1335 tsl->AddFacet(vert[48], vert[51], vert[50], vert[49]);
1336 tsl->AddFacet(vert[52], vert[55], vert[54], vert[53]);
1337 tsl->AddFacet(vert[56], vert[57], vert[58], vert[59]);
1338 tsl->AddFacet(vert[60], vert[63], vert[62], vert[61]);
1339 tsl->AddFacet(vert[64], vert[67], vert[66], vert[65]);
1340 tsl->AddFacet(vert[68], vert[71], vert[70], vert[69]);
1341 tsl->AddFacet(vert[72], vert[73], vert[74], vert[75]);
1342 tsl->AddFacet(vert[76], vert[77], vert[78], vert[79]);
1343 tsl->AddFacet(vert[80], vert[81], vert[82], vert[83]);
1344 tsl->AddFacet(vert[84], vert[87], vert[86], vert[85]);
1345 tsl->AddFacet(vert[88], vert[89], vert[90], vert[91]);
1346 tsl->AddFacet(vert[92], vert[93], vert[94], vert[95]);
1347 tsl->AddFacet(vert[96], vert[99], vert[98], vert[97]);
1348 tsl->AddFacet(vert[100], vert[101], vert[102], vert[103]);
1349 tsl->AddFacet(vert[104], vert[107], vert[106], vert[105]);
1350 tsl->AddFacet(vert[108], vert[111], vert[110], vert[109]);
1351 tsl->AddFacet(vert[112], vert[113], vert[114], vert[115]);
1352 tsl->AddFacet(vert[116], vert[117], vert[118], vert[119]);
1353
1354 TGeoVolume *vol = new TGeoVolume("TRIACONTHAEDRON", tsl, med);
1355 vol->SetLineColor(randomColor());
1356 vol->SetLineWidth(2);
1357 top->AddNode(vol,1);
1359
1360 top->Draw();
1361
1362 MakePicture();
1363 if (!comments) return;
1364 c->cd(2);
1365 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
1366 pt->SetLineColor(1);
1367 TText *text = pt->AddText("TGeoTessellated - Tessellated shape class");
1368 text->SetTextColor(2);
1369 AddMemberInfo(pt,"fNfacets",tsl->GetNfacets(),"number of facets");
1370 AddMemberInfo(pt,"fNvertices",tsl->GetNvertices(),"number of vertices");
1371 pt->AddText("----- A tessellated shape is defined by the number of facets");
1372 pt->AddText("----- facets can be added using AddFacet");
1373 pt->AddText("----- Create with: TGeoTessellated *tsl = new TGeoTessellated(nfacets);");
1374 AddExecInfo(pt, "tessellated");
1375 pt->Draw();
1376 c->cd(1);
1377}
1378
1379//______________________________________________________________________________
1380void composite()
1381{
1382 auto c = create_canvas("A Boolean shape composition");
1383
1384 if (gGeoManager) delete gGeoManager;
1385 new TGeoManager("xtru", "poza12");
1386 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
1387 TGeoMedium *med = new TGeoMedium("MED",1,mat);
1388 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
1390 // define shape components with names
1391 TGeoPgon *pgon = new TGeoPgon("pg",0.,360.,6,2);
1392 pgon->DefineSection(0,0,0,20);
1393 pgon->DefineSection(1, 30,0,20);
1394 new TGeoSphere("sph", 40., 45.);
1395 // define named geometrical transformations with names
1396 TGeoTranslation *tr = new TGeoTranslation(0., 0., 45.);
1397 tr->SetName("tr");
1398 // register all used transformations
1399 tr->RegisterYourself();
1400 // create the composite shape based on a Boolean expression
1401 TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph:tr*pg");
1402 TGeoVolume *vol = new TGeoVolume("COMP",cs);
1403 vol->SetLineColor(randomColor());
1404 top->AddNode(vol,1);
1407
1408 top->Draw();
1409
1410 MakePicture();
1411 if (!comments) return;
1412 c->cd(2);
1413 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
1414 pt->SetLineColor(1);
1415 TText *text = pt->AddText("TGeoCompositeShape - composite shape class");
1416 text->SetTextColor(2);
1417 pt->AddText("----- Define the shape components and don't forget to name them");
1418 pt->AddText("----- Define geometrical transformations that apply to shape components");
1419 pt->AddText("----- Name all transformations and register them");
1420 pt->AddText("----- Define the composite shape based on a Boolean expression");
1421 pt->AddText(" TGeoCompositeShape(\"someName\", \"expression\")");
1422 pt->AddText("----- Expression is made of <shapeName:transfName> components related by Boolean operators");
1423 pt->AddText("----- Boolean operators can be: (+) union, (-) subtraction and (*) intersection");
1424 pt->AddText("----- Use parenthesis in the expression to force precedence");
1425 AddExecInfo(pt, "composite");
1426 pt->Draw();
1427 c->cd(1);
1428}
1429
1430//______________________________________________________________________________
1431void ideal()
1432{
1433// This is an ideal geometry. In real life, some geometry pieces are moved/rotated
1434// with respect to their ideal positions. This is called alignment. Alignment
1435// operations can be handled by TGeo starting from a CLOSED geometry (applied a posteriori)
1436// Alignment is handled by PHYSICAL NODES, representing an unique object in geometry.
1437//
1438// Creating physical nodes:
1439// 1. TGeoPhysicalNode *node = gGeoManager->MakePhysicalNode(const char *path)
1440// - creates a physical node represented by path
1441// - path can be : TOP_1/A_2/B_3
1442// - B_3 is the 'final node' e.g. the logical node represented by this physical node
1443// 2. TGeoPhysicalNode *node = gGeoManager->MakePhysicalNode()
1444// - creates a physical node representing the current modeller state
1445
1446// Setting visualisation options for TGeoPhysicalNode *node:
1447// 1. node->SetVisibility(Bool_t flag); // set node visible(*) or invisible
1448// 2. node->SetIsVolAtt(Bool_t flag); // set line attributes to match the ones of the volumes in the branch
1449// - default - TRUE
1450// - when called with FALSE - the attributes defined for the physical node will be taken
1451// node->SetLineColor(color);
1452// node->SetLineWidth(width);
1453// node->SetLineStyle(style);
1454// 3. node->SetVisibleFull(Bool_t flag); // not only last node in the branch is visible (default)
1455//
1456// Activating/deactivating physical nodes drawing - not needed in case of alignment
1457
1458// Aligning physical nodes
1459//==========================
1460// node->Align(TGeoMatrix *newmat, TGeoShape *newshape, Bool_t check=kFALSE);
1461// newmat = new matrix to replace final node LOCAL matrix
1462// newshape = new shape to replace final node shape
1463// check = optional check if the new aligned node is overlapping
1464// gGeoManager->SetDrawExtraPaths(Bool_t flag)
1465
1466 auto c = create_canvas("Ideal geometry");
1467
1468 if (gGeoManager) delete gGeoManager;
1469 new TGeoManager("alignment", "Ideal geometry");
1470 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
1471 TGeoMedium *med = new TGeoMedium("MED",1,mat);
1472 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,10);
1474 TGeoVolume *slicex = top->Divide("SX",1,10,-100,10);
1475 TGeoVolume *slicey = slicex->Divide("SY",2,10,-100,10);
1476 TGeoVolume *vol = gGeoManager->MakePgon("CELL",med,0.,360.,6,2);
1477 TGeoPgon *pgon = (TGeoPgon*)(vol->GetShape());
1478 pgon->DefineSection(0,-5,0.,2.);
1479 pgon->DefineSection(1,5,0.,2.);
1480 vol->SetLineColor(randomColor());
1481 slicey->AddNode(vol,1);
1484
1485 top->Draw();
1486
1487 MakePicture();
1488 if (!comments) return;
1489 c->cd(2);
1490 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
1491 pt->SetLineColor(1);
1492 TText *text = pt->AddText("Ideal / Aligned geometry");
1493 text->SetTextColor(2);
1494 pt->AddText("-- Create physical nodes for the objects you want to align");
1495 pt->AddText("-- You must start from a valid CLOSED geometry");
1496 pt->AddText(" TGeoPhysicalNode *node = gGeoManager->MakePhysicalNode(const char *path)");
1497 pt->AddText(" + creates a physical node represented by path, e.g. TOP_1/A_2/B_3");
1498 pt->AddText(" node->Align(TGeoMatrix *newmat, TGeoShape *newshape, Bool_t check=kFALSE)");
1499 pt->AddText(" + newmat = new matrix to replace final node LOCAL matrix");
1500 pt->AddText(" + newshape = new shape to replace final node shape");
1501 pt->AddText(" + check = optional check if the new aligned node is overlapping");
1502 pt->AddText(" ");
1503 pt->SetAllWith("--","color",4);
1504 pt->SetAllWith("--","font",72);
1505 pt->SetAllWith("--","size",0.04);
1506 pt->SetAllWith("+","color",2);
1507 pt->SetAllWith("+","font",72);
1508 pt->SetAllWith("+","size",0.04);
1509 pt->SetTextAlign(12);
1510 pt->SetTextSize(0.044);
1511 pt->Draw();
1512 c->cd(1);
1513}
1514
1515//______________________________________________________________________________
1516void align()
1517{
1518 if (!gGeoManager) return;
1519 if (strcmp(gGeoManager->GetName(),"alignment")) {
1520 printf("Click: <Ideal geometry> first\n");
1521 return;
1522 }
1524 for (Int_t i=1; i<=10; i++) {
1525 for (Int_t j=1; j<=10; j++) {
1526 TGeoPhysicalNode *node = nullptr;
1527 auto name = TString::Format("TOP_1/SX_%d/SY_%d/CELL_1",i,j);
1528 if (list) node = (TGeoPhysicalNode*)list->At(10*(i-1)+j-1);
1529 if (!node) node = gGeoManager->MakePhysicalNode(name.Data());
1531 if (node->IsAligned()) {
1532 tr = (TGeoTranslation*)node->GetNode()->GetMatrix();
1533 tr->SetTranslation(2.*gRandom->Rndm(), 2.*gRandom->Rndm(),0.);
1534 } else {
1535 tr = new TGeoTranslation(2.*gRandom->Rndm(), 2.*gRandom->Rndm(),0.);
1536 }
1537 node->Align(tr);
1538 }
1539 }
1540 if (gPad) {
1541 gPad->Modified();
1542 gPad->Update();
1543 }
1544}
1545
1546//______________________________________________________________________________
1547void geodemo ()
1548{
1549// root[0] .x geodemo.C
1550// root[1] box(); //draw a TGeoBBox with description
1551//
1552// The box can be divided on one axis.
1553//
1554// root[2] box(iaxis, ndiv, start, step);
1555//
1556// where: iaxis = 1,2 or 3, meaning (X,Y,Z) or (Rxy, phi, Z) depending on shape type
1557// ndiv = number of slices
1558// start = starting position (must be in shape range)
1559// step = division step
1560// If step=0, all range of a given axis will be divided
1561//
1562// The same can procedure can be performed for visualizing other shapes.
1563// When drawing one shape after another, the old geometry/canvas will be deleted.
1564 TControlBar *bar = new TControlBar("vertical", "TGeo shapes",10,10);
1565 bar->AddButton("How to run ","help()","Instructions for running this macro");
1566 bar->AddButton("Arb8 ","arb8()","An arbitrary polyhedron defined by vertices (max 8) sitting on 2 parallel planes");
1567 bar->AddButton("Box ","box()","A box shape.");
1568 bar->AddButton("Composite ","composite()","A composite shape");
1569 bar->AddButton("Cone ","cone()","A conical tube");
1570 bar->AddButton("Cone segment","coneseg()","A conical segment");
1571 bar->AddButton("Cut tube ","ctub()","A cut tube segment");
1572 bar->AddButton("Elliptical tube","eltu()","An elliptical tube");
1573 bar->AddButton("Extruded poly","xtru()","A general polygone extrusion");
1574 bar->AddButton("Hyperboloid ","hype()","A hyperboloid");
1575 bar->AddButton("Paraboloid ","parab()","A paraboloid");
1576 bar->AddButton("Polycone ","pcon()","A polycone shape");
1577 bar->AddButton("Polygone ","pgon()","A polygone");
1578 bar->AddButton("Parallelepiped","para()","A parallelepiped shape");
1579 bar->AddButton("Sphere ","sphere()","A spherical sector");
1580 bar->AddButton("Trd1 ","trd1()","A trapezoid with dX varying with Z");
1581 bar->AddButton("Trd2 ","trd2()","A trapezoid with both dX and dY varying with Z");
1582 bar->AddButton("Trapezoid ","trap()","A general trapezoid");
1583 bar->AddButton("Torus ","torus()","A toroidal segment");
1584 bar->AddButton("Tube ","tube()","A tube with inner and outer radius");
1585 bar->AddButton("Tube segment","tubeseg()","A tube segment");
1586 bar->AddButton("Twisted trap","gtra()","A twisted trapezoid");
1587 bar->AddButton("Tessellated ","tessellated()","A tessellated shape");
1588 bar->AddButton("Aligned (ideal)","ideal()","An ideal (un-aligned) geometry");
1589 bar->AddButton("Un-aligned","align()","Some alignment operation");
1590 bar->AddButton("RAY-TRACE ON/OFF","raytrace()","Toggle ray-tracing mode");
1591 bar->AddButton("COMMENTS ON/OFF","comments = !comments;","Toggle explanations pad ON/OFF");
1592 bar->AddButton("AXES ON/OFF","axes()","Toggle axes ON/OFF");
1593 bar->AddButton("AUTOROTATE ON/OFF","autorotate()","Toggle autorotation ON/OFF");
1594 bar->Show();
1595 gROOT->SaveContext();
1596 gRandom = new TRandom3();
1597}
#define c(i)
Definition RSha256.hxx:101
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char text
char name[80]
Definition TGX11.cxx:110
R__EXTERN TGeoManager * gGeoManager
#define gROOT
Definition TROOT.h:414
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
#define gPad
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:42
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:47
The Canvas class.
Definition TCanvas.h:23
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition TControlBar.h:26
void Show()
Show control bar.
void AddButton(TControlBarButton *button)
Add button.
An arbitrary trapezoid with less than 8 vertices standing on two parallel planes perpendicular to Z a...
Definition TGeoArb8.h:17
void SetVisRaytrace(Bool_t flag=kTRUE)
Definition TGeoAtt.h:66
Box class.
Definition TGeoBBox.h:17
Composite shapes are Boolean combinations of two or more shape components.
A cone segment is a cone having a range in phi.
Definition TGeoCone.h:99
The cones are defined by 5 parameters:
Definition TGeoCone.h:17
An elliptical tube is defined by the two semi-axes A and B.
Definition TGeoEltu.h:17
A twisted trapezoid.
Definition TGeoArb8.h:149
A hyperboloid is represented as a solid limited by two planes perpendicular to the Z axis (top and bo...
Definition TGeoHype.h:17
The manager class for any TGeo geometry.
Definition TGeoManager.h:44
TGeoVolume * MakeCone(const char *name, TGeoMedium *medium, Double_t dz, Double_t rmin1, Double_t rmax1, Double_t rmin2, Double_t rmax2)
Make in one step a volume pointing to a cone shape with given medium.
TGeoVolume * MakeXtru(const char *name, TGeoMedium *medium, Int_t nz)
Make a TGeoXtru-shaped volume with nz planes.
TGeoVolume * MakePcon(const char *name, TGeoMedium *medium, Double_t phi, Double_t dphi, Int_t nz)
Make in one step a volume pointing to a polycone shape with given medium.
TGeoVolume * MakeTube(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t dz)
Make in one step a volume pointing to a tube shape with given medium.
TGeoVolume * MakeCons(const char *name, TGeoMedium *medium, Double_t dz, Double_t rmin1, Double_t rmax1, Double_t rmin2, Double_t rmax2, Double_t phi1, Double_t phi2)
Make in one step a volume pointing to a cone segment shape with given medium.
TVirtualGeoPainter * GetGeomPainter()
Make a default painter if none present. Returns pointer to it.
TGeoVolume * MakePara(const char *name, TGeoMedium *medium, Double_t dx, Double_t dy, Double_t dz, Double_t alpha, Double_t theta, Double_t phi)
Make in one step a volume pointing to a parallelepiped shape with given medium.
TGeoPhysicalNode * MakePhysicalNode(const char *path=nullptr)
Makes a physical node corresponding to a path.
TGeoVolume * MakeTorus(const char *name, TGeoMedium *medium, Double_t r, Double_t rmin, Double_t rmax, Double_t phi1=0, Double_t dphi=360)
Make in one step a volume pointing to a torus shape with given medium.
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
TGeoVolume * MakeTrd2(const char *name, TGeoMedium *medium, Double_t dx1, Double_t dx2, Double_t dy1, Double_t dy2, Double_t dz)
Make in one step a volume pointing to a TGeoTrd2 shape with given medium.
TGeoVolume * MakeGtra(const char *name, TGeoMedium *medium, Double_t dz, Double_t theta, Double_t phi, Double_t twist, Double_t h1, Double_t bl1, Double_t tl1, Double_t alpha1, Double_t h2, Double_t bl2, Double_t tl2, Double_t alpha2)
Make in one step a volume pointing to a twisted trapezoid shape with given medium.
TGeoVolume * MakeBox(const char *name, TGeoMedium *medium, Double_t dx, Double_t dy, Double_t dz)
Make in one step a volume pointing to a box shape with given medium.
TGeoVolume * MakeTrd1(const char *name, TGeoMedium *medium, Double_t dx1, Double_t dx2, Double_t dy, Double_t dz)
Make in one step a volume pointing to a TGeoTrd1 shape with given medium.
TGeoVolume * MakeSphere(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t themin=0, Double_t themax=180, Double_t phimin=0, Double_t phimax=360)
Make in one step a volume pointing to a sphere shape with given medium.
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
TGeoVolume * MakeCtub(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2, Double_t lx, Double_t ly, Double_t lz, Double_t tx, Double_t ty, Double_t tz)
Make in one step a volume pointing to a tube segment shape with given medium.
TGeoVolume * MakePgon(const char *name, TGeoMedium *medium, Double_t phi, Double_t dphi, Int_t nedges, Int_t nz)
Make in one step a volume pointing to a polygone shape with given medium.
TGeoVolume * MakeTrap(const char *name, TGeoMedium *medium, Double_t dz, Double_t theta, Double_t phi, Double_t h1, Double_t bl1, Double_t tl1, Double_t alpha1, Double_t h2, Double_t bl2, Double_t tl2, Double_t alpha2)
Make in one step a volume pointing to a trapezoid shape with given medium.
void SetNsegments(Int_t nseg)
Set number of segments for approximating circles in drawing.
TGeoVolume * GetTopVolume() const
TObjArray * GetListOfPhysicalNodes()
TGeoVolume * MakeHype(const char *name, TGeoMedium *medium, Double_t rin, Double_t stin, Double_t rout, Double_t stout, Double_t dz)
Make in one step a volume pointing to a tube shape with given medium.
TGeoVolume * MakeParaboloid(const char *name, TGeoMedium *medium, Double_t rlo, Double_t rhi, Double_t dz)
Make in one step a volume pointing to a tube shape with given medium.
TGeoVolume * MakeTubs(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2)
Make in one step a volume pointing to a tube segment shape with given medium.
TGeoVolume * MakeEltu(const char *name, TGeoMedium *medium, Double_t a, Double_t b, Double_t dz)
Make in one step a volume pointing to a tube shape with given medium.
Base class describing materials.
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:23
virtual TGeoMatrix * GetMatrix() const =0
Parallelepiped class.
Definition TGeoPara.h:17
A paraboloid is defined by the revolution surface generated by a parabola and is bounded by two plane...
Double_t GetDz() const
Double_t GetRhi() const
Double_t GetRlo() const
Base finder class for patterns.
A polycone is represented by a sequence of tubes/cones, glued together at defined Z planes.
Definition TGeoPcon.h:17
Polygons are defined in the same way as polycones, the difference being just that the segments betwee...
Definition TGeoPgon.h:20
Physical nodes are the actual 'touchable' objects in the geometry, representing a path of positioned ...
Bool_t IsAligned() const
TGeoNode * GetNode(Int_t level=-1) const
Return node in branch at LEVEL. If not specified, return last leaf.
Bool_t Align(TGeoMatrix *newmat=nullptr, TGeoShape *newshape=nullptr, Bool_t check=kFALSE, Double_t ovlp=0.001)
Align a physical node with a new relative matrix/shape.
Base abstract class for all shapes.
Definition TGeoShape.h:25
virtual const char * GetAxisName(Int_t iaxis) const =0
TGeoSphere are not just balls having internal and external radii, but sectors of a sphere having defi...
Definition TGeoSphere.h:17
Tessellated solid class.
The torus is defined by its axial radius, its inner and outer radius.
Definition TGeoTorus.h:17
Class describing translations.
Definition TGeoMatrix.h:116
A general trapezoid.
Definition TGeoArb8.h:96
A trapezoid with only X varying with Z.
Definition TGeoTrd1.h:17
A trapezoid with only X varying with Z.
Definition TGeoTrd2.h:17
A tube segment is a tube having a range in phi.
Definition TGeoTube.h:94
Cylindrical tube class.
Definition TGeoTube.h:17
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
void SetLineWidth(Width_t lwidth) override
Set the line width.
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
Add a TGeoNode to the list of nodes.
void Draw(Option_t *option="") override
draw top volume according to option
TGeoPatternFinder * GetFinder() const
Definition TGeoVolume.h:177
void SetLineColor(Color_t lcolor) override
Set the line color.
TGeoShape * GetShape() const
Definition TGeoVolume.h:190
virtual TGeoVolume * Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed=0, Option_t *option="")
Division a la G3.
Bool_t IsRaytracing() const
Check if the painter is currently ray-tracing the content of this volume.
A TGeoXtru shape is represented by the extrusion of an arbitrary polygon with fixed outline between s...
Definition TGeoXtru.h:22
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
An array of TObjects.
Definition TObjArray.h:31
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Clear(Option_t *="")
Definition TObject.h:119
TObject * FindObject(const char *name) const override
Search if object named name is inside this pad or in pads inside this pad.
Definition TPad.cxx:2700
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
virtual void SetAllWith(const char *text, Option_t *option, Double_t value)
Set attribute option for all lines containing string text.
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
Random number generator class based on M.
Definition TRandom3.h:27
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559
Basic string class.
Definition TString.h:139
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Base class for several text objects.
Definition TText.h:22
See TView3D.
Definition TView.h:25
virtual Double_t GetPsi()=0
virtual Double_t GetLongitude()=0
virtual void ShowAxis()=0
virtual Double_t GetLatitude()=0
virtual void SetView(Double_t longitude, Double_t latitude, Double_t psi, Int_t &irep)=0
Abstract class for geometry painters.
TPaveText * pt
TLine * line
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:594
constexpr Double_t Pi()
Definition TMath.h:37
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:588