CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CocoaAnalyzer.cc
Go to the documentation of this file.
4 #include <DD4hep/DD4hepUnits.h>
14 
28 
29 class CocoaAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
30 public:
31  explicit CocoaAnalyzer(edm::ParameterSet const& p);
32  explicit CocoaAnalyzer(int i) {}
33  ~CocoaAnalyzer() override {}
34 
35  void beginJob() override;
36  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
37 
38 private:
39  void readXMLFile(const edm::EventSetup& evts);
40 
41  std::vector<OpticalAlignInfo> readCalibrationDB(const edm::EventSetup& evts);
42  void correctAllOpticalAlignments(std::vector<OpticalAlignInfo>& allDBOpticalAlignments);
43  void correctOpticalAlignmentParameter(OpticalAlignParam& myXMLParam, const OpticalAlignParam& myDBParam);
44 
45  void runCocoa();
46 
47 private:
53 };
54 
56  theCocoaDaqRootFileName_ = pset.getParameter<std::string>("cocoaDaqRootFile");
57  int maxEvents = pset.getParameter<int32_t>("maxEvents");
59  GlobalOptionMgr::getInstance()->setGlobalOption("maxEvents", maxEvents);
60  GlobalOptionMgr::getInstance()->setGlobalOption("writeDBAlign", 1);
61  GlobalOptionMgr::getInstance()->setGlobalOption("writeDBOptAlign", 1);
62  usesResource("CocoaAnalyzer");
63 }
64 
66 
67 void CocoaAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& evts) {
69 
70  // Get ideal geometry description + measurements for simulation.
71  readXMLFile(evts);
72 
73  // Correct ideal geometry with data from DB.
74  std::vector<OpticalAlignInfo> oaListCalib = readCalibrationDB(evts);
75  correctAllOpticalAlignments(oaListCalib);
76 
77  // Run the least-squared fit and store results in DB.
78  runCocoa();
79 }
80 
81 /*
82  * This is used to create the ideal geometry description from the XMLs.
83  * Also get measurements from XMLs for simulation.
84  * Resulting optical alignment info is stored in oaList_ and measList_.
85  */
88  const cms::DDDetector* mySystem = myCompactView->detector();
89 
90  if (mySystem) {
91  // Always store world volume first.
92  const dd4hep::Volume& worldVolume = mySystem->worldVolume();
93 
94  if (ALIUtils::debug >= 3) {
95  edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML: world object = " << worldVolume.name();
96  }
97 
98  OpticalAlignInfo worldInfo;
99  worldInfo.ID_ = 0;
100  worldInfo.name_ = worldVolume.name();
101  worldInfo.type_ = "system";
102  worldInfo.parentName_ = "";
103  worldInfo.x_.value_ = 0.;
104  worldInfo.x_.error_ = 0.;
105  worldInfo.x_.quality_ = 0;
106  worldInfo.y_.value_ = 0.;
107  worldInfo.y_.error_ = 0.;
108  worldInfo.y_.quality_ = 0;
109  worldInfo.z_.value_ = 0.;
110  worldInfo.z_.error_ = 0.;
111  worldInfo.z_.quality_ = 0;
112  worldInfo.angx_.value_ = 0.;
113  worldInfo.angx_.error_ = 0.;
114  worldInfo.angx_.quality_ = 0;
115  worldInfo.angy_.value_ = 0.;
116  worldInfo.angy_.error_ = 0.;
117  worldInfo.angy_.quality_ = 0;
118  worldInfo.angz_.value_ = 0.;
119  worldInfo.angz_.error_ = 0.;
120  worldInfo.angz_.quality_ = 0;
121  oaList_.opticalAlignments_.emplace_back(worldInfo);
122 
123  // This gathers all the 'SpecPar' sections from the loaded XMLs.
124  // NB: Definition of a SpecPar section:
125  // It is a block in the XML file(s), containing paths to specific volumes,
126  // and ALLOWING THE ASSOCIATION OF SPECIFIC PARAMETERS AND VALUES TO THESE VOLUMES.
127  const cms::DDSpecParRegistry& allSpecParSections = myCompactView->specpars();
128 
129  // CREATION OF A COCOA FILTERED VIEW
130  // Creation of the dd4hep-based filtered view.
131  // NB: not filtered yet!
132  cms::DDFilteredView myFilteredView(mySystem, worldVolume);
133  // Declare a container which will gather all the filtered SpecPar sections.
134  cms::DDSpecParRefs cocoaParameterSpecParSections;
135  // Define a COCOA filter
136  const std::string cocoaParameterAttribute = "COCOA";
137  const std::string cocoaParameterValue = "COCOA";
138  // All the COCOA SpecPar sections are filtered from allSpecParSections,
139  // and assigned to cocoaParameterSpecParSections.
140  allSpecParSections.filter(cocoaParameterSpecParSections, cocoaParameterAttribute, cocoaParameterValue);
141  // This finally allows to filter the filtered view, with the COCOA filter.
142  // This means that we now have, in myFilteredView, all volumes whose paths were selected:
143  // ie all volumes with "COCOA" parameter and value in a SpecPar section from a loaded XML.
144  myFilteredView.mergedSpecifics(cocoaParameterSpecParSections);
145 
146  // Loop on parts
147  int nObjects = 0;
148  bool doCOCOA = myFilteredView.firstChild();
149 
150  // Loop on all COCOA volumes from filtered view
151  while (doCOCOA) {
152  ++nObjects;
153 
154  OpticalAlignInfo oaInfo;
155  OpticalAlignParam oaParam;
157 
158  // Current volume
159  const dd4hep::PlacedVolume& myPlacedVolume = myFilteredView.volume();
160  const std::string& name = myPlacedVolume.name();
161  const std::string& nodePath = myFilteredView.path();
162  oaInfo.name_ = nodePath;
163 
164  // Parent name
165  oaInfo.parentName_ = nodePath.substr(0, nodePath.rfind('/', nodePath.length()));
166 
167  if (ALIUtils::debug >= 4) {
168  edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML reading object " << name;
169  edm::LogInfo("Alignment") << " @@ Name built= " << oaInfo.name_ << " short_name= " << name
170  << " parent= " << oaInfo.parentName_;
171  }
172 
173  // TRANSLATIONS
174 
175  // A) GET TRANSLATIONS FROM DDETECTOR.
176  // Directly get translation from parent to child volume
177  const dd4hep::Direction& transl = myPlacedVolume.position();
178 
179  if (ALIUtils::debug >= 4) {
180  edm::LogInfo("Alignment") << "Local translation in dd4hep units = " << transl;
181  }
182 
183  // B) READ INFO FROM XMLS
184  // X
185  oaInfo.x_.name_ = "X";
186  oaInfo.x_.dim_type_ = "centre";
187  oaInfo.x_.value_ = transl.x() / dd4hep::m; // COCOA units are m
188  oaInfo.x_.error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
189  nodePath,
190  "centre_X_sigma",
191  0) /
192  dd4hep::m; // COCOA units are m
193  oaInfo.x_.quality_ = static_cast<int>(
194  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_X_quality", 0));
195  // Y
196  oaInfo.y_.name_ = "Y";
197  oaInfo.y_.dim_type_ = "centre";
198  oaInfo.y_.value_ = transl.y() / dd4hep::m; // COCOA units are m
199  oaInfo.y_.error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
200  nodePath,
201  "centre_Y_sigma",
202  0) /
203  dd4hep::m; // COCOA units are m
204  oaInfo.y_.quality_ = static_cast<int>(
205  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_Y_quality", 0));
206  // Z
207  oaInfo.z_.name_ = "Z";
208  oaInfo.z_.dim_type_ = "centre";
209  oaInfo.z_.value_ = transl.z() / dd4hep::m; // COCOA units are m
210  oaInfo.z_.error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
211  nodePath,
212  "centre_Z_sigma",
213  0) /
214  dd4hep::m; // COCOA units are m
215  oaInfo.z_.quality_ = static_cast<int>(
216  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_Z_quality", 0));
217 
218  // ROTATIONS
219 
220  // A) GET ROTATIONS FROM DDETECTOR.
221 
222  // Unlike in the initial code, here we manage to directly get the rotation matrix placement
223  // of the child in parent, EXPRESSED IN THE PARENT FRAME OF REFERENCE.
224  // Hence the (ugly) initial block of code is replaced by just 2 lines.
225  // PlacedVolume::matrix() returns the rotation matrix IN THE PARENT FRAME OF REFERENCE.
226  // NB: Not using DDFilteredView::rotation(),
227  // because it returns the rotation matrix IN THE WORLD FRAME OF REFERENCE.
228  const TGeoHMatrix parentToChild = myPlacedVolume.matrix();
229  // COCOA convention is FROM CHILD TO PARENT
230  const TGeoHMatrix& childToParent = parentToChild.Inverse();
231 
232  // Convert it to CLHEP::Matrix
233  // Below is not my code, below block is untouched (apart from bug fix).
234  // I would just directly use childToParent...
235  const Double_t* rot = childToParent.GetRotationMatrix();
236  const double xx = rot[0];
237  const double xy = rot[1];
238  const double xz = rot[2];
239  const double yx = rot[3];
240  const double yy = rot[4];
241  const double yz = rot[5];
242  const double zx = rot[6];
243  const double zy = rot[7];
244  const double zz = rot[8];
245  if (ALIUtils::debug >= 4) {
246  edm::LogInfo("Alignment") << "Local rotation = ";
247  edm::LogInfo("Alignment") << xx << " " << xy << " " << xz;
248  edm::LogInfo("Alignment") << yx << " " << yy << " " << yz;
249  edm::LogInfo("Alignment") << zx << " " << zy << " " << zz;
250  }
251  const CLHEP::Hep3Vector colX(xx, yx, zx);
252  const CLHEP::Hep3Vector colY(xy, yy, zy);
253  const CLHEP::Hep3Vector colZ(xz, yz, zz);
254  const CLHEP::HepRotation rotclhep(colX, colY, colZ);
255  const std::vector<double>& angles = ALIUtils::getRotationAnglesFromMatrix(rotclhep, 0., 0., 0.);
256 
257  // B) READ INFO FROM XMLS
258  // X
259  oaInfo.angx_.name_ = "X";
260  oaInfo.angx_.dim_type_ = "angles";
261  oaInfo.angx_.value_ =
262  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_value", 0);
263  oaInfo.angx_.error_ =
264  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_sigma", 0);
265  oaInfo.angx_.quality_ = static_cast<int>(
266  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_quality", 0));
267  // Y
268  oaInfo.angy_.name_ = "Y";
269  oaInfo.angy_.dim_type_ = "angles";
270  oaInfo.angy_.value_ =
271  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_value", 0);
272  oaInfo.angy_.error_ =
273  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_sigma", 0);
274  oaInfo.angy_.quality_ = static_cast<int>(
275  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_quality", 0));
276  // Z
277  oaInfo.angz_.name_ = "Z";
278  oaInfo.angz_.dim_type_ = "angles";
279  oaInfo.angz_.value_ =
280  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_value", 0);
281  oaInfo.angz_.error_ =
282  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_sigma", 0);
283  oaInfo.angz_.quality_ = static_cast<int>(
284  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_quality", 0));
285 
286  oaInfo.type_ =
287  cms::getParameterValueFromSpecParSections<std::string>(allSpecParSections, nodePath, "cocoa_type", 0);
288 
289  oaInfo.ID_ = static_cast<int>(
290  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "cmssw_ID", 0));
291 
292  if (ALIUtils::debug >= 4) {
293  edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML OBJECT " << oaInfo.name_ << " pos/angles read ";
294  }
295 
296  // Check that rotations match with values from XMLs.
297  // Same, that ugly code is not mine ;p
298  if (fabs(oaInfo.angx_.value_ - angles[0]) > 1.E-9 || fabs(oaInfo.angy_.value_ - angles[1]) > 1.E-9 ||
299  fabs(oaInfo.angz_.value_ - angles[2]) > 1.E-9) {
300  edm::LogError("Alignment") << " WRONG ANGLE IN OBJECT " << oaInfo.name_ << oaInfo.angx_.value_ << " =? "
301  << angles[0] << oaInfo.angy_.value_ << " =? " << angles[1] << oaInfo.angz_.value_
302  << " =? " << angles[2];
303  }
304 
305  // EXTRA PARAM ENTRIES (FROM XMLS)
306  // Here initial code to define the containers was fully removed, this is much more compact.
307  const std::vector<std::string>& names =
308  cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "extra_entry");
309  const std::vector<std::string>& dims =
310  cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "dimType");
311  const std::vector<double>& values =
312  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "value");
313  const std::vector<double>& errors =
314  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "sigma");
315  const std::vector<double>& quality =
316  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "quality");
317 
318  if (ALIUtils::debug >= 4) {
319  edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML: Fill extra entries with read parameters ";
320  }
321 
322  if (names.size() == dims.size() && dims.size() == values.size() && values.size() == errors.size() &&
323  errors.size() == quality.size()) {
324  for (size_t i = 0; i < names.size(); ++i) {
325  double dimFactor = 1.;
326  const std::string& type = dims[i];
327  if (type == "centre" || type == "length") {
328  dimFactor =
329  1. / dd4hep::m; // was converted to dd4hep unit with getParameterValueFromSpecPar, COCOA unit is m
330  } else if (type == "angles" || type == "angle" || type == "nodim") {
331  dimFactor = 1.;
332  }
333  oaParam.value_ = values[i] * dimFactor;
334  oaParam.error_ = errors[i] * dimFactor;
335  oaParam.quality_ = static_cast<int>(quality[i]);
336  oaParam.name_ = names[i];
337  oaParam.dim_type_ = dims[i];
338  oaInfo.extraEntries_.emplace_back(oaParam);
339  oaParam.clear();
340  }
341 
342  oaList_.opticalAlignments_.emplace_back(oaInfo);
343  } else {
344  edm::LogInfo("Alignment") << "WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do"
345  << " not match! Did not add " << nObjects << " item to OpticalAlignments.";
346  }
347 
348  // MEASUREMENTS (FROM XMLS)
349  const std::vector<std::string>& measNames =
350  cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "meas_name");
351  const std::vector<std::string>& measTypes =
352  cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "meas_type");
353 
354  std::map<std::string, std::vector<std::string>> measObjectNames;
355  std::map<std::string, std::vector<std::string>> measParamNames;
356  std::map<std::string, std::vector<double>> measParamValues;
357  std::map<std::string, std::vector<double>> measParamSigmas;
358  std::map<std::string, std::vector<double>> measIsSimulatedValue;
359  for (const auto& name : measNames) {
360  measObjectNames[name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
361  allSpecParSections, nodePath, "meas_object_name_" + name);
362  measParamNames[name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
363  allSpecParSections, nodePath, "meas_value_name_" + name);
364  measParamValues[name] =
365  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "meas_value_" + name);
366  measParamSigmas[name] =
367  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "meas_sigma_" + name);
368  measIsSimulatedValue[name] = cms::getAllParameterValuesFromSpecParSections<double>(
369  allSpecParSections, nodePath, "meas_is_simulated_value_" + name);
370  }
371 
372  if (ALIUtils::debug >= 4) {
373  edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML: Fill measurements with read parameters ";
374  }
375 
376  if (measNames.size() == measTypes.size()) {
377  for (size_t i = 0; i < measNames.size(); ++i) {
378  oaMeas.ID_ = i;
379  oaMeas.name_ = measNames[i];
380  oaMeas.type_ = measTypes[i];
381  oaMeas.measObjectNames_ = measObjectNames[oaMeas.name_];
382  if (measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size()) {
383  for (size_t i2 = 0; i2 < measParamNames[oaMeas.name_].size(); i2++) {
384  oaParam.name_ = measParamNames[oaMeas.name_][i2];
385  oaParam.value_ = measParamValues[oaMeas.name_][i2];
386  oaParam.error_ = measParamSigmas[oaMeas.name_][i2];
387  oaParam.quality_ = 2;
388  if (oaMeas.type_ == "SENSOR2D" || oaMeas.type_ == "COPS" || oaMeas.type_ == "DISTANCEMETER" ||
389  oaMeas.type_ == "DISTANCEMETER!DIM" || oaMeas.type_ == "DISTANCEMETER3DIM") {
390  oaParam.dim_type_ = "length";
391  } else if (oaMeas.type_ == "TILTMETER") {
392  oaParam.dim_type_ = "angle";
393  } else {
394  edm::LogError("Alignment") << "CocoaAnalyzer::readXMLFile. Invalid measurement type: " << oaMeas.type_;
395  }
396 
397  oaMeas.values_.emplace_back(oaParam);
398  oaMeas.isSimulatedValue_.emplace_back(measIsSimulatedValue[oaMeas.name_][i2]);
399  if (ALIUtils::debug >= 5) {
400  edm::LogInfo("Alignment") << oaMeas.name_ << " copying issimu "
401  << oaMeas.isSimulatedValue_[oaMeas.isSimulatedValue_.size() - 1] << " = "
402  << measIsSimulatedValue[oaMeas.name_][i2];
403  }
404  oaParam.clear();
405  }
406  } else {
407  if (ALIUtils::debug >= 2) {
408  edm::LogWarning("Alignment") << "WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do"
409  << " not match! for measurement " << oaMeas.name_
410  << " !Did not fill parameters for this measurement ";
411  }
412  }
413  measList_.oaMeasurements_.emplace_back(oaMeas);
414  if (ALIUtils::debug >= 5) {
415  edm::LogInfo("Alignment") << "CocoaAnalyser: MEASUREMENT " << oaMeas.name_ << " extra entries read "
416  << oaMeas;
417  }
418  oaMeas.clear();
419  }
420 
421  } else {
422  if (ALIUtils::debug >= 2) {
423  edm::LogWarning("Alignment") << "WARNING FOR NOW: sizes of measurements (names, types do"
424  << " not match! Did not add " << nObjects << " item to XXXMeasurements";
425  }
426  }
427 
428  oaInfo.clear();
429  doCOCOA = myFilteredView.firstChild();
430  } // while (doCOCOA)
431 
432  if (ALIUtils::debug >= 3) {
433  edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML: Finished building " << nObjects + 1
434  << " OpticalAlignInfo objects"
435  << " and " << measList_.oaMeasurements_.size()
436  << " OpticalAlignMeasurementInfo objects ";
437  }
438  if (ALIUtils::debug >= 5) {
439  edm::LogInfo("Alignment") << " @@@@@@ OpticalAlignments " << oaList_;
440  edm::LogInfo("Alignment") << " @@@@@@ OpticalMeasurements " << measList_;
441  }
442  }
443 }
444 
445 /*
446  * This is used to get the OpticalAlignInfo from DB,
447  * which can be used to correct the OpticalAlignInfo from IdealGeometry.
448  */
449 std::vector<OpticalAlignInfo> CocoaAnalyzer::readCalibrationDB(const edm::EventSetup& evts) {
450  if (ALIUtils::debug >= 3) {
451  edm::LogInfo("Alignment") << "$$$ CocoaAnalyzer::readCalibrationDB: ";
452  }
453 
454  using namespace edm::eventsetup;
455  const OpticalAlignments* pObjs = &evts.getData(optAliToken);
456  const std::vector<OpticalAlignInfo>& infoFromDB = pObjs->opticalAlignments_;
457 
458  if (ALIUtils::debug >= 5) {
459  edm::LogInfo("Alignment") << "CocoaAnalyzer::readCalibrationDB: Number of OpticalAlignInfo READ "
460  << infoFromDB.size();
461  for (const auto& myInfoFromDB : infoFromDB) {
462  edm::LogInfo("Alignment") << "CocoaAnalyzer::readCalibrationDB: OpticalAlignInfo READ " << myInfoFromDB;
463  }
464  }
465 
466  return infoFromDB;
467 }
468 
469 /*
470  * Correct all OpticalAlignInfo from IdealGeometry with values from DB.
471  */
472 void CocoaAnalyzer::correctAllOpticalAlignments(std::vector<OpticalAlignInfo>& allDBOpticalAlignments) {
473  if (ALIUtils::debug >= 3) {
474  edm::LogInfo("Alignment") << "$$$ CocoaAnalyzer::correctAllOpticalAlignments: ";
475  }
476 
477  for (const auto& myDBInfo : allDBOpticalAlignments) {
478  if (ALIUtils::debug >= 5) {
479  edm::LogInfo("Alignment") << "CocoaAnalyzer::findOpticalAlignInfoXML: Looking for OAI " << myDBInfo.name_;
480  }
481 
482  std::vector<OpticalAlignInfo>& allXMLOpticalAlignments = oaList_.opticalAlignments_;
483  const auto& myXMLInfo = std::find_if(
484  allXMLOpticalAlignments.begin(), allXMLOpticalAlignments.end(), [&](const auto& myXMLInfoCandidate) {
485  return myXMLInfoCandidate.name_ == myDBInfo.name_;
486  });
487 
488  if (myXMLInfo != allXMLOpticalAlignments.end()) {
489  if (ALIUtils::debug >= 4) {
490  edm::LogInfo("Alignment") << "CocoaAnalyzer::findOpticalAlignInfoXML: OAI found " << myXMLInfo->name_;
491  edm::LogInfo("Alignment")
492  << "CocoaAnalyzer::correctAllOpticalAlignments: correcting data from XML with DB info.";
493  }
494  correctOpticalAlignmentParameter(myXMLInfo->x_, myDBInfo.x_);
495  correctOpticalAlignmentParameter(myXMLInfo->y_, myDBInfo.y_);
496  correctOpticalAlignmentParameter(myXMLInfo->z_, myDBInfo.z_);
497  correctOpticalAlignmentParameter(myXMLInfo->angx_, myDBInfo.angx_);
498  correctOpticalAlignmentParameter(myXMLInfo->angy_, myDBInfo.angy_);
499  correctOpticalAlignmentParameter(myXMLInfo->angz_, myDBInfo.angz_);
500 
501  // Also correct extra entries
502  const std::vector<OpticalAlignParam>& allDBExtraEntries = myDBInfo.extraEntries_;
503  std::vector<OpticalAlignParam>& allXMLExtraEntries = myXMLInfo->extraEntries_;
504  for (const auto& myDBExtraEntry : allDBExtraEntries) {
505  const auto& myXMLExtraEntry = std::find_if(
506  allXMLExtraEntries.begin(), allXMLExtraEntries.end(), [&](const auto& myXMLExtraEntryCandidate) {
507  return myXMLExtraEntryCandidate.name_ == myDBExtraEntry.name_;
508  });
509 
510  if (myXMLExtraEntry != allXMLExtraEntries.end()) {
511  correctOpticalAlignmentParameter(*myXMLExtraEntry, myDBExtraEntry);
512  } else {
513  if (myDBExtraEntry.name_ != "None") {
514  if (ALIUtils::debug >= 2) {
515  edm::LogError("Alignment")
516  << "CocoaAnalyzer::correctAllOpticalAlignments: extra entry read from DB is not present in XML "
517  << myDBExtraEntry << " in object " << myDBInfo;
518  }
519  }
520  }
521  }
522 
523  if (ALIUtils::debug >= 5) {
524  edm::LogInfo("Alignment") << "CocoaAnalyzer::correctAllOpticalAlignments: corrected OpticalAlingInfo "
525  << oaList_;
526  }
527  } else {
528  if (ALIUtils::debug >= 2) {
529  edm::LogError("Alignment") << "CocoaAnalyzer::correctAllOpticalAlignments: OpticalAlignInfo read from DB "
530  << myDBInfo << " is not present in XML.";
531  }
532  }
533  }
534 }
535 
536 /*
537  * Correct an OpticalAlignment parameter from IdealGeometry with the value from DB.
538  */
540  const OpticalAlignParam& myDBParam) {
541  if (myDBParam.value_ != -9.999E9) {
542  const std::string& type = myDBParam.dimType();
543  double dimFactor = 1.;
544 
545  if (type == "centre" || type == "length") {
546  dimFactor = 1. / dd4hep::m; // in DB values are stored in dd4hep unit
547  } else if (type == "angles" || type == "angle" || type == "nodim") {
548  dimFactor = 1.;
549  } else {
550  edm::LogError("Alignment") << "Incorrect OpticalAlignParam type = " << type;
551  }
552 
553  const double correctedValue = myDBParam.value_ * dimFactor;
554  if (ALIUtils::debug >= 4) {
555  edm::LogInfo("Alignment") << "CocoaAnalyzer::correctOpticalAlignmentParameter old value= " << myXMLParam.value_
556  << " new value= " << correctedValue;
557  }
558  myXMLParam.value_ = correctedValue;
559  }
560 }
561 
562 /*
563  * Collect all information, do the fitting, and store results in DB.
564  */
566  if (ALIUtils::debug >= 3) {
567  edm::LogInfo("Alignment") << "$$$ CocoaAnalyzer::runCocoa: ";
568  }
569 
570  // Geometry model built from XML file (corrected with values from DB)
573 
574  if (ALIUtils::debug >= 3) {
575  edm::LogInfo("Alignment") << "$$ CocoaAnalyzer::runCocoa: geometry built ";
576  }
577 
578  // Build measurements
580 
581  if (ALIUtils::debug >= 3) {
582  edm::LogInfo("Alignment") << "$$ CocoaAnalyzer::runCocoa: measurements built ";
583  }
584 
585  // Do fit and store results in DB
587  Fit::startFit();
588 
589  if (ALIUtils::debug >= 0)
590  edm::LogInfo("Alignment") << "............ program ended OK";
591  if (ALIUtils::report >= 1) {
593  fileout << "............ program ended OK";
594  }
595 }
596 
void BuildMeasurementsFromOA(OpticalAlignMeasurements &measList)
Definition: Model.cc:1569
~CocoaAnalyzer() override
CocoaAnalyzer(edm::ParameterSet const &p)
void beginJob() override
const edm::EventSetup & c
std::string parentName_
void readXMLFile(const edm::EventSetup &evts)
CocoaAnalyzer(int i)
OpticalAlignParam x_
std::string theCocoaDaqRootFileName_
void mergedSpecifics(DDSpecParRefs const &)
User specific data.
dd4hep::SpecParRefs DDSpecParRefs
Definition: DDCompactView.h:29
static std::vector< double > getRotationAnglesFromMatrix(const CLHEP::HepRotation &rmLocal, double origAngleX, double origAngleY, double origAngleZ)
Definition: ALIUtils.cc:549
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
uint32_t const *__restrict__ Quality * quality
std::vector< std::string > measObjectNames_
static ALIint debug
Definition: ALIUtils.h:34
static ALIstring & ReportFName()
the name of the report File
Definition: Model.h:99
static Fit & getInstance()
Definition: Fit.cc:69
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > ddcvToken
Log< level::Error, false > LogError
static GlobalOptionMgr * getInstance()
const PlacedVolume volume() const
The physical volume of the current node.
const std::string names[nVars_]
dd4hep::SpecParRegistry DDSpecParRegistry
Definition: DDCompactView.h:28
bool getData(T &iHolder) const
Definition: EventSetup.h:128
std::string dimType() const
OpticalAlignParam angx_
OpticalAlignParam y_
void correctAllOpticalAlignments(std::vector< OpticalAlignInfo > &allDBOpticalAlignments)
std::vector< OpticalAlignInfo > opticalAlignments_
dd4hep::PlacedVolume PlacedVolume
edm::ESGetToken< OpticalAlignments, OpticalAlignmentsRcd > optAliToken
static Model & getInstance()
-------— Gets the only instance of this class
Definition: Model.cc:80
std::vector< OpticalAlignMeasurementInfo > oaMeasurements_
bool firstChild()
set the current node to the first child
void BuildSystemDescriptionFromOA(OpticalAlignments &optAlig)
Definition: Model.cc:1528
dd4hep::Volume Volume
Definition: Model.h:54
OpticalAlignParam angz_
void setGlobalOption(const ALIstring go, const ALIdouble val, ALIFileIn &filein)
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Log< level::Info, false > LogInfo
Basic2DVector< T > xy() const
void setDefaultGlobalOptions()
Set the list of default global options.
void correctOpticalAlignmentParameter(OpticalAlignParam &myXMLParam, const OpticalAlignParam &myDBParam)
OpticalAlignParam z_
dd4hep::Volume worldVolume() const
Handle to the world volume containing everything.
Definition: DDDetector.cc:60
const std::string path() const
The full path to the current node.
static void startFit()
Definition: Fit.cc:103
std::vector< OpticalAlignParam > extraEntries_
static ALIint report
Definition: ALIUtils.h:33
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< OpticalAlignInfo > readCalibrationDB(const edm::EventSetup &evts)
OpticalAlignMeasurements measList_
OpticalAlignParam angy_
static void setDebugVerbosity(ALIint val)
Definition: ALIUtils.h:38
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:168
std::vector< OpticalAlignParam > values_
Log< level::Warning, false > LogWarning
std::string dim_type_
static ALIFileOut & getInstance(const ALIstring &filename)
Definition: ALIFileOut.cc:18
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
OpticalAlignments oaList_
unsigned int ID_