Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleGunOptions.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParticleGunOptions.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-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 
16 
17 #include <boost/program_options.hpp>
18 
20  using boost::program_options::bool_switch;
22 
23  auto opt = desc.add_options();
24  opt("gen-vertex-xy-std-mm", value<double>()->default_value(0.0),
25  "Transverse vertex standard deviation in mm");
26  opt("gen-vertex-z-std-mm", value<double>()->default_value(0.0),
27  "Longitudinal vertex standard deviation in mm");
28  opt("gen-vertex-t-std-ns", value<double>()->default_value(0.0),
29  "Temporal vertex standard deviation in ns");
30  opt("gen-phi-degree",
31  value<Interval>()->value_name("MIN:MAX")->default_value({-180.0, 180.0}),
32  "Transverse direction angle generation range in degree");
33  opt("gen-eta",
34  value<Interval>()->value_name("MIN:MAX")->default_value({-4.0, 4.0}),
35  "Pseudo-rapidity generation range");
36  opt("gen-eta-uniform", bool_switch(),
37  "Sample eta directly and not cos(theta).");
38  opt("gen-mom-gev",
39  value<Interval>()->value_name("MIN:MAX")->default_value({1.0, 10.0}),
40  "Absolute (or transverse) momentum generation range in GeV");
41  opt("gen-mom-transverse", bool_switch(),
42  "Momentum referse to transverse momentum");
43  opt("gen-pdg", value<int32_t>()->default_value(Acts::PdgParticle::eMuon),
44  "PDG number of the particle, will be adjusted for charge flip.");
45  opt("gen-randomize-charge", bool_switch(),
46  "Flip the charge and change the PDG number accordingly.");
47  opt("gen-nparticles", value<size_t>()->default_value(1u),
48  "Number of generated particles per vertex");
49  opt("gen-nvertices", value<size_t>()->default_value(1u),
50  "Number of generated vertices");
51 }
52 
55  using namespace Acts::UnitLiterals;
56 
57  // access user config w/ unit conversion
58  auto getValue = [&](const char* name, auto unit) {
59  return vars[name].as<double>() * unit;
60  };
61  auto getRange = [&](const char* name, auto unit, auto& lower, auto& upper) {
62  auto interval = vars[name].as<Options::Interval>();
63  lower = interval.lower.value() * unit;
64  upper = interval.upper.value() * unit;
65  };
66 
67  auto vertexGen = std::make_shared<GaussianVertexGenerator>();
68  vertexGen->stddev[Acts::ePos0] = getValue("gen-vertex-xy-std-mm", 1_mm);
69  vertexGen->stddev[Acts::ePos1] = getValue("gen-vertex-xy-std-mm", 1_mm);
70  vertexGen->stddev[Acts::ePos2] = getValue("gen-vertex-z-std-mm", 1_mm);
71  vertexGen->stddev[Acts::eTime] = getValue("gen-vertex-t-std-ns", 1_ns);
72 
74  getRange("gen-phi-degree", 1_degree, pgCfg.phiMin, pgCfg.phiMax);
75  // user config sets eta but the generator takes theta
76  double etaMin = 0, etaMax = 0;
77  getRange("gen-eta", 1.0, etaMin, etaMax);
78 
79  pgCfg.etaUniform = vars["gen-eta-uniform"].template as<bool>();
80  pgCfg.thetaMin = 2 * std::atan(std::exp(-etaMin));
81  pgCfg.thetaMax = 2 * std::atan(std::exp(-etaMax));
82  getRange("gen-mom-gev", 1_GeV, pgCfg.pMin, pgCfg.pMax);
83  pgCfg.pTransverse = vars["gen-mom-transverse"].template as<bool>();
84  pgCfg.pdg =
85  static_cast<Acts::PdgParticle>(vars["gen-pdg"].template as<int32_t>());
86  pgCfg.randomizeCharge = vars["gen-randomize-charge"].template as<bool>();
87  pgCfg.numParticles = vars["gen-nparticles"].as<size_t>();
88 
89  if (pgCfg.numParticles > std::pow(2, ActsFatras::Barcode::bits(2))) {
90  throw std::runtime_error{
91  "Too many particles per vertex requested for Fatras Barcode"};
92  }
93 
94  size_t nVertices = vars["gen-nvertices"].as<size_t>();
95 
96  if (nVertices > std::pow(2, ActsFatras::Barcode::bits(0))) {
97  throw std::runtime_error{"Too many vertices requested for Fatras Barcode"};
98  }
99 
100  auto mGen = std::make_shared<FixedMultiplicityGenerator>();
101  mGen->n = nVertices;
102 
104  cfg.generators = {
105  {std::move(mGen), std::move(vertexGen),
106  std::make_shared<ParametricParticleGenerator>(pgCfg)},
107  };
108 
109  return cfg;
110 }