ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimLLPDoubletHoughTransformTool Class Reference

#include <FPGATrackSimLLPDoubletHoughTransformTool.h>

Inheritance diagram for FPGATrackSimLLPDoubletHoughTransformTool:
Collaboration diagram for FPGATrackSimLLPDoubletHoughTransformTool:

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual StatusCode getRoads (const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, std::vector< std::shared_ptr< const FPGATrackSimRoad > > &roads) override
virtual int getSubRegion () const override

Private Types

typedef vector2D< std::pair< int, std::unordered_set< std::shared_ptr< const FPGATrackSimHit > > > > Image

Private Member Functions

StatusCode fillImage (std::shared_ptr< const FPGATrackSimHit > &hit1, std::shared_ptr< const FPGATrackSimHit > &hit2, Image &image) const
bool passThreshold (Image const &image, int x, int y) const
bool isLocalMaxima (Image const &image, int x, int y) const
FPGATrackSimRoad createRoad (const std::unordered_set< std::shared_ptr< const FPGATrackSimHit > > &hits, unsigned x, unsigned y) const
void drawImage (Image const &image) const
float xtod0 (int x) const
float ytoqoverpt (int y) const

Private Attributes

Gaudi::Property< unsigned > m_imageSize_x { this, "nBins_x", 0, ""}
Gaudi::Property< unsigned > m_imageSize_y { this, "nBins_y", 0, ""}
Gaudi::Property< int > m_threshold { this, "m_threshold", 8, "Threshold to be allied to bins of abs(d0) > 50 (mm)"}
Gaudi::Property< int > m_threshold50 { this, "m_threshold50", 8, "Threshold to be allied to bins of abs(d0) < (mm)"}
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."}
Gaudi::Property< float > m_d0_range { this, "d0_range", 120, "The d0 span: (-range, range) in mm"}
Gaudi::Property< float > m_qOverPt_range { this, "qOverPt_range", 0.002, "The q/pT span: (-range, range) in e/MeV"}
Gaudi::Property< bool > m_continuous { this, "continuous", true, "assure that there is continuity of the line (i.e. middle bins in d0 are filled when one q/pT step would result in a hole)"}
std::vector< FPGATrackSimRoadm_roads
const double m_acceptedDistanceBetweenLayersMin = 200
const double m_acceptedDistanceBetweenLayersMax = 600
double m_step_x = 0
double m_step_y = 0
unsigned m_event = 0
int m_eventsProcessed = 0
int m_roadsGenerated = 0

Detailed Description

Definition at line 25 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

Member Typedef Documentation

◆ Image

typedef vector2D<std::pair<int, std::unordered_set<std::shared_ptr<const FPGATrackSimHit> > > > FPGATrackSimLLPDoubletHoughTransformTool::Image
private

Definition at line 51 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

Member Function Documentation

◆ createRoad()

FPGATrackSimRoad FPGATrackSimLLPDoubletHoughTransformTool::createRoad ( const std::unordered_set< std::shared_ptr< const FPGATrackSimHit > > & hits,
unsigned x,
unsigned y ) const
private

Definition at line 134 of file FPGATrackSimLLPDoubletHoughTransformTool.cxx.

134 {
135 // Get the road hits
136 std::vector<std::shared_ptr<const FPGATrackSimHit>> road_hits;
137 layer_bitmask_t hitLayers = 0;
138 for (const auto & hit : hits)
139 {
140 road_hits.push_back(hit);
141 hitLayers |= 1 << hit->getLayer();
142 }
143
144 auto sorted_hits = ::sortByLayer(road_hits);
145 sorted_hits.resize(8); // If no hits in last layer, return from sortByLayer will be too short
146
147 FPGATrackSimRoad r;
148 r.setHitLayers(hitLayers);
149 r.setHits(std::move(sorted_hits));
150 return r;
151}
std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit > > > sortByLayer(Container const &hits)
uint32_t layer_bitmask_t
int r
Definition globals.cxx:22

◆ drawImage()

void FPGATrackSimLLPDoubletHoughTransformTool::drawImage ( Image const & image) const
private

Definition at line 174 of file FPGATrackSimLLPDoubletHoughTransformTool.cxx.

