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