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
AlignmentData.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 #ifndef DD4HEP_ALIGMENTS_ALIGNMENTDATA_H
14 #define DD4HEP_ALIGMENTS_ALIGNMENTDATA_H
15 
16 // Framework include files
17 #include "DD4hep/NamedObject.h"
18 #include "DD4hep/Detector.h"
19 #include "DD4hep/Volumes.h"
20 
21 // ROOT include files
22 #include "TGeoMatrix.h"
23 
25 namespace DD4hep {
26 
28  namespace Alignments {
29 
30  // The DetElement is a central object. We alias it here.
35  using Geometry::Position;
36  using Geometry::LCDD;
37 
38  // Forward declarations
39  class Alignment;
40  class AlignmentCondition;
41 
43 
49  class Delta {
50  public:
55  unsigned int flags = 0;
56 
58  HAVE_NONE = 0,
60  HAVE_ROTATION = 1<<3,
61  HAVE_PIVOT = 1<<4,
62  };
63 
65  Delta() = default;
67  Delta(const Position& tr)
70  Delta(const RotationZYX& rot)
73  Delta(const Position& tr, const RotationZYX& rot)
76  Delta(const Translation3D& piv, const RotationZYX& rot)
77  : pivot(piv), rotation(rot), flags(HAVE_ROTATION|HAVE_PIVOT) {}
79  Delta(const Position& tr, const Translation3D& piv, const RotationZYX& rot)
82  Delta(const Delta& c);
84  ~Delta();
86  Delta& operator=(const Delta& c);
88  void clear();
90  bool checkFlag(unsigned int mask) const { return (flags&mask) == mask; }
92  void setFlag(unsigned int mask) { flags |= mask; }
94  bool hasTranslation() const { return checkFlag(HAVE_TRANSLATION); }
96  bool hasRotation() const { return checkFlag(HAVE_ROTATION); }
98  bool hasPivot() const { return checkFlag(HAVE_PIVOT); }
99  };
100 
102 
108  public:
109 
113  typedef std::vector<PlacedVolume> NodeList;
117  typedef unsigned int BitMask;
120 
121 
126  HAVE_OTHER = 1<<31
127  };
128  enum DataType {
129  IDEAL = 1<<10,
130  SURVEY = 1<<11,
131  TIME_STAMPED = 1<<12
132  };
133 
137  mutable TGeoHMatrix worldTrafo;
139  mutable TGeoHMatrix worldDelta;
141  mutable TGeoHMatrix detectorTrafo;
153  mutable BitMask flag;
155  unsigned int magic;
156 
157  public:
159  AlignmentData();
163  virtual ~AlignmentData();
167  inline AlignmentData& data() { return *this; }
169  bool hasCondition() const { return condition.isValid(); }
171  Alignment nominal() const;
173  const TGeoHMatrix& worldTransformation() const { return worldTrafo; }
175  const TGeoHMatrix& detectorTransformation() const { return detectorTrafo; }
177  const Transform3D& localToWorld() const { return trToWorld; }
178 
180  void localToWorld(const Position& local, Position& global) const;
183  void localToWorld(const Double_t local[3], Double_t global[3]) const;
185  Position localToWorld(const Position& local) const;
187  Position localToWorld(const Double_t local[3]) const
188  { return localToWorld(Position(local[0],local[1],local[2])); }
189 
191  void worldToLocal(const Position& global, Position& local) const;
194  void worldToLocal(const Double_t global[3], Double_t local[3]) const;
196  Position worldToLocal(const Position& global) const;
198  Position worldToLocal(const Double_t global[3]) const
199  { return worldToLocal(Position(global[0],global[1],global[2])); }
200 
202  void localToDetector(const Position& local, Position& detector) const;
205  void localToDetector(const Double_t local[3], Double_t detector[3]) const;
207  Position localToDetector(const Position& local) const;
209  Position localToDetector(const Double_t local[3]) const
210  { return localToDetector(Position(local[0],local[1],local[2])); }
211 
213  void detectorToLocal(const Position& detector, Position& local) const;
216  void detectorToLocal(const Double_t detector[3], Double_t local[3]) const;
220  Position detectorToLocal(const Double_t det[3]) const
221  { return detectorToLocal(Position(det[0],det[1],det[2])); }
222  };
223 
230  template <typename T> class AlignmentDecorator : public T {
231  public:
238 
244  template <typename Q> AlignmentDecorator(Q q) : T(q) {}
247 
249  const AlignmentData& data() const { return T::data(); }
252  { return data().detector; }
255  { return data().placement; }
258  { return data().detector.placement(); }
259 
261  const Transform3D& localToWorld() const
262  { return data().trToWorld; }
264  const TGeoHMatrix& worldTransformation() const
265  { return data().worldTransformation(); }
267  const TGeoHMatrix& detectorTransformation() const
268  { return data().detectorTransformation(); }
269 
271  void localToWorld(const Position& local, Position& global) const
272  { return data().localToWorld(local, global); }
274  void localToWorld(const Double_t local[3], Double_t global[3]) const
275  { return data().localToWorld(local, global); }
276 
278  void localToDetector(const Position& local, Position& det) const
279  { return data().localToDetector(local, det); }
281  void localToDetector(const Double_t local[3], Double_t det[3]) const
282  { return data().localToDetector(local, det); }
283 
285  void worldToLocal(const Position& global, Position& local) const
286  { return data().worldToLocal(global, local); }
288  void worldToLocal(const Double_t global[3], Double_t local[3]) const
289  { return data().worldToLocal(global, local); }
290 
292  void detectorToLocal(const Position& det, Position& local) const
293  { return data().detectorToLocal(det, local); }
295  void detectorToLocal(const Double_t det[3], Double_t local[3]) const
296  { return data().detectorToLocal(det, local); }
297 
299  const Alignment& nominal() const
300  { return data().detector.ideal(); }
302  const Delta& delta() const
303  { return data().delta; }
304 
306  void setDelta(const Delta& del) {
307  AlignmentData& d = data();
308  d.delta = del;
309  }
311  void setDelta(const Position& translation) {
312  AlignmentData& d = data();
313  d.delta.translation = translation;
315  }
317  void setDelta(const RotationZYX& rotation) {
318  AlignmentData& d = data();
319  d.delta.rotation = rotation;
321  }
323  void setDelta(const Position& translation, RotationZYX& rotation) {
324  AlignmentData& d = data();
325  d.delta.rotation = rotation;
326  d.delta.translation = translation;
329  }
331  void setDeltaPivot(const Translation3D& pivot, const RotationZYX& rotation) {
332  AlignmentData& d = data();
333  d.delta.pivot = pivot;
334  d.delta.rotation = rotation;
337  }
339  void setDeltaPivot(const Position& translation, const Translation3D& pivot, const RotationZYX& rotation) {
340  AlignmentData& d = data();
341  d.delta.pivot = pivot;
342  d.delta.rotation = rotation;
343  d.delta.translation = translation;
347  }
348  };
349 
351  template <typename T> inline
353 
355  template <typename T> inline
357 
358 
359  } /* End namespace Aligments */
360 } /* End namespace DD4hep */
361 #endif /* DD4HEP_ALIGMENTS_ALIGNMENTDATA_H */
PlacedVolume placement() const
Access the placement of this node.
bool hasRotation() const
Access flags: Check if the delta operation contains a rotation.
Definition: AlignmentData.h:96
AlignmentData::NodeList NodeList
Forward definition of the nodelist leading to the world.
BitMask flag
Flag to remember internally calculated quatities.
AlignmentDecorator(Q q)
Special constructors.
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:135
TGeoHMatrix detectorTrafo
Intermediate buffer to store the transformation to the parent detector element.
Position detectorToLocal(const Double_t det[3]) const
Transformation from detector element coordinates to the local placed volume coordinates.
Delta(const Position &tr, const Translation3D &piv, const RotationZYX &rot)
Initializing constructor.
Definition: AlignmentData.h:79
Ref_t condition
Reference to the original condition object (May not be present!)
Position localToWorld(const Double_t local[3]) const
Transformation from local coordinates of the placed volume to the world system.
void detectorToLocal(const Position &detector, Position &local) const
Transformation from detector element coordinates to the local placed volume coordinates.
~AlignmentDecorator()
Default destructor.
const TGeoHMatrix & detectorTransformation() const
Create cached matrix to transform to detector coordinates.
TGeoHMatrix worldDelta
Delta transformation to the world coordination system.
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
unsigned int BitMask
Forward declaration of the utility bit mask.
ReferenceBitMask< BitMask > MaskManipulator
Forward declaration of the utility mask manipulator.
bool hasPivot() const
Access flags: Check if the delta operation contains a pivot.
Definition: AlignmentData.h:98
bool checkFlag(unsigned int mask) const
Check a given flag.
Definition: AlignmentData.h:90
void worldToLocal(const Position &global, Position &local) const
Transformation from world coordinates of the local placed volume coordinates.
Delta()=default
Default constructor.
AlignmentData()
Standard constructor.
void clear()
Reset information to identity.
void setFlag(unsigned int mask)
Check a given flag.
Definition: AlignmentData.h:92
AlignmentData & operator=(const AlignmentData &copy)
Assignment operator necessary due to copy constructor.
Main handle class to hold an alignment object.
Definition: Alignments.h:65
void worldToLocal(const Double_t global[3], Double_t local[3]) const
Transformation from world coordinates of the local placed volume coordinates.
Alignments::Delta Delta
Forward definition of the alignment delta data.
DetElement detector() const
Access to the DetElement node.
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
NodeList nodes
The list of TGeoNodes (physical placements)
Alignment nominal() const
Access the ideal/nominal alignment/placement matrix.
Data structure to manipulate a bitmask held by reference and represented by an integer.
Definition: Primitives.h:526
Delta(const Position &tr, const RotationZYX &rot)
Initializing constructor.
Definition: AlignmentData.h:73
DD4hep::Geometry::DetElement DetElement
void setDelta(const Delta &del)
Set the delta alignment information.
void worldToLocal(const Position &global, Position &local) const
Transformation from world coordinates of the local placed volume coordinates.
DetElement detector
Reference to the next hosting detector element.
void localToDetector(const Double_t local[3], Double_t det[3]) const
Transformation from local coordinates of the placed volume to the detector system.
Position localToDetector(const Double_t local[3]) const
Transformation from local coordinates of the placed volume to the world system.
unsigned int magic
Magic word to verify object if necessary.
ROOT::Math::RotationZYX RotationZYX
Definition: Objects.h:98
Delta delta
Alignment changes.
std::vector< PlacedVolume > NodeList
Forward definition of the nodelist leading to the world.
void setDeltaPivot(const Translation3D &pivot, const RotationZYX &rotation)
Set the delta alignment if only a single rotation around a pivot point.
const TGeoHMatrix & worldTransformation() const
Create cached matrix to transform to world coordinates.
const Alignment & nominal() const
Access the currently applied alignment/placement matrix (mother to daughter)
const Transform3D & localToWorld() const
Access the currently applied alignment/placement matrix.
Delta(const Translation3D &piv, const RotationZYX &rot)
Initializing constructor.
Definition: AlignmentData.h:76
const TGeoHMatrix & detectorTransformation() const
Access the alignment/placement matrix with respect to the world.
void setDelta(const RotationZYX &rotation)
Set the delta alignment if only a single rotation.
Class describing an condition to re-adjust an alignment.
Definition: AlignmentData.h:49
ROOT::Math::XYZVector Position
Definition: Objects.h:75
void localToDetector(const Position &local, Position &det) const
Transformation from local coordinates of the placed volume to the detector system.
void localToWorld(const Double_t local[3], Double_t global[3]) const
Transformation from local coordinates of the placed volume to the world system.
AlignmentData::Delta Delta
Forward definition of the alignment delta data.
const Transform3D & localToWorld() const
Access the alignment/placement matrix with respect to the world.
void setDelta(const Position &translation, RotationZYX &rotation)
Set the delta alignment as a composite of a translation and a rotation.
Geometry::PlacedVolume PlacedVolume
Forward definition of the geometry placement.
const AlignmentData & data() const
Data accessor.
Delta(const RotationZYX &rot)
Initializing constructor.
Definition: AlignmentData.h:70
void setDelta(const Position &translation)
Set the delta alignment if only a single translation.
ROOT::Math::Translation3D Translation3D
Definition: Objects.h:112
void localToWorld(const Position &local, Position &global) const
Transformation from local coordinates of the placed volume to the world system.
Delta(const Position &tr)
Initializing constructor.
Definition: AlignmentData.h:67
const Delta & delta() const
Access the currently applied correction matrix (delta) (mother to daughter)
Transform3D trToWorld
Transformation from volume to the world.
AlignmentData::PlacedVolume PlacedVolume
Forward definition of the geometry placement.
PlacedVolume detectorPlacement() const
Access the placement of the DetElement node.
void detectorToLocal(const Position &det, Position &local) const
Transformation from world coordinates of the local placed volume coordinates.
AlignmentDecorator()
Default constructor.
ROOT::Math::Transform3D Transform3D
Definition: Objects.h:110
AlignmentData & data()
Data accessor for decorator.
const TGeoHMatrix & worldTransformation() const
Create cached matrix to transform to world coordinates.
bool hasTranslation() const
Access flags: Check if the delta operation contains a translation.
Definition: AlignmentData.h:94
bool hasCondition() const
Accessor if a conditions object is behind.
PlacedVolume placement
The subdetector placement corresponding to the actual detector element's volume.
void detectorToLocal(const Double_t det[3], Double_t local[3]) const
Transformation from world coordinates of the local placed volume coordinates.
Derived condition data-object definition.
void localToDetector(const Position &local, Position &detector) const
Transformation from local coordinates of the placed volume to the detector system.
Position worldToLocal(const Double_t global[3]) const
Transformation from local coordinates of the placed volume to the world system.
void setDeltaPivot(const Position &translation, const Translation3D &pivot, const RotationZYX &rotation)
Set the delta alignment if a translation and a rotation around pivot.
TGeoHMatrix worldTrafo
Intermediate buffer to store the transformation to the world coordination system. ...
Delta & operator=(const Delta &c)
Assignment operator.
~Delta()
Default destructor.
virtual ~AlignmentData()
Default destructor.