Logo ROOT  
Reference Guide
TGeoVolume.cxx
Go to the documentation of this file.
1// @(#)root/geom:$Id$
2// Author: Andrei Gheata 30/05/02
3// Divide(), CheckOverlaps() implemented by Mihaela Gheata
4
5/*************************************************************************
6 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13/** \class TGeoVolume
14\ingroup Shapes_classes
15
16TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes
17
18 Volumes are the basic objects used in building the geometrical hierarchy.
19They represent unpositioned objects but store all information about the
20placement of the other volumes they may contain. Therefore a volume can
21be replicated several times in the geometry. In order to create a volume, one
22has to put together a shape and a medium which are already defined. Volumes
23have to be named by users at creation time. Every different name may represent a
24an unique volume object, but may also represent more general a family (class)
25of volume objects having the same shape type and medium, but possibly
26different shape parameters. It is the user's task to provide different names
27for different volume families in order to avoid ambiguities at tracking time.
28A generic family rather than a single volume is created only in two cases :
29when a generic shape is provided to the volume constructor or when a division
30operation is applied. Each volume in the geometry stores an unique
31ID corresponding to its family. In order to ease-up their creation, the manager
32class is providing an API that allows making a shape and a volume in a single step.
33
34 Volumes are objects that can be visualized, therefore having visibility,
35colour, line and fill attributes that can be defined or modified any time after
36the volume creation. It is advisable however to define these properties just
37after the first creation of a volume namespace, since in case of volume families
38any new member created by the modeler inherits these properties.
39
40 In order to provide navigation features, volumes have to be able to find
41the proper container of any point defined in the local reference frame. This
42can be the volume itself, one of its positioned daughter volumes or none if
43the point is actually outside. On the other hand, volumes have to provide also
44other navigation methods such as finding the distances to its shape boundaries
45or which daughter will be crossed first. The implementation of these features
46is done at shape level, but the local mother-daughters management is handled
47by volumes that builds additional optimisation structures upon geometry closure.
48In order to have navigation features properly working one has to follow the
49general rules for building a valid geometry (see TGeoManager class).
50
51 Now let's make a simple volume representing a copper wire. We suppose that
52a medium is already created (see TGeoMedium class on how to create media).
53We will create a TUBE shape for our wire, having Rmin=0cm, Rmax=0.01cm
54and a half-length dZ=1cm :
55
56~~~ {.cpp}
57 TGeoTube *tube = new TGeoTube("wire_tube", 0, 0.01, 1);
58~~~
59
60One may omit the name for the shape if no retrieving by name is further needed
61during geometry building. The same shape can be shared by different volumes
62having different names and materials. Now let's make the volume for our wire.
63The prototype for volumes constructor looks like :
64
65 TGeoVolume::TGeoVolume(const char *name, TGeoShape *shape, TGeoMedium *med)
66
67Since TGeoTube derives from the base shape class, we can provide it to the volume
68constructor :
69
70~~~ {.cpp}
71 TGeoVolume *wire_co = new TGeoVolume("WIRE_CO", tube, ptrCOPPER);
72~~~
73
74Do not bother to delete neither the media, shapes or volumes that you have
75created since all will be automatically cleaned on exit by the manager class.
76If we would have taken a look inside TGeoManager::MakeTube() method, we would
77have been able to create our wire with a single line :
78
79~~~ {.cpp}
80 TGeoVolume *wire_co = gGeoManager->MakeTube("WIRE_CO", ptrCOPPER, 0, 0.01, 1);
81~~~
82
83The same applies for all primitive shapes, for which there can be found
84corresponding MakeSHAPE() methods. Their usage is much more convenient unless
85a shape has to be shared between more volumes. Let's make now an aluminium wire
86having the same shape, supposing that we have created the copper wire with the
87line above :
88
89~~~ {.cpp}
90 TGeoVolume *wire_al = new TGeoVolume("WIRE_AL", wire_co->GetShape(), ptrAL);
91~~~
92
93Now that we have learned how to create elementary volumes, let's see how we
94can create a geometrical hierarchy.
95
96
97### Positioning volumes
98
99 When creating a volume one does not specify if this will contain or not other
100volumes. Adding daughters to a volume implies creating those and adding them
101one by one to the list of daughters. Since the volume has to know the position
102of all its daughters, we will have to supply at the same time a geometrical
103transformation with respect to its local reference frame for each of them.
104The objects referencing a volume and a transformation are called NODES and
105their creation is fully handled by the modeler. They represent the link
106elements in the hierarchy of volumes. Nodes are unique and distinct geometrical
107objects ONLY from their container point of view. Since volumes can be replicated
108in the geometry, the same node may be found on different branches.
109
110\image html geom_t_example.png width=600px
111
112 An important observation is that volume objects are owned by the TGeoManager
113class. This stores a list of all volumes in the geometry, that is cleaned
114upon destruction.
115
116 Let's consider positioning now our wire in the middle of a gas chamber. We
117need first to define the gas chamber :
118
119~~~ {.cpp}
120 TGeoVolume *chamber = gGeoManager->MakeTube("CHAMBER", ptrGAS, 0, 1, 1);
121~~~
122
123Now we can put the wire inside :
124
125~~~ {.cpp}
126 chamber->AddNode(wire_co, 1);
127~~~
128
129If we inspect now the chamber volume in a browser, we will notice that it has
130one daughter. Of course the gas has some container also, but let's keep it like
131that for the sake of simplicity. The full prototype of AddNode() is :
132
133~~~ {.cpp}
134 TGeoVolume::AddNode(TGeoVolume *daughter, Int_t usernumber,
135 TGeoMatrix *matrix=gGeoIdentity)
136~~~
137
138Since we did not supplied the third argument, the wire will be positioned with
139an identity transformation inside the chamber. One will notice that the inner
140radii of the wire and chamber are both zero - therefore, aren't the two volumes
141overlapping ? The answer is no, the modeler is even relaying on the fact that
142any daughter is fully contained by its mother. On the other hand, neither of
143the nodes positioned inside a volume should overlap with each other. We will
144see that there are allowed some exceptions to those rules.
145
146### Overlapping volumes
147
148 Positioning volumes that does not overlap their neighbours nor extrude
149their container is sometimes quite strong constraint. Some parts of the geometry
150might overlap naturally, e.g. two crossing tubes. The modeller supports such
151cases only if the overlapping nodes are declared by the user. In order to do
152that, one should use TGeoVolume::AddNodeOverlap() instead of TGeoVolume::AddNode().
153 When 2 or more positioned volumes are overlapping, not all of them have to
154be declared so, but at least one. A point inside an overlapping region equally
155belongs to all overlapping nodes, but the way these are defined can enforce
156the modeler to give priorities.
157 The general rule is that the deepest node in the hierarchy containing a point
158have the highest priority. For the same geometry level, non-overlapping is
159prioritised over overlapping. In order to illustrate this, we will consider
160few examples. We will designate non-overlapping nodes as ONLY and the others
161MANY as in GEANT3, where this concept was introduced:
162 1. The part of a MANY node B extruding its container A will never be "seen"
163during navigation, as if B was in fact the result of the intersection of A and B.
164 2. If we have two nodes A (ONLY) and B (MANY) inside the same container, all
165points in the overlapping region of A and B will be designated as belonging to A.
166 3. If A an B in the above case were both MANY, points in the overlapping
167part will be designated to the one defined first. Both nodes must have the
168same medium.
169 4. The slices of a divided MANY will be as well MANY.
170
171One needs to know that navigation inside geometry parts MANY nodes is much
172slower. Any overlapping part can be defined based on composite shapes - this
173is always recommended.
174
175### Replicating volumes
176
177 What can we do if our chamber contains two identical wires instead of one ?
178What if then we would need 1000 chambers in our detector ? Should we create
1792000 wires and 1000 chamber volumes ? No, we will just need to replicate the
180ones that we have already created.
181
182~~~ {.cpp}
183 chamber->AddNode(wire_co, 1, new TGeoTranslation(-0.2,0,0));
184 chamber->AddNode(wire_co, 2, new TGeoTranslation(0.2,0,0));
185~~~
186
187 The 2 nodes that we have created inside chamber will both point to a wire_co
188object, but will be completely distinct : WIRE_CO_1 and WIRE_CO_2. We will
189want now to place symmetrically 1000 chambers on a pad, following a pattern
190of 20 rows and 50 columns. One way to do this will be to replicate our chamber
191by positioning it 1000 times in different positions of the pad. Unfortunately,
192this is far from being the optimal way of doing what we want.
193Imagine that we would like to find out which of the 1000 chambers is containing
194a (x,y,z) point defined in the pad reference. You will never have to do that,
195since the modeller will take care of it for you, but let's guess what it has
196to do. The most simple algorithm will just loop over all daughters, convert
197the point from mother to local reference and check if the current chamber
198contains the point or not. This might be efficient for pads with few chambers,
199but definitely not for 1000. Fortunately the modeler is smarter than that and
200create for each volume some optimization structures called voxels (see Voxelization)
201to minimize the penalty having too many daughters, but if you have 100 pads like
202this in your geometry you will anyway loose a lot in your tracking performance.
203
204 The way out when volumes can be arranged according to simple patterns is the
205usage of divisions. We will describe them in detail later on. Let's think now
206at a different situation : instead of 1000 chambers of the same type, we may
207have several types of chambers. Let's say all chambers are cylindrical and have
208a wire inside, but their dimensions are different. However, we would like all
209to be represented by a single volume family, since they have the same properties.
210*/
211
212/** \class TGeoVolumeMulti
213\ingroup Geometry_classes
214
215Volume families
216
217A volume family is represented by the class TGeoVolumeMulti. It represents
218a class of volumes having the same shape type and each member will be
219identified by the same name and volume ID. Any operation applied to a
220TGeoVolume equally affects all volumes in that family. The creation of a
221family is generally not a user task, but can be forced in particular cases:
222
223~~~ {.cpp}
224 TGeoManager::Volume(const char *vname, const char *shape, Int_t nmed);
225~~~
226
227where VNAME is the family name, NMED is the medium number and SHAPE is the
228shape type that can be:
229
230~~~ {.cpp}
231 box - for TGeoBBox
232 trd1 - for TGeoTrd1
233 trd2 - for TGeoTrd2
234 trap - for TGeoTrap
235 gtra - for TGeoGtra
236 para - for TGeoPara
237 tube, tubs - for TGeoTube, TGeoTubeSeg
238 cone, cons - for TGeoCone, TgeoCons
239 eltu - for TGeoEltu
240 ctub - for TGeoCtub
241 pcon - for TGeoPcon
242 pgon - for TGeoPgon
243~~~
244
245Volumes are then added to a given family upon adding the generic name as node
246inside other volume:
247
248~~~ {.cpp}
249 TGeoVolume *box_family = gGeoManager->Volume("BOXES", "box", nmed);
250 ...
251 gGeoManager->Node("BOXES", Int_t copy_no, "mother_name",
252 Double_t x, Double_t y, Double_t z, Int_t rot_index,
253 Bool_t is_only, Double_t *upar, Int_t npar);
254~~~
255
256here:
257
258~~~ {.cpp}
259 BOXES - name of the family of boxes
260 copy_no - user node number for the created node
261 mother_name - name of the volume to which we want to add the node
262 x,y,z - translation components
263 rot_index - indx of a rotation matrix in the list of matrices
264 upar - array of actual shape parameters
265 npar - number of parameters
266~~~
267
268The parameters order and number are the same as in the corresponding shape
269constructors.
270
271 Another particular case where volume families are used is when we want
272that a volume positioned inside a container to match one ore more container
273limits. Suppose we want to position the same box inside 2 different volumes
274and we want the Z size to match the one of each container:
275
276~~~ {.cpp}
277 TGeoVolume *container1 = gGeoManager->MakeBox("C1", imed, 10,10,30);
278 TGeoVolume *container2 = gGeoManager->MakeBox("C2", imed, 10,10,20);
279 TGeoVolume *pvol = gGeoManager->MakeBox("PVOL", jmed, 3,3,-1);
280 container1->AddNode(pvol, 1);
281 container2->AddNode(pvol, 1);
282~~~
283
284 Note that the third parameter of PVOL is negative, which does not make sense
285as half-length on Z. This is interpreted as: when positioned, create a box
286replacing all invalid parameters with the corresponding dimensions of the
287container. This is also internally handled by the TGeoVolumeMulti class, which
288does not need to be instantiated by users.
289
290### Dividing volumes
291
292 Volumes can be divided according a pattern. The most simple division can
293be done along one axis, that can be: X, Y, Z, Phi, Rxy or Rxyz. Let's take
294the most simple case: we would like to divide a box in N equal slices along X
295coordinate, representing a new volume family. Supposing we already have created
296the initial box, this can be done like:
297
298~~~ {.cpp}
299 TGeoVolume *slicex = box->Divide("SLICEX", 1, N);
300~~~
301
302where SLICE is the name of the new family representing all slices and 1 is the
303slicing axis. The meaning of the axis index is the following: for all volumes
304having shapes like box, trd1, trd2, trap, gtra or para - 1,2,3 means X,Y,Z; for
305tube, tubs, cone, cons - 1 means Rxy, 2 means phi and 3 means Z; for pcon and
306pgon - 2 means phi and 3 means Z; for spheres 1 means R and 2 means phi.
307 In fact, the division operation has the same effect as positioning volumes
308in a given order inside the divided container - the advantage being that the
309navigation in such a structure is much faster. When a volume is divided, a
310volume family corresponding to the slices is created. In case all slices can
311be represented by a single shape, only one volume is added to the family and
312positioned N times inside the divided volume, otherwise, each slice will be
313represented by a distinct volume in the family.
314 Divisions can be also performed in a given range of one axis. For that, one
315have to specify also the starting coordinate value and the step:
316
317~~~ {.cpp}
318 TGeoVolume *slicex = box->Divide("SLICEX", 1, N, start, step);
319~~~
320
321A check is always done on the resulting division range : if not fitting into
322the container limits, an error message is posted. If we will browse the divided
323volume we will notice that it will contain N nodes starting with index 1 upto
324N. The first one has the lower X limit at START position, while the last one
325will have the upper X limit at START+N*STEP. The resulting slices cannot
326be positioned inside an other volume (they are by default positioned inside the
327divided one) but can be further divided and may contain other volumes:
328
329~~~ {.cpp}
330 TGeoVolume *slicey = slicex->Divide("SLICEY", 2, N1);
331 slicey->AddNode(other_vol, index, some_matrix);
332~~~
333
334 When doing that, we have to remember that SLICEY represents a family, therefore
335all members of the family will be divided on Y and the other volume will be
336added as node inside all.
337 In the example above all the resulting slices had the same shape as the
338divided volume (box). This is not always the case. For instance, dividing a
339volume with TUBE shape on PHI axis will create equal slices having TUBESEG
340shape. Other divisions can also create slices having shapes with different
341dimensions, e.g. the division of a TRD1 volume on Z.
342 When positioning volumes inside slices, one can do it using the generic
343volume family (e.g. slicey). This should be done as if the coordinate system
344of the generic slice was the same as the one of the divided volume. The generic
345slice in case of PHI division is centered with respect to X axis. If the
346family contains slices of different sizes, any volume positioned inside should
347fit into the smallest one.
348 Examples for specific divisions according to shape types can be found inside
349shape classes.
350
351~~~ {.cpp}
352 TGeoVolume::Divide(N, Xmin, Xmax, "X");
353~~~
354
355 The GEANT3 option MANY is supported by TGeoVolumeOverlap class. An overlapping
356volume is in fact a virtual container that does not represent a physical object.
357It contains a list of nodes that are not its daughters but that must be checked
358always before the container itself. This list must be defined by users and it
359is checked and resolved in a priority order. Note that the feature is non-standard
360to geometrical modelers and it was introduced just to support conversions of
361GEANT3 geometries, therefore its extensive usage should be avoided.
362*/
363
364/** \class TGeoVolumeAssembly
365\ingroup Geometry_classes
366
367Volume assemblies
368
369Assemblies a volumes that have neither a shape or a material/medium. Assemblies
370behave exactly like normal volumes grouping several daughters together, but
371the daughters can never extrude the assembly since this has no shape. However,
372a bounding box and a voxelization structure are built for assemblies as for
373normal volumes, so that navigation is still optimized. Assemblies are useful
374for grouping hierarchically volumes which are otherwise defined in a flat
375manner, but also to avoid clashes between container shapes.
376To define an assembly one should just input a name, then start adding other
377volumes (or volume assemblies) as content.
378*/
379
380#include <fstream>
381#include <iomanip>
382
383#include "TString.h"
384#include "TBuffer.h"
385#include "TBrowser.h"
386#include "TStyle.h"
387#include "TH2F.h"
388#include "TROOT.h"
389#include "TEnv.h"
390#include "TMap.h"
391#include "TFile.h"
392#include "TKey.h"
393
394#include "TGeoManager.h"
395#include "TGeoNode.h"
396#include "TGeoMatrix.h"
397#include "TVirtualGeoPainter.h"
398#include "TGeoVolume.h"
399#include "TGeoShapeAssembly.h"
400#include "TGeoScaledShape.h"
401#include "TGeoCompositeShape.h"
402#include "TGeoVoxelFinder.h"
403#include "TGeoExtension.h"
404
406
408
409////////////////////////////////////////////////////////////////////////////////
410/// Create a dummy medium
411
413{
414 if (fgDummyMedium) return;
416 fgDummyMedium->SetName("dummy");
417 TGeoMaterial *dummyMaterial = new TGeoMaterial();
418 dummyMaterial->SetName("dummy");
419 fgDummyMedium->SetMaterial(dummyMaterial);
420}
421
422////////////////////////////////////////////////////////////////////////////////
423
425{
428}
429
430////////////////////////////////////////////////////////////////////////////////
431
433{
434 if (fFinder) fFinder->CreateThreadData(nthreads);
435 if (fShape) fShape->CreateThreadData(nthreads);
436}
437
438////////////////////////////////////////////////////////////////////////////////
439
441{
442 return fgDummyMedium;
443}
444
445////////////////////////////////////////////////////////////////////////////////
446/// dummy constructor
447
449{
450 fNodes = 0;
451 fShape = 0;
452 fMedium = 0;
453 fFinder = 0;
454 fVoxels = 0;
456 fField = 0;
457 fOption = "";
458 fNumber = 0;
459 fNtotal = 0;
460 fRefCount = 0;
461 fUserExtension = 0;
462 fFWExtension = 0;
464}
465
466////////////////////////////////////////////////////////////////////////////////
467/// default constructor
468
469TGeoVolume::TGeoVolume(const char *name, const TGeoShape *shape, const TGeoMedium *med)
470 :TNamed(name, "")
471{
472 fName = fName.Strip();
473 fNodes = 0;
474 fShape = (TGeoShape*)shape;
475 if (fShape) {
477 Warning("Ctor", "volume %s has invalid shape", name);
478 }
479 if (!fShape->IsValid()) {
480 Fatal("ctor", "Shape of volume %s invalid. Aborting!", fName.Data());
481 }
482 }
483 fMedium = (TGeoMedium*)med;
485 fFinder = 0;
486 fVoxels = 0;
488 fField = 0;
489 fOption = "";
490 fNumber = 0;
491 fNtotal = 0;
492 fRefCount = 0;
493 fUserExtension = 0;
494 fFWExtension = 0;
497}
498
499////////////////////////////////////////////////////////////////////////////////
500/// Destructor
501
503{
504 if (fNodes) {
506 fNodes->Delete();
507 }
508 delete fNodes;
509 }
511 if (fVoxels) delete fVoxels;
514}
515
516////////////////////////////////////////////////////////////////////////////////
517/// How to browse a volume
518
520{
521 if (!b) return;
522
523// if (!GetNdaughters()) b->Add(this, GetName(), IsVisible());
524 TGeoVolume *daughter;
525 TString title;
526 for (Int_t i=0; i<GetNdaughters(); i++) {
527 daughter = GetNode(i)->GetVolume();
528 if(daughter->GetTitle()[0]) {
529 if (daughter->IsAssembly()) title.TString::Format("Assembly with %d daughter(s)",
530 daughter->GetNdaughters());
531 else if (daughter->GetFinder()) {
532 TString s1 = daughter->GetFinder()->ClassName();
533 s1.ReplaceAll("TGeoPattern","");
534 title.TString::Format("Volume having %s shape divided in %d %s slices",
535 daughter->GetShape()->ClassName(),daughter->GetNdaughters(), s1.Data());
536
537 } else title.TString::Format("Volume with %s shape having %d daughter(s)",
538 daughter->GetShape()->ClassName(),daughter->GetNdaughters());
539 daughter->SetTitle(title.Data());
540 }
541 b->Add(daughter, daughter->GetName(), daughter->IsVisible());
542// if (IsVisDaughters())
543// b->AddCheckBox(daughter, daughter->IsVisible());
544// else
545// b->AddCheckBox(daughter, kFALSE);
546 }
547}
548
549////////////////////////////////////////////////////////////////////////////////
550/// Computes the capacity of this [cm^3] as the capacity of its shape.
551/// In case of assemblies, the capacity is computed as the sum of daughter's capacities.
552
554{
555 if (!IsAssembly()) return fShape->Capacity();
556 Double_t capacity = 0.0;
557 Int_t nd = GetNdaughters();
558 Int_t i;
559 for (i=0; i<nd; i++) capacity += GetNode(i)->GetVolume()->Capacity();
560 return capacity;
561}
562
563////////////////////////////////////////////////////////////////////////////////
564/// Shoot nrays with random directions from starting point (startx, starty, startz)
565/// in the reference frame of this volume. Track each ray until exiting geometry, then
566/// shoot backwards from exiting point and compare boundary crossing points.
567
568void TGeoVolume::CheckGeometry(Int_t nrays, Double_t startx, Double_t starty, Double_t startz) const
569{
570 TGeoVolume *old_vol = fGeoManager->GetTopVolume();
571 if (old_vol!=this) fGeoManager->SetTopVolume((TGeoVolume*)this);
572 else old_vol=0;
575 painter->CheckGeometry(nrays, startx, starty, startz);
576}
577
578////////////////////////////////////////////////////////////////////////////////
579/// Overlap checking tool. Check for illegal overlaps within a limit OVLP.
580/// Use option="s[number]" to force overlap checking by sampling volume with
581/// [number] points.
582///
583/// Ex:
584/// ~~~ {.cpp}
585/// myVol->CheckOverlaps(0.01, "s10000000"); // shoot 10000000 points
586/// myVol->CheckOverlaps(0.01, "s"); // shoot the default value of 1e6 points
587/// ~~~
588
590{
591 if (!GetNdaughters() || fFinder) return;
592 Bool_t sampling = kFALSE;
593 TString opt(option);
594 opt.ToLower();
595 if (opt.Contains("s")) sampling = kTRUE;
597 if (!sampling) fGeoManager->SetNsegments(80);
600// Info("CheckOverlaps", "=== Checking overlaps for volume %s ===\n", GetName());
601 }
602 painter->CheckOverlaps(this, ovlp, option);
603// if (sampling) return;
607 Int_t novlps = overlaps->GetEntriesFast();
608 TNamed *obj;
610 for (Int_t i=0; i<novlps; i++) {
611 obj = (TNamed*)overlaps->At(i);
612 if (novlps<1000) name = TString::Format("ov%03d", i);
613 else name = TString::Format("ov%06d", i);
614 obj->SetName(name);
615 }
616 if (novlps) Info("CheckOverlaps", "Number of illegal overlaps/extrusions for volume %s: %d\n", GetName(), novlps);
617 }
618}
619
620////////////////////////////////////////////////////////////////////////////////
621/// Tests for checking the shape navigation algorithms. See TGeoShape::CheckShape()
622
624{
625 fShape->CheckShape(testNo,nsamples,option);
626}
627
628////////////////////////////////////////////////////////////////////////////////
629/// Clean data of the volume.
630
632{
633 ClearNodes();
634 ClearShape();
635}
636
637////////////////////////////////////////////////////////////////////////////////
638/// Clear the shape of this volume from the list held by the current manager.
639
641{
643}
644
645////////////////////////////////////////////////////////////////////////////////
646/// check for negative parameters in shapes.
647
649{
650 if (fShape->IsRunTimeShape()) {
651 Error("CheckShapes", "volume %s has run-time shape", GetName());
652 InspectShape();
653 return;
654 }
655 if (!fNodes) return;
657 TGeoNode *node = 0;
658 TGeoNode *new_node;
659 const TGeoShape *shape = 0;
660 TGeoVolume *old_vol;
661 for (Int_t i=0; i<nd; i++) {
662 node=(TGeoNode*)fNodes->At(i);
663 // check if node has name
664 if (!node->GetName()[0]) printf("Daughter %i of volume %s - NO NAME!!!\n",
665 i, GetName());
666 old_vol = node->GetVolume();
667 shape = old_vol->GetShape();
668 if (shape->IsRunTimeShape()) {
669// printf(" Node %s/%s has shape with negative parameters. \n",
670// GetName(), node->GetName());
671// old_vol->InspectShape();
672 // make a copy of the node
673 new_node = node->MakeCopyNode();
674 if (!new_node) {
675 Fatal("CheckShapes", "Cannot make copy node for %s", node->GetName());
676 return;
677 }
678 TGeoShape *new_shape = shape->GetMakeRuntimeShape(fShape, node->GetMatrix());
679 if (!new_shape) {
680 Error("CheckShapes","cannot resolve runtime shape for volume %s/%s\n",
681 GetName(),old_vol->GetName());
682 continue;
683 }
684 TGeoVolume *new_volume = old_vol->MakeCopyVolume(new_shape);
685// printf(" new volume %s shape params :\n", new_volume->GetName());
686// new_volume->InspectShape();
687 new_node->SetVolume(new_volume);
688 // decouple the old node and put the new one instead
689 fNodes->AddAt(new_node, i);
690// new_volume->CheckShapes();
691 }
692 }
693}
694
695////////////////////////////////////////////////////////////////////////////////
696/// Count total number of subnodes starting from this volume, nlevels down
697/// - option = 0 (default) - count only once per volume
698/// - option = 1 - count every time
699/// - option = 2 - count volumes on visible branches
700/// - option = 3 - return maximum level counted already with option = 0
701
703{
704 static Int_t maxlevel = 0;
705 static Int_t nlev = 0;
706
707 if (option<0 || option>3) option = 0;
708 Int_t visopt = 0;
709 Int_t nd = GetNdaughters();
710 Bool_t last = (!nlevels || !nd)?kTRUE:kFALSE;
711 switch (option) {
712 case 0:
713 if (fNtotal) return fNtotal;
714 case 1:
715 fNtotal = 1;
716 break;
717 case 2:
718 visopt = fGeoManager->GetVisOption();
719 if (!IsVisDaughters()) last = kTRUE;
720 switch (visopt) {
722 fNtotal = (IsVisible())?1:0;
723 break;
725 fNtotal = (IsVisible() && last)?1:0;
726 }
727 if (!IsVisibleDaughters()) return fNtotal;
728 break;
729 case 3:
730 return maxlevel;
731 }
732 if (last) return fNtotal;
733 if (gGeoManager->GetTopVolume() == this) {
734 maxlevel=0;
735 nlev = 0;
736 }
737 if (nlev>maxlevel) maxlevel = nlev;
738 TGeoNode *node;
739 TGeoVolume *vol;
740 nlev++;
741 for (Int_t i=0; i<nd; i++) {
742 node = GetNode(i);
743 vol = node->GetVolume();
744 fNtotal += vol->CountNodes(nlevels-1, option);
745 }
746 nlev--;
747 return fNtotal;
748}
749
750////////////////////////////////////////////////////////////////////////////////
751/// Return TRUE if volume and all daughters are invisible.
752
754{
755 if (IsVisible()) return kFALSE;
756 Int_t nd = GetNdaughters();
757 for (Int_t i=0; i<nd; i++) if (GetNode(i)->GetVolume()->IsVisible()) return kFALSE;
758 return kTRUE;
759}
760
761////////////////////////////////////////////////////////////////////////////////
762/// Make volume and each of it daughters (in)visible.
763
765{
766 SetAttVisibility(!flag);
767 Int_t nd = GetNdaughters();
768 TObjArray *list = new TObjArray(nd+1);
769 list->Add(this);
770 TGeoVolume *vol;
771 for (Int_t i=0; i<nd; i++) {
772 vol = GetNode(i)->GetVolume();
773 vol->SetAttVisibility(!flag);
774 list->Add(vol);
775 }
776 TIter next(gROOT->GetListOfBrowsers());
777 TBrowser *browser = 0;
778 while ((browser=(TBrowser*)next())) {
779 for (Int_t i=0; i<nd+1; i++) {
780 vol = (TGeoVolume*)list->At(i);
781 browser->CheckObjectItem(vol, !flag);
782 }
783 browser->Refresh();
784 }
785 delete list;
787}
788
789////////////////////////////////////////////////////////////////////////////////
790/// Return TRUE if volume contains nodes
791
793{
794 return kTRUE;
795}
796
797////////////////////////////////////////////////////////////////////////////////
798/// check if the visibility and attributes are the default ones
799
801{
802 if (!IsVisible()) return kFALSE;
803 if (GetLineColor() != gStyle->GetLineColor()) return kFALSE;
804 if (GetLineStyle() != gStyle->GetLineStyle()) return kFALSE;
805 if (GetLineWidth() != gStyle->GetLineWidth()) return kFALSE;
806 return kTRUE;
807}
808
809////////////////////////////////////////////////////////////////////////////////
810/// True if this is the top volume of the geometry
811
813{
814 if (fGeoManager->GetTopVolume() == this) return kTRUE;
815 return kFALSE;
816}
817
818////////////////////////////////////////////////////////////////////////////////
819/// Check if the painter is currently ray-tracing the content of this volume.
820
822{
823 return TGeoAtt::IsVisRaytrace();
824}
825
826////////////////////////////////////////////////////////////////////////////////
827/// Inspect the material for this volume.
828
830{
831 GetMaterial()->Print();
832}
833
834////////////////////////////////////////////////////////////////////////////////
835/// Import a volume from a file.
836
837TGeoVolume *TGeoVolume::Import(const char *filename, const char *name, Option_t * /*option*/)
838{
839 if (!gGeoManager) gGeoManager = new TGeoManager("geometry","");
840 if (!filename) return 0;
841 TGeoVolume *volume = 0;
842 if (strstr(filename,".gdml")) {
843 // import from a gdml file
844 } else {
845 // import from a root file
848 if (!f || f->IsZombie()) {
849 printf("Error: TGeoVolume::Import : Cannot open file %s\n", filename);
850 return 0;
851 }
852 if (name && name[0]) {
853 volume = (TGeoVolume*)f->Get(name);
854 } else {
855 TIter next(f->GetListOfKeys());
856 TKey *key;
857 while ((key = (TKey*)next())) {
858 if (strcmp(key->GetClassName(),"TGeoVolume") != 0) continue;
859 volume = (TGeoVolume*)key->ReadObj();
860 break;
861 }
862 }
863 delete f;
864 }
865 if (!volume) return NULL;
866 volume->RegisterYourself();
867 return volume;
868}
869
870////////////////////////////////////////////////////////////////////////////////
871/// Export this volume to a file.
872///
873/// - Case 1: root file or root/xml file
874/// if filename end with ".root". The key will be named name
875/// if filename end with ".xml" a root/xml file is produced.
876///
877/// - Case 2: C++ script
878/// if filename end with ".C"
879///
880/// - Case 3: gdml file
881/// if filename end with ".gdml"
882///
883/// NOTE that to use this option, the PYTHONPATH must be defined like
884/// export PYTHONPATH=$ROOTSYS/lib:$ROOTSYS/gdml
885///
886
888{
889 TString sfile(filename);
890 if (sfile.Contains(".C")) {
891 //Save volume as a C++ script
892 Info("Export","Exporting volume %s as C++ code", GetName());
893 SaveAs(filename, "");
894 return 1;
895 }
896 if (sfile.Contains(".gdml")) {
897 //Save geometry as a gdml file
898 Info("Export","Exporting %s as gdml code - not implemented yet", GetName());
899 return 0;
900 }
901 if (sfile.Contains(".root") || sfile.Contains(".xml")) {
902 //Save volume in a root file
903 Info("Export","Exporting %s as root file.", GetName());
904 TString opt(option);
905 if (!opt.Length()) opt = "recreate";
906 TFile *f = TFile::Open(filename,opt.Data());
907 if (!f || f->IsZombie()) {
908 Error("Export","Cannot open file");
909 return 0;
910 }
911 TString keyname(name);
912 if (keyname.IsNull()) keyname = GetName();
913 Int_t nbytes = Write(keyname);
914 delete f;
915 return nbytes;
916 }
917 return 0;
918}
919
920////////////////////////////////////////////////////////////////////////////////
921/// Actualize matrix of node indexed `<inode>`
922
923void TGeoVolume::cd(Int_t inode) const
924{
925 if (fFinder) fFinder->cd(inode-fFinder->GetDivIndex());
926}
927
928////////////////////////////////////////////////////////////////////////////////
929/// Add a TGeoNode to the list of nodes. This is the usual method for adding
930/// daughters inside the container volume.
931
933{
934 TGeoMatrix *matrix = mat;
935 if (matrix==0) matrix = gGeoIdentity;
936 else matrix->RegisterYourself();
937 if (!vol) {
938 Error("AddNode", "Volume is NULL");
939 return 0;
940 }
941 if (!vol->IsValid()) {
942 Error("AddNode", "Won't add node with invalid shape");
943 printf("### invalid volume was : %s\n", vol->GetName());
944 return 0;
945 }
946 if (!fNodes) fNodes = new TObjArray();
947
948 if (fFinder) {
949 // volume already divided.
950 Error("AddNode", "Cannot add node %s_%i into divided volume %s", vol->GetName(), copy_no, GetName());
951 return 0;
952 }
953
954 TGeoNodeMatrix *node = 0;
955 node = new TGeoNodeMatrix(vol, matrix);
956 node->SetMotherVolume(this);
957 fNodes->Add(node);
958 TString name = TString::Format("%s_%d", vol->GetName(), copy_no);
959// if (fNodes->FindObject(name))
960// Warning("AddNode", "Volume %s : added node %s with same name", GetName(), name.Data());
961 node->SetName(name);
962 node->SetNumber(copy_no);
963 fRefCount++;
964 vol->Grab();
965 return node;
966}
967
968////////////////////////////////////////////////////////////////////////////////
969/// Add a division node to the list of nodes. The method is called by
970/// TGeoVolume::Divide() for creating the division nodes.
971
973{
974 if (!vol) {
975 Error("AddNodeOffset", "invalid volume");
976 return;
977 }
978 if (!vol->IsValid()) {
979 Error("AddNode", "Won't add node with invalid shape");
980 printf("### invalid volume was : %s\n", vol->GetName());
981 return;
982 }
983 if (!fNodes) fNodes = new TObjArray();
984 TGeoNode *node = new TGeoNodeOffset(vol, copy_no, offset);
985 node->SetMotherVolume(this);
986 fNodes->Add(node);
987 TString name = TString::Format("%s_%d", vol->GetName(), copy_no+1);
988 node->SetName(name);
989 node->SetNumber(copy_no+1);
990 vol->Grab();
991}
992
993////////////////////////////////////////////////////////////////////////////////
994/// Add a TGeoNode to the list of nodes. This is the usual method for adding
995/// daughters inside the container volume.
996
998{
999 if (!vol) {
1000 Error("AddNodeOverlap", "Volume is NULL");
1001 return;
1002 }
1003 if (!vol->IsValid()) {
1004 Error("AddNodeOverlap", "Won't add node with invalid shape");
1005 printf("### invalid volume was : %s\n", vol->GetName());
1006 return;
1007 }
1008 if (vol->IsAssembly()) {
1009 Warning("AddNodeOverlap", "Declaring assembly %s as possibly overlapping inside %s not allowed. Using AddNode instead !",vol->GetName(),GetName());
1010 AddNode(vol, copy_no, mat, option);
1011 return;
1012 }
1013 TGeoMatrix *matrix = mat;
1014 if (matrix==0) matrix = gGeoIdentity;
1015 else matrix->RegisterYourself();
1016 if (!fNodes) fNodes = new TObjArray();
1017
1018 if (fFinder) {
1019 // volume already divided.
1020 Error("AddNodeOverlap", "Cannot add node %s_%i into divided volume %s", vol->GetName(), copy_no, GetName());
1021 return;
1022 }
1023
1024 TGeoNodeMatrix *node = new TGeoNodeMatrix(vol, matrix);
1025 node->SetMotherVolume(this);
1026 fNodes->Add(node);
1027 TString name = TString::Format("%s_%d", vol->GetName(), copy_no);
1028 if (fNodes->FindObject(name))
1029 Warning("AddNode", "Volume %s : added node %s with same name", GetName(), name.Data());
1030 node->SetName(name);
1031 node->SetNumber(copy_no);
1032 node->SetOverlapping();
1033 if (vol->GetMedium() == fMedium)
1034 node->SetVirtual();
1035 vol->Grab();
1036}
1037
1038////////////////////////////////////////////////////////////////////////////////
1039/// Division a la G3. The volume will be divided along IAXIS (see shape classes), in NDIV
1040/// slices, from START with given STEP. The division volumes will have medium number NUMED.
1041/// If NUMED=0 they will get the medium number of the divided volume (this). If NDIV<=0,
1042/// all range of IAXIS will be divided and the resulting number of divisions will be centered on
1043/// IAXIS. If STEP<=0, the real STEP will be computed as the full range of IAXIS divided by NDIV.
1044/// Options (case insensitive):
1045/// - N - divide all range in NDIV cells (same effect as STEP<=0) (GSDVN in G3)
1046/// - NX - divide range starting with START in NDIV cells (GSDVN2 in G3)
1047/// - S - divide all range with given STEP. NDIV is computed and divisions will be centered
1048/// in full range (same effect as NDIV<=0) (GSDVS, GSDVT in G3)
1049/// - SX - same as DVS, but from START position. (GSDVS2, GSDVT2 in G3)
1050
1051TGeoVolume *TGeoVolume::Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed, Option_t *option)
1052{
1053 if (fFinder) {
1054 // volume already divided.
1055 Fatal("Divide","volume %s already divided", GetName());
1056 return 0;
1057 }
1058 TString opt(option);
1059 opt.ToLower();
1060 TString stype = fShape->ClassName();
1061 if (!fNodes) fNodes = new TObjArray();
1062 Double_t xlo, xhi, range;
1063 range = fShape->GetAxisRange(iaxis, xlo, xhi);
1064 // for phi divisions correct the range
1065 if (!strcmp(fShape->GetAxisName(iaxis), "PHI")) {
1066 if ((start-xlo)<-1E-3) start+=360.;
1067 if (TGeoShape::IsSameWithinTolerance(range,360)) {
1068 xlo = start;
1069 xhi = start+range;
1070 }
1071 }
1072 if (range <=0) {
1073 InspectShape();
1074 Fatal("Divide", "cannot divide volume %s (%s) on %s axis", GetName(), stype.Data(), fShape->GetAxisName(iaxis));
1075 return 0;
1076 }
1077 if (ndiv<=0 || opt.Contains("s")) {
1078 if (step<=0) {
1079 Fatal("Divide", "invalid division type for volume %s : ndiv=%i, step=%g", GetName(), ndiv, step);
1080 return 0;
1081 }
1082 if (opt.Contains("x")) {
1083 if ((xlo-start)>1E-3 || (xhi-start)<-1E-3) {
1084 Fatal("Divide", "invalid START=%g for division on axis %s of volume %s. Range is (%g, %g)",
1085 start, fShape->GetAxisName(iaxis), GetName(), xlo, xhi);
1086 return 0;
1087 }
1088 xlo = start;
1089 range = xhi-xlo;
1090 }
1091 ndiv = Int_t((range+0.1*step)/step);
1092 Double_t ddx = range - ndiv*step;
1093 // always center the division in this case
1094 if (ddx>1E-3) Warning("Divide", "division of volume %s on %s axis (ndiv=%d) will be centered in the full range",
1095 GetName(), fShape->GetAxisName(iaxis), ndiv);
1096 start = xlo + 0.5*ddx;
1097 }
1098 if (step<=0 || opt.Contains("n")) {
1099 if (opt.Contains("x")) {
1100 if ((xlo-start)>1E-3 || (xhi-start)<-1E-3) {
1101 Fatal("Divide", "invalid START=%g for division on axis %s of volume %s. Range is (%g, %g)",
1102 start, fShape->GetAxisName(iaxis), GetName(), xlo, xhi);
1103 return 0;
1104 }
1105 xlo = start;
1106 range = xhi-xlo;
1107 }
1108 step = range/ndiv;
1109 start = xlo;
1110 }
1111
1112 Double_t end = start+ndiv*step;
1113 if (((start-xlo)<-1E-3) || ((end-xhi)>1E-3)) {
1114 Fatal("Divide", "division of volume %s on axis %s exceed range (%g, %g)",
1115 GetName(), fShape->GetAxisName(iaxis), xlo, xhi);
1116 return 0;
1117 }
1118 TGeoVolume *voldiv = fShape->Divide(this, divname, iaxis, ndiv, start, step);
1119 if (numed) {
1120 TGeoMedium *medium = fGeoManager->GetMedium(numed);
1121 if (!medium) {
1122 Fatal("Divide", "invalid medium number %d for division volume %s", numed, divname);
1123 return voldiv;
1124 }
1125 voldiv->SetMedium(medium);
1126 if (medium->GetMaterial()) medium->GetMaterial()->SetUsed();
1127 }
1128 return voldiv;
1129}
1130
1131////////////////////////////////////////////////////////////////////////////////
1132/// compute the closest distance of approach from point px,py to this volume
1133
1135{
1138 Int_t dist = 9999;
1139 if (!painter) return dist;
1140 dist = painter->DistanceToPrimitiveVol(this, px, py);
1141 return dist;
1142}
1143
1144////////////////////////////////////////////////////////////////////////////////
1145/// draw top volume according to option
1146
1148{
1153 if (!IsVisContainers()) SetVisLeaves();
1154 if (option && option[0] > 0) {
1155 painter->DrawVolume(this, option);
1156 } else {
1157 painter->DrawVolume(this, gEnv->GetValue("Viewer3D.DefaultDrawOption",""));
1158 }
1159}
1160
1161////////////////////////////////////////////////////////////////////////////////
1162/// draw only this volume
1163
1165{
1166 if (IsAssembly()) {
1167 Info("DrawOnly", "Volume assemblies do not support this option.");
1168 return;
1169 }
1171 SetVisOnly();
1174 if (option && option[0] > 0) {
1175 painter->DrawVolume(this, option);
1176 } else {
1177 painter->DrawVolume(this, gEnv->GetValue("Viewer3D.DefaultDrawOption",""));
1178 }
1179}
1180
1181////////////////////////////////////////////////////////////////////////////////
1182/// Perform an extensive sampling to find which type of voxelization is
1183/// most efficient.
1184
1186{
1187 printf("Optimizing volume %s ...\n", GetName());
1189 return painter->TestVoxels(this);
1190}
1191
1192////////////////////////////////////////////////////////////////////////////////
1193/// Print volume info
1194
1196{
1197 printf("== Volume: %s type %s positioned %d times\n", GetName(), ClassName(), fRefCount);
1198 InspectShape();
1200}
1201
1202////////////////////////////////////////////////////////////////////////////////
1203/// paint volume
1204
1206{
1208 painter->SetTopVolume(this);
1209// painter->Paint(option);
1210 if (option && option[0] > 0) {
1211 painter->Paint(option);
1212 } else {
1213 painter->Paint(gEnv->GetValue("Viewer3D.DefaultDrawOption",""));
1214 }
1215}
1216
1217////////////////////////////////////////////////////////////////////////////////
1218/// Print the voxels for this volume.
1219
1221{
1222 if (fVoxels) fVoxels->Print();
1223}
1224
1225////////////////////////////////////////////////////////////////////////////////
1226/// Recreate the content of the other volume without pointer copying. Voxels are
1227/// ignored and supposed to be created in a later step via Voxelize.
1228
1230{
1231 Int_t nd = other->GetNdaughters();
1232 if (!nd) return;
1233 TGeoPatternFinder *finder = other->GetFinder();
1234 if (finder) {
1235 Int_t iaxis = finder->GetDivAxis();
1236 Int_t ndiv = finder->GetNdiv();
1237 Double_t start = finder->GetStart();
1238 Double_t step = finder->GetStep();
1239 Int_t numed = other->GetNode(0)->GetVolume()->GetMedium()->GetId();
1240 TGeoVolume *voldiv = Divide(other->GetNode(0)->GetVolume()->GetName(), iaxis, ndiv, start, step, numed);
1241 voldiv->ReplayCreation(other->GetNode(0)->GetVolume());
1242 return;
1243 }
1244 for (Int_t i=0; i<nd; i++) {
1245 TGeoNode *node = other->GetNode(i);
1246 if (node->IsOverlapping()) AddNodeOverlap(node->GetVolume(), node->GetNumber(), node->GetMatrix());
1247 else AddNode(node->GetVolume(), node->GetNumber(), node->GetMatrix());
1248 }
1249}
1250
1251////////////////////////////////////////////////////////////////////////////////
1252/// print nodes
1253
1255{
1256 Int_t nd = GetNdaughters();
1257 for (Int_t i=0; i<nd; i++) {
1258 printf("%s\n", GetNode(i)->GetName());
1259 cd(i);
1260 GetNode(i)->GetMatrix()->Print();
1261 }
1262}
1263////////////////////////////////////////////////////////////////////////////////
1264/// Generate a lego plot fot the top volume, according to option.
1265
1267 Int_t nphi, Double_t phimin, Double_t phimax,
1268 Double_t rmin, Double_t rmax, Option_t *option)
1269{
1271 TGeoVolume *old_vol = fGeoManager->GetTopVolume();
1272 if (old_vol!=this) fGeoManager->SetTopVolume(this);
1273 else old_vol=0;
1274 TH2F *hist = p->LegoPlot(ntheta, themin, themax, nphi, phimin, phimax, rmin, rmax, option);
1275 hist->Draw("lego1sph");
1276 return hist;
1277}
1278
1279////////////////////////////////////////////////////////////////////////////////
1280/// Register the volume and all materials/media/matrices/shapes to the manager.
1281
1283{
1284 if (fGeoManager->GetListOfVolumes()->FindObject(this)) return;
1285 // Register volume
1286 fGeoManager->AddVolume(this);
1287 // Register shape
1289 if (fShape->IsComposite()) {
1291 comp->RegisterYourself();
1292 } else {
1294 }
1295 }
1296 // Register medium/material
1301 }
1302 // Register matrices for nodes.
1303 TGeoMatrix *matrix;
1304 TGeoNode *node;
1305 Int_t nd = GetNdaughters();
1306 Int_t i;
1307 for (i=0; i<nd; i++) {
1308 node = GetNode(i);
1309 matrix = node->GetMatrix();
1310 if (!matrix->IsRegistered()) matrix->RegisterYourself();
1311 else if (!fGeoManager->GetListOfMatrices()->FindObject(matrix)) {
1312 fGeoManager->GetListOfMatrices()->Add(matrix);
1313 }
1314 }
1315 // Call RegisterYourself recursively
1316 for (i=0; i<nd; i++) GetNode(i)->GetVolume()->RegisterYourself(option);
1317}
1318
1319////////////////////////////////////////////////////////////////////////////////
1320/// Draw random points in the bounding box of this volume.
1321
1323{
1325 TGeoVolume *old_vol = fGeoManager->GetTopVolume();
1326 if (old_vol!=this) fGeoManager->SetTopVolume(this);
1327 else old_vol=0;
1328 fGeoManager->RandomPoints(this, npoints, option);
1329 if (old_vol) fGeoManager->SetTopVolume(old_vol);
1330}
1331
1332////////////////////////////////////////////////////////////////////////////////
1333/// Random raytracing method.
1334
1335void TGeoVolume::RandomRays(Int_t nrays, Double_t startx, Double_t starty, Double_t startz, const char *target_vol, Bool_t check_norm)
1336{
1338 TGeoVolume *old_vol = fGeoManager->GetTopVolume();
1339 if (old_vol!=this) fGeoManager->SetTopVolume(this);
1340 else old_vol=0;
1341 fGeoManager->RandomRays(nrays, startx, starty, startz, target_vol, check_norm);
1342 if (old_vol) fGeoManager->SetTopVolume(old_vol);
1343}
1344
1345////////////////////////////////////////////////////////////////////////////////
1346/// Draw this volume with current settings and perform raytracing in the pad.
1347
1349{
1353 Bool_t drawn = (painter->GetDrawnVolume()==this)?kTRUE:kFALSE;
1354 if (!drawn) {
1355 painter->DrawVolume(this, "");
1357 painter->ModifiedPad();
1358 return;
1359 }
1361 painter->ModifiedPad();
1362}
1363
1364////////////////////////////////////////////////////////////////////////////////
1365/// Save geometry having this as top volume as a C++ macro.
1366
1368{
1369 if (!filename) return;
1370 std::ofstream out;
1371 out.open(filename, std::ios::out);
1372 if (out.bad()) {
1373 Error("SavePrimitive", "Bad file name: %s", filename);
1374 return;
1375 }
1377
1378 TString fname(filename);
1379 Int_t ind = fname.Index(".");
1380 if (ind>0) fname.Remove(ind);
1381 out << "void "<<fname<<"() {" << std::endl;
1382 out << " gSystem->Load(\"libGeom\");" << std::endl;
1384 out << std::setprecision(prec);
1385 ((TGeoVolume*)this)->SavePrimitive(out,option);
1386 out << "}" << std::endl;
1387}
1388
1389////////////////////////////////////////////////////////////////////////////////
1390/// Connect user-defined extension to the volume. The volume "grabs" a copy, so
1391/// the original object can be released by the producer. Release the previously
1392/// connected extension if any.
1393///
1394/// NOTE: This interface is intended for user extensions and is guaranteed not
1395/// to be used by TGeo
1396
1398{
1400 fUserExtension = 0;
1401 if (ext) fUserExtension = ext->Grab();
1402}
1403
1404////////////////////////////////////////////////////////////////////////////////
1405/// Connect framework defined extension to the volume. The volume "grabs" a copy,
1406/// so the original object can be released by the producer. Release the previously
1407/// connected extension if any.
1408///
1409/// NOTE: This interface is intended for the use by TGeo and the users should
1410/// NOT connect extensions using this method
1411
1413{
1415 fFWExtension = 0;
1416 if (ext) fFWExtension = ext->Grab();
1417}
1418
1419////////////////////////////////////////////////////////////////////////////////
1420/// Get a copy of the user extension pointer. The user must call Release() on
1421/// the copy pointer once this pointer is not needed anymore (equivalent to
1422/// delete() after calling new())
1423
1425{
1426 if (fUserExtension) return fUserExtension->Grab();
1427 return 0;
1428}
1429
1430////////////////////////////////////////////////////////////////////////////////
1431/// Get a copy of the framework extension pointer. The user must call Release() on
1432/// the copy pointer once this pointer is not needed anymore (equivalent to
1433/// delete() after calling new())
1434
1436{
1437 if (fFWExtension) return fFWExtension->Grab();
1438 return 0;
1439}
1440
1441////////////////////////////////////////////////////////////////////////////////
1442/// Save a primitive as a C++ statement(s) on output stream "out".
1443
1444void TGeoVolume::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1445{
1446 Int_t i,icopy;
1447 Int_t nd = GetNdaughters();
1448 TGeoVolume *dvol;
1449 TGeoNode *dnode;
1450 TGeoMatrix *matrix;
1451
1452 // check if we need to save shape/volume
1453 Bool_t mustDraw = kFALSE;
1454 if (fGeoManager->GetGeomPainter()->GetTopVolume()==this) mustDraw = kTRUE;
1455 if (!option[0]) {
1457 out << " new TGeoManager(\"" << fGeoManager->GetName() << "\", \"" << fGeoManager->GetTitle() << "\");" << std::endl << std::endl;
1458// if (mustDraw) out << " Bool_t mustDraw = kTRUE;" << std::endl;
1459// else out << " Bool_t mustDraw = kFALSE;" << std::endl;
1460 out << " Double_t dx,dy,dz;" << std::endl;
1461 out << " Double_t dx1, dx2, dy1, dy2;" << std::endl;
1462 out << " Double_t vert[20], par[20];" << std::endl;
1463 out << " Double_t theta, phi, h1, bl1, tl1, alpha1, h2, bl2, tl2, alpha2;" << std::endl;
1464 out << " Double_t twist;" << std::endl;
1465 out << " Double_t origin[3];" << std::endl;
1466 out << " Double_t rmin, rmax, rmin1, rmax1, rmin2, rmax2;" << std::endl;
1467 out << " Double_t r, rlo, rhi;" << std::endl;
1468 out << " Double_t phi1, phi2;" << std::endl;
1469 out << " Double_t a,b;" << std::endl;
1470 out << " Double_t point[3], norm[3];" << std::endl;
1471 out << " Double_t rin, stin, rout, stout;" << std::endl;
1472 out << " Double_t thx, phx, thy, phy, thz, phz;" << std::endl;
1473 out << " Double_t alpha, theta1, theta2, phi1, phi2, dphi;" << std::endl;
1474 out << " Double_t tr[3], rot[9];" << std::endl;
1475 out << " Double_t z, density, radl, absl, w;" << std::endl;
1476 out << " Double_t lx,ly,lz,tx,ty,tz;" << std::endl;
1477 out << " Double_t xvert[50], yvert[50];" << std::endl;
1478 out << " Double_t zsect,x0,y0,scale0;" << std::endl;
1479 out << " Int_t nel, numed, nz, nedges, nvert;" << std::endl;
1480 out << " TGeoBoolNode *pBoolNode = 0;" << std::endl << std::endl;
1481 // first save materials/media
1482 out << " // MATERIALS, MIXTURES AND TRACKING MEDIA" << std::endl;
1483 SavePrimitive(out, "m");
1484 // then, save matrices
1485 out << std::endl << " // TRANSFORMATION MATRICES" << std::endl;
1486 SavePrimitive(out, "x");
1487 // save this volume and shape
1488 SavePrimitive(out, "s");
1489 out << std::endl << " // SET TOP VOLUME OF GEOMETRY" << std::endl;
1490 out << " gGeoManager->SetTopVolume(" << GetPointerName() << ");" << std::endl;
1491 // save daughters
1492 out << std::endl << " // SHAPES, VOLUMES AND GEOMETRICAL HIERARCHY" << std::endl;
1493 SavePrimitive(out, "d");
1494 out << std::endl << " // CLOSE GEOMETRY" << std::endl;
1495 out << " gGeoManager->CloseGeometry();" << std::endl;
1496 if (mustDraw) {
1497 if (!IsRaytracing()) out << " gGeoManager->GetTopVolume()->Draw();" << std::endl;
1498 else out << " gGeoManager->GetTopVolume()->Raytrace();" << std::endl;
1499 }
1500 return;
1501 }
1502 // check if we need to save shape/volume
1503 if (!strcmp(option, "s")) {
1504 // create the shape for this volume
1506 if (!IsAssembly()) {
1508 out << " // Volume: " << GetName() << std::endl;
1509 if (fMedium) out << " " << GetPointerName() << " = new TGeoVolume(\"" << GetName() << "\"," << fShape->GetPointerName() << ", "<< fMedium->GetPointerName() << ");" << std::endl;
1510 else out << " " << GetPointerName() << " = new TGeoVolume(\"" << GetName() << "\"," << fShape->GetPointerName() << ");" << std::endl;
1511
1512 } else {
1513 out << " // Assembly: " << GetName() << std::endl;
1514 out << " " << GetPointerName() << " = new TGeoVolumeAssembly(\"" << GetName() << "\"" << ");" << std::endl;
1515 }
1516 if (fLineColor != 1) out << " " << GetPointerName() << "->SetLineColor(" << fLineColor << ");" << std::endl;
1517 if (fLineWidth != 1) out << " " << GetPointerName() << "->SetLineWidth(" << fLineWidth << ");" << std::endl;
1518 if (fLineStyle != 1) out << " " << GetPointerName() << "->SetLineStyle(" << fLineStyle << ");" << std::endl;
1519 if (!IsVisible() && !IsAssembly()) out << " " << GetPointerName() << "->SetVisibility(kFALSE);" << std::endl;
1520 if (!IsVisibleDaughters()) out << " " << GetPointerName() << "->VisibleDaughters(kFALSE);" << std::endl;
1521 if (IsVisContainers()) out << " " << GetPointerName() << "->SetVisContainers(kTRUE);" << std::endl;
1522 if (IsVisLeaves()) out << " " << GetPointerName() << "->SetVisLeaves(kTRUE);" << std::endl;
1524 }
1525 // check if we need to save the media
1526 if (!strcmp(option, "m")) {
1528 for (i=0; i<nd; i++) {
1529 dvol = GetNode(i)->GetVolume();
1530 dvol->SavePrimitive(out,option);
1531 }
1532 return;
1533 }
1534 // check if we need to save the matrices
1535 if (!strcmp(option, "x")) {
1536 if (fFinder) {
1537 dvol = GetNode(0)->GetVolume();
1538 dvol->SavePrimitive(out,option);
1539 return;
1540 }
1541 for (i=0; i<nd; i++) {
1542 dnode = GetNode(i);
1543 matrix = dnode->GetMatrix();
1544 if (!matrix->IsIdentity()) matrix->SavePrimitive(out,option);
1545 dnode->GetVolume()->SavePrimitive(out,option);
1546 }
1547 return;
1548 }
1549 // check if we need to save volume daughters
1550 if (!strcmp(option, "d")) {
1551 if (!nd) return;
1554 if (fFinder) {
1555 // volume divided: generate volume->Divide()
1556 dnode = GetNode(0);
1557 dvol = dnode->GetVolume();
1558 out << " TGeoVolume *" << dvol->GetPointerName() << " = ";
1559 out << GetPointerName() << "->Divide(\"" << dvol->GetName() << "\", ";
1561 if (fMedium != dvol->GetMedium()) {
1562 out << ", " << dvol->GetMedium()->GetId();
1563 }
1564 out << ");" << std::endl;
1565 dvol->SavePrimitive(out,"d");
1566 return;
1567 }
1568 for (i=0; i<nd; i++) {
1569 dnode = GetNode(i);
1570 dvol = dnode->GetVolume();
1571 dvol->SavePrimitive(out,"s");
1572 matrix = dnode->GetMatrix();
1573 icopy = dnode->GetNumber();
1574 // generate AddNode()
1575 out << " " << GetPointerName() << "->AddNode";
1576 if (dnode->IsOverlapping()) out << "Overlap";
1577 out << "(" << dvol->GetPointerName() << ", " << icopy;
1578 if (!matrix->IsIdentity()) out << ", " << matrix->GetPointerName();
1579 out << ");" << std::endl;
1580 }
1581 // Recursive loop to daughters
1582 for (i=0; i<nd; i++) {
1583 dnode = GetNode(i);
1584 dvol = dnode->GetVolume();
1585 dvol->SavePrimitive(out,"d");
1586 }
1587 }
1588}
1589
1590////////////////////////////////////////////////////////////////////////////////
1591/// Reset SavePrimitive bits.
1592
1594{
1598}
1599
1600////////////////////////////////////////////////////////////////////////////////
1601/// Execute mouse actions on this volume.
1602
1604{
1606 if (!painter) return;
1607 painter->ExecuteVolumeEvent(this, event, px, py);
1608}
1609
1610////////////////////////////////////////////////////////////////////////////////
1611/// search a daughter inside the list of nodes
1612
1614{
1615 return ((TGeoNode*)fNodes->FindObject(name));
1616}
1617
1618////////////////////////////////////////////////////////////////////////////////
1619/// Get the index of a daughter within check_list by providing the node pointer.
1620
1621Int_t TGeoVolume::GetNodeIndex(const TGeoNode *node, Int_t *check_list, Int_t ncheck) const
1622{
1623 TGeoNode *current = 0;
1624 for (Int_t i=0; i<ncheck; i++) {
1625 current = (TGeoNode*)fNodes->At(check_list[i]);
1626 if (current==node) return check_list[i];
1627 }
1628 return -1;
1629}
1630
1631////////////////////////////////////////////////////////////////////////////////
1632/// get index number for a given daughter
1633
1635{
1636 TGeoNode *current = 0;
1637 Int_t nd = GetNdaughters();
1638 if (!nd) return -1;
1639 for (Int_t i=0; i<nd; i++) {
1640 current = (TGeoNode*)fNodes->At(i);
1641 if (current==node) return i;
1642 }
1643 return -1;
1644}
1645
1646////////////////////////////////////////////////////////////////////////////////
1647/// Get volume info for the browser.
1648
1650{
1651 TGeoVolume *vol = (TGeoVolume*)this;
1653 if (!painter) return 0;
1654 return (char*)painter->GetVolumeInfo(vol, px, py);
1655}
1656
1657////////////////////////////////////////////////////////////////////////////////
1658/// Returns true if cylindrical voxelization is optimal.
1659
1661{
1662 Int_t nd = GetNdaughters();
1663 if (!nd) return kFALSE;
1664 Int_t id;
1665 Int_t ncyl = 0;
1666 TGeoNode *node;
1667 for (id=0; id<nd; id++) {
1668 node = (TGeoNode*)fNodes->At(id);
1669 ncyl += node->GetOptimalVoxels();
1670 }
1671 if (ncyl>(nd/2)) return kTRUE;
1672 return kFALSE;
1673}
1674
1675////////////////////////////////////////////////////////////////////////////////
1676/// Provide a pointer name containing uid.
1677
1679{
1680 static TString name;
1681 name = TString::Format("p%s_%zx", GetName(), (size_t)this);
1682 return (char*)name.Data();
1683}
1684
1685////////////////////////////////////////////////////////////////////////////////
1686/// Getter for optimization structure.
1687
1689{
1690 if (fVoxels && !fVoxels->IsInvalid()) return fVoxels;
1691 return NULL;
1692}
1693
1694////////////////////////////////////////////////////////////////////////////////
1695/// Move perspective view focus to this volume
1696
1698{
1700 if (painter) painter->GrabFocus();
1701}
1702
1703////////////////////////////////////////////////////////////////////////////////
1704/// Returns true if the volume is an assembly or a scaled assembly.
1705
1707{
1708 return fShape->IsAssembly();
1709}
1710
1711////////////////////////////////////////////////////////////////////////////////
1712/// Clone this volume.
1713/// build a volume with same name, shape and medium
1714
1716{
1717 TGeoVolume *vol = new TGeoVolume(GetName(), fShape, fMedium);
1718 Int_t i;
1719 // copy volume attributes
1720 vol->SetTitle(GetTitle());
1721 vol->SetLineColor(GetLineColor());
1722 vol->SetLineStyle(GetLineStyle());
1723 vol->SetLineWidth(GetLineWidth());
1724 vol->SetFillColor(GetFillColor());
1725 vol->SetFillStyle(GetFillStyle());
1726 // copy other attributes
1727 Int_t nbits = 8*sizeof(UInt_t);
1728 for (i=0; i<nbits; i++)
1729 vol->SetAttBit(1<<i, TGeoAtt::TestAttBit(1<<i));
1730 for (i=14; i<24; i++)
1731 vol->SetBit(1<<i, TestBit(1<<i));
1732
1733 // copy field
1734 vol->SetField(fField);
1735 // Set bits
1736 for (i=0; i<nbits; i++)
1737 vol->SetBit(1<<i, TObject::TestBit(1<<i));
1738 vol->SetBit(kVolumeClone);
1739 // copy nodes
1740// CloneNodesAndConnect(vol);
1741 vol->MakeCopyNodes(this);
1742 // if volume is divided, copy finder
1743 vol->SetFinder(fFinder);
1744 // copy voxels
1745 TGeoVoxelFinder *voxels = 0;
1746 if (fVoxels) {
1747 voxels = new TGeoVoxelFinder(vol);
1748 vol->SetVoxelFinder(voxels);
1749 }
1750 // copy option, uid
1751 vol->SetOption(fOption);
1752 vol->SetNumber(fNumber);
1753 vol->SetNtotal(fNtotal);
1754 // copy extensions
1758 return vol;
1759}
1760
1761////////////////////////////////////////////////////////////////////////////////
1762/// Clone the array of nodes.
1763
1765{
1766 if (!fNodes) return;
1767 TGeoNode *node;
1768 Int_t nd = fNodes->GetEntriesFast();
1769 if (!nd) return;
1770 // create new list of nodes
1771 TObjArray *list = new TObjArray(nd);
1772 // attach it to new volume
1773 newmother->SetNodes(list);
1774// ((TObject*)newmother)->SetBit(kVolumeImportNodes);
1775 for (Int_t i=0; i<nd; i++) {
1776 //create copies of nodes and add them to list
1777 node = GetNode(i)->MakeCopyNode();
1778 if (!node) {
1779 Fatal("CloneNodesAndConnect", "cannot make copy node");
1780 return;
1781 }
1782 node->SetMotherVolume(newmother);
1783 list->Add(node);
1784 }
1785}
1786
1787////////////////////////////////////////////////////////////////////////////////
1788/// make a new list of nodes and copy all nodes of other volume inside
1789
1791{
1792 Int_t nd = other->GetNdaughters();
1793 if (!nd) return;
1794 if (fNodes) {
1796 delete fNodes;
1797 }
1798 fNodes = new TObjArray();
1799 for (Int_t i=0; i<nd; i++) fNodes->Add(other->GetNode(i));
1801}
1802
1803////////////////////////////////////////////////////////////////////////////////
1804/// make a copy of this volume
1805/// build a volume with same name, shape and medium
1806
1808{
1809 TGeoVolume *vol = new TGeoVolume(GetName(), newshape, fMedium);
1810 // copy volume attributes
1811 vol->SetVisibility(IsVisible());
1812 vol->SetLineColor(GetLineColor());
1813 vol->SetLineStyle(GetLineStyle());
1814 vol->SetLineWidth(GetLineWidth());
1815 vol->SetFillColor(GetFillColor());
1816 vol->SetFillStyle(GetFillStyle());
1817 // copy field
1818 vol->SetField(fField);
1819 // if divided, copy division object
1820 if (fFinder) {
1821// Error("MakeCopyVolume", "volume %s divided", GetName());
1822 vol->SetFinder(fFinder);
1823 }
1824 // Copy extensions
1828// ((TObject*)vol)->SetBit(kVolumeImportNodes);
1829 ((TObject*)vol)->SetBit(kVolumeClone);
1831 return vol;
1832}
1833
1834////////////////////////////////////////////////////////////////////////////////
1835/// Make a copy of this volume which is reflected with respect to XY plane.
1836
1838{
1839 static TMap map(100);
1840 if (!fGeoManager->IsClosed()) {
1841 Error("MakeReflectedVolume", "Geometry must be closed.");
1842 return NULL;
1843 }
1844 TGeoVolume *vol = (TGeoVolume*)map.GetValue(this);
1845 if (vol) {
1846 if (newname && newname[0]) vol->SetName(newname);
1847 return vol;
1848 }
1849// printf("Making reflection for volume: %s\n", GetName());
1850 vol = CloneVolume();
1851 if (!vol) {
1852 Fatal("MakeReflectedVolume", "Cannot clone volume %s\n", GetName());
1853 return 0;
1854 }
1855 map.Add((TObject*)this, vol);
1856 if (newname && newname[0]) vol->SetName(newname);
1857 delete vol->GetNodes();
1858 vol->SetNodes(NULL);
1861 // The volume is now properly cloned, but with the same shape.
1862 // Reflect the shape (if any) and connect it.
1863 if (fShape) {
1864 TGeoShape *reflected_shape =
1866 vol->SetShape(reflected_shape);
1867 }
1868 // Reflect the daughters.
1869 Int_t nd = vol->GetNdaughters();
1870 if (!nd) return vol;
1871 TGeoNodeMatrix *node;
1872 TGeoMatrix *local, *local_cloned;
1873 TGeoVolume *new_vol;
1874 if (!vol->GetFinder()) {
1875 for (Int_t i=0; i<nd; i++) {
1876 node = (TGeoNodeMatrix*)vol->GetNode(i);
1877 local = node->GetMatrix();
1878// printf("%s before\n", node->GetName());
1879// local->Print();
1880 Bool_t reflected = local->IsReflection();
1881 local_cloned = new TGeoCombiTrans(*local);
1882 local_cloned->RegisterYourself();
1883 node->SetMatrix(local_cloned);
1884 if (!reflected) {
1885 // We need to reflect only the translation and propagate to daughters.
1886 // H' = Sz * H * Sz
1887 local_cloned->ReflectZ(kTRUE);
1888 local_cloned->ReflectZ(kFALSE);
1889// printf("%s after\n", node->GetName());
1890// node->GetMatrix()->Print();
1891 new_vol = node->GetVolume()->MakeReflectedVolume();
1892 node->SetVolume(new_vol);
1893 continue;
1894 }
1895 // The next daughter is already reflected, so reflect on Z everything and stop
1896 local_cloned->ReflectZ(kTRUE); // rot + tr
1897// printf("%s already reflected... After:\n", node->GetName());
1898// node->GetMatrix()->Print();
1899 }
1900 if (vol->GetVoxels()) vol->GetVoxels()->Voxelize();
1901 return vol;
1902 }
1903 // Volume is divided, so we have to reflect the division.
1904// printf(" ... divided %s\n", fFinder->ClassName());
1905 TGeoPatternFinder *new_finder = fFinder->MakeCopy(kTRUE);
1906 if (!new_finder) {
1907 Fatal("MakeReflectedVolume", "Could not copy finder for volume %s", GetName());
1908 return 0;
1909 }
1910 new_finder->SetVolume(vol);
1911 vol->SetFinder(new_finder);
1912 TGeoNodeOffset *nodeoff;
1913 new_vol = 0;
1914 for (Int_t i=0; i<nd; i++) {
1915 nodeoff = (TGeoNodeOffset*)vol->GetNode(i);
1916 nodeoff->SetFinder(new_finder);
1917 new_vol = nodeoff->GetVolume()->MakeReflectedVolume();
1918 nodeoff->SetVolume(new_vol);
1919 }
1920 return vol;
1921}
1922
1923////////////////////////////////////////////////////////////////////////////////
1924/// Set this volume as the TOP one (the whole geometry starts from here)
1925
1927{
1929}
1930
1931////////////////////////////////////////////////////////////////////////////////
1932/// Set the current tracking point.
1933
1935{
1937}
1938
1939////////////////////////////////////////////////////////////////////////////////
1940/// set the shape associated with this volume
1941
1943{
1944 if (!shape) {
1945 Error("SetShape", "No shape");
1946 return;
1947 }
1948 fShape = (TGeoShape*)shape;
1949}
1950
1951////////////////////////////////////////////////////////////////////////////////
1952/// sort nodes by decreasing volume of the bounding box. ONLY nodes comes first,
1953/// then overlapping nodes and finally division nodes.
1954
1956{
1957 if (!Valid()) {
1958 Error("SortNodes", "Bounding box not valid");
1959 return;
1960 }
1961 Int_t nd = GetNdaughters();
1962// printf("volume : %s, nd=%i\n", GetName(), nd);
1963 if (!nd) return;
1964 if (fFinder) return;
1965// printf("Nodes for %s\n", GetName());
1966 Int_t id = 0;
1967 TGeoNode *node = 0;
1968 TObjArray *nodes = new TObjArray(nd);
1969 Int_t inode = 0;
1970 // first put ONLY's
1971 for (id=0; id<nd; id++) {
1972 node = GetNode(id);
1973 if (node->InheritsFrom(TGeoNodeOffset::Class()) || node->IsOverlapping()) continue;
1974 nodes->Add(node);
1975// printf("inode %i ONLY\n", inode);
1976 inode++;
1977 }
1978 // second put overlapping nodes
1979 for (id=0; id<nd; id++) {
1980 node = GetNode(id);
1981 if (node->InheritsFrom(TGeoNodeOffset::Class()) || (!node->IsOverlapping())) continue;
1982 nodes->Add(node);
1983// printf("inode %i MANY\n", inode);
1984 inode++;
1985 }
1986 // third put the divided nodes
1987 if (fFinder) {
1988 fFinder->SetDivIndex(inode);
1989 for (id=0; id<nd; id++) {
1990 node = GetNode(id);
1991 if (!node->InheritsFrom(TGeoNodeOffset::Class())) continue;
1992 nodes->Add(node);
1993// printf("inode %i DIV\n", inode);
1994 inode++;
1995 }
1996 }
1997 if (inode != nd) printf(" volume %s : number of nodes does not match!!!\n", GetName());
1998 delete fNodes;
1999 fNodes = nodes;
2000}
2001
2002////////////////////////////////////////////////////////////////////////////////
2003/// Stream an object of class TGeoVolume.
2004
2006{
2007 if (R__b.IsReading()) {
2008 R__b.ReadClassBuffer(TGeoVolume::Class(), this);
2009 if (fVoxels && fVoxels->IsInvalid()) Voxelize("");
2010 } else {
2011 if (!fVoxels) {
2012 R__b.WriteClassBuffer(TGeoVolume::Class(), this);
2013 } else {
2015 TGeoVoxelFinder *voxels = fVoxels;
2016 fVoxels = 0;
2017 R__b.WriteClassBuffer(TGeoVolume::Class(), this);
2018 fVoxels = voxels;
2019 } else {
2020 R__b.WriteClassBuffer(TGeoVolume::Class(), this);
2021 }
2022 }
2023 }
2024}
2025
2026////////////////////////////////////////////////////////////////////////////////
2027/// Set the current options (none implemented)
2028
2030{
2031 fOption = option;
2032}
2033
2034////////////////////////////////////////////////////////////////////////////////
2035/// Set the line color.
2036
2038{
2039 TAttLine::SetLineColor(lcolor);
2040}
2041
2042////////////////////////////////////////////////////////////////////////////////
2043/// Set the line style.
2044
2046{
2047 TAttLine::SetLineStyle(lstyle);
2048}
2049
2050////////////////////////////////////////////////////////////////////////////////
2051/// Set the line width.
2052
2054{
2055 TAttLine::SetLineWidth(lwidth);
2056}
2057
2058////////////////////////////////////////////////////////////////////////////////
2059/// get the pointer to a daughter node
2060
2062{
2063 if (!fNodes) return 0;
2064 TGeoNode *node = (TGeoNode *)fNodes->FindObject(name);
2065 return node;
2066}
2067
2068////////////////////////////////////////////////////////////////////////////////
2069/// get the total size in bytes for this volume
2070
2072{
2073 Int_t count = 28+2+6+4+0; // TNamed+TGeoAtt+TAttLine+TAttFill+TAtt3D
2074 count += fName.Capacity() + fTitle.Capacity(); // name+title
2075 count += 7*sizeof(char*); // fShape + fMedium + fFinder + fField + fNodes + 2 extensions
2076 count += fOption.Capacity(); // fOption
2077 if (fShape) count += fShape->GetByteCount();
2078 if (fFinder) count += fFinder->GetByteCount();
2079 if (fNodes) {
2080 count += 32 + 4*fNodes->GetEntries(); // TObjArray
2081 TIter next(fNodes);
2082 TGeoNode *node;
2083 while ((node=(TGeoNode*)next())) count += node->GetByteCount();
2084 }
2085 return count;
2086}
2087
2088////////////////////////////////////////////////////////////////////////////////
2089/// loop all nodes marked as overlaps and find overlapping brothers
2090
2092{
2093 if (!Valid()) {
2094 Error("FindOverlaps","Bounding box not valid");
2095 return;
2096 }
2097 if (!fVoxels) return;
2098 Int_t nd = GetNdaughters();
2099 if (!nd) return;
2100 TGeoNode *node=0;
2101 Int_t inode = 0;
2102 for (inode=0; inode<nd; inode++) {
2103 node = GetNode(inode);
2104 if (!node->IsOverlapping()) continue;
2105 fVoxels->FindOverlaps(inode);
2106 }
2107}
2108
2109////////////////////////////////////////////////////////////////////////////////
2110/// Remove an existing daughter.
2111
2113{
2114 if (!fNodes || !fNodes->GetEntriesFast()) return;
2115 if (!fNodes->Remove(node)) return;
2116 fNodes->Compress();
2118 if (IsAssembly()) fShape->ComputeBBox();
2119}
2120
2121////////////////////////////////////////////////////////////////////////////////
2122/// Replace an existing daughter with a new volume having the same name but
2123/// possibly a new shape, position or medium. Not allowed for positioned assemblies.
2124/// For division cells, the new shape/matrix are ignored.
2125
2127{
2128 Int_t ind = GetIndex(nodeorig);
2129 if (ind < 0) return NULL;
2130 TGeoVolume *oldvol = nodeorig->GetVolume();
2131 if (oldvol->IsAssembly()) {
2132 Error("ReplaceNode", "Cannot replace node %s since it is an assembly", nodeorig->GetName());
2133 return NULL;
2134 }
2135 TGeoShape *shape = oldvol->GetShape();
2136 if (newshape && !nodeorig->IsOffset()) shape = newshape;
2137 TGeoMedium *med = oldvol->GetMedium();
2138 if (newmed) med = newmed;
2139 // Make a new volume
2140 TGeoVolume *vol = new TGeoVolume(oldvol->GetName(), shape, med);
2141 // copy volume attributes
2142 vol->SetVisibility(oldvol->IsVisible());
2143 vol->SetLineColor(oldvol->GetLineColor());
2144 vol->SetLineStyle(oldvol->GetLineStyle());
2145 vol->SetLineWidth(oldvol->GetLineWidth());
2146 vol->SetFillColor(oldvol->GetFillColor());
2147 vol->SetFillStyle(oldvol->GetFillStyle());
2148 // copy field
2149 vol->SetField(oldvol->GetField());
2150 // Make a copy of the node
2151 TGeoNode *newnode = nodeorig->MakeCopyNode();
2152 if (!newnode) {
2153 Fatal("ReplaceNode", "Cannot make copy node for %s", nodeorig->GetName());
2154 return 0;
2155 }
2156 // Change the volume for the new node
2157 newnode->SetVolume(vol);
2158 // Replace the matrix
2159 if (newpos && !nodeorig->IsOffset()) {
2160 TGeoNodeMatrix *nodemat = (TGeoNodeMatrix*)newnode;
2161 nodemat->SetMatrix(newpos);
2162 }
2163 // Replace nodeorig with new one
2164 fNodes->RemoveAt(ind);
2165 fNodes->AddAt(newnode, ind);
2167 if (IsAssembly()) fShape->ComputeBBox();
2168 return newnode;
2169}
2170
2171////////////////////////////////////////////////////////////////////////////////
2172/// Select this volume as matching an arbitrary criteria. The volume is added to
2173/// a static list and the flag TGeoVolume::kVolumeSelected is set. All flags need
2174/// to be reset at the end by calling the method with CLEAR=true. This will also clear
2175/// the list.
2176
2178{
2179 static TObjArray array(256);
2180 static Int_t len = 0;
2181 Int_t i;
2182 TObject *vol;
2183 if (clear) {
2184 for (i=0; i<len; i++) {
2185 vol = array.At(i);
2187 }
2188 array.Clear();
2189 len = 0;
2190 return;
2191 }
2193 array.AddAtAndExpand(this, len++);
2194}
2195
2196////////////////////////////////////////////////////////////////////////////////
2197/// set visibility of this volume
2198
2200{
2204 TSeqCollection *brlist = gROOT->GetListOfBrowsers();
2205 TIter next(brlist);
2206 TBrowser *browser = 0;
2207 while ((browser=(TBrowser*)next())) {
2208 browser->CheckObjectItem(this, vis);
2209 browser->Refresh();
2210 }
2211}
2212
2213////////////////////////////////////////////////////////////////////////////////
2214/// Set visibility for containers.
2215
2217{
2219 if (fGeoManager && fGeoManager->IsClosed()) {
2222 }
2223}
2224
2225////////////////////////////////////////////////////////////////////////////////
2226/// Set visibility for leaves.
2227
2229{
2231 if (fGeoManager && fGeoManager->IsClosed()) {
2234 }
2235}
2236
2237////////////////////////////////////////////////////////////////////////////////
2238/// Set visibility for leaves.
2239
2241{
2242 if (IsAssembly()) return;
2243 TGeoAtt::SetVisOnly(flag);
2244 if (fGeoManager && fGeoManager->IsClosed()) {
2247 }
2248}
2249
2250////////////////////////////////////////////////////////////////////////////////
2251/// Check if the shape of this volume is valid.
2252
2254{
2255 return fShape->IsValidBox();
2256}
2257
2258////////////////////////////////////////////////////////////////////////////////
2259/// Find a daughter node having VOL as volume and fill TGeoManager::fHMatrix
2260/// with its global matrix.
2261
2263{
2264 if (vol == this) return kTRUE;
2265 Int_t nd = GetNdaughters();
2266 if (!nd) return kFALSE;
2267 TGeoHMatrix *global = fGeoManager->GetHMatrix();
2268 if (!global) return kFALSE;
2269 TGeoNode *dnode;
2270 TGeoVolume *dvol;
2271 TGeoMatrix *local;
2272 Int_t i;
2273 for (i=0; i<nd; i++) {
2274 dnode = GetNode(i);
2275 dvol = dnode->GetVolume();
2276 if (dvol == vol) {
2277 local = dnode->GetMatrix();
2278 global->MultiplyLeft(local);
2279 return kTRUE;
2280 }
2281 }
2282 for (i=0; i<nd; i++) {
2283 dnode = GetNode(i);
2284 dvol = dnode->GetVolume();
2285 if (dvol->FindMatrixOfDaughterVolume(vol)) return kTRUE;
2286 }
2287 return kFALSE;
2288}
2289
2290////////////////////////////////////////////////////////////////////////////////
2291/// set visibility for daughters
2292
2294{
2295 SetVisDaughters(vis);
2298}
2299
2300////////////////////////////////////////////////////////////////////////////////
2301/// build the voxels for this volume
2302
2304{
2305 if (!Valid()) {
2306 Error("Voxelize", "Bounding box not valid");
2307 return;
2308 }
2309 // do not voxelize divided volumes
2310 if (fFinder) return;
2311 // or final leaves
2312 Int_t nd = GetNdaughters();
2313 if (!nd) return;
2314 // If this is an assembly, re-compute bounding box
2315 if (IsAssembly()) fShape->ComputeBBox();
2316 // delete old voxelization if any
2317 if (fVoxels) {
2319 fVoxels = 0;
2320 }
2321 // Create the voxels structure
2322 fVoxels = new TGeoVoxelFinder(this);
2324 if (fVoxels) {
2325 if (fVoxels->IsInvalid()) {
2326 delete fVoxels;
2327 fVoxels = 0;
2328 }
2329 }
2330}
2331
2332////////////////////////////////////////////////////////////////////////////////
2333/// Estimate the weight of a volume (in kg) with SIGMA(M)/M better than PRECISION.
2334/// Option can contain : v - verbose, a - analytical (default)
2335
2337{
2339 if (top != this) fGeoManager->SetTopVolume(this);
2340 else top = 0;
2341 Double_t weight = fGeoManager->Weight(precision, option);
2342 if (top) fGeoManager->SetTopVolume(top);
2343 return weight;
2344}
2345
2346////////////////////////////////////////////////////////////////////////////////
2347/// Analytical computation of the weight.
2348
2350{
2351 Double_t capacity = Capacity();
2352 Double_t weight = 0.0;
2353 Int_t i;
2354 Int_t nd = GetNdaughters();
2355 TGeoVolume *daughter;
2356 for (i=0; i<nd; i++) {
2357 daughter = GetNode(i)->GetVolume();
2358 weight += daughter->WeightA();
2359 capacity -= daughter->Capacity();
2360 }
2361 Double_t density = 0.0;
2362 if (!IsAssembly()) {
2363 if (fMedium) density = fMedium->GetMaterial()->GetDensity();
2364 if (density<0.01) density = 0.0; // do not weight gases
2365 }
2366 weight += 0.001*capacity * density; //[kg]
2367 return weight;
2368}
2369
2371
2372
2373////////////////////////////////////////////////////////////////////////////////
2374/// dummy constructor
2375
2377{
2378 fVolumes = 0;
2379 fDivision = 0;
2380 fNumed = 0;
2381 fNdiv = 0;
2382 fAxis = 0;
2383 fStart = 0;
2384 fStep = 0;
2385 fAttSet = kFALSE;
2387}
2388
2389////////////////////////////////////////////////////////////////////////////////
2390/// default constructor
2391
2393{
2394 fVolumes = new TObjArray();
2395 fDivision = 0;
2396 fNumed = 0;
2397 fNdiv = 0;
2398 fAxis = 0;
2399 fStart = 0;
2400 fStep = 0;
2401 fAttSet = kFALSE;
2403 SetName(name);
2404 SetMedium(med);
2405 fGeoManager->AddVolume(this);
2406// printf("--- volume multi %s created\n", name);
2407}
2408
2409////////////////////////////////////////////////////////////////////////////////
2410/// Destructor
2411
2413{
2414 if (fVolumes) delete fVolumes;
2415}
2416
2417////////////////////////////////////////////////////////////////////////////////
2418/// Add a volume with valid shape to the list of volumes. Copy all existing nodes
2419/// to this volume
2420
2422{
2423 Int_t idx = fVolumes->GetEntriesFast();
2424 fVolumes->AddAtAndExpand(vol,idx);
2425 vol->SetUniqueID(idx+1);
2426 TGeoVolumeMulti *div;
2427 TGeoVolume *cell;
2428 if (fDivision) {
2430 if (!div) {
2431 Fatal("AddVolume", "Cannot divide volume %s", vol->GetName());
2432 return;
2433 }
2434 for (Int_t i=0; i<div->GetNvolumes(); i++) {
2435 cell = div->GetVolume(i);
2436 fDivision->AddVolume(cell);
2437 }
2438 }
2439 if (fNodes) {
2440 Int_t nd = fNodes->GetEntriesFast();
2441 for (Int_t id=0; id<nd; id++) {
2442 TGeoNode *node = (TGeoNode*)fNodes->At(id);
2443 Bool_t many = node->IsOverlapping();
2444 if (many) vol->AddNodeOverlap(node->GetVolume(), node->GetNumber(), node->GetMatrix());
2445 else vol->AddNode(node->GetVolume(), node->GetNumber(), node->GetMatrix());
2446 }
2447 }
2448// vol->MakeCopyNodes(this);
2449}
2450
2451
2452////////////////////////////////////////////////////////////////////////////////
2453/// Add a new node to the list of nodes. This is the usual method for adding
2454/// daughters inside the container volume.
2455
2457{
2458 TGeoNode *n = TGeoVolume::AddNode(vol, copy_no, mat, option);
2459 Int_t nvolumes = fVolumes->GetEntriesFast();
2460 TGeoVolume *volume = 0;
2461 for (Int_t ivo=0; ivo<nvolumes; ivo++) {
2462 volume = GetVolume(ivo);
2463 volume->SetLineColor(GetLineColor());
2464 volume->SetLineStyle(GetLineStyle());
2465 volume->SetLineWidth(GetLineWidth());
2466 volume->SetVisibility(IsVisible());
2467 volume->AddNode(vol, copy_no, mat, option);
2468 }
2469 // printf("--- vmulti %s : node %s added to %i components\n", GetName(), vol->GetName(), nvolumes);
2470 return n;
2471}
2472
2473////////////////////////////////////////////////////////////////////////////////
2474/// Add a new node to the list of nodes, This node is possibly overlapping with other
2475/// daughters of the volume or extruding the volume.
2476
2478{
2479 TGeoVolume::AddNodeOverlap(vol, copy_no, mat, option);
2480 Int_t nvolumes = fVolumes->GetEntriesFast();
2481 TGeoVolume *volume = 0;
2482 for (Int_t ivo=0; ivo<nvolumes; ivo++) {
2483 volume = GetVolume(ivo);
2484 volume->SetLineColor(GetLineColor());
2485 volume->SetLineStyle(GetLineStyle());
2486 volume->SetLineWidth(GetLineWidth());
2487 volume->SetVisibility(IsVisible());
2488 volume->AddNodeOverlap(vol, copy_no, mat, option);
2489 }
2490// printf("--- vmulti %s : node ovlp %s added to %i components\n", GetName(), vol->GetName(), nvolumes);
2491}
2492
2493////////////////////////////////////////////////////////////////////////////////
2494/// Returns the last shape.
2495
2497{
2499 if (!vol) return 0;
2500 return vol->GetShape();
2501}
2502
2503////////////////////////////////////////////////////////////////////////////////
2504/// division of multiple volumes
2505
2506TGeoVolume *TGeoVolumeMulti::Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed, const char *option)
2507{
2508 if (fDivision) {
2509 Error("Divide", "volume %s already divided", GetName());
2510 return 0;
2511 }
2512 Int_t nvolumes = fVolumes->GetEntriesFast();
2513 TGeoMedium *medium = fMedium;
2514 if (numed) {
2515 medium = fGeoManager->GetMedium(numed);
2516 if (!medium) {
2517 Error("Divide", "Invalid medium number %d for division volume %s", numed, divname);
2518 medium = fMedium;
2519 }
2520 }
2521 if (!nvolumes) {
2522 // this is a virtual volume
2523 fDivision = new TGeoVolumeMulti(divname, medium);
2524 fNumed = medium->GetId();
2525 fOption = option;
2526 fAxis = iaxis;
2527 fNdiv = ndiv;
2528 fStart = start;
2529 fStep = step;
2530 // nothing else to do at this stage
2531 return fDivision;
2532 }
2533 TGeoVolume *vol = 0;
2534 fDivision = new TGeoVolumeMulti(divname, medium);
2535 if (medium) fNumed = medium->GetId();
2536 fOption = option;
2537 fAxis = iaxis;
2538 fNdiv = ndiv;
2539 fStart = start;
2540 fStep = step;
2541 for (Int_t ivo=0; ivo<nvolumes; ivo++) {
2542 vol = GetVolume(ivo);
2543 vol->SetLineColor(GetLineColor());
2544 vol->SetLineStyle(GetLineStyle());
2545 vol->SetLineWidth(GetLineWidth());
2546 vol->SetVisibility(IsVisible());
2547 fDivision->AddVolume(vol->Divide(divname,iaxis,ndiv,start,step, numed, option));
2548 }
2549// printf("--- volume multi %s (%i volumes) divided\n", GetName(), nvolumes);
2550 if (numed) fDivision->SetMedium(medium);
2551 return fDivision;
2552}
2553
2554////////////////////////////////////////////////////////////////////////////////
2555/// Make a copy of this volume
2556/// build a volume with same name, shape and medium
2557
2559{
2560 TGeoVolume *vol = new TGeoVolume(GetName(), newshape, fMedium);
2561 Int_t i=0;
2562 // copy volume attributes
2563 vol->SetVisibility(IsVisible());
2564 vol->SetLineColor(GetLineColor());
2565 vol->SetLineStyle(GetLineStyle());
2566 vol->SetLineWidth(GetLineWidth());
2567 vol->SetFillColor(GetFillColor());
2568 vol->SetFillStyle(GetFillStyle());
2569 // copy field
2570 vol->SetField(fField);
2571 // Copy extensions
2574 // if divided, copy division object
2575// if (fFinder) {
2576// Error("MakeCopyVolume", "volume %s divided", GetName());
2577// vol->SetFinder(fFinder);
2578// }
2579 if (fDivision) {
2580 TGeoVolume *cell;
2582 if (!div) {
2583 Fatal("MakeCopyVolume", "Cannot divide volume %s", vol->GetName());
2584 return 0;
2585 }
2586 for (i=0; i<div->GetNvolumes(); i++) {
2587 cell = div->GetVolume(i);
2588 fDivision->AddVolume(cell);
2589 }
2590 }
2591
2592 if (!fNodes) return vol;
2593 TGeoNode *node;
2594 Int_t nd = fNodes->GetEntriesFast();
2595 if (!nd) return vol;
2596 // create new list of nodes
2597 TObjArray *list = new TObjArray();
2598 // attach it to new volume
2599 vol->SetNodes(list);
2600 ((TObject*)vol)->SetBit(kVolumeImportNodes);
2601 for (i=0; i<nd; i++) {
2602 //create copies of nodes and add them to list
2603 node = GetNode(i)->MakeCopyNode();
2604 if (!node) {
2605 Fatal("MakeCopyNode", "cannot make copy node for daughter %d of %s", i, GetName());
2606 return 0;
2607 }
2608 node->SetMotherVolume(vol);
2609 list->Add(node);
2610 }
2611 return vol;
2612}
2613
2614////////////////////////////////////////////////////////////////////////////////
2615/// Set the line color for all components.
2616
2618{
2620 Int_t nvolumes = fVolumes->GetEntriesFast();
2621 TGeoVolume *vol = 0;
2622 for (Int_t ivo=0; ivo<nvolumes; ivo++) {
2623 vol = GetVolume(ivo);
2624 vol->SetLineColor(lcolor);
2625 }
2626}
2627
2628////////////////////////////////////////////////////////////////////////////////
2629/// Set the line style for all components.
2630
2632{
2634 Int_t nvolumes = fVolumes->GetEntriesFast();
2635 TGeoVolume *vol = 0;
2636 for (Int_t ivo=0; ivo<nvolumes; ivo++) {
2637 vol = GetVolume(ivo);
2638 vol->SetLineStyle(lstyle);
2639 }
2640}
2641
2642////////////////////////////////////////////////////////////////////////////////
2643/// Set the line width for all components.
2644
2646{
2648 Int_t nvolumes = fVolumes->GetEntriesFast();
2649 TGeoVolume *vol = 0;
2650 for (Int_t ivo=0; ivo<nvolumes; ivo++) {
2651 vol = GetVolume(ivo);
2652 vol->SetLineWidth(lwidth);
2653 }
2654}
2655
2656////////////////////////////////////////////////////////////////////////////////
2657/// Set medium for a multiple volume.
2658
2660{
2662 Int_t nvolumes = fVolumes->GetEntriesFast();
2663 TGeoVolume *vol = 0;
2664 for (Int_t ivo=0; ivo<nvolumes; ivo++) {
2665 vol = GetVolume(ivo);
2666 vol->SetMedium(med);
2667 }
2668}
2669
2670
2671////////////////////////////////////////////////////////////////////////////////
2672/// Set visibility for all components.
2673
2675{
2677 Int_t nvolumes = fVolumes->GetEntriesFast();
2678 TGeoVolume *vol = 0;
2679 for (Int_t ivo=0; ivo<nvolumes; ivo++) {
2680 vol = GetVolume(ivo);
2681 vol->SetVisibility(vis);
2682 }
2683}
2684
2686
2687////////////////////////////////////////////////////////////////////////////////
2688/// Constructor.
2689
2691 fCurrent(-1), fNext(-1)
2692{
2693}
2694
2695////////////////////////////////////////////////////////////////////////////////
2696/// Destructor.
2697
2699{
2700}
2701
2702////////////////////////////////////////////////////////////////////////////////
2703
2705{
2707 return *fThreadData[tid];
2708}
2709
2710////////////////////////////////////////////////////////////////////////////////
2711
2713{
2714 std::lock_guard<std::mutex> guard(fMutex);
2716 std::vector<ThreadData_t*>::iterator i = fThreadData.begin();
2717 while (i != fThreadData.end())
2718 {
2719 delete *i;
2720 ++i;
2721 }
2722 fThreadData.clear();
2723 fThreadSize = 0;
2724}
2725
2726////////////////////////////////////////////////////////////////////////////////
2727
2729{
2730 std::lock_guard<std::mutex> guard(fMutex);
2731 // Create assembly thread data here
2732 fThreadData.resize(nthreads);
2733 fThreadSize = nthreads;
2734 for (Int_t tid=0; tid<nthreads; tid++) {
2735 if (fThreadData[tid] == 0) {
2736 fThreadData[tid] = new ThreadData_t;
2737 }
2738 }
2740}
2741
2742////////////////////////////////////////////////////////////////////////////////
2743
2745{
2746 return fThreadData[TGeoManager::ThreadId()]->fCurrent;
2747}
2748
2749////////////////////////////////////////////////////////////////////////////////
2750
2752{
2753 return fThreadData[TGeoManager::ThreadId()]->fNext;
2754}
2755
2756////////////////////////////////////////////////////////////////////////////////
2757
2759{
2761}
2762
2763////////////////////////////////////////////////////////////////////////////////
2764
2766{
2768}
2769
2770////////////////////////////////////////////////////////////////////////////////
2771/// Default constructor
2772
2774 :TGeoVolume()
2775{
2776 fThreadSize = 0;
2778}
2779
2780////////////////////////////////////////////////////////////////////////////////
2781/// Constructor. Just the name has to be provided. Assemblies does not have their own
2782/// shape or medium.
2783
2785 :TGeoVolume()
2786{
2787 fName = name;
2788 fName = fName.Strip();
2789 fShape = new TGeoShapeAssembly(this);
2791 fThreadSize = 0;
2793}
2794
2795////////////////////////////////////////////////////////////////////////////////
2796/// Destructor. The assembly is owner of its "shape".
2797
2799{
2801 if (fShape) delete fShape;
2802}
2803
2804////////////////////////////////////////////////////////////////////////////////
2805/// Add a component to the assembly.
2806
2808{
2809 TGeoNode *node = TGeoVolume::AddNode(vol, copy_no, mat, option);
2810 // ((TGeoShapeAssembly*)fShape)->RecomputeBoxLast();
2811 ((TGeoShapeAssembly*)fShape)->NeedsBBoxRecompute();
2812 return node;
2813}
2814
2815////////////////////////////////////////////////////////////////////////////////
2816/// Add an overlapping node - not allowed for assemblies.
2817
2819{
2820 Warning("AddNodeOverlap", "Declaring assembly %s as possibly overlapping inside %s not allowed. Using AddNode instead !",vol->GetName(),GetName());
2821 AddNode(vol, copy_no, mat, option);
2822}
2823
2824////////////////////////////////////////////////////////////////////////////////
2825/// Clone this volume.
2826/// build a volume with same name, shape and medium
2827
2829{
2831 Int_t i;
2832 // copy other attributes
2833 Int_t nbits = 8*sizeof(UInt_t);
2834 for (i=0; i<nbits; i++)
2835 vol->SetAttBit(1<<i, TGeoAtt::TestAttBit(1<<i));
2836 for (i=14; i<24; i++)
2837 vol->SetBit(1<<i, TestBit(1<<i));
2838
2839 // copy field
2840 vol->SetField(fField);
2841 // Set bits
2842 for (i=0; i<nbits; i++)
2843 vol->SetBit(1<<i, TObject::TestBit(1<<i));
2844 vol->SetBit(kVolumeClone);
2845 // make copy nodes
2846 vol->MakeCopyNodes(this);
2847// CloneNodesAndConnect(vol);
2848 ((TGeoShapeAssembly*)vol->GetShape())->NeedsBBoxRecompute();
2849 // copy voxels
2850 TGeoVoxelFinder *voxels = 0;
2851 if (fVoxels) {
2852 voxels = new TGeoVoxelFinder(vol);
2853 vol->SetVoxelFinder(voxels);
2854 }
2855 // copy option, uid
2856 vol->SetOption(fOption);
2857 vol->SetNumber(fNumber);
2858 vol->SetNtotal(fNtotal);
2859 vol->SetTitle(GetTitle());
2860 return vol;
2861}
2862
2863////////////////////////////////////////////////////////////////////////////////
2864/// Division makes no sense for assemblies.
2865
2867{
2868 Error("Divide","Assemblies cannot be divided");
2869 return 0;
2870}
2871
2872////////////////////////////////////////////////////////////////////////////////
2873/// Assign to the assembly a collection of identical volumes positioned according
2874/// a predefined pattern. The option can be spaced out or touching depending on the empty
2875/// space between volumes.
2876
2878{
2879 if (fNodes) {
2880 Error("Divide", "Cannot divide assembly %s since it has nodes", GetName());
2881 return NULL;
2882 }
2883 if (fFinder) {
2884 Error("Divide", "Assembly %s already divided", GetName());
2885 return NULL;
2886 }
2887 Int_t ncells = pattern->GetNdiv();
2888 if (!ncells || pattern->GetStep()<=0) {
2889 Error("Divide", "Pattern finder for dividing assembly %s not initialized. Use SetRange() method.", GetName());
2890 return NULL;
2891 }
2892 fFinder = pattern;
2893 TString opt(option);
2894 opt.ToLower();
2895 if (opt.Contains("spacedout")) fFinder->SetSpacedOut(kTRUE);
2897 // Position volumes
2898 for (Int_t i=0; i<ncells; i++) {
2899 fFinder->cd(i);
2900 TGeoNodeOffset *node = new TGeoNodeOffset(cell, i, 0.);
2901 node->SetFinder(fFinder);
2902 fNodes->Add(node);
2903 }
2904 return cell;
2905}
2906
2907////////////////////////////////////////////////////////////////////////////////
2908/// Make a clone of volume VOL but which is an assembly.
2909
2911{
2912 if (volorig->IsAssembly() || volorig->IsVolumeMulti()) return 0;
2913 Int_t nd = volorig->GetNdaughters();
2914 if (!nd) return 0;
2915 TGeoVolumeAssembly *vol = new TGeoVolumeAssembly(volorig->GetName());
2916 Int_t i;
2917 // copy other attributes
2918 Int_t nbits = 8*sizeof(UInt_t);
2919 for (i=0; i<nbits; i++)
2920 vol->SetAttBit(1<<i, volorig->TestAttBit(1<<i));
2921 for (i=14; i<24; i++)
2922 vol->SetBit(1<<i, volorig->TestBit(1<<i));
2923
2924 // copy field
2925 vol->SetField(volorig->GetField());
2926 // Set bits
2927 for (i=0; i<nbits; i++)
2928 vol->SetBit(1<<i, volorig->TestBit(1<<i));
2929 vol->SetBit(kVolumeClone);
2930 // make copy nodes
2931 vol->MakeCopyNodes(volorig);
2932// volorig->CloneNodesAndConnect(vol);
2933 vol->GetShape()->ComputeBBox();
2934 // copy voxels
2935 TGeoVoxelFinder *voxels = 0;
2936 if (volorig->GetVoxels()) {
2937 voxels = new TGeoVoxelFinder(vol);
2938 vol->SetVoxelFinder(voxels);
2939 }
2940 // copy option, uid
2941 vol->SetOption(volorig->GetOption());
2942 vol->SetNumber(volorig->GetNumber());
2943 vol->SetNtotal(volorig->GetNtotal());
2944 return vol;
2945}
#define f(i)
Definition: RSha256.hxx:104
#define s1(x)
Definition: RSha256.hxx:91
short Style_t
Definition: RtypesCore.h:89
int Int_t
Definition: RtypesCore.h:45
short Color_t
Definition: RtypesCore.h:92
const Bool_t kFALSE
Definition: RtypesCore.h:101
unsigned int UInt_t
Definition: RtypesCore.h:46
short Width_t
Definition: RtypesCore.h:91
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:375
R__EXTERN TEnv * gEnv
Definition: TEnv.h:170
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
char name[80]
Definition: TGX11.cxx:110
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:602
R__EXTERN TGeoIdentity * gGeoIdentity
Definition: TGeoMatrix.h:478
#define gROOT
Definition: TROOT.h:404
R__EXTERN TStyle * gStyle
Definition: TStyle.h:414
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:31
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
Width_t fLineWidth
Line width.
Definition: TAttLine.h:23
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:34
Style_t fLineStyle
Line style.
Definition: TAttLine.h:22
Color_t fLineColor
Line color.
Definition: TAttLine.h:21
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
void CheckObjectItem(TObject *obj, Bool_t check=kFALSE)
Change status of checkbox for this item.
Definition: TBrowser.cxx:329
void Refresh()
Refresh browser contents.
Definition: TBrowser.cxx:402
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
Bool_t IsReading() const
Definition: TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
TDirectory::TContext keeps track and restore the current directory.
Definition: TDirectory.h:89
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:4019
Bool_t IsVisRaytrace() const
Definition: TGeoAtt.h:87
virtual void SetVisOnly(Bool_t flag=kTRUE)
Set branch type visibility.
Definition: TGeoAtt.cxx:95
Bool_t TestAttBit(UInt_t f) const
Definition: TGeoAtt.h:68
virtual void SetVisLeaves(Bool_t flag=kTRUE)
Set branch type visibility.
Definition: TGeoAtt.cxx:85
@ kSaveNodesAtt
Definition: TGeoAtt.h:53
@ kSavePrimitiveAtt
Definition: TGeoAtt.h:52
void SetVisDaughters(Bool_t vis=kTRUE)
Set visibility for the daughters.
Definition: TGeoAtt.cxx:114
void ResetAttBit(UInt_t f)
Definition: TGeoAtt.h:67
void SetVisRaytrace(Bool_t flag=kTRUE)
Definition: TGeoAtt.h:70
Bool_t IsVisDaughters() const
Definition: TGeoAtt.h:89
virtual void SetVisibility(Bool_t vis=kTRUE)
Set visibility for this object.
Definition: TGeoAtt.cxx:105
void SetAttBit(UInt_t f)
Definition: TGeoAtt.h:65
void SetVisTouched(Bool_t vis=kTRUE)
Mark visualization attributes as "modified".
Definition: TGeoAtt.cxx:131
virtual void SetVisContainers(Bool_t flag=kTRUE)
Set branch type visibility.
Definition: TGeoAtt.cxx:77
Class describing rotation + translation.
Definition: TGeoMatrix.h:292
Composite shapes are Boolean combinations of two or more shape components.
void RegisterYourself()
Register the shape and all components to TGeoManager class.
ABC for user objects attached to TGeoVolume or TGeoNode.
Definition: TGeoExtension.h:20
virtual TGeoExtension * Grab()=0
virtual void Release() const =0
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition: TGeoMatrix.h:421
void MultiplyLeft(const TGeoMatrix *left)
multiply to the left with an other transformation if right is identity matrix, just return
The manager class for any TGeo geometry.
Definition: TGeoManager.h:45
TObjArray * GetListOfOverlaps()
Definition: TGeoManager.h:489
TList * GetListOfMedia() const
Definition: TGeoManager.h:492
void SetUserPaintVolume(TGeoVolume *vol)
Definition: TGeoManager.h:238
TObjArray * GetListOfVolumes() const
Definition: TGeoManager.h:493
void ClearOverlaps()
Clear the list of overlaps.
TObjArray * GetListOfMatrices() const
Definition: TGeoManager.h:490
Bool_t IsClosed() const
Definition: TGeoManager.h:305
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.
TVirtualGeoPainter * GetGeomPainter()
Make a default painter if none present. Returns pointer to it.
void SetVisOption(Int_t option=0)
set drawing mode :
Int_t AddMaterial(const TGeoMaterial *material)
Add a material to the list. Returns index of the material in list.
TGeoHMatrix * GetHMatrix()
Return stored current matrix (global matrix of the next touched node).
Int_t AddVolume(TGeoVolume *volume)
Add a volume to the list. Returns index of the volume in list.
Bool_t IsStreamingVoxels() const
Definition: TGeoManager.h:483
void SetCurrentPoint(Double_t *point)
Definition: TGeoManager.h:535
Int_t GetVisOption() const
Returns current depth to which geometry is drawn.
static UInt_t GetExportPrecision()
Definition: TGeoManager.h:479
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
void ClearShape(const TGeoShape *shape)
Remove a shape from the list of shapes.
TGeoMedium * GetMedium(const char *medium) const
Search for a named tracking medium. All trailing blanks stripped.
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.
void SetNsegments(Int_t nseg)
Set number of segments for approximating circles in drawing.
TVirtualGeoPainter * GetPainter() const
Definition: TGeoManager.h:213
Bool_t IsCheckingOverlaps() const
Definition: TGeoManager.h:411
void RandomPoints(const TGeoVolume *vol, Int_t npoints=10000, Option_t *option="")
Draw random points in the bounding box of a volume.
TList * GetListOfMaterials() const
Definition: TGeoManager.h:491
void SetAllIndex()
Assigns uid's for all materials,media and matrices.
TObjArray * GetListOfShapes() const
Definition: TGeoManager.h:495
TGeoVolume * GetTopVolume() const
Definition: TGeoManager.h:532
static Int_t ThreadId()
Translates the current thread id to an ordinal number.
Int_t AddShape(const TGeoShape *shape)
Add a shape to the list. Returns index of the shape in list.
void SortOverlaps()
Sort overlaps by decreasing overlap distance. Extrusions comes first.
Base class describing materials.
Definition: TGeoMaterial.h:36
virtual void Print(const Option_t *option="") const
print characteristics of this material
void SetUsed(Bool_t flag=kTRUE)
Definition: TGeoMaterial.h:139
virtual Double_t GetDensity() const
Definition: TGeoMaterial.h:108
Geometrical transformation package.
Definition: TGeoMatrix.h:41
virtual void ReflectZ(Bool_t leftside, Bool_t rotonly=kFALSE)
Multiply by a reflection respect to XY.
Definition: TGeoMatrix.cxx:519
Bool_t IsReflection() const
Definition: TGeoMatrix.h:69
virtual void RegisterYourself()
Register the matrix in the current manager, which will become the owner.
Definition: TGeoMatrix.cxx:526
void Print(Option_t *option="") const
print the matrix in 4x4 format
Definition: TGeoMatrix.cxx:486
Bool_t IsIdentity() const
Definition: TGeoMatrix.h:66
Bool_t IsRegistered() const
Definition: TGeoMatrix.h:77
char * GetPointerName() const
Provide a pointer name containing uid.
Definition: TGeoMatrix.cxx:294
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition: TGeoMedium.h:24
Int_t GetId() const
Definition: TGeoMedium.h:48
TGeoMaterial * GetMaterial() const
Definition: TGeoMedium.h:52
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGeoMedium.cxx:137
void SetMaterial(TGeoMaterial *mat)
Definition: TGeoMedium.h:55
char * GetPointerName() const
Provide a pointer name containing uid.
Definition: TGeoMedium.cxx:127
A node containing local transformation.
Definition: TGeoNode.h:153
void SetMatrix(const TGeoMatrix *matrix)
Matrix setter.
Definition: TGeoNode.cxx:767
virtual TGeoMatrix * GetMatrix() const
Definition: TGeoNode.h:170
Node containing an offset.
Definition: TGeoNode.h:184
void SetFinder(TGeoPatternFinder *finder)
Definition: TGeoNode.h:206
static TClass * Class()
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition: TGeoNode.h:41
Bool_t IsOverlapping() const
Definition: TGeoNode.h:105
TGeoVolume * GetVolume() const
Definition: TGeoNode.h:97
void SetVolume(TGeoVolume *volume)
Definition: TGeoNode.h:115
Bool_t IsOffset() const
Definition: TGeoNode.h:103
virtual Int_t GetByteCount() const
Definition: TGeoNode.h:84
void SetOverlapping(Bool_t flag=kTRUE)
Definition: TGeoNode.h:118
virtual Int_t GetOptimalVoxels() const
Definition: TGeoNode.h:99
virtual TGeoMatrix * GetMatrix() const =0
void SetMotherVolume(TGeoVolume *mother)
Definition: TGeoNode.h:123
virtual TGeoNode * MakeCopyNode() const
Definition: TGeoNode.h:111
void SetVirtual()
Definition: TGeoNode.h:119
Int_t GetNumber() const
Definition: TGeoNode.h:95
void SetNumber(Int_t number)
Definition: TGeoNode.h:116
Base finder class for patterns.
virtual void cd(Int_t)
void SetSpacedOut(Bool_t flag)
void SetDivIndex(Int_t index)
virtual TGeoPatternFinder * MakeCopy(Bool_t reflect=kFALSE)=0
virtual Int_t GetDivAxis()
Int_t GetNdiv() const
void SetVolume(TGeoVolume *vol)
Double_t GetStep() const
void ClearThreadData() const
Double_t GetStart() const
virtual Int_t GetByteCount() const
void CreateThreadData(Int_t nthreads)
Create thread data for n threads max.
Class describing scale transformations.
Definition: TGeoMatrix.h:245
static TGeoShape * MakeScaledShape(const char *name, TGeoShape *shape, TGeoScale *scale)
Create a scaled shape starting from a non-scaled one.
The shape encapsulating an assembly (union) of volumes.
Base abstract class for all shapes.
Definition: TGeoShape.h:26
virtual Double_t GetAxisRange(Int_t iaxis, Double_t &xlo, Double_t &xhi) const =0
virtual void CreateThreadData(Int_t)
Definition: TGeoShape.h:68
Bool_t IsValid() const
Definition: TGeoShape.h:140
virtual const char * GetAxisName(Int_t iaxis) const =0
virtual TGeoVolume * Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step)=0
virtual Bool_t IsComposite() const
Definition: TGeoShape.h:130
static Bool_t IsSameWithinTolerance(Double_t a, Double_t b)
Check if two numbers differ with less than a tolerance.
Definition: TGeoShape.cxx:326
Bool_t IsRunTimeShape() const
Definition: TGeoShape.h:139
virtual void ClearThreadData() const
Definition: TGeoShape.h:67
const char * GetPointerName() const
Provide a pointer name containing uid.
Definition: TGeoShape.cxx:699
void CheckShape(Int_t testNo, Int_t nsamples=10000, Option_t *option="")
Test for shape navigation methods.
Definition: TGeoShape.cxx:209
virtual Bool_t IsValidBox() const =0
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:248
virtual Int_t GetByteCount() const =0
virtual void ComputeBBox()=0
virtual Double_t Capacity() const =0
@ kGeoSavePrimitive
Definition: TGeoShape.h:65
virtual TGeoShape * GetMakeRuntimeShape(TGeoShape *mother, TGeoMatrix *mat) const =0
virtual Bool_t IsAssembly() const
Definition: TGeoShape.h:129
Bool_t TestShapeBit(UInt_t f) const
Definition: TGeoShape.h:163
Volume assemblies.
Definition: TGeoVolume.h:305
static TGeoVolumeAssembly * MakeAssemblyFromVolume(TGeoVolume *vol)
Make a clone of volume VOL but which is an assembly.
virtual Int_t GetCurrentNodeIndex() const
virtual TGeoVolume * Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed=0, Option_t *option="")
Division makes no sense for assemblies.
virtual void ClearThreadData() const
virtual Int_t GetNextNodeIndex() const
virtual void AddNodeOverlap(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat, Option_t *option)
Add an overlapping node - not allowed for assemblies.
std::vector< ThreadData_t * > fThreadData
Definition: TGeoVolume.h:321
virtual ~TGeoVolumeAssembly()
Destructor. The assembly is owner of its "shape".
std::mutex fMutex
Thread vector size.
Definition: TGeoVolume.h:323
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a component to the assembly.
Int_t fThreadSize
Thread specific data vector.
Definition: TGeoVolume.h:322
void SetNextNodeIndex(Int_t index)
virtual TGeoVolume * CloneVolume() const
Clone this volume.
void SetCurrentNodeIndex(Int_t index)
TGeoVolumeAssembly()
Default constructor.
virtual void CreateThreadData(Int_t nthreads)
ThreadData_t & GetThreadData() const
Volume families.
Definition: TGeoVolume.h:255
virtual void SetVisibility(Bool_t vis=kTRUE)
Set visibility for all components.
virtual TGeoVolume * MakeCopyVolume(TGeoShape *newshape)
Make a copy of this volume build a volume with same name, shape and medium.
Double_t fStart
Definition: TGeoVolume.h:262
void AddVolume(TGeoVolume *vol)
Add a volume with valid shape to the list of volumes.
virtual void SetLineStyle(Style_t lstyle)
Set the line style for all components.
virtual void AddNodeOverlap(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat, Option_t *option="")
Add a new node to the list of nodes, This node is possibly overlapping with other daughters of the vo...
TGeoVolume * GetVolume(Int_t id) const
Definition: TGeoVolume.h:275
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat, Option_t *option="")
Add a new node to the list of nodes.
virtual ~TGeoVolumeMulti()
Destructor.
virtual TGeoVolume * Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed=0, Option_t *option="")
division of multiple volumes
Double_t fStep
Definition: TGeoVolume.h:263
virtual void SetLineColor(Color_t lcolor)
Set the line color for all components.
TGeoVolumeMulti * fDivision
Definition: TGeoVolume.h:258
TGeoVolumeMulti()
dummy constructor
TGeoShape * GetLastShape() const
Returns the last shape.
Int_t GetNvolumes() const
Definition: TGeoVolume.h:281
virtual void SetMedium(TGeoMedium *medium)
Set medium for a multiple volume.
TObjArray * fVolumes
Definition: TGeoVolume.h:257
virtual void SetLineWidth(Width_t lwidth)
Set the line width for all components.
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:49
Double_t WeightA() const
Analytical computation of the weight.
void AddNodeOffset(TGeoVolume *vol, Int_t copy_no, Double_t offset=0, Option_t *option="")
Add a division node to the list of nodes.
Definition: TGeoVolume.cxx:972
virtual void cd(Int_t inode) const
Actualize matrix of node indexed <inode>
Definition: TGeoVolume.cxx:923
virtual void ClearThreadData() const
Definition: TGeoVolume.cxx:424
virtual ~TGeoVolume()
Destructor.
Definition: TGeoVolume.cxx:502
virtual void Print(Option_t *option="") const
Print volume info.
Bool_t IsVisContainers() const
Definition: TGeoVolume.h:156
void SetVoxelFinder(TGeoVoxelFinder *finder)
Definition: TGeoVolume.h:231
void RemoveNode(TGeoNode *node)
Remove an existing daughter.
Int_t GetNodeIndex(const TGeoNode *node, Int_t *check_list, Int_t ncheck) const
Get the index of a daughter within check_list by providing the node pointer.
void RandomRays(Int_t nrays=10000, Double_t startx=0, Double_t starty=0, Double_t startz=0, const char *target_vol=0, Bool_t check_norm=kFALSE)
Random raytracing method.
Bool_t Valid() const
Check if the shape of this volume is valid.
Bool_t IsAllInvisible() const
Return TRUE if volume and all daughters are invisible.
Definition: TGeoVolume.cxx:753
Int_t fNtotal
Definition: TGeoVolume.h:62
void MakeCopyNodes(const TGeoVolume *other)
make a new list of nodes and copy all nodes of other volume inside
TGeoNode * ReplaceNode(TGeoNode *nodeorig, TGeoShape *newshape=0, TGeoMatrix *newpos=0, TGeoMedium *newmed=0)
Replace an existing daughter with a new volume having the same name but possibly a new shape,...
void SetUserExtension(TGeoExtension *ext)
Connect user-defined extension to the volume.
TGeoExtension * GrabFWExtension() const
Get a copy of the framework extension pointer.
void SetNumber(Int_t number)
Definition: TGeoVolume.h:233
void ClearNodes()
Definition: TGeoVolume.h:100
void Raytrace(Bool_t flag=kTRUE)
Draw this volume with current settings and perform raytracing in the pad.
TGeoVolume()
dummy constructor
Definition: TGeoVolume.cxx:448
TGeoMedium * GetMedium() const
Definition: TGeoVolume.h:174
virtual Bool_t IsFolder() const
Return TRUE if volume contains nodes.
Definition: TGeoVolume.cxx:792
void CloneNodesAndConnect(TGeoVolume *newmother) const
Clone the array of nodes.
void SortNodes()
sort nodes by decreasing volume of the bounding box.
Bool_t FindMatrixOfDaughterVolume(TGeoVolume *vol) const
Find a daughter node having VOL as volume and fill TGeoManager::fHMatrix with its global matrix.
void Voxelize(Option_t *option)
build the voxels for this volume
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
compute the closest distance of approach from point px,py to this volume
Double_t Capacity() const
Computes the capacity of this [cm^3] as the capacity of its shape.
Definition: TGeoVolume.cxx:553
virtual TGeoVolume * MakeCopyVolume(TGeoShape *newshape)
make a copy of this volume build a volume with same name, shape and medium
void ReplayCreation(const TGeoVolume *other)
Recreate the content of the other volume without pointer copying.
Double_t Weight(Double_t precision=0.01, Option_t *option="va")
Estimate the weight of a volume (in kg) with SIGMA(M)/M better than PRECISION.
Int_t fNumber
option - if any
Definition: TGeoVolume.h:61
virtual void CreateThreadData(Int_t nthreads)
Definition: TGeoVolume.cxx:432
virtual Int_t GetByteCount() const
get the total size in bytes for this volume
Bool_t OptimizeVoxels()
Perform an extensive sampling to find which type of voxelization is most efficient.
void SetCurrentPoint(Double_t x, Double_t y, Double_t z)
Set the current tracking point.
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute mouse actions on this volume.
virtual void SetVisLeaves(Bool_t flag=kTRUE)
Set visibility for leaves.
void Browse(TBrowser *b)
How to browse a volume.
Definition: TGeoVolume.cxx:519
TGeoManager * fGeoManager
Definition: TGeoVolume.h:57
TH2F * LegoPlot(Int_t ntheta=20, Double_t themin=0., Double_t themax=180., Int_t nphi=60, Double_t phimin=0., Double_t phimax=360., Double_t rmin=0., Double_t rmax=9999999, Option_t *option="")
Generate a lego plot fot the top volume, according to option.
TGeoVoxelFinder * fVoxels
Definition: TGeoVolume.h:56
TGeoMaterial * GetMaterial() const
Definition: TGeoVolume.h:173
virtual Bool_t IsVolumeMulti() const
Definition: TGeoVolume.h:115
TGeoExtension * GrabUserExtension() const
Get a copy of the user extension pointer.
@ kVolumeClone
Definition: TGeoVolume.h:85
@ kVolumeSelected
Definition: TGeoVolume.h:78
@ kVolumeMulti
Definition: TGeoVolume.h:82
@ kVolumeImportNodes
Definition: TGeoVolume.h:81
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:702
void GrabFocus()
Move perspective view focus to this volume.
void UnmarkSaved()
Reset SavePrimitive bits.
virtual TGeoVolume * CloneVolume() const
Clone this volume.
void SetFinder(TGeoPatternFinder *finder)
Definition: TGeoVolume.h:232
Int_t GetNdaughters() const
Definition: TGeoVolume.h:351
Bool_t IsValid() const
Definition: TGeoVolume.h:153
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
void Grab()
Definition: TGeoVolume.h:140
char * GetPointerName() const
Provide a pointer name containing uid.
void CheckGeometry(Int_t nrays=1, Double_t startx=0, Double_t starty=0, Double_t startz=0) const
Shoot nrays with random directions from starting point (startx, starty, startz) in the reference fram...
Definition: TGeoVolume.cxx:568
void SelectVolume(Bool_t clear=kFALSE)
Select this volume as matching an arbitrary criteria.
static TClass * Class()
TObjArray * GetNodes()
Definition: TGeoVolume.h:168
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Get volume info for the browser.
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:932
Option_t * GetOption() const
Definition: TGeoVolume.h:186
void ClearShape()
Clear the shape of this volume from the list held by the current manager.
Definition: TGeoVolume.cxx:640
void SetFWExtension(TGeoExtension *ext)
Connect framework defined extension to the volume.
void VisibleDaughters(Bool_t vis=kTRUE)
set visibility for daughters
void FindOverlaps() const
loop all nodes marked as overlaps and find overlapping brothers
TGeoNode * GetNode(const char *name) const
get the pointer to a daughter node
virtual void SetVisibility(Bool_t vis=kTRUE)
set visibility of this volume
void RandomPoints(Int_t npoints=1000000, Option_t *option="")
Draw random points in the bounding box of this volume.
void CheckShapes()
check for negative parameters in shapes.
Definition: TGeoVolume.cxx:648
void SetNtotal(Int_t ntotal)
Definition: TGeoVolume.h:234
virtual void Paint(Option_t *option="")
paint volume
Bool_t GetOptimalVoxels() const
Returns true if cylindrical voxelization is optimal.
void InvisibleAll(Bool_t flag=kTRUE)
Make volume and each of it daughters (in)visible.
Definition: TGeoVolume.cxx:764
Bool_t IsVisibleDaughters() const
Definition: TGeoVolume.h:155
TString fOption
just a hook for now
Definition: TGeoVolume.h:60
void SaveAs(const char *filename, Option_t *option="") const
Save geometry having this as top volume as a C++ macro.
Int_t GetIndex(const TGeoNode *node) const
get index number for a given daughter
void SetNodes(TObjArray *nodes)
Definition: TGeoVolume.h:215
TGeoPatternFinder * GetFinder() const
Definition: TGeoVolume.h:176
void PrintVoxels() const
Print the voxels for this volume.
TGeoExtension * fUserExtension
Definition: TGeoVolume.h:64
virtual void SetMedium(TGeoMedium *medium)
Definition: TGeoVolume.h:230
TGeoVoxelFinder * GetVoxels() const
Getter for optimization structure.
void SetAttVisibility(Bool_t vis)
Definition: TGeoVolume.h:221
void SetShape(const TGeoShape *shape)
set the shape associated with this volume
static TGeoMedium * DummyMedium()
Definition: TGeoVolume.cxx:440
TObject * fField
pointer to TGeoManager owning this volume
Definition: TGeoVolume.h:59
Int_t GetNumber() const
Definition: TGeoVolume.h:183
void CleanAll()
Clean data of the volume.
Definition: TGeoVolume.cxx:631
Bool_t IsTopVolume() const
True if this is the top volume of the geometry.
Definition: TGeoVolume.cxx:812
TGeoMedium * fMedium
Definition: TGeoVolume.h:53
TGeoShape * GetShape() const
Definition: TGeoVolume.h:189
void InspectMaterial() const
Inspect the material for this volume.
Definition: TGeoVolume.cxx:829
void PrintNodes() const
print nodes
virtual void Streamer(TBuffer &)
Stream an object of class TGeoVolume.
static TGeoMedium * fgDummyMedium
Definition: TGeoVolume.h:54
void RegisterYourself(Option_t *option="")
Register the volume and all materials/media/matrices/shapes to the manager.
virtual void AddNodeOverlap(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:997
virtual void Draw(Option_t *option="")
draw top volume according to option
virtual void SetVisOnly(Bool_t flag=kTRUE)
Set visibility for leaves.
virtual TGeoVolume * Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed=0, Option_t *option="")
Division a la G3.
Bool_t IsRaytracing() const
Check if the painter is currently ray-tracing the content of this volume.
Definition: TGeoVolume.cxx:821
TGeoShape * fShape
Definition: TGeoVolume.h:52
void SetField(TObject *field)
Definition: TGeoVolume.h:219
static TGeoVolume * Import(const char *filename, const char *name="", Option_t *option="")
Import a volume from a file.
Definition: TGeoVolume.cxx:837
Bool_t IsStyleDefault() const
check if the visibility and attributes are the default ones
Definition: TGeoVolume.cxx:800
static void CreateDummyMedium()
Create a dummy medium.
Definition: TGeoVolume.cxx:412
TGeoExtension * fFWExtension
Transient user-defined extension to volumes.
Definition: TGeoVolume.h:65
void SetAsTopVolume()
Set this volume as the TOP one (the whole geometry starts from here)
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Bool_t IsVisLeaves() const
Definition: TGeoVolume.h:157
virtual void SetVisContainers(Bool_t flag=kTRUE)
Set visibility for containers.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
TObject * GetField() const
Definition: TGeoVolume.h:175
TGeoPatternFinder * fFinder
dummy medium
Definition: TGeoVolume.h:55
Int_t Export(const char *filename, const char *name="", Option_t *option="")
Export this volume to a file.
Definition: TGeoVolume.cxx:887
virtual void DrawOnly(Option_t *option="")
draw only this volume
virtual void SetLineColor(Color_t lcolor)
Set the line color.
void SetOption(const char *option)
Set the current options (none implemented)
virtual Bool_t IsAssembly() const
Returns true if the volume is an assembly or a scaled assembly.
TGeoVolume * MakeReflectedVolume(const char *newname="") const
Make a copy of this volume which is reflected with respect to XY plane.
TObjArray * fNodes
Definition: TGeoVolume.h:51
virtual Bool_t IsVisible() const
Definition: TGeoVolume.h:154
Int_t GetNtotal() const
Definition: TGeoVolume.h:170
void InspectShape() const
Definition: TGeoVolume.h:194
TGeoNode * FindNode(const char *name) const
search a daughter inside the list of nodes
void CheckOverlaps(Double_t ovlp=0.1, Option_t *option="") const
Overlap checking tool.
Definition: TGeoVolume.cxx:589
void SetOverlappingCandidate(Bool_t flag)
Definition: TGeoVolume.h:216
Bool_t IsOverlappingCandidate() const
Definition: TGeoVolume.h:147
Int_t fRefCount
Definition: TGeoVolume.h:63
void CheckShape(Int_t testNo, Int_t nsamples=10000, Option_t *option="")
Tests for checking the shape navigation algorithms. See TGeoShape::CheckShape()
Definition: TGeoVolume.cxx:623
Finder class handling voxels.
Bool_t IsInvalid() const
void SetNeedRebuild(Bool_t flag=kTRUE)
virtual void Voxelize(Option_t *option="")
Voxelize attached volume according to option If the volume is an assembly, make sure the bbox is comp...
virtual void FindOverlaps(Int_t inode) const
create the list of nodes for which the bboxes overlap with inode's bbox
virtual void Print(Option_t *option="") const
Print the voxels.
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3070
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:257
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:28
virtual const char * GetClassName() const
Definition: TKey.h:75
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:750
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition: TList.cxx:578
void Add(TObject *obj) override
Definition: TList.h:81
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:40
void Add(TObject *obj) override
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
Definition: TMap.cxx:54
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition: TMap.cxx:236
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
TString fTitle
Definition: TNamed.h:33
TString fName
Definition: TNamed.h:32
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
An array of TObjects.
Definition: TObjArray.h:31
Int_t GetEntriesFast() const
Definition: TObjArray.h:58
void AddAt(TObject *obj, Int_t idx) override
Add object at position ids.
Definition: TObjArray.cxx:254
void Clear(Option_t *option="") override
Remove all objects from the array.
Definition: TObjArray.cxx:321
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:235
virtual void Compress()
Remove empty slots from array.
Definition: TObjArray.cxx:334
Int_t GetEntries() const override
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:523
void Delete(Option_t *option="") override
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:356
TObject * At(Int_t idx) const override
Definition: TObjArray.h:164
TObject * Remove(TObject *obj) override
Remove object from array.
Definition: TObjArray.cxx:719
TObject * RemoveAt(Int_t idx) override
Remove object at index idx.
Definition: TObjArray.cxx:694
TObject * FindObject(const char *name) const override
Find an object in this collection using its name.
Definition: TObjArray.cxx:415
void Add(TObject *obj) override
Definition: TObjArray.h:68
Mother of all ROOT objects.
Definition: TObject.h:37
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:798
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:879
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:666
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:921
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:707
void ResetBit(UInt_t f)
Definition: TObject.h:186
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:867
Sequenceable collection abstract base class.
Basic string class.
Definition: TString.h:136
Ssiz_t Length() const
Definition: TString.h:410
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1150
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1131
const char * Data() const
Definition: TString.h:369
Ssiz_t Capacity() const
Definition: TString.h:357
Bool_t IsNull() const
Definition: TString.h:407
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
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:2336
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:639
Abstract class for geometry painters.
virtual void SetTopVolume(TGeoVolume *vol)=0
virtual void ModifiedPad(Bool_t update=kFALSE) const =0
virtual TGeoVolume * GetTopVolume() const =0
virtual void DrawVolume(TGeoVolume *vol, Option_t *option="")=0
virtual void GrabFocus(Int_t nfr=0, Double_t dlong=0, Double_t dlat=0, Double_t dpsi=0)=0
virtual void CheckOverlaps(const TGeoVolume *vol, Double_t ovlp=0.1, Option_t *option="") const =0
virtual void Paint(Option_t *option="")=0
This method must be overridden if a class wants to paint itself.
virtual Int_t DistanceToPrimitiveVol(TGeoVolume *vol, Int_t px, Int_t py)=0
virtual Bool_t TestVoxels(TGeoVolume *vol)=0
virtual TGeoVolume * GetDrawnVolume() const =0
virtual const char * GetVolumeInfo(const TGeoVolume *volume, Int_t px, Int_t py) const =0
virtual void ExecuteVolumeEvent(TGeoVolume *volume, Int_t event, Int_t px, Int_t py)=0
virtual void CheckGeometry(Int_t nrays, Double_t startx, Double_t starty, Double_t startz) const =0
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
static const std::string pattern("pattern")
constexpr Double_t E()
Base of natural log: .
Definition: TMath.h:93
ThreadData_t()
index of next node to be entered