CMS 3D CMS Logo

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