ATLAS Offline Software
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 
23 Trk::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.
28  m_currentPathInX0(0),
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;
103  m_currentPathInX0 = 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) ) {
135  m_momentumChange[m_updates] = mef->energyLoss()->deltaE();
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 }
EstimatedBremOnTrack.h
EnergyLoss.h
MaterialOnTrackValidation.h
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Trk::MaterialOnTrackValidation::bookTree
void bookTree()
booking the tree
Definition: MaterialOnTrackValidation.cxx:165
TrackParameters.h
Trk::MaterialOnTrackValidation::m_inputTrackCollection
std::string m_inputTrackCollection
properties from JobOptions:
Definition: MaterialOnTrackValidation.h:54
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::EstimatedBremOnTrack::retainedEnFraction
double retainedEnFraction() const
returns
Definition: EstimatedBremOnTrack.h:115
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::MaterialEffectsBase::thicknessInX0
double thicknessInX0() const
returns the actually traversed material .
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::MaterialOnTrackValidation::finalize
StatusCode finalize()
standard Athena-Algorithm method
Definition: MaterialOnTrackValidation.cxx:58
Trk::MaterialEffectsBase
base class to integrate material effects on Trk::Track in a flexible way.
Definition: MaterialEffectsBase.h:35
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MaterialEffectsOnTrack.h
Trk::MaterialEffectsOnTrack
represents the full description of deflection and e-loss of a track in material.
Definition: MaterialEffectsOnTrack.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::MaterialOnTrackValidation::execute
StatusCode execute()
standard Athena-Algorithm method
Definition: MaterialOnTrackValidation.cxx:66
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::MaterialOnTrackValidation::MaterialOnTrackValidation
MaterialOnTrackValidation(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: MaterialOnTrackValidation.cxx:23
TrackCollection.h
Trk::EnergyLoss::deltaE
double deltaE() const
returns the
Trk::ParametersBase
Definition: ParametersBase.h:55
DataVector< Trk::Track >
AthAlgorithm
Definition: AthAlgorithm.h:47
Trk::MaterialOnTrackValidation::initialize
StatusCode initialize()
standard Athena-Algorithm method
Definition: MaterialOnTrackValidation.cxx:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MAXUPDATES
#define MAXUPDATES
Definition: MaterialOnTrackValidation.h:17
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Trk::ParametersBase::momentum
const Amg::Vector3D & momentum() const
Access method for the momentum.
Trk::MaterialEffectsOnTrack::energyLoss
const EnergyLoss * energyLoss() const
returns the energy loss object.
Trk::EstimatedBremOnTrack
class holding information about momentum reduction and an additional noise term due to significant en...
Definition: EstimatedBremOnTrack.h:30
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Trk::MaterialOnTrackValidation::~MaterialOnTrackValidation
~MaterialOnTrackValidation()
Default Destructor.