CMS 3D CMS Logo

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