Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PropagationAlgorithm.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PropagationAlgorithm.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 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 
17 
18 #include <stdexcept>
19 
20 namespace ActsExamples {
21 
23  const AlgorithmContext& context) const {
24  // Create a random number generator
26  m_cfg.randomNumberSvc->spawnGenerator(context);
27 
28  // Standard gaussian distribution for covarianmces
29  std::normal_distribution<double> gauss(0., 1.);
30 
31  // Setup random number distributions for some quantities
32  std::uniform_real_distribution<double> phiDist(m_cfg.phiRange.first,
33  m_cfg.phiRange.second);
34  std::uniform_real_distribution<double> etaDist(m_cfg.etaRange.first,
35  m_cfg.etaRange.second);
36  std::uniform_real_distribution<double> ptDist(m_cfg.ptRange.first,
37  m_cfg.ptRange.second);
38  std::uniform_real_distribution<double> qDist(0., 1.);
39 
40  std::shared_ptr<const Acts::PerigeeSurface> surface =
41  Acts::Surface::makeShared<Acts::PerigeeSurface>(
42  Acts::Vector3(0., 0., 0.));
43 
44  // Output : the propagation steps
45  std::vector<std::vector<Acts::detail::Step>> propagationSteps;
46  propagationSteps.reserve(m_cfg.ntests);
47 
48  // Output (optional): the recorded material
49  std::unordered_map<size_t, Acts::RecordedMaterialTrack> recordedMaterial;
50 
51  // loop over number of particles
52  for (size_t it = 0; it < m_cfg.ntests; ++it) {
54  double d0 = m_cfg.d0Sigma * gauss(rng);
55  double z0 = m_cfg.z0Sigma * gauss(rng);
56  double phi = phiDist(rng);
57  double eta = etaDist(rng);
58  double theta = 2 * std::atan(std::exp(-eta));
59  double pt = ptDist(rng);
60  double p = pt / std::sin(theta);
61  double charge = qDist(rng) > 0.5 ? 1. : -1.;
62  double qop = charge / p;
63  double t = m_cfg.tSigma * gauss(rng);
64  // parameters
66  pars << d0, z0, phi, theta, qop, t;
67  // some screen output
68 
69  // The covariance generation
70  auto cov = generateCovariance(rng, gauss);
71 
72  // execute the test for charged particles
73  Acts::BoundTrackParameters startParameters(surface, pars, std::move(cov),
75  Acts::Vector3 sPosition = startParameters.position(context.geoContext);
76  Acts::Vector3 sMomentum = startParameters.momentum();
77  PropagationOutput pOutput = m_cfg.propagatorImpl->execute(
78  context, m_cfg, logger(), startParameters);
79  // Record the propagator steps
80  propagationSteps.push_back(std::move(pOutput.first));
82  !pOutput.second.materialInteractions.empty()) {
83  // Create a recorded material track with start position, momentum and the
84  // material
85  recordedMaterial.emplace(
86  it, std::make_pair(std::make_pair(sPosition, sMomentum),
87  std::move(pOutput.second)));
88  }
89  }
90 
91  // Write the propagation step data to the event store
92  m_outpoutPropagationSteps(context, std::move(propagationSteps));
93 
94  // Write the recorded material to the event store
96  m_recordedMaterial(context, std::move(recordedMaterial));
97  }
98 
99  return ProcessCode::SUCCESS;
100 }
101 
102 std::optional<Acts::BoundSquareMatrix> PropagationAlgorithm::generateCovariance(
104  std::normal_distribution<double>& gauss) const {
106  // We start from the correlation matrix
108  // Then we draw errors according to the error values
109  Acts::BoundVector covs_smeared = m_cfg.covariances;
110  for (size_t k = 0; k < size_t(covs_smeared.size()); ++k) {
111  covs_smeared[k] *= gauss(rnd);
112  }
113  // and apply a double loop
114  for (size_t i = 0; i < size_t(newCov.rows()); ++i) {
115  for (size_t j = 0; j < size_t(newCov.cols()); ++j) {
116  (newCov)(i, j) *= covs_smeared[i];
117  (newCov)(i, j) *= covs_smeared[j];
118  }
119  }
120  return newCov;
121  }
122  return std::nullopt;
123 }
124 
127  : IAlgorithm("PropagationAlgorithm", level), m_cfg(config) {
128  if (!m_cfg.propagatorImpl) {
129  throw std::invalid_argument("Config needs to contain a propagator");
130  }
131  if (!m_cfg.randomNumberSvc) {
132  throw std::invalid_argument("No random number generator given");
133  }
134 
137 }
138 
139 } // namespace ActsExamples