CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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; }
112  void addExtraEntryToList(Entry* entry) { theExtraEntryVector.push_back(entry); }
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 getEntryRMangle(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()
ALIbool anglesIsGlobal
void setMeas(Measurement *meas)
set current measurement
long double ALIdouble
Definition: CocoaGlobals.h:11
const ALIuint getCmsswID() const
Definition: OpticalObject.h:97
const std::vector< ALIdouble > & ExtraEntryValueOriginalOriginalList()
Definition: OpticalObject.h:70
void resetGlobalCoordinates()
double approxTo0(double val)
void transformCylindrical2Cartesian()
CLHEP::HepRotation theRmGlob
const edm::EventSetup & c
CLHEP::HepRotation buildRmFromEntryValuesOriginalOriginal()
void displaceExtraEntryOriginal(const ALIuint entryNo, const ALIdouble disp)
CocoaMaterialElementary * getMaterial() const
ALIstring theName
void setID(ALIuint id)
Definition: OpticalObject.h:99
virtual void defaultBehaviour(LightRay &lightray, Measurement &meas)
CocoaSolidShape * theSolidShape
void SetCentreLocalFromEntryValues()
uint16_t *__restrict__ id
virtual void fastDeviatesLightRay(LightRay &lightray)
void setRmGlobalOriginal(const CLHEP::HepRotation &rm)
const ALIdouble findExtraEntryValueMustExist(const ALIstring &eename) const
virtual void userDefinedBehaviour(LightRay &lightray, Measurement &meas, const ALIstring &behav)
void addExtraEntryToList(Entry *entry)
Definition: Entry.h:18
OpticalObject * createNewOptO(OpticalObject *parent, ALIstring optoType, ALIstring optoName, ALIbool fcopyComponents)
const CLHEP::HepRotation rmLocal() const
void displaceCentreGlobOriginal(const XYZcoor coor, const ALIdouble disp)
void displaceRmGlobOriginalOriginal(const OpticalObject *opto1stRotated, const XYZcoor coor, const ALIdouble disp)
virtual void fillVRML()
Definition: OpticalObject.h:54
const ALIbool findExtraEntryValueIfExists(const ALIstring &eename, ALIdouble &value) const
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
virtual void makeMeasurement(LightRay &lightray, Measurement &meas)
void addExtraEntryValueToList(ALIdouble entry_value)
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:63
std::vector< double > getRotationAnglesInOptOFrame(const OpticalObject *optoAncestor, const std::vector< Entry * > &entries) const
const std::vector< ALIdouble > & ExtraEntryValueOriginalList()
Definition: OpticalObject.h:69
XYZcoor
Definition: OpticalObject.h:33
const CLHEP::HepRotation & rmGlob() const
Definition: OpticalObject.h:83
void displaceRmGlobAroundGlobal(OpticalObject *opto1stRotated, const XYZcoor coor, const ALIdouble disp)
void setOriginalEntryValues()
void setGlobalCoordinatesOfComponents()
bool eq2ang(double ang1, double ang2)
void addExtraEntryValueOriginalToList(ALIdouble entry_value)
bool ALIbool
Definition: CocoaGlobals.h:19
const CLHEP::HepRotation & rmGlobOriginalOriginal() const
Definition: OpticalObject.h:88
void setExtraEntryValue(const ALIuint entryNo, const ALIdouble disp)
std::vector< double > getLocalRotationAngles(const std::vector< Entry * > &entries) const
ALIuint theCmsswID
void calculateLocalRotationAxisInGlobal()
const CLHEP::Hep3Vector centreLocal() 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)
const OpticalObject * parent() const
Definition: OpticalObject.h:60
virtual void constructSolidShape()
void setAnglesNull()
std::vector< Entry * > theExtraEntryVector
double addPii(double val)
const CLHEP::Hep3Vector & centreGlobOriginal() const
Definition: OpticalObject.h:81
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
const ALIdouble findExtraEntryValue(const ALIstring &eename) const
ALIstring theType
CLHEP::Hep3Vector getDisplacementInLocalCoordinates(const XYZcoor coor, const ALIdouble disp)
virtual void fastTraversesLightRay(LightRay &lightray)
void displaceExtraEntryOriginalOriginal(const ALIuint entryNo, const ALIdouble disp)
const ALIstring longName() const
void addExtraEntryValueOriginalOriginalToList(ALIdouble entry_value)
std::vector< ALIdouble > theExtraEntryValueOriginalVector
std::vector< ALIstring > getCoordinateFromOptAlignParam(const OpticalAlignParam &oaParam)
virtual void fillExtraEntry(std::vector< ALIstring > &wordlist)
void setCmsswID(ALIuint id)
Definition: OpticalObject.h:98
const CLHEP::HepRotation & rmGlobOriginal() const
Definition: OpticalObject.h:87
void readCoordinates(const ALIstring &coor_type_read, const ALIstring &coor_type_expected, ALIFileIn &filein)
void SetAnglesIsGlobal(ALIbool isG)
std::vector< Entry * > theCoordinateEntryVector
const double getEntryCentre(const XYZcoor coor) const
void resetOriginalOriginalCoordinates()
OpticalObject * theParent
CLHEP::Hep3Vector axisYLocalInGlobal
CocoaMaterialElementary * theMaterial
void buildWordList(const Entry *entry, std::vector< ALIstring > &wordlist)
const ALIint extraEntryNo(const ALIstring &entry_name) const
CLHEP::Hep3Vector getZAxis()
ALIbool fcopyData
void propagateGlobalRMOriginalOriginalChangeToChildren(const CLHEP::HepRotation &rmorioriold, const CLHEP::HepRotation &rmoriorinew)
virtual void fillIguana()
Definition: OpticalObject.h:55
const CLHEP::Hep3Vector & centreGlobOriginalOriginal() const
Definition: OpticalObject.h:82
void setGlobalCentre()
friend std::ostream & operator<<(std::ostream &os, const OpticalObject &c)
virtual ~OpticalObject()
CocoaSolidShape * getSolidShape() const
Measurement * meas()
void SetCentreGlobFromCentreLocal()
const CLHEP::Hep3Vector & centreGlob() const
Definition: OpticalObject.h:75
ALIPlane getPlate(const ALIbool forwardPlate, const ALIbool applyWedge)
const ALIuint ID() const
Definition: OpticalObject.h:96
ALIbool centreIsGlobal
void displaceExtraEntry(const ALIuint entryNo, const ALIdouble disp)
std::vector< ALIdouble > & ExtraEntryValueList()
Definition: OpticalObject.h:67
virtual void detailedDeviatesLightRay(LightRay &lightray)
const ALIstring shortName() const
const CLHEP::Hep3Vector & centreGlobal() const
Definition: OpticalObject.h:77
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)
list entry
Definition: mps_splice.py:68
double diff2pi(double ang1, double ang2)
void setType(const ALIstring &type)
virtual void participateInMeasurement(LightRay &lightray, Measurement &meas, const ALIstring &behav)
CLHEP::Hep3Vector axisXLocalInGlobal
std::vector< double > getRotationAnglesFromMatrix(CLHEP::HepRotation &rmLocal, const std::vector< Entry * > &entries) const
void readExtraEntries(ALIFileIn &filein)
def rm
Definition: eostools.py:363
const ALIstring & name() const
Definition: OpticalObject.h:58
void createComponentOptOs(ALIFileIn &filein)
virtual void detailedTraversesLightRay(LightRay &lightray)
void createComponentOptOsFromOptAlignInfo()
void SetRMGlobFromRMLocalOriginalOriginal(const CLHEP::HepRotation &rmoriori)
long double T
virtual void constructMaterial()
CLHEP::Hep3Vector theCentreGlob
void addCoordinateEntryToList(Entry *entry)
const std::vector< Entry * > & ExtraEntryList() const
Definition: OpticalObject.h:65
void setGlobalCoordinates()
CLHEP::Hep3Vector axisZLocalInGlobal
unsigned int ALIuint
Definition: CocoaGlobals.h:17
const ALIstring & type() const
Definition: OpticalObject.h:59
void setRmGlobal(const CLHEP::HepRotation &rm)