CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Alignment/CocoaModel/src/MeasurementDistancemeter.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/MeasurementDistancemeter.h"
00010 #include "Alignment/CocoaModel/interface/LightRay.h"
00011 #include "Alignment/CocoaModel/interface/OpticalObject.h"
00012 #include <iostream>
00013 #include <iomanip>
00014 #include <cstdlib>
00015 #ifdef COCOA_VIS
00016 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
00017 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
00018 #include "Alignment/IgCocoaFileWriter/interface/ALIVisLightPath.h"
00019 #endif
00020 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
00021 
00022 
00023 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00024 //@@ calculate the simulated value propagating the light ray through the OptO that take part in the Measurement
00025 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00026 void MeasurementDistancemeter::calculateSimulatedValue( ALIbool firstTime ) 
00027 {
00028  
00029   if( ALIUtils::debug >= 2) printStartCalculateSimulatedValue( this ); // important for Examples/FakeMeas
00030 
00031   //---------- Loop list of OptO that take part in measurement
00032   std::vector<OpticalObject*>::const_iterator vocite =  OptOList().begin();
00033   if( ALIUtils::debug >= 5) std::cout  << "OptOList size= " <<OptOList().size() << std::endl;
00034 
00035   //----- Check that there are only two measurements that are 'distance_target' and 'distancemeter'
00036   ALIbool right_objects = 0;
00037   if( OptOList().size() == 2 ) {
00038     if( (*vocite)->type() == "distance_target"
00039         && ( (*(vocite+1))->type() == "distancemeter" || 
00040         (*(vocite+1))->type() == "distancemeter1dim" ) ) { 
00041       right_objects = 1;
00042     } 
00043   }
00044   if( !right_objects ) {
00045     std::cerr << "!!! ERROR in MeasurementDistancemeter: " << name() << " There should only be two objects of type 'distance_target' and 'distancemeter' " << std::endl;
00046  std::cerr       << " 1st: " << (*vocite)->name() << " 2nd: " << (*vocite+1)->name()  << std::endl;
00047     std::cerr << " 1st " << (*vocite)->type() << " 2nd " << (*vocite+1)->type() << std::endl;
00048 
00049     DumpBadOrderOptOs();
00050     std::exception();
00051   }     
00052 
00053 #ifdef COCOA_VIS
00054   ALIVisLightPath* vispath = 0;
00055   if( ALIUtils::getFirstTime() ) {
00056     GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00057     if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
00058       vispath = IgCocoaFileMgr::getInstance().newLightPath( name() );
00059     } 
00060   }
00061 #endif
00062 
00063   ALIuint isec = 0;  //security variable to check OptOList().size()
00064   for( vocite = OptOList().begin(); vocite != OptOList().end(); vocite++) {
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     //---------- participate in measurement
00072     LightRay lightray;  //it is not used in this measurement type
00073     (*vocite)->participateInMeasurement( lightray, *this, behav);
00074 
00075 #ifdef COCOA_VIS
00076     if( ALIUtils::getFirstTime() ) {
00077       GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00078       if(gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
00079         ALIVRMLMgr::getInstance().addLightPoint( lightray.point() );
00080         if(ALIUtils::debug >= 5)std::cout << "ALIVRMLMg  addLightPoint " << lightray.point()  << (*vocite)->name() << std::endl;
00081       }
00082       if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
00083         vispath->addLightPoint( lightray.point(), *vocite );
00084       }
00085     }
00086 #endif    
00087 
00088     if ( isec > OptOList().size() ) {
00089       std::cerr << "ERROR DE PROGRAMACION EN GetSimulatedValue" << std::endl;
00090       std::exception();
00091     }
00092   }
00093   
00094   if(ALIUtils::debug >= 5) std::cout << "end calculateSimulatedValue" <<std::endl;
00095   
00096 }
00097 
00098 
00099 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00100 //@@ You input 2 numbers after 'DISTANCEMETER':
00101 //@@  
00102 //@@ set the conversion factor from mV to mm
00103 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00104 void MeasurementDistancemeter::setConversionFactor( const std::vector<ALIstring>& wordlist ) 
00105 {
00106   //--------- Check that the format is OK
00107   if(wordlist.size() == 1) return; 
00108   if( wordlist.size() != 4
00109     || !ALIUtils::IsNumber(wordlist[1]) || !ALIUtils::IsNumber(wordlist[3]) 
00110     || wordlist[2] != ALIstring("+-") ){  
00111     std::cerr << "!! Distancemeter Measurement setConversionFactor: WRONG FORMAT "<<  std::endl 
00112          << "It should be: DISTANCEMETER factor +- error " << std::endl 
00113          << "It is: ";
00114     ALIUtils::dumpVS( wordlist, " ", std::cerr );
00115     std::exception();
00116   }
00117   theFactor = atof(wordlist[1].c_str());
00118   //------ correct by dimension of value of tiltmeter
00119   GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00120   ALIint dimfac = ALIint( gomgr->GlobalOptions()[ ALIstring("distancemeter_meas_value_dimension") ] );
00121   if( dimfac == 0 ) {
00122     theFactor *= 1.;
00123   } else if( dimfac == 1 ) {
00124     theFactor *= 1.E-3;
00125   } else if( dimfac == 2 ) {
00126     theFactor *= 1.E-6;
00127   } else {
00128     std::cerr << " !!!EXITING: error in global option distancemeter_meas_value_dimension, it can only take values 0,1,2, not " << dimfac;
00129     std::exception();
00130   }
00131   theFactorSigma = atof(wordlist[3].c_str());
00132 
00133 }
00134 
00135 
00136 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00137 //@@ Value is given in mV: convert to mm 
00138 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00139 void MeasurementDistancemeter::correctValueAndSigma()
00140 {
00141   ALIdouble val = value()[0];
00142   ALIdouble sig = sigma()[0];
00143   if(ALIUtils::debug >= 4) std::cout << "MeasurementDistancemeter::correctValueAndSigma: old value" << val << " +- " << sig << std::endl;
00144 
00145   //- std::cout << "FACTOR " << theFactor << "correct " << val << " "  << thePedestal << std::endl; 
00146   val *= theFactor; 
00147   //-------- Do not correct the sigma!!!!
00148   //-  sig *= theFactor; 
00149   if(ALIUtils::debug >= 4) std::cout << "MeasuremenDistancemeter::correctValueAndSigma: new value " << val << " +- " << sig << std::endl;
00150   setValue( 0, val );
00151   setSigma( 0, sig );
00152 
00153 }
00154