DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Volumes.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 #ifndef DD4HEP_GEOMETRY_VOLUMES_H
15 #define DD4HEP_GEOMETRY_VOLUMES_H
16 
17 // Framework include files
18 #include "DD4hep/Handle.h"
19 #include "DD4hep/Shapes.h"
20 #include "DD4hep/Objects.h"
21 
22 // C/C++ include files
23 #include <map>
24 
25 // ROOT include file (includes TGeoVolume + TGeoShape)
26 #include "TGeoNode.h"
27 #include "TGeoPatternFinder.h"
28 
29 #if ROOT_VERSION_CODE > ROOT_VERSION(5,34,9)
30 // Recent ROOT versions
31 #include "TGeoExtension.h"
32 
33 #else
34 // Older ROOT version
35 #define DD4HEP_EMULATE_TGEOEXTENSIONS
36 class TGeoExtension : public TObject {
37 public:
38  virtual ~TGeoExtension() {}
40  virtual TGeoExtension *Grab() = 0;
42  virtual void Release() const = 0;
43 };
44 #endif
45 
47 namespace DD4hep {
48 
50  namespace Geometry {
51 
52  // Forward declarations
53  class LCDD;
54  class Region;
55  class LimitSet;
56  class Material;
57  class VisAttr;
58  class Volume;
59  class DetElement;
60  class PlacedVolume;
61  class SensitiveDetector;
62 
64 
73  public:
74  typedef std::pair<std::string, int> VolID;
76 
81  class VolIDs: public std::vector<VolID> {
82  public:
83  typedef std::vector<VolID> Base;
85  VolIDs() : std::vector<VolID>() {}
87  VolIDs(const VolIDs& c) : std::vector<VolID>(c) {}
89  ~VolIDs() {}
91  VolIDs& operator=(const VolIDs& c) {
92  if ( &c != this ) this->std::vector<VolID>::operator=(c);
93  return *this;
94  }
96  std::vector<VolID>::const_iterator find(const std::string& name) const;
98  std::pair<std::vector<VolID>::iterator, bool> insert(const std::string& name, int value);
99  };
101  unsigned long magic;
103  long refCount;
111  virtual ~PlacedVolumeExtension();
114  magic = c.magic;
115  volIDs = c.volIDs;
116  return *this;
117  }
119  virtual TGeoExtension *Grab();
121  virtual void Release() const;
124  };
125 
127 
135  class PlacedVolume : public Handle<TGeoNode> {
136  public:
140 
142  PlacedVolume(const TGeoNode* e)
143  : Handle<TGeoNode>(e) {
144  }
147  : Handle<TGeoNode>() {
148  }
151  : Handle<TGeoNode>(e) {
152  }
154  template <typename T> PlacedVolume(const Handle<T>& e)
155  : Handle<TGeoNode>(e) {
156  }
159  m_element = v.m_element;
160  return *this;
161  }
163  Object* data() const;
165  PlacedVolume& addPhysVolID(const std::string& name, int value);
167  Material material() const;
169  Volume volume() const;
171  Volume motherVol() const;
173  const VolIDs& volIDs() const;
175  std::string toString() const;
176  };
177 
179 
190  public:
192  unsigned long magic;
194  long refCount;
203 
206  VolumeExtension();
208  virtual ~VolumeExtension();
210  void copy(const VolumeExtension& c) {
211  magic = c.magic;
212  region = c.region;
213  limits = c.limits;
214  vis = c.vis;
215  sens_det = c.sens_det;
217  }
219  virtual TGeoExtension *Grab();
221  virtual void Release() const;
224  };
225 
227 
237  class Volume: public Handle<TGeoVolume> {
238 
239  public:
242 
243  public:
246  : Base(0) {
247  }
248 
250  Volume(const TGeoVolume* v)
251  : Base(v) {
252  }
253 
255  Volume(const Volume& v)
256  : Base(v) {
257  }
258 
260  template <typename T> Volume(const Handle<T>& v)
261  : Base(v) {
262  }
263 
265  Volume(const std::string& name);
266 
268  Volume(const std::string& name, const Solid& s, const Material& m);
269 
271  Volume& operator=(const Volume& a) {
272  m_element = a.m_element;
273  return *this;
274  }
275 
277  Object* data() const;
279  PlacedVolume placeVolume(const Volume& vol) const;
281  PlacedVolume placeVolume(const Volume& volume, const Transform3D& tr) const;
283  PlacedVolume placeVolume(const Volume& vol, const Position& pos) const;
285  PlacedVolume placeVolume(const Volume& vol, const RotationZYX& rot) const;
287  PlacedVolume placeVolume(const Volume& vol, const Rotation3D& rot) const;
288 
290  const Volume& setAttributes(const LCDD& lcdd, const std::string& region, const std::string& limits,
291  const std::string& vis) const;
292 
294  const Volume& setRegion(const LCDD& lcdd, const std::string& name) const;
296  const Volume& setRegion(const Region& obj) const;
298  Region region() const;
299 
301  const Volume& setLimitSet(const LCDD& lcdd, const std::string& name) const;
303  const Volume& setLimitSet(const LimitSet& obj) const;
305  LimitSet limitSet() const;
306 
308  const Volume& setVisAttributes(const VisAttr& obj) const;
310  const Volume& setVisAttributes(const LCDD& lcdd, const std::string& name) const;
312  VisAttr visAttributes() const;
313 
315  const Volume& setSensitiveDetector(const SensitiveDetector& obj) const;
317  Ref_t sensitiveDetector() const;
319  bool isSensitive() const;
320 
322  const Volume& setSolid(const Solid& s) const;
324  Solid solid() const;
325 
327  const Volume& setMaterial(const Material& m) const;
329  Material material() const;
330 
332  operator TGeoVolume*() const {
333  return m_element;
334  }
335  };
336 
338 
348  class Assembly: public Volume {
349  public:
352  : Volume() {
353  }
354 
357  : Volume(v) {
358  }
359 
361  template <typename T> Assembly(const Handle<T>& v)
362  : Volume(v) {
363  }
364 
366  Assembly(const std::string& name);
367 
370  m_element = a.m_element;
371  return *this;
372  }
373  };
374 
375  } /* End namespace Geometry */
376 } /* End namespace DD4hep */
377 #endif /* DD4HEP_GEOMETRY_VOLUMES_H */
Handle class to hold the information of a sensitive detector.
Definition: Detector.h:47
ClassDef(VolumeExtension, 1)
Enable ROOT persistency.
virtual ~PlacedVolumeExtension()
Default destructor.
Definition: Volumes.cpp:319
virtual void Release() const
TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore...
Definition: Volumes.cpp:447
VisAttr vis
Reference to visualization attributes.
Definition: Volumes.h:200
Ref_t sensitiveDetector() const
Access to the handle to the sensitive detector.
Definition: Volumes.cpp:743
const Volume & setLimitSet(const LCDD &lcdd, const std::string &name) const
Set the limits to the volume. Note: If the name string is empty, the action is ignored.
Definition: Volumes.cpp:717
Handle< TGeoVolume > Base
Definition: Volumes.h:240
PlacedVolume()
Default constructor.
Definition: Volumes.h:146
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:135
PlacedVolumeExtension Object
Definition: Volumes.h:137
Solid solid() const
Access to Solid (Shape)
Definition: Volumes.cpp:693
Volume volume() const
Logical volume of this placement.
Definition: Volumes.cpp:389
const VolIDs & volIDs() const
Access to the volume IDs.
Definition: Volumes.cpp:399
PlacedVolume(const TGeoNode *e)
Constructor to be used when reading the already parsed DOM tree.
Definition: Volumes.h:142
const char * name() const
Access the object name (or "" if not supported by the object)
Definition: Handle.inl:36
ClassDef(PlacedVolumeExtension, 1)
Enable ROOT persistency.
Assembly & operator=(const Assembly &a)
Assignment operator (must match copy constructor)
Definition: Volumes.h:369
long refCount
Reference count on object (used to implement Grab/Release)
Definition: Volumes.h:194
Handle class describing a material.
Definition: Objects.h:300
Implementation class extending the ROOT assembly volumes (TGeoVolumeAsembly)
Definition: Volumes.h:348
LimitSet limitSet() const
Access to the limit set.
Definition: Volumes.cpp:731
PlacedVolume(const PlacedVolume &e)
Copy assignment.
Definition: Volumes.h:150
virtual TGeoExtension * Grab()
TGeoExtension overload: Method called whenever requiring a pointer to the extension.
Definition: Volumes.cpp:434
Object * data() const
Check if placement is properly instrumented.
Definition: Volumes.cpp:371
VolIDs(const VolIDs &c)
Copy constructor.
Definition: Volumes.h:87
Implementation class extending the ROOT placed volume.
Definition: Volumes.h:72
TGeoShape * s
Definition: Volumes.cpp:294
Ref_t sens_det
Reference to the sensitive detector.
Definition: Volumes.h:202
virtual void Release() const
TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore...
Definition: Volumes.cpp:333
return e
Definition: Volumes.cpp:297
VisAttr visAttributes() const
Access the visualisation attributes.
Definition: Volumes.cpp:679
virtual TGeoExtension * Grab()
TGeoExtension overload: Method called whenever requiring a pointer to the extension.
Definition: Volumes.cpp:324
virtual ~TGeoExtension()
Definition: Volumes.h:38
DD4hep::Geometry::DetElement DetElement
std::string toString() const
String dump.
Definition: Volumes.cpp:404
PlacedVolumeExtension & operator=(const PlacedVolumeExtension &c)
Assignment operator.
Definition: Volumes.h:113
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:237
std::pair< std::vector< VolID >::iterator, bool > insert(const std::string &name, int value)
Inert new entry.
Definition: Volumes.cpp:350
Material material() const
Volume material.
Definition: Volumes.cpp:384
const Volume & setVisAttributes(const VisAttr &obj) const
Set Visualization attributes to the volume.
Definition: Volumes.cpp:564
long refCount
Reference count on object (used to implement Grab/Release)
Definition: Volumes.h:103
std::pair< std::string, int > VolID
Definition: Volumes.h:74
ROOT::Math::RotationZYX RotationZYX
Definition: Objects.h:98
Volume(const TGeoVolume *v)
Copy from handle.
Definition: Volumes.h:250
Assembly()
Default constructor.
Definition: Volumes.h:351
void copy(const VolumeExtension &c)
Copy the object.
Definition: Volumes.h:210
const Volume & setMaterial(const Material &m) const
Set the volume's material.
Definition: Volumes.cpp:544
ROOT::Math::Rotation3D Rotation3D
Definition: Objects.h:106
virtual void Release() const =0
TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore...
Volume motherVol() const
Parent volume (envelope)
Definition: Volumes.cpp:394
virtual ~VolumeExtension()
Default destructor.
Definition: Volumes.cpp:425
VolumeExtension Object
Definition: Volumes.h:241
const Volume & setAttributes(const LCDD &lcdd, const std::string &region, const std::string &limits, const std::string &vis) const
Attach attributes to the volume.
Definition: Volumes.cpp:669
Volume(const Volume &v)
Copy from handle.
Definition: Volumes.h:255
ROOT::Math::XYZVector Position
Definition: Objects.h:75
Volume()
Default constructor.
Definition: Volumes.h:245
DD4hep::Geometry::SensitiveDetector SensitiveDetector
Implementation class extending the ROOT volume (TGeoVolume)
Definition: Volumes.h:189
unsigned long magic
Magic word to detect memory corruptions.
Definition: Volumes.h:101
Region region() const
Access to the handle to the region structure.
Definition: Volumes.cpp:712
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:38
Volume & operator=(const Volume &a)
Assignment operator (must match copy constructor)
Definition: Volumes.h:271
Handle< NamedObject > Ref_t
Default Ref_t definition describing named objects.
Definition: Handle.h:176
VolumeExtension()
Default constructor.
Handle class describing visualization attributes.
Definition: Objects.h:341
Object * data() const
Check if placement is properly instrumented.
Definition: Volumes.cpp:485
std::vector< VolID >::const_iterator find(const std::string &name) const
Find entry.
Definition: Volumes.cpp:341
virtual TGeoExtension * Grab()=0
TGeoExtension overload: Method called whenever requiring a pointer to the extension.
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:87
Volume(const Handle< T > &v)
Copy from arbitrary Element.
Definition: Volumes.h:260
View * v
Definition: MultiView.cpp:30
Assembly(const Handle< T > &v)
Copy from arbitrary Element.
Definition: Volumes.h:361
Handle class describing a set of limits as they are used for simulation.
Definition: Objects.h:475
Handle class describing a region as used in simulation.
Definition: Objects.h:516
const Volume & setRegion(const LCDD &lcdd, const std::string &name) const
Set the regional attributes to the volume. Note: If the name string is empty, the action is ignored...
Definition: Volumes.cpp:698
LimitSet limits
Limit sets used for simulation.
Definition: Volumes.h:198
PlacedVolume & addPhysVolID(const std::string &name, int value)
Add identifier.
Definition: Volumes.cpp:377
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
PlacedVolume & operator=(const PlacedVolume &v)
Assignment operator (must match copy constructor)
Definition: Volumes.h:158
Region region
Region reference.
Definition: Volumes.h:196
PlacedVolume(const Handle< T > &e)
Copy assignment from other handle type.
Definition: Volumes.h:154
T * m_element
Single and only data member: Reference to the actual element.
Definition: Handle.h:96
const Volume & setSensitiveDetector(const SensitiveDetector &obj) const
Assign the sensitive detector structure.
Definition: Volumes.cpp:736
Material material() const
Access to the Volume material.
Definition: Volumes.cpp:557
ROOT::Math::Transform3D Transform3D
Definition: Objects.h:110
const Volume & setSolid(const Solid &s) const
Set the volume's solid shape.
Definition: Volumes.cpp:687
VolIDs & operator=(const VolIDs &c)
Assignment operator.
Definition: Volumes.h:91
PlacedVolumeExtension()
Default constructor.
Definition: Volumes.cpp:306
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: Volumes.h:36
TGeoShape TGeoMedium * m
Definition: Volumes.cpp:294
PlacedVolume placeVolume(const Volume &vol) const
Place daughter volume. The position and rotation are the identity.
Definition: Volumes.cpp:524
bool isSensitive() const
Accessor if volume is sensitive (ie. is attached to a sensitive detector)
Definition: Volumes.cpp:749
Assembly(const Assembly &v)
Copy from handle.
Definition: Volumes.h:356
unsigned long magic
Magic word to detect memory corruptions.
Definition: Volumes.h:192