Logo ROOT  
Reference Guide
parallel_world.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_geom
3 /// Misaligning geometry generate in many cases overlaps, due to the idealization
4 /// of the design and the fact that in real life movements of the geometry volumes
5 /// have constraints and are correlated.
6 ///
7 /// This typically generates inconsistent
8 /// response of the navigation methods, leading to inefficiencies during tracking,
9 /// errors in the material budget calculations, and so on. Among those, there are
10 /// dangerous cases when the hidden volumes are sensitive.
11 /// This macro demonstrates how to use the "parallel world" feature to assign
12 /// highest navigation priority to some physical paths in geometry.
13 ///
14 /// \macro_image
15 /// \macro_code
16 ///
17 /// \author Andrei Gheata
18 
19 void align();
20 
21 //______________________________________________________________________________
22 void parallel_world(Bool_t usepw=kTRUE, Bool_t useovlp=kTRUE)
23 {
24  TGeoManager *geom = new TGeoManager("parallel_world", "Showcase for prioritized physical paths");
25  TGeoMaterial *matV = new TGeoMaterial("Vac", 0,0,0);
26  TGeoMedium *medV = new TGeoMedium("MEDVAC",1,matV);
27  TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7);
28  TGeoMedium *medAl = new TGeoMedium("MEDAL",2,matAl);
29  TGeoMaterial *matSi = new TGeoMaterial("Si", 28.085,14,2.329);
30  TGeoMedium *medSi = new TGeoMedium("MEDSI",3,matSi);
31  TGeoVolume *top = gGeoManager->MakeBox("TOP",medV,100,400,1000);
33 
34  // Shape for the support block
35  TGeoBBox *sblock = new TGeoBBox("sblock", 20,10,2);
36  // The volume for the support
37  TGeoVolume *support = new TGeoVolume("block",sblock, medAl);
38  support->SetLineColor(kGreen);
39 
40  // Shape for the sensor to be prioritized in case of overlap
41  TGeoBBox *ssensor = new TGeoBBox("sensor", 19,9,0.2);
42  // The volume for the sensor
43  TGeoVolume *sensor = new TGeoVolume("sensor",ssensor, medSi);
44  sensor->SetLineColor(kRed);
45 
46  // Chip assembly of support+sensor
47  TGeoVolumeAssembly *chip = new TGeoVolumeAssembly("chip");
48  chip->AddNode(support, 1);
49  chip->AddNode(sensor,1, new TGeoTranslation(0,0,-2.1));
50 
51  // A ladder that normally sags
52  TGeoBBox *sladder = new TGeoBBox("sladder", 20,300,5);
53  // The volume for the ladder
54  TGeoVolume *ladder = new TGeoVolume("ladder",sladder, medAl);
55  ladder->SetLineColor(kBlue);
56 
57  // Add nodes
58  top->AddNode(ladder,1);
59  for (Int_t i=0; i<10; i++)
60  top->AddNode(chip, i+1, new TGeoTranslation(0, -225.+50.*i, 10));
61 
63  TGeoParallelWorld *pw = 0;
64  if (usepw) pw = gGeoManager->CreateParallelWorld("priority_sensors");
65 // Align chips
66  align();
67  if (usepw) {
68  if (useovlp) pw->AddOverlap(ladder);
69  pw->CloseGeometry();
71  }
72  TString cname;
73  cname = usepw ? "cpw" : "cnopw";
74  TCanvas *c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(cname);
75  if (c) c->cd();
76  else c = new TCanvas(cname, "",800,600);
77  top->Draw();
78 // top->RandomRays(0,0,0,0,sensor->GetName());
79  // Track random "particles" coming from the block side and draw only the tracklets
80  // actually crossing one of the sensors. Note that some of the tracks coming
81  // from the outer side may see the full sensor, while the others only part of it.
82  TStopwatch timer;
83  timer.Start();
84  top->RandomRays(100000,0,0,-30,sensor->GetName());
85  timer.Stop();
86  timer.Print();
87  TView3D *view = (TView3D*)gPad->GetView();
88  view->SetParallel();
89  view->Side();
90  if (usepw) pw->PrintDetectedOverlaps();
91 }
92 
93 //______________________________________________________________________________
94 void align()
95 {
96 // Aligning 2 sensors so they will overlap with the support. One sensor is positioned
97 // normally while the other using the shared matrix
98  TGeoPhysicalNode *node;
100  Double_t sag;
101  for (Int_t i=0; i<10; i++) {
102  node = gGeoManager->MakePhysicalNode(TString::Format("/TOP_1/chip_%d",i+1));
103  sag = 8.-0.494*(i-4.5)*(i-4.5);
104  TGeoTranslation *tr = new TGeoTranslation(0., -225.+50.*i, 10-sag);
105  node->Align(tr);
106  if (pw) pw->AddNode(TString::Format("/TOP_1/chip_%d",i+1));
107  }
108 }
c
#define c(i)
Definition: RSha256.hxx:101
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGeoPhysicalNode
Physical nodes are the actual 'touchable' objects in the geometry, representing a path of positioned ...
Definition: TGeoPhysicalNode.h:37
TView3D
The 3D view class.
Definition: TView3D.h:29
TGeoManager::SetUseParallelWorldNav
void SetUseParallelWorldNav(Bool_t flag)
Activate/deactivate usage of parallel world navigation.
Definition: TGeoManager.cxx:3991
TGeoManager::MakeBox
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.
Definition: TGeoManager.cxx:2918
kGreen
@ kGreen
Definition: Rtypes.h:66
gGeoManager
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:602
TGeoManager::CreateParallelWorld
TGeoParallelWorld * CreateParallelWorld(const char *name)
Create a parallel world for prioritised navigation.
Definition: TGeoManager.cxx:3980
TGeoParallelWorld::PrintDetectedOverlaps
Int_t PrintDetectedOverlaps() const
Print the overlaps which were detected during real tracking.
Definition: TGeoParallelWorld.cxx:104
TGeoManager::CloseGeometry
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
Definition: TGeoManager.cxx:1359
Int_t
int Int_t
Definition: RtypesCore.h:45
TGeoParallelWorld
Base class for a flat parallel geometry.
Definition: TGeoParallelWorld.h:22
TGeoVolume::AddNode
virtual void AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:932
TGeoParallelWorld::AddNode
void AddNode(const char *path)
Add a node normally to this world. Overlapping nodes not allowed.
Definition: TGeoParallelWorld.cxx:65
TString::Format
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:2311
TString
Basic string class.
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGeoTranslation
Class describing translations.
Definition: TGeoMatrix.h:122
TGeoMaterial
Base class describing materials.
Definition: TGeoMaterial.h:36
TGeoParallelWorld::AddOverlap
void AddOverlap(TGeoVolume *vol, Bool_t activate=kTRUE)
To use this optimization, the user should declare the full list of volumes which may overlap with any...
Definition: TGeoParallelWorld.cxx:80
TGeoManager::MakePhysicalNode
TGeoPhysicalNode * MakePhysicalNode(const char *path=0)
Makes a physical node corresponding to a path.
Definition: TGeoManager.cxx:3258
TStopwatch::Print
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
Definition: TStopwatch.cxx:219
TGeoManager::SetTopVolume
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
Definition: TGeoManager.cxx:3397
TGeoVolumeAssembly::AddNode
virtual void AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a component to the assembly.
Definition: TGeoVolume.cxx:2805
TGeoManager::GetParallelWorld
TGeoParallelWorld * GetParallelWorld() const
Definition: TGeoManager.h:595
TGeoVolume::Draw
virtual void Draw(Option_t *option="")
draw top volume according to option
Definition: TGeoVolume.cxx:1146
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
TGeoBBox
Box class.
Definition: TGeoBBox.h:18
kRed
@ kRed
Definition: Rtypes.h:66
TGeoParallelWorld::CloseGeometry
Bool_t CloseGeometry()
The main geometry must be closed.
Definition: TGeoParallelWorld.cxx:132
TGeoVolume::RandomRays
void RandomRays(Int_t nrays=10000, Double_t startx=0, Double_t starty=0, Double_t startz=0, const char *target_vol=0, Bool_t check_norm=kFALSE)
Random raytracing method.
Definition: TGeoVolume.cxx:1334
Double_t
double Double_t
Definition: RtypesCore.h:59
TCanvas
The Canvas class.
Definition: TCanvas.h:23
TStopwatch
Stopwatch class.
Definition: TStopwatch.h:28
kBlue
@ kBlue
Definition: Rtypes.h:66
gPad
#define gPad
Definition: TVirtualPad.h:287
TView3D::SetParallel
virtual void SetParallel()
Set the parallel option (default).
Definition: TView3D.cxx:1304
TGeoMedium
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition: TGeoMedium.h:24
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
TGeoPhysicalNode::Align
Bool_t Align(TGeoMatrix *newmat=0, TGeoShape *newshape=0, Bool_t check=kFALSE, Double_t ovlp=0.001)
Align a physical node with a new relative matrix/shape.
Definition: TGeoPhysicalNode.cxx:133
TStopwatch::Stop
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:77
TGeoVolume::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TGeoVolume.cxx:2036
TGeoManager
The manager class for any TGeo geometry.
Definition: TGeoManager.h:45
TView3D::Side
virtual void Side()
Definition: TView3D.cxx:1933
TGeoVolume
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:49
TGeoVolumeAssembly
Volume assemblies.
Definition: TGeoVolume.h:303
gROOT
#define gROOT
Definition: TROOT.h:406