CMS 3D CMS Logo

MeasurementTiltmeter.cc
Go to the documentation of this file.
1 // COCOA class implementation file
2 // Id: MeasurementTiltmeter.cc
3 // CAT: Model
4 // ---------------------------------------------------------------------------
5 // History: v1.0
6 // Authors:
7 // Pedro Arce
8 
13 #include <iostream>
14 #include <iomanip>
15 #include <cstdlib>
16 
17 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
18 //@@ calculate the simulated value propagating the light ray through the OptO that take part in the Measurement
19 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
21  if (ALIUtils::debug >= 2)
22  printStartCalculateSimulatedValue(this); // important for Examples/FakeMeas
23 
24  //--------- Check there is only one OptO of type 'tiltmeter'
25  std::vector<OpticalObject*>::const_iterator vocite = OptOList().begin();
26  if (OptOList().size() != 1 || (*vocite)->type() == "distancemeter") {
27  std::cerr << "!!! ERROR in MeasurementTiltmeter: " << name()
28  << " There should only be one object of type 'tiltmeter' " << std::endl;
30  exit(1);
31  }
32 
33  //---------- Get the behaviour of the object w.r.t the measurement (if it reflects the light, let it traverse it, ...)
34  ALIstring behav = getMeasuringBehaviour(vocite);
35 
36  //---------- participate in Measurement
37  LightRay ll;
38  (*vocite)->participateInMeasurement(ll, *this, behav);
39 
40  if (ALIUtils::debug >= 5)
41  std::cout << "end calculateSimulatedValue" << std::endl;
42 }
43 
44 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
45 //@@ You input 8 numbers after 'TILMETER':
46 //@@
47 //@@ set the conversion factor from mV to mrad and the pedestal
48 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
49 void MeasurementTiltmeter::setConversionFactor(const std::vector<ALIstring>& wordlist) {
50  //--------- Check that the format is OK
51  if (wordlist.size() == 1)
52  return;
53  if (wordlist.size() != 7 || !ALIUtils::IsNumber(wordlist[1]) || !ALIUtils::IsNumber(wordlist[3]) ||
54  !ALIUtils::IsNumber(wordlist[4]) || !ALIUtils::IsNumber(wordlist[6]) || wordlist[2] != ALIstring("+-") ||
55  wordlist[5] != ALIstring("+-")) {
56  std::cerr << "!! Tiltmeter Measurement setConversionFactor: WRONG FORMAT " << std::endl
57  << "It should be: TILTEMETER factor +- error constant_term +- error" << (wordlist.size() != 7)
58  << !ALIUtils::IsNumber(wordlist[1]) << !ALIUtils::IsNumber(wordlist[3])
59  << !ALIUtils::IsNumber(wordlist[4])
60  << !ALIUtils::IsNumber(wordlist[6])
61  // << (wordlist[2] != ALIstring("+-")) << (wordlist[5] != ALIstring("+-"))
62  << std::endl
63  << "It is: ";
64  ALIUtils::dumpVS(wordlist, " ", std::cerr);
65  exit(1);
66  }
67  theFactor = atof(wordlist[1].c_str());
68 
69  //------ correct by dimension of value of tiltmeter
71  ALIint dimfac = ALIint(gomgr->GlobalOptions()[ALIstring("tiltmeter_meas_value_dimension")]);
72  if (dimfac == 0) {
73  theFactor *= 1.;
74  } else if (dimfac == 1) {
75  theFactor *= 1.E-3;
76  } else if (dimfac == 2) {
77  theFactor *= 1.E-6;
78  } else {
79  std::cerr
80  << " !!!EXITING: error in global option tiltmeter_meas_value_dimension, it can only take values 0,1,2, not "
81  << dimfac;
82  }
83  theFactorSigma = atof(wordlist[3].c_str());
84  theConstantTerm = atof(wordlist[4].c_str()) * valueDimensionFactor();
85  theConstantTermSigma = atof(wordlist[6].c_str()) * sigmaDimensionFactor();
86  //- std::cout << "correctVal theConstantTerm" << theConstantTerm << valueDimensionFactor() << std::endl;
87  //----- Change value and sigma to dimensions used in SDF, because constant term and pedestal are in dimensions of SDF
88  //- thePedestal = atof(wordlist[7].c_str()) * valueDimensionFactor();
89  //-thePedestalSigma = atof(wordlist[9].c_str()) * sigmaDimensionFactor();
90  // std::cout << "reading thePedestalSigma " << thePedestalSigma << "= " << wordlist[9] << std::endl;
91  // TILTMETER 458.84 +- 1.58 0. +- 0. 1 +- 0
92 }
93 
94 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
95 //@@ Value is given in V: substract constant term, and convert to rad (taking into account the error in the constant term)
96 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
98  ALIdouble val = value()[0];
99  ALIdouble sig = sigma()[0];
100  if (ALIUtils::debug >= 4)
101  std::cout << "MeasurementTiltmeter::correctValueAndSigma: old value" << val << " +- " << sig << std::endl;
102  //---------- Substract pedestal
103  val -= theConstantTerm;
104  //- sig = sqrt(sig*sig + thePedestalSigma*thePedestalSigma );
105  //- std::cout << " sigma + pedestalSigma " << sig << " " << thePedestalSigma << std::endl;
106  //-if( thePedestal != 0. ) {
107  //- sig += sqrt( sig*sig + val*val*thePedestalSigma*thePedestalSigma/thePedestal/thePedestal );
108  //-}
109  //---------- Add error in constant term
110  sig = sqrt(sig * sig + theConstantTermSigma * theConstantTermSigma);
111  //- std::cout << " sigma + costantTermSigma " << sig << " " << theConstantTermSigma << std::endl;
112 
113  //---------- Convert to rad
114  //- std::cout << "FACTOR " << theFactor << "correct " << val << " " << thePedestal << std::endl;
115  val *= theFactor;
116  //-------- Do not correct the sigma!!!!
117  //- sig /= theFactor;
118  if (ALIUtils::debug >= 4)
119  std::cout << "MeasurementTiltmeter::correctValueAndSigma: new value " << val << " +- " << sig << std::endl;
120  setValue(0, val);
121  setSigma(0, sig);
122 }
size
Write out results.
long double ALIdouble
Definition: CocoaGlobals.h:11
const ALIdouble * value() const
Definition: Measurement.h:109
void calculateSimulatedValue(ALIbool firstTime) override
void setValue(ALIint coor, ALIdouble val)
Definition: Measurement.h:129
void setConversionFactor(const std::vector< ALIstring > &wordlist) override
int ALIint
Definition: CocoaGlobals.h:15
ALIstring getMeasuringBehaviour(const std::vector< OpticalObject *>::const_iterator vocite)
Definition: Measurement.cc:568
static ALIint debug
Definition: ALIUtils.h:34
static GlobalOptionMgr * getInstance()
virtual const ALIdouble valueDimensionFactor() const
Definition: Measurement.h:118
void DumpBadOrderOptOs()
Definition: Measurement.cc:469
bool ALIbool
Definition: CocoaGlobals.h:19
void setSigma(ALIint coor, ALIdouble val)
Definition: Measurement.h:131
static int IsNumber(const ALIstring &str)
Definition: ALIUtils.cc:33
T sqrt(T t)
Definition: SSEVec.h:19
const ALIdouble * sigma() const
Definition: Measurement.h:112
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()
std::string ALIstring
Definition: CocoaGlobals.h:9
void printStartCalculateSimulatedValue(const Measurement *meas)
Definition: Measurement.cc:427
const std::vector< OpticalObject * > & OptOList() const
Definition: Measurement.h:101
void correctValueAndSigma() override
const ALIstring & name() const
Definition: Measurement.h:86
virtual const ALIdouble sigmaDimensionFactor() const
Definition: Measurement.h:120
def exit(msg="")