ATLAS Offline Software
MaterialEffectsEngine.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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  m_eLossCorrection(true),
19  m_eLossMpv(true),
20  m_mscCorrection(true)
21 {
22  declareInterface<Trk::IMaterialEffectsEngine>(this);
23  // steering of the screen outoput (SOP)
24  declareProperty("OutputPrefix" , m_sopPrefix);
25  declareProperty("OutputPostfix" , m_sopPostfix);
26  // steering of the material effects engine behaviour
27  declareProperty("EnergyLossCorrection" , m_eLossCorrection);
28  declareProperty("MostProbableEnergyLoss" , m_eLossMpv);
29  declareProperty("MultipleScatteringCorrection" , m_mscCorrection);
30 }
31 
32 // destructor
34 = default;
35 
36 
37 // the interface method initialize
39 {
40  EX_MSG_DEBUG( "", "initialize","", "successful" );
41  return StatusCode::SUCCESS;
42 }
43 
44 // the interface method finalize
46 {
47  EX_MSG_DEBUG( "", "finalize","", "successful" );
48  return StatusCode::SUCCESS;
49 }
50 
54  Trk::MaterialUpdateStage matupstage) const
55 {
56 
57  // the Extrapolator made sure that the layer is the lead layer && the parameters are the lead parameters
58  if (eCell.leadLayer && eCell.leadLayer->layerMaterialProperties()){
59  EX_MSG_DEBUG( ++eCell.navigationStep, "layer", eCell.leadLayer->layerIndex().value(), "handleMaterial for neutral parameters called - collect material.");
60  // now calculate the pathCorrection from the layer surface - it is signed, gives you the relative direction to the layer
61  const Trk::Layer* layer = eCell.leadLayer;
62  // path correction
63  double pathCorrection = layer->surfaceRepresentation().pathCorrection(eCell.leadParameters->position(),dir*(eCell.leadParameters->momentum()));
64  // the relative direction wrt with the layer
65  Trk::PropDirection rlDir = (pathCorrection >= 0. ? Trk::alongMomentum : Trk::oppositeMomentum);
66  // multiply by the pre-and post-update factor
67  double mFactor = layer->layerMaterialProperties()->factor(rlDir, matupstage);
68  if (mFactor == 0.){
69  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material collection with " << (matupstage > 0. ? "pre " : "post ") << "factor 0.");
70  // return the parameters untouched -
72  }
73  pathCorrection = mFactor*pathCorrection;
74  // screen output
75  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update with corr factor = " << pathCorrection);
76  // get the actual material bin
77  const Trk::MaterialProperties* materialProperties = layer->layerMaterialProperties()->fullMaterial(eCell.leadParameters->position());
78  // and let's check if there's acutally something to do
79  if (materialProperties && std::abs(pathCorrection)>0.){
80  // thickness in X0
81  double thicknessInX0 = materialProperties->thicknessInX0();
82  // check if material filling was requested
84  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "collecting material of [t/X0] = " << thicknessInX0);
85  eCell.stepMaterial(eCell.leadParameters->associatedSurface(), layer, eCell.leadParameters->position(), pathCorrection, materialProperties);
86  } else {
87  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "adding material of [t/X0] = " << thicknessInX0);
88  eCell.addMaterial(pathCorrection, materialProperties);
89  }
90  }
91  }
92  // only in case of post update it should not return InProgress
94 }
95 
96 
100  Trk::MaterialUpdateStage matupstage) const
101 {
102 
103  // the Extrapolator made sure that the layer is the lead layer && the parameters are the lead parameters
104  if (eCell.leadLayer && eCell.leadLayer->layerMaterialProperties()){
105  EX_MSG_DEBUG( ++eCell.navigationStep, "layer", eCell.leadLayer->layerIndex().value(), "handleMaterial for charged parameters called.");
106  // update the track parameters
107  eCell.leadParameters = updateTrackParameters(*eCell.leadParameters,eCell,dir,matupstage);
108  }
109  // only in case of post update it should not return InProgress
111 }
112 
115  Trk::ExCellCharged& eCell,
117  Trk::MaterialUpdateStage matupstage) const
118 {
119  // now calculate the pathCorrection from the layer surface - it is signed, gives you the relative direction to the layer
120  const Trk::Layer* layer = eCell.leadLayer;
121  // path correction
122  double pathCorrection = layer->surfaceRepresentation().pathCorrection(parameters.position(),dir*(parameters.momentum()));
123  // the relative direction wrt with the layer
124  Trk::PropDirection rlDir = (pathCorrection >= 0. ? Trk::alongMomentum : Trk::oppositeMomentum);
125  // multiply by the pre-and post-update factor
126  double mFactor = layer->layerMaterialProperties()->factor(rlDir, matupstage);
127  if (mFactor == 0.){
128  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update with " << (matupstage > 0. ? "pre " : "post ") << "factor 0. No update done.");
129  // return the parameters untouched -
130  return (&parameters);
131  }
132  pathCorrection = mFactor*pathCorrection;
133  // screen output
134  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update with corr factor = " << pathCorrection);
135  // get the actual material bin
136  const Trk::MaterialProperties* materialProperties = layer->layerMaterialProperties()->fullMaterial(parameters.position());
137  // and let's check if there's acutally something to do
138  if (materialProperties && std::abs(pathCorrection)>0. &&
139  ( m_eLossCorrection || m_mscCorrection || eCell.checkConfigurationMode(Trk::ExtrapolationMode::CollectMaterial)) ){
140  // and add them
141  int sign = int(eCell.materialUpdateMode);
142  // a simple cross-check if the parameters are the initial ones
143  AmgVector(5) uParameters = parameters.parameters();
144  std::unique_ptr<AmgSymMatrix(5)> uCovariance =
145  parameters.covariance()
146  ? std::make_unique<AmgSymMatrix(5)>(*parameters.covariance())
147  : nullptr;
148  // get the material itself & its parameters
149  const Trk::Material& material = materialProperties->material();
150  double thicknessInX0 = materialProperties->thicknessInX0();
151  double thickness = materialProperties->thickness();
152  // calculate energy loss and multiple scattering
153  double p = parameters.momentum().mag();
154  double m = Trk::ParticleMasses::mass[eCell.pHypothesis];
155  double E = sqrt(p*p+m*m);
156  double beta = p/E;
157  // (A) - energy loss correction
158  if (m_eLossCorrection){
159  double sigmaP = 0.;
160  double kazl = 0.;
162  double dEdl = sign*dir*Trk::MaterialInteraction::dEdl_ionization(p, material, eCell.pHypothesis, sigmaP, kazl);
163  double dE = thickness*pathCorrection*dEdl;
164  sigmaP *= thickness*pathCorrection;
165  // calcuate the new momentum
166  double newP = sqrt((E+dE)*(E+dE)-m*m);
167  uParameters[Trk::qOverP] = parameters.charge()/newP;
168  double sigmaDeltaE = thickness*pathCorrection*sigmaP;
169  double sigmaQoverP = sigmaDeltaE/std::pow(beta*p,2);
170  // update the covariance if needed
171  if (uCovariance)
172  (*uCovariance)(Trk::qOverP, Trk::qOverP) += sign*sigmaQoverP*sigmaQoverP;
173  }
174  // (B) - update the covariance if needed
175  if (uCovariance && m_mscCorrection){
177  double sigmaMS = Trk::MaterialInteraction::sigmaMS(thicknessInX0*pathCorrection, p, beta);
178  double sinTheta = sin(parameters.parameters()[Trk::theta]);
179  double sigmaDeltaPhiSq = sigmaMS*sigmaMS/(sinTheta*sinTheta);
180  double sigmaDeltaThetaSq = sigmaMS*sigmaMS;
181  // add or remove @TODO implement check for covariance matrix -> 0
182  (*uCovariance)(Trk::phi,Trk::phi) += sign*sigmaDeltaPhiSq;
183  (*uCovariance)(Trk::theta, Trk::theta) += sign*sigmaDeltaThetaSq;
184  }
185  // check if material filling was requested
187  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "collecting material of [t/X0] = " << thicknessInX0);
188  eCell.stepMaterial(parameters.associatedSurface(), layer, parameters.position(), pathCorrection, materialProperties);
189  } else {
190  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "adding material of [t/X0] = " << thicknessInX0);
191  eCell.addMaterial(pathCorrection, materialProperties);
192  }
193  // now either create new ones or update - only start parameters can not be updated
194  if (eCell.leadParameters != eCell.startParameters ){
195  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update on non-initial parameters.");
196  if (uCovariance)
197  parameters.updateParameters(uParameters,*uCovariance);
198  else
199  parameters.updateParameters(uParameters);
200  } else {
201  EX_MSG_VERBOSE(eCell.navigationStep, "layer", layer->layerIndex().value(), "material update on initial parameters, creating new ones.");
202  // create new parameters
203  const Trk::Surface& tSurface = parameters.associatedSurface();
204  Trk::TrackParameters* tParameters = tSurface.createUniqueTrackParameters(uParameters[Trk::loc1],
205  uParameters[Trk::loc2],
206  uParameters[Trk::phi],
207  uParameters[Trk::theta],
208  uParameters[Trk::qOverP],
209  *uCovariance).release();
210  // these are newly created
211  return tParameters;
212  }
213  }
214  //note aliasing input ...
215  return (&parameters);
216 }
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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Trk::oppositeMomentum
@ oppositeMomentum
Definition: PropDirection.h:21
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::IMaterialEffectsEngine::m_sopPrefix
std::string m_sopPrefix
prefix for screen output
Definition: IMaterialEffectsEngine.h:61
Trk::ExtrapolationCell::pHypothesis
ParticleHypothesis pHypothesis
what particle hypothesis to be used, default : pion
Definition: ExtrapolationCell.h:279
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
Trk::MaterialProperties::thicknessInX0
float thicknessInX0() const
Return the radiationlength fraction.
Trk::loc2
@ loc2
generic first and second local coordinate
Definition: ParamDefs.h:41
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:636
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:114
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:98
Trk::MaterialEffectsEngine::~MaterialEffectsEngine
~MaterialEffectsEngine()
Destructor.
Trk::MaterialEffectsEngine::m_mscCorrection
bool m_mscCorrection
apply the multiple (coulomb) scattering correction
Definition: MaterialEffectsEngine.h:73
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
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:72
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
Trk::ExtrapolationCode
Definition: ExtrapolationCell.h:105
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:127
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:351
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
Trk::IMaterialEffectsEngine::m_sopPostfix
std::string m_sopPostfix
prefix for screen output
Definition: IMaterialEffectsEngine.h:62
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:605
Trk::ExtrapolationCell::leadParameters
T * leadParameters
the one last truely valid parameter in the stream
Definition: ExtrapolationCell.h:246
Trk::MaterialEffectsEngine::m_eLossCorrection
bool m_eLossCorrection
apply the energy loss correction
Definition: MaterialEffectsEngine.h:71
Trk::MaterialEffectsEngine::initialize
StatusCode initialize()
AlgTool initialize method.
Definition: MaterialEffectsEngine.cxx:38
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:73
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:81
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:40
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::MaterialEffectsEngine::finalize
StatusCode finalize()
AlgTool finalize method.
Definition: MaterialEffectsEngine.cxx:45
Trk::MaterialEffectsEngine::m_eLossMpv
bool m_eLossMpv
apply the energy loss correction as most probable value
Definition: MaterialEffectsEngine.h:72
Trk::ExtrapolationCode::InProgress
@ InProgress
Definition: ExtrapolationCell.h:111
Trk::Layer
Definition: Layer.h:73
Trk::Layer::layerIndex
const LayerIndex & layerIndex() const
get the layerIndex