Logo ROOT   6.10/09
Reference Guide
TGeoManager.cxx
Go to the documentation of this file.
1 // @(#)root/geom:$Id$
2 // Author: Andrei Gheata 25/10/01
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TGeoManager
13 \ingroup Geometry_classes
14 
15 The manager class for any TGeo geometry. Provides user
16 interface for geometry creation, navigation, state querying,
17 visualization, IO, geometry checking and other utilities.
18 
19 ## General architecture
20 
21  The ROOT geometry package is a tool designed for building, browsing,
22 tracking and visualizing a detector geometry. The code is independent from
23 other external MC for simulation, therefore it does not contain any
24 constraints related to physics. However, the package defines a number of
25 hooks for tracking, such as media, materials, magnetic field or track state flags,
26 in order to allow interfacing to tracking MC's. The final goal is to be
27 able to use the same geometry for several purposes, such as tracking,
28 reconstruction or visualization, taking advantage of the ROOT features
29 related to bookkeeping, I/O, histograming, browsing and GUI's.
30 
31  The geometrical modeler is the most important component of the package and
32 it provides answers to the basic questions like "Where am I ?" or "How far
33 from the next boundary ?", but also to more complex ones like "How far from
34 the closest surface ?" or "Which is the next crossing along a helix ?".
35 
36  The architecture of the modeler is a combination between a GEANT-like
37 containment scheme and a normal CSG binary tree at the level of shapes. An
38 important common feature of all detector geometry descriptions is the
39 mother-daughter concept. This is the most natural approach when tracking
40 is concerned and imposes a set of constraints to the way geometry is defined.
41 Constructive solid geometry composition is used only in order to create more
42 complex shapes from an existing set of primitives through boolean operations.
43 This feature is not implemented yet but in future full definition of boolean
44 expressions will be supported.
45 
46  Practically every geometry defined in GEANT style can be mapped by the modeler.
47 The basic components used for building the logical hierarchy of the geometry
48 are called "volumes" and "nodes". Volumes (sometimes called "solids") are fully
49 defined geometrical objects having a given shape and medium and possibly
50 containing a list of nodes. Nodes represent just positioned instances of volumes
51 inside a container volume and they are not directly defined by user. They are
52 automatically created as a result of adding one volume inside other or dividing
53 a volume. The geometrical transformation hold by nodes is always defined with
54 respect to their mother (relative positioning). Reflection matrices are allowed.
55 All volumes have to be fully aware of their containees when the geometry is
56 closed. They will build additional structures (voxels) in order to fasten-up
57 the search algorithms. Finally, nodes can be regarded as bidirectional links
58 between containers and containees objects.
59 
60  The structure defined in this way is a graph structure since volumes are
61 replicable (same volume can become daughter node of several other volumes),
62 every volume becoming a branch in this graph. Any volume in the logical graph
63 can become the actual top volume at run time (see TGeoManager::SetTopVolume()).
64 All functionalities of the modeler will behave in this case as if only the
65 corresponding branch starting from this volume is the registered geometry.
66 
67 \image html geom_graf.jpg
68 
69  A given volume can be positioned several times in the geometry. A volume
70 can be divided according default or user-defined patterns, creating automatically
71 the list of division nodes inside. The elementary volumes created during the
72 dividing process follow the same scheme as usual volumes, therefore it is possible
73 to position further geometrical structures inside or to divide them further more
74 (see TGeoVolume::Divide()).
75 
76  The primitive shapes supported by the package are basically the GEANT3
77 shapes (see class TGeoShape), arbitrary wedges with eight vertices on two parallel
78 planes. All basic primitives inherits from class TGeoBBox since the bounding box
79 of a solid is essential for the tracking algorithms. They also implement the
80 virtual methods defined in the virtual class TGeoShape (point and segment
81 classification). User-defined primitives can be directly plugged into the modeler
82 provided that they override these methods. Composite shapes will be soon supported
83 by the modeler. In order to build a TGeoCompositeShape, one will have to define
84 first the primitive components. The object that handle boolean
85 operations among components is called TGeoBoolCombinator and it has to be
86 constructed providing a string boolean expression between the components names.
87 
88 
89 ## Example for building a simple geometry
90 
91 Begin_Macro(source)
92 ../../../tutorials/geom/rootgeom.C
93 End_Macro
94 
95 ## TGeoManager - the manager class for the geometry package.
96 
97  TGeoManager class is embedding all the API needed for building and tracking
98 a geometry. It defines a global pointer (gGeoManager) in order to be fully
99 accessible from external code. The mechanism of handling multiple geometries
100 at the same time will be soon implemented.
101 
102  TGeoManager is the owner of all geometry objects defined in a session,
103 therefore users must not try to control their deletion. It contains lists of
104 media, materials, transformations, shapes and volumes. Logical nodes (positioned
105 volumes) are created and destroyed by the TGeoVolume class. Physical
106 nodes and their global transformations are subjected to a caching mechanism
107 due to the sometimes very large memory requirements of logical graph expansion.
108 The caching mechanism is triggered by the total number of physical instances
109 of volumes and the cache manager is a client of TGeoManager. The manager class
110 also controls the painter client. This is linked with ROOT graphical libraries
111 loaded on demand in order to control visualization actions.
112 
113 ## Rules for building a valid geometry
114 
115  A given geometry can be built in various ways, but there are mandatory steps
116 that have to be followed in order to be validated by the modeler. There are
117 general rules : volumes needs media and shapes in order to be created,
118 both container an containee volumes must be created before linking them together,
119 and the relative transformation matrix must be provided. All branches must
120 have an upper link point otherwise they will not be considered as part of the
121 geometry. Visibility or tracking properties of volumes can be provided both
122 at build time or after geometry is closed, but global visualization settings
123 (see TGeoPainter class) should not be provided at build time, otherwise the
124 drawing package will be loaded. There is also a list of specific rules :
125 positioned daughters should not extrude their mother or intersect with sisters
126 unless this is specified (see TGeoVolume::AddNodeOverlap()), the top volume
127 (containing all geometry tree) must be specified before closing the geometry
128 and must not be positioned - it represents the global reference frame. After
129 building the full geometry tree, the geometry must be closed
130 (see TGeoManager::CloseGeometry()). Voxelization can be redone per volume after
131 this process.
132 
133 
134  Below is the general scheme of the manager class.
135 
136 \image html geom_mgr.jpg
137 
138 ## An interactive session
139 
140  Provided that a geometry was successfully built and closed (for instance the
141 previous example $ROOTSYS/tutorials/geom/rootgeom.C ), the manager class will register
142 itself to ROOT and the logical/physical structures will become immediately browsable.
143 The ROOT browser will display starting from the geometry folder : the list of
144 transformations and media, the top volume and the top logical node. These last
145 two can be fully expanded, any intermediate volume/node in the browser being subject
146 of direct access context menu operations (right mouse button click). All user
147 utilities of classes TGeoManager, TGeoVolume and TGeoNode can be called via the
148 context menu.
149 
150 \image html geom_browser.jpg
151 
152 ### Drawing the geometry
153 
154  Any logical volume can be drawn via TGeoVolume::Draw() member function.
155 This can be directly accessed from the context menu of the volume object
156 directly from the browser.
157  There are several drawing options that can be set with
158 TGeoManager::SetVisOption(Int_t opt) method :
159 
160 #### opt=0
161  only the content of the volume is drawn, N levels down (default N=3).
162  This is the default behavior. The number of levels to be drawn can be changed
163  via TGeoManager::SetVisLevel(Int_t level) method.
164 
165 \image html geom_frame0.jpg
166 
167 #### opt=1
168  the final leaves (e.g. daughters with no containment) of the branch
169  starting from volume are drawn down to the current number of levels.
170  WARNING : This mode is memory consuming
171  depending of the size of geometry, so drawing from top level within this mode
172  should be handled with care for expensive geometries. In future there will be
173  a limitation on the maximum number of nodes to be visualized.
174 
175 \image html geom_frame1.jpg
176 
177 #### opt=2
178  only the clicked volume is visualized. This is automatically set by
179  TGeoVolume::DrawOnly() method
180 
181 #### opt=3 - only a given path is visualized. This is automatically set by
182  TGeoVolume::DrawPath(const char *path) method
183 
184  The current view can be exploded in cartesian, cylindrical or spherical
185 coordinates :
186  TGeoManager::SetExplodedView(Int_t opt). Options may be :
187 - 0 - default (no bombing)
188 - 1 - cartesian coordinates. The bomb factor on each axis can be set with
189  TGeoManager::SetBombX(Double_t bomb) and corresponding Y and Z.
190 - 2 - bomb in cylindrical coordinates. Only the bomb factors on Z and R
191  are considered
192  \image html geom_frameexp.jpg
193 
194 - 3 - bomb in radial spherical coordinate : TGeoManager::SetBombR()
195 
196 Volumes themselves support different visualization settings :
197  - TGeoVolume::SetVisibility() : set volume visibility.
198  - TGeoVolume::VisibleDaughters() : set daughters visibility.
199 All these actions automatically updates the current view if any.
200 
201 ### Checking the geometry
202 
203  Several checking methods are accessible from the volume context menu. They
204 generally apply only to the visible parts of the drawn geometry in order to
205 ease geometry checking, and their implementation is in the TGeoChecker class
206 from the painting package.
207 
208 #### Checking a given point.
209  Can be called from TGeoManager::CheckPoint(Double_t x, Double_t y, Double_t z).
210 This method is drawing the daughters of the volume containing the point one
211 level down, printing the path to the deepest physical node holding this point.
212 It also computes the closest distance to any boundary. The point will be drawn
213 in red.
214 
215 \image html geom_checkpoint.jpg
216 
217 #### Shooting random points.
218  Can be called from TGeoVolume::RandomPoints() (context menu function) and
219 it will draw this volume with current visualization settings. Random points
220 are generated in the bounding box of the top drawn volume. The points are
221 classified and drawn with the color of their deepest container. Only points
222 in visible nodes will be drawn.
223 
224 \image html geom_random1.jpg
225 
226 
227 #### Raytracing.
228  Can be called from TGeoVolume::RandomRays() (context menu of volumes) and
229 will shoot rays from a given point in the local reference frame with random
230 directions. The intersections with displayed nodes will appear as segments
231 having the color of the touched node. Drawn geometry will be then made invisible
232 in order to enhance rays.
233 
234 \image html geom_random2.jpg
235 */
236 
237 #include <stdlib.h>
238 
239 #include "Riostream.h"
240 
241 #include "TROOT.h"
242 #include "TGeoManager.h"
243 #include "TSystem.h"
244 #include "TStyle.h"
245 #include "TVirtualPad.h"
246 #include "TBrowser.h"
247 #include "TFile.h"
248 #include "TKey.h"
249 #include "THashList.h"
250 #include "TClass.h"
251 #include "ThreadLocalStorage.h"
252 
253 #include "TGeoVoxelFinder.h"
254 #include "TGeoElement.h"
255 #include "TGeoMaterial.h"
256 #include "TGeoMedium.h"
257 #include "TGeoMatrix.h"
258 #include "TGeoNode.h"
259 #include "TGeoPhysicalNode.h"
260 #include "TGeoManager.h"
261 #include "TGeoPara.h"
262 #include "TGeoParaboloid.h"
263 #include "TGeoTube.h"
264 #include "TGeoEltu.h"
265 #include "TGeoHype.h"
266 #include "TGeoCone.h"
267 #include "TGeoSphere.h"
268 #include "TGeoArb8.h"
269 #include "TGeoPgon.h"
270 #include "TGeoTrd1.h"
271 #include "TGeoTrd2.h"
272 #include "TGeoTorus.h"
273 #include "TGeoXtru.h"
274 #include "TGeoCompositeShape.h"
275 #include "TGeoBoolNode.h"
276 #include "TGeoBuilder.h"
277 #include "TVirtualGeoPainter.h"
278 #include "TPluginManager.h"
279 #include "TVirtualGeoTrack.h"
280 #include "TQObject.h"
281 #include "TMath.h"
282 #include "TEnv.h"
283 #include "TGeoParallelWorld.h"
284 
285 // statics and globals
286 
290 
291 std::mutex TGeoManager::fgMutex;
300 
301 ////////////////////////////////////////////////////////////////////////////////
302 /// Default constructor.
303 
305 {
308  fTimeCut = kFALSE;
309  fTmin = 0.;
310  fTmax = 999.;
311  fPhiCut = kFALSE;
312  fPhimin = 0;
313  fPhimax = 360;
314  fDrawExtra = kFALSE;
318  fClosed = kFALSE;
320  fBits = 0;
321  fCurrentNavigator = 0;
322  fMaterials = 0;
323  fHashPNE = 0;
324  fArrayPNE = 0;
325  fMatrices = 0;
326  fNodes = 0;
327  fOverlaps = 0;
328  fNNodes = 0;
329  fMaxVisNodes = 10000;
330  fVolumes = 0;
331  fPhysicalNodes = 0;
332  fShapes = 0;
333  fGVolumes = 0;
334  fGShapes = 0;
335  fTracks = 0;
336  fMedia = 0;
337  fNtracks = 0;
338  fNpdg = 0;
339  fPdgNames = 0;
340  memset(fPdgId, 0, 1024*sizeof(Int_t));
341  fCurrentTrack = 0;
342  fCurrentVolume = 0;
343  fTopVolume = 0;
344  fTopNode = 0;
345  fMasterVolume = 0;
346  fPainter = 0;
347  fActivity = kFALSE;
349  fVisDensity = 0.;
350  fVisLevel = 3;
351  fVisOption = 1;
352  fExplodedView = 0;
353  fNsegments = 20;
354  fNLevel = 0;
355  fUniqueVolumes = 0;
356  fNodeIdArray = 0;
357  fClippingShape = 0;
360  fGLMatrix = 0;
361  fPaintVolume = 0;
362  fUserPaintVolume = 0;
363  fElementTable = 0;
364  fHashVolumes = 0;
365  fHashGVolumes = 0;
366  fSizePNEId = 0;
367  fNPNEId = 0;
368  fKeyPNEId = 0;
369  fValuePNEId = 0;
371  fRaytraceMode = 0;
372  fMaxThreads = 0;
373  fUsePWNav = kFALSE;
374  fParallelWorld = 0;
375  ClearThreadsMap();
376  } else {
377  Init();
380  }
381 }
382 
383 ////////////////////////////////////////////////////////////////////////////////
384 /// Constructor.
385 
386 TGeoManager::TGeoManager(const char *name, const char *title)
387  :TNamed(name, title)
388 {
389  if (!gROOT->GetListOfGeometries()->FindObject(this)) gROOT->GetListOfGeometries()->Add(this);
390  if (!gROOT->GetListOfBrowsables()->FindObject(this)) gROOT->GetListOfBrowsables()->Add(this);
391  Init();
392  gGeoIdentity = new TGeoIdentity("Identity");
394  if (fgVerboseLevel>0) Info("TGeoManager","Geometry %s, %s created", GetName(), GetTitle());
395 }
396 
397 ////////////////////////////////////////////////////////////////////////////////
398 /// Initialize manager class.
399 
400 void TGeoManager::Init()
401 {
402  if (gGeoManager) {
403  Warning("Init","Deleting previous geometry: %s/%s",gGeoManager->GetName(),gGeoManager->GetTitle());
404  delete gGeoManager;
405  if (fgLock) Fatal("Init", "New geometry created while the old one locked !!!");
406  }
407 
408  gGeoManager = this;
410  fTimeCut = kFALSE;
411  fTmin = 0.;
412  fTmax = 999.;
413  fPhiCut = kFALSE;
414  fPhimin = 0;
415  fPhimax = 360;
416  fDrawExtra = kFALSE;
420  fClosed = kFALSE;
422  fBits = new UChar_t[50000]; // max 25000 nodes per volume
423  fCurrentNavigator = 0;
424  fHashPNE = new THashList(256,3);
425  fArrayPNE = 0;
426  fMaterials = new THashList(200,3);
427  fMatrices = new TObjArray(256);
428  fNodes = new TObjArray(30);
429  fOverlaps = new TObjArray(256);
430  fNNodes = 0;
431  fMaxVisNodes = 10000;
432  fVolumes = new TObjArray(256);
433  fPhysicalNodes = new TObjArray(256);
434  fShapes = new TObjArray(256);
435  fGVolumes = new TObjArray(256);
436  fGShapes = new TObjArray(256);
437  fTracks = new TObjArray(256);
438  fMedia = new THashList(200,3);
439  fNtracks = 0;
440  fNpdg = 0;
441  fPdgNames = 0;
442  memset(fPdgId, 0, 1024*sizeof(Int_t));
443  fCurrentTrack = 0;
444  fCurrentVolume = 0;
445  fTopVolume = 0;
446  fTopNode = 0;
447  fMasterVolume = 0;
448  fPainter = 0;
449  fActivity = kFALSE;
451  fVisDensity = 0.;
452  fVisLevel = 3;
453  fVisOption = 1;
454  fExplodedView = 0;
455  fNsegments = 20;
456  fNLevel = 0;
457  fUniqueVolumes = new TObjArray(256);
458  fNodeIdArray = 0;
459  fClippingShape = 0;
462  fGLMatrix = new TGeoHMatrix();
463  fPaintVolume = 0;
464  fUserPaintVolume = 0;
465  fElementTable = 0;
466  fHashVolumes = 0;
467  fHashGVolumes = 0;
468  fSizePNEId = 0;
469  fNPNEId = 0;
470  fKeyPNEId = 0;
471  fValuePNEId = 0;
473  fRaytraceMode = 0;
474  fMaxThreads = 0;
475  fUsePWNav = kFALSE;
476  fParallelWorld = 0;
477  ClearThreadsMap();
478 }
479 
480 ////////////////////////////////////////////////////////////////////////////////
481 ///copy constructor
482 
484  TNamed(gm),
485  fPhimin(gm.fPhimin),
486  fPhimax(gm.fPhimax),
487  fTmin(gm.fTmin),
488  fTmax(gm.fTmax),
489  fNNodes(gm.fNNodes),
494  fVisLevel(gm.fVisLevel),
496  fNtracks(gm.fNtracks),
499  fNpdg(gm.fNpdg),
500  fClosed(gm.fClosed),
505  fPhiCut(gm.fPhiCut),
506  fTimeCut(gm.fTimeCut),
510  fActivity(gm.fActivity),
512  fPainter(gm.fPainter),
513  fMatrices(gm.fMatrices),
514  fShapes(gm.fShapes),
515  fVolumes(gm.fVolumes),
517  fGShapes(gm.fGShapes),
518  fGVolumes(gm.fGVolumes),
519  fTracks(gm.fTracks),
520  fPdgNames(gm.fPdgNames),
522  fMedia(gm.fMedia),
523  fNodes(gm.fNodes),
524  fOverlaps(gm.fOverlaps),
525  fBits(gm.fBits),
529  fTopNode(gm.fTopNode),
531  fGLMatrix(gm.fGLMatrix),
536  fNLevel(gm.fNLevel),
541  fHashPNE(gm.fHashPNE),
542  fArrayPNE(gm.fArrayPNE),
543  fSizePNEId(0),
544  fNPNEId(0),
545  fKeyPNEId(0),
546  fValuePNEId(0),
547  fMaxThreads(0),
549  fRaytraceMode(0),
550  fUsePWNav(kFALSE),
551  fParallelWorld(0)
552 {
553  for(Int_t i=0; i<1024; i++)
554  fPdgId[i]=gm.fPdgId[i];
556  ClearThreadsMap();
557 }
558 
559 ////////////////////////////////////////////////////////////////////////////////
560 ///assignment operator
561 
563 {
565  if(this!=&gm) {
566  TNamed::operator=(gm);
567  fPhimin=gm.fPhimin;
568  fPhimax=gm.fPhimax;
569  fTmin=gm.fTmin;
570  fTmax=gm.fTmax;
571  fNNodes=gm.fNNodes;
576  fVisLevel=gm.fVisLevel;
578  fNtracks=gm.fNtracks;
581  fNpdg=gm.fNpdg;
582  for(Int_t i=0; i<1024; i++)
583  fPdgId[i]=gm.fPdgId[i];
584  fClosed=gm.fClosed;
589  fPhiCut=gm.fPhiCut;
590  fTimeCut=gm.fTimeCut;
594  fActivity=gm.fActivity;
596  fPainter=gm.fPainter;
597  fMatrices=gm.fMatrices;
598  fShapes=gm.fShapes;
599  fVolumes=gm.fVolumes;
601  fGShapes=gm.fGShapes;
602  fGVolumes=gm.fGVolumes;
603  fTracks=gm.fTracks;
604  fPdgNames=gm.fPdgNames;
606  fMedia=gm.fMedia;
607  fNodes=gm.fNodes;
608  fOverlaps=gm.fOverlaps;
609  fBits=gm.fBits;
613  fTopNode=gm.fTopNode;
615  fGLMatrix=gm.fGLMatrix;
620  fNLevel=gm.fNLevel;
625  fHashPNE=gm.fHashPNE;
626  fArrayPNE=gm.fArrayPNE;
627  fSizePNEId = 0;
628  fNPNEId = 0;
629  fKeyPNEId = 0;
630  fValuePNEId = 0;
632  fRaytraceMode = 0;
633  fMaxThreads = 0;
634  fUsePWNav = kFALSE;
635  fParallelWorld = 0;
636  ClearThreadsMap();
637  ClearThreadData();
638  }
639  return *this;
640 }
641 
642 ////////////////////////////////////////////////////////////////////////////////
643 /// Destructor
644 
646 {
647  if (gGeoManager != this) gGeoManager = this;
649 
650  if (gROOT->GetListOfFiles()) { //in case this function is called from TROOT destructor
651  gROOT->GetListOfGeometries()->Remove(this);
652  gROOT->GetListOfBrowsables()->Remove(this);
653  }
654 // TSeqCollection *brlist = gROOT->GetListOfBrowsers();
655 // TIter next(brlist);
656 // TBrowser *browser = 0;
657 // while ((browser=(TBrowser*)next())) browser->RecursiveRemove(this);
658  ClearThreadsMap();
659  ClearThreadData();
660  delete TGeoBuilder::Instance(this);
661  if (fBits) delete [] fBits;
667  if (fMedia) {fMedia->Delete(); SafeDelete(fMedia);}
671  if (fArrayPNE) {delete fArrayPNE;}
673  if (fShapes) {fShapes->Delete(); SafeDelete( fShapes );}
676  if (fTracks) {fTracks->Delete(); SafeDelete( fTracks );}
679  ClearNavigators();
680  CleanGarbage();
681  SafeDelete( fPainter );
683  if (fSizePNEId) {
684  delete [] fKeyPNEId;
685  delete [] fValuePNEId;
686  }
687  delete fParallelWorld;
689  gGeoIdentity = 0;
690  gGeoManager = 0;
691 }
692 
693 ////////////////////////////////////////////////////////////////////////////////
694 /// Add a material to the list. Returns index of the material in list.
695 
697 {
698  return TGeoBuilder::Instance(this)->AddMaterial((TGeoMaterial*)material);
699 }
700 
701 ////////////////////////////////////////////////////////////////////////////////
702 /// Add an illegal overlap/extrusion to the list.
703 
705 {
706  Int_t size = fOverlaps->GetEntriesFast();
707  fOverlaps->Add((TObject*)ovlp);
708  return size;
709 }
710 
711 ////////////////////////////////////////////////////////////////////////////////
712 /// Add a matrix to the list. Returns index of the matrix in list.
713 
715 {
716  return TGeoBuilder::Instance(this)->AddTransformation((TGeoMatrix*)matrix);
717 }
718 
719 ////////////////////////////////////////////////////////////////////////////////
720 /// Add a shape to the list. Returns index of the shape in list.
721 
723 {
724  return TGeoBuilder::Instance(this)->AddShape((TGeoShape*)shape);
725 }
726 
727 ////////////////////////////////////////////////////////////////////////////////
728 /// Add a track to the list of tracks. Use this for primaries only. For secondaries,
729 /// add them to the parent track. The method create objects that are registered
730 /// to the analysis manager but have to be cleaned-up by the user via ClearTracks().
731 
732 Int_t TGeoManager::AddTrack(Int_t id, Int_t pdgcode, TObject *particle)
733 {
734  Int_t index = fNtracks;
735  fTracks->AddAtAndExpand(GetGeomPainter()->AddTrack(id,pdgcode,particle),fNtracks++);
736  return index;
737 }
738 
739 ////////////////////////////////////////////////////////////////////////////////
740 /// Add a track to the list of tracks
741 
743 {
744  Int_t index = fNtracks;
745  fTracks->AddAtAndExpand(track,fNtracks++);
746  return index;
747 }
748 
749 ////////////////////////////////////////////////////////////////////////////////
750 /// Makes a primary track but do not attach it to the list of tracks. The track
751 /// can be attached as daughter to another one with TVirtualGeoTrack::AddTrack
752 
754 {
755  TVirtualGeoTrack *track = GetGeomPainter()->AddTrack(id,pdgcode,particle);
756  return track;
757 }
758 
759 ////////////////////////////////////////////////////////////////////////////////
760 /// Add a volume to the list. Returns index of the volume in list.
761 
763 {
764  if (!volume) {
765  Error("AddVolume", "invalid volume");
766  return -1;
767  }
769  if (!uid) uid++;
770  if (!fCurrentVolume) {
771  fCurrentVolume = volume;
772  fUniqueVolumes->AddAtAndExpand(volume,uid);
773  } else {
774  if (!strcmp(volume->GetName(), fCurrentVolume->GetName())) {
775  uid = fCurrentVolume->GetNumber();
776  } else {
777  fCurrentVolume = volume;
778  Int_t olduid = GetUID(volume->GetName());
779  if (olduid<0) {
780  fUniqueVolumes->AddAtAndExpand(volume,uid);
781  } else {
782  uid = olduid;
783  }
784  }
785  }
786  volume->SetNumber(uid);
787  if (!fHashVolumes) {
788  fHashVolumes = new THashList(256);
789  fHashGVolumes = new THashList(256);
790  }
791  TObjArray *list = fVolumes;
792  if (!volume->GetShape() || volume->IsRunTime() || volume->IsVolumeMulti()) {
793  list = fGVolumes;
794  fHashGVolumes->Add(volume);
795  } else {
796  fHashVolumes->Add(volume);
797  }
798  Int_t index = list->GetEntriesFast();
799  list->AddAtAndExpand(volume,index);
800  return uid;
801 }
802 
803 ////////////////////////////////////////////////////////////////////////////////
804 /// Add a navigator in the list of navigators. If it is the first one make it
805 /// current navigator.
806 
808 {
809  if (fMultiThread) fgMutex.lock();
810  std::thread::id threadId = std::this_thread::get_id();
811  NavigatorsMap_t::const_iterator it = fNavigators.find(threadId);
812  TGeoNavigatorArray *array = 0;
813  if (it != fNavigators.end()) array = it->second;
814  else {
815  array = new TGeoNavigatorArray(this);
816  fNavigators.insert(NavigatorsMap_t::value_type(threadId, array));
817  }
818  TGeoNavigator *nav = array->AddNavigator();
819  if (fClosed) nav->GetCache()->BuildInfoBranch();
820  if (fMultiThread) fgMutex.unlock();
821  return nav;
822 }
823 
824 ////////////////////////////////////////////////////////////////////////////////
825 /// Returns current navigator for the calling thread.
826 
828 {
829  TTHREAD_TLS(TGeoNavigator*) tnav = 0;
830  if (!fMultiThread) return fCurrentNavigator;
831  TGeoNavigator *nav = tnav; // TTHREAD_TLS_GET(TGeoNavigator*,tnav);
832  if (nav) return nav;
833  std::thread::id threadId = std::this_thread::get_id();
834  NavigatorsMap_t::const_iterator it = fNavigators.find(threadId);
835  if (it == fNavigators.end()) return 0;
836  TGeoNavigatorArray *array = it->second;
837  nav = array->GetCurrentNavigator();
838  tnav = nav; // TTHREAD_TLS_SET(TGeoNavigator*,tnav,nav);
839  return nav;
840 }
841 
842 ////////////////////////////////////////////////////////////////////////////////
843 /// Get list of navigators for the calling thread.
844 
846 {
847  std::thread::id threadId = std::this_thread::get_id();
848  NavigatorsMap_t::const_iterator it = fNavigators.find(threadId);
849  if (it == fNavigators.end()) return 0;
850  TGeoNavigatorArray *array = it->second;
851  return array;
852 }
853 
854 ////////////////////////////////////////////////////////////////////////////////
855 /// Switch to another existing navigator for the calling thread.
856 
858 {
859  std::thread::id threadId = std::this_thread::get_id();
860  NavigatorsMap_t::const_iterator it = fNavigators.find(threadId);
861  if (it == fNavigators.end()) {
862  Error("SetCurrentNavigator", "No navigator defined for this thread\n");
863  std::cout << " thread id: " << threadId << std::endl;
864  return kFALSE;
865  }
866  TGeoNavigatorArray *array = it->second;
867  TGeoNavigator *nav = array->SetCurrentNavigator(index);
868  if (!nav) {
869  Error("SetCurrentNavigator", "Navigator %d not existing for this thread\n", index);
870  std::cout << " thread id: " << threadId << std::endl;
871  return kFALSE;
872  }
873  if (!fMultiThread) fCurrentNavigator = nav;
874  return kTRUE;
875 }
876 
877 ////////////////////////////////////////////////////////////////////////////////
878 /// Set the lock for navigators.
879 
881 {
882  fgLockNavigators = flag;
883 }
884 
885 ////////////////////////////////////////////////////////////////////////////////
886 /// Clear all navigators.
887 
889 {
890  if (fMultiThread) fgMutex.lock();
891  TGeoNavigatorArray *arr = 0;
892  for (NavigatorsMap_t::iterator it = fNavigators.begin();
893  it != fNavigators.end(); it++) {
894  arr = (*it).second;
895  if (arr) delete arr;
896  }
897  fNavigators.clear();
898  if (fMultiThread) fgMutex.unlock();
899 }
900 
901 ////////////////////////////////////////////////////////////////////////////////
902 /// Clear a single navigator.
903 
905 {
906  if (fMultiThread) fgMutex.lock();
907  for (NavigatorsMap_t::iterator it = fNavigators.begin();
908  it != fNavigators.end(); it++) {
909  TGeoNavigatorArray *arr = (*it).second;
910  if (arr) {
911  if ((TGeoNavigator*)arr->Remove((TObject*)nav)) {
912  delete nav;
913  if (!arr->GetEntries()) fNavigators.erase(it);
914  if (fMultiThread) fgMutex.unlock();
915  return;
916  }
917  }
918  }
919  Error("Remove navigator", "Navigator %p not found", nav);
920  if (fMultiThread) fgMutex.unlock();
921 }
922 
923 ////////////////////////////////////////////////////////////////////////////////
924 /// Set maximum number of threads for navigation.
925 
926 void TGeoManager::SetMaxThreads(Int_t nthreads)
927 {
928  if (!fClosed) {
929  Error("SetMaxThreads", "Cannot set maximum number of threads before closing the geometry");
930  return;
931  }
932  if (!fMultiThread) {
934  std::thread::id threadId = std::this_thread::get_id();
935  NavigatorsMap_t::const_iterator it = fNavigators.find(threadId);
936  if (it != fNavigators.end()) {
937  TGeoNavigatorArray *array = it->second;
938  fNavigators.erase(it);
939  fNavigators.insert(NavigatorsMap_t::value_type(threadId, array));
940  }
941  }
942  if (fMaxThreads) {
943  ClearThreadsMap();
944  ClearThreadData();
945  }
946  fMaxThreads = nthreads+1;
947  if (fMaxThreads>0) {
950  }
951 }
952 
953 ////////////////////////////////////////////////////////////////////////////////
954 
955 void TGeoManager::ClearThreadData() const
956 {
957  if (!fMaxThreads) return;
958  fgMutex.lock();
959  TIter next(fVolumes);
960  TGeoVolume *vol;
961  while ((vol=(TGeoVolume*)next())) vol->ClearThreadData();
962  fgMutex.unlock();
963 }
964 
965 ////////////////////////////////////////////////////////////////////////////////
966 /// Create thread private data for all geometry objects.
967 
969 {
970  if (!fMaxThreads) return;
971  fgMutex.lock();
972  TIter next(fVolumes);
973  TGeoVolume *vol;
974  while ((vol=(TGeoVolume*)next())) vol->CreateThreadData(fMaxThreads);
975  fgMutex.unlock();
976 }
977 
978 ////////////////////////////////////////////////////////////////////////////////
979 /// Clear the current map of threads. This will be filled again by the calling
980 /// threads via ThreadId calls.
981 
983 {
984  if (gGeoManager && !gGeoManager->IsMultiThread()) return;
985  fgMutex.lock();
986  if (!fgThreadId->empty()) fgThreadId->clear();
987  fgNumThreads = 0;
988  fgMutex.unlock();
989 }
990 
991 ////////////////////////////////////////////////////////////////////////////////
992 /// Translates the current thread id to an ordinal number. This can be used to
993 /// manage data which is specific for a given thread.
994 
996 {
997  TTHREAD_TLS(Int_t) tid = -1;
998  Int_t ttid = tid; // TTHREAD_TLS_GET(Int_t,tid);
999  if (ttid > -1) return ttid;
1000  if (gGeoManager && !gGeoManager->IsMultiThread()) return 0;
1001  std::thread::id threadId = std::this_thread::get_id();
1002  TGeoManager::ThreadsMapIt_t it = fgThreadId->find(threadId);
1003  if (it != fgThreadId->end()) return it->second;
1004  // Map needs to be updated.
1005  fgMutex.lock();
1006  (*fgThreadId)[threadId] = fgNumThreads;
1007  tid = fgNumThreads; // TTHREAD_TLS_SET(Int_t,tid,fgNumThreads);
1008  ttid = fgNumThreads++;
1009  fgMutex.unlock();
1010  return ttid;
1011 }
1012 
1013 ////////////////////////////////////////////////////////////////////////////////
1014 /// Describe how to browse this object.
1015 
1018  if (!b) return;
1019  if (fMaterials) b->Add(fMaterials, "Materials");
1020  if (fMedia) b->Add(fMedia, "Media");
1021  if (fMatrices) b->Add(fMatrices, "Local transformations");
1022  if (fOverlaps) b->Add(fOverlaps, "Illegal overlaps");
1023  if (fTracks) b->Add(fTracks, "Tracks");
1024  if (fMasterVolume) b->Add(fMasterVolume, "Master Volume", fMasterVolume->IsVisible());
1025  if (fTopVolume) b->Add(fTopVolume, "Top Volume", fTopVolume->IsVisible());
1026  if (fTopNode) b->Add(fTopNode);
1027  TString browserImp(gEnv->GetValue("Browser.Name", "TRootBrowserLite"));
1028  TQObject::Connect(browserImp.Data(), "Checked(TObject*,Bool_t)",
1029  "TGeoManager", this, "SetVisibility(TObject*,Bool_t)");
1030 }
1031 
1032 ////////////////////////////////////////////////////////////////////////////////
1033 /// Append a pad for this geometry.
1034 
1035 void TGeoManager::Edit(Option_t *option) {
1037  GetGeomPainter()->EditGeometry(option);
1038 }
1039 
1040 ////////////////////////////////////////////////////////////////////////////////
1041 /// Set visibility for a volume.
1042 
1045  if(obj->IsA() == TGeoVolume::Class()) {
1046  TGeoVolume *vol = (TGeoVolume *) obj;
1047  vol->SetVisibility(vis);
1048  } else {
1049  if (obj->InheritsFrom(TGeoNode::Class())) {
1050  TGeoNode *node = (TGeoNode *) obj;
1051  node->SetVisibility(vis);
1052  } else return;
1053  }
1055 }
1056 
1057 ////////////////////////////////////////////////////////////////////////////////
1058 /// Get the new 'bombed' translation vector according current exploded view mode.
1059 
1060 void TGeoManager::BombTranslation(const Double_t *tr, Double_t *bombtr)
1062  if (fPainter) fPainter->BombTranslation(tr, bombtr);
1063  return;
1064 }
1065 
1066 ////////////////////////////////////////////////////////////////////////////////
1067 /// Get the new 'unbombed' translation vector according current exploded view mode.
1068 
1069 void TGeoManager::UnbombTranslation(const Double_t *tr, Double_t *bombtr)
1071  if (fPainter) fPainter->UnbombTranslation(tr, bombtr);
1072  return;
1073 }
1074 
1075 ////////////////////////////////////////////////////////////////////////////////
1076 /// Backup the current state without affecting the cache stack.
1077 
1081 }
1082 
1083 ////////////////////////////////////////////////////////////////////////////////
1084 /// Restore a backed-up state without affecting the cache stack.
1085 
1089 }
1090 
1091 ////////////////////////////////////////////////////////////////////////////////
1092 /// Register a matrix to the list of matrices. It will be cleaned-up at the
1093 /// destruction TGeoManager.
1094 
1095 void TGeoManager::RegisterMatrix(const TGeoMatrix *matrix)
1097  return TGeoBuilder::Instance(this)->RegisterMatrix((TGeoMatrix*)matrix);
1098 }
1099 
1100 ////////////////////////////////////////////////////////////////////////////////
1101 /// Replaces all occurrences of VORIG with VNEW in the geometry tree. The volume VORIG
1102 /// is not replaced from the list of volumes, but all node referencing it will reference
1103 /// VNEW instead. Returns number of occurrences changed.
1104 
1107  Int_t nref = 0;
1108  if (!vorig || !vnew) return nref;
1109  TGeoMedium *morig = vorig->GetMedium();
1110  Bool_t checkmed = kFALSE;
1111  if (morig) checkmed = kTRUE;
1112  TGeoMedium *mnew = vnew->GetMedium();
1113  // Try to limit the damage produced by incorrect usage.
1114  if (!mnew && !vnew->IsAssembly()) {
1115  Error("ReplaceVolume","Replacement volume %s has no medium and it is not an assembly",
1116  vnew->GetName());
1117  return nref;
1118  }
1119  if (mnew && checkmed) {
1120  if (mnew->GetId() != morig->GetId())
1121  Warning("ReplaceVolume","Replacement volume %s has different medium than original volume %s",
1122  vnew->GetName(), vorig->GetName());
1123  checkmed = kFALSE;
1124  }
1125 
1126  // Medium checking now performed only if replacement is an assembly and old volume a real one.
1127  // Check result is dependent on positioning.
1128  Int_t nvol = fVolumes->GetEntriesFast();
1129  Int_t i,j,nd;
1130  Int_t ierr = 0;
1131  TGeoVolume *vol;
1132  TGeoNode *node;
1133  TGeoVoxelFinder *voxels;
1134  for (i=0; i<nvol; i++) {
1135  vol = (TGeoVolume*)fVolumes->At(i);
1136  if (!vol) continue;
1137  if (vol==vorig || vol==vnew) continue;
1138  nd = vol->GetNdaughters();
1139  for (j=0; j<nd; j++) {
1140  node = vol->GetNode(j);
1141  if (node->GetVolume() == vorig) {
1142  if (checkmed) {
1143  mnew = node->GetMotherVolume()->GetMedium();
1144  if (mnew && mnew->GetId()!=morig->GetId()) ierr++;
1145  }
1146  nref++;
1147  if (node->IsOverlapping()) {
1148  node->SetOverlapping(kFALSE);
1149  Info("ReplaceVolume","%s replaced with assembly and declared NON-OVERLAPPING!",node->GetName());
1150  }
1151  node->SetVolume(vnew);
1152  voxels = node->GetMotherVolume()->GetVoxels();
1153  if (voxels) voxels->SetNeedRebuild();
1154  } else {
1155  if (node->GetMotherVolume() == vorig) {
1156  nref++;
1157  node->SetMotherVolume(vnew);
1158  if (node->IsOverlapping()) {
1159  node->SetOverlapping(kFALSE);
1160  Info("ReplaceVolume","%s inside substitute assembly %s declared NON-OVERLAPPING!",node->GetName(),vnew->GetName());
1161  }
1162  }
1163  }
1164  }
1165  }
1166  if (ierr) Warning("ReplaceVolume", "Volumes should not be replaced with assemblies if they are positioned in containers having a different medium ID.\n %i occurrences for assembly replacing volume %s",
1167  ierr, vorig->GetName());
1168  return nref;
1169 }
1170 
1171 ////////////////////////////////////////////////////////////////////////////////
1172 /// Transform all volumes named VNAME to assemblies. The volumes must be virtual.
1173 
1176  TGeoVolume *toTransform = FindVolumeFast(vname);
1177  if (!toTransform) {
1178  Warning("TransformVolumeToAssembly", "Volume %s not found", vname);
1179  return 0;
1180  }
1181  Int_t index = fVolumes->IndexOf(toTransform);
1182  Int_t count = 0;
1183  Int_t indmax = fVolumes->GetEntries();
1184  Bool_t replace = kTRUE;
1185  TGeoVolume *transformed;
1186  while (index<indmax) {
1187  if (replace) {
1188  replace = kFALSE;
1189  transformed = TGeoVolumeAssembly::MakeAssemblyFromVolume(toTransform);
1190  if (transformed) {
1191  ReplaceVolume(toTransform, transformed);
1192  count++;
1193  } else {
1194  if (toTransform->IsAssembly())
1195  Warning("TransformVolumeToAssembly", "Volume %s already assembly", toTransform->GetName());
1196  if (!toTransform->GetNdaughters())
1197  Warning("TransformVolumeToAssembly", "Volume %s has no daughters, cannot transform", toTransform->GetName());
1198  if (toTransform->IsVolumeMulti())
1199  Warning("TransformVolumeToAssembly", "Volume %s divided, cannot transform", toTransform->GetName());
1200  }
1201  }
1202  index++;
1203  if (index >= indmax) return count;
1204  toTransform = (TGeoVolume*)fVolumes->At(index);
1205  if (!strcmp(toTransform->GetName(),vname)) replace = kTRUE;
1206  }
1207  return count;
1208 }
1209 
1210 ////////////////////////////////////////////////////////////////////////////////
1211 /// Create a new volume by dividing an existing one (GEANT3 like)
1212 ///
1213 /// Divides MOTHER into NDIV divisions called NAME
1214 /// along axis IAXIS starting at coordinate value START
1215 /// and having size STEP. The created volumes will have tracking
1216 /// media ID=NUMED (if NUMED=0 -> same media as MOTHER)
1217 /// The behavior of the division operation can be triggered using OPTION :
1218 ///
1219 /// OPTION (case insensitive) :
1220 /// - N - divide all range in NDIV cells (same effect as STEP<=0) (GSDVN in G3)
1221 /// - NX - divide range starting with START in NDIV cells (GSDVN2 in G3)
1222 /// - S - divide all range with given STEP. NDIV is computed and divisions will be centered
1223 /// in full range (same effect as NDIV<=0) (GSDVS, GSDVT in G3)
1224 /// - SX - same as DVS, but from START position. (GSDVS2, GSDVT2 in G3)
1225 
1226 TGeoVolume *TGeoManager::Division(const char *name, const char *mother, Int_t iaxis,
1227  Int_t ndiv, Double_t start, Double_t step, Int_t numed, Option_t *option)
1228 {
1229  return TGeoBuilder::Instance(this)->Division(name, mother, iaxis, ndiv, start, step, numed, option);
1230 }
1231 
1232 ////////////////////////////////////////////////////////////////////////////////
1233 /// Create rotation matrix named 'mat<index>'.
1234 ///
1235 /// - index rotation matrix number
1236 /// - theta1 polar angle for axis X
1237 /// - phi1 azimuthal angle for axis X
1238 /// - theta2 polar angle for axis Y
1239 /// - phi2 azimuthal angle for axis Y
1240 /// - theta3 polar angle for axis Z
1241 /// - phi3 azimuthal angle for axis Z
1242 ///
1243 
1244 void TGeoManager::Matrix(Int_t index, Double_t theta1, Double_t phi1,
1245  Double_t theta2, Double_t phi2,
1246  Double_t theta3, Double_t phi3)
1247 {
1248  TGeoBuilder::Instance(this)->Matrix(index, theta1, phi1, theta2, phi2, theta3, phi3);
1249 }
1250 
1251 ////////////////////////////////////////////////////////////////////////////////
1252 /// Create material with given A, Z and density, having an unique id.
1253 
1254 TGeoMaterial *TGeoManager::Material(const char *name, Double_t a, Double_t z, Double_t dens, Int_t uid,Double_t radlen, Double_t intlen)
1256  return TGeoBuilder::Instance(this)->Material(name, a, z, dens, uid, radlen, intlen);
1257 
1258 }
1259 
1260 ////////////////////////////////////////////////////////////////////////////////
1261 /// Create mixture OR COMPOUND IMAT as composed by THE BASIC nelem
1262 /// materials defined by arrays A,Z and WMAT, having an unique id.
1263 
1265  Int_t nelem, Float_t *wmat, Int_t uid)
1266 {
1267  return TGeoBuilder::Instance(this)->Mixture(name, a, z, dens, nelem, wmat, uid);
1268 }
1269 
1270 ////////////////////////////////////////////////////////////////////////////////
1271 /// Create mixture OR COMPOUND IMAT as composed by THE BASIC nelem
1272 /// materials defined by arrays A,Z and WMAT, having an unique id.
1273 
1275  Int_t nelem, Double_t *wmat, Int_t uid)
1276 {
1277  return TGeoBuilder::Instance(this)->Mixture(name, a, z, dens, nelem, wmat, uid);
1278 }
1279 
1280 ////////////////////////////////////////////////////////////////////////////////
1281 /// Create tracking medium
1282 ///
1283 /// - numed tracking medium number assigned
1284 /// - name tracking medium name
1285 /// - nmat material number
1286 /// - isvol sensitive volume flag
1287 /// - ifield magnetic field
1288 /// - fieldm max. field value (kilogauss)
1289 /// - tmaxfd max. angle due to field (deg/step)
1290 /// - stemax max. step allowed
1291 /// - deemax max. fraction of energy lost in a step
1292 /// - epsil tracking precision (cm)
1293 /// - stmin min. step due to continuous processes (cm)
1294 ///
1295 /// - ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
1296 /// - ifield = 1 if tracking performed with g3rkuta; ifield = 2 if tracking
1297 /// performed with g3helix; ifield = 3 if tracking performed with g3helx3.
1298 ///
1299 
1300 TGeoMedium *TGeoManager::Medium(const char *name, Int_t numed, Int_t nmat, Int_t isvol,
1301  Int_t ifield, Double_t fieldm, Double_t tmaxfd,
1302  Double_t stemax, Double_t deemax, Double_t epsil,
1303  Double_t stmin)
1304 {
1305  return TGeoBuilder::Instance(this)->Medium(name, numed, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
1306 }
1307 
1308 ////////////////////////////////////////////////////////////////////////////////
1309 /// Create a node called <name_nr> pointing to the volume called <name>
1310 /// as daughter of the volume called <mother> (gspos). The relative matrix is
1311 /// made of : a translation (x,y,z) and a rotation matrix named <matIROT>.
1312 /// In case npar>0, create the volume to be positioned in mother, according
1313 /// its actual parameters (gsposp).
1314 /// - NAME Volume name
1315 /// - NUMBER Copy number of the volume
1316 /// - MOTHER Mother volume name
1317 /// - X X coord. of the volume in mother ref. sys.
1318 /// - Y Y coord. of the volume in mother ref. sys.
1319 /// - Z Z coord. of the volume in mother ref. sys.
1320 /// - IROT Rotation matrix number w.r.t. mother ref. sys.
1321 /// - ISONLY ONLY/MANY flag
1322 
1323 void TGeoManager::Node(const char *name, Int_t nr, const char *mother,
1325  Bool_t isOnly, Float_t *upar, Int_t npar)
1326 {
1327  TGeoBuilder::Instance(this)->Node(name, nr, mother, x, y, z, irot, isOnly, upar, npar);
1328 }
1329 
1330 ////////////////////////////////////////////////////////////////////////////////
1331 /// Create a node called <name_nr> pointing to the volume called <name>
1332 /// as daughter of the volume called <mother> (gspos). The relative matrix is
1333 /// made of : a translation (x,y,z) and a rotation matrix named <matIROT>.
1334 /// In case npar>0, create the volume to be positioned in mother, according
1335 /// its actual parameters (gsposp).
1336 /// - NAME Volume name
1337 /// - NUMBER Copy number of the volume
1338 /// - MOTHER Mother volume name
1339 /// - X X coord. of the volume in mother ref. sys.
1340 /// - Y Y coord. of the volume in mother ref. sys.
1341 /// - Z Z coord. of the volume in mother ref. sys.
1342 /// - IROT Rotation matrix number w.r.t. mother ref. sys.
1343 /// - ISONLY ONLY/MANY flag
1344 
1345 void TGeoManager::Node(const char *name, Int_t nr, const char *mother,
1347  Bool_t isOnly, Double_t *upar, Int_t npar)
1348 {
1349  TGeoBuilder::Instance(this)->Node(name, nr, mother, x, y, z, irot, isOnly, upar, npar);
1350 
1351 }
1352 
1353 ////////////////////////////////////////////////////////////////////////////////
1354 /// Create a volume in GEANT3 style.
1355 /// - NAME Volume name
1356 /// - SHAPE Volume type
1357 /// - NMED Tracking medium number
1358 /// - NPAR Number of shape parameters
1359 /// - UPAR Vector containing shape parameters
1360 
1361 TGeoVolume *TGeoManager::Volume(const char *name, const char *shape, Int_t nmed,
1362  Float_t *upar, Int_t npar)
1363 {
1364  return TGeoBuilder::Instance(this)->Volume(name, shape, nmed, upar, npar);
1365 }
1366 
1367 ////////////////////////////////////////////////////////////////////////////////
1368 /// Create a volume in GEANT3 style.
1369 /// - NAME Volume name
1370 /// - SHAPE Volume type
1371 /// - NMED Tracking medium number
1372 /// - NPAR Number of shape parameters
1373 /// - UPAR Vector containing shape parameters
1374 
1375 TGeoVolume *TGeoManager::Volume(const char *name, const char *shape, Int_t nmed,
1376  Double_t *upar, Int_t npar)
1377 {
1378  return TGeoBuilder::Instance(this)->Volume(name, shape, nmed, upar, npar);
1379 }
1380 
1381 ////////////////////////////////////////////////////////////////////////////////
1382 /// Assigns uid's for all materials,media and matrices.
1383 
1386  Int_t index = 1;
1387  TIter next(fMaterials);
1388  TGeoMaterial *mater;
1389  while ((mater=(TGeoMaterial*)next())) {
1390  mater->SetUniqueID(index++);
1392  }
1393  index = 1;
1394  TIter next1(fMedia);
1395  TGeoMedium *med;
1396  while ((med=(TGeoMedium*)next1())) {
1397  med->SetUniqueID(index++);
1399  }
1400  index = 1;
1401  TIter next2(fShapes);
1402  TGeoShape *shape;
1403  while ((shape=(TGeoShape*)next2())) {
1404  shape->SetUniqueID(index++);
1405  if (shape->IsComposite()) ((TGeoCompositeShape*)shape)->GetBoolNode()->RegisterMatrices();
1406  }
1407 
1408  TIter next3(fMatrices);
1409  TGeoMatrix *matrix;
1410  while ((matrix=(TGeoMatrix*)next3())) {
1411  matrix->RegisterYourself();
1412  }
1413  TIter next4(fMatrices);
1414  index = 1;
1415  while ((matrix=(TGeoMatrix*)next4())) {
1416  matrix->SetUniqueID(index++);
1418  }
1419  TIter next5(fVolumes);
1420  TGeoVolume *vol;
1421  while ((vol=(TGeoVolume*)next5())) vol->UnmarkSaved();
1422 }
1423 
1424 ////////////////////////////////////////////////////////////////////////////////
1425 /// Reset all attributes to default ones. Default attributes for visualization
1426 /// are those defined before closing the geometry.
1427 
1430  if (gPad) delete gPad;
1431  gPad = 0;
1432  SetVisOption(0);
1433  SetVisLevel(3);
1434  SetExplodedView(0);
1435  SetBombFactors();
1436  if (!gStyle) return;
1437  TIter next(fVolumes);
1438  TGeoVolume *vol = 0;
1439  while ((vol=(TGeoVolume*)next())) {
1440  if (!vol->IsVisTouched()) continue;
1441  vol->SetVisTouched(kFALSE);
1442  }
1443 }
1444 ////////////////////////////////////////////////////////////////////////////////
1445 /// Closing geometry implies checking the geometry validity, fixing shapes
1446 /// with negative parameters (run-time shapes)building the cache manager,
1447 /// voxelizing all volumes, counting the total number of physical nodes and
1448 /// registering the manager class to the browser.
1449 
1452  if (fClosed) {
1453  Warning("CloseGeometry", "geometry already closed");
1454  return;
1455  }
1456  if (!fMasterVolume) {
1457  Error("CloseGeometry","you MUST call SetTopVolume() first !");
1458  return;
1459  }
1460  if (!gROOT->GetListOfGeometries()->FindObject(this)) gROOT->GetListOfGeometries()->Add(this);
1461  if (!gROOT->GetListOfBrowsables()->FindObject(this)) gROOT->GetListOfBrowsables()->Add(this);
1462 // TSeqCollection *brlist = gROOT->GetListOfBrowsers();
1463 // TIter next(brlist);
1464 // TBrowser *browser = 0;
1465 // while ((browser=(TBrowser*)next())) browser->Refresh();
1466  TString opt(option);
1467  opt.ToLower();
1468 // Bool_t dummy = opt.Contains("d");
1469  Bool_t nodeid = opt.Contains("i");
1470  // Create a geometry navigator if not present
1471  TGeoNavigator *nav = 0;
1472  Int_t nnavigators = 0;
1473  // Check if the geometry is streamed from file
1474  if (fIsGeomReading) {
1475  if (fgVerboseLevel>0) Info("CloseGeometry","Geometry loaded from file...");
1477  if (!fElementTable) fElementTable = new TGeoElementTable(200);
1478  if (!fTopNode) {
1479  if (!fMasterVolume) {
1480  Error("CloseGeometry", "Master volume not streamed");
1481  return;
1482  }
1484  if (fStreamVoxels && fgVerboseLevel>0) Info("CloseGeometry","Voxelization retrieved from file");
1485  }
1486  // Create a geometry navigator if not present
1488  nnavigators = GetListOfNavigators()->GetEntriesFast();
1489  TIter next(fShapes);
1490  TGeoShape *shape;
1491  while ((shape = (TGeoShape*)next())) shape->AfterStreamer();
1492  Voxelize("ALL");
1493  CountLevels();
1494  for (Int_t i=0; i<nnavigators; i++) {
1495  nav = (TGeoNavigator*)GetListOfNavigators()->At(i);
1496  nav->GetCache()->BuildInfoBranch();
1497  if (nodeid) nav->GetCache()->BuildIdArray();
1498  }
1499  if (!fHashVolumes) {
1500  Int_t nvol = fVolumes->GetEntriesFast();
1501  Int_t ngvol = fGVolumes->GetEntriesFast();
1502  fHashVolumes = new THashList(nvol+1);
1503  fHashGVolumes = new THashList(ngvol+1);
1504  Int_t i;
1505  for (i=0; i<ngvol; i++) fHashGVolumes->AddLast(fGVolumes->At(i));
1506  for (i=0; i<nvol; i++) fHashVolumes->AddLast(fVolumes->At(i));
1507  }
1508  fClosed = kTRUE;
1509  if (fParallelWorld) {
1510  if (fgVerboseLevel>0) Info("CloseGeometry","Recreating parallel world %s ...",fParallelWorld->GetName());
1512  }
1513 
1514  if (fgVerboseLevel>0) Info("CloseGeometry","%i nodes/ %i volume UID's in %s", fNNodes, fUniqueVolumes->GetEntriesFast()-1, GetTitle());
1515  if (fgVerboseLevel>0) Info("CloseGeometry","----------------modeler ready----------------");
1516  return;
1517  }
1518 
1519  // Create a geometry navigator if not present
1521  nnavigators = GetListOfNavigators()->GetEntriesFast();
1523  CheckGeometry();
1524  if (fgVerboseLevel>0) Info("CloseGeometry","Counting nodes...");
1525  fNNodes = CountNodes();
1526  fNLevel = fMasterVolume->CountNodes(1,3)+1;
1527  if (fNLevel<30) fNLevel = 100;
1528 
1529 // BuildIdArray();
1530  Voxelize("ALL");
1531  if (fgVerboseLevel>0) Info("CloseGeometry","Building cache...");
1532  CountLevels();
1533  for (Int_t i=0; i<nnavigators; i++) {
1534  nav = (TGeoNavigator*)GetListOfNavigators()->At(i);
1535  nav->GetCache()->BuildInfoBranch();
1536  if (nodeid) nav->GetCache()->BuildIdArray();
1537  }
1538  fClosed = kTRUE;
1539  if (fgVerboseLevel>0) {
1540  Info("CloseGeometry","%i nodes/ %i volume UID's in %s", fNNodes, fUniqueVolumes->GetEntriesFast()-1, GetTitle());
1541  Info("CloseGeometry","----------------modeler ready----------------");
1542  }
1543 }
1544 
1545 ////////////////////////////////////////////////////////////////////////////////
1546 /// Clear the list of overlaps.
1547 
1550  if (fOverlaps) {
1551  fOverlaps->Delete();
1552  delete fOverlaps;
1553  }
1554  fOverlaps = new TObjArray();
1555 }
1556 
1557 ////////////////////////////////////////////////////////////////////////////////
1558 /// Remove a shape from the list of shapes.
1559 
1560 void TGeoManager::ClearShape(const TGeoShape *shape)
1562  if (fShapes->FindObject(shape)) fShapes->Remove((TGeoShape*)shape);
1563  delete shape;
1564 }
1565 
1566 ////////////////////////////////////////////////////////////////////////////////
1567 /// Clean temporary volumes and shapes from garbage collection.
1568 
1571  if (!fGVolumes && !fGShapes) return;
1572  Int_t i,nentries;
1573  if (fGVolumes) {
1574  nentries = fGVolumes->GetEntries();
1575  TGeoVolume *vol = 0;
1576  for (i=0; i<nentries; i++) {
1577  vol=(TGeoVolume*)fGVolumes->At(i);
1578  if (vol) vol->SetFinder(0);
1579  }
1580  fGVolumes->Delete();
1581  delete fGVolumes;
1582  fGVolumes = 0;
1583  }
1584  if (fGShapes) {
1585  fGShapes->Delete();
1586  delete fGShapes;
1587  fGShapes = 0;
1588  }
1589 }
1590 
1591 ////////////////////////////////////////////////////////////////////////////////
1592 /// Change current path to point to the node having this id.
1593 /// Node id has to be in range : 0 to fNNodes-1 (no check for performance reasons)
1594 
1595 void TGeoManager::CdNode(Int_t nodeid)
1597  GetCurrentNavigator()->CdNode(nodeid);
1598 }
1599 
1600 ////////////////////////////////////////////////////////////////////////////////
1601 /// Get the unique ID of the current node.
1602 
1606 }
1607 
1608 ////////////////////////////////////////////////////////////////////////////////
1609 /// Make top level node the current node. Updates the cache accordingly.
1610 /// Determine the overlapping state of current node.
1611 
1612 void TGeoManager::CdTop()
1615 }
1616 
1617 ////////////////////////////////////////////////////////////////////////////////
1618 /// Go one level up in geometry. Updates cache accordingly.
1619 /// Determine the overlapping state of current node.
1620 
1621 void TGeoManager::CdUp()
1624 }
1625 
1626 ////////////////////////////////////////////////////////////////////////////////
1627 /// Make a daughter of current node current. Can be called only with a valid
1628 /// daughter index (no check). Updates cache accordingly.
1629 
1630 void TGeoManager::CdDown(Int_t index)
1632  GetCurrentNavigator()->CdDown(index);
1633 }
1634 
1635 ////////////////////////////////////////////////////////////////////////////////
1636 /// Do a cd to the node found next by FindNextBoundary
1637 
1638 void TGeoManager::CdNext()
1641 }
1642 
1643 ////////////////////////////////////////////////////////////////////////////////
1644 /// Browse the tree of nodes starting from fTopNode according to pathname.
1645 /// Changes the path accordingly.
1646 
1647 Bool_t TGeoManager::cd(const char *path)
1649  return GetCurrentNavigator()->cd(path);
1650 }
1651 
1652 ////////////////////////////////////////////////////////////////////////////////
1653 /// Check if a geometry path is valid without changing the state of the current navigator.
1654 
1655 Bool_t TGeoManager::CheckPath(const char *path) const
1657  return GetCurrentNavigator()->CheckPath(path);
1658 }
1659 
1660 ////////////////////////////////////////////////////////////////////////////////
1661 /// Convert all reflections in geometry to normal rotations + reflected shapes.
1662 
1665  if (!fTopNode) return;
1666  if (fgVerboseLevel>0) Info("ConvertReflections", "Converting reflections in: %s - %s ...", GetName(), GetTitle());
1667  TGeoIterator next(fTopVolume);
1668  TGeoNode *node;
1669  TGeoNodeMatrix *nodematrix;
1670  TGeoMatrix *matrix, *mclone;
1671  TGeoVolume *reflected;
1672  while ((node=next())) {
1673  matrix = node->GetMatrix();
1674  if (matrix->IsReflection()) {
1675 // printf("%s before\n", node->GetName());
1676 // matrix->Print();
1677  mclone = new TGeoCombiTrans(*matrix);
1678  mclone->RegisterYourself();
1679  // Reflect just the rotation component
1680  mclone->ReflectZ(kFALSE, kTRUE);
1681  nodematrix = (TGeoNodeMatrix*)node;
1682  nodematrix->SetMatrix(mclone);
1683 // printf("%s after\n", node->GetName());
1684 // node->GetMatrix()->Print();
1685  reflected = node->GetVolume()->MakeReflectedVolume();
1686  node->SetVolume(reflected);
1687  }
1688  }
1689  if (fgVerboseLevel>0) Info("ConvertReflections", "Done");
1690 }
1691 
1692 ////////////////////////////////////////////////////////////////////////////////
1693 /// Count maximum number of nodes per volume, maximum depth and maximum
1694 /// number of xtru vertices.
1695 
1698  if (!fTopNode) {
1699  Error("CountLevels", "Top node not defined.");
1700  return;
1701  }
1702  TGeoIterator next(fTopVolume);
1703  Bool_t fixrefs = fIsGeomReading && (fMasterVolume->GetRefCount()==1);
1705  if (fgVerboseLevel>1 && fixrefs) Info("CountLevels", "Fixing volume reference counts");
1706  TGeoNode *node;
1707  Int_t maxlevel = 1;
1708  Int_t maxnodes = fTopVolume->GetNdaughters();
1709  Int_t maxvertices = 1;
1710  while ((node=next())) {
1711  if (fixrefs) {
1712  node->GetVolume()->Grab();
1713  for (Int_t ibit=10; ibit<14; ibit++) {
1714  node->SetBit(BIT(ibit+4), node->TestBit(BIT(ibit)));
1715 // node->ResetBit(BIT(ibit)); // cannot overwrite old crap for reproducibility
1716  }
1717  }
1718  if (node->GetVolume()->GetVoxels()) {
1719  if (node->GetNdaughters()>maxnodes) maxnodes = node->GetNdaughters();
1720  }
1721  if (next.GetLevel()>maxlevel) maxlevel = next.GetLevel();
1722  if (node->GetVolume()->GetShape()->IsA()==TGeoXtru::Class()) {
1723  TGeoXtru *xtru = (TGeoXtru*)node->GetVolume()->GetShape();
1724  if (xtru->GetNvert()>maxvertices) maxvertices = xtru->GetNvert();
1725  }
1726  }
1727  fgMaxLevel = maxlevel;
1728  fgMaxDaughters = maxnodes;
1729  fgMaxXtruVert = maxvertices;
1730  if (fgVerboseLevel>0) Info("CountLevels", "max level = %d, max placements = %d", fgMaxLevel, fgMaxDaughters);
1731 }
1732 
1733 ////////////////////////////////////////////////////////////////////////////////
1734 /// Count the total number of nodes starting from a volume, nlevels down.
1735 
1736 Int_t TGeoManager::CountNodes(const TGeoVolume *vol, Int_t nlevels, Int_t option)
1738  TGeoVolume *top;
1739  if (!vol) {
1740  top = fTopVolume;
1741  } else {
1742  top = (TGeoVolume*)vol;
1743  }
1744  Int_t count = top->CountNodes(nlevels, option);
1745  return count;
1746 }
1747 
1748 ////////////////////////////////////////////////////////////////////////////////
1749 /// Set default angles for a given view.
1750 
1754 }
1755 
1756 ////////////////////////////////////////////////////////////////////////////////
1757 /// Draw current point in the same view.
1758 
1761  if (fPainter) fPainter->DrawCurrentPoint(color);
1762 }
1763 
1764 ////////////////////////////////////////////////////////////////////////////////
1765 /// Draw animation of tracks
1766 
1767 void TGeoManager::AnimateTracks(Double_t tmin, Double_t tmax, Int_t nframes, Option_t *option)
1769  SetAnimateTracks();
1770  GetGeomPainter();
1771  if (tmin<0 || tmin>=tmax || nframes<1) return;
1773  box[0] = box[1] = box[2] = 0;
1774  box[3] = box[4] = box[5] = 100;
1775  Double_t dt = (tmax-tmin)/Double_t(nframes);
1776  Double_t delt = 2E-9;
1777  Double_t t = tmin;
1778  Int_t i, j;
1779  TString opt(option);
1780  Bool_t save = kFALSE, geomanim=kFALSE;
1781  TString fname;
1782  if (opt.Contains("/S")) save = kTRUE;
1783 
1784  if (opt.Contains("/G")) geomanim = kTRUE;
1785  SetTminTmax(0,0);
1786  DrawTracks(opt.Data());
1787  Double_t start[6], end[6];
1788  Double_t dd[6] = {0,0,0,0,0,0};
1789  Double_t dlat=0, dlong=0, dpsi=0;
1790  if (geomanim) {
1791  fPainter->EstimateCameraMove(tmin+5*dt, tmin+15*dt, start, end);
1792  for (i=0; i<3; i++) {
1793  start[i+3] = 20 + 1.3*start[i+3];
1794  end[i+3] = 20 + 0.9*end[i+3];
1795  }
1796  for (i=0; i<6; i++) {
1797  dd[i] = (end[i]-start[i])/10.;
1798  }
1799  memcpy(box, start, 6*sizeof(Double_t));
1800  fPainter->GetViewAngles(dlong,dlat,dpsi);
1801  dlong = (-206-dlong)/Double_t(nframes);
1802  dlat = (126-dlat)/Double_t(nframes);
1803  dpsi = (75-dpsi)/Double_t(nframes);
1804  fPainter->GrabFocus();
1805  }
1806 
1807  for (i=0; i<nframes; i++) {
1808  if (t-delt<0) SetTminTmax(t-delt,t);
1809  else gGeoManager->SetTminTmax(t-delt,t);
1810  if (geomanim) {
1811  for (j=0; j<6; j++) box[j]+=dd[j];
1812  fPainter->GrabFocus(1,dlong,dlat,dpsi);
1813  } else {
1814  ModifiedPad();
1815  }
1816  if (save) {
1817  fname = TString::Format("anim%04d.gif", i);
1818  gPad->Print(fname);
1819  }
1820  t += dt;
1821  }
1823 }
1824 
1825 ////////////////////////////////////////////////////////////////////////////////
1826 /// Draw tracks over the geometry, according to option. By default, only
1827 /// primaries are drawn. See TGeoTrack::Draw() for additional options.
1828 
1829 void TGeoManager::DrawTracks(Option_t *option)
1831  TVirtualGeoTrack *track;
1832  //SetVisLevel(1);
1833  //SetVisOption(1);
1834  SetAnimateTracks();
1835  for (Int_t i=0; i<fNtracks; i++) {
1836  track = GetTrack(i);
1837  if (track) track->Draw(option);
1838  }
1840  ModifiedPad();
1841 }
1842 
1843 ////////////////////////////////////////////////////////////////////////////////
1844 /// Draw current path
1845 
1846 void TGeoManager::DrawPath(const char *path, Option_t *option)
1848  if (!fTopVolume) return;
1850  GetGeomPainter()->DrawPath(path, option);
1851 }
1852 
1853 ////////////////////////////////////////////////////////////////////////////////
1854 /// Draw random points in the bounding box of a volume.
1855 
1856 void TGeoManager::RandomPoints(const TGeoVolume *vol, Int_t npoints, Option_t *option)
1858  GetGeomPainter()->RandomPoints((TGeoVolume*)vol, npoints, option);
1859 }
1860 
1861 ////////////////////////////////////////////////////////////////////////////////
1862 /// Check time of finding "Where am I" for n points.
1863 
1864 void TGeoManager::Test(Int_t npoints, Option_t *option)
1866  GetGeomPainter()->Test(npoints, option);
1867 }
1868 
1869 ////////////////////////////////////////////////////////////////////////////////
1870 /// Geometry overlap checker based on sampling.
1871 
1872 void TGeoManager::TestOverlaps(const char* path)
1874  GetGeomPainter()->TestOverlaps(path);
1875 }
1876 
1877 ////////////////////////////////////////////////////////////////////////////////
1878 /// Fill volume names of current branch into an array.
1879 
1880 void TGeoManager::GetBranchNames(Int_t *names) const
1883 }
1884 
1885 ////////////////////////////////////////////////////////////////////////////////
1886 /// Get name for given pdg code;
1887 
1888 const char *TGeoManager::GetPdgName(Int_t pdg) const
1890  static char defaultname[5] = { "XXX" };
1891  if (!fPdgNames || !pdg) return defaultname;
1892  for (Int_t i=0; i<fNpdg; i++) {
1893  if (fPdgId[i]==pdg) return fPdgNames->At(i)->GetName();
1894  }
1895  return defaultname;
1896 }
1897 
1898 ////////////////////////////////////////////////////////////////////////////////
1899 /// Set a name for a particle having a given pdg.
1900 
1901 void TGeoManager::SetPdgName(Int_t pdg, const char *name)
1903  if (!pdg) return;
1904  if (!fPdgNames) {
1905  fPdgNames = new TObjArray(1024);
1906  }
1907  if (!strcmp(name, GetPdgName(pdg))) return;
1908  // store pdg name
1909  if (fNpdg>1023) {
1910  Warning("SetPdgName", "No more than 256 different pdg codes allowed");
1911  return;
1912  }
1913  fPdgId[fNpdg] = pdg;
1914  TNamed *pdgname = new TNamed(name, "");
1915  fPdgNames->AddAtAndExpand(pdgname, fNpdg++);
1916 }
1917 
1918 ////////////////////////////////////////////////////////////////////////////////
1919 /// Fill node copy numbers of current branch into an array.
1920 
1921 void TGeoManager::GetBranchNumbers(Int_t *copyNumbers, Int_t *volumeNumbers) const
1923  GetCurrentNavigator()->GetBranchNumbers(copyNumbers, volumeNumbers);
1924 }
1925 
1926 ////////////////////////////////////////////////////////////////////////////////
1927 /// Fill node copy numbers of current branch into an array.
1928 
1929 void TGeoManager::GetBranchOnlys(Int_t *isonly) const
1932 }
1933 
1934 ////////////////////////////////////////////////////////////////////////////////
1935 /// Retrieve cartesian and radial bomb factors.
1936 
1937 void TGeoManager::GetBombFactors(Double_t &bombx, Double_t &bomby, Double_t &bombz, Double_t &bombr) const
1939  if (fPainter) {
1940  fPainter->GetBombFactors(bombx, bomby, bombz, bombr);
1941  return;
1942  }
1943  bombx = bomby = bombz = bombr = 1.3;
1944 }
1945 
1946 ////////////////////////////////////////////////////////////////////////////////
1947 /// Return maximum number of daughters of a volume used in the geometry.
1948 
1951  return fgMaxDaughters;
1952 }
1953 
1954 ////////////////////////////////////////////////////////////////////////////////
1955 /// Return maximum number of levels used in the geometry.
1956 
1959  return fgMaxLevel;
1960 }
1961 
1962 ////////////////////////////////////////////////////////////////////////////////
1963 /// Return maximum number of vertices for an xtru shape used.
1964 
1967  return fgMaxXtruVert;
1968 }
1969 
1970 ////////////////////////////////////////////////////////////////////////////////
1971 /// Returns number of threads that were set to use geometry.
1972 
1975  return fgNumThreads;
1976 }
1977 
1978 ////////////////////////////////////////////////////////////////////////////////
1979 /// Return stored current matrix (global matrix of the next touched node).
1980 
1983  if (!GetCurrentNavigator()) return NULL;
1984  return GetCurrentNavigator()->GetHMatrix();
1985 }
1986 
1987 ////////////////////////////////////////////////////////////////////////////////
1988 /// Returns current depth to which geometry is drawn.
1989 
1992  return fVisLevel;
1993 }
1994 
1995 ////////////////////////////////////////////////////////////////////////////////
1996 /// Returns current depth to which geometry is drawn.
1997 
2000  return fVisOption;
2001 }
2002 
2003 ////////////////////////////////////////////////////////////////////////////////
2004 /// Find level of virtuality of current overlapping node (number of levels
2005 /// up having the same tracking media.
2006 
2010 }
2011 
2012 ////////////////////////////////////////////////////////////////////////////////
2013 /// Search the track hierarchy to find the track with the
2014 /// given id
2015 ///
2016 /// if 'primsFirst' is true, then:
2017 /// first tries TGeoManager::GetTrackOfId, then does a
2018 /// recursive search if that fails. this would be faster
2019 /// if the track is somehow known to be a primary
2020 
2023  TVirtualGeoTrack* trk = 0;
2024  trk = GetTrackOfId(id);
2025  if (trk) return trk;
2026  // need recursive search
2027  TIter next(fTracks);
2028  TVirtualGeoTrack* prim;
2029  while ((prim = (TVirtualGeoTrack*)next())) {
2030  trk = prim->FindTrackWithId(id);
2031  if (trk) return trk;
2032  }
2033  return NULL;
2034 }
2035 
2036 ////////////////////////////////////////////////////////////////////////////////
2037 /// Get track with a given ID.
2038 
2041  TVirtualGeoTrack *track;
2042  for (Int_t i=0; i<fNtracks; i++) {
2043  if ((track = (TVirtualGeoTrack *)fTracks->UncheckedAt(i))) {
2044  if (track->GetId() == id) return track;
2045  }
2046  }
2047  return 0;
2048 }
2049 
2050 ////////////////////////////////////////////////////////////////////////////////
2051 /// Get parent track with a given ID.
2052 
2056  while ((track=track->GetMother())) {
2057  if (track->GetId()==id) return track;
2058  }
2059  return 0;
2060 }
2061 
2062 ////////////////////////////////////////////////////////////////////////////////
2063 /// Get index for track id, -1 if not found.
2064 
2067  TVirtualGeoTrack *track;
2068  for (Int_t i=0; i<fNtracks; i++) {
2069  if ((track = (TVirtualGeoTrack *)fTracks->UncheckedAt(i))) {
2070  if (track->GetId() == id) return i;
2071  }
2072  }
2073  return -1;
2074 }
2075 
2076 ////////////////////////////////////////////////////////////////////////////////
2077 /// Go upwards the tree until a non-overlapping node
2078 
2081  return GetCurrentNavigator()->GotoSafeLevel();
2082 }
2083 
2084 ////////////////////////////////////////////////////////////////////////////////
2085 /// Go upwards the tree until a non-overlapping node
2086 
2089  return GetCurrentNavigator()->GetSafeLevel();
2090 }
2091 
2092 ////////////////////////////////////////////////////////////////////////////////
2093 /// Set default volume colors according to A of material
2094 
2097  const Int_t nmax = 110;
2098  Int_t col[nmax];
2099  for (Int_t i=0;i<nmax;i++) col[i] = kGray;
2100 
2101  //here we should create a new TColor with the same rgb as in the default
2102  //ROOT colors used below
2103  col[ 3] = kYellow-10;
2104  col[ 4] = col[ 5] = kGreen-10;
2105  col[ 6] = col[ 7] = kBlue-7;
2106  col[ 8] = col[ 9] = kMagenta-3;
2107  col[10] = col[11] = kRed-10;
2108  col[12] = kGray+1;
2109  col[13] = kBlue-10;
2110  col[14] = kOrange+7;
2111  col[16] = kYellow+1;
2112  col[20] = kYellow-10;
2113  col[24] = col[25] = col[26] = kBlue-8;
2114  col[29] = kOrange+9;
2115  col[79] = kOrange-2;
2116 
2117  TGeoVolume *vol;
2118  TIter next(fVolumes);
2119  while ((vol=(TGeoVolume*)next())) {
2120  TGeoMedium *med = vol->GetMedium();
2121  if (!med) continue;
2122  TGeoMaterial *mat = med->GetMaterial();
2123  Int_t matZ = (Int_t)mat->GetZ();
2124  vol->SetLineColor(col[matZ]);
2125  if (mat->GetDensity()<0.1) vol->SetTransparency(60);
2126  }
2127 }
2128 
2129 ////////////////////////////////////////////////////////////////////////////////
2130 /// Compute safe distance from the current point. This represent the distance
2131 /// from POINT to the closest boundary.
2132 
2135  return GetCurrentNavigator()->Safety(inside);
2136 }
2137 
2138 ////////////////////////////////////////////////////////////////////////////////
2139 /// Set volume attributes in G3 style.
2140 
2141 void TGeoManager::SetVolumeAttribute(const char *name, const char *att, Int_t val)
2143  TGeoVolume *volume;
2144  Bool_t all = kFALSE;
2145  if (strstr(name,"*")) all=kTRUE;
2146  Int_t ivo=0;
2147  TIter next(fVolumes);
2148  TString chatt = att;
2149  chatt.ToLower();
2150  while ((volume=(TGeoVolume*)next())) {
2151  if (strcmp(volume->GetName(), name) && !all) continue;
2152  ivo++;
2153  if (chatt.Contains("colo")) volume->SetLineColor(val);
2154  if (chatt.Contains("lsty")) volume->SetLineStyle(val);
2155  if (chatt.Contains("lwid")) volume->SetLineWidth(val);
2156  if (chatt.Contains("fill")) volume->SetFillColor(val);
2157  if (chatt.Contains("seen")) volume->SetVisibility(val);
2158  }
2159  TIter next1(fGVolumes);
2160  while ((volume=(TGeoVolume*)next1())) {
2161  if (strcmp(volume->GetName(), name) && !all) continue;
2162  ivo++;
2163  if (chatt.Contains("colo")) volume->SetLineColor(val);
2164  if (chatt.Contains("lsty")) volume->SetLineStyle(val);
2165  if (chatt.Contains("lwid")) volume->SetLineWidth(val);
2166  if (chatt.Contains("fill")) volume->SetFillColor(val);
2167  if (chatt.Contains("seen")) volume->SetVisibility(val);
2168  }
2169  if (!ivo) {
2170  Warning("SetVolumeAttribute","volume: %s does not exist",name);
2171  }
2172 }
2173 
2174 ////////////////////////////////////////////////////////////////////////////////
2175 /// Set factors that will "bomb" all translations in cartesian and cylindrical coordinates.
2176 
2177 void TGeoManager::SetBombFactors(Double_t bombx, Double_t bomby, Double_t bombz, Double_t bombr)
2179  if (fPainter) fPainter->SetBombFactors(bombx, bomby, bombz, bombr);
2180 }
2181 
2182 ////////////////////////////////////////////////////////////////////////////////
2183 /// Set a user-defined shape as clipping for ray tracing.
2184 
2187  TVirtualGeoPainter *painter = GetGeomPainter();
2188  if (shape) {
2190  fClippingShape = shape;
2191  }
2192  painter->SetClippingShape(shape);
2193 }
2194 
2195 ////////////////////////////////////////////////////////////////////////////////
2196 /// set the maximum number of visible nodes.
2197 
2198 void TGeoManager::SetMaxVisNodes(Int_t maxnodes) {
2199  fMaxVisNodes = maxnodes;
2200  if (maxnodes>0 && fgVerboseLevel>0)
2201  Info("SetMaxVisNodes","Automatic visible depth for %d visible nodes", maxnodes);
2202  if (!fPainter) return;
2204  Int_t level = fPainter->GetVisLevel();
2205  if (level != fVisLevel) fVisLevel = level;
2206 }
2207 
2208 ////////////////////////////////////////////////////////////////////////////////
2209 /// make top volume visible on screen
2210 
2213  fPainter->SetTopVisible(vis);
2214 }
2215 
2216 ////////////////////////////////////////////////////////////////////////////////
2217 /// Assign a given node to be checked for overlaps. Any other overlaps will be ignored.
2218 
2221 }
2222 
2223 ////////////////////////////////////////////////////////////////////////////////
2224 /// Set the number of points to be generated on the shape outline when checking
2225 /// for overlaps.
2226 
2227 void TGeoManager::SetNmeshPoints(Int_t npoints)
2229  GetGeomPainter()->SetNmeshPoints(npoints);
2230 }
2231 
2232 ////////////////////////////////////////////////////////////////////////////////
2233 /// set drawing mode :
2234 /// - option=0 (default) all nodes drawn down to vislevel
2235 /// - option=1 leaves and nodes at vislevel drawn
2236 /// - option=2 path is drawn
2237 /// - option=4 visibility changed
2238 
2239 void TGeoManager::SetVisOption(Int_t option) {
2240  if ((option>=0) && (option<3)) fVisOption=option;
2241  if (fPainter) fPainter->SetVisOption(option);
2242 }
2243 
2244 ////////////////////////////////////////////////////////////////////////////////
2245 /// Set visualization option (leaves only OR all volumes)
2246 
2249  if (flag) SetVisOption(1);
2250  else SetVisOption(0);
2251 }
2252 
2253 ////////////////////////////////////////////////////////////////////////////////
2254 /// Set density threshold. Volumes with densities lower than this become
2255 /// transparent.
2256 
2259  fVisDensity = density;
2260  if (fPainter) fPainter->ModifiedPad();
2261 }
2262 
2263 ////////////////////////////////////////////////////////////////////////////////
2264 /// set default level down to which visualization is performed
2265 
2266 void TGeoManager::SetVisLevel(Int_t level) {
2267  if (level>0) {
2268  fVisLevel = level;
2269  fMaxVisNodes = 0;
2270  if (fgVerboseLevel>0)
2271  Info("SetVisLevel","Automatic visible depth disabled");
2273  } else {
2274  SetMaxVisNodes();
2275  }
2276 }
2277 
2278 ////////////////////////////////////////////////////////////////////////////////
2279 /// Sort overlaps by decreasing overlap distance. Extrusions comes first.
2280 
2283  fOverlaps->Sort();
2284 }
2285 
2286 ////////////////////////////////////////////////////////////////////////////////
2287 /// Optimize voxelization type for all volumes. Save best choice in a macro.
2288 
2289 void TGeoManager::OptimizeVoxels(const char *filename)
2291  if (!fTopNode) {
2292  Error("OptimizeVoxels","Geometry must be closed first");
2293  return;
2294  }
2295  std::ofstream out;
2296  TString fname = filename;
2297  if (fname.IsNull()) fname = "tgeovox.C";
2298  out.open(fname, std::ios::out);
2299  if (!out.good()) {
2300  Error("OptimizeVoxels", "cannot open file");
2301  return;
2302  }
2303  // write header
2304  TDatime t;
2305  TString sname(fname);
2306  sname.ReplaceAll(".C", "");
2307  out << sname.Data()<<"()"<<std::endl;
2308  out << "{" << std::endl;
2309  out << "//=== Macro generated by ROOT version "<< gROOT->GetVersion()<<" : "<<t.AsString()<<std::endl;
2310  out << "//=== Voxel optimization for " << GetTitle() << " geometry"<<std::endl;
2311  out << "//===== <run this macro JUST BEFORE closing the geometry>"<<std::endl;
2312  out << " TGeoVolume *vol = 0;"<<std::endl;
2313  out << " // parse all voxelized volumes"<<std::endl;
2314  TGeoVolume *vol = 0;
2315  Bool_t cyltype;
2316  TIter next(fVolumes);
2317  while ((vol=(TGeoVolume*)next())) {
2318  if (!vol->GetVoxels()) continue;
2319  out<<" vol = gGeoManager->GetVolume(\""<<vol->GetName()<<"\");"<<std::endl;
2320  cyltype = vol->OptimizeVoxels();
2321  if (cyltype) {
2322  out<<" vol->SetCylVoxels();"<<std::endl;
2323  } else {
2324  out<<" vol->SetCylVoxels(kFALSE);"<<std::endl;
2325  }
2326  }
2327  out << "}" << std::endl;
2328  out.close();
2329 }
2330 ////////////////////////////////////////////////////////////////////////////////
2331 /// Parse a string boolean expression and do a syntax check. Find top
2332 /// level boolean operator and returns its type. Fill the two
2333 /// substrings to which this operator applies. The returned integer is :
2334 /// - -1 : parse error
2335 /// - 0 : no boolean operator
2336 /// - 1 : union - represented as '+' in expression
2337 /// - 2 : difference (subtraction) - represented as '-' in expression
2338 /// - 3 : intersection - represented as '*' in expression.
2339 /// Parentheses should be used to avoid ambiguities. For instance :
2340 /// - A+B-C will be interpreted as (A+B)-C which is not the same as A+(B-C)
2341 /// eliminate not needed parentheses
2342 
2343 Int_t TGeoManager::Parse(const char *expr, TString &expr1, TString &expr2, TString &expr3)
2345  TString startstr(expr);
2346  Int_t len = startstr.Length();
2347  Int_t i;
2348  TString e0 = "";
2349  expr3 = "";
2350  // eliminate blanks
2351  for (i=0; i< len; i++) {
2352  if (startstr(i)==' ') continue;
2353  e0 += startstr(i, 1);
2354  }
2355  Int_t level = 0;
2356  Int_t levmin = 999;
2357  Int_t boolop = 0;
2358  Int_t indop = 0;
2359  Int_t iloop = 1;
2360  Int_t lastop = 0;
2361  Int_t lastdp = 0;
2362  Int_t lastpp = 0;
2363  Bool_t foundmat = kFALSE;
2364  // check/eliminate parentheses
2365  while (iloop==1) {
2366  iloop = 0;
2367  lastop = 0;
2368  lastdp = 0;
2369  lastpp = 0;
2370  len = e0.Length();
2371  for (i=0; i<len; i++) {
2372  if (e0(i)=='(') {
2373  if (!level) iloop++;
2374  level++;
2375  continue;
2376  }
2377  if (e0(i)==')') {
2378  level--;
2379  if (level==0) lastpp=i;
2380  continue;
2381  }
2382  if ((e0(i)=='+') || (e0(i)=='-') || (e0(i)=='*')) {
2383  lastop = i;
2384  if (level<levmin) {
2385  levmin = level;
2386  indop = i;
2387  }
2388  continue;
2389  }
2390  if ((e0(i)==':') && (level==0)) {
2391  lastdp = i;
2392  continue;
2393  }
2394  }
2395  if (level!=0) {
2396  if (gGeoManager) gGeoManager->Error("Parse","parentheses does not match");
2397  return -1;
2398  }
2399  if (iloop==1 && (e0(0)=='(') && (e0(len-1)==')')) {
2400  // eliminate extra parentheses
2401  e0=e0(1, len-2);
2402  continue;
2403  }
2404  if (foundmat) break;
2405  if (((lastop==0) && (lastdp>0)) || ((lastpp>0) && (lastdp>lastpp) && (indop<lastpp))) {
2406  expr3 = e0(lastdp+1, len-lastdp);
2407  e0=e0(0, lastdp);
2408  foundmat = kTRUE;
2409  iloop = 1;
2410  continue;
2411  } else break;
2412  }
2413  // loop expression and search parentheses/operators
2414  levmin = 999;
2415  for (i=0; i<len; i++) {
2416  if (e0(i)=='(') {
2417  level++;
2418  continue;
2419  }
2420  if (e0(i)==')') {
2421  level--;
2422  continue;
2423  }
2424  // Take LAST operator at lowest level (revision 28/07/08)
2425  if (level<=levmin) {
2426  if (e0(i)=='+') {
2427  boolop = 1; // union
2428  levmin = level;
2429  indop = i;
2430  }
2431  if (e0(i)=='-') {
2432  boolop = 2; // difference
2433  levmin = level;
2434  indop = i;
2435  }
2436  if (e0(i)=='*') {
2437  boolop = 3; // intersection
2438  levmin = level;
2439  indop = i;
2440  }
2441  }
2442  }
2443  if (indop==0) {
2444  expr1=e0;
2445  return indop;
2446  }
2447  expr1 = e0(0, indop);
2448  expr2 = e0(indop+1, len-indop);
2449  return boolop;
2450 }
2451 
2452 
2453 ////////////////////////////////////////////////////////////////////////////////
2454 /// Save current attributes in a macro
2455 
2456 void TGeoManager::SaveAttributes(const char *filename)
2458  if (!fTopNode) {
2459  Error("SaveAttributes","geometry must be closed first\n");
2460  return;
2461  }
2462  std::ofstream out;
2463  TString fname(filename);
2464  if (fname.IsNull()) fname = "tgeoatt.C";
2465  out.open(fname, std::ios::out);
2466  if (!out.good()) {
2467  Error("SaveAttributes", "cannot open file");
2468  return;
2469  }
2470  // write header
2471  TDatime t;
2472  TString sname(fname);
2473  sname.ReplaceAll(".C", "");
2474  out << sname.Data()<<"()"<<std::endl;
2475  out << "{" << std::endl;
2476  out << "//=== Macro generated by ROOT version "<< gROOT->GetVersion()<<" : "<<t.AsString()<<std::endl;
2477  out << "//=== Attributes for " << GetTitle() << " geometry"<<std::endl;
2478  out << "//===== <run this macro AFTER loading the geometry in memory>"<<std::endl;
2479  // save current top volume
2480  out << " TGeoVolume *top = gGeoManager->GetVolume(\""<<fTopVolume->GetName()<<"\");"<<std::endl;
2481  out << " TGeoVolume *vol = 0;"<<std::endl;
2482  out << " TGeoNode *node = 0;"<<std::endl;
2483  out << " // clear all volume attributes and get painter"<<std::endl;
2484  out << " gGeoManager->ClearAttributes();"<<std::endl;
2485  out << " gGeoManager->GetGeomPainter();"<<std::endl;
2486  out << " // set visualization modes and bomb factors"<<std::endl;
2487  out << " gGeoManager->SetVisOption("<<GetVisOption()<<");"<<std::endl;
2488  out << " gGeoManager->SetVisLevel("<<GetVisLevel()<<");"<<std::endl;
2489  out << " gGeoManager->SetExplodedView("<<GetBombMode()<<");"<<std::endl;
2490  Double_t bombx, bomby, bombz, bombr;
2491  GetBombFactors(bombx, bomby, bombz, bombr);
2492  out << " gGeoManager->SetBombFactors("<<bombx<<","<<bomby<<","<<bombz<<","<<bombr<<");"<<std::endl;
2493  out << " // iterate volumes container and set new attributes"<<std::endl;
2494 // out << " TIter next(gGeoManager->GetListOfVolumes());"<<std::endl;
2495  TGeoVolume *vol = 0;
2496  fTopNode->SaveAttributes(out);
2497 
2498  TIter next(fVolumes);
2499  while ((vol=(TGeoVolume*)next())) {
2500  vol->SetVisStreamed(kFALSE);
2501  }
2502  out << " // draw top volume with new settings"<<std::endl;
2503  out << " top->Draw();"<<std::endl;
2504  out << " gPad->x3d();"<<std::endl;
2505  out << "}" << std::endl;
2506  out.close();
2507 }
2508 
2509 ////////////////////////////////////////////////////////////////////////////////
2510 /// Returns the deepest node containing fPoint, which must be set a priori.
2511 
2512 TGeoNode *TGeoManager::SearchNode(Bool_t downwards, const TGeoNode *skipnode)
2514  return GetCurrentNavigator()->SearchNode(downwards, skipnode);
2515 }
2516 
2517 ////////////////////////////////////////////////////////////////////////////////
2518 /// Cross next boundary and locate within current node
2519 /// The current point must be on the boundary of fCurrentNode.
2520 
2523  return GetCurrentNavigator()->CrossBoundaryAndLocate(downwards, skipnode);
2524 }
2525 
2526 ////////////////////////////////////////////////////////////////////////////////
2527 /// Compute distance to next boundary within STEPMAX. If no boundary is found,
2528 /// propagate current point along current direction with fStep=STEPMAX. Otherwise
2529 /// propagate with fStep=SNEXT (distance to boundary) and locate/return the next
2530 /// node.
2531 
2534  return GetCurrentNavigator()->FindNextBoundaryAndStep(stepmax, compsafe);
2535 }
2536 
2537 ////////////////////////////////////////////////////////////////////////////////
2538 /// Find distance to next boundary and store it in fStep. Returns node to which this
2539 /// boundary belongs. If PATH is specified, compute only distance to the node to which
2540 /// PATH points. If STEPMAX is specified, compute distance only in case fSafety is smaller
2541 /// than this value. STEPMAX represent the step to be made imposed by other reasons than
2542 /// geometry (usually physics processes). Therefore in this case this method provides the
2543 /// answer to the question : "Is STEPMAX a safe step ?" returning a NULL node and filling
2544 /// fStep with a big number.
2545 /// In case frombdr=kTRUE, the isotropic safety is set to zero.
2546 ///
2547 /// Note : safety distance for the current point is computed ONLY in case STEPMAX is
2548 /// specified, otherwise users have to call explicitly TGeoManager::Safety() if
2549 /// they want this computed for the current point.
2550 
2551 TGeoNode *TGeoManager::FindNextBoundary(Double_t stepmax, const char *path, Bool_t frombdr)
2553  // convert current point and direction to local reference
2554  return GetCurrentNavigator()->FindNextBoundary(stepmax,path, frombdr);
2555 }
2556 
2557 ////////////////////////////////////////////////////////////////////////////////
2558 /// Computes as fStep the distance to next daughter of the current volume.
2559 /// The point and direction must be converted in the coordinate system of the current volume.
2560 /// The proposed step limit is fStep.
2561 
2562 TGeoNode *TGeoManager::FindNextDaughterBoundary(Double_t *point, Double_t *dir, Int_t &idaughter, Bool_t compmatrix)
2564  return GetCurrentNavigator()->FindNextDaughterBoundary(point, dir, idaughter, compmatrix);
2565 }
2566 
2567 ////////////////////////////////////////////////////////////////////////////////
2568 /// Reset current state flags.
2569 
2573 }
2574 
2575 ////////////////////////////////////////////////////////////////////////////////
2576 /// Returns deepest node containing current point.
2577 
2580  return GetCurrentNavigator()->FindNode(safe_start);
2581 }
2582 
2583 ////////////////////////////////////////////////////////////////////////////////
2584 /// Returns deepest node containing current point.
2585 
2588  return GetCurrentNavigator()->FindNode(x, y, z);
2589 }
2590 
2591 ////////////////////////////////////////////////////////////////////////////////
2592 /// Computes fast normal to next crossed boundary, assuming that the current point
2593 /// is close enough to the boundary. Works only after calling FindNextBoundary.
2594 
2597  return GetCurrentNavigator()->FindNormalFast();
2598 }
2599 
2600 ////////////////////////////////////////////////////////////////////////////////
2601 /// Computes normal vector to the next surface that will be or was already
2602 /// crossed when propagating on a straight line from a given point/direction.
2603 /// Returns the normal vector cosines in the MASTER coordinate system. The dot
2604 /// product of the normal and the current direction is positive defined.
2605 
2608  return GetCurrentNavigator()->FindNormal(forward);
2609 }
2610 
2611 ////////////////////////////////////////////////////////////////////////////////
2612 /// Checks if point (x,y,z) is still in the current node.
2613 
2616  return GetCurrentNavigator()->IsSameLocation(x,y,z,change);
2617 }
2618 
2619 ////////////////////////////////////////////////////////////////////////////////
2620 /// Check if a new point with given coordinates is the same as the last located one.
2621 
2624  return GetCurrentNavigator()->IsSamePoint(x,y,z);
2625 }
2626 
2627 ////////////////////////////////////////////////////////////////////////////////
2628 /// True if current node is in phi range
2629 
2632  if (!fPhiCut) return kTRUE;
2633  const Double_t *origin;
2635  origin = ((TGeoBBox*)GetCurrentNavigator()->GetCurrentVolume()->GetShape())->GetOrigin();
2636  Double_t point[3];
2637  LocalToMaster(origin, &point[0]);
2638  Double_t phi = TMath::ATan2(point[1], point[0])*TMath::RadToDeg();
2639  if (phi<0) phi+=360.;
2640  if ((phi>=fPhimin) && (phi<=fPhimax)) return kFALSE;
2641  return kTRUE;
2642 }
2643 
2644 ////////////////////////////////////////////////////////////////////////////////
2645 /// Initialize current point and current direction vector (normalized)
2646 /// in MARS. Return corresponding node.
2647 
2648 TGeoNode *TGeoManager::InitTrack(const Double_t *point, const Double_t *dir)
2650  return GetCurrentNavigator()->InitTrack(point, dir);
2651 }
2652 
2653 ////////////////////////////////////////////////////////////////////////////////
2654 /// Initialize current point and current direction vector (normalized)
2655 /// in MARS. Return corresponding node.
2656 
2659  return GetCurrentNavigator()->InitTrack(x,y,z,nx,ny,nz);
2660 }
2661 
2662 ////////////////////////////////////////////////////////////////////////////////
2663 /// Inspects path and all flags for the current state.
2664 
2665 void TGeoManager::InspectState() const
2668 }
2669 
2670 ////////////////////////////////////////////////////////////////////////////////
2671 /// Get path to the current node in the form /node0/node1/...
2672 
2673 const char *TGeoManager::GetPath() const
2675  return GetCurrentNavigator()->GetPath();
2676 }
2677 
2678 ////////////////////////////////////////////////////////////////////////////////
2679 /// Get total size of geometry in bytes.
2680 
2683  Int_t count = 0;
2684  TIter next(fVolumes);
2685  TGeoVolume *vol;
2686  while ((vol=(TGeoVolume*)next())) count += vol->GetByteCount();
2687  TIter next1(fMatrices);
2688  TGeoMatrix *matrix;
2689  while ((matrix=(TGeoMatrix*)next1())) count += matrix->GetByteCount();
2690  TIter next2(fMaterials);
2691  TGeoMaterial *mat;
2692  while ((mat=(TGeoMaterial*)next2())) count += mat->GetByteCount();
2693  TIter next3(fMedia);
2694  TGeoMedium *med;
2695  while ((med=(TGeoMedium*)next3())) count += med->GetByteCount();
2696  if (fgVerboseLevel>0) Info("GetByteCount","Total size of logical tree : %i bytes", count);
2697  return count;
2698 }
2699 
2700 ////////////////////////////////////////////////////////////////////////////////
2701 /// Make a default painter if none present. Returns pointer to it.
2702 
2705  if (!fPainter) {
2706  TPluginHandler *h;
2707  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualGeoPainter"))) {
2708  if (h->LoadPlugin() == -1)
2709  return 0;
2710  fPainter = (TVirtualGeoPainter*)h->ExecPlugin(1,this);
2711  if (!fPainter) {
2712  Error("GetGeomPainter", "could not create painter");
2713  return 0;
2714  }
2715  }
2716  }
2717  return fPainter;
2718 }
2719 
2720 ////////////////////////////////////////////////////////////////////////////////
2721 /// Search for a named volume. All trailing blanks stripped.
2722 
2723 TGeoVolume *TGeoManager::GetVolume(const char *name) const
2725  TString sname = name;
2726  sname = sname.Strip();
2727  TGeoVolume *vol = (TGeoVolume*)fVolumes->FindObject(sname.Data());
2728  return vol;
2729 }
2730 
2731 ////////////////////////////////////////////////////////////////////////////////
2732 /// Fast search for a named volume. All trailing blanks stripped.
2733 
2734 TGeoVolume *TGeoManager::FindVolumeFast(const char *name, Bool_t multi)
2736  if (!fHashVolumes) {
2737  Int_t nvol = fVolumes->GetEntriesFast();
2738  Int_t ngvol = fGVolumes->GetEntriesFast();
2739  fHashVolumes = new THashList(nvol+1);
2740  fHashGVolumes = new THashList(ngvol+1);
2741  Int_t i;
2742  for (i=0; i<ngvol; i++) fHashGVolumes->AddLast(fGVolumes->At(i));
2743  for (i=0; i<nvol; i++) fHashVolumes->AddLast(fVolumes->At(i));
2744  }
2745  TString sname = name;
2746  sname = sname.Strip();
2747  THashList *list = fHashVolumes;
2748  if (multi) list = fHashGVolumes;
2749  TGeoVolume *vol = (TGeoVolume*)list->FindObject(sname.Data());
2750  return vol;
2751 }
2752 
2753 ////////////////////////////////////////////////////////////////////////////////
2754 /// Retrieve unique id for a volume name. Return -1 if name not found.
2755 
2756 Int_t TGeoManager::GetUID(const char *volname) const
2758  TGeoManager *geom = (TGeoManager*)this;
2759  TGeoVolume *vol = geom->FindVolumeFast(volname, kFALSE);
2760  if (!vol) vol = geom->FindVolumeFast(volname, kTRUE);
2761  if (!vol) return -1;
2762  return vol->GetNumber();
2763 }
2764 
2765 ////////////////////////////////////////////////////////////////////////////////
2766 /// Find if a given material duplicates an existing one.
2767 
2770  Int_t index = fMaterials->IndexOf(mat);
2771  if (index <= 0) return 0;
2772  TGeoMaterial *other;
2773  for (Int_t i=0; i<index; i++) {
2774  other = (TGeoMaterial*)fMaterials->At(i);
2775  if (other == mat) continue;
2776  if (other->IsEq(mat)) return other;
2777  }
2778  return 0;
2779 }
2780 
2781 ////////////////////////////////////////////////////////////////////////////////
2782 /// Search for a named material. All trailing blanks stripped.
2783 
2784 TGeoMaterial *TGeoManager::GetMaterial(const char *matname) const
2786  TString sname = matname;
2787  sname = sname.Strip();
2788  TGeoMaterial *mat = (TGeoMaterial*)fMaterials->FindObject(sname.Data());
2789  return mat;
2790 }
2791 
2792 ////////////////////////////////////////////////////////////////////////////////
2793 /// Search for a named tracking medium. All trailing blanks stripped.
2794 
2795 TGeoMedium *TGeoManager::GetMedium(const char *medium) const
2797  TString sname = medium;
2798  sname = sname.Strip();
2799  TGeoMedium *med = (TGeoMedium*)fMedia->FindObject(sname.Data());
2800  return med;
2801 }
2802 
2803 ////////////////////////////////////////////////////////////////////////////////
2804 /// Search for a tracking medium with a given ID.
2805 
2808  TIter next(fMedia);
2809  TGeoMedium *med;
2810  while ((med=(TGeoMedium*)next())) {
2811  if (med->GetId()==numed) return med;
2812  }
2813  return 0;
2814 }
2815 
2816 ////////////////////////////////////////////////////////////////////////////////
2817 /// Return material at position id.
2818 
2821  if (id<0 || id >= fMaterials->GetSize()) return 0;
2822  TGeoMaterial *mat = (TGeoMaterial*)fMaterials->At(id);
2823  return mat;
2824 }
2825 
2826 ////////////////////////////////////////////////////////////////////////////////
2827 /// Return index of named material.
2828 
2829 Int_t TGeoManager::GetMaterialIndex(const char *matname) const
2831  TIter next(fMaterials);
2832  TGeoMaterial *mat;
2833  Int_t id = 0;
2834  TString sname = matname;
2835  sname = sname.Strip();
2836  while ((mat = (TGeoMaterial*)next())) {
2837  if (!strcmp(mat->GetName(),sname.Data()))
2838  return id;
2839  id++;
2840  }
2841  return -1; // fail
2842 }
2843 
2844 ////////////////////////////////////////////////////////////////////////////////
2845 /// Randomly shoot nrays and plot intersections with surfaces for current
2846 /// top node.
2847 
2848 void TGeoManager::RandomRays(Int_t nrays, Double_t startx, Double_t starty, Double_t startz, const char *target_vol, Bool_t check_norm)
2850  GetGeomPainter()->RandomRays(nrays, startx, starty, startz, target_vol, check_norm);
2851 }
2852 
2853 ////////////////////////////////////////////////////////////////////////////////
2854 /// Remove material at given index.
2855 
2858  TObject *obj = fMaterials->At(index);
2859  if (obj) fMaterials->Remove(obj);
2860 }
2861 
2862 ////////////////////////////////////////////////////////////////////////////////
2863 /// Sets all pointers TGeoVolume::fField to NULL. User data becomes decoupled
2864 /// from geometry. Deletion has to be managed by users.
2865 
2868  TIter next(fVolumes);
2869  TGeoVolume *vol;
2870  while ((vol=(TGeoVolume*)next())) vol->SetField(0);
2871 }
2872 
2873 ////////////////////////////////////////////////////////////////////////////////
2874 /// Change raytracing mode.
2875 
2876 void TGeoManager::SetRTmode(Int_t mode)
2878  fRaytraceMode = mode;
2880 }
2881 
2882 ////////////////////////////////////////////////////////////////////////////////
2883 /// Restore the master volume of the geometry.
2884 
2887  if (fTopVolume == fMasterVolume) return;
2889 }
2890 
2891 ////////////////////////////////////////////////////////////////////////////////
2892 /// Voxelize all non-divided volumes.
2893 
2894 void TGeoManager::Voxelize(Option_t *option)
2896  TGeoVolume *vol;
2897 // TGeoVoxelFinder *vox = 0;
2898  if (!fStreamVoxels && fgVerboseLevel>0) Info("Voxelize","Voxelizing...");
2899 // Int_t nentries = fVolumes->GetSize();
2900  TIter next(fVolumes);
2901  while ((vol = (TGeoVolume*)next())) {
2902  if (!fIsGeomReading) vol->SortNodes();
2903  if (!fStreamVoxels) {
2904  vol->Voxelize(option);
2905  }
2906  if (!fIsGeomReading) vol->FindOverlaps();
2907  }
2908 }
2909 
2910 ////////////////////////////////////////////////////////////////////////////////
2911 /// Send "Modified" signal to painter.
2912 
2913 void TGeoManager::ModifiedPad() const
2915  if (!fPainter) return;
2916  fPainter->ModifiedPad();
2917 }
2918 
2919 ////////////////////////////////////////////////////////////////////////////////
2920 /// Make an TGeoArb8 volume.
2921 
2922 TGeoVolume *TGeoManager::MakeArb8(const char *name, TGeoMedium *medium,
2923  Double_t dz, Double_t *vertices)
2924 {
2925  return TGeoBuilder::Instance(this)->MakeArb8(name, medium, dz, vertices);
2926 }
2927 
2928 ////////////////////////////////////////////////////////////////////////////////
2929 /// Make in one step a volume pointing to a box shape with given medium.
2930 
2931 TGeoVolume *TGeoManager::MakeBox(const char *name, TGeoMedium *medium,
2933 {
2934  return TGeoBuilder::Instance(this)->MakeBox(name, medium, dx, dy, dz);
2935 }
2936 
2937 ////////////////////////////////////////////////////////////////////////////////
2938 /// Make in one step a volume pointing to a parallelepiped shape with given medium.
2939 
2940 TGeoVolume *TGeoManager::MakePara(const char *name, TGeoMedium *medium,
2942  Double_t alpha, Double_t theta, Double_t phi)
2943 {
2944  return TGeoBuilder::Instance(this)->MakePara(name, medium, dx, dy, dz, alpha, theta, phi);
2945 }
2946 
2947 ////////////////////////////////////////////////////////////////////////////////
2948 /// Make in one step a volume pointing to a sphere shape with given medium
2949 
2950 TGeoVolume *TGeoManager::MakeSphere(const char *name, TGeoMedium *medium,
2951  Double_t rmin, Double_t rmax, Double_t themin, Double_t themax,
2952  Double_t phimin, Double_t phimax)
2953 {
2954  return TGeoBuilder::Instance(this)->MakeSphere(name, medium, rmin, rmax, themin, themax, phimin, phimax);
2955 }
2956 
2957 ////////////////////////////////////////////////////////////////////////////////
2958 /// Make in one step a volume pointing to a torus shape with given medium.
2959 
2961  Double_t rmin, Double_t rmax, Double_t phi1, Double_t dphi)
2962 {
2963  return TGeoBuilder::Instance(this)->MakeTorus(name, medium, r, rmin, rmax, phi1, dphi);
2964 }
2965 
2966 ////////////////////////////////////////////////////////////////////////////////
2967 /// Make in one step a volume pointing to a tube shape with given medium.
2968 
2969 TGeoVolume *TGeoManager::MakeTube(const char *name, TGeoMedium *medium,
2970  Double_t rmin, Double_t rmax, Double_t dz)
2971 {
2972  return TGeoBuilder::Instance(this)->MakeTube(name, medium, rmin, rmax, dz);
2973 }
2974 
2975 ////////////////////////////////////////////////////////////////////////////////
2976 /// Make in one step a volume pointing to a tube segment shape with given medium.
2977 /// The segment will be from phiStart to phiEnd, the angles are expressed in degree
2978 
2979 TGeoVolume *TGeoManager::MakeTubs(const char *name, TGeoMedium *medium,
2980  Double_t rmin, Double_t rmax, Double_t dz,
2981  Double_t phiStart, Double_t phiEnd)
2982 {
2983  return TGeoBuilder::Instance(this)->MakeTubs(name, medium, rmin, rmax, dz, phiStart, phiEnd);
2984 }
2985 
2986 ////////////////////////////////////////////////////////////////////////////////
2987 /// Make in one step a volume pointing to a tube shape with given medium
2988 
2989 TGeoVolume *TGeoManager::MakeEltu(const char *name, TGeoMedium *medium,
2991 {
2992  return TGeoBuilder::Instance(this)->MakeEltu(name, medium, a, b, dz);
2993 }
2994 
2995 ////////////////////////////////////////////////////////////////////////////////
2996 /// Make in one step a volume pointing to a tube shape with given medium
2997 
2998 TGeoVolume *TGeoManager::MakeHype(const char *name, TGeoMedium *medium,
2999  Double_t rin, Double_t stin, Double_t rout, Double_t stout, Double_t dz)
3000 {
3001  return TGeoBuilder::Instance(this)->MakeHype(name, medium, rin, stin, rout, stout, dz);
3002 }
3003 
3004 ////////////////////////////////////////////////////////////////////////////////
3005 /// Make in one step a volume pointing to a tube shape with given medium
3006 
3009 {
3010  return TGeoBuilder::Instance(this)->MakeParaboloid(name, medium, rlo, rhi, dz);
3011 }
3012 
3013 ////////////////////////////////////////////////////////////////////////////////
3014 /// Make in one step a volume pointing to a tube segment shape with given medium
3015 
3016 TGeoVolume *TGeoManager::MakeCtub(const char *name, TGeoMedium *medium,
3017  Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2,
3018  Double_t lx, Double_t ly, Double_t lz, Double_t tx, Double_t ty, Double_t tz)
3019 {
3020  return TGeoBuilder::Instance(this)->MakeCtub(name, medium, rmin, rmax, dz, phi1, phi2, lx, ly, lz, tx, ty, tz);
3021 }
3022 
3023 ////////////////////////////////////////////////////////////////////////////////
3024 /// Make in one step a volume pointing to a cone shape with given medium.
3025 
3026 TGeoVolume *TGeoManager::MakeCone(const char *name, TGeoMedium *medium,
3027  Double_t dz, Double_t rmin1, Double_t rmax1,
3028  Double_t rmin2, Double_t rmax2)
3029 {
3030  return TGeoBuilder::Instance(this)->MakeCone(name, medium, dz, rmin1, rmax1, rmin2, rmax2);
3031 }
3032 
3033 ////////////////////////////////////////////////////////////////////////////////
3034 /// Make in one step a volume pointing to a cone segment shape with given medium
3035 
3036 TGeoVolume *TGeoManager::MakeCons(const char *name, TGeoMedium *medium,
3037  Double_t dz, Double_t rmin1, Double_t rmax1,
3038  Double_t rmin2, Double_t rmax2,
3039  Double_t phi1, Double_t phi2)
3040 {
3041  return TGeoBuilder::Instance(this)->MakeCons(name, medium, dz, rmin1, rmax1, rmin2, rmax2, phi1, phi2);
3042 }
3043 
3044 ////////////////////////////////////////////////////////////////////////////////
3045 /// Make in one step a volume pointing to a polycone shape with given medium.
3046 
3047 TGeoVolume *TGeoManager::MakePcon(const char *name, TGeoMedium *medium,
3048  Double_t phi, Double_t dphi, Int_t nz)
3049 {
3050  return TGeoBuilder::Instance(this)->MakePcon(name, medium, phi, dphi, nz);
3051 }
3052 
3053 ////////////////////////////////////////////////////////////////////////////////
3054 /// Make in one step a volume pointing to a polygone shape with given medium.
3055 
3056 TGeoVolume *TGeoManager::MakePgon(const char *name, TGeoMedium *medium,
3057  Double_t phi, Double_t dphi, Int_t nedges, Int_t nz)
3058 {
3059  return TGeoBuilder::Instance(this)->MakePgon(name, medium, phi, dphi, nedges, nz);
3060 }
3061 
3062 ////////////////////////////////////////////////////////////////////////////////
3063 /// Make in one step a volume pointing to a TGeoTrd1 shape with given medium.
3064 
3065 TGeoVolume *TGeoManager::MakeTrd1(const char *name, TGeoMedium *medium,
3067 {
3068  return TGeoBuilder::Instance(this)->MakeTrd1(name, medium, dx1, dx2, dy, dz);
3069 }
3070 
3071 ////////////////////////////////////////////////////////////////////////////////
3072 /// Make in one step a volume pointing to a TGeoTrd2 shape with given medium.
3073 
3074 TGeoVolume *TGeoManager::MakeTrd2(const char *name, TGeoMedium *medium,
3075  Double_t dx1, Double_t dx2, Double_t dy1, Double_t dy2,
3076  Double_t dz)
3077 {
3078  return TGeoBuilder::Instance(this)->MakeTrd2(name, medium, dx1, dx2, dy1, dy2, dz);
3079 }
3080 
3081 ////////////////////////////////////////////////////////////////////////////////
3082 /// Make in one step a volume pointing to a trapezoid shape with given medium.
3083 
3084 TGeoVolume *TGeoManager::MakeTrap(const char *name, TGeoMedium *medium,
3086  Double_t bl1, Double_t tl1, Double_t alpha1, Double_t h2, Double_t bl2,
3087  Double_t tl2, Double_t alpha2)
3088 {
3089  return TGeoBuilder::Instance(this)->MakeTrap(name, medium, dz, theta, phi, h1, bl1, tl1, alpha1, h2, bl2, tl2, alpha2);
3090 }
3091 
3092 ////////////////////////////////////////////////////////////////////////////////
3093 /// Make in one step a volume pointing to a twisted trapezoid shape with given medium.
3094 
3095 TGeoVolume *TGeoManager::MakeGtra(const char *name, TGeoMedium *medium,
3096  Double_t dz, Double_t theta, Double_t phi, Double_t twist, Double_t h1,
3097  Double_t bl1, Double_t tl1, Double_t alpha1, Double_t h2, Double_t bl2,
3098  Double_t tl2, Double_t alpha2)
3099 {
3100  return TGeoBuilder::Instance(this)->MakeGtra(name, medium, dz, theta, phi, twist, h1, bl1, tl1, alpha1, h2, bl2, tl2, alpha2);
3101 }
3102 
3103 ////////////////////////////////////////////////////////////////////////////////
3104 /// Make a TGeoXtru-shaped volume with nz planes
3105 
3106 TGeoVolume *TGeoManager::MakeXtru(const char *name, TGeoMedium *medium, Int_t nz)
3108  return TGeoBuilder::Instance(this)->MakeXtru(name, medium, nz);
3109 }
3110 
3111 ////////////////////////////////////////////////////////////////////////////////
3112 /// Creates an alignable object with unique name corresponding to a path
3113 /// and adds it to the list of alignables. An optional unique ID can be
3114 /// provided, in which case PN entries can be searched fast by uid.
3115 
3116 TGeoPNEntry *TGeoManager::SetAlignableEntry(const char *unique_name, const char *path,
3117  Int_t uid)
3118 {
3119  if (!CheckPath(path)) return NULL;
3120  if (!fHashPNE) fHashPNE = new THashList(256,3);
3121  if (!fArrayPNE) fArrayPNE = new TObjArray(256);
3122  TGeoPNEntry *entry = GetAlignableEntry(unique_name);
3123  if (entry) {
3124  Error("SetAlignableEntry", "An alignable object with name %s already existing. NOT ADDED !", unique_name);
3125  return 0;
3126  }
3127  entry = new TGeoPNEntry(unique_name, path);
3128  Int_t ientry = fHashPNE->GetSize();
3129  fHashPNE->Add(entry);
3130  fArrayPNE->AddAtAndExpand(entry, ientry);
3131  if (uid>=0) {
3132  Bool_t added = InsertPNEId(uid, ientry);
3133  if (!added) Error("SetAlignableEntry", "A PN entry: has already uid=%i", uid);
3134  }
3135  return entry;
3136 }
3137 
3138 ////////////////////////////////////////////////////////////////////////////////
3139 /// Retrieves an existing alignable object.
3140 
3143  if (!fHashPNE) return 0;
3144  return (TGeoPNEntry*)fHashPNE->FindObject(name);
3145 }
3146 
3147 ////////////////////////////////////////////////////////////////////////////////
3148 /// Retrieves an existing alignable object at a given index.
3149 
3152  if (!fArrayPNE && !InitArrayPNE()) return 0;
3153  return (TGeoPNEntry*)fArrayPNE->At(index);
3154 }
3155 
3156 ////////////////////////////////////////////////////////////////////////////////
3157 /// Retrieves an existing alignable object having a preset UID.
3158 
3161  if (!fNPNEId || (!fArrayPNE && !InitArrayPNE())) return NULL;
3162  Int_t index = TMath::BinarySearch(fNPNEId, fKeyPNEId, uid);
3163  if (index<0 || fKeyPNEId[index]!=uid) return NULL;
3164  return (TGeoPNEntry*)fArrayPNE->At(fValuePNEId[index]);
3165 }
3166 
3167 ////////////////////////////////////////////////////////////////////////////////
3168 /// Retrieves number of PN entries with or without UID.
3169 
3170 Int_t TGeoManager::GetNAlignable(Bool_t with_uid) const
3172  if (!fHashPNE) return 0;
3173  if (with_uid) return fNPNEId;
3174  return fHashPNE->GetSize();
3175 }
3176 
3177 ////////////////////////////////////////////////////////////////////////////////
3178 /// Insert a PN entry in the sorted array of indexes.
3179 
3182  if (!fSizePNEId) {
3183  // Create the arrays.
3184  fSizePNEId = 128;
3185  fKeyPNEId = new Int_t[fSizePNEId];
3186  memset(fKeyPNEId, 0, fSizePNEId*sizeof(Int_t));
3187  fValuePNEId = new Int_t[fSizePNEId];
3188  memset(fValuePNEId, 0, fSizePNEId*sizeof(Int_t));
3189  fKeyPNEId[fNPNEId] = uid;
3190  fValuePNEId[fNPNEId++] = ientry;
3191  return kTRUE;
3192  }
3193  // Search id in the existing array and return false if it already exists.
3194  Int_t index = TMath::BinarySearch(fNPNEId, fKeyPNEId, uid);
3195  if (index>0 && fKeyPNEId[index]==uid) return kFALSE;
3196  // Resize the arrays and insert the value
3197  Bool_t resize = (fNPNEId==fSizePNEId)?kTRUE:kFALSE;
3198  if (resize) {
3199  // Double the size of the array
3200  fSizePNEId *= 2;
3201  // Create new arrays of keys and values
3202  Int_t *keys = new Int_t[fSizePNEId];
3203  memset(keys, 0, fSizePNEId*sizeof(Int_t));
3204  Int_t *values = new Int_t[fSizePNEId];
3205  memset(values, 0, fSizePNEId*sizeof(Int_t));
3206  // Copy all keys<uid in the new keys array (0 to index)
3207  memcpy(keys, fKeyPNEId, (index+1)*sizeof(Int_t));
3208  memcpy(values, fValuePNEId, (index+1)*sizeof(Int_t));
3209  // Insert current key at index+1
3210  keys[index+1] = uid;
3211  values[index+1] = ientry;
3212  // Copy all remaining keys from the old to new array
3213  memcpy(&keys[index+2], &fKeyPNEId[index+1], (fNPNEId-index-1)*sizeof(Int_t));
3214  memcpy(&values[index+2], &fValuePNEId[index+1], (fNPNEId-index-1)*sizeof(Int_t));
3215  delete [] fKeyPNEId;
3216  fKeyPNEId = keys;
3217  delete [] fValuePNEId;
3218  fValuePNEId = values;
3219  fNPNEId++;
3220  return kTRUE;
3221  }
3222  // Insert the value in the existing arrays
3223  Int_t i;
3224  for (i=fNPNEId-1; i>index; i--) {
3225  fKeyPNEId[i+1] = fKeyPNEId[i];
3226  fValuePNEId[i+1] = fValuePNEId[i];
3227  }
3228  fKeyPNEId[index+1] = uid;
3229  fValuePNEId[index+1] = ientry;
3230  fNPNEId++;
3231  return kTRUE;
3232 }
3233 
3234 ////////////////////////////////////////////////////////////////////////////////
3235 /// Make a physical node from the path pointed by an alignable object with a given name.
3236 
3239  TGeoPNEntry *entry = GetAlignableEntry(name);
3240  if (!entry) {
3241  Error("MakeAlignablePN","No alignable object named %s found !", name);
3242  return 0;
3243  }
3244  return MakeAlignablePN(entry);
3245 }
3246 
3247 ////////////////////////////////////////////////////////////////////////////////
3248 /// Make a physical node from the path pointed by a given alignable object.
3249 
3252  if (!entry) {
3253  Error("MakeAlignablePN","No alignable object specified !");
3254  return 0;
3255  }
3256  const char *path = entry->GetTitle();
3257  if (!cd(path)) {
3258  Error("MakeAlignablePN", "Alignable object %s poins to invalid path: %s",
3259  entry->GetName(), path);
3260  return 0;
3261  }
3262  TGeoPhysicalNode *node = MakePhysicalNode(path);
3263  entry->SetPhysicalNode(node);
3264  return node;
3265 }
3266 
3267 ////////////////////////////////////////////////////////////////////////////////
3268 /// Makes a physical node corresponding to a path. If PATH is not specified,
3269 /// makes physical node matching current modeller state.
3270 
3273  TGeoPhysicalNode *node;
3274  if (path) {
3275  if (!CheckPath(path)) {
3276  Error("MakePhysicalNode", "path: %s not valid", path);
3277  return NULL;
3278  }
3279  node = new TGeoPhysicalNode(path);
3280  } else {
3281  node = new TGeoPhysicalNode(GetPath());
3282  }
3283  fPhysicalNodes->Add(node);
3284  return node;
3285 }
3286 
3287 ////////////////////////////////////////////////////////////////////////////////
3288 /// Refresh physical nodes to reflect the actual geometry paths after alignment
3289 /// was applied. Optionally locks physical nodes (default).
3290 
3293  TIter next(gGeoManager->GetListOfPhysicalNodes());
3294  TGeoPhysicalNode *pn;
3295  while ((pn=(TGeoPhysicalNode*)next())) pn->Refresh();
3297  if (lock) LockGeometry();
3298 }
3299 
3300 ////////////////////////////////////////////////////////////////////////////////
3301 /// Clear the current list of physical nodes, so that we can start over with a new list.
3302 /// If MUSTDELETE is true, delete previous nodes.
3303 
3304 void TGeoManager::ClearPhysicalNodes(Bool_t mustdelete)
3306  if (mustdelete) fPhysicalNodes->Delete();
3307  else fPhysicalNodes->Clear();
3308 }
3309 
3310 ////////////////////////////////////////////////////////////////////////////////
3311 /// Make an assembly of volumes.
3312 
3315  return TGeoBuilder::Instance(this)->MakeVolumeAssembly(name);
3316 }
3317 
3318 ////////////////////////////////////////////////////////////////////////////////
3319 /// Make a TGeoVolumeMulti handling a list of volumes.
3320 
3323  return TGeoBuilder::Instance(this)->MakeVolumeMulti(name, medium);
3324 }
3325 
3326 ////////////////////////////////////////////////////////////////////////////////
3327 /// Set type of exploding view (see TGeoPainter::SetExplodedView())
3328 
3331  if ((ibomb>=0) && (ibomb<4)) fExplodedView = ibomb;
3332  if (fPainter) fPainter->SetExplodedView(ibomb);
3333 }
3334 
3335 ////////////////////////////////////////////////////////////////////////////////
3336 /// Set cut phi range
3337 
3338 void TGeoManager::SetPhiRange(Double_t phimin, Double_t phimax)
3340  if ((phimin==0) && (phimax==360)) {
3341  fPhiCut = kFALSE;
3342  return;
3343  }
3344  fPhiCut = kTRUE;
3345  fPhimin = phimin;
3346  fPhimax = phimax;
3347 }
3348 
3349 ////////////////////////////////////////////////////////////////////////////////
3350 /// Set number of segments for approximating circles in drawing.
3351 
3354  if (fNsegments==nseg) return;
3355  if (nseg>2) fNsegments = nseg;
3356  if (fPainter) fPainter->SetNsegments(nseg);
3357 }
3358 
3359 ////////////////////////////////////////////////////////////////////////////////
3360 /// Get number of segments approximating circles
3361 
3364  return fNsegments;
3365 }
3366 
3367 ////////////////////////////////////////////////////////////////////////////////
3368 /// Now just a shortcut for GetElementTable.
3369 
3372  GetElementTable();
3374 }
3375 
3376 ////////////////////////////////////////////////////////////////////////////////
3377 /// Returns material table. Creates it if not existing.
3378 
3381  if (!fElementTable) fElementTable = new TGeoElementTable(200);
3382  return fElementTable;
3383 }
3384 
3385 ////////////////////////////////////////////////////////////////////////////////
3386 /// Make a rectilinear step of length fStep from current point (fPoint) on current
3387 /// direction (fDirection). If the step is imposed by geometry, is_geom flag
3388 /// must be true (default). The cross flag specifies if the boundary should be
3389 /// crossed in case of a geometry step (default true). Returns new node after step.
3390 /// Set also on boundary condition.
3391 
3392 TGeoNode *TGeoManager::Step(Bool_t is_geom, Bool_t cross)
3394  return GetCurrentNavigator()->Step(is_geom, cross);
3395 }
3396 
3397 ////////////////////////////////////////////////////////////////////////////////
3398 /// shoot npoints randomly in a box of 1E-5 around current point.
3399 /// return minimum distance to points outside
3400 
3402  const char* g3path)
3403 {
3404  return GetGeomPainter()->SamplePoints(npoints, dist, epsil, g3path);
3405 }
3406 
3407 ////////////////////////////////////////////////////////////////////////////////
3408 /// Set the top volume and corresponding node as starting point of the geometry.
3409 
3412  if (fTopVolume==vol) return;
3413 
3414  TSeqCollection *brlist = gROOT->GetListOfBrowsers();
3415  TIter next(brlist);
3416  TBrowser *browser = 0;
3417 
3418  if (fTopVolume) fTopVolume->SetTitle("");
3419  fTopVolume = vol;
3420  vol->SetTitle("Top volume");
3421  if (fTopNode) {
3422  TGeoNode *topn = fTopNode;
3423  fTopNode = 0;
3424  while ((browser=(TBrowser*)next())) browser->RecursiveRemove(topn);
3425  delete topn;
3426  } else {
3427  fMasterVolume = vol;
3428  fMasterVolume->Grab();
3430  if (fgVerboseLevel>0) Info("SetTopVolume","Top volume is %s. Master volume is %s", fTopVolume->GetName(),
3431  fMasterVolume->GetName());
3432  }
3433 // fMasterVolume->FindMatrixOfDaughterVolume(vol);
3434 // fCurrentMatrix->Print();
3435  fTopNode = new TGeoNodeMatrix(vol, gGeoIdentity);
3436  fTopNode->SetName(TString::Format("%s_1",vol->GetName()));
3437  fTopNode->SetNumber(1);
3438  fTopNode->SetTitle("Top logical node");
3439  fNodes->AddAt(fTopNode, 0);
3440  if (!GetCurrentNavigator()) {
3442  return;
3443  }
3444  Int_t nnavigators = 0;
3446  if (!arr) return;
3447  nnavigators = arr->GetEntriesFast();
3448  for (Int_t i=0; i<nnavigators; i++) {
3449  TGeoNavigator *nav = (TGeoNavigator*)arr->At(i);
3450  nav->ResetAll();
3451  if (fClosed) nav->GetCache()->BuildInfoBranch();
3452  }
3453 }
3454 
3455 ////////////////////////////////////////////////////////////////////////////////
3456 /// Define different tracking media.
3457 
3460 /*
3461  Int_t nmat = fMaterials->GetSize();
3462  if (!nmat) {printf(" No materials !\n"); return;}
3463  Int_t *media = new Int_t[nmat];
3464  memset(media, 0, nmat*sizeof(Int_t));
3465  Int_t imedia = 1;
3466  TGeoMaterial *mat, *matref;
3467  mat = (TGeoMaterial*)fMaterials->At(0);
3468  if (mat->GetMedia()) {
3469  for (Int_t i=0; i<nmat; i++) {
3470  mat = (TGeoMaterial*)fMaterials->At(i);
3471  mat->Print();
3472  }
3473  return;
3474  }
3475  mat->SetMedia(imedia);
3476  media[0] = imedia++;
3477  mat->Print();
3478  for (Int_t i=0; i<nmat; i++) {
3479  mat = (TGeoMaterial*)fMaterials->At(i);
3480  for (Int_t j=0; j<i; j++) {
3481  matref = (TGeoMaterial*)fMaterials->At(j);
3482  if (mat->IsEq(matref)) {
3483  mat->SetMedia(media[j]);
3484  break;
3485  }
3486  if (j==(i-1)) {
3487  // different material
3488  mat->SetMedia(imedia);
3489  media[i] = imedia++;
3490  mat->Print();
3491  }
3492  }
3493  }
3494 */
3495 }
3496 
3497 ////////////////////////////////////////////////////////////////////////////////
3498 /// Check pushes and pulls needed to cross the next boundary with respect to the
3499 /// position given by FindNextBoundary. If radius is not mentioned the full bounding
3500 /// box will be sampled.
3501 
3502 void TGeoManager::CheckBoundaryErrors(Int_t ntracks, Double_t radius)
3504  GetGeomPainter()->CheckBoundaryErrors(ntracks, radius);
3505 }
3506 
3507 ////////////////////////////////////////////////////////////////////////////////
3508 /// Check the boundary errors reference file created by CheckBoundaryErrors method.
3509 /// The shape for which the crossing failed is drawn with the starting point in red
3510 /// and the extrapolated point to boundary (+/- failing push/pull) in yellow.
3511 
3515 }
3516 
3517 ////////////////////////////////////////////////////////////////////////////////
3518 /// Classify a given point. See TGeoChecker::CheckPoint().
3519 
3522  GetGeomPainter()->CheckPoint(x,y,z,option);
3523 }
3524 
3525 ////////////////////////////////////////////////////////////////////////////////
3526 /// Test for shape navigation methods. Summary for test numbers:
3527 /// 1: DistFromInside/Outside. Sample points inside the shape. Generate
3528 /// directions randomly in cos(theta). Compute DistFromInside and move the
3529 /// point with bigger distance. Compute DistFromOutside back from new point.
3530 /// Plot d-(d1+d2)
3531 ///
3532 
3533 void TGeoManager::CheckShape(TGeoShape *shape, Int_t testNo, Int_t nsamples, Option_t *option)
3535  GetGeomPainter()->CheckShape(shape, testNo, nsamples, option);
3536 }
3537 
3538 ////////////////////////////////////////////////////////////////////////////////
3539 /// Geometry checking.
3540 /// - if option contains 'o': Optional overlap checkings (by sampling and by mesh).
3541 /// - if option contains 'b': Optional boundary crossing check + timing per volume.
3542 ///
3543 /// STAGE 1: extensive overlap checking by sampling per volume. Stdout need to be
3544 /// checked by user to get report, then TGeoVolume::CheckOverlaps(0.01, "s") can
3545 /// be called for the suspicious volumes.
3546 ///
3547 /// STAGE2 : normal overlap checking using the shapes mesh - fills the list of
3548 /// overlaps.
3549 ///
3550 /// STAGE3 : shooting NRAYS rays from VERTEX and counting the total number of
3551 /// crossings per volume (rays propagated from boundary to boundary until
3552 /// geometry exit). Timing computed and results stored in a histo.
3553 ///
3554 /// STAGE4 : shooting 1 mil. random rays inside EACH volume and calling
3555 /// FindNextBoundary() + Safety() for each call. The timing is normalized by the
3556 /// number of crossings computed at stage 2 and presented as percentage.
3557 /// One can get a picture on which are the most "burned" volumes during
3558 /// transportation from geometry point of view. Another plot of the timing per
3559 /// volume vs. number of daughters is produced.
3560 
3561 void TGeoManager::CheckGeometryFull(Int_t ntracks, Double_t vx, Double_t vy, Double_t vz, Option_t *option)
3563  TString opt(option);
3564  opt.ToLower();
3565  if (!opt.Length()) {
3566  Error("CheckGeometryFull","The option string must contain a letter. See method documentation.");
3567  return;
3568  }
3569  Bool_t checkoverlaps = opt.Contains("o");
3570  Bool_t checkcrossings = opt.Contains("b");
3571  Double_t vertex[3];
3572  vertex[0] = vx;
3573  vertex[1] = vy;
3574  vertex[2] = vz;
3575  GetGeomPainter()->CheckGeometryFull(checkoverlaps,checkcrossings,ntracks,vertex);
3576 }
3577 
3578 ////////////////////////////////////////////////////////////////////////////////
3579 /// Perform last checks on the geometry
3580 
3581 void TGeoManager::CheckGeometry(Option_t * /*option*/)
3583  if (fgVerboseLevel>0) Info("CheckGeometry","Fixing runtime shapes...");
3584  TIter next(fShapes);
3585  TIter nextv(fVolumes);
3586  TGeoShape *shape;
3587  TGeoVolume *vol;
3588  Bool_t has_runtime = kFALSE;
3589  while ((shape = (TGeoShape*)next())) {
3590  if (shape->IsRunTimeShape()) {
3591  has_runtime = kTRUE;
3592  }
3593  if (fIsGeomReading) shape->AfterStreamer();
3595  if (!shape->TestShapeBit(TGeoShape::kGeoClosedShape)) shape->ComputeBBox();
3596  }
3597  if (has_runtime) fTopNode->CheckShapes();
3598  else if (fgVerboseLevel>0) Info("CheckGeometry","...Nothing to fix");
3599  // Compute bounding box for assemblies
3601  while ((vol = (TGeoVolume*)nextv())) {
3602  if (vol->IsAssembly()) vol->GetShape()->ComputeBBox();
3603  else if (vol->GetMedium() == dummy) {
3604  Warning("CheckGeometry", "Volume \"%s\" has no medium: assigned dummy medium and material", vol->GetName());
3605  vol->SetMedium(dummy);
3606  }
3607  }
3608 }
3609 
3610 ////////////////////////////////////////////////////////////////////////////////
3611 /// Check all geometry for illegal overlaps within a limit OVLP.
3612 
3613 void TGeoManager::CheckOverlaps(Double_t ovlp, Option_t * option)
3615  if (!fTopNode) {
3616  Error("CheckOverlaps","Top node not set");
3617  return;
3618  }
3619  fTopNode->CheckOverlaps(ovlp,option);
3620 }
3621 
3622 ////////////////////////////////////////////////////////////////////////////////
3623 /// Prints the current list of overlaps.
3624 
3625 void TGeoManager::PrintOverlaps() const
3627  if (!fOverlaps) return;
3628  Int_t novlp = fOverlaps->GetEntriesFast();
3629  if (!novlp) return;
3630  TGeoManager *geom = (TGeoManager*)this;
3631  geom->GetGeomPainter()->PrintOverlaps();
3632 }
3633 
3634 ////////////////////////////////////////////////////////////////////////////////
3635 /// Estimate weight of volume VOL with a precision SIGMA(W)/W better than PRECISION.
3636 /// Option can be "v" - verbose (default)
3637 
3638 Double_t TGeoManager::Weight(Double_t precision, Option_t *option)
3640  GetGeomPainter();
3641  TString opt(option);
3642  opt.ToLower();
3643  Double_t weight;
3644  TGeoVolume *volume = fTopVolume;
3645  if (opt.Contains("v")) {
3646  if (opt.Contains("a")) {
3647  if (fgVerboseLevel>0) Info("Weight", "Computing analytically weight of %s", volume->GetName());
3648  weight = volume->WeightA();
3649  if (fgVerboseLevel>0) Info("Weight", "Computed weight: %f [kg]\n", weight);
3650  return weight;
3651  }
3652  if (fgVerboseLevel>0) {
3653  Info("Weight", "Estimating weight of %s with %g %% precision", fTopVolume->GetName(), 100.*precision);
3654  printf(" event weight err\n");
3655  printf("========================================\n");
3656  }
3657  }
3658  weight = fPainter->Weight(precision, option);
3659  return weight;
3660 }
3661 
3662 ////////////////////////////////////////////////////////////////////////////////
3663 /// computes the total size in bytes of the branch starting with node.
3664 /// The option can specify if all the branch has to be parsed or only the node
3665 
3666 ULong_t TGeoManager::SizeOf(const TGeoNode * /*node*/, Option_t * /*option*/)
3668  return 0;
3669 }
3670 
3671 ////////////////////////////////////////////////////////////////////////////////
3672 /// Stream an object of class TGeoManager.
3673 
3674 void TGeoManager::Streamer(TBuffer &R__b)
3675 {
3676  if (R__b.IsReading()) {
3677  R__b.ReadClassBuffer(TGeoManager::Class(), this);
3679  CloseGeometry();
3682  } else {
3683  R__b.WriteClassBuffer(TGeoManager::Class(), this);
3684  }
3685 }
3686 
3687 ////////////////////////////////////////////////////////////////////////////////
3688 /// Execute mouse actions on this manager.
3689 
3690 void TGeoManager::ExecuteEvent(Int_t event, Int_t px, Int_t py)
3692  if (!fPainter) return;
3693  fPainter->ExecuteManagerEvent(this, event, px, py);
3694 }
3695 
3696 ////////////////////////////////////////////////////////////////////////////////
3697 /// Export this geometry to a file
3698 ///
3699 /// - Case 1: root file or root/xml file
3700 /// if filename end with ".root". The key will be named name
3701 /// By default the geometry is saved without the voxelisation info.
3702 /// Use option 'v" to save the voxelisation info.
3703 /// if filename end with ".xml" a root/xml file is produced.
3704 ///
3705 /// - Case 2: C++ script
3706 /// if filename end with ".C"
3707 ///
3708 /// - Case 3: gdml file
3709 /// if filename end with ".gdml"
3710 /// NOTE that to use this option, the PYTHONPATH must be defined like
3711 /// export PYTHONPATH=$ROOTSYS/lib:$ROOTSYS/geom/gdml
3712 ///
3713 
3714 Int_t TGeoManager::Export(const char *filename, const char *name, Option_t *option)
3716  TString sfile(filename);
3717  if (sfile.Contains(".C")) {
3718  //Save geometry as a C++ script
3719  if (fgVerboseLevel>0) Info("Export","Exporting %s %s as C++ code", GetName(), GetTitle());
3720  fTopVolume->SaveAs(filename);
3721  return 1;
3722  }
3723  if (sfile.Contains(".gdml")) {
3724  //Save geometry as a gdml file
3725  if (fgVerboseLevel>0) Info("Export","Exporting %s %s as gdml code", GetName(), GetTitle());
3726  //C++ version
3727  TString cmd ;
3728  cmd = TString::Format("TGDMLWrite::StartGDMLWriting(gGeoManager,\"%s\",\"%s\")", filename, option);
3729  gROOT->ProcessLineFast(cmd);
3730  return 1;
3731  }
3732  if (sfile.Contains(".root") || sfile.Contains(".xml")) {
3733  //Save geometry as a root file
3734  TFile *f = TFile::Open(filename,"recreate");
3735  if (!f || f->IsZombie()) {
3736  Error("Export","Cannot open file");
3737  return 0;
3738  }
3739  TString keyname = name;
3740  if (keyname.IsNull()) keyname = GetName();
3741  TString opt = option;
3742  opt.ToLower();
3743  if (opt.Contains("v")) {
3744  fStreamVoxels = kTRUE;
3745  if (fgVerboseLevel>0) Info("Export","Exporting %s %s as root file. Optimizations streamed.", GetName(), GetTitle());
3746  } else {
3748  if (fgVerboseLevel>0) Info("Export","Exporting %s %s as root file. Optimizations not streamed.", GetName(), GetTitle());
3749  }
3750  Int_t nbytes = Write(keyname);
3752  delete f;
3753  return nbytes;
3754  }
3755  return 0;
3756 }
3757 
3758 ////////////////////////////////////////////////////////////////////////////////
3759 /// Lock current geometry so that no other geometry can be imported.
3760 
3763  fgLock = kTRUE;
3764 }
3765 
3766 ////////////////////////////////////////////////////////////////////////////////
3767 /// Unlock current geometry.
3768 
3771  fgLock = kFALSE;
3772 }
3773 
3774 ////////////////////////////////////////////////////////////////////////////////
3775 /// Check lock state.
3776 
3779  return fgLock;
3780 }
3781 
3782 ////////////////////////////////////////////////////////////////////////////////
3783 /// Set verbosity level (static function).
3784 /// - 0 - suppress messages related to geom-painter visibility level
3785 /// - 1 - default value
3786 
3789  return fgVerboseLevel;
3790 }
3791 
3792 ////////////////////////////////////////////////////////////////////////////////
3793 /// Return current verbosity level (static function).
3794 
3797  fgVerboseLevel = vl;
3798 }
3799 
3800 ////////////////////////////////////////////////////////////////////////////////
3801 ///static function
3802 ///Import a geometry from a gdml or ROOT file
3803 ///
3804 /// - Case 1: gdml
3805 /// if filename ends with ".gdml" the foreign geometry described with gdml
3806 /// is imported executing some python scripts in $ROOTSYS/gdml.
3807 /// NOTE that to use this option, the PYTHONPATH must be defined like
3808 /// export PYTHONPATH=$ROOTSYS/lib:$ROOTSYS/gdml
3809 ///
3810 /// - Case 2: root file (.root) or root/xml file (.xml)
3811 /// Import in memory from filename the geometry with key=name.
3812 /// if name="" (default), the first TGeoManager object in the file is returned.
3813 ///
3814 /// Note that this function deletes the current gGeoManager (if one)
3815 /// before importing the new object.
3816 
3817 TGeoManager *TGeoManager::Import(const char *filename, const char *name, Option_t * /*option*/)
3819  if (fgLock) {
3820  ::Warning("TGeoManager::Import", "TGeoMananager in lock mode. NOT IMPORTING new geometry");
3821  return NULL;
3822  }
3823  if (!filename) return 0;
3824  if (fgVerboseLevel>0) ::Info("TGeoManager::Import","Reading geometry from file: %s",filename);
3825 
3826  if (gGeoManager) delete gGeoManager;
3827  gGeoManager = 0;
3828 
3829  if (strstr(filename,".gdml")) {
3830  // import from a gdml file
3831  new TGeoManager("GDMLImport", "Geometry imported from GDML");
3832  TString cmd = TString::Format("TGDMLParse::StartGDML(\"%s\")", filename);
3833  TGeoVolume* world = (TGeoVolume*)gROOT->ProcessLineFast(cmd);
3834 
3835  if(world == 0) {
3836  ::Error("TGeoManager::Import", "Cannot open file");
3837  }
3838  else {
3839  gGeoManager->SetTopVolume(world);
3840  gGeoManager->CloseGeometry();
3841  gGeoManager->DefaultColors();
3842  }
3843  } else {
3844  // import from a root file
3845  TDirectory::TContext ctxt;
3846  // in case a web file is specified, use the cacheread option to cache
3847  // this file in the cache directory
3848  TFile *f = 0;
3849  if (strstr(filename,"http")) f = TFile::Open(filename,"CACHEREAD");
3850  else f = TFile::Open(filename);
3851  if (!f || f->IsZombie()) {
3852  ::Error("TGeoManager::Import", "Cannot open file");
3853  return 0;
3854  }
3855  if (name && strlen(name) > 0) {
3856  gGeoManager = (TGeoManager*)f->Get(name);
3857  } else {
3858  TIter next(f->GetListOfKeys());
3859  TKey *key;
3860  while ((key = (TKey*)next())) {
3861  if (strcmp(key->GetClassName(),"TGeoManager") != 0) continue;
3862  gGeoManager = (TGeoManager*)key->ReadObj();
3863  break;
3864  }
3865  }
3866  delete f;
3867  }
3868  if (!gGeoManager) return 0;
3869  if (!gROOT->GetListOfGeometries()->FindObject(gGeoManager)) gROOT->GetListOfGeometries()->Add(gGeoManager);
3870  if (!gROOT->GetListOfBrowsables()->FindObject(gGeoManager)) gROOT->GetListOfBrowsables()->Add(gGeoManager);
3871  gGeoManager->UpdateElements();
3872  return gGeoManager;
3873 }
3874 
3875 ////////////////////////////////////////////////////////////////////////////////
3876 /// Update element flags when geometry is loaded from a file.
3877 
3880  if (!fElementTable) return;
3881  TIter next(fMaterials);
3882  TGeoMaterial *mat;
3883  TGeoMixture *mix;
3884  TGeoElement *elem, *elem_table;
3885  Int_t i, nelem;
3886  while ((mat=(TGeoMaterial*)next())) {
3887  if (mat->IsMixture()) {
3888  mix = (TGeoMixture*)mat;
3889  nelem = mix->GetNelements();
3890  for (i=0; i<nelem; i++) {
3891  elem = mix->GetElement(i);
3892  if (!elem) continue;
3893  elem_table = fElementTable->GetElement(elem->Z());
3894  if (!elem_table) continue;
3895  if (elem != elem_table) {
3896  elem_table->SetDefined(elem->IsDefined());
3897  elem_table->SetUsed(elem->IsUsed());
3898  } else {
3899  elem_table->SetDefined();
3900  }
3901  }
3902  } else {
3903  elem = mat->GetElement();
3904  if (!elem) continue;
3905  elem_table = fElementTable->GetElement(elem->Z());
3906  if (!elem_table) continue;
3907  if (elem != elem_table) {
3908  elem_table->SetDefined(elem->IsDefined());
3909  elem_table->SetUsed(elem->IsUsed());
3910  } else {
3911  elem_table->SetUsed();
3912  }
3913  }
3914  }
3915 }
3916 
3917 ////////////////////////////////////////////////////////////////////////////////
3918 /// Initialize PNE array for fast access via index and unique-id.
3919 
3922  if (fHashPNE) {
3923  fArrayPNE = new TObjArray(fHashPNE->GetSize());
3924  TIter next(fHashPNE);
3925  TObject *obj;
3926  while ((obj = next())) {
3927  fArrayPNE->Add(obj);
3928  }
3929  return kTRUE;
3930  }
3931  return kFALSE;
3932 }
3933 
3934 ////////////////////////////////////////////////////////////////////////////////
3935 /// Get time cut for drawing tracks.
3936 
3939  tmin = fTmin;
3940  tmax = fTmax;
3941  return fTimeCut;
3942 }
3943 
3944 ////////////////////////////////////////////////////////////////////////////////
3945 /// Set time cut interval for drawing tracks. If called with no arguments, time
3946 /// cut will be disabled.
3947 
3950  fTmin = tmin;
3951  fTmax = tmax;
3952  if (tmin==0 && tmax==999) fTimeCut = kFALSE;
3953  else fTimeCut = kTRUE;
3954  if (fTracks && !IsAnimatingTracks()) ModifiedPad();
3955 }
3956 
3957 ////////////////////////////////////////////////////////////////////////////////
3958 /// Convert coordinates from master volume frame to top.
3959 
3960 void TGeoManager::MasterToTop(const Double_t *master, Double_t *top) const
3962  GetCurrentNavigator()->MasterToLocal(master, top);
3963 }
3964 
3965 ////////////////////////////////////////////////////////////////////////////////
3966 /// Convert coordinates from top volume frame to master.
3967 
3968 void TGeoManager::TopToMaster(const Double_t *top, Double_t *master) const
3970  GetCurrentNavigator()->LocalToMaster(top, master);
3971 }
3972 
3973 ////////////////////////////////////////////////////////////////////////////////
3974 /// Create a parallel world for prioritised navigation. This can be populated
3975 /// with physical nodes and can be navigated independently using its API.
3976 /// In case the flag SetUseParallelWorldNav is set, any navigation query in the
3977 /// main geometry is checked against the parallel geometry, which gets priority
3978 /// in case of overlaps with the main geometry volumes.
3979 
3982  fParallelWorld = new TGeoParallelWorld(name, this);
3983  return fParallelWorld;
3984 }
3985 
3986 ////////////////////////////////////////////////////////////////////////////////
3987 /// Activate/deactivate usage of parallel world navigation. Can only be done if
3988 /// there is a parallel world. Activating navigation will automatically close
3989 /// the parallel geometry.
3990 
3993  if (!fParallelWorld) {
3994  Error("SetUseParallelWorldNav", "No parallel world geometry defined. Use CreateParallelWorld.");
3995  return;
3996  }
3997  if (!flag) {
3998  fUsePWNav = flag;
3999  return;
4000  }
4001  if (!fClosed) {
4002  Error("SetUseParallelWorldNav", "The geometry must be closed first");
4003  return;
4004  }
4005  // Closing the parallel world geometry is mandatory
4007 }
const int nx
Definition: kalman.C:16
void SetTopVisible(Bool_t vis=kTRUE)
make top volume visible on screen
void SetPhysicalNode(TGeoPhysicalNode *node)
Setter for the corresponding physical node.
TObjArray * fShapes
Definition: TGeoManager.h:83
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
Definition: TBrowser.cxx:261
TGeoVolumeMulti * MakeVolumeMulti(const char *name, TGeoMedium *medium)
Make a TGeoVolumeMulti handling a list of volumes.
void CheckPoint(Double_t x=0, Double_t y=0, Double_t z=0, Option_t *option="")
Classify a given point. See TGeoChecker::CheckPoint().
void ClearThreadData() const
Double_t fPhimin
Definition: TGeoManager.h:51
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:778
virtual Int_t GetVisLevel() const =0
void GetBranchNames(Int_t *names) const
Fill volume names of current branch into an array.
Int_t AddShape(TGeoShape *shape)
Add a shape to the list. Returns index of the shape in list.
TGeoNode * SamplePoints(Int_t npoints, Double_t &dist, Double_t epsil=1E-5, const char *g3path="")
shoot npoints randomly in a box of 1E-5 around current point.
Bool_t IsReading() const
Definition: TBuffer.h:81
Volume families.
Definition: TGeoVolume.h:256
TList * fMedia
Definition: TGeoManager.h:92
A node containing local transformation.
Definition: TGeoNode.h:149
void CheckGeometryFull(Int_t ntracks=1000000, Double_t vx=0., Double_t vy=0., Double_t vz=0., Option_t *option="ob")
Geometry checking.
TGeoNode * CrossBoundaryAndLocate(Bool_t downwards, TGeoNode *skipnode)
Cross next boundary and locate within current node The current point must be on the boundary of fCurr...
void ModifiedPad() const
Send "Modified" signal to painter.
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
void PrintOverlaps() const
Prints the current list of overlaps.
TObjArray * fVolumes
Definition: TGeoManager.h:84
Bool_t GotoSafeLevel()
Go upwards the tree until a non-overlapping node.
An array of TObjects.
Definition: TObjArray.h:37
virtual Int_t CountVisibleNodes()=0
TGeoHMatrix * fGLMatrix
Definition: TGeoManager.h:111
TGeoPhysicalNode * MakePhysicalNode(const char *path=0)
Makes a physical node corresponding to a path.
TGeoNode * InitTrack(const Double_t *point, const Double_t *dir)
Initialize current point and current direction vector (normalized) in MARS.
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.
virtual void GetViewAngles(Double_t &, Double_t &, Double_t &)
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
void DoRestoreState()
Restore a backed-up state without affecting the cache stack.
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:409
TGeoVolume * MakeXtru(const char *name, TGeoMedium *medium, Int_t nz)
Make a TGeoXtru-shaped volume with nz planes.
void AddLast(TObject *obj)
Add object at the end of the list.
Definition: THashList.cxx:90
Bool_t GetTminTmax(Double_t &tmin, Double_t &tmax) const
Get time cut for drawing tracks.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:847
void CheckGeometry(Option_t *option="")
Perform last checks on the geometry.
Int_t GetCurrentNodeId() const
Get the unique ID of the current node.
void CheckShape(TGeoShape *shape, Int_t testNo, Int_t nsamples, Option_t *option)
Test for shape navigation methods.
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.
The manager class for any TGeo geometry.
Definition: TGeoManager.h:37
TGeoVolumeAssembly * MakeVolumeAssembly(const char *name)
Make an assembly of volumes.
virtual void CreateThreadData(Int_t nthreads)
Definition: TGeoVolume.cxx:431
Box class.
Definition: TGeoBBox.h:17
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.
Bool_t fActivity
flag for GL reflections
Definition: TGeoManager.h:78
virtual void EditGeometry(Option_t *option="")=0
void Release()
Definition: TGeoVolume.h:143
void ClearAttributes()
Reset all attributes to default ones.
Volume assemblies.
Definition: TGeoVolume.h:307
void Voxelize(Option_t *option)
build the voxels for this volume
Table of elements.
Definition: TGeoElement.h:357
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.
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.
void SetFinder(TGeoPatternFinder *finder)
Definition: TGeoVolume.h:234
virtual void ModifiedPad(Bool_t update=kFALSE) const =0
void SetAllIndex()
Assigns uid&#39;s for all materials,media and matrices.
Bool_t fMatrixTransform
flag that the list of physical nodes has to be drawn
Definition: TGeoManager.h:76
virtual void Sort(Int_t upto=kMaxInt)
If objects in array are sortable (i.e.
Definition: TObjArray.cxx:744
virtual Double_t * GetViewBox()=0
TGeoNode * InitTrack(const Double_t *point, const Double_t *dir)
Initialize current point and current direction vector (normalized) in MARS.
virtual void Clear(Option_t *option="")
Remove all objects from the array.
Definition: TObjArray.cxx:298
float Float_t
Definition: RtypesCore.h:53
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.
virtual Double_t GetDensity() const
Definition: TGeoMaterial.h:87
Bool_t IsSamePoint(Double_t x, Double_t y, Double_t z) const
Check if a new point with given coordinates is the same as the last located one.
void BombTranslation(const Double_t *tr, Double_t *bombtr)
Get the new &#39;bombed&#39; translation vector according current exploded view mode.
Bool_t IsOverlapping() const
Definition: TGeoNode.h:102
virtual TVirtualGeoTrack * AddTrack(Int_t id, Int_t pdgcode, TObject *particle)=0
const char Option_t
Definition: RtypesCore.h:62
Geometrical transformation package.
Definition: TGeoMatrix.h:38
Double_t Safety(Bool_t inside=kFALSE)
Compute safe distance from the current point.
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:329
Definition: Rtypes.h:56
Int_t ReplaceVolume(TGeoVolume *vorig, TGeoVolume *vnew)
Replaces all occurrences of VORIG with VNEW in the geometry tree.
TGeoMaterial * Mixture(const char *name, Float_t *a, Float_t *z, Double_t dens, Int_t nelem, Float_t *wmat, Int_t uid)
Create mixture OR COMPOUND IMAT as composed by THE BASIC nelem materials defined by arrays A...
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.
TGeoNode * SearchNode(Bool_t downwards=kFALSE, const TGeoNode *skipnode=0)
Returns the deepest node containing fPoint, which must be set a priori.
static TGeoMedium * DummyMedium()
Definition: TGeoVolume.cxx:439
TGeoNode * GetNode(const char *name) const
get the pointer to a daughter node
void Test(Int_t npoints=1000000, Option_t *option="")
Check time of finding "Where am I" for n points.
Int_t Z() const
Definition: TGeoElement.h:66
void CdUp()
Go one level up in geometry.
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:640
void CheckOverlaps(Double_t ovlp=0.1, Option_t *option="")
Check all geometry for illegal overlaps within a limit OVLP.
void SetRTmode(Int_t mode)
Change raytracing mode.
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
std::map< std::thread::id, Int_t > ThreadsMap_t
Definition: TGeoManager.h:99
virtual void Test(Int_t npoints, Option_t *option)=0
THashList * fHashVolumes
Definition: TGeoManager.h:120
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:159
TGeoMaterial * GetMaterial() const
Definition: TGeoMedium.h:52
TVirtualGeoTrack * GetTrack(Int_t index)
Definition: TGeoManager.h:372
void Init()
Initialize manager class.
#define BIT(n)
Definition: Rtypes.h:75
TH1 * h
Definition: legend2.C:5
Int_t GetTrackIndex(Int_t id) const
Get index for track id, -1 if not found.
static Int_t fgMaxDaughters
Maximum level in geometry.
Definition: TGeoManager.h:44
void GetBranchOnlys(Int_t *isonly) const
Fill node copy numbers of current branch into an array.
An identity transformation.
Definition: TGeoMatrix.h:371
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:48
TGeoElementTable * GetElementTable()
Returns material table. Creates it if not existing.
Int_t GetSafeLevel() const
Go upwards the tree until a non-overlapping node.
virtual void CheckShape(TGeoShape *shape, Int_t testNo, Int_t nsamples, Option_t *option)=0
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
virtual Double_t Weight(Double_t precision, Option_t *option="v")=0
void SetVisBranch()
Set branch type visibility.
Definition: TGeoAtt.cxx:67
Definition: Rtypes.h:55
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
Bool_t fMatrixReflection
flag for using GL matrix
Definition: TGeoManager.h:77
virtual TGeoElement * GetElement(Int_t i=0) const
Retrieve the pointer to the element corresponding to component I.
TGeoVolume * GetVolume(const char *name) const
Search for a named volume. All trailing blanks stripped.
TVirtualGeoTrack * fCurrentTrack
Definition: TGeoManager.h:65
Int_t fNtracks
Definition: TGeoManager.h:63
void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: THashList.cxx:184
Int_t fNNodes
upper time limit for tracks drawing
Definition: TGeoManager.h:55
static Int_t GetVerboseLevel()
Set verbosity level (static function).
static void SetVerboseLevel(Int_t vl)
Return current verbosity level (static function).
#define gROOT
Definition: TROOT.h:375
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.
Int_t fPdgId[1024]
Definition: TGeoManager.h:67
virtual TObject * Remove(TObject *obj)
Remove object from array.
Definition: TObjArray.cxx:653
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
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.
virtual void PrintOverlaps() const =0
Int_t GetId() const
Definition: TGeoMedium.h:48
Int_t LoadPlugin()
Load the plugin library for this handler.
void ResetUserData()
Sets all pointers TGeoVolume::fField to NULL.
TGeoVolume * Volume(const char *name, const char *shape, Int_t nmed, Float_t *upar, Int_t npar=0)
Create a volume in GEANT3 style.
void ViewLeaves(Bool_t flag=kTRUE)
Set visualization option (leaves only OR all volumes)
void InspectState() const
Inspects path and all flags for the current state.
Basic string class.
Definition: TString.h:129
Matrix class used for computing global transformations Should NOT be used for node definition...
Definition: TGeoMatrix.h:408
Base class describing materials.
Definition: TGeoMaterial.h:29
void GetBranchNumbers(Int_t *copyNumbers, Int_t *volumeNumbers) const
Fill node copy numbers of current branch into an array.
static void ClearThreadsMap()
Clear the current map of threads.
void GetBranchNames(Int_t *names) const
Fill volume names of current branch into an array.
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1099
TObjArray * fUniqueVolumes
Definition: TGeoManager.h:112
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
TGeoNodeCache * GetCache() const
TGeoNode * fTopNode
top level volume in geometry
Definition: TGeoManager.h:109
Bool_t fIsNodeSelectable
switch ON/OFF volume activity (default OFF - all volumes active))
Definition: TGeoManager.h:79
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:202
void OptimizeVoxels(const char *filename="tgeovox.C")
Optimize voxelization type for all volumes. Save best choice in a macro.
static Int_t Parse(const char *expr, TString &expr1, TString &expr2, TString &expr3)
Parse a string boolean expression and do a syntax check.
Int_t fVisOption
Definition: TGeoManager.h:60
TVirtualGeoTrack * MakeTrack(Int_t id, Int_t pdgcode, TObject *particle)
Makes a primary track but do not attach it to the list of tracks.
Definition: Rtypes.h:56
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.
Definition: Rtypes.h:56
TGeoVolume * Division(const char *name, const char *mother, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed=0, Option_t *option="")
Create a new volume by dividing an existing one (GEANT3 like)
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.
Int_t GetNvert() const
Definition: TGeoXtru.h:94
virtual void ExecuteManagerEvent(TGeoManager *geom, Int_t event, Int_t px, Int_t py)=0
#define NULL
Definition: RtypesCore.h:88
TGeoShape * fClippingShape
Definition: TGeoManager.h:113
virtual void RandomPoints(const TGeoVolume *vol, Int_t npoints, Option_t *option="")=0
TObject * At(Int_t idx) const
Definition: TObjArray.h:165
Bool_t fDrawExtra
Definition: TGeoManager.h:75
TObjArray * fPdgNames
Definition: TGeoManager.h:89
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:213
void SetBombFactors(Double_t bombx=1.3, Double_t bomby=1.3, Double_t bombz=1.3, Double_t bombr=1.3)
Set factors that will "bomb" all translations in cartesian and cylindrical coordinates.
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
void AnimateTracks(Double_t tmin=0, Double_t tmax=5E-8, Int_t nframes=200, Option_t *option="/*")
Draw animation of tracks.
void Refresh()
Refresh this physical node.
Int_t GetId() const
virtual void DefaultAngles()=0
TGeoVoxelFinder * GetVoxels() const
Getter for optimization structure.
Int_t GetVisLevel() const
Returns current depth to which geometry is drawn.
Bool_t InitArrayPNE() const
Initialize PNE array for fast access via index and unique-id.
static void SetNavigatorsLock(Bool_t flag)
Set the lock for navigators.
Int_t GetRefCount() const
Definition: TGeoVolume.h:137
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.
const char * GetPdgName(Int_t pdg) const
Get name for given pdg code;.
Int_t GetSafeLevel() const
Go upwards the tree until a non-overlapping node.
TGeoVolume * GetMotherVolume() const
Definition: TGeoNode.h:89
void GetBranchOnlys(Int_t *isonly) const
Fill node copy numbers of current branch into an array.
TObjArray * fArrayPNE
Definition: TGeoManager.h:123
TObjArray * fGShapes
Definition: TGeoManager.h:86
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:687
virtual Int_t GetByteCount() const
get the total size in bytes for this volume
void SetVisibility(TObject *obj, Bool_t vis)
Set visibility for a volume.
Bool_t IsSameLocation(Double_t x, Double_t y, Double_t z, Bool_t change=kFALSE)
Checks if point (x,y,z) is still in the current node.
TGeoHMatrix * GetHMatrix()
Return stored current matrix (global matrix of the next touched node).
void SetVisDensity(Double_t dens=0.01)
Set density threshold.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:501
TGeoMedium * Medium(const char *name, Int_t numed, Int_t nmat, Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd, Double_t stemax, Double_t deemax, Double_t epsil, Double_t stmin)
Create tracking medium.
static Int_t GetNumThreads()
Returns number of threads that were set to use geometry.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3909
Int_t CountNodes(Int_t nlevels=1000, Int_t option=0)
Count total number of subnodes starting from this volume, nlevels down.
Definition: TGeoVolume.cxx:754
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:112
TObjArray * fOverlaps
Definition: TGeoManager.h:94
Int_t fNsegments
Definition: TGeoManager.h:62
virtual void SetClippingShape(TGeoShape *shape)=0
void InspectState() const
Inspects path and all flags for the current state.
Bool_t fIsGeomCleaning
flag set when reading geometry
Definition: TGeoManager.h:72
void DoRestoreState()
Restore a backed-up state without affecting the cache stack.
TObjArray * fMatrices
current painter
Definition: TGeoManager.h:82
void ResetState()
Reset current state flags.
Int_t GetNdaughters() const
Definition: TGeoVolume.h:350
TGeoMaterial * GetMaterial(const char *matname) const
Search for a named material. All trailing blanks stripped.
void CdNode(Int_t nodeid)
Change current path to point to the node having this id.
TGeoParallelWorld * fParallelWorld
Definition: TGeoManager.h:132
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.
#define SafeDelete(p)
Definition: RConfig.h:499
virtual Int_t Export(const char *filename, const char *name="", Option_t *option="vg")
Export this geometry to a file.
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.
Sequenceable collection abstract base class.
Double_t x[n]
Definition: legend1.C:17
TGeoNode * FindNextDaughterBoundary(Double_t *point, Double_t *dir, Int_t &idaughter, Bool_t compmatrix=kFALSE)
Computes as fStep the distance to next daughter of the current volume.
void UpdateElements()
Update element flags when geometry is loaded from a file.
TGeoPNEntry * SetAlignableEntry(const char *unique_name, const char *path, Int_t uid=-1)
Creates an alignable object with unique name corresponding to a path and adds it to the list of align...
static Bool_t fgLock
mutex for navigator booking in MT mode
Definition: TGeoManager.h:41
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:2345
void SetVolumeAttribute(const char *name, const char *att, Int_t val)
Set volume attributes in G3 style.
void RandomRays(Int_t nrays=1000, Double_t startx=0, Double_t starty=0, Double_t startz=0, const char *target_vol=0, Bool_t check_norm=kFALSE)
Randomly shoot nrays and plot intersections with surfaces for current top node.
virtual void GrabFocus(Int_t nfr=0, Double_t dlong=0, Double_t dlat=0, Double_t dpsi=0)=0
Int_t GetLevel() const
Definition: TGeoNode.h:274
void Class()
Definition: Class.C:29
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
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.
Int_t AddTrack(Int_t id, Int_t pdgcode, TObject *particle=0)
Add a track to the list of tracks.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
A geometry iterator.
Definition: TGeoNode.h:243
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Definition: TObjArray.cxx:396
virtual void SetNsegments(Int_t nseg=20)=0
void CdDown(Int_t index)
Make a daughter of current node current.
void SetVisStreamed(Bool_t vis=kTRUE)
Mark attributes as "streamed to file".
Definition: TGeoAtt.cxx:123
const int ny
Definition: kalman.C:17
void CleanGarbage()
Clean temporary volumes and shapes from garbage collection.
THashList * fHashGVolumes
hash list of volumes providing fast search
Definition: TGeoManager.h:121
void ClearShape(const TGeoShape *shape)
Remove a shape from the list of shapes.
Double_t fTmax
lower time limit for tracks drawing
Definition: TGeoManager.h:54
static Bool_t IsLocked()
Check lock state.
THashList * fHashPNE
hash list of group volumes providing fast search
Definition: TGeoManager.h:122
void Browse(TBrowser *b)
Describe how to browse this object.
Bool_t IsUsed() const
Definition: TGeoElement.h:79
void SortOverlaps()
Sort overlaps by decreasing overlap distance. Extrusions comes first.
const char * GetPath() const
Get path to the current node in the form /node0/node1/...
TGeoVolume * MakeArb8(const char *name, TGeoMedium *medium, Double_t dz, Double_t *vertices=0)
Make an TGeoArb8 volume.
virtual void SetExplodedView(Int_t iopt=0)=0
virtual void BombTranslation(const Double_t *tr, Double_t *bombtr)=0
Base class for chemical elements.
Definition: TGeoElement.h:36
Bool_t IsDefined() const
Definition: TGeoElement.h:77
void GetBombFactors(Double_t &bombx, Double_t &bomby, Double_t &bombz, Double_t &bombr) const
Retrieve cartesian and radial bomb factors.
TGeoVolume * MakeReflectedVolume(const char *newname="") const
Make a copy of this volume which is reflected with respect to XY plane.
TGeoNavigator * fCurrentNavigator
Lock existing navigators.
Definition: TGeoManager.h:106
TGeoVolume * MakeXtru(const char *name, TGeoMedium *medium, Int_t nz)
Make a TGeoXtru-shaped volume with nz planes.
TGeoVolume * GetCurrentVolume() const
TGeoNavigator * GetCurrentNavigator() const
TGeoMedium * GetMedium() const
Definition: TGeoVolume.h:176
static Int_t GetMaxDaughters()
Return maximum number of daughters of a volume used in the geometry.
void TopToMaster(const Double_t *top, Double_t *master) const
Convert coordinates from top volume frame to master.
void CheckBoundaryErrors(Int_t ntracks=1000000, Double_t radius=-1.)
Check pushes and pulls needed to cross the next boundary with respect to the position given by FindNe...
Int_t AddVolume(TGeoVolume *volume)
Add a volume to the list. Returns index of the volume in list.
virtual Bool_t IsVisible() const
Definition: TGeoVolume.h:156
Bool_t CheckPath(const char *path) const
Check if a geometry path is valid without changing the state of the navigator.
TGeoVolume * fTopVolume
current volume
Definition: TGeoManager.h:108
Int_t GetVirtualLevel()
Find level of virtuality of current overlapping node (number of levels up having the same tracking me...
void LocalToMaster(const Double_t *local, Double_t *master) const
Definition: TGeoManager.h:507
TVirtualGeoTrack * GetParentTrackOfId(Int_t id) const
Get parent track with a given ID.
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.
Int_t fNPNEId
Definition: TGeoManager.h:125
virtual TGeoMatrix * GetMatrix() const =0
static Int_t fgNumThreads
Thread id&#39;s map.
Definition: TGeoManager.h:104
Bool_t InsertPNEId(Int_t uid, Int_t ientry)
Insert a PN entry in the sorted array of indexes.
ThreadsMap_t::const_iterator ThreadsMapIt_t
Definition: TGeoManager.h:100
virtual TVirtualGeoTrack * FindTrackWithId(Int_t id) const
Recursively search through this track for a daughter particle (at any depth) with the specified id...
virtual void CheckBoundaryReference(Int_t icheck=-1)=0
Bool_t IsRunTime() const
Definition: TGeoVolume.h:117
Int_t GetVisOption() const
Returns current depth to which geometry is drawn.
Base class for user-defined tracks attached to a geometry.
Double_t ATan2(Double_t, Double_t)
Definition: TMath.h:581
void SetClippingShape(TGeoShape *clip)
Set a user-defined shape as clipping for ray tracing.
TGeoMaterial * FindDuplicateMaterial(const TGeoMaterial *mat) const
Find if a given material duplicates an existing one.
TGeoVolume * MakeArb8(const char *name, TGeoMedium *medium, Double_t dz, Double_t *vertices=0)
Make an TGeoArb8 volume.
void SetMaxVisNodes(Int_t maxnodes=10000)
set the maximum number of visible nodes.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
virtual void SetBombFactors(Double_t bombx=1.3, Double_t bomby=1.3, Double_t bombz=1.3, Double_t bombr=1.3)=0
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.
void RestoreMasterVolume()
Restore the master volume of the geometry.
Bool_t fPhiCut
flag to notify that the manager is being destructed
Definition: TGeoManager.h:73
static ENewType IsCallingNew()
Static method returning the defConstructor flag passed to TClass::New().
Definition: TClass.cxx:5539
TH1F * h1
Definition: legend1.C:5
NavigatorsMap_t fNavigators
Definition: TGeoManager.h:102
TGeoNavigatorArray * GetListOfNavigators() const
Get list of navigators for the calling thread.
Bool_t fIsGeomReading
Definition: TGeoManager.h:71
Int_t fVisLevel
Definition: TGeoManager.h:61
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.
virtual void DrawCurrentPoint(Int_t color)=0
void ResetState()
Reset current state flags.
Int_t GetNAlignable(Bool_t with_uid=kFALSE) const
Retrieves number of PN entries with or without UID.
Int_t TransformVolumeToAssembly(const char *vname)
Transform all volumes named VNAME to assemblies. The volumes must be virtual.
TGeoNode * GetCurrentNode() const
Definition: TGeoManager.h:483
Bool_t IsAnimatingTracks() const
Definition: TGeoManager.h:384
static Int_t fgVerboseLevel
Lock preventing a second geometry to be loaded.
Definition: TGeoManager.h:42
The knowledge of the path to the objects that need to be misaligned is essential since there is no ot...
static TGeoVolumeAssembly * MakeAssemblyFromVolume(TGeoVolume *vol)
Make a clone of volume VOL but which is an assembly.
void RefreshPhysicalNodes(Bool_t lock=kTRUE)
Refresh physical nodes to reflect the actual geometry paths after alignment was applied.
virtual void ClearThreadData() const
Definition: TGeoVolume.cxx:423
virtual Double_t GetZ() const
Definition: TGeoMaterial.h:85
Int_t fMaxThreads
Definition: TGeoManager.h:128
Int_t * fKeyPNEId
Definition: TGeoManager.h:126
REAL * vertex
Definition: triangle.c:512
void SortNodes()
sort nodes by decreasing volume of the bounding box.
Bool_t fLoopVolumes
flag that geometry is closed
Definition: TGeoManager.h:69
Physical nodes are the actual &#39;touchable&#39; objects in the geometry, representing a path of positioned ...
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:698
TGeoPhysicalNode * MakeAlignablePN(const char *name)
Make a physical node from the path pointed by an alignable object with a given name.
TGeoNode * SearchNode(Bool_t downwards=kFALSE, const TGeoNode *skipnode=0)
Returns the deepest node containing fPoint, which must be set a priori.
void CdTop()
Make top level node the current node.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
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.
Class handling Boolean composition of shapes.
virtual TGeoNode * SamplePoints(Int_t npoints, Double_t &dist, Double_t epsil, const char *g3path)=0
virtual void SetTopVisible(Bool_t vis=kTRUE)=0
void GetBranchNumbers(Int_t *copyNumbers, Int_t *volumeNumbers) const
Fill node copy numbers of current branch into an array.
void SelectTrackingMedia()
Define different tracking media.
TGeoNode * FindNextBoundaryAndStep(Double_t stepmax=TGeoShape::Big(), Bool_t compsafe=kFALSE)
Compute distance to next boundary within STEPMAX.
Int_t GetUID(const char *volname) const
Retrieve unique id for a volume name. Return -1 if name not found.
Int_t AddOverlap(const TNamed *ovlp)
Add an illegal overlap/extrusion to the list.
TGeoVolumeAssembly * MakeVolumeAssembly(const char *name)
Make an assembly of volumes.
Double_t fTmin
highest range for phi cut
Definition: TGeoManager.h:53
void RemoveNavigator(const TGeoNavigator *nav)
Clear a single navigator.
TObjArray * fPhysicalNodes
Definition: TGeoManager.h:85
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Bool_t fTimeCut
Definition: TGeoManager.h:74
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:867
TGeoPNEntry * GetAlignableEntryByUID(Int_t uid) const
Retrieves an existing alignable object having a preset UID.
Int_t CountNodes(const TGeoVolume *vol=0, Int_t nlevels=10000, Int_t option=0)
Count the total number of nodes starting from a volume, nlevels down.
Int_t * fNodeIdArray
table of elements
Definition: TGeoManager.h:116
Int_t fNLevel
array of node id&#39;s
Definition: TGeoManager.h:117
void SetNeedRebuild(Bool_t flag=kTRUE)
void Clear(Option_t *option="")
Remove all objects from the list.
Definition: THashList.cxx:168
Int_t GetNsegments() const
Get number of segments approximating circles.
virtual void AfterStreamer()
Definition: TGeoShape.h:94
Bool_t cd(const char *path="")
Browse the tree of nodes starting from top node according to pathname.
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:42
Double_t Safety(Bool_t inside=kFALSE)
Compute safe distance from the current point.
void LocalToMaster(const Double_t *local, Double_t *master) const
Base abstract class for all shapes.
Definition: TGeoShape.h:25
void CheckOverlaps(Double_t ovlp=0.1, Option_t *option="")
Check overlaps bigger than OVLP hierarchically, starting with this node.
Definition: TGeoNode.cxx:214
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:222
void Matrix(Int_t index, Double_t theta1, Double_t phi1, Double_t theta2, Double_t phi2, Double_t theta3, Double_t phi3)
Create rotation matrix named &#39;mat<index>&#39;.
Int_t AddMaterial(TGeoMaterial *material)
Add a material to the list. Returns index of the material in list.
void SetMotherVolume(TGeoVolume *mother)
Definition: TGeoNode.h:120
TRandom2 r(17)
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.
static void LockGeometry()
Lock current geometry so that no other geometry can be imported.
TGeoMedium * Medium(const char *name, Int_t numed, Int_t nmat, Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd, Double_t stemax, Double_t deemax, Double_t epsil, Double_t stmin)
Create tracking medium.
Class describing rotation + translation.
Definition: TGeoMatrix.h:283
TGeoNode * Step(Bool_t is_geom=kTRUE, Bool_t cross=kTRUE)
Make a rectilinear step of length fStep from current point (fPoint) on current direction (fDirection)...
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
void SaveAttributes(std::ostream &out)
save attributes for this node
Definition: TGeoNode.cxx:439
void SetField(TObject *field)
Definition: TGeoVolume.h:221
Int_t GetVirtualLevel()
Find level of virtuality of current overlapping node (number of levels up having the same tracking me...
virtual void CheckGeometryFull(Bool_t checkoverlaps=kTRUE, Bool_t checkcrossings=kTRUE, Int_t nrays=10000, const Double_t *vertex=NULL)=0
void Node(const char *name, Int_t nr, const char *mother, Double_t x, Double_t y, Double_t z, Int_t irot, Bool_t isOnly, Float_t *upar, Int_t npar=0)
Create a node called <name_nr> pointing to the volume called <name> as daughter of the volume called ...
TGeoNode * FindNextBoundaryAndStep(Double_t stepmax=TGeoShape::Big(), Bool_t compsafe=kFALSE)
Compute distance to next boundary within STEPMAX.
void DefaultColors()
Set default volume colors according to A of material.
TVirtualGeoTrack * GetMother() const
Int_t fExplodedView
Definition: TGeoManager.h:59
TGeoNavigator * AddNavigator()
Add a navigator in the list of navigators.
Long_t ExecPlugin(int nargs, const T &... params)
Bool_t IsInPhiRange() const
True if current node is in phi range.
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:482
TGeoManager()
Default constructor.
Double_t * FindNormalFast()
Computes fast normal to next crossed boundary, assuming that the current point is close enough to the...
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.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:679
virtual Bool_t IsComposite() const
Definition: TGeoShape.h:130
Double_t * FindNormal(Bool_t forward=kTRUE)
Computes normal vector to the next surface that will be or was already crossed when propagating on a ...
virtual void GetBombFactors(Double_t &bombx, Double_t &bomby, Double_t &bombz, Double_t &bombr) const =0
static Int_t fgMaxLevel
Verbosity level for Info messages (no IO).
Definition: TGeoManager.h:43
void SetTransparency(Char_t transparency=0)
Definition: TGeoVolume.h:220
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:436
void CdNode(Int_t nodeid)
Change current path to point to the node having this id.
virtual Int_t GetNelements() const
Definition: TGeoMaterial.h:176
TVirtualGeoTrack * GetTrackOfId(Int_t id) const
Get track with a given ID.
Double_t fPhimax
lowest range for phi cut
Definition: TGeoManager.h:52
TGeoVolumeMulti * MakeVolumeMulti(const char *name, TGeoMedium *medium)
Make a TGeoVolumeMulti handling a list of volumes.
void SetPdgName(Int_t pdg, const char *name)
Set a name for a particle having a given pdg.
void SetMatrix(const TGeoMatrix *matrix)
Matrix setter.
Definition: TGeoNode.cxx:816
Bool_t IsMultiThread() const
Definition: TGeoManager.h:436
void RefreshPhysicalNodes()
Refresh the node pointers and re-voxelize.
Int_t fMaxVisNodes
Definition: TGeoManager.h:64
Int_t GetEntriesFast() const
Definition: TObjArray.h:64
void UnmarkSaved()
Reset SavePrimitive bits.
virtual void EstimateCameraMove(Double_t, Double_t, Double_t *, Double_t *)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
void DrawCurrentPoint(Int_t color=2)
Draw current point in the same view.
void CdDown(Int_t index)
Make a daughter of current node current.
Ssiz_t Length() const
Definition: TString.h:388
virtual void RegisterYourself()
Register the matrix in the current manager, which will become the owner.
Definition: TGeoMatrix.cxx:575
virtual void SetCheckedNode(TGeoNode *node)=0
Int_t fNpdg
current track
Definition: TGeoManager.h:66
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1080
Bool_t CheckPath(const char *path) const
Check if a geometry path is valid without changing the state of the current navigator.
TObjArray * fTracks
list of runtime volumes
Definition: TGeoManager.h:88
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.
Double_t fVisDensity
particles to be drawn
Definition: TGeoManager.h:58
const std::string sname
Definition: testIO.cxx:45
virtual Int_t GetByteCount(Option_t *option=0)
Get total size of geometry in bytes.
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:315
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 CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
TList * fMaterials
Definition: TGeoManager.h:91
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.
virtual Int_t GetByteCount() const
Get total size in bytes of this.
Definition: TGeoMatrix.cxx:332
Int_t * fValuePNEId
Definition: TGeoManager.h:127
void DrawTracks(Option_t *option="")
Draw tracks over the geometry, according to option.
void SetCheckedNode(TGeoNode *node)
Assign a given node to be checked for overlaps. Any other overlaps will be ignored.
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.
Bool_t fStreamVoxels
flag volume lists loop
Definition: TGeoManager.h:70
TVirtualGeoTrack * FindTrackWithId(Int_t id) const
Search the track hierarchy to find the track with the given id.
TGeoVolume * Division(const char *name, const char *mother, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed=0, Option_t *option="")
Create a new volume by dividing an existing one (GEANT3 like)
void SetUseParallelWorldNav(Bool_t flag)
Activate/deactivate usage of parallel world navigation.
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TObjArray.cxx:239
void DrawPath(const char *path, Option_t *option="")
Draw current path.
virtual ~TGeoManager()
Destructor.
TObjArray * fNodes
Definition: TGeoManager.h:93
constexpr Double_t E()
Definition: TMath.h:74
void RandomPoints(const TGeoVolume *vol, Int_t npoints=10000, Option_t *option="")
Draw random points in the bounding box of a volume.
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.
TGeoNode * FindNode(Bool_t safe_start=kTRUE)
Returns deepest node containing current point.
TObjArray * fGVolumes
list of runtime shapes
Definition: TGeoManager.h:87
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.
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGeoMedium * GetMedium(const char *medium) const
Search for a named tracking medium. All trailing blanks stripped.
virtual TGeoElement * GetElement(Int_t i=0) const
Get a pointer to the element this material is made of.
void SetOverlapping(Bool_t flag=kTRUE)
Definition: TGeoNode.h:115
TGeoVolume * fCurrentVolume
current navigator
Definition: TGeoManager.h:107
TGeoMaterial * Material(const char *name, Double_t a, Double_t z, Double_t dens, Int_t uid, Double_t radlen=0, Double_t intlen=0)
Create material with given A, Z and density, having an unique id.
Int_t fRaytraceMode
Flag for multi-threading.
Definition: TGeoManager.h:130
void DefaultAngles()
Set default angles for a given view.
Bool_t IsClosed() const
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Bool_t cd(const char *path="")
Browse the tree of nodes starting from fTopNode according to pathname.
void TestOverlaps(const char *path="")
Geometry overlap checker based on sampling.
Double_t Weight(Double_t precision=0.01, Option_t *option="va")
Estimate weight of volume VOL with a precision SIGMA(W)/W better than PRECISION.
static std::mutex fgMutex
Definition: TGeoManager.h:40
Bool_t IsSamePoint(Double_t x, Double_t y, Double_t z) const
Check if a new point with given coordinates is the same as the last located one.
An extrusion with fixed outline shape in x-y and a sequence of z extents (segments).
Definition: TGeoXtru.h:21
static Int_t GetMaxLevels()
Return maximum number of levels used in the geometry.
virtual void SetVisOption(Int_t option=0)=0
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:89
void SetUsed(Bool_t flag=kTRUE)
Definition: TGeoElement.h:82
virtual void ReflectZ(Bool_t leftside, Bool_t rotonly=kFALSE)
Multiply by a reflection respect to XY.
Definition: TGeoMatrix.cxx:568
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.
#define ClassImp(name)
Definition: Rtypes.h:336
double f(double x)
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
Definition: TROOT.cxx:498
void DoBackupState()
Backup the current state without affecting the cache stack.
Bool_t IsZombie() const
Definition: TObject.h:122
virtual Bool_t IsMixture() const
Definition: TGeoMaterial.h:108
void CdUp()
Go one level up in geometry.
void RemoveMaterial(Int_t index)
Remove material at given index.
TGeoNavigator * SetCurrentNavigator(Int_t inav)
Bool_t GotoSafeLevel()
Go upwards the tree until a non-overlapping node.
double Double_t
Definition: RtypesCore.h:55
Int_t GetNumber() const
Definition: TGeoVolume.h:185
virtual void SetVisibility(Bool_t vis=kTRUE)
set visibility of this volume
void RegisterMatrix(TGeoMatrix *matrix)
Register a matrix to the list of matrices.
TGeoNode * FindNextBoundary(Double_t stepmax=TGeoShape::Big(), const char *path="", Bool_t frombdr=kFALSE)
Find distance to next boundary and store it in fStep.
void SaveAs(const char *filename, Option_t *option="") const
Save geometry having this as top volume as a C++ macro.
TVirtualGeoPainter * fPainter
flag that nodes are the selected objects in pad rather than volumes
Definition: TGeoManager.h:80
void Voxelize(Option_t *option=0)
Voxelize all non-divided volumes.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Bool_t TestShapeBit(UInt_t f) const
Definition: TGeoShape.h:163
virtual ULong_t SizeOf(const TGeoNode *node, Option_t *option)
computes the total size in bytes of the branch starting with node.
R__EXTERN TEnv * gEnv
Definition: TEnv.h:170
Int_t IndexOf(const TObject *obj) const
Definition: TObjArray.cxx:552
virtual void DrawPath(const char *path, Option_t *option="")=0
TNamed()
Definition: TNamed.h:36
void CdTop()
Make top level node the current node.
unsigned long ULong_t
Definition: RtypesCore.h:51
void RegisterMatrix(const TGeoMatrix *matrix)
Register a matrix to the list of matrices.
Int_t AddTransformation(TGeoMatrix *matrix)
Add a matrix to the list. Returns index of the matrix in list.
static RooMathCoreReg dummy
int nentries
Definition: THbookFile.cxx:89
void SetPhiRange(Double_t phimin=0., Double_t phimax=360.)
Set cut phi range.
Bool_t CloseGeometry()
The main geometry must be closed.
Double_t y[n]
Definition: legend1.C:17
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:572
virtual void SetNmeshPoints(Int_t npoints)=0
virtual Int_t GetByteCount() const
Definition: TGeoMedium.h:47
static Bool_t fgLockNavigators
Number of registered threads.
Definition: TGeoManager.h:105
TObjArray * GetListOfPhysicalNodes()
Definition: TGeoManager.h:457
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition: TDatime.cxx:101
TGeoManager * gGeoManager
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.
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN
Definition: NeuralNet.icc:544
void SetDefined(Bool_t flag=kTRUE)
Definition: TGeoElement.h:81
Bool_t fUsePWNav
Raytrace mode: 0=normal, 1=pass through, 2=transparent.
Definition: TGeoManager.h:131
Bool_t SetCurrentNavigator(Int_t index)
Switch to another existing navigator for the calling thread.
Bool_t fClosed
Definition: TGeoManager.h:68
void SetTminTmax(Double_t tmin=0, Double_t tmax=999)
Set time cut interval for drawing tracks.
Finder class handling voxels.
virtual void ComputeBBox()=0
Int_t AddShape(const TGeoShape *shape)
Add a shape to the list. Returns index of the shape in list.
Bool_t IsReflection() const
Definition: TGeoMatrix.h:78
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition: TGeoMedium.h:23
TGeoMaterial * Material(const char *name, Double_t a, Double_t z, Double_t dens, Int_t uid, Double_t radlen=0, Double_t intlen=0)
Create material with given A, Z and density, having an unique id.
void ResetAll()
Reset the navigator.
static ThreadsMap_t * fgThreadId
Map between thread id&#39;s and navigator arrays.
Definition: TGeoManager.h:103
Bool_t IsNull() const
Definition: TString.h:385
virtual void SetLineColor(Color_t lcolor)
Set the line color.
void SetVolume(TGeoVolume *volume)
Definition: TGeoNode.h:112
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.
static void CreateDummyMedium()
Create a dummy medium.
Definition: TGeoVolume.cxx:411
virtual void CheckBoundaryErrors(Int_t ntracks=1000000, Double_t radius=-1.)=0
void ConvertReflections()
Convert all reflections in geometry to normal rotations + reflected shapes.
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.
TGeoHMatrix * GetHMatrix()
Return stored current matrix (global matrix of the next touched node).
Mother of all ROOT objects.
Definition: TObject.h:37
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
TGeoNode * FindNextBoundary(Double_t stepmax=TGeoShape::Big(), const char *path="", Bool_t frombdr=kFALSE)
Find distance to next boundary and store it in fStep.
constexpr Double_t RadToDeg()
Definition: TMath.h:60
Class providing navigation API for TGeo geometries.
Definition: TGeoNavigator.h:33
void CdNext()
Do a cd to the node found next by FindNextBoundary.
void MasterToTop(const Double_t *master, Double_t *top) const
Convert coordinates from master volume frame to top.
TGeoPNEntry * GetAlignableEntry(const char *name) const
Retrieves an existing alignable object.
Int_t GetMaterialIndex(const char *matname) const
Return index of named material.
void CountLevels()
Count maximum number of nodes per volume, maximum depth and maximum number of xtru vertices...
Int_t GetBombMode() const
Definition: TGeoManager.h:188
Abstract class for geometry painters.
void ClearOverlaps()
Clear the list of overlaps.
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition: TGeoNode.h:39
void Node(const char *name, Int_t nr, const char *mother, Double_t x, Double_t y, Double_t z, Int_t irot, Bool_t isOnly, Float_t *upar, Int_t npar=0)
Create a node called <name_nr> pointing to the volume called <name> as daughter of the volume called ...
void SetNsegments(Int_t nseg)
Set number of segments for approximating circles in drawing.
void SetMaxThreads(Int_t nthreads)
Set maximum number of threads for navigation.
void CheckShapes()
check for wrong parameters in shapes
Definition: TGeoNode.cxx:338
void SetExplodedView(Int_t iopt=0)
Set type of exploding view (see TGeoPainter::SetExplodedView())
virtual void Edit(Option_t *option="")
Append a pad for this geometry.
virtual Bool_t IsRaytracing() const =0
R__EXTERN TGeoIdentity * gGeoIdentity
Definition: TGeoMatrix.h:462
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
TGeoNavigator * GetCurrentNavigator() const
Returns current navigator for the calling thread.
TGeoElementTable * fElementTable
clipping shape for raytracing
Definition: TGeoManager.h:114
Bool_t IsVisTouched() const
Definition: TGeoAtt.h:96
void SaveAttributes(const char *filename="tgeoatt.C")
Save current attributes in a macro.
TGeoManager & operator=(const TGeoManager &)
assignment operator
static Int_t ThreadId()
Translates the current thread id to an ordinal number.
Int_t fSizePNEId
array of physical node entries
Definition: TGeoManager.h:124
static TGeoBuilder * Instance(TGeoManager *geom)
Return pointer to singleton.
Definition: TGeoBuilder.cxx:92
virtual void Add(TObject *obj)
Definition: TList.h:77
TGeoVolume * fUserPaintVolume
volume currently painted
Definition: TGeoManager.h:119
TGeoVolume * FindVolumeFast(const char *name, Bool_t multi=kFALSE)
Fast search for a named volume. All trailing blanks stripped.
Bool_t IsSameLocation() const
Definition: TGeoManager.h:389
void BuildIdArray()
Builds node id array.
Definition: TGeoCache.cxx:124
virtual TList * GetListOfKeys() const
Double_t * FindNormal(Bool_t forward=kTRUE)
Computes normal vector to the next surface that will be or was already crossed when propagating on a ...
void CdNext()
Do a cd to the node found next by FindNextBoundary.
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.
void BuildDefaultMaterials()
Now just a shortcut for GetElementTable.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
virtual Int_t GetByteCount() const
Definition: TGeoMaterial.h:83
Int_t GetNdaughters() const
Definition: TGeoNode.h:90
virtual void RandomRays(Int_t nrays, Double_t startx, Double_t starty, Double_t startz, const char *target_vol, Bool_t check_norm)=0
void SetAnimateTracks(Bool_t flag=kTRUE)
Definition: TGeoManager.h:531
void Matrix(Int_t index, Double_t theta1, Double_t phi1, Double_t theta2, Double_t phi2, Double_t theta3, Double_t phi3)
Create rotation matrix named &#39;mat<index>&#39;.
Int_t AddMaterial(const TGeoMaterial *material)
Add a material to the list. Returns index of the material in list.
TGeoNode * FindNode(Bool_t safe_start=kTRUE)
Returns deepest node containing current point.
#define gPad
Definition: TVirtualPad.h:284
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:494
Double_t WeightA() const
Analytical computation of the weight.
Bool_t fMultiThread
Max number of threads.
Definition: TGeoManager.h:129
UChar_t * fBits
Definition: TGeoManager.h:95
TString fParticleName
path to current node
Definition: TGeoManager.h:57
void Add(TObject *obj)
Definition: TObjArray.h:73
Int_t AddTransformation(const TGeoMatrix *matrix)
Add a matrix to the list. Returns index of the matrix in list.
virtual Bool_t IsVolumeMulti() const
Definition: TGeoVolume.h:118
void SetVisibility(Bool_t vis=kTRUE)
Set visibility of the node (obsolete).
Definition: TGeoNode.cxx:685
static Int_t GetMaxXtruVert()
Return maximum number of vertices for an xtru shape used.
Definition: Rtypes.h:56
TGeoVolume * fPaintVolume
Definition: TGeoManager.h:118
void ResetBit(UInt_t f)
Definition: TObject.h:158
unsigned char UChar_t
Definition: RtypesCore.h:34
TGeoElement * GetElement(Int_t z)
Definition: TGeoElement.h:398
virtual void UnbombTranslation(const Double_t *tr, Double_t *bombtr)=0
TGeoParallelWorld * CreateParallelWorld(const char *name)
Create a parallel world for prioritised navigation.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:901
virtual void SetMedium(TGeoMedium *medium)
Definition: TGeoVolume.h:232
void ClearNavigators()
Clear all navigators.
void FindOverlaps() const
loop all nodes marked as overlaps and find overlapping brothers
void UnbombTranslation(const Double_t *tr, Double_t *bombtr)
Get the new &#39;unbombed&#39; translation vector according current exploded view mode.
Int_t GetCurrentNodeId() const
TGeoShape * GetShape() const
Definition: TGeoVolume.h:191
TGeoVolume * Volume(const char *name, const char *shape, Int_t nmed, Float_t *upar, Int_t npar=0)
Create a volume in GEANT3 style.
TGeoNode * FindNextDaughterBoundary(Double_t *point, Double_t *dir, Int_t &idaughter, Bool_t compmatrix=kFALSE)
Computes as fStep the distance to next daughter of the current volume.
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:364
virtual Int_t GetSize() const
Definition: TCollection.h:89
void DoBackupState()
Backup the current state without affecting the cache stack.
Double_t * FindNormalFast()
Computes fast normal to next crossed boundary, assuming that the current point is close enough to the...
TGeoMaterial * Mixture(const char *name, Float_t *a, Float_t *z, Double_t dens, Int_t nelem, Float_t *wmat, Int_t uid)
Create mixture OR COMPOUND IMAT as composed by THE BASIC nelem materials defined by arrays A...
void SetVisTouched(Bool_t vis=kTRUE)
Mark visualization attributes as "modified".
Definition: TGeoAtt.cxx:131
TGeoVolume * fMasterVolume
top physical node
Definition: TGeoManager.h:110
void SetNumber(Int_t number)
Definition: TGeoVolume.h:235
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
Base class for a flat parallel geometry.
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.
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
virtual void TestOverlaps(const char *path)=0
const Bool_t kTRUE
Definition: RtypesCore.h:91
void Grab()
Definition: TGeoVolume.h:142
virtual void CheckPoint(Double_t x=0, Double_t y=0, Double_t z=0, Option_t *option="")=0
void SetVisOption(Int_t option=0)
set drawing mode :
TVirtualGeoPainter * GetGeomPainter()
Make a default painter if none present. Returns pointer to it.
Bool_t OptimizeVoxels()
Perform an extensive sampling to find which type of voxelization is most efficient.
TGeoVolume * GetVolume() const
Definition: TGeoNode.h:94
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.
static void UnlockGeometry()
Unlock current geometry.
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMath.h:1093
void CreateThreadData() const
Create thread private data for all geometry objects.
const char * GetPath() const
Get path to the current node in the form /node0/node1/...
Definition: Rtypes.h:57
void BuildInfoBranch()
Builds info branch. Navigation is possible only after this step.
Definition: TGeoCache.cxx:141
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.
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute mouse actions on this manager.
void MasterToLocal(const Double_t *master, Double_t *local) const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:859
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.
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
virtual Bool_t IsEq(const TGeoMaterial *other) const
return true if the other material has the same physical properties
void ClearPhysicalNodes(Bool_t mustdelete=kFALSE)
Clear the current list of physical nodes, so that we can start over with a new list.
void SetNmeshPoints(Int_t npoints=1000)
Set the number of points to be generated on the shape outline when checking for overlaps.
virtual void RecursiveRemove(TObject *obj)
Recursively remove obj from browser.
Definition: TBrowser.cxx:366
virtual Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
Bool_t IsRunTimeShape() const
Definition: TGeoShape.h:139
TGeoNode * Step(Bool_t is_geom=kTRUE, Bool_t cross=kTRUE)
Make a rectiliniar step of length fStep from current point (fPoint) on current direction (fDirection)...
static Int_t fgMaxXtruVert
Maximum number of daughters.
Definition: TGeoManager.h:45
const char * Data() const
Definition: TString.h:347
virtual Bool_t IsAssembly() const
Returns true if the volume is an assembly or a scaled assembly.
void CheckBoundaryReference(Int_t icheck=-1)
Check the boundary errors reference file created by CheckBoundaryErrors method.
TGeoNode * CrossBoundaryAndLocate(Bool_t downwards, TGeoNode *skipnode)
Cross next boundary and locate within current node The current point must be on the boundary of fCurr...