DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
AlignmentTools.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/IOV.h>
16 #include <DD4hep/Printout.h>
17 #include <DD4hep/MatrixHelpers.h>
18 #include <DD4hep/AlignmentTools.h>
19 #include <DD4hep/DetectorTools.h>
22 
23 // ROOT include files
24 #include <TGeoMatrix.h>
25 
27 using dd4hep::Alignment;
29 
30 namespace {
31  void reset_matrix(TGeoHMatrix* m) {
32  double tr[3] = {0e0,0e0,0e0};
33  double rot[9] = {1e0,0e0,0e0,
34  0e0,1e0,0e0,
35  0e0,0e0,1e0};
36  m->SetTranslation(tr);
37  m->SetRotation(rot);
38  }
39 
40 }
41 
44  const AlignmentData& f = from.ptr()->values();
45  AlignmentData& t = to.ptr()->values();
46  if ( &t != &f ) {
47  t.flag = f.flag;
49  t.worldTrafo = f.worldTrafo;
50  t.trToWorld = f.trToWorld;
51  t.detector = f.detector;
52  t.placement = f.placement;
53  t.nodes = f.nodes;
54  t.delta = f.delta;
55  t.magic = f.magic;
56  }
57 }
58 
61  AlignmentData& a = alignment->values();
62  ReferenceBitMask<AlignmentData::BitMask> mask(a.flag);
63  DetElement parent = a.detector.parent();
64  reset_matrix(&a.detectorTrafo);
65  if ( parent.isValid() ) {
67  detail::tools::placementPath(parent, a.detector, path);
68 
69  for (size_t i = 0, n=path.size(); n>0 && i < n-1; ++i) {
70  const PlacedVolume& p = path[i];
71  a.detectorTrafo.MultiplyLeft(p->GetMatrix());
72  a.nodes.emplace_back(p);
73  }
74  //a.worldTrafo = parent.nominal()->worldTrafo;
75  //a.worldTrafo.MultiplyLeft(&a.detectorTrafo);
77  a.worldTrafo.MultiplyLeft(&parent.nominal().worldTransformation());
80  mask.clear();
81  mask.set(AlignmentData::HAVE_PARENT_TRAFO);
82  mask.set(AlignmentData::HAVE_WORLD_TRAFO);
83  mask.set(AlignmentData::IDEAL);
84  }
85  else {
86  reset_matrix(&a.worldTrafo);
87  }
88 }
89 #if 0
92  const Alignment::NodeList& node_list)
93 {
94  AlignmentData& a = alignment->values();
95  ReferenceBitMask<AlignmentData::BitMask> mask(a.flag);
96  a.nodes = node_list;
97  for (size_t i = a.nodes.size(); i > 1; --i) { // Omit the placement of the parent DetElement
98  TGeoMatrix* m = a.nodes[i - 1]->GetMatrix();
99  a.worldTrafo.MultiplyLeft(m);
100  }
102  if ( !a.nodes.empty() ) {
104  a.detectorTrafo.MultiplyLeft(a.nodes[0]->GetMatrix());
105  a.placement = node_list.back();
106  }
107  else {
108  a.placement = det->placement;
109  }
110  a.worldTrafo.MultiplyLeft(&(a.detector.nominal().worldTransformation()));
112  mask.set(AlignmentData::IDEAL);
113 }
114 #endif
115 
118 {
119  AlignmentData& a = alignment->values();
120  DetElement parent = a.detector.parent();
121  ReferenceBitMask<AlignmentData::BitMask> mask(a.flag);
122 
123  if ( parent.isValid() ) {
125  detail::tools::placementPath(parent, a.detector, path);
126 
127  // TODO: need to take survey corrections into account!
128 
129  for (size_t i = 0, n=path.size(); n>0 && i < n-1; ++i) {
130  const PlacedVolume& p = path[i];
131  a.detectorTrafo.MultiplyLeft(p->GetMatrix());
132  }
133  a.worldTrafo = parent.survey().worldTransformation();
134  a.worldTrafo.MultiplyLeft(&a.detectorTrafo);
136  a.placement = a.detector.placement();
137  }
138  mask.set(AlignmentData::SURVEY);
139  //mask.clear(AlignmentData::INVALID|AlignmentData::DIRTY);
140  //mask.set(AlignmentData::VALID|AlignmentData::IDEAL);
141 }
dd4hep::AlignmentData::nodes
std::vector< PlacedVolume > nodes
The list of TGeoNodes (physical placements)
Definition: AlignmentData.h:122
dd4hep::DetElement::parent
DetElement parent() const
Access to the detector elements's parent.
Definition: DetElement.cpp:239
MatrixHelpers.h
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:163
IOV.h
dd4hep::AlignmentData::placement
PlacedVolume placement
The subdetector placement corresponding to the actual detector element's volume.
Definition: AlignmentData.h:128
dd4hep::DetElement::placement
PlacedVolume placement() const
Access to the physical volume of this detector element.
Definition: DetElement.cpp:321
dd4hep::AlignmentData::detector
DetElement detector
Reference to the next hosting detector element.
Definition: AlignmentData.h:126
dd4hep::detail::tools::placementPath
std::string placementPath(DetElement element)
Assemble the placement path from a given detector element to the world volume.
Definition: DetectorTools.cpp:276
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
DetectorInterna.h
dd4hep::detail::matrix::_transform
TGeoHMatrix * _transform(const Transform3D &trans)
Convert a Transform3D object to a newly created TGeoHMatrix.
Definition: MatrixHelpers.cpp:140
dd4hep::detail::AlignmentObject::values
AlignmentData & values()
Accessor to the alignment data. Cannot be NULL. Initialized in the constructor(s)
Definition: AlignmentsInterna.h:75
dd4hep::DetElementObject
Data class with properties of a detector element.
Definition: DetectorInterna.h:81
dd4hep::Handle::clear
Handle< T > & clear()
Release the object held by the handle.
Definition: Handle.h:136
AlignmentTools.h
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::AlignmentData::magic
unsigned int magic
Magic word to verify object if necessary.
Definition: AlignmentData.h:132
dd4hep::Alignment::worldTransformation
const TGeoHMatrix & worldTransformation() const
Create cached matrix to transform to world coordinates.
Definition: Alignments.cpp:68
DetectorTools.h
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::detail::tools::computeSurvey
void computeSurvey(Alignment alignment)
Compute the ideal/nominal to-world transformation from the detector element placement.
Definition: AlignmentTools.cpp:117
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:185
dd4hep::AlignmentData::detectorTrafo
TGeoHMatrix detectorTrafo
Intermediate buffer to store the transformation to the parent detector element.
Definition: AlignmentData.h:120
dd4hep::AlignmentData::worldTrafo
TGeoHMatrix worldTrafo
Intermediate buffer to store the transformation to the world coordination system.
Definition: AlignmentData.h:118
dd4hep::detail::tools::computeIdeal
void computeIdeal(Alignment alignment)
Compute the ideal/nominal to-world transformation from the detector element placement.
Definition: AlignmentTools.cpp:60
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::detail::tools::PlacementPath
std::vector< PlacedVolume > PlacementPath
Definition: DetectorTools.h:39
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
AlignmentsInterna.h
dd4hep::DetElement::survey
Alignment survey() const
Access to the constant survey alignment information.
Definition: DetElement.cpp:198
Printout.h