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