ATLAS Offline Software
MultipleScatteringUpdator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // MultipleScatteringUpdator.cxx, (c) ATLAS Detector software
8 
9 // Trk include
12 // CLHEP
13 
16 #include "GaudiKernel/ThreadLocalContext.h"
17 #include "CLHEP/Random/RandFlat.h"
19 
20 namespace{
21 // static doubles
22 constexpr double s_main_RutherfordScott = 13.6 * Gaudi::Units::MeV;
23 constexpr double s_log_RutherfordScott = 0.038;
24 
25 constexpr double s_main_RossiGreisen = 17.5 * Gaudi::Units::MeV;
26 constexpr double s_log_RossiGreisen = 0.125;
27 
28 // ============================= Gaussian mixture model =============
29 constexpr double s_gausMixSigma1_a0 = 8.471e-1;
30 constexpr double s_gausMixSigma1_a1 = 3.347e-2;
31 constexpr double s_gausMixSigma1_a2 = -1.843e-3;
32 
33 constexpr double s_gausMixEpsilon_a0 = 4.841e-2;
34 constexpr double s_gausMixEpsilon_a1 = 6.348e-3;
35 constexpr double s_gausMixEpsilon_a2 = 6.096e-4;
36 
37 constexpr double s_gausMixEpsilon_b0 = -1.908e-2;
38 constexpr double s_gausMixEpsilon_b1 = 1.106e-1;
39 constexpr double s_gausMixEpsilon_b2 = -5.729e-3;
40 }
41 
42 
43 // constructor
44 Trk::MultipleScatteringUpdator::MultipleScatteringUpdator(const std::string &t, const std::string &n,
45  const IInterface *p) :
46  AthAlgTool(t, n, p),
47  m_useTrkUtils(true),
48  m_log_include(true),
49  m_gaussianMixture(false),
50  m_optGaussianMixtureG4(true),
51  m_rndGenSvc("AthRNGSvc", n),
52  m_rngWrapper(nullptr),
53  m_randomEngineName("TrkExRnd") {
54  declareInterface<IMultipleScatteringUpdator>(this);
55  // multiple scattering parameters
56  declareProperty("UseTrkUtils", m_useTrkUtils);
57  declareProperty("MultipleScatteringLogarithmicTermOn", m_log_include);
58  declareProperty("GaussianMixtureModel", m_gaussianMixture);
59  declareProperty("G4OptimisedGaussianMixtureModel", m_optGaussianMixtureG4);
60  // random service for Gaussian mixture model
61  declareProperty("RandomNumberService", m_rndGenSvc, "Name of the random number service");
62  declareProperty("RandomStreamName", m_randomEngineName, "Name of the random number stream");
63 }
64 
65 // destructor
67 
68 // Athena standard methods
69 // initialize
72  // if Gaussian mixture is required
73  if (m_gaussianMixture) {
74  // get the random generator service
75  if (m_rndGenSvc.retrieve().isFailure()) {
76  ATH_MSG_WARNING("Could not retrieve " << m_rndGenSvc << " -> switching Gaussian mixture model off.");
77  m_gaussianMixture = false;
78  } else {
79  ATH_MSG_VERBOSE("Successfully retrieved " << m_rndGenSvc);
80  }
81 
82  // Get own engine with own seeds:
83  m_rngWrapper = m_gaussianMixture ? m_rndGenSvc->getEngine(this, m_randomEngineName) : nullptr;
84  if (!m_rngWrapper) {
86  "Could not get random engine '" << m_randomEngineName << "' -> switching Gaussian mixture model off.");
87  m_gaussianMixture = false;
88  }
89  }
90  if (m_gaussianMixture) {
91  ATH_MSG_VERBOSE("Gaussian mixture model = ON ... optimised = " << m_optGaussianMixtureG4);
92  } else {
93  ATH_MSG_VERBOSE("Gaussian mixture model = OFF");
94  }
95 
96  return StatusCode::SUCCESS;
97 }
98 
99 double
101  double p,
102  double pathcorrection,
104  double) const {
105  if (mat.thicknessInX0() <= 0. || particle == Trk::geantino) {
106  return 0.;
107  }
108 
109  // make sure the path correction is positive to avoid a floating point exception
110  pathcorrection *= pathcorrection < 0. ? (-1.) : (1);
111 
112  // scale the path length to the radiation length
113  double t = pathcorrection * mat.thicknessInX0();
114 
115  // kinematics (relativistic)
117  double E = sqrt(p * p + m * m);
118  double beta = p / E;
119 
120  double sigma2(0.);
121 
123  sigma2 = sigma * sigma;
124 
125  if (m_useTrkUtils && particle != Trk::electron) {
126  return sigma2;
127  }
128 
129 // Code below will not be used if the parameterization of TrkUtils is used
130 
131 
132  if (particle != Trk::electron) {
133  // the highland formula
134  sigma2 = s_main_RutherfordScott / (beta * p);
135 
136  if (m_log_include) {
137  sigma2 *= (1. + s_log_RutherfordScott * log(t));
138  }
139 
140  sigma2 *= (sigma2 * t);
141  }else {
142  // Electron multiple scattering effects - see Highland NIM 129 (1975) p497-499
143  // (Highland extension to the Rossi-Greisen formulation)
144  // NOTE: The formula can be extended by replacing the momentum^2 term with pi * pf
145  sigma2 = s_main_RossiGreisen / (beta * p);
146  sigma2 *= (sigma2 * t);
147 
148  if (m_log_include) {
149  double factor = 1. + s_log_RossiGreisen * log10(10. * t);
150  factor *= factor;
151  sigma2 *= factor;
152  }
153  }
154 
155  // use the Gaussian mixture model
156  if (m_gaussianMixture) {
157  // Reseed the RNG if needed.
158  const EventContext& ctx = Gaudi::Hive::currentContext();
159  if (m_rngWrapper->evtSeeded(ctx) != ctx.evt()) {
160  // Ok, the wrappers are unique to this algorithm and a given slot,
161  // so cannot be accessed concurrently.
162  ATHRNG::RNGWrapper* wrapper_nc ATLAS_THREAD_SAFE = m_rngWrapper;
163  wrapper_nc->setSeed (this->name(), ctx);
164  }
165  CLHEP::HepRandomEngine* engine = m_rngWrapper->getEngine (ctx);
166  // d_0'
167  double dprime = t / (beta * beta);
168  double log_dprime = log(dprime);
169  // d_0''
170  double log_dprimeprime = log(std::pow(mat.averageZ(), 2.0 / 3.0) * dprime);
171  // get epsilon
172  double epsilon = log_dprimeprime < 0.5 ?
173  s_gausMixEpsilon_a0 + s_gausMixEpsilon_a1 * log_dprimeprime + s_gausMixEpsilon_a2 *
174  log_dprimeprime * log_dprimeprime :
175  s_gausMixEpsilon_b0 + s_gausMixEpsilon_b1 * log_dprimeprime + s_gausMixEpsilon_b2 *
176  log_dprimeprime * log_dprimeprime;
177  // the standard sigma
178  double sigma1square = s_gausMixSigma1_a0 + s_gausMixSigma1_a1 * log_dprime + s_gausMixSigma1_a2 * log_dprime *
179  log_dprime;
180  // G4 optimised / native double Gaussian model
181  if (!m_optGaussianMixtureG4) {
182  sigma2 = 225. * dprime / (p * p);
183  }
184  // throw the random number core/tail
185  if (CLHEP::RandFlat::shoot(engine) < epsilon) {
186  sigma2 *= (1. - (1. - epsilon) * sigma1square) / epsilon;
187  }
188  }
189 
190  return sigma2;
191 }
Trk::MultipleScatteringUpdator::m_gaussianMixture
bool m_gaussianMixture
mainly for Fatras
Definition: MultipleScatteringUpdator.h:69
Trk::MultipleScatteringUpdator::m_useTrkUtils
bool m_useTrkUtils
use eloss parametrisation from TrkUtils MaterialInterAction.h
Definition: MultipleScatteringUpdator.h:67
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
Trk::MaterialInteraction::sigmaMS
static double sigmaMS(double dInX0, double p, double beta)
multiple scattering as function of dInX0
Definition: MaterialInteraction.cxx:278
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
Trk::MultipleScatteringUpdator::MultipleScatteringUpdator
MultipleScatteringUpdator(const std::string &, const std::string &, const IInterface *)
AlgTool like constructor.
Definition: MultipleScatteringUpdator.cxx:44
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
Trk::MultipleScatteringUpdator::m_rndGenSvc
ServiceHandle< IAthRNGSvc > m_rndGenSvc
Random Generator service
Definition: MultipleScatteringUpdator.h:74
Trk::MultipleScatteringUpdator::initialize
virtual StatusCode initialize() override
AlgTool initailize method.
Definition: MultipleScatteringUpdator.cxx:71
MaterialProperties.h
MultipleScatteringUpdator.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:55
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::MultipleScatteringUpdator::m_log_include
bool m_log_include
boolean switch to include log term
Definition: MultipleScatteringUpdator.h:68
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:25
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::electron
@ electron
Definition: ParticleHypothesis.h:27
Trk::geantino
@ geantino
Definition: ParticleHypothesis.h:26
Trk::MultipleScatteringUpdator::m_optGaussianMixtureG4
bool m_optGaussianMixtureG4
modifies the Fruehwirth/Regler model to fit with G4
Definition: MultipleScatteringUpdator.h:70
Trk::MultipleScatteringUpdator::~MultipleScatteringUpdator
virtual ~MultipleScatteringUpdator()
Virtual destructor.
Trk::ParticleMasses::mass
constexpr double mass[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:53
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
MaterialInteraction.h
RNGWrapper.h
Trk::MultipleScatteringUpdator::m_randomEngineName
std::string m_randomEngineName
Name of the random number stream.
Definition: MultipleScatteringUpdator.h:77
Trk::MaterialProperties
Definition: MaterialProperties.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
AthAlgTool
Definition: AthAlgTool.h:26
MuonParameters::beta
@ beta
Definition: MuonParamDefs.h:144
checker_macros.h
Define macros for attributes used to control the static checker.
Trk::MultipleScatteringUpdator::sigmaSquare
virtual double sigmaSquare(const MaterialProperties &mat, double p, double pathcorrection, ParticleHypothesis particle=pion, double deltaE=0.) const override
Calculate the sigma on theta introduced by multiple scattering, according to the RutherFord-Scott For...
Definition: MultipleScatteringUpdator.cxx:100