CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Alignment/CocoaModel/interface/OpticalObject.h

Go to the documentation of this file.
00001 //   COCOA class header file
00002 //Id:  OpticalObject.h
00003 //CAT: Model
00004 //
00005 //   Base class to describe all types of Optical Objects 
00006 // 
00007 //   History: v1.0 
00008 //   Pedro Arce
00009 
00010 #ifndef _OPTICALOBJECT_HH
00011 #define _OPTICALOBJECT_HH
00012 
00013 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h"
00014 #include "stdint.h"
00015 
00016 class LightRay;
00017 class Measurement;
00018 class Entry;
00019 class ALIFileIn;
00020 class Measurement;
00021 class ALIPlane;
00022 
00023 class CocoaMaterialElementary;
00024 class CocoaSolidShape;
00025 
00026 #include "CLHEP/Vector/ThreeVector.h"
00027 #include "CLHEP/Vector/Rotation.h"
00028 #include <fstream>
00029 #include <vector>
00030 class OpticalAlignInfo;
00031 class OpticalAlignParam;
00032 
00033 enum XYZcoor{XCoor, YCoor, ZCoor};
00034 
00035 class OpticalObject
00036 {
00037   friend std::ostream& operator << (std::ostream& os, const OpticalObject& c);
00038 
00039  public:
00040   //---------- Constructors / destructor
00041   OpticalObject(){ };
00042   OpticalObject(OpticalObject* parent, const ALIstring& type, const ALIstring& name, const ALIbool copy_data);
00043   virtual ~OpticalObject();
00044 
00045   //----- Steering function to read OptO data from SDF file (and also start component OptOs)
00046   void construct(); 
00047 
00048   void constructFromOptAligInfo( const OpticalAlignInfo& oaInfo );
00049   std::vector<ALIstring> getCoordinateFromOptAlignParam( const OpticalAlignParam& oaParam );
00050   void createComponentOptOsFromOptAlignInfo();
00051 
00052   virtual void constructMaterial(); 
00053   virtual void constructSolidShape(); 
00054 
00055   virtual void fillVRML(){ } ;
00056   virtual void fillIguana(){ };
00057 
00058 
00059  // ACCESS DATA MEMBERS
00060   const ALIstring& name() const{ return theName; };
00061   const ALIstring& type() const{ return theType; };
00062   const OpticalObject* parent() const{ return theParent;};
00063 
00064   // Return List of Coordinate Entries
00065   const std::vector< Entry* >& CoordinateEntryList() const {
00066      return theCoordinateEntryVector;
00067   }
00068   // Return List of Extra Entries
00069   const std::vector< Entry* >& ExtraEntryList() const {
00070     return theExtraEntryVector;
00071   }
00072   // Return List of Extra Entry Values
00073   std::vector< ALIdouble >& ExtraEntryValueList() {
00074     return theExtraEntryValueVector;
00075   }
00076 
00077   const std::vector< ALIdouble >& ExtraEntryValueOriginalList() {
00078     return theExtraEntryValueOriginalVector;
00079   }
00080   const std::vector< ALIdouble >& ExtraEntryValueOriginalOriginalList() {
00081     return theExtraEntryValueOriginalOriginalVector;
00082   }
00083 
00084  // ACCESS CENTRE AND ROTATION DATA MEMBERS
00085   const CLHEP::Hep3Vector& centreGlob() const {
00086     return theCentreGlob;
00087   }
00088 
00089   const CLHEP::Hep3Vector& centreGlobal() const {
00090     return centreGlob();
00091   }
00092 
00093   const CLHEP::Hep3Vector centreLocal() const;
00094 
00095   const CLHEP::Hep3Vector& centreGlobOriginal() const {
00096     return theCentreGlobOriginal;
00097   }
00098   const CLHEP::Hep3Vector& centreGlobOriginalOriginal() const {
00099     return theCentreGlobOriginalOriginal;
00100   }
00101   const CLHEP::HepRotation& rmGlob() const {
00102     return theRmGlob;
00103   }
00104 
00105   const CLHEP::HepRotation rmLocal() const;
00106 
00107   const CLHEP::HepRotation& rmGlobOriginal() const {
00108     return theRmGlobOriginal;
00109   }
00110   const CLHEP::HepRotation& rmGlobOriginalOriginal() const {
00111     return theRmGlobOriginalOriginal;
00112   }
00113 
00114 
00115   const double getEntryCentre( const XYZcoor coor ) const;
00116   const double getEntryCentre( const ALIstring& coor ) const;
00117 
00118   const double getEntryRMangle( const XYZcoor coor ) const;
00119   const double getEntryRMangle( const ALIstring& coor ) const;
00120 
00121   const ALIuint ID() const { return theCmsswID; }
00122   const ALIuint getCmsswID() const { return theCmsswID; }
00123   void setCmsswID( ALIuint id ){ theCmsswID = id; }
00124   void setID( ALIuint id ) { theCmsswID = id; }
00125 
00126   // SET DATA METHODS
00127   void setRmGlobalOriginal( const CLHEP::HepRotation& rm ){
00128     theRmGlobOriginal = rm; 
00129   }
00130   void setGlobalRMOriginalOriginal(const CLHEP::HepRotation& rmoriori );
00131   void propagateGlobalRMOriginalOriginalChangeToChildren( const CLHEP::HepRotation& rmorioriold, const CLHEP::HepRotation& rmoriorinew );
00132    CLHEP::HepRotation buildRmFromEntryValuesOriginalOriginal();
00133 
00134   void setRmGlobal( const CLHEP::HepRotation& rm ){
00135     theRmGlob = rm; 
00136   }
00137 
00138   void setType( const ALIstring& type ) {
00139    theType = type; 
00140   }
00141   void addCoordinateEntryToList( Entry* entry ) {
00142      theCoordinateEntryVector.push_back( entry );
00143   }
00144   void addExtraEntryToList( Entry* entry ) {
00145      theExtraEntryVector.push_back( entry );
00146   }
00147   void addExtraEntryValueToList( ALIdouble entry_value ) {
00148      theExtraEntryValueVector.push_back( entry_value );
00149   }
00150   void addExtraEntryValueOriginalToList( ALIdouble entry_value ) {
00151      theExtraEntryValueOriginalVector.push_back( entry_value );
00152   }
00153   void addExtraEntryValueOriginalOriginalToList( ALIdouble entry_value ) {
00154      theExtraEntryValueOriginalOriginalVector.push_back( entry_value );
00155   }
00156 
00157 
00158   //-  void test(){};
00159   //@@@@@----- METHODS USED IN Fit
00160   //---------- Propagate the light ray with the behaviour 'behav'
00161   virtual void participateInMeasurement( LightRay& lightray, Measurement& meas, const ALIstring& behav );
00162   //---------- default behaviour (depends of subclass type). A default behaviour can be makeMeasurement(), therefore you have to pass 'meas'
00163   virtual void defaultBehaviour( LightRay& lightray, Measurement& meas );
00164   //---------- Fast simulation of deviation of the light ray (reflection, shift, ...)
00165   virtual void fastDeviatesLightRay( LightRay& lightray );
00166   //---------- Detailed simulation of the light ray traversing
00167   virtual void fastTraversesLightRay( LightRay& lightray );
00168   //---------- Detailed simulation of deviation of the light ray (reflection, shift, ...)
00169   virtual void detailedDeviatesLightRay( LightRay& lightray );
00170   //---------- Fast simulation of the light ray traversing
00171   virtual void detailedTraversesLightRay( LightRay& lightray );
00172 
00173   //---------- Fast simulation of the light ray traversing
00174   virtual void makeMeasurement( LightRay& lightray, Measurement& meas );
00175 
00176   //---------- User Defined Behaviour
00177   virtual void userDefinedBehaviour( LightRay& lightray, Measurement& meas, const ALIstring& behav);
00178 
00179   //---------- Obtain the Z Axis of the OptO (ZAxis rotated with the OptO rotation matrix)
00180   CLHEP::Hep3Vector getZAxis() {
00181     CLHEP::Hep3Vector ZAxis(0.,0.,1.);
00182     CLHEP::HepRotation rmt = rmGlob();
00183     ZAxis = rmt*ZAxis;
00184     return ZAxis;
00185   }
00186   //---------- Get one of the plates of an OptO made of two parallel plates
00187   ALIPlane getPlate(const ALIbool forwardPlate, const ALIbool applyWedge);
00188 
00189   //---------- Displacements to get the derivative of a measurement w.r.t an entry
00190   //----- Displace the centre coordinate 'coor'
00191   void displaceCentreGlob( const XYZcoor coor, const  ALIdouble disp);
00192   CLHEP::Hep3Vector getDisplacementInLocalCoordinates( const XYZcoor coor, const ALIdouble disp );
00193    void displaceCentreGlob( const CLHEP::Hep3Vector& dispVec);
00194   //----- Rotate around axis 'coor' 
00195   void displaceRmGlobAroundGlobal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
00196   void displaceRmGlobAroundLocal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
00197   //----- Displace extra entry number 'entryNo' 
00198   void displaceExtraEntry( const ALIuint entryNo, const ALIdouble disp);
00199   void setExtraEntryValue(const ALIuint entryNo, const ALIdouble disp);
00200 
00201   //----------- Displacements of original coordinates: do it to reset the original data 
00202   //----------- every new iteration of the non linear fit
00203   //----- Displace the centre coordinate 'coor'
00204   void displaceCentreGlobOriginal( const XYZcoor coor, const ALIdouble disp);
00205   void displaceCentreGlobOriginal( const CLHEP::Hep3Vector& dispVec);
00206   void displaceCentreGlobOriginalOriginal( const XYZcoor coor, const ALIdouble disp);
00207   void displaceCentreGlobOriginalOriginal( const CLHEP::Hep3Vector& dispVec);
00208   //----- Rotate around axis 'coor' 
00209   void displaceRmGlobOriginal( const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
00210   void displaceRmGlobOriginalOriginal( const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
00211   //----- Displace extra entry number 'entryNo' 
00212   void displaceExtraEntryOriginal( const ALIuint entryNo, const ALIdouble disp);
00213   void displaceExtraEntryOriginalOriginal( const ALIuint entryNo, const ALIdouble disp);
00214 
00215   //---------- Reset the global coordinates and extra entries (after derivative is finished)
00216   void resetGlobalCoordinates();
00217   void resetOriginalOriginalCoordinates();
00218 
00219   // Find position of an extra entry in ExtraEntryList (and therefore in ExtraEntryValueList)
00220   const ALIint extraEntryNo( const ALIstring& entry_name ) const;
00221 
00222   // //@@ Find an extra Entry by name and return its value. If entry not found, stop.
00223   const ALIdouble findExtraEntryValueMustExist( const ALIstring& eename ) const;  
00224   // Find an extra Entry by name and return its value, if it is not found return 0
00225   const ALIdouble findExtraEntryValue( const ALIstring& eename ) const;  
00226 
00227   // Find an extra Entry by name and pass its value. Return if entry is found or not
00228   const ALIbool findExtraEntryValueIfExists( const ALIstring& eename, ALIdouble& value ) const;
00229 
00230   // Return the name of the OptO without its path
00231   const ALIstring shortName() const;
00232   // Return the name of the OptO with its path
00233   const ALIstring longName() const{ 
00234     return name();
00235   }
00236 
00238   void setMeas( Measurement* meas ) {
00239     theCurrentMeas = meas;
00240   }
00241   Measurement* meas() {
00242     return theCurrentMeas;
00243   }
00244 
00245   std::vector<double> getRotationAnglesInOptOFrame( const OpticalObject* optoAncestor, std::vector< Entry* > entries ) const;
00246   std::vector<double> getLocalRotationAngles(  std::vector< Entry* > entries ) const;
00247   std::vector<double> getRotationAnglesFromMatrix( CLHEP::HepRotation& rmLocal, std::vector< Entry* > entries ) const;
00248   double diff2pi( double ang1, double ang2 );
00249   bool eq2ang( double ang1, double ang2 );
00250   double approxTo0( double val );
00251   double addPii( double val );
00252   int checkMatrixEquations( double angleX, double angleY, double angleZ, CLHEP::HepRotation* rot = 0);
00253 
00254   //-  CLHEP::Hep3Vector GetAxisForDisplacement( const XYZcoor coor );
00255   void setGlobalCoordinates();
00256   void setOriginalEntryValues();
00257 
00258  CocoaMaterialElementary* getMaterial() const {
00259    return theMaterial; }
00260  CocoaSolidShape* getSolidShape() const {
00261    return theSolidShape; }
00262 
00263   //private DATA METHODS
00264 private:
00265   // Reads the data 
00266   void readData( ALIFileIn& filein );
00267   // Copy the data from last OptO found of the same type
00268   void copyData();
00269 
00270   // Read extra entries
00271   void readExtraEntries( ALIFileIn& filein );
00272 
00273  protected:
00274   // Create and fill an extra entry
00275   virtual void fillExtraEntry( std::vector<ALIstring>& wordlist );
00276  private:
00277   // Read centre or angles
00278   void readCoordinates( const ALIstring& coor_type_read, const ALIstring& coor_type_expected, ALIFileIn& filein );
00279   // Create and fill a coordinate entry
00280   void fillCoordinateEntry( const ALIstring& coor_name, const std::vector<ALIstring>& wordlist );
00281   // Set angles null
00282   void setAnglesNull();
00283 
00284   //------ Build wordlist copying data of entry 'entry'
00285   void buildWordList( const Entry* entry, std::vector<ALIstring>& wordlist );
00286 
00287   // start Optical Objects that are components of current 
00288   void createComponentOptOs( ALIFileIn& filein );
00289 
00290   OpticalObject* createNewOptO( OpticalObject* parent, ALIstring optoType, ALIstring optoName, ALIbool fcopyComponents );
00291 
00292   // Set global centre and rotation matrix
00293   void setGlobalCentre();
00294   void setGlobalRM();
00295   void setGlobalCoordinatesOfComponents();
00296 
00297   void SetCentreLocalFromEntryValues();
00298   void SetCentreGlobFromCentreLocal();
00299   void SetRMLocalFromEntryValues();
00300   void SetRMGlobFromRMLocal();
00301   void SetRMGlobFromRMLocalOriginalOriginal( CLHEP::HepRotation rmoriori );
00302   // Calculate local rot axis with new rm glob
00303   void calculateLocalRotationAxisInGlobal();
00304 
00305   void transformCylindrical2Cartesian();
00306   void transformSpherical2Cartesian();
00307   void transformGlobal2Local();
00308 
00309 template<class T>
00310   void rotateItAroundGlobal( T& object, const XYZcoor coor, const double disp );
00311 
00312  CLHEP::Hep3Vector getDispVec( const XYZcoor coor, const ALIdouble disp);
00313 
00314  void SetCentreIsGlobal( ALIbool isG ) {
00315    centreIsGlobal = isG; }
00316  void SetAnglesIsGlobal( ALIbool isG ) {
00317    anglesIsGlobal = isG; }
00318 
00319 private:
00320   // private DATA MEMBERS 
00321   OpticalObject* theParent;
00322   ALIstring theType;
00323   ALIstring theName;  
00324   //----- Boolean to mark if data is going to be read or copied from closest previous OptO with same type
00325   ALIbool fcopyData;
00326 
00327   //----- Global centre and rotation matrix
00328   CLHEP::Hep3Vector theCentreGlob;
00329   CLHEP::HepRotation theRmGlob;
00330   //----- Original global centre and rotation matrix (for backup when they are changed to get derivatives)
00331   CLHEP::Hep3Vector theCentreGlobOriginal;
00332   CLHEP::HepRotation theRmGlobOriginal;
00333   CLHEP::Hep3Vector theCentreGlobOriginalOriginal;
00334   CLHEP::HepRotation theRmGlobOriginalOriginal;
00335 
00336   // Lists of entries
00337   std::vector< Entry* > theCoordinateEntryVector;
00338   std::vector< Entry* > theExtraEntryVector;
00339 
00340   // Lists of values of entries
00341   std::vector< ALIdouble > theExtraEntryValueVector;
00342   std::vector< ALIdouble > theExtraEntryValueOriginalVector;
00343   std::vector< ALIdouble > theExtraEntryValueOriginalOriginalVector;
00344 
00345   // centre and angles are global
00346   ALIbool centreIsGlobal;
00347   ALIbool anglesIsGlobal;
00348 
00349   Measurement* theCurrentMeas;
00350 
00351   CLHEP::Hep3Vector axisXLocalInGlobal;
00352   CLHEP::Hep3Vector axisYLocalInGlobal;
00353   CLHEP::Hep3Vector axisZLocalInGlobal;
00354 
00355   ALIuint theCmsswID;
00356 
00357  protected:
00358   CocoaMaterialElementary* theMaterial;
00359   CocoaSolidShape* theSolidShape;
00360 
00361   ALIint verbose;
00362 };
00363 
00364 #endif