CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Alignment/CocoaModel/src/OptOCOPS.cc

Go to the documentation of this file.
00001 //   COCOA class implementation file
00002 //Id:  OptOCops.cc
00003 //CAT: Model
00004 //
00005 //   History: v1.0 
00006 //   Pedro Arce
00007 
00008 #include "Alignment/CocoaModel/interface/OptOCOPS.h"
00009 #include "Alignment/CocoaModel/interface/LightRay.h"
00010 #include "Alignment/CocoaModel/interface/Measurement.h"
00011 #include "Alignment/CocoaModel/interface/Model.h"
00012 #ifdef COCOA_VIS
00013 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
00014 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
00015 #endif
00016 #include "Alignment/CocoaModel/interface/ALILine.h"
00017 #include "Alignment/CocoaModel/interface/ALIPlane.h"
00018 #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
00019 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
00020 #include "FWCore/Utilities/interface/isFinite.h"
00021 
00022 #include <iostream>
00023 #include <iomanip>
00024 #include <fstream>
00025 #include <math.h>               // I have added a new library for edm::isNotFinite() function
00026 #include <cstdlib>
00027 
00028 using namespace CLHEP;
00029 
00030 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00031 //@@  Make measurement as distance to previous object 'screen'
00032 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00033 void OptOCOPS::defaultBehaviour( LightRay& lightray, Measurement& meas )
00034 {
00035   if(ALIUtils::debug >= 5) std::cout << "***** OptOCOPS::defaultBehaviour" <<std::endl;
00036   makeMeasurement( lightray, meas);
00037 }
00038 
00039 
00040 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00041 //@@  Make measurement as distance to previous object 'screen'
00042 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00043 void OptOCOPS::makeMeasurement( LightRay& lightray, Measurement& meas ) 
00044 {
00045 
00046   if (ALIUtils::debug >= 4) std::cout << "***** OptOCOPS::makeMeasurement(lightray, meas) " << std::endl; 
00047   //---------- Centre of COPS is at dowel point 2 
00048   CLHEP::Hep3Vector dowel2 = centreGlob();
00049   //---------- Coordinates of dowel point 1 are given with respect to dowel point 2 (in local reference frame)
00050   ALIdouble posx12 = findExtraEntryValue("dowel1X");
00051 // Changed default value to .045 from .03
00052   if(posx12 == 0. ) posx12 = -0.045; //samir changed sign to correct the dowel 1st pixel
00053   CLHEP::Hep3Vector dowel1(posx12,findExtraEntryValue("dowel1Y"), 0.);
00054   CLHEP::HepRotation rmt = rmGlob(); 
00055   dowel1 = rmt*dowel1;
00056   dowel1 += dowel2;  
00057   if (ALIUtils::debug >= 3) {
00058     ALIUtils::dump3v(dowel2, " dowel2");
00059     ALIUtils::dump3v(dowel1, " dowel1");
00060   }
00061 
00062   //---------- Get line joining dowel1-dowel2 and perpendicular to it inside cops
00063 //  CLHEP::Hep3Vector line_dowel21 = - (dowel1-dowel2 ); //////
00064   CLHEP::Hep3Vector line_dowel21 =  (dowel1-dowel2 ); // samir changed sign to correct the dowel 1st pixel
00065   CLHEP::Hep3Vector ZAxis(0.,0,1.); 
00066   ZAxis = rmt * ZAxis; 
00067   CLHEP::Hep3Vector line_dowel21_perp = ZAxis.cross( line_dowel21 ); 
00068   if (ALIUtils::debug >= 3) {
00069     ALIUtils::dump3v(line_dowel21," line_dowel21");
00070     ALIUtils::dump3v(line_dowel21_perp," line_dowel21_perp");
00071   }
00072  
00073   //---------- Position four CCDs (locally, i.e. with respect to centre)
00074   //----- Get first CCD length, that will be used to give a default placement to the CCDs
00075   ALIdouble CCDlength = findExtraEntryValue("CCDlength");
00076   if( CCDlength == 0. ) CCDlength = 2048*14 * 1.E-6; // (in meters, the default unit)
00077 
00078 
00079 
00080   //  global / local output of ccd location in RF was reversed, I am swapping
00081 
00082 
00083   //----- Upper CCD (leftmost point & direction dowel1-dowel2)
00084   if(ALIUtils::debug>= 3) std::cout << std::endl << "***** UP CCD *****" << std::endl
00085                             << "******************" << std::endl << std::endl;
00086   ALIdouble posX = findExtraEntryValue("upCCDXtoDowel2");
00087   ALIdouble posY;
00088   ALIbool eexists = findExtraEntryValueIfExists("upCCDYtoDowel2", posY);
00089   if(!eexists) posY = CCDlength + 0.004;
00090   //if(!eexists) posY =  0.004;
00091   CLHEP::Hep3Vector posxy( posX, posY, 0);
00092   if(ALIUtils::debug>= 3) std::cout << " %%%% CCD distances to Dowel2: " << std::endl;
00093   if(ALIUtils::debug>= 3) std::cout << "   up ccd in local RF " << posxy << std::endl; 
00094   posxy = rmt * posxy;
00095   if(ALIUtils::debug>= 3) std::cout << "   up ccd in global RF " << posxy << std::endl; 
00096  // ALILine upCCD( dowel2 + posxy, -line_dowel21 ); 
00097  // ccds[0] = ALILine( posxy, -line_dowel21 );
00098    ALILine upCCD( dowel2 + posxy, line_dowel21 );// Samir changed sign to correct the dowel 1st pixel
00099   ccds[0] = ALILine( posxy, line_dowel21 ); // samir changed sign to correct the dowel 1st pixel
00100   //----- Lower CCD (leftmost point & direction dowel2-dowel1)
00101   if(ALIUtils::debug>= 3) std::cout << std::endl << "***** DOWN CCD *****" << std::endl 
00102                             << "********************" << std::endl << std::endl ;
00103   posX = findExtraEntryValue("downCCDXtoDowel2");
00104   eexists = findExtraEntryValueIfExists("downCCDYtoDowel2", posY);
00105   if(!eexists) posY = 0.002;
00106   posxy = CLHEP::Hep3Vector( posX, posY, 0);
00107   if(ALIUtils::debug>= 3) std::cout << "   down ccd in local RF " << posxy << std::endl; 
00108   posxy = rmt * posxy;
00109   if(ALIUtils::debug>= 3) std::cout << "   down ccd in global RF " << posxy << std::endl; 
00110 //  ALILine downCCD( dowel2 + posxy, -line_dowel21 );
00111  // ccds[1] = ALILine( posxy, -line_dowel21 );
00112 
00113 ALILine downCCD( dowel2 + posxy, line_dowel21 );//samir changed signto correct the dowel 1st pixel
00114   ccds[1] = ALILine( posxy, line_dowel21 ); // samir changed sign to correct the dowel 1st pixel
00115 
00116   //----- left CCD (uppermost point & direction perpendicular to dowel2-dowel1)
00117 
00118   if(ALIUtils::debug>= 3) std::cout << std::endl << "***** LEFT CCD *****" << std::endl
00119                             << "********************" << std::endl << std::endl;
00120   eexists = findExtraEntryValueIfExists("leftCCDXtoDowel2", posX);
00121 //  if(!eexists) posX = -0.002;
00122   if(!eexists) posX = -CCDlength - 0.002; // Samir changed sign to correct the dowel 1st pixel
00123   posY = findExtraEntryValue("leftCCDYtoDowel2");
00124   posxy = CLHEP::Hep3Vector( posX, posY, 0);
00125   if(ALIUtils::debug>= 3) std::cout << "   left ccd in local RF " << posxy << std::endl; 
00126   posxy = rmt * posxy;
00127   if(ALIUtils::debug>= 3) std::cout << "   left ccd in global RF " << posxy << std::endl; 
00128  // ALILine leftCCD( dowel2 + posxy, line_dowel21_perp );
00129  // ccds[2] = ALILine(  posxy, line_dowel21_perp );
00130 
00131   ALILine leftCCD( dowel2 + posxy, -line_dowel21_perp );//samir changed sign to correct the dowel 1st pixel
00132   ccds[2] = ALILine(  posxy, -line_dowel21_perp );//samir changed sign to correct the dowel 1st pixel
00133 
00134   //----- right CCD (uppermost point & direction perpendicular to dowel2-dowel1)
00135   if(ALIUtils::debug>= 3) std::cout << std::endl << "***** RIGHT CCD *****" << std::endl 
00136                             << "*********************" << std::endl<< std::endl ;
00137   eexists = findExtraEntryValueIfExists("rightCCDXtoDowel2", posX);
00138  // if(!eexists) posX = -CCDlength - 0.004;
00139   if(!eexists) posX =  - 0.004; // samir tried to change in order to adjust the position of 1 st pixel.
00140   posY = findExtraEntryValue("rightCCDYtoDowel2");
00141   posxy = CLHEP::Hep3Vector( posX, posY, 0);
00142   if(ALIUtils::debug>= 3) std::cout << "   right ccd in local RF " << posxy << std::endl; 
00143   posxy = rmt * posxy;
00144   if(ALIUtils::debug>= 3) std::cout << "   right ccd in global RF " << posxy  << std::endl << std::endl; 
00145  // ALILine rightCCD( dowel2 + posxy, line_dowel21_perp );
00146  // ccds[3] = ALILine(  posxy, line_dowel21_perp );
00147   
00148 ALILine rightCCD( dowel2 + posxy, -line_dowel21_perp ); //samir changed sign to correct the dowel 1st pixel
00149   ccds[3] = ALILine(  posxy, -line_dowel21_perp ); //samir changed sign to correct the dowel 1st pixel
00150 
00151   if (ALIUtils::debug >= 3) {
00152     std::cout << " %%%  Positions of CCDs in global RF: " << std::endl<< std::endl;
00153     std::cout << "     upCCD: " << upCCD << std::endl;
00154     std::cout << "     downCCD: " << downCCD << std::endl;
00155     std::cout << "     leftCCD: " << leftCCD << std::endl;
00156     std::cout << "     rightCCD: " << rightCCD << std::endl << std::endl;
00157   }
00158 
00159   //---------- Intersect x-hair laser with COPS
00160   if (ALIUtils::debug >= 3) std::cout << " %%%  Intersecting x-hair laser with COPS: " << std::endl;
00161   ALIPlane copsPlane(centreGlob(), ZAxis);
00162   lightray.intersect( *this ); 
00163   CLHEP::Hep3Vector inters = lightray.point();
00164   if (ALIUtils::debug >= 3) {
00165      ALIUtils::dump3v(inters, " Intersection of x-hair laser with COPS ");
00166   }
00167 
00168   //---------- Get cross of x-hair laser:
00169    if (ALIUtils::debug >= 5) std::cout << "1. Get the OptO x-hair laser from the measurement list of OptOs" << std::endl;
00170    
00171   OpticalObject* xhairOptO = *(meas.OptOList().begin());
00172 
00173   if (ALIUtils::debug >= 35) std::cout << "2. Get the Y of the laser and project it on the COPS" << std::endl;
00174   CLHEP::Hep3Vector YAxis_xhair(0.,1.,0.);
00175   CLHEP::HepRotation rmtx = xhairOptO->rmGlob(); 
00176   YAxis_xhair = rmtx * YAxis_xhair;
00177   ALILine Yline_xhair( inters, copsPlane.project( YAxis_xhair ));
00178   if (ALIUtils::debug >= 3) {
00179     std::cout << "  %%%% Projecting x-hair laser on COPS: " << std::endl;
00180      ALIUtils::dump3v(YAxis_xhair, " Y direction of laser ");
00181     std::cout << " Y line of laser projected on COPS " <<  Yline_xhair << std::endl;
00182   }
00183 
00184   if (ALIUtils::debug >= 5) std::cout << " 3. Get the X of the laser (correct it if cross is not 90o) and project it on the COPS" << std::endl;
00185   
00186   ALIdouble anglebx;
00187   eexists = xhairOptO->findExtraEntryValueIfExists("angleBetweenAxis", anglebx);
00188   if(!eexists) anglebx = PI/2.;
00189   CLHEP::Hep3Vector XAxis_xhair = YAxis_xhair;
00190 
00191  //   if (ALIUtils::debug >= 3) ALIUtils::dump3v(XAxis_xhair," X of laser1 ");
00192   ZAxis = CLHEP::Hep3Vector(0.,0.,1.);
00193   ZAxis = rmtx * ZAxis;
00194   XAxis_xhair.rotate(anglebx, ZAxis );
00195   ALILine Xline_xhair( inters, copsPlane.project( XAxis_xhair ) );
00196   if (ALIUtils::debug >= 3) {
00197     std::cout << "angleBetweenAxis = " << anglebx << std::endl;
00198     ALIUtils::dump3v(XAxis_xhair," X direction of laser ");
00199     std::cout << " X line of laser projected on COPS " <<  Xline_xhair << std::endl;
00200   }
00201  
00202 
00203   //---------- Get measurement as intersection with four CCDs 
00204   if(ALIUtils::debug >= 3) std::cout << "  Getting measurements as intersection with four CCDs: " << std::endl;
00205 
00206   if(ALIUtils::debug >= 4)std::cout << "intersecting with upCCD " << std::endl;
00207   ALIdouble measv[4][2];
00208 
00209 // swap Y and X line_xhair by exchanging second index
00210 
00211   if(ALIUtils::debug >= 5)std::cout << "$@S@ measv[0][0] upccd " << std::endl;
00212   measv[0][0] = getMeasFromInters( Yline_xhair, upCCD, line_dowel21 );
00213   if(ALIUtils::debug >= 5)std::cout << "$@$@ measv[0][1] upccd " << std::endl;
00214   measv[0][1] = getMeasFromInters( Xline_xhair, upCCD, line_dowel21 );
00215   
00216   //---- check if postive or negative: 
00217   if(ALIUtils::debug >= 4) std::cout << "intersecting with downCCD " << std::endl;
00218   measv[1][0] = getMeasFromInters(Yline_xhair, downCCD, line_dowel21 );
00219   measv[1][1] = getMeasFromInters(Xline_xhair, downCCD, line_dowel21 );
00220   
00221 //  
00222   
00223   if(ALIUtils::debug >= 4) std::cout << "intersecting with leftCCD " << std::endl;
00224   measv[2][0] = getMeasFromInters(Xline_xhair, leftCCD, line_dowel21_perp );
00225   measv[2][1] = getMeasFromInters(Yline_xhair, leftCCD, line_dowel21_perp );
00226   if(ALIUtils::debug >= 4) std::cout << "intersecting with rightCCD " << std::endl;
00227   measv[3][0] = getMeasFromInters(Xline_xhair, rightCCD, line_dowel21_perp );
00228   measv[3][1] = getMeasFromInters(Yline_xhair, rightCCD, line_dowel21_perp );
00229 
00230   /* Both X and Y axis of the x-laser are intersected with each CCD and it checks that one of 
00231   the two is inside the CCD(less than CCDlength/2). If no one is inside, it will give an 
00232   exception. If both are inside (a strange case where, for example, the laser centre is very 
00233   close and forms 45 degrees with the CCD) it will also make an exception (if you prefer, I can
00234   put a warning saying that you have two measurements, but I guess this should never happen for
00235   you, so I better give an exception and you don't risk to overpass this warning).
00236 
00237   Then it is mandatory that you put the CCDlength parameter (I could put a default one if 
00238   you prefer). 
00239   
00240 
00241   ALIbool measInCCD[2];
00242   ALIuint ii,jj;
00243   for( ii = 0; ii < 4; ii++ ) {
00244     for( jj = 0; jj < 2; jj++ ) {
00245       measInCCD[jj] =  fabs( measv[ii][jj] ) < CCDlength/2;
00246     }
00247     if (ALIUtils::debug >= 2) std::cout << "$@$@ CHECK CCD = " << ii << std::endl; 
00248     if( measInCCD[0] && measInCCD[1] ){
00249       std::cerr << "!!!EXITING: both lasers lines of x-hair laser intersect with same CCD " << measNames[ii] << " one at " << measv[ii][0] << " another one at " << measv[ii][1] << "CCDhalfLegth " << CCDlength/2 << std::endl;
00250       exit(1);
00251     } else if( !(measInCCD[0] || measInCCD[1]) ){
00252       std::cerr << "!!!EXITING: none of the lasers lines of x-hair laser intersect with CCD " << measNames[ii] << ", one at " << measv[ii][0] << " another one at " << measv[ii][1] << "CCDhalfLegth " << CCDlength/2 << std::endl;
00253       exit(1);
00254     } else {
00255       measInCCD[0] ?  meas.setValueSimulated( ii, measv[ii][0] ) :
00256         meas.setValueSimulated( ii, measv[ii][1] );
00257     }
00258   }
00259   */
00260 
00261   ALIstring measNames[4] ={"up","down","left","right"};
00262   ALIbool laserLine; 
00263   if (ALIUtils::debug >= 2) std::cout << std::endl << "--> Now comparing measurement in ccds by x and y laser lines (will always choose the smaller one) " <<std::endl; 
00264      
00265   unsigned int ii;
00266   for( ii = 0; ii < 4; ii++ ) {
00267     if (ALIUtils::debug >= 2) std::cout << "\tmeas CCD " << measNames[ii] << " ii=(" << ii << ") \t Values: "
00268      //<< (fabs( measv[ii][0] ) <  fabs( measv[ii][1]) 
00269        << " " << fabs( measv[ii][0] ) << " " <<  fabs( measv[ii][1] ) << "  edm::isNotFinite() = " <<
00270        edm::isNotFinite(measv[ii][1]) << std::endl;
00271 
00272     if( meas.xlaserLine( ii ) != -1 ) { 
00273       laserLine = ALIbool( meas.xlaserLine( ii ) );
00274     } else { 
00275     
00276     //  Problem here !!!
00277     //
00278     //  Somehow measv[][1] can occasionally return value of 'nan'
00279     //  which is interpretted as less than any real value
00280     //
00281       if(edm::isNotFinite(measv[ii][1]) != 0){
00282                 measv[ii][1] = 1e99;
00283                 if (ALIUtils::debug >= 2) std::cout << "  --> Swapping for " << measv[ii][1] << "(inf)" << std::endl;
00284                                   }
00285                                    
00286       laserLine = fabs( measv[ii][0] ) <  fabs( measv[ii][1] );
00287       
00288       meas.setXlaserLine( ii, int(laserLine) );
00289     }
00290     laserLine ? meas.setValueSimulated( ii, measv[ii][0] ) 
00291       : meas.setValueSimulated( ii, measv[ii][1] );
00292   }
00293   
00294     if (ALIUtils::debug >= 2) std::cout << std::endl;   //Keep format of debug output reasonable
00295 
00296   // try to identify pathological cases: up and down CCD are intersected by the same 
00297   // laser line (say X) and the same for the left and right CCD
00298 
00299   if(ALIUtils::debug >= 2) std::cout << "***** OptOCOPS::makeMeasurement  - identify pathological cases U and D intersected by same line" <<std::endl;
00300   ALIbool xlaserDir[4];
00301   for( ii = 0; ii < 4; ii++ ) {
00302     //    xlaserDir[ii] = fabs( measv[ii][0] ) <  fabs( measv[ii][1] );
00303     xlaserDir[ii] = ALIbool( meas.xlaserLine( ii ) ); 
00304   }
00305   if( xlaserDir[0] ^ xlaserDir[1] ) {
00306     std::cerr << "!!EXITING up and down CCDs intersected by different x-laser line " << xlaserDir[0] << " " <<  xlaserDir[1] << std::endl;
00307     exit(1);
00308   }
00309   if( xlaserDir[2] ^ xlaserDir[3] ) {
00310     std::cerr << "!!EXITING right and left CCDs intersected by different x-laser line " << xlaserDir[0] << " " <<  xlaserDir[1] << std::endl;
00311     exit(1);
00312   }
00313 
00314   if(ALIUtils::debug >= 5) std::cout << "***** OptOCOPS::makeMeasurement - now output sim values" << std::endl;
00315 
00316   if (ALIUtils::debug >= 1) {
00317     ALIstring chrg = "";
00318     std::cout << "REAL value: " << chrg <<"U: " << 1000*meas.value()[0] << chrg 
00319          << " D: " << 1000*meas.value()[1] 
00320          << " L: " << 1000*meas.value()[2] 
00321          << " R: " << 1000*meas.value()[3]  
00322          << " (mm)  " << (this)->name() << std::endl;
00323     ALIdouble detU =  1000*meas.valueSimulated(0); if(fabs(detU) <= 1.e-9 ) detU = 0.;
00324     ALIdouble detD =  1000*meas.valueSimulated(1); if(fabs(detD) <= 1.e-9 ) detD = 0.;
00325     ALIdouble detL =  1000*meas.valueSimulated(2); if(fabs(detL) <= 1.e-9 ) detL = 0.;
00326     ALIdouble detR =  1000*meas.valueSimulated(3); if(fabs(detR) <= 1.e-9 ) detR = 0.;
00327     std::cout << "SIMU value: " << chrg << "U: "
00328       // << setprecision(3) << setw(4)
00329          << detU
00330          << chrg << " D: " << detD
00331          << chrg << " L: " << detL
00332          << chrg << " R: " << detR
00333          << " (mm)  " << (this)->name() << std::endl;
00334   }
00335   
00336 
00337 }
00338 
00339 
00340 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00341 //@@ Fast simulation of Light Ray traverses
00342 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00343 void OptOCOPS::fastTraversesLightRay( LightRay& lightray )
00344 {
00345 
00346   if(ALIUtils::debug >= 5) std::cout << "***** OptOCOPS::fastTraversesLightRay" <<std::endl;
00347   if (ALIUtils::debug >= 2) std::cout << "LR: FAST TRAVERSES COPS  " << name() << std::endl;
00348 
00349   //---------- Get intersection 
00350   CLHEP::Hep3Vector ZAxis(0.,0,1.);
00351   CLHEP::HepRotation rmt = rmGlob();
00352   ZAxis = rmt * ZAxis;
00353   lightray.intersect( ALIPlane(centreGlob(), ZAxis) );
00354   CLHEP::Hep3Vector inters = lightray.point();
00355   lightray.setPoint( inters );
00356 
00357   if (ALIUtils::debug >= 2) {
00358     lightray.dumpData(" after COPS ");
00359   }
00360 
00361 }     
00362 
00363 
00364 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00365 ALIdouble* OptOCOPS::convertPointToLocalCoordinates( const CLHEP::Hep3Vector& point)
00366 {
00367   if(ALIUtils::debug >= 1) std::cout << "***** OptOCOPS::convertPointToLocalCoordinates" <<std::endl;
00368   ALIdouble* interslc = new ALIdouble[2];
00369 
00370   //----- X value
00371   CLHEP::HepRotation rmt = rmGlob();
00372   CLHEP::Hep3Vector XAxism(1.,0.,0.);
00373   XAxism*=rmt;
00374   if( ALIUtils::debug >= 5) ALIUtils::dump3v( (this)->centreGlob(),  "centre glob sensor2D" );
00375   if( ALIUtils::debug >= 5) ALIUtils::dumprm( rmt,  "rotation matrix sensor2D" );
00376   //t  ALIUtils::dump3v(point - (this)->centreGlob() , "inters - (this)->centreGlob()");
00377   //t  ALIUtils::dump3v(XAxism , "XAxism");
00378   interslc[0] = (point - (this)->centreGlob() ) * XAxism;
00379   
00380   //----- Y value
00381   CLHEP::Hep3Vector YAxism(0.,1.,0.);
00382   YAxism*=rmt;
00383   //t  ALIUtils::dump3v(YAxism , "YAxism");
00384   interslc[1] = (point - (this)->centreGlob() ) * YAxism;
00385 
00386   if( ALIUtils::debug >=5 ) {
00387     std::cout << " intersection in local coordinates: X= " << interslc[0] << "  Y= " << interslc[1] << std::endl;
00388   }
00389   return interslc;
00390 }
00391 
00392 
00393 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00394 ALIdouble OptOCOPS::getMeasFromInters( ALILine& line_xhair, ALILine& ccd, CLHEP::Hep3Vector& cops_line )
00395 {
00396 
00397   if(ALIUtils::debug >= 5) std::cout << "***** OptOCOPS::getMeasFromInters" <<std::endl;
00398   CLHEP::Hep3Vector inters = line_xhair.intersect( ccd, 0 ) - ccd.pt(); 
00399   ALIdouble sign = inters*ccd.vec(); 
00400   if( sign != 0 ){
00401     sign = fabs(sign)/sign;
00402     //    std::cout << "  @@@@@@@@@@@@ sign = " << sign << std::endl;
00403     //   ALIUtils::dump3v(inters, " intersection " );
00404     //   ALIUtils::dump3v( ccd.vec(), " cops_line ");
00405   } //sign can be zero only if inters is 0, because they are parallel
00406   return sign*inters.mag();
00407 }
00408 
00409 
00410 #ifdef COCOA_VIS
00411 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00412 void OptOCOPS::fillVRML()
00413 {
00414  
00415   ALIVRMLMgr& vrmlmgr = ALIVRMLMgr::getInstance();
00416 
00417   //---------- Position four CCDs (locally, i.e. with respect to centre)
00418   //----- Get first CCD length, that will be used to give a default placement to the CCDs
00419   ALIdouble CCDlength = findExtraEntryValue("CCDlength");
00420   if( CCDlength == 0. ) CCDlength = 2048*14 * 1.E-6; // (in meters, the default unit)
00421   //Original CCDdim value was 10; .05 works well
00422 //  ALIdouble CCDdim = .040;
00423     ALIdouble CCDdim = 2048*14 * 1.E-6;
00424   //Original was divided by 10
00425 //  ALIdouble CCDwidth = CCDdim/10.;
00426   ALIdouble CCDwidth = .005;
00427 
00428   if(ALIUtils::debug >= 4) std::cout << " ccds0 " << ccds[0] << "ccds1 " << ccds[1] << std::endl;
00429   ALIColour colup( 1.,0.,0., 0.);
00430   ALIColour coldown( 0.,1.,0., 0.);
00431   ALIColour colleft( 0.,0.,1., 0.);
00432   ALIColour colright( 0.,1.,1., 0.);
00433   //----- Upper CCD (leftmost point & direction dowel1-dowel2)
00434   //original ccdsize was 50; 1 works ok
00435   ALIdouble ccdsize = 1.;
00436 
00437   // VRML objects are drawn 'after rotation into system'; so to make all CCDs look the
00438   //  same in the drawing, CCDwidth parameters must be the same
00439   // x, y , z , color
00440 
00441   //----- Upper CCD 
00442   vrmlmgr.AddBoxDisplaced( *this, CCDdim, CCDwidth, CCDwidth, ccdsize*(ccds[0].pt()+0.5*CCDlength*ccds[0].vec()), &colup);
00443   //----- Lower CCD (leftmost point & direction dowel2-dowel1)
00444   vrmlmgr.AddBoxDisplaced( *this, CCDdim, CCDwidth, CCDwidth, ccdsize*(ccds[1].pt()+0.5*CCDlength*ccds[1].vec()), &coldown );
00445   //----- left CCD (uppermost point & direction perpendicular to dowel2-dowel1)
00446   vrmlmgr.AddBoxDisplaced( *this, CCDwidth, CCDdim, CCDwidth, ccdsize*(ccds[2].pt()+0.5*CCDlength*ccds[2].vec()), &colleft );
00447   //----- right CCD (uppermost point & direction perpendicular to dowel2-dowel1)
00448   vrmlmgr.AddBoxDisplaced( *this, CCDwidth, CCDdim, CCDwidth, ccdsize*(ccds[3].pt()+0.5*CCDlength*ccds[3].vec()), &colright );
00449 
00450   vrmlmgr.SendReferenceFrame( *this, CCDdim); 
00451   vrmlmgr.SendName( *this, 0.01 );
00452 
00453 }
00454 
00455 
00456 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00457 void OptOCOPS::fillIguana()
00458 {
00459   //---------- Position four CCDs (locally, i.e. with respect to centre)
00460   //----- Get first CCD length, that will be used to give a default placement to the CCDs
00461   ALIdouble CCDlength;
00462   ALIbool pexists = findExtraEntryValueIfExists("CCDlength",CCDlength);
00463   if( !pexists ) CCDlength = 2048*14 * 1.E-6;
00464   ALIdouble CCDdim = 2048*14 * 1.E-6;
00465   ALIdouble CCDwidth = .005;
00466 
00467   if(ALIUtils::debug >= 4) std::cout << " ccds0 " << ccds[0] << "ccds1 " << ccds[1] << std::endl;
00468   ALIColour colup( 0.2,1.,0., 0.);
00469   ALIColour coldown( 0.3,1.,0., 0.);
00470   ALIColour colleft( 0.4,1.,0., 0.);
00471   ALIColour colright( 0.5,1.,0., 0.);
00472   //----- Upper CCD (leftmost point & direction dowel1-dowel2)
00473   //original ccdsize was 50; 1 works ok
00474   ALIdouble ccdsize = 1;
00475 
00476   // VRML objects are drawn 'after rotation into system'; so to make all CCDs look the
00477   //  same in the drawing, CCDwidth parameters must be the same
00478   // x, y , z , color
00479 
00480   std::vector<ALIdouble> spar;
00481   spar.push_back(CCDdim);
00482   spar.push_back(CCDwidth);
00483   spar.push_back(CCDwidth);
00484   //----- Upper CCD 
00485  IgCocoaFileMgr::getInstance().addSolid( *this, "BOX", spar, &colup, ccdsize*(ccds[0].pt()+0.5*CCDlength*ccds[0].vec()));
00486   //----- Lower CCD (leftmost point & direction dowel2-dowel1)
00487  IgCocoaFileMgr::getInstance().addSolid( *this, "BOX", spar, &coldown, ccdsize*(ccds[1].pt()+0.5*CCDlength*ccds[1].vec()) );
00488   //----- left CCD (uppermost point & direction perpendicular to dowel2-dowel1)
00489   std::vector<ALIdouble> spar2;
00490   spar2.push_back(CCDwidth);
00491   spar2.push_back(CCDdim);
00492   spar2.push_back(CCDwidth);
00493   IgCocoaFileMgr::getInstance().addSolid( *this, "BOX", spar2, &colleft, ccdsize*(ccds[2].pt()+0.5*CCDlength*ccds[2].vec()));
00494   //----- right CCD (uppermost point & direction perpendicular to dowel2-dowel1)
00495   IgCocoaFileMgr::getInstance().addSolid( *this, "BOX", spar2, &colright, ccdsize*(ccds[3].pt()+0.5*CCDlength*ccds[3].vec()));
00496 
00497 }
00498 #endif
00499 
00500 
00501 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00502 void OptOCOPS::constructSolidShape()
00503 {
00504   ALIdouble go;
00505   GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00506   gomgr->getGlobalOptionValue("VisScale", go );
00507 
00508   theSolidShape = new CocoaSolidShapeBox( "Box", go*5.*cm/m, go*5.*cm/m, go*1.*cm/m ); //COCOA internal units are meters
00509 }