ATLAS Offline Software
Loading...
Searching...
No Matches
MuonLayerHough.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef MUONLAYERHOUGH_H
6#define MUONLAYERHOUGH_H
7
8#include <cmath>
9#include <iostream>
10#include <memory>
11#include <string>
12#include <vector>
13
14#include "MuonLayerHough/Hit.h"
17
18class TH1;
19
20namespace MuonHough {
21 using HitVec = std::vector<std::shared_ptr<MuonHough::Hit>>;
22
23
26
29
30 RegionDescriptor(int sector_, DetRegIdx region_, ChIdx chIndex_,
31 float referencePosition_, float yMinRange_,
32 float yMaxRange_, float yBinSize_, float thetaStep_,
33 unsigned int nthetaSamples_) :
34 sector{sector_},
35 region{region_},
36 chIndex{chIndex_},
37 referencePosition{referencePosition_},
38 yMinRange{yMinRange_},
39 yMaxRange{yMaxRange_},
40 yBinSize{yBinSize_},
41 thetaStep{thetaStep_},
42 nthetaSamples{nthetaSamples_} {}
43 RegionDescriptor() = default;
44
45 int sector{0};
46 DetRegIdx region{DetRegIdx::DetectorRegionUnknown};
47 ChIdx chIndex{ChIdx::ChUnknown};
49 float yMinRange{0};
50 float yMaxRange{0};
51 float yBinSize{0};
52 float thetaStep{0};
53 unsigned int nthetaSamples{1};
54 };
55
56 using RegionDescriptionVec = std::vector<RegionDescriptor>;
57
58
60
64 struct Maximum {
65 Maximum() = default;
66
67 float max{0.}; // value of the maximum
68 float pos{0.}; // spacial position
69 float theta{0.}; // angle
70
71 float refpos{0.}; // reference position
72 DetRegIdx refregion{DetRegIdx::DetectorRegionUnknown}; // reference region
73 ChIdx refchIndex{ChIdx::ChUnknown}; // reference chamber index
74
75 int binpos{-1}; // position bin
76 int binposmin{-1}; // lower edge of the maximum
77 int binposmax{-1}; // upper edge of the maximu
78 float binsize{0.}; // size of bin
79 int bintheta{-1}; // theta bin
80 int triggerConfirmed{0}; // number of in time trigger hits associated with the maximum
81 HitVec hits; // vector of associated hits
82
83 const MuonLayerHough* hough{nullptr}; // pointer to the corresponding hough
84
85 bool isEndcap() const {
86 // refers to the chamber orientation!!!! so BEE is a barell in this def
87 DetRegIdx region = hough->m_descriptor.region;
88 ChIdx chIndex = hough->m_descriptor.chIndex;
89 // need to make sure BEE's reference plane is the same as barrel
90 if (region != DetRegIdx::Barrel && chIndex != ChIdx::BEE) { return true; }
91 return false;
92 };
93 float getGlobalR() const {
94 if (isEndcap()) { return pos; }
95 return refpos;
96 };
97 float getGlobalZ() const {
98 if (isEndcap()) { return refpos; }
99 return pos;
100 };
101 float getGlobalTheta() const {
102 if (isEndcap()) {
103 // return M_PI/2.0 - theta;
104 if (theta > 0) {
105 return M_PI / 2.0 - theta;
106 } else {
107 return -M_PI / 2.0 - theta;
108 }
109 }
110 return theta;
111 };
112 };
113
115 MuonLayerHough(const RegionDescriptor& descriptor);
116
118 ~MuonLayerHough() = default;
119
121 void reset();
122
124 void setDebug(bool d) { m_debug = d; }
125
127 int bin(const Hit& hit) const;
128
130 int bin(float x, float y) const;
131
133 float yval(int posBin) const;
134
136 void pars(int posBin, int /*thetaBin*/, float& x, float& y) const;
137
139 float layerConfirmation(const Hit& hit, float range = 1000.) const;
140
142 float layerConfirmation(float x, float y, float range = 1000.) const;
143
145 std::pair<float, float> layerConfirmation(unsigned int thetaBin, float x, float y, float range = 1000.) const;
146
148 bool findMaximum(Maximum& maximum, const MuonLayerHoughSelector& selector) const;
149
151 void associateHitsToMaximum(Maximum& maximum, const HitVec& hits) const;
152
154 std::pair<int, int> range(const float x, const float y1, const float y2, const int bintheta) const;
155
157 std::pair<float, float> maximum(float x, float y, int& posbin, int& thetabin) const;
158
160 void fill(const Hit& hit);
161
163 void fill(float x, float y, float weight);
164
166 void fillLayer(const HitVec& hits, bool substract = false);
167
168 // fill the hough space with a vector of hits using the layer mode
169 void fillLayer2(const HitVec& hits, bool subtract = false);
170
172 std::vector<TH1*> rootHistos(const std::string& prefix, const float* rmin = 0, const float* rmax = 0) const;
173
174 // members
175
176 float m_binsize{0};
177 float m_invbinsize{0};
178
179 // unsigned int m_nthetasamples;
180 int m_nbins{-1};
181
182 unsigned int max{0};
183 int maxhist{-1};
184 int maxbin{-1};
185 bool m_debug{false};
186 std::vector<std::unique_ptr<unsigned int[]> > m_histos; // the maximum contents of all the histograms, overlayed
188 };
189
190 inline int MuonLayerHough::bin(const Hit& hit) const { return bin(hit.x, hit.ymin); }
191
192 inline int MuonLayerHough::bin(float x, float y) const {
193 float yref = y * (m_descriptor.referencePosition - x) / x + y;
194 int in = (yref - m_descriptor.yMinRange) / m_binsize;
195 if (in < 0 || in >= m_nbins) in = -1;
196 return in;
197 }
198
199 inline void MuonLayerHough::pars(int posBin, int /*thetaBin*/, float& x, float& y) const {
200 x = m_descriptor.referencePosition;
201 y = yval(posBin);
202 }
203
204 inline float MuonLayerHough::yval(int posBin) const { return m_descriptor.yMinRange + posBin * m_binsize; }
205
206 inline float MuonLayerHough::layerConfirmation(const Hit& hit, float range) const { return layerConfirmation(hit.x, hit.ymin, range); }
207
208 inline void MuonLayerHough::fill(const Hit& hit) { fill(hit.x, hit.ymin, hit.w); }
209
210 // function for linear/parabolic extrapolation from maxima to maxima in a different station
211 float extrapolate(const MuonLayerHough::Maximum& ref, const MuonLayerHough::Maximum& ex, bool doparabolic = false);
212} // namespace MuonHough
213#endif
const boost::regex ref(r_ef)
#define M_PI
#define y
#define x
struct containing all hit information needed for the Hough transform
float x
layer identifier (packed word containing technology/sublayer)
float w
maximum value of the hit in the precision coordinate (y=z in barrel, y=r in endcap)
float extrapolate(const MuonLayerHough::Maximum &ref, const MuonLayerHough::Maximum &ex, bool doparabolic=false)
std::vector< RegionDescriptor > RegionDescriptionVec
std::vector< std::shared_ptr< MuonHough::Hit > > HitVec
DetectorRegionIndex
enum to classify the different layers in the muon spectrometer
ChIndex
enum to classify the different chamber layers in the muon spectrometer
struct representing the maximum in the hough space
void pars(int posBin, int, float &x, float &y) const
calculate x,y for the given position bin
void reset()
reset the transform
int bin(const Hit &hit) const
calculate the position bin the hit will endup in
void associateHitsToMaximum(Maximum &maximum, const HitVec &hits) const
associates the list of input hits to the provided maximum
void setDebug(bool d)
enable debug output
RegionDescriptor m_descriptor
std::pair< float, float > maximum(float x, float y, int &posbin, int &thetabin) const
returns a pair with the position and angle corresponing to the input x,y values
~MuonLayerHough()=default
destructor
std::vector< std::unique_ptr< unsigned int[]> > m_histos
int m_nbins
inverse binsize
std::vector< TH1 * > rootHistos(const std::string &prefix, const float *rmin=0, const float *rmax=0) const
returns a vector with all the histograms of the hough as TH1*
float layerConfirmation(const Hit &hit, float range=1000.) const
calculate the highest value of the hough transform within the specified range for the given hit
float yval(int posBin) const
access to y coordinate of a given bin
void fillLayer2(const HitVec &hits, bool subtract=false)
bool findMaximum(Maximum &maximum, const MuonLayerHoughSelector &selector) const
find the highest maximum that is above maxval
MuonLayerHough(const RegionDescriptor &descriptor)
constructor
Muon::MuonStationIndex::DetectorRegionIndex DetRegIdx
void fill(const Hit &hit)
fill the hough space with a single position
Muon::MuonStationIndex::ChIndex ChIdx
void fillLayer(const HitVec &hits, bool substract=false)
fill the hough space with a vector of hits using the layer mode
std::pair< int, int > range(const float x, const float y1, const float y2, const int bintheta) const
calculates the first and last bin the hit should be filled in for a given theta bin
struct containing all information to build a Hough transform for a given chamber index
Muon::MuonStationIndex::DetectorRegionIndex DetRegIdx
Muon::MuonStationIndex::ChIndex ChIdx
RegionDescriptor(int sector_, DetRegIdx region_, ChIdx chIndex_, float referencePosition_, float yMinRange_, float yMaxRange_, float yBinSize_, float thetaStep_, unsigned int nthetaSamples_)