CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
34 
36 {
37  friend std::ostream& operator << (std::ostream& os, const OpticalObject& c);
38 
39  public:
40  //---------- Constructors / destructor
42  OpticalObject(OpticalObject* parent, const ALIstring& type, const ALIstring& name, const ALIbool copy_data);
43  virtual ~OpticalObject();
44 
45  //----- Steering function to read OptO data from SDF file (and also start component OptOs)
46  void construct();
47 
48  void constructFromOptAligInfo( const OpticalAlignInfo& oaInfo );
49  std::vector<ALIstring> getCoordinateFromOptAlignParam( const OpticalAlignParam& oaParam );
51 
52  virtual void constructMaterial();
53  virtual void constructSolidShape();
54 
55  virtual void fillVRML(){ } ;
56  virtual void fillIguana(){ };
57 
58 
59  // ACCESS DATA MEMBERS
60  const ALIstring& name() const{ return theName; };
61  const ALIstring& type() const{ return theType; };
62  const OpticalObject* parent() const{ return theParent;};
63 
64  // Return List of Coordinate Entries
65  const std::vector< Entry* >& CoordinateEntryList() const {
67  }
68  // Return List of Extra Entries
69  const std::vector< Entry* >& ExtraEntryList() const {
70  return theExtraEntryVector;
71  }
72  // Return List of Extra Entry Values
73  std::vector< ALIdouble >& ExtraEntryValueList() {
75  }
76 
77  const std::vector< ALIdouble >& ExtraEntryValueOriginalList() {
79  }
80  const std::vector< ALIdouble >& ExtraEntryValueOriginalOriginalList() {
82  }
83 
84  // ACCESS CENTRE AND ROTATION DATA MEMBERS
85  const CLHEP::Hep3Vector& centreGlob() const {
86  return theCentreGlob;
87  }
88 
89  const CLHEP::Hep3Vector& centreGlobal() const {
90  return centreGlob();
91  }
92 
93  const CLHEP::Hep3Vector centreLocal() const;
94 
95  const CLHEP::Hep3Vector& centreGlobOriginal() const {
96  return theCentreGlobOriginal;
97  }
98  const CLHEP::Hep3Vector& centreGlobOriginalOriginal() const {
100  }
101  const CLHEP::HepRotation& rmGlob() const {
102  return theRmGlob;
103  }
104 
105  const CLHEP::HepRotation rmLocal() const;
106 
107  const CLHEP::HepRotation& rmGlobOriginal() const {
108  return theRmGlobOriginal;
109  }
110  const CLHEP::HepRotation& rmGlobOriginalOriginal() const {
112  }
113 
114 
115  const double getEntryCentre( const XYZcoor coor ) const;
116  const double getEntryCentre( const ALIstring& coor ) const;
117 
118  const double getEntryRMangle( const XYZcoor coor ) const;
119  const double getEntryRMangle( const ALIstring& coor ) const;
120 
121  const ALIuint ID() const { return theCmsswID; }
122  const ALIuint getCmsswID() const { return theCmsswID; }
123  void setCmsswID( ALIuint id ){ theCmsswID = id; }
124  void setID( ALIuint id ) { theCmsswID = id; }
125 
126  // SET DATA METHODS
127  void setRmGlobalOriginal( const CLHEP::HepRotation& rm ){
129  }
130  void setGlobalRMOriginalOriginal(const CLHEP::HepRotation& rmoriori );
131  void propagateGlobalRMOriginalOriginalChangeToChildren( const CLHEP::HepRotation& rmorioriold, const CLHEP::HepRotation& rmoriorinew );
132  CLHEP::HepRotation buildRmFromEntryValuesOriginalOriginal();
133 
134  void setRmGlobal( const CLHEP::HepRotation& rm ){
135  theRmGlob = rm;
136  }
137 
138  void setType( const ALIstring& type ) {
139  theType = type;
140  }
142  theCoordinateEntryVector.push_back( entry );
143  }
144  void addExtraEntryToList( Entry* entry ) {
145  theExtraEntryVector.push_back( entry );
146  }
147  void addExtraEntryValueToList( ALIdouble entry_value ) {
148  theExtraEntryValueVector.push_back( entry_value );
149  }
151  theExtraEntryValueOriginalVector.push_back( entry_value );
152  }
154  theExtraEntryValueOriginalOriginalVector.push_back( entry_value );
155  }
156 
157 
158  //- void test(){};
159  //@@@@@----- METHODS USED IN Fit
160  //---------- Propagate the light ray with the behaviour 'behav'
161  virtual void participateInMeasurement( LightRay& lightray, Measurement& meas, const ALIstring& behav );
162  //---------- default behaviour (depends of subclass type). A default behaviour can be makeMeasurement(), therefore you have to pass 'meas'
163  virtual void defaultBehaviour( LightRay& lightray, Measurement& meas );
164  //---------- Fast simulation of deviation of the light ray (reflection, shift, ...)
165  virtual void fastDeviatesLightRay( LightRay& lightray );
166  //---------- Detailed simulation of the light ray traversing
167  virtual void fastTraversesLightRay( LightRay& lightray );
168  //---------- Detailed simulation of deviation of the light ray (reflection, shift, ...)
169  virtual void detailedDeviatesLightRay( LightRay& lightray );
170  //---------- Fast simulation of the light ray traversing
171  virtual void detailedTraversesLightRay( LightRay& lightray );
172 
173  //---------- Fast simulation of the light ray traversing
174  virtual void makeMeasurement( LightRay& lightray, Measurement& meas );
175 
176  //---------- User Defined Behaviour
177  virtual void userDefinedBehaviour( LightRay& lightray, Measurement& meas, const ALIstring& behav);
178 
179  //---------- Obtain the Z Axis of the OptO (ZAxis rotated with the OptO rotation matrix)
180  CLHEP::Hep3Vector getZAxis() {
181  CLHEP::Hep3Vector ZAxis(0.,0.,1.);
182  CLHEP::HepRotation rmt = rmGlob();
183  ZAxis = rmt*ZAxis;
184  return ZAxis;
185  }
186  //---------- Get one of the plates of an OptO made of two parallel plates
187  ALIPlane getPlate(const ALIbool forwardPlate, const ALIbool applyWedge);
188 
189  //---------- Displacements to get the derivative of a measurement w.r.t an entry
190  //----- Displace the centre coordinate 'coor'
191  void displaceCentreGlob( const XYZcoor coor, const ALIdouble disp);
192  CLHEP::Hep3Vector getDisplacementInLocalCoordinates( const XYZcoor coor, const ALIdouble disp );
193  void displaceCentreGlob( const CLHEP::Hep3Vector& dispVec);
194  //----- Rotate around axis 'coor'
195  void displaceRmGlobAroundGlobal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
196  void displaceRmGlobAroundLocal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
197  //----- Displace extra entry number 'entryNo'
198  void displaceExtraEntry( const ALIuint entryNo, const ALIdouble disp);
199  void setExtraEntryValue(const ALIuint entryNo, const ALIdouble disp);
200 
201  //----------- Displacements of original coordinates: do it to reset the original data
202  //----------- every new iteration of the non linear fit
203  //----- Displace the centre coordinate 'coor'
204  void displaceCentreGlobOriginal( const XYZcoor coor, const ALIdouble disp);
205  void displaceCentreGlobOriginal( const CLHEP::Hep3Vector& dispVec);
206  void displaceCentreGlobOriginalOriginal( const XYZcoor coor, const ALIdouble disp);
207  void displaceCentreGlobOriginalOriginal( const CLHEP::Hep3Vector& dispVec);
208  //----- Rotate around axis 'coor'
209  void displaceRmGlobOriginal( const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
210  void displaceRmGlobOriginalOriginal( const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
211  //----- Displace extra entry number 'entryNo'
212  void displaceExtraEntryOriginal( const ALIuint entryNo, const ALIdouble disp);
213  void displaceExtraEntryOriginalOriginal( const ALIuint entryNo, const ALIdouble disp);
214 
215  //---------- Reset the global coordinates and extra entries (after derivative is finished)
216  void resetGlobalCoordinates();
218 
219  // Find position of an extra entry in ExtraEntryList (and therefore in ExtraEntryValueList)
220  const ALIint extraEntryNo( const ALIstring& entry_name ) const;
221 
222  // //@@ Find an extra Entry by name and return its value. If entry not found, stop.
223  const ALIdouble findExtraEntryValueMustExist( const ALIstring& eename ) const;
224  // Find an extra Entry by name and return its value, if it is not found return 0
225  const ALIdouble findExtraEntryValue( const ALIstring& eename ) const;
226 
227  // Find an extra Entry by name and pass its value. Return if entry is found or not
228  const ALIbool findExtraEntryValueIfExists( const ALIstring& eename, ALIdouble& value ) const;
229 
230  // Return the name of the OptO without its path
231  const ALIstring shortName() const;
232  // Return the name of the OptO with its path
233  const ALIstring longName() const{
234  return name();
235  }
236 
240  }
242  return theCurrentMeas;
243  }
244 
245  std::vector<double> getRotationAnglesInOptOFrame( const OpticalObject* optoAncestor, const std::vector< Entry* >& entries ) const;
246  std::vector<double> getLocalRotationAngles( const std::vector< Entry* >& entries ) const;
247  std::vector<double> getRotationAnglesFromMatrix( CLHEP::HepRotation& rmLocal, const std::vector< Entry* >& entries ) const;
248  double diff2pi( double ang1, double ang2 );
249  bool eq2ang( double ang1, double ang2 );
250  double approxTo0( double val );
251  double addPii( double val );
252  int checkMatrixEquations( double angleX, double angleY, double angleZ, CLHEP::HepRotation* rot = 0);
253 
254  //- CLHEP::Hep3Vector GetAxisForDisplacement( const XYZcoor coor );
255  void setGlobalCoordinates();
256  void setOriginalEntryValues();
257 
259  return theMaterial; }
261  return theSolidShape; }
262 
263  //private DATA METHODS
264 private:
265  // Reads the data
266  void readData( ALIFileIn& filein );
267  // Copy the data from last OptO found of the same type
268  void copyData();
269 
270  // Read extra entries
271  void readExtraEntries( ALIFileIn& filein );
272 
273  protected:
274  // Create and fill an extra entry
275  virtual void fillExtraEntry( std::vector<ALIstring>& wordlist );
276  private:
277  // Read centre or angles
278  void readCoordinates( const ALIstring& coor_type_read, const ALIstring& coor_type_expected, ALIFileIn& filein );
279  // Create and fill a coordinate entry
280  void fillCoordinateEntry( const ALIstring& coor_name, const std::vector<ALIstring>& wordlist );
281  // Set angles null
282  void setAnglesNull();
283 
284  //------ Build wordlist copying data of entry 'entry'
285  void buildWordList( const Entry* entry, std::vector<ALIstring>& wordlist );
286 
287  // start Optical Objects that are components of current
288  void createComponentOptOs( ALIFileIn& filein );
289 
290  OpticalObject* createNewOptO( OpticalObject* parent, ALIstring optoType, ALIstring optoName, ALIbool fcopyComponents );
291 
292  // Set global centre and rotation matrix
293  void setGlobalCentre();
294  void setGlobalRM();
296 
300  void SetRMGlobFromRMLocal();
301  void SetRMGlobFromRMLocalOriginalOriginal( const CLHEP::HepRotation& rmoriori );
302  // Calculate local rot axis with new rm glob
304 
307  void transformGlobal2Local();
308 
309 template<class T>
310  void rotateItAroundGlobal( T& object, const XYZcoor coor, const double disp );
311 
312  CLHEP::Hep3Vector getDispVec( const XYZcoor coor, const ALIdouble disp);
313 
315  centreIsGlobal = isG; }
317  anglesIsGlobal = isG; }
318 
319 private:
320  // private DATA MEMBERS
324  //----- Boolean to mark if data is going to be read or copied from closest previous OptO with same type
326 
327  //----- Global centre and rotation matrix
328  CLHEP::Hep3Vector theCentreGlob;
329  CLHEP::HepRotation theRmGlob;
330  //----- Original global centre and rotation matrix (for backup when they are changed to get derivatives)
331  CLHEP::Hep3Vector theCentreGlobOriginal;
332  CLHEP::HepRotation theRmGlobOriginal;
333  CLHEP::Hep3Vector theCentreGlobOriginalOriginal;
334  CLHEP::HepRotation theRmGlobOriginalOriginal;
335 
336  // Lists of entries
337  std::vector< Entry* > theCoordinateEntryVector;
338  std::vector< Entry* > theExtraEntryVector;
339 
340  // Lists of values of entries
341  std::vector< ALIdouble > theExtraEntryValueVector;
342  std::vector< ALIdouble > theExtraEntryValueOriginalVector;
344 
345  // centre and angles are global
348 
350 
351  CLHEP::Hep3Vector axisXLocalInGlobal;
352  CLHEP::Hep3Vector axisYLocalInGlobal;
353  CLHEP::Hep3Vector axisZLocalInGlobal;
354 
356 
357  protected:
360 
362 };
363 
364 #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)
type
Definition: HCALResponse.h:21
void transformGlobal2Local()
ALIbool anglesIsGlobal
void setMeas(Measurement *meas)
set current measurement
const std::vector< ALIdouble > & ExtraEntryValueOriginalList()
Definition: OpticalObject.h:77
long double ALIdouble
Definition: CocoaGlobals.h:11
const ALIuint getCmsswID() const
void resetGlobalCoordinates()
double approxTo0(double val)
void transformCylindrical2Cartesian()
CLHEP::HepRotation theRmGlob
CLHEP::HepRotation buildRmFromEntryValuesOriginalOriginal()
const std::vector< ALIdouble > & ExtraEntryValueOriginalOriginalList()
Definition: OpticalObject.h:80
void displaceExtraEntryOriginal(const ALIuint entryNo, const ALIdouble disp)
CocoaMaterialElementary * getMaterial() const
ALIstring theName
void setID(ALIuint id)
virtual void defaultBehaviour(LightRay &lightray, Measurement &meas)
CocoaSolidShape * theSolidShape
void SetCentreLocalFromEntryValues()
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
const std::vector< Entry * > & ExtraEntryList() const
Definition: OpticalObject.h:69
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:55
std::vector< ALIdouble > & ExtraEntryValueList()
Definition: OpticalObject.h:73
std::vector< ALIdouble > theExtraEntryValueOriginalOriginalVector
const ALIbool findExtraEntryValueIfExists(const ALIstring &eename, ALIdouble &value) const
void SetCentreIsGlobal(ALIbool isG)
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:65
int ALIint
Definition: CocoaGlobals.h:15
std::vector< Entry * > theCoordinateEntryVector
void displaceCentreGlobOriginalOriginal(const XYZcoor coor, const ALIdouble disp)
CLHEP::HepRotation theRmGlobOriginalOriginal
virtual void makeMeasurement(LightRay &lightray, Measurement &meas)
void addExtraEntryValueToList(ALIdouble entry_value)
std::vector< double > getRotationAnglesInOptOFrame(const OpticalObject *optoAncestor, const std::vector< Entry * > &entries) const
XYZcoor
Definition: OpticalObject.h:33
const CLHEP::HepRotation & rmGlob() const
void displaceRmGlobAroundGlobal(OpticalObject *opto1stRotated, const XYZcoor coor, const ALIdouble disp)
void setOriginalEntryValues()
void setGlobalCoordinatesOfComponents()
std::vector< ALIdouble > theExtraEntryValueVector
bool eq2ang(double ang1, double ang2)
void addExtraEntryValueOriginalToList(ALIdouble entry_value)
bool ALIbool
Definition: CocoaGlobals.h:19
const CLHEP::HepRotation & rmGlobOriginalOriginal() const
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:62
virtual void constructSolidShape()
void setAnglesNull()
string rm
Definition: submit.py:76
double addPii(double val)
const CLHEP::Hep3Vector & centreGlobOriginal() const
Definition: OpticalObject.h:95
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
std::vector< Entry * > theExtraEntryVector
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< ALIstring > getCoordinateFromOptAlignParam(const OpticalAlignParam &oaParam)
virtual void fillExtraEntry(std::vector< ALIstring > &wordlist)
void setCmsswID(ALIuint id)
const CLHEP::HepRotation & rmGlobOriginal() const
void readCoordinates(const ALIstring &coor_type_read, const ALIstring &coor_type_expected, ALIFileIn &filein)
void SetAnglesIsGlobal(ALIbool isG)
std::vector< ALIdouble > theExtraEntryValueOriginalVector
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:56
const CLHEP::Hep3Vector & centreGlobOriginalOriginal() const
Definition: OpticalObject.h:98
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:85
ALIPlane getPlate(const ALIbool forwardPlate, const ALIbool applyWedge)
const ALIuint ID() const
ALIbool centreIsGlobal
void displaceExtraEntry(const ALIuint entryNo, const ALIdouble disp)
virtual void detailedDeviatesLightRay(LightRay &lightray)
const ALIstring shortName() const
const CLHEP::Hep3Vector & centreGlobal() const
Definition: OpticalObject.h:89
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=0)
void constructFromOptAligInfo(const OpticalAlignInfo &oaInfo)
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)
const ALIstring & name() const
Definition: OpticalObject.h:60
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)
void setGlobalCoordinates()
CLHEP::Hep3Vector axisZLocalInGlobal
unsigned int ALIuint
Definition: CocoaGlobals.h:17
const ALIstring & type() const
Definition: OpticalObject.h:61
void setRmGlobal(const CLHEP::HepRotation &rm)