ATLAS Offline Software
MuonHoughHisto2D.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MUONHOUGHPATTERNEVENT_MUONHOUGHHISTO2D_H
6 #define MUONHOUGHPATTERNEVENT_MUONHOUGHHISTO2D_H
7 
9 #include <memory.h>
10 
11 #include <algorithm>
12 #include <cmath>
13 #include <functional>
14 #include <iostream>
15 #include <set>
16 #include <vector>
17 class TH2F;
18 
23 public:
25  ~MuonHoughHisto2D() = default;
27  MuonHoughHisto2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, int number_of_maxima = 1);
28 
30  int fill(double x, double y, double weight = 1.);
31 
33  void fill(int binnumber, double weight = 1.);
34 
36  int getNbinsX() const;
38  int getNbinsY() const;
39 
41  double getXmin() const;
43  double getXmax() const;
44 
46  double getBinWidthX() const;
47 
49  double getBinWidthY() const;
50 
52  double getBinContent(int binnumber) const;
53 
55  void reset();
56 
58  void findMaxima();
59 
61  std::pair<int, double> getMax() const;
63  std::pair<int, double> getMaximumBin(unsigned int maximum_number = 0);
65  std::pair<double, double> getCoordsMaximum(unsigned int maximum_number = 0);
66 
68  bool checkIfMaximumAlreadyUsed(int binnumber) const;
70  bool checkIfMaximum(int binnumber, double& maximum, int& maxbin) const;
71 
73  int distanceBins(int binnumber1, int binnumber2) const;
74 
76  double getMaximum(unsigned int maximum_number = 0);
78  int getMaxBin(unsigned int maximum_number = 0);
79 
81  double content_Bin_Area(int binnumber) const;
82 
83  // histogram functions:
84 
86  std::pair<double, double> binnumberToCoords(int binnumber, int printlevel = 0) const; // <x-point, y-point>
88  double binnumberToXCoord(int binnumber) const;
90  double binnumberToYCoord(int binnumber) const;
91 
93  int coordToBinnumber(double x, double y) const;
95  int coordToBinx(double x) const;
97  int coordToBiny(double y) const;
98 
105  int binInHistogram(unsigned int bin) const;
106 
108  void setThreshold(double threshold);
110  double getThreshold() const;
111 
113  std::unique_ptr<TH2F> bookAndFillRootHistogram(const std::string& hname) const;
114 
116 
117 private:
119  void init();
120 
122  void resetHisto();
123 
125  std::unique_ptr<unsigned int []> m_histBuffer{};
127  unsigned int m_size{0};
128 
130  unsigned int m_nbinsx{0};
132  unsigned int m_nbinsx_plus2{0};
134  double m_xmin{0};
136  double m_xmax{0};
138  unsigned int m_nbinsy{0};
140  unsigned int m_nbinsy_plus2{0};
142  double m_ymin{0.};
144  double m_ymax{0.};
145 
147  double m_binwidthx{0.};
149  double m_binwidthy{0.};
150 
152  double m_invbinwidthx{0.};
154  double m_invbinwidthy{0.};
155 
158  std::set<int> m_bins_above_threshold{};
159 
161  std::vector<int> m_maximumbins{};
162 
163 
165  const int m_number_of_maxima{0};
166 
168  unsigned int m_scale{0}; // conversion from double -> unsigned int
169  unsigned int m_threshold{0};
170 
173 
175  bool m_maxima_found{false};
176 
178  int m_maximumBin{-1};
179  unsigned int m_maximum{0};
180  bool m_maximumIsValid{true}; // flag whether the maximum can be trusted
182  void setBinContent(int binnumber, double value);
184  void setBinContent(int binx, int biny, double value);
185 
188 };
189 
190 inline int MuonHoughHisto2D::fill(double x, double y, double w) {
191  int binnumber = coordToBinnumber(x, y);
192  fill(binnumber, w);
193  return binnumber;
194 }
195 
196 inline void MuonHoughHisto2D::fill(int binnumber, double weight) {
197  unsigned int& binval = m_histBuffer[binnumber];
198  binval += m_scale * weight;
199  if (binval > m_maximum) {
200  m_maximum = binval;
201  m_maximumBin = binnumber;
202  }
203 }
204 inline void MuonHoughHisto2D::setBinContent(int binnumber, double value) { m_histBuffer[binnumber] = m_scale * value; }
205 inline double MuonHoughHisto2D::getBinContent(int binnumber) const { return m_histBuffer[binnumber] / m_scale; }
206 inline double MuonHoughHisto2D::content_Bin_Area(int binnumber) const { return getBinContent(binnumber); }
207 inline int MuonHoughHisto2D::getNbinsX() const { return m_nbinsx; }
208 inline int MuonHoughHisto2D::getNbinsY() const { return m_nbinsy; }
209 inline double MuonHoughHisto2D::getXmin() const { return m_xmin; }
210 inline double MuonHoughHisto2D::getXmax() const { return m_xmax; }
211 inline double MuonHoughHisto2D::getBinWidthX() const { return m_binwidthx; }
212 inline double MuonHoughHisto2D::getBinWidthY() const { return m_binwidthy; }
214 inline double MuonHoughHisto2D::getThreshold() const { return m_threshold; }
215 inline double MuonHoughHisto2D::getMaximum(unsigned int maximum_number) {
216  return getMaximumBin(maximum_number).second;
217 }
218 inline int MuonHoughHisto2D::getMaxBin(unsigned int maximum_number) {
219  return getMaximumBin(maximum_number).first;
220 }
221 inline int MuonHoughHisto2D::coordToBinx(double x) const { return static_cast<int>((x - m_xmin) * m_invbinwidthx) + 1; }
222 inline int MuonHoughHisto2D::coordToBiny(double y) const { return static_cast<int>((y - m_ymin) * m_invbinwidthy) + 1; }
223 inline int MuonHoughHisto2D::coordToBinnumber(double x, double y) const {
224  int biny = coordToBiny(y);
225  int binx = coordToBinx(x);
226  return binx + biny * m_nbinsx_plus2;
227 }
228 inline double MuonHoughHisto2D::binnumberToXCoord(int binnumber) const {
229  return m_xmin + m_binwidthx * (-0.5 + (binnumber) % m_nbinsx_plus2);
230 }
231 inline double MuonHoughHisto2D::binnumberToYCoord(int binnumber) const {
232  return m_ymin + m_binwidthy * (-0.5 + (binnumber) / m_nbinsx_plus2);
233 }
234 inline void MuonHoughHisto2D::resetHisto() { memset(m_histBuffer.get(), 0, sizeof(unsigned int) * m_size); }
235 
236 #endif // MUONHOUGHPATTERNEVENT_MUONHOUGHHISTO2D_H
MuonHoughHisto2D::getBinContent
double getBinContent(int binnumber) const
returns x axis
Definition: MuonHoughHisto2D.h:205
MuonHoughHisto2D::m_invbinwidthx
double m_invbinwidthx
inv binwidth x axis used for cpu speedup
Definition: MuonHoughHisto2D.h:152
MuonHoughHisto2D::setBinContent
void setBinContent(int binx, int biny, double value)
set bin content of binnumber corresponding to coordinates
ymin
double ymin
Definition: listroot.cxx:63
MuonHoughHisto2D::m_ymax
double m_ymax
maximum y coordinate
Definition: MuonHoughHisto2D.h:144
MuonHoughHisto2D::m_maximum
unsigned int m_maximum
Definition: MuonHoughHisto2D.h:179
MuonHoughHisto2D::m_binwidthy
double m_binwidthy
binwidth y axis
Definition: MuonHoughHisto2D.h:149
MuonHoughHisto2D::getMax
std::pair< int, double > getMax() const
returns binnumber and maximum of histogram (doesn't use m_bins_above_threshold)
Definition: MuonHoughHisto2D.cxx:87
MuonHoughHisto2D::findMaxima
void findMaxima()
find maxima in histogram
Definition: MuonHoughHisto2D.cxx:47
MuonHoughHisto2D::m_maximumIsValid
bool m_maximumIsValid
Definition: MuonHoughHisto2D.h:180
MuonHoughHisto2D::getNbinsX
int getNbinsX() const
returns number of bins x coordinate
Definition: MuonHoughHisto2D.h:207
MuonHoughHisto2D::setMaximumIsValid
void setMaximumIsValid(bool flag)
Definition: MuonHoughHisto2D.h:115
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:279
MuonHoughHisto2D::binnumberToXCoord
double binnumberToXCoord(int binnumber) const
gives x-coordinate for certain binnumber
Definition: MuonHoughHisto2D.h:228
MuonHoughHisto2D::distanceBins
int distanceBins(int binnumber1, int binnumber2) const
calculates the distance in binwidths between two binnumbers ("Manhattan metric")
Definition: MuonHoughHisto2D.cxx:180
MuonHoughHisto2D::m_histBuffer
std::unique_ptr< unsigned int[]> m_histBuffer
actual storage of bin values
Definition: MuonHoughHisto2D.h:125
MuonHoughHisto2D::m_size
unsigned int m_size
size of array
Definition: MuonHoughHisto2D.h:127
MuonHoughHisto2D::coordToBiny
int coordToBiny(double y) const
converts y-coordinates to biny
Definition: MuonHoughHisto2D.h:222
MuonHoughHisto2D::init
void init()
initialises private members, called in constructor
Definition: MuonHoughHisto2D.cxx:34
bin
Definition: BinsDiffFromStripMedian.h:43
athena.value
value
Definition: athena.py:124
MuonHoughHisto2D::m_maxima_found
bool m_maxima_found
check if search for maxima already performed
Definition: MuonHoughHisto2D.h:175
MuonHoughHisto2D::m_maximumbins
std::vector< int > m_maximumbins
binnumbers found as maxima
Definition: MuonHoughHisto2D.h:161
MuonHoughHisto2D::m_threshold
unsigned int m_threshold
Definition: MuonHoughHisto2D.h:169
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
MuonHoughHisto2D::coordToBinx
int coordToBinx(double x) const
converts x-coordinates to binx
Definition: MuonHoughHisto2D.h:221
x
#define x
MuonHoughHisto2D::m_distance_to_next_maximum
const int m_distance_to_next_maximum
minimum distance for a maximum to be away from another maximum
Definition: MuonHoughHisto2D.h:172
MuonHoughHisto2D::coordToBinnumber
int coordToBinnumber(double x, double y) const
converts coordinates to a binnumber
Definition: MuonHoughHisto2D.h:223
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
MuonHoughHisto2D::checkIfMaximum
bool checkIfMaximum(int binnumber, double &maximum, int &maxbin) const
check if binnumber is a maximum
Definition: MuonHoughHisto2D.cxx:157
MuonHoughHisto2D::m_nbinsy
unsigned int m_nbinsy
number of y bins
Definition: MuonHoughHisto2D.h:138
MuonHoughHisto2D::m_ymin
double m_ymin
minimum y coordinate
Definition: MuonHoughHisto2D.h:142
MuonHoughHisto2D::getBinWidthX
double getBinWidthX() const
return binwidth x axis
Definition: MuonHoughHisto2D.h:211
xmin
double xmin
Definition: listroot.cxx:60
master.flag
bool flag
Definition: master.py:29
MuonHoughHisto2D::content_Bin_Area
double content_Bin_Area(int binnumber) const
return the total content of binarea (default: content of bin)
Definition: MuonHoughHisto2D.h:206
MuonHoughHisto2D::checkIfMaximumAlreadyUsed
bool checkIfMaximumAlreadyUsed(int binnumber) const
check when searching for several maxima if binnumber is close to an earlier found maximum
Definition: MuonHoughHisto2D.cxx:144
MuonHoughHisto2D::reset
void reset()
clears histogram and bins_above_threshold
Definition: MuonHoughHisto2D.cxx:36
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
MuonHoughHisto2D::operator=
MuonHoughHisto2D & operator=(const MuonHoughHisto2D &right)
MuonHoughHisto2D::m_nbinsx
unsigned int m_nbinsx
number of x bins
Definition: MuonHoughHisto2D.h:130
MuonHoughHisto2D::binnumberToCoords
std::pair< double, double > binnumberToCoords(int binnumber, int printlevel=0) const
gives coordinates for certain binnumber
Definition: MuonHoughHisto2D.cxx:189
MuonHoughHisto2D::resetHisto
void resetHisto()
resets histogram
Definition: MuonHoughHisto2D.h:234
MuonHoughHisto2D::binInHistogram
int binInHistogram(unsigned int bin) const
checks if bin is in histogram or if it is an under/overflow bin (unused) 0 is in histo 1 x underflow ...
Definition: MuonHoughHisto2D.cxx:210
MuonHoughHisto2D::binnumberToYCoord
double binnumberToYCoord(int binnumber) const
gives y-coordinate for certain binnumber
Definition: MuonHoughHisto2D.h:231
MuonHoughHisto2D::m_xmin
double m_xmin
minimum x coordinate
Definition: MuonHoughHisto2D.h:134
MuonHoughHisto2D::getMaxBin
int getMaxBin(unsigned int maximum_number=0)
return maximum binnumber
Definition: MuonHoughHisto2D.h:218
threshold
Definition: chainparser.cxx:74
MuonHoughHisto2D::setBinContent
void setBinContent(int binnumber, double value)
set bin content of binnumber
Definition: MuonHoughHisto2D.h:204
MuonHoughHisto2D::m_xmax
double m_xmax
maximum x coordinate
Definition: MuonHoughHisto2D.h:136
MuonHoughHisto2D::getXmax
double getXmax() const
returns max x axis
Definition: MuonHoughHisto2D.h:210
MuonHoughHisto2D::getNbinsY
int getNbinsY() const
returns number of bins y coordinate
Definition: MuonHoughHisto2D.h:208
MuonHoughHisto2D::setThreshold
void setThreshold(double threshold)
set threshold for maxima in histogram
Definition: MuonHoughHisto2D.h:213
y
#define y
MuonHoughHisto2D::getMaximumBin
std::pair< int, double > getMaximumBin(unsigned int maximum_number=0)
returns binnumber and maximum of maximum number maximum_number
Definition: MuonHoughHisto2D.cxx:111
MuonHoughHisto2D::getMaximum
double getMaximum(unsigned int maximum_number=0)
return value of maximum bin
Definition: MuonHoughHisto2D.h:215
MuonHoughHisto2D::m_nbinsy_plus2
unsigned int m_nbinsy_plus2
number of y bins + 2 , used for cpu speedup
Definition: MuonHoughHisto2D.h:140
AthMessaging.h
MuonHoughHisto2D::m_bins_above_threshold
std::set< int > m_bins_above_threshold
set of bins that are above threshold used for speeding up searching for maxima
Definition: MuonHoughHisto2D.h:158
xmax
double xmax
Definition: listroot.cxx:61
MuonHoughHisto2D::m_invbinwidthy
double m_invbinwidthy
inv binwidth y axis used for cpu speedup
Definition: MuonHoughHisto2D.h:154
MuonHoughHisto2D::fill
int fill(double x, double y, double weight=1.)
fill 2d histogram with point (x,y) with weight w, return binnumber filled
Definition: MuonHoughHisto2D.h:190
MuonHoughHisto2D::m_number_of_maxima
const int m_number_of_maxima
number of maxima to be searched for
Definition: MuonHoughHisto2D.h:165
MuonHoughHisto2D::getCoordsMaximum
std::pair< double, double > getCoordsMaximum(unsigned int maximum_number=0)
returns coords of maximum number maximum_number
Definition: MuonHoughHisto2D.cxx:130
MuonHoughHisto2D::getXmin
double getXmin() const
returns min x axis
Definition: MuonHoughHisto2D.h:209
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
MuonHoughHisto2D::getThreshold
double getThreshold() const
returns threshold for maxima in histogram
Definition: MuonHoughHisto2D.h:214
MuonHoughHisto2D::~MuonHoughHisto2D
~MuonHoughHisto2D()=default
destructor
MuonHoughHisto2D::m_maximumBin
int m_maximumBin
maximum
Definition: MuonHoughHisto2D.h:178
dumpTgcDigiThreshold.threshold
list threshold
Definition: dumpTgcDigiThreshold.py:34
MuonHoughHisto2D::getBinWidthY
double getBinWidthY() const
return binwidth y axis
Definition: MuonHoughHisto2D.h:212
MuonHoughHisto2D::m_scale
unsigned int m_scale
threshold for minimum content for a maximum
Definition: MuonHoughHisto2D.h:168
MuonHoughHisto2D::m_nbinsx_plus2
unsigned int m_nbinsx_plus2
number of x bins + 2 , used for cpu speedup
Definition: MuonHoughHisto2D.h:132
MuonHoughHisto2D::bookAndFillRootHistogram
std::unique_ptr< TH2F > bookAndFillRootHistogram(const std::string &hname) const
intialises a root histogram of MuonHoughHisto2D and fill it, used for debugging purposes
Definition: MuonHoughHisto2D.cxx:226
MuonHoughHisto2D
Histogram class, similar to Root's TH2D.
Definition: MuonHoughHisto2D.h:22
ymax
double ymax
Definition: listroot.cxx:64
MuonHoughHisto2D::m_binwidthx
double m_binwidthx
binwidth x axis
Definition: MuonHoughHisto2D.h:147
MuonHoughHisto2D::MuonHoughHisto2D
MuonHoughHisto2D(const MuonHoughHisto2D &)
MuonHoughHisto2D::MuonHoughHisto2D
MuonHoughHisto2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, int number_of_maxima=1)
constructor
Definition: MuonHoughHisto2D.cxx:10