ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimHoughTransformTool.h
Go to the documentation of this file.
1// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
3#ifndef FPGATrackSimHOUGHTRANSFORMTOOL_H
4#define FPGATrackSimHOUGHTRANSFORMTOOL_H
5
46
47#include "GaudiKernel/ServiceHandle.h"
49
61
62#include "TFile.h"
63
64#include <string>
65#include <vector>
66#include <utility>
67#include <unordered_set>
68
69
70/* I adopt the following nomenclature within this class:
71 * image: The 'graph' in q/pT vs phi_track space, filled with a line calculated as above for each hit.
72 * point: A specific q/pT and phi_track bin in the above image; i.e. what is normally called a pixel
73 * but I don't want to confuse this with the detector type. A point's value is the number of
74 * lines that go through it.
75 *
76 * For the first iteration, x refers to phi_track, and y refers to q/pT, although
77 * this should remain flexible. These are set via the variables m_par_x and m_par_y.
78 *
79 * NOTE: We store the image in graph sense and not computer-science sense. That is,
80 * the row-index is y. The y-axis still points downwards, so that y=0 represents the
81 * lowest bin.
82 * image[y=0][x=0] : lowest q/pT and lowest phi_track bin
83 * image[y=size-1][x=0] : highest q/pT and lowest phi_track bin
84 *
85 * I use the following units for relevant variables:
86 * x,y,z,r : mm
87 * q : e
88 * pT : GeV / c
89 */
90class FPGATrackSimHoughTransformTool : public extends <AthAlgTool, IFPGATrackSimRoadFinderTool>
91{
92 public:
94 using base_class::base_class;
95
96 virtual StatusCode initialize() override;
97
99 // IFPGATrackSimRoadFinderTool
100
101 virtual StatusCode getRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads) override;
102
104 // FPGATrackSimHoughTransformTool
105
106 double getMinX() const { return m_parMin[m_par_x]; }
107 double getMaxX() const { return m_parMax[m_par_x]; }
108 double getMinY() const { return m_parMin[m_par_y]; }
109 double getMaxY() const { return m_parMax[m_par_y]; }
110 unsigned getThreshold() const { return m_threshold[m_threshold.size() / 2]; }
111 virtual int getSubRegion() const override{return m_subRegion;}
112
113 double yToX(double y, const std::shared_ptr<const FPGATrackSimHit> &hit) const;
114
115
117 // An image is a 2d array of points, where each point has a value.
118 // The value starts as the number of hit layers, but can change with effects
119 // like a convolution. Also stored are all hits that contributed to each bin.
120 // Size m_imageSize_y * m_imageSize_x. (NOTE y is row coordinate)
121 Image const & getImage() const { return m_image; } // Returns the image generated from the last call of getRoads
122
123 //used for FPGA emulation
124 struct pos
125 {
126 int x;
127 int y;
128 int layer;
129 };
130
131 struct LUT
132 {
135 int layer;
136 std::vector<pos> output;
137 };
138 int m_bitlength = 16;
139
140 private:
141
143 // Handles
144
145 ServiceHandle<IFPGATrackSimEventSelectionSvc> m_EvtSel {this, "FPGATrackSimEventSelectionSvc", ""};
146 ServiceHandle<IFPGATrackSimBankSvc> m_FPGATrackSimBankSvc {this, "FPGATrackSimBankSvc", "FPGATrackSimBankSvc"};
147 ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping {this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"};
149 // Properties
150
151
152 // === Image ===
153 FPGATrackSimTrackPars m_parMin; // These are the bounds of the image, i.e. the region of interest
154 FPGATrackSimTrackPars m_parMax; // Only the two parameters chosen above are used for the image, however others may be used for slicing
155
158
159 Gaudi::Property <int> m_subRegion { this, "subRegion", 0," -1 for entire region (no slicing)"};
160 Gaudi::Property <float> m_tempMin_phi { this, "phi_min", 0, "min phi"};
161 Gaudi::Property <float> m_tempMax_phi { this, "phi_max", 0, "max phi"};
162 Gaudi::Property <float> m_tempMin_qOverPt { this, "qpT_min", 0, "min q/pt"};
163 Gaudi::Property <float> m_tempMax_qOverPt { this, "qpT_max", 0, "max q/pt"};
164 Gaudi::Property <float> m_tempMin_d0 { this, "d0_min", 0, "min q/pt"};
165 Gaudi::Property <float> m_tempMax_d0 { this, "d0_max", 0, "max q/pt"};
166 Gaudi::Property<std::vector<int> > m_threshold { this, "threshold", {},"Minimum number of hit layers to fire a road"};
167 Gaudi::Property <unsigned> m_imageSize_x { this, "nBins_x", 0, ""};
168 Gaudi::Property <unsigned> m_imageSize_y { this, "nBins_y", 0, ""};
169 Gaudi::Property<std::vector<int> > m_conv { this, "convolution", {}, "Convolution filter, with size m_convSize_y * m_convSize_x"};
170 Gaudi::Property<std::vector<unsigned> > m_combineLayers { this, "combine_layers", {}, ""};
171 Gaudi::Property<std::vector<unsigned> > m_binScale { this, "scale", {}, "Vector containing the scales for each layers"};
172 Gaudi::Property <unsigned> m_convSize_x { this, "convSize_x", 0, ""};
173 Gaudi::Property <unsigned> m_convSize_y { this, "convSize_y", 0, ""};
174 Gaudi::Property<std::vector<unsigned> > m_hitExtend_x { this, "hitExtend_x", {}, "Hit lines will fill extra bins in x by this amount on each side, size == nLayers"};
175 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."};
176 Gaudi::Property <bool> m_localMaxWindowSize { this, "localMaxWindowSize", 0, "Only create roads that are a local maximum within this window size. Set this to 0 to turn off local max filtering"};
177 Gaudi::Property <bool> m_fieldCorrection { this, "fieldCorrection", true, "Apply corrections to hough equation due to field nonuniformity"};
178 Gaudi::Property <bool> m_useSectors { this, "useSectors", false, "Will reverse calculate the sector for track-fitting purposes"};
179 Gaudi::Property <bool> m_idealGeoRoads { this, "IdealGeoRoads", true, "Set sectors to use ideal geometry fit constants"};
180 Gaudi::Property <bool> m_doRegionalMapping { this, "RegionalMapping", false, "Use the sub-region maps to define the sector"};
181 Gaudi::Property <bool> m_doEtaPatternConsts { this, "doEtaPatternConsts", false, "Whether to use the eta pattern tool for constant generation"};
182 Gaudi::Property <bool> m_useSpacePoints { this, "useSpacePoints", false, "Whether we are using spacepoints."};
183 Gaudi::Property <std::string> m_houghType { this, "houghType", "Original", "Switch Hough strategy. Original: close to mathematical HT, LowResource: emulate pre calculated LUTs base FPGA performance, Flexible: emulate culculation on FPGA performance"};
184 Gaudi::Property <bool> m_roadMerge { this, "roadMerge", false};
185 Gaudi::Property <std::string> m_requirements { this, "requirements", "", "path of the requirements file"};
186
187 //Parameters generally used by Hough Transform 2D Flexible
188 Gaudi::Property <int> m_r_max { this, "r_max", 2047," - maximum -"};
189 Gaudi::Property <int> m_phi_coord_max { this, "phi_coord_max", 65535," - maximum - phi"};
190 Gaudi::Property <double> m_phi_range { this, "phi_range", 6.399609375,"range of phi in rad, customized ofr the algo"};
191 Gaudi::Property <double> m_r_max_mm { this, "r_max_mm", 1137.5,"r value maximum used in the mm-to-bits conversion"};
192 Gaudi::Property <int> m_bitwise_qApt_conv { this, "bitwise_qApt_conv", 16384, "exponential of 2 to multiply with qA/pt in case the latter in < 1"};
193 Gaudi::Property <int> m_bitwise_phi0_conv { this, "bitwise_phi0_conv", 1, "exponential of 2 to multiply with phi0 in case the latter in < 1"};
194 Gaudi::Property <int> m_phi0_sectors { this, "phi0_sectors", 1,"firmware method to draw monotonic lines. separation alongside phi0"};
195 Gaudi::Property <int> m_qApt_sectors { this, "qApt_sectors", 7,"firmware method to draw monotonic lines. separation alongside qA/pt"};
196 Gaudi::Property <int> m_pipes_qApt { this, "pipes_qApt", 8,"!!!!!!MAX 32 !!!!!!clock domains separation alongside qA/pt bins"};
197 Gaudi::Property <int> m_pipes_phi0 { this, "pipes_phi0", 1," !!!!!!MAX 32 !!!!!!clock domains separation alongside phi0 bins"};
198
199 std::vector<std::vector<unsigned>> m_combineLayer2D; // 2d array of combined layers i.e. [[1,2,3],[0,4,5],[6,7]] will combine (L1, L2, L3), (L0, L4, L5), (L6, L7)
200
202 // Convenience
203
204 unsigned m_nLayers = 0U; // alias to m_FPGATrackSimMapping->PlaneMap1stStage()->getNLogiLayers();
205 unsigned m_nCombineLayers = 0U; // number of layers after combined
206
207 double m_step_x = 0; // step size of the bin boundaries in x
208 double m_step_y = 0; // step size of the bin boundaries in y
209 std::vector<double> m_bins_x; // size == m_imageSize_x + 1.
210 std::vector<double> m_bins_y; // size == m_imageSize_y + 1
211 // Bin boundaries, where m_bins_x[i] is the lower bound of bin i.
212 // These are calculated from m_parMin/Max.
213
215 // Conistants for HT2D Flex
216 int m_HT_sel = 0;
218 double m_phi0_min_bit = 0;
219 double m_qApt_min_bit = 0;
220 long int m_DBinQApt_bit_int = 0;
221 long int m_DBinPhi0_bit_int = 0;
222 long int m_qAptBins_bit = 0;
223 long int m_phi0Bins_bit = 0;
226 long int m_tot_bitwise_conv = 0;
229
231 // Event Storage
232
234 std::vector<FPGATrackSimRoad> m_roads;
235
236
238 // Core
239
240 // std::vector<FPGATrackSimHit const *> filterHits(std::vector<FPGATrackSimHit const *> const & hits) const;
241 Image createLayerImage(std::vector<unsigned> const & combine_layers, const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, unsigned const scale) const;
242 Image createImage(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits) const;
243 std::vector<std::vector<int>> lineGenLay(const std::shared_ptr<const FPGATrackSimHit> &hit) const;
244 Image convolute(Image const & image) const;
245
247 // Helpers
248
249 std::pair<unsigned, unsigned> yToXBins(size_t yBin_min, size_t yBin_max, const std::shared_ptr<const FPGATrackSimHit> &hit) const;
250 unsigned getExtension(unsigned y, unsigned layer) const;
251 bool passThreshold(Image const & image, unsigned x, unsigned y) const;
252 void addRoad(const std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>> & hits, layer_bitmask_t hitLayers, unsigned x, unsigned y);
253 void addRoad(const std::unordered_set<std::shared_ptr<const FPGATrackSimHit>> & hits, unsigned x, unsigned y);
254 void addRoad(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, unsigned x, unsigned y);
255 int conv(unsigned y, unsigned x) { return m_conv[y * m_convSize_x + x]; } // NOTE: y index is first
256 void drawImage(Image const & image, std::string const & name);
258 // FPGA emulation functions
259 std::vector<std::vector<std::vector<LUT>>> m_LUT;
260 std::vector<TH1D*> m_h_rfix;
261 void makeLUT(std::vector<std::vector<std::vector<LUT>>> &v_LUT,std::vector<TH1D*> &v_h, const std::string& tag="");
263};
264
265
266
267#endif // FPGATrackSimHOUGHTRANSFORMTOOL_H
: FPGATrackSim-specific class to represent an hit in the detector.
Defines a class for roads.
Structs that store the 5 track parameters.
uint32_t layer_bitmask_t
Defines several vector wrappers for homogenous multi-dimensional vectors, declared as 1D arrays for l...
Interface declaration for road filter tools.
Interface declaration for road finder tools.
#define y
#define x
Gaudi::Property< std::vector< int > > m_conv
FPGATrackSimTrackPars::pars_index m_par_x
Image createLayerImage(std::vector< unsigned > const &combine_layers, const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, unsigned const scale) const
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
ServiceHandle< IFPGATrackSimBankSvc > m_FPGATrackSimBankSvc
Gaudi::Property< std::vector< int > > m_threshold
Gaudi::Property< std::vector< unsigned > > m_binScale
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
std::pair< unsigned, unsigned > yToXBins(size_t yBin_min, size_t yBin_max, const std::shared_ptr< const FPGATrackSimHit > &hit) const
std::vector< std::vector< std::vector< LUT > > > m_LUT
vector2D< std::pair< int, std::unordered_set< std::shared_ptr< const FPGATrackSimHit > > > > Image
Gaudi::Property< std::vector< unsigned > > m_combineLayers
unsigned getExtension(unsigned y, unsigned layer) const
Gaudi::Property< std::string > m_houghType
std::vector< std::vector< int > > lineGenLay(const std::shared_ptr< const FPGATrackSimHit > &hit) const
double yToX(double y, const std::shared_ptr< const FPGATrackSimHit > &hit) const
void addRoad(const std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit > > > &hits, layer_bitmask_t hitLayers, unsigned x, unsigned y)
virtual StatusCode getRoads(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, std::vector< std::shared_ptr< const FPGATrackSimRoad > > &roads) override
Gaudi::Property< std::vector< unsigned > > m_hitExtend_x
void drawImage(Image const &image, std::string const &name)
std::vector< FPGATrackSimRoad > m_roads
FPGATrackSimTrackPars::pars_index m_par_y
Gaudi::Property< std::string > m_requirements
void makeLUT(std::vector< std::vector< std::vector< LUT > > > &v_LUT, std::vector< TH1D * > &v_h, const std::string &tag="")
bool passThreshold(Image const &image, unsigned x, unsigned y) const
std::vector< std::vector< unsigned > > m_combineLayer2D
Image createImage(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits) const