CMS 3D CMS Logo

AlignmentProducerBase.cc
Go to the documentation of this file.
2 
14 
16 
21 
25 
32 
33 //------------------------------------------------------------------------------
35  : doTracker_{config.getUntrackedParameter<bool>("doTracker")},
36  doMuon_{config.getUntrackedParameter<bool>("doMuon")},
37  useExtras_{config.getUntrackedParameter<bool>("useExtras")},
38  tjTkAssociationMapTag_{config.getParameter<edm::InputTag>("tjTkAssociationMapTag")},
39  beamSpotTag_{config.getParameter<edm::InputTag>("beamSpotTag")},
40  tkLasBeamTag_{config.getParameter<edm::InputTag>("tkLasBeamTag")},
41  clusterValueMapTag_{config.getParameter<edm::InputTag>("hitPrescaleMapTag")},
42  uniqueRunRanges_{align::makeUniqueRunRanges(config.getParameter<edm::VParameterSet>("RunRangeSelection"),
44  config_{config},
45  stNFixAlignables_{config.getParameter<int>("nFixAlignables")},
46  stRandomShift_{config.getParameter<double>("randomShift")},
47  stRandomRotation_{config.getParameter<double>("randomRotation")},
48  applyDbAlignment_{config.getUntrackedParameter<bool>("applyDbAlignment")},
49  checkDbAlignmentValidity_{config.getUntrackedParameter<bool>("checkDbAlignmentValidity")},
50  doMisalignmentScenario_{config.getParameter<bool>("doMisalignmentScenario")},
51  saveToDB_{config.getParameter<bool>("saveToDB")},
52  saveApeToDB_{config.getParameter<bool>("saveApeToDB")},
53  saveDeformationsToDB_{config.getParameter<bool>("saveDeformationsToDB")},
54  useSurvey_{config.getParameter<bool>("useSurvey")},
55  enableAlignableUpdates_{config.getParameter<bool>("enableAlignableUpdates")} {
56  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::AlignmentProducerBase";
57 
58  const auto& algoConfig = config_.getParameterSet("algoConfig");
59  if (config_.existsAs<bool>("runAtPCL")) {
60  // configured in main config?
61  runAtPCL_ = config_.getParameter<bool>("runAtPCL");
62 
63  if (algoConfig.existsAs<bool>("runAtPCL") && (runAtPCL_ != algoConfig.getParameter<bool>("runAtPCL"))) {
64  throw cms::Exception("BadConfig") << "Inconsistent settings for 'runAtPCL' in configuration of the "
65  << "alignment producer and the alignment algorithm.";
66  }
67 
68  } else if (algoConfig.existsAs<bool>("runAtPCL")) {
69  // configured in algo config?
70  runAtPCL_ = algoConfig.getParameter<bool>("runAtPCL");
71 
72  } else {
73  // assume 'false' if it was not configured
74  runAtPCL_ = false;
75  }
76 
80 }
81 
82 //------------------------------------------------------------------------------
84 
85 //------------------------------------------------------------------------------
87  if (isDuringLoop_)
88  return;
89 
90  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::startProcessing"
91  << "Begin";
92 
93  if (!isAlgoInitialized_) {
94  throw cms::Exception("LogicError") << "@SUB=AlignmentProducerBase::startProcessing\n"
95  << "Trying to start event processing before initializing the alignment "
96  << "algorithm.";
97  }
98 
99  nevent_ = 0;
100 
101  alignmentAlgo_->startNewLoop();
102 
103  // FIXME: Should this be done in algorithm::startNewLoop()??
104  for (const auto& iCal : calibrations_)
105  iCal->startNewLoop();
106  for (const auto& monitor : monitors_)
107  monitor->startingNewLoop();
108 
110  isDuringLoop_ = true;
111 }
112 
113 //------------------------------------------------------------------------------
115  if (!isDuringLoop_)
116  return;
117 
118  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::terminateProcessing"
119  << "Terminating algorithm.";
120  if (setup) {
121  alignmentAlgo_->terminate(*setup);
122  } else {
123  alignmentAlgo_->terminate();
124  }
125 
126  // FIXME: Should this be done in algorithm::terminate()??
127  for (const auto& iCal : calibrations_)
128  iCal->endOfLoop();
129  for (const auto& monitor : monitors_)
130  monitor->endOfLoop();
131 
132  isDuringLoop_ = false;
133 }
134 
135 //------------------------------------------------------------------------------
137  if (setupChanged(setup)) {
138  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::processEvent"
139  << "EventSetup-Record changed.";
140 
141  // updatable alignables are currently not used at PCL, but event setup
142  // changes require a complete re-initialization
143  if (runAtPCL_) {
144  initAlignmentAlgorithm(setup, /* update = */ false);
145  } else if (enableAlignableUpdates_) {
146  initAlignmentAlgorithm(setup, /* update = */ true);
147  }
148  }
149 
150  initBeamSpot(event); // must happen every event and before incrementing 'nevent_'
151 
152  ++nevent_; // must happen before the check below;
153  // otherwise subsequent checks fail for "EmptySource"
154 
155  if (!alignmentAlgo_->processesEvents()) {
156  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::processEvent"
157  << "Skipping event. The current configuration of the alignment algorithm "
158  << "does not need to process any events.";
159  return false;
160  }
161 
162  // reading in survey records
163  readInSurveyRcds(setup);
164 
165  // Printout event number
166  for (int i = 10; i < 10000000; i *= 10) {
167  if (nevent_ < 10 * i && (nevent_ % i) == 0) {
168  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::processEvent"
169  << "Events processed: " << nevent_;
170  }
171  }
172 
173  // Retrieve trajectories and tracks from the event
174  // -> merely skip if collection is empty
175  edm::Handle<TrajTrackAssociationCollection> handleTrajTracksCollection;
176 
177  if (getTrajTrackAssociationCollection(event, handleTrajTracksCollection)) {
178  // Form pairs of trajectories and tracks
179  ConstTrajTrackPairs trajTracks;
180  for (auto iter = handleTrajTracksCollection->begin(); iter != handleTrajTracksCollection->end(); ++iter) {
181  trajTracks.push_back(ConstTrajTrackPair(&(*(*iter).key), &(*(*iter).val)));
182  }
183 
184  // Run the alignment algorithm with its input
185  const AliClusterValueMap* clusterValueMapPtr{nullptr};
186  if (!clusterValueMapTag_.encode().empty()) {
187  edm::Handle<AliClusterValueMap> clusterValueMap;
188  getAliClusterValueMap(event, clusterValueMap);
189  clusterValueMapPtr = &(*clusterValueMap);
190  }
191 
192  const AlignmentAlgorithmBase::EventInfo eventInfo{event.id(), trajTracks, *beamSpot_, clusterValueMapPtr};
193  alignmentAlgo_->run(setup, eventInfo);
194 
195  for (const auto& monitor : monitors_) {
196  monitor->duringLoop(event, setup, trajTracks); // forward eventInfo?
197  }
198  } else {
199  edm::LogError("Alignment") << "@SUB=AlignmentProducerBase::processEvent"
200  << "No track collection found: skipping event";
201  }
202 
203  return true;
204 }
205 
206 //------------------------------------------------------------------------------
208  const bool changed{setupChanged(setup)};
209  if (changed) {
210  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::beginRunImpl"
211  << "EventSetup-Record changed.";
212 
213  // updatable alignables are currently not used at PCL, but event setup
214  // changes require a complete re-initialization
215  if (runAtPCL_) {
216  initAlignmentAlgorithm(setup, /* update = */ false);
217  } else if (enableAlignableUpdates_) {
218  initAlignmentAlgorithm(setup, /* update = */ true);
219  }
220  }
221 
222  alignmentAlgo_->beginRun(run, setup, changed && (runAtPCL_ || enableAlignableUpdates_));
223 
224  for (const auto& iCal : calibrations_)
225  iCal->beginRun(run, setup);
226 
227  //store the first run analyzed to be used for setting the IOV (for PCL)
228  if (firstRun_ > static_cast<cond::Time_t>(run.id().run())) {
229  firstRun_ = static_cast<cond::Time_t>(run.id().run());
230  }
231 }
232 
233 //------------------------------------------------------------------------------
235  if (!tkLasBeamTag_.encode().empty()) {
238  getTkFittedLasBeamCollection(run, lasBeams);
239  getTsosVectorCollection(run, tsoses);
240 
241  alignmentAlgo_->endRun(EndRunInfo(run.id(), &(*lasBeams), &(*tsoses)), setup);
242  } else {
243  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::endRunImpl"
244  << "No Tk LAS beams to forward to algorithm.";
245  alignmentAlgo_->endRun(EndRunInfo(run.id(), nullptr, nullptr), setup);
246  }
247 }
248 
249 //------------------------------------------------------------------------------
251  // Do not forward edm::LuminosityBlock
252  alignmentAlgo_->beginLuminosityBlock(setup);
253 }
254 
255 //------------------------------------------------------------------------------
257  // Do not forward edm::LuminosityBlock
258  alignmentAlgo_->endLuminosityBlock(setup);
259 }
260 
261 //------------------------------------------------------------------------------
263  auto algoConfig = config_.getParameter<edm::ParameterSet>("algoConfig");
264  algoConfig.addUntrackedParameter("RunRangeSelection", config_.getParameter<edm::VParameterSet>("RunRangeSelection"));
265  algoConfig.addUntrackedParameter<align::RunNumber>("firstIOV", runAtPCL_ ? 1 : uniqueRunRanges_.front().first);
266  algoConfig.addUntrackedParameter("enableAlignableUpdates", enableAlignableUpdates_);
267 
268  const auto& algoName = algoConfig.getParameter<std::string>("algoName");
270 }
271 
272 //------------------------------------------------------------------------------
274  const auto& monitorConfig = config_.getParameter<edm::ParameterSet>("monitorConfig");
275  auto monitors = monitorConfig.getUntrackedParameter<std::vector<std::string> >("monitors");
276  for (const auto& miter : monitors) {
277  monitors_.emplace_back(
278  AlignmentMonitorPluginFactory::get()->create(miter, monitorConfig.getUntrackedParameterSet(miter)));
279  }
280 }
281 
282 //------------------------------------------------------------------------------
284  const auto& calibrations = config_.getParameter<edm::VParameterSet>("calibrations");
285  for (const auto& iCalib : calibrations) {
286  calibrations_.emplace_back(
287  IntegratedCalibrationPluginFactory::get()->create(iCalib.getParameter<std::string>("calibrationName"), iCalib));
288  }
289 }
290 
291 //------------------------------------------------------------------------------
293  bool changed{false};
294 
295  if (watchIdealGeometryRcd_.check(setup)) {
296  changed = true;
297  }
298 
299  if (watchGlobalPositionRcd_.check(setup)) {
300  changed = true;
301  }
302 
303  if (doTracker_) {
304  if (watchTrackerAlRcd_.check(setup)) {
305  changed = true;
306  }
307 
308  if (watchTrackerAlErrorExtRcd_.check(setup)) {
309  changed = true;
310  }
311 
312  if (watchTrackerSurDeRcd_.check(setup)) {
313  changed = true;
314  }
315  }
316 
317  if (doMuon_) {
318  if (watchDTAlRcd_.check(setup)) {
319  changed = true;
320  }
321 
322  if (watchDTAlErrExtRcd_.check(setup)) {
323  changed = true;
324  }
325 
326  if (watchCSCAlRcd_.check(setup)) {
327  changed = true;
328  }
329 
330  if (watchCSCAlErrExtRcd_.check(setup)) {
331  changed = true;
332  }
333  }
334 
335  /* TODO: ExtraAlignables: Which record(s) to check?
336  *
337  if (useExtras_) {}
338  */
339 
340  return changed;
341 }
342 
343 //------------------------------------------------------------------------------
345  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::initAlignmentAlgorithm"
346  << "Begin";
347 
348  auto isTrueUpdate = update && isAlgoInitialized_;
349 
350  // Retrieve tracker topology from geometry
351  edm::ESHandle<TrackerTopology> tTopoHandle;
352  setup.get<TrackerTopologyRcd>().get(tTopoHandle);
353  const TrackerTopology* const tTopo = tTopoHandle.product();
354 
355  // Create the geometries from the ideal geometries
356  createGeometries(setup, tTopo);
357 
358  applyAlignmentsToDB(setup);
359  createAlignables(tTopo, isTrueUpdate);
362 
363  // Initialize alignment algorithm and integrated calibration and pass the
364  // latter to algorithm
365  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::initAlignmentAlgorithm"
366  << "Initializing alignment algorithm.";
367  alignmentAlgo_->initialize(
369 
370  // Not all algorithms support calibrations - so do not pass empty vector
371  // and throw if non-empty and not supported:
372  if (!calibrations_.empty()) {
373  if (alignmentAlgo_->supportsCalibrations()) {
374  alignmentAlgo_->addCalibrations(calibrations_);
375  } else {
376  throw cms::Exception("BadConfig") << "@SUB=AlignmentProducerBase::createCalibrations\n"
377  << "Configured " << calibrations_.size() << " calibration(s) "
378  << "for algorithm not supporting it.";
379  }
380  }
381 
382  isAlgoInitialized_ = true;
383 
385 
386  if (!isTrueUpdate) { // only needed the first time
387  for (const auto& iCal : calibrations_) {
388  iCal->beginOfJob(alignableTracker_.get(), alignableMuon_.get(), alignableExtras_.get());
389  }
390  for (const auto& monitor : monitors_) {
391  monitor->beginOfJob(alignableTracker_.get(), alignableMuon_.get(), alignmentParameterStore_.get());
392  }
393  }
394  startProcessing(); // needed if derived class is non-EDLooper-based
395  // has no effect, if called during loop
396 
397  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::initAlignmentAlgorithm"
398  << "End";
399 }
400 
401 //------------------------------------------------------------------------------
403  getBeamSpot(event, beamSpot_);
404 
405  if (nevent_ == 0 && alignableExtras_) {
406  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::initBeamSpot"
407  << "Initializing AlignableBeamSpot";
408 
409  alignableExtras_->initializeBeamSpot(
411  }
412 }
413 
414 //------------------------------------------------------------------------------
416  if (doTracker_) {
417  edm::ESHandle<GeometricDet> geometricDet;
418  iSetup.get<IdealGeometryRecord>().get(geometricDet);
419 
421  iSetup.get<PTrackerParametersRcd>().get(ptp);
422 
423  TrackerGeomBuilderFromGeometricDet trackerBuilder;
424 
425  trackerGeometry_ = std::shared_ptr<TrackerGeometry>(trackerBuilder.build(&(*geometricDet), *ptp, tTopo));
426  }
427 
428  if (doMuon_) {
430  iSetup.get<IdealGeometryRecord>().get(cpv);
432  iSetup.get<MuonNumberingRecord>().get(mdc);
435  muonDTGeometry_ = std::make_shared<DTGeometry>();
436  DTGeometryBuilder.build(*muonDTGeometry_, &(*cpv), *mdc);
437  muonCSCGeometry_ = std::make_shared<CSCGeometry>();
438  CSCGeometryBuilder.build(*muonCSCGeometry_, &(*cpv), *mdc);
439  }
440 }
441 
442 //------------------------------------------------------------------------------
444  // Retrieve and apply alignments, if requested (requires z setup)
445  if (applyDbAlignment_) {
446  // we need GlobalPositionRcd - and have to keep track for later removal
447  // before writing again to DB...
448 
449  edm::ESHandle<Alignments> globalAlignments;
450  setup.get<GlobalPositionRcd>().get(globalAlignments);
451  globalPositions_ = std::make_unique<Alignments>(*globalAlignments);
452 
453  if (doTracker_) {
454  applyDB<TrackerGeometry, TrackerAlignmentRcd, TrackerAlignmentErrorExtendedRcd>(
456 
457  applyDB<TrackerGeometry, TrackerSurfaceDeformationRcd>(trackerGeometry_.get(), setup);
458  }
459 
460  if (doMuon_) {
461  applyDB<DTGeometry, DTAlignmentRcd, DTAlignmentErrorExtendedRcd>(
463 
464  applyDB<CSCGeometry, CSCAlignmentRcd, CSCAlignmentErrorExtendedRcd>(
466  }
467  }
468 }
469 
470 //------------------------------------------------------------------------------
472  if (doTracker_) {
473  if (update) {
474  alignableTracker_->update(trackerGeometry_.get(), tTopo);
475  } else {
476  alignableTracker_ = std::make_unique<AlignableTracker>(trackerGeometry_.get(), tTopo);
477  }
478  }
479 
480  if (doMuon_) {
481  if (update) {
482  alignableMuon_->update(muonDTGeometry_.get(), muonCSCGeometry_.get());
483  } else {
484  alignableMuon_ = std::make_unique<AlignableMuon>(muonDTGeometry_.get(), muonCSCGeometry_.get());
485  }
486  }
487 
488  if (useExtras_) {
489  if (update) {
490  // FIXME: Requires further code changes to track beam spot condition changes
491  } else {
492  alignableExtras_ = std::make_unique<AlignableExtras>();
493  }
494  }
495 }
496 
497 //------------------------------------------------------------------------------
499  // Create alignment parameter builder
500  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::buildParameterStore"
501  << "Creating AlignmentParameterBuilder";
502 
503  const auto& alParamBuildCfg = config_.getParameter<edm::ParameterSet>("ParameterBuilder");
504  const auto& alParamStoreCfg = config_.getParameter<edm::ParameterSet>("ParameterStore");
505 
506  AlignmentParameterBuilder alignmentParameterBuilder{
507  alignableTracker_.get(), alignableMuon_.get(), alignableExtras_.get(), alParamBuildCfg};
508 
509  // Fix alignables if requested
510  if (stNFixAlignables_ > 0) {
511  alignmentParameterBuilder.fixAlignables(stNFixAlignables_);
512  }
513 
514  // Get list of alignables
515  const auto& alignables = alignmentParameterBuilder.alignables();
516  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::buildParameterStore"
517  << "got " << alignables.size() << " alignables";
518 
519  // Create AlignmentParameterStore
520  alignmentParameterStore_ = std::make_unique<AlignmentParameterStore>(alignables, alParamStoreCfg);
521  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::buildParameterStore"
522  << "AlignmentParameterStore created!";
523 }
524 
525 //------------------------------------------------------------------------------
527  // Apply misalignment scenario to alignable tracker and muon if requested
528  // WARNING: this assumes scenarioConfig can be passed to both muon and tracker
529 
531  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::applyMisalignment"
532  << "Applying misalignment scenario to " << (doTracker_ ? "tracker" : "")
533  << (doMuon_ ? (doTracker_ ? " and muon" : "muon") : ".");
534 
535  const auto& scenarioConfig = config_.getParameterSet("MisalignmentScenario");
536 
537  if (doTracker_) {
538  TrackerScenarioBuilder scenarioBuilder(alignableTracker_.get());
539  scenarioBuilder.applyScenario(scenarioConfig);
540  }
541  if (doMuon_) {
542  MuonScenarioBuilder muonScenarioBuilder(alignableMuon_.get());
543  muonScenarioBuilder.applyScenario(scenarioConfig);
544  }
545 
546  } else {
547  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::applyMisalignment"
548  << "NOT applying misalignment scenario!";
549  }
550 
551  // Apply simple misalignment
552  const auto& sParSel = config_.getParameter<std::string>("parameterSelectorSimple");
554 }
555 
556 // ----------------------------------------------------------------------------
558  const align::Alignables& alivec, const std::string& selection, float shift, float rot, bool local) {
559  std::ostringstream output; // collecting output
560 
561  if (shift > 0. || rot > 0.) {
562  output << "Adding random flat shift of max size " << shift << " and adding random flat rotation of max size " << rot
563  << " to ";
564 
565  std::vector<bool> commSel(0);
566  if (selection != "-1") {
567  AlignmentParameterSelector aSelector(nullptr, nullptr); // no alignable needed here...
568  const std::vector<char> cSel(aSelector.convertParamSel(selection));
569  if (cSel.size() < RigidBodyAlignmentParameters::N_PARAM) {
570  throw cms::Exception("BadConfig")
571  << "[AlignmentProducerBase::simpleMisalignment_]\n"
572  << "Expect selection string '" << selection << "' to be at least of length "
573  << RigidBodyAlignmentParameters::N_PARAM << " or to be '-1'.\n"
574  << "(Most probably you have to adjust the parameter 'parameterSelectorSimple'.)";
575  }
576  for (const auto& cIter : cSel) {
577  commSel.push_back(cIter == '0' ? false : true);
578  }
579  output << "parameters defined by (" << selection << "), representing (x,y,z,alpha,beta,gamma),";
580  } else {
581  output << "the active parameters of each alignable,";
582  }
583  output << " in " << (local ? "local" : "global") << " frame.";
584 
585  for (const auto& ali : alivec) {
586  std::vector<bool> mysel(commSel.empty() ? ali->alignmentParameters()->selector() : commSel);
587 
588  if (std::abs(shift) > 0.00001) {
589  double s0 = 0., s1 = 0., s2 = 0.;
591  s0 = shift * double(random() % 1000 - 500) / 500.;
593  s1 = shift * double(random() % 1000 - 500) / 500.;
595  s2 = shift * double(random() % 1000 - 500) / 500.;
596 
597  if (local)
598  ali->move(ali->surface().toGlobal(align::LocalVector(s0, s1, s2)));
599  else
600  ali->move(align::GlobalVector(s0, s1, s2));
601 
602  //AlignmentPositionError ape(dx,dy,dz);
603  //ali->addAlignmentPositionError(ape);
604  }
605 
606  if (std::abs(rot) > 0.00001) {
609  r(1) = rot * double(random() % 1000 - 500) / 500.;
611  r(2) = rot * double(random() % 1000 - 500) / 500.;
613  r(3) = rot * double(random() % 1000 - 500) / 500.;
614 
615  const align::RotationType mrot = align::toMatrix(r);
616  if (local)
617  ali->rotateInLocalFrame(mrot);
618  else
619  ali->rotateInGlobalFrame(mrot);
620 
621  //ali->addAlignmentPositionErrorFromRotation(mrot);
622  }
623  } // end loop on alignables
624  } else {
625  output << "No simple misalignment added!";
626  }
627  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::simpleMisalignment" << output.str();
628 }
629 
630 //------------------------------------------------------------------------------
632  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::applyAlignmentsToGeometry"
633  << "Now physically apply alignments to geometry...";
634 
635  // Propagate changes to reconstruction geometry (from initialisation or iteration)
636  GeometryAligner aligner;
637 
638  if (doTracker_) {
639  if (!alignableTracker_) {
640  throw cms::Exception("LogicError") << "@SUB=AlignmentProducerBase::applyAlignmentsToGeometry\n"
641  << "Trying to apply tracker alignment before creating it.";
642  }
643 
644  std::unique_ptr<Alignments> alignments{alignableTracker_->alignments()};
645  std::unique_ptr<AlignmentErrorsExtended> alignmentErrExt{alignableTracker_->alignmentErrors()};
646  std::unique_ptr<AlignmentSurfaceDeformations> aliDeforms{alignableTracker_->surfaceDeformations()};
647 
648  aligner.applyAlignments(trackerGeometry_.get(), alignments.get(), alignmentErrExt.get(), AlignTransform());
649  aligner.attachSurfaceDeformations(trackerGeometry_.get(), aliDeforms.get());
650  }
651 
652  if (doMuon_) {
653  if (!alignableMuon_) {
654  throw cms::Exception("LogicError") << "@SUB=AlignmentProducerBase::applyAlignmentsToGeometry\n"
655  << "Trying to apply muon alignment before creating it.";
656  }
657 
658  std::unique_ptr<Alignments> dtAlignments{alignableMuon_->dtAlignments()};
659  std::unique_ptr<Alignments> cscAlignments{alignableMuon_->cscAlignments()};
660 
661  std::unique_ptr<AlignmentErrorsExtended> dtAlignmentErrExt{alignableMuon_->dtAlignmentErrorsExtended()};
662  std::unique_ptr<AlignmentErrorsExtended> cscAlignmentErrExt{alignableMuon_->cscAlignmentErrorsExtended()};
663 
664  aligner.applyAlignments(muonDTGeometry_.get(), dtAlignments.get(), dtAlignmentErrExt.get(), AlignTransform());
665  aligner.applyAlignments(muonCSCGeometry_.get(), cscAlignments.get(), cscAlignmentErrExt.get(), AlignTransform());
666  }
667 }
668 
669 //------------------------------------------------------------------------------
671  // Get Survey Rcds and add Survey Info
672  if (doTracker_ && useSurvey_) {
673  bool tkSurveyBool = watchTkSurveyRcd_.check(iSetup);
674  bool tkSurveyErrBool = watchTkSurveyErrExtRcd_.check(iSetup);
675  edm::LogInfo("Alignment") << "watcher tksurveyrcd: " << tkSurveyBool;
676  edm::LogInfo("Alignment") << "watcher tksurveyerrrcd: " << tkSurveyErrBool;
677  if (tkSurveyBool || tkSurveyErrBool) {
678  edm::LogInfo("Alignment") << "ADDING THE SURVEY INFORMATION";
680  edm::ESHandle<SurveyErrors> surveyErrors;
681 
682  iSetup.get<TrackerSurveyRcd>().get(surveys);
683  iSetup.get<TrackerSurveyErrorExtendedRcd>().get(surveyErrors);
684 
685  surveyIndex_ = 0;
686  surveyValues_ = &*surveys;
687  surveyErrors_ = &*surveyErrors;
689  }
690  }
691 
692  if (doMuon_ && useSurvey_) {
693  bool DTSurveyBool = watchTkSurveyRcd_.check(iSetup);
694  bool DTSurveyErrBool = watchTkSurveyErrExtRcd_.check(iSetup);
695  bool CSCSurveyBool = watchTkSurveyRcd_.check(iSetup);
696  bool CSCSurveyErrBool = watchTkSurveyErrExtRcd_.check(iSetup);
697 
698  if (DTSurveyBool || DTSurveyErrBool || CSCSurveyBool || CSCSurveyErrBool) {
699  edm::ESHandle<Alignments> dtSurveys;
700  edm::ESHandle<SurveyErrors> dtSurveyErrors;
701  edm::ESHandle<Alignments> cscSurveys;
702  edm::ESHandle<SurveyErrors> cscSurveyErrors;
703 
704  iSetup.get<DTSurveyRcd>().get(dtSurveys);
705  iSetup.get<DTSurveyErrorExtendedRcd>().get(dtSurveyErrors);
706  iSetup.get<CSCSurveyRcd>().get(cscSurveys);
707  iSetup.get<CSCSurveyErrorExtendedRcd>().get(cscSurveyErrors);
708 
709  surveyIndex_ = 0;
710  surveyValues_ = &*dtSurveys;
711  surveyErrors_ = &*dtSurveyErrors;
712  const auto& barrels = alignableMuon_->DTBarrel();
713  for (const auto& barrel : barrels)
715 
716  surveyIndex_ = 0;
717  surveyValues_ = &*cscSurveys;
718  surveyErrors_ = &*cscSurveyErrors;
719  const auto& endcaps = alignableMuon_->CSCEndcaps();
720  for (const auto& endcap : endcaps)
722  }
723  }
724 }
725 
726 //------------------------------------------------------------------------------
728  const auto& comps = ali->components();
729 
730  for (const auto& comp : comps)
732 
734 
735  if (ali->id() != error.rawId() || ali->alignableObjectId() != error.structureType()) {
736  throw cms::Exception("DatabaseError") << "Error reading survey info from DB. Mismatched id!";
737  }
738 
739  const auto& pos = surveyValues_->m_align[surveyIndex_].translation();
740  const auto& rot = surveyValues_->m_align[surveyIndex_].rotation();
741 
742  AlignableSurface surf(
743  align::PositionType(pos.x(), pos.y(), pos.z()),
744  align::RotationType(rot.xx(), rot.xy(), rot.xz(), rot.yx(), rot.yy(), rot.yz(), rot.zx(), rot.zy(), rot.zz()));
745 
746  surf.setWidth(ali->surface().width());
747  surf.setLength(ali->surface().length());
748 
749  ali->setSurvey(new SurveyDet(surf, error.matrix()));
750 
751  ++surveyIndex_;
752 }
753 
754 //------------------------------------------------------------------------------
756  for (const auto& monitor : monitors_)
757  monitor->endOfJob();
758 
759  if (alignmentAlgo_->processesEvents() && nevent_ == 0) {
760  return false;
761  }
762 
764  if (alignmentAlgo_->storeAlignments())
766  } else {
767  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::finish"
768  << "No payload to be stored!";
769  }
770 
771  // takes care of storing output of calibrations, but needs to be called only
772  // after 'storeAlignmentsToDB()'
773  for (const auto& iCal : calibrations_)
774  iCal->endOfJob();
775 
776  return true;
777 }
778 
779 //------------------------------------------------------------------------------
781  const auto runRangeSelectionVPSet = config_.getParameterSetVector("RunRangeSelection");
782 
783  // handle PCL use case
784  const auto& uniqueRunRanges =
785  (runAtPCL_ ? align::makeUniqueRunRanges(runRangeSelectionVPSet, firstRun_) : uniqueRunRanges_);
786 
787  std::vector<AlgebraicVector> beamSpotParameters;
788 
789  for (const auto& iRunRange : uniqueRunRanges) {
790  alignmentAlgo_->setParametersForRunRange(iRunRange);
791 
792  // Save alignments to database
794  writeForRunRange(iRunRange.first);
795  }
796 
797  // Deal with extra alignables, e.g. beam spot
798  if (alignableExtras_) {
799  auto& alis = alignableExtras_->beamSpot();
800  if (!alis.empty()) {
801  auto beamSpotAliPars = dynamic_cast<BeamSpotAlignmentParameters*>(alis[0]->alignmentParameters());
802  if (!beamSpotAliPars) {
803  throw cms::Exception("LogicError") << "@SUB=AlignmentProducerBase::storeAlignmentsToDB\n"
804  << "First alignable of alignableExtras_ does not have "
805  << "'BeamSpotAlignmentParameters', while it should have.";
806  }
807 
808  beamSpotParameters.push_back(beamSpotAliPars->parameters());
809  }
810  }
811  }
812 
813  if (alignableExtras_) {
814  std::ostringstream bsOutput;
815 
816  auto itPar = beamSpotParameters.cbegin();
817  for (auto iRunRange = uniqueRunRanges.cbegin(); iRunRange != uniqueRunRanges.cend(); ++iRunRange, ++itPar) {
818  bsOutput << "Run range: " << (*iRunRange).first << " - " << (*iRunRange).second << "\n";
819  bsOutput << " Displacement: x=" << (*itPar)[0] << ", y=" << (*itPar)[1] << "\n";
820  bsOutput << " Slope: dx/dz=" << (*itPar)[2] << ", dy/dz=" << (*itPar)[3] << "\n";
821  }
822 
823  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::storeAlignmentsToDB"
824  << "Parameters for alignable beamspot:\n"
825  << bsOutput.str();
826  }
827 }
828 
829 //------------------------------------------------------------------------------
831  if (doTracker_) { // first tracker
832  const AlignTransform* trackerGlobal{nullptr}; // will be 'removed' from constants
833  if (globalPositions_) { // i.e. applied before in applyDB
835  }
836 
837  auto alignments = alignableTracker_->alignments();
838  auto alignmentErrors = alignableTracker_->alignmentErrors();
839  this->writeDB(
840  alignments, "TrackerAlignmentRcd", alignmentErrors, "TrackerAlignmentErrorExtendedRcd", trackerGlobal, time);
841 
842  // Save surface deformations to database
843  if (saveDeformationsToDB_) {
844  auto alignmentSurfaceDeformations = alignableTracker_->surfaceDeformations();
845  this->writeDB(alignmentSurfaceDeformations, "TrackerSurfaceDeformationRcd", time);
846  }
847  }
848 
849  if (doMuon_) { // now muon
850  const AlignTransform* muonGlobal{nullptr}; // will be 'removed' from constants
851  if (globalPositions_) { // i.e. applied before in applyDB
853  }
854  // Get alignments+errors, first DT - ownership taken over by writeDB(..), so no delete
855  auto alignments = alignableMuon_->dtAlignments();
856  auto alignmentErrors = alignableMuon_->dtAlignmentErrorsExtended();
857  this->writeDB(alignments, "DTAlignmentRcd", alignmentErrors, "DTAlignmentErrorExtendedRcd", muonGlobal, time);
858 
859  // Get alignments+errors, now CSC - ownership taken over by writeDB(..), so no delete
860  alignments = alignableMuon_->cscAlignments();
861  alignmentErrors = alignableMuon_->cscAlignmentErrorsExtended();
862  this->writeDB(alignments, "CSCAlignmentRcd", alignmentErrors, "CSCAlignmentErrorExtendedRcd", muonGlobal, time);
863  }
864 }
865 
866 //------------------------------------------------------------------------------
868  const std::string& alignRcd,
869  AlignmentErrorsExtended* alignmentErrors,
870  const std::string& errRcd,
871  const AlignTransform* globalCoordinates,
872  cond::Time_t time) const {
873  Alignments* tempAlignments = alignments;
874  AlignmentErrorsExtended* tempAlignmentErrorsExtended = alignmentErrors;
875 
876  // Call service
878  if (!poolDb.isAvailable()) { // Die if not available
879  delete tempAlignments; // promised to take over ownership...
880  delete tempAlignmentErrorsExtended; // dito
881  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
882  }
883 
884  if (globalCoordinates // happens only if (applyDbAlignment_ == true)
885  && globalCoordinates->transform() != AlignTransform::Transform::Identity) {
886  tempAlignments = new Alignments(); // temporary storage for
887  tempAlignmentErrorsExtended = new AlignmentErrorsExtended(); // final alignments and errors
888 
889  GeometryAligner aligner;
890  aligner.removeGlobalTransform(
891  alignments, alignmentErrors, *globalCoordinates, tempAlignments, tempAlignmentErrorsExtended);
892 
893  delete alignments; // have to delete original alignments
894  delete alignmentErrors; // same thing for the errors
895 
896  edm::LogInfo("Alignment") << "@SUB=AlignmentProducerBase::writeDB"
897  << "globalCoordinates removed from alignments (" << alignRcd << ") and errors ("
898  << alignRcd << ").";
899  }
900 
901  if (saveToDB_) {
902  edm::LogInfo("Alignment") << "Writing Alignments for run " << time << " to " << alignRcd << ".";
903  poolDb->writeOne<Alignments>(tempAlignments, time, alignRcd);
904  } else { // poolDb->writeOne(..) takes over 'alignments' ownership,...
905  delete tempAlignments; // ...otherwise we have to delete, as promised!
906  }
907 
908  if (saveApeToDB_) {
909  edm::LogInfo("Alignment") << "Writing AlignmentErrorsExtended for run " << time << " to " << errRcd << ".";
910  poolDb->writeOne<AlignmentErrorsExtended>(tempAlignmentErrorsExtended, time, errRcd);
911  } else { // poolDb->writeOne(..) takes over 'alignmentErrors' ownership,...
912  delete tempAlignmentErrorsExtended; // ...otherwise we have to delete, as promised!
913  }
914 }
915 
916 //------------------------------------------------------------------------------
918  const std::string& surfaceDeformationRcd,
919  cond::Time_t time) const {
920  // Call service
922  if (!poolDb.isAvailable()) { // Die if not available
923  delete alignmentSurfaceDeformations; // promised to take over ownership...
924  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
925  }
926 
927  if (saveDeformationsToDB_) {
928  edm::LogInfo("Alignment") << "Writing AlignmentSurfaceDeformations for run " << time << " to "
929  << surfaceDeformationRcd << ".";
930  poolDb->writeOne<AlignmentSurfaceDeformations>(alignmentSurfaceDeformations, time, surfaceDeformationRcd);
931  } else { // poolDb->writeOne(..) takes over 'surfaceDeformation' ownership,...
932  delete alignmentSurfaceDeformations; // ...otherwise we have to delete, as promised!
933  }
934 }
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
align::Scalar width() const
T getParameter(std::string const &) const
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
double z0() const
z coordinate
Definition: BeamSpot.h:65
T getUntrackedParameter(std::string const &, T const &) const
VParameterSet const & getParameterSetVector(std::string const &name) const
const edm::InputTag tjTkAssociationMapTag_
Map with tracks/trajectories.
void readInSurveyRcds(const edm::EventSetup &)
Reads in survey records.
void applyAlignmentsToDB(const edm::EventSetup &)
void createGeometries(const edm::EventSetup &, const TrackerTopology *)
Creates ideal geometry from IdealGeometryRecord.
void writeDB(Alignments *, const std::string &, AlignmentErrorsExtended *, const std::string &, const AlignTransform *, cond::Time_t) const
std::vector< ConstTrajTrackPair > ConstTrajTrackPairs
RunID const & id() const
Definition: RunBase.h:39
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
std::shared_ptr< CSCGeometry > muonCSCGeometry_
Builds a scenario from configuration and applies it to the alignable Muon.
Alignment producer base class.
RunNumber_t run() const
Definition: RunID.h:36
def create(alignables, pedeDump, additionalData, outputFile, config)
edm::ESWatcher< DTAlignmentErrorExtendedRcd > watchDTAlErrExtRcd_
const_iterator end() const
last iterator over the map (read only)
edm::ESWatcher< DTAlignmentRcd > watchDTAlRcd_
Time_t beginValue
Definition: Time.h:41
Class to update a given geometry with a set of alignments.
bool processEvent(const edm::Event &, const edm::EventSetup &)
Process event.
void initAlignmentAlgorithm(const edm::EventSetup &, bool update=false)
void terminateProcessing(const edm::EventSetup *=0)
Terminate processing of events.
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
ErrorMatrix matrix() const
Definition: SurveyError.h:63
AlignmentProducerBase(const edm::ParameterSet &)
selection
main part
Definition: corrVsCorr.py:100
void buildParameterStore()
Creates the , which manages all Alignables.
virtual bool getAliClusterValueMap(const edm::Event &, edm::Handle< AliClusterValueMap > &)=0
std::unique_ptr< AlignableMuon > alignableMuon_
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
virtual ~AlignmentProducerBase()(false)
const Alignments * surveyValues_
void setWidth(align::Scalar width)
Definition: config.py:1
virtual const Alignables & components() const =0
Return vector of all direct components.
std::unique_ptr< AlignmentParameterStore > alignmentParameterStore_
uint8_t structureType() const
Definition: SurveyError.h:59
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
std::string encode() const
Definition: InputTag.cc:159
virtual bool getTkFittedLasBeamCollection(const edm::Run &, edm::Handle< TkFittedLasBeamCollection > &)=0
define event information passed to algorithms
std::shared_ptr< TrackerGeometry > trackerGeometry_
void setLength(align::Scalar length)
edm::ESWatcher< GlobalPositionRcd > watchGlobalPositionRcd_
virtual bool getTsosVectorCollection(const edm::Run &, edm::Handle< TsosVectorCollection > &)=0
double dydz() const
dydz slope
Definition: BeamSpot.h:80
void writeForRunRange(cond::Time_t)
unsigned long long Time_t
Definition: Time.h:14
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
void build(CSCGeometry &geom, const DDCompactView *fv, const MuonDDDConstants &muonConstants)
Build the geometry.
std::unique_ptr< AlignableExtras > alignableExtras_
void build(DTGeometry &theGeometry, const DDCompactView *cview, const MuonDDDConstants &muonConstants)
RunRanges makeUniqueRunRanges(const edm::VParameterSet &runRanges, const RunNumber &defaultRun)
Definition: Utilities.cc:241
void attachSurfaceDeformations(C *geometry, const AlignmentSurfaceDeformations *surfaceDeformations)
const edm::InputTag beamSpotTag_
BeamSpot.
void removeGlobalTransform(const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates, Alignments *newAlignments, AlignmentErrorsExtended *newAlignmentErrorsExtended)
edm::ESWatcher< TrackerSurveyErrorExtendedRcd > watchTkSurveyErrExtRcd_
void endRunImpl(const edm::Run &, const edm::EventSetup &)
end run
void addSurveyInfo(Alignable *)
Adds survey info to an Alignable.
bool isAvailable() const
Definition: Service.h:40
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< AlignableTracker > alignableTracker_
void endLuminosityBlockImpl(const edm::LuminosityBlock &, const edm::EventSetup &)
end lumi block
align::ID rawId() const
Definition: SurveyError.h:61
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void createAlignables(const TrackerTopology *, bool update=false)
std::unique_ptr< const Alignments > globalPositions_
GlobalPositions that might be read from DB, nullptr otherwise.
AlignmentAlgorithmBase::EndRunInfo EndRunInfo
void startProcessing()
Start processing of events.
edm::ESWatcher< IdealGeometryRecord > watchIdealGeometryRcd_
double dxdz() const
dxdz slope
Definition: BeamSpot.h:78
virtual bool getBeamSpot(const edm::Event &, edm::Handle< reco::BeamSpot > &)=0
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
edm::ESWatcher< CSCAlignmentErrorExtendedRcd > watchCSCAlErrExtRcd_
#define noexcept
Definition: DetId.h:17
edm::ESWatcher< TrackerSurfaceDeformationRcd > watchTrackerSurDeRcd_
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
AlgebraicVector EulerAngles
Definition: Definitions.h:34
align::Scalar length() const
Transform transform() const
edm::Handle< reco::BeamSpot > beamSpot_
ParameterSet const & getParameterSet(std::string const &) const
void applyMisalignment()
Applies misalignment scenario to .
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:266
const align::RunRanges uniqueRunRanges_
void storeAlignmentsToDB()
Writes Alignments (i.e. Records) to database-file.
virtual bool getTrajTrackAssociationCollection(const edm::Event &, edm::Handle< TrajTrackAssociationCollection > &)=0
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
std::shared_ptr< DTGeometry > muonDTGeometry_
edm::ESWatcher< TrackerAlignmentRcd > watchTrackerAlRcd_
void applyScenario(const edm::ParameterSet &scenario) override
Apply misalignment scenario to the tracker.
void beginLuminosityBlockImpl(const edm::LuminosityBlock &, const edm::EventSetup &)
begin lumi block
edm::ESWatcher< TrackerAlignmentErrorExtendedRcd > watchTrackerAlErrorExtRcd_
bool setupChanged(const edm::EventSetup &)
Checks if one of the EventSetup-Records has changed.
#define update(a, b)
edm::ESWatcher< TrackerSurveyRcd > watchTkSurveyRcd_
T get() const
Definition: EventSetup.h:73
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:34
void createCalibrations()
Creates the calibrations.
std::vector< char > convertParamSel(const std::string &selString) const
Converting std::string into std::vector<char>
double y0() const
y coordinate
Definition: BeamSpot.h:63
static unsigned int const shift
void createAlignmentAlgorithm()
Creates the choosen alignment algorithm.
edm::ESWatcher< CSCAlignmentRcd > watchCSCAlRcd_
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
const edm::InputTag tkLasBeamTag_
LAS beams in edm::Run (ignore if empty)
const SurveyErrors * surveyErrors_
void initBeamSpot(const edm::Event &)
Initializes Beamspot of Alignables .
std::pair< const Trajectory *, const reco::Track * > ConstTrajTrackPair
void applyScenario(const edm::ParameterSet &scenario) override
Apply misalignment scenario to the Muon.
const_iterator begin() const
first iterator over the map (read only)
CalibrationsOwner calibrations_
std::vector< SurveyError > m_surveyErrors
Definition: SurveyErrors.h:22
Builds a scenario from configuration and applies it to the alignable tracker.
void beginRunImpl(const edm::Run &, const edm::EventSetup &)
begin run
const edm::InputTag clusterValueMapTag_
ValueMap containing associtaion cluster-flag.
T const * product() const
Definition: ESHandle.h:86
void simpleMisalignment(const align::Alignables &, const std::string &, float, float, bool)
Applies misalignment scenario to .
Definition: event.py:1
Definition: Run.h:45
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:37
std::unique_ptr< AlignmentAlgorithmBase > alignmentAlgo_
double x0() const
x coordinate
Definition: BeamSpot.h:61
void createMonitors()
Creates the monitors.