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