test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MeasurementDistancemeter.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 #include <iostream>
13 #include <iomanip>
14 #include <cstdlib>
15 #ifdef COCOA_VIS
16 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
17 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
18 #include "Alignment/IgCocoaFileWriter/interface/ALIVisLightPath.h"
19 #endif
21 
22 
23 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
24 //@@ calculate the simulated value propagating the light ray through the OptO that take part in the Measurement
25 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
27 {
28 
29  if( ALIUtils::debug >= 2) printStartCalculateSimulatedValue( this ); // important for Examples/FakeMeas
30 
31  //---------- Loop list of OptO that take part in measurement
32  std::vector<OpticalObject*>::const_iterator vocite = OptOList().begin();
33  if( ALIUtils::debug >= 5) std::cout << "OptOList size= " <<OptOList().size() << std::endl;
34 
35  //----- Check that there are only two measurements that are 'distance_target' and 'distancemeter'
36  ALIbool right_objects = 0;
37  if( OptOList().size() == 2 ) {
38  if( (*vocite)->type() == "distance_target"
39  && ( (*(vocite+1))->type() == "distancemeter" ||
40  (*(vocite+1))->type() == "distancemeter1dim" ) ) {
41  right_objects = 1;
42  }
43  }
44  if( !right_objects ) {
45  std::cerr << "!!! ERROR in MeasurementDistancemeter: " << name() << " There should only be two objects of type 'distance_target' and 'distancemeter' " << std::endl;
46  std::cerr << " 1st: " << (*vocite)->name() << " 2nd: " << (*vocite+1)->name() << std::endl;
47  std::cerr << " 1st " << (*vocite)->type() << " 2nd " << (*vocite+1)->type() << std::endl;
48 
51  }
52 
53 #ifdef COCOA_VIS
54  ALIVisLightPath* vispath = 0;
55  if( ALIUtils::getFirstTime() ) {
57  if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
58  vispath = IgCocoaFileMgr::getInstance().newLightPath( name() );
59  }
60  }
61 #endif
62 
63  ALIuint isec = 0; //security variable to check OptOList().size()
64  for( vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite) {
65  if( ALIUtils::debug >= 2) std::cout << std::endl << "@@@@ LR:OBJECT " << (*vocite)->name() << std::endl;
66  isec ++;
67 
68  //---------- Get the behaviour of the object w.r.t the measurement (if it reflects the light, let it traverse it, ...)
69  ALIstring behav = getMeasuringBehaviour(vocite);
70 
71  //---------- participate in measurement
72  LightRay lightray; //it is not used in this measurement type
73  (*vocite)->participateInMeasurement( lightray, *this, behav);
74 
75 #ifdef COCOA_VIS
76  if( ALIUtils::getFirstTime() ) {
78  if(gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
79  ALIVRMLMgr::getInstance().addLightPoint( lightray.point() );
80  if(ALIUtils::debug >= 5)std::cout << "ALIVRMLMg addLightPoint " << lightray.point() << (*vocite)->name() << std::endl;
81  }
82  if(gomgr->GlobalOptions()["VisWriteIguana"] > 1) {
83  vispath->addLightPoint( lightray.point(), *vocite );
84  }
85  }
86 #endif
87 
88  if ( isec > OptOList().size() ) {
89  std::cerr << "ERROR DE PROGRAMACION EN GetSimulatedValue" << std::endl;
91  }
92  }
93 
94  if(ALIUtils::debug >= 5) std::cout << "end calculateSimulatedValue" <<std::endl;
95 
96 }
97 
98 
99 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
100 //@@ You input 2 numbers after 'DISTANCEMETER':
101 //@@
102 //@@ set the conversion factor from mV to mm
103 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
104 void MeasurementDistancemeter::setConversionFactor( const std::vector<ALIstring>& wordlist )
105 {
106  //--------- Check that the format is OK
107  if(wordlist.size() == 1) return;
108  if( wordlist.size() != 4
109  || !ALIUtils::IsNumber(wordlist[1]) || !ALIUtils::IsNumber(wordlist[3])
110  || wordlist[2] != ALIstring("+-") ){
111  std::cerr << "!! Distancemeter Measurement setConversionFactor: WRONG FORMAT "<< std::endl
112  << "It should be: DISTANCEMETER factor +- error " << std::endl
113  << "It is: ";
114  ALIUtils::dumpVS( wordlist, " ", std::cerr );
115  std::exception();
116  }
117  theFactor = atof(wordlist[1].c_str());
118  //------ correct by dimension of value of tiltmeter
120  ALIint dimfac = ALIint( gomgr->GlobalOptions()[ ALIstring("distancemeter_meas_value_dimension") ] );
121  if( dimfac == 0 ) {
122  theFactor *= 1.;
123  } else if( dimfac == 1 ) {
124  theFactor *= 1.E-3;
125  } else if( dimfac == 2 ) {
126  theFactor *= 1.E-6;
127  } else {
128  std::cerr << " !!!EXITING: error in global option distancemeter_meas_value_dimension, it can only take values 0,1,2, not " << dimfac;
129  std::exception();
130  }
131  theFactorSigma = atof(wordlist[3].c_str());
132 
133 }
134 
135 
136 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
137 //@@ Value is given in mV: convert to mm
138 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
140 {
141  ALIdouble val = value()[0];
142  ALIdouble sig = sigma()[0];
143  if(ALIUtils::debug >= 4) std::cout << "MeasurementDistancemeter::correctValueAndSigma: old value" << val << " +- " << sig << std::endl;
144 
145  //- std::cout << "FACTOR " << theFactor << "correct " << val << " " << thePedestal << std::endl;
146  val *= theFactor;
147  //-------- Do not correct the sigma!!!!
148  //- sig *= theFactor;
149  if(ALIUtils::debug >= 4) std::cout << "MeasuremenDistancemeter::correctValueAndSigma: new value " << val << " +- " << sig << std::endl;
150  setValue( 0, val );
151  setSigma( 0, sig );
152 
153 }
154 
long double ALIdouble
Definition: CocoaGlobals.h:11
virtual void calculateSimulatedValue(ALIbool firstTime)
void setValue(ALIint coor, ALIdouble val)
Definition: Measurement.h:167
virtual void setConversionFactor(const std::vector< ALIstring > &wordlist)
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
void setSigma(ALIint coor, ALIdouble val)
Definition: Measurement.h:171
static int IsNumber(const ALIstring &str)
Definition: ALIUtils.cc:34
bool firstTime
Definition: QTestHandle.cc:16
const ALIdouble * sigma() const
Definition: Measurement.h:132
const CLHEP::Hep3Vector & point() const
Definition: LightRay.h:52
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
#define begin
Definition: vmac.h:30
const ALIstring & type() const
Definition: Measurement.h:86
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.
unsigned int ALIuint
Definition: CocoaGlobals.h:17