Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MaterialEffectsEngine.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // MaterialEffectsEngine.cxx, (c) ATLAS Detector software
8 
9 // STL
10 #include <sstream>
11 // Trk include
13 #include "TrkGeometry/Layer.h"
14 
15 // constructor
16 Trk::MaterialEffectsEngine::MaterialEffectsEngine(const std::string& t, const std::string& n, const IInterface* p)
17 : AthAlgTool(t,n,p)
18 {
19  declareInterface<Trk::IMaterialEffectsEngine>(this);
20 }
21 
22 // destructor
24 = default;
25 
26 
27 // the interface method initialize
29 {
30  m_sopPrefix = m_sopPrefix_prop;
31  m_sopPostfix = m_sopPostfix_prop;
32 
33  EX_MSG_DEBUG( "", "initialize","", "successful" );
34  return StatusCode::SUCCESS;
35 }
36 
37 // the interface method finalize
39 {
40  EX_MSG_DEBUG( "", "finalize","", "successful" );
41  return StatusCode::SUCCESS;
42 }
43 
47  Trk::MaterialUpdateStage matupstage) const
48 {
49 
50  // the Extrapolator made sure that the layer is the lead layer && the parameters are the lead parameters
51  if (eCell.leadLayer && eCell.leadLayer->layerMaterialProperties()){
52  EX_MSG_DEBUG( ++eCell.navigationStep, "layer", eCell.leadLayer->layerIndex().value(), "handleMaterial for neutral parameters called - collect material.");
53  // now calculate the pathCorrection from the layer surface - it is signed, gives you the relative direction to the layer
54  const Trk::Layer* layer = eCell.leadLayer;
55  // path correction
56  double pathCorrection = layer->surfaceRepresentation().pathCorrection(eCell.leadParameters->position(),dir*(eCell.leadParameters->momentum()));
57  // the relative direction wrt with the layer
58  Trk::PropDirection rlDir = (pathCorrection >= 0. ? Trk::alongMomentum : Trk::oppositeMomentum);
59  // multiply by the pre-and post-update factor
60  double mFactor = layer->layerMaterialProperties()->factor(rlDir, matupstage);
61  if (mFactor == 0.){
62  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material collection with " << (matupstage > 0. ? "pre " : "post ") << "factor 0.");
63  // return the parameters untouched -
65  }
66  pathCorrection = mFactor*pathCorrection;
67  // screen output
68  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update with corr factor = " << pathCorrection);
69  // get the actual material bin
70  const Trk::MaterialProperties* materialProperties = layer->layerMaterialProperties()->fullMaterial(eCell.leadParameters->position());
71  // and let's check if there's acutally something to do
72  if (materialProperties && std::abs(pathCorrection)>0.){
73  // thickness in X0
74  double thicknessInX0 = materialProperties->thicknessInX0();
75  // check if material filling was requested
77  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "collecting material of [t/X0] = " << thicknessInX0);
78  eCell.stepMaterial(eCell.leadParameters->associatedSurface(), layer, eCell.leadParameters->position(), pathCorrection, materialProperties);
79  } else {
80  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "adding material of [t/X0] = " << thicknessInX0);
81  eCell.addMaterial(pathCorrection, materialProperties);
82  }
83  }
84  }
85  // only in case of post update it should not return InProgress
87 }
88 
89 
93  Trk::MaterialUpdateStage matupstage) const
94 {
95 
96  // the Extrapolator made sure that the layer is the lead layer && the parameters are the lead parameters
97  if (eCell.leadLayer && eCell.leadLayer->layerMaterialProperties()){
98  EX_MSG_DEBUG( ++eCell.navigationStep, "layer", eCell.leadLayer->layerIndex().value(), "handleMaterial for charged parameters called.");
99  // update the track parameters
100  eCell.leadParameters = updateTrackParameters(*eCell.leadParameters,eCell,dir,matupstage);
101  }
102  // only in case of post update it should not return InProgress
104 }
105 
108  Trk::ExCellCharged& eCell,
110  Trk::MaterialUpdateStage matupstage) const
111 {
112  // now calculate the pathCorrection from the layer surface - it is signed, gives you the relative direction to the layer
113  const Trk::Layer* layer = eCell.leadLayer;
114  // path correction
115  double pathCorrection = layer->surfaceRepresentation().pathCorrection(parameters.position(),dir*(parameters.momentum()));
116  // the relative direction wrt with the layer
117  Trk::PropDirection rlDir = (pathCorrection >= 0. ? Trk::alongMomentum : Trk::oppositeMomentum);
118  // multiply by the pre-and post-update factor
119  double mFactor = layer->layerMaterialProperties()->factor(rlDir, matupstage);
120  if (mFactor == 0.){
121  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update with " << (matupstage > 0. ? "pre " : "post ") << "factor 0. No update done.");
122  // return the parameters untouched -
123  return (&parameters);
124  }
125  pathCorrection = mFactor*pathCorrection;
126  // screen output
127  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update with corr factor = " << pathCorrection);
128  // get the actual material bin
129  const Trk::MaterialProperties* materialProperties = layer->layerMaterialProperties()->fullMaterial(parameters.position());
130  // and let's check if there's acutally something to do
131  if (materialProperties && std::abs(pathCorrection)>0. &&
132  ( m_eLossCorrection || m_mscCorrection || eCell.checkConfigurationMode(Trk::ExtrapolationMode::CollectMaterial)) ){
133  // and add them
134  int sign = int(eCell.materialUpdateMode);
135  // a simple cross-check if the parameters are the initial ones
136  AmgVector(5) uParameters = parameters.parameters();
137  std::unique_ptr<AmgSymMatrix(5)> uCovariance =
138  parameters.covariance()
139  ? std::make_unique<AmgSymMatrix(5)>(*parameters.covariance())
140  : nullptr;
141  // get the material itself & its parameters
142  const Trk::Material& material = materialProperties->material();
143  double thicknessInX0 = materialProperties->thicknessInX0();
144  double thickness = materialProperties->thickness();
145  // calculate energy loss and multiple scattering
146  double p = parameters.momentum().mag();
147  double m = Trk::ParticleMasses::mass[eCell.pHypothesis];
148  double E = sqrt(p*p+m*m);
149  double beta = p/E;
150  // (A) - energy loss correction
151  if (m_eLossCorrection){
152  double sigmaP = 0.;
153  double kazl = 0.;
155  double dEdl = sign*dir*Trk::MaterialInteraction::dEdl_ionization(p, material, eCell.pHypothesis, sigmaP, kazl);
156  double dE = thickness*pathCorrection*dEdl;
157  sigmaP *= thickness*pathCorrection;
158  // calcuate the new momentum
159  double newP = sqrt((E+dE)*(E+dE)-m*m);
160  uParameters[Trk::qOverP] = parameters.charge()/newP;
161  double sigmaDeltaE = thickness*pathCorrection*sigmaP;
162  double sigmaQoverP = sigmaDeltaE/std::pow(beta*p,2);
163  // update the covariance if needed
164  if (uCovariance)
165  (*uCovariance)(Trk::qOverP, Trk::qOverP) += sign*sigmaQoverP*sigmaQoverP;
166  }
167  // (B) - update the covariance if needed
168  if (uCovariance && m_mscCorrection){
170  double sigmaMS = Trk::MaterialInteraction::sigmaMS(thicknessInX0*pathCorrection, p, beta);
171  double sinTheta = sin(parameters.parameters()[Trk::theta]);
172  double sigmaDeltaPhiSq = sigmaMS*sigmaMS/(sinTheta*sinTheta);
173  double sigmaDeltaThetaSq = sigmaMS*sigmaMS;
174  // add or remove @TODO implement check for covariance matrix -> 0
175  (*uCovariance)(Trk::phi,Trk::phi) += sign*sigmaDeltaPhiSq;
176  (*uCovariance)(Trk::theta, Trk::theta) += sign*sigmaDeltaThetaSq;
177  }
178  // check if material filling was requested
180  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "collecting material of [t/X0] = " << thicknessInX0);
181  eCell.stepMaterial(parameters.associatedSurface(), layer, parameters.position(), pathCorrection, materialProperties);
182  } else {
183  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "adding material of [t/X0] = " << thicknessInX0);
184  eCell.addMaterial(pathCorrection, materialProperties);
185  }
186  // now either create new ones or update - only start parameters can not be updated
187  if (eCell.leadParameters != eCell.startParameters ){
188  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update on non-initial parameters.");
189  if (uCovariance)
190  parameters.updateParameters(uParameters,*uCovariance);
191  else
192  parameters.updateParameters(uParameters);
193  } else {
194  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update on initial parameters, creating new ones.");
195  // create new parameters
196  const Trk::Surface& tSurface = parameters.associatedSurface();
197  Trk::TrackParameters* tParameters = tSurface.createUniqueTrackParameters(uParameters[Trk::loc1],
198  uParameters[Trk::loc2],
199  uParameters[Trk::phi],
200  uParameters[Trk::theta],
201  uParameters[Trk::qOverP],
202  *uCovariance).release();
203  // these are newly created
204  return tParameters;
205  }
206  }
207  //note aliasing input ...
208  return (&parameters);
209 }
Trk::MaterialEffectsEngine::MaterialEffectsEngine
MaterialEffectsEngine(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: MaterialEffectsEngine.cxx:16
Trk::MaterialInteraction::dEdl_ionization
static double dEdl_ionization(double p, const Material &mat, ParticleHypothesis particle, double &sigma, double &kazL)
dE/dl ionization energy loss per path unit
Definition: MaterialInteraction.cxx:117
Trk::MaterialInteraction::sigmaMS
static double sigmaMS(double dInX0, double p, double beta)
multiple scattering as function of dInX0
Definition: MaterialInteraction.cxx:278
Trk::MaterialUpdateStage
MaterialUpdateStage
This is a steering enum to tell which material update stage:
Definition: PropDirection.h:40
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
Trk::oppositeMomentum
@ oppositeMomentum
Definition: PropDirection.h:21
Trk::ExtrapolationCell::pHypothesis
ParticleHypothesis pHypothesis
what particle hypothesis to be used, default : pion
Definition: ExtrapolationCell.h:279
Trk::MaterialProperties::thicknessInX0
float thicknessInX0() const
Return the radiationlength fraction.
Trk::loc2
@ loc2
generic first and second local coordinate
Definition: ParamDefs.h:35
Layer.h
Trk::ExtrapolationCell::stepMaterial
void stepMaterial(const Surface &sf, const Layer *lay, const Amg::Vector3D &position, double sfactor, const MaterialProperties *mprop=nullptr)
fill or attach material, jacobian, step length
Definition: ExtrapolationCell.h:637
Trk::alongMomentum
@ alongMomentum
Definition: PropDirection.h:20
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Trk::MaterialProperties::material
const Material & material() const
Return the stored Material.
Trk::MaterialEffectsEngine::updateTrackParameters
TrackParameters * updateTrackParameters(Trk::TrackParameters &parameters, Trk::ExCellCharged &eCell, Trk::PropDirection dir, Trk::MaterialUpdateStage matupstage) const
charged extrapolation
Definition: MaterialEffectsEngine.cxx:107
Trk::ExtrapolationCell::leadLayer
const Layer * leadLayer
the lead Layer - carrying the navigation stream
Definition: ExtrapolationCell.h:249
Trk::MaterialEffectsEngine::handleMaterial
virtual ExtrapolationCode handleMaterial(ExCellCharged &ecCharged, PropDirection dir=alongMomentum, MaterialUpdateStage matupstage=fullUpdate) const
charged extrapolation
Definition: MaterialEffectsEngine.cxx:91
Trk::MaterialEffectsEngine::~MaterialEffectsEngine
~MaterialEffectsEngine()
Destructor.
Trk::MaterialProperties::thickness
float thickness() const
Return the thickness in mm.
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
Trk::ExtrapolationCell::navigationStep
int navigationStep
a counter of the navigation Step
Definition: ExtrapolationCell.h:268
Trk::PropDirection
PropDirection
Definition: PropDirection.h:19
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
MaterialEffectsEngine.h
Trk::Surface::createUniqueTrackParameters
virtual ChargedTrackParametersUniquePtr createUniqueTrackParameters(double l1, double l2, double phi, double theat, double qop, std::optional< AmgSymMatrix(5)> cov=std::nullopt) const =0
Use the Surface as a ParametersBase constructor, from local parameters - charged.
beamspotman.n
n
Definition: beamspotman.py:731
Trk::theta
@ theta
Definition: ParamDefs.h:66
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
python.LArMinBiasAlgConfig.int
int
Definition: LArMinBiasAlgConfig.py:59
Trk::ExtrapolationCode
Definition: ExtrapolationCell.h:105
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:107
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::ExtrapolationCell::startParameters
T * startParameters
by reference - need to be defined
Definition: ExtrapolationCell.h:233
Trk::LayerIndex::value
int value() const
layerIndex expressed in an integer
Definition: LayerIndex.h:71
Trk::ExtrapolationCell::checkConfigurationMode
bool checkConfigurationMode(ExtrapolationMode::eMode em) const
check the configuration mode
Definition: ExtrapolationCell.h:352
beamspotman.dir
string dir
Definition: beamspotman.py:623
Trk::ParticleMasses::mass
constexpr double mass[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:53
Trk::ExtrapolationCell::materialUpdateMode
MaterialUpdateMode materialUpdateMode
how to deal with the material effect, default: addNoise
Definition: ExtrapolationCell.h:282
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
Trk::ExtrapolationMode::CollectMaterial
@ CollectMaterial
Definition: ExtrapolationCell.h:59
EX_MSG_DEBUG
#define EX_MSG_DEBUG(navstep, step, idx, x)
Definition: ExtrapolationMacros.h:13
EX_MSG_VERBOSE
#define EX_MSG_VERBOSE(navstep, step, idx, x)
Definition: ExtrapolationMacros.h:14
Trk::MaterialProperties
Definition: MaterialProperties.h:40
Trk::ExtrapolationCell
Definition: ExtrapolationCell.h:231
Trk::ExtrapolationCell::addMaterial
void addMaterial(double sfactor, const MaterialProperties *mprop=nullptr)
fill or attach material, jacobian, step length
Definition: ExtrapolationCell.h:606
Trk::ExtrapolationCell::leadParameters
T * leadParameters
the one last truely valid parameter in the stream
Definition: ExtrapolationCell.h:246
Trk::MaterialEffectsEngine::initialize
StatusCode initialize()
AlgTool initialize method.
Definition: MaterialEffectsEngine.cxx:28
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:67
Trk::Layer::layerMaterialProperties
const LayerMaterialProperties * layerMaterialProperties() const
getting the LayerMaterialProperties including full/pre/post update
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
Trk::phi
@ phi
Definition: ParamDefs.h:75
Trk::Material
Definition: Material.h:116
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
AthAlgTool
Definition: AthAlgTool.h:26
MuonParameters::beta
@ beta
Definition: MuonParamDefs.h:144
Trk::loc1
@ loc1
Definition: ParamDefs.h:34
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
Trk::MaterialEffectsEngine::finalize
StatusCode finalize()
AlgTool finalize method.
Definition: MaterialEffectsEngine.cxx:38
Trk::ExtrapolationCode::InProgress
@ InProgress
Definition: ExtrapolationCell.h:111
Trk::Layer
Definition: Layer.h:73
Trk::Layer::layerIndex
const LayerIndex & layerIndex() const
get the layerIndex