CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Alignment/CocoaModel/src/MeasurementSensor2D.cc

Go to the documentation of this file.
00001 // COCOA class implementation file
00002 // Id:  Measurement.C
00003 // CAT: Model
00004 // ---------------------------------------------------------------------------
00005 // History: v1.0 
00006 // Authors:
00007 //   Pedro Arce
00008 
00009 #include "Alignment/CocoaModel/interface/MeasurementSensor2D.h"
00010 #include "Alignment/CocoaModel/interface/LightRay.h"
00011 #include "Alignment/CocoaModel/interface/OpticalObject.h"
00012 #ifdef COCOA_VIS
00013 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
00014 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
00015 #include "Alignment/IgCocoaFileWriter/interface/ALIVisLightPath.h"
00016 #endif
00017 
00018 #include <iostream>
00019 #include <iomanip>
00020 #include <cstdlib>
00021 
00022 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00023 //@@ calculate the simulated value propagating the light ray through the OptO that take part in the Measurement
00024 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00025 void MeasurementSensor2D::calculateSimulatedValue( ALIbool firstTime ) 
00026 {
00027  
00028   if( ALIUtils::debug >= 2) printStartCalculateSimulatedValue( this ); // important
00029   //---------- Create light ray
00030   LightRay* lightray = new LightRay;
00031 
00032   int isec = 0;  //security variable to check OptOList().size()
00033 
00034   //---------- Loop list of OptO that take part in measurement
00035   std::vector<OpticalObject*>::const_iterator vocite =  OptOList().begin();
00036   //-  if( ALIUtils::debug >= 5) std::cout  << "OptOList size" <<OptOList().size() << std::endl;
00037 
00038   //----- Check that first object is 'laser' or 'source'
00039   if( (*vocite)->type() != "laser" && (*vocite)->type() != "source" ) { 
00040     std::cerr << " first Optical object should be 'laser' or 'source'" << std::endl;
00041     DumpBadOrderOptOs();
00042     exit(1);
00043   }     
00044 #ifdef COCOA_VIS
00045   ALIVisLightPath* vispath = 0;
00046   if( ALIUtils::getFirstTime() ) {
00047     GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00048     if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
00049       vispath = IgCocoaFileMgr::getInstance().newLightPath( name() );
00050     } 
00051   }
00052 #endif
00053 
00054   //-  while( (*vocite) !=  *(OptOList().end()) ) {
00055   while( (vocite) !=  (OptOList().end()) ) {
00056     if( ALIUtils::debug >= 2) std::cout << std::endl << "@@@@ LR:OBJECT " << (*vocite)->name() << std::endl;  
00057     isec ++;
00058 
00059     //---------- Get the behaviour of the object w.r.t the measurement (if it reflects the light, let it traverse it, ...)
00060     ALIstring behav = getMeasuringBehaviour(vocite);
00061 
00062     //---------- Check that last object is a Sensor (that makes measuremnt and kill the lightray)
00063     if( lightray ) {
00064       (*vocite)->participateInMeasurement( *lightray, *this, behav );
00065 
00066 #ifdef COCOA_VIS
00067       if( ALIUtils::getFirstTime() ) {
00068         GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00069         if(gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
00070           ALIVRMLMgr::getInstance().addLightPoint( lightray->point() );
00071           if(ALIUtils::debug >= 5)std::cout << "ALIVRMLMg  addLightPoint " << lightray->point() << (*vocite)->name() << std::endl;
00072         }
00073         if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
00074           vispath->addLightPoint( lightray->point(), (*vocite) );
00075         }
00076       }
00077 #endif
00078 
00079     } else {
00080       std::cerr << "!! Last object is not Sensor 2D in measurement " << name() << std::endl;
00081       DumpBadOrderOptOs();
00082       exit(1);
00083     }
00084 
00085     vocite++;
00086     if ( isec > ALIint(OptOList().size()) ) {
00087       std::cerr << "ERROR DE PROGRAMACION EN GetSimulatedValue" << std::endl;
00088       exit(5);
00089     }
00090     //-    lightray.normalizeDirection();
00091   }
00092 
00093   delete lightray;
00094  
00095   if(ALIUtils::debug >= 9) std::cout << "end calculateSimulatedValue" <<std::endl;
00096   
00097 }
00098 
00099 
00100 
00101 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00102 //@@ You input 8 numbers after 'TILMETER':
00103 //@@  
00104 //@@ set the conversion factor from mV to mrad and the pedestal 
00105 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00106 void MeasurementSensor2D::setConversionFactor( const std::vector<ALIstring>& wordlist ) 
00107 {
00108   //--------- Check that the format is OK
00109   theDisplaceX = 0;
00110   theDisplaceY = 0;
00111   theMultiplyX = 1.;
00112   theMultiplyY = 1.;
00113   //-  std::cout << " 0 factors for correction X = " << theDisplaceX << " Y " << theDisplaceY << std::endl;
00114  
00115   if(wordlist.size() == 1) return; 
00116   if( (wordlist.size() != 3 && wordlist.size() != 5 )
00117       || !ALIUtils::IsNumber(wordlist[1]) || !ALIUtils::IsNumber(wordlist[2]) ) {
00118     std::cerr << "!! Sensor2D Measurement setConversionFactor: WRONG FORMAT "<<  std::endl 
00119          << "It should be: SENSOR2D displace_X displace_Y " << std::endl 
00120          << "It is: ";
00121     ALIUtils::dumpVS( wordlist, " ", std::cerr );
00122     exit(1);
00123   }
00124   theDisplaceX = atof(wordlist[1].c_str())* valueDimensionFactor();
00125   theDisplaceY = atof(wordlist[2].c_str())* valueDimensionFactor();
00126   //-  std::cout << " factors for correction X = " << theDisplaceX << " Y " << theDisplaceY << std::endl;
00127 
00128   if( wordlist.size() == 5 ) {
00129     theMultiplyX = atof(wordlist[3].c_str());
00130     theMultiplyY = atof(wordlist[4].c_str());
00131   } else {
00132     theMultiplyX = 1.;
00133     theMultiplyY = 1.;
00134   }  
00135 }
00136 
00137 
00139 void MeasurementSensor2D::correctValueAndSigma()
00140 {
00141    //---------- Make  displacement
00142   ALIdouble val = value()[0];
00143   val += theDisplaceX;
00144   val *= theMultiplyX;
00145   //-  std::cout << " theDisplaceX " <<  theDisplaceX << " theMultiplyX " << theMultiplyX << std::endl;
00146   if(ALIUtils::debug >= 4) std::cout << "MeasurementSensor2D::correctValueAndSigma: " << " old value X " << value()[0] << " new " << val << std::endl;
00147   setValue( 0, val );
00148 
00149   val = value()[1];
00150   val += theDisplaceY;
00151   val *= theMultiplyY;
00152   if(ALIUtils::debug >= 4) std::cout << "MeasurementSensor2D::correctValueAndSigma: old value Y " << value()[1] << " new " << val << std::endl;
00153   setValue( 1, val );
00154 
00155 }
00156