ATLAS Offline Software
Loading...
Searching...
No Matches
WTAObject.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef WTAObject_h
6#define WTAObject_h
7
8#include <iostream>
9#include <algorithm>
10#include <cassert>
11#include <cmath>
12
13#include "./WTASimTypes.h" // Use the WTASimTypes
14
15template <typename T>
16 static void SortByPt(std::vector<T>& list) // Simple List sorting
17 {
18 std::stable_sort(list.begin(), list.end(), // Use stable_sort to preserve the order of equal elements
19 [](const T &a, const T &b)
20 {
21 return a.pt() > b.pt();
22 }
23 );
24 }
25
27 public:
28 WTATrigObj(pt_t pt = 0, eta_t eta = 0, phi_t phi = 0, m_t m = 0, int idx = -99)
29 : m_pt(pt), m_eta(eta), m_phi(phi), m_m(m), m_idx(idx){}; // Constructor
30
31 pt_t pt() const {return m_pt;};
32 void pt(pt_t pt) {m_pt = pt;};
33 eta_t eta() const {return m_eta;};
34 void eta(eta_t eta) {m_eta = eta;};
35 phi_t phi() const {return m_phi;};
36 void phi(phi_t phi) {m_phi = phi;};
37 m_t m() const {return m_m;};
38 void m(m_t m) {m_m = m;};
39 int idx() const {return m_idx;};
40 void idx(int idx) {m_idx = idx;};
41
42#ifdef FLOATING_POINT_SIMULATION
43 phi_t d_phi_0_2PI(const WTATrigObj& o2) const;
44#endif
45 phi_t d_phi_MPI_PI(const WTATrigObj& o2) const;
46 eta_t d_eta(const WTATrigObj& o2) const {eta_t tmp = m_eta - o2.eta(); return tmp;}
47 bool IsAssocdR(WTATrigObj& tower, tech_t dr);
48
49 // comparison operators for easy sorting
50 friend bool operator< (const WTATrigObj &o1, const WTATrigObj &o2){ return o1.pt() < o2.pt(); }; // Call .pt(), not directly access private m_pt
51 friend bool operator> (const WTATrigObj &o1, const WTATrigObj &o2){ return o1.pt() > o2.pt(); };
52 friend bool operator<= (const WTATrigObj &o1, const WTATrigObj &o2){ return o1.pt() <= o2.pt(); };
53 friend bool operator>= (const WTATrigObj &o1, const WTATrigObj &o2){ return o1.pt() >= o2.pt(); };
54
55 // operation override, for easy merging
57 WTATrigObj new_obj;
58 new_obj.m_pt = this->pt() + obj.pt(); // Current default is the scalar sum, WTA
59 new_obj.m_eta = this->eta();
60 new_obj.m_phi = this->phi();
61 new_obj.m_m = this->m();
62 return new_obj;
63 };
64
65 private:
66 pt_t m_pt;
67 eta_t m_eta;
68 phi_t m_phi;
69 m_t m_m;
70 int m_idx; // Index required to track constituent indices in TrigGepPerf
71
72};
73
74#ifdef FLOATING_POINT_SIMULATION
75inline phi_t WTATrigObj::d_phi_0_2PI(const WTATrigObj& o2) const
76{
77 phi_t tmp = m_phi - o2.phi();
78 while(tmp < 0)tmp += 2*PI;
79 while(tmp > 2*PI)tmp -= 2*PI;
80 return tmp;
81}
82inline phi_t WTATrigObj::d_phi_MPI_PI(const WTATrigObj& o2) const
83{
84 phi_t tmp = m_phi - o2.phi();
85 while(tmp < -PI)tmp += 2*PI;
86 while(tmp > PI)tmp -= 2*PI;
87 return tmp;
88}
89#else
90inline phi_t WTATrigObj::d_phi_MPI_PI(const WTATrigObj& o2) const
91{
92 phi_t tmp;
93 if (m_phi >= o2.phi()){
94 tmp = m_phi - o2.phi();
95 } else {
96 tmp = o2.phi() - m_phi;
97 }
98
99 // Wrap difference to [-32, +31]
100 if (tmp < -HALF_PHI_LEN) tmp = tmp + PHI_LEN;
101 else if (tmp >= HALF_PHI_LEN) tmp = tmp - PHI_LEN;
102
103 return tmp;
104}
105#endif
106
107#ifdef FLOATING_POINT_SIMULATION
108inline bool WTATrigObj::IsAssocdR(WTATrigObj& tower, tech_t dr){
109 eta_t d_eta = this->d_eta(tower);
110 phi_t d_phi = this->d_phi_MPI_PI(tower);
111 bool assoc = (dr*dr) >= (d_eta*d_eta + d_phi*d_phi);
112 return assoc;
113}
114#else
115inline bool WTATrigObj::IsAssocdR(WTATrigObj& tower, tech_t dr){
116 assert(tower.eta() >= 0 && "Input tower.eta() must be non-negative");
117 assert(tower.phi() >= 0 && "Input tower.phi() must be non-negative");
118 assert(dr >= 0 && "Input dr must be non-negative");
119 eta_t d_eta = this->eta() > tower.eta() ? this->d_eta(tower) : tower.d_eta(*this); // ensure positive d_eta d_phi
120 phi_t raw_dphi = abs(int32_t(this->phi()) - int32_t(tower.phi()));
121 phi_t d_phi = std::min(raw_dphi, PHI_LEN - raw_dphi);
122 bool assoc = false;
123 for (unsigned int i = 0; i <= dr; i++){
124 unsigned int max_j = sqrt(static_cast<double>(dr*dr - i*i)); // Need to be careful with the sqrt
125 for(unsigned int j = 0; j <= max_j; j++){
126 if(d_eta <= i && d_phi <= j){
127 assoc = true;
128 break;
129 }
130 }
131 }
132 return assoc;
133}
134#endif
135
137 pt_t ring0_Et = 0;
138 pt_t ring1_Et = 0;
139 pt_t ring2_Et = 0;
140 pt_t ring3_Et = 0;
141 pt_t ring4_Et = 0;
142 tobn_t total_TobN = 0;
143 ring0_tobn_t ring0_TobN = 0;
144 ring1_tobn_t ring1_TobN = 0;
145 ring2_tobn_t ring2_TobN = 0;
146 ring3_tobn_t ring3_TobN = 0;
147 ring4_tobn_t ring4_TobN = 0;
148};
149
150class WTAJet : public WTATrigObj{ // The class
151 public: // Access specifier
152 WTAJet (pt_t pt = 0, eta_t eta = 0, phi_t phi = 0, m_t m = 0, int idx = -99, tech_t jet_dr = R_PAR) :
153 WTATrigObj(pt, eta, phi, m, idx) {
154 m_Seed = WTATrigObj(pt, eta, phi, m, idx);
155 m_jet_dr = jet_dr;
156 m_ConstituentList.clear();
157 m_ConstituentList.push_back(m_Seed);
158 #ifdef FLOATING_POINT_SIMULATION
159 m_ring_n = static_cast<unsigned int>(jet_dr / 0.1);
160 #else
161 m_ring_n = jet_dr;
162 #endif
163 };
164
165 const WTATrigObj& GetSeed() const {return m_Seed;};
166 void MergeConstituent(WTATrigObj &tower);
167 void MergeConstituent(WTATrigObj *tower);
168 void MergeWTAJet(WTAJet &targetjet);
170 const std::vector<WTATrigObj>& GetConstituentList() const {return m_ConstituentList;};
171 tobn_t GetConstituentCount() const {return static_cast<tobn_t>(m_ConstituentList.size());}; // Match the type
172
173 unsigned int GetRingN(const WTATrigObj& tower) const;
174 void CreateERingInfo(); // To be called after jet clustering is done
175 void PrintERingInfo() const;
176 const WTA4JetERingInfo& GetERingInfo() const {return m_ERingInfo;};
177 void SetERingInfo(const WTA4JetERingInfo& ering_info) {m_ERingInfo = ering_info;}; // When parsing the ref jet, ERingInfo does not get created automatically
178
179 private:
181 std::vector<WTATrigObj> m_ConstituentList;
182 tech_t m_jet_dr;
183 unsigned int m_ring_n;
185};
186
188{
189 this->pt(this->pt() + tower.pt());// Scalar sum, WTA
190 m_ConstituentList.push_back(tower);
191}
192
194{
195 this->pt(this->pt() + tower->pt());// Scalar sum, WTA
196 m_ConstituentList.push_back(*tower);
197}
198
199inline void WTAJet::MergeWTAJet(WTAJet &targetjet)
200{
201 WTATrigObj tmptower(targetjet.pt(), targetjet.eta(), targetjet.phi(), targetjet.m());
202 this->pt(this->pt() + tmptower.pt()); // Scalar sum, WTA
203 std::vector<WTATrigObj> tmp_const_list = targetjet.GetConstituentList();
204 m_ConstituentList.insert(m_ConstituentList.end(), tmp_const_list.begin(), tmp_const_list.end());
205}
206
208{
209 WTATrigObj lastconst = m_ConstituentList.back(); //std::vector::back() returns the last element
210 this->pt(this->pt() - lastconst.pt()); // Scalar subtraction, WTA
211 m_ConstituentList.pop_back(); // Popback the last element
212}
213
214#ifdef FLOATING_POINT_SIMULATION
215inline unsigned int WTAJet::GetRingN(const WTATrigObj& tower) const {
216 eta_t d_eta = this->d_eta(tower);
217 phi_t d_phi = this->d_phi_MPI_PI(tower);
218 tech_t dr = std::sqrt(d_eta*d_eta + d_phi*d_phi);
219 unsigned int ring_n = static_cast<unsigned int>(std::ceil(dr / 0.1)); // Each ring has dR of 0.1
220 return ring_n;
221}
222#elif defined(BITWISE_SIMULATION)
223inline unsigned int WTAJet::GetRingN(const WTATrigObj& tower) const {
224 eta_t d_eta = this->eta() > tower.eta() ? this->d_eta(tower) : tower.d_eta(*this); // ensure positive d_eta d_phi
225 phi_t raw_dphi = abs(int32_t(this->phi()) - int32_t(tower.phi()));
226 phi_t d_phi = std::min(raw_dphi, PHI_LEN - raw_dphi);
227 unsigned int ring_n = std::max(d_eta, static_cast<eta_t>(d_phi.raw()));
228 return ring_n;
229}
230#else
231inline unsigned int WTAJet::GetRingN(const WTATrigObj& tower) const {
232 eta_t d_eta = this->eta() > tower.eta() ? this->d_eta(tower) : tower.d_eta(*this); // ensure positive d_eta d_phi
233 phi_t raw_dphi = abs(int32_t(this->phi()) - int32_t(tower.phi()));
234 phi_t d_phi = std::min(raw_dphi, PHI_LEN - raw_dphi);
235 unsigned int ring_n = std::max(d_eta, static_cast<eta_t>(d_phi)); // No .raw() in long long int
236 return ring_n;
237}
238#endif
239
241 // This function is ideally called after all jet clustering is done
242
243 // Check if the constituent list is empty
244 if(m_ConstituentList.empty()){
245 std::cerr << "Error: Constituent list is empty. Cannot create ERingInfo." << std::endl;
246 return;
247 }
248
249 // Reset the ERingInfo
250 WTA4JetERingInfo ering_info;
251 m_ERingInfo = ering_info;
252
253 for(const auto& tower:m_ConstituentList){
254 unsigned int ring_n = this->GetRingN(tower);
255 m_ERingInfo.total_TobN = m_ERingInfo.total_TobN + 1;
256 switch(ring_n){
257 case 0:
258 m_ERingInfo.ring0_Et = m_ERingInfo.ring0_Et + tower.pt();
259 m_ERingInfo.ring0_TobN = m_ERingInfo.ring0_TobN + 1;
260 break;
261 case 1:
262 m_ERingInfo.ring1_Et = m_ERingInfo.ring1_Et + tower.pt();
263 m_ERingInfo.ring1_TobN = m_ERingInfo.ring1_TobN + 1;
264 break;
265 case 2:
266 m_ERingInfo.ring2_Et = m_ERingInfo.ring2_Et + tower.pt();
267 m_ERingInfo.ring2_TobN = m_ERingInfo.ring2_TobN + 1;
268 break;
269 case 3:
270 m_ERingInfo.ring3_Et = m_ERingInfo.ring3_Et + tower.pt();
271 m_ERingInfo.ring3_TobN = m_ERingInfo.ring3_TobN + 1;
272 break;
273 case 4:
274 m_ERingInfo.ring4_Et = m_ERingInfo.ring4_Et + tower.pt();
275 m_ERingInfo.ring4_TobN = m_ERingInfo.ring4_TobN + 1;
276 break;
277 default:
278 break;
279 }
280 }
281}
282
283inline void WTAJet::PrintERingInfo() const {
284 std::cout << "WTAJet ERing Info:" << std::endl;
285 std::cout << " Raw Jet Et: " << this->pt() << " , Constituent Count: " << this->GetConstituentCount() << std::endl;
286 std::cout << " Total TobN: " << m_ERingInfo.total_TobN << std::endl;
287 std::cout << " Ring 0: Et = " << m_ERingInfo.ring0_Et << ", TobN = " << m_ERingInfo.ring0_TobN << std::endl;
288 std::cout << " Ring 1: Et = " << m_ERingInfo.ring1_Et << ", TobN = " << m_ERingInfo.ring1_TobN << std::endl;
289 std::cout << " Ring 2: Et = " << m_ERingInfo.ring2_Et << ", TobN = " << m_ERingInfo.ring2_TobN << std::endl;
290 std::cout << " Ring 3: Et = " << m_ERingInfo.ring3_Et << ", TobN = " << m_ERingInfo.ring3_TobN << std::endl;
291 std::cout << " Ring 4: Et = " << m_ERingInfo.ring4_Et << ", TobN = " << m_ERingInfo.ring4_TobN << std::endl;
292}
293
294#endif
static Double_t a
static void SortByPt(std::vector< T > &list)
Definition WTAObject.h:16
void MergeWTAJet(WTAJet &targetjet)
Definition WTAObject.h:199
WTATrigObj m_Seed
Definition WTAObject.h:180
void PopOutLastConstituent()
Definition WTAObject.h:207
WTA4JetERingInfo m_ERingInfo
Definition WTAObject.h:184
WTAJet(pt_t pt=0, eta_t eta=0, phi_t phi=0, m_t m=0, int idx=-99, tech_t jet_dr=R_PAR)
Definition WTAObject.h:152
tech_t m_jet_dr
Definition WTAObject.h:182
tobn_t GetConstituentCount() const
Definition WTAObject.h:171
unsigned int GetRingN(const WTATrigObj &tower) const
Definition WTAObject.h:231
void SetERingInfo(const WTA4JetERingInfo &ering_info)
Definition WTAObject.h:177
unsigned int m_ring_n
Definition WTAObject.h:183
const std::vector< WTATrigObj > & GetConstituentList() const
Definition WTAObject.h:170
const WTATrigObj & GetSeed() const
Definition WTAObject.h:165
const WTA4JetERingInfo & GetERingInfo() const
Definition WTAObject.h:176
std::vector< WTATrigObj > m_ConstituentList
Definition WTAObject.h:181
void MergeConstituent(WTATrigObj &tower)
Definition WTAObject.h:187
void CreateERingInfo()
Definition WTAObject.h:240
void PrintERingInfo() const
Definition WTAObject.h:283
friend bool operator<(const WTATrigObj &o1, const WTATrigObj &o2)
Definition WTAObject.h:50
phi_t d_phi_MPI_PI(const WTATrigObj &o2) const
Definition WTAObject.h:90
eta_t eta() const
Definition WTAObject.h:33
phi_t phi() const
Definition WTAObject.h:35
friend bool operator<=(const WTATrigObj &o1, const WTATrigObj &o2)
Definition WTAObject.h:52
pt_t pt() const
Definition WTAObject.h:31
int idx() const
Definition WTAObject.h:39
eta_t m_eta
Definition WTAObject.h:67
bool IsAssocdR(WTATrigObj &tower, tech_t dr)
Definition WTAObject.h:115
WTATrigObj operator+(const WTATrigObj &obj)
Definition WTAObject.h:56
pt_t m_pt
Definition WTAObject.h:66
void idx(int idx)
Definition WTAObject.h:40
void eta(eta_t eta)
Definition WTAObject.h:34
m_t m() const
Definition WTAObject.h:37
friend bool operator>=(const WTATrigObj &o1, const WTATrigObj &o2)
Definition WTAObject.h:53
WTATrigObj(pt_t pt=0, eta_t eta=0, phi_t phi=0, m_t m=0, int idx=-99)
Definition WTAObject.h:28
friend bool operator>(const WTATrigObj &o1, const WTATrigObj &o2)
Definition WTAObject.h:51
void pt(pt_t pt)
Definition WTAObject.h:32
phi_t m_phi
Definition WTAObject.h:68
void m(m_t m)
Definition WTAObject.h:38
eta_t d_eta(const WTATrigObj &o2) const
Definition WTAObject.h:46
void phi(phi_t phi)
Definition WTAObject.h:36
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
ring4_tobn_t ring4_TobN
Definition WTAObject.h:147
ring1_tobn_t ring1_TobN
Definition WTAObject.h:144
ring2_tobn_t ring2_TobN
Definition WTAObject.h:145
ring0_tobn_t ring0_TobN
Definition WTAObject.h:143
ring3_tobn_t ring3_TobN
Definition WTAObject.h:146
const float PI