ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimGenScanTool.h
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3#ifndef FPGATrackSimGenScanTool_H
4#define FPGATrackSimGenScanTool_H
5
52
53#include "GaudiKernel/ServiceHandle.h"
55
62
63// new binnning classes
65
66
67#include <string>
68#include <vector>
69#include <utility>
70#include <bit>
71
73
74class FPGATrackSimGenScanTool : public extends<AthAlgTool, IFPGATrackSimRoadFinderTool>
75{
76public:
79
81 using base_class::base_class;
82 FPGATrackSimGenScanTool(const std::string& algname, const std::string &name, const IInterface *ifc);
83
84 virtual StatusCode initialize() override;
85
87 // IFPGATrackSimRoadFinderTool virtual method for interface
88 virtual StatusCode getRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> &hits,
89 std::vector<std::shared_ptr<const FPGATrackSimRoad>> &road) override;
90 virtual int getSubRegion() const override {return 0;}
91
93
94protected:
96 // Handles
97
98 ServiceHandle<IFPGATrackSimEventSelectionSvc> m_EvtSel{this, "FPGATrackSimEventSelectionSvc", ""};
99 ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping{this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"};
100 ToolHandle<FPGATrackSimGenScanMonitoring> m_monitoring {this, "Monitoring", "FPGATrackSimGenScanMonitoring", "Monitoring Tool"};
101 ToolHandle<FPGATrackSimBinnedHits> m_binnedhits {this, "BinnedHits", "FPGATrackSimBinnedHits", "Binned Hits Class"};
102
104 // Properties
105 Gaudi::Property<double> m_rin{this, "rin", {-1.0}, "Radius of inner layer for extrapolations and keylayer definition"};
106 Gaudi::Property<double> m_rout{this, "rout", {-1.0}, "Radius of outer layer for extrapolations and keylayer definition"};
107
108
109 Gaudi::Property<unsigned> m_threshold{this, "threshold", {}, "Minimum value to accept as a road (inclusive)"};
110
111 Gaudi::Property<std::string> m_binFilter{this, "binFilter", {"PairThenGroup"}, "which bin filter to run, current options: PairThenGroup, IncrementalBuild"};
112
113 Gaudi::Property<bool> m_binningOnly{this, "binningOnly", {false}, "Turn off road building to test the binning only"};
114 Gaudi::Property<bool> m_applyPairFilter{this, "applyPairFilter", {}, "Apply Pair Filter"};
115 Gaudi::Property<bool> m_reversePairDir{this, "reversePairDir", {}, "Build Pairs starting at last layer and work in"};
116 Gaudi::Property<std::vector<double>> m_pairFilterDeltaPhiCut{this, "pairFilterDeltaPhiCut", {}, "Pair Filter Delta Phi Cut Value (list one per layer)"};
117 Gaudi::Property<std::vector<double>> m_pairFilterDeltaEtaCut{this, "pairFilterDeltaEtaCut", {}, "Pair Filter Delta Eta Cut Value (list one per layer)"};
118 Gaudi::Property<std::vector<double>> m_pairFilterPhiExtrapCut{this, "pairFilterPhiExtrapCut", {}, "Pair Filter Phi Extrap Cut Value (in/out pair)"};
119 Gaudi::Property<std::vector<double>> m_pairFilterEtaExtrapCut{this, "pairFilterEtaExtrapCut", {}, "Pair Filter Eta Extrap Cut Value(in/out pair)"};
120
121 Gaudi::Property<bool> m_applyPairSetFilter{this, "applyPairSetFilter", {}, "Apply PairSet Filter"};
122 Gaudi::Property<double> m_pairSetMatchPhiCut{this, "pairSetMatchPhiCut", {}, "Pair Set Match Phi Cut Value"};
123 Gaudi::Property<double> m_pairSetMatchEtaCut{this, "pairSetMatchEtaCut", {}, "Pair Set Match Eta Cut Value"};
124 Gaudi::Property<double> m_pairSetDeltaDeltaPhiCut{this, "pairSetDeltaDeltaPhiCut", {}, "Pair Set Delta Delta Phi Cut Value"};
125 Gaudi::Property<double> m_pairSetDeltaDeltaEtaCut{this, "pairSetDeltaDeltaEtaCut", {}, "Pair Set Delta Eta Cut Value"};
126 Gaudi::Property<double> m_pairSetPhiCurvatureCut{this, "pairSetPhiCurvatureCut", {}, "Pair Set Phi Cut Value"};
127 Gaudi::Property<double> m_pairSetEtaCurvatureCut{this, "pairSetEtaCurvatureCut", {}, "Pair Set Eta Cut Value"};
128 Gaudi::Property<double> m_pairSetDeltaPhiCurvatureCut{this, "pairSetDeltaPhiCurvatureCut", {}, "Pair Set Delta Phi Curvature Cut Value"};
129 Gaudi::Property<double> m_pairSetDeltaEtaCurvatureCut{this, "pairSetDeltaEtaCurvatureCut", {}, "Pair Set Delta Eta Curvature Cut Value"};
130 Gaudi::Property<std::vector<double>> m_pairSetPhiExtrapCurvedCut{this, "pairSetPhiExtrapCurvedCut", {}, "Pair Set Phi Extrap Curved Cut Value(in/out pair)"};
131 Gaudi::Property<double> m_phiWeight_4hits{this, "phiChi2Weight_4hits", 1.0, "Weight for phi component of chi2 in genscan fit for 4 hit roads"};
132 Gaudi::Property<double> m_etaWeight_4hits{this, "etaChi2Weight_4hits", 1.0, "Weight for eta component of chi2 in genscan fit for 4 hit roads"};
133 Gaudi::Property<double> m_phiWeight_5hits{this, "phiChi2Weight_5hits", 1.0, "Weight for phi component of chi2 in genscan fit for 5 hit roads"};
134 Gaudi::Property<double> m_etaWeight_5hits{this, "etaChi2Weight_5hits", 1.0, "Weight for eta component of chi2 in genscan fit for 5 hit roads"};
135 Gaudi::Property<bool> m_inBinFiltering {this, "inBinFiltering", true, "Filter roads that appear to be outside their bin"};
136 Gaudi::Property<int> m_keepHitsStrategy {this, "keepHitsStrategy", -1, "If this is less than 0, do nothing. If 1, pick 3 hits furthest apart. If 2, pick 3 inner hits. If 3, pick 3 outer hits. If 4, drop only middle hit for 5/5 otherwise keep all 4 hits for 4/5"};
137
139 // Core
140
141 class HitPair; // pair of StoredHit with methods to make variables to cut on
142 struct HitPairSet; // group of HitPair with methods to make variables to cut on
143
144 // Filter the bins above threshold into pairsets which output roads (2 options)
145 //
146 // Option 1) Originl version described here: https://indico.cern.ch/event/1469103/contributions/6187259/attachments/2952665/5190800/InsideOut_241010.pdf
147 StatusCode pairThenGroupFilter(const BinEntry &bindata, std::vector<HitPairSet> &output_pairset);
148 // Option 2) New version (no external documentation as of now)
149 struct IntermediateState;
150 void updateState(const IntermediateState &inputstate,
151 IntermediateState &outputstate,
152 unsigned lyridx, const std::vector<const StoredHit *>& newhits);
153 StatusCode incrementalBuildFilter(const BinEntry &bindata, std::vector<HitPairSet> &output_pairset);
154
155 // 1st step of filter: sort hits by layer
156 StatusCode sortHitsByLayer(const BinEntry &bindata, std::vector<std::vector<const StoredHit *>> &hitsByLayer);
157
158 // 2nd step of filter: make pairs of hits from adjacent and next-to-adjacent layers
159 StatusCode makePairs(const std::vector<std::vector<const StoredHit *>>& hitsByLayer, HitPairSet &pairs);
160
161 // 3rd step of filter: make cuts on the pairs to ensure that are consisten
162 // with the bin they are in
163 bool pairPassesFilter(const HitPair &pair);
164 StatusCode filterPairs(HitPairSet &pairs, HitPairSet &filteredpairs);
165
166 // 4th step of filter: group pairs into sets where they are all consistent with being from the same track
167 StatusCode groupPairs(HitPairSet &filteredpairs, std::vector<HitPairSet> &clusters, bool verbose);
168
169 // used to determine if a pair is consistend with a pairset
170 bool pairMatchesPairSet(const HitPairSet &pairset, const HitPair &pair, bool verbose);
171
172 // format final pairsets into expected output of getRoads
173 void addRoad(std::vector<const StoredHit *> const &hits, const FPGATrackSimBinUtil::IdxSet &idx);
174
175 // Experimental fit
176 bool fitRoad(std::vector<const StoredHit *> const &hits, const FPGATrackSimBinUtil::IdxSet &idx, FPGATrackSimTrackPars& trackpars, double& chi2, double& chi2_phi,double& chi2_eta ) const;
177
178 std::vector<unsigned> PickHitsToUse(layer_bitmask_t) const;
179
181 // HitPair and HitPairSet Storage Classes
182
183 // Pair of hits, methods gives variable you might want to cut on
184 class HitPair : public std::pair<const StoredHit *, const StoredHit *>
185 {
186 public:
187 HitPair(const StoredHit *first, const StoredHit *second, bool reverse) : std::pair<const StoredHit *, const StoredHit *>(first, second), m_reverse(reverse) {}
188 double dPhi() const { return this->second->phiShift - this->first->phiShift; }
189 double dEta() const { return this->second->etaShift - this->first->etaShift; }
190 double dR() const { return this->second->hitptr->getR() - this->first->hitptr->getR(); }
191
192 // Eta/PhiExtrapolation methods below assume pair is radially ordered
193 // this enables flipping them if working in reverse
194 const HitPair Reversed() const {
195 return HitPair(this->second, this->first, false);
196 }
197
198 double PhiOutExtrap(double r_out) const {
199 if (m_reverse)
200 return Reversed().PhiOutExtrap(r_out);
201 return this->second->phiShift + this->dPhi() / this->dR() * (r_out - this->second->hitptr->getR()); }
202 double PhiInExtrap(double r_in) const {
203 if (m_reverse) return Reversed().PhiInExtrap(r_in);
204 return this->first->phiShift + this->dPhi() / this->dR() * (r_in - this->first->hitptr->getR()); }
205 double EtaOutExtrap(double r_out) const {
206 if (m_reverse) return Reversed().EtaOutExtrap(r_out);
207 return this->second->etaShift + this->dEta() / this->dR() * (r_out - this->second->hitptr->getR()); }
208 double EtaInExtrap(double r_in) const {
209 if (m_reverse) return Reversed().EtaInExtrap(r_in);
210 return this->first->etaShift + this->dEta() / this->dR() * (r_in - this->first->hitptr->getR()); }
211
212 private:
214 };
215
216 // Pair of hits, methods gives variable you might want to cut on
218 {
220 // Data
221
222 // list of hit pairs
223 std::vector<HitPair> pairList{};
224
225 // bit mask of layers hit
227
228 // list of hits in all included pairs
229 std::vector<const StoredHit *> hitlist{};
230
231 // saves curvatures from last pair added so change in curvature can be calculated
232 double LastPhiCurvature = 0.;
233 double LastEtaCurvature = 0.;
234
236 // Methods - name are hopefully clear
237 int addPair(const HitPair &pair);
238 const HitPair &lastpair() const { return pairList.back(); }
239 const HitPair &secondtolastpair() const { return *std::prev(pairList.end(), 2); }
240
241 bool hasHit(const StoredHit *hit) const;
242 bool hasLayer(int layer) const { return ((hitLayers & (0x1 << layer)) != 0); }
243 unsigned int lyrCnt() const { return __builtin_popcount(hitLayers); }
244
245 // variable to check if new pair is consistent with last pair added to pairset
246 double MatchPhi(const HitPair &pair) const;
247 double MatchEta(const HitPair &pair) const;
248
249 double DeltaDeltaPhi(const HitPair &pair) const;
250
251 double DeltaDeltaEta(const HitPair &pair) const;
252
253 double PhiCurvature(const HitPair &pair) const;
254 double EtaCurvature(const HitPair &pair) const;
255
256 double DeltaPhiCurvature(const HitPair &pair) const;
257 double DeltaEtaCurvature(const HitPair &pair) const;
258 double PhiInExtrapCurved(const HitPair &pair, double r_in) const;
259 double PhiOutExtrapCurved(const HitPair &pair, double r_out) const;
260 };
261
262 // state structure used by buildGroupsWithPairs method
264 std::vector<const StoredHit *> unpairedHits{};
265 std::vector<HitPairSet> pairsets{};
266 };
267
269 // Event Storage
271 std::vector<unsigned int> m_pairingLayers;
272
273 // output roads
274 std::vector<std::unique_ptr<FPGATrackSimRoad>> m_roads{};
275};
276
277#endif // FPGATrackSimGenScanTool_H
Binning Classes for GenScanTool.
: FPGATrackSim-specific class to represent an hit in the detector.
Defines a class for roads.
uint32_t layer_bitmask_t
Interface declaration for road finder tools.
double PhiOutExtrap(double r_out) const
HitPair(const StoredHit *first, const StoredHit *second, bool reverse)
double EtaOutExtrap(double r_out) const
Gaudi::Property< double > m_pairSetMatchPhiCut
bool pairMatchesPairSet(const HitPairSet &pairset, const HitPair &pair, bool verbose)
bool fitRoad(std::vector< const StoredHit * > const &hits, const FPGATrackSimBinUtil::IdxSet &idx, FPGATrackSimTrackPars &trackpars, double &chi2, double &chi2_phi, double &chi2_eta) const
StatusCode groupPairs(HitPairSet &filteredpairs, std::vector< HitPairSet > &clusters, bool verbose)
Gaudi::Property< double > m_etaWeight_4hits
FPGATrackSimGenScanTool(const std::string &algname, const std::string &name, const IInterface *ifc)
Gaudi::Property< std::vector< double > > m_pairFilterDeltaEtaCut
virtual StatusCode initialize() override
bool pairPassesFilter(const HitPair &pair)
virtual int getSubRegion() const override
Gaudi::Property< double > m_pairSetDeltaDeltaPhiCut
Gaudi::Property< double > m_pairSetDeltaEtaCurvatureCut
std::vector< unsigned > PickHitsToUse(layer_bitmask_t) const
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Gaudi::Property< int > m_keepHitsStrategy
Gaudi::Property< double > m_phiWeight_5hits
Gaudi::Property< double > m_rin
Gaudi::Property< std::string > m_binFilter
Gaudi::Property< std::vector< double > > m_pairSetPhiExtrapCurvedCut
Gaudi::Property< double > m_pairSetDeltaDeltaEtaCut
Gaudi::Property< unsigned > m_threshold
Gaudi::Property< double > m_pairSetEtaCurvatureCut
Gaudi::Property< double > m_pairSetMatchEtaCut
Gaudi::Property< bool > m_applyPairFilter
void addRoad(std::vector< const StoredHit * > const &hits, const FPGATrackSimBinUtil::IdxSet &idx)
virtual StatusCode getRoads(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, std::vector< std::shared_ptr< const FPGATrackSimRoad > > &road) override
std::vector< unsigned int > m_pairingLayers
Gaudi::Property< bool > m_binningOnly
StatusCode sortHitsByLayer(const BinEntry &bindata, std::vector< std::vector< const StoredHit * > > &hitsByLayer)
StatusCode pairThenGroupFilter(const BinEntry &bindata, std::vector< HitPairSet > &output_pairset)
Gaudi::Property< double > m_etaWeight_5hits
Gaudi::Property< double > m_phiWeight_4hits
StatusCode filterPairs(HitPairSet &pairs, HitPairSet &filteredpairs)
Gaudi::Property< std::vector< double > > m_pairFilterPhiExtrapCut
Gaudi::Property< std::vector< double > > m_pairFilterDeltaPhiCut
StatusCode makePairs(const std::vector< std::vector< const StoredHit * > > &hitsByLayer, HitPairSet &pairs)
Gaudi::Property< bool > m_reversePairDir
FPGATrackSimBinnedHits::BinEntry BinEntry
Gaudi::Property< double > m_rout
std::vector< std::unique_ptr< FPGATrackSimRoad > > m_roads
StatusCode incrementalBuildFilter(const BinEntry &bindata, std::vector< HitPairSet > &output_pairset)
FPGATrackSimBinUtil::StoredHit StoredHit
Gaudi::Property< std::vector< double > > m_pairFilterEtaExtrapCut
Gaudi::Property< bool > m_inBinFiltering
ToolHandle< FPGATrackSimBinnedHits > m_binnedhits
void updateState(const IntermediateState &inputstate, IntermediateState &outputstate, unsigned lyridx, const std::vector< const StoredHit * > &newhits)
Gaudi::Property< bool > m_applyPairSetFilter
Gaudi::Property< double > m_pairSetPhiCurvatureCut
Gaudi::Property< double > m_pairSetDeltaPhiCurvatureCut
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
ToolHandle< FPGATrackSimGenScanMonitoring > m_monitoring
STL class.
double chi2(TH1 *h0, TH1 *h1)
bool verbose
Definition hcg.cxx:73
STL namespace.
double PhiCurvature(const HitPair &pair) const
double MatchPhi(const HitPair &pair) const
double DeltaDeltaPhi(const HitPair &pair) const
bool hasHit(const StoredHit *hit) const
double PhiInExtrapCurved(const HitPair &pair, double r_in) const
double DeltaDeltaEta(const HitPair &pair) const
double EtaCurvature(const HitPair &pair) const
double MatchEta(const HitPair &pair) const
double DeltaEtaCurvature(const HitPair &pair) const
double PhiOutExtrapCurved(const HitPair &pair, double r_out) const
double DeltaPhiCurvature(const HitPair &pair) const
std::vector< const StoredHit * > hitlist