ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
16
20
21#include <algorithm>
22#include <cmath>
23#include <vector>
24
25
27 const std::string& name,
28 const IInterface* parent)
29 : AthAlgTool(type, name, parent)
30 , m_ParticleHypothesis(Trk::electron)
31 , m_idHelper(nullptr)
32{
33 declareInterface<IegammaTrkRefitterTool>(this);
34}
35
36StatusCode
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
55StatusCode
57{
58 return StatusCode::SUCCESS;
59}
60
61StatusCode
62egammaTrkRefitterTool::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 =
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) {
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
167std::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 }
184
185 const auto* meas = tsos->measurementOnTrack();
186 if (meas) {
187 const Trk::RIO_OnTrack* rio = nullptr;
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
double charge(const T &p)
Definition AtlasPID.h:997
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
Identifier identify() const
return the identifier -extends MeasurementBase
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
const Perigee * perigeeParameters() const
return Perigee.
IegammaTrkRefitterTool::Cache Cache
ToolHandle< ICaloCluster_OnTrackBuilder > m_CCOTBuilder
virtual StatusCode refitTrack(const EventContext &ctx, const Trk::Track *, Cache &cache) const override final
Refit a track.
ToolHandle< Trk::ITrackFitter > m_ITrackFitter
The track refitter.
egammaTrkRefitterTool(const std::string &, const std::string &, const IInterface *)
Constructor with AlgTool parameters.
Gaudi::Property< int > m_matEffects
type of material interaction in extrapolation
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.
Gaudi::Property< bool > m_useClusterPosition
virtual StatusCode initialize() override
AlgTool initialise method.
virtual StatusCode finalize() override
AlgTool finalise method.
const AtlasDetectorID * m_idHelper
std::vector< const Trk::MeasurementBase * > getIDHits(const Trk::Track *track) const
Get the hits from the Inner Detector.
Gaudi::Property< bool > m_RemoveTRT
Option to remove TRT hits from track.
Trk::ParticleHypothesis m_ParticleHypothesis
Particle Hypothesis.
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Ensure that the ATLAS eigen extensions are properly loaded.
@ phi0
Definition ParamDefs.h:65
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
@ d0
Definition ParamDefs.h:63
@ z0
Definition ParamDefs.h:64
Electron_v1 Electron
Definition of the current "egamma version".
std::unique_ptr< Trk::Track > refittedTrack
Pointer to the refitted track.
const xAOD::Electron * electron
pointer to the Electron input
const Trk::Perigee * refittedTrackPerigee
Pointer to the refitted MeasuredPerigee.
const Trk::Perigee * originalTrackPerigee
Pointer to the original Perigee.
const Trk::Track * originalTrack
Pointer to the original track.