ATLAS Offline Software
Loading...
Searching...
No Matches
TrackSlimmingTool.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// TrackSlimmingTool.cxx, (c) ATLAS Detector software
8
19#include "TrkSurfaces/Surface.h"
22
24 const std::string& n,
25 const IInterface* p)
26 : AthAlgTool(t, n, p)
27 , m_keepCaloDeposit(true)
28 , m_keepOutliers(false)
29 , m_keepParameters(false)
30 , m_detID{}
31{
32 declareInterface<ITrackSlimmingTool>(this);
33
34 // template for property decalration
36 "KeepCaloDeposit",
38 "If this is set to true, any CaloDeposit with its adjacent MEOT's will be "
39 "kept on the slimmed track (combined muon property)");
40 declareProperty("KeepOutliers",
42 "If this is set to true, Outlier measurements will be kept "
43 "on the slimmed track");
44 declareProperty("KeepParameters",
46 "If this is set to true, the first and last parameters will "
47 "be kept on the slimmed track");
48}
50
51StatusCode
53{
54
55 StatusCode sc = AlgTool::initialize();
56 if (sc.isFailure())
57 return sc;
58
59 sc = detStore()->retrieve(m_detID, "AtlasID");
60 if (sc.isFailure()) {
61 ATH_MSG_FATAL("Could not get AtlasDetectorID ");
62 return sc;
63 }
64 ATH_MSG_DEBUG("Found AtlasDetectorID");
65
66 return StatusCode::SUCCESS;
67}
68
69StatusCode
71{
72 return StatusCode::SUCCESS;
73}
74
75void
77{
78 setHints(track);
79 track.info().setTrackProperties(TrackInfo::SlimmedTrack);
80}
81
82void
84{
85 setHints(track);
86}
87
88void
90{
91 const Trk::TrackStates* oldTrackStates =
92 track.trackStateOnSurfaces();
93 if (oldTrackStates == nullptr) {
94 ATH_MSG_WARNING("Track has no TSOS vector! Skipping track, returning");
95 return;
96 }
97
98 const TrackStateOnSurface* firstValidIDTSOS(nullptr);
99 const TrackStateOnSurface* lastValidIDTSOS(nullptr);
100 const TrackStateOnSurface* firstValidMSTSOS(nullptr);
101 const TrackStateOnSurface* lastValidMSTSOS(nullptr);
102 if (m_keepParameters) {
103 // search last valid TSOS first (as won't be found in later loop)
104 findLastValidTSoS(oldTrackStates, lastValidIDTSOS, lastValidMSTSOS);
105 }
106
107 // If m_keepParameters is true, then we want to keep the first and last
108 // parameters of ID & MS.
109 const Trk::MeasurementBase* rot = nullptr;
110 const Trk::TrackParameters* parameters = nullptr;
111 bool keepParameter = false;
112 // looping over all TSOS
114 oldTrackStates->begin();
115 for (; itTSoS != oldTrackStates->end(); ++itTSoS) {
116
117 // The hints we want to create for this tsos
118 std::bitset<Trk::TrackStateOnSurface::NumberOfPersistencyHints> hints{};
119 //
121 parameters = nullptr;
122 rot = nullptr;
123 // if requested: keep calorimeter TSOS with adjacent scatterers (on combined
124 // muons)
125 if (m_keepCaloDeposit &&
126 (**itTSoS).type(TrackStateOnSurface::CaloDeposit)) {
127 // preceding TSOS (if Scatterer)
128 if (itTSoS != oldTrackStates->begin()) {
129 --itTSoS;
130 if ((**itTSoS).type(TrackStateOnSurface::Scatterer)) {
132 }
133 ++itTSoS;
134 }
135 // copy removes CaloEnergy (just keep base EnergyLoss)
136 const MaterialEffectsOnTrack* meot =
137 dynamic_cast<const MaterialEffectsOnTrack*>(
138 (**itTSoS).materialEffectsOnTrack());
139 if (meot && meot->energyLoss()) {
142 }
143 // following TSOS (if Scatterer)
144 ++itTSoS;
145 if (itTSoS != oldTrackStates->end() &&
146 (**itTSoS).type(TrackStateOnSurface::Scatterer)) {
148 }
149 --itTSoS;
150 }
151
152 // We only keep TSOS if they either contain a perigee, OR are a measurement
153 if ((*itTSoS)->measurementOnTrack() == nullptr &&
154 !(*itTSoS)->type(TrackStateOnSurface::Perigee)) {
155 // pass the hints to the tsos before we continue to the next
156 (*itTSoS)->setHints(hints.to_ulong());
157 continue;
158 }
159
160 keepParameter = keepParameters((*itTSoS),
161 firstValidIDTSOS,
162 lastValidIDTSOS,
163 firstValidMSTSOS,
164 lastValidMSTSOS);
165
166 if (keepParameter) {
167 parameters = (*itTSoS)->trackParameters();
168 }
169 if ((*itTSoS)->measurementOnTrack() != nullptr &&
170 ((*itTSoS)->type(TrackStateOnSurface::Measurement) ||
171 (m_keepOutliers && (*itTSoS)->type(TrackStateOnSurface::Outlier)))) {
172 rot = (*itTSoS)->measurementOnTrack();
173 }
174 if (rot != nullptr || parameters != nullptr) {
175 if (rot) {
177 }
178 if (parameters) {
180 }
181 }
182 // pass the hints to the tsos
183 (*itTSoS)->setHints(hints.to_ulong());
184 }
185}
186
187void
189 bool& isIDmeas,
190 bool& isMSmeas) const
191{
192 if (tsos->measurementOnTrack() != nullptr) {
193 bool isPseudo = (tsos->measurementOnTrack()->type(
195 // Handle cROTs
196 const Trk::CompetingRIOsOnTrack* cROT = nullptr;
197 if (tsos->measurementOnTrack()->type(
199 cROT = static_cast<const Trk::CompetingRIOsOnTrack*>(
200 tsos->measurementOnTrack());
201 }
202 Identifier id;
203 if (cROT) {
204 id = cROT->rioOnTrack(cROT->indexOfMaxAssignProb()).identify();
205 } else {
206 id = tsos->measurementOnTrack()
209 }
210 isIDmeas = !isPseudo && m_detID->is_indet(id);
211 isMSmeas = tsos->measurementOnTrack() != nullptr && !isPseudo &&
212 m_detID->is_muon(id);
213 }
214}
215
216void
218 const Trk::TrackStates* oldTrackStates,
219 const Trk::TrackStateOnSurface*& lastValidIDTSOS,
220 const TrackStateOnSurface*& lastValidMSTSOS) const
221{
222
224 oldTrackStates->rbegin();
225 rItTSoS != oldTrackStates->rend();
226 ++rItTSoS) {
227 if ((*rItTSoS)->type(TrackStateOnSurface::Measurement) &&
228 (*rItTSoS)->trackParameters() != nullptr &&
229 (*rItTSoS)->measurementOnTrack() != nullptr &&
230 !(*rItTSoS)->measurementOnTrack()->type(
232
233 if (m_detID->is_indet((*rItTSoS)
234 ->trackParameters()
235 ->associatedSurface()
236 .associatedDetectorElementIdentifier())) {
237 lastValidIDTSOS = (*rItTSoS);
238 break;
239 }
240 if (m_detID->is_muon((*rItTSoS)
241 ->trackParameters()
242 ->associatedSurface()
243 .associatedDetectorElementIdentifier())) {
244 lastValidMSTSOS = (*rItTSoS);
245 break;
246 }
247 }
248 }
249}
250
251bool
253 const Trk::TrackStateOnSurface* TSoS,
254 const TrackStateOnSurface*& firstValidIDTSOS,
255 const TrackStateOnSurface*& lastValidIDTSOS,
256 const TrackStateOnSurface*& firstValidMSTSOS,
257 const TrackStateOnSurface*& lastValidMSTSOS) const
258{
259
260 if (TSoS->trackParameters() != nullptr &&
262 return true;
263 }
264 // Now do checks for first/last ID/MS measurement (isIDmeas and isMSmeas)
265 if (m_keepParameters) {
266 bool isIDmeas = false;
267 bool isMSmeas = false;
268 checkForValidMeas(TSoS, isIDmeas, isMSmeas);
269 // entering ID?
270 if (isIDmeas && !firstValidIDTSOS &&
272 firstValidIDTSOS = TSoS;
273 if (TSoS->trackParameters() != nullptr)
274 return true;
275 }
276 // entering MS?
277 if (isMSmeas && !firstValidMSTSOS) {
278 firstValidMSTSOS = TSoS;
279 if (TSoS->trackParameters() != nullptr)
280 return true;
281 }
282 // Is this the last TSOS on the track?
283 if (lastValidIDTSOS == TSoS || lastValidMSTSOS == TSoS) {
284 if (TSoS->trackParameters() != nullptr)
285 return true;
286 }
287 }
288 return false;
289}
#define ATH_MSG_FATAL(x)
#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...
static Double_t sc
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_reverse_iterator rend() const noexcept
Return a const_reverse_iterator pointing at the beginning of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition DataVector.h:847
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
unsigned int indexOfMaxAssignProb() const
Index of the ROT with the highest assignment probability.
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
represents the full description of deflection and e-loss of a track in material.
const EnergyLoss * energyLoss() const
returns the energy loss object.
This class is the pure abstract base class for all fittable tracking measurements.
virtual const Surface & associatedSurface() const =0
Interface method to get the associated Surface.
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
Identifier identify() const
return the identifier -extends MeasurementBase
Identifier associatedDetectorElementIdentifier() const
return Identifier of the associated Detector Element
TrackSlimmingTool(const std::string &, const std::string &, const IInterface *)
bool keepParameters(const Trk::TrackStateOnSurface *TSoS, const TrackStateOnSurface *&firstValidIDTSOS, const TrackStateOnSurface *&lastValidIDTSOS, const TrackStateOnSurface *&firstValidMSTSOS, const TrackStateOnSurface *&lastValidMSTSOS) const
void slimTrack(Trk::Track &track) const override final
Slim a non const Track.
bool m_keepParameters
If true, the first and last parameters of ID & MS subsystems will be kept on the slimmed track.
void setHints(const Trk::Track &track) const
This method just set persistification Hints.
virtual ~TrackSlimmingTool()
default destructor
const AtlasDetectorID * m_detID
atlas id helper
bool m_keepOutliers
If true, Outliers will be kept on the slimmed track.
void checkForValidMeas(const Trk::TrackStateOnSurface *tsos, bool &isIDmeas, bool &isMSmeas) const
void slimConstTrack(const Trk::Track &track) const override final
Slim a const Track.
bool m_keepCaloDeposit
any CaloDeposit with its adjacent MEOT's will be kept on the slimmed track (combined muon property)
void findLastValidTSoS(const Trk::TrackStates *oldTrackStates, const Trk::TrackStateOnSurface *&lastValidIDTSOS, const TrackStateOnSurface *&lastValidMSTSOS) const
virtual StatusCode initialize() override
standard Athena-Algorithm method
virtual StatusCode finalize() override
standard Athena-Algorithm method
represents the track state (measurement, material, fit parameters and quality) at a surface.
const MeasurementBase * measurementOnTrack() const
returns MeasurementBase const overload
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
bool type(const TrackStateOnSurfaceType type) const
Use this method to find out if the TSoS is of a certain type: i.e.
@ PersistifySlimCaloDeposit
Mark track parameters for persisitification.
@ PersistifyMeasurement
Mark the measuremenet for persistification.
@ PersistifyTrackParameters
Mark track parameters for persisitification.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
@ CaloDeposit
This TSOS contains a CaloEnergy object.
DataVector< const Trk::TrackStateOnSurface > TrackStates
ParametersBase< TrackParametersDim, Charged > TrackParameters