ATLAS Offline Software
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 
18 class TH1;
19 
20 namespace 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 
59  struct MuonLayerHough {
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
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 {
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
MuonHough::Hit::ymin
float ymin
global hit position (x=r in barrel, x=z in endcap)
Definition: MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonLayerHough/MuonLayerHough/Hit.h:79
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
MuonHough::HitVec
std::vector< std::shared_ptr< MuonHough::Hit > > HitVec
Definition: MuonLayerHough.h:21
MuonHough::MuonLayerHough::yval
float yval(int posBin) const
access to y coordinate of a given bin
Definition: MuonLayerHough.h:204
MuonHough::MuonLayerHough::m_binsize
float m_binsize
Definition: MuonLayerHough.h:176
MuonHough::Hit::w
float w
maximum value of the hit in the precision coordinate (y=z in barrel, y=r in endcap)
Definition: MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonLayerHough/MuonLayerHough/Hit.h:81
hist_file_dump.d
d
Definition: hist_file_dump.py:137
MuonHough::MuonLayerHough::layerConfirmation
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
Definition: MuonLayerHough.h:206
MuonHough::MuonLayerHough::max
unsigned int max
Definition: MuonLayerHough.h:182
MuonHough::MuonLayerHough::m_descriptor
RegionDescriptor m_descriptor
Definition: MuonLayerHough.h:187
xAOD::L2MuonParameters::BEE
@ BEE
BEE measurement point.
Definition: TrigMuonDefs.h:24
MuonHough::MuonLayerHough::m_nbins
int m_nbins
inverse binsize
Definition: MuonLayerHough.h:180
MuonHough::MuonLayerHough::m_debug
bool m_debug
Definition: MuonLayerHough.h:185
MuonHough::RegionDescriptor::yMinRange
float yMinRange
Definition: MuonLayerHough.h:49
MuonHough::MuonLayerHough::Maximum::refpos
float refpos
Definition: MuonLayerHough.h:71
M_PI
#define M_PI
Definition: ActiveFraction.h:11
MuonHough::RegionDescriptor::thetaStep
float thetaStep
Definition: MuonLayerHough.h:52
MuonHough::RegionDescriptor::nthetaSamples
unsigned int nthetaSamples
Definition: MuonLayerHough.h:53
MuonHough::MuonLayerHough
Definition: MuonLayerHough.h:59
MuonHough::MuonLayerHoughSelector
Definition: MuonLayerHoughSelector.h:12
MuonHough::MuonLayerHough::Maximum::binpos
int binpos
Definition: MuonLayerHough.h:75
MuonHough::RegionDescriptor::yMaxRange
float yMaxRange
Definition: MuonLayerHough.h:50
MuonHough::RegionDescriptor::referencePosition
float referencePosition
Definition: MuonLayerHough.h:48
MuonHough::MuonLayerHough::Maximum::refchIndex
ChIdx refchIndex
Definition: MuonLayerHough.h:73
MuonHough::Hit
struct containing all hit information needed for the Hough transform
Definition: MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonLayerHough/MuonLayerHough/Hit.h:60
MuonHough::RegionDescriptor
struct containing all information to build a Hough transform for a given chamber index
Definition: MuonLayerHough.h:25
MuonHough::MuonLayerHough::Maximum::getGlobalR
float getGlobalR() const
Definition: MuonLayerHough.h:93
x
#define x
MuonHough::MuonLayerHough::maxhist
int maxhist
Definition: MuonLayerHough.h:183
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
DetType::Barrel
@ Barrel
Definition: DetType.h:14
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
MuonHough::MuonLayerHough::bin
int bin(const Hit &hit) const
calculate the position bin the hit will endup in
Definition: MuonLayerHough.h:190
Hit.h
MuonHough::RegionDescriptor::region
DetRegIdx region
Definition: MuonLayerHough.h:46
MuonHough::RegionDescriptor::RegionDescriptor
RegionDescriptor(int sector_, DetRegIdx region_, ChIdx chIndex_, float referencePosition_, float yMinRange_, float yMaxRange_, float yBinSize_, float thetaStep_, unsigned int nthetaSamples_)
Definition: MuonLayerHough.h:30
MuonHough::MuonLayerHough::Maximum::binposmin
int binposmin
Definition: MuonLayerHough.h:76
MuonHough::MuonLayerHough::Maximum
struct representing the maximum in the hough space
Definition: MuonLayerHough.h:64
MuonHough::RegionDescriptor::sector
int sector
Definition: MuonLayerHough.h:45
MuonHough::MuonLayerHough::Maximum::theta
float theta
Definition: MuonLayerHough.h:69
MuonHough::MuonLayerHough::fill
void fill(const Hit &hit)
fill the hough space with a single position
Definition: MuonLayerHough.h:208
MuonHough::MuonLayerHough::Maximum::max
float max
Definition: MuonLayerHough.h:67
MuonHough::MuonLayerHough::Maximum::binsize
float binsize
Definition: MuonLayerHough.h:78
MuonHough::MuonLayerHough::range
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
Definition: MuonLayerHough.cxx:486
MuonHough::MuonLayerHough::maximum
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
Definition: MuonLayerHough.cxx:391
MuonHough::MuonLayerHough::findMaximum
bool findMaximum(Maximum &maximum, const MuonLayerHoughSelector &selector) const
find the highest maximum that is above maxval
Definition: MuonLayerHough.cxx:290
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
MuonHough::MuonLayerHough::Maximum::triggerConfirmed
int triggerConfirmed
Definition: MuonLayerHough.h:80
MuonHough
Definition: MuonLayerHoughTool.h:41
MuonHough::Hit::x
float x
layer identifier (packed word containing technology/sublayer)
Definition: MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonLayerHough/MuonLayerHough/Hit.h:78
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
MuonHough::MuonLayerHough::Maximum::getGlobalZ
float getGlobalZ() const
Definition: MuonLayerHough.h:97
MuonHough::MuonLayerHough::Maximum::Maximum
Maximum()=default
MuonHough::MuonLayerHough::m_invbinsize
float m_invbinsize
binsize
Definition: MuonLayerHough.h:177
MuonHough::MuonLayerHough::associateHitsToMaximum
void associateHitsToMaximum(Maximum &maximum, const HitVec &hits) const
associates the list of input hits to the provided maximum
Definition: MuonLayerHough.cxx:368
MuonHough::MuonLayerHough::MuonLayerHough
MuonLayerHough(const RegionDescriptor &descriptor)
constructor
Definition: MuonLayerHough.cxx:35
MuonHough::RegionDescriptor::RegionDescriptor
RegionDescriptor()=default
MuonHough::MuonLayerHough::Maximum::hough
const MuonLayerHough * hough
Definition: MuonLayerHough.h:83
Muon::MuonStationIndex::DetectorRegionIndex
DetectorRegionIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:47
MuonHough::MuonLayerHough::setDebug
void setDebug(bool d)
enable debug output
Definition: MuonLayerHough.h:124
MuonHough::MuonLayerHough::~MuonLayerHough
~MuonLayerHough()=default
destructor
MuonHough::MuonLayerHough::maxbin
int maxbin
Definition: MuonLayerHough.h:184
MuonHough::MuonLayerHough::Maximum::bintheta
int bintheta
Definition: MuonLayerHough.h:79
MuonHough::RegionDescriptor::yBinSize
float yBinSize
Definition: MuonLayerHough.h:51
MuonHough::MuonLayerHough::reset
void reset()
reset the transform
Definition: MuonLayerHough.cxx:48
MuonHough::MuonLayerHough::Maximum::pos
float pos
Definition: MuonLayerHough.h:68
MuonHough::MuonLayerHough::fillLayer
void fillLayer(const HitVec &hits, bool substract=false)
fill the hough space with a vector of hits using the layer mode
Definition: MuonLayerHough.cxx:100
MuonHough::MuonLayerHough::Maximum::refregion
DetRegIdx refregion
Definition: MuonLayerHough.h:72
MuonHough::MuonLayerHough::Maximum::hits
HitVec hits
Definition: MuonLayerHough.h:81
python.selector.AtlRunQuerySelectorLhcOlc.selector
selector
Definition: AtlRunQuerySelectorLhcOlc.py:611
y
#define y
ref
const boost::regex ref(r_ef)
MuonHough::MuonLayerHough::m_histos
std::vector< std::unique_ptr< unsigned int[]> > m_histos
Definition: MuonLayerHough.h:186
MuonHough::MuonLayerHough::rootHistos
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*
Definition: MuonLayerHough.cxx:272
MuonHough::MuonLayerHough::fillLayer2
void fillLayer2(const HitVec &hits, bool subtract=false)
Definition: MuonLayerHough.cxx:200
MuonHough::MuonLayerHough::Maximum::getGlobalTheta
float getGlobalTheta() const
Definition: MuonLayerHough.h:101
Muon::MuonStationIndex::ChIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Definition: MuonStationIndex.h:15
MuonHough::extrapolate
float extrapolate(const MuonLayerHough::Maximum &ref, const MuonLayerHough::Maximum &ex, bool doparabolic=false)
Definition: MuonLayerHough.cxx:521
MuonHough::MuonLayerHough::pars
void pars(int posBin, int, float &x, float &y) const
calculate x,y for the given position bin
Definition: MuonLayerHough.h:199
MuonStationIndex.h
MuonHough::RegionDescriptionVec
std::vector< RegionDescriptor > RegionDescriptionVec
Definition: MuonLayerHough.h:56
MuonHough::MuonLayerHough::Maximum::binposmax
int binposmax
Definition: MuonLayerHough.h:77
MuonHough::RegionDescriptor::chIndex
ChIdx chIndex
Definition: MuonLayerHough.h:47
MuonLayerHoughSelector.h
MuonHough::MuonLayerHough::Maximum::isEndcap
bool isEndcap() const
Definition: MuonLayerHough.h:85