00001
00002
00003
00004
00005
00006
00007
00008
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
00041 OpticalObject(){ };
00042 OpticalObject(OpticalObject* parent, const ALIstring& type, const ALIstring& name, const ALIbool copy_data);
00043 virtual ~OpticalObject();
00044
00045
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
00060 const ALIstring& name() const{ return theName; };
00061 const ALIstring& type() const{ return theType; };
00062 const OpticalObject* parent() const{ return theParent;};
00063
00064
00065 const std::vector< Entry* >& CoordinateEntryList() const {
00066 return theCoordinateEntryVector;
00067 }
00068
00069 const std::vector< Entry* >& ExtraEntryList() const {
00070 return theExtraEntryVector;
00071 }
00072
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
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
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
00159
00160
00161 virtual void participateInMeasurement( LightRay& lightray, Measurement& meas, const ALIstring& behav );
00162
00163 virtual void defaultBehaviour( LightRay& lightray, Measurement& meas );
00164
00165 virtual void fastDeviatesLightRay( LightRay& lightray );
00166
00167 virtual void fastTraversesLightRay( LightRay& lightray );
00168
00169 virtual void detailedDeviatesLightRay( LightRay& lightray );
00170
00171 virtual void detailedTraversesLightRay( LightRay& lightray );
00172
00173
00174 virtual void makeMeasurement( LightRay& lightray, Measurement& meas );
00175
00176
00177 virtual void userDefinedBehaviour( LightRay& lightray, Measurement& meas, const ALIstring& behav);
00178
00179
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
00187 ALIPlane getPlate(const ALIbool forwardPlate, const ALIbool applyWedge);
00188
00189
00190
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
00195 void displaceRmGlobAroundGlobal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
00196 void displaceRmGlobAroundLocal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp);
00197
00198 void displaceExtraEntry( const ALIuint entryNo, const ALIdouble disp);
00199 void setExtraEntryValue(const ALIuint entryNo, const ALIdouble disp);
00200
00201
00202
00203
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
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
00212 void displaceExtraEntryOriginal( const ALIuint entryNo, const ALIdouble disp);
00213 void displaceExtraEntryOriginalOriginal( const ALIuint entryNo, const ALIdouble disp);
00214
00215
00216 void resetGlobalCoordinates();
00217 void resetOriginalOriginalCoordinates();
00218
00219
00220 const ALIint extraEntryNo( const ALIstring& entry_name ) const;
00221
00222
00223 const ALIdouble findExtraEntryValueMustExist( const ALIstring& eename ) const;
00224
00225 const ALIdouble findExtraEntryValue( const ALIstring& eename ) const;
00226
00227
00228 const ALIbool findExtraEntryValueIfExists( const ALIstring& eename, ALIdouble& value ) const;
00229
00230
00231 const ALIstring shortName() const;
00232
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
00255 void setGlobalCoordinates();
00256 void setOriginalEntryValues();
00257
00258 CocoaMaterialElementary* getMaterial() const {
00259 return theMaterial; }
00260 CocoaSolidShape* getSolidShape() const {
00261 return theSolidShape; }
00262
00263
00264 private:
00265
00266 void readData( ALIFileIn& filein );
00267
00268 void copyData();
00269
00270
00271 void readExtraEntries( ALIFileIn& filein );
00272
00273 protected:
00274
00275 virtual void fillExtraEntry( std::vector<ALIstring>& wordlist );
00276 private:
00277
00278 void readCoordinates( const ALIstring& coor_type_read, const ALIstring& coor_type_expected, ALIFileIn& filein );
00279
00280 void fillCoordinateEntry( const ALIstring& coor_name, const std::vector<ALIstring>& wordlist );
00281
00282 void setAnglesNull();
00283
00284
00285 void buildWordList( const Entry* entry, std::vector<ALIstring>& wordlist );
00286
00287
00288 void createComponentOptOs( ALIFileIn& filein );
00289
00290 OpticalObject* createNewOptO( OpticalObject* parent, ALIstring optoType, ALIstring optoName, ALIbool fcopyComponents );
00291
00292
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
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
00321 OpticalObject* theParent;
00322 ALIstring theType;
00323 ALIstring theName;
00324
00325 ALIbool fcopyData;
00326
00327
00328 CLHEP::Hep3Vector theCentreGlob;
00329 CLHEP::HepRotation theRmGlob;
00330
00331 CLHEP::Hep3Vector theCentreGlobOriginal;
00332 CLHEP::HepRotation theRmGlobOriginal;
00333 CLHEP::Hep3Vector theCentreGlobOriginalOriginal;
00334 CLHEP::HepRotation theRmGlobOriginalOriginal;
00335
00336
00337 std::vector< Entry* > theCoordinateEntryVector;
00338 std::vector< Entry* > theExtraEntryVector;
00339
00340
00341 std::vector< ALIdouble > theExtraEntryValueVector;
00342 std::vector< ALIdouble > theExtraEntryValueOriginalVector;
00343 std::vector< ALIdouble > theExtraEntryValueOriginalOriginalVector;
00344
00345
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