CMS 3D CMS Logo

OpticalObject.h
Go to the documentation of this file.
1 // COCOA class header file
2 //Id: OpticalObject.h
3 //CAT: Model
4 //
5 // Base class to describe all types of Optical Objects
6 //
7 // History: v1.0
8 // Pedro Arce
9 
10 #ifndef _OPTICALOBJECT_HH
11 #define _OPTICALOBJECT_HH
12 
14 #include <cstdint>
15 
16 class LightRay;
17 class Measurement;
18 class Entry;
19 class ALIFileIn;
20 class Measurement;
21 class ALIPlane;
22 
24 class CocoaSolidShape;
25 
26 #include "CLHEP/Vector/ThreeVector.h"
27 #include "CLHEP/Vector/Rotation.h"
28 #include <fstream>
29 #include <vector>
30 class OpticalAlignInfo;
31 class OpticalAlignParam;
32 
33 enum XYZcoor { XCoor, YCoor, ZCoor };
34 
36  friend std::ostream& operator<<(std::ostream& os, const OpticalObject& c);
37 
38 public:
39  //---------- Constructors / destructor
41  OpticalObject(OpticalObject* parent, const ALIstring& type, const ALIstring& name, const ALIbool copy_data);
42  virtual ~OpticalObject();
43 
44  //----- Steering function to read OptO data from SDF file (and also start component OptOs)
45  void construct();
46 
47  void constructFromOptAligInfo(const OpticalAlignInfo& oaInfo);
48  std::vector<ALIstring> getCoordinateFromOptAlignParam(const OpticalAlignParam& oaParam);
50 
51  virtual void constructMaterial();
52  virtual void constructSolidShape();
53 
54  virtual void fillVRML(){};
55  virtual void fillIguana(){};
56 
57  // ACCESS DATA MEMBERS
58  const ALIstring& name() const { return theName; };
59  const ALIstring& type() const { return theType; };
60  const OpticalObject* parent() const { return theParent; };
61 
62  // Return List of Coordinate Entries
63  const std::vector<Entry*>& CoordinateEntryList() const { return theCoordinateEntryVector; }
64  // Return List of Extra Entries
65  const std::vector<Entry*>& ExtraEntryList() const { return theExtraEntryVector; }
66  // Return List of Extra Entry Values
67  std::vector<ALIdouble>& ExtraEntryValueList() { return theExtraEntryValueVector; }
68 
69  const std::vector<ALIdouble>& ExtraEntryValueOriginalList() { return theExtraEntryValueOriginalVector; }
70  const std::vector<ALIdouble>& ExtraEntryValueOriginalOriginalList() {
72  }
73 
74  // ACCESS CENTRE AND ROTATION DATA MEMBERS
75  const CLHEP::Hep3Vector& centreGlob() const { return theCentreGlob; }
76 
77  const CLHEP::Hep3Vector& centreGlobal() const { return centreGlob(); }
78 
79  const CLHEP::Hep3Vector centreLocal() const;
80 
81  const CLHEP::Hep3Vector& centreGlobOriginal() const { return theCentreGlobOriginal; }
82  const CLHEP::Hep3Vector& centreGlobOriginalOriginal() const { return theCentreGlobOriginalOriginal; }
83  const CLHEP::HepRotation& rmGlob() const { return theRmGlob; }
84 
85  const CLHEP::HepRotation rmLocal() const;
86 
87  const CLHEP::HepRotation& rmGlobOriginal() const { return theRmGlobOriginal; }
88  const CLHEP::HepRotation& rmGlobOriginalOriginal() const { return theRmGlobOriginalOriginal; }
89 
90  const double getEntryCentre(const XYZcoor coor) const;
91  const double getEntryCentre(const ALIstring& coor) const;
92 
93  const double getEntryRMangle(const XYZcoor coor) const;
94  const double getEntryRMangle(const ALIstring& coor) const;
95 
96  const ALIuint ID() const { return theCmsswID; }
97  const ALIuint getCmsswID() const { return theCmsswID; }
98  void setCmsswID(ALIuint id) { theCmsswID = id; }
99  void setID(ALIuint id) { theCmsswID = id; }
100 
101  // SET DATA METHODS
102  void setRmGlobalOriginal(const CLHEP::HepRotation& rm) { theRmGlobOriginal = rm; }
103  void setGlobalRMOriginalOriginal(const CLHEP::HepRotation& rmoriori);
104  void propagateGlobalRMOriginalOriginalChangeToChildren(const CLHEP::HepRotation& rmorioriold,
105  const CLHEP::HepRotation& rmoriorinew);
106  CLHEP::HepRotation buildRmFromEntryValuesOriginalOriginal();
107 
108  void setRmGlobal(const CLHEP::HepRotation& rm) { theRmGlob = rm; }
109 
110  void setType(const ALIstring& type) { theType = type; }
113  void addExtraEntryValueToList(ALIdouble entry_value) { theExtraEntryValueVector.push_back(entry_value); }
115  theExtraEntryValueOriginalVector.push_back(entry_value);
116  }
118  theExtraEntryValueOriginalOriginalVector.push_back(entry_value);
119  }
120 
121  //- void test(){};
122  //@@@@@----- METHODS USED IN Fit
123  //---------- Propagate the light ray with the behaviour 'behav'
124  virtual void participateInMeasurement(LightRay& lightray, Measurement& meas, const ALIstring& behav);
125  //---------- default behaviour (depends of subclass type). A default behaviour can be makeMeasurement(), therefore you have to pass 'meas'
126  virtual void defaultBehaviour(LightRay& lightray, Measurement& meas);
127  //---------- Fast simulation of deviation of the light ray (reflection, shift, ...)
128  virtual void fastDeviatesLightRay(LightRay& lightray);
129  //---------- Detailed simulation of the light ray traversing
130  virtual void fastTraversesLightRay(LightRay& lightray);
131  //---------- Detailed simulation of deviation of the light ray (reflection, shift, ...)
132  virtual void detailedDeviatesLightRay(LightRay& lightray);
133  //---------- Fast simulation of the light ray traversing
134  virtual void detailedTraversesLightRay(LightRay& lightray);
135 
136  //---------- Fast simulation of the light ray traversing
137  virtual void makeMeasurement(LightRay& lightray, Measurement& meas);
138 
139  //---------- User Defined Behaviour
140  virtual void userDefinedBehaviour(LightRay& lightray, Measurement& meas, const ALIstring& behav);
141 
142  //---------- Obtain the Z Axis of the OptO (ZAxis rotated with the OptO rotation matrix)
143  CLHEP::Hep3Vector getZAxis() {
144  CLHEP::Hep3Vector ZAxis(0., 0., 1.);
145  CLHEP::HepRotation rmt = rmGlob();
146  ZAxis = rmt * ZAxis;
147  return ZAxis;
148  }
149  //---------- Get one of the plates of an OptO made of two parallel plates
150  ALIPlane getPlate(const ALIbool forwardPlate, const ALIbool applyWedge);
151 
152  //---------- Displacements to get the derivative of a measurement w.r.t an entry
153  //----- Displace the centre coordinate 'coor'
154  void displaceCentreGlob(const XYZcoor coor, const ALIdouble disp);
155  CLHEP::Hep3Vector getDisplacementInLocalCoordinates(const XYZcoor coor, const ALIdouble disp);
156  void displaceCentreGlob(const CLHEP::Hep3Vector& dispVec);
157  //----- Rotate around axis 'coor'
158  void displaceRmGlobAroundGlobal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
159  void displaceRmGlobAroundLocal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
160  //----- Displace extra entry number 'entryNo'
161  void displaceExtraEntry(const ALIuint entryNo, const ALIdouble disp);
162  void setExtraEntryValue(const ALIuint entryNo, const ALIdouble disp);
163 
164  //----------- Displacements of original coordinates: do it to reset the original data
165  //----------- every new iteration of the non linear fit
166  //----- Displace the centre coordinate 'coor'
167  void displaceCentreGlobOriginal(const XYZcoor coor, const ALIdouble disp);
168  void displaceCentreGlobOriginal(const CLHEP::Hep3Vector& dispVec);
169  void displaceCentreGlobOriginalOriginal(const XYZcoor coor, const ALIdouble disp);
170  void displaceCentreGlobOriginalOriginal(const CLHEP::Hep3Vector& dispVec);
171  //----- Rotate around axis 'coor'
172  void displaceRmGlobOriginal(const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
173  void displaceRmGlobOriginalOriginal(const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
174  //----- Displace extra entry number 'entryNo'
175  void displaceExtraEntryOriginal(const ALIuint entryNo, const ALIdouble disp);
176  void displaceExtraEntryOriginalOriginal(const ALIuint entryNo, const ALIdouble disp);
177 
178  //---------- Reset the global coordinates and extra entries (after derivative is finished)
179  void resetGlobalCoordinates();
181 
182  // Find position of an extra entry in ExtraEntryList (and therefore in ExtraEntryValueList)
183  const ALIint extraEntryNo(const ALIstring& entry_name) const;
184 
185  // //@@ Find an extra Entry by name and return its value. If entry not found, stop.
186  const ALIdouble findExtraEntryValueMustExist(const ALIstring& eename) const;
187  // Find an extra Entry by name and return its value, if it is not found return 0
188  const ALIdouble findExtraEntryValue(const ALIstring& eename) const;
189 
190  // Find an extra Entry by name and pass its value. Return if entry is found or not
191  const ALIbool findExtraEntryValueIfExists(const ALIstring& eename, ALIdouble& value) const;
192 
193  // Return the name of the OptO without its path
194  const ALIstring shortName() const;
195  // Return the name of the OptO with its path
196  const ALIstring longName() const { return name(); }
197 
201 
202  std::vector<double> getRotationAnglesInOptOFrame(const OpticalObject* optoAncestor,
203  const std::vector<Entry*>& entries) const;
204  std::vector<double> getLocalRotationAngles(const std::vector<Entry*>& entries) const;
205  std::vector<double> getRotationAnglesFromMatrix(CLHEP::HepRotation& rmLocal,
206  const std::vector<Entry*>& entries) const;
207  double diff2pi(double ang1, double ang2);
208  bool eq2ang(double ang1, double ang2);
209  double approxTo0(double val);
210  double addPii(double val);
211  int checkMatrixEquations(double angleX, double angleY, double angleZ, CLHEP::HepRotation* rot = nullptr);
212 
213  //- CLHEP::Hep3Vector GetAxisForDisplacement( const XYZcoor coor );
214  void setGlobalCoordinates();
215  void setOriginalEntryValues();
216 
219 
220  //private DATA METHODS
221 private:
222  // Reads the data
223  void readData(ALIFileIn& filein);
224  // Copy the data from last OptO found of the same type
225  void copyData();
226 
227  // Read extra entries
228  void readExtraEntries(ALIFileIn& filein);
229 
230 protected:
231  // Create and fill an extra entry
232  virtual void fillExtraEntry(std::vector<ALIstring>& wordlist);
233 
234 private:
235  // Read centre or angles
236  void readCoordinates(const ALIstring& coor_type_read, const ALIstring& coor_type_expected, ALIFileIn& filein);
237  // Create and fill a coordinate entry
238  void fillCoordinateEntry(const ALIstring& coor_name, const std::vector<ALIstring>& wordlist);
239  // Set angles null
240  void setAnglesNull();
241 
242  //------ Build wordlist copying data of entry 'entry'
243  void buildWordList(const Entry* entry, std::vector<ALIstring>& wordlist);
244 
245  // start Optical Objects that are components of current
246  void createComponentOptOs(ALIFileIn& filein);
247 
248  OpticalObject* createNewOptO(OpticalObject* parent, ALIstring optoType, ALIstring optoName, ALIbool fcopyComponents);
249 
250  // Set global centre and rotation matrix
251  void setGlobalCentre();
252  void setGlobalRM();
254 
258  void SetRMGlobFromRMLocal();
259  void SetRMGlobFromRMLocalOriginalOriginal(const CLHEP::HepRotation& rmoriori);
260  // Calculate local rot axis with new rm glob
262 
265  void transformGlobal2Local();
266 
267  template <class T>
268  void rotateItAroundGlobal(T& object, const XYZcoor coor, const double disp);
269 
270  CLHEP::Hep3Vector getDispVec(const XYZcoor coor, const ALIdouble disp);
271 
274 
275 private:
276  // private DATA MEMBERS
280  //----- Boolean to mark if data is going to be read or copied from closest previous OptO with same type
282 
283  //----- Global centre and rotation matrix
284  CLHEP::Hep3Vector theCentreGlob;
285  CLHEP::HepRotation theRmGlob;
286  //----- Original global centre and rotation matrix (for backup when they are changed to get derivatives)
287  CLHEP::Hep3Vector theCentreGlobOriginal;
288  CLHEP::HepRotation theRmGlobOriginal;
289  CLHEP::Hep3Vector theCentreGlobOriginalOriginal;
290  CLHEP::HepRotation theRmGlobOriginalOriginal;
291 
292  // Lists of entries
293  std::vector<Entry*> theCoordinateEntryVector;
294  std::vector<Entry*> theExtraEntryVector;
295 
296  // Lists of values of entries
297  std::vector<ALIdouble> theExtraEntryValueVector;
298  std::vector<ALIdouble> theExtraEntryValueOriginalVector;
300 
301  // centre and angles are global
304 
306 
307  CLHEP::Hep3Vector axisXLocalInGlobal;
308  CLHEP::Hep3Vector axisYLocalInGlobal;
309  CLHEP::Hep3Vector axisZLocalInGlobal;
310 
312 
313 protected:
316 
318 };
319 
320 #endif
const double getEntryCentre(const XYZcoor coor) const
void fillCoordinateEntry(const ALIstring &coor_name, const std::vector< ALIstring > &wordlist)
void setGlobalRMOriginalOriginal(const CLHEP::HepRotation &rmoriori)
std::vector< ALIdouble > theExtraEntryValueVector
void transformGlobal2Local()
const ALIdouble findExtraEntryValue(const ALIstring &eename) const
def rm(path, rec=False)
Definition: eostools.py:363
ALIbool anglesIsGlobal
void setMeas(Measurement *meas)
set current measurement
const CLHEP::Hep3Vector & centreGlob() const
Definition: OpticalObject.h:75
long double ALIdouble
Definition: CocoaGlobals.h:11
const std::vector< ALIdouble > & ExtraEntryValueOriginalOriginalList()
Definition: OpticalObject.h:70
void resetGlobalCoordinates()
double approxTo0(double val)
void transformCylindrical2Cartesian()
CLHEP::HepRotation theRmGlob
CLHEP::HepRotation buildRmFromEntryValuesOriginalOriginal()
void displaceExtraEntryOriginal(const ALIuint entryNo, const ALIdouble disp)
ALIstring theName
void setID(ALIuint id)
Definition: OpticalObject.h:99
const CLHEP::Hep3Vector & centreGlobal() const
Definition: OpticalObject.h:77
virtual void defaultBehaviour(LightRay &lightray, Measurement &meas)
CocoaSolidShape * theSolidShape
void SetCentreLocalFromEntryValues()
virtual void fastDeviatesLightRay(LightRay &lightray)
void setRmGlobalOriginal(const CLHEP::HepRotation &rm)
virtual void userDefinedBehaviour(LightRay &lightray, Measurement &meas, const ALIstring &behav)
void addExtraEntryToList(Entry *entry)
Definition: Entry.h:18
std::vector< double > getRotationAnglesInOptOFrame(const OpticalObject *optoAncestor, const std::vector< Entry *> &entries) const
OpticalObject * createNewOptO(OpticalObject *parent, ALIstring optoType, ALIstring optoName, ALIbool fcopyComponents)
void displaceCentreGlobOriginal(const XYZcoor coor, const ALIdouble disp)
CocoaMaterialElementary * getMaterial() const
void displaceRmGlobOriginalOriginal(const OpticalObject *opto1stRotated, const XYZcoor coor, const ALIdouble disp)
std::vector< double > getRotationAnglesFromMatrix(CLHEP::HepRotation &rmLocal, const std::vector< Entry *> &entries) const
virtual void fillVRML()
Definition: OpticalObject.h:54
const CLHEP::Hep3Vector & centreGlobOriginal() const
Definition: OpticalObject.h:81
void SetCentreIsGlobal(ALIbool isG)
int ALIint
Definition: CocoaGlobals.h:15
std::vector< ALIdouble > theExtraEntryValueOriginalOriginalVector
void displaceCentreGlobOriginalOriginal(const XYZcoor coor, const ALIdouble disp)
CLHEP::HepRotation theRmGlobOriginalOriginal
const ALIstring shortName() const
const ALIstring & name() const
Definition: OpticalObject.h:58
const CLHEP::Hep3Vector & centreGlobOriginalOriginal() const
Definition: OpticalObject.h:82
virtual void makeMeasurement(LightRay &lightray, Measurement &meas)
void addExtraEntryValueToList(ALIdouble entry_value)
const ALIbool findExtraEntryValueIfExists(const ALIstring &eename, ALIdouble &value) const
const std::vector< ALIdouble > & ExtraEntryValueOriginalList()
Definition: OpticalObject.h:69
const ALIstring longName() const
XYZcoor
Definition: OpticalObject.h:33
void displaceRmGlobAroundGlobal(OpticalObject *opto1stRotated, const XYZcoor coor, const ALIdouble disp)
const std::vector< Entry * > & ExtraEntryList() const
Definition: OpticalObject.h:65
void setOriginalEntryValues()
void setGlobalCoordinatesOfComponents()
bool eq2ang(double ang1, double ang2)
void addExtraEntryValueOriginalToList(ALIdouble entry_value)
bool ALIbool
Definition: CocoaGlobals.h:19
void setExtraEntryValue(const ALIuint entryNo, const ALIdouble disp)
ALIuint theCmsswID
void calculateLocalRotationAxisInGlobal()
const ALIint extraEntryNo(const ALIstring &entry_name) const
std::vector< double > getLocalRotationAngles(const std::vector< Entry *> &entries) const
void displaceRmGlobAroundLocal(OpticalObject *opto1stRotated, const XYZcoor coor, const ALIdouble disp)
void readData(ALIFileIn &filein)
Measurement * theCurrentMeas
CLHEP::Hep3Vector theCentreGlobOriginal
void displaceCentreGlob(const XYZcoor coor, const ALIdouble disp)
virtual void constructSolidShape()
void setAnglesNull()
std::vector< Entry * > theExtraEntryVector
const CLHEP::HepRotation rmLocal() const
double addPii(double val)
void SetRMGlobFromRMLocal()
CLHEP::HepRotation theRmGlobOriginal
void rotateItAroundGlobal(T &object, const XYZcoor coor, const double disp)
void displaceRmGlobOriginal(const OpticalObject *opto1stRotated, const XYZcoor coor, const ALIdouble disp)
CLHEP::Hep3Vector theCentreGlobOriginalOriginal
Definition: value.py:1
ALIstring theType
CLHEP::Hep3Vector getDisplacementInLocalCoordinates(const XYZcoor coor, const ALIdouble disp)
virtual void fastTraversesLightRay(LightRay &lightray)
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:63
const CLHEP::HepRotation & rmGlobOriginalOriginal() const
Definition: OpticalObject.h:88
void displaceExtraEntryOriginalOriginal(const ALIuint entryNo, const ALIdouble disp)
void addExtraEntryValueOriginalOriginalToList(ALIdouble entry_value)
std::vector< ALIdouble > theExtraEntryValueOriginalVector
std::vector< ALIstring > getCoordinateFromOptAlignParam(const OpticalAlignParam &oaParam)
const ALIuint ID() const
Definition: OpticalObject.h:96
virtual void fillExtraEntry(std::vector< ALIstring > &wordlist)
CocoaSolidShape * getSolidShape() const
void setCmsswID(ALIuint id)
Definition: OpticalObject.h:98
void readCoordinates(const ALIstring &coor_type_read, const ALIstring &coor_type_expected, ALIFileIn &filein)
void SetAnglesIsGlobal(ALIbool isG)
std::vector< Entry * > theCoordinateEntryVector
void resetOriginalOriginalCoordinates()
const CLHEP::HepRotation & rmGlob() const
Definition: OpticalObject.h:83
OpticalObject * theParent
CLHEP::Hep3Vector axisYLocalInGlobal
CocoaMaterialElementary * theMaterial
void buildWordList(const Entry *entry, std::vector< ALIstring > &wordlist)
CLHEP::Hep3Vector getZAxis()
ALIbool fcopyData
void propagateGlobalRMOriginalOriginalChangeToChildren(const CLHEP::HepRotation &rmorioriold, const CLHEP::HepRotation &rmoriorinew)
virtual void fillIguana()
Definition: OpticalObject.h:55
void setGlobalCentre()
friend std::ostream & operator<<(std::ostream &os, const OpticalObject &c)
virtual ~OpticalObject()
Measurement * meas()
void SetCentreGlobFromCentreLocal()
const CLHEP::Hep3Vector centreLocal() const
ALIPlane getPlate(const ALIbool forwardPlate, const ALIbool applyWedge)
ALIbool centreIsGlobal
void displaceExtraEntry(const ALIuint entryNo, const ALIdouble disp)
std::vector< ALIdouble > & ExtraEntryValueList()
Definition: OpticalObject.h:67
const ALIdouble findExtraEntryValueMustExist(const ALIstring &eename) const
virtual void detailedDeviatesLightRay(LightRay &lightray)
CLHEP::Hep3Vector getDispVec(const XYZcoor coor, const ALIdouble disp)
void transformSpherical2Cartesian()
std::string ALIstring
Definition: CocoaGlobals.h:9
void SetRMLocalFromEntryValues()
int checkMatrixEquations(double angleX, double angleY, double angleZ, CLHEP::HepRotation *rot=nullptr)
void constructFromOptAligInfo(const OpticalAlignInfo &oaInfo)
const OpticalObject * parent() const
Definition: OpticalObject.h:60
double diff2pi(double ang1, double ang2)
void setType(const ALIstring &type)
virtual void participateInMeasurement(LightRay &lightray, Measurement &meas, const ALIstring &behav)
CLHEP::Hep3Vector axisXLocalInGlobal
void readExtraEntries(ALIFileIn &filein)
const double getEntryRMangle(const XYZcoor coor) const
void createComponentOptOs(ALIFileIn &filein)
virtual void detailedTraversesLightRay(LightRay &lightray)
void createComponentOptOsFromOptAlignInfo()
const CLHEP::HepRotation & rmGlobOriginal() const
Definition: OpticalObject.h:87
void SetRMGlobFromRMLocalOriginalOriginal(const CLHEP::HepRotation &rmoriori)
long double T
virtual void constructMaterial()
CLHEP::Hep3Vector theCentreGlob
void addCoordinateEntryToList(Entry *entry)
void setGlobalCoordinates()
CLHEP::Hep3Vector axisZLocalInGlobal
const ALIstring & type() const
Definition: OpticalObject.h:59
unsigned int ALIuint
Definition: CocoaGlobals.h:17
const ALIuint getCmsswID() const
Definition: OpticalObject.h:97
void setRmGlobal(const CLHEP::HepRotation &rm)