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