ATLAS Offline Software
Loading...
Searching...
No Matches
MMT_Diamond.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_Diamond.h"
6
7
8namespace {
9 // The stereo angle is fixed and can be hardcoded
10 const double tan_stereo_angle = std::tan(0.02618);
11
12 constexpr int bc_wind = 4; // fixed time window (in bunch crossings) during which the algorithm collects ART hits
13 constexpr int n_addc = 4;
14 constexpr int n_vmm = 128;
15}
16
17
18MMT_Diamond::MMT_Diamond(const int diamXthreshold, const bool uv, const int diamUVthreshold, const int roadSize,
19 const int olapEtaUp, const int olapEtaDown, const int olapStereoUp, const int olapStereoDown): AthMessaging(Athena::getMessageSvc(), "MMT_Diamond") {
20 m_xthr = diamXthreshold;
21 m_uvthr = diamUVthreshold;
22 m_uvflag = uv;
23 m_roadSize = roadSize;
24 m_roadSizeUpX = olapEtaUp;
25 m_roadSizeDownX = olapEtaDown;
26 m_roadSizeUpUV = olapStereoUp;
27 m_roadSizeDownUV = olapStereoDown;
28}
29
30void MMT_Diamond::createRoads(std::vector<MMT_Road>& roads, const bool isLarge, const bool isEta1) const {
31 const char sec = (isLarge) ? 'L' : 'S';
32 /*
33 * This computation is done as follows: 1024 X roads, from 8192 strips in total (5120 for |eta|==1 and 3072 for |eta|==2)
34 * MML: for i in [0,8] -> i*6 UV roads. Then: (1024-9)*6*9 UV roads
35 * MMS: for i in [0,6] -> i*6 UV roads. Then: (1024-7)*6*7 UV roads
36 */
37 const unsigned int vecRoads = 35000;
38 roads.reserve(vecRoads);
39 const int nroad = 8192/m_roadSize;
40 for (int i = 0; i < nroad; ++i) {
41 const int div = 5120/m_roadSize;
42 if((isEta1 && i>div) || (!isEta1 && i<=div)) continue;
44
45 /*
46 * The computation of "nuv" is:
47 * B = (1./std::tan(1.5/180.*M_PI));
48 * nuv = std::round( par->getlWidth() / (B * 0.4 * 2.)/this->getRoadSize() );
49 * As getlWidth() has to deal with the full wedge, only two (fixed by construction) integer values are allowed, according to small (7) or large (9) wedge
50 */
51 if(m_uvflag) {
52 const int nuv = (isLarge) ? 9 : 7;
53 for (int uv = 1; uv <= nuv; uv++) {
54 if (i-uv < 0) continue;
55 roads.emplace_back(sec, m_roadSize, m_roadSizeUpX, m_roadSizeDownX, m_roadSizeUpUV, m_roadSizeDownUV, m_xthr, m_uvthr, i, i+uv, i-uv);
56 roads.emplace_back(sec, m_roadSize, m_roadSizeUpX, m_roadSizeDownX, m_roadSizeUpUV, m_roadSizeDownUV, m_xthr, m_uvthr, i, i-uv, i+uv);
57 roads.emplace_back(sec, m_roadSize, m_roadSizeUpX, m_roadSizeDownX, m_roadSizeUpUV, m_roadSizeDownUV, m_xthr, m_uvthr, i, i+uv-1, i-uv);
58 roads.emplace_back(sec, m_roadSize, m_roadSizeUpX, m_roadSizeDownX, m_roadSizeUpUV, m_roadSizeDownUV, m_xthr, m_uvthr, i, i-uv, i+uv-1);
59 roads.emplace_back(sec, m_roadSize, m_roadSizeUpX, m_roadSizeDownX, m_roadSizeUpUV, m_roadSizeDownUV, m_xthr, m_uvthr, i, i-uv+1, i+uv);
60 roads.emplace_back(sec, m_roadSize, m_roadSizeUpX, m_roadSizeDownX, m_roadSizeUpUV, m_roadSizeDownUV, m_xthr, m_uvthr, i, i+uv, i-uv+1);
61 }
62 }
63 }
64}
65
66void MMT_Diamond::findDiamonds(std::vector<std::shared_ptr<MMT_Hit> >& hits, std::vector<MMT_Road>& roads, std::vector<slope_t>& diamondSlopes, const int sectorPhi) const {
67
68 // Comparison with lambda function (easier to implement)
69 std::ranges::sort(hits, [](const auto &h1, const auto &h2){ return h1->getBC() < h2->getBC(); });
70 const int bc_start = hits.front()->getBC();
71 const int bc_end = hits.front()->getBC() + 16;
72 ATH_MSG_DEBUG("Window Start: " << bc_start << " - Window End: " << bc_end);
73
74 std::vector<std::shared_ptr<MMT_Hit> > hits_now;
75 std::vector< std::pair<int, float> > vmm_same;
76 std::vector< std::pair<int, int> > addc_same;
77 std::vector<int> to_erase;
78
79 // each road makes independent triggers, evaluated on each BC
80 unsigned int ibc = 0;
81 for (int bc = hits.front()->getBC(); bc < bc_end; bc++) {
82 // Cleaning stuff
83 hits_now.clear();
84
85 for (unsigned int j = ibc; j < hits.size(); j++) {
86 if (hits[j]->getBC() == bc) hits_now.push_back(hits[j]);
87 else if (hits[j]->getBC() > bc) {
88 ibc = j;
89 break;
90 }
91 }
92
93 // Simulate harware filters: ART hits + ADDC filter
94 for (unsigned int ib = 0; ib < 8; ib++) { //loop on plane from 0 to 7
95 // VMM-ART-hit filter
96 for (int j = 0; j < n_vmm; j++) {
97 vmm_same.clear();
98 unsigned int k = 0;
99 for (const auto &hit_pointer: hits_now) {
100 if (static_cast<unsigned int>(hit_pointer->getPlane()) != ib) continue;
101 if (hit_pointer->getVMM() == j){
102 vmm_same.push_back( std::make_pair(k, hit_pointer->getTime()) );
103 }
104 k++;
105 }
106 if (vmm_same.size() > 1) {
107 to_erase.clear();
108 std::ranges::sort(vmm_same, {}, &std::pair<int, float>::second);
109 for (auto pair: vmm_same) to_erase.push_back(pair.first);
110 // reverse and erase
111 std::sort(to_erase.rbegin(), to_erase.rend());
112 to_erase.pop_back(); //removes the hit with the earliest time
113 for (auto l : to_erase) {
114 hits_now.erase(hits_now.begin() + l);
115 }
116 }
117 }
118 // ADDC-like filter
119 for (int ia = 0; ia < n_addc; ia++) { // From 0 to 3 (local index of the ART ASIC in the layer)
120 addc_same.clear();
121 for (unsigned int k = 0; k < hits_now.size(); k++) {
122 if ((unsigned int)(hits_now[k]->getPlane()) != ib) continue;
123 int istrip = (std::abs(hits_now[k]->getStationEta())-1) * (64*8*10) + hits_now[k]->getChannel(); //needed the global strip index on the sector layer (getChannel returns chamber's local strip index)
124 if (hits_now[k]->getART() == ia) addc_same.emplace_back(k, istrip);
125 }
126
127 if (addc_same.size() > 8) {
128 // priority encode the hits by channel number; remember hits 8+
129 to_erase.clear();
130
131 std::ranges::sort(addc_same, {}, &std::pair<int, int>::second);
132 for (unsigned int it = 8; it < addc_same.size(); it++) to_erase.push_back(addc_same[it].first);
133
134 // reverse and erase
135 std::sort(to_erase.rbegin(), to_erase.rend());
136 for (auto l : to_erase) {
137 hits_now.erase(hits_now.begin() + l);
138 }
139 }
140 }
141 } // loop on plane for VMM and ART ASIC filter
142
143 for (auto &road : roads) {
144
145 if (!road.getHitVector().empty()) road.incrementAge(bc_wind);
146 if (!hits_now.empty()) road.addHits(hits_now);
147
148 if (road.checkCoincidences(bc_wind) && bc >= (bc_start - 1)) {
149
150 ATH_MSG_DEBUG("------------------------------------------------------------------");
151 ATH_MSG_DEBUG("Coincidence FOUND @BC: " << bc);
152 ATH_MSG_DEBUG("Road (x, u, v, count): (" << road.iRoadx() << ", " << road.iRoadu() << ", " << road.iRoadv() << ", " << road.countHits() << ")");
153 ATH_MSG_DEBUG("------------------------------------------------------------------");
154
155 std::vector<int> bcidVec;
156 for (const auto &hit: road.getHitVector()) {
157 bcidVec.push_back(hit.getBC());
158 }
159 std::ranges::sort(bcidVec);
160
161 // evaluating mode of the BCID of the hits in the diamond
162 // default setting in the firmware is the mode of the hits's bcid in the diamond
163 int bcidVal=bcidVec[0], bcidCount=1, modeCount=1, bcidMode=bcidVec[0];
164 for (unsigned int i=1; i<bcidVec.size(); i++){
165 if (bcidVec[i] == bcidVal){
166 bcidCount++;
167 } else {
168 bcidCount = 1;
169 bcidVal = bcidVec[i];
170 }
171 if (bcidCount > modeCount) {
172 modeCount = bcidCount;
173 bcidMode = bcidVal;
174 }
175 }
176
177 slope_t slope;
178 slope.BC = bcidMode;
179 slope.totalCount = road.countHits();
180 slope.iRoad = road.iRoadx();
181 slope.iRoadu = road.iRoadu();
182 slope.iRoadv = road.iRoadv();
183 slope.xCount = road.countXHits();
184 slope.uCount = road.countUHits();
185 slope.age = slope.BC - bc_start;
186 slope.mxl = road.mxl();
187 slope.my = road.avgSofXUV('X'); // defined as my in ATL-COM-UPGRADE-2015-033
188 slope.uavg = road.avgSofXUV('U');
189 slope.vavg = road.avgSofXUV('V');
190 slope.mx = (slope.uavg-slope.vavg)/(2.*tan_stereo_angle);
191 const double theta = std::atan(std::sqrt(std::pow(slope.mx,2) + std::pow(slope.my,2)));
192 slope.theta = (slope.my > 0.) ? theta : M_PI - theta;
193 slope.eta = -1.*std::log(std::tan(slope.theta/2.));
194 slope.dtheta = (slope.mxl - slope.my)/(1. + slope.mxl*slope.my);
195 slope.side = (slope.my > 0.) ? 'A' : 'C';
196 slope.phi = std::atan(slope.mx/slope.my);
197 slope.phiShf = phiShift(sectorPhi, slope.phi, slope.side);
198 slope.lowRes = road.evaluateLowRes();
199
200 diamondSlopes.push_back(slope);
201 }
202 }
203 }
204}
205
206double MMT_Diamond::phiShift(const int n, const double phi, const char side) const {
207 double Phi = (side == 'A') ? -phi : phi;
208 double shift = (n > 8) ? (16-n)*M_PI/8. : n*M_PI/8.;
209 if (n < 8) return (Phi + shift);
210 else if (n == 8) return (Phi + ((Phi > 0.) ? -1. : 1.)*shift);
211 else return (Phi - shift);
212}
#define M_PI
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_MSG_DEBUG(x)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
MMT_Diamond(const int diamXthreshold, const bool uv, const int diamUVthreshold, const int roadSize, const int olapEtaUp, const int olapEtaDown, const int olapStereoUp, const int olapStereoDown)
double phiShift(const int n, const double phi, const char side) const
int m_roadSizeDownUV
Definition MMT_Diamond.h:53
void createRoads(std::vector< MMT_Road > &roads, const bool isLarge, const bool isEta1) const
int m_roadSizeUpUV
Definition MMT_Diamond.h:53
int m_roadSizeDownX
Definition MMT_Diamond.h:53
int m_roadSizeUpX
Definition MMT_Diamond.h:53
void findDiamonds(std::vector< std::shared_ptr< MMT_Hit > > &hits, std::vector< MMT_Road > &roads, std::vector< slope_t > &diamondSlopes, const int sectorPhi) const
STL class.
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
unsigned int uCount
Definition MMT_Diamond.h:21
double my
Definition MMT_Diamond.h:24
double phi
Definition MMT_Diamond.h:31
double phiShf
Definition MMT_Diamond.h:32
double eta
Definition MMT_Diamond.h:29
int iRoadu
Definition MMT_Diamond.h:18
double mx
Definition MMT_Diamond.h:27
int iRoadv
Definition MMT_Diamond.h:19
double mxl
Definition MMT_Diamond.h:23
unsigned int totalCount
Definition MMT_Diamond.h:16
unsigned int xCount
Definition MMT_Diamond.h:20
double theta
Definition MMT_Diamond.h:28
double vavg
Definition MMT_Diamond.h:26
double dtheta
Definition MMT_Diamond.h:30
char side
Definition MMT_Diamond.h:33
bool lowRes
Definition MMT_Diamond.h:34
double uavg
Definition MMT_Diamond.h:25
int iRoad
Definition MMT_Diamond.h:17