ATLAS Offline Software
CurvedSegmentFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #define sq(x) ((x) * (x))
7 
8 namespace TrkDriftCircleMath {
9 
10  void CurvedSegmentFinder::curvedSegments(const ChamberGeometry& mdtGeo, SegVec& segs) const {
11  int nCurved = 0;
12  // collect all the ML1 and ML2 only segments
13  SegVec ml1segs, ml2segs;
14  for (auto & seg : segs) {
15  int isBarrel = seg.dcs()[0].id().isBarrel();
16  if (!isBarrel) continue;
17 
18  if (seg.hitsMl2() == 0) {
19  ml1segs.push_back(seg);
20  } else if (seg.hitsMl1() == 0) {
21  ml2segs.push_back(seg);
22  }
23  }
24  // check that both ML have segments
25  if (ml1segs.empty() || ml2segs.empty()) return;
26  // Chamber information needed to calculate Delta b
27  const LocVec2D& ml1LocVec2D = mdtGeo.tubePosition(0, mdtGeo.nlay(), 0);
28  const LocVec2D& ml2LocVec2D = mdtGeo.tubePosition(1, 1, 0);
29  double chamberMidPtY = (ml1LocVec2D.y() + ml2LocVec2D.y()) / 2.0;
30  // loop over the ML segments and find matches
31  if (m_debugLevel >= 10)
32  std::cout << "CurvedSegmentsFinder begining match with " << ml1segs.size() << " ML1 segments and " << ml2segs.size()
33  << " ML2 segments" << std::endl;
34  for (auto & ml1seg : ml1segs) {
35  // bool foundCurvedSeg = false;
36  const double tanML1 = std::tan(ml1seg.line().phi());
37  const double mid1 = (chamberMidPtY - ml1seg.line().position().y()) / tanML1 + ml1seg.line().position().x();
38  const double y01 = ml1seg.line().position().y() - ml1seg.line().position().x() * tanML1;
39  for (auto & ml2seg : ml2segs) {
40  // angle between the 2 segments
41  const double deltaAlpha = ml1seg.line().phi() - ml2seg.line().phi();
42  // distance of closest approach between the 2 segments at the middle of chamber
43  const double tanML2 = std::tan(ml2seg.line().phi());
44 
45  const double mid2 = (chamberMidPtY - ml2seg.line().position().y()) / tanML2 + ml2seg.line().position().x();
46  const double y02 = ml2seg.line().position().y() - ml2seg.line().position().x() * tanML2;
47  double deltab = (mid2 * tanML1 - chamberMidPtY + y01) / std::hypot(1, tanML1);
48  const double deltab2 = (mid1 * tanML2 - chamberMidPtY + y02) / std::hypot(1, tanML2);
49  if (std::abs(deltab2) < std::abs(deltab)) deltab = deltab2;
50  if (std::abs(deltaAlpha) >= m_maxDeltaAlpha || std::abs(deltab) >= m_maxDeltab) continue;
51  ++nCurved;
52 
53  // foundCurvedSeg = true;
54  if (m_debugLevel >= 10)
55  std::cout << "CurvedSegment combination found with parameters (DeltaAlpha,Deltab) = (" << deltaAlpha << ", "
56  << deltab << ")" << std::endl;
57  // build the curved segment
58  DCOnTrackVec dcs = ml1seg.dcs();
59  dcs.insert(dcs.end(), ml2seg.dcs().begin(), ml2seg.dcs().end());
60  double segChi2 = ml1seg.chi2() + ml2seg.chi2();
61  double segNDoF = ml1seg.ndof() + ml2seg.ndof();
62  Segment seg(ml1seg.line(), dcs, segChi2, segNDoF, ml1seg.dtheta(), ml1seg.dy0());
63  // find the x coordinate of at the middle of the chamber for ml2 segment
64  const double xb = ml2seg.line().position().x() - (ml2seg.line().position().y() - chamberMidPtY) / tan(ml2seg.line().phi());
65  // set the curvature parameters
66  seg.setCurvatureParameters(deltaAlpha, xb);
67  // hit information
68  seg.deltas(ml1seg.deltas() + ml2seg.deltas());
69  seg.hitsOutOfTime(ml1seg.hitsOutOfTime() + ml2seg.hitsOutOfTime());
70  seg.hitsOnTrack(ml1seg.hitsOnTrack() + ml2seg.hitsOnTrack());
71  seg.hitsPerMl(ml1seg.hitsMl1(), ml2seg.hitsMl2());
72  seg.closeHits(ml1seg.closeHits() + ml2seg.closeHits());
73 
74  // store the new segment
75  segs.push_back(seg);
76  // remove the ML2 segment from the list
77  // ml2segs.erase( ml2 );
78  // break;
79  }
80  } // end loop on ml2
81  if (m_debugLevel >= 5) std::cout << "Finished CurvedSegments Finding, and found " << nCurved << " CurvedSegments" << std::endl;
82  }
83 
84 } // end namespace TrkDriftCircleMath
TrkDriftCircleMath::DCOnTrackVec
std::vector< DCOnTrack > DCOnTrackVec
Definition: DCOnTrack.h:59
TrkDriftCircleMath::CurvedSegmentFinder::m_maxDeltab
double m_maxDeltab
Definition: CurvedSegmentFinder.h:35
TrkDriftCircleMath::ChamberGeometry
Definition: ChamberGeometry.h:17
TrkDriftCircleMath::CurvedSegmentFinder::curvedSegments
void curvedSegments(const ChamberGeometry &mdtGeo, SegVec &Segs) const
Definition: CurvedSegmentFinder.cxx:10
TrkDriftCircleMath::CurvedSegmentFinder::m_maxDeltaAlpha
double m_maxDeltaAlpha
Definition: CurvedSegmentFinder.h:34
TrkDriftCircleMath
Function object to check whether two Segments are sub/super sets or different.
Definition: IMdtSegmentFinder.h:13
TrkDriftCircleMath::Segment::hitsOutOfTime
void hitsOutOfTime(unsigned int hitsOutOfTime)
Definition: TrkUtilityPackages/TrkDriftCircleMath/TrkDriftCircleMath/Segment.h:51
TrkDriftCircleMath::Segment::closeHits
void closeHits(unsigned int closeHits)
Definition: TrkUtilityPackages/TrkDriftCircleMath/TrkDriftCircleMath/Segment.h:53
TrkDriftCircleMath::Segment
Definition: TrkUtilityPackages/TrkDriftCircleMath/TrkDriftCircleMath/Segment.h:18
TrkDriftCircleMath::LocVec2D
Implementation of 2 dimensional vector class.
Definition: LocVec2D.h:16
TrkDriftCircleMath::Segment::hitsPerMl
void hitsPerMl(unsigned int hml1, unsigned int hml2)
Definition: TrkUtilityPackages/TrkDriftCircleMath/TrkDriftCircleMath/Segment.h:59
TrkDriftCircleMath::ChamberGeometry::nlay
virtual unsigned int nlay() const =0
TrkDriftCircleMath::LocVec2D::y
double y() const
Returns the y coordinate of the vector.
Definition: LocVec2D.h:29
TrkDriftCircleMath::Segment::hitsOnTrack
void hitsOnTrack(unsigned int hitsOnTrack)
Definition: TrkUtilityPackages/TrkDriftCircleMath/TrkDriftCircleMath/Segment.h:52
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
TrkDriftCircleMath::Segment::setCurvatureParameters
void setCurvatureParameters(double deltaAlpha, double deltab)
Definition: TrkUtilityPackages/TrkDriftCircleMath/TrkDriftCircleMath/Segment.h:72
DataModelTestDataCommonDict::xb
DMTest::CView::Pers_t xb
Definition: DataModelTestDataCommonDict.h:44
TrkDriftCircleMath::ChamberGeometry::tubePosition
virtual LocVec2D tubePosition(unsigned int ml, unsigned int lay, unsigned int tube) const =0
python.LArCondContChannels.isBarrel
isBarrel
Definition: LArCondContChannels.py:659
TrkDriftCircleMath::CurvedSegmentFinder::m_debugLevel
int m_debugLevel
Definition: CurvedSegmentFinder.h:33
TrkDriftCircleMath::SegVec
std::vector< Segment > SegVec
Definition: TrkUtilityPackages/TrkDriftCircleMath/TrkDriftCircleMath/Segment.h:122
CurvedSegmentFinder.h
TrkDriftCircleMath::Segment::deltas
void deltas(unsigned int dts)
Definition: TrkUtilityPackages/TrkDriftCircleMath/TrkDriftCircleMath/Segment.h:50