CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MeasurementSensor2D.cc
Go to the documentation of this file.
1 // COCOA class implementation file
2 // Id: Measurement.C
3 // CAT: Model
4 // ---------------------------------------------------------------------------
5 // History: v1.0
6 // Authors:
7 // Pedro Arce
8 
12 #ifdef COCOA_VIS
13 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
14 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
15 #include "Alignment/IgCocoaFileWriter/interface/ALIVisLightPath.h"
16 #endif
17 
18 #include <iostream>
19 #include <iomanip>
20 #include <cstdlib>
21 
22 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
23 //@@ calculate the simulated value propagating the light ray through the OptO that take part in the Measurement
24 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
26  if (ALIUtils::debug >= 2)
27  printStartCalculateSimulatedValue(this); // important
28  //---------- Create light ray
29  LightRay* lightray = new LightRay;
30 
31  int isec = 0; //security variable to check OptOList().size()
32 
33  //---------- Loop list of OptO that take part in measurement
34  std::vector<OpticalObject*>::const_iterator vocite = OptOList().begin();
35  //- if( ALIUtils::debug >= 5) std::cout << "OptOList size" <<OptOList().size() << std::endl;
36 
37  //----- Check that first object is 'laser' or 'source'
38  if ((*vocite)->type() != "laser" && (*vocite)->type() != "source") {
39  std::cerr << " first Optical object should be 'laser' or 'source'" << std::endl;
41  exit(1);
42  }
43 #ifdef COCOA_VIS
44  ALIVisLightPath* vispath = 0;
45  if (ALIUtils::getFirstTime()) {
47  if (gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
48  vispath = IgCocoaFileMgr::getInstance().newLightPath(name());
49  }
50  }
51 #endif
52 
53  //- while( (*vocite) != *(OptOList().end()) ) {
54  while ((vocite) != (OptOList().end())) {
55  if (ALIUtils::debug >= 2)
56  std::cout << std::endl << "@@@@ LR:OBJECT " << (*vocite)->name() << std::endl;
57  isec++;
58 
59  //---------- Get the behaviour of the object w.r.t the measurement (if it reflects the light, let it traverse it, ...)
60  ALIstring behav = getMeasuringBehaviour(vocite);
61 
62  //---------- Check that last object is a Sensor (that makes measuremnt and kill the lightray)
63  if (lightray) {
64  (*vocite)->participateInMeasurement(*lightray, *this, behav);
65 
66 #ifdef COCOA_VIS
67  if (ALIUtils::getFirstTime()) {
69  if (gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
70  ALIVRMLMgr::getInstance().addLightPoint(lightray->point());
71  if (ALIUtils::debug >= 5)
72  std::cout << "ALIVRMLMg addLightPoint " << lightray->point() << (*vocite)->name() << std::endl;
73  }
74  if (gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
75  vispath->addLightPoint(lightray->point(), (*vocite));
76  }
77  }
78 #endif
79 
80  } else {
81  std::cerr << "!! Last object is not Sensor 2D in measurement " << name() << std::endl;
83  exit(1);
84  }
85 
86  ++vocite;
87  if (isec > ALIint(OptOList().size())) {
88  std::cerr << "ERROR DE PROGRAMACION EN GetSimulatedValue" << std::endl;
89  exit(5);
90  }
91  //- lightray.normalizeDirection();
92  }
93 
94  delete lightray;
95 
96  if (ALIUtils::debug >= 9)
97  std::cout << "end calculateSimulatedValue" << std::endl;
98 }
99 
100 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
101 //@@ You input 8 numbers after 'TILMETER':
102 //@@
103 //@@ set the conversion factor from mV to mrad and the pedestal
104 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
105 void MeasurementSensor2D::setConversionFactor(const std::vector<ALIstring>& wordlist) {
106  //--------- Check that the format is OK
107  theDisplaceX = 0;
108  theDisplaceY = 0;
109  theMultiplyX = 1.;
110  theMultiplyY = 1.;
111  //- std::cout << " 0 factors for correction X = " << theDisplaceX << " Y " << theDisplaceY << std::endl;
112 
113  if (wordlist.size() == 1)
114  return;
115  if ((wordlist.size() != 3 && wordlist.size() != 5) || !ALIUtils::IsNumber(wordlist[1]) ||
116  !ALIUtils::IsNumber(wordlist[2])) {
117  std::cerr << "!! Sensor2D Measurement setConversionFactor: WRONG FORMAT " << std::endl
118  << "It should be: SENSOR2D displace_X displace_Y " << std::endl
119  << "It is: ";
120  ALIUtils::dumpVS(wordlist, " ", std::cerr);
121  exit(1);
122  }
123  theDisplaceX = atof(wordlist[1].c_str()) * valueDimensionFactor();
124  theDisplaceY = atof(wordlist[2].c_str()) * valueDimensionFactor();
125  //- std::cout << " factors for correction X = " << theDisplaceX << " Y " << theDisplaceY << std::endl;
126 
127  if (wordlist.size() == 5) {
128  theMultiplyX = atof(wordlist[3].c_str());
129  theMultiplyY = atof(wordlist[4].c_str());
130  } else {
131  theMultiplyX = 1.;
132  theMultiplyY = 1.;
133  }
134 }
135 
138  //---------- Make displacement
139  ALIdouble val = value()[0];
140  val += theDisplaceX;
141  val *= theMultiplyX;
142  //- std::cout << " theDisplaceX " << theDisplaceX << " theMultiplyX " << theMultiplyX << std::endl;
143  if (ALIUtils::debug >= 4)
144  std::cout << "MeasurementSensor2D::correctValueAndSigma: "
145  << " old value X " << value()[0] << " new " << val << std::endl;
146  setValue(0, val);
147 
148  val = value()[1];
149  val += theDisplaceY;
150  val *= theMultiplyY;
151  if (ALIUtils::debug >= 4)
152  std::cout << "MeasurementSensor2D::correctValueAndSigma: old value Y " << value()[1] << " new " << val << std::endl;
153  setValue(1, val);
154 }
long double ALIdouble
Definition: CocoaGlobals.h:11
virtual const ALIdouble valueDimensionFactor() const
Definition: Measurement.h:118
void setValue(ALIint coor, ALIdouble val)
Definition: Measurement.h:129
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:34
void calculateSimulatedValue(ALIbool firstTime) override
static GlobalOptionMgr * getInstance()
void correctValueAndSigma() override
ALIstring getMeasuringBehaviour(const std::vector< OpticalObject * >::const_iterator vocite)
Definition: Measurement.cc:568
void DumpBadOrderOptOs()
Definition: Measurement.cc:469
bool ALIbool
Definition: CocoaGlobals.h:19
static int IsNumber(const ALIstring &str)
Definition: ALIUtils.cc:33
const CLHEP::Hep3Vector & point() const
Definition: LightRay.h:57
const std::vector< OpticalObject * > & OptOList() const
Definition: Measurement.h:101
static ALIbool getFirstTime()
Definition: ALIUtils.h:87
static void dumpVS(const std::vector< ALIstring > &wl, const std::string &msg, std::ostream &outs=std::cout)
dumps a vector of strings with a message to outs
Definition: ALIUtils.cc:465
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
const ALIdouble * value() const
Definition: Measurement.h:109
void setConversionFactor(const std::vector< ALIstring > &wordlist) override
std::string ALIstring
Definition: CocoaGlobals.h:9
string end
Definition: dataset.py:937
void printStartCalculateSimulatedValue(const Measurement *meas)
Definition: Measurement.cc:427
const ALIstring & name() const
Definition: Measurement.h:86
tuple cout
Definition: gather_cfg.py:144
tuple size
Write out results.