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