Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:29

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/MeasurementDistancemeter.h"
0010 #include "Alignment/CocoaModel/interface/LightRay.h"
0011 #include "Alignment/CocoaModel/interface/OpticalObject.h"
0012 #include <iostream>
0013 #include <iomanip>
0014 #include <cstdlib>
0015 #ifdef COCOA_VIS
0016 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
0017 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
0018 #include "Alignment/IgCocoaFileWriter/interface/ALIVisLightPath.h"
0019 #endif
0020 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
0021 
0022 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0023 //@@ calculate the simulated value propagating the light ray through the OptO that take part in the Measurement

0024 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0025 void MeasurementDistancemeter::calculateSimulatedValue(ALIbool firstTime) {
0026   if (ALIUtils::debug >= 2)
0027     printStartCalculateSimulatedValue(this);  // important for Examples/FakeMeas

0028 
0029   //---------- Loop list of OptO that take part in measurement

0030   std::vector<OpticalObject*>::const_iterator vocite = OptOList().begin();
0031   if (ALIUtils::debug >= 5)
0032     std::cout << "OptOList size= " << OptOList().size() << std::endl;
0033 
0034   //----- Check that there are only two measurements that are 'distance_target' and 'distancemeter'

0035   ALIbool right_objects = false;
0036   if (OptOList().size() == 2) {
0037     if ((*vocite)->type() == "distance_target" &&
0038         ((*(vocite + 1))->type() == "distancemeter" || (*(vocite + 1))->type() == "distancemeter1dim")) {
0039       right_objects = true;
0040     }
0041   }
0042   if (!right_objects) {
0043     std::cerr << "!!! ERROR in MeasurementDistancemeter: " << name()
0044               << " There should only be two objects of type 'distance_target' and 'distancemeter' " << std::endl;
0045     std::cerr << " 1st: " << (*vocite)->name() << " 2nd: " << (*vocite + 1)->name() << std::endl;
0046     std::cerr << " 1st " << (*vocite)->type() << " 2nd " << (*vocite + 1)->type() << std::endl;
0047 
0048     DumpBadOrderOptOs();
0049     std::exception();
0050   }
0051 
0052 #ifdef COCOA_VIS
0053   ALIVisLightPath* vispath = 0;
0054   if (ALIUtils::getFirstTime()) {
0055     GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0056     if (gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
0057       vispath = IgCocoaFileMgr::getInstance().newLightPath(name());
0058     }
0059   }
0060 #endif
0061 
0062   ALIuint isec = 0;  //security variable to check OptOList().size()

0063   for (vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite) {
0064     if (ALIUtils::debug >= 2)
0065       std::cout << std::endl << "@@@@ LR:OBJECT " << (*vocite)->name() << std::endl;
0066     isec++;
0067 
0068     //---------- Get the behaviour of the object w.r.t the measurement (if it reflects the light, let it traverse it, ...)

0069     ALIstring behav = getMeasuringBehaviour(vocite);
0070 
0071     //---------- participate in measurement

0072     LightRay lightray;  //it is not used in this measurement type

0073     (*vocite)->participateInMeasurement(lightray, *this, behav);
0074 
0075 #ifdef COCOA_VIS
0076     if (ALIUtils::getFirstTime()) {
0077       GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0078       if (gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
0079         ALIVRMLMgr::getInstance().addLightPoint(lightray.point());
0080         if (ALIUtils::debug >= 5)
0081           std::cout << "ALIVRMLMg  addLightPoint " << lightray.point() << (*vocite)->name() << std::endl;
0082       }
0083       if (gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
0084         vispath->addLightPoint(lightray.point(), *vocite);
0085       }
0086     }
0087 #endif
0088 
0089     if (isec > OptOList().size()) {
0090       std::cerr << "ERROR DE PROGRAMACION EN GetSimulatedValue" << std::endl;
0091       std::exception();
0092     }
0093   }
0094 
0095   if (ALIUtils::debug >= 5)
0096     std::cout << "end calculateSimulatedValue" << std::endl;
0097 }
0098 
0099 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0100 //@@ You input 2 numbers after 'DISTANCEMETER':

0101 //@@

0102 //@@ set the conversion factor from mV to mm

0103 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0104 void MeasurementDistancemeter::setConversionFactor(const std::vector<ALIstring>& wordlist) {
0105   //--------- Check that the format is OK

0106   if (wordlist.size() == 1)
0107     return;
0108   if (wordlist.size() != 4 || !ALIUtils::IsNumber(wordlist[1]) || !ALIUtils::IsNumber(wordlist[3]) ||
0109       wordlist[2] != ALIstring("+-")) {
0110     std::cerr << "!! Distancemeter Measurement setConversionFactor: WRONG FORMAT " << std::endl
0111               << "It should be: DISTANCEMETER factor +- error " << std::endl
0112               << "It is: ";
0113     ALIUtils::dumpVS(wordlist, " ", std::cerr);
0114     std::exception();
0115   }
0116   theFactor = atof(wordlist[1].c_str());
0117   //------ correct by dimension of value of tiltmeter

0118   GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0119   ALIint dimfac = ALIint(gomgr->GlobalOptions()[ALIstring("distancemeter_meas_value_dimension")]);
0120   if (dimfac == 0) {
0121     theFactor *= 1.;
0122   } else if (dimfac == 1) {
0123     theFactor *= 1.E-3;
0124   } else if (dimfac == 2) {
0125     theFactor *= 1.E-6;
0126   } else {
0127     std::cerr
0128         << " !!!EXITING: error in global option distancemeter_meas_value_dimension, it can only take values 0,1,2, not "
0129         << dimfac;
0130     std::exception();
0131   }
0132   theFactorSigma = atof(wordlist[3].c_str());
0133 }
0134 
0135 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0136 //@@ Value is given in mV: convert to mm

0137 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0138 void MeasurementDistancemeter::correctValueAndSigma() {
0139   ALIdouble val = value()[0];
0140   ALIdouble sig = sigma()[0];
0141   if (ALIUtils::debug >= 4)
0142     std::cout << "MeasurementDistancemeter::correctValueAndSigma: old value" << val << " +- " << sig << std::endl;
0143 
0144   //- std::cout << "FACTOR " << theFactor << "correct " << val << " "  << thePedestal << std::endl;

0145   val *= theFactor;
0146   //-------- Do not correct the sigma!!!!

0147   //-  sig *= theFactor;

0148   if (ALIUtils::debug >= 4)
0149     std::cout << "MeasuremenDistancemeter::correctValueAndSigma: new value " << val << " +- " << sig << std::endl;
0150   setValue(0, val);
0151   setSigma(0, sig);
0152 }