ATLAS Offline Software
MuonHoughTransformer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include "GaudiKernel/MsgStream.h"
10 
11 MuonHoughTransformer::MuonHoughTransformer(const std::string& tr_name,int nbins, int nbins_angle, double detectorsize, double detectorsize_angle,
12  double threshold_histo, int number_of_sectors) :
13  AthMessaging(tr_name),
14  m_threshold_histo(threshold_histo),
15  m_eventsize(0),
16  m_eventsize_weightfactor(20.),
17  m_nbins(nbins),
18  m_nbins_plus3(m_nbins + 3),
19  m_nbins_angle(nbins_angle),
20  m_detectorsize(detectorsize),
21  m_detectorsize_angle(detectorsize_angle),
22  m_number_of_sectors(number_of_sectors) {
23  m_add_weight_angle = false;
26 
27  m_use_negative_weights = false;
28  m_ip_setting = true;
29 
30  m_stepsize = 2 * detectorsize / (nbins + 0.);
31  m_stepsize_per_angle = detectorsize_angle / (nbins_angle + 0.);
32 
35  for (int i = 0; i < m_number_of_sectors; i++) {
36  std::unique_ptr<MuonHoughHisto2D> histo = std::make_unique<MuonHoughHisto2D>(nbins, -detectorsize, detectorsize, nbins_angle, 0., detectorsize_angle);
37  histo->setThreshold(m_threshold_histo);
38  m_histos.push_back(std::move(histo));
39  }
40 
43 }
44 
46 
48  m_eventsize = event.size();
49  m_eventsize_weightfactor = 20. * std::sqrt(m_eventsize) / std::sqrt(7000.);
50  if (subtract) {
51  // invalidate maxima
52  for (int i = 0; i < m_histos.size(); ++i) m_histos.getHisto(i)->setMaximumIsValid(false);
53 
54  for (unsigned int hitid = 0; hitid < m_eventsize; hitid++) {
55  std::shared_ptr<MuonHoughHit> hit = event.getHit(hitid);
56  if (hit->getAssociated()) fillHit(hit, -1. * hit->getWeight());
57  }
58  } else {
59  for (unsigned int hitid = 0; hitid < m_eventsize; hitid++) { fillHit(event.getHit(hitid), event.getHit(hitid)->getWeight()); }
60  }
61 }
62 
63 std::unique_ptr<MuonHoughPattern> MuonHoughTransformer::associateHitsToMaximum(const MuonHoughHitContainer& event, double maximum_residu_mm,
64  double maximum_residu_grad, int maximum_number) const {
65  std::unique_ptr<MuonHoughPattern> houghpattern{};
66  std::pair<double, double> coordsmaximum;
67  std::pair<int, int> maximumbin;
68  maximumbin = m_histos.getMaximumBinnumber();
69 
70  int sector = maximumbin.first;
71 
72  if (sector != -1) {
73  coordsmaximum = m_histos.getHisto(sector)->getCoordsMaximum(maximum_number);
74  if (maximumbin.second == -1){ // no maximum, no bin above threshold
75  ATH_MSG_VERBOSE("No Maximum Found");
76  return nullptr;
77  }
78  ATH_MSG_VERBOSE("maximum binnumber of histogram: " << maximumbin.second
79  << " value: " << m_histos.getHisto(sector)->getBinContent(maximumbin.second));
80  ATH_MSG_VERBOSE(" coordinates: " << coordsmaximum.first << " second " << coordsmaximum.second<<" sector: "<<sector);
81  houghpattern = hookAssociateHitsToMaximum(event, coordsmaximum, maximum_residu_mm, maximum_residu_grad, sector);
82  if (houghpattern) { houghpattern->setMaximumHistogram(m_histos.getHisto(sector)->getBinContent(maximumbin.second)); }
83  } else {
84  ATH_MSG_VERBOSE("No Maximum Found sector is -1");
85  return nullptr;
86  }
87 
88  return houghpattern;
89 }
90 
91 std::unique_ptr<MuonHoughPattern> MuonHoughTransformer::associateHitsToCoords(const MuonHoughHitContainer& event, std::pair<double, double> coordsmaximum,
92  double maximum_residu_mm, double maximum_residu_angle, int sector) const {
93  return hookAssociateHitsToMaximum(event, coordsmaximum, maximum_residu_mm, maximum_residu_angle, sector);
94 }
95 
96 std::unique_ptr<MuonHoughPattern> MuonHoughTransformer::associateHitsToBinnumber(const MuonHoughHitContainer& event, int binnumber,
97  double maximum_residu_mm, double maximum_residu_angle, int sector) const {
98  ATH_MSG_VERBOSE("associateHitsToBinnumber() -- sector "<<sector<<",binnumber "<<binnumber<<
99  " maximum of histogram: " << m_histos.getHisto(sector)->getBinContent(binnumber));
100 
101  std::pair<double, double> coordsmaximum = m_histos.getHisto(sector)->binnumberToCoords(binnumber);
102  std::unique_ptr<MuonHoughPattern> houghpattern = hookAssociateHitsToMaximum(event, coordsmaximum,
103  maximum_residu_mm, maximum_residu_angle, sector);
104  houghpattern->setMaximumHistogram(m_histos.getHisto(sector)->getBinContent(binnumber));
105  return houghpattern;
106 }
107 
108 std::pair<double, double> MuonHoughTransformer::getEndPointsFillLoop(double radius, double stepsize, int sector) const {
109  std::pair<double, double> endpoints(-radius + 0.00001, radius); // why +0.00001?
110 
111  if (-radius < m_histos.getHisto(sector)->getXmin()) // randomizer to avoid binning effects
112  {
113  endpoints.first = m_histos.getHisto(sector)->getXmin() + 0.5 * stepsize; // no randomizer! no radius constraint
114  }
115 
116  if (radius > m_histos.getHisto(sector)->getXmax()) { endpoints.second = m_histos.getHisto(sector)->getXmax(); }
117  return endpoints;
118 }
119 
121 
122 std::vector<std::pair<int, int> > MuonHoughTransformer::getMaxima(int max_patterns) const {
123  std::vector<std::pair<int, int> > maximumbins; // sorted
124 
125  std::vector<std::pair<std::pair<int, int>, double> > maxima;
126 
127  for (int sector = 0; sector < m_number_of_sectors; sector++) // to be made more general when m_number_of_sectors ==1 e.g.
128  {
129  std::pair<int, double> maximumbin = m_histos.getHisto(sector)->getMax();
130  std::pair<std::pair<int, int>, double> maximum;
131  maximum.first.first = sector;
132  maximum.first.second = maximumbin.first;
133  maximum.second = maximumbin.second;
134  maxima.push_back(maximum);
135  }
136 
137  sort(maxima.begin(), maxima.end(), maximaCompare());
138 
139  unsigned int count_maxima = 0; // should be iterator
140  int number_of_patterns = 0;
141  std::set<int> sectors; // sectors that are already used
142  const unsigned int size = maxima.size();
143  while (count_maxima != size && number_of_patterns != max_patterns) {
144  std::pair<int, int> maximumbin = maxima[count_maxima].first;
145 
146  bool check = true; // check if sector is not nearby a sector already chosen
147  int sector = maximumbin.first;
148 
149  if (sectors.find(sector) != sectors.end()) { check = false; }
150 
151  if (check) {
152  maximumbins.push_back(maximumbin);
153  sectors.insert(maximumbin.first);
154 
155  int sectormin = sector - 1;
156  int sectorplus = sector + 1;
157  if (sectormin < 0) { sectormin = m_number_of_sectors; }
158  if (sectorplus > m_number_of_sectors) { sectorplus = 0; }
159 
160  sectors.insert(sectormin);
161  sectors.insert(sectorplus);
162 
163  if (m_number_of_sectors > 20 && maximumbin.first % 2 == 1) // hack for new single and overlap filling curved transform!
164  {
165  int sectorminmin = sectormin - 1;
166  int sectorplusplus = sectorplus + 1;
167  sectors.insert(sectorminmin);
168  sectors.insert(sectorplusplus);
169  }
170 
171  count_maxima++;
172  number_of_patterns++;
173  } else {
174  count_maxima++;
175  }
176  }
177 
178  return maximumbins;
179 }
MuonHoughTransformer::m_weight_constant_angle
double m_weight_constant_angle
weight constant of patterns in angle coordinate
Definition: MuonHoughTransformer.h:92
MuonHoughTransformer::maximaCompare
Definition: MuonHoughTransformer.h:132
MuonHoughHisto2DContainer::reserve
void reserve(int)
reserve a certain size (memory) for m_histos
Definition: MuonHoughHisto2DContainer.h:40
MuonHoughHisto2D::getBinContent
double getBinContent(int binnumber) const
returns x axis
Definition: MuonHoughHisto2D.h:205
MuonHoughHisto2DContainer::getHisto
MuonHoughHisto2D * getHisto(int id) const
return histogram at place id
Definition: MuonHoughHisto2DContainer.h:39
MuonHoughTransformer::m_threshold_histo
double m_threshold_histo
threshold of histograms
Definition: MuonHoughTransformer.h:82
MuonHoughTransformer.h
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
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonHoughHisto2D::setMaximumIsValid
void setMaximumIsValid(bool flag)
Definition: MuonHoughHisto2D.h:115
MuonHoughTransformer::m_weight_constant_radius
double m_weight_constant_radius
weight constant of patterns in radius coordinate
Definition: MuonHoughTransformer.h:96
MuonHoughTransformer::resetHisto
void resetHisto()
reset histograms
Definition: MuonHoughTransformer.cxx:120
MuonHoughHisto2DContainer::push_back
void push_back(std::unique_ptr< MuonHoughHisto2D >)
push_back a histogram
Definition: MuonHoughHisto2DContainer.h:41
MuonHoughHisto2DContainer::size
int size() const
returns size of container
Definition: MuonHoughHisto2DContainer.h:38
MuonHoughTransformer::getMaxima
std::vector< std::pair< int, int > > getMaxima(int max_patterns) const
return the first certain number of maxima of histograms
Definition: MuonHoughTransformer.cxx:122
MuonHoughTransformer::m_use_negative_weights
bool m_use_negative_weights
use of negative weights
Definition: MuonHoughTransformer.h:99
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonHoughTransformer::m_histos
MuonHoughHisto2DContainer m_histos
histogram container
Definition: MuonHoughTransformer.h:79
MuonHoughTransformer::fill
virtual void fill(const MuonHoughHitContainer &event, bool subtract=false)
fill histograms with hitcontainer
Definition: MuonHoughTransformer.cxx:47
MuonHoughTransformer::MuonHoughTransformer
MuonHoughTransformer(const std::string &tr_name, int nbins, int nbins_angle, double detectorsize, double detectorsize_angle, double threshold_histo, int number_of_sectors=1)
constructor, input values are those of histograms
Definition: MuonHoughTransformer.cxx:11
MuonHoughTransformer::m_binwidthx
double m_binwidthx
x-binwidth of histogram
Definition: MuonHoughTransformer.h:115
MuonHoughTransformer::associateHitsToMaximum
std::unique_ptr< MuonHoughPattern > associateHitsToMaximum(const MuonHoughHitContainer &event, double residu_mm, double residu_grad, int maximum_number) const
associate hits to certain maximum number of histograms
Definition: MuonHoughTransformer.cxx:63
MuonHoughTransformer::m_eventsize_weightfactor
double m_eventsize_weightfactor
weightfactor based on eventsize (used in curved hough transform)
Definition: MuonHoughTransformer.h:87
MuonHoughTransformer::hookAssociateHitsToMaximum
virtual std::unique_ptr< MuonHoughPattern > hookAssociateHitsToMaximum(const MuonHoughHitContainer &event, std::pair< double, double > coordsmaximum, double residu_mm, double residu_angle, int sector) const =0
pure virtual method for derived class implementation of associateHitsToMaximum method
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
MuonHoughTransformer::m_stepsize
double m_stepsize
stepsize of transform for radius coordinate
Definition: MuonHoughTransformer.h:120
MuonHoughHisto2DContainer::reset
void reset() const
resets histograms
Definition: MuonHoughHisto2DContainer.cxx:26
MuonHoughHisto2D::getBinWidthX
double getBinWidthX() const
return binwidth x axis
Definition: MuonHoughHisto2D.h:211
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
lumiFormat.i
int i
Definition: lumiFormat.py:85
MuonHoughTransformer::associateHitsToBinnumber
std::unique_ptr< MuonHoughPattern > associateHitsToBinnumber(const MuonHoughHitContainer &event, int binnumber, double maximum_residu_mm, double maximum_residu_angle, int sector=0) const
associate hits to certain binnumber and sector
Definition: MuonHoughTransformer.cxx:96
MuonHoughTransformer::m_stepsize_per_angle
double m_stepsize_per_angle
stepsize of transform for angle coordinate
Definition: MuonHoughTransformer.h:122
MuonHoughHitContainer
Definition: MuonHoughHitContainer.h:15
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
MuonHoughHitContainer.h
MuonHoughHisto2D::binnumberToCoords
std::pair< double, double > binnumberToCoords(int binnumber, int printlevel=0) const
gives coordinates for certain binnumber
Definition: MuonHoughHisto2D.cxx:189
MuonHoughTransformer::m_number_of_sectors
const int m_number_of_sectors
number of histograms (1 for cosmics 16 for rz)
Definition: MuonHoughTransformer.h:128
MuonHoughTransformer::fillHit
virtual void fillHit(const std::shared_ptr< MuonHoughHit > &hit, double weight=1.)=0
fill histograms with hit
MuonHoughTransformer::associateHitsToCoords
std::unique_ptr< MuonHoughPattern > associateHitsToCoords(const MuonHoughHitContainer &event, std::pair< double, double > coords, double residu_mm, double residu_angle, int sector=0) const
associate hits to certain coordinates and sector
Definition: MuonHoughTransformer.cxx:91
MuonHoughTransformer::getEndPointsFillLoop
std::pair< double, double > getEndPointsFillLoop(double radius, double stepsize, int sector) const
returns begin and end value of the filling loop
Definition: MuonHoughTransformer.cxx:108
MuonHoughHit::getWeight
double getWeight() const
returns weight in histogram after rescaling
Definition: MuonHoughHit.h:162
LArNewCalib_Delay_OFC_Cali.check
check
Definition: LArNewCalib_Delay_OFC_Cali.py:267
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
MuonHoughHisto2D::getXmax
double getXmax() const
returns max x axis
Definition: MuonHoughHisto2D.h:210
MuonHoughPattern::setMaximumHistogram
void setMaximumHistogram(double maximumhistogram)
set maximum of histogram used to generate pattern
Definition: MuonHoughPattern.h:128
MuonHoughHisto2DContainer::getMaximumBinnumber
std::pair< int, int > getMaximumBinnumber() const
return maximum of container gives first id histogram (sector) and then maximumbin
Definition: MuonHoughHisto2DContainer.cxx:9
MuonHoughTransformer::m_binwidthy
double m_binwidthy
y-binwidth of histogram
Definition: MuonHoughTransformer.h:117
MuonHoughTransformer::m_ip_setting
bool m_ip_setting
use settings for patterns originating from origin
Definition: MuonHoughTransformer.h:125
MuonHoughTransformer::~MuonHoughTransformer
virtual ~MuonHoughTransformer()
destructor
MuonHoughTransformer::m_eventsize
unsigned int m_eventsize
size of event to be filled (can be used for weighting)
Definition: MuonHoughTransformer.h:85
MuonHoughTransformer::m_add_weight_radius
bool m_add_weight_radius
use weight of patterns in radius coordinate
Definition: MuonHoughTransformer.h:94
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
plotBeamSpotCompare.histo
histo
Definition: plotBeamSpotCompare.py:415
MuonHoughTransformer::sector
virtual int sector(const std::shared_ptr< MuonHoughHit > &hit) const =0
returns sector for coords
MuonHoughHit::getAssociated
bool getAssociated() const
return if hit already associated to pattern
Definition: MuonHoughHit.h:176
MuonHoughTransformer::m_add_weight_angle
bool m_add_weight_angle
use weight of patterns in angle coordinate
Definition: MuonHoughTransformer.h:90
MuonHoughHisto2D::getBinWidthY
double getBinWidthY() const
return binwidth y axis
Definition: MuonHoughHisto2D.h:212