CMS 3D CMS Logo

CocoaAnalyzer.cc
Go to the documentation of this file.
6 
7 #include "../interface/CocoaAnalyzer.h"
15 
25 
26 //----------------------------------------------------------------------
28 {
29  theCocoaDaqRootFileName = pset.getParameter< std::string >("cocoaDaqRootFile");
30 
31  int maxEvents = pset.getParameter< int32_t >("maxEvents");
33  GlobalOptionMgr::getInstance()->setGlobalOption("maxEvents",maxEvents);
34  GlobalOptionMgr::getInstance()->setGlobalOption("writeDBAlign",1);
35  GlobalOptionMgr::getInstance()->setGlobalOption("writeDBOptAlign",1);
36  usesResource("CocoaAnalyzer");
37 }
38 
39 //----------------------------------------------------------------------
41 {
42 }
43 
44 
45 //------------------------------------------------------------------------
47 {
48  if(ALIUtils::debug >= 3) {
49  std::cout << std::endl << "$$$ CocoaAnalyzer::RunCocoa: " << std::endl;
50  }
51  //-ALIFileIn fin;
52  //- GlobalOptionMgr::getInstance()->setGlobalOption("debug_verbose",5, fin );
53 
54  //---------- Build the Model out of the system description text file
55  Model& model = Model::getInstance();
56 
58 
59  if(ALIUtils::debug >= 3) {
60  std::cout << "$$ CocoaAnalyzer::RunCocoa: geometry built " << std::endl;
61  }
62 
64 
65  if(ALIUtils::debug >= 3) {
66  std::cout << "$$ CocoaAnalyzer::RunCocoa: measurements built " << std::endl;
67  }
68 
70 
71  Fit::startFit();
72 
73  if(ALIUtils::debug >= 0) std::cout << "............ program ended OK" << std::endl;
74  if( ALIUtils::report >=1 ) {
76  fileout << "............ program ended OK" << std::endl;
77  }
78 
79 } // end of ::beginJob
80 
81 
82 //-----------------------------------------------------------------------
84 {
85 
86  // STEP ONE: Initial COCOA objects will be built from a DDL geometry
87  // description.
88 
90  evts.get<IdealGeometryRecord>().get(cpv);
91 
92  if(ALIUtils::debug >= 3) {
93  std::cout << std::endl << "$$$ CocoaAnalyzer::ReadXML: root object= " << cpv->root() << std::endl;
94  }
95 
96  //Build OpticalAlignInfo "system"
97  const DDLogicalPart lv = cpv->root();
98 
99  OpticalAlignInfo oaInfo;
100  oaInfo.ID_ = 0;
101  //--- substract file name to object name
102  oaInfo.name_ = lv.name().name();
103  oaInfo.parentName_ = "";
104  oaInfo.x_.quality_ = 0;
105  oaInfo.x_.value_ = 0.;
106  oaInfo.x_.error_ = 0.;
107  oaInfo.x_.quality_ = 0;
108  oaInfo.y_.value_ = 0.;
109  oaInfo.y_.error_ = 0.;
110  oaInfo.y_.quality_ = 0;
111  oaInfo.z_.value_ = 0.;
112  oaInfo.z_.error_ = 0.;
113  oaInfo.z_.quality_ = 0;
114  oaInfo.angx_.value_ = 0.;
115  oaInfo.angx_.error_ = 0.;
116  oaInfo.angx_.quality_ = 0;
117  oaInfo.angy_.value_ = 0.;
118  oaInfo.angy_.error_ = 0.;
119  oaInfo.angy_.quality_ = 0;
120  oaInfo.angz_.value_ = 0.;
121  oaInfo.angz_.error_ = 0.;
122  oaInfo.angz_.quality_ = 0;
123 
124  oaInfo.type_ = "system";
125 
126  oaList_.opticalAlignments_.push_back(oaInfo);
127  oaInfo.clear();
128 
129  // Example of traversing the whole optical alignment geometry.
130  // At each node we get specpars as variables and use them in
131  // constructing COCOA objects.
132  // It stores these objects in a private data member, opt
133  std::string attribute = "COCOA";
134  std::string value = "COCOA";
135 
136  // get all parts labelled with COCOA using a SpecPar
137  DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
138  DDFilteredView fv(*cpv, filter);
139  bool doCOCOA = fv.firstChild();
140 
141  // Loop on parts
142  int nObjects=0;
143  OpticalAlignParam oaParam;
145 
146  while ( doCOCOA ){
147  ++nObjects;
148  // oaInfo.ID_ = nObjects;
149  const DDsvalues_type params(fv.mergedSpecifics());
150 
151  const DDLogicalPart lv = fv.logicalPart();
152  if(ALIUtils::debug >= 4) {
153  std::cout << " CocoaAnalyzer::ReadXML reading object " << lv.name() << std::endl;
154  }
155 
156  std::vector<DDExpandedNode> history = fv.geoHistory();
157  oaInfo.parentName_ = "";
158  size_t ii;
159  for(ii = 0; ii < history.size()-1;ii++ ) {
160  if( ii != 0 ) oaInfo.parentName_ += "/";
161  std::string name = history[ii].logicalPart().name().name();
162  oaInfo.parentName_ += name;
163  // oaInfo.parentName_ = (fv.geoHistory()[fv.geoHistory().size()-2]).logicalPart().name();
164 // icol = oaInfo.parentName_.find(":");
165  // oaInfo.parentName_ = oaInfo.parentName_.substr(icol+1,oaInfo.parentName_.length());
166  }
167 
168  //--- build object name (= parent name + object name)
169  std::string name = history[ii].logicalPart().name().name();
170  //--- substract file name to object name
171  oaInfo.name_ = oaInfo.parentName_ + "/" + name;
172  if(ALIUtils::debug >= 5) {
173  std::cout << " @@ Name built= " << oaInfo.name_ << " short_name= " << name << " parent= " << oaInfo.parentName_ << std::endl;
174  }
175  //----- Read centre and angles
176  oaInfo.x_.quality_ = int (myFetchDbl(params, "centre_X_quality", 0));
177  DDTranslation transl = (fv.translation());
178  DDRotationMatrix rot = (fv.rotation());
179  DDExpandedNode parent = fv.geoHistory()[ fv.geoHistory().size()-2 ];
180  DDTranslation parentTransl = parent.absTranslation();
181  DDRotationMatrix parentRot = parent.absRotation();
182  transl = parentRot.Inverse()*(transl - parentTransl );
183  rot = parentRot.Inverse()*rot;
184  rot = rot.Inverse(); //DDL uses opposite convention than COCOA
185  /* if(ALIUtils::debug >= 4) {
186  ALIUtils::dumprm( rot, "local rotation ");
187  ALIUtils::dump3v( transl, "local translation");
188  } */
189 
190  oaInfo.x_.name_ = "X";
191  oaInfo.x_.dim_type_ = "centre";
192  oaInfo.x_.value_ = transl.x()*0.001; // CLHEP units are mm, COCOA are m
193  oaInfo.x_.error_ = myFetchDbl(params, "centre_X_sigma", 0)*0.001; // CLHEP units are mm, COCOA are m
194  oaInfo.x_.quality_ = int (myFetchDbl(params, "centre_X_quality", 0));
195 
196  oaInfo.y_.name_ = "Y";
197  oaInfo.y_.dim_type_ = "centre";
198  oaInfo.y_.value_ = transl.y()*0.001; // CLHEP units are mm, COCOA are m
199  oaInfo.y_.error_ = myFetchDbl(params, "centre_Y_sigma", 0)*0.001; // CLHEP units are mm, COCOA are m
200  oaInfo.y_.quality_ = int (myFetchDbl(params, "centre_Y_quality", 0));
201 
202  oaInfo.z_.name_ = "Z";
203  oaInfo.z_.dim_type_ = "centre";
204  oaInfo.z_.value_ = transl.z()*0.001; // CLHEP units are mm, COCOA are m
205  oaInfo.z_.error_ = myFetchDbl(params, "centre_Z_sigma", 0)*0.001; // CLHEP units are mm, COCOA are m
206  oaInfo.z_.quality_ = int (myFetchDbl(params, "centre_Z_quality", 0));
207 
208  //---- DDD convention is to use the inverse matrix, COCOA is the direct one!!!
209  //---- convert it to CLHEP::Matrix
210  double xx,xy,xz,yx,yy,yz,zx,zy,zz;
211  rot.GetComponents (xx, xy, xz,
212  yx, yy, yz,
213  zx, zy, zz);
214  CLHEP::Hep3Vector colX(xx,xy,xz);
215  CLHEP::Hep3Vector colY(yx,yy,yz);
216  CLHEP::Hep3Vector colZ(zx,zy,zz);
217  CLHEP::HepRotation rotclhep( colX, colY, colZ );
218  std::vector<double> angles = ALIUtils::getRotationAnglesFromMatrix( rotclhep,0., 0., 0. );
219 
220  oaInfo.angx_.name_ = "X";
221  oaInfo.angx_.dim_type_ = "angles";
222  //- oaInfo.angx_.value_ = angles[0];
223  oaInfo.angx_.value_ = myFetchDbl(params, "angles_X_value", 0);
224  oaInfo.angx_.error_ = myFetchDbl(params, "angles_X_sigma", 0);
225  oaInfo.angx_.quality_ = int (myFetchDbl(params, "angles_X_quality", 0));
226 
227  oaInfo.angy_.name_ = "Y";
228  oaInfo.angy_.dim_type_ = "angles";
229  //- oaInfo.angy_.value_ = angles[1];
230  oaInfo.angy_.value_ = myFetchDbl(params, "angles_Y_value", 0);
231  oaInfo.angy_.error_ = myFetchDbl(params, "angles_Y_sigma", 0);
232  oaInfo.angy_.quality_ = int (myFetchDbl(params, "angles_Y_quality", 0));
233 
234  oaInfo.angz_.name_ = "Z";
235  oaInfo.angz_.dim_type_ = "angles";
236  // oaInfo.angz_.value_ = angles[2];
237  oaInfo.angz_.value_ = myFetchDbl(params, "angles_Z_value", 0);
238  oaInfo.angz_.error_ = myFetchDbl(params, "angles_Z_sigma", 0);
239  oaInfo.angz_.quality_ = int (myFetchDbl(params, "angles_Z_quality", 0));
240 
241  oaInfo.type_ = myFetchString(params, "cocoa_type", 0);
242 
243  oaInfo.ID_ = int(myFetchDbl(params, "cmssw_ID", 0));
244 
245  if(ALIUtils::debug >= 4) {
246  std::cout << "CocoaAnalyzer::ReadXML OBJECT " << oaInfo.name_ << " pos/angles read " << std::endl;
247  }
248 
249  if( fabs( oaInfo.angx_.value_ - angles[0] ) > 1.E-9 ||
250  fabs( oaInfo.angy_.value_ - angles[1] ) > 1.E-9 ||
251  fabs( oaInfo.angz_.value_ - angles[2] ) > 1.E-9 ) {
252  std::cerr << " WRONG ANGLE IN OBJECT " << oaInfo.name_<<
253  oaInfo.angx_.value_ << " =? " << angles[0] <<
254  oaInfo.angy_.value_ << " =? " << angles[1] <<
255  oaInfo.angz_.value_ << " =? " << angles[2] << std::endl;
256  }
257 
258  //----- Read extra entries and measurements
259  const std::vector<const DDsvalues_type *> params2(fv.specifics());
260  std::vector<const DDsvalues_type *>::const_iterator spit = params2.begin();
261  std::vector<const DDsvalues_type *>::const_iterator endspit = params2.end();
262  //--- extra entries variables
263  std::vector<std::string> names, dims;
264  std::vector<double> values, errors, quality;
265  //--- measurements variables
266  std::vector<std::string> measNames;
267  std::vector<std::string> measTypes;
268  std::map<std::string, std::vector<std::string> > measObjectNames;
269  std::map<std::string, std::vector<std::string> > measParamNames;
270  std::map<std::string, std::vector<double> > measParamValues;
271  std::map<std::string, std::vector<double> > measParamSigmas;
272  std::map<std::string, std::vector<double> > measIsSimulatedValue;
273 
274  for ( ; spit != endspit; ++spit ) {
275  DDsvalues_type::const_iterator sit = (**spit).begin();
276  DDsvalues_type::const_iterator endsit = (**spit).end();
277  for ( ; sit != endsit; ++sit ) {
278  if (sit->second.name() == "extra_entry") {
279  names = sit->second.strings();
280  } else if (sit->second.name() == "dimType") {
281  dims = sit->second.strings();
282  } else if (sit->second.name() == "value") {
283  values = sit->second.doubles();
284  } else if (sit->second.name() == "sigma") {
285  errors = sit->second.doubles();
286  } else if (sit->second.name() == "quality") {
287  quality = sit->second.doubles();
288 
289  } else if (sit->second.name() == "meas_name") {
290  //- std::cout << " meas_name found " << std::endl;
291  measNames = sit->second.strings();
292  } else if (sit->second.name() == "meas_type") {
293  //- std::cout << " meas_type found " << std::endl;
294  measTypes = sit->second.strings();
295  }
296 
297  }
298  }
299 
300  //---- loop again to look for the measurement object names, that have the meas name in the SpecPar title
301  // <Parameter name="meas_object_name_SENSOR2D:OCMS/sens2" value="OCMS/laser1" eval="false" />
302  // <Parameter name="meas_object_name_SENSOR2D:OCMS/sens2" value="OCMS/sens2" eval="false" />
303 
304  std::vector<std::string>::iterator vsite;
305  for ( spit = params2.begin(); spit != params2.end(); ++spit ) {
306  //- std::cout << "loop vector DDsvalues " << std::endl;
307  DDsvalues_type::const_iterator sit = (**spit).begin();
308  DDsvalues_type::const_iterator endsit = (**spit).end();
309  for ( ; sit != endsit; ++sit ) {
310  for( vsite = measNames.begin(); vsite != measNames.end(); ++vsite ){
311  //- std::cout << "looping measObjectNames " << *vsite << std::endl;
312  if (sit->second.name() == "meas_object_name_"+(*vsite)) {
313  measObjectNames[*vsite] = sit->second.strings();
314  }else if (sit->second.name() == "meas_value_name_"+(*vsite)) {
315  measParamNames[*vsite] = sit->second.strings();
316  }else if (sit->second.name() == "meas_value_"+(*vsite)) {
317  measParamValues[*vsite] = sit->second.doubles();
318  }else if (sit->second.name() == "meas_sigma_"+(*vsite)) {
319  measParamSigmas[*vsite] = sit->second.doubles();
320  }else if (sit->second.name() == "meas_is_simulated_value_"+(*vsite)) {
321  measIsSimulatedValue[*vsite] = sit->second.doubles(); // this is not in OptAlignParam info
322  if(ALIUtils::debug >= 5) {
323  std::cout << *vsite << " setting issimu " << measIsSimulatedValue[*vsite][0] << std::endl;
324  }
325  }
326  if(ALIUtils::debug >= 5) {
327  std::cout << "CocoaAnalyser: looped measObjectNames " << "meas_object_name_"+(*vsite) << " n obj " << measObjectNames[*vsite].size() << std::endl;
328  }
329 
330  }
331 
332  }
333  }
334 
335  if(ALIUtils::debug >= 4) {
336  std::cout << " CocoaAnalyzer::ReadXML: Fill extra entries with read parameters " << std::endl;
337  }
338  //--- Fill extra entries with read parameters
339  if ( names.size() == dims.size() && dims.size() == values.size()
340  && values.size() == errors.size() && errors.size() == quality.size() ) {
341  for ( size_t ind = 0; ind < names.size(); ++ind ) {
342  double dimFactor = 1.;
343  std::string type = oaParam.dimType();
344  if( type == "centre" || type == "length" ) {
345  dimFactor = 0.001; // in XML it is in mm
346  }else if ( type == "angles" || type == "angle" || type == "nodim" ){
347  dimFactor = 1.;
348  }
349  oaParam.value_ = values[ind]*dimFactor;
350  oaParam.error_ = errors[ind]*dimFactor;
351  oaParam.quality_ = int (quality[ind]);
352  oaParam.name_ = names[ind];
353  oaParam.dim_type_ = dims[ind];
354  oaInfo.extraEntries_.push_back (oaParam);
355  oaParam.clear();
356  }
357 
358  //t std::cout << names.size() << " OBJECT " << oaInfo.name_ << " extra entries read " << oaInfo << std::endl;
359 
360  oaList_.opticalAlignments_.push_back(oaInfo);
361  } else {
362  std::cout << "WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do"
363  << " not match! Did not add " << nObjects << " item to OpticalAlignments."
364  << std::endl;
365  }
366 
367  if(ALIUtils::debug >= 4) {
368  std::cout << " CocoaAnalyzer::ReadXML: Fill measurements with read parameters " << std::endl;
369  }
370  //--- Fill measurements with read parameters
371  if ( measNames.size() == measTypes.size() ) {
372  for ( size_t ind = 0; ind < measNames.size(); ++ind ) {
373  oaMeas.ID_ = ind;
374  oaMeas.name_ = measNames[ind];
375  oaMeas.type_ = measTypes[ind];
376  oaMeas.measObjectNames_ = measObjectNames[oaMeas.name_];
377  if( measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size() ) {
378  for( size_t ind2 = 0; ind2 < measParamNames[oaMeas.name_].size(); ind2++ ){
379  oaParam.name_ = measParamNames[oaMeas.name_][ind2];
380  oaParam.value_ = measParamValues[oaMeas.name_][ind2];
381  oaParam.error_ = measParamSigmas[oaMeas.name_][ind2];
382  if( oaMeas.type_ == "SENSOR2D" || oaMeas.type_ == "COPS" || oaMeas.type_ == "DISTANCEMETER" || oaMeas.type_ == "DISTANCEMETER!DIM" || oaMeas.type_ == "DISTANCEMETER3DIM" ) {
383  oaParam.dim_type_ = "length";
384  } else if( oaMeas.type_ == "TILTMETER" ) {
385  oaParam.dim_type_ = "angle";
386  } else {
387  std::cerr << "CocoaAnalyzer::ReadXMLFile. Invalid measurement type: " << oaMeas.type_ << std::endl;
388  std::exception();
389  }
390 
391  oaMeas.values_.push_back( oaParam );
392  oaMeas.isSimulatedValue_.push_back( measIsSimulatedValue[oaMeas.name_][ind2] );
393  if(ALIUtils::debug >= 5) {
394  std::cout << oaMeas.name_ << " copying issimu " << oaMeas.isSimulatedValue_[oaMeas.isSimulatedValue_.size()-1] << " = " << measIsSimulatedValue[oaMeas.name_][ind2] << std::endl;
395  //- std::cout << ind2 << " adding meas value " << oaParam << std::endl;
396  }
397  oaParam.clear();
398  }
399  } else {
400  if(ALIUtils::debug >= 2) {
401  std::cout << "WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do"
402  << " not match! for measurement " << oaMeas.name_ << " !Did not fill parameters for this measurement " << std::endl;
403  }
404  }
405  measList_.oaMeasurements_.push_back (oaMeas);
406  if(ALIUtils::debug >= 5) {
407  std::cout << "CocoaAnalyser: MEASUREMENT " << oaMeas.name_ << " extra entries read " << oaMeas << std::endl;
408  }
409  oaMeas.clear();
410  }
411 
412  } else {
413  if(ALIUtils::debug >= 2) {
414  std::cout << "WARNING FOR NOW: sizes of measurements (names, types do"
415  << " not match! Did not add " << nObjects << " item to XXXMeasurements"
416  << std::endl;
417  }
418  }
419 
420 // std::cout << "sizes are values=" << values.size();
421 // std::cout << " sigma(errors)=" << errors.size();
422 // std::cout << " quality=" << quality.size();
423 // std::cout << " names=" << names.size();
424 // std::cout << " dimType=" << dims.size() << std::endl;
425  oaInfo.clear();
426  doCOCOA = fv.next(); // go to next part
427  } // while (doCOCOA)
428  if(ALIUtils::debug >= 3) {
429  std::cout << "CocoaAnalyzer::ReadXML: Finished building " << nObjects+1 << " OpticalAlignInfo objects" << " and " << measList_.oaMeasurements_.size() << " OpticalAlignMeasurementInfo objects " << std::endl;
430  }
431  if(ALIUtils::debug >= 5) {
432  std::cout << " @@@@@@ OpticalAlignments " << oaList_ << std::endl;
433  std::cout << " @@@@@@ OpticalMeasurements " << measList_ << std::endl;
434  }
435 
436 }
437 
438 //------------------------------------------------------------------------
439 std::vector<OpticalAlignInfo> CocoaAnalyzer::ReadCalibrationDB( const edm::EventSetup& evts )
440 {
441  if(ALIUtils::debug >= 3) {
442  std::cout<< std::endl <<"$$$ CocoaAnalyzer::ReadCalibrationDB: " << std::endl;
443  }
444 
445  using namespace edm::eventsetup;
447  evts.get<OpticalAlignmentsRcd>().get(pObjs);
448  const OpticalAlignments* dbObj = pObjs.product();
449 
450  if(ALIUtils::debug >= 5) {
451  std::vector<OpticalAlignInfo>::const_iterator it;
452  for( it=dbObj->opticalAlignments_.begin();it!=dbObj->opticalAlignments_.end(); ++it ){
453  std::cout<<"CocoaAnalyzer::ReadCalibrationDB: OpticalAlignInfo READ "<< *it << std::endl;
454  }
455  }
456 
457  if(ALIUtils::debug >= 4) {
458  std::cout<<"CocoaAnalyzer::ReadCalibrationDB: Number of OpticalAlignInfo READ "<< dbObj->opticalAlignments_.size() << std::endl;
459  }
460 
461  return dbObj->opticalAlignments_;
462 }
463 
464 
465 //------------------------------------------------------------------------
466 void CocoaAnalyzer::CorrectOptAlignments( std::vector<OpticalAlignInfo>& oaListCalib )
467 {
468  if(ALIUtils::debug >= 3) {
469  std::cout<< std::endl<< "$$$ CocoaAnalyzer::CorrectOptAlignments: " << std::endl;
470  }
471 
472  std::vector<OpticalAlignInfo>::const_iterator it;
473  for( it=oaListCalib.begin();it!=oaListCalib.end(); ++it ){
474  OpticalAlignInfo oaInfoDB = *it;
475  OpticalAlignInfo* oaInfoXML = FindOpticalAlignInfoXML( oaInfoDB );
476  std::cerr << "error " << (*it).name_ << std::endl;
477  if( oaInfoXML == 0 ) {
478  if(ALIUtils::debug >= 2) {
479  std::cerr << "@@@@@ WARNING CocoaAnalyzer::CorrectOptAlignments: OpticalAlignInfo read from DB is not present in XML "<< *it << std::endl;
480  }
481  } else {
482  //------ Correct info
483  if(ALIUtils::debug >= 5) {
484  std::cout << "CocoaAnalyzer::CorrectOptAlignments: correcting data from DB info " << std::endl;
485  }
486  CorrectOaParam( &oaInfoXML->x_, oaInfoDB.x_ );
487  CorrectOaParam( &oaInfoXML->y_, oaInfoDB.y_ );
488  CorrectOaParam( &oaInfoXML->z_, oaInfoDB.z_ );
489  CorrectOaParam( &oaInfoXML->angx_, oaInfoDB.angx_ );
490  CorrectOaParam( &oaInfoXML->angy_, oaInfoDB.angy_ );
491  CorrectOaParam( &oaInfoXML->angz_, oaInfoDB.angz_ );
492  std::vector<OpticalAlignParam>::iterator itoap1, itoap2;
493  std::vector<OpticalAlignParam> extraEntDB = oaInfoDB.extraEntries_;
494  std::vector<OpticalAlignParam>* extraEntXML = &(oaInfoXML->extraEntries_);
495  for( itoap1 = extraEntDB.begin(); itoap1 != extraEntDB.end(); ++itoap1 ){
496  bool pFound = false;
497  //----- Look for the extra parameter in XML oaInfo that has the same name
498  std::string oaName = (*itoap1).name_.substr( 1, (*itoap1).name_.size()-2 );
499  for( itoap2 = extraEntXML->begin(); itoap2 != extraEntXML->end(); ++itoap2 ){
500  if( oaName == (*itoap2).name_ ) {
501  CorrectOaParam( &(*itoap2), *itoap1 );
502  pFound = true;
503  break;
504  }
505  }
506  if( !pFound && oaName != "None" ) {
507  if(ALIUtils::debug >= 2) {
508  std::cerr << "@@@@@ WARNING CocoaAnalyzer::CorrectOptAlignments: extra entry read from DB is not present in XML "<< *itoap1 << " in object " << *it << std::endl;
509  }
510  }
511 
512  }
513  if(ALIUtils::debug >= 5) {
514  std::cout << "CocoaAnalyzer::CorrectOptAlignments: corrected OpticalAlingInfo " << oaList_ << std::endl;
515  }
516 
517  }
518  }
519 
520 }
521 
522 
523 //------------------------------------------------------------------------
525 {
526  OpticalAlignInfo* oaInfoXML = 0;
527  std::vector<OpticalAlignInfo>::iterator it;
528  for( it=oaList_.opticalAlignments_.begin();it!=oaList_.opticalAlignments_.end(); ++it ){
529  std::string oaName = oaInfo.name_.substr( 1, oaInfo.name_.size()-2 );
530 
531  if(ALIUtils::debug >= 5) {
532  std::cout << "CocoaAnalyzer::FindOpticalAlignInfoXML: looking for OAI " << (*it).name_ << " =? " << oaName << std::endl;
533  }
534  if( (*it).name_ == oaName ) {
535  oaInfoXML = &(*it);
536  if(ALIUtils::debug >= 4) {
537  std::cout << "CocoaAnalyzer::FindOpticalAlignInfoXML: OAI found " << oaInfoXML->name_ << std::endl;
538  }
539  break;
540  }
541  }
542 
543  return oaInfoXML;
544 }
545 
546 
547 //------------------------------------------------------------------------
549 {
550  if(ALIUtils::debug >= 4) {
551  std::cout << "CocoaAnalyzer::CorrectOaParam old value= " << oaParamXML->value_ << " new value= " << oaParamDB.value_ << std::endl;
552  }
553  if( oaParamDB.value_ == -9.999E9 ) return false;
554 
555  double dimFactor = 1.;
556  //loop for an Entry with equal type to entries to know which is the
557  std::string type = oaParamDB.dimType();
558  if( type == "centre" || type == "length" ) {
559  dimFactor = 0.01; // in DB it is in cm
560  }else if ( type == "angles" || type == "angle" || type == "nodim" ){
561  dimFactor = 1.;
562  }else {
563  std::cerr << "!!! COCOA programming error: inform responsible: incorrect OpticalAlignParam type = " << type << std::endl;
564  std::exception();
565  }
566 
567  oaParamXML->value_ = oaParamDB.value_*dimFactor;
568 
569  return true;
570 
571 }
572 
573 
574 //-#include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
575 //-#include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
576 
577 //-----------------------------------------------------------------------
578 void CocoaAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& evts)
579 {
581 
582  ReadXMLFile( evts );
583 
584  std::vector<OpticalAlignInfo> oaListCalib = ReadCalibrationDB( evts );
585 
586  CorrectOptAlignments( oaListCalib );
587 
589 
590  /*-
591  int nEvents = daqReader->GetNEvents();
592  for( int ii = 0; ii < nEvents; ii++) {
593  if( ! daqReader->ReadEvent( ii ) ) break;
594  }
595  */
596 
597  RunCocoa();
598 
599  // std::cout << "!!!! NOT DumpCocoaResults() " << std::endl;
600 
601  // CocoaDBMgr::getInstance()->DumpCocoaResults();
602 
603  return;
604 
605 
606  // using namespace edm::eventsetup;
607  // std::cout <<" I AM IN RUN NUMBER "<<evt.id().run() <<std::endl;
608  // std::cout <<" ---EVENT NUMBER "<<evt.id().event() <<std::endl;
609 
610  // just a quick dump of the private OpticalAlignments object
611  // std::cout << oaList_ << std::endl;
612 
613  // STEP 2:
614  // Get calibrated OpticalAlignments. In this case I'm using
615  // some sqlite database examples that are generated using
616  // testOptAlignWriter.cc
617  // from CondFormats/OptAlignObjects/test/
618 
619 // edm::ESHandle<OpticalAlignments> oaESHandle;
620 // context.get<OpticalAlignmentsRcd>().get(oaESHandle);
621 
622 // // This assumes they ALL come in together. This may not be
623 // // the "real" case. One could envision different objects coming
624 // // in and we would get by label each one (type).
625 
626 // std::cout << "========== eventSetup data changes with IOV =========" << std::endl;
627 // std::cout << *oaESHandle << std::endl;
628 // //============== COCOA WORK!
629 // // calibrated values should be used to "correct" the ones read in during beginJob
630 // //==============
631 
632 // //
633 // // to see how to iterate over the OpticalAlignments, please
634 // // refer to the << operator of OpticalAlignments, OpticalAlignInfo
635 // // and OpticalAlignParam.
636 // // const OpticalAlignments* myoa=oa.product();
637 
638 // // STEP 3:
639 // // This retrieves the Measurements
640 // // for each event, a new set of measurements is available.
641 // edm::Handle<OpticalAlignMeasurements> measHandle;
642 // evt.getByLabel("OptAlignGeneratedSource", measHandle);
643 
644 
645 // std::cout << "========== event data product changes with every event =========" << std::endl;
646 // std::cout << *measHandle << std::endl;
647 
648  //============== COCOA WORK!
649  // Each set of optical alignment measurements can be used
650  // in whatever type of analysis COCOA does.
651  //==============
652 
653 } //end of ::analyze()
654 
655 // STEP 4: one could use ::endJob() to write out the OpticalAlignments
656 // generated by the analysis. Example code of writing is in
657 // CondFormats/Alignment/test/testOptAlignWriter.cc
658 
659 
660 //-----------------------------------------------------------------------
662  const std::string& spName,
663  const size_t& vecInd ) {
664  DDValue val(spName, 0.0);
665  if (DDfetch(&dvst,val)) {
666  if ( val.doubles().size() > vecInd ) {
667  // std::cout << "about to return: " << val.doubles()[vecInd] << std::endl;
668  return val.doubles()[vecInd];
669  } else {
670  std::cout << "WARNING: OUT OF BOUNDS RETURNING 0 for index " << vecInd << " of SpecPar " << spName << std::endl;
671  }
672  }
673  return 0.0;
674 }
675 
676 //-----------------------------------------------------------------------
678  const std::string& spName,
679  const size_t& vecInd ) {
680  DDValue val(spName, 0.0);
681  if (DDfetch(&dvst,val)) {
682  if ( val.strings().size() > vecInd ) {
683  // std::cout << "about to return: " << val.doubles()[vecInd] << std::endl;
684  return val.strings()[vecInd];
685  } else {
686  std::cout << "WARNING: OUT OF BOUNDS RETURNING 0 for index " << vecInd << " of SpecPar " << spName << std::endl;
687  }
688  }
689  return "";
690 }
691 
std::string myFetchString(const DDsvalues_type &dvst, const std::string &spName, const size_t &vecInd)
type
Definition: HCALResponse.h:21
void BuildMeasurementsFromOA(OpticalAlignMeasurements &measList)
Definition: Model.cc:1626
T getParameter(std::string const &) const
std::string theCocoaDaqRootFileName
Definition: CocoaAnalyzer.h:75
CocoaAnalyzer(edm::ParameterSet const &p)
virtual void beginJob() override
const DDTranslation & absTranslation() const
absolute translation of this node
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:137
std::string parentName_
const N & name() const
Definition: DDBase.h:78
static const HistoName names[]
OpticalAlignParam x_
const DDRotationMatrix & absRotation() const
absolute rotation of this node
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
void ReadXMLFile(const edm::EventSetup &evts)
std::vector< std::string > measObjectNames_
static ALIint debug
Definition: ALIUtils.h:36
static ALIstring & ReportFName()
the name of the report File
Definition: Model.h:96
represents one node in the DDExpandedView
static Fit & getInstance()
Definition: Fit.cc:71
void CorrectOptAlignments(std::vector< OpticalAlignInfo > &oaListCalib)
static GlobalOptionMgr * getInstance()
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:80
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
std::string dimType() const
OpticalAlignParam angx_
OpticalAlignParam y_
bool next()
set current node to the next node in the filtered tree
std::vector< OpticalAlignInfo > opticalAlignments_
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:20
static Model & getInstance()
-------— Gets the only instance of this class
Definition: Model.cc:81
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
Definition: value.py:1
std::vector< OpticalAlignMeasurementInfo > oaMeasurements_
void BuildSystemDescriptionFromOA(OpticalAlignments &optAlig)
Definition: Model.cc:1580
Definition: Model.h:38
OpticalAlignParam angz_
ii
Definition: cuy.py:588
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:61
void setGlobalOption(const ALIstring go, const ALIdouble val, ALIFileIn &filein)
virtual void analyze(const edm::Event &e, const edm::EventSetup &c) override
double myFetchDbl(const DDsvalues_type &dvst, const std::string &spName, const size_t &vecInd)
void setDefaultGlobalOptions()
Set the list of default global options.
OpticalAlignParam z_
static void startFit()
Definition: Fit.cc:105
const T & get() const
Definition: EventSetup.h:56
std::vector< OpticalAlignParam > extraEntries_
static ALIint report
Definition: ALIUtils.h:35
DDsvalues_type mergedSpecifics() const
OpticalAlignMeasurements measList_
Definition: CocoaAnalyzer.h:74
OpticalAlignParam angy_
static void setDebugVerbosity(ALIint val)
Definition: ALIUtils.h:42
bool firstChild()
set the current node to the first child ...
std::vector< OpticalAlignParam > values_
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
OpticalAlignInfo * FindOpticalAlignInfoXML(const OpticalAlignInfo &oaInfo)
static std::vector< double > getRotationAnglesFromMatrix(CLHEP::HepRotation &rmLocal, double origAngleX, double origAngleY, double origAngleZ)
Definition: ALIUtils.cc:591
const DDTranslation & translation() const
The absolute translation of the current node.
std::vector< const DDsvalues_type * > specifics() const
std::string dim_type_
static ALIFileOut & getInstance(const ALIstring &filename)
Definition: ALIFileOut.cc:19
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
T const * product() const
Definition: ESHandle.h:86
std::vector< OpticalAlignInfo > ReadCalibrationDB(const edm::EventSetup &evts)
OpticalAlignments oaList_
Definition: CocoaAnalyzer.h:73
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
bool CorrectOaParam(OpticalAlignParam *oaParamXML, const OpticalAlignParam &oaParamDB)
unsigned int ID_