File indexing completed on 2025-01-18 09:13:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/IOV.h>
0016 #include <DD4hep/Printout.h>
0017 #include <DD4hep/MatrixHelpers.h>
0018 #include <DD4hep/AlignmentTools.h>
0019 #include <DD4hep/DetectorTools.h>
0020 #include <DD4hep/detail/DetectorInterna.h>
0021 #include <DD4hep/detail/AlignmentsInterna.h>
0022
0023
0024 #include <TGeoMatrix.h>
0025
0026 using dd4hep::PlacedVolume;
0027 using dd4hep::Alignment;
0028 using dd4hep::AlignmentData;
0029
0030 namespace {
0031 void reset_matrix(TGeoHMatrix* m) {
0032 double tr[3] = {0e0,0e0,0e0};
0033 double rot[9] = {1e0,0e0,0e0,
0034 0e0,1e0,0e0,
0035 0e0,0e0,1e0};
0036 m->SetTranslation(tr);
0037 m->SetRotation(rot);
0038 }
0039
0040 }
0041
0042
0043 void dd4hep::detail::tools::copy(Alignment from, Alignment to) {
0044 const AlignmentData& f = from.ptr()->values();
0045 AlignmentData& t = to.ptr()->values();
0046 if ( &t != &f ) {
0047 t.flag = f.flag;
0048 t.detectorTrafo = f.detectorTrafo;
0049 t.worldTrafo = f.worldTrafo;
0050 t.trToWorld = f.trToWorld;
0051 t.detector = f.detector;
0052 t.placement = f.placement;
0053 t.nodes = f.nodes;
0054 t.delta = f.delta;
0055 t.magic = f.magic;
0056 }
0057 }
0058
0059
0060 void dd4hep::detail::tools::computeIdeal(Alignment alignment) {
0061 AlignmentData& a = alignment->values();
0062 ReferenceBitMask<AlignmentData::BitMask> mask(a.flag);
0063 DetElement parent = a.detector.parent();
0064 reset_matrix(&a.detectorTrafo);
0065 if ( parent.isValid() ) {
0066 detail::tools::PlacementPath path;
0067 detail::tools::placementPath(parent, a.detector, path);
0068
0069 for (size_t i = 0, n=path.size(); n>0 && i < n-1; ++i) {
0070 const PlacedVolume& p = path[i];
0071 a.detectorTrafo.MultiplyLeft(p->GetMatrix());
0072 a.nodes.emplace_back(p);
0073 }
0074
0075
0076 a.worldTrafo = a.detectorTrafo;
0077 a.worldTrafo.MultiplyLeft(&parent.nominal().worldTransformation());
0078 a.trToWorld = detail::matrix::_transform(&a.worldTrafo);
0079 a.placement = a.detector.placement();
0080 mask.clear();
0081 mask.set(AlignmentData::HAVE_PARENT_TRAFO);
0082 mask.set(AlignmentData::HAVE_WORLD_TRAFO);
0083 mask.set(AlignmentData::IDEAL);
0084 }
0085 else {
0086 reset_matrix(&a.worldTrafo);
0087 }
0088 }
0089 #if 0
0090
0091 void dd4hep::detail::tools::computeIdeal(Alignment alignment,
0092 const Alignment::NodeList& node_list)
0093 {
0094 AlignmentData& a = alignment->values();
0095 ReferenceBitMask<AlignmentData::BitMask> mask(a.flag);
0096 a.nodes = node_list;
0097 for (size_t i = a.nodes.size(); i > 1; --i) {
0098 TGeoMatrix* m = a.nodes[i - 1]->GetMatrix();
0099 a.worldTrafo.MultiplyLeft(m);
0100 }
0101 DetElement::Object* det = a.detector.ptr();
0102 if ( !a.nodes.empty() ) {
0103 a.detectorTrafo = a.worldTrafo;
0104 a.detectorTrafo.MultiplyLeft(a.nodes[0]->GetMatrix());
0105 a.placement = node_list.back();
0106 }
0107 else {
0108 a.placement = det->placement;
0109 }
0110 a.worldTrafo.MultiplyLeft(&(a.detector.nominal().worldTransformation()));
0111 a.trToWorld = detail::matrix::_transform(&a.worldTrafo);
0112 mask.set(AlignmentData::IDEAL);
0113 }
0114 #endif
0115
0116
0117 void dd4hep::detail::tools::computeSurvey(Alignment alignment)
0118 {
0119 AlignmentData& a = alignment->values();
0120 DetElement parent = a.detector.parent();
0121 ReferenceBitMask<AlignmentData::BitMask> mask(a.flag);
0122
0123 if ( parent.isValid() ) {
0124 detail::tools::PlacementPath path;
0125 detail::tools::placementPath(parent, a.detector, path);
0126
0127
0128
0129 for (size_t i = 0, n=path.size(); n>0 && i < n-1; ++i) {
0130 const PlacedVolume& p = path[i];
0131 a.detectorTrafo.MultiplyLeft(p->GetMatrix());
0132 }
0133 a.worldTrafo = parent.survey().worldTransformation();
0134 a.worldTrafo.MultiplyLeft(&a.detectorTrafo);
0135 a.trToWorld = detail::matrix::_transform(&a.worldTrafo);
0136 a.placement = a.detector.placement();
0137 }
0138 mask.set(AlignmentData::SURVEY);
0139
0140
0141 }