CMS 3D CMS Logo

OptOOpticalSquare.cc

Go to the documentation of this file.
00001 //   COCOA class implementation file
00002 //Id:  OptOOpticalSquare
00003 //CAT: Model
00004 //
00005 //   History: v1.0 
00006 //   Pedro Arce
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 //@@  Detailed simulation of deviation of the light ray 
00023 //@@  Refract at entering, reflect in two of the plates and gets deviated 90o, refract at exiting
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   //---------- Deviate in prism
00033   //---------- Refract after entering face 0, reflect in face 1, reflect in face 2, refract after face 3
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     //---- interchange refraction index for exiting instead of entering
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   //----- checks that it is inside prism and the order of faces hit is the good one
00054   //   
00055 
00056 }
00057 
00058 
00059 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00060 //@@  Detailed simulation of traversing of the light ray 
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 //@@ Fast simulation of deviation of the light ray
00079 //@@ Reflect in two of the plates and gets deviated 90o
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   //---------- Deviate in prism
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   //----- Deviates by 'devi' X & Y??
00103   lightray.shiftAndDeviateWhileTraversing( this, 'R');
00104   /*  ALIdouble deviRX = findExtraEntryValue("deviRX");
00105   ALIdouble deviRY = findExtraEntryValue("deviRY");
00106   ALIdouble shiftRX = findExtraEntryValue("shiftRX");
00107   ALIdouble shiftRY = findExtraEntryValue("shiftRY");
00108   lightray.shiftAndDeviateWhileTraversing( this, shiftRX, shiftRY, deviRX, deviRY);
00109   */
00110 
00111   if (ALIUtils::debug >= 2) {
00112     //  std::cout << " shiftRX " << shiftRX << " shiftRY " << shiftRY << std::endl;
00113     // std::cout << " deviRX " << deviRX << " deviRY " << deviRY << std::endl;
00114     lightray.dumpData("Deviated ");
00115   }
00116 
00117 
00118 }
00119 
00120 
00121 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00122 //@@ 
00123 //@@ 
00124 //@@
00125 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00126   //---------- Fast simulation of the light ray traversing
00127 void OptOOpticalSquare::fastTraversesLightRay( LightRay& lightray )
00128 {
00129   //  std::cerr << " WARNING  there should be an extra piece to make entering and exiting surfaces parallel (like in modified_rhomboid_prism) " << std::endl;
00130 
00131   calculateFaces( 0 );
00132 
00133   lightray.intersect( ALIPlane(faceP[1],faceV[1] ));
00134   //---------- Shift and Deviate
00135   lightray.shiftAndDeviateWhileTraversing( this, 'T');
00136   /*  ALIdouble shiftX = findExtraEntryValue("shiftTX");
00137   ALIdouble shiftY = findExtraEntryValue("shiftTY");
00138   ALIdouble deviTX = findExtraEntryValue("deviTX");
00139   ALIdouble deviTY = findExtraEntryValue("deviTY");
00140   lightray.shiftAndDeviateWhileTraversing( this, shiftX, shiftY, deviTX, deviTY);
00141   */
00142   if (ALIUtils::debug >= 2) {
00143     lightray.dumpData("Shifted and Deviated");
00144   }
00145 }
00146 
00147 
00148 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00149 //@@ Calculate the centre points and normal std::vector of each of the four pentaprism faces the light ray may touch
00150 //@@ Build the four faces. 0: entry, 1: 1st reflection, 2: 2nd reflection, 3: exit  (look at figure in documentation)
00151 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00152 void OptOOpticalSquare::calculateFaces( ALIbool isDetailed )
00153 {
00154 
00155   ALIint numberOfFaces = 5;
00156 
00157   //----- useful variables
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   //-  if( ALIUtils::debug >= 3) std::cout << "length 1 " << 2*hlen1 << " length 2 " << hlen2 * 2 << std::endl;
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   // face of added piece (so that light when traversing finds parallel surfaces at entry and exit)
00176   faceP[4] = CLHEP::Hep3Vector( 0, 0, hlen1 + 2*hlen2*cos(ang) );
00177   faceV[4] = CLHEP::Hep3Vector( 0, 0, 1 );
00178 
00179   //--------- Put faces in global reference frame
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   //----------- Correct faces 1 & 2 by wedge: rotate each face normal 1/2 of the wedge around two axis perpendicular to normal 
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     //----- One axis is along X axis for the two faces (X belong to both faces)
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     //----- Other axis perpendicular to first and to normal of each face
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 ); //COCOA internal units are meters
00271 }

Generated on Tue Jun 9 17:23:39 2009 for CMSSW by  doxygen 1.5.4