ATLAS Offline Software
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
35  declareProperty(
36  "KeepCaloDeposit",
37  m_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",
41  m_keepOutliers,
42  "If this is set to true, Outlier measurements will be kept "
43  "on the slimmed track");
44  declareProperty("KeepParameters",
45  m_keepParameters,
46  "If this is set to true, the first and last parameters will "
47  "be kept on the slimmed track");
48 }
50 
53 {
54 
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 
71 {
72  return StatusCode::SUCCESS;
73 }
74 
75 void
77 {
78  setHints(track);
79  track.info().setTrackProperties(TrackInfo::SlimmedTrack);
80 }
81 
82 void
84 {
85  setHints(track);
86 }
87 
88 void
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 
187 void
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 
216 void
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 
251 bool
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 }
Trk::TrackStateOnSurface::trackParameters
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
Trk::TrackStateOnSurface::CaloDeposit
@ CaloDeposit
This TSOS contains a CaloEnergy object.
Definition: TrackStateOnSurface.h:135
Trk::TrackSlimmingTool::~TrackSlimmingTool
virtual ~TrackSlimmingTool()
default destructor
EnergyLoss.h
xAOD::identify
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
Trk::TrackStateOnSurface::Perigee
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
Definition: TrackStateOnSurface.h:117
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TrackParameters.h
MeasurementBase.h
CompetingRIOsOnTrack.h
Surface.h
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
DataVector::rend
const_reverse_iterator rend() const noexcept
Return a const_reverse_iterator pointing at the beginning of the collection.
Trk::TrackStateOnSurface::PersistifyTrackParameters
@ PersistifyTrackParameters
Mark track parameters for persisitification.
Definition: TrackStateOnSurface.h:167
initialize
void initialize()
Definition: run_EoverP.cxx:894
Trk::Surface::associatedDetectorElementIdentifier
Identifier associatedDetectorElementIdentifier() const
return Identifier of the associated Detector Element
Trk::TrackSlimmingTool::checkForValidMeas
void checkForValidMeas(const Trk::TrackStateOnSurface *tsos, bool &isIDmeas, bool &isMSmeas) const
Definition: TrackSlimmingTool.cxx:188
Trk::TrackStateOnSurface::measurementOnTrack
const MeasurementBase * measurementOnTrack() const
returns MeasurementBase const overload
Trk::TrackSlimmingTool::slimTrack
void slimTrack(Trk::Track &track) const override final
Slim a non const Track.
Definition: TrackSlimmingTool.cxx:76
Trk::TrackStateOnSurface::PersistifyMeasurement
@ PersistifyMeasurement
Mark the measuremenet for persistification.
Definition: TrackStateOnSurface.h:162
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Trk::TrackSlimmingTool::TrackSlimmingTool
TrackSlimmingTool(const std::string &, const std::string &, const IInterface *)
Definition: TrackSlimmingTool.cxx:23
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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
MaterialEffectsOnTrack.h
Trk::TrackInfo::SlimmedTrack
@ SlimmedTrack
A slimmed track.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:87
Trk::MaterialEffectsOnTrack
represents the full description of deflection and e-loss of a track in material.
Definition: MaterialEffectsOnTrack.h:40
Trk::TrackStateOnSurface::type
bool type(const TrackStateOnSurfaceType type) const
Use this method to find out if the TSoS is of a certain type: i.e.
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Trk::CompetingRIOsOnTrack::rioOnTrack
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Trk::MeasurementBaseType::CompetingRIOsOnTrack
@ CompetingRIOsOnTrack
Definition: MeasurementBase.h:50
beamspotman.n
n
Definition: beamspotman.py:731
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
Trk::TrackSlimmingTool::keepParameters
bool keepParameters(const Trk::TrackStateOnSurface *TSoS, const TrackStateOnSurface *&firstValidIDTSOS, const TrackStateOnSurface *&lastValidIDTSOS, const TrackStateOnSurface *&firstValidMSTSOS, const TrackStateOnSurface *&lastValidMSTSOS) const
Definition: TrackSlimmingTool.cxx:252
Trk::CompetingRIOsOnTrack
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
Definition: CompetingRIOsOnTrack.h:64
PseudoMeasurementOnTrack.h
Trk::MeasurementBase::type
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
Trk::TrackSlimmingTool::slimConstTrack
void slimConstTrack(const Trk::Track &track) const override final
Slim a const Track.
Definition: TrackSlimmingTool.cxx:83
TrackSummary.h
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::TrackStateOnSurface::PersistifySlimCaloDeposit
@ PersistifySlimCaloDeposit
Mark track parameters for persisitification.
Definition: TrackStateOnSurface.h:172
DataVector< const Trk::TrackStateOnSurface >
DataVector::rbegin
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
Trk::MeasurementBase
Definition: MeasurementBase.h:58
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
Trk::MeasurementBase::associatedSurface
virtual const Surface & associatedSurface() const =0
Interface method to get the associated Surface.
RIO_OnTrack.h
DataVector< const Trk::TrackStateOnSurface >::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Standard const_reverse_iterator.
Definition: DataVector.h:846
Trk::TrackSlimmingTool::setHints
void setHints(const Trk::Track &track) const
This method just set persistification Hints.
Definition: TrackSlimmingTool.cxx:89
Trk::TrackSlimmingTool::findLastValidTSoS
void findLastValidTSoS(const Trk::TrackStates *oldTrackStates, const Trk::TrackStateOnSurface *&lastValidIDTSOS, const TrackStateOnSurface *&lastValidMSTSOS) const
Definition: TrackSlimmingTool.cxx:217
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Trk::TrackSlimmingTool::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: TrackSlimmingTool.cxx:52
Trk::MaterialEffectsOnTrack::energyLoss
const EnergyLoss * energyLoss() const
returns the energy loss object.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::TrackStateOnSurface::Scatterer
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
Definition: TrackStateOnSurface.h:113
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
Trk::MeasurementBaseType::PseudoMeasurementOnTrack
@ PseudoMeasurementOnTrack
Definition: MeasurementBase.h:51
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
AthAlgTool
Definition: AthAlgTool.h:26
FitQuality.h
Trk::CompetingRIOsOnTrack::indexOfMaxAssignProb
unsigned int indexOfMaxAssignProb() const
Index of the ROT with the highest assignment probability.
Definition: CompetingRIOsOnTrack.cxx:101
TrackSlimmingTool.h
Trk::TrackStateOnSurface::PartialPersistification
@ PartialPersistification
Definition: TrackStateOnSurface.h:158
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
TrackStateOnSurface.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Trk::TrackSlimmingTool::finalize
virtual StatusCode finalize() override
standard Athena-Algorithm method
Definition: TrackSlimmingTool.cxx:70
Identifier
Definition: IdentifierFieldParser.cxx:14