ATLAS Offline Software
Loading...
Searching...
No Matches
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
16Trk::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{
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. &&
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
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}
#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.
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.
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