CMS 3D CMS Logo

Measurement.cc
Go to the documentation of this file.
1 // COCOA class implementation file
2 // Id: Measurement.cc
3 // CAT: Model
4 // ---------------------------------------------------------------------------
5 // History: v1.0
6 // Authors:
7 // Pedro Arce
8 
10 
11 #include <algorithm>
12 #include <iomanip>
13 #include <iostream>
14 #include <iterator>
15 //#include <algo.h>
16 #include <cstdlib>
17 #include <cmath> // include floating-point std::abs functions
18 
25 #ifdef COCOA_VIS
26 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
27 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
28 #endif
31 
36 
40 
41 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
42 //@@ constructor:
43 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
45  : theDim(measdim), theType(type), theName(name) {
46  // _OptOnames = new ALIstring[theDim];
47  theValue = new ALIdouble[theDim];
48  theSigma = new ALIdouble[theDim];
50 
54 }
55 
56 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
57 //@@ construct (read from file)
58 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
61 
62  //---------- Read OptOs that take part in this Measurement
63  std::vector<ALIstring> wordlist;
64  filein.getWordsInLine(wordlist);
65 
66  //--------- Fill the list of names of OptOs that take part in this measurement ( names only )
67  buildOptONamesList(wordlist);
68 
69  if (ALIUtils::debug >= 3) {
70  std::cout << "@@@@ Reading Measurement " << name() << " TYPE= " << type() << std::endl << " MEASURED OPTO NAMES: ";
71  std::ostream_iterator<ALIstring> outs(std::cout, " ");
72  copy(wordlist.begin(), wordlist.end(), outs);
73  std::cout << std::endl;
74  }
75 
76  //---------- Read the data
77  for (unsigned int ii = 0; ii < dim(); ii++) {
78  filein.getWordsInLine(wordlist);
79  fillData(ii, wordlist);
80  }
81 
82  if (!valueIsSimulated(0))
84 
85  postConstruct();
86 }
87 
88 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
90  //---- Build wordlist to build object name list
91  std::vector<std::string> objNames = measInfo.measObjectNames_;
92  std::vector<std::string>::const_iterator site;
93  std::vector<ALIstring> wordlist;
94  //--- Fill the list of names of OptOs that take part in this measurement ( names only )
95  for (site = objNames.begin(); site != objNames.end(); ++site) {
96  if (site != objNames.begin())
97  wordlist.push_back("&");
98  wordlist.push_back(*site);
99  }
100  buildOptONamesList(wordlist);
101 
102  if (ALIUtils::debug >= 3) {
103  std::cout << "@@@@ Reading Measurement " << name() << " TYPE= " << type() << " " << measInfo << std::endl
104  << " MEASURED OPTO NAMES: ";
105  for (size_t ii = 0; ii < _OptONameList.size(); ii++) {
106  std::cout << _OptONameList[ii] << " ";
107  }
108  std::cout << std::endl;
109  }
110 
111  //---------- No data, set to simulated_value
112  for (unsigned int ii = 0; ii < dim(); ii++) {
113  wordlist.clear();
114  wordlist.push_back((measInfo.values_)[ii].name_);
115  char ctmp[20];
116  if (measInfo.isSimulatedValue_[ii]) {
117  if (ALIUtils::debug >= 5) {
118  std::cout << "Measurement::constructFromOA: meas value " << ii << " " << dim() << " = simulated_value"
119  << std::endl;
120  }
121  wordlist.push_back("simulated_value");
122  } else {
123  if (ALIUtils::debug >= 5) {
124  std::cout << "Measurement::constructFromOA: meas value " << ii << " " << dim() << " = "
125  << measInfo.values_.size() << std::endl;
126  }
127  ALIdouble val =
128  (measInfo.values_)[ii].value_ /
129  valueDimensionFactor(); //in XML values are without dimensions, so neutralize multiplying by valueDimensionFactor() in fillData
130  gcvt(val, 10, ctmp);
131  wordlist.push_back(ctmp);
132  }
133  ALIdouble err =
134  (measInfo.values_)[ii].error_ /
135  sigmaDimensionFactor(); //in XML values are without dimensions, so neutralize multiplying by valueDimensionFactor() in fillData
136  gcvt(err, 10, ctmp);
137  wordlist.push_back(ctmp);
138  std::cout << " sigma " << err << " = " << ctmp << " " << (measInfo.values_)[ii].error_ << std::endl;
139  //- wordlist.push_back( "simulated_value" );
140  //- wordlist.push_back( "1." );
141  if (ALIUtils::debug >= 5)
142  ALIUtils::dumpVS(wordlist, " Measurement: calling fillData ");
143  //- std::cout << " MEAS INFO " << measInfo << std::endl;
144  //- std::cout << ii << " MEAS INFO PARAM " << (measInfo.values_)[ii] << std::endl;
145  //- std::cout << ii << " MEAS INFO PARAM VALUE " << (measInfo.values_)[ii].value_ << std::endl;
146  fillData(ii, wordlist);
147  }
148 
149  postConstruct();
150 }
151 
152 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
154  //---------- Set name as name of last OptO
155  setName();
156 
157  //---------- Transform for each Measurement the Measured OptO names to Measured OptO pointers
158  buildOptOList();
159 
160  //---------- Build list of Entries that affect a Measurement
162 
163  //---------- add this measurement to the global list of measurements
165 
166  if (ALIUtils::debug >= 10) {
167  std::cout << Model::MeasurementList().size() << std::endl;
168  }
169 }
170 
171 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
172 //@@ Fills a list of names of OpticalObjects that take part in this measurement
173 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
174 void Measurement::buildOptONamesList(const std::vector<ALIstring>& wl) {
175  int NPairs = (wl.size() + 1) / 2; // Number of OptO names ( pair of name and '&' )
176 
177  //--------- Fill list with names
178  for (int ii = 0; ii < NPairs; ii++) {
179  _OptONameList.push_back(wl[ii * 2]);
180  // Check for separating '&'
181  if (ii != NPairs - 1 && wl[2 * ii + 1] != ALIstring("&")) {
182  // ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
183  std::cerr << "!!! Measured Optical Objects should be separated by '&', not by" << wl[2 * ii + 1] << std::endl;
184  exit(2);
185  }
186  }
187 }
188 
189 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
190 //@@ Fill the data of measurement coordinate 'coor' with values in 'wordlist'
191 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
192 void Measurement::fillData(ALIuint coor, const std::vector<ALIstring>& wordlist) {
193  if (ALIUtils::debug >= 3) {
194  std::cout << "@@ Filling coordinate " << coor << std::endl;
195  //- ostream_iterator<ALIstring> outs(std::cout," ");
196  //- copy(wordlist.begin(), wordlist.end(), outs);
197  }
198 
200 
201  //---------- Check that there are 3 attributes: name, value, error
202  if (wordlist.size() != 3) {
203  // ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
204  std::cerr << " Incorrect format for Measurement value:" << std::endl;
205  std::ostream_iterator<ALIstring> outs(std::cout, " ");
206  copy(wordlist.begin(), wordlist.end(), outs);
207  std::cout << std::endl << "There should be three words: name value sigma " << std::endl;
208  exit(2);
209  }
210 
211  //---------- check coor value
212  if (coor >= theDim) {
213  // ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
214  std::cerr << "Trying to fill Measurement coordinate No " << coor << " but the dimension is " << theDim << std::endl;
215  exit(2);
216  }
217 
218  //---------- set data members
219  //----- Set valueType
220  theValueType[coor] = wordlist[0];
221 
222  //----- Set value (translate it if a PARAMETER is used)
223  ALIdouble val = 0.;
224  theValueIsSimulated[coor] = false;
225  if (!ALIUtils::IsNumber(wordlist[1])) {
226  if (parmgr->getParameterValue(wordlist[1], val) == 0) {
227  if (wordlist[1] == ALIstring("simulated_value")) {
228  theValueIsSimulated[coor] = true;
229  } else {
230  // ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
231  std::cerr << "!!! parameter for value not found: " << wordlist[1].c_str() << std::endl;
232  exit(2);
233  }
234  }
235  //d val *= valueDimensionFactor();
236  } else {
237  //d val = DimensionMgr()::getInstance()->extractValue( wordlist[1], ValueDimensionFactor() );
238  val = atof(wordlist[1].c_str());
239  }
241  if (ALIUtils::debug >= 3)
242  std::cout << "Meas VALUE= " << val << " (ValueDimensionFactor= " << valueDimensionFactor() << std::endl;
243 
244  //----- Set sigma (translate it if a PARAMETER is used)
245  ALIdouble sig = 0.;
246  if (!ALIUtils::IsNumber(wordlist[2])) {
247  if (parmgr->getParameterValue(wordlist[2], sig) == 0) {
248  // ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
249  std::cerr << "!!! parameter for sigma not found: " << wordlist[2].c_str() << std::endl;
250  exit(2);
251  }
252  //d sig *= sigmaDimensionFactor();
253  } else {
254  // sig = DimensionMgr()::getInstance()->extractValue( wordlist[2], ValueDimensionFactor() );
255  sig = atof(wordlist[2].c_str());
256  }
257  sig *= sigmaDimensionFactor();
258  if (ALIUtils::debug >= 3)
259  std::cout << "SIGMA= " << sig << " (SigmaDimensionFactor= " << sigmaDimensionFactor() << std::endl;
260 
261  //----- set theValue & theSigma
262  theValue[coor] = val;
263  theSigma[coor] = sig;
264 }
265 
266 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
268  if (ALIUtils::debug >= 3) {
269  std::cout << "@@ Filling coordinate " << coor << std::endl;
270  }
271 
272  // ParameterMgr* parmgr = ParameterMgr::getInstance();
273 
274  //---------- check coor value
275  if (coor >= theDim) {
276  std::cerr << "Trying to fill Measurement coordinate No " << coor << " but the dimension is " << theDim << std::endl;
277  exit(2);
278  }
279 
280  //---------- set data members
281  //----- Set value (translate it if a PARAMETER is used)
282  ALIdouble val = 0.;
283  theValueIsSimulated[coor] = false;
284  val = oaParam->value();
286  theValue[coor] = val;
287  if (ALIUtils::debug >= 3)
288  std::cout << "Meas VALUE= " << val << " (ValueDimensionFactor= " << valueDimensionFactor() << std::endl;
289 
290  ALIbool sigmaFF = GlobalOptionMgr::getInstance()->GlobalOptions()["measurementErrorFromFile"];
291  if (sigmaFF) {
292  //----- Set sigma (translate it if a PARAMETER is used)
293  ALIdouble sig = 0.;
294  sig = oaParam->sigma(); // it is in mm always
295  sig *= sigmaDimensionFactor();
296  theSigma[coor] = sig;
297  if (ALIUtils::debug >= 3)
298  std::cout << "SIGMA= " << sig << " (SigmaDimensionFactor= " << sigmaDimensionFactor() << std::endl;
299  }
300 }
301 
302 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
303 //@@ Once the complete list of OptOs is read, convert OptO names to pointers
304 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
306  //- if ( ALIUtils::debug >= 3 ) std::cout << std::endl << " MEASUREMENT: " << " " << this->name() << std::endl;
307  ALIstring twopoints(".."); // .. goes one level up in the tree fo OptOs
308 
309  //---------------------------------------- Loop OptONameList
310  std::vector<ALIstring>::iterator vsite;
311  for (vsite = _OptONameList.begin(); vsite != _OptONameList.end(); ++vsite) {
312  //----------------------------------- Count how many '..' there are in the name
313  ALIuint ii = 0;
314  // ALIuint slen = (*vsite).length();
315  ALIuint Ntwopoints = 0; //---- No '..' in ALIstring
316  for (;;) {
317  int i2p = (*vsite).find_first_of(twopoints, 3 * ii); // if it is ., it also finds it!!!
318  if (i2p < 0)
319  break;
320  if (i2p != ALIint(3 * ii)) {
321  std::cerr << i2p << "!!! Bad position of '..' in reference ALIstring: " << (*vsite).c_str() << std::endl;
322  exit(2);
323  } else {
324  Ntwopoints++;
325  if (ALIUtils::debug >= 9)
326  std::cout << "N2p" << Ntwopoints;
327  }
328  ii++;
329  }
330  //------ Substitute '..' by reference (the last OptO in list)
331  if (Ntwopoints != 0) {
332  Substitute2p((*vsite), *(_OptONameList.end() - 1), Ntwopoints);
333  }
334  //----- Get OpticalObject* that correspond to ALIstring and fill list
335  ALIstring referenceOptO = (*vsite);
336  //--- a ':' is used in OptOs that have several possible behavious
337  ALIint colon = referenceOptO.find(':');
338  if (colon != -1) {
339  if (ALIUtils::debug >= 99) {
340  std::cout << "colon in reference OptO name " << colon << referenceOptO.c_str() << std::endl;
341  }
342  referenceOptO = referenceOptO.substr(0, colon);
343  }
344  OpticalObject* OptOitem = Model::getOptOByName(referenceOptO);
345  if (ALIUtils::debug >= 3)
346  std::cout << "Measurement::buildOptOList: OptO in Measurement: " << OptOitem->name() << std::endl;
347  if (OptOitem != (OpticalObject*)nullptr) {
348  _OptOList.push_back(OptOitem);
349  } else {
350  std::cerr << "!!! Error in Measurement: can't find Optical Object " << (*vsite).c_str() << std::endl;
351  exit(2);
352  }
353  }
354 }
355 
356 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
357 //@@ Build the list of all entries of every OptO that take part in this
358 //@@ Measurement and also the list of all entries of their OptO ancestors
359 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
361  //---------- Loop OptO MeasuredList
362  std::vector<OpticalObject*>::const_iterator vocite;
363  for (vocite = _OptOList.begin(); vocite != _OptOList.end(); ++vocite) {
365  }
366 }
367 
368 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
369 //@@ Get the list of all entries of this OptO that take part in this Measurement
370 //@@ and of their OptO ancestors
371 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
373  if (ALIUtils::debug >= 3)
374  std::cout << "Measurement::addAffectingEntriesFromOptO: OptO taking part in Measurement: " << optoP->name()
375  << std::endl;
376  //---------- Loop entries in this OptO
377  std::vector<Entry*>::const_iterator vecite;
378  std::vector<Entry*>::const_iterator fvecite;
379  for (vecite = optoP->CoordinateEntryList().begin(); vecite != optoP->CoordinateEntryList().end(); ++vecite) {
380  //T if( find( theAffectingEntryList.begin(), theAffectingEntryList.end(), (*vecite) ) == theAffectingEntryList.end() ){
381  //t theAffectingEntryList.push_back(*vecite);
382  //T }
383  fvecite = find(theAffectingEntryList.begin(), theAffectingEntryList.end(), (*vecite));
384  if (fvecite == theAffectingEntryList.end()) {
385  theAffectingEntryList.push_back(*vecite);
386  if (ALIUtils::debug >= 4)
387  std::cout << "Entry that may affect Measurement: " << (*vecite)->name() << std::endl;
388  }
389  }
390  for (vecite = optoP->ExtraEntryList().begin(); vecite != optoP->ExtraEntryList().end(); ++vecite) {
391  fvecite = find(theAffectingEntryList.begin(), theAffectingEntryList.end(), (*vecite));
392  if (fvecite == theAffectingEntryList.end()) {
393  theAffectingEntryList.push_back(*vecite);
394  if (ALIUtils::debug >= 4)
395  std::cout << "Entry that may affect Measurement: " << (*vecite)->name() << std::endl;
396  }
397  }
398  if (optoP->parent() != nullptr) {
400  }
401 }
402 
403 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
404 //@@ Substitute '..' in 'ref' by name of parent OptO ('firstref')
405 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
406 void Measurement::Substitute2p(ALIstring& ref, const ALIstring& firstref, int Ntwopoints) {
407  // '/' sets hierarchy of OptOs
408  ALIstring slash("/");
409 
410  int pos1st = firstref.length();
411  // Go back an '/' in firstref for each '..' in ref
412  for (int ii = 0; ii < Ntwopoints; ii++) {
413  pos1st = firstref.find_last_of(slash, pos1st - 1);
414  if (ALIUtils::debug >= 9)
415  std::cout << "pos1st=" << pos1st;
416  }
417 
418  if (ALIUtils::debug >= 9)
419  std::cout << "before change ref: " << ref << " 1ref " << firstref << std::endl;
420  // Substitute name
421  ref.replace(0, (Ntwopoints * 3) - 1, firstref, 0, pos1st);
422  if (ALIUtils::debug >= 9)
423  std::cout << "after change ref: " << ref << " 1ref " << firstref << std::endl;
424 }
425 
426 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
428  std::cout << std::endl
429  << "@@@ Start calculation of simulated value of " << meas->type() << " Measurement " << meas->name()
430  << std::endl;
431 }
432 
433 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
434 //@@ Calculate the simulated value of the Measurement propagating the LightRay when all the entries have their original values
435 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
437  //---------- Calculate the simulated value of the Measurement
439 
440 #ifdef COCOA_VIS
441  if (ALIUtils::getFirstTime()) {
443  if (gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
444  ALIVRMLMgr::getInstance().newLightRay();
445  }
446  /*- if(Model::GlobalOptions()["VisWriteIguana"] > 1) {
447  IgCocoaFileMgr::getInstance().newLightPath( theName );
448  } */
449  }
450 #endif
451 
452  //---------- Set original simulated values to it
453  //- if(ALIUtils::debug >= 5) std::cout << "MEAS DIMENSION" << dim() << std::endl;
454  for (ALIuint ii = 0; ii < dim(); ii++) {
456  if (ALIUtils::debug >= 4)
457  std::cout << "SETsimuvalOriginal" << valueSimulated(ii) << std::endl;
458  //----- If Measurement has as value 'simulated_value', set the value to the simulated one
459  if (valueIsSimulated(ii) == 1) {
461  //- std::cout << ii << " setting value as simulated " << valueSimulated(ii) << " " << value(ii) << this << std::endl;
462  }
463  }
464 }
465 
466 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
467 //@@
468 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
470  std::cerr << " Detector can not make measurement with these optical objects " << std::endl;
471  if (ALIUtils::debug >= 1) {
472  // std::vector<OpticalObject*>::iterator voite;
473  // for ( voite = _OptOList.begin();
474  // voite != _OptOList.end(); voite++) {
475  // std::cout << (*voite)->type() << " : " << (*voite)->name() << std::endl;
476  // }
477  std::vector<ALIstring>::const_iterator vsite;
478  for (vsite = OptONameList().begin(); vsite != OptONameList().end(); ++vsite) {
479  std::cerr << (*vsite) << " : ";
480  }
481  std::cerr << std::endl;
482  }
483  exit(2);
484 }
485 
486 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
487 //@@
488 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
490  //---------- std::vector of derivatives to return
491  std::vector<ALIdouble> deriv;
492  ALIdouble sumderiv;
493 
494  //---------- displacement to start with
495  ALIdouble displacement = entry->startingDisplacement();
496  //----- all angles are in radians, so, if displace is not, rescale it before making the displacement
497  //- displacement *= entry->SigmaDimensionFactor();
498  if (ALIUtils::debug >= 3)
499  std::cout << std::endl
500  << "%%% Derivative w.r.t. entry " << entry->name() << ": displacement = " << displacement << std::endl;
501 
502  ALIint count_itera = 0;
503 
504  //---------- Loop decreasing the displacement a factor 2, until the precision set is reached
505  do {
506  count_itera++;
507  entry->displace(displacement);
508 
509  if (ALIUtils::debug >= 5)
510  std::cout << "Get simulated value for displacement " << displacement << std::endl;
512 
513  //---------- Get sum of derivatives
514  sumderiv = 0;
515  for (ALIuint ii = 0; ii < theDim; ii++) {
517  if (ALIUtils::debug >= 4) {
518  std::cout << "iteration " << count_itera << " COOR " << ii << " difference ="
520  //- << " " << theValueSimulated[ii] << " " << theValueSimulated_orig[ii]
521  << " derivative = " << (theValueSimulated[ii] - theValueSimulated_orig[ii]) / displacement << " disp "
522  << displacement << " sum derivatives = " << sumderiv << std::endl;
523  }
524  if (ALIUtils::debug >= 5) {
525  std::cout << " new simu value= " << theValueSimulated[ii] << " orig simu value " << theValueSimulated_orig[ii]
526  << std::endl;
527  }
528  }
529  if (count_itera >= 100) {
530  std::cerr << "EXITING: too many iterations in derivative, displacement is " << displacement
531  << " sum of derivatives is " << sumderiv << std::endl;
532  exit(3);
533  }
534  displacement /= 2.;
535  //- std::cout << "sumderiv " << sumderiv << " maximu " << Fit::maximum_deviation_derivative << std::endl;
536  } while (sumderiv > ALIUtils::getMaximumDeviationDerivative());
537  displacement *= 2;
538 
539  //---------- Enough precision reached: pass result
540  for (ALIuint ii = 0; ii < theDim; ii++) {
541  deriv.push_back((theValueSimulated[ii] - theValueSimulated_orig[ii]) / displacement);
542  //----- change it to entry sigma dimensions
543  // deriv[ii] /= entry->SigmaDimensionFactor();
544  if (ALIUtils::debug >= 1)
545  std::cout << name() << ": " << entry->OptOCurrent()->name() << " " << entry->name() << " " << ii
546  << "### DERIVATIVE: " << deriv[ii] << std::endl;
547  }
548  //- if(ALIUtils::debug >= 5) std::cout << "END derivative: " << deriv << "disp" << displacement << std::endl;
549 
550  //--------------------- Reset _centreGlob and _rmGlob of OptO entry belongs to (and component OptOs)
551  entry->OptOCurrent()->resetGlobalCoordinates();
552 
553  return deriv;
554 }
555 
556 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
557 //@@ destructor
558 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
560  // delete[] _name;
561  delete[] theValue;
562  delete[] theSigma;
563 }
564 
565 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
566 //@@ get the ':X' that determines how the behaviour of the OptO w.r.t. this Measurement
567 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
568 ALIstring Measurement::getMeasuringBehaviour(const std::vector<OpticalObject*>::const_iterator vocite) {
569  std::vector<ALIstring>::const_iterator vscite =
570  _OptONameList.begin() + (vocite - _OptOList.begin()); // point to corresponding name of this OptO
571  ALIint colon = (*vscite).find(':');
572  ALIstring behav;
573  if (colon != -1) {
574  behav = (*vscite).substr(colon + 1, (*vscite).size());
575  } else {
576  behav = " ";
577  }
578  return behav;
579 }
580 
581 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
582 //@@ Get the previous OptOs in the list of OptO that take part in this measurement
583 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
585  //--------- Loop OptOs that take part in this measurement
586  std::vector<OpticalObject*>::const_iterator vocite;
587  for (vocite = _OptOList.begin(); vocite != _OptOList.end(); ++vocite) {
588  if (*vocite == Popto) {
589  if (vocite == _OptOList.begin()) {
590  std::cerr << " ERROR in getPreviousOptO of measurement " << name() << std::endl;
591  std::cerr << " OptO " << Popto->name() << " is the first one " << std::endl;
592  exit(1);
593  } else {
594  return *(vocite - 1);
595  }
596  }
597  }
598 
599  std::cerr << " ERROR in getPreviousOptO of measurement " << name() << std::endl;
600  std::cerr << " OptO " << Popto->name() << " not found " << std::endl;
601  exit(1);
602 }
603 
604 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
605 void Measurement::setCurrentDate(const std::vector<ALIstring>& wl) {
606  if (wl.size() != 3) {
607  std::cerr << "!!!EXITING: reading DATE of measurements set: it must have three words, it is though " << std::endl;
608  ALIUtils::dumpVS(wl, " ");
609  exit(1);
610  } else if (wl[0] != "DATE:") {
611  std::cerr << "!!!EXITING: reading DATE of measurements set: first word must be 'DATE:', it is though " << std::endl;
612  ALIUtils::dumpVS(wl, " ");
613  exit(1);
614  } else {
615  theCurrentDate = wl[1];
616  theCurrentTime = wl[2];
617  }
618 }
619 
620 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
621 void Measurement::copyMeas(Measurement* meas, const std::string& subsstr1, const std::string& subsstr2) {
622  theDim = meas->dim();
623  theType = meas->type();
624  theName = ALIUtils::changeName(meas->name(), subsstr1, subsstr2);
625 
626  // _OptOnames = new ALIstring[theDim];
630  theValue = const_cast<ALIdouble*>(meas->value());
631  theSigma = const_cast<ALIdouble*>(meas->sigma());
632 
633  unsigned int ii;
634  for (ii = 0; ii < theDim; ii++) {
638  }
639 
640  //--------- Fill the list of names of OptOs that take part in this measurement ( names only )
641 
642  std::vector<std::string> wordlist;
643  auto& optolist = meas->OptOList();
644  ALIuint nOptos = optolist.size();
645  for (ALIuint ii = 0; ii < nOptos; ii++) {
646  wordlist.push_back(ALIUtils::changeName(optolist[ii]->longName(), subsstr1, subsstr2));
647  std::cout << " copymeas " << ALIUtils::changeName(optolist[ii]->longName(), subsstr1, subsstr2) << std::endl;
648  if (ii != nOptos - 1)
649  wordlist.push_back("&");
650  }
651 
652  buildOptONamesList(wordlist);
653 
654  if (ALIUtils::debug >= 3) {
655  std::cout << "@@@@ Reading Measurement " << name() << " TYPE= " << type() << std::endl << " MEASURED OPTO NAMES: ";
656  std::ostream_iterator<ALIstring> outs(std::cout, " ");
657  copy(wordlist.begin(), wordlist.end(), outs);
658  std::cout << std::endl;
659  }
660 
661  postConstruct();
662 }
663 
664 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
666  // name already set by passing one argument with sensor type
667  if (!theName.empty())
668  return;
669  if (_OptONameList.empty()) {
670  std::cerr
671  << " !!! Error in your code, you cannot ask for the name of the Measurement before the OptONameList is build "
672  << std::endl;
673  exit(9);
674  }
675  std::vector<ALIstring>::iterator vsite = (_OptONameList.end() - 1);
676  theName = type() + ":" + (*vsite);
677 }
Measurement::only1Time
static ALIstring only1Time
Definition: Measurement.h:214
ALIbool
bool ALIbool
Definition: CocoaGlobals.h:19
OpticalObject.h
OpticalAlignMeasurementInfo.h
ParameterMgr::getInstance
static ParameterMgr * getInstance()
Definition: ParameterMgr.cc:18
Measurement::theValueIsSimulated
ALIbool * theValueIsSimulated
Definition: Measurement.h:195
Measurement::printStartCalculateSimulatedValue
void printStartCalculateSimulatedValue(const Measurement *meas)
Definition: Measurement.cc:427
Model.h
Measurement::copyMeas
void copyMeas(Measurement *meas, const std::string &subsstr1, const std::string &subsstr2)
Definition: Measurement.cc:621
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
LaserClient_cfi.wl
wl
Definition: LaserClient_cfi.py:46
Measurement::fillData
void fillData(ALIuint coor, const std::vector< ALIstring > &wl)
Definition: Measurement.cc:192
Measurement::getMeasuringBehaviour
ALIstring getMeasuringBehaviour(const std::vector< OpticalObject * >::const_iterator vocite)
Definition: Measurement.cc:568
GlobalOptionMgr::GlobalOptions
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
Definition: GlobalOptionMgr.h:31
Measurement::theName
ALIstring theName
Definition: Measurement.h:183
mps_splice.entry
entry
Definition: mps_splice.py:68
Model::MeasurementList
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:88
Measurement::theValue
ALIdouble * theValue
Definition: Measurement.h:181
GlobalOptionMgr
Definition: GlobalOptionMgr.h:18
OpticalObject::name
const ALIstring & name() const
Definition: OpticalObject.h:58
GlobalOptionMgr::getInstance
static GlobalOptionMgr * getInstance()
Definition: GlobalOptionMgr.cc:18
Measurement::constructFromOA
void constructFromOA(OpticalAlignMeasurementInfo &measInfo)
Definition: Measurement.cc:89
Measurement::valueDimensionFactor
virtual const ALIdouble valueDimensionFactor() const
Definition: Measurement.h:118
Model::addMeasurementToList
static void addMeasurementToList(Measurement *measadd)
Definition: Model.h:145
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ALIstring
std::string ALIstring
Definition: CocoaGlobals.h:9
Measurement::valueSimulated_orig
const ALIdouble valueSimulated_orig(ALIuint ii) const
Definition: Measurement.h:107
Measurement::calculateSimulatedValue
virtual void calculateSimulatedValue(ALIbool firstTime)
Definition: Measurement.h:50
GlobalOptionMgr.h
OpticalAlignMeasurementInfo::values_
std::vector< OpticalAlignParam > values_
Definition: OpticalAlignMeasurementInfo.h:35
OpticalAlignMeasurementInfo::isSimulatedValue_
std::vector< bool > isSimulatedValue_
Definition: OpticalAlignMeasurementInfo.h:33
ParameterMgr::getParameterValue
ALIint getParameterValue(const ALIstring &name, ALIdouble &val)
Definition: ParameterMgr.cc:114
Measurement::theValueSimulated
ALIdouble * theValueSimulated
Definition: Measurement.h:187
OpticalObject
Definition: OpticalObject.h:35
ALIUtils::IsNumber
static int IsNumber(const ALIstring &str)
Definition: ALIUtils.cc:33
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
ParameterMgr.h
Measurement::postConstruct
void postConstruct()
Definition: Measurement.cc:153
Measurement::valueIsSimulated
bool valueIsSimulated(ALIint coor)
Definition: Measurement.h:156
Measurement::dim
const ALIuint dim() const
Definition: Measurement.h:82
OpticalAlignMeasurementInfo::measObjectNames_
std::vector< std::string > measObjectNames_
Definition: OpticalAlignMeasurementInfo.h:32
Measurement::_OptONameList
std::vector< ALIstring > _OptONameList
Definition: Measurement.h:198
Measurement::Substitute2p
void Substitute2p(ALIstring &ref, const ALIstring &firstref, int NtwoPoints)
Definition: Measurement.cc:406
Measurement::setName
void setName()
Definition: Measurement.cc:665
Model::getOptOByName
static OpticalObject * getOptOByName(const ALIstring &opto_name)
--— Find an OptO name in theOptOList and return a pointer to it
Definition: Model.cc:570
Model::SDFName
static ALIstring & SDFName()
the name of the System Description File
Definition: Model.h:93
Measurement::Measurement
Measurement()
Definition: Measurement.h:31
ALIUtils::getFirstTime
static ALIbool getFirstTime()
Definition: ALIUtils.h:87
Measurement::addAffectingEntriesFromOptO
void addAffectingEntriesFromOptO(const OpticalObject *optoP)
Definition: Measurement.cc:372
ALIUtils::debug
static ALIint debug
Definition: ALIUtils.h:34
Measurement::_OptOList
std::vector< OpticalObject * > _OptOList
Definition: Measurement.h:200
Measurement
Definition: Measurement.h:27
OpticalAlignInfo.h
Entry.h
ALIFileIn::getInstance
static ALIFileIn & getInstance(const ALIstring &name)
Definition: ALIFileIn.cc:22
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Measurement.h
OpticalAlignParam
Definition: OpticalAlignInfo.h:34
OpticalObject::ExtraEntryList
const std::vector< Entry * > & ExtraEntryList() const
Definition: OpticalObject.h:65
Measurement::theValueSimulated_orig
ALIdouble * theValueSimulated_orig
Definition: Measurement.h:189
Measurement::calculateOriginalSimulatedValue
void calculateOriginalSimulatedValue()
Definition: Measurement.cc:436
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
OpticalObject::parent
const OpticalObject * parent() const
Definition: OpticalObject.h:60
ALIdouble
long double ALIdouble
Definition: CocoaGlobals.h:11
ALIuint
unsigned int ALIuint
Definition: CocoaGlobals.h:17
Measurement::OptOList
const std::vector< OpticalObject * > & OptOList() const
Definition: Measurement.h:101
Measurement::type
const ALIstring & type() const
Definition: Measurement.h:84
Measurement::theType
ALIstring theType
Definition: Measurement.h:180
OpticalObject::CoordinateEntryList
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:63
Entry
Definition: Entry.h:18
Measurement::setValueSimulated_orig
void setValueSimulated_orig(ALIint coor, ALIdouble value)
Definition: Measurement.h:144
Measurement::theCurrentDate
static ALIstring theCurrentDate
Definition: Measurement.h:208
Measurement::DumpBadOrderOptOs
void DumpBadOrderOptOs()
Definition: Measurement.cc:469
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
Measurement::only1Date
static ALIstring only1Date
Definition: Measurement.h:213
OpticalAlignParam::value
double value() const
Definition: OpticalAlignInfo.h:40
Measurement::setCurrentDate
static void setCurrentDate(const std::vector< ALIstring > &wl)
set the date of the current measurement
Definition: Measurement.cc:605
ALIUtils::dumpVS
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
Measurement::construct
void construct()
Definition: Measurement.cc:59
Measurement::only1
static ALIbool only1
Definition: Measurement.h:212
Measurement::buildOptONamesList
virtual void buildOptONamesList(const std::vector< ALIstring > &wl)
Definition: Measurement.cc:174
Measurement::correctValueAndSigma
virtual void correctValueAndSigma()
Definition: Measurement.h:66
Measurement::theSigma
ALIdouble * theSigma
Definition: Measurement.h:182
Measurement::valueSimulated
const ALIdouble valueSimulated(ALIuint ii) const
Definition: Measurement.h:105
heppy_batch.val
val
Definition: heppy_batch.py:351
Measurement::~Measurement
virtual ~Measurement()
Definition: Measurement.cc:559
Measurement::name
const ALIstring & name() const
Definition: Measurement.h:86
ALIUtils::getMaximumDeviationDerivative
static ALIdouble getMaximumDeviationDerivative()
Definition: ALIUtils.h:89
pickleFileParser.slash
slash
Definition: pickleFileParser.py:12
ParameterMgr
Definition: ParameterMgr.h:15
Measurement::theValueType
ALIstring * theValueType
Definition: Measurement.h:184
Measurement::theDim
ALIuint theDim
Definition: Measurement.h:179
OpticalAlignMeasurementInfo
Definition: OpticalAlignMeasurementInfo.h:28
Measurement::theCurrentTime
static ALIstring theCurrentTime
Definition: Measurement.h:209
Measurement::theAffectingEntryList
std::vector< Entry * > theAffectingEntryList
Definition: Measurement.h:202
OpticalAlignParam::sigma
double sigma() const
Definition: OpticalAlignInfo.h:41
Measurement::sigmaDimensionFactor
virtual const ALIdouble sigmaDimensionFactor() const
Definition: Measurement.h:120
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Measurement::theMeasurementsFileName
static ALIstring theMeasurementsFileName
Definition: Measurement.h:206
ALIint
int ALIint
Definition: CocoaGlobals.h:15
Measurement::value
const ALIdouble * value() const
Definition: Measurement.h:109
ALIFileIn::getWordsInLine
ALIint getWordsInLine(std::vector< ALIstring > &wl)
Definition: ALIFileIn.cc:74
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
Measurement::getPreviousOptO
const OpticalObject * getPreviousOptO(const OpticalObject *Popto) const
Definition: Measurement.cc:584
Measurement::DerivativeRespectEntry
std::vector< ALIdouble > DerivativeRespectEntry(Entry *entry)
Definition: Measurement.cc:489
Measurement::cameraScaleFactor
static ALIdouble cameraScaleFactor
Definition: Measurement.h:158
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
Measurement::OptONameList
const std::vector< ALIstring > & OptONameList() const
Definition: Measurement.h:99
ALIUtils::changeName
static std::string changeName(const std::string &oldName, const std::string &subsstr1, const std::string &subsstr2)
Definition: ALIUtils.cc:535
Measurement::buildOptOList
void buildOptOList()
Definition: Measurement.cc:305
cuy.ii
ii
Definition: cuy.py:590
Measurement::buildAffectingEntryList
void buildAffectingEntryList()
Definition: Measurement.cc:360
ALIFileIn.h
ALIFileIn
Definition: ALIFileIn.h:20
Measurement::setValue
void setValue(ALIint coor, ALIdouble val)
Definition: Measurement.h:129
Measurement::sigma
const ALIdouble * sigma() const
Definition: Measurement.h:112