test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 {
27 
28  if( ALIUtils::debug >= 2) printStartCalculateSimulatedValue( this ); // important
29  //---------- Create light ray
30  LightRay* lightray = new LightRay;
31 
32  int isec = 0; //security variable to check OptOList().size()
33 
34  //---------- Loop list of OptO that take part in measurement
35  std::vector<OpticalObject*>::const_iterator vocite = OptOList().begin();
36  //- if( ALIUtils::debug >= 5) std::cout << "OptOList size" <<OptOList().size() << std::endl;
37 
38  //----- Check that first object is 'laser' or 'source'
39  if( (*vocite)->type() != "laser" && (*vocite)->type() != "source" ) {
40  std::cerr << " first Optical object should be 'laser' or 'source'" << std::endl;
42  exit(1);
43  }
44 #ifdef COCOA_VIS
45  ALIVisLightPath* vispath = 0;
46  if( ALIUtils::getFirstTime() ) {
48  if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
49  vispath = IgCocoaFileMgr::getInstance().newLightPath( name() );
50  }
51  }
52 #endif
53 
54  //- while( (*vocite) != *(OptOList().end()) ) {
55  while( (vocite) != (OptOList().end()) ) {
56  if( ALIUtils::debug >= 2) 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)std::cout << "ALIVRMLMg addLightPoint " << lightray->point() << (*vocite)->name() << std::endl;
72  }
73  if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
74  vispath->addLightPoint( lightray->point(), (*vocite) );
75  }
76  }
77 #endif
78 
79  } else {
80  std::cerr << "!! Last object is not Sensor 2D in measurement " << name() << std::endl;
82  exit(1);
83  }
84 
85  ++vocite;
86  if ( isec > ALIint(OptOList().size()) ) {
87  std::cerr << "ERROR DE PROGRAMACION EN GetSimulatedValue" << std::endl;
88  exit(5);
89  }
90  //- lightray.normalizeDirection();
91  }
92 
93  delete lightray;
94 
95  if(ALIUtils::debug >= 9) std::cout << "end calculateSimulatedValue" <<std::endl;
96 
97 }
98 
99 
100 
101 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
102 //@@ You input 8 numbers after 'TILMETER':
103 //@@
104 //@@ set the conversion factor from mV to mrad and the pedestal
105 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
106 void MeasurementSensor2D::setConversionFactor( const std::vector<ALIstring>& wordlist )
107 {
108  //--------- Check that the format is OK
109  theDisplaceX = 0;
110  theDisplaceY = 0;
111  theMultiplyX = 1.;
112  theMultiplyY = 1.;
113  //- std::cout << " 0 factors for correction X = " << theDisplaceX << " Y " << theDisplaceY << std::endl;
114 
115  if(wordlist.size() == 1) return;
116  if( (wordlist.size() != 3 && wordlist.size() != 5 )
117  || !ALIUtils::IsNumber(wordlist[1]) || !ALIUtils::IsNumber(wordlist[2]) ) {
118  std::cerr << "!! Sensor2D Measurement setConversionFactor: WRONG FORMAT "<< std::endl
119  << "It should be: SENSOR2D displace_X displace_Y " << std::endl
120  << "It is: ";
121  ALIUtils::dumpVS( wordlist, " ", std::cerr );
122  exit(1);
123  }
124  theDisplaceX = atof(wordlist[1].c_str())* valueDimensionFactor();
125  theDisplaceY = atof(wordlist[2].c_str())* valueDimensionFactor();
126  //- std::cout << " factors for correction X = " << theDisplaceX << " Y " << theDisplaceY << std::endl;
127 
128  if( wordlist.size() == 5 ) {
129  theMultiplyX = atof(wordlist[3].c_str());
130  theMultiplyY = atof(wordlist[4].c_str());
131  } else {
132  theMultiplyX = 1.;
133  theMultiplyY = 1.;
134  }
135 }
136 
137 
140 {
141  //---------- Make displacement
142  ALIdouble val = value()[0];
143  val += theDisplaceX;
144  val *= theMultiplyX;
145  //- std::cout << " theDisplaceX " << theDisplaceX << " theMultiplyX " << theMultiplyX << std::endl;
146  if(ALIUtils::debug >= 4) std::cout << "MeasurementSensor2D::correctValueAndSigma: " << " old value X " << value()[0] << " new " << val << std::endl;
147  setValue( 0, val );
148 
149  val = value()[1];
150  val += theDisplaceY;
151  val *= theMultiplyY;
152  if(ALIUtils::debug >= 4) std::cout << "MeasurementSensor2D::correctValueAndSigma: old value Y " << value()[1] << " new " << val << std::endl;
153  setValue( 1, val );
154 
155 }
156 
long double ALIdouble
Definition: CocoaGlobals.h:11
virtual void calculateSimulatedValue(ALIbool firstTime)
virtual const ALIdouble valueDimensionFactor() const
Definition: Measurement.h:144
virtual void correctValueAndSigma()
virtual void setConversionFactor(const std::vector< ALIstring > &wordlist)
void setValue(ALIint coor, ALIdouble val)
Definition: Measurement.h:167
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:35
static GlobalOptionMgr * getInstance()
ALIstring getMeasuringBehaviour(const std::vector< OpticalObject * >::const_iterator vocite)
Definition: Measurement.cc:592
void DumpBadOrderOptOs()
Definition: Measurement.cc:488
bool ALIbool
Definition: CocoaGlobals.h:19
static int IsNumber(const ALIstring &str)
Definition: ALIUtils.cc:34
bool firstTime
Definition: QTestHandle.cc:16
const CLHEP::Hep3Vector & point() const
Definition: LightRay.h:52
#define end
Definition: vmac.h:37
const std::vector< OpticalObject * > & OptOList() const
Definition: Measurement.h:109
static ALIbool getFirstTime()
Definition: ALIUtils.h:100
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:501
const ALIdouble * value() const
Definition: Measurement.h:125
std::string ALIstring
Definition: CocoaGlobals.h:9
void printStartCalculateSimulatedValue(const Measurement *meas)
Definition: Measurement.cc:445
const ALIstring & name() const
Definition: Measurement.h:90
tuple cout
Definition: gather_cfg.py:145
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
tuple size
Write out results.