00001
00002
00003
00004
00005
00006
00007
00008 #include "Alignment/CocoaModel/interface/OptOOpticalSquare.h"
00009 #include "Alignment/CocoaModel/interface/LightRay.h"
00010 #include "Alignment/CocoaModel/interface/ALIPlane.h"
00011 #include "Alignment/CocoaModel/interface/Measurement.h"
00012 #include <iostream>
00013 #include <iomanip>
00014 #ifdef COCOA_VIS
00015 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
00016 #include "Alignment/CocoaVisMgr/interface/ALIColour.h"
00017 #endif
00018 #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
00019 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
00020
00021 using namespace CLHEP;
00022
00023
00024
00025
00026
00027
00028 void OptOOpticalSquare::detailedDeviatesLightRay( LightRay& lightray )
00029 {
00030 if (ALIUtils::debug >= 2) std::cout << "LR: DETAILED DEVIATION IN OPTICAL SQUARE " << name() << std::endl;
00031
00032 calculateFaces( 1 );
00033
00034
00035
00036 const ALIdouble refra_ind = findExtraEntryValueMustExist("refra_ind");
00037 const ALIdouble refra_ind0 = 1.;
00038
00039 ALIint ii;
00040 for( ii = 0; ii < 4; ii++ ) {
00041 if(ii == 0) {
00042 if( ALIUtils::debug >= 3 ) std::cout << "## OPTOOPTICALSQUARE: refract in face " << ii << std::endl;
00043 lightray.refract( ALIPlane(faceP[ii],faceV[ii]), refra_ind0, refra_ind );
00044 } else if( ii == 3) {
00045
00046 lightray.refract( ALIPlane(faceP[ii],faceV[ii]), refra_ind, refra_ind0 );
00047 } else {
00048 lightray.reflect( ALIPlane(faceP[ii],faceV[ii] ));
00049 }
00050 if (ALIUtils::debug >= 3) {
00051 lightray.dumpData( "After face ");
00052 }
00053 }
00054
00055
00056
00057
00058 }
00059
00060
00061
00062
00063
00064
00065 void OptOOpticalSquare::detailedTraversesLightRay( LightRay& lightray )
00066 {
00067 if (ALIUtils::debug >= 2) std::cout << "LR: DETAILED TRAVERSES OPTICAL SQUARE " << name() << std::endl;
00068
00069 calculateFaces( 1 );
00070 const ALIdouble refra_ind = findExtraEntryValueMustExist("refra_ind");
00071 const ALIdouble refra_ind0 = 1.;
00072
00073 lightray.refract( ALIPlane(faceP[0],faceV[0]), refra_ind0, refra_ind );
00074 lightray.refract( ALIPlane(faceP[4],faceV[4]), refra_ind, refra_ind0 );
00075
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 void OptOOpticalSquare::fastDeviatesLightRay( LightRay& lightray )
00085 {
00086 if (ALIUtils::debug >= 2) std::cout << "LR: FAST DEVIATION IN OPTICAL SQUARE " << name() << std::endl;
00087
00088 calculateFaces( 0 );
00089
00090
00091 lightray.reflect( ALIPlane(faceP[1],faceV[1] ));
00092 if (ALIUtils::debug >= 3) {
00093 lightray.dumpData( "After face 1");
00094 }
00095 lightray.reflect( ALIPlane(faceP[2],faceV[2] ));
00096 if (ALIUtils::debug >= 3) {
00097 lightray.dumpData( "After face 2");
00098 }
00099 lightray.intersect( ALIPlane(faceP[3],faceV[3] ));
00100 if (ALIUtils::debug >= 3) {
00101 lightray.dumpData( "intersected at face 3");
00102 }
00103
00104
00105 lightray.shiftAndDeviateWhileTraversing( this, 'R');
00106
00107
00108
00109
00110
00111
00112
00113 if (ALIUtils::debug >= 2) {
00114
00115
00116 lightray.dumpData("Deviated ");
00117 }
00118
00119
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129 void OptOOpticalSquare::fastTraversesLightRay( LightRay& lightray )
00130 {
00131
00132
00133 calculateFaces( 0 );
00134
00135 lightray.intersect( ALIPlane(faceP[1],faceV[1] ));
00136
00137 lightray.shiftAndDeviateWhileTraversing( this, 'T');
00138
00139
00140
00141
00142
00143
00144 if (ALIUtils::debug >= 2) {
00145 lightray.dumpData("Shifted and Deviated");
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154 void OptOOpticalSquare::calculateFaces( ALIbool isDetailed )
00155 {
00156
00157 ALIint numberOfFaces = 5;
00158
00159
00160 CLHEP::Hep3Vector opto_centre = centreGlob();
00161 if(ALIUtils::debug >= 3) std::cout << "opto_centre " << opto_centre << std::endl;
00162 const ALIdouble hlen1 = findExtraEntryValueMustExist("length1") / 2.;
00163 const ALIdouble hlen2 = findExtraEntryValueMustExist("length2") / 2.;
00164 ALIdouble ang = 67.5*acos(0.)/90.;
00165
00166
00167 faceP[0] = CLHEP::Hep3Vector( 0, 0 , -hlen1 );
00168 faceV[0] = CLHEP::Hep3Vector( 0, 0, -1 );
00169 faceP[1] = CLHEP::Hep3Vector( 0, hlen1 - hlen2*sin(ang), hlen1 + hlen2*cos(ang) );
00170 faceV[1] = CLHEP::Hep3Vector( 0, cos(ang), sin(ang) );
00171
00172 faceP[2] = CLHEP::Hep3Vector( 0, -hlen1 - hlen2*cos(ang), -hlen1 + hlen2*sin(ang) );
00173 faceV[2] = CLHEP::Hep3Vector( 0, -sin(ang), -cos(ang) );
00174 faceP[3] = CLHEP::Hep3Vector( 0, hlen1, 0 );
00175 faceV[3] = CLHEP::Hep3Vector( 0, 1, 0 );
00176
00177
00178 faceP[4] = CLHEP::Hep3Vector( 0, 0, hlen1 + 2*hlen2*cos(ang) );
00179 faceV[4] = CLHEP::Hep3Vector( 0, 0, 1 );
00180
00181
00182 CLHEP::HepRotation rmt = rmGlob();
00183 ALIint ii;
00184 if (ALIUtils::debug >= 3) {
00185 std::cout << " optical_square centre" << opto_centre << std::endl;
00186 }
00187 for( ii = 0; ii < numberOfFaces; ii++ ) {
00188 faceP[ii] = rmt * faceP[ii];
00189 faceP[ii] += opto_centre;
00190 faceV[ii] = rmt * faceV[ii];
00191 if (ALIUtils::debug >= 3) {
00192 std::cout << "point at face " << ii << ": " << faceP[ii] << std::endl;
00193 std::cout << "normal at face " << ii << ": " << faceV[ii] << std::endl;
00194 }
00195 }
00196
00197
00198 if( isDetailed ) {
00199 ALIdouble wedge, wedgeX, wedgeY;
00200 const ALIbool wxy = findExtraEntryValueIfExists("wedge", wedge);
00201 if( !wxy ) {
00202 wedgeX = findExtraEntryValue("wedgeX");
00203 wedgeY = findExtraEntryValue("wedgeY");
00204 } else {
00205 wedgeX = wedge;
00206 wedgeY = wedge;
00207 }
00208
00209
00210 if(ALIUtils::debug >= 4) std::cout << "OptOOpticalSquare calculateFaces: wedgeX " << wedgeX << " wedgeY " << wedgeY << std::endl;
00211 CLHEP::Hep3Vector Axis1(1.,0.,0.);
00212 Axis1 = rmt * Axis1;
00213 if( ALIUtils::debug >= 4) {
00214 ALIUtils::dump3v(faceV[1], "faceV[1] before wedge");
00215 ALIUtils::dump3v(faceV[2], "faceV[2] before wedge");
00216 }
00217 faceV[1].rotate(0.5* wedgeX, Axis1);
00218 if( ALIUtils::debug >= 4) ALIUtils::dump3v( Axis1, " Axis1 in faceV[1] ");
00219 faceV[2].rotate(-0.5* wedgeX, Axis1);
00220 if( ALIUtils::debug >= 4) {
00221 ALIUtils::dump3v( Axis1, " Axis1 in faceV[2] ");
00222 ALIUtils::dump3v(faceV[1], "faceV[1] after wedge X");
00223 ALIUtils::dump3v(faceV[2], "faceV[2] after wedge X");
00224 }
00225
00226
00227 CLHEP::Hep3Vector Axis2 = Axis1;
00228 Axis2 = Axis2.cross( faceV[1] );
00229 faceV[1].rotate(0.5* wedgeY, Axis2);
00230 if( ALIUtils::debug >= 4) ALIUtils::dump3v( Axis2, " Axis2 in faceV[1] ");
00231 Axis2 = Axis1;
00232 Axis2 = Axis2.cross( faceV[2] );
00233 faceV[2].rotate(-0.5* wedgeY, Axis2);
00234 if( ALIUtils::debug >= 4) {
00235 ALIUtils::dump3v( Axis2, " Axis2 in faceV[2] ");
00236 ALIUtils::dump3v(faceV[1], "faceV[1] after wedge Y");
00237 ALIUtils::dump3v(faceV[2], "faceV[2] after wedge Y");
00238 }
00239
00240 }
00241
00242 }
00243
00244
00245 #ifdef COCOA_VIS
00246
00247 void OptOOpticalSquare::fillIguana()
00248 {
00249 ALIColour* col = new ALIColour( 0., 0., 1., 0. );
00250 ALIdouble length1;
00251 ALIbool wexists = findExtraEntryValueIfExists("length1",length1);
00252 if( !wexists ) length1 = 4.;
00253 ALIdouble length2;
00254 wexists = findExtraEntryValueIfExists("length2",length2);
00255 if( !wexists ) length2 = 4.;
00256
00257 std::vector<ALIdouble> spar;
00258 spar.push_back(length1);
00259 spar.push_back(length2);
00260 IgCocoaFileMgr::getInstance().addSolid( *this, "OPTSQR", spar, col);
00261 }
00262 #endif
00263
00264
00265
00266 void OptOOpticalSquare::constructSolidShape()
00267 {
00268 ALIdouble go;
00269 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00270 gomgr->getGlobalOptionValue("VisScale", go );
00271
00272 theSolidShape = new CocoaSolidShapeBox( "Box", go*5.*cm/m, go*5.*cm/m, go*5.*cm/m );
00273 }