EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AlignmentDecorator.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AlignmentDecorator.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
12 
13 #include <random>
14 
17  std::unique_ptr<const Acts::Logger> logger)
18  : m_cfg(cfg), m_logger(std::move(logger)) {}
19 
22  AlgorithmContext& context) {
23  // We need to lock the Decorator
24  std::lock_guard<std::mutex> alignmentLock(m_alignmentMutex);
25 
26  // In which iov batch are we?
27  unsigned int iov = context.eventNumber / m_cfg.iovSize;
28 
29  if (m_cfg.randomNumberSvc != nullptr) {
30  // Detect if we have a new alignment range
31  if (m_iovStatus.size() == 0 or m_iovStatus.size() < iov or
32  !m_iovStatus[iov]) {
33  auto cios = m_iovStatus.size();
34  ACTS_VERBOSE("New IOV detected at event " << context.eventNumber
35  << ", emulate new alignment.");
36  ACTS_VERBOSE("New IOV identifier set to "
37  << iov << ", curently valid: " << cios);
38 
39  for (unsigned int ic = cios; ic <= iov; ++ic) {
40  m_iovStatus.push_back(false);
41  }
42 
43  // Create an algorithm local random number generator
44  RandomEngine rng = m_cfg.randomNumberSvc->spawnGenerator(context);
45  std::normal_distribution<double> gauss(0., 1.);
46 
47  // Are we in a gargabe collection event?
48  for (auto& lstore : m_cfg.detectorStore) {
49  for (auto& ldet : lstore) {
50  // get the nominal transform
51  auto& tForm = ldet->nominalTransform(context.geoContext);
52  // create a new transform
53  auto atForm = std::make_unique<Acts::Transform3D>(tForm);
54  if (iov != 0 or not m_cfg.firstIovNominal) {
55  // the shifts in x, y, z
56  double tx = m_cfg.gSigmaX != 0 ? m_cfg.gSigmaX * gauss(rng) : 0.;
57  double ty = m_cfg.gSigmaY != 0 ? m_cfg.gSigmaY * gauss(rng) : 0.;
58  double tz = m_cfg.gSigmaZ != 0 ? m_cfg.gSigmaZ * gauss(rng) : 0.;
59  // Add a translation - if there is any
60  if (tx != 0. or ty != 0. or tz != 0.) {
61  const auto& tMatrix = atForm->matrix();
62  auto colX = tMatrix.block<3, 1>(0, 0).transpose();
63  auto colY = tMatrix.block<3, 1>(0, 1).transpose();
64  auto colZ = tMatrix.block<3, 1>(0, 2).transpose();
65  Acts::Vector3D newCenter = tMatrix.block<3, 1>(0, 3).transpose() +
66  tx * colX + ty * colY + tz * colZ;
67  atForm->translation() = newCenter;
68  }
69  // now modify it - rotation around local X
70  if (m_cfg.aSigmaX != 0.) {
71  (*atForm) *= Acts::AngleAxis3D(m_cfg.aSigmaX * gauss(rng),
72  Acts::Vector3D::UnitX());
73  }
74  if (m_cfg.aSigmaY != 0.) {
75  (*atForm) *= Acts::AngleAxis3D(m_cfg.aSigmaY * gauss(rng),
76  Acts::Vector3D::UnitY());
77  }
78  if (m_cfg.aSigmaZ != 0.) {
79  (*atForm) *= Acts::AngleAxis3D(m_cfg.aSigmaZ * gauss(rng),
80  Acts::Vector3D::UnitZ());
81  }
82  }
83  // put it back into the store
84  ldet->addAlignedTransform(std::move(atForm), iov);
85  }
86  }
87  }
88  // book keeping
89  m_iovStatus[iov] = true;
90  }
91  // Set the geometry context
92  AlignedDetectorElement::ContextType alignedContext{iov};
93  context.geoContext =
94  std::make_any<AlignedDetectorElement::ContextType>(alignedContext);
95 
96  return ProcessCode::SUCCESS;
97 }