ATLAS Offline Software
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 
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  */
90 class FPGATrackSimHoughTransformTool : public extends <AthAlgTool, IFPGATrackSimRoadFinderTool>
91 {
92  public:
93 
95  // AthAlgTool
96 
97  FPGATrackSimHoughTransformTool(const std::string&, const std::string&, const IInterface*);
98 
99  virtual StatusCode initialize() override;
100 
102  // IFPGATrackSimRoadFinderTool
103 
104  virtual StatusCode getRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads) override;
105 
107  // FPGATrackSimHoughTransformTool
108 
109  double getMinX() const { return m_parMin[m_par_x]; }
110  double getMaxX() const { return m_parMax[m_par_x]; }
111  double getMinY() const { return m_parMin[m_par_y]; }
112  double getMaxY() const { return m_parMax[m_par_y]; }
113  unsigned getThreshold() const { return m_threshold[m_threshold.size() / 2]; }
114  virtual int getSubRegion() const override{return m_subRegion;}
115 
116  double yToX(double y, const std::shared_ptr<const FPGATrackSimHit> &hit) const;
117 
118 
120  // An image is a 2d array of points, where each point has a value.
121  // The value starts as the number of hit layers, but can change with effects
122  // like a convolution. Also stored are all hits that contributed to each bin.
123  // Size m_imageSize_y * m_imageSize_x. (NOTE y is row coordinate)
124  Image const & getImage() const { return m_image; } // Returns the image generated from the last call of getRoads
125 
126  private:
127 
129  // Handles
130 
131  ServiceHandle<IFPGATrackSimEventSelectionSvc> m_EvtSel {this, "FPGATrackSimEventSelectionSvc", "FPGATrackSimEventSelectionSvc"};
132  ServiceHandle<IFPGATrackSimBankSvc> m_FPGATrackSimBankSvc {this, "FPGATrackSimBankSvc", "FPGATrackSimBankSvc"};
133  ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping {this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"};
135  // Properties
136 
137 
138  // === Image ===
139  FPGATrackSimTrackPars m_parMin; // These are the bounds of the image, i.e. the region of interest
140  FPGATrackSimTrackPars m_parMax; // Only the two parameters chosen above are used for the image, however others may be used for slicing
141 
144 
145  Gaudi::Property <int> m_subRegion { this, "subRegion", 0," -1 for entire region (no slicing)"};
146  Gaudi::Property <float> m_tempMin_phi { this, "phi_min", 0, "min phi"};
147  Gaudi::Property <float> m_tempMax_phi { this, "phi_max", 0, "max phi"};
148  Gaudi::Property <float> m_tempMin_qOverPt { this, "qpT_min", 0, "min q/pt"};
149  Gaudi::Property <float> m_tempMax_qOverPt { this, "qpT_max", 0, "max q/pt"};
150  Gaudi::Property <float> m_tempMin_d0 { this, "d0_min", 0, "min q/pt"};
151  Gaudi::Property <float> m_tempMax_d0 { this, "d0_max", 0, "max q/pt"};
152  Gaudi::Property<std::vector<int> > m_threshold { this, "threshold", {},"Minimum number of hit layers to fire a road"};
153  Gaudi::Property <unsigned> m_imageSize_x { this, "nBins_x", 0, ""};
154  Gaudi::Property <unsigned> m_imageSize_y { this, "nBins_y", 0, ""};
155  Gaudi::Property<std::vector<int> > m_conv { this, "convolution", {}, "Convolution filter, with size m_convSize_y * m_convSize_x"};
156  Gaudi::Property<std::vector<unsigned> > m_combineLayers { this, "combine_layers", {}, ""};
157  Gaudi::Property<std::vector<unsigned> > m_binScale { this, "scale", {}, "Vector containing the scales for each layers"};
158  Gaudi::Property <unsigned> m_convSize_x { this, "convSize_x", 0, ""};
159  Gaudi::Property <unsigned> m_convSize_y { this, "convSize_y", 0, ""};
160  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"};
161  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."};
162  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"};
163  Gaudi::Property <bool> m_fieldCorrection { this, "fieldCorrection", true, "Apply corrections to hough equation due to field nonuniformity"};
164  Gaudi::Property <bool> m_useSectors { this, "useSectors", false, "Will reverse calculate the sector for track-fitting purposes"};
165  Gaudi::Property <bool> m_idealGeoRoads { this, "IdealGeoRoads", true, "Set sectors to use ideal geometry fit constants"};
166  Gaudi::Property <bool> m_doRegionalMapping { this, "RegionalMapping", false, "Use the sub-region maps to define the sector"};
167  Gaudi::Property <bool> m_doEtaPatternConsts { this, "doEtaPatternConsts", false, "Whether to use the eta pattern tool for constant generation"};
168  Gaudi::Property <bool> m_useSpacePoints { this, "useSpacePoints", false, "Whether we are using spacepoints."};
169 
170  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)
171 
173  // Convenience
174 
175  unsigned m_nLayers = 0U; // alias to m_FPGATrackSimMapping->PlaneMap1stStage()->getNLogiLayers();
176  unsigned m_nCombineLayers = 0U; // number of layers after combined
177 
178  double m_step_x = 0; // step size of the bin boundaries in x
179  double m_step_y = 0; // step size of the bin boundaries in y
180  std::vector<double> m_bins_x; // size == m_imageSize_x + 1.
181  std::vector<double> m_bins_y; // size == m_imageSize_y + 1
182  // Bin boundaries, where m_bins_x[i] is the lower bound of bin i.
183  // These are calculated from m_parMin/Max.
184 
186  // Event Storage
187 
189  std::vector<FPGATrackSimRoad> m_roads;
190 
191 
193  // Core
194 
195  // std::vector<FPGATrackSimHit const *> filterHits(std::vector<FPGATrackSimHit const *> const & hits) const;
196  Image createLayerImage(std::vector<unsigned> const & combine_layers, const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, unsigned const scale) const;
197  Image createImage(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits) const;
198  Image convolute(Image const & image) const;
199 
201  // Helpers
202 
203  std::pair<unsigned, unsigned> yToXBins(size_t yBin_min, size_t yBin_max, const std::shared_ptr<const FPGATrackSimHit> &hit) const;
204  unsigned getExtension(unsigned y, unsigned layer) const;
205  bool passThreshold(Image const & image, unsigned x, unsigned y) const;
206  void addRoad(const std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>> & hits, layer_bitmask_t hitLayers, unsigned x, unsigned y);
207  void addRoad(const std::unordered_set<std::shared_ptr<const FPGATrackSimHit>> & hits, unsigned x, unsigned y);
208  void addRoad(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, unsigned x, unsigned y);
209  int conv(unsigned y, unsigned x) { return m_conv[y * m_convSize_x + x]; } // NOTE: y index is first
210  void drawImage(Image const & image, std::string const & name);
211 };
212 
213 
214 
215 #endif // FPGATrackSimHOUGHTRANSFORMTOOL_H
FPGATrackSimHoughTransformTool::m_bins_y
std::vector< double > m_bins_y
Definition: FPGATrackSimHoughTransformTool.h:181
FPGATrackSimHoughTransformTool::m_tempMax_qOverPt
Gaudi::Property< float > m_tempMax_qOverPt
Definition: FPGATrackSimHoughTransformTool.h:149
FPGATrackSimHoughTransformTool::m_FPGATrackSimBankSvc
ServiceHandle< IFPGATrackSimBankSvc > m_FPGATrackSimBankSvc
Definition: FPGATrackSimHoughTransformTool.h:132
FPGATrackSimTrackPars::IHIP
@ IHIP
Definition: FPGATrackSimTrackPars.h:49
FPGATrackSimHoughTransformTool
Definition: FPGATrackSimHoughTransformTool.h:91
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
FPGATrackSimHoughTransformTool::m_nLayers
unsigned m_nLayers
Definition: FPGATrackSimHoughTransformTool.h:175
FPGATrackSimHoughTransformTool::m_useSectors
Gaudi::Property< bool > m_useSectors
Definition: FPGATrackSimHoughTransformTool.h:164
FPGATrackSimHoughTransformTool::m_nCombineLayers
unsigned m_nCombineLayers
Definition: FPGATrackSimHoughTransformTool.h:176
FPGATrackSimHoughTransformTool::m_fieldCorrection
Gaudi::Property< bool > m_fieldCorrection
Definition: FPGATrackSimHoughTransformTool.h:163
FPGATrackSimHoughTransformTool::addRoad
void addRoad(const std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit >>> &hits, layer_bitmask_t hitLayers, unsigned x, unsigned y)
Definition: FPGATrackSimHoughTransformTool.cxx:363
FPGATrackSimHoughTransformTool::m_traceHits
Gaudi::Property< bool > m_traceHits
Definition: FPGATrackSimHoughTransformTool.h:161
FPGATrackSimTrackPars
Definition: FPGATrackSimTrackPars.h:22
IFPGATrackSimMappingSvc.h
FPGATrackSimHoughTransformTool::m_binScale
Gaudi::Property< std::vector< unsigned > > m_binScale
Definition: FPGATrackSimHoughTransformTool.h:157
FPGATrackSimHoughTransformTool::drawImage
void drawImage(Image const &image, std::string const &name)
FPGATrackSimHoughTransformTool::m_parMin
FPGATrackSimTrackPars m_parMin
Definition: FPGATrackSimHoughTransformTool.h:139
FPGATrackSimHoughTransformTool::m_combineLayers
Gaudi::Property< std::vector< unsigned > > m_combineLayers
Definition: FPGATrackSimHoughTransformTool.h:156
FPGATrackSimHoughTransformTool::m_idealGeoRoads
Gaudi::Property< bool > m_idealGeoRoads
Definition: FPGATrackSimHoughTransformTool.h:165
FPGATrackSimHoughTransformTool::m_tempMin_phi
Gaudi::Property< float > m_tempMin_phi
Definition: FPGATrackSimHoughTransformTool.h:146
FPGATrackSimHoughTransformTool::createImage
Image createImage(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits) const
Definition: FPGATrackSimHoughTransformTool.cxx:202
FPGATrackSimHoughTransformTool::m_convSize_x
Gaudi::Property< unsigned > m_convSize_x
Definition: FPGATrackSimHoughTransformTool.h:158
FPGATrackSimHoughTransformTool::m_conv
Gaudi::Property< std::vector< int > > m_conv
Definition: FPGATrackSimHoughTransformTool.h:155
IFPGATrackSimRoadFinderTool.h
Interface declaration for road finder tools.
FPGATrackSimHoughTransformTool::m_imageSize_y
Gaudi::Property< unsigned > m_imageSize_y
Definition: FPGATrackSimHoughTransformTool.h:154
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
x
#define x
FPGATrackSimHoughTransformTool::getMinY
double getMinY() const
Definition: FPGATrackSimHoughTransformTool.h:111
FPGATrackSimHoughTransformTool::m_par_y
FPGATrackSimTrackPars::pars_index m_par_y
Definition: FPGATrackSimHoughTransformTool.h:143
FPGATrackSimHoughTransformTool::m_bins_x
std::vector< double > m_bins_x
Definition: FPGATrackSimHoughTransformTool.h:180
FPGATrackSimHoughTransformTool::m_tempMax_phi
Gaudi::Property< float > m_tempMax_phi
Definition: FPGATrackSimHoughTransformTool.h:147
FPGATrackSimHoughTransformTool::m_tempMax_d0
Gaudi::Property< float > m_tempMax_d0
Definition: FPGATrackSimHoughTransformTool.h:151
FPGATrackSimHoughTransformTool::m_tempMin_qOverPt
Gaudi::Property< float > m_tempMin_qOverPt
Definition: FPGATrackSimHoughTransformTool.h:148
FPGATrackSimHoughTransformTool::m_par_x
FPGATrackSimTrackPars::pars_index m_par_x
Definition: FPGATrackSimHoughTransformTool.h:142
FPGATrackSimHoughTransformTool::conv
int conv(unsigned y, unsigned x)
Definition: FPGATrackSimHoughTransformTool.h:209
FPGATrackSimHoughTransformTool::m_localMaxWindowSize
Gaudi::Property< bool > m_localMaxWindowSize
Definition: FPGATrackSimHoughTransformTool.h:162
FPGATrackSimHoughTransformTool::m_step_y
double m_step_y
Definition: FPGATrackSimHoughTransformTool.h:179
FPGATrackSimVectors.h
Defines several vector wrappers for homogenous multi-dimensional vectors, declared as 1D arrays for l...
vector2D
Definition: FPGATrackSimVectors.h:28
FPGATrackSimHoughTransformTool::yToXBins
std::pair< unsigned, unsigned > yToXBins(size_t yBin_min, size_t yBin_max, const std::shared_ptr< const FPGATrackSimHit > &hit) const
Definition: FPGATrackSimHoughTransformTool.cxx:323
FPGATrackSimHoughTransformTool::FPGATrackSimHoughTransformTool
FPGATrackSimHoughTransformTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimHoughTransformTool.cxx:34
FPGATrackSimHoughTransformTool::getThreshold
unsigned getThreshold() const
Definition: FPGATrackSimHoughTransformTool.h:113
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
FPGATrackSimHoughTransformTool::getMinX
double getMinX() const
Definition: FPGATrackSimHoughTransformTool.h:109
FPGATrackSimHoughTransformTool::convolute
Image convolute(Image const &image) const
Definition: FPGATrackSimHoughTransformTool.cxx:221
AthAlgTool.h
FPGATrackSimHoughTransformTool::getSubRegion
virtual int getSubRegion() const override
Definition: FPGATrackSimHoughTransformTool.h:114
FPGATrackSimHoughTransformTool::getExtension
unsigned getExtension(unsigned y, unsigned layer) const
Definition: FPGATrackSimHoughTransformTool.cxx:349
FPGATrackSimHoughTransformTool::getMaxX
double getMaxX() const
Definition: FPGATrackSimHoughTransformTool.h:110
FPGATrackSimHoughTransformTool::m_convSize_y
Gaudi::Property< unsigned > m_convSize_y
Definition: FPGATrackSimHoughTransformTool.h:159
FPGATrackSimHoughTransformTool::m_step_x
double m_step_x
Definition: FPGATrackSimHoughTransformTool.h:178
FPGATrackSimHoughTransformTool::m_roads
std::vector< FPGATrackSimRoad > m_roads
Definition: FPGATrackSimHoughTransformTool.h:189
FPGATrackSimHoughTransformTool::m_useSpacePoints
Gaudi::Property< bool > m_useSpacePoints
Definition: FPGATrackSimHoughTransformTool.h:168
FPGATrackSimHoughTransformTool::m_subRegion
Gaudi::Property< int > m_subRegion
Definition: FPGATrackSimHoughTransformTool.h:145
FPGATrackSimHoughTransformTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimHoughTransformTool.cxx:41
FPGATrackSimHoughTransformTool::m_doRegionalMapping
Gaudi::Property< bool > m_doRegionalMapping
Definition: FPGATrackSimHoughTransformTool.h:166
IFPGATrackSimRoadFilterTool.h
Interface declaration for road filter tools.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
FPGATrackSimTrackPars::pars_index
pars_index
Definition: FPGATrackSimTrackPars.h:49
FPGATrackSimFunctions.h
FPGATrackSimHit.h
: FPGATrackSim-specific class to represent an hit in the detector.
FPGATrackSimHoughTransformTool::m_imageSize_x
Gaudi::Property< unsigned > m_imageSize_x
Definition: FPGATrackSimHoughTransformTool.h:153
MyPlots.image
string image
Definition: MyPlots.py:43
FPGATrackSimHoughTransformTool::yToX
double yToX(double y, const std::shared_ptr< const FPGATrackSimHit > &hit) const
Definition: FPGATrackSimHoughTransformTool.cxx:300
FPGATrackSimTrackPars::IPHI
@ IPHI
Definition: FPGATrackSimTrackPars.h:49
FPGATrackSimHoughTransformTool::Image
vector2D< std::pair< int, std::unordered_set< std::shared_ptr< const FPGATrackSimHit > > > > Image
Definition: FPGATrackSimHoughTransformTool.h:119
FPGATrackSimHoughTransformTool::createLayerImage
Image createLayerImage(std::vector< unsigned > const &combine_layers, const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, unsigned const scale) const
Definition: FPGATrackSimHoughTransformTool.cxx:169
FPGATrackSimHoughTransformTool::getRoads
virtual StatusCode getRoads(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, std::vector< std::shared_ptr< const FPGATrackSimRoad >> &roads) override
Definition: FPGATrackSimHoughTransformTool.cxx:139
y
#define y
FPGATrackSimHoughTransformTool::passThreshold
bool passThreshold(Image const &image, unsigned x, unsigned y) const
Definition: FPGATrackSimHoughTransformTool.cxx:243
IFPGATrackSimEventSelectionSvc.h
layer_bitmask_t
uint32_t layer_bitmask_t
Definition: FPGATrackSimTypes.h:22
IFPGATrackSimBankSvc.h
FPGATrackSimHoughTransformTool::getMaxY
double getMaxY() const
Definition: FPGATrackSimHoughTransformTool.h:112
FPGATrackSimHoughTransformTool::m_hitExtend_x
Gaudi::Property< std::vector< unsigned > > m_hitExtend_x
Definition: FPGATrackSimHoughTransformTool.h:160
FPGATrackSimHoughTransformTool::getImage
Image const & getImage() const
Definition: FPGATrackSimHoughTransformTool.h:124
FPGATrackSimHoughTransformTool::m_doEtaPatternConsts
Gaudi::Property< bool > m_doEtaPatternConsts
Definition: FPGATrackSimHoughTransformTool.h:167
FPGATrackSimHoughTransformTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimHoughTransformTool.h:133
FPGATrackSimRoad.h
Defines a class for roads.
FPGATrackSimHoughTransformTool::m_tempMin_d0
Gaudi::Property< float > m_tempMin_d0
Definition: FPGATrackSimHoughTransformTool.h:150
FPGATrackSimHoughTransformTool::m_parMax
FPGATrackSimTrackPars m_parMax
Definition: FPGATrackSimHoughTransformTool.h:140
FPGATrackSimHoughTransformTool::m_combineLayer2D
std::vector< std::vector< unsigned > > m_combineLayer2D
Definition: FPGATrackSimHoughTransformTool.h:170
FPGATrackSimTypes.h
FPGATrackSimHoughTransformTool::m_EvtSel
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
Definition: FPGATrackSimHoughTransformTool.h:131
FPGATrackSimTrackPars.h
Structs that store the 5 track parameters.
FPGATrackSimHoughTransformTool::m_threshold
Gaudi::Property< std::vector< int > > m_threshold
Definition: FPGATrackSimHoughTransformTool.h:152
ServiceHandle< IFPGATrackSimEventSelectionSvc >
FPGATrackSimHoughTransformTool::m_image
Image m_image
Definition: FPGATrackSimHoughTransformTool.h:188