ATLAS Offline Software
Loading...
Searching...
No Matches
MuonTrackCleaner.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef MUON_MUONTRACKCLEANER_H
6#define MUON_MUONTRACKCLEANER_H
7
9#include "GaudiKernel/ServiceHandle.h"
10#include "GaudiKernel/ToolHandle.h"
22
23// For magneticfield
24#include <set>
25#include <string>
26
34
35namespace Trk {
36 class Track;
37 class TrackStateOnSurface;
38 class MeasurementBase;
39 class FitQuality;
40} // namespace Trk
41
42namespace Muon {
43
44 class MuonTrackCleaner : virtual public extends<AthAlgTool, IMuonTrackCleaner> {
45 public:
50 int useInFit{1};
51 bool inBounds{true};
52 bool isNoise{false};
53 bool copyState{true}; // if true the state will be copied instead of evaluated for outliers
54 double residual{DBL_MAX};
55 double pull{DBL_MAX};
57 const Trk::MeasurementBase* meas{nullptr};
58 const Trk::TrackParameters* pars{nullptr};
59 std::optional<Trk::ResidualPull> resPull{std::nullopt};
60 std::unique_ptr<MdtDriftCircleOnTrack> flippedMdt{nullptr};
61 std::unique_ptr<const CompetingMuonClustersOnTrack> cleanedCompROT{nullptr};
62 const Trk::FitQuality* fitQ{nullptr};
63
66
67 MCTBCleaningInfo(const Identifier& i, const Identifier& chi, MuonStationIndex::ChIndex chIn, bool inB, double r, double p,
68 const Trk::TrackStateOnSurface* orState) :
69 id(i),
70 chId(chi),
71 chIndex(chIn),
72 inBounds(inB),
73 residual(r),
74 pull(p),
75 originalState(orState){}
76
77 MCTBCleaningInfo(const Identifier& i, const Identifier& chi, MuonStationIndex::ChIndex chIn, bool inB, double r, double p,
78 const Trk::TrackStateOnSurface* orState, const Trk::MeasurementBase* me, const Trk::TrackParameters* par,
79 std::optional<Trk::ResidualPull>&& resP, const Trk::FitQuality* fq) :
80 id(i),
81 chId(chi),
82 chIndex(chIn),
83 inBounds(inB),
84 copyState{false},
85 residual(r),
86 pull(p),
87 originalState(orState),
88 meas(me),
89 pars(par),
90 resPull(std::move(resP)),
91 fitQ(fq) {}
92 };
93 typedef std::vector<MCTBCleaningInfo> InfoVec;
94 typedef InfoVec::iterator InfoIt;
95
96 typedef std::set<const Trk::MeasurementBase*> MeasSet;
97 typedef MeasSet::iterator MeasIt;
98
102 std::unique_ptr<Trk::Track> track;
104 std::vector<MCTBCleaningInfo*> removedHits;
105 };
107 bool operator()(const ChamberRemovalOutput& r1, const ChamberRemovalOutput& r2) const {
108 SortTracksByChi2Ndof sortTracks;
109 return sortTracks(r1.track.get(), r2.track.get());
110 }
111 };
112
114 ChamberPullInfo() = default;
115 double pullSum{0.};
116 double maxPull{0.};
117 int nhits{0};
118 };
119 typedef std::map<Identifier, ChamberPullInfo> PullChamberMap;
120 typedef PullChamberMap::iterator PullChamberIt;
121 typedef PullChamberMap::const_iterator PullChamberCit;
122
123 struct EtaPhiHits {
124 EtaPhiHits() = default;
125 int neta{0};
126 int nphi{0};
127 };
128 typedef std::map<Identifier, EtaPhiHits> EtaPhiPerChamberMap;
129 typedef EtaPhiPerChamberMap::iterator EtaPhiPerChamberIt;
130
131 typedef std::vector<std::pair<double, Identifier>> PullChVec;
132 typedef PullChVec::iterator PullChIt;
133
135 bool operator()(const std::pair<double, Identifier>& entry1, const std::pair<double, Identifier>& entry2) const {
136 return entry1.first > entry2.first;
137 }
138 };
139
149
150 // struct to hold the internal state information, i.e. the various track properties relevant for the cleaner
156
157 // need to keep these somewhere while they're being used: couldn't figure out how to make unique_ptr work with
158 // Trk::TrackParameter given the inheritance issues
159 std::vector<std::unique_ptr<Trk::TrackParameters>> parsToBeDeleted{};
160
161 unsigned int nscatterers{0};
162 unsigned int nhits{0};
163 unsigned int noutliers{0};
164
165 bool slFit{false};
166 unsigned int nIdHits{0};
167 unsigned int nPseudoMeasurements{0};
168 unsigned int nPhiConstraints{0};
169
170 unsigned int numberOfFlippedMdts{0};
171 unsigned int numberOfCleanedCompROTs{0};
174 bool hasSmall{false};
175 bool hasLarge{false};
176
180
183
187
190
191 std::set<MuonStationIndex::StIndex> stations{};
192 std::set<MuonStationIndex::PhiIndex> phiLayers{};
193
194 std::map<MuonStationIndex::ChIndex, ChamberLayerStatistics> chamberLayerStatistics{};
195
196 std::set<Identifier> chamberRemovalExclusionList{};
197 CleaningState() = default;
198 };
199
200 public:
201 using base_class::base_class;
203 ~MuonTrackCleaner() = default;
204
206 StatusCode initialize() override;
207
212 std::unique_ptr<Trk::Track> clean(const Trk::Track& track, const EventContext& ctx) const override;
213
219 std::unique_ptr<Trk::Track> clean(const Trk::Track& track, const std::set<Identifier>& chamberRemovalExclusionList,
220 const EventContext& ctx) const override;
221
222 private:
225
227 std::unique_ptr<Trk::Track> cleanTrack(const EventContext& ctx, const Trk::Track* track, CleaningState& state) const;
228
230 double calcPull(const double residual, const double locMesCov, const double locTrkCov, const bool& trkStateIsUnbiased) const;
231
233 std::unique_ptr<Trk::Track> cleanCompROTs(const EventContext& ctx, std::unique_ptr<Trk::Track> track, CleaningState& state) const;
234
236 std::unique_ptr<Trk::Track> recoverFlippedMdt(const EventContext& ctx, std::unique_ptr<Trk::Track> track,
237 CleaningState& state) const;
238
240 std::unique_ptr<Trk::Track> hitCleaning(const EventContext& ctx, std::unique_ptr<Trk::Track> track, CleaningState& state) const;
241
243 std::unique_ptr<Trk::Track> chamberCleaning(const EventContext& ctx, std::unique_ptr<Trk::Track> track, CleaningState& state) const;
244
248 std::unique_ptr<Trk::Track> outlierRecovery(const EventContext& ctx, std::unique_ptr<Trk::Track> track, CleaningState& state,
249 const MuonStationIndex::ChIndex* currentIndex = nullptr) const;
250
252 bool isOutsideOnTrackCut(const Identifier& id, double res, double pull, double cutScaleFactor) const;
253
255 ChamberRemovalOutput removeChamber(const EventContext& ctx, const std::unique_ptr<Trk::Track>& track, Identifier chId,
256 bool removePhi, bool removeEta, CleaningState& state) const;
257
259 void init(const EventContext& ctx, const Trk::Track& track, CleaningState& state) const;
260
261 // check for station removal
262 bool checkStations(CleaningState& state) const;
263
264 // check for failure due to inner removal
265 bool checkInnerConstraint(CleaningState& state) const;
266
267 // check for not enough phi constraints
268 bool checkPhiConstraint(CleaningState& state) const;
269
270 // unremove hits for next iteration of chamber cleaning
272
273 // print track states
274 void printStates(Trk::Track* track) const;
275
276 // choose fitter and fit
277 std::unique_ptr<Trk::Track> fitTrack(const EventContext& ctx, Trk::Track& track, Trk::ParticleHypothesis pHyp, bool slFit) const;
278
279 ToolHandle<Trk::ITrackFitter> m_trackFitter{
280 this,
281 "Fitter",
282 "Trk::GlobalChi2Fitter/MCTBFitterMaterialFromTrack",
283 };
284 ToolHandle<Trk::ITrackFitter> m_slTrackFitter{this, "SLFitter", "Trk::GlobalChi2Fitter/MCTBSLFitterMaterialFromTrack"};
285 ToolHandle<Trk::IUpdator> m_measurementUpdator{this, "MeasurementUpdator", "Trk::KalmanUpdator/MuonMeasUpdator"};
286 ToolHandle<Muon::IMdtDriftCircleOnTrackCreator> m_mdtRotCreator{this, "MdtRotCreator",
287 "Muon::MdtDriftCircleOnTrackCreator/MdtDriftCircleOnTrackCreator"};
288 ToolHandle<IMuonCompetingClustersOnTrackCreator> m_compRotCreator{
289 this, "CompRotCreator", "Muon::TriggerChamberClusterOnTrackCreator/TriggerChamberClusterOnTrackCreator"};
290 ToolHandle<Trk::IResidualPullCalculator> m_pullCalculator{this, "PullCalculator",
291 "Trk::ResidualPullCalculator/ResidualPullCalculator"};
292 ServiceHandle<Muon::IMuonEDMHelperSvc> m_edmHelperSvc{this, "edmHelper", "Muon::MuonEDMHelperSvc/MuonEDMHelperSvc",
293 "Handle to the service providing the IMuonEDMHelperSvc interface"};
294 PublicToolHandle<Muon::MuonEDMPrinterTool> m_printer{this, "Printer", "Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"};
295 ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
296 ToolHandle<Trk::IExtrapolator> m_extrapolator{this, "Extrapolator", "Trk::Extrapolator/AtlasExtrapolator"};
297 // Read handle for conditions object to get the field cache
299 "Name of the Magnetic Field conditions object key"};
300
301 Gaudi::Property<bool> m_useMdtResiCut{this, "UseMdtResiCut", false};
302 Gaudi::Property<double> m_chi2Cut{this, "Chi2Cut", 100.};
303 Gaudi::Property<double> m_pullCut{this, "PullCut", 5.};
304 Gaudi::Property<double> m_mdtResiCut{this, "MdtResiCut", 1.};
305 Gaudi::Property<double> m_pullCutPhi{this, "PullCutPhi", 10.};
306 Gaudi::Property<double> m_associationScaleFactor{this, "AssociationScaleFactor", 0.7};
307 Gaudi::Property<unsigned int> m_ncycles{this, "CleaningCycles", 5};
308 Gaudi::Property<double> m_avePullSumPerChamberCut{this, "MaxAvePullSumPerChamber", 3.5};
309 Gaudi::Property<bool> m_recoverOutliers{this, "RecoverOutliers", true};
310 Gaudi::Property<bool> m_flipMdtDriftRadii{this, "FlipMdtDriftRadii", true};
311 Gaudi::Property<bool> m_cleanCompROTs{this, "CleanCompROTs", true};
312 Gaudi::Property<bool> m_onlyUseHitErrorInRecovery{this, "OnlyUseHitErrorInRecovery", true};
313 Gaudi::Property<double> m_adcCut{this, "AdcCut", 50.};
314 Gaudi::Property<bool> m_iterate{this, "Iterate", 0.7};
315 Gaudi::Property<bool> m_use_slFit{this, "UseSLFit", false};
316
318 bool extractChambersToBeRemoved(CleaningState& state, std::set<Identifier>& chambersToBeRemovedSet, bool usePhi = false) const;
319
320 static std::string print(ChamberLayerStatistics& statistics) ;
321 };
322
323} // namespace Muon
324
325#endif
std::pair< std::vector< unsigned int >, bool > res
Define macros for attributes used to control the static checker.
#define ATLAS_CHECK_FILE_THREAD_SAFETY
ToolHandle< Trk::IExtrapolator > m_extrapolator
ServiceHandle< Muon::IMuonEDMHelperSvc > m_edmHelperSvc
PullChamberMap::const_iterator PullChamberCit
bool checkPhiConstraint(CleaningState &state) const
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
void init(const EventContext &ctx, const Trk::Track &track, CleaningState &state) const
init cleaner
bool extractChambersToBeRemoved(CleaningState &state, std::set< Identifier > &chambersToBeRemovedSet, bool usePhi=false) const
helper function to extract chambers that are to be removed
bool checkStations(CleaningState &state) const
std::unique_ptr< Trk::Track > outlierRecovery(const EventContext &ctx, std::unique_ptr< Trk::Track > track, CleaningState &state, const MuonStationIndex::ChIndex *currentIndex=nullptr) const
recover outliers that are within the cuts.
std::map< Identifier, EtaPhiHits > EtaPhiPerChamberMap
ToolHandle< IMuonCompetingClustersOnTrackCreator > m_compRotCreator
Gaudi::Property< double > m_avePullSumPerChamberCut
ToolHandle< Muon::IMdtDriftCircleOnTrackCreator > m_mdtRotCreator
bool checkInnerConstraint(CleaningState &state) const
~MuonTrackCleaner()=default
destructor
std::unique_ptr< Trk::Track > cleanCompROTs(const EventContext &ctx, std::unique_ptr< Trk::Track > track, CleaningState &state) const
clean up competing ROTs that consist out of two clusters
ToolHandle< Trk::IResidualPullCalculator > m_pullCalculator
MeasSet::iterator MeasIt
std::unique_ptr< Trk::Track > clean(const Trk::Track &track, const EventContext &ctx) const override
clean a track, returns a pointer to a new track if successfull.
std::map< Identifier, ChamberPullInfo > PullChamberMap
InfoVec::iterator InfoIt
std::unique_ptr< Trk::Track > fitTrack(const EventContext &ctx, Trk::Track &track, Trk::ParticleHypothesis pHyp, bool slFit) const
Gaudi::Property< bool > m_cleanCompROTs
Gaudi::Property< double > m_associationScaleFactor
EtaPhiPerChamberMap::iterator EtaPhiPerChamberIt
static void unremoveHits(ChamberRemovalOutput &result)
StatusCode initialize() override
AlgTool initialize.
Gaudi::Property< bool > m_onlyUseHitErrorInRecovery
std::unique_ptr< Trk::Track > chamberCleaning(const EventContext &ctx, std::unique_ptr< Trk::Track > track, CleaningState &state) const
remove bad chamber from track.
std::vector< std::pair< double, Identifier > > PullChVec
std::unique_ptr< Trk::Track > cleanTrack(const EventContext &ctx, const Trk::Track *track, CleaningState &state) const
clean a track, actual implementation
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCacheCondObjInputKey
ToolHandle< Trk::ITrackFitter > m_trackFitter
std::vector< MCTBCleaningInfo > InfoVec
Gaudi::Property< double > m_pullCutPhi
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
bool isOutsideOnTrackCut(const Identifier &id, double res, double pull, double cutScaleFactor) const
check whether hit is an outlier
std::unique_ptr< Trk::Track > hitCleaning(const EventContext &ctx, std::unique_ptr< Trk::Track > track, CleaningState &state) const
remove bad hits from track.
Gaudi::Property< bool > m_iterate
Gaudi::Property< bool > m_flipMdtDriftRadii
const Trk::ResidualPull * calculateResPul(const Trk::MeasurementBase &meas, const Trk::TrackParameters &pars) const
calculate Residual/Pull for a given MeasurementBase + TrackParameters, ownership is transfered to use...
ToolHandle< Trk::ITrackFitter > m_slTrackFitter
Gaudi::Property< double > m_adcCut
void printStates(Trk::Track *track) const
double calcPull(const double residual, const double locMesCov, const double locTrkCov, const bool &trkStateIsUnbiased) const
calculate the pull given measurement error and track error
ToolHandle< Trk::IUpdator > m_measurementUpdator
PullChamberMap::iterator PullChamberIt
Gaudi::Property< double > m_mdtResiCut
static std::string print(ChamberLayerStatistics &statistics)
Gaudi::Property< bool > m_recoverOutliers
ChamberRemovalOutput removeChamber(const EventContext &ctx, const std::unique_ptr< Trk::Track > &track, Identifier chId, bool removePhi, bool removeEta, CleaningState &state) const
remove chamber from track
Gaudi::Property< unsigned int > m_ncycles
PullChVec::iterator PullChIt
std::set< const Trk::MeasurementBase * > MeasSet
Gaudi::Property< double > m_pullCut
std::unique_ptr< Trk::Track > recoverFlippedMdt(const EventContext &ctx, std::unique_ptr< Trk::Track > track, CleaningState &state) const
flip signs of MDT hits with large pull if pull if the oppositely signed radius is small
Gaudi::Property< double > m_chi2Cut
Gaudi::Property< bool > m_useMdtResiCut
Gaudi::Property< bool > m_use_slFit
Class to represent and store fit qualities from track reconstruction in terms of and number of degre...
Definition FitQuality.h:97
This class is the pure abstract base class for all fittable tracking measurements.
This class containes residual and pull information.
represents the track state (measurement, material, fit parameters and quality) at a surface.
int r
Definition globals.cxx:22
ChIndex
enum to classify the different chamber layers in the muon spectrometer
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Ensure that the ATLAS eigen extensions are properly loaded.
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.
ParametersBase< TrackParametersDim, Charged > TrackParameters
STL namespace.
struct to store return values of chamber removal, contains the new track plus a list the removed hits
std::vector< MCTBCleaningInfo * > removedHits
std::set< MuonStationIndex::PhiIndex > phiLayers
std::map< MuonStationIndex::ChIndex, ChamberLayerStatistics > chamberLayerStatistics
std::set< MuonStationIndex::StIndex > stations
std::set< Identifier > chamberRemovalExclusionList
std::vector< std::unique_ptr< Trk::TrackParameters > > parsToBeDeleted
std::optional< Trk::ResidualPull > resPull
MCTBCleaningInfo(const Identifier &i, const Identifier &chi, MuonStationIndex::ChIndex chIn, bool inB, double r, double p, const Trk::TrackStateOnSurface *orState)
MCTBCleaningInfo(const Identifier &i, const Identifier &chi, MuonStationIndex::ChIndex chIn, bool inB, double r, double p, const Trk::TrackStateOnSurface *orState, const Trk::MeasurementBase *me, const Trk::TrackParameters *par, std::optional< Trk::ResidualPull > &&resP, const Trk::FitQuality *fq)
const Trk::TrackStateOnSurface * originalState
std::unique_ptr< MdtDriftCircleOnTrack > flippedMdt
MCTBCleaningInfo(const Trk::TrackStateOnSurface *orState)
std::unique_ptr< const CompetingMuonClustersOnTrack > cleanedCompROT
bool operator()(const std::pair< double, Identifier > &entry1, const std::pair< double, Identifier > &entry2) const
bool operator()(const ChamberRemovalOutput &r1, const ChamberRemovalOutput &r2) const