ECCE @ 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 #include <random>
13 
16  std::unique_ptr<const Acts::Logger> logger)
17  : m_cfg(cfg), m_logger(std::move(logger)) {}
18 
21  // We need to lock the Decorator
22  std::lock_guard<std::mutex> alignmentLock(m_alignmentMutex);
23 
24  // In which iov batch are we?
25  unsigned int iov = context.eventNumber / m_cfg.iovSize;
26 
27  if (m_cfg.randomNumberSvc != nullptr) {
28  // Detect if we have a new alignment range
29  if (m_iovStatus.size() == 0 or m_iovStatus.size() < iov or
30  !m_iovStatus[iov]) {
31  auto cios = m_iovStatus.size();
32  ACTS_VERBOSE("New IOV detected at event " << context.eventNumber
33  << ", emulate new alignment.");
34  ACTS_VERBOSE("New IOV identifier set to "
35  << iov << ", curently valid: " << cios);
36 
37  for (unsigned int ic = cios; ic <= iov; ++ic) {
38  m_iovStatus.push_back(false);
39  }
40 
41  // Create an algorithm local random number generator
42  RandomEngine rng = m_cfg.randomNumberSvc->spawnGenerator(context);
43  std::normal_distribution<double> gauss(0., 1.);
44 
45  // Are we in a gargabe collection event?
46  for (auto& lstore : m_cfg.detectorStore) {
47  for (auto& ldet : lstore) {
48  // get the nominal transform
49  auto& tForm = ldet->nominalTransform(context.geoContext);
50  // create a new transform
51  auto atForm = std::make_unique<Acts::Transform3D>(tForm);
52  if (iov != 0 or not m_cfg.firstIovNominal) {
53  // the shifts in x, y, z
54  double tx = m_cfg.gSigmaX != 0 ? m_cfg.gSigmaX * gauss(rng) : 0.;
55  double ty = m_cfg.gSigmaY != 0 ? m_cfg.gSigmaY * gauss(rng) : 0.;
56  double tz = m_cfg.gSigmaZ != 0 ? m_cfg.gSigmaZ * gauss(rng) : 0.;
57  // Add a translation - if there is any
58  if (tx != 0. or ty != 0. or tz != 0.) {
59  const auto& tMatrix = atForm->matrix();
60  auto colX = tMatrix.block<3, 1>(0, 0).transpose();
61  auto colY = tMatrix.block<3, 1>(0, 1).transpose();
62  auto colZ = tMatrix.block<3, 1>(0, 2).transpose();
63  Acts::Vector3D newCenter = tMatrix.block<3, 1>(0, 3).transpose() +
64  tx * colX + ty * colY + tz * colZ;
65  atForm->translation() = newCenter;
66  }
67  // now modify it - rotation around local X
68  if (m_cfg.aSigmaX != 0.) {
69  (*atForm) *= Acts::AngleAxis3D(m_cfg.aSigmaX * gauss(rng),
70  Acts::Vector3D::UnitX());
71  }
72  if (m_cfg.aSigmaY != 0.) {
73  (*atForm) *= Acts::AngleAxis3D(m_cfg.aSigmaY * gauss(rng),
74  Acts::Vector3D::UnitY());
75  }
76  if (m_cfg.aSigmaZ != 0.) {
77  (*atForm) *= Acts::AngleAxis3D(m_cfg.aSigmaZ * gauss(rng),
78  Acts::Vector3D::UnitZ());
79  }
80  }
81  // put it back into the store
82  ldet->addAlignedTransform(std::move(atForm), iov);
83  }
84  }
85  }
86  // book keeping
87  m_iovStatus[iov] = true;
88  }
89  // Set the geometry context
90  AlignedDetectorElement::ContextType alignedContext{iov};
91  context.geoContext =
92  std::make_any<AlignedDetectorElement::ContextType>(alignedContext);
93 
94  return ProcessCode::SUCCESS;
95 }