CMS 3D CMS Logo

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