ATLAS Offline Software
LocalSegmentResolver.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <iostream>
8 
10 #include "GaudiKernel/MsgStream.h"
13 
14 namespace MuonCalib {
15 
17 
19  if (!seg) {
20  if (m_printLevel >= 1) {
21  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
22  log << MSG::VERBOSE << "LocalSegmentResolver::resolve: <got nullptr>" << endmsg;
23  }
24  return false;
25  }
26  if (seg->mdtHitsOnTrack() < 2) {
27  if (m_printLevel >= 1) {
28  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
29  log << MSG::VERBOSE << "LocalSegmentResolver::resolve: <to few hits, cannot resolve direction>" << endmsg;
30  }
31  return false;
32  }
33 
34  // get tangent lines
35  LineVec lines = getLines(*seg->mdtHOT().front(), *seg->mdtHOT().back());
36 
37  // find line which yields smallest residuals
38  int lineIndex = bestLine(seg->mdtHOT(), lines);
39 
40  // check if everything went right
41  if (lineIndex < 0) return false;
42 
43  // reset local position and direction of segment
44  seg->set(seg->chi2(), MuonCalib::LocalToPrecision::local(lines[lineIndex].first),
45  MuonCalib::LocalToPrecision::local(lines[lineIndex].second));
46 
47  return true;
48  }
49 
52  double x1 = hpos1.x();
53  double y1 = hpos1.y();
54  double r1 = std::abs(firstHit.driftRadius());
56  double x2 = hpos2.x();
57  double y2 = hpos2.y();
58  double r2 = std::abs(lastHit.driftRadius());
59 
60  double DeltaX = x2 - x1;
61  double DeltaY = y2 - y1;
62  double DistanceOfCenters = std::hypot(DeltaX, DeltaY);
63  double Alpha0 = std::atan2(DeltaY, DeltaX);
64 
65  LineVec list_of_lines;
66 
67  if (m_printLevel >= 1) {
68  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
69  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: calculating Lines (" << x1 << "," << y1 << ") " << r1 << " ("
70  << x2 << "," << y2 << ") " << r2 << endmsg;
71  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: general dir " << (hpos2 - hpos1).unit()
72  << " calculated : " << Amg::Vector3D(std::cos(Alpha0), std::sin(Alpha0), 0.) << endmsg;
73  }
74 
75  // Case of 0 drift distances, only 1 line
76  if (r1 == 0. && r2 == 0.) {
77  Amg::Vector3D pos = hpos1;
78  Amg::Vector3D dir(std::cos(Alpha0), std::sin(Alpha0), 0);
79  if (m_printLevel >= 1) {
80  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
81  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: line pos " << pos << " dir " << dir << endmsg;
82  }
83  list_of_lines.push_back(std::make_pair(pos, dir));
84  return list_of_lines;
85  }
86 
87  // Here are the first 2 "inner" lines ....
88  double RSum = r1 + r2;
89  double Alpha1 = std::asin(RSum / DistanceOfCenters);
90 
91  double line_phi = Alpha0 + Alpha1;
92 
93  Amg::Vector3D pos1(x1 + r1 * std::sin(line_phi), y1 - r1 * std::cos(line_phi), 0.);
94  Amg::Vector3D dir1(std::cos(line_phi), std::sin(line_phi), 0.);
95 
96  if (m_printLevel >= 1) {
97  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
98  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: line pos " << pos1 << " dir " << dir1 << endmsg;
99  }
100 
101  list_of_lines.push_back(std::make_pair(pos1, dir1));
102 
103  line_phi = Alpha0 - Alpha1;
104 
105  Amg::Vector3D pos2(x1 - r1 * std::sin(line_phi), y1 + r1 * std::cos(line_phi), 0.);
106  Amg::Vector3D dir2(std::cos(line_phi), std::sin(line_phi), 0.);
107 
108  if (m_printLevel >= 1) {
109  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
110  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: line pos " << pos2 << " dir " << dir2 << endmsg;
111  }
112 
113  list_of_lines.push_back(std::make_pair(pos2, dir2));
114 
115  // Case where one of the drifts is 0 ==> Only two lines
116  if (r1 == 0. || r2 == 0.) return list_of_lines;
117 
118  // ... and here are the other 2 "outer" lines
119  double DeltaR = std::abs(r2 - r1);
120  double Alpha2 = std::asin(DeltaR / DistanceOfCenters);
121 
122  if (r1 < r2) {
123  if (m_printLevel >= 1) {
124  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
125  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: r1 < r2" << endmsg;
126  }
127 
128  line_phi = Alpha0 + Alpha2;
129 
130  Amg::Vector3D pos3(x1 - r1 * std::sin(line_phi), y1 + r1 * std::cos(line_phi), 0.);
131  Amg::Vector3D dir3(std::cos(line_phi), std::sin(line_phi), 0.);
132 
133  if (m_printLevel >= 1) {
134  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
135  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: line pos " << pos3 << " dir " << dir3 << endmsg;
136  }
137 
138  list_of_lines.push_back(std::make_pair(pos3, dir3));
139 
140  line_phi = Alpha0 - Alpha2;
141 
142  Amg::Vector3D pos4(x1 + r1 * std::sin(line_phi), y1 - r1 * std::cos(line_phi), 0.);
143  Amg::Vector3D dir4(std::cos(line_phi), std::sin(line_phi), 0.);
144 
145  if (m_printLevel >= 1) {
146  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
147  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: line pos " << pos4 << " dir " << dir4 << endmsg;
148  }
149 
150  list_of_lines.push_back(std::make_pair(pos4, dir4));
151 
152  } else {
153  if (m_printLevel >= 1) {
154  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
155  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: r1 > r2" << endmsg;
156  }
157 
158  line_phi = Alpha0 + Alpha2;
159 
160  Amg::Vector3D pos3(x1 + r1 * std::sin(line_phi), y1 - r1 * std::cos(line_phi), 0.);
161  Amg::Vector3D dir3(std::cos(line_phi), std::sin(line_phi), 0.);
162 
163  if (m_printLevel >= 1) {
164  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
165  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: line pos " << pos3 << " dir " << dir3 << endmsg;
166  }
167 
168  list_of_lines.push_back(std::make_pair(pos3, dir3));
169 
170  line_phi = Alpha0 - Alpha2;
171 
172  Amg::Vector3D pos4(x1 - r1 * std::sin(line_phi), y1 + r1 * std::cos(line_phi), 0.);
173  Amg::Vector3D dir4(std::cos(line_phi), std::sin(line_phi), 0.);
174 
175  if (m_printLevel >= 1) {
176  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
177  log << MSG::VERBOSE << "LocalSegmentResolver::getLines: line pos " << pos4 << " dir " << dir4 << endmsg;
178  }
179 
180  list_of_lines.push_back(std::make_pair(pos4, dir4));
181  }
182 
183  return list_of_lines;
184  }
185 
187  // loop over tangent lines
188  LineVec::const_iterator lit = localTracks.begin();
189  LineVec::const_iterator lit_end = localTracks.end();
190 
191  // look for line with smallest residual sum
192  double ressummin = 1e20;
193  unsigned int resnum = 0;
194 
195  for (; lit != lit_end; ++lit) {
196  double ressum = 0;
197 
198  // calculate angle between line and z precision plane
199  double alpha = std::atan2(lit->second.y(), lit->second.x());
200 
201  // get rotations in track frame
202  Amg::AngleAxis3D rotationAroundZ(-alpha, Amg::Vector3D::UnitZ());
203  // Amg::AngleAxis3D rotationAroundZ_inv(alpha,Amg::Vector3D::UnitZ());
204 
205  // rotate position on track into track frame
206  Amg::Vector3D avePosTrk = rotationAroundZ * lit->first;
207 
208  if (m_printLevel >= 1) {
209  Amg::Vector3D lTrkDir = rotationAroundZ * lit->second;
210  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
211  log << MSG::VERBOSE << " angle " << alpha * 57.32 << " trk dir in trk frame " << lTrkDir << " pos " << avePosTrk
212  << endmsg;
213  }
214  // loop over local hits
215  LocalSegmentResolver::HitVec::const_iterator it = hits.begin();
216  LocalSegmentResolver::HitVec::const_iterator it_end = hits.end();
217  for (; it != it_end; ++it) {
218  // rotate into track system
219  Amg::Vector3D spos = MuonCalib::LocalToPrecision::precision((*it)->localPosition());
220  Amg::Vector3D sposAve = rotationAroundZ * spos - avePosTrk;
221 
222  // get drift radius (unsigned)
223  double r = std::abs((*it)->driftRadius());
224 
225  // calculate residual and pull
226  double res = r - std::abs(sposAve.y());
227 
228  if (m_printLevel >= 1) {
229  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
230  log << MSG::VERBOSE << " r " << r << " r_trk " << std::abs(sposAve.y()) << " residual " << res << endmsg;
231  }
232 
233  ressum += res * res;
234  }
235 
236  if (m_printLevel >= 3) {
237  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
238  log << MSG::INFO << " line " << lit - localTracks.begin() << " residual sum " << ressum << endmsg;
239  }
240  if (ressum < ressummin) {
241  ressummin = ressum;
242  resnum = lit - localTracks.begin();
243  }
244  }
245 
246  if (m_printLevel >= 3) {
247  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
248  log << MSG::INFO << " Done selected line: ressum " << ressummin << " ## " << resnum << endmsg;
249  log << MSG::INFO << " Position " << localTracks[resnum].first << " direction " << localTracks[resnum].second << endmsg;
250  }
251  if (resnum >= localTracks.size()) {
252  MsgStream log(Athena::getMessageSvc(), "LocalSegmentResolver");
253  log << MSG::WARNING << "wrong line index" << endmsg;
254  return -1;
255  }
256 
257  return resnum;
258  }
259 
260 } // namespace MuonCalib
beamspotman.r
def r
Definition: beamspotman.py:676
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonCalib::LocalSegmentResolver::getLines
LineVec getLines(const MdtCalibHitBase &firstHit, const MdtCalibHitBase &lastHit) const
Definition: LocalSegmentResolver.cxx:50
met::DeltaR
@ DeltaR
Definition: METRecoCommon.h:11
MuonCalib::LocalToPrecision::local
static Amg::Vector3D local(const Amg::Vector3D &p)
Definition: LocalToPrecision.h:16
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
skel.it
it
Definition: skel.GENtoEVGEN.py:396
MuonCalib::MuonCalibSegment
Definition: MuonCalibSegment.h:39
LocalToPrecision.h
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
MuonCalib::LocalToPrecision::precision
static Amg::Vector3D precision(const Amg::Vector3D &p)
Definition: LocalToPrecision.h:15
MuonCalib::LocalSegmentResolver::LineVec
std::vector< Line > LineVec
Definition: LocalSegmentResolver.h:46
CaloCondBlobAlgs_fillNoiseFromASCII.lines
lines
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:104
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
LocalSegmentResolver.h
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
MuonCalib::LocalSegmentResolver::m_printLevel
int m_printLevel
print level
Definition: LocalSegmentResolver.h:54
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::MdtCalibHitBase::localPosition
const Amg::Vector3D & localPosition() const
retrieve the position expressed in local (station) coordinates
Definition: MdtCalibHitBase.cxx:68
beamspotman.dir
string dir
Definition: beamspotman.py:623
MuonCalib::MuonCalibSegment::mdtHitsOnTrack
unsigned int mdtHitsOnTrack() const
retrieve the number of MdtCalibHitBase s assigned to this segment
Definition: MuonCalibSegment.cxx:146
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
MuonCalib::LocalSegmentResolver::bestLine
int bestLine(const HitVec &hits, const LineVec &localTracks) const
Definition: LocalSegmentResolver.cxx:186
MuonCalib::MuonCalibSegment::set
void set(double chi2, const Amg::Vector3D &pos, const Amg::Vector3D &dir)
Definition: MuonCalibSegment.cxx:128
MuonCalib::MdtCalibHitBase
Definition: MdtCalibHitBase.h:38
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:21
MuonCalib::LocalSegmentResolver::LocalSegmentResolver
LocalSegmentResolver()
constructor
Definition: LocalSegmentResolver.cxx:16
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::LocalSegmentResolver::resolve
bool resolve(MuonCalibSegment *seg) const
resolve local position and direction of the track segment
Definition: LocalSegmentResolver.cxx:18
Amg::AngleAxis3D
Eigen::AngleAxisd AngleAxis3D
Definition: GeoPrimitives.h:45
MuonCalib::MuonCalibSegment::chi2
double chi2() const
retrieve chi2
Definition: MuonCalibSegment.cxx:182
MuonCalib::MuonCalibSegment::mdtHOT
const MdtHitVec & mdtHOT() const
retrieve the full set of MdtCalibHitBase s assigned to this segment
Definition: MuonCalibSegment.cxx:147
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
MuonCalib::LocalSegmentResolver::HitVec
MuonCalibSegment::MdtHitVec HitVec
Definition: LocalSegmentResolver.h:44
MdtCalibHitBase.h
MuonCalib::MdtCalibHitBase::driftRadius
float driftRadius() const
retrieve the radius of the drift circle
Definition: MdtCalibHitBase.cxx:74