ATLAS Offline Software
MMT_Road.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2023 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  m_road_hits.emplace_back(std::make_unique<MMT_Hit>(hit_i.get()));
67  m_road_hits.back()->setAge(0);
68  }
69 }
70 
71 double MMT_Road::avgSofX() const {
72  std::vector<double> sl;
73  for (const auto &hit : m_road_hits) {
74  int bo = hit->getPlane();
75  if (bo < 2 || bo > 5) sl.push_back(hit->getRZSlope());
76  }
77  double avg_x = std::accumulate(sl.begin(), sl.end(), 0.0)/(double)sl.size();
78  return avg_x;
79 }
80 
81 double MMT_Road::avgSofUV(const int uv1, const int uv2) const {
82  std::vector<double> sl;
83  for (const auto &hit : m_road_hits) {
84  int bo = hit->getPlane();
85  if (bo == uv1 || bo == uv2) sl.push_back(hit->getRZSlope());
86  }
87  double avg_uv = std::accumulate(sl.begin(), sl.end(), 0.0)/(double)sl.size();
88  return avg_uv;
89 }
90 
91 double MMT_Road::avgZofUV(const int uv1, const int uv2) const {
92  std::vector<double> zs;
93  for (const auto &hit : m_road_hits) {
94  int bo = hit->getPlane();
95  if (bo == uv1 || bo == uv2) zs.push_back(hit->getZ());
96  }
97  double avg_z = std::accumulate(zs.begin(), zs.end(), 0.0)/(double)zs.size();
98  return avg_z;
99 }
100 
101 bool MMT_Road::checkCoincidences(const int bcwind) const {
102  bool passHorizontalCheck = this->horizontalCheck();
103  if (!passHorizontalCheck) return false;
104  bool passStereoCheck = this->stereoCheck();
105  if (!passStereoCheck) return false;
106  bool passMatureCheck = this->matureCheck(bcwind);
107  return (passHorizontalCheck && passStereoCheck && passMatureCheck);
108 }
109 
110 unsigned int MMT_Road::countRealHits() const {
111  int nreal = 0;
112  for (const auto &hit : m_road_hits) {
113  if (hit->isNoise() == false) nreal++;
114  }
115  return nreal;
116 }
117 
118 unsigned int MMT_Road::countUVHits(bool flag) const {
119  unsigned int nuv = 0;
120  for (const auto &hit : m_road_hits) {
121  if (hit->getPlane() == 2 || hit->getPlane() == 4) {
122  if (hit->isNoise() == flag) nuv++;
123  }
124  if (hit->getPlane() == 3 || hit->getPlane() == 5) {
125  if (hit->isNoise() == flag) nuv++;
126  }
127  }
128  return nuv;
129 }
130 
131 unsigned int MMT_Road::countXHits(bool flag) const {
132  unsigned int nx = 0;
133  for (const auto &hit : m_road_hits) {
134  if (hit->getPlane() < 2 || hit->getPlane() > 5) {
135  if (hit->isNoise() == flag) nx++;
136  }
137  }
138  return nx;
139 }
140 
142  unsigned int nhits1 = 0, nhits2 = 0;
143  for (const auto &hit : m_road_hits) {
144  if (hit->getPlane() < 4 && !hit->isNoise()) nhits1++;
145  else if (hit->getPlane() > 3 && !hit->isNoise()) nhits2++;
146  }
147  return (nhits1 < 4 || nhits2 < 4);
148 }
149 
151  int nx1 = 0, nx2 = 0;
152  for (const auto &hit : m_road_hits) {
153  if (hit->getPlane() >-1 && hit->getPlane() < 2) nx1++;
154  if (hit->getPlane() > 5 && hit->getPlane() < 8) nx2++;
155  }
156  return (nx1 > 0 && nx2 > 0 && (nx1+nx2) >= m_xthr);
157 }
158 
159 void MMT_Road::incrementAge(const int bcwind) {
160  std::vector<unsigned int> old_ihits;
161  for (unsigned int j = 0; j < m_road_hits.size(); j++) {
162  m_road_hits[j]->setAge(m_road_hits[j]->getAge() +1);
163  if (m_road_hits[j]->getAge() > (bcwind-1)) old_ihits.push_back(j);
164  }
165  for (int j = old_ihits.size()-1; j > -1; j--) m_road_hits.erase(m_road_hits.begin()+j);
166 }
167 
168 bool MMT_Road::matureCheck(const int bcwind) const {
169  for (const auto &hit : m_road_hits) {
170  if (hit->getAge() == (bcwind - 1)) return true;
171  }
172  return false;
173 }
174 
175 double MMT_Road::mxl() const {
176  std::vector<double> ys, zs;
177  for (const auto &hit : m_road_hits) {
178  int bo = hit->getPlane();
179  if (bo < 2 || bo > 5) {
180  ys.push_back(hit->getR());
181  zs.push_back(hit->getZ());
182  }
183  }
184  double mxl = 0;
185  double avg_z = std::accumulate(zs.begin(), zs.end(), 0.0)/(double)zs.size();
186  double sum_sq_z = std::inner_product(zs.begin(), zs.end(), zs.begin(), 0.0);
187  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)) );
188 
189  return mxl;
190 }
191 
193  if (!m_road_hits.empty()) m_road_hits.clear();
194 }
195 
196 bool MMT_Road::stereoCheck() const {
197 
198  if (this->getUVthreshold() == 0) return true;
199 
200  int nu = 0, nv = 0;
201  for (const auto &hit : m_road_hits) {
202  if (hit->getPlane() == 2 || hit->getPlane() == 4) nu++;
203  if (hit->getPlane() == 3 || hit->getPlane() == 5) nv++;
204  }
205 
206  return (nu > 0 && nv > 0 && (nu+nv) >= m_uvthr);
207 }
MMT_Road::stereoCheck
bool stereoCheck() const
Definition: MMT_Road.cxx:196
MMT_Road::avgZofUV
double avgZofUV(const int uv1, const int uv2) const
Definition: MMT_Road.cxx:91
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:175
MMT_Road::m_road_hits
std::vector< std::unique_ptr< MMT_Hit > > m_road_hits
Definition: MMT_Road.h:54
MMT_Road::avgSofX
double avgSofX() const
Definition: MMT_Road.cxx:71
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:131
MMT_Road::evaluateLowRes
bool evaluateLowRes() const
Definition: MMT_Road.cxx:141
MMT_Road::m_roadSize
int m_roadSize
Definition: MMT_Road.h:53
MMT_Road::m_uvthr
int m_uvthr
Definition: MMT_Road.h:52
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
skel.it
it
Definition: skel.GENtoEVGEN.py:423
MMT_Road::m_iroadx
int m_iroadx
Definition: MMT_Road.h:48
MMT_Road::reset
void reset()
Definition: MMT_Road.cxx:192
MMT_Road::matureCheck
bool matureCheck(const int bcwind) const
Definition: MMT_Road.cxx:168
MMT_Road::m_roadSizeUpX
int m_roadSizeUpX
Definition: MMT_Road.h:53
MMT_Road::countRealHits
unsigned int countRealHits() const
Definition: MMT_Road.cxx:110
lumiFormat.i
int i
Definition: lumiFormat.py:92
MMT_Road::countUVHits
unsigned int countUVHits(bool flag) const
Definition: MMT_Road.cxx:118
LArG4ShowerLibProcessing.hits
hits
Definition: LArG4ShowerLibProcessing.py:136
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:159
MMT_Road::horizontalCheck
bool horizontalCheck() const
Definition: MMT_Road.cxx:150
MMT_Road::avgSofUV
double avgSofUV(const int uv1, const int uv2) const
Definition: MMT_Road.cxx:81
MMT_Road::checkCoincidences
bool checkCoincidences(const int bcwind) const
Definition: MMT_Road.cxx:101
MMT_Road::m_roadSizeDownX
int m_roadSizeDownX
Definition: MMT_Road.h:53
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