CMS 3D CMS Logo

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