Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:03

0001 //   COCOA class implementation file
0002 //Id:  OptOCops.cc
0003 //CAT: Model
0004 //
0005 //   History: v1.0
0006 //   Pedro Arce
0007 
0008 #include "Alignment/CocoaModel/interface/OptOCOPS.h"
0009 #include "Alignment/CocoaModel/interface/LightRay.h"
0010 #include "Alignment/CocoaModel/interface/Measurement.h"
0011 #include "Alignment/CocoaModel/interface/Model.h"
0012 #ifdef COCOA_VIS
0013 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
0014 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
0015 #endif
0016 #include "Alignment/CocoaModel/interface/ALILine.h"
0017 #include "Alignment/CocoaModel/interface/ALIPlane.h"
0018 #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
0019 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
0020 #include "FWCore/Utilities/interface/isFinite.h"
0021 
0022 #include <iostream>
0023 #include <iomanip>
0024 #include <fstream>
0025 #include <cmath>  // among others include also floating-point std::abs functions
0026 #include <cstdlib>
0027 
0028 using namespace CLHEP;
0029 
0030 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0031 //@@  Make measurement as distance to previous object 'screen'
0032 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0033 void OptOCOPS::defaultBehaviour(LightRay& lightray, Measurement& meas) {
0034   if (ALIUtils::debug >= 5)
0035     std::cout << "***** OptOCOPS::defaultBehaviour" << std::endl;
0036   makeMeasurement(lightray, meas);
0037 }
0038 
0039 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0040 //@@  Make measurement as distance to previous object 'screen'
0041 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0042 void OptOCOPS::makeMeasurement(LightRay& lightray, Measurement& meas) {
0043   if (ALIUtils::debug >= 4)
0044     std::cout << "***** OptOCOPS::makeMeasurement(lightray, meas) " << std::endl;
0045   //---------- Centre of COPS is at dowel point 2
0046   CLHEP::Hep3Vector dowel2 = centreGlob();
0047   //---------- Coordinates of dowel point 1 are given with respect to dowel point 2 (in local reference frame)
0048   ALIdouble posx12 = findExtraEntryValue("dowel1X");
0049   // Changed default value to .045 from .03
0050   if (posx12 == 0.)
0051     posx12 = -0.045;  //samir changed sign to correct the dowel 1st pixel
0052   CLHEP::Hep3Vector dowel1(posx12, findExtraEntryValue("dowel1Y"), 0.);
0053   CLHEP::HepRotation rmt = rmGlob();
0054   dowel1 = rmt * dowel1;
0055   dowel1 += dowel2;
0056   if (ALIUtils::debug >= 3) {
0057     ALIUtils::dump3v(dowel2, " dowel2");
0058     ALIUtils::dump3v(dowel1, " dowel1");
0059   }
0060 
0061   //---------- Get line joining dowel1-dowel2 and perpendicular to it inside cops
0062   //  CLHEP::Hep3Vector line_dowel21 = - (dowel1-dowel2 ); //////
0063   CLHEP::Hep3Vector line_dowel21 = (dowel1 - dowel2);  // samir changed sign to correct the dowel 1st pixel
0064   CLHEP::Hep3Vector ZAxis(0., 0, 1.);
0065   ZAxis = rmt * ZAxis;
0066   CLHEP::Hep3Vector line_dowel21_perp = ZAxis.cross(line_dowel21);
0067   if (ALIUtils::debug >= 3) {
0068     ALIUtils::dump3v(line_dowel21, " line_dowel21");
0069     ALIUtils::dump3v(line_dowel21_perp, " line_dowel21_perp");
0070   }
0071 
0072   //---------- Position four CCDs (locally, i.e. with respect to centre)
0073   //----- Get first CCD length, that will be used to give a default placement to the CCDs
0074   ALIdouble CCDlength = findExtraEntryValue("CCDlength");
0075   if (CCDlength == 0.)
0076     CCDlength = 2048 * 14 * 1.E-6;  // (in meters, the default unit)
0077 
0078   //  global / local output of ccd location in RF was reversed, I am swapping
0079 
0080   //----- Upper CCD (leftmost point & direction dowel1-dowel2)
0081   if (ALIUtils::debug >= 3)
0082     std::cout << std::endl << "***** UP CCD *****" << std::endl << "******************" << std::endl << std::endl;
0083   ALIdouble posX = findExtraEntryValue("upCCDXtoDowel2");
0084   ALIdouble posY;
0085   ALIbool eexists = findExtraEntryValueIfExists("upCCDYtoDowel2", posY);
0086   if (!eexists)
0087     posY = CCDlength + 0.004;
0088   //if(!eexists) posY =  0.004;
0089   CLHEP::Hep3Vector posxy(posX, posY, 0);
0090   if (ALIUtils::debug >= 3)
0091     std::cout << " %%%% CCD distances to Dowel2: " << std::endl;
0092   if (ALIUtils::debug >= 3)
0093     std::cout << "   up ccd in local RF " << posxy << std::endl;
0094   posxy = rmt * posxy;
0095   if (ALIUtils::debug >= 3)
0096     std::cout << "   up ccd in global RF " << posxy << std::endl;
0097   // ALILine upCCD( dowel2 + posxy, -line_dowel21 );
0098   // ccds[0] = ALILine( posxy, -line_dowel21 );
0099   ALILine upCCD(dowel2 + posxy, line_dowel21);  // Samir changed sign to correct the dowel 1st pixel
0100   ccds[0] = ALILine(posxy, line_dowel21);       // samir changed sign to correct the dowel 1st pixel
0101   //----- Lower CCD (leftmost point & direction dowel2-dowel1)
0102   if (ALIUtils::debug >= 3)
0103     std::cout << std::endl << "***** DOWN CCD *****" << std::endl << "********************" << std::endl << std::endl;
0104   posX = findExtraEntryValue("downCCDXtoDowel2");
0105   eexists = findExtraEntryValueIfExists("downCCDYtoDowel2", posY);
0106   if (!eexists)
0107     posY = 0.002;
0108   posxy = CLHEP::Hep3Vector(posX, posY, 0);
0109   if (ALIUtils::debug >= 3)
0110     std::cout << "   down ccd in local RF " << posxy << std::endl;
0111   posxy = rmt * posxy;
0112   if (ALIUtils::debug >= 3)
0113     std::cout << "   down ccd in global RF " << posxy << std::endl;
0114   //  ALILine downCCD( dowel2 + posxy, -line_dowel21 );
0115   // ccds[1] = ALILine( posxy, -line_dowel21 );
0116 
0117   ALILine downCCD(dowel2 + posxy, line_dowel21);  //samir changed signto correct the dowel 1st pixel
0118   ccds[1] = ALILine(posxy, line_dowel21);         // samir changed sign to correct the dowel 1st pixel
0119 
0120   //----- left CCD (uppermost point & direction perpendicular to dowel2-dowel1)
0121 
0122   if (ALIUtils::debug >= 3)
0123     std::cout << std::endl << "***** LEFT CCD *****" << std::endl << "********************" << std::endl << std::endl;
0124   eexists = findExtraEntryValueIfExists("leftCCDXtoDowel2", posX);
0125   //  if(!eexists) posX = -0.002;
0126   if (!eexists)
0127     posX = -CCDlength - 0.002;  // Samir changed sign to correct the dowel 1st pixel
0128   posY = findExtraEntryValue("leftCCDYtoDowel2");
0129   posxy = CLHEP::Hep3Vector(posX, posY, 0);
0130   if (ALIUtils::debug >= 3)
0131     std::cout << "   left ccd in local RF " << posxy << std::endl;
0132   posxy = rmt * posxy;
0133   if (ALIUtils::debug >= 3)
0134     std::cout << "   left ccd in global RF " << posxy << std::endl;
0135   // ALILine leftCCD( dowel2 + posxy, line_dowel21_perp );
0136   // ccds[2] = ALILine(  posxy, line_dowel21_perp );
0137 
0138   ALILine leftCCD(dowel2 + posxy, -line_dowel21_perp);  //samir changed sign to correct the dowel 1st pixel
0139   ccds[2] = ALILine(posxy, -line_dowel21_perp);         //samir changed sign to correct the dowel 1st pixel
0140 
0141   //----- right CCD (uppermost point & direction perpendicular to dowel2-dowel1)
0142   if (ALIUtils::debug >= 3)
0143     std::cout << std::endl << "***** RIGHT CCD *****" << std::endl << "*********************" << std::endl << std::endl;
0144   eexists = findExtraEntryValueIfExists("rightCCDXtoDowel2", posX);
0145   // if(!eexists) posX = -CCDlength - 0.004;
0146   if (!eexists)
0147     posX = -0.004;  // samir tried to change in order to adjust the position of 1 st pixel.
0148   posY = findExtraEntryValue("rightCCDYtoDowel2");
0149   posxy = CLHEP::Hep3Vector(posX, posY, 0);
0150   if (ALIUtils::debug >= 3)
0151     std::cout << "   right ccd in local RF " << posxy << std::endl;
0152   posxy = rmt * posxy;
0153   if (ALIUtils::debug >= 3)
0154     std::cout << "   right ccd in global RF " << posxy << std::endl << std::endl;
0155   // ALILine rightCCD( dowel2 + posxy, line_dowel21_perp );
0156   // ccds[3] = ALILine(  posxy, line_dowel21_perp );
0157 
0158   ALILine rightCCD(dowel2 + posxy, -line_dowel21_perp);  //samir changed sign to correct the dowel 1st pixel
0159   ccds[3] = ALILine(posxy, -line_dowel21_perp);          //samir changed sign to correct the dowel 1st pixel
0160 
0161   if (ALIUtils::debug >= 3) {
0162     std::cout << " %%%  Positions of CCDs in global RF: " << std::endl << std::endl;
0163     std::cout << "     upCCD: " << upCCD << std::endl;
0164     std::cout << "     downCCD: " << downCCD << std::endl;
0165     std::cout << "     leftCCD: " << leftCCD << std::endl;
0166     std::cout << "     rightCCD: " << rightCCD << std::endl << std::endl;
0167   }
0168 
0169   //---------- Intersect x-hair laser with COPS
0170   if (ALIUtils::debug >= 3)
0171     std::cout << " %%%  Intersecting x-hair laser with COPS: " << std::endl;
0172   ALIPlane copsPlane(centreGlob(), ZAxis);
0173   lightray.intersect(*this);
0174   CLHEP::Hep3Vector inters = lightray.point();
0175   if (ALIUtils::debug >= 3) {
0176     ALIUtils::dump3v(inters, " Intersection of x-hair laser with COPS ");
0177   }
0178 
0179   //---------- Get cross of x-hair laser:
0180   if (ALIUtils::debug >= 5)
0181     std::cout << "1. Get the OptO x-hair laser from the measurement list of OptOs" << std::endl;
0182 
0183   OpticalObject* xhairOptO = *(meas.OptOList().begin());
0184 
0185   if (ALIUtils::debug >= 35)
0186     std::cout << "2. Get the Y of the laser and project it on the COPS" << std::endl;
0187   CLHEP::Hep3Vector YAxis_xhair(0., 1., 0.);
0188   const CLHEP::HepRotation& rmtx = xhairOptO->rmGlob();
0189   YAxis_xhair = rmtx * YAxis_xhair;
0190   ALILine Yline_xhair(inters, copsPlane.project(YAxis_xhair));
0191   if (ALIUtils::debug >= 3) {
0192     std::cout << "  %%%% Projecting x-hair laser on COPS: " << std::endl;
0193     ALIUtils::dump3v(YAxis_xhair, " Y direction of laser ");
0194     std::cout << " Y line of laser projected on COPS " << Yline_xhair << std::endl;
0195   }
0196 
0197   if (ALIUtils::debug >= 5)
0198     std::cout << " 3. Get the X of the laser (correct it if cross is not 90o) and project it on the COPS" << std::endl;
0199 
0200   ALIdouble anglebx;
0201   eexists = xhairOptO->findExtraEntryValueIfExists("angleBetweenAxis", anglebx);
0202   if (!eexists)
0203     anglebx = PI / 2.;
0204   CLHEP::Hep3Vector XAxis_xhair = YAxis_xhair;
0205 
0206   //   if (ALIUtils::debug >= 3) ALIUtils::dump3v(XAxis_xhair," X of laser1 ");
0207   ZAxis = CLHEP::Hep3Vector(0., 0., 1.);
0208   ZAxis = rmtx * ZAxis;
0209   XAxis_xhair.rotate(anglebx, ZAxis);
0210   ALILine Xline_xhair(inters, copsPlane.project(XAxis_xhair));
0211   if (ALIUtils::debug >= 3) {
0212     std::cout << "angleBetweenAxis = " << anglebx << std::endl;
0213     ALIUtils::dump3v(XAxis_xhair, " X direction of laser ");
0214     std::cout << " X line of laser projected on COPS " << Xline_xhair << std::endl;
0215   }
0216 
0217   //---------- Get measurement as intersection with four CCDs
0218   if (ALIUtils::debug >= 3)
0219     std::cout << "  Getting measurements as intersection with four CCDs: " << std::endl;
0220 
0221   if (ALIUtils::debug >= 4)
0222     std::cout << "intersecting with upCCD " << std::endl;
0223   ALIdouble measv[4][2];
0224 
0225   // swap Y and X line_xhair by exchanging second index
0226 
0227   if (ALIUtils::debug >= 5)
0228     std::cout << "$@S@ measv[0][0] upccd " << std::endl;
0229   measv[0][0] = getMeasFromInters(Yline_xhair, upCCD, line_dowel21);
0230   if (ALIUtils::debug >= 5)
0231     std::cout << "$@$@ measv[0][1] upccd " << std::endl;
0232   measv[0][1] = getMeasFromInters(Xline_xhair, upCCD, line_dowel21);
0233 
0234   //---- check if postive or negative:
0235   if (ALIUtils::debug >= 4)
0236     std::cout << "intersecting with downCCD " << std::endl;
0237   measv[1][0] = getMeasFromInters(Yline_xhair, downCCD, line_dowel21);
0238   measv[1][1] = getMeasFromInters(Xline_xhair, downCCD, line_dowel21);
0239 
0240   //
0241 
0242   if (ALIUtils::debug >= 4)
0243     std::cout << "intersecting with leftCCD " << std::endl;
0244   measv[2][0] = getMeasFromInters(Xline_xhair, leftCCD, line_dowel21_perp);
0245   measv[2][1] = getMeasFromInters(Yline_xhair, leftCCD, line_dowel21_perp);
0246   if (ALIUtils::debug >= 4)
0247     std::cout << "intersecting with rightCCD " << std::endl;
0248   measv[3][0] = getMeasFromInters(Xline_xhair, rightCCD, line_dowel21_perp);
0249   measv[3][1] = getMeasFromInters(Yline_xhair, rightCCD, line_dowel21_perp);
0250 
0251   /* Both X and Y axis of the x-laser are intersected with each CCD and it checks that one of
0252   the two is inside the CCD(less than CCDlength/2). If no one is inside, it will give an
0253   exception. If both are inside (a strange case where, for example, the laser centre is very
0254   close and forms 45 degrees with the CCD) it will also make an exception (if you prefer, I can
0255   put a warning saying that you have two measurements, but I guess this should never happen for
0256   you, so I better give an exception and you don't risk to overpass this warning).
0257 
0258   Then it is mandatory that you put the CCDlength parameter (I could put a default one if
0259   you prefer).
0260 
0261 
0262   ALIbool measInCCD[2];
0263   ALIuint ii,jj;
0264   for( ii = 0; ii < 4; ii++ ) {
0265     for( jj = 0; jj < 2; jj++ ) {
0266       measInCCD[jj] =  std::abs( measv[ii][jj] ) < CCDlength/2;
0267     }
0268     if (ALIUtils::debug >= 2) std::cout << "$@$@ CHECK CCD = " << ii << std::endl;
0269     if( measInCCD[0] && measInCCD[1] ){
0270       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;
0271       exit(1);
0272     } else if( !(measInCCD[0] || measInCCD[1]) ){
0273       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;
0274       exit(1);
0275     } else {
0276       measInCCD[0] ?  meas.setValueSimulated( ii, measv[ii][0] ) :
0277         meas.setValueSimulated( ii, measv[ii][1] );
0278     }
0279   }
0280   */
0281 
0282   ALIstring measNames[4] = {"up", "down", "left", "right"};
0283   ALIbool laserLine;
0284   if (ALIUtils::debug >= 2)
0285     std::cout << std::endl
0286               << "--> Now comparing measurement in ccds by x and y laser lines (will always choose the smaller one) "
0287               << std::endl;
0288 
0289   unsigned int ii;
0290   for (ii = 0; ii < 4; ii++) {
0291     if (ALIUtils::debug >= 2)
0292       std::cout << "\tmeas CCD " << measNames[ii] << " ii=(" << ii
0293                 << ") \t Values: "
0294                 //<< (std::abs( measv[ii][0] ) <  std::abs( measv[ii][1])
0295                 << " " << std::abs(measv[ii][0]) << " " << std::abs(measv[ii][1])
0296                 << "  edm::isNotFinite() = " << edm::isNotFinite(measv[ii][1]) << std::endl;
0297 
0298     if (meas.xlaserLine(ii) != -1) {
0299       laserLine = ALIbool(meas.xlaserLine(ii));
0300     } else {
0301       //  Problem here !!!
0302       //
0303       //  Somehow measv[][1] can occasionally return value of 'nan'
0304       //  which is interpretted as less than any real value
0305       //
0306       if (edm::isNotFinite(measv[ii][1]) != 0) {
0307         measv[ii][1] = 1e99;
0308         if (ALIUtils::debug >= 2)
0309           std::cout << "  --> Swapping for " << measv[ii][1] << "(inf)" << std::endl;
0310       }
0311 
0312       laserLine = std::abs(measv[ii][0]) < std::abs(measv[ii][1]);
0313 
0314       meas.setXlaserLine(ii, int(laserLine));
0315     }
0316     laserLine ? meas.setValueSimulated(ii, measv[ii][0]) : meas.setValueSimulated(ii, measv[ii][1]);
0317   }
0318 
0319   if (ALIUtils::debug >= 2)
0320     std::cout << std::endl;  //Keep format of debug output reasonable
0321 
0322   // try to identify pathological cases: up and down CCD are intersected by the same
0323   // laser line (say X) and the same for the left and right CCD
0324 
0325   if (ALIUtils::debug >= 2)
0326     std::cout << "***** OptOCOPS::makeMeasurement  - identify pathological cases U and D intersected by same line"
0327               << std::endl;
0328   ALIbool xlaserDir[4];
0329   for (ii = 0; ii < 4; ii++) {
0330     //    xlaserDir[ii] = std::abs( measv[ii][0] ) <  std::abs( measv[ii][1] );
0331     xlaserDir[ii] = ALIbool(meas.xlaserLine(ii));
0332   }
0333   if (xlaserDir[0] ^ xlaserDir[1]) {
0334     std::cerr << "!!EXITING up and down CCDs intersected by different x-laser line " << xlaserDir[0] << " "
0335               << xlaserDir[1] << std::endl;
0336     exit(1);
0337   }
0338   if (xlaserDir[2] ^ xlaserDir[3]) {
0339     std::cerr << "!!EXITING right and left CCDs intersected by different x-laser line " << xlaserDir[0] << " "
0340               << xlaserDir[1] << std::endl;
0341     exit(1);
0342   }
0343 
0344   if (ALIUtils::debug >= 5)
0345     std::cout << "***** OptOCOPS::makeMeasurement - now output sim values" << std::endl;
0346 
0347   if (ALIUtils::debug >= 1) {
0348     ALIstring chrg = "";
0349     std::cout << "REAL value: " << chrg << "U: " << 1000 * meas.value()[0] << chrg << " D: " << 1000 * meas.value()[1]
0350               << " L: " << 1000 * meas.value()[2] << " R: " << 1000 * meas.value()[3] << " (mm)  " << (this)->name()
0351               << std::endl;
0352     ALIdouble detU = 1000 * meas.valueSimulated(0);
0353     if (std::abs(detU) <= 1.e-9)
0354       detU = 0.;
0355     ALIdouble detD = 1000 * meas.valueSimulated(1);
0356     if (std::abs(detD) <= 1.e-9)
0357       detD = 0.;
0358     ALIdouble detL = 1000 * meas.valueSimulated(2);
0359     if (std::abs(detL) <= 1.e-9)
0360       detL = 0.;
0361     ALIdouble detR = 1000 * meas.valueSimulated(3);
0362     if (std::abs(detR) <= 1.e-9)
0363       detR = 0.;
0364     std::cout << "SIMU value: " << chrg
0365               << "U: "
0366               // << setprecision(3) << setw(4)
0367               << detU << chrg << " D: " << detD << chrg << " L: " << detL << chrg << " R: " << detR << " (mm)  "
0368               << (this)->name() << std::endl;
0369   }
0370 }
0371 
0372 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0373 //@@ Fast simulation of Light Ray traverses
0374 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0375 void OptOCOPS::fastTraversesLightRay(LightRay& lightray) {
0376   if (ALIUtils::debug >= 5)
0377     std::cout << "***** OptOCOPS::fastTraversesLightRay" << std::endl;
0378   if (ALIUtils::debug >= 2)
0379     std::cout << "LR: FAST TRAVERSES COPS  " << name() << std::endl;
0380 
0381   //---------- Get intersection
0382   CLHEP::Hep3Vector ZAxis(0., 0, 1.);
0383   CLHEP::HepRotation rmt = rmGlob();
0384   ZAxis = rmt * ZAxis;
0385   lightray.intersect(ALIPlane(centreGlob(), ZAxis));
0386   CLHEP::Hep3Vector inters = lightray.point();
0387   lightray.setPoint(inters);
0388 
0389   if (ALIUtils::debug >= 2) {
0390     lightray.dumpData(" after COPS ");
0391   }
0392 }
0393 
0394 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0395 ALIdouble* OptOCOPS::convertPointToLocalCoordinates(const CLHEP::Hep3Vector& point) {
0396   if (ALIUtils::debug >= 1)
0397     std::cout << "***** OptOCOPS::convertPointToLocalCoordinates" << std::endl;
0398   ALIdouble* interslc = new ALIdouble[2];
0399 
0400   //----- X value
0401   CLHEP::HepRotation rmt = rmGlob();
0402   CLHEP::Hep3Vector XAxism(1., 0., 0.);
0403   XAxism *= rmt;
0404   if (ALIUtils::debug >= 5)
0405     ALIUtils::dump3v((this)->centreGlob(), "centre glob sensor2D");
0406   if (ALIUtils::debug >= 5)
0407     ALIUtils::dumprm(rmt, "rotation matrix sensor2D");
0408   //t  ALIUtils::dump3v(point - (this)->centreGlob() , "inters - (this)->centreGlob()");
0409   //t  ALIUtils::dump3v(XAxism , "XAxism");
0410   interslc[0] = (point - (this)->centreGlob()) * XAxism;
0411 
0412   //----- Y value
0413   CLHEP::Hep3Vector YAxism(0., 1., 0.);
0414   YAxism *= rmt;
0415   //t  ALIUtils::dump3v(YAxism , "YAxism");
0416   interslc[1] = (point - (this)->centreGlob()) * YAxism;
0417 
0418   if (ALIUtils::debug >= 5) {
0419     std::cout << " intersection in local coordinates: X= " << interslc[0] << "  Y= " << interslc[1] << std::endl;
0420   }
0421   return interslc;
0422 }
0423 
0424 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0425 ALIdouble OptOCOPS::getMeasFromInters(ALILine& line_xhair, ALILine& ccd, CLHEP::Hep3Vector& cops_line) {
0426   if (ALIUtils::debug >= 5)
0427     std::cout << "***** OptOCOPS::getMeasFromInters" << std::endl;
0428   CLHEP::Hep3Vector inters = line_xhair.intersect(ccd, false) - ccd.pt();
0429   ALIdouble sign = inters * ccd.vec();
0430   if (sign != 0) {
0431     sign = std::abs(sign) / sign;
0432     //    std::cout << "  @@@@@@@@@@@@ sign = " << sign << std::endl;
0433     //   ALIUtils::dump3v(inters, " intersection " );
0434     //   ALIUtils::dump3v( ccd.vec(), " cops_line ");
0435   }  //sign can be zero only if inters is 0, because they are parallel
0436   return sign * inters.mag();
0437 }
0438 
0439 #ifdef COCOA_VIS
0440 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0441 void OptOCOPS::fillVRML() {
0442   ALIVRMLMgr& vrmlmgr = ALIVRMLMgr::getInstance();
0443 
0444   //---------- Position four CCDs (locally, i.e. with respect to centre)
0445   //----- Get first CCD length, that will be used to give a default placement to the CCDs
0446   ALIdouble CCDlength = findExtraEntryValue("CCDlength");
0447   if (CCDlength == 0.)
0448     CCDlength = 2048 * 14 * 1.E-6;  // (in meters, the default unit)
0449                                     //Original CCDdim value was 10; .05 works well
0450                                     //  ALIdouble CCDdim = .040;
0451   ALIdouble CCDdim = 2048 * 14 * 1.E-6;
0452   //Original was divided by 10
0453   //  ALIdouble CCDwidth = CCDdim/10.;
0454   ALIdouble CCDwidth = .005;
0455 
0456   if (ALIUtils::debug >= 4)
0457     std::cout << " ccds0 " << ccds[0] << "ccds1 " << ccds[1] << std::endl;
0458   ALIColour colup(1., 0., 0., 0.);
0459   ALIColour coldown(0., 1., 0., 0.);
0460   ALIColour colleft(0., 0., 1., 0.);
0461   ALIColour colright(0., 1., 1., 0.);
0462   //----- Upper CCD (leftmost point & direction dowel1-dowel2)
0463   //original ccdsize was 50; 1 works ok
0464   ALIdouble ccdsize = 1.;
0465 
0466   // VRML objects are drawn 'after rotation into system'; so to make all CCDs look the
0467   //  same in the drawing, CCDwidth parameters must be the same
0468   // x, y , z , color
0469 
0470   //----- Upper CCD
0471   vrmlmgr.AddBoxDisplaced(
0472       *this, CCDdim, CCDwidth, CCDwidth, ccdsize * (ccds[0].pt() + 0.5 * CCDlength * ccds[0].vec()), &colup);
0473   //----- Lower CCD (leftmost point & direction dowel2-dowel1)
0474   vrmlmgr.AddBoxDisplaced(
0475       *this, CCDdim, CCDwidth, CCDwidth, ccdsize * (ccds[1].pt() + 0.5 * CCDlength * ccds[1].vec()), &coldown);
0476   //----- left CCD (uppermost point & direction perpendicular to dowel2-dowel1)
0477   vrmlmgr.AddBoxDisplaced(
0478       *this, CCDwidth, CCDdim, CCDwidth, ccdsize * (ccds[2].pt() + 0.5 * CCDlength * ccds[2].vec()), &colleft);
0479   //----- right CCD (uppermost point & direction perpendicular to dowel2-dowel1)
0480   vrmlmgr.AddBoxDisplaced(
0481       *this, CCDwidth, CCDdim, CCDwidth, ccdsize * (ccds[3].pt() + 0.5 * CCDlength * ccds[3].vec()), &colright);
0482 
0483   vrmlmgr.SendReferenceFrame(*this, CCDdim);
0484   vrmlmgr.SendName(*this, 0.01);
0485 }
0486 
0487 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0488 void OptOCOPS::fillIguana() {
0489   //---------- Position four CCDs (locally, i.e. with respect to centre)
0490   //----- Get first CCD length, that will be used to give a default placement to the CCDs
0491   ALIdouble CCDlength;
0492   ALIbool pexists = findExtraEntryValueIfExists("CCDlength", CCDlength);
0493   if (!pexists)
0494     CCDlength = 2048 * 14 * 1.E-6;
0495   ALIdouble CCDdim = 2048 * 14 * 1.E-6;
0496   ALIdouble CCDwidth = .005;
0497 
0498   if (ALIUtils::debug >= 4)
0499     std::cout << " ccds0 " << ccds[0] << "ccds1 " << ccds[1] << std::endl;
0500   ALIColour colup(0.2, 1., 0., 0.);
0501   ALIColour coldown(0.3, 1., 0., 0.);
0502   ALIColour colleft(0.4, 1., 0., 0.);
0503   ALIColour colright(0.5, 1., 0., 0.);
0504   //----- Upper CCD (leftmost point & direction dowel1-dowel2)
0505   //original ccdsize was 50; 1 works ok
0506   ALIdouble ccdsize = 1;
0507 
0508   // VRML objects are drawn 'after rotation into system'; so to make all CCDs look the
0509   //  same in the drawing, CCDwidth parameters must be the same
0510   // x, y , z , color
0511 
0512   std::vector<ALIdouble> spar;
0513   spar.push_back(CCDdim);
0514   spar.push_back(CCDwidth);
0515   spar.push_back(CCDwidth);
0516   //----- Upper CCD
0517   IgCocoaFileMgr::getInstance().addSolid(
0518       *this, "BOX", spar, &colup, ccdsize * (ccds[0].pt() + 0.5 * CCDlength * ccds[0].vec()));
0519   //----- Lower CCD (leftmost point & direction dowel2-dowel1)
0520   IgCocoaFileMgr::getInstance().addSolid(
0521       *this, "BOX", spar, &coldown, ccdsize * (ccds[1].pt() + 0.5 * CCDlength * ccds[1].vec()));
0522   //----- left CCD (uppermost point & direction perpendicular to dowel2-dowel1)
0523   std::vector<ALIdouble> spar2;
0524   spar2.push_back(CCDwidth);
0525   spar2.push_back(CCDdim);
0526   spar2.push_back(CCDwidth);
0527   IgCocoaFileMgr::getInstance().addSolid(
0528       *this, "BOX", spar2, &colleft, ccdsize * (ccds[2].pt() + 0.5 * CCDlength * ccds[2].vec()));
0529   //----- right CCD (uppermost point & direction perpendicular to dowel2-dowel1)
0530   IgCocoaFileMgr::getInstance().addSolid(
0531       *this, "BOX", spar2, &colright, ccdsize * (ccds[3].pt() + 0.5 * CCDlength * ccds[3].vec()));
0532 }
0533 #endif
0534 
0535 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0536 void OptOCOPS::constructSolidShape() {
0537   ALIdouble go;
0538   GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0539   gomgr->getGlobalOptionValue("VisScale", go);
0540 
0541   theSolidShape = new CocoaSolidShapeBox(
0542       "Box", go * 5. * cm / m, go * 5. * cm / m, go * 1. * cm / m);  //COCOA internal units are meters
0543 }