Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:34:26

0001 //   COCOA class header file

0002 //Id:  OpticalObject.h

0003 //CAT: Model

0004 //

0005 //   Base class to describe all types of Optical Objects

0006 //

0007 //   History: v1.0

0008 //   Pedro Arce

0009 
0010 #ifndef _OPTICALOBJECT_HH
0011 #define _OPTICALOBJECT_HH
0012 
0013 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h"
0014 #include <cstdint>
0015 
0016 class LightRay;
0017 class Measurement;
0018 class Entry;
0019 class ALIFileIn;
0020 class Measurement;
0021 class ALIPlane;
0022 
0023 class CocoaMaterialElementary;
0024 class CocoaSolidShape;
0025 
0026 #include "CLHEP/Vector/ThreeVector.h"
0027 #include "CLHEP/Vector/Rotation.h"
0028 #include <fstream>
0029 #include <vector>
0030 class OpticalAlignInfo;
0031 class OpticalAlignParam;
0032 
0033 enum XYZcoor { XCoor, YCoor, ZCoor };
0034 
0035 class OpticalObject {
0036   friend std::ostream& operator<<(std::ostream& os, const OpticalObject& c);
0037 
0038 public:
0039   //---------- Constructors / destructor

0040   OpticalObject() {}
0041   OpticalObject(OpticalObject* parent, const ALIstring& type, const ALIstring& name, const ALIbool copy_data);
0042   virtual ~OpticalObject();
0043 
0044   //----- Steering function to read OptO data from SDF file (and also start component OptOs)

0045   void construct();
0046 
0047   void constructFromOptAligInfo(const OpticalAlignInfo& oaInfo);
0048   std::vector<ALIstring> getCoordinateFromOptAlignParam(const OpticalAlignParam& oaParam);
0049   void createComponentOptOsFromOptAlignInfo();
0050 
0051   virtual void constructMaterial();
0052   virtual void constructSolidShape();
0053 
0054   virtual void fillVRML() {}
0055   virtual void fillIguana() {}
0056 
0057   // ACCESS DATA MEMBERS

0058   const ALIstring& name() const { return theName; };
0059   const ALIstring& type() const { return theType; };
0060   const OpticalObject* parent() const { return theParent; };
0061 
0062   // Return List of Coordinate Entries

0063   const std::vector<Entry*>& CoordinateEntryList() const { return theCoordinateEntryVector; }
0064   // Return List of Extra Entries

0065   const std::vector<Entry*>& ExtraEntryList() const { return theExtraEntryVector; }
0066   // Return List of Extra Entry Values

0067   std::vector<ALIdouble>& ExtraEntryValueList() { return theExtraEntryValueVector; }
0068 
0069   const std::vector<ALIdouble>& ExtraEntryValueOriginalList() { return theExtraEntryValueOriginalVector; }
0070   const std::vector<ALIdouble>& ExtraEntryValueOriginalOriginalList() {
0071     return theExtraEntryValueOriginalOriginalVector;
0072   }
0073 
0074   // ACCESS CENTRE AND ROTATION DATA MEMBERS

0075   const CLHEP::Hep3Vector& centreGlob() const { return theCentreGlob; }
0076 
0077   const CLHEP::Hep3Vector& centreGlobal() const { return centreGlob(); }
0078 
0079   const CLHEP::Hep3Vector centreLocal() const;
0080 
0081   const CLHEP::Hep3Vector& centreGlobOriginal() const { return theCentreGlobOriginal; }
0082   const CLHEP::Hep3Vector& centreGlobOriginalOriginal() const { return theCentreGlobOriginalOriginal; }
0083   const CLHEP::HepRotation& rmGlob() const { return theRmGlob; }
0084 
0085   const CLHEP::HepRotation rmLocal() const;
0086 
0087   const CLHEP::HepRotation& rmGlobOriginal() const { return theRmGlobOriginal; }
0088   const CLHEP::HepRotation& rmGlobOriginalOriginal() const { return theRmGlobOriginalOriginal; }
0089 
0090   const double getEntryCentre(const XYZcoor coor) const;
0091   const double getEntryCentre(const ALIstring& coor) const;
0092 
0093   const double getEntryRMangle(const XYZcoor coor) const;
0094   const double getEntryRMangle(const ALIstring& coor) const;
0095 
0096   const ALIuint ID() const { return theCmsswID; }
0097   const ALIuint getCmsswID() const { return theCmsswID; }
0098   void setCmsswID(ALIuint id) { theCmsswID = id; }
0099   void setID(ALIuint id) { theCmsswID = id; }
0100 
0101   // SET DATA METHODS

0102   void setRmGlobalOriginal(const CLHEP::HepRotation& rm) { theRmGlobOriginal = rm; }
0103   void setGlobalRMOriginalOriginal(const CLHEP::HepRotation& rmoriori);
0104   void propagateGlobalRMOriginalOriginalChangeToChildren(const CLHEP::HepRotation& rmorioriold,
0105                                                          const CLHEP::HepRotation& rmoriorinew);
0106   CLHEP::HepRotation buildRmFromEntryValuesOriginalOriginal();
0107 
0108   void setRmGlobal(const CLHEP::HepRotation& rm) { theRmGlob = rm; }
0109 
0110   void setType(const ALIstring& type) { theType = type; }
0111   void addCoordinateEntryToList(Entry* entry) { theCoordinateEntryVector.push_back(entry); }
0112   void addExtraEntryToList(Entry* entry) { theExtraEntryVector.push_back(entry); }
0113   void addExtraEntryValueToList(ALIdouble entry_value) { theExtraEntryValueVector.push_back(entry_value); }
0114   void addExtraEntryValueOriginalToList(ALIdouble entry_value) {
0115     theExtraEntryValueOriginalVector.push_back(entry_value);
0116   }
0117   void addExtraEntryValueOriginalOriginalToList(ALIdouble entry_value) {
0118     theExtraEntryValueOriginalOriginalVector.push_back(entry_value);
0119   }
0120 
0121   //-  void test(){};

0122   //@@@@@----- METHODS USED IN Fit

0123   //---------- Propagate the light ray with the behaviour 'behav'

0124   virtual void participateInMeasurement(LightRay& lightray, Measurement& meas, const ALIstring& behav);
0125   //---------- default behaviour (depends of subclass type). A default behaviour can be makeMeasurement(), therefore you have to pass 'meas'

0126   virtual void defaultBehaviour(LightRay& lightray, Measurement& meas);
0127   //---------- Fast simulation of deviation of the light ray (reflection, shift, ...)

0128   virtual void fastDeviatesLightRay(LightRay& lightray);
0129   //---------- Detailed simulation of the light ray traversing

0130   virtual void fastTraversesLightRay(LightRay& lightray);
0131   //---------- Detailed simulation of deviation of the light ray (reflection, shift, ...)

0132   virtual void detailedDeviatesLightRay(LightRay& lightray);
0133   //---------- Fast simulation of the light ray traversing

0134   virtual void detailedTraversesLightRay(LightRay& lightray);
0135 
0136   //---------- Fast simulation of the light ray traversing

0137   virtual void makeMeasurement(LightRay& lightray, Measurement& meas);
0138 
0139   //---------- User Defined Behaviour

0140   virtual void userDefinedBehaviour(LightRay& lightray, Measurement& meas, const ALIstring& behav);
0141 
0142   //---------- Obtain the Z Axis of the OptO (ZAxis rotated with the OptO rotation matrix)

0143   CLHEP::Hep3Vector getZAxis() {
0144     CLHEP::Hep3Vector ZAxis(0., 0., 1.);
0145     CLHEP::HepRotation rmt = rmGlob();
0146     ZAxis = rmt * ZAxis;
0147     return ZAxis;
0148   }
0149   //---------- Get one of the plates of an OptO made of two parallel plates

0150   ALIPlane getPlate(const ALIbool forwardPlate, const ALIbool applyWedge);
0151 
0152   //---------- Displacements to get the derivative of a measurement w.r.t an entry

0153   //----- Displace the centre coordinate 'coor'

0154   void displaceCentreGlob(const XYZcoor coor, const ALIdouble disp);
0155   CLHEP::Hep3Vector getDisplacementInLocalCoordinates(const XYZcoor coor, const ALIdouble disp);
0156   void displaceCentreGlob(const CLHEP::Hep3Vector& dispVec);
0157   //----- Rotate around axis 'coor'

0158   void displaceRmGlobAroundGlobal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
0159   void displaceRmGlobAroundLocal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
0160   //----- Displace extra entry number 'entryNo'

0161   void displaceExtraEntry(const ALIuint entryNo, const ALIdouble disp);
0162   void setExtraEntryValue(const ALIuint entryNo, const ALIdouble disp);
0163 
0164   //----------- Displacements of original coordinates: do it to reset the original data

0165   //----------- every new iteration of the non linear fit

0166   //----- Displace the centre coordinate 'coor'

0167   void displaceCentreGlobOriginal(const XYZcoor coor, const ALIdouble disp);
0168   void displaceCentreGlobOriginal(const CLHEP::Hep3Vector& dispVec);
0169   void displaceCentreGlobOriginalOriginal(const XYZcoor coor, const ALIdouble disp);
0170   void displaceCentreGlobOriginalOriginal(const CLHEP::Hep3Vector& dispVec);
0171   //----- Rotate around axis 'coor'

0172   void displaceRmGlobOriginal(const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
0173   void displaceRmGlobOriginalOriginal(const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
0174   //----- Displace extra entry number 'entryNo'

0175   void displaceExtraEntryOriginal(const ALIuint entryNo, const ALIdouble disp);
0176   void displaceExtraEntryOriginalOriginal(const ALIuint entryNo, const ALIdouble disp);
0177 
0178   //---------- Reset the global coordinates and extra entries (after derivative is finished)

0179   void resetGlobalCoordinates();
0180   void resetOriginalOriginalCoordinates();
0181 
0182   // Find position of an extra entry in ExtraEntryList (and therefore in ExtraEntryValueList)

0183   const ALIint extraEntryNo(const ALIstring& entry_name) const;
0184 
0185   // //@@ Find an extra Entry by name and return its value. If entry not found, stop.

0186   const ALIdouble findExtraEntryValueMustExist(const ALIstring& eename) const;
0187   // Find an extra Entry by name and return its value, if it is not found return 0

0188   const ALIdouble findExtraEntryValue(const ALIstring& eename) const;
0189 
0190   // Find an extra Entry by name and pass its value. Return if entry is found or not

0191   const ALIbool findExtraEntryValueIfExists(const ALIstring& eename, ALIdouble& value) const;
0192 
0193   // Return the name of the OptO without its path

0194   const ALIstring shortName() const;
0195   // Return the name of the OptO with its path

0196   const ALIstring longName() const { return name(); }
0197 
0198   //! set current measurement

0199   void setMeas(Measurement* meas) { theCurrentMeas = meas; }
0200   Measurement* meas() { return theCurrentMeas; }
0201 
0202   std::vector<double> getRotationAnglesInOptOFrame(const OpticalObject* optoAncestor,
0203                                                    const std::vector<Entry*>& entries) const;
0204   std::vector<double> getLocalRotationAngles(const std::vector<Entry*>& entries) const;
0205   std::vector<double> getRotationAnglesFromMatrix(CLHEP::HepRotation& rmLocal,
0206                                                   const std::vector<Entry*>& entries) const;
0207   double diff2pi(double ang1, double ang2);
0208   bool eq2ang(double ang1, double ang2);
0209   double approxTo0(double val);
0210   double addPii(double val);
0211   int checkMatrixEquations(double angleX, double angleY, double angleZ, CLHEP::HepRotation* rot = nullptr);
0212 
0213   //-  CLHEP::Hep3Vector GetAxisForDisplacement( const XYZcoor coor );

0214   void setGlobalCoordinates();
0215   void setOriginalEntryValues();
0216 
0217   CocoaMaterialElementary* getMaterial() const { return theMaterial; }
0218   CocoaSolidShape* getSolidShape() const { return theSolidShape; }
0219 
0220   //private DATA METHODS

0221 private:
0222   // Reads the data

0223   void readData(ALIFileIn& filein);
0224   // Copy the data from last OptO found of the same type

0225   void copyData();
0226 
0227   // Read extra entries

0228   void readExtraEntries(ALIFileIn& filein);
0229 
0230 protected:
0231   // Create and fill an extra entry

0232   virtual void fillExtraEntry(std::vector<ALIstring>& wordlist);
0233 
0234 private:
0235   // Read centre or angles

0236   void readCoordinates(const ALIstring& coor_type_read, const ALIstring& coor_type_expected, ALIFileIn& filein);
0237   // Create and fill a coordinate entry

0238   void fillCoordinateEntry(const ALIstring& coor_name, const std::vector<ALIstring>& wordlist);
0239   // Set angles null

0240   void setAnglesNull();
0241 
0242   //------ Build wordlist copying data of entry 'entry'

0243   void buildWordList(const Entry* entry, std::vector<ALIstring>& wordlist);
0244 
0245   // start Optical Objects that are components of current

0246   void createComponentOptOs(ALIFileIn& filein);
0247 
0248   OpticalObject* createNewOptO(OpticalObject* parent, ALIstring optoType, ALIstring optoName, ALIbool fcopyComponents);
0249 
0250   // Set global centre and rotation matrix

0251   void setGlobalCentre();
0252   void setGlobalRM();
0253   void setGlobalCoordinatesOfComponents();
0254 
0255   void SetCentreLocalFromEntryValues();
0256   void SetCentreGlobFromCentreLocal();
0257   void SetRMLocalFromEntryValues();
0258   void SetRMGlobFromRMLocal();
0259   void SetRMGlobFromRMLocalOriginalOriginal(const CLHEP::HepRotation& rmoriori);
0260   // Calculate local rot axis with new rm glob

0261   void calculateLocalRotationAxisInGlobal();
0262 
0263   void transformCylindrical2Cartesian();
0264   void transformSpherical2Cartesian();
0265   void transformGlobal2Local();
0266 
0267   template <class T>
0268   void rotateItAroundGlobal(T& object, const XYZcoor coor, const double disp);
0269 
0270   CLHEP::Hep3Vector getDispVec(const XYZcoor coor, const ALIdouble disp);
0271 
0272   void SetCentreIsGlobal(ALIbool isG) { centreIsGlobal = isG; }
0273   void SetAnglesIsGlobal(ALIbool isG) { anglesIsGlobal = isG; }
0274 
0275 private:
0276   // private DATA MEMBERS

0277   OpticalObject* theParent;
0278   ALIstring theType;
0279   ALIstring theName;
0280   //----- Boolean to mark if data is going to be read or copied from closest previous OptO with same type

0281   ALIbool fcopyData;
0282 
0283   //----- Global centre and rotation matrix

0284   CLHEP::Hep3Vector theCentreGlob;
0285   CLHEP::HepRotation theRmGlob;
0286   //----- Original global centre and rotation matrix (for backup when they are changed to get derivatives)

0287   CLHEP::Hep3Vector theCentreGlobOriginal;
0288   CLHEP::HepRotation theRmGlobOriginal;
0289   CLHEP::Hep3Vector theCentreGlobOriginalOriginal;
0290   CLHEP::HepRotation theRmGlobOriginalOriginal;
0291 
0292   // Lists of entries

0293   std::vector<Entry*> theCoordinateEntryVector;
0294   std::vector<Entry*> theExtraEntryVector;
0295 
0296   // Lists of values of entries

0297   std::vector<ALIdouble> theExtraEntryValueVector;
0298   std::vector<ALIdouble> theExtraEntryValueOriginalVector;
0299   std::vector<ALIdouble> theExtraEntryValueOriginalOriginalVector;
0300 
0301   // centre and angles are global

0302   ALIbool centreIsGlobal;
0303   ALIbool anglesIsGlobal;
0304 
0305   Measurement* theCurrentMeas;
0306 
0307   CLHEP::Hep3Vector axisXLocalInGlobal;
0308   CLHEP::Hep3Vector axisYLocalInGlobal;
0309   CLHEP::Hep3Vector axisZLocalInGlobal;
0310 
0311   ALIuint theCmsswID;
0312 
0313 protected:
0314   CocoaMaterialElementary* theMaterial;
0315   CocoaSolidShape* theSolidShape;
0316 
0317   ALIint verbose;
0318 };
0319 
0320 #endif