Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // COCOA class implementation file

0002 // Id:  Measurement.C

0003 // CAT: Model

0004 // ---------------------------------------------------------------------------

0005 // History: v1.0

0006 // Authors:

0007 //   Pedro Arce

0008 
0009 #include "Alignment/CocoaModel/interface/MeasurementSensor2D.h"
0010 #include "Alignment/CocoaModel/interface/LightRay.h"
0011 #include "Alignment/CocoaModel/interface/OpticalObject.h"
0012 #ifdef COCOA_VIS
0013 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
0014 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
0015 #include "Alignment/IgCocoaFileWriter/interface/ALIVisLightPath.h"
0016 #endif
0017 
0018 #include <iostream>
0019 #include <iomanip>
0020 #include <cstdlib>
0021 
0022 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0023 //@@ calculate the simulated value propagating the light ray through the OptO that take part in the Measurement

0024 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0025 void MeasurementSensor2D::calculateSimulatedValue(ALIbool firstTime) {
0026   if (ALIUtils::debug >= 2)
0027     printStartCalculateSimulatedValue(this);  // important

0028   //---------- Create light ray

0029   LightRay* lightray = new LightRay;
0030 
0031   int isec = 0;  //security variable to check OptOList().size()

0032 
0033   //---------- Loop list of OptO that take part in measurement

0034   std::vector<OpticalObject*>::const_iterator vocite = OptOList().begin();
0035   //-  if( ALIUtils::debug >= 5) std::cout  << "OptOList size" <<OptOList().size() << std::endl;

0036 
0037   //----- Check that first object is 'laser' or 'source'

0038   if ((*vocite)->type() != "laser" && (*vocite)->type() != "source") {
0039     std::cerr << " first Optical object should be 'laser' or 'source'" << std::endl;
0040     DumpBadOrderOptOs();
0041     exit(1);
0042   }
0043 #ifdef COCOA_VIS
0044   ALIVisLightPath* vispath = 0;
0045   if (ALIUtils::getFirstTime()) {
0046     GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0047     if (gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
0048       vispath = IgCocoaFileMgr::getInstance().newLightPath(name());
0049     }
0050   }
0051 #endif
0052 
0053   //-  while( (*vocite) !=  *(OptOList().end()) ) {

0054   while ((vocite) != (OptOList().end())) {
0055     if (ALIUtils::debug >= 2)
0056       std::cout << std::endl << "@@@@ LR:OBJECT " << (*vocite)->name() << std::endl;
0057     isec++;
0058 
0059     //---------- Get the behaviour of the object w.r.t the measurement (if it reflects the light, let it traverse it, ...)

0060     ALIstring behav = getMeasuringBehaviour(vocite);
0061 
0062     //---------- Check that last object is a Sensor (that makes measuremnt and kill the lightray)

0063     if (lightray) {
0064       (*vocite)->participateInMeasurement(*lightray, *this, behav);
0065 
0066 #ifdef COCOA_VIS
0067       if (ALIUtils::getFirstTime()) {
0068         GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0069         if (gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
0070           ALIVRMLMgr::getInstance().addLightPoint(lightray->point());
0071           if (ALIUtils::debug >= 5)
0072             std::cout << "ALIVRMLMg  addLightPoint " << lightray->point() << (*vocite)->name() << std::endl;
0073         }
0074         if (gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
0075           vispath->addLightPoint(lightray->point(), (*vocite));
0076         }
0077       }
0078 #endif
0079 
0080     } else {
0081       std::cerr << "!! Last object is not Sensor 2D in measurement " << name() << std::endl;
0082       DumpBadOrderOptOs();
0083       exit(1);
0084     }
0085 
0086     ++vocite;
0087     if (isec > ALIint(OptOList().size())) {
0088       std::cerr << "ERROR DE PROGRAMACION EN GetSimulatedValue" << std::endl;
0089       exit(5);
0090     }
0091     //-    lightray.normalizeDirection();

0092   }
0093 
0094   delete lightray;
0095 
0096   if (ALIUtils::debug >= 9)
0097     std::cout << "end calculateSimulatedValue" << std::endl;
0098 }
0099 
0100 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0101 //@@ You input 8 numbers after 'TILMETER':

0102 //@@

0103 //@@ set the conversion factor from mV to mrad and the pedestal

0104 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0105 void MeasurementSensor2D::setConversionFactor(const std::vector<ALIstring>& wordlist) {
0106   //--------- Check that the format is OK

0107   theDisplaceX = 0;
0108   theDisplaceY = 0;
0109   theMultiplyX = 1.;
0110   theMultiplyY = 1.;
0111   //-  std::cout << " 0 factors for correction X = " << theDisplaceX << " Y " << theDisplaceY << std::endl;

0112 
0113   if (wordlist.size() == 1)
0114     return;
0115   if ((wordlist.size() != 3 && wordlist.size() != 5) || !ALIUtils::IsNumber(wordlist[1]) ||
0116       !ALIUtils::IsNumber(wordlist[2])) {
0117     std::cerr << "!! Sensor2D Measurement setConversionFactor: WRONG FORMAT " << std::endl
0118               << "It should be: SENSOR2D displace_X displace_Y " << std::endl
0119               << "It is: ";
0120     ALIUtils::dumpVS(wordlist, " ", std::cerr);
0121     exit(1);
0122   }
0123   theDisplaceX = atof(wordlist[1].c_str()) * valueDimensionFactor();
0124   theDisplaceY = atof(wordlist[2].c_str()) * valueDimensionFactor();
0125   //-  std::cout << " factors for correction X = " << theDisplaceX << " Y " << theDisplaceY << std::endl;

0126 
0127   if (wordlist.size() == 5) {
0128     theMultiplyX = atof(wordlist[3].c_str());
0129     theMultiplyY = atof(wordlist[4].c_str());
0130   } else {
0131     theMultiplyX = 1.;
0132     theMultiplyY = 1.;
0133   }
0134 }
0135 
0136 //////////////////////////////////////////////////////////////////

0137 void MeasurementSensor2D::correctValueAndSigma() {
0138   //---------- Make  displacement

0139   ALIdouble val = value()[0];
0140   val += theDisplaceX;
0141   val *= theMultiplyX;
0142   //-  std::cout << " theDisplaceX " <<  theDisplaceX << " theMultiplyX " << theMultiplyX << std::endl;

0143   if (ALIUtils::debug >= 4)
0144     std::cout << "MeasurementSensor2D::correctValueAndSigma: "
0145               << " old value X " << value()[0] << " new " << val << std::endl;
0146   setValue(0, val);
0147 
0148   val = value()[1];
0149   val += theDisplaceY;
0150   val *= theMultiplyY;
0151   if (ALIUtils::debug >= 4)
0152     std::cout << "MeasurementSensor2D::correctValueAndSigma: old value Y " << value()[1] << " new " << val << std::endl;
0153   setValue(1, val);
0154 }