ATLAS Offline Software
Loading...
Searching...
No Matches
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
11MuonHoughTransformer::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),
17 m_nbins(nbins),
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
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
41 m_binwidthx = m_histos.getHisto(0)->getBinWidthX();
42 m_binwidthy = m_histos.getHisto(0)->getBinWidthY();
43}
44
46
47void MuonHoughTransformer::fill(const MuonHoughHitContainer& event, bool subtract) {
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
63std::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
91std::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
96std::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
108std::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
122std::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}
#define ATH_MSG_VERBOSE(x)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
const double m_detectorsize_angle
range of angle coordinate
MuonHoughHisto2DContainer m_histos
histogram container
bool m_ip_setting
use settings for patterns originating from origin
bool m_use_negative_weights
use of negative weights
bool m_add_weight_angle
use weight of patterns in angle coordinate
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
const int m_nbins_angle
number of bins in histograms in angle coordinate
const int m_nbins
number of bins in histograms in radius coordinate
std::vector< std::pair< int, int > > getMaxima(int max_patterns) const
return the first certain number of maxima of histograms
virtual void fillHit(const std::shared_ptr< MuonHoughHit > &hit, double weight=1.)=0
fill histograms with hit
double m_weight_constant_radius
weight constant of patterns in radius coordinate
virtual void fill(const MuonHoughHitContainer &event, bool subtract=false)
fill histograms with hitcontainer
unsigned int m_eventsize
size of event to be filled (can be used for weighting)
void resetHisto()
reset histograms
double m_stepsize_per_angle
stepsize of transform for angle coordinate
const int m_number_of_sectors
number of histograms (1 for cosmics 16 for rz)
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
double m_eventsize_weightfactor
weightfactor based on eventsize (used in curved hough transform)
double m_stepsize
stepsize of transform for radius coordinate
double m_binwidthx
x-binwidth of histogram
virtual ~MuonHoughTransformer()
destructor
const int m_nbins_plus3
number of bins in histograms in radius coordinate
double m_threshold_histo
threshold of histograms
const double m_detectorsize
range of radius coordinate
virtual int sector(const std::shared_ptr< MuonHoughHit > &hit) const =0
returns sector for coords
double m_binwidthy
y-binwidth of histogram
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
bool m_add_weight_radius
use weight of patterns in radius coordinate
std::pair< double, double > getEndPointsFillLoop(double radius, double stepsize, int sector) const
returns begin and end value of the filling loop
double m_weight_constant_angle
weight constant of patterns in angle coordinate
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
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
singleton-like access to IMessageSvc via open function and helper