Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AlignmentDecorator.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AlignmentDecorator.hpp
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 
9 #pragma once
10 
17 
18 #include <iostream>
19 #include <mutex>
20 #include <vector>
21 
22 namespace ActsExamples {
23 
24 namespace Contextual {
25 
32  public:
34  struct Config {
36  unsigned int iovSize = 100;
37 
39  bool doGarbageCollection = true;
40  unsigned int flushSize = 200;
41 
42  std::shared_ptr<RandomNumbers> randomNumberSvc = nullptr;
43 
45  double gSigmaX = 0.; // smear position along local x Axis
46  double gSigmaY = 0.; // smear position along local y Axis
47  double gSigmaZ = 0.; // smear position along local z Axis
48  double aSigmaX = 0.; // rotate around local x Axis
49  double aSigmaY = 0.; // rotate around local y Axis
50  double aSigmaZ = 0.; // rotate around local z Axis
51 
52  bool firstIovNominal = false;
53  };
54 
55  protected:
56  static void applyTransform(Acts::Transform3& trf, const Config& cfg,
57  RandomEngine& rng, unsigned int iov) {
58  std::normal_distribution<double> gauss(0., 1.);
59  if (iov != 0 or not cfg.firstIovNominal) {
60  // the shifts in x, y, z
61  double tx = cfg.gSigmaX != 0 ? cfg.gSigmaX * gauss(rng) : 0.;
62  double ty = cfg.gSigmaY != 0 ? cfg.gSigmaY * gauss(rng) : 0.;
63  double tz = cfg.gSigmaZ != 0 ? cfg.gSigmaZ * gauss(rng) : 0.;
64  // Add a translation - if there is any
65  if (tx != 0. or ty != 0. or tz != 0.) {
66  const auto& tMatrix = trf.matrix();
67  auto colX = tMatrix.block<3, 1>(0, 0).transpose();
68  auto colY = tMatrix.block<3, 1>(0, 1).transpose();
69  auto colZ = tMatrix.block<3, 1>(0, 2).transpose();
70  Acts::Vector3 newCenter = tMatrix.block<3, 1>(0, 3).transpose() +
71  tx * colX + ty * colY + tz * colZ;
72  trf.translation() = newCenter;
73  }
74  // now modify it - rotation around local X
75  if (cfg.aSigmaX != 0.) {
76  trf *=
77  Acts::AngleAxis3(cfg.aSigmaX * gauss(rng), Acts::Vector3::UnitX());
78  }
79  if (cfg.aSigmaY != 0.) {
80  trf *=
81  Acts::AngleAxis3(cfg.aSigmaY * gauss(rng), Acts::Vector3::UnitY());
82  }
83  if (cfg.aSigmaZ != 0.) {
84  trf *=
85  Acts::AngleAxis3(cfg.aSigmaZ * gauss(rng), Acts::Vector3::UnitZ());
86  }
87  }
88  }
89 };
90 } // namespace Contextual
91 } // namespace ActsExamples