DD4hep  1.28.0
Detector Description Toolkit for High Energy Physics
AlignmentData.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
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 // Framework include files
15 #include <DD4hep/AlignmentData.h>
16 #include <DD4hep/MatrixHelpers.h>
17 #include <DD4hep/InstanceCount.h>
18 #include <DD4hep/DetElement.h>
19 #include <DD4hep/OpaqueData.h>
20 #include <DD4hep/Primitives.h>
21 
22 // ROOT include files
23 #include <TGeoMatrix.h>
24 
25 // C/C++ include files
26 #include <sstream>
27 
28 using namespace dd4hep;
29 
32  : translation(c.translation), pivot(c.pivot), rotation(c.rotation), flags(c.flags)
33 {
34 }
35 
38 }
39 
42  if ( &c != this ) {
43  pivot = c.pivot;
45  rotation = c.rotation;
46  flags = c.flags;
47  }
48  return *this;
49 }
50 
52 void Delta::clear() {
53  flags = 0;
54  pivot = Pivot();
57 }
58 
60 void Delta::computeMatrix(TGeoHMatrix& tr_delta) const {
61  const Delta& delta = *this;
62  const Position& pos = delta.translation;
63  const Translation3D& piv = delta.pivot;
64  const RotationZYX& rot = delta.rotation;
65 
66  switch(delta.flags) {
68  detail::matrix::_transform(tr_delta, Transform3D(Translation3D(pos)*piv*rot*(piv.Inverse())));
69  break;
71  detail::matrix::_transform(tr_delta, Transform3D(rot,pos));
72  break;
74  detail::matrix::_transform(tr_delta, Transform3D(piv*rot*(piv.Inverse())));
75  break;
77  detail::matrix::_transform(tr_delta, rot);
78  break;
80  detail::matrix::_transform(tr_delta, pos);
81  break;
82  default:
83  break;
84  }
85 }
86 
88 std::ostream& operator << (std::ostream& ostr, const Delta& data) {
89  std::string res;
90  std::stringstream str;
91  str << "[" << data.translation << "," << data.rotation << "," << data.pivot << "]";
92  res = str.str();
93  for(std::size_t i=0; i<res.length(); ++i)
94  if ( res[i]=='\n' ) res[i] = ' ';
95  return ostr << res;
96 }
97 
100  : flag(0), magic(magic_word())
101 {
103 }
104 
107  : delta(copy.delta), worldTrafo(copy.worldTrafo),
108  detectorTrafo(copy.detectorTrafo),
109  nodes(copy.nodes), trToWorld(copy.trToWorld), detector(copy.detector),
110  placement(copy.placement), flag(copy.flag), magic(magic_word())
111 {
113 }
114 
118 }
119 
122  if ( this != &copy ) {
123  delta = copy.delta;
124  detectorTrafo = copy.detectorTrafo;
125  nodes = copy.nodes;
126  trToWorld = copy.trToWorld;
127  detector = copy.detector;
128  placement = copy.placement;
129  flag = copy.flag;
130  }
131  return *this;
132 }
133 
135 std::ostream& operator << (std::ostream& ostr, const AlignmentData& data) {
136  std::stringstream str;
137  str << data.delta;
138  return ostr << str.str();
139 }
140 
143  Position global;
144  Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
145  worldTrafo.LocalToMaster(local_point, master_point);
146  global.SetCoordinates(master_point);
147  return global;
148 }
149 
151 void AlignmentData::localToWorld(const Position& local, Position& global) const {
152  Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
153  worldTrafo.LocalToMaster(local_point, master_point);
154  global.SetCoordinates(master_point);
155 }
156 
158 void AlignmentData::localToWorld(const Double_t local[3], Double_t global[3]) const {
159  worldTrafo.LocalToMaster(local, global);
160 }
161 
164  Position local;
165  // If the path is unknown an exception will be thrown inside worldTransformation() !
166  Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
167  worldTrafo.MasterToLocal(master_point, local_point);
168  local.SetCoordinates(local_point);
169  return local;
170 }
171 
173 void AlignmentData::worldToLocal(const Position& global, Position& local) const {
174  Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
175  worldTrafo.MasterToLocal(master_point, local_point);
176  local.SetCoordinates(local_point);
177 }
178 
180 void AlignmentData::worldToLocal(const Double_t global[3], Double_t local[3]) const {
181  worldTrafo.MasterToLocal(global, local);
182 }
183 
186  Position global;
187  Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
188  detectorTrafo.LocalToMaster(local_point, master_point);
189  global.SetCoordinates(master_point);
190  return global;
191 }
192 
194 void AlignmentData::localToDetector(const Position& local, Position& global) const {
195  Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
196  detectorTrafo.LocalToMaster(local_point, master_point);
197  global.SetCoordinates(master_point);
198 }
199 
201 void AlignmentData::localToDetector(const Double_t local[3], Double_t global[3]) const {
202  detectorTrafo.LocalToMaster(local, global);
203 }
204 
207  Position local;
208  // If the path is unknown an exception will be thrown inside worldTransformation() !
209  Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
210  detectorTrafo.MasterToLocal(master_point, local_point);
211  local.SetCoordinates(local_point);
212  return local;
213 }
214 
216 void AlignmentData::detectorToLocal(const Position& global, Position& local) const {
217  // If the path is unknown an exception will be thrown inside worldTransformation() !
218  Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
219  detectorTrafo.MasterToLocal(master_point, local_point);
220  local.SetCoordinates(local_point);
221 }
222 
224 void AlignmentData::detectorToLocal(const Double_t global[3], Double_t local[3]) const {
225  detectorTrafo.MasterToLocal(global, local);
226 }
227 
230  return detector.nominal();
231 }
232 
233 #include <DD4hep/GrammarUnparsed.h>
234 static auto s_registry = GrammarRegistry::pre_note<Delta>(1)
235  .pre_note<AlignmentData>(1)
236  .pre_note<std::map<DetElement, Delta> >(1);
dd4hep::AlignmentData::nodes
std::vector< PlacedVolume > nodes
The list of TGeoNodes (physical placements)
Definition: AlignmentData.h:122
dd4hep::Delta::HAVE_TRANSLATION
@ HAVE_TRANSLATION
Definition: AlignmentData.h:48
dd4hep::AlignmentData::nominal
Alignment nominal() const
Access the ideal/nominal alignment/placement matrix.
Definition: AlignmentData.cpp:229
MatrixHelpers.h
dd4hep::Delta::clear
void clear()
Reset information to identity.
Definition: AlignmentData.cpp:52
dd4hep::Delta::HAVE_PIVOT
@ HAVE_PIVOT
Definition: AlignmentData.h:50
dd4hep::AlignmentData::AlignmentData
AlignmentData()
Standard constructor.
Definition: AlignmentData.cpp:99
dd4hep::AlignmentData::placement
PlacedVolume placement
The subdetector placement corresponding to the actual detector element's volume.
Definition: AlignmentData.h:128
dd4hep::Delta::HAVE_ROTATION
@ HAVE_ROTATION
Definition: AlignmentData.h:49
dd4hep::Delta::rotation
RotationZYX rotation
Definition: AlignmentData.h:43
dd4hep::AlignmentData::detector
DetElement detector
Reference to the next hosting detector element.
Definition: AlignmentData.h:126
delta
const Delta * delta
Definition: AlignmentsCalculator.cpp:67
dd4hep::AlignmentData::localToDetector
void localToDetector(const Position &local, Position &detector) const
Transformation from local coordinates of the placed volume to the detector system.
Definition: AlignmentData.cpp:194
dd4hep::Delta::flags
unsigned int flags
Definition: AlignmentData.h:44
dd4hep::detail::matrix::_transform
TGeoHMatrix * _transform(const Transform3D &trans)
Convert a Transform3D object to a newly created TGeoHMatrix.
Definition: MatrixHelpers.cpp:140
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::magic_word
unsigned long long int magic_word()
Access to the magic word, which is protecting some objects against memory corruptions.
Definition: Handle.h:53
dd4hep::operator<<
std::ostream & operator<<(std::ostream &os, const DetType &t)
Definition: DetType.h:99
dd4hep::Delta
Class describing an condition to re-adjust an alignment.
Definition: AlignmentData.h:38
dd4hep::Delta::Delta
Delta()=default
Default constructor.
dd4hep::Translation3D
ROOT::Math::Translation3D Translation3D
Definition: Objects.h:119
dd4hep::Delta::translation
Position translation
Definition: AlignmentData.h:41
dd4hep::AlignmentData::trToWorld
Transform3D trToWorld
Transformation from volume to the world.
Definition: AlignmentData.h:124
dd4hep::AlignmentData::delta
Delta delta
Alignment changes.
Definition: AlignmentData.h:116
dd4hep::Delta::pivot
Pivot pivot
Definition: AlignmentData.h:42
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::Delta::computeMatrix
void computeMatrix(TGeoHMatrix &tr_delta) const
Compute the alignment delta for one detector element and its alignment condition.
Definition: AlignmentData.cpp:60
dd4hep::AlignmentData::flag
BitMask flag
Flag to remember internally calculated quatities.
Definition: AlignmentData.h:130
dd4hep::Alignment
Main handle class to hold an alignment object.
Definition: Alignments.h:115
dd4hep::AlignmentData
Derived condition data-object definition.
Definition: AlignmentData.h:98
dd4hep::DetElement::nominal
Alignment nominal() const
Access to the constant ideal (nominal) alignment information.
Definition: DetElement.cpp:184
dd4hep::AlignmentData::localToWorld
const Transform3D & localToWorld() const
Access the currently applied alignment/placement matrix.
Definition: AlignmentData.h:152
dd4hep::AlignmentData::detectorTrafo
TGeoHMatrix detectorTrafo
Intermediate buffer to store the transformation to the parent detector element.
Definition: AlignmentData.h:120
GrammarUnparsed.h
OpaqueData.h
dd4hep::Transform3D
ROOT::Math::Transform3D Transform3D
Definition: Objects.h:117
dd4hep::AlignmentData::worldTrafo
TGeoHMatrix worldTrafo
Intermediate buffer to store the transformation to the world coordination system.
Definition: AlignmentData.h:118
dd4hep::AlignmentData::operator=
AlignmentData & operator=(const AlignmentData &copy)
Assignment operator necessary due to copy constructor.
Definition: AlignmentData.cpp:121
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
Primitives.h
dd4hep::AlignmentData::detectorToLocal
void detectorToLocal(const Position &detector, Position &local) const
Transformation from detector element coordinates to the local placed volume coordinates.
Definition: AlignmentData.cpp:216
DetElement.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Delta::~Delta
~Delta()
Default destructor.
Definition: AlignmentData.cpp:37
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::RotationZYX
ROOT::Math::RotationZYX RotationZYX
Definition: Objects.h:105
dd4hep::AlignmentData::worldToLocal
void worldToLocal(const Position &global, Position &local) const
Transformation from world coordinates of the local placed volume coordinates.
Definition: AlignmentData.cpp:173
dd4hep::Delta::Pivot
Translation3D Pivot
Definition: AlignmentData.h:40
InstanceCount.h
AlignmentData.h
dd4hep::AlignmentData::~AlignmentData
virtual ~AlignmentData()
Default destructor.
Definition: AlignmentData.cpp:116
dd4hep::Delta::operator=
Delta & operator=(const Delta &c)
Assignment operator.
Definition: AlignmentData.cpp:41