ATLAS Offline Software
Loading...
Searching...
No Matches
MMT_Road.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
5#include "MMT_Road.h"
6#include <stdexcept>
7
8MMT_Road::MMT_Road(const char sector, const int roadSize,
9 const int UpX, const int DownX, const int UpUV, const int DownUV,
10 const int xthr, const int uvthr,
11 const int iroadx, const int iroadu, const int iroadv) :
12 m_iroadx(iroadx),
13 m_iroadu(iroadu != -1 ? iroadu : iroadx),
14 m_iroadv(iroadv != -1 ? iroadv : iroadx),
15 m_xthr(xthr),
16 m_uvthr(uvthr),
17 m_sector(sector)
18{
19 // Pre-calculate slopes
20 m_slopeXlow = roadSize*m_iroadx + 0.5 - DownX;
21 m_slopeXhigh = roadSize*(m_iroadx+1) + 0.5 + UpX;
22
23 m_slopeUlow = roadSize*m_iroadu + 0.5 - DownUV;
24 m_slopeUhigh = roadSize*(m_iroadu+1) + 0.5 + UpUV;
25
26 m_slopeVlow = roadSize*m_iroadv + 0.5 - DownUV;
27 m_slopeVhigh = roadSize*(m_iroadv+1) + 0.5 + UpUV;
28}
29
30void MMT_Road::addHits(const std::vector<std::shared_ptr<MMT_Hit> > &hits) {
31 for (const auto &hit_i : hits) {
32 double slow, shigh;
33 if (hit_i->isX()) {
34 slow = hit_i->getShift() + m_slopeXlow * hit_i->getPitchOverZ();
35 shigh = hit_i->getShift() + m_slopeXhigh * hit_i->getPitchOverZ();
36 }
37 else if (hit_i->isU()) {
38 slow = hit_i->getShift() + m_slopeUlow * hit_i->getPitchOverZ();
39 shigh = hit_i->getShift() + m_slopeUhigh * hit_i->getPitchOverZ();
40 }
41 else {
42 slow = hit_i->getShift() + m_slopeVlow * hit_i->getPitchOverZ();
43 shigh = hit_i->getShift() + m_slopeVhigh * hit_i->getPitchOverZ();
44 }
45
46 const double val = hit_i->getRZSlope();
47 bool has_hit = (val > 0.) ? (val > slow && val < shigh) : (val > shigh && val < slow);
48 if (!has_hit) continue;
49
50 const int pl = hit_i->getPlane();
51 if (std::ranges::any_of(m_road_hits, [&pl](const auto &hit) { return (hit.getPlane() == pl); })) continue;
52
53 m_road_hits.emplace_back(*hit_i.get());
54 m_road_hits.back().setAge(0);
55 }
56}
57
58double MMT_Road::avgSofXUV(const char type) const {
59 double sum = 0;
60 unsigned short int N = 0;
61 for (const auto &hit : m_road_hits) {
62 if (hit.isX() && type == 'X') {
63 sum += hit.getRZSlope();
64 ++N;
65 }
66 else if (hit.isU() && type == 'U') {
67 sum += hit.getRZSlope();
68 ++N;
69 }
70 else if (hit.isV() && type == 'V') {
71 sum += hit.getRZSlope();
72 ++N;
73 }
74 else continue;
75 }
76 if (N == 0)[[unlikely]]{
77 throw std::runtime_error("MMT_Road::avgSofXUV: N is zero.");
78 }
79 return sum/N;
80}
81
82unsigned int MMT_Road::countUHits() const {
83 return std::count_if(m_road_hits.begin(), m_road_hits.end(),
84 [](const auto& hit) { return hit.isU(); });
85}
86
87unsigned int MMT_Road::countXHits() const {
88 return std::count_if(m_road_hits.begin(), m_road_hits.end(),
89 [](const auto& hit) { return hit.isX(); });
90}
91
93 unsigned short int nhits1 = 0, nhits2 = 0;
94 for (const auto &hit : m_road_hits) {
95 nhits1 += hit.getPlane() < 4;
96 nhits2 += hit.getPlane() > 3;
97 }
98 return (nhits1 < 4 || nhits2 < 4);
99}
100
102 unsigned short int nx1 = 0, nx2 = 0;
103 for (const auto &hit : m_road_hits) {
104 nx1 += hit.getPlane() < 2;
105 nx2 += hit.getPlane() > 5;
106
107 if (nx1 > 0 && nx2 > 0 && (nx1+nx2) >= m_xthr) return true;
108 }
109 return false;
110}
111
112void MMT_Road::incrementAge(const int bcwind) {
113 unsigned short int old_ihits = 0;
114 for (auto &hit : m_road_hits) {
115 hit.setAge(hit.getAge()+1);
116 if (hit.getAge() > (bcwind-1)) ++old_ihits;
117 }
118 m_road_hits.erase(m_road_hits.begin(), m_road_hits.begin()+old_ihits);
119}
120
121bool MMT_Road::matureCheck(const int bcwind) const {
122 for (const auto &hit : m_road_hits) {
123 if (hit.getAge() == (bcwind - 1)) return true;
124 }
125 return false;
126}
127
128double MMT_Road::mxl() const {
129 std::vector<double> ys, zs;
130 for (const auto &hit : m_road_hits) {
131 if (hit.isX()) {
132 ys.push_back(hit.getR());
133 zs.push_back(hit.getZ());
134 }
135 }
136 double mxl = 0;
137 double avg_z = std::accumulate(zs.begin(), zs.end(), 0.0)/(double)zs.size();
138 double sum_sq_z = std::inner_product(zs.begin(), zs.end(), zs.begin(), 0.0);
139 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)) );
140
141 return mxl;
142}
143
145 unsigned short int nu = 0, nv = 0;
146 for (const auto &hit : m_road_hits) {
147 nu += hit.isU();
148 nv += hit.isV();
149
150 if (nu > 0 && nv > 0 && (nu+nv) >= m_uvthr) return true;
151 }
152 return false;
153}
bool hit(const Container &ids, int pdgId)
double avgSofXUV(const char type) const
Definition MMT_Road.cxx:58
double m_slopeUlow
Definition MMT_Road.h:42
double mxl() const
Definition MMT_Road.cxx:128
double m_slopeXhigh
Definition MMT_Road.h:42
int m_xthr
Definition MMT_Road.h:44
void incrementAge(const int bcwind)
Definition MMT_Road.cxx:112
double m_slopeXlow
Definition MMT_Road.h:42
std::vector< MMT_Hit > m_road_hits
Definition MMT_Road.h:41
bool stereoCheck() const
Definition MMT_Road.cxx:144
int m_iroadu
Definition MMT_Road.h:43
int m_iroadv
Definition MMT_Road.h:43
double m_slopeVlow
Definition MMT_Road.h:42
double m_slopeUhigh
Definition MMT_Road.h:42
void addHits(const std::vector< std::shared_ptr< MMT_Hit > > &hits)
Definition MMT_Road.cxx:30
double m_slopeVhigh
Definition MMT_Road.h:42
char m_sector
Definition MMT_Road.h:45
bool evaluateLowRes() const
Definition MMT_Road.cxx:92
int m_uvthr
Definition MMT_Road.h:44
bool matureCheck(const int bcwind) const
Definition MMT_Road.cxx:121
bool horizontalCheck() const
Definition MMT_Road.cxx:101
int m_iroadx
Definition MMT_Road.h:43
unsigned int countXHits() const
Definition MMT_Road.cxx:87
unsigned int countUHits() const
Definition MMT_Road.cxx:82
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:8
#define unlikely(x)