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/MeasurementCOPS.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 MeasurementCOPS::calculateSimulatedValue(ALIbool firstTime) {
0026   if (ALIUtils::debug >= 2)
0027     printStartCalculateSimulatedValue(this);  // important for Examples/FakeMeas

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

0030   LightRay* lightray = new LightRay;
0031 
0032   //---------- Define types of OptO that may take part in the Measurement

0033   ALIuint isec = 0;  //security variable to check OptOList().size()

0034 
0035   //---------- Loop list of OptO that take part in measurement

0036   std::vector<OpticalObject*>::const_iterator vocite = OptOList().begin();
0037   if (ALIUtils::debug >= 5)
0038     std::cout << "OptOList size" << OptOList().size() << std::endl;
0039 
0040   //----- Check that first object is 'Xlaser'

0041   if ((*vocite)->type() != "Xlaser") {
0042     std::cerr << "!!ERROR MeasurementCOPS: first Optical object should be 'Xlaser'" << std::endl;
0043     DumpBadOrderOptOs();
0044     exit(1);
0045   }
0046 
0047   //---------- Check that last object is a COPS Sensor (that makes measuremnt and kill the lightray)

0048   if ((*(OptOList().end() - 1))->type() != "COPS") {
0049     std::cerr << "!!ERROR MeasurementCOPS: last Optical object should be 'COPS'" << std::endl;
0050     DumpBadOrderOptOs();
0051     exit(1);
0052   }
0053 
0054 #ifdef COCOA_VIS
0055   ALIVisLightPath* vispath = 0;
0056   if (ALIUtils::getFirstTime()) {
0057     GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0058     if (gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
0059       vispath = IgCocoaFileMgr::getInstance().newLightPath(name());
0060     }
0061   }
0062 #endif
0063   std::cout << (vocite == OptOList().end()) << " vocite " << (*vocite)->name() << std::endl;
0064   while (vocite != OptOList().end()) {
0065     if (ALIUtils::debug >= -2)
0066       std::cout << std::endl << "@@@@ LR:OBJECT " << (*vocite)->name() << std::endl;
0067     isec++;
0068 
0069     //---------- Get the behaviour of the object w.r.t the measurement (if it reflects the light, let it traverse it, ...)

0070     ALIstring behav = getMeasuringBehaviour(vocite);
0071 
0072     if (lightray) {
0073       (*vocite)->participateInMeasurement(*lightray, *this, behav);
0074 #ifdef COCOA_VIS
0075       if (ALIUtils::getFirstTime()) {
0076         GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0077         if (gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
0078           ALIVRMLMgr::getInstance().addLightPoint(lightray->point());
0079           //      std::cout << "ALIVRMLMg  addLightPoint " << lightray->point() << (*vocite)->name() << std::endl;

0080         }
0081         if (gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
0082           vispath->addLightPoint(lightray->point(), *vocite);
0083         }
0084       }
0085 #endif
0086     } else {
0087       std::cerr << "!! Last object is not Sensor 2D in measurement " << name() << std::endl;
0088       DumpBadOrderOptOs();
0089       exit(1);
0090     }
0091 
0092     ++vocite;
0093     if (isec > OptOList().size()) {
0094       std::cerr << "ERROR DE PROGRAMACION EN GetSimulatedValue" << std::endl;
0095       exit(5);
0096     }
0097   }
0098 
0099   if (ALIUtils::debug >= 9)
0100     std::cout << "end calculateSimulatedValue" << std::endl;
0101 
0102   delete lightray;
0103 }
0104 
0105 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

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

0107 //@@

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

0109 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0110 void MeasurementCOPS::setConversionFactor(const std::vector<ALIstring>& wordlist) {
0111   //--------- Set it to 0

0112   ALIuint ii;
0113   for (ii = 0; ii < dim(); ii++) {
0114     theDisplace[ii] = 0.;
0115   }
0116 
0117   //--------- Check that the format is OK

0118   if (wordlist.size() == 1)
0119     return;
0120   if (wordlist.size() != 3 || !ALIUtils::IsNumber(wordlist[1]) || !ALIUtils::IsNumber(wordlist[2]) ||
0121       !ALIUtils::IsNumber(wordlist[3]) || !ALIUtils::IsNumber(wordlist[4])) {
0122     std::cerr << "!! SensorCOPS Measurement setConversionFactor: WRONG FORMAT " << std::endl
0123               << "It should be: SENSOR2D displace_U displace_D displace_L displace_R " << std::endl
0124               << "It is: ";
0125     ALIUtils::dumpVS(wordlist, " ", std::cerr);
0126     exit(1);
0127   }
0128 
0129   for (ii = 0; ii < dim(); ii++) {
0130     theDisplace[ii] = atof(wordlist[ii + 1].c_str()) * valueDimensionFactor();
0131   }
0132 }
0133 
0134 void MeasurementCOPS::correctValueAndSigma() {
0135   //---------- Make  displacement

0136   ALIuint ii;
0137   for (ii = 0; ii < dim(); ii++) {
0138     ALIdouble val = value()[ii];
0139     val += theDisplace[ii];
0140     if (ALIUtils::debug >= 9)
0141       std::cout << "MeasurementCOPS::correctValueAndSigma: old value X " << value()[ii] << " new " << val << " +- "
0142                 << std::endl;
0143     setValue(ii, val);
0144   }
0145 }