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, const int UpX, const int DownX, const int UpUV, const int DownUV, const int xthr, const int uvthr,
8  const int iroadx, const int iroadu, const int iroadv) {
9  m_sector = sector;
10  m_iroadx = iroadx;
11  m_iroadu = (iroadu != -1) ? iroadu : iroadx;
12  m_iroadv = (iroadv != -1) ? iroadv : iroadx;
13  m_xthr = xthr;
14  m_uvthr = uvthr;
15 
16  m_roadSize = roadSize;
17  m_roadSizeUpX = UpX;
18  m_roadSizeDownX = DownX;
19  m_roadSizeUpUV = UpUV;
20  m_roadSizeDownUV = DownUV;
21 }
22 
23 void MMT_Road::addHits(std::vector<std::shared_ptr<MMT_Hit> > &hits) {
24  for (const auto &hit_i : hits) {
25  if (m_sector != hit_i->getSector()) continue;
26 
27  int iroad = 0;
28  unsigned short int olow = 0, ohigh = 0;
29  if (hit_i->isX()) {
30  iroad = m_iroadx;
31  olow = m_roadSizeDownX;
32  ohigh = m_roadSizeUpX;
33  }
34  else if (hit_i->isU()) {
35  iroad = m_iroadu;
36  olow = m_roadSizeDownUV;
37  ohigh = m_roadSizeUpUV;
38  }
39  else if (hit_i->isV()) {
40  iroad = m_iroadv;
41  olow = m_roadSizeDownUV;
42  ohigh = m_roadSizeUpUV;
43  }
44  else continue;
45 
46  double val = hit_i->getShift();
47  double slow = val + (m_roadSize*iroad + 0.5 - olow )*hit_i->getPitchOverZ();
48  double shigh = val + (m_roadSize*(iroad+1) + 0.5 + ohigh)*hit_i->getPitchOverZ();
49 
50  val = hit_i->getRZSlope();
51  bool has_hit = (val > 0.) ? (val > slow && val < shigh) : (val > shigh && val < slow);
52  if (!has_hit) continue;
53 
54  has_hit = false;
55  unsigned short int bo = hit_i->getPlane();
56  auto it = std::find_if(m_road_hits.begin(), m_road_hits.end(), [&bo](const auto &hit) { return (hit->getPlane() == bo); });
57  if (it != m_road_hits.end()) {
58  has_hit = true;
59  if (!hit_i->isNoise() && (*it)->isNoise()) {
60  m_road_hits.erase(it);
61  has_hit = false;
62  }
63  }
64 
65  if (has_hit) continue;
66  auto hit = std::make_unique<MMT_Hit>(*hit_i.get());
67  hit->setAge(0);
68  m_road_hits.push_back(std::move(hit));
69  }
70 }
71 
72 double MMT_Road::avgSofX() const {
73  std::vector<double> sl;
74  for (const auto &hit : m_road_hits) {
75  int bo = hit->getPlane();
76  if (bo < 2 || bo > 5) sl.push_back(hit->getRZSlope());
77  }
78  double avg_x = std::accumulate(sl.begin(), sl.end(), 0.0)/(double)sl.size();
79  return avg_x;
80 }
81 
82 double MMT_Road::avgSofUV(const int uv1, const int uv2) const {
83  std::vector<double> sl;
84  for (const auto &hit : m_road_hits) {
85  int bo = hit->getPlane();
86  if (bo == uv1 || bo == uv2) sl.push_back(hit->getRZSlope());
87  }
88  double avg_uv = std::accumulate(sl.begin(), sl.end(), 0.0)/(double)sl.size();
89  return avg_uv;
90 }
91 
92 double MMT_Road::avgZofUV(const int uv1, const int uv2) const {
93  std::vector<double> zs;
94  for (const auto &hit : m_road_hits) {
95  int bo = hit->getPlane();
96  if (bo == uv1 || bo == uv2) zs.push_back(hit->getZ());
97  }
98  double avg_z = std::accumulate(zs.begin(), zs.end(), 0.0)/(double)zs.size();
99  return avg_z;
100 }
101 
102 bool MMT_Road::checkCoincidences(const int bcwind) const {
103  bool passHorizontalCheck = this->horizontalCheck();
104  if (!passHorizontalCheck) return false;
105  bool passStereoCheck = this->stereoCheck();
106  if (!passStereoCheck) return false;
107  bool passMatureCheck = this->matureCheck(bcwind);
108  return (passHorizontalCheck && passStereoCheck && passMatureCheck);
109 }
110 
111 unsigned int MMT_Road::countRealHits() const {
112  int nreal = 0;
113  for (const auto &hit : m_road_hits) {
114  if (hit->isNoise() == false) nreal++;
115  }
116  return nreal;
117 }
118 
119 unsigned int MMT_Road::countUVHits(bool flag) const {
120  unsigned int nuv = 0;
121  for (const auto &hit : m_road_hits) {
122  if (hit->getPlane() == 2 || hit->getPlane() == 4) {
123  if (hit->isNoise() == flag) nuv++;
124  }
125  if (hit->getPlane() == 3 || hit->getPlane() == 5) {
126  if (hit->isNoise() == flag) nuv++;
127  }
128  }
129  return nuv;
130 }
131 
132 unsigned int MMT_Road::countXHits(bool flag) const {
133  unsigned int nx = 0;
134  for (const auto &hit : m_road_hits) {
135  if (hit->getPlane() < 2 || hit->getPlane() > 5) {
136  if (hit->isNoise() == flag) nx++;
137  }
138  }
139  return nx;
140 }
141 
143  unsigned int nhits1 = 0, nhits2 = 0;
144  for (const auto &hit : m_road_hits) {
145  if (hit->getPlane() < 4 && !hit->isNoise()) nhits1++;
146  else if (hit->getPlane() > 3 && !hit->isNoise()) nhits2++;
147  }
148  return (nhits1 < 4 || nhits2 < 4);
149 }
150 
152  int nx1 = 0, nx2 = 0;
153  for (const auto &hit : m_road_hits) {
154  if (hit->getPlane() >-1 && hit->getPlane() < 2) nx1++;
155  if (hit->getPlane() > 5 && hit->getPlane() < 8) nx2++;
156  }
157  return (nx1 > 0 && nx2 > 0 && (nx1+nx2) >= m_xthr);
158 }
159 
160 void MMT_Road::incrementAge(const int bcwind) {
161  std::vector<unsigned int> old_ihits;
162  for (unsigned int j = 0; j < m_road_hits.size(); j++) {
163  m_road_hits[j]->setAge(m_road_hits[j]->getAge() +1);
164  if (m_road_hits[j]->getAge() > (bcwind-1)) old_ihits.push_back(j);
165  }
166  for (int j = old_ihits.size()-1; j > -1; j--) m_road_hits.erase(m_road_hits.begin()+j);
167 }
168 
169 bool MMT_Road::matureCheck(const int bcwind) const {
170  for (const auto &hit : m_road_hits) {
171  if (hit->getAge() == (bcwind - 1)) return true;
172  }
173  return false;
174 }
175 
176 double MMT_Road::mxl() const {
177  std::vector<double> ys, zs;
178  for (const auto &hit : m_road_hits) {
179  int bo = hit->getPlane();
180  if (bo < 2 || bo > 5) {
181  ys.push_back(hit->getR());
182  zs.push_back(hit->getZ());
183  }
184  }
185  double mxl = 0;
186  double avg_z = std::accumulate(zs.begin(), zs.end(), 0.0)/(double)zs.size();
187  double sum_sq_z = std::inner_product(zs.begin(), zs.end(), zs.begin(), 0.0);
188  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)) );
189 
190  return mxl;
191 }
192 
194  if (!m_road_hits.empty()) m_road_hits.clear();
195 }
196 
197 bool MMT_Road::stereoCheck() const {
198 
199  if (this->getUVthreshold() == 0) return true;
200 
201  int nu = 0, nv = 0;
202  for (const auto &hit : m_road_hits) {
203  if (hit->getPlane() == 2 || hit->getPlane() == 4) nu++;
204  if (hit->getPlane() == 3 || hit->getPlane() == 5) nv++;
205  }
206 
207  return (nu > 0 && nv > 0 && (nu+nv) >= m_uvthr);
208 }
MMT_Road::stereoCheck
bool stereoCheck() const
Definition: MMT_Road.cxx:197
MMT_Road::avgZofUV
double avgZofUV(const int uv1, const int uv2) const
Definition: MMT_Road.cxx:92
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:176
MMT_Road::m_road_hits
std::vector< std::unique_ptr< MMT_Hit > > m_road_hits
Definition: MMT_Road.h:54
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
MMT_Road::avgSofX
double avgSofX() const
Definition: MMT_Road.cxx:72
MMT_Road::m_sector
char m_sector
Definition: MMT_Road.h:51
MMT_Road::countXHits
unsigned int countXHits(bool flag) const
Definition: MMT_Road.cxx:132
MMT_Road::evaluateLowRes
bool evaluateLowRes() const
Definition: MMT_Road.cxx:142
MMT_Road::m_roadSize
int m_roadSize
Definition: MMT_Road.h:53
MMT_Road::m_uvthr
int m_uvthr
Definition: MMT_Road.h:52
skel.it
it
Definition: skel.GENtoEVGEN.py:407
MMT_Road::m_iroadx
int m_iroadx
Definition: MMT_Road.h:48
MMT_Road::reset
void reset()
Definition: MMT_Road.cxx:193
MMT_Road::matureCheck
bool matureCheck(const int bcwind) const
Definition: MMT_Road.cxx:169
MMT_Road::m_roadSizeUpX
int m_roadSizeUpX
Definition: MMT_Road.h:53
MMT_Road::countRealHits
unsigned int countRealHits() const
Definition: MMT_Road.cxx:111
lumiFormat.i
int i
Definition: lumiFormat.py:85
MMT_Road::countUVHits
unsigned int countUVHits(bool flag) const
Definition: MMT_Road.cxx:119
master.flag
bool flag
Definition: master.py:29
MMT_Road.h
MMT_Road::m_roadSizeDownUV
int m_roadSizeDownUV
Definition: MMT_Road.h:53
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
MMT_Road::m_xthr
int m_xthr
Definition: MMT_Road.h:52
MMT_Road::m_roadSizeUpUV
int m_roadSizeUpUV
Definition: MMT_Road.h:53
MMT_Road::m_iroadv
int m_iroadv
Definition: MMT_Road.h:50
MMT_Road::incrementAge
void incrementAge(const int bcwind)
Definition: MMT_Road.cxx:160
MMT_Road::horizontalCheck
bool horizontalCheck() const
Definition: MMT_Road.cxx:151
MMT_Road::avgSofUV
double avgSofUV(const int uv1, const int uv2) const
Definition: MMT_Road.cxx:82
MMT_Road::checkCoincidences
bool checkCoincidences(const int bcwind) const
Definition: MMT_Road.cxx:102
MMT_Road::m_roadSizeDownX
int m_roadSizeDownX
Definition: MMT_Road.h:53
runIDAlign.accumulate
accumulate
Update flags based on parser line args.
Definition: runIDAlign.py:107
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
MMT_Road::m_iroadu
int m_iroadu
Definition: MMT_Road.h:49
MMT_Road::getUVthreshold
int getUVthreshold() const
Definition: MMT_Road.h:38
MMT_Road::addHits
void addHits(std::vector< std::shared_ptr< MMT_Hit > > &hits)
Definition: MMT_Road.cxx:23
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15