ATLAS Offline Software
FPGATrackSimHoughTransform_d0phi0_Tool.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 #ifndef FPGATrackSimHOUGHTRANSFORM_D0PHI0_TOOL_H
4 #define FPGATrackSimHOUGHTRANSFORM_D0PHI0_TOOL_H
5 
14 #include "GaudiKernel/ServiceHandle.h"
16 
25 
26 #include "TFile.h"
27 
28 #include <string>
29 #include <vector>
30 #include <utility>
31 #include <unordered_set>
32 
35 
36 
37 class FPGATrackSimHoughTransform_d0phi0_Tool : public extends <AthAlgTool, IFPGATrackSimRoadFinderTool>
38 {
39  public:
40 
42  // AthAlgTool
43 
44  FPGATrackSimHoughTransform_d0phi0_Tool(const std::string&, const std::string&, const IInterface*);
45 
46  virtual StatusCode initialize() override;
47  virtual StatusCode finalize() override;
48 
50  // IFPGATrackSimRoadFinderTool
51 
52  virtual StatusCode getRoads(const std::vector<const FPGATrackSimHit*> & hits, std::vector<FPGATrackSimRoad*> & roads) override;
53 
54  private:
55 
57  // Handles
58 
59  ServiceHandle<IFPGATrackSimBankSvc> m_FPGATrackSimBankSvc {this, "FPGATrackSimBankSvc", "FPGATrackSimBankSvc"};
60  ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping {this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"};
61 
62 
64  // Properties
65 
66  Gaudi::Property <int> m_subRegion { this, "subRegion", 0," -1 for entire region (no slicing)"};
67  Gaudi::Property <float> m_tempMin_phi { this, "phi_min", 0, "min phi"};
68  Gaudi::Property <float> m_tempMax_phi { this, "phi_max", 1, "max phi"};
69  Gaudi::Property <float> m_tempMin_d0 { this, "d0_min", -1, "min q/pt"};
70  Gaudi::Property <float> m_tempMax_d0 { this, "d0_max", 1, "max q/pt"};
71  Gaudi::Property<std::vector<int> > m_threshold { this, "threshold", {1},"Minimum number of hit layers to fire a road"};
72  Gaudi::Property <unsigned int> m_imageSize_x { this, "nBins_x", 1, ""};
73  Gaudi::Property <unsigned int> m_imageSize_y { this, "nBins_y", 1, ""};
74  Gaudi::Property<std::vector<int> > m_conv { this, "convolution", {}, "Convolution filter, with size m_convSize_y * m_convSize_x"};
75  Gaudi::Property<std::vector<unsigned int> > m_combineLayers { this, "combine_layers", {0,1,2,3,4,5,6,7}, ""};
76  Gaudi::Property<std::vector<unsigned int> > m_binScale { this, "scale", {}, "Vector containing the scales for each layers"};
77  Gaudi::Property <unsigned int> m_convSize_x { this, "convSize_x", 0, ""};
78  Gaudi::Property <unsigned int> m_convSize_y { this, "convSize_y", 0, ""};
79  Gaudi::Property<std::vector<unsigned int> > m_hitExtend_x { this, "hitExtend_x", {}, "Hit lines will fill extra bins in x by this amount on each side, size == nLayers"};
80  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."};
81  Gaudi::Property <bool> m_stereo { this, "stereo", false, "Combine stereo layers"};
82  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"};
83  Gaudi::Property <bool> m_useSectors { this, "useSectors", false, "Will reverse calculate the sector for track-fitting purposes"};
84  Gaudi::Property <bool> m_idealGeoRoads { this, "IdealGeoRoads", false, "Set sectors to use ideal geometry fit constants"};
85 
88 
89  FPGATrackSimTrackPars m_parMin; // These are the bounds of the image, i.e. the region of interest
90  FPGATrackSimTrackPars m_parMax; // Only the two parameters chosen above are used
91 
92  unsigned m_nCombineLayers = 0U; // number of layers after combined
93  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)
94 
96  // Convenience
97 
98  unsigned m_nLayers = 0U; // alias to m_FPGATrackSimMapping->PlaneMap1stStage()->getNLogiLayers();
99 
100  double m_step_x = 0; // step size of the bin boundaries in x
101  double m_step_y = 0; // step size of the bin boundaries in y
102  std::vector<double> m_bins_x; // size == m_imageSize_x + 1.
103  std::vector<double> m_bins_y; // size == m_imageSize_y + 1
104  // Bin boundaries, where m_bins_x[i] is the lower bound of bin i.
105  // These are calculated from m_parMin/Max.
106  std::unordered_map<int, std::vector<size_t>> m_yBins_scaled; // saved all scaled binnings
107 
109  // An image is a 2d array of points, where each point has a value.
110  // This starts as the number of hits (or hit layers), but will
111  // change after the convolution. Also stored are all hits that
112  // contributed to each bin.
113  // Size m_imageSize_y * m_imageSize_x. (NOTE y is row coordinate)
114 
116  // Event Storage
117 
118  std::vector<FPGATrackSimRoad> m_roads;
119 
121  // Metadata and Monitoring
122 
123  int m_event = 0;
124  std::string m_name; // Gets the instance name from the full gaudi name
126 
128  // Core
129 
130  // std::vector<FPGATrackSimHit const *> filterHits(std::vector<FPGATrackSimHit const *> const & hits) const;
131  Image createLayerImage(std::vector<unsigned> const & combine_layers, std::vector<FPGATrackSimHit const *> const & hits, unsigned const scale) const;
132  Image createImage(std::vector<FPGATrackSimHit const *> const & hits) const;
133  Image convolute(Image const & image) const;
134 
136  // Helpers
137 
138  double yToX(double y, FPGATrackSimHit const * h) const;
139  std::pair<unsigned, unsigned> yToXBins(size_t yBin_min, size_t yBin_max, FPGATrackSimHit const * hit) const;
140  bool passThreshold(Image const & image, unsigned x, unsigned y) const;
141  void matchIdealGeoSector(FPGATrackSimRoad & r) const;
142  FPGATrackSimRoad createRoad(std::unordered_set<const FPGATrackSimHit*> const & hits, unsigned x, unsigned y) const;
143  FPGATrackSimRoad createRoad(std::vector<std::vector<const FPGATrackSimHit*>> const & hits, layer_bitmask_t hitLayers, unsigned x, unsigned y) const;
144  void addRoad(std::unordered_set<const FPGATrackSimHit*> const & hits, unsigned x, unsigned y);
145  void addRoad(std::vector<const FPGATrackSimHit*> const & hits, unsigned x, unsigned y);
146  int conv(unsigned y, unsigned x) { return m_conv[y * m_convSize_x + x]; } // NOTE: y index is first
147  void drawImage(Image const & image, std::string const & name);
148 
149 };
150 
151 
152 
153 #endif // FPGATrackSimHOUGHTRANSFORM_D0PHI0_TOOL_H
FPGATrackSimHoughTransform_d0phi0_Tool::m_par_x
FPGATrackSimTrackPars::pars_index m_par_x
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:86
beamspotman.r
def r
Definition: beamspotman.py:676
FPGATrackSimHoughTransform_d0phi0_Tool::createLayerImage
Image createLayerImage(std::vector< unsigned > const &combine_layers, std::vector< FPGATrackSimHit const * > const &hits, unsigned const scale) const
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:179
FPGATrackSimTrackPars::ID0
@ ID0
Definition: FPGATrackSimTrackPars.h:49
FPGATrackSimHoughTransform_d0phi0_Tool::addRoad
void addRoad(std::unordered_set< const FPGATrackSimHit * > const &hits, unsigned x, unsigned y)
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:454
FPGATrackSimHoughTransform_d0phi0_Tool::m_convSize_y
Gaudi::Property< unsigned int > m_convSize_y
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:78
FPGATrackSimHoughTransform_d0phi0_Tool::m_idealGeoRoads
Gaudi::Property< bool > m_idealGeoRoads
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:84
FPGATrackSimHoughTransform_d0phi0_Tool::m_nLayers
unsigned m_nLayers
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:98
FPGATrackSimTrackPars
Definition: FPGATrackSimTrackPars.h:22
FPGATrackSimHoughTransform_d0phi0_Tool::m_binScale
Gaudi::Property< std::vector< unsigned int > > m_binScale
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:76
FPGATrackSimHoughTransform_d0phi0_Tool::matchIdealGeoSector
void matchIdealGeoSector(FPGATrackSimRoad &r) const
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:378
IFPGATrackSimMappingSvc.h
FPGATrackSimHoughTransform_d0phi0_Tool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:60
IFPGATrackSimRoadFinderTool.h
Interface declaration for road finder tools.
IFPGATrackSimMappingSvc
Definition: IFPGATrackSimMappingSvc.h:17
FPGATrackSimHoughTransform_d0phi0_Tool::m_imageSize_y
Gaudi::Property< unsigned int > m_imageSize_y
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:73
FPGATrackSimHoughTransform_d0phi0_Tool::m_tempMin_phi
Gaudi::Property< float > m_tempMin_phi
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:67
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
x
#define x
FPGATrackSimHoughTransform_d0phi0_Tool::m_conv
Gaudi::Property< std::vector< int > > m_conv
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:74
FPGATrackSimHoughTransform_d0phi0_Tool::conv
int conv(unsigned y, unsigned x)
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:146
FPGATrackSimHit
Definition: FPGATrackSimHit.h:38
FPGATrackSimHoughTransform_d0phi0_Tool::m_threshold
Gaudi::Property< std::vector< int > > m_threshold
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:71
FPGATrackSimHoughTransform_d0phi0_Tool::m_stereo
Gaudi::Property< bool > m_stereo
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:81
FPGATrackSimVectors.h
Defines several vector wrappers for homogenous multi-dimensional vectors, declared as 1D arrays for l...
vector2D
Definition: FPGATrackSimVectors.h:28
FPGATrackSimHoughTransform_d0phi0_Tool::m_step_y
double m_step_y
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:101
FPGATrackSimHoughTransform_d0phi0_Tool::m_parMax
FPGATrackSimTrackPars m_parMax
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:90
FPGATrackSimHoughTransform_d0phi0_Tool::m_traceHits
Gaudi::Property< bool > m_traceHits
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:80
FPGATrackSimHoughTransform_d0phi0_Tool::m_event
int m_event
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:123
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FPGATrackSimHoughTransform_d0phi0_Tool::m_step_x
double m_step_x
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:100
LArG4ShowerLibProcessing.hits
hits
Definition: LArG4ShowerLibProcessing.py:136
AthAlgTool.h
FPGATrackSimHoughTransform_d0phi0_Tool::FPGATrackSimHoughTransform_d0phi0_Tool
FPGATrackSimHoughTransform_d0phi0_Tool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:37
FPGATrackSimHoughTransform_d0phi0_Tool::createRoad
FPGATrackSimRoad createRoad(std::unordered_set< const FPGATrackSimHit * > const &hits, unsigned x, unsigned y) const
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:411
FPGATrackSimHoughTransform_d0phi0_Tool::yToX
double yToX(double y, FPGATrackSimHit const *h) const
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:336
FPGATrackSimHoughTransform_d0phi0_Tool::m_tempMax_phi
Gaudi::Property< float > m_tempMax_phi
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:68
FPGATrackSimHoughTransform_d0phi0_Tool::m_convSize_x
Gaudi::Property< unsigned int > m_convSize_x
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:77
FPGATrackSimHoughTransform_d0phi0_Tool::convolute
Image convolute(Image const &image) const
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:247
FPGATrackSimHoughTransform_d0phi0_Tool::drawImage
void drawImage(Image const &image, std::string const &name)
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:506
FPGATrackSimHoughTransform_d0phi0_Tool::m_tempMax_d0
Gaudi::Property< float > m_tempMax_d0
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:70
FPGATrackSimHoughTransform_d0phi0_Tool
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:38
FPGATrackSimHoughTransform_d0phi0_Tool::finalize
virtual StatusCode finalize() override
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:140
FPGATrackSimHoughTransform_d0phi0_Tool::m_monitorFile
TFile m_monitorFile
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:125
FPGATrackSimHoughTransform_d0phi0_Tool::m_bins_y
std::vector< double > m_bins_y
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:103
FPGATrackSimHoughTransform_d0phi0_Tool::m_parMin
FPGATrackSimTrackPars m_parMin
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:89
FPGATrackSimHoughTransform_d0phi0_Tool::m_useSectors
Gaudi::Property< bool > m_useSectors
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:83
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.
FPGATrackSimHoughTransform_d0phi0_Tool::m_bins_x
std::vector< double > m_bins_x
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:102
FPGATrackSimHoughTransform_d0phi0_Tool::Image
vector2D< std::pair< int, std::unordered_set< const FPGATrackSimHit * > > > Image
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:108
MyPlots.image
string image
Definition: MyPlots.py:43
FPGATrackSimHoughTransform_d0phi0_Tool::m_combineLayers
Gaudi::Property< std::vector< unsigned int > > m_combineLayers
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:75
FPGATrackSimTrackPars::IPHI
@ IPHI
Definition: FPGATrackSimTrackPars.h:49
FPGATrackSimHoughTransform_d0phi0_Tool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:46
FPGATrackSimHoughTransform_d0phi0_Tool::createImage
Image createImage(std::vector< FPGATrackSimHit const * > const &hits) const
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:227
y
#define y
h
layer_bitmask_t
uint32_t layer_bitmask_t
Definition: FPGATrackSimTypes.h:22
IFPGATrackSimBankSvc.h
FPGATrackSimHoughTransform_d0phi0_Tool::m_hitExtend_x
Gaudi::Property< std::vector< unsigned int > > m_hitExtend_x
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:79
FPGATrackSimHoughTransform_d0phi0_Tool::m_imageSize_x
Gaudi::Property< unsigned int > m_imageSize_x
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:72
FPGATrackSimHoughTransform_d0phi0_Tool::m_FPGATrackSimBankSvc
ServiceHandle< IFPGATrackSimBankSvc > m_FPGATrackSimBankSvc
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:59
FPGATrackSimHoughTransform_d0phi0_Tool::m_name
std::string m_name
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:124
FPGATrackSimHoughTransform_d0phi0_Tool::m_roads
std::vector< FPGATrackSimRoad > m_roads
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:118
FPGATrackSimHoughTransform_d0phi0_Tool::m_nCombineLayers
unsigned m_nCombineLayers
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:92
FPGATrackSimHoughTransform_d0phi0_Tool::getRoads
virtual StatusCode getRoads(const std::vector< const FPGATrackSimHit * > &hits, std::vector< FPGATrackSimRoad * > &roads) override
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:150
FPGATrackSimHoughTransform_d0phi0_Tool::m_tempMin_d0
Gaudi::Property< float > m_tempMin_d0
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:69
FPGATrackSimHoughTransform_d0phi0_Tool::yToXBins
std::pair< unsigned, unsigned > yToXBins(size_t yBin_min, size_t yBin_max, FPGATrackSimHit const *hit) const
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:354
FPGATrackSimRoad.h
Defines a class for roads.
FPGATrackSimHoughTransform_d0phi0_Tool::m_combineLayer2D
std::vector< std::vector< unsigned > > m_combineLayer2D
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:93
FPGATrackSimHoughTransform_d0phi0_Tool::m_yBins_scaled
std::unordered_map< int, std::vector< size_t > > m_yBins_scaled
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:106
FPGATrackSimHoughTransform_d0phi0_Tool::m_par_y
FPGATrackSimTrackPars::pars_index m_par_y
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:87
FPGATrackSimHoughTransform_d0phi0_Tool::m_localMaxWindowSize
Gaudi::Property< bool > m_localMaxWindowSize
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:82
IFPGATrackSimBankSvc
Definition: IFPGATrackSimBankSvc.h:21
FPGATrackSimTypes.h
FPGATrackSimHoughTransform_d0phi0_Tool::passThreshold
bool passThreshold(Image const &image, unsigned x, unsigned y) const
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.cxx:273
FPGATrackSimTrackPars.h
Structs that store the 5 track parameters.
FPGATrackSimRoad
Definition: FPGATrackSimRoad.h:29
ServiceHandle< IFPGATrackSimBankSvc >
FPGATrackSimHoughTransform_d0phi0_Tool::m_subRegion
Gaudi::Property< int > m_subRegion
Definition: FPGATrackSimHoughTransform_d0phi0_Tool.h:66