Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:05

0001 #ifndef Alignment_CommonAlignment_Alignable_H
0002 #define Alignment_CommonAlignment_Alignable_H
0003 
0004 #include "Alignment/CommonAlignment/interface/AlignableSurface.h"
0005 #include "Alignment/CommonAlignment/interface/StructureType.h"
0006 #include "Alignment/CommonAlignment/interface/Utilities.h"
0007 #include "DataFormats/DetId/interface/DetId.h"
0008 
0009 class AlignmentErrorsExtended;
0010 class AlignmentParameters;
0011 class AlignmentPositionError;
0012 class Alignments;
0013 class AlignmentSurfaceDeformations;
0014 class SurfaceDeformation;
0015 
0016 /** \class Alignable
0017  *
0018  * Abstract base class for alignable entities.
0019  * Any Alignable object can be moved and rotated.
0020  * Also an alignment uncertainty can be set.
0021  *
0022  */
0023 
0024 class AlignmentParameters;
0025 class SurveyDet;
0026 
0027 class Alignable {
0028 public:
0029   typedef align::Scalar Scalar;
0030   typedef align::PositionType PositionType;
0031   typedef align::RotationType RotationType;
0032   typedef align::GlobalVector GlobalVector;
0033   typedef align::LocalVector LocalVector;
0034   typedef align::Alignables Alignables;
0035   typedef align::StructureType StructureType;
0036 
0037   enum class CompConstraintType { NONE, POSITION, POSITION_Z };
0038 
0039   /// Constructor from id and surface, setting also geomDetId
0040   /// (AlignableNavigator relies on the fact that only AlignableDet/DetUnit have geomDetId!)
0041   Alignable(align::ID, const AlignableSurface&);
0042 
0043   /// Constructor for a composite with given rotation.
0044   /// Position is found (later) from average of daughters' positions.
0045   Alignable(align::ID, const RotationType&);
0046 
0047   /// Destructor
0048   virtual ~Alignable();
0049 
0050   /// Updater using id and surface.
0051   /// The given id has to match the current id.
0052   void update(align::ID, const AlignableSurface&);
0053 
0054   /// Set the AlignmentParameters
0055   void setAlignmentParameters(AlignmentParameters* dap);
0056 
0057   /// Get the AlignmentParameters
0058   AlignmentParameters* alignmentParameters() const { return theAlignmentParameters; }
0059 
0060   /// Add a component to alignable
0061   /// (GF: Should be interface in Composite, but needed in AlignableBuilder::build)
0062   virtual void addComponent(Alignable*) = 0;
0063 
0064   /// Return vector of all direct components
0065   virtual const Alignables& components() const = 0;
0066 
0067   /// Return number of direct components
0068   int size() const { return components().size(); }
0069 
0070   /// Return the list of lowest daughters (non-composites) of Alignable.
0071   /// Contain itself if Alignable is a unit.
0072   const Alignables& deepComponents() const { return theDeepComponents; }
0073 
0074   /// Provide all components, subcomponents, subsub... etc. of Alignable
0075   /// down to AlignableDetUnit, except for 'single childs' like e.g.
0076   /// AlignableDetUnits of AlignableDets representing single sided SiStrip
0077   /// modules. (for performance reason by adding to argument)
0078   virtual void recursiveComponents(Alignables& result) const = 0;
0079 
0080   /// Steps down hierarchy until components with AlignmentParameters are found
0081   /// and adds them to argument. True either if no such components are found
0082   /// or if all branches of components end with such components (i.e. 'consistent').
0083   bool firstCompsWithParams(Alignables& paramComps) const;
0084 
0085   /// Steps down hierarchy to the lowest level of components with AlignmentParameters
0086   /// and adds them to argument. True either if no such components are found
0087   /// or if all branches of components end with such components (i.e. 'consistent').
0088   bool lastCompsWithParams(Alignables& paramComps) const;
0089 
0090   /// Return pointer to container alignable (if any)
0091   Alignable* mother() const { return theMother; }
0092 
0093   /// Assign mother to alignable
0094   void setMother(Alignable* mother) { theMother = mother; }
0095 
0096   /// Movement with respect to the global reference frame
0097   virtual void move(const GlobalVector& displacement) = 0;
0098 
0099   /// Rotation intepreted such that the orientation of the rotation
0100   /// axis is w.r.t. to the global coordinate system. Rotation is
0101   /// relative to current orientation
0102   virtual void rotateInGlobalFrame(const RotationType& rotation) = 0;
0103 
0104   /// Rotation intepreted in the local reference frame
0105   virtual void rotateInLocalFrame(const RotationType& rotation);
0106 
0107   /// Rotation around arbitratry global axis
0108   virtual void rotateAroundGlobalAxis(const GlobalVector& axis, Scalar radians);
0109 
0110   /// Rotation around arbitratry local axis
0111   virtual void rotateAroundLocalAxis(const LocalVector& axis, Scalar radians);
0112 
0113   /// Rotation around global x-axis
0114   virtual void rotateAroundGlobalX(Scalar radians);
0115 
0116   /// Rotation around local x-axis
0117   virtual void rotateAroundLocalX(Scalar radians);
0118 
0119   /// Rotation around global y-axis
0120   virtual void rotateAroundGlobalY(Scalar radians);
0121 
0122   /// Rotation around local y-axis
0123   virtual void rotateAroundLocalY(Scalar radians);
0124 
0125   /// Rotation around global z-axis
0126   virtual void rotateAroundGlobalZ(Scalar radians);
0127 
0128   /// Rotation around local z-axis
0129   virtual void rotateAroundLocalZ(Scalar radians);
0130 
0131   /// Return the Surface (global position and orientation) of the object
0132   const AlignableSurface& surface() const { return theSurface; }
0133 
0134   /// Return the global position of the object
0135   const PositionType& globalPosition() const { return surface().position(); }
0136 
0137   /// Return the global orientation of the object
0138   const RotationType& globalRotation() const { return surface().rotation(); }
0139 
0140   /// Return change of the global position since the creation of the object
0141   const GlobalVector& displacement() const { return theDisplacement; }
0142 
0143   /// Return change of orientation since the creation of the object
0144   const RotationType& rotation() const { return theRotation; }
0145 
0146   /// Set the alignment position error - if (!propagateDown) do not affect daughters
0147   virtual void setAlignmentPositionError(const AlignmentPositionError& ape, bool propagateDown) = 0;
0148 
0149   /// Add (or set if not already present) the AlignmentPositionError,
0150   /// but if (!propagateDown) do not affect daughters
0151   virtual void addAlignmentPositionError(const AlignmentPositionError& ape, bool propagateDown) = 0;
0152 
0153   /// add (or set if not already present) the AlignmentPositionError
0154   /// which would result from a rotation (given in the GLOBAL frame
0155   /// of CMS) of the alignable object,
0156   /// but if (!propagateDown) do not affect daughters
0157   virtual void addAlignmentPositionErrorFromRotation(const RotationType& rotation, bool propagateDown) = 0;
0158 
0159   /// add (or set if not already present) the AlignmentPositionError
0160   /// which would result from a rotation (given in the LOCAL frame
0161   /// of the Alignable)  of the alignable object,
0162   /// but if (!propagateDown) do not affect daughters
0163   virtual void addAlignmentPositionErrorFromLocalRotation(const RotationType& rotation, bool propagateDown) = 0;
0164 
0165   /// Set the surface deformation parameters - if (!propagateDown) do not affect daughters
0166   virtual void setSurfaceDeformation(const SurfaceDeformation* deformation, bool propagateDown) = 0;
0167 
0168   /// Add the surface deformation parameters to the existing ones,
0169   /// if (!propagateDown) do not affect daughters.
0170   virtual void addSurfaceDeformation(const SurfaceDeformation* deformation, bool propagateDown) = 0;
0171 
0172   /// Return the alignable type identifier
0173   virtual StructureType alignableObjectId() const = 0;
0174 
0175   /// Return the DetId of the associated GeomDet (0 by default)
0176   /// This should be removed. Ultimately we need only one ID.
0177   const DetId& geomDetId() const { return theDetId; }
0178 
0179   /// Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
0180   align::ID id() const { return theId; }
0181 
0182   /// Return the alignable type of contraints wrt. its components
0183   virtual CompConstraintType compConstraintType() const { return compConstraintType_; }
0184 
0185   /// Recursive printout of alignable information
0186   virtual void dump() const = 0;
0187 
0188   /// Return vector of alignment data
0189   virtual Alignments* alignments() const = 0;
0190 
0191   /// Return vector of alignment errors
0192   virtual AlignmentErrorsExtended* alignmentErrors() const = 0;
0193 
0194   /// Return surface deformations, sorted by DetId
0195   AlignmentSurfaceDeformations* surfaceDeformations() const;
0196 
0197   /// Return surface deformations as a vector of pairs of raw DetId
0198   /// and pointers to surface deformations
0199   virtual int surfaceDeformationIdPairs(std::vector<std::pair<int, SurfaceDeformation*> >&) const = 0;
0200 
0201   /// cache the current position, rotation and other parameters (e.g. surface deformations), also for possible components
0202   virtual void cacheTransformation();
0203 
0204   /// cache for the given run the current position, rotation and other
0205   /// parameters (e.g. surface deformations), also for possible components
0206   virtual void cacheTransformation(const align::RunNumber&);
0207 
0208   /// restore the previously cached transformation, also for possible components
0209   virtual void restoreCachedTransformation();
0210 
0211   /// restore for the given run the previously cached transformation, also for
0212   /// possible components
0213   virtual void restoreCachedTransformation(const align::RunNumber&);
0214 
0215   /// Return survey info
0216   const SurveyDet* survey() const { return theSurvey; }
0217 
0218   /// Set survey info
0219   void setSurvey(const SurveyDet*);
0220 
0221   /// Recenter surface object without moving possible components
0222   virtual void recenterSurface();
0223 
0224 protected:
0225   template <class T>
0226   using Cache = std::map<align::RunNumber, T>;
0227 
0228   void addDisplacement(const GlobalVector& displacement);
0229   void addRotation(const RotationType& rotation);
0230   virtual void updateMother(const GlobalVector& shift);
0231 
0232   DetId theDetId;  // used to check if Alignable is associated to a GeomDet
0233                    // ugly way to keep AlignableNavigator happy for now
0234 
0235   align::ID theId;  // real ID as int, above DetId should be removed
0236 
0237   AlignableSurface theSurface;  // Global position and orientation of surface
0238 
0239   GlobalVector theDisplacement;  // total linear displacement
0240   RotationType theRotation;      // total angular displacement
0241 
0242   AlignableSurface theCachedSurface;
0243   GlobalVector theCachedDisplacement;
0244   RotationType theCachedRotation;
0245 
0246   CompConstraintType compConstraintType_{CompConstraintType::NONE};
0247 
0248   Alignables theDeepComponents;  // list of lowest daughters
0249                                  // contain itself if Alignable is a unit
0250 
0251   Cache<AlignableSurface> surfacesCache_;
0252   Cache<GlobalVector> displacementsCache_;
0253   Cache<RotationType> rotationsCache_;
0254 
0255 private:
0256   /// private default ctr. to enforce usage of the specialised ones
0257   Alignable(){};
0258 
0259   AlignmentParameters* theAlignmentParameters;
0260 
0261   Alignable* theMother;  // Pointer to container
0262 
0263   const SurveyDet* theSurvey;  // Pointer to survey info; owned by class
0264 };
0265 
0266 #endif