CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Alignment/CocoaModel/src/MeasurementCOPS.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/MeasurementCOPS.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 MeasurementCOPS::calculateSimulatedValue( ALIbool firstTime ) 
00026 {
00027  
00028   if( ALIUtils::debug >= 2) printStartCalculateSimulatedValue( this ); // important for Examples/FakeMeas
00029 
00030   //---------- Create light ray
00031   LightRay* lightray = new LightRay;
00032 
00033   //---------- Define types of OptO that may take part in the Measurement
00034   ALIuint isec = 0;  //security variable to check OptOList().size()
00035 
00036   //---------- Loop list of OptO that take part in measurement
00037   std::vector<OpticalObject*>::const_iterator vocite =  OptOList().begin();
00038   if( ALIUtils::debug >= 5) std::cout  << "OptOList size" <<OptOList().size() << std::endl;
00039 
00040   //----- Check that first object is 'Xlaser' 
00041   if( (*vocite)->type() != "Xlaser" ) { 
00042     std::cerr << "!!ERROR MeasurementCOPS: first Optical object should be 'Xlaser'" << std::endl;
00043     DumpBadOrderOptOs();
00044     exit(1);
00045   }     
00046 
00047   //---------- Check that last object is a COPS Sensor (that makes measuremnt and kill the lightray)
00048   if( ( *(OptOList().end() -1) )->type() != "COPS" ) { 
00049     std::cerr << "!!ERROR MeasurementCOPS: last Optical object should be 'COPS'" << std::endl;
00050     DumpBadOrderOptOs();
00051     exit(1);
00052   }     
00053 
00054 #ifdef COCOA_VIS
00055   ALIVisLightPath* vispath = 0;
00056   if( ALIUtils::getFirstTime() ) { 
00057     GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00058     if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
00059       vispath = IgCocoaFileMgr::getInstance().newLightPath( name() );
00060     } 
00061   }
00062 #endif
00063   std::cout << (vocite == OptOList().end()) << " vocite " << (*vocite)->name() << std::endl;
00064   while( vocite != OptOList().end() ) {
00065     if( ALIUtils::debug >= -2) std::cout << std::endl << "@@@@ LR:OBJECT " << (*vocite)->name() << std::endl;  
00066     isec ++;
00067 
00068     //---------- Get the behaviour of the object w.r.t the measurement (if it reflects the light, let it traverse it, ...)
00069     ALIstring behav = getMeasuringBehaviour(vocite);
00070 
00071     if( lightray ) {
00072       (*vocite)->participateInMeasurement( *lightray, *this, behav );
00073 #ifdef COCOA_VIS
00074       if( ALIUtils::getFirstTime() ) {
00075         GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00076         if(gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
00077           ALIVRMLMgr::getInstance().addLightPoint( lightray->point());
00078           //      std::cout << "ALIVRMLMg  addLightPoint " << lightray->point() << (*vocite)->name() << std::endl;
00079         }
00080         if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
00081           vispath->addLightPoint( lightray->point(), *vocite  );
00082         }
00083       }
00084 #endif
00085     } else {
00086       std::cerr << "!! Last object is not Sensor 2D in measurement " << name() << std::endl;
00087       DumpBadOrderOptOs();
00088       exit(1);
00089     }
00090 
00091     vocite++;
00092     if ( isec > OptOList().size() ) {
00093       std::cerr << "ERROR DE PROGRAMACION EN GetSimulatedValue" << std::endl;
00094       exit(5);
00095     }
00096   }
00097 
00098  
00099   if(ALIUtils::debug >= 9) std::cout << "end calculateSimulatedValue" <<std::endl;
00100   
00101   delete lightray;
00102 }
00103 
00104 
00105 
00106 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00107 //@@ You input 8 numbers after 'TILMETER':
00108 //@@  
00109 //@@ set the conversion factor from mV to mrad and the pedestal 
00110 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00111 void MeasurementCOPS::setConversionFactor( const std::vector<ALIstring>& wordlist ) 
00112 {
00113   //--------- Set it to 0 
00114   ALIuint ii;
00115   for( ii = 0; ii < dim(); ii++) {
00116     theDisplace[ii] = 0.; 
00117   }
00118 
00119   //--------- Check that the format is OK
00120   if(wordlist.size() == 1) return; 
00121   if( wordlist.size() != 3 
00122       || !ALIUtils::IsNumber(wordlist[1]) || !ALIUtils::IsNumber(wordlist[2])
00123       || !ALIUtils::IsNumber(wordlist[3]) || !ALIUtils::IsNumber(wordlist[4]) ) {
00124     std::cerr << "!! SensorCOPS Measurement setConversionFactor: WRONG FORMAT "<<  std::endl 
00125          << "It should be: SENSOR2D displace_U displace_D displace_L displace_R " << std::endl 
00126          << "It is: ";
00127     ALIUtils::dumpVS( wordlist, " ", std::cerr );
00128     exit(1);
00129   }
00130 
00131   for( ii = 0; ii < dim(); ii++) {
00132     theDisplace[ii] = atof(wordlist[ii+1].c_str())* valueDimensionFactor();
00133   }
00134 
00135 }
00136 
00137 
00138 
00139 void MeasurementCOPS::correctValueAndSigma()
00140 {
00141    //---------- Make  displacement
00142   ALIuint ii;
00143   for( ii = 0; ii < dim(); ii++) { 
00144     ALIdouble val = value()[ii];
00145     val += theDisplace[ii];
00146     if(ALIUtils::debug >= 9) std::cout << "MeasurementCOPS::correctValueAndSigma: old value X " << value()[ii] << " new " << val << " +- " << std::endl;
00147     setValue( ii, val );
00148   }
00149 
00150 }
00151