ATLAS Offline Software
Loading...
Searching...
No Matches
EMBremCollectionBuilder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
6
9#include "TrkTrack/Track.h"
11
13
20
23
24#include <algorithm>
25#include <memory>
26
27
29 ISvcLocator* pSvcLocator)
30 : AthReentrantAlgorithm(name, pSvcLocator)
31{}
32
33StatusCode
35{
36
41
42 /* retrieve the track refitter tool*/
43 ATH_CHECK(m_trkRefitTool.retrieve());
44 /* Get the particle creation tool */
46 /* Get the track slimming tool if needed */
48 ATH_CHECK(m_slimTool.retrieve());
49 } else {
50 m_slimTool.disable();
51 }
52
53 return StatusCode::SUCCESS;
54}
55
56StatusCode
57EMBremCollectionBuilder::EMBremCollectionBuilder::finalize()
58{
59 ATH_MSG_INFO("====> GSF fitting Statistics ============");
60 ATH_MSG_INFO("RefittedTracks: " << m_RefittedTracks);
61 ATH_MSG_INFO("Failed Fit Tracks: " << m_FailedFitTracks);
62 ATH_MSG_INFO("Not refitted due to selection: " << m_FailedSiliconRequirFit);
63 ATH_MSG_INFO("<========================================");
64 return StatusCode::SUCCESS;
65}
66
67StatusCode
68EMBremCollectionBuilder::execute(const EventContext& ctx) const
69{
70 // Read the inputs
71 // The input track particles
74 ATH_CHECK(trackTES.isValid());
75
76 // The input selected track particles (subset of "all" input
77 // read above).
80 ATH_CHECK(selectedTrackParticles.isValid());
81
82 // Create the final containers to be written out
83 // 1. Track particles
86 ATH_CHECK(finalTrkPartContainer.record(
87 std::make_unique<xAOD::TrackParticleContainer>(),
88 std::make_unique<xAOD::TrackParticleAuxContainer>()));
89 xAOD::TrackParticleContainer* cPtrTrkPart = finalTrkPartContainer.ptr();
90
91 // 2. Trk::Tracks
93 ATH_CHECK(finalTracks.record(std::make_unique<TrackCollection>()));
94 TrackCollection* cPtrTracks = finalTracks.ptr();
95
96 // Loop over the selected track-particles
97 // Split TRT-alone from silicon ones.
98 // For the TRT we can get all the info
99 // already since we are not going to refit.
100 std::vector<const xAOD::TrackParticle*> siliconTrkTracks;
101 siliconTrkTracks.reserve(16);
102 std::vector<TrackWithIndex> trtAloneTrkTracks;
103 trtAloneTrkTracks.reserve(8);
104
105 for (const xAOD::TrackParticle* trackParticle : *selectedTrackParticles) {
106 ATH_CHECK(trackParticle->trackLink().isValid());
107 const Trk::Track* trktrack = trackParticle->track();
108 int nSiliconHits_trk = xAOD::EgammaHelpers::summaryValueInt(
109 *trackParticle, xAOD::numberOfSCTHits, 0);
110 nSiliconHits_trk += xAOD::EgammaHelpers::summaryValueInt(
111 *trackParticle, xAOD::numberOfPixelHits, 0);
112 if (nSiliconHits_trk >= m_MinNoSiHits) {
113 siliconTrkTracks.push_back(trackParticle);
114 } else {
115 // copy Trk::Track
116 trtAloneTrkTracks.emplace_back(std::make_unique<Trk::Track>(*trktrack),
117 trackParticle->index());
118 }
119 }
120
121 // Store the results of the GSF refit
122 std::vector<TrackWithIndex> refitted; // refit success
123 refitted.reserve(siliconTrkTracks.size());
124 std::vector<TrackWithIndex> failedfit; // refit failure
125
126 // Do the GSF refit.
127 // Note that altough the input is a xAOD::TrackParticle
128 // what we really refit is the corresponding Trk::Track.
129 // The output is two collections
130 // one for fit success or failure.
131 // TrackWithIndex means the newly created Trk::::Track
132 // and the index of the xAOD::TrackParticle to the
133 // original TrackParticle Collection.
134 ATH_CHECK(refitTracks(ctx, siliconTrkTracks, refitted, failedfit));
135
136 const size_t refittedCount = refitted.size();
137 const size_t failedCount = failedfit.size();
138 const size_t trtCount = trtAloneTrkTracks.size();
139 const size_t totalCount = refittedCount + failedCount + trtCount;
140
141 // reserve as we know how many we will create
142 cPtrTracks->reserve(totalCount);
143 cPtrTrkPart->reserve(totalCount);
144 // Fill the final collections
146 refitted,
147 failedfit,
148 trtAloneTrkTracks,
149 cPtrTracks,
150 cPtrTrkPart,
151 trackTES.ptr()));
152
153 // Update counters
154 m_RefittedTracks.fetch_add(refittedCount, std::memory_order_relaxed);
155 m_FailedFitTracks.fetch_add(failedCount, std::memory_order_relaxed);
156 m_FailedSiliconRequirFit.fetch_add(trtCount, std::memory_order_relaxed);
157 return StatusCode::SUCCESS;
158}
159
160StatusCode
162 const EventContext& ctx,
163 const std::vector<const xAOD::TrackParticle*>& input,
164 std::vector<TrackWithIndex>& refitted,
165 std::vector<TrackWithIndex>& failedfit) const
166{
167 for (const xAOD::TrackParticle* in : input) {
168 const Trk::Track* track = in->track();
170 StatusCode status = m_trkRefitTool->refitTrack(ctx, track, cache);
171 if (status == StatusCode::SUCCESS) {
172 // this is new track
173 refitted.emplace_back(std::move(cache.refittedTrack), in->index());
174 } else {
175 // This is copy ctor
176 failedfit.emplace_back(std::make_unique<Trk::Track>(*track), in->index());
177 }
178 }
179 return StatusCode::SUCCESS;
180}
181
182StatusCode
184 const EventContext& ctx,
185 std::vector<TrackWithIndex>& refitted,
186 std::vector<TrackWithIndex>& failedfit,
187 std::vector<TrackWithIndex>& trtAlone,
188 TrackCollection* finalTracks,
189 xAOD::TrackParticleContainer* finalTrkPartContainer,
190 const xAOD::TrackParticleContainer* inputTrkPartContainer) const
191{
192 // Now we can create the final ouput
193 // 1. Add the refitted
194 for (auto& trk : refitted) {
196 trk,
197 finalTracks,
198 finalTrkPartContainer,
199 inputTrkPartContainer,
200 true));
201 }
202 // 2. Add the failed fit
203 for (auto& trk : failedfit) {
205 trk,
206 finalTracks,
207 finalTrkPartContainer,
208 inputTrkPartContainer,
209 false));
210 }
211 // 3. Add the TRT alone
212 for (auto& trk : trtAlone) {
214 trk,
215 finalTracks,
216 finalTrkPartContainer,
217 inputTrkPartContainer,
218 false));
219 }
220 return StatusCode::SUCCESS;
221}
222
223StatusCode
225 const EventContext& ctx,
226 TrackWithIndex& trk_info,
227 TrackCollection* finalTracks,
228 xAOD::TrackParticleContainer* finalTrkPartContainer,
229 const xAOD::TrackParticleContainer* inputTrkPartContainer,
230 bool isRefitted) const
231{
232
233 // Create new TrackParticle owned by finalTrkPartContainer
234 xAOD::TrackParticle* aParticle = m_particleCreatorTool->createParticle(
235 ctx, *(trk_info.track), finalTrkPartContainer, nullptr, xAOD::electron);
236
237 if (!aParticle) {
239 "Could not create TrackParticle!!! for Track: " << *(trk_info.track));
240 return StatusCode::SUCCESS;
241 }
242 size_t origIndex = trk_info.origIndex;
243 const xAOD::TrackParticle* original = inputTrkPartContainer->at(origIndex);
244
245 // Add an element link back to original Track Particle collection
246 static const SG::AuxElement::Accessor<
248 tP("originalTrackParticle");
250 *inputTrkPartContainer, origIndex, ctx);
251 tP(*aParticle) = linkToOriginal;
252 // Add qoverP from the last measurement
253 float QoverPLast(0);
254 auto rtsos = trk_info.track->trackStateOnSurfaces()->rbegin();
255 for (; rtsos != trk_info.track->trackStateOnSurfaces()->rend(); ++rtsos) {
256 if ((*rtsos)->type(Trk::TrackStateOnSurface::Measurement) &&
257 (*rtsos)->trackParameters() != nullptr &&
258 (*rtsos)->measurementOnTrack() != nullptr &&
259 !(*rtsos)->measurementOnTrack()->type(
261 QoverPLast = (*rtsos)->trackParameters()->parameters()[Trk::qOverP];
262 break;
263 }
264 }
265 static const SG::AuxElement::Accessor<float> QoverPLM("QoverPLM");
266 QoverPLM(*aParticle) = QoverPLast;
267 egammaCopyTrackParticleInfo::ToCopy toCopy{.isRefitted = isRefitted,
268 .doTruth = m_doTruth,
269 .doPix = m_doPix,
270 .doSCT = m_doSCT,
271 .doTRT = m_doTRT,
272 .doHGTD = m_doHGTD};
273 egammaCopyTrackParticleInfo::copy(*aParticle, *original, toCopy);
274 // Slim the Trk::Track, store to the new
275 // Trk::Track collection and make the Track
276 // Particle point to it
277 if (m_doSlimTrkTracks) {
278 m_slimTool->slimTrack(*(trk_info.track));
279 }
280 finalTracks->push_back(std::move(trk_info.track));
282 *finalTracks, finalTracks->size() - 1, ctx);
283 aParticle->setTrackLink(trackLink);
284 return StatusCode::SUCCESS;
285}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
Helpers for checking error return status codes and reporting errors.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
An algorithm that can be simultaneously executed in multiple threads.
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
const T * at(size_type n) const
Access an element, as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Gaudi::Property< bool > m_doTruth
Option to do truth.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticleContainerKey
ToolHandle< Trk::ITrackSlimmingTool > m_slimTool
Tool to slim tracks.
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_OutputTrkPartContainerKey
Gaudi::Property< bool > m_doTRT
Option to copy TRT holes estimation.
Gaudi::Property< bool > m_doHGTD
Option to copy HGTD time to new gsf tracks.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_selectedTrackParticleContainerKey
Names of input output collections.
StatusCode createCollections(const EventContext &ctx, std::vector< TrackWithIndex > &refitted, std::vector< TrackWithIndex > &failedfit, std::vector< TrackWithIndex > &trtAlone, TrackCollection *finalTracks, xAOD::TrackParticleContainer *finalTrkPartContainer, const xAOD::TrackParticleContainer *inputTrkPartContainer) const
StatusCode createNew(const EventContext &ctx, TrackWithIndex &Info, TrackCollection *finalTracks, xAOD::TrackParticleContainer *finalTrkPartContainer, const xAOD::TrackParticleContainer *inputTrkPartContainer, bool isRefitted) const
Gaudi::Property< bool > m_doSCT
Option to copy SCT holes estimation.
virtual StatusCode initialize() override final
ToolHandle< IegammaTrkRefitterTool > m_trkRefitTool
The track refitter.
std::atomic_uint m_FailedSiliconRequirFit
Gaudi::Property< bool > m_doSlimTrkTracks
Option to slim the Trk::Tracks.
ToolHandle< Trk::ITrackParticleCreatorTool > m_particleCreatorTool
Tool to create track particle.
SG::WriteHandleKey< TrackCollection > m_OutputTrackContainerKey
StatusCode refitTracks(const EventContext &ctx, const std::vector< const xAOD::TrackParticle * > &input, std::vector< TrackWithIndex > &refitted, std::vector< TrackWithIndex > &failedfit) const
EMBremCollectionBuilder(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< int > m_MinNoSiHits
@Cut on minimum silicon hits
virtual StatusCode execute(const EventContext &ctx) const override final
Gaudi::Property< bool > m_doPix
Option to copy pixel holes estimation.
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
const_pointer_type ptr()
Dereference the pointer.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
void setTrackLink(const ElementLink< TrackCollection > &track)
Set the link to the original track.
@ qOverP
perigee
Definition ParamDefs.h:67
void copy(xAOD::TrackParticle &created, const xAOD::TrackParticle &original, const egammaCopyTrackParticleInfo::ToCopy &toCopy)
int summaryValueInt(const xAOD::TrackParticle &tp, const xAOD::SummaryType &info, int deflt=-999)
return the summary value for a TrackParticle or default value (-999) (to be used mostly in python whe...
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
Helper struct to store the Trk::Track corresponding to a TrackParticle and the index of the Track Par...
Struct Holding the result to return and intermediate objects Things are owned by the EDM or the uniqu...
std::unique_ptr< Trk::Track > refittedTrack
Pointer to the refitted track.