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 
60 
61 #include "TFile.h"
62 
63 #include <string>
64 #include <vector>
65 #include <utility>
66 #include <unordered_set>
67 
68 
69 /* I adopt the following nomenclature within this class:
70  * image: The 'graph' in q/pT vs phi_track space, filled with a line calculated as above for each hit.
71  * point: A specific q/pT and phi_track bin in the above image; i.e. what is normally called a pixel
72  * but I don't want to confuse this with the detector type. A point's value is the number of
73  * lines that go through it.
74  *
75  * For the first iteration, x refers to phi_track, and y refers to q/pT, although
76  * this should remain flexible. These are set via the variables m_par_x and m_par_y.
77  *
78  * NOTE: We store the image in graph sense and not computer-science sense. That is,
79  * the row-index is y. The y-axis still points downwards, so that y=0 represents the
80  * lowest bin.
81  * image[y=0][x=0] : lowest q/pT and lowest phi_track bin
82  * image[y=size-1][x=0] : highest q/pT and lowest phi_track bin
83  *
84  * I use the following units for relevant variables:
85  * x,y,z,r : mm
86  * q : e
87  * pT : GeV / c
88  */
89 class FPGATrackSimHoughTransformTool : public extends <AthAlgTool, IFPGATrackSimRoadFinderTool>
90 {
91  public:
92 
94  // AthAlgTool
95 
96  FPGATrackSimHoughTransformTool(const std::string&, const std::string&, const IInterface*);
97 
98  virtual StatusCode initialize() override;
99 
101  // IFPGATrackSimRoadFinderTool
102 
103  virtual StatusCode getRoads(const std::vector<const FPGATrackSimHit*> & hits, std::vector<FPGATrackSimRoad*> & roads) override;
104 
106  // FPGATrackSimHoughTransformTool
107 
108  double getMinX() const { return m_parMin[m_par_x]; }
109  double getMaxX() const { return m_parMax[m_par_x]; }
110  double getMinY() const { return m_parMin[m_par_y]; }
111  double getMaxY() const { return m_parMax[m_par_y]; }
112  unsigned getThreshold() const { return m_threshold[m_threshold.size() / 2]; }
113  int getSubRegion() const { return m_subRegion; }
114 
115  // Apply correction due to B != 2T everywhere. This correction should be ADDED to
116  // phi_track.
117  static double fieldCorrection(unsigned region, double y, double r);
118 
119  double yToX(double y, FPGATrackSimHit const * h) const;
120 
121 
123  // An image is a 2d array of points, where each point has a value.
124  // The value starts as the number of hit layers, but can change with effects
125  // like a convolution. Also stored are all hits that contributed to each bin.
126  // Size m_imageSize_y * m_imageSize_x. (NOTE y is row coordinate)
127  Image const & getImage() const { return m_image; } // Returns the image generated from the last call of getRoads
128 
129  private:
130 
132  // Handles
133 
134  ServiceHandle<IFPGATrackSimEventSelectionSvc> m_EvtSel {this, "FPGATrackSimEventSelectionSvc", "FPGATrackSimEventSelectionSvc"};
135  ServiceHandle<IFPGATrackSimBankSvc> m_FPGATrackSimBankSvc {this, "FPGATrackSimBankSvc", "FPGATrackSimBankSvc"};
136  ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping {this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"};
138  // Properties
139 
140 
141  // === Image ===
142  FPGATrackSimTrackPars m_parMin; // These are the bounds of the image, i.e. the region of interest
143  FPGATrackSimTrackPars m_parMax; // Only the two parameters chosen above are used for the image, however others may be used for slicing
144 
147 
148  Gaudi::Property <int> m_subRegion { this, "subRegion", 0," -1 for entire region (no slicing)"};
149  Gaudi::Property <float> m_tempMin_phi { this, "phi_min", 0, "min phi"};
150  Gaudi::Property <float> m_tempMax_phi { this, "phi_max", 0, "max phi"};
151  Gaudi::Property <float> m_tempMin_qOverPt { this, "qpT_min", 0, "min q/pt"};
152  Gaudi::Property <float> m_tempMax_qOverPt { this, "qpT_max", 0, "max q/pt"};
153  Gaudi::Property <float> m_tempMin_d0 { this, "d0_min", 0, "min q/pt"};
154  Gaudi::Property <float> m_tempMax_d0 { this, "d0_max", 0, "max q/pt"};
155  Gaudi::Property<std::vector<int> > m_threshold { this, "threshold", {},"Minimum number of hit layers to fire a road"};
156  Gaudi::Property <unsigned> m_imageSize_x { this, "nBins_x", 0, ""};
157  Gaudi::Property <unsigned> m_imageSize_y { this, "nBins_y", 0, ""};
158  Gaudi::Property<std::vector<int> > m_conv { this, "convolution", {}, "Convolution filter, with size m_convSize_y * m_convSize_x"};
159  Gaudi::Property<std::vector<unsigned> > m_combineLayers { this, "combine_layers", {}, ""};
160  Gaudi::Property<std::vector<unsigned> > m_binScale { this, "scale", {}, "Vector containing the scales for each layers"};
161  Gaudi::Property <unsigned> m_convSize_x { this, "convSize_x", 0, ""};
162  Gaudi::Property <unsigned> m_convSize_y { this, "convSize_y", 0, ""};
163  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"};
164  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."};
165  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"};
166  Gaudi::Property <bool> m_fieldCorrection { this, "fieldCorrection", true, "Apply corrections to hough equation due to field nonuniformity"};
167  Gaudi::Property <bool> m_useSectors { this, "useSectors", false, "Will reverse calculate the sector for track-fitting purposes"};
168  Gaudi::Property <bool> m_idealGeoRoads { this, "IdealGeoRoads", true, "Set sectors to use ideal geometry fit constants"};
169  Gaudi::Property <bool> m_doRegionalMapping { this, "RegionalMapping", false, "Use the sub-region maps to define the sector"};
170  Gaudi::Property <bool> m_doEtaPatternConsts { this, "doEtaPatternConsts", false, "Whether to use the eta pattern tool for constant generation"};
171  Gaudi::Property <bool> m_useSpacePoints { this, "useSpacePoints", false, "Whether we are using spacepoints."};
172 
173  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)
174 
176  // Convenience
177 
178  unsigned m_nLayers = 0U; // alias to m_FPGATrackSimMapping->PlaneMap1stStage()->getNLogiLayers();
179  unsigned m_nCombineLayers = 0U; // number of layers after combined
180 
181  double m_step_x = 0; // step size of the bin boundaries in x
182  double m_step_y = 0; // step size of the bin boundaries in y
183  std::vector<double> m_bins_x; // size == m_imageSize_x + 1.
184  std::vector<double> m_bins_y; // size == m_imageSize_y + 1
185  // Bin boundaries, where m_bins_x[i] is the lower bound of bin i.
186  // These are calculated from m_parMin/Max.
187 
189  // Event Storage
190 
192  std::vector<FPGATrackSimRoad> m_roads;
193 
194 
196  // Core
197 
198  // std::vector<FPGATrackSimHit const *> filterHits(std::vector<FPGATrackSimHit const *> const & hits) const;
199  Image createLayerImage(std::vector<unsigned> const & combine_layers, std::vector<FPGATrackSimHit const *> const & hits, unsigned const scale) const;
200  Image createImage(std::vector<FPGATrackSimHit const *> const & hits) const;
201  Image convolute(Image const & image) const;
202 
204  // Helpers
205 
206  std::pair<unsigned, unsigned> yToXBins(size_t yBin_min, size_t yBin_max, FPGATrackSimHit const * hit) const;
207  unsigned getExtension(unsigned y, unsigned layer) const;
208  bool passThreshold(Image const & image, unsigned x, unsigned y) const;
209  void matchIdealGeoSector(FPGATrackSimRoad & r) const;
210  void addRoad(std::vector<std::vector<const FPGATrackSimHit*>> const & hits, layer_bitmask_t hitLayers, unsigned x, unsigned y);
211  void addRoad(std::unordered_set<const FPGATrackSimHit*> const & hits, unsigned x, unsigned y);
212  void addRoad(std::vector<const FPGATrackSimHit*> const & hits, unsigned x, unsigned y);
213  int conv(unsigned y, unsigned x) { return m_conv[y * m_convSize_x + x]; } // NOTE: y index is first
214  void drawImage(Image const & image, std::string const & name);
215 };
216 
217 
218 
219 #endif // FPGATrackSimHOUGHTRANSFORMTOOL_H
FPGATrackSimHoughTransformTool::m_bins_y
std::vector< double > m_bins_y
Definition: FPGATrackSimHoughTransformTool.h:184
FPGATrackSimHoughTransformTool::m_tempMax_qOverPt
Gaudi::Property< float > m_tempMax_qOverPt
Definition: FPGATrackSimHoughTransformTool.h:152
FPGATrackSimHoughTransformTool::m_FPGATrackSimBankSvc
ServiceHandle< IFPGATrackSimBankSvc > m_FPGATrackSimBankSvc
Definition: FPGATrackSimHoughTransformTool.h:135
FPGATrackSimTrackPars::IHIP
@ IHIP
Definition: FPGATrackSimTrackPars.h:49
beamspotman.r
def r
Definition: beamspotman.py:676
FPGATrackSimHoughTransformTool
Definition: FPGATrackSimHoughTransformTool.h:90
FPGATrackSimHoughTransformTool::m_nLayers
unsigned m_nLayers
Definition: FPGATrackSimHoughTransformTool.h:178
FPGATrackSimHoughTransformTool::fieldCorrection
static double fieldCorrection(unsigned region, double y, double r)
Definition: FPGATrackSimHoughTransformTool.cxx:301
FPGATrackSimHoughTransformTool::m_useSectors
Gaudi::Property< bool > m_useSectors
Definition: FPGATrackSimHoughTransformTool.h:167
FPGATrackSimHoughTransformTool::m_nCombineLayers
unsigned m_nCombineLayers
Definition: FPGATrackSimHoughTransformTool.h:179
FPGATrackSimHoughTransformTool::m_fieldCorrection
Gaudi::Property< bool > m_fieldCorrection
Definition: FPGATrackSimHoughTransformTool.h:166
FPGATrackSimHoughTransformTool::createLayerImage
Image createLayerImage(std::vector< unsigned > const &combine_layers, std::vector< FPGATrackSimHit const * > const &hits, unsigned const scale) const
Definition: FPGATrackSimHoughTransformTool.cxx:162
FPGATrackSimHoughTransformTool::m_traceHits
Gaudi::Property< bool > m_traceHits
Definition: FPGATrackSimHoughTransformTool.h:164
FPGATrackSimHoughTransformTool::addRoad
void addRoad(std::vector< std::vector< const FPGATrackSimHit * >> const &hits, layer_bitmask_t hitLayers, unsigned x, unsigned y)
Definition: FPGATrackSimHoughTransformTool.cxx:446
FPGATrackSimHoughTransformTool::createImage
Image createImage(std::vector< FPGATrackSimHit const * > const &hits) const
Definition: FPGATrackSimHoughTransformTool.cxx:202
FPGATrackSimTrackPars
Definition: FPGATrackSimTrackPars.h:22
FPGATrackSimHoughTransformTool::matchIdealGeoSector
void matchIdealGeoSector(FPGATrackSimRoad &r) const
Definition: FPGATrackSimHoughTransformTool.cxx:379
FPGATrackSimHoughTransformTool::getRoads
virtual StatusCode getRoads(const std::vector< const FPGATrackSimHit * > &hits, std::vector< FPGATrackSimRoad * > &roads) override
Definition: FPGATrackSimHoughTransformTool.cxx:139
IFPGATrackSimMappingSvc.h
FPGATrackSimHoughTransformTool::m_binScale
Gaudi::Property< std::vector< unsigned > > m_binScale
Definition: FPGATrackSimHoughTransformTool.h:160
FPGATrackSimHoughTransformTool::drawImage
void drawImage(Image const &image, std::string const &name)
FPGATrackSimHoughTransformTool::m_parMin
FPGATrackSimTrackPars m_parMin
Definition: FPGATrackSimHoughTransformTool.h:142
FPGATrackSimHoughTransformTool::m_combineLayers
Gaudi::Property< std::vector< unsigned > > m_combineLayers
Definition: FPGATrackSimHoughTransformTool.h:159
FPGATrackSimHoughTransformTool::m_idealGeoRoads
Gaudi::Property< bool > m_idealGeoRoads
Definition: FPGATrackSimHoughTransformTool.h:168
FPGATrackSimHoughTransformTool::m_tempMin_phi
Gaudi::Property< float > m_tempMin_phi
Definition: FPGATrackSimHoughTransformTool.h:149
FPGATrackSimHoughTransformTool::m_convSize_x
Gaudi::Property< unsigned > m_convSize_x
Definition: FPGATrackSimHoughTransformTool.h:161
FPGATrackSimHoughTransformTool::m_conv
Gaudi::Property< std::vector< int > > m_conv
Definition: FPGATrackSimHoughTransformTool.h:158
IFPGATrackSimRoadFinderTool.h
Interface declaration for road finder tools.
FPGATrackSimHoughTransformTool::m_imageSize_y
Gaudi::Property< unsigned > m_imageSize_y
Definition: FPGATrackSimHoughTransformTool.h:157
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
x
#define x
FPGATrackSimHoughTransformTool::getSubRegion
int getSubRegion() const
Definition: FPGATrackSimHoughTransformTool.h:113
FPGATrackSimHoughTransformTool::getMinY
double getMinY() const
Definition: FPGATrackSimHoughTransformTool.h:110
FPGATrackSimHoughTransformTool::m_par_y
FPGATrackSimTrackPars::pars_index m_par_y
Definition: FPGATrackSimHoughTransformTool.h:146
FPGATrackSimHoughTransformTool::m_bins_x
std::vector< double > m_bins_x
Definition: FPGATrackSimHoughTransformTool.h:183
FPGATrackSimHoughTransformTool::m_tempMax_phi
Gaudi::Property< float > m_tempMax_phi
Definition: FPGATrackSimHoughTransformTool.h:150
FPGATrackSimHit
Definition: FPGATrackSimHit.h:38
FPGATrackSimHoughTransformTool::m_tempMax_d0
Gaudi::Property< float > m_tempMax_d0
Definition: FPGATrackSimHoughTransformTool.h:154
FPGATrackSimHoughTransformTool::m_tempMin_qOverPt
Gaudi::Property< float > m_tempMin_qOverPt
Definition: FPGATrackSimHoughTransformTool.h:151
FPGATrackSimHoughTransformTool::m_par_x
FPGATrackSimTrackPars::pars_index m_par_x
Definition: FPGATrackSimHoughTransformTool.h:145
FPGATrackSimHoughTransformTool::conv
int conv(unsigned y, unsigned x)
Definition: FPGATrackSimHoughTransformTool.h:213
FPGATrackSimHoughTransformTool::m_localMaxWindowSize
Gaudi::Property< bool > m_localMaxWindowSize
Definition: FPGATrackSimHoughTransformTool.h:165
FPGATrackSimHoughTransformTool::yToXBins
std::pair< unsigned, unsigned > yToXBins(size_t yBin_min, size_t yBin_max, FPGATrackSimHit const *hit) const
Definition: FPGATrackSimHoughTransformTool.cxx:340
FPGATrackSimHoughTransformTool::m_step_y
double m_step_y
Definition: FPGATrackSimHoughTransformTool.h:182
FPGATrackSimVectors.h
Defines several vector wrappers for homogenous multi-dimensional vectors, declared as 1D arrays for l...
vector2D
Definition: FPGATrackSimVectors.h:28
FPGATrackSimHoughTransformTool::FPGATrackSimHoughTransformTool
FPGATrackSimHoughTransformTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimHoughTransformTool.cxx:34
FPGATrackSimHoughTransformTool::getThreshold
unsigned getThreshold() const
Definition: FPGATrackSimHoughTransformTool.h:112
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FPGATrackSimHoughTransformTool::yToX
double yToX(double y, FPGATrackSimHit const *h) const
Definition: FPGATrackSimHoughTransformTool.cxx:317
LArG4ShowerLibProcessing.hits
hits
Definition: LArG4ShowerLibProcessing.py:136
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
FPGATrackSimHoughTransformTool::getMinX
double getMinX() const
Definition: FPGATrackSimHoughTransformTool.h:108
FPGATrackSimHoughTransformTool::convolute
Image convolute(Image const &image) const
Definition: FPGATrackSimHoughTransformTool.cxx:221
AthAlgTool.h
FPGATrackSimHoughTransformTool::getExtension
unsigned getExtension(unsigned y, unsigned layer) const
Definition: FPGATrackSimHoughTransformTool.cxx:366
FPGATrackSimHoughTransformTool::Image
vector2D< std::pair< int, std::unordered_set< const FPGATrackSimHit * > > > Image
Definition: FPGATrackSimHoughTransformTool.h:122
FPGATrackSimHoughTransformTool::getMaxX
double getMaxX() const
Definition: FPGATrackSimHoughTransformTool.h:109
FPGATrackSimHoughTransformTool::m_convSize_y
Gaudi::Property< unsigned > m_convSize_y
Definition: FPGATrackSimHoughTransformTool.h:162
FPGATrackSimHoughTransformTool::m_step_x
double m_step_x
Definition: FPGATrackSimHoughTransformTool.h:181
FPGATrackSimHoughTransformTool::m_roads
std::vector< FPGATrackSimRoad > m_roads
Definition: FPGATrackSimHoughTransformTool.h:192
FPGATrackSimHoughTransformTool::m_useSpacePoints
Gaudi::Property< bool > m_useSpacePoints
Definition: FPGATrackSimHoughTransformTool.h:171
FPGATrackSimHoughTransformTool::m_subRegion
Gaudi::Property< int > m_subRegion
Definition: FPGATrackSimHoughTransformTool.h:148
FPGATrackSimHoughTransformTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimHoughTransformTool.cxx:41
FPGATrackSimHoughTransformTool::m_doRegionalMapping
Gaudi::Property< bool > m_doRegionalMapping
Definition: FPGATrackSimHoughTransformTool.h:169
IFPGATrackSimRoadFilterTool.h
Interface declaration for road filter tools.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
FPGATrackSimTrackPars::pars_index
pars_index
Definition: FPGATrackSimTrackPars.h:49
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:156
MyPlots.image
string image
Definition: MyPlots.py:43
FPGATrackSimTrackPars::IPHI
@ IPHI
Definition: FPGATrackSimTrackPars.h:49
y
#define y
h
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:111
FPGATrackSimHoughTransformTool::m_hitExtend_x
Gaudi::Property< std::vector< unsigned > > m_hitExtend_x
Definition: FPGATrackSimHoughTransformTool.h:163
FPGATrackSimHoughTransformTool::getImage
Image const & getImage() const
Definition: FPGATrackSimHoughTransformTool.h:127
FPGATrackSimHoughTransformTool::m_doEtaPatternConsts
Gaudi::Property< bool > m_doEtaPatternConsts
Definition: FPGATrackSimHoughTransformTool.h:170
FPGATrackSimHoughTransformTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimHoughTransformTool.h:136
FPGATrackSimRoad.h
Defines a class for roads.
FPGATrackSimHoughTransformTool::m_tempMin_d0
Gaudi::Property< float > m_tempMin_d0
Definition: FPGATrackSimHoughTransformTool.h:153
FPGATrackSimHoughTransformTool::m_parMax
FPGATrackSimTrackPars m_parMax
Definition: FPGATrackSimHoughTransformTool.h:143
FPGATrackSimHoughTransformTool::m_combineLayer2D
std::vector< std::vector< unsigned > > m_combineLayer2D
Definition: FPGATrackSimHoughTransformTool.h:173
FPGATrackSimTypes.h
FPGATrackSimHoughTransformTool::m_EvtSel
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
Definition: FPGATrackSimHoughTransformTool.h:134
FPGATrackSimTrackPars.h
Structs that store the 5 track parameters.
FPGATrackSimRoad
Definition: FPGATrackSimRoad.h:29
FPGATrackSimHoughTransformTool::m_threshold
Gaudi::Property< std::vector< int > > m_threshold
Definition: FPGATrackSimHoughTransformTool.h:155
ServiceHandle< IFPGATrackSimEventSelectionSvc >
FPGATrackSimHoughTransformTool::m_image
Image m_image
Definition: FPGATrackSimHoughTransformTool.h:191