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
Detector.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_DETECTOR_H
15 #define DD4HEP_DETECTOR_H
16 
17 // Framework include files
18 #include "DD4hep/Handle.h"
19 #include "DD4hep/Callback.h"
20 #include "DD4hep/Objects.h"
21 #include "DD4hep/Volumes.h"
22 #include "DD4hep/Readout.h"
23 #include "DD4hep/Alignments.h"
24 #include "DD4hep/Segmentations.h"
25 
26 // C/C++ include files
27 #include <map>
28 #include <typeinfo>
29 
31 namespace DD4hep {
32 
34  namespace Geometry {
35 
36  // Forward declarations
37  class LCDD;
38  class DetElementObject;
39  class SensitiveDetectorObject;
40 
42 
47  class SensitiveDetector: public Handle<SensitiveDetectorObject> {
48  public:
50  typedef void (*destruct_t)(void*);
55  protected:
56 
58  template <typename T> static void _delete(void* ptr) {
59  delete (T*) (ptr);
60  }
61 
63  void* i_addExtension(void* ptr, const std::type_info& info, void (*destruct)(void*));
64 
66  void* i_extension(const std::type_info& info) const;
67 
68  public:
69 
72 
74  SensitiveDetector(Object* obj_pointer) : RefObject(obj_pointer) { }
75 
77  SensitiveDetector(const RefObject& sd) : RefObject(sd) { }
78 
80  SensitiveDetector(const SensitiveDetector& sd) = default;
81 
83  template <typename Q> SensitiveDetector(const Handle<Q>& e) : RefObject(e) { }
84 
86  SensitiveDetector(const std::string& name, const std::string& type = "sensitive");
87 
89  SensitiveDetector& operator=(const SensitiveDetector& sd) = default;
90 
92  std::string type() const;
93 
95  SensitiveDetector& setType(const std::string& typ);
96 
98  SensitiveDetector& setVerbose(bool value);
99 
101  bool verbose() const;
102 
104  SensitiveDetector& setCombineHits(bool value);
105 
107  bool combineHits() const;
108 
110  SensitiveDetector& setHitsCollection(const std::string& spec);
111 
113  const std::string& hitsCollection() const;
114 
117 
119  Readout readout() const;
120 
122  SensitiveDetector& setEnergyCutoff(double value);
123 
125  double energyCutoff() const;
126 
129 
131  Region region() const;
132 
135 
137  LimitSet limits() const;
138 
140  template <typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) {
141  return (IFACE*) i_addExtension(dynamic_cast<IFACE*>(c), typeid(IFACE), _delete<IFACE>);
142  }
143 
145  template <typename IFACE> IFACE* extension() const {
146  return (IFACE*) i_extension(typeid(IFACE));
147  }
148  };
149 
151 
172  class DetElement: public Handle<DetElementObject> {
173  public:
175 
180  class Processor {
181  public:
183  Processor();
185  virtual ~Processor();
187  virtual int processElement(DetElement detector) = 0;
188  };
189 
196 
198  typedef void* (*copy_t)(const void*, DetElement);
200  typedef void (*destruct_t)(void*);
201 
202  typedef std::map<std::string, DetElement> Children;
203  typedef std::map<const std::type_info*, void*> Extensions;
204 
206  COPY_NONE = 0, COPY_PLACEMENT = 1 << 0, COPY_PARENT = 1 << 1, COPY_ALIGNMENT = 1 << 2, LAST
207  };
208 
209  enum UpdateParam {
217  };
218 
220  void check(bool condition, const std::string& msg) const;
221 
222  protected:
223 
225  template <typename T> static void _delete(void* ptr) {
226  delete (T*) (ptr);
227  }
229  template <typename T> static void* _copy(const void* ptr, DetElement elt) {
230  return new T(*(dynamic_cast<const T*>((T*) ptr)), elt);
231  }
232 
234  void* i_addExtension(void* ptr, const std::type_info& info, copy_t ctor, destruct_t dtor) const;
236  void* i_extension(const std::type_info& info) const;
238  void i_addUpdateCall(unsigned int callback_type, const Callback& callback) const;
239 
240  public:
241 
244 
246  DetElement(Object* object_ptr) : RefObject(object_ptr) { }
247 
249  DetElement(Object* data, const std::string& name, const std::string& type);
250 
252  template <typename Q> DetElement(const Handle<Q>& e) : RefObject(e) {}
253 
255  DetElement(const DetElement& e) = default;
256 
257 #ifdef __MAKECINT__
258  DetElement(const Ref_t& e)
260  : RefObject(e) {
261  }
262 #endif
263  DetElement(const std::string& name, const std::string& type, int id);
265 
267  DetElement(const std::string& name, int id);
268 
270  DetElement(DetElement parent, const std::string& name, int id);
271 
273  Object& _data() const {
274  return object<Object>();
275  }
276 
278  bool operator <(const DetElement e) const {
279  return ptr() < e.ptr();
280  }
281 
283  bool operator ==(const DetElement e) const {
284  return ptr() == e.ptr();
285  }
286 
288  DetElement& operator=(const DetElement& e) = default;
289 
291  DetElement clone(const std::string& new_name) const;
292 
294  DetElement clone(const std::string& new_name, int new_id) const;
295 
297  template <typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) const {
298  CallbackSequence::checkTypes(typeid(IFACE), typeid(CONCRETE), dynamic_cast<IFACE*>(c));
299  return (IFACE*) i_addExtension(dynamic_cast<IFACE*>(c), typeid(IFACE), _copy<CONCRETE>, _delete<IFACE>);
300  }
302  template <typename IFACE> IFACE* extension() const {
303  return (IFACE*) i_extension(typeid(IFACE));
304  }
306  template <typename Q, typename T>
307  void callAtUpdate(unsigned int typ, Q* pointer,
308  void (T::*pmf)(unsigned long typ, DetElement& det, void* opt_par)) const
309  {
310  CallbackSequence::checkTypes(typeid(T), typeid(Q), dynamic_cast<T*>(pointer));
311  i_addUpdateCall(typ, Callback(pointer).make(pmf));
312  }
314  void removeAtUpdate(unsigned int type, void* pointer) const;
315 
317  int id() const;
319  DetElement& setCombineHits(bool value, SensitiveDetector& sens);
321  bool combineHits() const;
322 
326  std::string type() const;
328  DetElement& setType(const std::string& typ);
329 
330  // Return flag word encoding detector types ( ideally use DD4hep::DetType for decoding )
331  unsigned int typeFlag() const;
332 
334  DetElement& setTypeFlag(unsigned int types);
335 
337  unsigned int key() const;
339  int level() const;
341  const std::string& path() const;
343  const std::string& placementPath() const;
344 
346  DetElement& setAttributes(const LCDD& lcdd, const Volume& volume, const std::string& region, const std::string& limits,
347  const std::string& vis);
348 
350  DetElement& setVisAttributes(const LCDD& lcdd, const std::string& name, const Volume& volume);
352  DetElement& setRegion(const LCDD& lcdd, const std::string& name, const Volume& volume);
354  DetElement& setLimitSet(const LCDD& lcdd, const std::string& name, const Volume& volume);
355 
357  Volume volume() const;
358 
360  PlacedVolume placement() const;
364  VolumeID volumeID() const;
365 
367  DetElement& add(DetElement sub_element);
369  const Children& children() const;
371  DetElement child(const std::string& name) const;
373  DetElement parent() const;
375  DetElement world() const;
376 
378  bool hasConditions() const;
380  bool hasAlignments() const;
381 
383  Alignment nominal() const;
385  Alignment survey() const;
386 
387  // Deprecated functions to be removed soon:
388 
390  //DetElement& setReference(DetElement reference);
391 
393  const TGeoHMatrix& worldTransformation() const;
395  const TGeoHMatrix& parentTransformation() const;
397  //const TGeoHMatrix& referenceTransformation() const;
398 
400  bool localToWorld(const Position& local, Position& global) const;
402  bool localToParent(const Position& local, Position& parent) const;
404  //bool localToReference(const Position& local, Position& reference) const;
405 
407  bool worldToLocal(const Position& global, Position& local) const;
409  bool parentToLocal(const Position& parent, Position& local) const;
411  //bool referenceToLocal(const Position& reference, Position& local) const;
412  };
413 
414  } /* End namespace Geometry */
415 } /* End namespace DD4hep */
416 
417 #include "DD4hep/AlignmentData.h"
418 
419 #endif /* DD4HEP_DETECTOR_H */
SensitiveDetector & setVerbose(bool value)
Set flag to handle hits collection.
Definition: Detector.cpp:478
Handle class to hold the information of a sensitive detector.
Definition: Detector.h:47
bool hasAlignments() const
Check if this DetElement has time dependent Alignments attached.
Definition: Detector.cpp:242
void(* destruct_t)(void *)
Extensions destructor type.
Definition: Detector.h:50
SensitiveDetector & setHitsCollection(const std::string &spec)
Assign the name of the hits collection.
Definition: Detector.cpp:467
DetElement(Object *object_ptr)
Constructor to hold handled object.
Definition: Detector.h:246
SensitiveDetector & operator=(const SensitiveDetector &sd)=default
Assignment operator.
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:135
virtual ~Processor()
Default destructor.
Definition: Detector.cpp:36
DetElement world() const
Access to the world object. Only possible once the geometry is closed.
Definition: Detector.cpp:228
bool operator<(const DetElement e) const
Operator less to insert into a map.
Definition: Detector.h:278
SensitiveDetectorObject Object
Internal object type.
Definition: Detector.h:52
Volume volume() const
Access to the logical volume of the detector element's placement.
Definition: Detector.cpp:311
bool hasConditions() const
Check if this DetElement has time dependent Conditions attached.
Definition: Detector.cpp:234
Handle< SensitiveDetectorObject > RefObject
Definition of the base handle type.
Definition: Detector.h:54
const char * name() const
Access the object name (or "" if not supported by the object)
Definition: Handle.inl:36
DetElement & setLimitSet(const LCDD &lcdd, const std::string &name, const Volume &volume)
Set the limits to the detector element.
Definition: Detector.cpp:327
Alignment nominal() const
Access to the constant ideal (nominal) alignment information.
Definition: Detector.cpp:187
Data class with properties of sensitive detectors.
const std::string & hitsCollection() const
Access the hits collection name.
Definition: Detector.cpp:473
void(* destruct_t)(void *)
Extensions destructor type.
Definition: Detector.h:200
Q * data() const
Access to an unrelated object type.
Definition: Handle.h:157
SensitiveDetector(Object *obj_pointer)
Constructor to copy handled object.
Definition: Detector.h:74
SensitiveDetector & setRegion(Region reg)
Set the regional attributes to the sensitive detector.
Definition: Detector.cpp:502
IFACE * addExtension(CONCRETE *c) const
Extend the detector element with an arbitrary structure accessible by the type.
Definition: Detector.h:297
DetElement & setType(const std::string &typ)
Set detector type (structure, tracker, calorimeter, etc.).
Definition: Detector.cpp:103
LimitSet limits() const
Access to the limit set of the sensitive detector (not mandatory).
Definition: Detector.cpp:519
DetElement(const Handle< Q > &e)
Templated constructor for handle conversions.
Definition: Detector.h:252
bool operator==(const DetElement e) const
Equality operator.
Definition: Detector.h:283
virtual int processElement(DetElement detector)=0
Container callback for object processing.
bool combineHits() const
Getter: Combine hits attribute.
Definition: Detector.cpp:175
void * i_extension(const std::type_info &info) const
Access an existing extension object from the detector element.
Definition: Detector.cpp:529
void callAtUpdate(unsigned int typ, Q *pointer, void(T::*pmf)(unsigned long typ, DetElement &det, void *opt_par)) const
Extend the detector element with an arbitrary callback.
Definition: Detector.h:307
Main handle class to hold an alignment object.
Definition: Alignments.h:65
int level() const
Access the hierarchical level of the detector element (Only valid once geometry is closed!) ...
Definition: Detector.cpp:148
DetElement & setVisAttributes(const LCDD &lcdd, const std::string &name, const Volume &volume)
Set Visualization attributes to the detector element.
Definition: Detector.cpp:315
void *(* copy_t)(const void *, DetElement)
Extensions copy constructor type.
Definition: Detector.h:198
SensitiveDetector()
Default constructor.
Definition: Detector.h:71
const Children & children() const
Access to the list of children.
Definition: Detector.cpp:207
bool parentToLocal(const Position &parent, Position &local) const
Transformation from world coordinates of the local placed volume coordinates.
Definition: Detector.cpp:412
std::string type() const
Access detector type (structure, tracker, calorimeter, etc.).
Definition: Detector.cpp:98
return e
Definition: Volumes.cpp:297
SensitiveDetector & setType(const std::string &typ)
Set detector type (structure, tracker, calorimeter, etc.).
Definition: Detector.cpp:434
SensitiveDetector & setCombineHits(bool value)
Set flag to handle hits collection.
Definition: Detector.cpp:490
std::map< const std::type_info *, void * > Extensions
Definition: Detector.h:203
DetElement & setRegion(const LCDD &lcdd, const std::string &name, const Volume &volume)
Set the regional attributes to the detector element.
Definition: Detector.cpp:320
Handle to the implementation of the readout structure of a subdetector.
Definition: Readout.h:46
T * ptr() const
Access to the held object.
Definition: Handle.h:149
unsigned int typeFlag() const
Definition: Detector.cpp:109
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:237
Abstract base for processing callbacks to DetElement objects.
Definition: Detector.h:180
void removeAtUpdate(unsigned int type, void *pointer) const
Remove callback from object.
Definition: Detector.cpp:81
DetElement & add(DetElement sub_element)
Add new child to the detector structure.
Definition: Detector.cpp:255
DetElement & setTypeFlag(unsigned int types)
Set the flag word encoding detector types ( ideally use DD4hep::DetType for encoding ) ...
Definition: Detector.cpp:114
DetElement child(const std::string &name) const
Access to individual children by name.
Definition: Detector.cpp:212
void i_addUpdateCall(unsigned int callback_type, const Callback &callback) const
Internal call to extend the detector element with an arbitrary structure accessible by the type...
Definition: Detector.cpp:76
static void checkTypes(const std::type_info &typ1, const std::type_info &typ2, void *test)
Check the compatibility of two typed objects. The test is the result of a dynamic_cast.
Definition: Callback.cpp:22
SensitiveDetector(const Handle< Q > &e)
Templated constructor for handle conversions.
Definition: Detector.h:83
VolumeID volumeID() const
The cached VolumeID of this subdetector element.
Definition: Detector.cpp:303
DetElement()
Default constructor.
Definition: Detector.h:243
DetElementObject Object
Internal object type.
Definition: Detector.h:191
Handle< DetElementObject > RefObject
Definition of the base handle type.
Definition: Detector.h:193
DetElement & setPlacement(const PlacedVolume &volume)
Set the physical volumes of the detector element.
Definition: Detector.cpp:290
Definition of the generic callback structure for member functions.
Definition: Callback.h:38
DetElement & setCombineHits(bool value, SensitiveDetector &sens)
Setter: Combine hits attribute.
Definition: Detector.cpp:179
DetElement clone(const std::string &new_name) const
Clone (Deep copy) the DetElement structure with a new name.
Definition: Detector.cpp:268
void * i_addExtension(void *ptr, const std::type_info &info, copy_t ctor, destruct_t dtor) const
Add an extension object to the detector element.
Definition: Detector.cpp:66
SensitiveDetector & setLimitSet(LimitSet limits)
Set the limits to the sensitive detector.
Definition: Detector.cpp:513
Processor()
Default constructor.
Definition: Detector.cpp:32
ROOT::Math::XYZVector Position
Definition: Objects.h:75
Alignments::Alignment Alignment
Definition: Detector.h:195
void check(bool condition, const std::string &msg) const
Internal assert function to check conditions.
Definition: Detector.cpp:249
bool verbose() const
Access flag to combine hist.
Definition: Detector.cpp:485
const std::string & path() const
Path of the detector element (not necessarily identical to placement path!)
Definition: Detector.cpp:160
PlacedVolume placement() const
Access to the physical volume of this detector element.
Definition: Detector.cpp:279
static void _delete(void *ptr)
Templated destructor function.
Definition: Detector.h:225
int id() const
Get the detector identifier.
Definition: Detector.cpp:171
DetElement parent() const
Access to the detector elements's parent.
Definition: Detector.cpp:222
Handle< NamedObject > Ref_t
Default Ref_t definition describing named objects.
Definition: Handle.h:176
Handle class describing a detector element.
Definition: Detector.h:172
Readout readout() const
Access readout structure of the sensitive detector.
Definition: Detector.cpp:451
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:87
IFACE * extension() const
Access extension element by the type.
Definition: Detector.h:145
IFACE * extension() const
Access extension element by the type.
Definition: Detector.h:302
bool localToParent(const Position &local, Position &parent) const
Transformation from local coordinates of the placed volume to the parent system.
Definition: Detector.cpp:394
Handle class describing a set of limits as they are used for simulation.
Definition: Objects.h:475
long long int VolumeID
Definition: Primitives.h:35
Object & _data() const
Additional data accessor.
Definition: Detector.h:273
Handle class describing a region as used in simulation.
Definition: Objects.h:516
static void _delete(void *ptr)
Templated destructor function.
Definition: Detector.h:58
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
bool localToWorld(const Position &local, Position &global) const
Create cached matrix to transform to reference coordinates.
Definition: Detector.cpp:385
IFACE * addExtension(CONCRETE *c)
Extend the sensitive detector element with an arbitrary structure accessible by the type...
Definition: Detector.h:140
DetElement & setAttributes(const LCDD &lcdd, const Volume &volume, const std::string &region, const std::string &limits, const std::string &vis)
Set all attributes in one go.
Definition: Detector.cpp:334
bool worldToLocal(const Position &global, Position &local) const
Transformation from local coordinates of the placed volume to arbitrary parent system set as referenc...
Definition: Detector.cpp:403
std::map< std::string, DetElement > Children
Definition: Detector.h:202
Data class with properties of a detector element.
unsigned int key() const
Access hash key of this detector element (Only valid once geometry is closed!)
Definition: Detector.cpp:136
const TGeoHMatrix & parentTransformation() const
Create cached matrix to transform to parent coordinates.
Definition: Detector.cpp:380
bool combineHits() const
Access flag to combine hist.
Definition: Detector.cpp:497
std::string type() const
Access the type of the sensitive detector.
Definition: Detector.cpp:440
Region region() const
Access to the region setting of the sensitive detector (not mandatory)
Definition: Detector.cpp:508
SensitiveDetector(const RefObject &sd)
Copy from named handle.
Definition: Detector.h:77
static void * _copy(const void *ptr, DetElement elt)
Templated copy constructor.
Definition: Detector.h:229
SensitiveDetector & setReadout(Readout readout)
Assign the IDDescriptor reference.
Definition: Detector.cpp:445
DetElement & operator=(const DetElement &e)=default
Assignment operator.
const TGeoHMatrix & worldTransformation() const
Set detector element for reference transformations. Will delete existing reference trafo...
Definition: Detector.cpp:375
SensitiveDetector & setEnergyCutoff(double value)
Set energy cut off.
Definition: Detector.cpp:456
void * i_extension(const std::type_info &info) const
Access an existing extension object from the detector element.
Definition: Detector.cpp:71
const std::string & placementPath() const
Access to the full path to the placed object.
Definition: Detector.cpp:86
void * i_addExtension(void *ptr, const std::type_info &info, void(*destruct)(void *))
Add an extension object to the detector element.
Definition: Detector.cpp:524
Alignment survey() const
Access to the constant survey alignment information.
Definition: Detector.cpp:198
double energyCutoff() const
Access energy cut off.
Definition: Detector.cpp:462