ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimHough1DShiftTool.h
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3#ifndef FPGATRACKSIMHOUGH1DSHIFTTOOL_H
4#define FPGATRACKSIMHOUGH1DSHIFTTOOL_H
5
39
40#include "GaudiKernel/ServiceHandle.h"
42
53
54#include "TFile.h"
55
56#include <string>
57#include <vector>
58#include <map>
59#include <boost/dynamic_bitset.hpp>
60
61
62
63/*
64 * The hits of an event are stored in a bit vector for each layer, with the number
65 * of bits being the number of phi bins. A hit sets a bit (or a range of bits to
66 * account for resolution effects) in the respective layer's bit vector.
67 *
68 * Shifting phi is now simply a bit shift of the bit vectors. Roads are created
69 * whenever a threshold number of layers have the same phi bin set after the shift.
70 *
71 * Shifts are precalculated in the initialize routine. Instead of iterating over
72 * q/pt, we can iterate over n-bin shift increments in the outer layer. Each shift
73 * in the outer layer uniquely determines a q/pt and the corresponding shifts in
74 * the other layers. This is better than a q/pt scan by taking into account the
75 * quantization in the binning. Actually, we can optimize even better by iterating
76 * over n-bin shifts in the difference between the inner and outer layer, to help
77 * account also for the hit extension.
78 *
79 * I use the following units for relevant variables:
80 * x,y,z,r : mm
81 * q : e
82 * pT : GeV / c
83 */
84class FPGATrackSimHough1DShiftTool : public extends <AthAlgTool, IFPGATrackSimRoadFinderTool>
85{
86 public:
88 using base_class::base_class;
89
90 virtual StatusCode initialize() override;
91 virtual StatusCode finalize() override;
92
94 // FPGATrackSimRoadFinderToolI
95
96 virtual StatusCode getRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads) override;
97 virtual int getSubRegion() const override{return m_subRegion;}
98 private:
99
101 // Handles
102 ServiceHandle<IFPGATrackSimEventSelectionSvc> m_EvtSel {this, "FPGATrackSimEventSelectionSvc", ""};
103 ServiceHandle<IFPGATrackSimBankSvc> m_FPGATrackSimBankSvc {this, "FPGATrackSimBankSvc", "FPGATrackSimBankSvc"};
104 ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping {this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"};
105
107 // Properties
108
109 Gaudi::Property<bool> m_traceHits { this, "traceHits", true, "Trace each hit that goes in a bin. Disabling this will save memory/time since each bin doesn't have to store all its hits but the roads created won't have hits from convolution, etc."};
110
111 Gaudi::Property<bool> m_doEtaPatternConsts { this, "doEtaPatternConsts", false, "Whether to use the eta pattern tool for constant generation"};
112 Gaudi::Property<bool> m_useSpacePoints { this, "useSpacePoints", false, "Whether we are using spacepoints." };
113 Gaudi::Property<bool> m_useSectors { this, "useSectors", false, "Will reverse calculate the sector for track-fitting purposes" };
114 Gaudi::Property<bool> m_idealGeoRoads { this, "IdealGeoRoads", false, "Set sectors to use ideal geometry fit constants" };
115 Gaudi::Property<bool> m_doRegionalMapping { this, "RegionalMapping", false, "Use the sub-region maps to define the sector" };
116 Gaudi::Property<bool> m_drawHitMasks { this, "drawHitMasks", false, "Draws hit masks if true"};
117
118 Gaudi::Property<int> m_subRegion { this, "subRegion", 0, "Sub region of this transform, or -1 for full region" };
119 Gaudi::Property<float> m_phiMin { this, "phiMin", 0, "Minimum phi of transform" };
120 Gaudi::Property<float> m_phiMax { this, "phiMax", 0, "Maximum phi of transform" };
121 Gaudi::Property<float> m_qptMin { this, "qptMin", 0, "Minimum q/pT of transform" };
122 Gaudi::Property<float> m_qptMax { this, "qptMax", 0, "Maximum q/pT of transform" };
123
124 Gaudi::Property<unsigned> m_phiBins { this, "nBins", 0, "Number of phi bins used by transform." };
125 Gaudi::Property<unsigned> m_threshold { this, "threshold", 0, "Minimum number of layers hit to accept as a road (inclusive)" };
126 Gaudi::Property<unsigned> m_iterStep { this, "iterStep", 0, "Instead of iterating over steps in pT, we iterate over iterStep-bin shifts in iterLayer" };
127 Gaudi::Property<unsigned> m_iterLayer { this, "iterLayer", 0, "Instead of iterating over steps in pT, we iterate over iterStep-bin shifts in iterLayer" };
128
129 Gaudi::Property<bool> m_useDiff { this, "useDiff", false, "Use the diff of inner and outer layer" };
130 Gaudi::Property<bool> m_variableExtend { this, "variableExtend", false, "Do variable extension based off of hit delta R" };
131 Gaudi::Property<bool> m_phiRangeCut {this, "phiRangeCut", false, "Require tracks to be in phi range to avoid counting minbias roads for larger region" };
132
133 Gaudi::Property<float> m_d0spread {this, "d0spread", -1.0, "Make patterns with a d0spread as given, negative value turns it off" };
134 Gaudi::Property<std::vector<float>> m_hitExtendProperty {this, "hitExtend", {}, "Number of adjacent bins that a hit triggers" };
135 Gaudi::Property<std::string> m_bitShift_path { this, "bitShifts", "", "Instead of calculating bit shifts, input a list of shifts via a text file" };
136 Gaudi::Property<bool> m_applyDropable { this, "applyDropable", false, "Enable logic that prevents redundant patterns with dropped hits" };
137 Gaudi::Property<int> m_neighborWindow { this, "neighborWindow", 0, "Supress if neighbors have higher number of hit layers" };
138 Gaudi::Property<unsigned> m_historyWindow {this, "historyWindow", 0, "Suppress if previous N bit shifts have neighbors with higher nubmer of hit layers" };
139 Gaudi::Property<bool> m_fieldCorrection {this, "fieldCorrection", true, "Apply corrections to hough equation due to field nonuniformity" };
140 Gaudi::Property<float> m_enhanceHighPt {this, "enhanceHighPt", -1.0, "if positive, double number of patterns for region with qpT below value" };
141
142
143 std::vector<float> m_hitExtend; // need second copy because property is "const" and can't be changed to default
144 std::vector<float> m_r; // will be filled from m_radii_file (now loaded through region map class).
145
147 // Convenience
148
149 unsigned m_nLayers = 0; // alias to m_FPGATrackSimMapping->PlaneMap1stStage()->getNLogiLayers();
150
151 float m_phiStep = 0; // width of one phi bin
152 std::vector<double> m_bins; // size == m_phiBins + 1.
153 // Bin boundaries, where m_bins[i] is the lower bound of bin i.
154 // These are calculated from m_phiMin/Max.
155
156 FPGATrackSimTrackPars m_regionMin; // alias to m_EvtSel->getRegions()->getMin(m_EvtSel->getReginID())
157 FPGATrackSimTrackPars m_regionMax; // alias to m_EvtSel->getRegions()->getMax(m_EvtSel->getReginID())
158
159 std::vector<std::vector<int>> m_shifts; // size (nShifts, nLayers)
160 std::vector<boost::dynamic_bitset<>> m_dropable; // size (nShifts, nLayers)
161 // for shift patterns, we can cut duplication by only allowing some layers to be missed when doing 7/8
162
163 std::vector<float> m_qpt; // size (nShifts)
164 std::vector<std::vector<float>> m_phivals; // size (nShifts, nLayers)
165 std::vector<std::vector<int>> m_d0shifts; // size (nShifts, nLayers), optional subshifts by d0
166 std::vector<unsigned> m_currentcounts; // just here so we don't reallocate every call
167 std::deque<std::vector<unsigned>> m_vetolist; // last N events, bit string of hit layers per bin
168
169
171 // Event Storage
172
173 std::vector<FPGATrackSimRoad> m_roads;
174
176 // Metadata and Monitoring
177
178 unsigned m_event = 0;
179 std::string m_name; // Gets the instance name from the full gaudi name
181
183 // Helpers
184
185 void calculateShifts();
186 float getPtFromShiftDiff(int shift) const;
187 void readShifts(std::string const & filepath);
188 std::vector<boost::dynamic_bitset<>> makeHitMasks(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits);
189
190 FPGATrackSimRoad makeRoad(const std::vector<std::shared_ptr<const FPGATrackSimHit>>& hits, int bin_track, size_t iShift);
191 bool passThreshold(std::vector<boost::dynamic_bitset<>>& binHits, int bin ) const;
192 void printHitMasks(std::vector<boost::dynamic_bitset<>> const & hitMasks) const;
193
194 void drawHitMasks(std::vector<boost::dynamic_bitset<>> const & hitMasks, std::string const & name);
195 void drawHitMasks(std::vector<boost::dynamic_bitset<>> const & hitMasks, std::string const & name, std::vector<int> const & shifts);
196 void printShifts() const;
197
198 std::pair<int, int> getBins(const std::shared_ptr<const FPGATrackSimHit>& hit) const;
199 float phitrkDiff(float r1, float phi1, float r2, float phi2) const;
200 std::pair<float, bool> phitrk(int bin, std::vector<int> const & shifts ) const; // returns phi of track and a bool if the
201 // value is invalid because at the edge
202 float qPt(float r, float deltaPhi) const;
203 float deltaPhi(float r, float qPt) const;
204
205 void calculated0Shifts();
206 std::vector<int> applyVariation(const std::vector<int>& base, const std::vector<int>& var, int sign) const;
207 void calculateDropable();
208 std::vector<int> shiftWithDrop(std::vector<int>& shift,unsigned droplayer) const;
209
210
211};
212
213
214#endif // FPGATRACKSIMHOUGH1DSHIFTTOOL_H
: FPGATrackSim-specific class to represent an hit in the detector.
Defines a class for roads.
Structs that store the 5 track parameters.
Defines several vector wrappers for homogenous multi-dimensional vectors, declared as 1D arrays for l...
Interface declaration for road finder tools.
int sign(int a)
std::vector< FPGATrackSimRoad > m_roads
std::vector< int > applyVariation(const std::vector< int > &base, const std::vector< int > &var, int sign) const
std::vector< std::vector< int > > m_d0shifts
std::deque< std::vector< unsigned > > m_vetolist
Gaudi::Property< unsigned > m_threshold
std::pair< int, int > getBins(const std::shared_ptr< const FPGATrackSimHit > &hit) const
FPGATrackSimRoad makeRoad(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, int bin_track, size_t iShift)
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
void readShifts(std::string const &filepath)
Gaudi::Property< std::vector< float > > m_hitExtendProperty
std::vector< boost::dynamic_bitset<> > m_dropable
Gaudi::Property< unsigned > m_historyWindow
void drawHitMasks(std::vector< boost::dynamic_bitset<> > const &hitMasks, std::string const &name)
virtual StatusCode getRoads(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, std::vector< std::shared_ptr< const FPGATrackSimRoad > > &roads) override
std::vector< boost::dynamic_bitset<> > makeHitMasks(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits)
std::vector< std::vector< float > > m_phivals
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
bool passThreshold(std::vector< boost::dynamic_bitset<> > &binHits, int bin) const
std::vector< int > shiftWithDrop(std::vector< int > &shift, unsigned droplayer) const
void printHitMasks(std::vector< boost::dynamic_bitset<> > const &hitMasks) const
virtual int getSubRegion() const override
std::pair< float, bool > phitrk(int bin, std::vector< int > const &shifts) const
virtual StatusCode initialize() override
Gaudi::Property< unsigned > m_iterLayer
std::vector< std::vector< int > > m_shifts
float deltaPhi(float r, float qPt) const
ServiceHandle< IFPGATrackSimBankSvc > m_FPGATrackSimBankSvc
float phitrkDiff(float r1, float phi1, float r2, float phi2) const
float qPt(float r, float deltaPhi) const
Gaudi::Property< std::string > m_bitShift_path
int r
Definition globals.cxx:22
std::string base
Definition hcg.cxx:81