File indexing completed on 2025-01-30 10:04:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DD4HEP_ALIGNMENTDATA_H
0014 #define DD4HEP_ALIGNMENTDATA_H
0015
0016
0017 #include <DD4hep/NamedObject.h>
0018 #include <DD4hep/DetElement.h>
0019 #include <DD4hep/Volumes.h>
0020
0021
0022 #include <TGeoMatrix.h>
0023
0024
0025 namespace dd4hep {
0026
0027
0028 class Alignment;
0029 class AlignmentCondition;
0030
0031
0032
0033
0034
0035
0036
0037
0038 class Delta {
0039 public:
0040 typedef Translation3D Pivot;
0041 Position translation;
0042 Pivot pivot;
0043 RotationZYX rotation;
0044 unsigned int flags = 0;
0045
0046 enum AlignmentFlags {
0047 HAVE_NONE = 0,
0048 HAVE_TRANSLATION = 1<<2,
0049 HAVE_ROTATION = 1<<3,
0050 HAVE_PIVOT = 1<<4,
0051 };
0052
0053
0054 Delta() = default;
0055
0056 Delta(const Position& tr)
0057 : translation(tr), flags(HAVE_TRANSLATION) {}
0058
0059 Delta(const RotationZYX& rot)
0060 : translation(), rotation(rot), flags(HAVE_ROTATION) {}
0061
0062 Delta(const Position& tr, const RotationZYX& rot)
0063 : translation(tr), rotation(rot), flags(HAVE_ROTATION|HAVE_TRANSLATION) {}
0064
0065 Delta(const Translation3D& piv, const RotationZYX& rot)
0066 : pivot(piv), rotation(rot), flags(HAVE_ROTATION|HAVE_PIVOT) {}
0067
0068 Delta(const Position& tr, const Translation3D& piv, const RotationZYX& rot)
0069 : translation(tr), pivot(piv), rotation(rot), flags(HAVE_ROTATION|HAVE_PIVOT|HAVE_TRANSLATION) {}
0070
0071 Delta(const Delta& c);
0072
0073 ~Delta();
0074
0075 Delta& operator=(const Delta& c);
0076
0077 void clear();
0078
0079 bool checkFlag(unsigned int mask) const { return (flags&mask) == mask; }
0080
0081 void setFlag(unsigned int mask) { flags |= mask; }
0082
0083 bool hasTranslation() const { return checkFlag(HAVE_TRANSLATION); }
0084
0085 bool hasRotation() const { return checkFlag(HAVE_ROTATION); }
0086
0087 bool hasPivot() const { return checkFlag(HAVE_PIVOT); }
0088
0089 void computeMatrix(TGeoHMatrix& tr_delta) const;
0090 };
0091
0092
0093
0094
0095
0096
0097
0098 class AlignmentData {
0099 public:
0100
0101 typedef unsigned int BitMask;
0102
0103 enum AlignmentFlags {
0104 HAVE_NONE = 0,
0105 HAVE_WORLD_TRAFO = 1<<0,
0106 HAVE_PARENT_TRAFO = 1<<1,
0107 HAVE_OTHER = 1<<31
0108 };
0109 enum DataType {
0110 IDEAL = 1<<10,
0111 SURVEY = 1<<11,
0112 TIME_STAMPED = 1<<12
0113 };
0114
0115
0116 Delta delta;
0117
0118 mutable TGeoHMatrix worldTrafo;
0119
0120 mutable TGeoHMatrix detectorTrafo;
0121
0122 std::vector<PlacedVolume> nodes;
0123
0124 Transform3D trToWorld;
0125
0126 DetElement detector;
0127
0128 PlacedVolume placement;
0129
0130 mutable BitMask flag;
0131
0132 unsigned int magic;
0133
0134 public:
0135
0136 AlignmentData();
0137
0138 AlignmentData(const AlignmentData& copy);
0139
0140 virtual ~AlignmentData();
0141
0142 AlignmentData& operator=(const AlignmentData& copy);
0143
0144 inline AlignmentData& data() { return *this; }
0145
0146 Alignment nominal() const;
0147
0148 const TGeoHMatrix& worldTransformation() const { return worldTrafo; }
0149
0150 const TGeoHMatrix& detectorTransformation() const { return detectorTrafo; }
0151
0152 const Transform3D& localToWorld() const { return trToWorld; }
0153
0154
0155
0156 void localToWorld(const Position& local, Position& global) const;
0157
0158 void localToWorld(const Double_t local[3], Double_t global[3]) const;
0159
0160 Position localToWorld(const Position& local) const;
0161
0162 Position localToWorld(const Double_t local[3]) const
0163 { return localToWorld({local[0],local[1],local[2]}); }
0164
0165
0166
0167 void worldToLocal(const Position& global, Position& local) const;
0168
0169 void worldToLocal(const Double_t global[3], Double_t local[3]) const;
0170
0171 Position worldToLocal(const Position& global) const;
0172
0173 Position worldToLocal(const Double_t global[3]) const
0174 { return worldToLocal({global[0],global[1],global[2]}); }
0175
0176
0177
0178 void localToDetector(const Position& local, Position& detector) const;
0179
0180 void localToDetector(const Double_t local[3], Double_t detector[3]) const;
0181
0182 Position localToDetector(const Position& local) const;
0183
0184 Position localToDetector(const Double_t local[3]) const
0185 { return localToDetector({local[0],local[1],local[2]}); }
0186
0187
0188
0189 void detectorToLocal(const Position& detector, Position& local) const;
0190
0191 void detectorToLocal(const Double_t detector[3], Double_t local[3]) const;
0192
0193 Position detectorToLocal(const Position& detector) const;
0194
0195 Position detectorToLocal(const Double_t det[3]) const
0196 { return detectorToLocal({det[0],det[1],det[2]}); }
0197 };
0198 }
0199 std::ostream& operator << (std::ostream& s, const dd4hep::Delta& data);
0200 std::ostream& operator << (std::ostream& s, const dd4hep::AlignmentData& data);
0201 #endif