ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParametricProcessGenerator.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParametricProcessGenerator.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 
11 #include <random>
12 
15 
18  : m_cfg(cfg),
19  m_charge(ActsFatras::findCharge(m_cfg.pdg)),
20  m_mass(ActsFatras::findMass(m_cfg.pdg)) {}
21 
22 std::vector<FW::SimVertex> FW::ParametricProcessGenerator::operator()(
23  FW::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[] = {m_charge, -m_charge};
41 
42  // create empty process vertex
43  SimVertex process(SimVertex::Vector4::Zero());
44 
45  // counter will be reused as barcode particle number which must be non-zero.
46  for (size_t ip = 1; ip <= m_cfg.numParticles; ++ip) {
47  const auto d0 = d0Dist(rng);
48  const auto z0 = z0Dist(rng);
49  const auto t0 = t0Dist(rng);
50  const auto phi = phiDist(rng);
51  const auto eta = etaDist(rng);
52  const auto pt = ptDist(rng);
53  const auto type = particleTypeChoice(rng);
54  const auto pdg = pdgChoices[type];
55  const auto q = qChoices[type];
56 
57  // all particles are treated as originating from the same primary vertex
58  const auto pid = ActsFatras::Barcode(0u).setParticle(ip);
59  // construct the particle;
60  ActsFatras::Particle particle(pid, pdg, q, m_mass);
61  particle.setPosition4(d0 * std::sin(phi), d0 * -std::cos(phi), z0, t0);
63  // TODO check abs p value
64  particle.setAbsMomentum(pt / std::cosh(eta));
65 
66  process.outgoing.push_back(std::move(particle));
67  }
68 
69  return {process};
70 }