174 {
175
176 TH2I h(("event"+std::to_string( m_event )).c_str(), "LLP Doublet Hough space;d_{0}[mm];q/pT [e/GeV]",
179
180 for (unsigned x = 0; x < m_imageSize_x; x++)
181 for (unsigned y = 0; y < m_imageSize_y; y++)
182 h.SetBinContent(x+1, y+1, image(x, y).first); // +1 since root bins are 1-indexed
183
184 h.SaveAs((name()+"_event_"+std::to_string( m_event )+".root").c_str(), "");
185}
#define y
#define x
str image
Definition MyPlots.py:40

◆ fillImage()

StatusCode FPGATrackSimLLPDoubletHoughTransformTool::fillImage ( std::shared_ptr< const FPGATrackSimHit > & hit1,
std::shared_ptr< const FPGATrackSimHit > & hit2,
Image & image ) const
private

Definition at line 94 of file FPGATrackSimLLPDoubletHoughTransformTool.cxx.

94 {
95 const pvec p1 {{hit1->getX(), hit1->getY()}};
96 const pvec p2 {{hit2->getX(), hit2->getY()}};
97 const pvec halfDiff = (p2 - p1)*0.5;
98 const fp_t halfLen = length(halfDiff);
99
100 int xbefore = -1;
101
102 for ( unsigned y = 0; y < m_imageSize_y; y++ ) {
103 const fp_t qoverpt = (y * m_step_y) + m_step_y*0.5 - m_qOverPt_range; // use middle f the bin
104 const fp_t radius = 1.0/(0.6*qoverpt); // magic transform constants
105 const fp_t scale = std::copysign( std::sqrt( std::pow(radius/halfLen, 2) - 1), radius );
106 const pvec rprime = rotate90(halfDiff) * scale;
107 const pvec center = p1 + halfDiff + rprime;
108 const fp_t d0 = (std::signbit(radius) ? -1.0 : 1.0)*(length(center) - abs(radius));
109
110 // find the bin x position in the image
111 int x = (d0 + m_d0_range) / m_step_x;
112
113 if ( 0 <= x && x < (int)m_imageSize_x) {
114 if (xbefore == -1) xbefore = x;
115 if ( m_continuous ) { // fill the bins along x starintg from the last one filled
116 const int xmin = (xbefore < x)? xbefore: x;
117 const int xmax = (xbefore < x)? x: xbefore;
118 for ( int xinterpolated = xmin; xinterpolated <= xmax; ++xinterpolated) {
119 image(xinterpolated, y).first++;
120 image(xinterpolated, y).second.insert( hit1 );
121 image(xinterpolated, y).second.insert( hit2 );
122 }
123 } else {
124 image(x, y).first++;
125 image(x, y).second.insert( hit1 );
126 image(x, y).second.insert( hit2 );
127 }
128 xbefore = x;
129 }
130 }
131 return StatusCode::SUCCESS;
132}
pvec rotate90(const pvec &v)
std::array< fp_t, 2 > pvec
double length(const pvec &v)
float getY() const
float getX() const
double xmax
Definition listroot.cxx:61
double xmin
Definition listroot.cxx:60

◆ finalize()

StatusCode FPGATrackSimLLPDoubletHoughTransformTool::finalize ( )
overridevirtual

Definition at line 49 of file FPGATrackSimLLPDoubletHoughTransformTool.cxx.

49 {
50 ATH_MSG_INFO("Number of events procesed by the FPGATrackSimLLPDoubletHoughTransformTool " << m_eventsProcessed << " roads " << m_roadsGenerated);
51 return StatusCode::SUCCESS;
52}
#define ATH_MSG_INFO(x)

◆ getRoads()

StatusCode FPGATrackSimLLPDoubletHoughTransformTool::getRoads ( const std::vector< std::shared_ptr< const FPGATrackSimHit > > & hits,
std::vector< std::shared_ptr< const FPGATrackSimRoad > > & roads )
overridevirtual

Definition at line 54 of file FPGATrackSimLLPDoubletHoughTransformTool.cxx.

54 {
55 roads.clear();
56 m_roads.clear();
58 Image image(m_imageSize_x, m_imageSize_y); // not quite optimal to allocate this memory in evey event, but following nominal HT
59 for (unsigned ihit1 = 0; ihit1 < hits.size(); ihit1++) {
60 std::shared_ptr<const FPGATrackSimHit> hit1 = hits[ihit1];
61 for (unsigned ihit2 = ihit1+1; ihit2 < hits.size(); ihit2++) {
62 std::shared_ptr<const FPGATrackSimHit> hit2 = hits[ihit2];
63 ATH_MSG_DEBUG("Hits pair R: " << hit1->getR() << " " << hit2->getR());
64 //TODO: replace with qualification by layer IDs
65 const double radiusDifference = hit2->getR() - hit1->getR();
66
67 if ( not (m_acceptedDistanceBetweenLayersMin < radiusDifference && radiusDifference < m_acceptedDistanceBetweenLayersMax) )
68 continue;
69 if ( hit1->getLayer() == hit2->getLayer() )
70 continue;
71 ATH_CHECK(fillImage( hit1, hit2, image ));
72 }
73 }
74 if ( m_event < 20 )
75 drawImage(image);
76
77 for (unsigned y = 0; y < m_imageSize_y; y++) {
78 for (unsigned x = 0; x < m_imageSize_x; x++) {
79 if (passThreshold(image, x, y) && isLocalMaxima( image, x, y ) ) {
80 ATH_MSG_DEBUG("Creating road with threshold " << image(x,y).first << " hits " << image(x,y).second.size()
81 << " at x: " << x << " d0 " << xtod0(x) << " y: "<< y << " q/pt " << ytoqoverpt(y));
83 m_roads.push_back(createRoad(image(x, y).second, x, y));
84 }
85 }
86 }
87 roads.reserve(m_roads.size());
88 for (FPGATrackSimRoad & r : m_roads) roads.emplace_back(std::make_shared<const FPGATrackSimRoad>(r));
89 m_event++;
90 return StatusCode::SUCCESS;
91}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
bool passThreshold(Image const &image, int x, int y) const
bool isLocalMaxima(Image const &image, int x, int y) const
FPGATrackSimRoad createRoad(const std::unordered_set< std::shared_ptr< const FPGATrackSimHit > > &hits, unsigned x, unsigned y) const
StatusCode fillImage(std::shared_ptr< const FPGATrackSimHit > &hit1, std::shared_ptr< const FPGATrackSimHit > &hit2, Image &image) const
vector2D< std::pair< int, std::unordered_set< std::shared_ptr< const FPGATrackSimHit > > > > Image

◆ getSubRegion()

virtual int FPGATrackSimLLPDoubletHoughTransformTool::getSubRegion ( ) const
inlineoverridevirtual

Definition at line 36 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

36{return -1;}

◆ initialize()

StatusCode FPGATrackSimLLPDoubletHoughTransformTool::initialize ( )
overridevirtual

Definition at line 38 of file FPGATrackSimLLPDoubletHoughTransformTool.cxx.

38 {
39 if (m_imageSize_y %2 == 1) {
40 ATH_MSG_ERROR("Can not have odd number " << m_imageSize_y << " of bins in q/pT - will result in division by 0");
41 return StatusCode::FAILURE;
42 }
45
46 return StatusCode::SUCCESS;
47 }
#define ATH_MSG_ERROR(x)

◆ isLocalMaxima()

bool FPGATrackSimLLPDoubletHoughTransformTool::isLocalMaxima ( Image const & image,
int x,
int y ) const
private

Definition at line 163 of file FPGATrackSimLLPDoubletHoughTransformTool.cxx.

163 {
164 const auto centerValue = image(x,y).first;
165 for ( int xaround = std::min(x-1, 0); xaround <= std::max((int)m_imageSize_x-1, x+1); xaround++ ) {
166 for ( int yaround = std::min(y-1, 0); yaround <= std::max((int)m_imageSize_y-1, y+1); yaround++ ) {
167 if ( image(xaround,yaround).first > centerValue )
168 return false;
169 }
170 }
171 return true;
172}

◆ passThreshold()

bool FPGATrackSimLLPDoubletHoughTransformTool::passThreshold ( Image const & image,
int x,
int y ) const
private

Definition at line 154 of file FPGATrackSimLLPDoubletHoughTransformTool.cxx.

154 {
155 const int count = image(x,y).first;
156 const float d0 = xtod0(x);
157 if ( std::abs(d0) < 50.0 && count >= m_threshold50 ) return true;
158 if ( std::abs(d0) >= 50.0 && count >= m_threshold ) return true;
159
160 return false;
161}
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146

◆ xtod0()

float FPGATrackSimLLPDoubletHoughTransformTool::xtod0 ( int x) const
inlineprivate

Definition at line 68 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

68{ return x*m_step_x - m_d0_range; }

◆ ytoqoverpt()

float FPGATrackSimLLPDoubletHoughTransformTool::ytoqoverpt ( int y) const
inlineprivate

Definition at line 69 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

69{ return y*m_step_y - m_qOverPt_range; }

Member Data Documentation

◆ m_acceptedDistanceBetweenLayersMax

const double FPGATrackSimLLPDoubletHoughTransformTool::m_acceptedDistanceBetweenLayersMax = 600
private

Definition at line 55 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

◆ m_acceptedDistanceBetweenLayersMin

const double FPGATrackSimLLPDoubletHoughTransformTool::m_acceptedDistanceBetweenLayersMin = 200
private

Definition at line 54 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

◆ m_continuous

Gaudi::Property<bool> FPGATrackSimLLPDoubletHoughTransformTool::m_continuous { this, "continuous", true, "assure that there is continuity of the line (i.e. middle bins in d0 are filled when one q/pT step would result in a hole)"}
private

Definition at line 48 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

48{ this, "continuous", true, "assure that there is continuity of the line (i.e. middle bins in d0 are filled when one q/pT step would result in a hole)"};

◆ m_d0_range

Gaudi::Property<float> FPGATrackSimLLPDoubletHoughTransformTool::m_d0_range { this, "d0_range", 120, "The d0 span: (-range, range) in mm"}
private

Definition at line 46 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

46{ this, "d0_range", 120, "The d0 span: (-range, range) in mm"};

◆ m_event

unsigned FPGATrackSimLLPDoubletHoughTransformTool::m_event = 0
private

Definition at line 65 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

◆ m_eventsProcessed

int FPGATrackSimLLPDoubletHoughTransformTool::m_eventsProcessed = 0
private

Definition at line 70 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

◆ m_imageSize_x

Gaudi::Property<unsigned> FPGATrackSimLLPDoubletHoughTransformTool::m_imageSize_x { this, "nBins_x", 0, ""}
private

Definition at line 41 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

41{ this, "nBins_x", 0, ""};

◆ m_imageSize_y

Gaudi::Property<unsigned> FPGATrackSimLLPDoubletHoughTransformTool::m_imageSize_y { this, "nBins_y", 0, ""}
private

Definition at line 42 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

42{ this, "nBins_y", 0, ""};

◆ m_qOverPt_range

Gaudi::Property<float> FPGATrackSimLLPDoubletHoughTransformTool::m_qOverPt_range { this, "qOverPt_range", 0.002, "The q/pT span: (-range, range) in e/MeV"}
private

Definition at line 47 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

47{ this, "qOverPt_range", 0.002, "The q/pT span: (-range, range) in e/MeV"};

◆ m_roads

std::vector<FPGATrackSimRoad> FPGATrackSimLLPDoubletHoughTransformTool::m_roads
private

Definition at line 52 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

◆ m_roadsGenerated

int FPGATrackSimLLPDoubletHoughTransformTool::m_roadsGenerated = 0
private

Definition at line 71 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

◆ m_step_x

double FPGATrackSimLLPDoubletHoughTransformTool::m_step_x = 0
private

Definition at line 57 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

◆ m_step_y

double FPGATrackSimLLPDoubletHoughTransformTool::m_step_y = 0
private

Definition at line 58 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

◆ m_threshold

Gaudi::Property<int> FPGATrackSimLLPDoubletHoughTransformTool::m_threshold { this, "m_threshold", 8, "Threshold to be allied to bins of abs(d0) > 50 (mm)"}
private

Definition at line 43 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

43{ this, "m_threshold", 8, "Threshold to be allied to bins of abs(d0) > 50 (mm)"};

◆ m_threshold50

Gaudi::Property<int> FPGATrackSimLLPDoubletHoughTransformTool::m_threshold50 { this, "m_threshold50", 8, "Threshold to be allied to bins of abs(d0) < (mm)"}
private

Definition at line 44 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

44{ this, "m_threshold50", 8, "Threshold to be allied to bins of abs(d0) < (mm)"};

◆ m_traceHits

Gaudi::Property<bool> FPGATrackSimLLPDoubletHoughTransformTool::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."}
private

Definition at line 45 of file FPGATrackSimLLPDoubletHoughTransformTool.h.

45{ 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."};

The documentation for this class was generated from the following files: