ATLAS Offline Software
MuonLayerHough.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 
27  float referencePosition_, float yMinRange_, float yMaxRange_, float yBinSize_, float thetaStep_,
28  unsigned int nthetaSamples_) :
29  sector(sector_),
30  region(region_),
31  chIndex(chIndex_),
32  referencePosition(referencePosition_),
33  yMinRange(yMinRange_),
34  yMaxRange(yMaxRange_),
35  yBinSize(yBinSize_),
36  thetaStep(thetaStep_),
37  nthetaSamples(nthetaSamples_) {}
38  RegionDescriptor() = default;
39 
40  int sector{0};
44  float yMinRange{0};
45  float yMaxRange{0};
46  float yBinSize{0};
47  float thetaStep{0};
48  unsigned int nthetaSamples{1};
49  };
50 
51  using RegionDescriptionVec = std::vector<RegionDescriptor>;
52 
53 
54  struct MuonLayerHough {
56  struct Maximum {
57  Maximum() = default;
58 
59  float max{0.}; // value of the maximum
60  float pos{0.}; // spacial position
61  float theta{0.}; // angle
62 
63  float refpos{0.}; // reference position
64  int refregion{0}; // reference region
65  int refchIndex{0}; // reference chamber index
66 
67  int binpos{-1}; // position bin
68  int binposmin{-1}; // lower edge of the maximum
69  int binposmax{-1}; // upper edge of the maximu
70  float binsize{0.}; // size of bin
71  int bintheta{-1}; // theta bin
72  int triggerConfirmed{0}; // number of in time trigger hits associated with the maximum
73  HitVec hits; // vector of associated hits
74 
75  const MuonLayerHough* hough{nullptr}; // pointer to the corresponding hough
76 
77  bool isEndcap() const {
78  // refers to the chamber orientation!!!! so BEE is a barell in this def
81  // need to make sure BEE's reference plane is the same as barrel
82  if (region != Muon::MuonStationIndex::Barrel && chIndex != Muon::MuonStationIndex::BEE) { return true; }
83  return false;
84  };
85  float getGlobalR() const {
86  if (isEndcap()) { return pos; }
87  return refpos;
88  };
89  float getGlobalZ() const {
90  if (isEndcap()) { return refpos; }
91  return pos;
92  };
93  float getGlobalTheta() const {
94  if (isEndcap()) {
95  // return M_PI/2.0 - theta;
96  if (theta > 0) {
97  return M_PI / 2.0 - theta;
98  } else {
99  return -M_PI / 2.0 - theta;
100  }
101  }
102  return theta;
103  };
104  };
105 
107  MuonLayerHough(const RegionDescriptor& descriptor);
108 
110  ~MuonLayerHough() = default;
111 
113  void reset();
114 
116  void setDebug(bool d) { m_debug = d; }
117 
119  int bin(const Hit& hit) const;
120 
122  int bin(float x, float y) const;
123 
125  float yval(int posBin) const;
126 
128  void pars(int posBin, int /*thetaBin*/, float& x, float& y) const;
129 
131  float layerConfirmation(const Hit& hit, float range = 1000.) const;
132 
134  float layerConfirmation(float x, float y, float range = 1000.) const;
135 
137  std::pair<float, float> layerConfirmation(unsigned int thetaBin, float x, float y, float range = 1000.) const;
138 
140  bool findMaximum(Maximum& maximum, const MuonLayerHoughSelector& selector) const;
141 
143  void associateHitsToMaximum(Maximum& maximum, const HitVec& hits) const;
144 
146  std::pair<int, int> range(const float x, const float y1, const float y2, const int bintheta) const;
147 
149  std::pair<float, float> maximum(float x, float y, int& posbin, int& thetabin) const;
150 
152  void fill(const Hit& hit);
153 
155  void fill(float x, float y, float weight);
156 
158  void fillLayer(const HitVec& hits, bool substract = false);
159 
160  // fill the hough space with a vector of hits using the layer mode
161  void fillLayer2(const HitVec& hits, bool subtract = false);
162 
164  std::vector<TH1*> rootHistos(const std::string& prefix, const float* rmin = 0, const float* rmax = 0) const;
165 
166  // members
167 
168  float m_binsize{0};
169  float m_invbinsize{0};
170 
171  // unsigned int m_nthetasamples;
172  int m_nbins{-1};
173 
174  unsigned int max{0};
175  int maxhist{-1};
176  int maxbin{-1};
177  bool m_debug{false};
178  std::vector<std::unique_ptr<unsigned int[]> > m_histos; // the maximum contents of all the histograms, overlayed
180  };
181 
182  inline int MuonLayerHough::bin(const Hit& hit) const { return bin(hit.x, hit.ymin); }
183 
184  inline int MuonLayerHough::bin(float x, float y) const {
185  float yref = y * (m_descriptor.referencePosition - x) / x + y;
186  int in = (yref - m_descriptor.yMinRange) / m_binsize;
187  if (in < 0 || in >= m_nbins) in = -1;
188  return in;
189  }
190 
191  inline void MuonLayerHough::pars(int posBin, int /*thetaBin*/, float& x, float& y) const {
193  y = yval(posBin);
194  }
195 
196  inline float MuonLayerHough::yval(int posBin) const { return m_descriptor.yMinRange + posBin * m_binsize; }
197 
198  inline float MuonLayerHough::layerConfirmation(const Hit& hit, float range) const { return layerConfirmation(hit.x, hit.ymin, range); }
199 
200  inline void MuonLayerHough::fill(const Hit& hit) { fill(hit.x, hit.ymin, hit.w); }
201 
202  // function for linear/parabolic extrapolation from maxima to maxima in a different station
203  float extrapolate(const MuonLayerHough::Maximum& ref, const MuonLayerHough::Maximum& ex, bool doparabolic = false);
204 } // namespace MuonHough
205 #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:76
MuonHough::RegionDescriptor::region
Muon::MuonStationIndex::DetectorRegionIndex region
Definition: MuonLayerHough.h:41
MuonHough::HitVec
std::vector< std::shared_ptr< MuonHough::Hit > > HitVec
Definition: MuonLayerHough.h:21
MuonHough::RegionDescriptor::RegionDescriptor
RegionDescriptor(int sector_, Muon::MuonStationIndex::DetectorRegionIndex region_, Muon::MuonStationIndex::ChIndex chIndex_, float referencePosition_, float yMinRange_, float yMaxRange_, float yBinSize_, float thetaStep_, unsigned int nthetaSamples_)
Definition: MuonLayerHough.h:26
MuonHough::MuonLayerHough::yval
float yval(int posBin) const
access to y coordinate of a given bin
Definition: MuonLayerHough.h:196
MuonHough::MuonLayerHough::m_binsize
float m_binsize
Definition: MuonLayerHough.h:168
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:78
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:198
MuonHough::MuonLayerHough::max
unsigned int max
Definition: MuonLayerHough.h:174
MuonHough::MuonLayerHough::m_descriptor
RegionDescriptor m_descriptor
Definition: MuonLayerHough.h:179
MuonHough::MuonLayerHough::m_nbins
int m_nbins
inverse binsize
Definition: MuonLayerHough.h:172
MuonHough::MuonLayerHough::m_debug
bool m_debug
Definition: MuonLayerHough.h:177
MuonHough::RegionDescriptor::yMinRange
float yMinRange
Definition: MuonLayerHough.h:44
MuonHough::MuonLayerHough::Maximum::refpos
float refpos
Definition: MuonLayerHough.h:63
M_PI
#define M_PI
Definition: ActiveFraction.h:11
MuonHough::RegionDescriptor::thetaStep
float thetaStep
Definition: MuonLayerHough.h:47
MuonHough::RegionDescriptor::nthetaSamples
unsigned int nthetaSamples
Definition: MuonLayerHough.h:48
MuonHough::MuonLayerHough
Definition: MuonLayerHough.h:54
MuonHough::MuonLayerHoughSelector
Definition: MuonLayerHoughSelector.h:12
MuonHough::MuonLayerHough::Maximum::binpos
int binpos
Definition: MuonLayerHough.h:67
MuonHough::RegionDescriptor::yMaxRange
float yMaxRange
Definition: MuonLayerHough.h:45
MuonHough::RegionDescriptor::referencePosition
float referencePosition
Definition: MuonLayerHough.h:43
MuonHough::Hit
struct containing all hit information needed for the Hough transform
Definition: MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonLayerHough/MuonLayerHough/Hit.h:58
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:85
x
#define x
MuonHough::MuonLayerHough::maxhist
int maxhist
Definition: MuonLayerHough.h:175
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
MuonHough::MuonLayerHough::bin
int bin(const Hit &hit) const
calculate the position bin the hit will endup in
Definition: MuonLayerHough.h:182
Hit.h
MuonHough::MuonLayerHough::Maximum::binposmin
int binposmin
Definition: MuonLayerHough.h:68
MuonHough::MuonLayerHough::Maximum
struct representing the maximum in the hough space
Definition: MuonLayerHough.h:56
MuonHough::RegionDescriptor::sector
int sector
Definition: MuonLayerHough.h:40
MuonHough::MuonLayerHough::Maximum::theta
float theta
Definition: MuonLayerHough.h:61
MuonHough::MuonLayerHough::fill
void fill(const Hit &hit)
fill the hough space with a single position
Definition: MuonLayerHough.h:200
MuonHough::MuonLayerHough::Maximum::max
float max
Definition: MuonLayerHough.h:59
MuonHough::MuonLayerHough::Maximum::binsize
float binsize
Definition: MuonLayerHough.h:70
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:484
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:389
LArG4ShowerLibProcessing.hits
hits
Definition: LArG4ShowerLibProcessing.py:136
Muon::MuonStationIndex::Barrel
@ Barrel
Definition: MuonStationIndex.h:49
MuonHough::MuonLayerHough::findMaximum
bool findMaximum(Maximum &maximum, const MuonLayerHoughSelector &selector) const
find the highest maximum that is above maxval
Definition: MuonLayerHough.cxx:288
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
MuonHough::MuonLayerHough::Maximum::triggerConfirmed
int triggerConfirmed
Definition: MuonLayerHough.h:72
MuonHough
Definition: MuonLayerHoughTool.h:42
MuonHough::Hit::x
float x
layer identifier (packed word containing technology/sublayer)
Definition: MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonLayerHough/MuonLayerHough/Hit.h:75
MuonHough::RegionDescriptor::chIndex
Muon::MuonStationIndex::ChIndex chIndex
Definition: MuonLayerHough.h:42
Muon::MuonStationIndex::DetectorRegionUnknown
@ DetectorRegionUnknown
Definition: MuonStationIndex.h:48
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:89
MuonHough::MuonLayerHough::Maximum::Maximum
Maximum()=default
MuonHough::MuonLayerHough::m_invbinsize
float m_invbinsize
binsize
Definition: MuonLayerHough.h:169
MuonHough::MuonLayerHough::associateHitsToMaximum
void associateHitsToMaximum(Maximum &maximum, const HitVec &hits) const
associates the list of input hits to the provided maximum
Definition: MuonLayerHough.cxx:366
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:75
Muon::MuonStationIndex::ChUnknown
@ ChUnknown
Definition: MuonStationIndex.h:16
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:116
MuonHough::MuonLayerHough::~MuonLayerHough
~MuonLayerHough()=default
destructor
MuonHough::MuonLayerHough::maxbin
int maxbin
Definition: MuonLayerHough.h:176
MuonHough::MuonLayerHough::Maximum::refchIndex
int refchIndex
Definition: MuonLayerHough.h:65
MuonHough::MuonLayerHough::Maximum::bintheta
int bintheta
Definition: MuonLayerHough.h:71
MuonHough::RegionDescriptor::yBinSize
float yBinSize
Definition: MuonLayerHough.h:46
MuonHough::MuonLayerHough::reset
void reset()
reset the transform
Definition: MuonLayerHough.cxx:48
MuonHough::MuonLayerHough::Maximum::pos
float pos
Definition: MuonLayerHough.h:60
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::hits
HitVec hits
Definition: MuonLayerHough.h:73
MuonHough::MuonLayerHough::Maximum::refregion
int refregion
Definition: MuonLayerHough.h:64
python.selector.AtlRunQuerySelectorLhcOlc.selector
selector
Definition: AtlRunQuerySelectorLhcOlc.py:611
y
#define y
ref
const boost::regex ref(r_ef)
Muon::MuonStationIndex::BEE
@ BEE
Definition: MuonStationIndex.h:17
TH1
Definition: rootspy.cxx:268
MuonHough::MuonLayerHough::m_histos
std::vector< std::unique_ptr< unsigned int[]> > m_histos
Definition: MuonLayerHough.h:178
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:270
MuonHough::MuonLayerHough::fillLayer2
void fillLayer2(const HitVec &hits, bool subtract=false)
Definition: MuonLayerHough.cxx:199
MuonHough::MuonLayerHough::Maximum::getGlobalTheta
float getGlobalTheta() const
Definition: MuonLayerHough.h:93
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:519
MuonHough::MuonLayerHough::pars
void pars(int posBin, int, float &x, float &y) const
calculate x,y for the given position bin
Definition: MuonLayerHough.h:191
MuonStationIndex.h
MuonHough::RegionDescriptionVec
std::vector< RegionDescriptor > RegionDescriptionVec
Definition: MuonLayerHough.h:51
MuonHough::MuonLayerHough::Maximum::binposmax
int binposmax
Definition: MuonLayerHough.h:69
MuonLayerHoughSelector.h
MuonHough::MuonLayerHough::Maximum::isEndcap
bool isEndcap() const
Definition: MuonLayerHough.h:77