Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoNode.h
Go to the documentation of this file.
1 // @(#)root/geom:$Id$
2 // Author: Andrei Gheata 24/10/01
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGeoNode
13 #define ROOT_TGeoNode
14 
15 #include "TGeoAtt.h"
16 
17 #include "TNamed.h"
18 
19 #include "TGeoVolume.h"
20 
21 #include "TGeoPatternFinder.h"
22 
23 // forward declarations
24 class TString;
25 class TGeoVolume;
26 class TGeoShape;
27 class TGeoMedium;
28 class TGeoMatrix;
29 class TGeoHMatrix;
30 class TGeoExtension;
31 
32 ////////////////////////////////////////////////////////////////////////////
33 // //
34 // TGeoNode - base class for logical nodes. They represent volumes //
35 // positioned inside a mother volume //
36 // //
37 ////////////////////////////////////////////////////////////////////////////
38 
39 class TGeoNode : public TNamed,
40  public TGeoAtt
41 {
42 protected:
43  TGeoVolume *fVolume = nullptr; // volume associated with this
44  TGeoVolume *fMother = nullptr; // mother volume
45  Int_t fNumber = 0; // copy number
46  Int_t fNovlp = 0; // number of overlaps
47  Int_t *fOverlaps = nullptr; //[fNovlp] list of indices for overlapping brothers
48  TGeoExtension *fUserExtension = nullptr; //! Transient user-defined extension to volumes
49  TGeoExtension *fFWExtension = nullptr; //! Transient framework-defined extension to volumes
50 
51  void CopyOverlaps(Int_t *ovlp, Int_t novlp);
52 
53 private:
54  TGeoNode(const TGeoNode&); // not implemented
55  TGeoNode& operator=(const TGeoNode&); // not implemented
56 
57 public:
58  enum {
59  kGeoNodeMatrix = BIT(14),
60  kGeoNodeOffset = BIT(15),
61  kGeoNodeVC = BIT(16),
62  kGeoNodeOverlap = BIT(17),
63  kGeoNodeCloned = BIT(18)
64  };
65 
66  // constructors
67  TGeoNode();
68  TGeoNode(const TGeoVolume *vol);
69  // destructor
70  virtual ~TGeoNode();
71 
72  void Browse(TBrowser *b);
73  virtual void cd() const {;}
74  void CheckOverlaps(Double_t ovlp=0.1, Option_t *option=""); // *MENU*
75  void CheckShapes();
76  Int_t CountDaughters(Bool_t unique_volumes=kFALSE);
77  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
78  void Draw(Option_t *option="");
79  void DrawOnly(Option_t *option="");
80  void DrawOverlaps();
81  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
82  void FillIdArray(Int_t &ifree, Int_t &nodeid, Int_t *array) const;
83  Int_t FindNode(const TGeoNode *node, Int_t level);
84  virtual Int_t GetByteCount() const {return 44;}
85  TGeoNode *GetDaughter(Int_t ind) const {return fVolume->GetNode(ind);}
86  virtual TGeoMatrix *GetMatrix() const = 0;
87 
88  Int_t GetColour() const {return fVolume->GetLineColor();}
89  virtual Int_t GetIndex() const {return 0;}
90  virtual TGeoPatternFinder *GetFinder() const {return 0;}
91  TGeoMedium *GetMedium() const {return fVolume->GetMedium();}
92  TGeoVolume *GetMotherVolume() const {return fMother;}
93  Int_t GetNdaughters() const {return fVolume->GetNdaughters();}
94  TObjArray *GetNodes() const {return fVolume->GetNodes();}
95  Int_t GetNumber() const {return fNumber;}
96  Int_t *GetOverlaps(Int_t &novlp) const {novlp=fNovlp; return fOverlaps;}
97  TGeoVolume *GetVolume() const {return fVolume;}
98  virtual char *GetObjectInfo(Int_t px, Int_t py) const;
99  virtual Int_t GetOptimalVoxels() const {return 0;}
100  void InspectNode() const; // *MENU*
101  Bool_t IsCloned() const {return TObject::TestBit(kGeoNodeCloned);}
102  virtual Bool_t IsFolder() const {return (GetNdaughters()?kTRUE:kFALSE);}
103  Bool_t IsOffset() const {return TObject::TestBit(kGeoNodeOffset);}
104  Bool_t IsOnScreen() const; // *MENU*
105  Bool_t IsOverlapping() const {return TObject::TestBit(kGeoNodeOverlap);}
106  Bool_t IsVirtual() const {return TObject::TestBit(kGeoNodeVC);}
107  Bool_t IsVisible() const {return (TGeoAtt::IsVisible() && fVolume->IsVisible());}
108  Bool_t IsVisDaughters() const {return (TGeoAtt::IsVisDaughters() && fVolume->IsVisDaughters());}
109  Bool_t MayOverlap(Int_t iother) const;
110 
111  virtual TGeoNode *MakeCopyNode() const {return 0;}
112  Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const;
113  void SaveAttributes(std::ostream &out);
114  void SetCurrentPoint(Double_t x, Double_t y, Double_t z) {fVolume->SetCurrentPoint(x,y,z);}// *MENU*
115  void SetVolume(TGeoVolume *volume) {fVolume = volume;}
116  void SetNumber(Int_t number) {fNumber=number;}
117  void SetCloned(Bool_t flag=kTRUE) {TObject::SetBit(kGeoNodeCloned, flag);}
118  void SetOverlapping(Bool_t flag=kTRUE) {TObject::SetBit(kGeoNodeOverlap, flag);}
119  void SetVirtual() {TObject::SetBit(kGeoNodeVC, kTRUE);}
120  void SetVisibility(Bool_t vis=kTRUE); // *MENU*
121  void SetInvisible() {SetVisibility(kFALSE);} // *MENU*
122  void SetAllInvisible() {VisibleDaughters(kFALSE);} // *MENU*
123  void SetMotherVolume(TGeoVolume *mother) {fMother = mother;}
124  void SetOverlaps(Int_t *ovlp, Int_t novlp);
125  void SetUserExtension(TGeoExtension *ext);
126  void SetFWExtension(TGeoExtension *ext);
127  TGeoExtension *GetUserExtension() const {return fUserExtension;}
128  TGeoExtension *GetFWExtension() const {return fFWExtension;}
129  TGeoExtension *GrabUserExtension() const;
130  TGeoExtension *GrabFWExtension() const;
131 
132  virtual void MasterToLocal(const Double_t *master, Double_t *local) const;
133  virtual void MasterToLocalVect(const Double_t *master, Double_t *local) const;
134  virtual void LocalToMaster(const Double_t *local, Double_t *master) const;
135  virtual void LocalToMasterVect(const Double_t *local, Double_t *master) const;
136 
137  virtual void ls(Option_t *option = "") const;
138  virtual void Paint(Option_t *option = "");
139  void PrintCandidates() const; // *MENU*
140  void PrintOverlaps() const; // *MENU*
141  void VisibleDaughters(Bool_t vis=kTRUE); // *MENU*
142 
143  ClassDef(TGeoNode, 2) // base class for all geometry nodes
144 };
145 
146 ////////////////////////////////////////////////////////////////////////////
147 // //
148 // TGeoNodeMatrix - node containing a general transformation //
149 // //
150 ////////////////////////////////////////////////////////////////////////////
151 
152 class TGeoNodeMatrix : public TGeoNode
153 {
154 private:
155  TGeoMatrix *fMatrix = nullptr; // transf. matrix of fNode in fMother system
156 
157  TGeoNodeMatrix(const TGeoNodeMatrix& gnm); // not implemented
158  TGeoNodeMatrix& operator=(const TGeoNodeMatrix& gnm); // not implemented
159 
160 public:
161  // constructors
162  TGeoNodeMatrix();
163  TGeoNodeMatrix(const TGeoVolume *vol, const TGeoMatrix *matrix);
164  // destructor
165  virtual ~TGeoNodeMatrix();
166 
167  virtual Int_t GetByteCount() const;
168  virtual Int_t GetOptimalVoxels() const;
169  virtual Bool_t IsFolder() const {return kTRUE;}
170  virtual TGeoMatrix *GetMatrix() const {return fMatrix;}
171  virtual TGeoNode *MakeCopyNode() const;
172  void SetMatrix(const TGeoMatrix *matrix);
173 
174  ClassDef(TGeoNodeMatrix, 1) // a geometry node in the general case
175 };
176 
177 ////////////////////////////////////////////////////////////////////////////
178 // //
179 // TGeoNodeOffset - node containing only an translation offset //
180 // //
181 ////////////////////////////////////////////////////////////////////////////
182 
183 class TGeoNodeOffset : public TGeoNode
184 {
185 private:
186  Double_t fOffset = 0.; // X offset for this node with respect to its mother
187  Int_t fIndex = 0; // index of this node in the division
188  TGeoPatternFinder *fFinder = nullptr; // finder for this node
189 
190  TGeoNodeOffset(const TGeoNodeOffset&); // not implemented
191  TGeoNodeOffset& operator=(const TGeoNodeOffset&); // not implemented
192 
193 public:
194  // constructors
195  TGeoNodeOffset();
196  TGeoNodeOffset(const TGeoVolume *vol, Int_t index, Double_t offset);
197  // destructor
198  virtual ~TGeoNodeOffset();
199 
200  virtual void cd() const {fFinder->cd(fIndex);}
201  Double_t GetOffset() const {return fOffset;}
202  virtual Int_t GetIndex() const;
203  virtual TGeoPatternFinder *GetFinder() const {return fFinder;}
204  virtual TGeoMatrix *GetMatrix() const {cd(); return fFinder->GetMatrix();}
205  virtual TGeoNode *MakeCopyNode() const;
206  void SetFinder(TGeoPatternFinder *finder) {fFinder = finder;}
207 
208  ClassDef(TGeoNodeOffset, 1) // a geometry node with just an offset
209 };
210 
211 ////////////////////////////////////////////////////////////////////////////
212 // //
213 // TGeoIteratorPlugin - Plugin for a TGeoIterator providing the method //
214 // ProcessNode each time Next is called. //
215 // //
216 ////////////////////////////////////////////////////////////////////////////
217 
218 class TGeoIterator;
219 
220 class TGeoIteratorPlugin : public TObject
221 {
222 protected:
223  const TGeoIterator *fIterator = nullptr; // Caller iterator
224 private:
225  // No copy
226  TGeoIteratorPlugin(const TGeoIteratorPlugin &);
227  TGeoIteratorPlugin &operator=(const TGeoIteratorPlugin &);
228 public:
229  TGeoIteratorPlugin() : TObject(),fIterator(0) {}
230  virtual ~TGeoIteratorPlugin() {}
231 
232  virtual void ProcessNode() = 0;
233  void SetIterator(const TGeoIterator *iter) {fIterator = iter;}
234 
235  ClassDef(TGeoIteratorPlugin, 0) // ABC for user plugins connecter to a geometry iterator.
236 };
237 
238 ////////////////////////////////////////////////////////////////////////////
239 // //
240 // TGeoIterator - iterator for the node tree //
241 // //
242 ////////////////////////////////////////////////////////////////////////////
243 
244 class TGeoIterator
245 {
246 private:
247  TGeoVolume *fTop = nullptr; // Top volume of the iterated branch
248  Bool_t fMustResume = kFALSE; // Private flag to resume from current node.
249  Bool_t fMustStop = kFALSE; // Private flag to signal that the iterator has finished.
250  Int_t fLevel = 0; // Current level in the tree
251  Int_t fType = 0; // Type of iteration
252  Int_t *fArray = nullptr; // Array of node indices for the current path
253  TGeoHMatrix *fMatrix = nullptr; // Current global matrix
254  TString fTopName; // User name for top
255  TGeoIteratorPlugin
256  *fPlugin = nullptr; // User iterator plugin
257  Bool_t fPluginAutoexec = kFALSE; // Plugin automatically executed during next()
258 
259  void IncreaseArray();
260 protected:
261  TGeoIterator() : fTop(0), fMustResume(0), fMustStop(0), fLevel(0), fType(0),
262  fArray(0), fMatrix(0), fTopName(), fPlugin(0), fPluginAutoexec(kFALSE) { }
263 
264 public:
265  TGeoIterator(TGeoVolume *top);
266  TGeoIterator(const TGeoIterator &iter);
267  virtual ~TGeoIterator();
268 
269  TGeoIterator &operator=(const TGeoIterator &iter);
270  TGeoNode *operator()();
271  TGeoNode *Next();
272  void Up() { if (fLevel > 0) fLevel--; }
273 
274  const TGeoMatrix *GetCurrentMatrix() const;
275  Int_t GetIndex(Int_t i) const {return ((i<=fLevel)?fArray[i]:-1);}
276  Int_t GetLevel() const {return fLevel;}
277  TGeoNode *GetNode(Int_t level) const;
278  void GetPath(TString &path) const;
279  TGeoIteratorPlugin
280  *GetUserPlugin() const {return fPlugin;}
281 
282  TGeoVolume *GetTopVolume() const {return fTop;}
283  Int_t GetType() const {return fType;}
284  void Reset(TGeoVolume *top=0);
285  void SetUserPlugin(TGeoIteratorPlugin *plugin);
286  void SetPluginAutoexec(Bool_t mode) {fPluginAutoexec = mode;}
287  void SetType(Int_t type) {fType = type;}
288  void SetTopName(const char* name);
289  void Skip();
290 
291  ClassDef(TGeoIterator,0) //Iterator for geometry.
292 };
293 
294 #endif