ATLAS Offline Software
egammaTrkRefitterTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "xAODEgamma/Electron.h"
8 
16 
20 
21 #include <algorithm>
22 #include <cmath>
23 #include <vector>
24 
25 
27  const std::string& name,
28  const IInterface* parent)
30  , m_ParticleHypothesis(Trk::electron)
31  , m_idHelper(nullptr)
32 {
33  declareInterface<IegammaTrkRefitterTool>(this);
34 }
35 
38 {
39  // Retrieve fitter
40  ATH_CHECK(m_ITrackFitter.retrieve());
41 
42  ATH_CHECK(detStore()->retrieve(m_idHelper, "AtlasID"));
43 
44  // configure calo cluster on track builder (only if used)
46  ATH_CHECK(m_CCOTBuilder.retrieve());
47  } else {
48  m_CCOTBuilder.disable();
49  }
50  // Set the particle hypothesis to match the material effects
52  return StatusCode::SUCCESS;
53 }
54 
57 {
58  return StatusCode::SUCCESS;
59 }
60 
62 egammaTrkRefitterTool::refitTrack(const EventContext& ctx,
63  const Trk::Track* track,
64  Cache& cache) const
65 {
66  cache.refittedTrack = nullptr;
67  cache.refittedTrackPerigee = nullptr;
68  cache.originalTrack = nullptr;
69  cache.originalTrackPerigee = nullptr;
70  if (!track) {
71  return StatusCode::FAILURE;
72  }
73  // Set the pointer to the track
74  cache.originalTrack = track;
75 
76  // Set pointer to the original perigee
78 
79  if (cache.originalTrackPerigee != nullptr) {
80  double od0 = cache.originalTrackPerigee->parameters()[Trk::d0];
81  double oz0 = cache.originalTrackPerigee->parameters()[Trk::z0];
82  double ophi0 = cache.originalTrackPerigee->parameters()[Trk::phi0];
83  double otheta = cache.originalTrackPerigee->parameters()[Trk::theta];
84  double oqOverP = cache.originalTrackPerigee->parameters()[Trk::qOverP];
85  ATH_MSG_DEBUG("Original parameters " << od0 << " " << oz0 << " " << ophi0
86  << " " << otheta << " " << oqOverP
87  << " " << 1 / oqOverP);
88  } else {
89  ATH_MSG_WARNING("Could not get Trk::Perigee of original track");
90  }
91 
92  // Refit the track with the beam spot if desired otherwise just refit the
93  // original track
96  addPointsToTrack(ctx, cache.originalTrack, cache.electron);
97  if (collect.m_measurements.size() > 4) {
98  cache.refittedTrack =
99  m_ITrackFitter->fit(ctx,
100  collect.m_measurements,
102  false,
104  } else {
105  cache.refittedTrack = nullptr;
106  }
107  } else {
108  std::vector<const Trk::MeasurementBase*> measurements =
109  getIDHits(cache.originalTrack);
110  if (measurements.size() > 4) {
111  cache.refittedTrack =
112  m_ITrackFitter->fit(ctx,
113  measurements,
115  false,
117  } else {
118  cache.refittedTrack = nullptr;
119  }
120  }
121 
122  // Store refitted perigee pointers
123  if (cache.refittedTrack) {
124  cache.refittedTrackPerigee = cache.refittedTrack->perigeeParameters();
125  if (cache.refittedTrackPerigee == nullptr) {
126  ATH_MSG_WARNING("Could not get refitted Trk::Perigee");
127  return StatusCode::FAILURE;
128  }
129  return StatusCode::SUCCESS;
130  }
131  return StatusCode::FAILURE;
132 }
133 
136  const Trk::Track* track,
137  const xAOD::Electron* eg) const
138 {
140  /* The issue here is that some of the returned measurements are owned by
141  * storegate some not. For the ones that are not put them in a vector of
142  * unique_ptr which we will also return to the caller*/
143  if (m_useClusterPosition && eg->caloCluster()) {
144  int charge(0);
145  if (track->perigeeParameters()) {
146  charge = (int)track->perigeeParameters()->charge();
147  }
148  std::unique_ptr<const Trk::CaloCluster_OnTrack> ccot(
149  m_CCOTBuilder->buildClusterOnTrack(ctx, eg->caloCluster(), charge));
150  if (ccot != nullptr) {
151  collect.m_trash.push_back(std::move(ccot));
152  collect.m_measurements.push_back(collect.m_trash.back().get());
153  }
154  }
155  std::vector<const Trk::MeasurementBase*> vecIDHits = getIDHits(track);
156  std::vector<const Trk::MeasurementBase*>::const_iterator it =
157  vecIDHits.begin();
158  std::vector<const Trk::MeasurementBase*>::const_iterator itend =
159  vecIDHits.end();
160  // Fill the track , these are not trash
161  for (; it != itend; ++it) {
162  collect.m_measurements.push_back(*it);
163  }
164  return collect;
165 }
166 
167 std::vector<const Trk::MeasurementBase*>
169 {
170 
171  //store measurement to fit in the measurementSet
172  std::vector<const Trk::MeasurementBase*> measurementSet;
173  measurementSet.reserve(track->trackStateOnSurfaces()->size());
174 
175  for (const auto* tsos : *(track->trackStateOnSurfaces())) {
176  if (!tsos) {
178  "This track contains an empty TrackStateOnSurface "
179  "that won't be included in the fit");
180  continue;
181  }
182  if (tsos->type(Trk::TrackStateOnSurface::Measurement) ||
183  tsos->type(Trk::TrackStateOnSurface::Outlier)) {
184 
185  const auto* meas = tsos->measurementOnTrack();
186  if (meas) {
187  const Trk::RIO_OnTrack* rio = nullptr;
188  if (meas->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
189  rio = static_cast<const Trk::RIO_OnTrack*>(meas);
190  }
191  if (rio != nullptr) {
192  const Identifier& surfaceID = (rio->identify());
193  if (m_idHelper->is_sct(surfaceID) ||
194  m_idHelper->is_pixel(surfaceID) ||
195  (!m_RemoveTRT && m_idHelper->is_trt(surfaceID))) {
196  measurementSet.push_back(meas);
197  }
198  }
199  }
200  }
201  }
202  return measurementSet;
203 }
204 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AtlasDetectorID::is_pixel
bool is_pixel(Identifier id) const
Definition: AtlasDetectorID.h:760
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
egammaTrkRefitterTool::MeasurementsAndTrash
Definition: egammaTrkRefitterTool.h:68
PerigeeSurface.h
ParticleTest.eg
eg
Definition: ParticleTest.py:29
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
AtlasDetectorID::is_sct
bool is_sct(Identifier id) const
Definition: AtlasDetectorID.h:770
egammaTrkRefitterTool::m_CCOTBuilder
ToolHandle< ICaloCluster_OnTrackBuilder > m_CCOTBuilder
Definition: egammaTrkRefitterTool.h:92
IegammaTrkRefitterTool::Cache::refittedTrackPerigee
const Trk::Perigee * refittedTrackPerigee
Pointer to the refitted MeasuredPerigee.
Definition: IegammaTrkRefitterTool.h:43
IegammaTrkRefitterTool::Cache::originalTrack
const Trk::Track * originalTrack
Pointer to the original track.
Definition: IegammaTrkRefitterTool.h:45
skel.it
it
Definition: skel.GENtoEVGEN.py:423
Trk::z0
@ z0
Definition: ParamDefs.h:70
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
AtlasDetectorID::is_trt
bool is_trt(Identifier id) const
Definition: AtlasDetectorID.h:782
IdDictManager.h
MaterialEffectsBase.h
ParamDefs.h
egammaTrkRefitterTool::finalize
virtual StatusCode finalize() override
AlgTool finalise method.
Definition: egammaTrkRefitterTool.cxx:56
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
IegammaTrkRefitterTool::Cache
Struct Holding the result to return and intermediate objects Things are owned by the EDM or the uniqu...
Definition: IegammaTrkRefitterTool.h:39
Trk::TrackStateOnSurface::Outlier
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
Definition: TrackStateOnSurface.h:122
egammaTrkRefitterTool.h
egammaTrkRefitterTool::egammaTrkRefitterTool
egammaTrkRefitterTool(const std::string &, const std::string &, const IInterface *)
Constructor with AlgTool parameters.
Definition: egammaTrkRefitterTool.cxx:26
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
egammaTrkRefitterTool::m_matEffects
Gaudi::Property< int > m_matEffects
type of material interaction in extrapolation
Definition: egammaTrkRefitterTool.h:95
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
Trk::theta
@ theta
Definition: ParamDefs.h:72
egammaTrkRefitterTool::initialize
virtual StatusCode initialize() override
AlgTool initialise method.
Definition: egammaTrkRefitterTool.cxx:37
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IegammaTrkRefitterTool::Cache::originalTrackPerigee
const Trk::Perigee * originalTrackPerigee
Pointer to the original Perigee.
Definition: IegammaTrkRefitterTool.h:47
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ParticleHypothesis.h
egammaTrkRefitterTool::addPointsToTrack
MeasurementsAndTrash addPointsToTrack(const EventContext &ctx, const Trk::Track *track, const xAOD::Electron *eg=nullptr) const
Adds a beam spot to the Measurements passed to the track refitter.
Definition: egammaTrkRefitterTool.cxx:135
egammaTrkRefitterTool::m_RemoveTRT
Gaudi::Property< bool > m_RemoveTRT
Option to remove TRT hits from track.
Definition: egammaTrkRefitterTool.h:115
Trk::Track::perigeeParameters
const Perigee * perigeeParameters() const
return Perigee.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:163
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Trk::d0
@ d0
Definition: ParamDefs.h:69
RIO_OnTrack.h
egammaTrkRefitterTool::m_idHelper
const AtlasDetectorID * m_idHelper
Definition: egammaTrkRefitterTool.h:105
charge
double charge(const T &p)
Definition: AtlasPID.h:494
LocalParameters.h
Trk::MeasurementBaseType::RIO_OnTrack
@ RIO_OnTrack
Definition: MeasurementBase.h:49
xAOD::Electron_v1
Definition: Electron_v1.h:34
TrackParticle.h
egammaTrkRefitterTool::m_ITrackFitter
ToolHandle< Trk::ITrackFitter > m_ITrackFitter
The track refitter.
Definition: egammaTrkRefitterTool.h:84
CaloCluster_OnTrack.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
egammaTrkRefitterTool::refitTrack
virtual StatusCode refitTrack(const EventContext &ctx, const Trk::Track *, Cache &cache) const override final
Refit a track.
Definition: egammaTrkRefitterTool.cxx:62
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:73
Trk::RIO_OnTrack::identify
virtual Identifier identify() const final
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:155
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
Trig::FeatureAccessImpl::collect
void collect(const HLT::TriggerElement *te, std::vector< Trig::Feature< T > > &data, const std::string &label, unsigned int condition, const std::string &teName, const HLT::TrigNavStructure *navstructure)
actual feature acceess implementation It has (thanks to the ClassTraits) functionality to flatten con...
Definition: FeatureCollectAthena.h:299
egammaTrkRefitterTool::m_ParticleHypothesis
Trk::ParticleHypothesis m_ParticleHypothesis
Particle Hypothesis.
Definition: egammaTrkRefitterTool.h:103
Electron.h
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
AthAlgTool
Definition: AthAlgTool.h:26
IegammaTrkRefitterTool::Cache::refittedTrack
std::unique_ptr< Trk::Track > refittedTrack
Pointer to the refitted track.
Definition: IegammaTrkRefitterTool.h:41
Trk::phi0
@ phi0
Definition: ParamDefs.h:71
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
egammaTrkRefitterTool::getIDHits
std::vector< const Trk::MeasurementBase * > getIDHits(const Trk::Track *track) const
Get the hits from the Inner Detector.
Definition: egammaTrkRefitterTool.cxx:168
TrackStateOnSurface.h
IegammaTrkRefitterTool::Cache::electron
const xAOD::Electron * electron
pointer to the Electron input
Definition: IegammaTrkRefitterTool.h:49
egammaTrkRefitterTool::m_useClusterPosition
Gaudi::Property< bool > m_useClusterPosition
Definition: egammaTrkRefitterTool.h:107