File indexing completed on 2026-09-25 09:29:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGeoMatrix
0013 #define ROOT_TGeoMatrix
0014
0015
0016
0017
0018
0019
0020
0021 #include "TNamed.h"
0022 #include "Math/Vector3D.h"
0023
0024
0025 const Double_t kNullVector[3] = {0.0, 0.0, 0.0};
0026
0027 const Double_t kIdentityMatrix[3 * 3] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
0028
0029 const Double_t kUnitScale[3] = {1.0, 1.0, 1.0};
0030
0031 class TGeoHMatrix;
0032
0033
0034
0035
0036
0037
0038
0039 class TGeoMatrix : public TNamed {
0040 public:
0041 enum EGeoTransfTypes {
0042 kGeoIdentity = 0,
0043 kGeoShared = BIT(14),
0044 kGeoTranslation = BIT(17),
0045 kGeoRotation = BIT(18),
0046 kGeoScale = BIT(19),
0047 kGeoReflection = BIT(20),
0048 kGeoRegistered = BIT(21),
0049 kGeoSavePrimitive = BIT(22),
0050 kGeoMatrixOwned = BIT(23),
0051 kGeoCombiTrans = kGeoTranslation | kGeoRotation,
0052 kGeoGenTrans = kGeoTranslation | kGeoRotation | kGeoScale,
0053 kGeoMatrixBits = kGeoShared | kGeoGenTrans | kGeoReflection | kGeoRegistered | kGeoSavePrimitive | kGeoMatrixOwned
0054 };
0055
0056 protected:
0057 TGeoMatrix(const TGeoMatrix &other);
0058
0059 public:
0060 TGeoMatrix();
0061 TGeoMatrix(const char *name);
0062 ~TGeoMatrix() override;
0063
0064 Bool_t IsIdentity() const { return !TestBit(kGeoGenTrans); }
0065 Bool_t IsTranslation() const { return TestBit(kGeoTranslation); }
0066 Bool_t IsRotation() const { return TestBit(kGeoRotation); }
0067 Bool_t IsReflection() const { return TestBit(kGeoReflection); }
0068 Bool_t IsScale() const { return TestBit(kGeoScale); }
0069 Bool_t IsShared() const { return TestBit(kGeoShared); }
0070 Bool_t IsOwned() const { return TestBit(kGeoMatrixOwned); }
0071 Bool_t IsCombi() const { return (TestBit(kGeoTranslation) && TestBit(kGeoRotation)); }
0072 Bool_t IsGeneral() const { return (TestBit(kGeoTranslation) && TestBit(kGeoRotation) && TestBit(kGeoScale)); }
0073 Bool_t IsRegistered() const { return TestBit(kGeoRegistered); }
0074 Bool_t IsRotAboutZ() const;
0075 void GetHomogenousMatrix(Double_t *hmat) const;
0076 const char *GetPointerName() const;
0077 void GetWorldAxes(ROOT::Math::XYZVector &ax, ROOT::Math::XYZVector &ay, ROOT::Math::XYZVector &az) const;
0078 virtual Int_t GetByteCount() const;
0079 virtual const Double_t *GetTranslation() const = 0;
0080 virtual const Double_t *GetRotationMatrix() const = 0;
0081 virtual const Double_t *GetScale() const = 0;
0082 virtual TGeoHMatrix Inverse() const = 0;
0083 virtual void LocalToMaster(const Double_t *local, Double_t *master) const;
0084 virtual void LocalToMasterVect(const Double_t *local, Double_t *master) const;
0085 virtual void LocalToMasterBomb(const Double_t *local, Double_t *master) const;
0086 virtual TGeoMatrix *MakeClone() const = 0;
0087 virtual void MasterToLocal(const Double_t *master, Double_t *local) const;
0088 virtual void MasterToLocalVect(const Double_t *master, Double_t *local) const;
0089 virtual void MasterToLocalBomb(const Double_t *master, Double_t *local) const;
0090 static void Normalize(Double_t *vect);
0091 void Print(Option_t *option = "") const override;
0092 virtual void RotateX(Double_t) {}
0093 virtual void RotateY(Double_t) {}
0094 virtual void RotateZ(Double_t) {}
0095 virtual void ReflectX(Bool_t leftside, Bool_t rotonly = kFALSE);
0096 virtual void ReflectY(Bool_t leftside, Bool_t rotonly = kFALSE);
0097 virtual void ReflectZ(Bool_t leftside, Bool_t rotonly = kFALSE);
0098 virtual void RegisterYourself();
0099 void SetDefaultName();
0100 virtual void SetDx(Double_t) {}
0101 virtual void SetDy(Double_t) {}
0102 virtual void SetDz(Double_t) {}
0103 void SetShared(Bool_t flag = kTRUE) { SetBit(kGeoShared, flag); }
0104
0105 ClassDefOverride(TGeoMatrix, 1)
0106 };
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 class TGeoTranslation : public TGeoMatrix {
0118 protected:
0119 Double_t fTranslation[3];
0120 public:
0121 TGeoTranslation();
0122 TGeoTranslation(const TGeoTranslation &other);
0123 TGeoTranslation(const TGeoMatrix &other);
0124 TGeoTranslation(Double_t dx, Double_t dy, Double_t dz);
0125 TGeoTranslation(const char *name, Double_t dx, Double_t dy, Double_t dz);
0126 ~TGeoTranslation() override {}
0127
0128 TGeoTranslation &operator=(const TGeoTranslation &other) { return TGeoTranslation::operator=((TGeoMatrix &)other); }
0129 TGeoTranslation &operator=(const TGeoMatrix &matrix);
0130 TGeoTranslation &operator*=(const TGeoTranslation &other);
0131 TGeoTranslation operator*(const TGeoTranslation &right) const;
0132 TGeoHMatrix operator*(const TGeoMatrix &right) const;
0133 Bool_t operator==(const TGeoTranslation &other) const;
0134
0135 void Add(const TGeoTranslation *other);
0136 TGeoHMatrix Inverse() const override;
0137 void LocalToMaster(const Double_t *local, Double_t *master) const override;
0138 void LocalToMasterVect(const Double_t *local, Double_t *master) const override;
0139 void LocalToMasterBomb(const Double_t *local, Double_t *master) const override;
0140 TGeoMatrix *MakeClone() const override;
0141 void MasterToLocal(const Double_t *master, Double_t *local) const override;
0142 void MasterToLocalVect(const Double_t *master, Double_t *local) const override;
0143 void MasterToLocalBomb(const Double_t *master, Double_t *local) const override;
0144 void RotateX(Double_t angle) override;
0145 void RotateY(Double_t angle) override;
0146 void RotateZ(Double_t angle) override;
0147 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0148 void Subtract(const TGeoTranslation *other);
0149 void SetTranslation(Double_t dx, Double_t dy, Double_t dz);
0150 void SetTranslation(const TGeoMatrix &other);
0151 void SetDx(Double_t dx) override { SetTranslation(dx, fTranslation[1], fTranslation[2]); }
0152 void SetDy(Double_t dy) override { SetTranslation(fTranslation[0], dy, fTranslation[2]); }
0153 void SetDz(Double_t dz) override { SetTranslation(fTranslation[0], fTranslation[1], dz); }
0154
0155 const Double_t *GetTranslation() const override { return &fTranslation[0]; }
0156 const Double_t *GetRotationMatrix() const override { return &kIdentityMatrix[0]; }
0157 const Double_t *GetScale() const override { return &kUnitScale[0]; }
0158
0159 ClassDefOverride(TGeoTranslation, 1)
0160 };
0161
0162
0163
0164
0165
0166
0167
0168
0169 class TGeoRotation : public TGeoMatrix {
0170 protected:
0171 Double_t fRotationMatrix[3 * 3];
0172
0173 void CheckMatrix();
0174
0175 public:
0176 TGeoRotation();
0177 TGeoRotation(const TGeoRotation &other);
0178 TGeoRotation(const TGeoMatrix &other);
0179 TGeoRotation(const char *name);
0180
0181 TGeoRotation(const char *name, Double_t phi, Double_t theta, Double_t psi);
0182 TGeoRotation(const char *name, Double_t theta1, Double_t phi1, Double_t theta2, Double_t phi2, Double_t theta3,
0183 Double_t phi3);
0184 ~TGeoRotation() override {}
0185
0186 TGeoRotation &operator=(const TGeoRotation &other) { return TGeoRotation::operator=((TGeoMatrix &)other); }
0187 TGeoRotation &operator=(const TGeoMatrix &other);
0188 TGeoRotation &operator*=(const TGeoRotation &other);
0189 TGeoRotation operator*(const TGeoRotation &other) const;
0190 TGeoHMatrix operator*(const TGeoMatrix &right) const;
0191 Bool_t operator==(const TGeoRotation &other) const;
0192
0193 Bool_t IsValid() const;
0194 TGeoHMatrix Inverse() const override;
0195 void Clear(Option_t *option = "") override;
0196 Double_t Determinant() const;
0197 void FastRotZ(const Double_t *sincos);
0198 void GetAngles(Double_t &theta1, Double_t &phi1, Double_t &theta2, Double_t &phi2, Double_t &theta3,
0199 Double_t &phi3) const;
0200 void GetAngles(Double_t &phi, Double_t &theta, Double_t &psi) const;
0201 Double_t GetPhiRotation(Bool_t fixX = kFALSE) const;
0202 void LocalToMaster(const Double_t *local, Double_t *master) const override;
0203 void LocalToMasterVect(const Double_t *local, Double_t *master) const override
0204 {
0205 TGeoRotation::LocalToMaster(local, master);
0206 }
0207 void LocalToMasterBomb(const Double_t *local, Double_t *master) const override
0208 {
0209 TGeoRotation::LocalToMaster(local, master);
0210 }
0211 TGeoMatrix *MakeClone() const override;
0212 void MasterToLocal(const Double_t *master, Double_t *local) const override;
0213 void MasterToLocalVect(const Double_t *master, Double_t *local) const override
0214 {
0215 TGeoRotation::MasterToLocal(master, local);
0216 }
0217 void MasterToLocalBomb(const Double_t *master, Double_t *local) const override
0218 {
0219 TGeoRotation::MasterToLocal(master, local);
0220 }
0221 void MultiplyBy(const TGeoRotation *rot, Bool_t after = kTRUE);
0222 void RotateX(Double_t angle) override;
0223 void RotateY(Double_t angle) override;
0224 void RotateZ(Double_t angle) override;
0225 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0226 void ReflectX(Bool_t leftside, Bool_t rotonly = kFALSE) override;
0227 void ReflectY(Bool_t leftside, Bool_t rotonly = kFALSE) override;
0228 void ReflectZ(Bool_t leftside, Bool_t rotonly = kFALSE) override;
0229 void SetAngles(Double_t phi, Double_t theta, Double_t psi);
0230 void SetAngles(Double_t theta1, Double_t phi1, Double_t theta2, Double_t phi2, Double_t theta3, Double_t phi3);
0231 void SetMatrix(const Double_t *rot)
0232 {
0233 memcpy(&fRotationMatrix[0], rot, 9 * sizeof(Double_t));
0234 CheckMatrix();
0235 }
0236 void SetRotation(const TGeoMatrix &other);
0237 void GetInverse(Double_t *invmat) const;
0238
0239 const Double_t *GetTranslation() const override { return &kNullVector[0]; }
0240 const Double_t *GetRotationMatrix() const override { return &fRotationMatrix[0]; }
0241 const Double_t *GetScale() const override { return &kUnitScale[0]; }
0242
0243 ClassDefOverride(TGeoRotation, 1)
0244 };
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254 class TGeoScale : public TGeoMatrix {
0255 protected:
0256 Double_t fScale[3];
0257 public:
0258 TGeoScale();
0259 TGeoScale(const TGeoScale &other);
0260 TGeoScale(const TGeoMatrix &other);
0261 TGeoScale(Double_t sx, Double_t sy, Double_t sz);
0262 TGeoScale(const char *name, Double_t sx, Double_t sy, Double_t sz);
0263 ~TGeoScale() override;
0264
0265 TGeoScale &operator=(const TGeoScale &other) { return TGeoScale::operator=((TGeoMatrix &)other); }
0266 TGeoScale &operator=(const TGeoMatrix &other);
0267 TGeoScale &operator*=(const TGeoScale &other);
0268 TGeoScale operator*(const TGeoScale &other) const;
0269 TGeoHMatrix operator*(const TGeoMatrix &right) const;
0270 Bool_t operator==(const TGeoScale &other) const;
0271
0272 TGeoHMatrix Inverse() const override;
0273 void SetScale(Double_t sx, Double_t sy, Double_t sz);
0274 void SetScale(const TGeoMatrix &other);
0275 void LocalToMaster(const Double_t *local, Double_t *master) const override;
0276 Double_t LocalToMaster(Double_t dist, const Double_t *dir = nullptr) const;
0277 void LocalToMasterVect(const Double_t *local, Double_t *master) const override
0278 {
0279 TGeoScale::LocalToMaster(local, master);
0280 }
0281 TGeoMatrix *MakeClone() const override;
0282 void MasterToLocal(const Double_t *master, Double_t *local) const override;
0283 Double_t MasterToLocal(Double_t dist, const Double_t *dir = nullptr) const;
0284 void MasterToLocalVect(const Double_t *master, Double_t *local) const override
0285 {
0286 TGeoScale::MasterToLocal(master, local);
0287 }
0288 void ReflectX(Bool_t, Bool_t) override
0289 {
0290 fScale[0] = -fScale[0];
0291 SetBit(kGeoReflection, !IsReflection());
0292 }
0293 void ReflectY(Bool_t, Bool_t) override
0294 {
0295 fScale[1] = -fScale[1];
0296 SetBit(kGeoReflection, !IsReflection());
0297 }
0298 void ReflectZ(Bool_t, Bool_t) override
0299 {
0300 fScale[2] = -fScale[2];
0301 SetBit(kGeoReflection, !IsReflection());
0302 }
0303
0304 const Double_t *GetTranslation() const override { return &kNullVector[0]; }
0305 const Double_t *GetRotationMatrix() const override { return &kIdentityMatrix[0]; }
0306 const Double_t *GetScale() const override { return &fScale[0]; }
0307
0308 ClassDefOverride(TGeoScale, 1)
0309 };
0310
0311
0312
0313
0314
0315
0316
0317
0318 class TGeoCombiTrans : public TGeoMatrix {
0319 protected:
0320 Double_t fTranslation[3];
0321 TGeoRotation *fRotation;
0322 public:
0323 TGeoCombiTrans();
0324 TGeoCombiTrans(const TGeoCombiTrans &other) : TGeoCombiTrans((TGeoMatrix &)other) {}
0325 TGeoCombiTrans(const TGeoMatrix &other);
0326 TGeoCombiTrans(const TGeoTranslation &tr, const TGeoRotation &rot);
0327 TGeoCombiTrans(const char *name);
0328 TGeoCombiTrans(Double_t dx, Double_t dy, Double_t dz, TGeoRotation *rot);
0329 TGeoCombiTrans(const char *name, Double_t dx, Double_t dy, Double_t dz, TGeoRotation *rot);
0330
0331 TGeoCombiTrans &operator=(const TGeoCombiTrans &other) { return TGeoCombiTrans::operator=((TGeoMatrix &)other); }
0332 TGeoCombiTrans &operator=(const TGeoMatrix &matrix);
0333 TGeoCombiTrans &operator*=(const TGeoMatrix &other);
0334 TGeoCombiTrans operator*(const TGeoMatrix &other) const;
0335 Bool_t operator==(const TGeoMatrix &other) const;
0336
0337 ~TGeoCombiTrans() override;
0338
0339 void Clear(Option_t *option = "") override;
0340 TGeoHMatrix Inverse() const override;
0341 TGeoMatrix *MakeClone() const override;
0342 void Multiply(const TGeoMatrix *right);
0343 void RegisterYourself() override;
0344 void RotateX(Double_t angle) override;
0345 void RotateY(Double_t angle) override;
0346 void RotateZ(Double_t angle) override;
0347 void ReflectX(Bool_t leftside, Bool_t rotonly = kFALSE) override;
0348 void ReflectY(Bool_t leftside, Bool_t rotonly = kFALSE) override;
0349 void ReflectZ(Bool_t leftside, Bool_t rotonly = kFALSE) override;
0350 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0351 void SetDx(Double_t dx) override { SetTranslation(dx, fTranslation[1], fTranslation[2]); }
0352 void SetDy(Double_t dy) override { SetTranslation(fTranslation[0], dy, fTranslation[2]); }
0353 void SetDz(Double_t dz) override { SetTranslation(fTranslation[0], fTranslation[1], dz); }
0354 void SetTranslation(const TGeoTranslation &tr);
0355 void SetTranslation(Double_t dx, Double_t dy, Double_t dz);
0356 void SetTranslation(Double_t *vect);
0357 void SetRotation(const TGeoRotation &other);
0358 void SetRotation(const TGeoRotation *rot);
0359
0360 TGeoRotation *GetRotation() const { return fRotation; }
0361
0362 const Double_t *GetTranslation() const override { return &fTranslation[0]; }
0363 const Double_t *GetRotationMatrix() const override;
0364 const Double_t *GetScale() const override { return &kUnitScale[0]; }
0365
0366 ClassDefOverride(TGeoCombiTrans, 1)
0367 };
0368
0369
0370
0371
0372
0373
0374
0375
0376 class TGeoGenTrans : public TGeoCombiTrans {
0377 protected:
0378 Double_t fScale[3];
0379 public:
0380 TGeoGenTrans();
0381 TGeoGenTrans(const char *name);
0382 TGeoGenTrans(Double_t dx, Double_t dy, Double_t dz, Double_t sx, Double_t sy, Double_t sz, TGeoRotation *rot);
0383 TGeoGenTrans(const char *name, Double_t dx, Double_t dy, Double_t dz, Double_t sx, Double_t sy, Double_t sz,
0384 TGeoRotation *rot);
0385 ~TGeoGenTrans() override;
0386
0387 void Clear(Option_t *option = "") override;
0388 TGeoHMatrix Inverse() const override;
0389 void SetScale(Double_t sx, Double_t sy, Double_t sz);
0390 void SetScale(Double_t *scale) { memcpy(&fScale[0], scale, 3 * sizeof(Double_t)); }
0391 TGeoMatrix *MakeClone() const override { return nullptr; }
0392 Bool_t Normalize();
0393
0394 const Double_t *GetScale() const override { return &fScale[0]; }
0395
0396 ClassDefOverride(TGeoGenTrans, 1)
0397 };
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407 class TGeoIdentity : public TGeoMatrix {
0408 private:
0409
0410 public:
0411 TGeoIdentity();
0412 TGeoIdentity(const char *name);
0413 ~TGeoIdentity() override {}
0414
0415 TGeoHMatrix Inverse() const override;
0416 void LocalToMaster(const Double_t *local, Double_t *master) const override
0417 {
0418 memcpy(master, local, 3 * sizeof(Double_t));
0419 }
0420 void LocalToMasterVect(const Double_t *local, Double_t *master) const override
0421 {
0422 memcpy(master, local, 3 * sizeof(Double_t));
0423 }
0424 void LocalToMasterBomb(const Double_t *local, Double_t *master) const override
0425 {
0426 TGeoIdentity::LocalToMaster(local, master);
0427 }
0428 TGeoMatrix *MakeClone() const override { return nullptr; }
0429 void MasterToLocal(const Double_t *master, Double_t *local) const override
0430 {
0431 memcpy(local, master, 3 * sizeof(Double_t));
0432 }
0433 void MasterToLocalVect(const Double_t *master, Double_t *local) const override
0434 {
0435 memcpy(local, master, 3 * sizeof(Double_t));
0436 }
0437 void MasterToLocalBomb(const Double_t *master, Double_t *local) const override
0438 {
0439 TGeoIdentity::MasterToLocal(master, local);
0440 }
0441
0442 const Double_t *GetTranslation() const override { return &kNullVector[0]; }
0443 const Double_t *GetRotationMatrix() const override { return &kIdentityMatrix[0]; }
0444 const Double_t *GetScale() const override { return &kUnitScale[0]; }
0445 void SavePrimitive(std::ostream &, Option_t * = "") override {}
0446
0447 ClassDefOverride(TGeoIdentity, 1)
0448 };
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459 class TGeoHMatrix : public TGeoMatrix {
0460 private:
0461 Double_t fTranslation[3];
0462 Double_t fRotationMatrix[9];
0463 Double_t fScale[3];
0464
0465 public:
0466 TGeoHMatrix();
0467 TGeoHMatrix(const TGeoHMatrix &other);
0468 TGeoHMatrix(const TGeoMatrix &matrix);
0469 TGeoHMatrix(const char *name);
0470 ~TGeoHMatrix() override;
0471
0472 TGeoHMatrix &operator=(const TGeoHMatrix &other) { return TGeoHMatrix::operator=((TGeoMatrix &)other); }
0473 TGeoHMatrix &operator=(const TGeoMatrix *other);
0474 TGeoHMatrix &operator=(const TGeoMatrix &other);
0475 TGeoHMatrix &operator*=(const TGeoMatrix &other);
0476 TGeoHMatrix operator*(const TGeoMatrix &other) const;
0477 Bool_t operator==(const TGeoMatrix &other) const;
0478
0479 void Clear(Option_t *option = "") override;
0480 void CopyFrom(const TGeoMatrix *other);
0481 Double_t Determinant() const;
0482 void FastRotZ(const Double_t *sincos);
0483 TGeoHMatrix Inverse() const override;
0484 TGeoMatrix *MakeClone() const override;
0485 void Multiply(const TGeoMatrix *right);
0486 void Multiply(const TGeoMatrix &right) { Multiply(&right); }
0487 void MultiplyLeft(const TGeoMatrix *left);
0488 void MultiplyLeft(const TGeoMatrix &left) { MultiplyLeft(&left); }
0489
0490 void RotateX(Double_t angle) override;
0491 void RotateY(Double_t angle) override;
0492 void RotateZ(Double_t angle) override;
0493 void ReflectX(Bool_t leftside, Bool_t rotonly = kFALSE) override;
0494 void ReflectY(Bool_t leftside, Bool_t rotonly = kFALSE) override;
0495 void ReflectZ(Bool_t leftside, Bool_t rotonly = kFALSE) override;
0496 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0497 void SetDx(Double_t dx) override
0498 {
0499 fTranslation[0] = dx;
0500 SetBit(kGeoTranslation);
0501 }
0502 void SetDy(Double_t dy) override
0503 {
0504 fTranslation[1] = dy;
0505 SetBit(kGeoTranslation);
0506 }
0507 void SetDz(Double_t dz) override
0508 {
0509 fTranslation[2] = dz;
0510 SetBit(kGeoTranslation);
0511 }
0512 void SetTranslation(const Double_t *vect)
0513 {
0514 SetBit(kGeoTranslation);
0515 memcpy(&fTranslation[0], vect, 3 * sizeof(Double_t));
0516 }
0517 void SetRotation(const Double_t *matrix)
0518 {
0519 SetBit(kGeoRotation);
0520 memcpy(&fRotationMatrix[0], matrix, 9 * sizeof(Double_t));
0521 }
0522 void SetScale(const Double_t *scale)
0523 {
0524 SetBit(kGeoScale);
0525 memcpy(&fScale[0], scale, 3 * sizeof(Double_t));
0526 }
0527
0528 const Double_t *GetTranslation() const override { return &fTranslation[0]; }
0529 const Double_t *GetRotationMatrix() const override { return &fRotationMatrix[0]; }
0530 const Double_t *GetScale() const override { return &fScale[0]; }
0531
0532 virtual Double_t *GetTranslation() { return &fTranslation[0]; }
0533 virtual Double_t *GetRotationMatrix() { return &fRotationMatrix[0]; }
0534 virtual Double_t *GetScale() { return &fScale[0]; }
0535 ClassDefOverride(TGeoHMatrix, 1)
0536 };
0537
0538 R__EXTERN TGeoIdentity *gGeoIdentity;
0539
0540 #endif