ATLAS Offline Software
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 
11 MuonHoughPattern::MuonHoughPattern(int id_number) : MuonHoughHitContainer(), m_id_number(id_number) {}
12 
14  m_hit.clear();
15 }
16 
17 bool 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 
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;
109  case MuonHough::hough_rz:
113  case MuonHough::hough_curved_at_a_cylinder: eangle = m_etheta; 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 
121 double MuonHoughPattern::getER() const {
122  double er = 0;
123  switch (m_id_number) {
124  case MuonHough::hough_xy: er = m_erphi; break;
125  case MuonHough::hough_rz:
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 
137 void MuonHoughPattern::setEAngle(double eangle) {
138  switch (m_id_number) {
139  case MuonHough::hough_xy: m_ephi = eangle; break;
140  case MuonHough::hough_rz:
144  case MuonHough::hough_curved_at_a_cylinder: m_etheta = 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 
151 void MuonHoughPattern::setER(double er) {
152  switch (m_id_number) {
153  case MuonHough::hough_xy: m_erphi = er; break;
154  case MuonHough::hough_rz:
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 
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 
187  CxxUtils::sincos scphi(m_ephi);
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 }
CxxUtils::sincos::apply
double apply(double a, double b) const
Definition: sincos.h:98
MuonHoughPattern::setERPhi
void setERPhi(double erphi)
set r0 of pattern
Definition: MuonHoughPattern.h:124
MuonHoughPattern::m_ephi
double m_ephi
phi in rad
Definition: MuonHoughPattern.h:101
MuonHoughMathUtils::signedDistanceToLine
static double signedDistanceToLine(double x0, double y0, double r0, double phi)
distance from (x0,y0) to the line (r0,phi), phi in rad
Definition: MuonHoughMathUtils.cxx:31
MuonHoughPattern::MuonHoughPattern
MuonHoughPattern(int id_number)
MuonHoughPattern does not own its hits (contrary to the default) MuonHoughHitContainer!
Definition: MuonHoughPattern.cxx:11
MuonHough::hough_rzcosmics
@ hough_rzcosmics
Definition: MuonHoughPattern.h:14
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonHough::hough_rz_mdt
@ hough_rz_mdt
Definition: MuonHoughPattern.h:14
MuonHoughPattern::getER
double getER() const
returns radius in precision plane in mm
Definition: MuonHoughPattern.cxx:121
MuonHoughPattern::m_etheta
double m_etheta
theta in rad
Definition: MuonHoughPattern.h:105
MuonHoughPattern::getEPos
Amg::Vector3D getEPos() const
calulates 3d point closest to ip
Definition: MuonHoughPattern.cxx:165
MuonHoughHitContainer::getHit
std::shared_ptr< MuonHoughHit > getHit(int hitno) const
returns Hit at position hitno
Definition: MuonHoughHitContainer.h:91
MuonHough::hough_rz_rpc
@ hough_rz_rpc
Definition: MuonHoughPattern.h:14
M_PI
#define M_PI
Definition: ActiveFraction.h:11
sincos.h
Helper to simultaneously calculate sin and cos of the same angle.
MuonHoughPattern::setEPhi
void setEPhi(double ephi)
set phi of pattern
Definition: MuonHoughPattern.h:123
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
MuonHoughPattern::hitInHoughPattern
bool hitInHoughPattern(const std::shared_ptr< MuonHoughHit > &hit) const
returns if hit is in pattern
Definition: MuonHoughPattern.cxx:17
cosmics
Definition: cosmics.py:1
MuonHoughHitContainer::m_hit
std::vector< std::shared_ptr< MuonHoughHit > > m_hit
vector of hits in container
Definition: MuonHoughHitContainer.h:86
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
MuonHoughPattern::m_ertheta
double m_ertheta
z0 in mm
Definition: MuonHoughPattern.h:107
MuonHough::hough_xy
@ hough_xy
Definition: MuonHoughPattern.h:14
CxxUtils::sincos::cs
double cs
Definition: sincos.h:95
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
MuonHoughHitContainer::size
unsigned int size() const
returns size of hitcontainer
Definition: MuonHoughHitContainer.h:104
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonHoughPattern::m_id_number
int m_id_number
id number of hough transform used to generate pattern
Definition: MuonHoughPattern.h:94
MuonHoughHitContainer::getHity
double getHity(unsigned int hitno) const
returns y position of hit hitno
Definition: MuonHoughHitContainer.h:95
TRT_PAI_physicsConstants::r0
const double r0
electron radius{cm}
Definition: TRT_PAI_physicsConstants.h:20
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:127
MuonHoughHitContainer
Definition: MuonHoughHitContainer.h:15
MuonHough::hough_curved_at_a_cylinder
@ hough_curved_at_a_cylinder
Definition: MuonHoughPattern.h:14
MuonHoughPattern::updateParametersRPhi
void updateParametersRPhi(bool cosmics=false)
update parameters in rphi plane based on weighted fit
Definition: MuonHoughPattern.cxx:192
MuonHoughPattern::calculateEZ
double calculateEZ() const
calculate estimated z-position of pattern
Definition: MuonHoughPattern.cxx:65
MuonHoughPattern::m_erphi
double m_erphi
r0 in mm
Definition: MuonHoughPattern.h:103
MuonHoughPattern::printHoughPattern
void printHoughPattern() const
prints out info about hough pattern
Definition: MuonHoughPattern.cxx:91
MuonHoughPattern::resetTracksegment
void resetTracksegment()
clear pattern
Definition: MuonHoughPattern.cxx:13
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CxxUtils::sincos::sn
double sn
Definition: sincos.h:92
MuonHoughPattern::setEAngle
void setEAngle(double eangle)
set angle in precision plane in rad
Definition: MuonHoughPattern.cxx:137
MuonHoughPattern.h
MuonHoughPattern::getEAngle
double getEAngle() const
returns angle in precision plane in rad
Definition: MuonHoughPattern.cxx:105
MuonHoughHitContainer::empty
bool empty() const
returns if hitcontainer is empty
Definition: MuonHoughHitContainer.h:105
MuonHoughPattern::getEDir
Amg::Vector3D getEDir() const
calculates direction at point closest to ip
Definition: MuonHoughPattern.cxx:185
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
CxxUtils::sincos
Helper to simultaneously calculate sin and cos of the same angle.
Definition: sincos.h:76
MuonHoughPattern::setER
void setER(double er)
set radius in precision plane in mm
Definition: MuonHoughPattern.cxx:151
MuonHoughPattern::patternLength
double patternLength() const
returns distance between first and last hit
Definition: MuonHoughPattern.cxx:26
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
MuonHoughHitContainer::getHitx
double getHitx(unsigned int hitno) const
returns x position of hit hitno
Definition: MuonHoughHitContainer.h:94
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
MuonHough::hough_rz
@ hough_rz
Definition: MuonHoughPattern.h:14