EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParametricParticleGenerator.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParametricParticleGenerator.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2020 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 
13 
14 #include <random>
15 
17  const Config& cfg)
18  : m_cfg(cfg),
19  m_charge(ActsFatras::findCharge(m_cfg.pdg)),
20  m_mass(ActsFatras::findMass(m_cfg.pdg)) {}
21 
23 operator()(RandomEngine& rng) const {
24  using UniformReal = std::uniform_real_distribution<double>;
25  using UniformIndex = std::uniform_int_distribution<size_t>;
26 
27  UniformReal d0Dist(m_cfg.d0Range[0], m_cfg.d0Range[1]);
28  UniformReal z0Dist(m_cfg.z0Range[0], m_cfg.z0Range[1]);
29  UniformReal t0Dist(m_cfg.t0Range[0], m_cfg.t0Range[1]);
30  UniformReal phiDist(m_cfg.phiRange[0], m_cfg.phiRange[1]);
31  UniformReal etaDist(m_cfg.etaRange[0], m_cfg.etaRange[1]);
32  UniformReal ptDist(m_cfg.ptRange[0], m_cfg.ptRange[1]);
33  // choose between particle/anti-particle if requested
34  UniformIndex particleTypeChoice(0u, m_cfg.randomizeCharge ? 1u : -0u);
35  // (anti-)particle choice is one random draw but defines two properties
36  const Acts::PdgParticle pdgChoices[] = {
37  m_cfg.pdg,
38  static_cast<Acts::PdgParticle>(-m_cfg.pdg),
39  };
40  const double qChoices[] = {
41  m_charge,
42  -m_charge,
43  };
44 
45  SimParticleContainer particles;
46  particles.reserve(m_cfg.numParticles);
47 
48  // counter will be reused as barcode particle number which must be non-zero.
49  for (size_t ip = 1; ip <= m_cfg.numParticles; ++ip) {
50  const auto d0 = d0Dist(rng);
51  const auto z0 = z0Dist(rng);
52  const auto t0 = t0Dist(rng);
53  const auto phi = phiDist(rng);
54  const auto eta = etaDist(rng);
55  const auto pt = ptDist(rng);
56  const auto type = particleTypeChoice(rng);
57  const auto pdg = pdgChoices[type];
58  const auto q = qChoices[type];
59 
60  // all particles are treated as originating from the same primary vertex
61  const auto pid = ActsFatras::Barcode(0u).setParticle(ip);
62  // construct the particle;
63  ActsFatras::Particle particle(pid, pdg, q, m_mass);
64  particle.setPosition4(d0 * std::sin(phi), d0 * -std::cos(phi), z0, t0);
66  // see e.g. https://en.wikipedia.org/wiki/Pseudorapidity
67  particle.setAbsMomentum(pt / std::cosh(eta));
68 
69  // generated particle ids are already ordered and should end up at the end
70  particles.insert(particles.end(), std::move(particle));
71  }
72 
73  return particles;
74 }