ATLAS Offline Software
Loading...
Searching...
No Matches
MuonHoughPattern.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 "CxxUtils/sincos.h"
9#include "GaudiKernel/MsgStream.h"
10
12
16
17bool MuonHoughPattern::hitInHoughPattern(const std::shared_ptr<MuonHoughHit>& hit) const // adviced not to use, slow function
18{
19 for (unsigned int i = 0; i < size(); i++) {
20 if (m_hit[i]->getId() == hit->getId()) { return true; }
21 }
22
23 return false;
24}
25
27 // takes the first 2 hits and calculates distance and then takes next hit, and calculates from previous 2 hits which 2 are farthest
28 // away, etc.. also possible to calculate point closest to IP and determine if left/ right to pattern, app. just as fast.
29
30 double max_patternlength = 0;
31
32 if (m_hit.size() >= 2) {
33 double pattern_length1 = 0, pattern_length2 = 0;
34 int hitno1 = 0;
35 int hitno2 = 1;
36
37 Amg::Vector3D diff = m_hit[hitno1]->getPosition() - m_hit[hitno2]->getPosition();
38 max_patternlength = diff.mag();
39
40 for (unsigned int i = 2; i < m_hit.size(); i++) {
41 diff = m_hit[hitno1]->getPosition() - m_hit[i]->getPosition();
42 pattern_length1 = diff.mag();
43
44 diff = m_hit[hitno2]->getPosition() - m_hit[i]->getPosition();
45 pattern_length2 = diff.mag();
46
47 if (pattern_length1 <= max_patternlength && pattern_length2 <= max_patternlength) {
48 // nothing happens..
49 } else if (pattern_length1 > max_patternlength && pattern_length1 >= pattern_length2) {
50 hitno2 = i;
51 max_patternlength = pattern_length1;
52 } else if (pattern_length2 > max_patternlength && pattern_length2 > pattern_length1) {
53 hitno1 = i;
54 max_patternlength = pattern_length2;
55 }
56 }
57 } else {
58 MsgStream log(Athena::getMessageSvc(), "MuonHoughPattern::patternLength");
59 if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "MuonHoughPattern::pattern_size <2" << endmsg;
60 }
61
62 return max_patternlength;
63}
64
66 double ez = 0;
67 double count = 0;
68 // double r0 = m_erphi;
69
70 for (unsigned int hitno = 0; hitno < m_hit.size(); hitno++) {
71 // for each hit the distance from the hit to x,y line through (0,0) in the xy plane is calcualted and then distance*cos(theta) gives
72 // z_hit - z
73
74 double distance = MuonHoughMathUtils::signedDistanceToLine(getHit(hitno)->getHitx(), getHit(hitno)->getHity(), 0, m_ephi - M_PI);
75
76 double z = getHit(hitno)->getHitz() -
77 (distance * std::cos(m_etheta) / std::sin(m_etheta)); // distance * sin (m_etheta) = L // - sign correct?
78 // hough correction in here?
79
80 // straight line fitter?
81
82 ez += z;
83 count++;
84 }
85
86 ez = ez / count;
87
88 return ez;
89}
90
92 MsgStream log(Athena::getMessageSvc(), "MuonHoughPattern::printHoughPattern");
93 if (m_hit.empty()) {
94 if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "MuonHoughPattern::No pattern_Segment" << endmsg;
95 }
96
97 if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "MuonHoughPattern::Size of MuonHoughPattern: " << m_hit.size() << endmsg;
98 for (unsigned int i = 0; i < m_hit.size(); i++) {
99 if (log.level() <= MSG::VERBOSE)
100 log << MSG::VERBOSE << m_hit[i]->getHitx() << " " << m_hit[i]->getHity() << " " << m_hit[i]->getHitz() << " "
101 << m_hit[i]->getId() << endmsg;
102 }
103}
104
106 double eangle = 0;
107 switch (m_id_number) {
108 case MuonHough::hough_xy: eangle = m_ephi; break;
114 default:
115 MsgStream log(Athena::getMessageSvc(), "MuonHoughPattern::getEAngle");
116 if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "MuonHoughPattern::no valid id_number" << endmsg;
117 }
118 return eangle;
119}
120
122 double er = 0;
123 switch (m_id_number) {
124 case MuonHough::hough_xy: er = m_erphi; break;
130 default:
131 MsgStream log(Athena::getMessageSvc(), "MuonHoughPattern::getER");
132 if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "MuonHoughPattern::no valid id_number" << endmsg;
133 }
134 return er;
135}
136
137void MuonHoughPattern::setEAngle(double eangle) {
138 switch (m_id_number) {
139 case MuonHough::hough_xy: m_ephi = eangle; break;
145 default:
146 MsgStream log(Athena::getMessageSvc(), "MuonHoughPattern::setEAngle");
147 if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "MuonHoughPattern::no valid id_number" << endmsg;
148 }
149}
150
151void MuonHoughPattern::setER(double er) {
152 switch (m_id_number) {
153 case MuonHough::hough_xy: m_erphi = er; break;
159 default:
160 MsgStream log(Athena::getMessageSvc(), "MuonHoughPattern::setER");
161 if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "MuonHoughPattern::no valid id_number" << endmsg;
162 }
163}
164
166 // similar to StandardAlgs::shortestPointOfLineToOrigin3D
167
168 // should be maybe really shortest point, but
169
170 // problem is that there is no starting point on the line (well this calc. pos could be available)
171
172 Amg::Vector3D pos;
173
174 pos[0] = m_erphi * std::sin(m_ephi);
175 pos[1] = -m_erphi * std::cos(m_ephi);
176
177 if (m_etheta != 0) {
178 pos[2] = m_ertheta / std::sin(m_etheta);
179 } else {
180 pos[2] = 0;
181 }
182 return pos;
183}
184
188 CxxUtils::sincos sctheta(m_etheta);
189 return {scphi.cs * sctheta.sn, scphi.sn * sctheta.sn, sctheta.cs};
190}
191
193 if (empty()) return;
194
195 double sum_x = 0.;
196 double sum_y = 0.;
197
198 int hitsno = size();
199
200 for (unsigned int i = 0; i < size(); i++) {
201 sum_x += getHitx(i); //*getOrigWeight(i);
202 sum_y += getHity(i); //*getOrigWeight(i);
203 }
204
205 // adding interaction point constraint:
206 if (!cosmics || size() == 1) hitsno += size();
207
208 const double av_x = sum_x / (hitsno + 0.);
209 const double av_y = sum_y / (hitsno + 0.);
210
211 double sumx = 0.;
212 double sumy = 0.;
213 for (unsigned int i = 0; i < size(); i++) {
214 double hitx = getHitx(i);
215 double hity = getHity(i);
216 double x_offset = hitx - av_x;
217 double y_offset = hity - av_y;
218 double weight = (x_offset * x_offset + y_offset * y_offset); //*getOrigWeight(i);
219 int sign = 1;
220 if (!cosmics) {
221 if (x_offset * hitx + y_offset * hity < 0) { sign = -1; }
222 } else {
223 if (y_offset < 0) { sign = -1; } // assume cosmic muon comes from above
224 }
225 sumx += weight * sign * x_offset;
226 sumy += weight * sign * y_offset;
227 }
228 // adding interaction point (count size)
229 if (!cosmics) {
230 double weight = av_x * av_x + av_y * av_y;
231 sumx += size() * weight * av_x;
232 sumy += size() * weight * av_y;
233 }
234
235 if (std::abs(sumx) < 0.000001 || std::abs(sumy) < 0.000001) { return; }
236
237 double phi = std::atan2(sumy, sumx);
238 if (cosmics) {
239 if (phi > 0) phi -= M_PI; // phi between 0,-Pi for cosmics!
240 }
241
242 CxxUtils::sincos scphi(phi);
243
244 const double r0 = scphi.apply(av_x, -av_y);
245
246 setEPhi(phi);
247 setERPhi(r0);
248}
#define M_PI
Scalar phi() const
phi method
#define endmsg
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
int sign(int a)
#define z
unsigned int size() const
returns size of hitcontainer
double getHitx(unsigned int hitno) const
returns x position of hit hitno
double getHity(unsigned int hitno) const
returns y position of hit hitno
std::shared_ptr< MuonHoughHit > getHit(int hitno) const
returns Hit at position hitno
std::vector< std::shared_ptr< MuonHoughHit > > m_hit
vector of hits in container
bool empty() const
returns if hitcontainer is empty
MuonHoughHitContainer()=default
MuonHoughHitContainer does own its hits all added hits should be 'newed', except when m_ownhits==fals...
double getHitz() const
returns z position
static double signedDistanceToLine(double x0, double y0, double r0, double phi)
distance from (x0,y0) to the line (r0,phi), phi in rad
Amg::Vector3D getEPos() const
calulates 3d point closest to ip
double m_ephi
phi in rad
double m_ertheta
z0 in mm
void printHoughPattern() const
prints out info about hough pattern
void setERPhi(double erphi)
set r0 of pattern
void updateParametersRPhi(bool cosmics=false)
update parameters in rphi plane based on weighted fit
void resetTracksegment()
clear pattern
void setER(double er)
set radius in precision plane in mm
double calculateEZ() const
calculate estimated z-position of pattern
double patternLength() const
returns distance between first and last hit
double getER() const
returns radius in precision plane in mm
double getEAngle() const
returns angle in precision plane in rad
bool hitInHoughPattern(const std::shared_ptr< MuonHoughHit > &hit) const
returns if hit is in pattern
void setEAngle(double eangle)
set angle in precision plane in rad
Amg::Vector3D getEDir() const
calculates direction at point closest to ip
double m_erphi
r0 in mm
double m_etheta
theta in rad
void setEPhi(double ephi)
set phi of pattern
MuonHoughPattern(int id_number)
MuonHoughPattern does not own its hits (contrary to the default) MuonHoughHitContainer!
int m_id_number
id number of hough transform used to generate pattern
singleton-like access to IMessageSvc via open function and helper
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
Eigen::Matrix< double, 3, 1 > Vector3D
IMessageSvc * getMessageSvc(bool quiet=false)
@ hough_curved_at_a_cylinder
Helper to simultaneously calculate sin and cos of the same angle.
Helper to simultaneously calculate sin and cos of the same angle.
Definition sincos.h:39
double apply(double a, double b) const
Definition sincos.h:57