ATLAS Offline Software
Loading...
Searching...
No Matches
MaterialEffectsEngine.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// MaterialEffectsEngine.cxx, (c) ATLAS Detector software
8
9
10// Trk include
12#include "TrkGeometry/Layer.h"
13// STL
14#include <sstream>
15
16// constructor
17Trk::MaterialEffectsEngine::MaterialEffectsEngine(const std::string& t, const std::string& n, const IInterface* p)
18: AthAlgTool(t,n,p)
19{
20 declareInterface<Trk::IMaterialEffectsEngine>(this);
21}
22
23// destructor
25= default;
26
27
28// the interface method initialize
30{
33
34 EX_MSG_DEBUG( "", "initialize","", "successful" );
35 return StatusCode::SUCCESS;
36}
37
38// the interface method finalize
40{
41 EX_MSG_DEBUG( "", "finalize","", "successful" );
42 return StatusCode::SUCCESS;
43}
44
48 Trk::MaterialUpdateStage matupstage) const
49{
50
51 // the Extrapolator made sure that the layer is the lead layer && the parameters are the lead parameters
52 if (eCell.leadLayer && eCell.leadLayer->layerMaterialProperties()){
53 EX_MSG_DEBUG( ++eCell.navigationStep, "layer", eCell.leadLayer->layerIndex().value(), "handleMaterial for neutral parameters called - collect material.");
54 // now calculate the pathCorrection from the layer surface - it is signed, gives you the relative direction to the layer
55 const Trk::Layer* layer = eCell.leadLayer;
56 // path correction
57 double pathCorrection = layer->surfaceRepresentation().pathCorrection(eCell.leadParameters->position(),dir*(eCell.leadParameters->momentum()));
58 // the relative direction wrt with the layer
59 Trk::PropDirection rlDir = (pathCorrection >= 0. ? Trk::alongMomentum : Trk::oppositeMomentum);
60 // multiply by the pre-and post-update factor
61 double mFactor = layer->layerMaterialProperties()->factor(rlDir, matupstage);
62 if (mFactor == 0.){
63 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material collection with " << (matupstage > 0. ? "pre " : "post ") << "factor 0.");
64 // return the parameters untouched -
66 }
67 pathCorrection = mFactor*pathCorrection;
68 // screen output
69 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update with corr factor = " << pathCorrection);
70 // get the actual material bin
71 const Trk::MaterialProperties* materialProperties = layer->layerMaterialProperties()->fullMaterial(eCell.leadParameters->position());
72 // and let's check if there's acutally something to do
73 if (materialProperties && std::abs(pathCorrection)>0.){
74 // thickness in X0
75 double thicknessInX0 = materialProperties->thicknessInX0();
76 // check if material filling was requested
78 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "collecting material of [t/X0] = " << thicknessInX0);
79 eCell.stepMaterial(eCell.leadParameters->associatedSurface(), layer, eCell.leadParameters->position(), pathCorrection, materialProperties);
80 } else {
81 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "adding material of [t/X0] = " << thicknessInX0);
82 eCell.addMaterial(pathCorrection, materialProperties);
83 }
84 }
85 }
86 // only in case of post update it should not return InProgress
88}
89
90
94 Trk::MaterialUpdateStage matupstage) const
95{
96
97 // the Extrapolator made sure that the layer is the lead layer && the parameters are the lead parameters
98 if (eCell.leadLayer && eCell.leadLayer->layerMaterialProperties()){
99 EX_MSG_DEBUG( ++eCell.navigationStep, "layer", eCell.leadLayer->layerIndex().value(), "handleMaterial for charged parameters called.");
100 // update the track parameters
101 eCell.leadParameters = updateTrackParameters(*eCell.leadParameters,eCell,dir,matupstage);
102 }
103 // only in case of post update it should not return InProgress
105}
106
109 Trk::ExCellCharged& eCell,
111 Trk::MaterialUpdateStage matupstage) const
112{
113 // now calculate the pathCorrection from the layer surface - it is signed, gives you the relative direction to the layer
114 const Trk::Layer* layer = eCell.leadLayer;
115 // path correction
116 double pathCorrection = layer->surfaceRepresentation().pathCorrection(parameters.position(),dir*(parameters.momentum()));
117 // the relative direction wrt with the layer
118 Trk::PropDirection rlDir = (pathCorrection >= 0. ? Trk::alongMomentum : Trk::oppositeMomentum);
119 // multiply by the pre-and post-update factor
120 double mFactor = layer->layerMaterialProperties()->factor(rlDir, matupstage);
121 if (mFactor == 0.){
122 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update with " << (matupstage > 0. ? "pre " : "post ") << "factor 0. No update done.");
123 // return the parameters untouched -
124 return (&parameters);
125 }
126 pathCorrection = mFactor*pathCorrection;
127 // screen output
128 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update with corr factor = " << pathCorrection);
129 // get the actual material bin
130 const Trk::MaterialProperties* materialProperties = layer->layerMaterialProperties()->fullMaterial(parameters.position());
131 // and let's check if there's acutally something to do
132 if (materialProperties && std::abs(pathCorrection)>0. &&
134 // and add them
135 int sign = int(eCell.materialUpdateMode);
136 // a simple cross-check if the parameters are the initial ones
137 AmgVector(5) uParameters = parameters.parameters();
138 std::unique_ptr<AmgSymMatrix(5)> uCovariance =
139 parameters.covariance()
140 ? std::make_unique<AmgSymMatrix(5)>(*parameters.covariance())
141 : nullptr;
142 // get the material itself & its parameters
143 const Trk::Material& material = materialProperties->material();
144 double thicknessInX0 = materialProperties->thicknessInX0();
145 double thickness = materialProperties->thickness();
146 // calculate energy loss and multiple scattering
147 double p = parameters.momentum().mag();
148 double m = Trk::ParticleMasses::mass[eCell.pHypothesis];
149 double E = sqrt(p*p+m*m);
150 double beta = p/E;
151 // (A) - energy loss correction
153 double sigmaP = 0.;
154 double kazl = 0.;
156 double dEdl = sign*dir*Trk::MaterialInteraction::dEdl_ionization(p, material, eCell.pHypothesis, sigmaP, kazl);
157 double dE = thickness*pathCorrection*dEdl;
158 sigmaP *= thickness*pathCorrection;
159 // calcuate the new momentum
160 double newP = sqrt((E+dE)*(E+dE)-m*m);
161 uParameters[Trk::qOverP] = parameters.charge()/newP;
162 double sigmaDeltaE = thickness*pathCorrection*sigmaP;
163 double sigmaQoverP = sigmaDeltaE/std::pow(beta*p,2);
164 // update the covariance if needed
165 if (uCovariance)
166 (*uCovariance)(Trk::qOverP, Trk::qOverP) += sign*sigmaQoverP*sigmaQoverP;
167 }
168 // (B) - update the covariance if needed
169 if (uCovariance && m_mscCorrection){
171 double sigmaMS = Trk::MaterialInteraction::sigmaMS(thicknessInX0*pathCorrection, p, beta);
172 double sinTheta = sin(parameters.parameters()[Trk::theta]);
173 double sigmaDeltaPhiSq = sigmaMS*sigmaMS/(sinTheta*sinTheta);
174 double sigmaDeltaThetaSq = sigmaMS*sigmaMS;
175 // add or remove @TODO implement check for covariance matrix -> 0
176 (*uCovariance)(Trk::phi,Trk::phi) += sign*sigmaDeltaPhiSq;
177 (*uCovariance)(Trk::theta, Trk::theta) += sign*sigmaDeltaThetaSq;
178 }
179 // check if material filling was requested
181 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "collecting material of [t/X0] = " << thicknessInX0);
182 eCell.stepMaterial(parameters.associatedSurface(), layer, parameters.position(), pathCorrection, materialProperties);
183 } else {
184 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "adding material of [t/X0] = " << thicknessInX0);
185 eCell.addMaterial(pathCorrection, materialProperties);
186 }
187 // now either create new ones or update - only start parameters can not be updated
188 if (eCell.leadParameters != eCell.startParameters ){
189 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update on non-initial parameters.");
190 if (uCovariance)
191 parameters.updateParameters(uParameters,*uCovariance);
192 else
193 parameters.updateParameters(uParameters);
194 } else {
195 EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update on initial parameters, creating new ones.");
196 // create new parameters
197 const Trk::Surface& tSurface = parameters.associatedSurface();
198 if (!uCovariance){
199 return &parameters; //just return original
200 }
201 Trk::TrackParameters* tParameters = tSurface.createUniqueTrackParameters(uParameters[Trk::loc1],
202 uParameters[Trk::loc2],
203 uParameters[Trk::phi],
204 uParameters[Trk::theta],
205 uParameters[Trk::qOverP],
206 *uCovariance).release();
207 // these are newly created
208 return tParameters;
209 }
210 }
211 //note aliasing input ...
212 return (&parameters);
213}
#define AmgSymMatrix(dim)
#define AmgVector(rows)
#define EX_MSG_DEBUG(navstep, step, idx, x)
#define EX_MSG_VERBOSE(navstep, step, idx, x)
int sign(int a)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
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
void addMaterial(double sfactor, const MaterialProperties *mprop=nullptr)
fill or attach material, jacobian, step length
T * startParameters
by reference - need to be defined
int navigationStep
a counter of the navigation Step
T * leadParameters
the one last truely valid parameter in the stream
MaterialUpdateMode materialUpdateMode
how to deal with the material effect, default: addNoise
const Layer * leadLayer
the lead Layer - carrying the navigation stream
bool checkConfigurationMode(ExtrapolationMode::eMode em) const
check the configuration mode
ParticleHypothesis pHypothesis
what particle hypothesis to be used, default : pion
std::string m_sopPostfix
prefix for screen output
std::string m_sopPrefix
prefix for screen output
int value() const
layerIndex expressed in an integer
Definition LayerIndex.h:71
Base Class for a Detector Layer in the Tracking realm.
Definition Layer.h:72
const LayerMaterialProperties * layerMaterialProperties() const
getting the LayerMaterialProperties including full/pre/post update
const LayerIndex & layerIndex() const
get the layerIndex
virtual ExtrapolationCode handleMaterial(ExCellCharged &ecCharged, PropDirection dir=alongMomentum, MaterialUpdateStage matupstage=fullUpdate) const
charged extrapolation
StatusCode initialize()
AlgTool initialize method.
~MaterialEffectsEngine()
Destructor.
StatusCode finalize()
AlgTool finalize method.
MaterialEffectsEngine(const std::string &, const std::string &, const IInterface *)
Constructor.
TrackParameters * updateTrackParameters(Trk::TrackParameters &parameters, Trk::ExCellCharged &eCell, Trk::PropDirection dir, Trk::MaterialUpdateStage matupstage) const
charged extrapolation
Material with information about thickness of material.
float thicknessInX0() const
Return the radiationlength fraction.
const Material & material() const
Return the stored Material.
float thickness() const
Return the thickness in mm.
A common object to be contained by.
Definition Material.h:117
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
virtual const Surface & associatedSurface() const override=0
Access to the Surface associated to the Parameters.
Abstract Base Class for tracking surfaces.
Definition Surface.h:79
virtual ChargedTrackParametersUniquePtr createUniqueTrackParameters(double l1, double l2, double phi, double theat, double qop, const std::optional< AmgSymMatrix(5)> &cov=std::nullopt) const =0
Use the Surface as a ParametersBase constructor, from local parameters - charged.
constexpr double mass[PARTICLEHYPOTHESES]
the array of masses
PropDirection
PropDirection, enum for direction of the propagation.
@ oppositeMomentum
@ alongMomentum
MaterialUpdateStage
This is a steering enum to tell which material update stage:
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
@ loc2
generic first and second local coordinate
Definition ParamDefs.h:35
@ phi
Definition ParamDefs.h:75
@ loc1
Definition ParamDefs.h:34
ExtrapolationCell< TrackParameters > ExCellCharged
ParametersBase< TrackParametersDim, Charged > TrackParameters
ExtrapolationCell< NeutralParameters > ExCellNeutral
static double dEdl_ionization(double p, const Material &mat, ParticleHypothesis particle, double &sigma, double &kazL)
dE/dl ionization energy loss per path unit
static double sigmaMS(double dInX0, double p, double beta)
multiple scattering as function of dInX0