CMS 3D CMS Logo

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