File indexing completed on 2025-12-16 09:26:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/AlignmentData.h>
0016 #include <DD4hep/MatrixHelpers.h>
0017 #include <DD4hep/InstanceCount.h>
0018 #include <DD4hep/DetElement.h>
0019 #include <DD4hep/OpaqueData.h>
0020 #include <DD4hep/Primitives.h>
0021
0022
0023 #include <TGeoMatrix.h>
0024
0025
0026 #include <sstream>
0027
0028 using namespace dd4hep;
0029
0030
0031 Delta::Delta(const Delta& c)
0032 : translation(c.translation), pivot(c.pivot), rotation(c.rotation), flags(c.flags)
0033 {
0034 }
0035
0036
0037 Delta::~Delta() {
0038 }
0039
0040
0041 Delta& Delta::operator=(const Delta& c) {
0042 if ( &c != this ) {
0043 pivot = c.pivot;
0044 translation = c.translation;
0045 rotation = c.rotation;
0046 flags = c.flags;
0047 }
0048 return *this;
0049 }
0050
0051
0052 void Delta::clear() {
0053 flags = 0;
0054 pivot = Pivot();
0055 translation = Position();
0056 rotation = RotationZYX();
0057 }
0058
0059
0060 void Delta::computeMatrix(TGeoHMatrix& tr_delta) const {
0061 const Delta& delta = *this;
0062 const Position& pos = delta.translation;
0063 const Translation3D& piv = delta.pivot;
0064 const RotationZYX& rot = delta.rotation;
0065
0066 switch(delta.flags) {
0067 case Delta::HAVE_TRANSLATION+Delta::HAVE_ROTATION+Delta::HAVE_PIVOT:
0068 detail::matrix::_transform(tr_delta, Transform3D(Translation3D(pos)*piv*rot*(piv.Inverse())));
0069 break;
0070 case Delta::HAVE_TRANSLATION+Delta::HAVE_ROTATION:
0071 detail::matrix::_transform(tr_delta, Transform3D(rot,pos));
0072 break;
0073 case Delta::HAVE_ROTATION+Delta::HAVE_PIVOT:
0074 detail::matrix::_transform(tr_delta, Transform3D(piv*rot*(piv.Inverse())));
0075 break;
0076 case Delta::HAVE_ROTATION:
0077 detail::matrix::_transform(tr_delta, rot);
0078 break;
0079 case Delta::HAVE_TRANSLATION:
0080 detail::matrix::_transform(tr_delta, pos);
0081 break;
0082 default:
0083 break;
0084 }
0085 }
0086
0087
0088 std::ostream& operator << (std::ostream& ostr, const Delta& data) {
0089 std::string res;
0090 std::stringstream str;
0091 str << "[" << data.translation << "," << data.rotation << "," << data.pivot << "]";
0092 res = str.str();
0093 for(std::size_t i=0; i<res.length(); ++i)
0094 if ( res[i]=='\n' ) res[i] = ' ';
0095 return ostr << res;
0096 }
0097
0098
0099 AlignmentData::AlignmentData()
0100 : flag(0), magic(magic_word())
0101 {
0102 InstanceCount::increment(this);
0103 }
0104
0105
0106 AlignmentData::AlignmentData(const AlignmentData& copy)
0107 : delta(copy.delta), worldTrafo(copy.worldTrafo),
0108 detectorTrafo(copy.detectorTrafo),
0109 nodes(copy.nodes), trToWorld(copy.trToWorld), detector(copy.detector),
0110 placement(copy.placement), flag(copy.flag), magic(magic_word())
0111 {
0112 InstanceCount::increment(this);
0113 }
0114
0115
0116 AlignmentData::~AlignmentData() {
0117 InstanceCount::decrement(this);
0118 }
0119
0120
0121 AlignmentData& AlignmentData::operator=(const AlignmentData& copy) {
0122 if ( this != © ) {
0123 delta = copy.delta;
0124 detectorTrafo = copy.detectorTrafo;
0125 nodes = copy.nodes;
0126 trToWorld = copy.trToWorld;
0127 detector = copy.detector;
0128 placement = copy.placement;
0129 flag = copy.flag;
0130 }
0131 return *this;
0132 }
0133
0134
0135 std::ostream& operator << (std::ostream& ostr, const AlignmentData& data) {
0136 std::stringstream str;
0137 str << data.delta;
0138 return ostr << str.str();
0139 }
0140
0141
0142 Position AlignmentData::localToWorld(const Position& local) const {
0143 Position global;
0144 Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
0145 worldTrafo.LocalToMaster(local_point, master_point);
0146 global.SetCoordinates(master_point);
0147 return global;
0148 }
0149
0150
0151 void AlignmentData::localToWorld(const Position& local, Position& global) const {
0152 Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
0153 worldTrafo.LocalToMaster(local_point, master_point);
0154 global.SetCoordinates(master_point);
0155 }
0156
0157
0158 void AlignmentData::localToWorld(const Double_t local[3], Double_t global[3]) const {
0159 worldTrafo.LocalToMaster(local, global);
0160 }
0161
0162
0163 Position AlignmentData::worldToLocal(const Position& global) const {
0164 Position local;
0165
0166 Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
0167 worldTrafo.MasterToLocal(master_point, local_point);
0168 local.SetCoordinates(local_point);
0169 return local;
0170 }
0171
0172
0173 void AlignmentData::worldToLocal(const Position& global, Position& local) const {
0174 Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
0175 worldTrafo.MasterToLocal(master_point, local_point);
0176 local.SetCoordinates(local_point);
0177 }
0178
0179
0180 void AlignmentData::worldToLocal(const Double_t global[3], Double_t local[3]) const {
0181 worldTrafo.MasterToLocal(global, local);
0182 }
0183
0184
0185 Position AlignmentData::localToDetector(const Position& local) const {
0186 Position global;
0187 Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
0188 detectorTrafo.LocalToMaster(local_point, master_point);
0189 global.SetCoordinates(master_point);
0190 return global;
0191 }
0192
0193
0194 void AlignmentData::localToDetector(const Position& local, Position& global) const {
0195 Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
0196 detectorTrafo.LocalToMaster(local_point, master_point);
0197 global.SetCoordinates(master_point);
0198 }
0199
0200
0201 void AlignmentData::localToDetector(const Double_t local[3], Double_t global[3]) const {
0202 detectorTrafo.LocalToMaster(local, global);
0203 }
0204
0205
0206 Position AlignmentData::detectorToLocal(const Position& global) const {
0207 Position local;
0208
0209 Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
0210 detectorTrafo.MasterToLocal(master_point, local_point);
0211 local.SetCoordinates(local_point);
0212 return local;
0213 }
0214
0215
0216 void AlignmentData::detectorToLocal(const Position& global, Position& local) const {
0217
0218 Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
0219 detectorTrafo.MasterToLocal(master_point, local_point);
0220 local.SetCoordinates(local_point);
0221 }
0222
0223
0224 void AlignmentData::detectorToLocal(const Double_t global[3], Double_t local[3]) const {
0225 detectorTrafo.MasterToLocal(global, local);
0226 }
0227
0228
0229 Alignment AlignmentData::nominal() const {
0230 return detector.nominal();
0231 }
0232
0233 #include <DD4hep/GrammarUnparsed.h>
0234 static auto s_registry = GrammarRegistry::pre_note<Delta>(1)
0235 .pre_note<AlignmentData>(1)
0236 .pre_note<std::map<DetElement, Delta> >(1);