ATLAS Offline Software
Loading...
Searching...
No Matches
MaterialOnTrackValidation.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// MaterialOnTrackValidation.cxx, (c) ATLAS Detector software
8
15#include "GaudiKernel/ISvcLocator.h"
16#include "GaudiKernel/ITHistSvc.h"
17#include "GaudiKernel/Bootstrap.h"
18#include "TTree.h"
19
20
21//================ Constructor =================================================
22
23Trk::MaterialOnTrackValidation::MaterialOnTrackValidation(const std::string& name, ISvcLocator* pSvcLocator):
24 AthAlgorithm(name,pSvcLocator),
25 m_inputTrackCollection("Tracks"),
26 m_Tree(nullptr),
27 m_updates(0), // Coverity complaints about this and the following members not to be initialised, although they are before usage.
29 m_stepInX0(0)
30{
31
32
33 // Get Parameter values from JobOptions file
34 declareProperty("InputTrackCollection", m_inputTrackCollection);
35}
36
37//================ Destructor =================================================
38
40= default;
41
42
43//================ Initialisation =================================================
44
46{
47 ATH_MSG_INFO( "initialize() successful in " << name() );
48
49 // Book the Tree
50 bookTree();
51
52 return StatusCode::SUCCESS;
53
54}
55
56//================ Finalisation =================================================
57
59{
60 // Code entered here will be executed once at the end of the program run.
61 return StatusCode::SUCCESS;
62}
63
64//================ Execution ====================================================
65
67{
68 // Code entered here will be executed once per event
69
70 // Retrieving the Trackcollection specified via m_inputTrackCollection
71 StatusCode sc = StatusCode::SUCCESS;
72 const TrackCollection* trackCollection = nullptr;
73
74 if (!m_inputTrackCollection.empty()) {
75 sc = evtStore()->retrieve(trackCollection,m_inputTrackCollection);
76 if (sc.isFailure())
77 ATH_MSG_ERROR( "TrackCollection "<<m_inputTrackCollection<<" not found!" );
78 else
79 ATH_MSG_VERBOSE("TrackCollection " << m_inputTrackCollection<<" found." );
80
81 } else {
82 ATH_MSG_ERROR("No Track collection given!" );
83 return StatusCode::FAILURE;
84 }
85
86 // Looping over the tracks of retrieved trackcollection
87
88 // Creating the iterators for the loop
89 TrackCollection::const_iterator itTracks = trackCollection->begin();
90 TrackCollection::const_iterator endTracks = trackCollection->end();
91
92 for (;itTracks!=endTracks;++itTracks) {
93
94 // Getting the TrackStateOnSurface for every track
95 const Trk::TrackStates *currentTSOSList =(*itTracks)->trackStateOnSurfaces();
96
97 // Iterators for loop inside track
100
101 // Initialize variables
102 m_updates = 0;
104
105 // Loop over all TrackStatesOnSurface
106 for (;itTSOS!=endTSOS;++itTSOS) {
107
108 // Get the Pointer to a trackStateOnSurface
109 const MaterialEffectsBase* mEffect = (*itTSOS)->materialEffectsOnTrack();
110
111 // Get the Pointer to Trackparameters
112 const TrackParameters* tParameter = (*itTSOS)->trackParameters();
113
114 // Getting all the parameters
115 if (mEffect&&tParameter) { //protection against zero pointers
116
117 m_stepInX0 = mEffect->thicknessInX0(); //traversed thickness in radiation length
118 m_currentPathInX0 += m_stepInX0; //accumulated traversed path in rlength
119
120 // Get hit parameters
121 m_positionR[m_updates] = tParameter->position().perp();
122 m_positionX[m_updates] = tParameter->position().x();
123 m_positionY[m_updates] = tParameter->position().y();
124 m_positionZ[m_updates] = tParameter->position().z();
125
126 // Get momentum parameters
127 m_momentum[m_updates] = tParameter->momentum().mag();
128 const Trk::EstimatedBremOnTrack* eb =
129 dynamic_cast<const Trk::EstimatedBremOnTrack*>(mEffect);
130 const Trk::MaterialEffectsOnTrack* mef =
131 dynamic_cast<const Trk::MaterialEffectsOnTrack*>(mEffect);
132 if (eb!=nullptr) {
133 m_momentumChange[m_updates] = (1.0-eb->retainedEnFraction()) * tParameter->momentum().mag();
134 } else if ( (mef!=nullptr) && (mef->energyLoss() != nullptr) ) {
136 } else m_momentumChange[m_updates] = 0.0;
137
138 m_eta[m_updates] = tParameter->position().eta();
139 m_traversedStepInX0[m_updates] = m_stepInX0; //current traversed thickness/radiation length
140 m_traversedPathInX0[m_updates] = m_currentPathInX0; //accumulated traversed path/radiation length
141
142 ++m_updates; //increases m_updates everytime the trackparameters are nonzero
143 if (m_updates>=MAXUPDATES) {
144 ATH_MSG_ERROR("Maximum number of updates reached!");
145 // @TODO still fill the tree ?
146 return StatusCode::FAILURE;
147 }
148
149 } //protection end
150
151
152 } //loop TSOS end
153
154 if (m_Tree)
155 m_Tree->Fill();
156
157 } //loop tracks end
158
159
160 return StatusCode::SUCCESS;
161}
162
163//============================================================================================
164
166
167 // Booking the Tree
168 ATH_MSG_VERBOSE("Booking the tree ...");
169 m_Tree = new TTree("MaterialOnTrackValidation","Material on track validation");
170
171 // Adding the branches
172 m_Tree->Branch("Updates" ,&m_updates , "updates/I");
173 m_Tree->Branch("UpdatePositionX", m_positionX , "updateX[updates]/F");
174 m_Tree->Branch("UpdatePositionR", m_positionR , "updateR[updates]/F");
175 m_Tree->Branch("PreMomentum" , m_momentum , "preMomentum[updates]/F");
176 m_Tree->Branch("MomentumChange" , m_momentumChange , "momentumChange[updates]/F");
177 m_Tree->Branch("PathInX0" , m_traversedPathInX0 , "PathInX0[updates]/F");
178 m_Tree->Branch("StepInX0" , m_traversedStepInX0 , "StepInX0[updates]/F");
179 m_Tree->Branch("Eta" , m_eta , "Eta[updates]/F");
180
181
182 // Registering the Tree
183 SmartIF<ITHistSvc> tHistSvc{service("THistSvc")};
184 if (!tHistSvc) {
185 ATH_MSG_ERROR("initialize() Could not find Hist Service -> Switching ValidationMode Off !");
186 delete m_Tree; m_Tree = nullptr;
187 return;
188 }
189
190 if ((tHistSvc->regTree("/val/MaterialOnTrackValidation", m_Tree)).isFailure()) {
191 ATH_MSG_ERROR("initialize() Could not register the Tree -> Switching ValidationMode Off !");
192 delete m_Tree; m_Tree = nullptr;
193 return;
194 }
195
196}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
static Double_t sc
#define MAXUPDATES
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
double deltaE() const
returns the
class holding information about momentum reduction and an additional noise term due to significant en...
double retainedEnFraction() const
returns
base class to integrate material effects on Trk::Track in a flexible way.
double thicknessInX0() const
returns the actually traversed material .
represents the full description of deflection and e-loss of a track in material.
const EnergyLoss * energyLoss() const
returns the energy loss object.
float m_positionY[MAXUPDATES]
y position of the update
float m_positionZ[MAXUPDATES]
z position of the update
float m_positionR[MAXUPDATES]
r value of the material update
~MaterialOnTrackValidation()
Default Destructor.
std::string m_inputTrackCollection
properties from JobOptions:
float m_positionX[MAXUPDATES]
x position of the update
float m_traversedStepInX0[MAXUPDATES]
the step path in x0
MaterialOnTrackValidation(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
float m_momentumChange[MAXUPDATES]
change of the momentum
StatusCode initialize()
standard Athena-Algorithm method
StatusCode execute()
standard Athena-Algorithm method
double m_currentPathInX0
accumulation variable
float m_traversedPathInX0[MAXUPDATES]
accumulated traversed path in rlength
StatusCode finalize()
standard Athena-Algorithm method
double m_stepInX0
traversed thickness in radiation length
float m_momentum[MAXUPDATES]
momentum before the update is applied
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
DataVector< const Trk::TrackStateOnSurface > TrackStates
ParametersBase< TrackParametersDim, Charged > TrackParameters