CMS 3D CMS Logo

Model.cc
Go to the documentation of this file.
1 // COCOA class implementation file
2 //Id: Model.cc
3 //CAT: Model
4 //
5 // History: v1.0
6 // Pedro Arce
7 
9 
22 //t#include "Alignment/CocoaModel/interface/MeasurementDiffAngle.h"
23 //t#include "Alignment/CocoaModel/interface/MeasurementCentreEntry.h"
28 //#include "Alignment/Scan/interface/ScanMgr.h"
32 
35 
37 
38 #include <cstdlib>
39 #include <cctype>
40 //#include <algo.h>
41 #include <cassert>
42 #include <ctime>
43 
44 #include <algorithm>
45 
46 #ifdef OS_OSPACE_STD_NAMESPACE
47  using namespace os_std;
48 #endif
49 
50 //using namespace os_std;
51 
52 
53 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
54 Model* Model::theInstance = nullptr;
55 //map< ALIstring, ALIdouble, std::less<ALIstring> > Model::theParameters;
56 std::vector< std::vector<ALIstring> > Model::theOptODictionary;
57 //-map< ALIstring, int, std::less<ALIstring> > Model::theStandardMeasurerTypes;
58 //-multimap< ALIstring, OpticalObject*, std::less<ALIstring> > Model::_OptOtree;
59 //map< ALIstring, OpticalObject*, std::less<ALIstring> > Model::theOptOlist;
60 std::vector< OpticalObject* > Model::theOptOList;
61 std::vector<Entry*> Model::theEntryVector;
62 std::vector<Measurement*> Model::theMeasurementVector;
63 std::vector<ALIdouble> Model::theParamFittedSigmaVector;
64 std::map<ALIstring, ALIdouble, std::less<ALIstring> > Model::theParamFittedValueDisplacementMap;
65 std::vector<OpticalObject*> Model::theOptOsToCopyList;
66 std::vector<OpticalObject*>::const_iterator Model::theOptOsToCopyListIterator;
69 std::vector<ALIdouble> Model::CMSLinkRangeDetValue;
70 ALIstring Model::theSDFName = "SystemDescription.txt";
71 ALIstring Model::theMeasFName = "Measurements.txt";
72 ALIstring Model::theReportFName = "report.out";
73 ALIstring Model::theMatricesFName = "matrices.out";
74 //struct tm Model::theMeasurementsTime = struct tm();
75 // struct tm Model::theMeasurementsTime;
78 std::vector<OpticalAlignInfo> Model::theOpticalAlignments;
79 
80 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
81 //@@ Gets the only instance of Model
82 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
84 {
85  if(!theInstance) {
86  theInstance = new Model;
87  }
88  return *theInstance;
89 }
90 
91 
92 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
93 //@@ Constructor
94 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
96 {
97  // theMeasurementsTime = clock();
98 }
99 
100 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
101 //@@ Reads the System Description file section by section and acts accordingly
102 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
104 {
106 
107  ALIint data_reading = 0; // variable to identify the first line of section SYSTEM_TREE_DATA
108 
109  //---------- Open the system description file
111 
112  //----------- Set section titles
113  std::vector<ALIstring> SectionTitle;
114  SectionTitle.push_back(ALIstring("GLOBAL_OPTIONS"));
115  SectionTitle.push_back(ALIstring("PARAMETERS"));
116  SectionTitle.push_back(ALIstring("SYSTEM_TREE_DESCRIPTION"));
117  SectionTitle.push_back(ALIstring("SYSTEM_TREE_DATA"));
118  SectionTitle.push_back(ALIstring("MEASUREMENTS"));
119  SectionTitle.push_back(ALIstring("REPORT.OUT"));
120  std::vector<ALIstring>::iterator SectionTitleIterator;
121 
122  //---------------------------------------- Loops lines in SDF file
123  std::vector<ALIstring> wordlist;
124  ALIint InSectionNo = -1;
125  ALIint currentSectionNo = -1;
126  while (!filein.eof()) {
127 
128  if( !filein.getWordsInLine(wordlist) ) break; //----- Read line
129  assert( !wordlist.empty() );
130 
131  //----- checking
132  if( ALIUtils::debug > 99) {
133  ALIUtils::dumpVS( wordlist, " ", std::cout );
134  }
135 
136  //---------- Get in which section the current line is and act accordingly
137 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
138 //@@@ ---------- Check if word is start of section
139  SectionTitleIterator = find(SectionTitle.begin(), SectionTitle.end(), *wordlist.begin());
140  if( SectionTitleIterator != SectionTitle.end() ) {
141  //---------- Check that previous sections are correct
142  currentSectionNo = SectionTitleIterator - SectionTitle.begin();
143  if ( currentSectionNo != InSectionNo + 1 ) {
144  if( currentSectionNo != sectReportOut ) {
146  std::cerr << "BAD ORDER OF SECTIONS, reading section "
147  << *SectionTitleIterator << std::endl
148  << " currentSectionNo = " << currentSectionNo << " InSectionNo = " << InSectionNo << std::endl
149  << " --------- Please see documentation ---------- " << std::endl;
150  exit(1);
151  }
152  } else {
153  if( currentSectionNo != sectReportOut ) {
154  InSectionNo++;
155  }
156  }
157  if( currentSectionNo == sectMeasurements ) {
158  SetValueDisplacementsFromReportOut();
159  }
160 
161  if( ALIUtils::debug >= 4) std::cout << std::endl << "START OF SECTION: " << currentSectionNo << " " << *SectionTitleIterator << std::endl;
162 
163 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
164 //@@@ ---------- Reading GLOBAL_OPTIONS section
165  } else if( currentSectionNo == sectGlobalOptions ) {
166  //- std::cout << "utilsdebug " << ALIUtils::debug << std::endl;
167  //-------- Check format of line read
168  //----- Two words
169  if( wordlist.size() == 2 ) {
170  //----- Second word is number
171  int isnumber = ALIUtils::IsNumber( wordlist[1] );
172  if (!isnumber && wordlist[0] != ALIstring("external_meas")) {
174  std::cerr << ": EXPECTING A NUMBER, FOUND: " << wordlist[1] << std::endl;
175  exit(2);
176  }
177 
179  gomgr->setGlobalOption( wordlist[0], ALIUtils::getFloat(wordlist[1]), ALIFileIn::getInstance(Model::SDFName()) );
180 
181  //-or GlobalOptions.insert(std::pair<const ALIstring, ALIdouble>(wordlist[0] , atof(wordlist[1].c_str()) ) );
182 
183  if( ALIUtils::debug >= 1) {
184  ALIUtils::dumpVS( wordlist, "GLOBAL_OPTION: ", std::cout );
185  }
186 
187  } else {
188  std::cout << "error < 1" << std::endl;
190  std::cerr << ": IN GLOBAL_OPTIONS section TWO-WORD LINES ARE EXPECTED " << std::endl;
191  exit(2);
192  }
193 
194  //------- Set dimension factors for lengths and angles
199 
200 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
201 //@@@ ---------- Reading PARAMETERS section
202  } else if( currentSectionNo == sectParameters ||
203  currentSectionNo == -1 ) { // Allow parameters in first lines (for easy study of different parameter values)
204 
205  //---------- Check format of line read
206  //----- Two words
207  if( wordlist.size() == 2 ) {
208  /* now checked in ParameterMgr
209  //----- Second is number
210  int isnumber = ALIUtils::IsNumber( wordlist[1] );
211  if( !isnumber ) {
212  ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
213  std::cerr << ": EXPECTING A NUMBER, FOUND: " << wordlist[1] << std::endl;
214  exit(2);
215  } */
216 
217  //old---------- Create parameter with value read (or overwrite existing value)
218  //---------- Create parameter with value read if parameter does not exist yet
220  parmgr->addParameter( wordlist[0], wordlist[1] );
221 
222  } else if( wordlist.size() == 3 ) {
223  if( wordlist[1] != "seed" ) {
225  std::cerr << ": For a three-word parameter line, second has to be 'seed', it is " << wordlist[1] << std::endl;
226  exit(1);
227  }
228 
229  if( wordlist[0] == "gauss" || wordlist[0] == "flat" ){
231  } else {
233  std::cerr << ": For a three-word parameter line, first has to be 'gauss' or 'flat', it is " << wordlist[0] << std::endl;
234  exit(1);
235  }
236  } else if( wordlist.size() == 4 ) {
237  if( wordlist[0] == "gauss" ) {
238  ParameterMgr::getInstance()->addRandomGaussParameter( wordlist[1], wordlist[2], wordlist[3] );
239  } else if( wordlist[0] == "flat" ) {
240  ParameterMgr::getInstance()->addRandomFlatParameter( wordlist[1], wordlist[2], wordlist[3] );
241  } else {
243  std::cerr << ": For a four-word parameter line, first has to be 'gauss' or 'flat', it is " << wordlist[0] << std::endl;
244  exit(1);
245  }
246  } else {
248  std::cerr << ": IN PARAMETERS section TWO-WORD-LINES ARE EXPECTED " << std::endl;
249  ALIUtils::dumpVS( wordlist , " " );
250  exit(2);
251  }
252 
253  //print it out
254  if( ALIUtils::debug >= 1) {
255  ALIUtils::dumpVS( wordlist, "PARAMETERS: ", std::cout );
256  }
257 
258 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
259 //@@@ ---------- Reading SYSTEM_TREE_DESCRIPTION section
260  } else if( currentSectionNo == sectSystemTreeDescription ) {
261 
262  //---------- Convert the numbers found in list of components (e.g. 2 laser -> laser laser )
263  //----- Backup wordlist and erase it
264  std::vector<ALIstring> wordlist2 = wordlist;
265  std::vector<ALIstring>::iterator vsite;
266  ALIint wsiz = wordlist.size();
267  for ( ALIint ii = 0; ii < wsiz; ii++) {
268  wordlist.pop_back();
269  }
270  //----- Loop objects looking for numbers to convert
271  for ( vsite=wordlist2.begin(); vsite!=wordlist2.end(); ++vsite ) {
272  if( ALIUtils::IsNumber( *vsite ) ) {
273  int nOpticalObjects = atoi( (*vsite).c_str() );
274  //----- If number is 1 it is not necessary
275  if( nOpticalObjects == 1 ) {
276  if( ALIUtils::debug >= 0) std::cerr << "WARNING: in line " << ALIFileIn::getInstance( Model::SDFName() ).nline()
277  << " number of repeated OpticalObjects = 1. Please avoid the numbering " << std::endl;
278  //- wordlist.erase( wordlist.begin() + (vsite-wordlist2.begin()) );
279  } else {
280  //----- The number cannot be the last in the list and you cannot put two numbers together
281  if( vsite+1 == wordlist.end() || ALIUtils::IsNumber(*(vsite+1)) ) {
283  std::cerr << "NUMBER SHOULD BE FOLLOWED BY an OpticalObject type" << std::endl;
284  exit(2);
285  }
286  //----- Right format: convert
287  //--- Substitute the number by the object type in wordlist
288  //- *( wordlist.begin() + (vsite-wordlist2.begin()) ) = *(vsite+1);
289  //--- Add n-1 object types to wordlist (the nth object will be added as the object taht goes after the number)
290  for ( ALIint ii=0; ii<nOpticalObjects-1; ii++ ) {
291  //-std::cout << ii << "inserting in wordlist " << *(vsite+1) << std::endl;
292  wordlist.push_back( *(vsite+1) );
293  }
294  }
295  } else {
296  //----- Not number, add it to wordlist
297  wordlist.push_back( *vsite );
298  }
299  }
300 
301  //---------- Dump system structure
302  if ( ALIUtils::debug >= 1 ) {
303  ALIUtils::dumpVS( wordlist, "SYSTEM TREE DESCRIPTION: before ordering, OBJECT: ", std::cout );
304  }
305 
306  //---------- Fill the list of Optical Object with components (theOptODictionary)
307  //----- First word is 'object': new OptO
308  if ( wordlist[0] == ALIstring("object") ) {
309  //----- Check out repeated objects
310  std::vector< std::vector<ALIstring> >::iterator vvsite;
311  for ( vvsite = theOptODictionary.begin(); vvsite != theOptODictionary.end(); ++vvsite) {
312  //- std::cout << " system" << vvsite << std::endl;
313 
314  if( *( (*vvsite).begin() ) == wordlist[1] ) {
316  std::cerr << "SYSTEM_TREE_DESCRIPTION: REPEATED object " << *((*vvsite).begin()) << " ( NOT ALLOWED NEITHER WITH EQUAL NOR WITH DIFFERENT COMPONENTS)" << std::endl;
317  exit(1);
318  }
319  }
320  //------- Add an item to theOptODictionary
321  std::vector<ALIstring> vstemp;
322  copy( wordlist.begin()+1, wordlist.end(),back_inserter( vstemp ) );
323  Model::OptODictionary().push_back(vstemp);
324  } else {
325  //----- First word is not 'object': add to previous OptO
326  if(OptODictionary().empty()) {
328  std::cerr << "SYSTEM_TREE_DESCRIPTION section: FIRST LINE SHOULD START WITH 'object'" << std::endl;
329  exit(2);
330  }
331  copy(wordlist.begin(), wordlist.end(),
332  back_inserter( *(OptODictionary().end()-1) ) );
333  }
334 
335 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
336 //---------------------------------- Reading SYSTEM_TREE_DATA section
337  } else if( currentSectionNo == sectSystemTreeData ) {
338  //---------- First line of data:
339  if ( !data_reading ) {
340  // ALIint dictsize = theOptODictionary.size();
341  //------- Reorder theOptODictionary
342  std::vector< std::vector<ALIstring> > OptODictionary2;
343  reorderOptODictionary( "system", OptODictionary2);
344  if(OptODictionary2.empty()) {
345  std::cerr << "SYSTEM_TREE_DESCRIPTION section: no object 'system' found " << std::endl;
346  exit(9);
347  }
348  //------- We start reordering with 'system', therefore if 'system' is not the top most object, the objects not hanging from it would not be considered
349  //---- Check if all the objects are here
350  std::vector< std::vector<ALIstring> >::const_iterator vvscite, vvscite2;
351  // ALIint dictsizen = 0;
352  for( vvscite = theOptODictionary.begin(); vvscite != theOptODictionary.end(); ++vvscite) {
353  ALIbool ofound = false;
354  for( vvscite2 = OptODictionary2.begin(); vvscite2 != OptODictionary2.end(); ++vvscite2) {
355  if( *( (*vvscite).begin() ) == *( (*vvscite2).begin() ) ) {
356  ofound = true;
357  break;
358  }
359  }
360  if( !ofound ) {
361  std::cerr << "!!!SYSTEM_TREE_DESCRIPTION section: object " << *( (*vvscite).begin()) << " is not hanging from object 'system' " << std::endl;
362  for (vvscite=OptODictionary().begin();vvscite!=OptODictionary().end();++vvscite){
363  std::vector<ALIstring> ptemp = *vvscite;
364  ALIUtils::dumpVS( ptemp, "OBJECT ", std::cerr );
365  }
366  exit(9);
367  }
368  }
369  theOptODictionary = OptODictionary2;
370 
371  data_reading = 1;
372 
373  //------- Dump ordered OptOs
374  if ( ALIUtils::debug >= 3) {
375  std::vector< std::vector<ALIstring> >::iterator itevs;
376  for (itevs=OptODictionary().begin();itevs!=OptODictionary().end();++itevs){
377  std::vector<ALIstring> ptemp = *itevs;
378  ALIUtils::dumpVS( ptemp, " SYSTEM TREE DESCRIPTION: after ordering: OBJECT ", std::cout );
379  }
380  }
381 
382  //---------- Create OpticalObject 'system' (first OpticalObject object):
383  //---------- it will create its components and recursively all the System Tree of Optical Objects
384  if(wordlist[0] != "system" ) {
385  std::cerr << "SYSTEM_TREE_DATA section: object 'system' is not the first one " << std::endl;
386  exit(9);
387  }
388 
389  OpticalObject* OptOsystem = new OpticalObject( nullptr, "system", wordlist[1], false );
390  OptOsystem->construct();
391  //- Model::_OptOtree.insert( std::multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::value_type(OptOsystem->type(), OptOsystem) );
392  // theOptOlist[OptOsystem->name()] = OptOsystem;
393  theOptOList.push_back( OptOsystem );
394 
395  } else {
396  //----------- All system is read by the Optical Objects, it should not reach here
398  std::cerr << " STILL SOME LINES AFTER ALL SYSTEM TREE IS READ!!!"<< std::endl;
399  exit(9);
400  }
401 
402 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
403 //----------------------------------- Reading MEASUREMENTS section
404  } else if( currentSectionNo == sectMeasurements ) {
405  //---------- Create Measurement with appropiate dimension
406  Measurement* meastemp = nullptr;
407  ALIstring measType = wordlist[0];
408  ALIstring measName;
409  if( wordlist.size() == 2 ) {
410  measName = wordlist[1];
411  wordlist.pop_back();
412  } else {
413  measName = "";
414  }
415  if ( measType == ALIstring("SENSOR2D") ) {
416  meastemp = new MeasurementSensor2D( 2, measType, measName );
417  meastemp->setConversionFactor( wordlist );
418  meastemp->construct();
419  } else if ( measType == ALIstring("DISTANCEMETER3DIM") ) {
420  meastemp = new MeasurementDistancemeter3dim( 1, measType, measName );
421  meastemp->setConversionFactor( wordlist );
422  meastemp->construct();
423  } else if ( measType == ALIstring("DISTANCEMETER") ||
424  measType == ALIstring("DISTANCEMETER1DIM") ) {
425  meastemp = new MeasurementDistancemeter( 1, measType, measName );
426  meastemp->setConversionFactor( wordlist );
427  meastemp->construct();
428  } else if ( measType == ALIstring("TILTMETER") ) {
429  meastemp = new MeasurementTiltmeter( 1, measType, measName );
430  meastemp->setConversionFactor( wordlist );
431  meastemp->construct();
432  } else if ( measType == ALIstring("COPS") ) {
433  meastemp = new MeasurementCOPS( 4, measType, measName );
434  meastemp->setConversionFactor( wordlist );
435  meastemp->construct();
436  } else if ( measType == ALIstring("DIFFCENTRE") ) {
437  //t meastemp = new MeasurementDiffCentre( 1, measType, measName );
438  meastemp->construct();
439  } else if ( measType == ALIstring("DIFFANGLE") ) {
440 //t meastemp = new MeasurementDiffAngle( 2, measType, measName );
441  meastemp->construct();
442  } else if ( measType == ALIstring("DIFFENTRY") ) {
443  meastemp = new MeasurementDiffEntry( 1, measType, measName );
444  meastemp->construct();
445  } else if ( measType == ALIstring("measurements_from_file") || measType == ALIstring("@measurements_from_file") ) {
446  new CocoaDaqReaderText( wordlist[1] );
447  //m Measurement::setMeasurementsFileName( wordlist[1] );
448  //m if ( ALIUtils::debug >= 2) std::cout << " setting measurements_from_file " << measType << " == " << Measurement::measurementsFileName() << std::endl;
449  if( wordlist.size() == 4) {
450  Measurement::only1 = true;
451  Measurement::only1Date = wordlist[2];
452  Measurement::only1Time = wordlist[3];
453  //- std::cout << " setting Measurement::only1" << Measurement::only1 << std::endl;
454  }
455  } else if ( measType == ALIstring("measurements_from_file_ROOT") || measType == ALIstring("@measurements_from_file") ) {
456  new CocoaDaqReaderRoot( wordlist[1] );
457  } else if ( wordlist[0] == ALIstring("correlations_from_file") || wordlist[0] == ALIstring("@correlations_from_file") ) {
459  } else if ( wordlist[0] == ALIstring("copy_measurements") || wordlist[0] == ALIstring("@copy_measurements") ) {
460  copyMeasurements( wordlist );
461  // } else if( wordlist[0] == "scan" || wordlist[0] == "@scan" ) {
462  // ScanMgr::getInstance()->addOptOEntry( wordlist );
463  } else if ( wordlist[0] == ALIstring("fittedEntries_from_file") ) {
464  theFittedEntriesReader = new FittedEntriesReader( wordlist[1] );
465  if ( ALIUtils::debug >= 2) std::cout << " setting fittedEntries_from_file " << wordlist[0] << " == " << wordlist[1] << std::endl;
466  } else {
467  std::cerr << "Measurement:" << std::endl;
469  std::cerr << "!!! type of measurement not allowed: " << wordlist[0]
470  << std::endl;
471  std::cerr << " Allowed types: SENSOR2D, DISTANCEMETER, DISTANCEMETER1DIM, TILTMETER, COPS, DIFFENTRY " << std::endl;
472  exit(2);
473  }
474 //- meastemp->setGlobalName( wordlist[0] );
475 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
476 //@@@ ---------- Reading REPORT OUT section
477  } else if( currentSectionNo == sectReportOut ) {
478  //----- It must be after global options section
479  if ( InSectionNo+1 != sectParameters ) {
481  std::cerr << "BAD ORDER OF SECTIONS, reading section "
482  << *SectionTitleIterator << std::endl
483  << " currentSectionNo = " << currentSectionNo << " InSectionNo = " << InSectionNo << std::endl
484  << " --------- Please see documentation ---------- " << std::endl;
485  exit(1);
486  }
487 
489  }
490  }
491 
492 
493 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
494 //@@@ All system read
495  //---------- make Measurements links to their OptOs
496  if ( ALIUtils::debug >= 2) std::cout << std::endl << "@@@@ Building Measurements links to OptOs" << std::endl;
498 
499  if ( ALIUtils::debug >= 1) {
500  std::cout << "---------- SYSTEM SUCCESFULLY READ ----------" << std::endl << std::endl;
501  }
502  filein.close();
503 
504  return;
505 
506 }
507 
508 
509 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
510 //@@ reorderOptODictionary: REBUILDS THE SYSTEM_TREE_DESCRIPTION SECTION 'objects'
511 //@@ (_OptODictionary) IN A HIERARCHICAL (TREE LIKE) ORDER
512 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
513 void Model::reorderOptODictionary(const ALIstring& ssearch, std::vector< std::vector<ALIstring> >& OptODictionary2 ){
514 
515  // int ALIstring_found = 0;
516  std::vector< std::vector<ALIstring> >::iterator vvsite;
517  std::vector< ALIstring >::iterator vsite;
518 
519 //---------------------------------------- Look for 'ssearch' as the first ALIstring of an OptODictionary item
520  for( vvsite = OptODictionary().begin(); vvsite != OptODictionary().end(); ++vvsite) {
521  if( *( (*vvsite).begin() ) == ssearch ) {
522  // ALIstring_found = 1;
523  OptODictionary2.push_back(*vvsite);
524 
525  //- std::cout << "VVSITE";
526  //- ostream_iterator<ALIstring> outs(std::cout,"&");
527  //- copy( (*vvsite).begin(), (*vvsite).end(), outs);
528 
529 //---------------------------------- look for components of this _OptODictionary item
530  for( vsite = (*vvsite).begin()+1; vsite != (*vvsite).end(); ++vsite ) {
531  reorderOptODictionary( *vsite, OptODictionary2 );
532  }
533  break;
534  }
535  }
536 
537  /* //------- object 'system' should exist
538  if(!ALIstring_found && ssearch == "system") {
539  std::cerr << "SYSTEM_TREE_DATA section: no 'object system' found " << std::endl;
540  exit(9);
541  } */
542 
543 }
544 
545 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
546 //@@ BuildMeasurementLinksToOptOs
547 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
549 
550 //---------- Loop Measurements
551  std::vector< Measurement* >::const_iterator vmcite;
552  for ( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); ++vmcite) {
553 //---------- Transform for each Measurement the Measured OptO names to Measured OptO pointers
554  // (*vmcite)->buildOptOList();
555 
556 //---------- Build list of Entries that affect a Measurement
557  // (*vmcite)->buildAffectingEntryList();
558 
559  }
560 
561 }
562 
563 
564 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
565 //@@ Get the value of a parameter in theParameters std::vector
566 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
568 {
570  ALIint iret = parmgr->getParameterValue( sstr, val );
571 
572  return iret;
573 
574 }
575 
576 
577 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
578 //@@ getOptOByName: Find an OptO name in _OptOlist and return a pointer to it
579 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
581 {
582  //---------- Look for Optical Object name in OptOList
583  std::vector< OpticalObject* >::const_iterator vocite;
584  for( vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite ) {
585  if( (*vocite)->name() == opto_name ) break;
586  }
587 
588  if ( vocite == OptOList().end() ) {
589  //---------- If opto_name not found, exit
590  std::cerr << " LIST OF OpticalObjects " << std::endl;
591  for( vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite ) {
592  std::cerr << (*vocite)->name() << std::endl;
593  }
594  std::cerr << "!!EXITING at getOptOByName: Optical Object " << opto_name << " doesn't exist!!" << std::endl;
595  exit(4);
596  // return (OpticalObject*)0;
597  } else {
598  //---------- If opto_name found, return pointer to it
599  if( ALIUtils::debug>999) {
600  std::cout << opto_name.c_str() << "SSOptOitem" << (*vocite) << (*vocite)->name() << "len" << OptOList().size() << std::endl;
601  }
602  return (*vocite);
603  }
604 
605 }
606 
607 
608 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
609 //@@ getOptOByType: Find an OptO type in _OptOList (the first one with this type)
610 //@@ and return a pointer to it
611 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
613 {
614  //---------- Look for Optical Object type in OptOList
615  std::vector< OpticalObject* >::const_iterator vocite;
616  for( vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite ) {
617  // std::cout << "OPTOList" << (*msocite).first << std::endl;
618  if( (*vocite)->type() == opto_type ) break;
619  }
620 
621  if ( vocite == OptOList().end() ) {
622  //---------- If opto_type not found, exit
623  std::cerr << "!!EXITING at getOptOByType: Optical Object " << opto_type << " doesn't exist!!" << std::endl;
624  exit(4);
625  } else {
626  //---------- If opto_type found, return pointer to it
627  return (*vocite);
628  }
629 
630 }
631 
632 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
633 //@@ Find an Entry name in theEntryVector and return a pointer to it
634 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
635 Entry* Model::getEntryByName( const ALIstring& opto_name, const ALIstring& entry_name )
636 {
637  //---------- Look for Entry name type in EntryList
638  std::vector<Entry*>::const_iterator vecite;
639  for( vecite = EntryList().begin(); vecite != EntryList().end(); ++vecite) {
640  if( ALIUtils::debug >= 4 ) std::cout << "getEntryByName: " <<(*vecite)->OptOCurrent()->name()
641  << " E " << (*vecite)->name() << " Searching: " << opto_name << " E " << entry_name << std::endl;
642  //- std::cout << " optoName " << (*vecite)->OptOCurrent()->name()<< " " << (*vecite)->name() << std::endl;
643  if( (*vecite)->OptOCurrent()->name() == opto_name &&
644  (*vecite)->name() == entry_name ) {
645  return *vecite;
646  }
647  }
648  //---------- Entry not found!
649  std::cerr << "!!!EXITING at getEntryByName: Entry name not found:" << opto_name << " " << entry_name << std::endl;
650  exit(1);
651 }
652 
653 
654 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
656 {
657  //---------- Look for Optical Object name in OptOList
658  std::vector< Measurement* >::const_iterator vmcite;
659  for( vmcite = theMeasurementVector.begin(); vmcite != theMeasurementVector.end(); ++vmcite ) {
660  if( (*vmcite)->name() == meas_name ) break;
661  }
662 
663  if ( vmcite != theMeasurementVector.end() ) {
664  //---------- If opto_name found, return pointer to it
665  return (*vmcite);
666  }else {
667  if( exists ) {
668  //---------- If opto_name not found, exit
669  std::cerr << " LIST OF Measurements " << std::endl;
670  for( vmcite = theMeasurementVector.begin(); vmcite != theMeasurementVector.end(); ++vmcite ) {
671  std::cerr << (*vmcite)->name() << std::endl;
672  }
673  std::cerr << "!!EXITING at getMeasurementByName: Measurement " << meas_name << " doesn't exist!!" << std::endl;
674  abort();
675  // return (OpticalObject*)0;
676  } else {
677  return nullptr;
678  }
679 
680  }
681 
682 
683 }
684 
685 
686 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
687 //@@ Get an OptO list of components
688 //@@ Looks the theOptODictionary item that has 'opto_type' as the first ALIstring,
689 //@@ copies this item to 'vcomponents', substracting the first ALIstring, that is the opto_type itself,
690 //@@ Returns 1 if item found, 0 if not
691 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
692 ALIbool Model::getComponentOptOTypes( const ALIstring& opto_type, std::vector<ALIstring>& vcomponents )
693 {
694  //---------- clean std::vector in which you are going to store opto types
695  std::vector<ALIstring>::iterator vsite;
696  for (vsite = vcomponents.begin(); vsite != vcomponents.end(); ++vsite) {
697  vcomponents.pop_back();
698  }
699 
700  //---------- Looks the theOptODictionary item that has 'opto_type' as the first ALIstring,
701  ALIint ALIstring_found = 0;
702  std::vector< std::vector<ALIstring> >::iterator vvsite;
703  for( vvsite = OptODictionary().begin(); vvsite != OptODictionary().end(); ++vvsite) {
704  if( *( (*vvsite).begin() ) == opto_type ) {
705  ALIstring_found = 1;
706  //tt copies this item to 'vcomponents', substracting the first ALIstring, that is the opto_type itself,
707  vcomponents = *vvsite;
708  vcomponents.erase( vcomponents.begin() );
709  break;
710  }
711  }
712 
713  if ( ALIstring_found ) {
714  return true;
715  } else {
716  return false;
717  }
718 }
719 
720 
721 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
722 //@@ Get from _OptOList the list of OptOs pointers that has as parent 'opto_name'
723 //@@ and store it in vcomponents
724 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
725 ALIbool Model::getComponentOptOs( const ALIstring& opto_name, std::vector<OpticalObject*>& vcomponents)
726 {
727  //---------- clean std::vector in which you are going to store opto pointers
728  std::vector<OpticalObject*>::iterator voite;
729  for (voite = vcomponents.begin(); voite != vcomponents.end(); ++voite) {
730  vcomponents.pop_back();
731  }
732 
733  //---------- Get OptO corresponding to name 'opto_name'
734  OpticalObject* opto = getOptOByName( opto_name );
735 
736  if ( ALIUtils::debug >= 99) std::cout << opto_name << "getComponentOptOs: opto " << opto << opto->name() << std::endl;
737  std::vector<OpticalObject*>::const_iterator vocite;
738 
739  if ( ALIUtils::debug >= 99) std::cout << "optolist size " << OptOList().size() << std::endl;
740  ALIbool opto_found = false;
741  for (vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite) {
742  if( (*vocite)->parent() != nullptr ) {
743  // std::cout << "looping OptOlist" << (*vocite)->name() << " parent " <<(*vocite)->parent()->name() << std::endl;
744  if( (*vocite)->parent()->name() == opto_name ) {
745  opto_found = true;
746  vcomponents.push_back( (*vocite) );
747  }
748  }
749  }
750 
751  /* std::pair<multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::iterator,
752  std::multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::iterator>
753  pmmao = _OptOtree.equal_range(opto_name);
754 
755  if( pmmao.first != _OptOtree.end()) {
756  std::multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::const_iterator socite;
757  for (socite = pmmao.first; socite != (pmmao.second); socite++) {
758  vcomponents.push_back( (*socite).second );
759  }
760  }
761  */
762  return opto_found;
763 
764 }
765 
766 
768 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
769 //@@ createCopyComponentList:
770 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
772 {
773  //---------- Find an OptO with the same type (YOU HAVE TO BE SURE THAT ALL EXISTING OPTOs OF THIS TYPE HAVE SAME COMPONENTS, IF NOT COPYING MAY GIVE YOU UNPREDICTABLE RESULTS)
774  if(ALIUtils::debug >= 3) std::cout << "createCopyComponentList " << typ << std::endl;
775  OpticalObject* start_opto = getOptOByType( typ );
776 
777  //---------- clean list of OptOs to copy
778  theOptOsToCopyList.erase( theOptOsToCopyList.begin(), theOptOsToCopyList.end() );
779 
780  //---------- Fill list of OptOs to copy
781  fillCopyComponentList( start_opto );
782  //- if(ALIUtils::debug >= 9) std::cout << "createCopyComponentList " << typ << theOptOsToCopyList.size() << std::endl;
783 
784  theOptOsToCopyListIterator = theOptOsToCopyList.begin();
785  return true;
786 }
787 
788 
789 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
790 //@@ fillCopyOptOList: Fill list of objects to copy with the components of 'opto'
791 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
793 {
794  if(ALIUtils::debug >= 3) std::cout << "entering fillCopyComponentList(): OptO" << opto->name() << std::endl;
795  //---------- Get list of components of 'opto'
796  std::vector<OpticalObject*> vopto;
797  ALIbool opto_found = getComponentOptOs( opto->name(), vopto);
798  if( !opto_found ) {
799  if(ALIUtils::debug >= 5) std::cout << "fillCopyComponentList: NO COMPONENTS TO COPY IN THIS OptO" << opto->name() << std::endl ;
800  }
801 
802  //---------- Loop list of components of 'opto'
803  std::vector<OpticalObject*>::const_iterator vocite;
804  for( vocite = vopto.begin(); vocite != vopto.end(); ++vocite ){
805  theOptOsToCopyList.push_back( *vocite );
806  if(ALIUtils::debug >= 5) std::cout << "fillCopyOptOList " << (*vocite)->type() << " " << (*vocite)->name() << std::endl;
807  //---------- Add components of this component
808  fillCopyComponentList( *vocite );
809  }
810  return opto_found;
811 }
812 
813 
814 
815 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
816 //@@ nextOptOToCopy: return next object to copy from theOptOsToCopyListIterator
817 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
819 {
820  if(ALIUtils::debug >= 5) std::cout << "entering nextOptOToCopy() " << std::endl;
821  ++theOptOsToCopyListIterator;
822  // if(ALIUtils::debug >= 5) std::cout <<" nextOptOToCopy " << (*(theOptOsToCopyListIterator-1))->name() << std::endl;
823  return *(theOptOsToCopyListIterator-1);
824 }
825 
826 
828 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
829 //@@ If fitting CMS link, it has to be fitted part by part, in several iterations
830 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
831 void Model::CMSLinkFit( ALIint cmslink)
832 {
833  /*
834  //---------- Get number of fits
835  ALIint cmslinkNoFits = 0;
836  if( cmslink == 1) {
837  cmslinkNoFits = 3;
838  } else if( cmslink == 2) {
839  cmslinkNoFits = 2;
840  }
841  if(ALIUtils::debug >= 4) std::cout << " Start CMS link fit with method " << cmslink << " (number of fits = " << cmslinkNoFits << ")" << std::endl;
842 
843  //----------- Loop number of cms_link fits
844  for(ALIint ilink = ALIint(Model::GlobalOptions()["cms_link"]); ilink <= cmslinkNoFits; ilink++) {
845 
846  //----- Iteration 2 of method 2 resembles iteration 3 of method 1
847  ALIdouble cmslink_method;
848  assert(Model::getGlobalOptionValue("cms_link_method", cmslink_method));
849  if( cmslink_method == 2 && ilink == 2) ilink = 3;
850 
851 //---- Set variable CMSLinkIteration, Checked in Fit.C and other //- std::cout << "ilink" << ilink << std::endl;
852  Model::setGlobalOption("cms_link", ilink);
853  Model::CMSLinkIteration = ilink;
854 
855  if(ilink > 1)Model::readSystemDescription(); //already read once to fill value Model::GlobalOptions()["cms_link"]
856 
857  //---------- Delete the OptO not fitted in this iteration
858  // Model::CMSLinkDeleteOptOs();
859  // cannot be here because you may recover a parameter saved in previous iteration that now it is deleted (!!MODIFY THIS)
860 
861  //---------- Recover parameters fitted in previous iteration
862  Model::CMSLinkRecoverParamFittedSigma( ilink );
863 
864  Model::CMSLinkRecoverParamFittedValueDisplacement( ilink );
865 
866  //---------- Delete the OptO not fitted in this iteration
867  Model::CMSLinkDeleteOptOs();
868 
869  //---------- Start fit
870  Fit::startFit();
871 
872  //---------- Save parameters fitted in this iteration (to be used in next one)
873  Model::CMSLinkSaveParamFittedSigma( ilink );
874 
875  Model::CMSLinkSaveParamFittedValueDisplacement( ilink );
876 
877  //---------- Delete whole system to start anew in next iteration
878  Model::CMSLinkCleanModel();
879 
880  }
881  */
882 }
883 
884 
885 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
886 //@@ CMSLinkCleanModel: clean Model for new iteration while fitting CMS link
887 //@@ part by part
888 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
890 {
891  deleteOptO("s");
892  //---------- Clean OptOdicitionary (in case this is not first reading)
893  ALIuint odsize = theOptODictionary.size();
894  for( ALIuint ii = 0; ii < odsize; ii++) {
895  theOptODictionary.pop_back();
896  }
897 
898 }
899 
900 
901 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
902 //@@ CMSLinkDeleteOptOs
903 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
905 {
906  ALIint cmslink_iter = Model::CMSLinkIteration;
907  ALIdouble cmslink_method;
908 
910  assert(gomgr->getGlobalOptionValue("cms_link_method", cmslink_method));
911  ALIdouble cmslink_halfplanes;
912  assert(gomgr->getGlobalOptionValue("cms_link_halfplanes", cmslink_halfplanes));
913  if(ALIUtils::debug >= 2) std::cout << "CMSLinkDeleteOptOs: cms_link_halfplanes " << cmslink_halfplanes << cmslink_iter << std::endl;
914 
915  if( cmslink_iter == 1){
916  //---------- First fit: delete everything but laser1 and det_tkU
917  // deleteOptO("s/laserboxL/laser2");
918  //- std::cout << "delete mabs" << std::endl;
919  deleteOptO("s/mabsL");
920  //------- Method 1: detectors at tracker down
921  if (cmslink_method == 1){
922  deleteOptO("s/tracker/det_trkDL");
923  deleteOptO("s/tracker/det_trkDR");
924  }
925 
926  if( cmslink_halfplanes == 2) {
927  // deleteOptO("s/laserboxR/laser2");
928  deleteOptO("s/mabsR");
929  }
930 
931  } else if( cmslink_iter == 2) {
932  //---------- Second fit (method 1): delete everything but laser1 and det3
933  // deleteOptO("s/laserboxL/laser2");
934  deleteOptO("s/mabsL");
935  deleteOptO("s/tracker/CST/wheel_trkL/peri/mirror"); //??
936  deleteOptO("s/tracker/CST/wheel_trkL/det_trkU");
937  //------- Method 1: detectors on CST, Method 2: detectors on tracker
938  //not necessary deleteOptO("s/tracker/CST/det6");
939 
940  if( cmslink_halfplanes <= 1) {
941  deleteOptO("s/tracker/CST/wheel_trkR");
942  } else if( cmslink_halfplanes == 2) {
943  // deleteOptO("s/laserboxR/laser2");
944  deleteOptO("s/mabsR");
945  deleteOptO("s/tracker/CST/wheel_trkR/peri/mirror"); //??
946  deleteOptO("s/tracker/CST/wheel_trkR/det_trkU");
947  }
948 
949  } else if( cmslink_iter == 3) {
950  //---------- Third fit: delete everything but laser2 and mabs
951  // deleteOptO("s/laserboxL/laser1");
952  deleteOptO("s/tracker");
953 
954  if( cmslink_halfplanes == 2) {
955  // deleteOptO("s/laserboxR/laser1");
956  }
957  //---------- Do nothing
958  } else {
959 
960  }
961 
962 }
963 
964 
965 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
966 //@@ CMSLinkSaveParamFittedSigma
967 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
969 {
970  /*
971  ALIdouble cms_link_halfplanes = (GlobalOptions()["cms_link_halfplanes"]);
972 
973  cleanParamFittedSigmaVector();
974 
975  //---------- First fit: Save laserbox angles fitted at tracker
976  if( cms_link == 1) {
977  //? if (GlobalOptions()["cms_link_method"] < 10){
978  saveParamFittedSigma("s/laserboxL","Angles X");
979  saveParamFittedSigma("s/laserboxL","Angles Y");
980 
981  saveParamFittedCorrelation("s/laserboxL","Angles X",
982  "s/tracker/CST","Centre Y");
983  saveParamFittedCorrelation("s/laserboxL","Angles Y",
984  "s/tracker/CST","Centre X");
985  if( cms_link_halfplanes == 2) {
986  saveParamFittedSigma("s/laserboxR","Angles X");
987  saveParamFittedSigma("s/laserboxR","Angles Y");
988 
989  saveParamFittedCorrelation("s/laserboxR","Angles X",
990  "s/tracker/CST","Centre Y");
991  saveParamFittedCorrelation("s/laserboxR","Angles Y",
992  "s/tracker/CST","Centre X");
993  }
994 
995  } else if( cms_link == 2) {
996  //---------- Second fit: Save laserbox angles and position
997  saveParamFittedSigma("s/laserboxL","Centre X");
998  saveParamFittedSigma("s/laserboxL","Centre Y");
999  // Make quality unk to cal
1000  saveParamFittedSigma("s/laserboxL","Centre Z");
1001  saveParamFittedSigma("s/laserboxL","Angles X");
1002  saveParamFittedSigma("s/laserboxL","Angles Y");
1003 
1004  saveParamFittedCorrelation("s/laserboxL","Centre X",
1005  "s/laserboxL","Angles Y");
1006  saveParamFittedCorrelation("s/laserboxL","Centre Y",
1007  "s/laserboxL","Angles X");
1008 
1009  if( cms_link_halfplanes == 2) {
1010  saveParamFittedSigma("s/laserboxR","Centre X");
1011  saveParamFittedSigma("s/laserboxR","Centre Y");
1012  // Make quality unk to cal
1013  saveParamFittedSigma("s/laserboxR","Centre Z");
1014  saveParamFittedSigma("s/laserboxR","Angles X");
1015  saveParamFittedSigma("s/laserboxR","Angles Y");
1016 
1017  saveParamFittedCorrelation("s/laserboxR","Centre X",
1018  "s/laserboxR","Angles Y");
1019  saveParamFittedCorrelation("s/laserboxR","Centre Y",
1020  "s/laserboxR","Angles X");
1021  }
1022  } else {
1023  //---------- Do nothing
1024 
1025  }
1026  */
1027 }
1028 
1029 
1030 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1031 //@@ CMSLinkSaveParamFittedValueDisplacement:
1032 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1034 {
1035  /*
1036  cleanParamFittedValueDisplacementMap();
1037 
1038  //----------
1039  if( cms_link == 1 || cms_link == 2 ) {
1040  std::vector<Entry*>::const_iterator vecite;
1041  for( vecite = EntryList().begin(); vecite != EntryList().end(); vecite++) {
1042  if( (*vecite)->valueDisplacementByFitting() != 0 ) {
1043  ALIstring names = (*vecite)->OptOCurrent()->name() + "/" + (*vecite)->name();
1044  std::cout << "saeParamFittedValueDisplacementMap" << names << (*vecite)->valueDisplacementByFitting() << std::endl;
1045  theParamFittedValueDisplacementMap[ names ] = (*vecite)->valueDisplacementByFitting();
1046  }
1047  }
1048 
1049  //---------- Do nothing
1050  } else {
1051 
1052  }
1053  */
1054 }
1055 
1056 
1057 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1058 //@@ CMSLinkRecoverParamFittedSigma:
1059 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1061 {
1062  /*
1063  ALIdouble cms_link_halfplanes = (GlobalOptions()["cms_link_halfplanes"]);
1064 
1065  if( cms_link == 2) {
1066  //---------- Second fit: recover laserbox angles
1067  recoverParamFittedSigma("s/laserboxL","Angles X",0);
1068  recoverParamFittedSigma("s/laserboxL","Angles Y",1);
1069 
1070  if( cms_link_halfplanes == 2) {
1071  recoverParamFittedSigma("s/laserboxR","Angles X",0);
1072  recoverParamFittedSigma("s/laserboxR","Angles Y",1);
1073  }
1074 
1075  } else if( cms_link == 3) {
1076  //---------- Third fit: recover laserbox angles and position and rotate angles to mabs
1077  recoverParamFittedSigma("s/laserboxL","Centre X",0);
1078  recoverParamFittedSigma("s/laserboxL","Centre Y",1);
1079  recoverParamFittedSigma("s/laserboxL","Centre Z",2);
1080  recoverParamFittedSigma("s/laserboxL","Angles X",3);
1081 
1082  //----- Angle around Y is converted to angle around Z when turning 90 deg
1083  Entry* slaZ = getEntryByName("s/laserboxL","Angles Z");
1084  //--- prec_level_laser
1085  Entry* smaZ = getEntryByName("s/mabsL","Angles Z");
1086  slaZ->setQuality(0);
1087  slaZ->setValue( smaZ->value() );
1088  // smaZ->setQuality(0); //!!???!!?
1089 
1090  Entry* slaY = getEntryByName("s/laserboxL","Angles Y");
1091  slaY->setQuality(0);
1092 
1093  if( cms_link_halfplanes == 2) {
1094  recoverParamFittedSigma("s/laserboxR","Centre X",0);
1095  recoverParamFittedSigma("s/laserboxR","Centre Y",1);
1096  recoverParamFittedSigma("s/laserboxR","Centre Z",2);
1097  recoverParamFittedSigma("s/laserboxR","Angles X",3);
1098 
1099  //----- Angle around Y is converted to angle around Z when turning 90 deg
1100  Entry* slaZ = getEntryByName("s/laserboxR","Angles Z");
1101  //--- prec_level_laser
1102  Entry* smaZ = getEntryByName("s/mabsR","Angles Z");
1103  slaZ->setQuality(0);
1104  slaZ->setValue( smaZ->value() );
1105  // smaZ->setQuality(0); //!!???!!?
1106 
1107  Entry* slaY = getEntryByName("s/laserboxR","Angles Y");
1108  slaY->setQuality(0);
1109  }
1110  } else {
1111  //---------- Do nothing
1112 
1113  }
1114  */
1115 }
1116 
1117 
1118 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1119 //@@ CMSLinkRecoverParamFittedValueDisplacement:
1120 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1122 {
1123  /*
1124  //---------- Second fit: recover laserbox angles
1125  if( cms_link == 2 || cms_link == 3 ) {
1126 
1127  std::map<ALIstring, ALIdouble, std::less<ALIstring> >::const_iterator vsdmite;
1128  if ( ALIUtils::debug >= 99) std::cout << "theParamFittedValueDisplacementMap.size " << theParamFittedValueDisplacementMap.size() << std::endl;
1129  for( vsdmite = theParamFittedValueDisplacementMap.begin(); vsdmite != theParamFittedValueDisplacementMap.end(); vsdmite++) {
1130  std::cout << "reoverValueDisp" << (*vsdmite).first << " " << (*vsdmite).second << std::endl;
1131  Entry* this_entry = getEntryByName( (*vsdmite).first);
1132  this_entry->displaceOriginal( (*vsdmite).second );
1133  this_entry->OptOCurrent()->resetGlobalCoordinates();
1134  this_entry->setValueDisplacementByFitting( (*vsdmite).second );
1135 
1136  }
1137 
1138  //---------- Do nothing
1139  } else {
1140 
1141  }
1142  */
1143 }
1144 
1145 
1146 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1147 //@@ Delete an OptO
1148 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1149 void Model::deleteOptO( const ALIstring& opto_name )
1150 {
1151  OpticalObject* opto = getOptOByName( opto_name );
1152  deleteOptO( opto );
1153 }
1154 
1155 
1156 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1157 //@@ deleteOptO: delete OptO, its Entries, and the Measurements in which it participates. Then deleteOptO of components
1158 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1160 {
1161  if(ALIUtils::debug >= 5 ) std::cout << "DELETING OptO" << opto->name() << std::endl;
1162 
1163  //---------- Delete Coordinate Entries of this OptO
1164  std::vector<Entry*>::const_iterator vecite;
1165  std::vector<Entry*>::iterator veite2;
1166  if ( ALIUtils::debug >= 9) std::cout << "SIZE" << theEntryVector.size() <<std::endl;
1167  for( vecite = opto->CoordinateEntryList().begin(); vecite != opto->CoordinateEntryList().end(); ++vecite) {
1168  // ALIuint pos = FindItemInVector( (*veite), opto->CoordinateEntryList() );
1169  veite2 = find( theEntryVector.begin(), theEntryVector.end(), (*vecite) );
1170  //- if ( ALIUtils::debug >= 9) std::cout << (*veite2) << "DELETE ENTRY " << (*vecite) <<(*veite2)->OptOCurrent()->name() << (*veite2)->name() << std::endl;
1171  delete ( (*veite2) );
1172  theEntryVector.erase( veite2 );
1173  }
1174 
1175  for( vecite = opto->ExtraEntryList().begin(); vecite != opto->ExtraEntryList().end(); ++vecite) {
1176  // ALIuint pos = FindItemInVector( (*veite), opto->CoordinateEntryList() );
1177  veite2 = find( theEntryVector.begin(), theEntryVector.end(), (*vecite) );
1178  //- if(ALIUtils::debug >= 9) std::cout << (*veite2) << "DELETE ENTRY " << (*veite2)->OptOCurrent()->name() << (*veite2)->name() << std::endl;
1179  delete ( (*veite2) );
1180  theEntryVector.erase( veite2 );
1181  }
1182 
1183 
1184  for( vecite = theEntryVector.begin(); vecite != theEntryVector.end(); ++vecite ) {
1185  // std::cout << (*vecite) << "ENTReY " << (*vecite)->OptOCurrent()->name() << (*vecite)->name() << std::endl;
1186  }
1187 
1188  //---------- Delete all Measurement in which opto takes part
1189  std::vector<Measurement*> MeasToBeDeleted;
1190  std::vector<Measurement*>::const_iterator vmite;
1191  std::vector<OpticalObject*>::const_iterator vocite;
1192  for( vmite = MeasurementList().begin(); vmite != MeasurementList().end(); ++vmite ) {
1193  if(ALIUtils::debug >= 5) std::cout << "Deleting Measurement" << (*vmite)->name() << std::endl;
1194  //----- If any of the OptO Measured is opto, delete this Measurement
1195  for( vocite = (*vmite)->OptOList().begin(); vocite != (*vmite)->OptOList().end(); ++vocite) {
1196  if( (*vocite) == opto ) {
1197  //- std::cout << "MEASTBD" << (*vmite) << std::endl;
1198  MeasToBeDeleted.push_back( *vmite );
1199  //? delete (*vmite);
1200  break;
1201  }
1202  }
1203  }
1204 
1205  //---------- Delete Measurements from list
1206  std::vector<Measurement*>::const_iterator vmcite;
1207  std::vector<Measurement*>::iterator vmite2;
1208  if ( ALIUtils::debug >= 9) std::cout << "SIZEMEAS" << MeasToBeDeleted.size() <<std::endl;
1209  for( vmcite = MeasToBeDeleted.begin(); vmcite != MeasToBeDeleted.end(); ++vmcite) {
1210  vmite2 = find( theMeasurementVector.begin(), theMeasurementVector.end(), (*vmcite) );
1211  // std::cout << (*vmite2) << "DELETE MSEASU " << (*vmcite) << (*vmite2)->name()[0] << std::endl;
1212  delete ( (*vmite2) );
1213  theMeasurementVector.erase( vmite2 );
1214  }
1215 
1216 
1217  //---------- Delete components
1218  // std::vector<OpticalObject*>::iterator voite;
1219  std::vector<OpticalObject*> vopto;
1220  // ALIbool opto_found = getComponentOptOs( opto->name(), vopto );
1221  for( vocite = vopto.begin(); vocite != vopto.end(); ++vocite ) {
1222  deleteOptO( *vocite );
1223  }
1224 
1225  //---------- Delete this OptO
1226  //---------- Delete OptO (only from list, to delete it really first delete components)
1227  /* map< ALIstring, OpticalObject*, std::less<ALIstring> >::iterator msoite =
1228 find( theOptOList.begin(), theOptOList.end(),
1229 map< ALIstring, OpticalObject*, std::less<ALIstring> >::value_type( opto->name(), opto) );*/
1230  std::vector< OpticalObject* >::iterator dvoite =
1231  find( theOptOList.begin(), theOptOList.end(),
1233  //- std::cout << (*dvoite) << "DELETE OPTO " << opto <<"WW" << (*dvoite)->name() << std::endl;
1234  theOptOList.erase( dvoite );
1235  delete opto;
1236 
1237 }
1238 
1239 
1240 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1241 //@@
1242 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1243 void Model::saveParamFittedSigma( const ALIstring& opto_name, const ALIstring& entry_name)
1244 {
1245  /*
1246 //---------- Get sigma of param Optical
1247  Entry* entry = getEntryByName(opto_name, entry_name);
1248  ALIuint fit_pos = entry->fitPos();
1249  if( fit_pos < 0 || fit_pos >= Fit::propagationMatrix().NoLines()) {
1250  std::cerr << "!!EXITING at saveParamFittedSigma: fit position incorrect " <<
1251  fit_pos << "propagationMatrix size =" << Fit::propagationMatrix().NoLines() << opto_name << std::endl;
1252  exit(3);
1253  }
1254  std::cout << entry_name << "saveParamFittedSigma" << fit_pos << sqrt(Fit::propagationMatrix()( fit_pos, fit_pos)) << std::endl;
1255  theParamFittedSigmaVector.push_back( sqrt(Fit::propagationMatrix()( fit_pos, fit_pos)) );
1256  //- Fit::propagationMatrix().Dump(" the 2PropagationMatrix");
1257  */
1258 }
1259 
1260 
1261 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1262 //@@
1263 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1264 void Model::saveParamFittedCorrelation( const ALIstring& opto_name1, const ALIstring& entry_name1, const ALIstring& opto_name2, const ALIstring& entry_name2)
1265 {
1266  /*
1267 //---------- Get sigma of param Optical
1268  Entry* entry1 = getEntryByName(opto_name1, entry_name1);
1269  Entry* entry2 = getEntryByName(opto_name2, entry_name2);
1270  ALIuint fit_pos1 = entry1->fitPos();
1271  ALIuint fit_pos2 = entry2->fitPos();
1272 
1273  //---------- Get correlation if entry has been fitted
1274  ALIuint pmsize = Fit::propagationMatrix().NoLines();
1275  if( fit_pos1 >= 0 && fit_pos1 < pmsize && fit_pos2 >= 0 && fit_pos2 < pmsize ) {
1276  ALIdouble error1 = sqrt( Fit::propagationMatrix()( fit_pos1, fit_pos1) );
1277  ALIdouble error2 = sqrt( Fit::propagationMatrix()( fit_pos2, fit_pos2) );
1278  ALIdouble correl = Fit::propagationMatrix()( fit_pos1, fit_pos2) / error1 / error2;
1279  theParamFittedSigmaVector.push_back( correl );
1280  if(ALIUtils::debug>=9) {
1281  std::cout << "saveParamFittedCorre" << opto_name1 << entry_name1 << fit_pos1 <<
1282  opto_name2 << entry_name2 << fit_pos2 << "MM " << correl << std::endl;
1283  }
1284  } else {
1285  if(ALIUtils::debug>=9) {
1286  std::cout << "NOsaveParamFittedCorre" << opto_name1 << entry_name1 << fit_pos1 <<
1287  opto_name2 << entry_name2 << fit_pos2 << "MM " << std::endl;
1288  theParamFittedSigmaVector.push_back( 0. );
1289  }
1290 
1291  }
1292  //- Fit::propagationMatrix().Dump(" the 2PropagationMatrix");
1293  */
1294 }
1295 
1296 
1297 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1298 //@@
1299 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1300 void Model::recoverParamFittedSigma( const ALIstring& opto_name, const ALIstring& entry_name, const ALIuint position )
1301 {
1302  /*
1303  if( position >= theParamFittedSigmaVector.size() ) {
1304  std::cerr << "!!EXITING at recoverParamFittedSigma: position" << position <<
1305  " bigger than dimension of theParamFittedSigmaVector " << theParamFittedSigmaVector.size() << std::endl;
1306  exit(3);
1307  }
1308  ALIdouble sigma = getParamFittedSigmaVectorItem( position );
1309 
1310  Entry* entry = getEntryByName(opto_name, entry_name);
1311  entry->setSigma( sigma );
1312  entry->setQuality( 1 );
1313  std::cout << "recover " << opto_name << entry_name << entry->sigma() <<std::endl;
1314  */
1315 }
1316 
1317 
1318 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1319 //@@ getParamFittedSigmaVectorItem
1320 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1322 {
1323  if( position >= theParamFittedSigmaVector.size() ) {
1324  std::cerr << "!!EXITING at getParamFittedSigma: position" << position <<
1325  " bigger than dimension of theParamFittedSigmaVector " << theParamFittedSigmaVector.size() << std::endl;
1326  exit(3);
1327  }
1328  std::vector<ALIdouble>::const_iterator vdcite = theParamFittedSigmaVector.begin() + position;
1329  return (*vdcite);
1330 
1331 }
1332 
1333 
1334 
1335 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1336 //@@ getParamFittedSigmaVectorItem
1337 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1339 {
1340  if(ALIUtils::debug >= 5) std::cout << " readMeasurementsFromFile " << Measurement::measurementsFileName() << std::endl;
1341  if( Measurement::measurementsFileName() == "") return true;
1342 
1344  std::vector<ALIstring> wordlist;
1345  //---------- read date
1346  // ALIint retfil = filein.getWordsInLine(wordlist);
1347  // std::cout << "@@@@@@@@@@@@@@@ RETFIL " << retfil << std::endl;
1348  //if( retfil == 0 ) {
1349  if( filein.getWordsInLine(wordlist) == 0 ) {
1350  if(ALIUtils::debug>=4 ) std::cout << "@@@@ No more measurements left" << std::endl;
1351  return false;
1352  }
1353 
1355  // struct tm tim;
1356  //t Model::setMeasurementsTime( tim );
1357 
1358  //if you are looking for only one measurement with a given date and time, loop all measurements until you find it
1359  if( Measurement::only1 ) {
1360  for(;;) {
1361  if( wordlist[0] == "DATE:" && wordlist[1] == Measurement::only1Date && wordlist[2] == Measurement::only1Time ) break;
1362  filein.getWordsInLine(wordlist);
1363  if(filein.eof() ) {
1364  std::cerr << "!! EXITING date not found in measurements file" << Measurement::only1Date << " " << Measurement::only1Time << std::endl;
1365  exit(1);
1366  }
1367  }
1368  }
1369 
1370  //set date and time of current measurement
1371  if( wordlist[0] == "DATE:" ) {
1372  Measurement::setCurrentDate( wordlist );
1373  }
1374 
1375  //---------- loop measurements
1376  ALIint nMeas = Model::MeasurementList().size();
1377  if(ALIUtils::debug >= 4) {
1378  std::cout << " Reading " << nMeas << " measurements from file " << Measurement::measurementsFileName()
1379  << " DATE: " << wordlist[1] << " " << wordlist[1] << std::endl;
1380  }
1381  ALIint ii;
1382  for(ii = 0; ii < nMeas; ii++) {
1383  filein.getWordsInLine(wordlist);
1384  if( wordlist[0] == ALIstring("SENSOR2D") || wordlist[0] == ALIstring("TILTMETER") || wordlist[0] == ALIstring("DISTANCEMETER") || wordlist[0] == ALIstring("DISTANCEMETER1DIM") || wordlist[0] == ALIstring("COPS") ) {
1385  if( wordlist.size() != 2 ) {
1386  std::cerr << "!!!EXITING Model::readMeasurementsFromFile. number of words should be 2 instead of " << wordlist.size() << std::endl;
1387  ALIUtils::dumpVS( wordlist, " " );
1388  exit(1);
1389  }
1390  std::vector< Measurement* >::const_iterator vmcite;
1391  for( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); ++vmcite ) {
1392  //-------- Measurement found, fill data
1393  /* ALIint last_slash = (*vmcite)->name().rfind('/');
1394  ALIstring oname = (*vmcite)->name();
1395  if( last_slash != -1 ) {
1396  oname = oname.substr(last_slash+1, (*vmcite)->name().size()-1);
1397  }
1398  */
1399  ALIint fcolon = (*vmcite)->name().find(':');
1400  ALIstring oname = (*vmcite)->name();
1401  oname = oname.substr(fcolon+1,oname.length());
1402  //- std::cout << " measurement name " << (*vmcite)->name() << " short " << oname << std::endl;
1403  if( oname == wordlist[1] ) {
1404  //- std::cout << " measurement name found " << oname << std::endl;
1405  if( (*vmcite)->type() != wordlist[0] ) {
1406  std::cerr << "!!! Reading measurement from file: type in file is "
1407  << wordlist[0] << " and should be " << (*vmcite)->type() << std::endl;
1408  exit(1);
1409  }
1410  Measurement* meastemp = *vmcite;
1411 
1413  ALIbool sigmaFF = gomgr->GlobalOptions()["measurementErrorFromFile"];
1414  //---------- Read the data
1415  for ( ALIuint ii=0; ii < meastemp->dim(); ii++){
1416  filein.getWordsInLine( wordlist );
1417  ALIdouble sigma = 0.;
1418  if( !sigmaFF ) {
1419  // keep the sigma, do not read it from file
1420  const ALIdouble* sigmav = meastemp->sigma();
1421  sigma = sigmav[ii];
1422  }
1423  //---- Check measurement value type is OK
1424  if( meastemp->valueType(ii) != wordlist[0] ) {
1425  filein.ErrorInLine();
1426  std::cerr << "!!!FATAL ERROR: Measurement value type is " << wordlist[0] << " while in setup definition was " << meastemp->valueType(ii) << std::endl;
1427  exit(1);
1428  }
1429  meastemp->fillData( ii, wordlist );
1430  if( !sigmaFF ) {
1431  meastemp->setSigma( ii, sigma );
1432  }
1433  }
1434  meastemp->correctValueAndSigma();
1435  break;
1436  }
1437  }
1438  if( vmcite == MeasurementList().end() ) {
1439  for( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); ++vmcite ) {
1440  std::cerr << "MEAS: " << (*vmcite)->name() << " " << (*vmcite)->type() << std::endl;
1441  }
1442  std::cerr << "!!! Reading measurement from file: measurement not found in list: type in file is " << wordlist[1] << std::endl;
1443  exit(1);
1444  }
1445  } else {
1446  std::cerr << " wrong type of measurement: " << wordlist[0] << std::endl
1447  << " Available types are SENSOR2D, TILTMETER, DISTANCEMETER, DISTANCEMETER1DIM, COPS" << std::endl;
1448  exit(1);
1449  }
1450  }
1451  //- std::cout << " returning readmeasff" << std::endl;
1452 
1453  return true;
1454 }
1455 
1456 
1457 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1458 
1459 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1460 void Model::copyMeasurements( const std::vector<ALIstring>& wl )
1461 {
1462 
1463  //----- Check format, e.g. @copy_measurements _1/_2/*_1
1464 
1465 
1466  //----- get list of Measurement's that satisfy the query in their name
1467  //t std::string querystr = wl[1].substr( wl[1].find("/")+1, wl[1].length() );
1468  std::string subsstr1 = wl[1].substr( 0, wl[1].find("/") );
1469  std::string subsstr2 = wl[1].substr( wl[1].find("/")+1, wl[1].rfind("/") - wl[1].find("/")-1 );
1470  std::string querystr = wl[1].substr( wl[1].rfind("/")+1, wl[1].length() );
1471 
1472  std::cout << " Model::copyMeasurements " << " subsstr1 " << subsstr1 << " subsstr2 " << subsstr2 << " querystr " << querystr << std::endl;
1473 
1474  std::vector< Measurement* > measToCopy;
1475  std::vector< Measurement* >::iterator mite;
1476  for( mite = theMeasurementVector.begin(); mite != theMeasurementVector.end(); ++mite) {
1477  Measurement* meas = (*mite);
1478  //improve this
1479  if( meas->name().find( querystr ) != std::string::npos ) {
1480  measToCopy.push_back( meas );
1481  }
1482  }
1483 
1484  //---- Build new measurements
1485  Measurement* meastemp = nullptr;
1486  for( mite = measToCopy.begin(); mite != measToCopy.end(); ++mite) {
1487  Measurement* meas = (*mite);
1488  std::vector<ALIstring> wlt;
1489  wlt.push_back( meas->type() );
1490 
1491  //---- create new name
1492  std::string newName = ALIUtils::changeName( meas->name(), subsstr1, subsstr2 );
1493  std::cout << " newName " << newName << std::endl;
1494  wlt.push_back( newName );
1495 
1496  ALIstring measType = wlt[0];
1497  ALIstring measName;
1498  if( wlt.size() == 2 ) {
1499  measName = wlt[1];
1500  } else {
1501  measName = "";
1502  }
1503  if ( meas->type() == ALIstring("SENSOR2D") ) {
1504  meastemp = new MeasurementSensor2D( 2, measType, measName );
1505  // } else if ( meas->type() == ALIstring("DISTANCEMETER3DIM") ) {
1506  // meastemp = new MeasurementDistancemeter3dim( 1, measType, measName );
1507  } else if ( meas->type() == ALIstring("DISTANCEMETER") ||
1508  meas->type() == ALIstring("DISTANCEMETER1DIM") ) {
1509  meastemp = new MeasurementDistancemeter( 1, measType, measName );
1510  } else if ( meas->type() == ALIstring("TILTMETER") ) {
1511  meastemp = new MeasurementTiltmeter( 1, measType, measName );
1512  // } else if ( meas->type() == ALIstring("DIFFCENTRE") ) {
1513  // meastemp = new MeasurementDiffCentre( 1, measType, measName );
1514  // } else if ( meas->type() == ALIstring("DIFFANGLE") ) {
1515  // meastemp = new MeasurementDiffAngle( 1, measType, measName );
1516  } else if ( meas->type() == ALIstring("DIFFENTRY") ) {
1517  meastemp = new MeasurementDiffEntry( 1, measType, measName );
1518  } else if ( meas->type() == ALIstring("COPS") ) {
1519  meastemp = new MeasurementCOPS( 4, measType, measName );
1520  } else {
1521  throw cms::Exception("LogicError")
1522  << "@SUB=Model::copyMeasurements\n"
1523  << "unknown measurement type: " << meas->type();
1524  }
1525 
1526  //later meastemp->copyConversionFactor( wordlist );
1527  meastemp->copyMeas(meas, subsstr1, subsstr2);
1528 
1529  break;
1530  }
1531 
1532 }
1533 
1534 
1535 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1537 {
1538  if( ALIUtils::debug >= 3 ) std::cout << " Model::SetValueDisplacementsFromReportOut() " << std::endl;
1539 
1540  EntryMgr* entryMgr = EntryMgr::getInstance();
1541 
1542  if( entryMgr->numberOfEntries() != 0 ){
1543  EntryData* entryData;
1544 
1545  std::vector<Entry*>::const_iterator vecite;
1546  for ( vecite = Model::EntryList().begin();
1547  vecite != Model::EntryList().end(); ++vecite ) {
1548  //----- Find the EntryData corresponding to this entry
1549  entryData = entryMgr->findEntryByLongName( (*vecite)->OptOCurrent()->longName(), (*vecite)->name() );
1550  if( ALIUtils::debug >= 3 ) std::cout << "SetValueDisplacementsFromReportOut "<< (*vecite)->OptOCurrent()->longName() << " " << (*vecite)->name() << " " << entryData->valueDisplacement() << std::endl;
1551  (*vecite)->addFittedDisplacementToValue( entryData->valueDisplacement() );
1552  }
1553  }
1554 
1555 }
1556 
1557 
1558 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1560 {
1561  std::string str ="";
1562 
1563  if( cs == COCOA_Init ) {
1564  str = "COCOA_Init ";
1565  }else if( cs == COCOA_ReadingModel) {
1566  str = "COCOA_ReadingModel";
1567  }else if( cs == COCOA_InitFit) {
1568  str = "COCOA_InitFit";
1569  }else if( cs == COCOA_FitOK) {
1570  str = "COCOA_FitOK";
1571  }else if( cs == COCOA_FitImproving) {
1572  str = "COCOA_FitImproving";
1573  }else if( cs == COCOA_FitCannotImprove) {
1574  str = "COCOA_FitCannotImprove";
1575  }else if( cs == COCOA_FitChi2Worsened) {
1576  str = "COCOA_FitChi2Worsened";
1577  }else if( cs == COCOA_FitMatrixNonInversable) {
1578  str = "COCOA_FitMatrixNonInversable";
1579  }
1580 
1581  return str;
1582 }
1583 
1584 
1585 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1587 {
1588  theOpticalAlignments = optAlig.opticalAlignments();
1589 
1590  OpticalAlignInfo oai_system = FindOptAlignInfoByType( "system" );
1591 
1592  OpticalObject* OptOsystem = new OpticalObject( nullptr, "system", oai_system.name_, false );
1593 
1594  OptOsystem->constructFromOptAligInfo( oai_system );
1595 
1596  //- Model::_OptOtree.insert( std::multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::value_type(OptOsystem->type(), OptOsystem) );
1597  // theOptOlist[OptOsystem->name()] = OptOsystem;
1598  theOptOList.push_back( OptOsystem );
1599 }
1600 
1601 
1602 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1604 {
1605  OpticalAlignInfo oai;
1606 
1607  ALIbool bFound = false;
1608  std::vector<OpticalAlignInfo>::iterator ite;
1609  for( ite = theOpticalAlignments.begin(); ite != theOpticalAlignments.end(); ++ite ){
1610  // std::cout << " Model::FindOptAlignInfoByType " << (*ite).type_ << " =? " << type << std::endl;
1611  if( (*ite).type_ == type ) {
1612  if( !bFound ){
1613  oai = *ite;
1614  bFound = true;
1615  } else {
1616  std::cerr << "!! WARNING: Model::FindOptAlignInfoByType more than one objects of type " << type << std::endl;
1617  std::cerr << " returning object " << oai.name_ << std::endl
1618  << " skipping object " << (*ite).name_ << std::endl;
1619  }
1620  }
1621  }
1622  if( !bFound ) {
1623  std::cerr << "!! ERROR: Model::FindOptAlignInfoByType object not found, of type " << type << std::endl;
1624  std::exception();
1625  }
1626 
1627  return oai;
1628 }
1629 
1630 
1631 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1633 {
1634  std::vector<OpticalAlignMeasurementInfo>::iterator mite;
1635 
1636  if( ALIUtils::debug >= 5 ) std::cout << " BuildMeasurementsFromOA " << std::endl;
1637  std::vector<OpticalAlignMeasurementInfo> measInfos = measList.oaMeasurements_;
1638  for( mite = measInfos.begin(); mite != measInfos.end(); ++mite ) {
1639  std::string measType = (*mite).type_;
1640  std::string measName = (*mite).name_;
1641  if( ALIUtils::debug >= 4 ) std::cout << " BuildMeasurementsFromOA measType " << measType << " measName " << measName << std::endl;
1642  //---------- Create Measurement with appropiate dimension
1643  Measurement* meastemp = nullptr;
1644  if ( measType == ALIstring("SENSOR2D") ) {
1645  meastemp = new MeasurementSensor2D( 2, measType, measName );
1646  } else if ( measType == ALIstring("DISTANCEMETER3DIM") ) {
1647  meastemp = new MeasurementDistancemeter3dim( 1, measType, measName );
1648  } else if ( measType == ALIstring("DISTANCEMETER") ||
1649  measType == ALIstring("DISTANCEMETER1DIM") ) {
1650  meastemp = new MeasurementDistancemeter( 1, measType, measName );
1651  } else if ( measType == ALIstring("TILTMETER") ) {
1652  meastemp = new MeasurementTiltmeter( 1, measType, measName );
1653  } else if ( measType == ALIstring("COPS") ) {
1654  meastemp = new MeasurementCOPS( 4, measType, measName );
1655  // } else if ( measType == ALIstring("DIFFCENTRE") ) {
1656  // meastemp = new MeasurementDiffCentre( 1, measType, measName );
1657  // } else if ( measType == ALIstring("DIFFANGLE") ) {
1658  // meastemp = new MeasurementDiffAngle( 2, measType, measName );
1659  } else if ( measType == ALIstring("DIFFENTRY") ) {
1660  meastemp = new MeasurementDiffEntry( 1, measType, measName );
1661  } else {
1662  std::cerr << " !!! Model::BuildMeasurementsFromOA : measType not found " << measType << std::endl;
1663  throw std::exception();
1664  }
1665  meastemp->constructFromOA( *mite );
1666 
1667  }
1668 }
cocoaStatus
Definition: Model.h:36
static ALIbool only1
Definition: Measurement.h:267
type
Definition: HCALResponse.h:21
void BuildMeasurementsFromOA(OpticalAlignMeasurements &measList)
Definition: Model.cc:1632
static ALIbool getComponentOptOs(const ALIstring &opto_name, std::vector< OpticalObject * > &vcomponents)
--— Get from theOptOList the list of pointers to component OptOs
Definition: Model.cc:725
static ALIint CMSLinkIteration
Definition: Model.h:253
long double ALIdouble
Definition: CocoaGlobals.h:11
static void saveParamFittedSigma(const ALIstring &opto_name, const ALIstring &entry_name)
Definition: Model.cc:1243
ALIbool eof()
Definition: ALIFileIn.cc:211
auto_ptr< ClusterSequence > cs
static void CMSLinkSaveParamFittedValueDisplacement(ALIint cmslink)
Definition: Model.cc:1033
static std::vector< OpticalAlignInfo > theOpticalAlignments
Definition: Model.h:296
static ALIFileIn & getInstance(const ALIstring &name)
Definition: ALIFileIn.cc:23
OpticalAlignInfo FindOptAlignInfoByType(const ALIstring &type)
Definition: Model.cc:1603
static void deleteOptO(const ALIstring &opto_name)
Definition: Model.cc:1149
const ALIuint dim() const
Definition: Measurement.h:82
Definition: Entry.h:18
static void setCocoaStatus(const cocoaStatus cs)
Definition: Model.h:49
static std::string printCocoaStatus(const cocoaStatus cs)
Definition: Model.cc:1559
const std::vector< Entry * > & ExtraEntryList() const
Definition: OpticalObject.h:69
const ALIstring valueType(ALIuint ii) const
Definition: Measurement.h:140
static void SetOutputLengthDimensionFactors()
Definition: ALIUtils.cc:141
static void buildMeasurementsLinksToOptOs()
Read Measurements (to be implemented for reading from an external file the DATA of the measurements) ...
Definition: Model.cc:548
static ParameterMgr * getInstance()
Definition: ParameterMgr.cc:19
static std::map< ALIstring, ALIdouble, std::less< ALIstring > > theParamFittedValueDisplacementMap
Definition: Model.h:290
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:65
void CMSLinkCleanModel()
Definition: Model.cc:889
int ALIint
Definition: CocoaGlobals.h:15
std::vector< OpticalAlignInfo > opticalAlignments() const
void readFromReportFile(const ALIstring &filename)
static OpticalObject * getOptOByName(const ALIstring &opto_name)
--— Find an OptO name in theOptOList and return a pointer to it
Definition: Model.cc:580
static ALIint debug
Definition: ALIUtils.h:36
static ALIstring & SDFName()
the name of the System Description File
Definition: Model.h:86
string newName
Definition: mps_merge.py:84
static OpticalObject * nextOptOToCopy()
Definition: Model.cc:818
static ErrorCorrelationMgr * getInstance()
static Model * theInstance
Only instance of Model.
Definition: Model.h:191
static ALIstring only1Time
Definition: Measurement.h:269
static GlobalOptionMgr * getInstance()
#define nullptr
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
static ALIstring theMatricesFName
the name of the File for storing the matrices
Definition: Model.h:218
static ALIstring theSDFName
the name of the System Description File
Definition: Model.h:212
static Entry * getEntryByName(const ALIstring &opto_name, const ALIstring &entry_name)
--— Search an Entry name in the Entry* list and return a pointer to it
Definition: Model.cc:635
const ALIint nline()
Definition: ALIFileIn.h:42
static std::vector< std::vector< ALIstring > > & OptODictionary()
ACCESS STATIC DATA MEMBERS.
Definition: Model.h:67
static ALIint Ncmslinkrange
*************** FOR RANGE STUDIES
Definition: Model.h:238
static double getFloat(const ALIstring &str)
Convert a string to an float, checking that it is really a number.
Definition: ALIUtils.cc:404
static void copyMeasurements(const std::vector< ALIstring > &wl)
Definition: Model.cc:1460
ALIint getParameterValue(const ALIstring &name, ALIdouble &val)
static ALIdouble getParamFittedSigmaVectorItem(const ALIuint position)
Definition: Model.cc:1321
int getGlobalOptionValue(const ALIstring &sstr, ALIdouble &val)
--— Search a string in theGlobalOptions and return 1 if found
bool ALIbool
Definition: CocoaGlobals.h:19
void fillData(ALIuint coor, const std::vector< ALIstring > &wl)
Definition: Measurement.cc:201
void addRandomGaussParameter(const ALIstring &name, const ALIstring &valMean, const ALIstring &valStdDev)
Definition: ParameterMgr.cc:87
void setRandomSeed(const long seed)
Definition: ParameterMgr.cc:80
void setSigma(ALIint coor, ALIdouble val)
Definition: Measurement.h:171
static int IsNumber(const ALIstring &str)
Definition: ALIUtils.cc:34
static OpticalObject * getOptOByType(const ALIstring &type)
--— Find the first OptO of type &#39;opto_type&#39; in theOptOList and return a pointer to it ...
Definition: Model.cc:612
const ALIdouble * sigma() const
Definition: Measurement.h:132
static void readSystemDescription()
-------— Read the different sections of the SDF and act accordingly
Definition: Model.cc:103
void close()
Definition: ALIFileIn.cc:229
static std::vector< OpticalObject * > theOptOsToCopyList
Definition: Model.h:230
static std::vector< OpticalObject * > theOptOList
map of OptO*/type of parent OptO, for navigation down the tree structure
Definition: Model.h:203
virtual void setConversionFactor(const std::vector< ALIstring > &wordlist)
Definition: Measurement.h:70
static Model & getInstance()
-------— Gets the only instance of this class
Definition: Model.cc:83
static void SetValueDisplacementsFromReportOut()
Definition: Model.cc:1536
static std::vector< OpticalObject * >::const_iterator theOptOsToCopyListIterator
Definition: Model.h:232
#define end
Definition: vmac.h:37
std::vector< OpticalAlignMeasurementInfo > oaMeasurements_
static std::vector< Measurement * > theMeasurementVector
std::vector of all Measurements
Definition: Model.h:209
Model()
Definition: Model.cc:95
void BuildSystemDescriptionFromOA(OpticalAlignments &optAlig)
Definition: Model.cc:1586
Definition: Model.h:38
static ALIbool createCopyComponentList(const ALIstring &optoname)
**************** FOR COPYING AN OPTO
Definition: Model.cc:771
static void SetAngleDimensionFactors()
Definition: ALIUtils.cc:116
static ALIbool fillCopyComponentList(const OpticalObject *opto)
Definition: Model.cc:792
static void SetOutputAngleDimensionFactors()
Definition: ALIUtils.cc:169
ii
Definition: cuy.py:588
void setGlobalOption(const ALIstring go, const ALIdouble val, ALIFileIn &filein)
static ALIstring theMeasFName
the name of the Measurements File
Definition: Model.h:214
void addRandomFlatParameter(const ALIstring &name, const ALIstring &valMean, const ALIstring &valInterval)
ALIint getWordsInLine(std::vector< ALIstring > &wl)
Definition: ALIFileIn.cc:83
static ALIstring theReportFName
the name of the report File
Definition: Model.h:216
static ALIbool getComponentOptOTypes(const ALIstring &opto_type, std::vector< ALIstring > &vcomponents)
--— Get from theOptODictionary the list of component OptO types
Definition: Model.cc:692
static ALIstring & measurementsFileName()
Definition: Measurement.h:213
static int getParameterValue(const ALIstring &sstr, ALIdouble &val)
************ ACCESS INFO FROM STATIC DATA
Definition: Model.cc:567
static std::vector< Entry * > theEntryVector
std::vector of all Entries
Definition: Model.h:206
void ErrorInLine()
Definition: ALIFileIn.cc:204
ALIint numberOfEntries()
Definition: EntryMgr.h:41
static void SetLengthDimensionFactors()
Definition: ALIUtils.cc:91
static std::vector< ALIdouble > CMSLinkRangeDetValue
Definition: Model.h:239
static FittedEntriesReader * theFittedEntriesReader
Definition: Model.h:294
static std::string changeName(const std::string &oldName, const std::string &subsstr1, const std::string &subsstr2)
Definition: ALIUtils.cc:573
static void recoverParamFittedSigma(const ALIstring &opto_name, const ALIstring &entry_name, const ALIuint position)
Definition: Model.cc:1300
static EntryMgr * getInstance()
Definition: EntryMgr.cc:17
static Measurement * getMeasurementByName(const ALIstring &name, ALIbool exists=true)
Definition: Model.cc:655
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
static void CMSLinkRecoverParamFittedValueDisplacement(ALIint cmslink)
Definition: Model.cc:1121
static std::vector< ALIdouble > theParamFittedSigmaVector
Definition: Model.h:288
#define begin
Definition: vmac.h:30
const ALIstring & type() const
Definition: Measurement.h:86
static int position[264][3]
Definition: ReadPGInfo.cc:509
std::string ALIstring
Definition: CocoaGlobals.h:9
static cocoaStatus theCocoaStatus
Definition: Model.h:286
static void saveParamFittedCorrelation(const ALIstring &opto_name1, const ALIstring &entry_name1, const ALIstring &opto_name2, const ALIstring &entry_name2)
Definition: Model.cc:1264
void constructFromOptAligInfo(const OpticalAlignInfo &oaInfo)
static void reorderOptODictionary(const ALIstring &ssearch, std::vector< std::vector< ALIstring > > &OptODictionary2)
********** private METHODS
Definition: Model.cc:513
ALIbool readEntryFromReportOut(const std::vector< ALIstring > &wl)
Definition: EntryMgr.cc:33
static ALIbool readMeasurementsFromFile(ALIstring only1Date=ALIstring(""), ALIstring only1Time=ALIstring(""))
Definition: Model.cc:1338
const ALIstring & name() const
Definition: Measurement.h:90
static void CMSLinkDeleteOptOs()
Definition: Model.cc:904
const ALIstring & name() const
Definition: OpticalObject.h:60
void constructFromOA(OpticalAlignMeasurementInfo &measInfo)
Definition: Measurement.cc:96
virtual void correctValueAndSigma()
Definition: Measurement.h:67
static std::vector< std::vector< ALIstring > > theOptODictionary
parameters
Definition: Model.h:197
static int getInt(const ALIstring &str)
Convert a string to an integer, checking that it is really an integer.
Definition: ALIUtils.cc:417
void addParameter(const ALIstring &name, const ALIstring &valstr)
Definition: ParameterMgr.cc:69
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
void CMSLinkFit(ALIint cmslink)
*************** FOR CMS LINK SYSTEM (to fit it part by part)
Definition: Model.cc:831
static void CMSLinkRecoverParamFittedSigma(ALIint cmslink)
Definition: Model.cc:1060
EntryData * findEntryByLongName(const ALIstring &optoName, const ALIstring &entryName="")
Definition: EntryMgr.cc:83
static ALIstring only1Date
Definition: Measurement.h:268
static void CMSLinkSaveParamFittedSigma(ALIint cmslink)
Definition: Model.cc:968
void construct()
Definition: Measurement.cc:63
ALIdouble valueDisplacement() const
Definition: EntryData.h:32
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
static void setCurrentDate(const std::vector< ALIstring > &wl)
set the date of the current measurement
Definition: Measurement.cc:632
unsigned int ALIuint
Definition: CocoaGlobals.h:17