ATLAS Offline Software
MMT_Road.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 MMT_Road::MMT_Road(const char sector, const int roadSize,
8  const int UpX, const int DownX, const int UpUV, const int DownUV,
9  const int xthr, const int uvthr,
10  const int iroadx, const int iroadu, const int iroadv) :
11  m_iroadx(iroadx),
12  m_iroadu(iroadu != -1 ? iroadu : iroadx),
13  m_iroadv(iroadv != -1 ? iroadv : iroadx),
14  m_xthr(xthr),
15  m_uvthr(uvthr),
16  m_sector(sector)
17 {
18  // Pre-calculate slopes
19  m_slopeXlow = roadSize*m_iroadx + 0.5 - DownX;
20  m_slopeXhigh = roadSize*(m_iroadx+1) + 0.5 + UpX;
21 
22  m_slopeUlow = roadSize*m_iroadu + 0.5 - DownUV;
23  m_slopeUhigh = roadSize*(m_iroadu+1) + 0.5 + UpUV;
24 
25  m_slopeVlow = roadSize*m_iroadv + 0.5 - DownUV;
26  m_slopeVhigh = roadSize*(m_iroadv+1) + 0.5 + UpUV;
27 }
28 
29 void MMT_Road::addHits(std::vector<std::shared_ptr<MMT_Hit> > &hits) {
30  for (const auto &hit_i : hits) {
31  if (m_sector != hit_i->getSector()) continue;
32 
33  double slow, shigh;
34  if (hit_i->isX()) {
35  slow = hit_i->getShift() + m_slopeXlow * hit_i->getPitchOverZ();
36  shigh = hit_i->getShift() + m_slopeXhigh * hit_i->getPitchOverZ();
37  }
38  else if (hit_i->isU()) {
39  slow = hit_i->getShift() + m_slopeUlow * hit_i->getPitchOverZ();
40  shigh = hit_i->getShift() + m_slopeUhigh * hit_i->getPitchOverZ();
41  }
42  else if (hit_i->isV()) {
43  slow = hit_i->getShift() + m_slopeVlow * hit_i->getPitchOverZ();
44  shigh = hit_i->getShift() + m_slopeVhigh * hit_i->getPitchOverZ();
45  }
46  else continue;
47 
48  const double val = hit_i->getRZSlope();
49  bool has_hit = (val > 0.) ? (val > slow && val < shigh) : (val > shigh && val < slow);
50 
51  if (!has_hit) continue;
52 
53  has_hit = false;
54  const int bo = hit_i->getPlane();
55  auto it = std::find_if(m_road_hits.begin(), m_road_hits.end(), [&bo](const auto &hit) { return (hit.getPlane() == bo); });
56  if (it != m_road_hits.end()) {
57  has_hit = true;
58  if (!hit_i->isNoise() && it->isNoise()) {
59  m_road_hits.erase(it);
60  has_hit = false;
61  }
62  }
63 
64  if (has_hit) continue;
65  m_road_hits.emplace_back(*hit_i.get());
66  m_road_hits.back().setAge(0);
67  }
68 }
69 
70 double MMT_Road::avgSofX() const {
71  double sum = 0;
72  int N = 0;
73  for (const auto &hit : m_road_hits) {
74  if (hit.isX()) {
75  sum += hit.getRZSlope();
76  ++N;
77  }
78  }
79  return sum/N;
80 }
81 
82 double MMT_Road::avgSofUV(const int uv1, const int uv2) const {
83  double sum = 0;
84  int N = 0;
85  for (const auto &hit : m_road_hits) {
86  const int bo = hit.getPlane();
87  if (bo == uv1 || bo == uv2) {
88  sum += hit.getRZSlope();
89  ++N;
90  }
91  }
92  return sum/N;
93 }
94 
95 unsigned int MMT_Road::countRealHits() const {
96  return std::count_if(m_road_hits.begin(), m_road_hits.end(),
97  [&](auto& hit) { return hit.isNoise()==false; });
98 }
99 
100 unsigned int MMT_Road::countUVHits(bool flag) const {
101  return std::count_if(m_road_hits.begin(), m_road_hits.end(),
102  [&](auto& hit) { return (hit.isU() || hit.isV()) && hit.isNoise()==flag; });
103 }
104 
105 unsigned int MMT_Road::countXHits(bool flag) const {
106  return std::count_if(m_road_hits.begin(), m_road_hits.end(),
107  [&](auto& hit) { return hit.isX() && hit.isNoise()==flag; });
108 }
109 
111  unsigned int nhits1 = 0, nhits2 = 0;
112  for (const auto &hit : m_road_hits) {
113  nhits1 += hit.getPlane() < 4 && !hit.isNoise();
114  nhits2 += hit.getPlane() > 3 && !hit.isNoise();
115  }
116  return (nhits1 < 4 || nhits2 < 4);
117 }
118 
120  int nx1 = 0, nx2 = 0;
121  for (const auto &hit : m_road_hits) {
122  nx1 += hit.getPlane() >-1 && hit.getPlane() < 2;
123  nx2 += hit.getPlane() > 5 && hit.getPlane() < 8;
124 
125  if (nx1 > 0 && nx2 > 0 && (nx1+nx2) >= m_xthr) return true;
126  }
127  return false;
128 }
129 
130 void MMT_Road::incrementAge(const int bcwind) {
131  std::vector<unsigned int> old_ihits;
132  for (unsigned int j = 0; j < m_road_hits.size(); j++) {
133  m_road_hits[j].setAge(m_road_hits[j].getAge() +1);
134  if (m_road_hits[j].getAge() > (bcwind-1)) old_ihits.push_back(j);
135  }
136  for (int j = old_ihits.size()-1; j > -1; j--) m_road_hits.erase(m_road_hits.begin()+j);
137 }
138 
139 bool MMT_Road::matureCheck(const int bcwind) const {
140  for (const auto &hit : m_road_hits) {
141  if (hit.getAge() == (bcwind - 1)) return true;
142  }
143  return false;
144 }
145 
146 double MMT_Road::mxl() const {
147  std::vector<double> ys, zs;
148  for (const auto &hit : m_road_hits) {
149  if (hit.isX()) {
150  ys.push_back(hit.getR());
151  zs.push_back(hit.getZ());
152  }
153  }
154  double mxl = 0;
155  double avg_z = std::accumulate(zs.begin(), zs.end(), 0.0)/(double)zs.size();
156  double sum_sq_z = std::inner_product(zs.begin(), zs.end(), zs.begin(), 0.0);
157  for (unsigned int i = 0; i < ys.size(); i++) mxl += ys[i]*( (zs[i]-avg_z) / (sum_sq_z - zs.size()*std::pow(avg_z,2)) );
158 
159  return mxl;
160 }
161 
163  m_road_hits.clear();
164 }
165 
166 bool MMT_Road::stereoCheck() const {
167 
168  if (m_uvthr == 0) return true;
169 
170  int nu = 0, nv = 0;
171  for (const auto &hit : m_road_hits) {
172  nu += hit.isU();
173  nv += hit.isV();
174 
175  if (nu > 0 && nv > 0 && (nu+nv) >= m_uvthr) return true;
176  }
177  return false;
178 }
MMT_Road::stereoCheck
bool stereoCheck() const
Definition: MMT_Road.cxx:166
MMT_Road::MMT_Road
MMT_Road(const char sector, const int roadSize, const int UpX, const int DownX, const int UpUV, const int DownUV, const int xthr, const int uvthr, const int iroadx, const int iroadu=-1, const int iroadv=-1)
Definition: MMT_Road.cxx:7
MMT_Road::mxl
double mxl() const
Definition: MMT_Road.cxx:146
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
MMT_Road::avgSofX
double avgSofX() const
Definition: MMT_Road.cxx:70
MMT_Road::m_sector
char m_sector
Definition: MMT_Road.h:48
MMT_Road::countXHits
unsigned int countXHits(bool flag) const
Definition: MMT_Road.cxx:105
MMT_Road::evaluateLowRes
bool evaluateLowRes() const
Definition: MMT_Road.cxx:110
MMT_Road::m_uvthr
int m_uvthr
Definition: MMT_Road.h:47
skel.it
it
Definition: skel.GENtoEVGEN.py:407
MMT_Road::m_iroadx
int m_iroadx
Definition: MMT_Road.h:46
MMT_Road::m_slopeUhigh
double m_slopeUhigh
Definition: MMT_Road.h:45
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
MMT_Road::reset
void reset()
Definition: MMT_Road.cxx:162
MMT_Road::matureCheck
bool matureCheck(const int bcwind) const
Definition: MMT_Road.cxx:139
MMT_Road::m_slopeVlow
double m_slopeVlow
Definition: MMT_Road.h:45
MMT_Road::countRealHits
unsigned int countRealHits() const
Definition: MMT_Road.cxx:95
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
lumiFormat.i
int i
Definition: lumiFormat.py:85
MMT_Road::countUVHits
unsigned int countUVHits(bool flag) const
Definition: MMT_Road.cxx:100
master.flag
bool flag
Definition: master.py:29
MMT_Road.h
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
MMT_Road::m_slopeXhigh
double m_slopeXhigh
Definition: MMT_Road.h:45
MMT_Road::m_xthr
int m_xthr
Definition: MMT_Road.h:47
MMT_Road::m_iroadv
int m_iroadv
Definition: MMT_Road.h:46
MMT_Road::incrementAge
void incrementAge(const int bcwind)
Definition: MMT_Road.cxx:130
MMT_Road::horizontalCheck
bool horizontalCheck() const
Definition: MMT_Road.cxx:119
MMT_Road::avgSofUV
double avgSofUV(const int uv1, const int uv2) const
Definition: MMT_Road.cxx:82
MMT_Road::m_road_hits
std::vector< MMT_Hit > m_road_hits
Definition: MMT_Road.h:44
runIDAlign.accumulate
accumulate
Update flags based on parser line args.
Definition: runIDAlign.py:107
MMT_Road::m_slopeUlow
double m_slopeUlow
Definition: MMT_Road.h:45
MMT_Road::m_slopeVhigh
double m_slopeVhigh
Definition: MMT_Road.h:45
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
MMT_Road::m_iroadu
int m_iroadu
Definition: MMT_Road.h:46
MMT_Road::addHits
void addHits(std::vector< std::shared_ptr< MMT_Hit > > &hits)
Definition: MMT_Road.cxx:29
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
MMT_Road::m_slopeXlow
double m_slopeXlow
Definition: MMT_Road.h:45