Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GaussianMixture.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GaussianMixture.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-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 
9 #pragma once
10 
12 
13 #include <random>
14 
15 namespace ActsFatras {
16 namespace detail {
17 
21  bool optGaussianMixtureG4 = false;
22  double gausMixSigma1_a0 = 8.471e-1;
23  double gausMixSigma1_a1 = 3.347e-2;
24  double gausMixSigma1_a2 = -1.843e-3;
25  double gausMixEpsilon_a0 = 4.841e-2;
26  double gausMixEpsilon_a1 = 6.348e-3;
27  double gausMixEpsilon_a2 = 6.096e-4;
28  double gausMixEpsilon_b0 = -1.908e-2;
29  double gausMixEpsilon_b1 = 1.106e-1;
30  double gausMixEpsilon_b2 = -5.729e-3;
31 
40  template <typename generator_t>
41  double operator()(generator_t &generator, const Acts::MaterialSlab &slab,
42  Particle &particle) const {
45  slab, particle.absolutePdg(), particle.mass(), particle.qOverP(),
46  particle.absoluteCharge());
47  double sigma2 = sigma * sigma;
48 
49  // Gauss distribution, will be sampled with generator
50  std::normal_distribution<double> gaussDist(0., 1.);
51  // Uniform distribution, will be sampled with generator
52  std::uniform_real_distribution<double> uniformDist(0., 1.);
53 
54  // Now correct for the tail fraction
55  // d_0'
56  // beta² = (p/E)² = p²/(p² + m²) = 1/(1 + (m/p)²)
57  // 1/beta² = 1 + (m/p)²
58  double mOverP = particle.mass() / particle.absoluteMomentum();
59  double beta2inv = 1 + mOverP * mOverP;
60  double dprime = slab.thicknessInX0() * beta2inv;
61  double log_dprime = std::log(dprime);
62  // d_0''
63  double log_dprimeprime =
64  std::log(std::pow(slab.material().Z(), 2.0 / 3.0) * dprime);
65 
66  // get epsilon
67  double epsilon =
68  log_dprimeprime < 0.5
69  ? gausMixEpsilon_a0 + gausMixEpsilon_a1 * log_dprimeprime +
70  gausMixEpsilon_a2 * log_dprimeprime * log_dprimeprime
71  : gausMixEpsilon_b0 + gausMixEpsilon_b1 * log_dprimeprime +
72  gausMixEpsilon_b2 * log_dprimeprime * log_dprimeprime;
73 
74  // the standard sigma
75  double sigma1square = gausMixSigma1_a0 + gausMixSigma1_a1 * log_dprime +
76  gausMixSigma1_a2 * log_dprime * log_dprime;
77 
78  // G4 optimised / native double Gaussian model
80  sigma2 = 225. * dprime /
81  (particle.absoluteMomentum() * particle.absoluteMomentum());
82  }
83  // throw the random number core/tail
84  if (uniformDist(generator) < epsilon) {
85  sigma2 *= (1. - (1. - epsilon) * sigma1square) / epsilon;
86  }
87  // return back to the
88  return M_SQRT2 * std::sqrt(sigma2) * gaussDist(generator);
89  }
90 };
91 
92 } // namespace detail
93 } // namespace ActsFatras