test
CMS 3D CMS Logo

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