Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:04:14

0001 //==========================================================================
0002 //  AIDA Detector description implementation
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DD4HEP_ALIGNMENTDATA_H
0014 #define DD4HEP_ALIGNMENTDATA_H
0015 
0016 // Framework include files
0017 #include <DD4hep/NamedObject.h>
0018 #include <DD4hep/DetElement.h>
0019 #include <DD4hep/Volumes.h>
0020 
0021 // ROOT include files
0022 #include <TGeoMatrix.h>
0023 
0024 /// Namespace for the AIDA detector description toolkit
0025 namespace dd4hep {
0026 
0027   // Forward declarations
0028   class Alignment;
0029   class AlignmentCondition;
0030 
0031   /// Class describing an condition to re-adjust an alignment
0032   /**
0033    *
0034    *  \author  M.Frank
0035    *  \version 1.0
0036    *  \ingroup DD4HEP_CONDITIONS
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     /// Default constructor
0054     Delta() = default;
0055     /// Initializing constructor
0056     Delta(const Position& tr)
0057       : translation(tr), flags(HAVE_TRANSLATION) {}
0058     /// Initializing constructor
0059     Delta(const RotationZYX& rot)
0060       : translation(), rotation(rot), flags(HAVE_ROTATION) {}
0061     /// Initializing constructor
0062     Delta(const Position& tr, const RotationZYX& rot)
0063       : translation(tr), rotation(rot), flags(HAVE_ROTATION|HAVE_TRANSLATION) {}
0064     /// Initializing constructor
0065     Delta(const Translation3D& piv, const RotationZYX& rot)
0066       : pivot(piv), rotation(rot), flags(HAVE_ROTATION|HAVE_PIVOT) {}
0067     /// Initializing constructor
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     /// Copy constructor
0071     Delta(const Delta& c);
0072     /// Default destructor
0073     ~Delta();
0074     /// Assignment operator
0075     Delta& operator=(const Delta& c);
0076     /// Reset information to identity
0077     void clear();
0078     /// Check a given flag
0079     bool checkFlag(unsigned int mask) const {  return (flags&mask) == mask;        }
0080     /// Check a given flag
0081     void setFlag(unsigned int mask)         {  flags |= mask;                      }
0082     /// Access flags: Check if the delta operation contains a translation
0083     bool hasTranslation() const             {  return checkFlag(HAVE_TRANSLATION); }
0084     /// Access flags: Check if the delta operation contains a rotation
0085     bool hasRotation() const                {  return checkFlag(HAVE_ROTATION);    }
0086     /// Access flags: Check if the delta operation contains a pivot
0087     bool hasPivot() const                   {  return checkFlag(HAVE_PIVOT);       }
0088     /// Compute the alignment delta for one detector element and its alignment condition
0089     void computeMatrix(TGeoHMatrix& tr_delta)  const;
0090   };
0091 
0092   /// Derived condition data-object definition
0093   /**
0094    *  \author  M.Frank
0095    *  \version 1.0
0096    *  \ingroup DD4HEP_CONDITIONS
0097    */
0098   class AlignmentData   {
0099   public:
0100     /// Forward declaration of the utility bit mask
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     /// Alignment changes
0116     Delta                delta;
0117     /// Intermediate buffer to store the transformation to the world coordination system
0118     mutable TGeoHMatrix  worldTrafo;
0119     /// Intermediate buffer to store the transformation to the parent detector element
0120     mutable TGeoHMatrix  detectorTrafo;
0121     /// The list of TGeoNodes (physical placements)
0122     std::vector<PlacedVolume> nodes;
0123     /// Transformation from volume to the world
0124     Transform3D          trToWorld;
0125     /// Reference to the next hosting detector element
0126     DetElement           detector;
0127     /// The subdetector placement corresponding to the actual detector element's volume
0128     PlacedVolume         placement;
0129     /// Flag to remember internally calculated quatities
0130     mutable BitMask      flag;
0131     /// Magic word to verify object if necessary
0132     unsigned int         magic;
0133 
0134   public:
0135     /// Standard constructor
0136     AlignmentData();
0137     /// Copy constructor
0138     AlignmentData(const AlignmentData& copy);
0139     /// Default destructor
0140     virtual ~AlignmentData();
0141     /// Assignment operator necessary due to copy constructor
0142     AlignmentData& operator=(const AlignmentData& copy);
0143     /// Data accessor for decorator
0144     inline AlignmentData& data()                       {  return *this;               }
0145     /// Access the ideal/nominal alignment/placement matrix
0146     Alignment nominal() const;
0147     /// Create cached matrix to transform to world coordinates
0148     const TGeoHMatrix& worldTransformation()  const    {  return worldTrafo;          }
0149     /// Access the alignment/placement matrix with respect to the world
0150     const TGeoHMatrix& detectorTransformation() const  {  return detectorTrafo;       }
0151     /// Access the currently applied alignment/placement matrix
0152     const Transform3D& localToWorld() const            {  return trToWorld;           }
0153 
0154     /** Aliases for the transformation from local coordinates to the world system  */
0155     /// Transformation from local coordinates of the placed volume to the world system
0156     void localToWorld(const Position& local, Position& global) const;
0157     /// Transformation from local coordinates of the placed volume to the world system
0158     void localToWorld(const Double_t local[3], Double_t global[3]) const;
0159     /// Transformation from local coordinates of the placed volume to the world system
0160     Position localToWorld(const Position& local) const;
0161     /// Transformation from local coordinates of the placed volume to the world system
0162     Position localToWorld(const Double_t local[3]) const
0163     {  return localToWorld({local[0],local[1],local[2]});                            }
0164 
0165     /** Aliases for the transformation from world coordinates to the local volume  */
0166     /// Transformation from world coordinates of the local placed volume coordinates
0167     void worldToLocal(const Position& global, Position& local) const;
0168     /// Transformation from world coordinates of the local placed volume coordinates
0169     void worldToLocal(const Double_t global[3], Double_t local[3]) const;
0170     /// Transformation from local coordinates of the placed volume to the world system
0171     Position worldToLocal(const Position& global) const;
0172     /// Transformation from local coordinates of the placed volume to the world system
0173     Position worldToLocal(const Double_t global[3]) const
0174     {  return worldToLocal({global[0],global[1],global[2]});                          }
0175 
0176     /** Aliases for the transformation from local coordinates to the next DetElement system  */
0177     /// Transformation from local coordinates of the placed volume to the detector system
0178     void localToDetector(const Position& local, Position& detector) const;
0179     /// Transformation from local coordinates of the placed volume to the detector system
0180     void localToDetector(const Double_t local[3], Double_t detector[3]) const;
0181     /// Transformation from local coordinates of the placed volume to the world system
0182     Position localToDetector(const Position& local) const;
0183     /// Transformation from local coordinates of the placed volume to the world system
0184     Position localToDetector(const Double_t local[3]) const
0185     {  return localToDetector({local[0],local[1],local[2]});                          }
0186 
0187     /** Aliases for the transformation from the next DetElement to local coordinates */
0188     /// Transformation from detector element coordinates to the local placed volume coordinates
0189     void detectorToLocal(const Position& detector, Position& local) const;
0190     /// Transformation from detector element coordinates to the local placed volume coordinates
0191     void detectorToLocal(const Double_t detector[3], Double_t local[3]) const;
0192     /// Transformation from detector element coordinates to the local placed volume coordinates
0193     Position detectorToLocal(const Position& detector) const;
0194     /// Transformation from detector element coordinates to the local placed volume coordinates
0195     Position detectorToLocal(const Double_t det[3]) const
0196     {  return detectorToLocal({det[0],det[1],det[2]});                                }
0197   };
0198 }         /* End namespace dd4hep               */
0199 std::ostream& operator << (std::ostream& s, const dd4hep::Delta& data);
0200 std::ostream& operator << (std::ostream& s, const dd4hep::AlignmentData& data);
0201 #endif // DD4HEP_ALIGNMENTDATA_H