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