ATLAS Offline Software
Loading...
Searching...
No Matches
WTAObject.h
Go to the documentation of this file.
1#ifndef WTAObject_h
2#define WTAObject_h
3
4#include <iostream>
5#include <algorithm>
6
7#ifdef BITWISE_SIMULATION
8// 1: Integer type for bitwise simulation
9typedef long long int IntOrFloat;
10const IntOrFloat PI = 32;
11const IntOrFloat R2PAR = 16;
12#elif defined(FLOATING_POINT_SIMULATION)
13// 2: Floating point for athena simulation
14// typedef double IntOrFloat;
15typedef float IntOrFloat;
16const IntOrFloat PI = 3.14159265;
17const IntOrFloat R2PAR = 0.16;
18#else
19#error "Simulation type not defined. Define either BITWISE_SIMULATION or FLOATING_POINT_SIMULATION."
20#endif
21
22template <typename T>
23 static void SortByPt(std::vector<T>& list) // Simple List sorting
24 {
25 std::stable_sort(list.begin(), list.end(), // Use stable_sort to preserve the order of equal elements
26 [](const T &a, const T &b)
27 {
28 return a.pt() > b.pt();
29 }
30 );
31 }
32
34 public:
35 WTATrigObj(IntOrFloat pt = 0, IntOrFloat eta = 0, IntOrFloat phi = 0, IntOrFloat m = 0, int idx = -99)
36 : m_pt(pt), m_eta(eta), m_phi(phi), m_m(m), m_idx(idx){}; // Constructor
37
38 IntOrFloat pt() const {return m_pt;};
39 void pt(IntOrFloat pt) {m_pt = pt;};
40 IntOrFloat eta() const {return m_eta;};
41 void eta(IntOrFloat eta) {m_eta = eta;};
42 IntOrFloat phi() const {return m_phi;};
43 void phi(IntOrFloat phi) {m_phi = phi;};
44 IntOrFloat m() const {return m_m;};
45 void m(IntOrFloat m) {m_m = m;};
46 int idx() const {return m_idx;};
47 void idx(int idx) {m_idx = idx;};
48
49 IntOrFloat d_phi_0_2PI(const WTATrigObj& o2);
50 IntOrFloat d_phi_MPI_PI(const WTATrigObj& o2);
51 IntOrFloat d_eta(const WTATrigObj& o2){IntOrFloat tmp = m_eta - o2.eta(); return tmp;}
52 IntOrFloat dR2(const WTATrigObj& o2);
53 bool IsAssocdR(WTATrigObj& tower, IntOrFloat dr2);
54
55 // comparison operators for easy sorting
56 friend bool operator< (const WTATrigObj &o1, const WTATrigObj &o2){ return o1.pt() < o2.pt(); }; // Call .pt(), not directly access private m_pt
57 friend bool operator> (const WTATrigObj &o1, const WTATrigObj &o2){ return o1.pt() > o2.pt(); };
58 friend bool operator<= (const WTATrigObj &o1, const WTATrigObj &o2){ return o1.pt() <= o2.pt(); };
59 friend bool operator>= (const WTATrigObj &o1, const WTATrigObj &o2){ return o1.pt() >= o2.pt(); };
60
61 // operation override, for easy merging
63 WTATrigObj new_obj;
64 new_obj.m_pt = this->pt() + obj.pt(); // Current default is the scalar sum, WTA
65 new_obj.m_eta = this->eta();
66 new_obj.m_phi = this->phi();
67 new_obj.m_m = this->m();
68 return new_obj;
69 };
70
71 private:
72 IntOrFloat m_pt;
73 IntOrFloat m_eta;
74 IntOrFloat m_phi;
75 IntOrFloat m_m;
76 int m_idx;
77
78};
79
80inline IntOrFloat WTATrigObj::d_phi_0_2PI(const WTATrigObj& o2)
81{
82 IntOrFloat tmp = m_phi - o2.phi();
83 while(tmp < 0)tmp += 2*PI;
84 while(tmp > 2*PI)tmp -= 2*PI;
85 return tmp;
86}
87inline IntOrFloat WTATrigObj::d_phi_MPI_PI(const WTATrigObj& o2)
88{
89 IntOrFloat tmp = m_phi - o2.phi();
90 while(tmp < -PI)tmp += 2*PI;
91 while(tmp > PI)tmp -= 2*PI;
92 return tmp;
93}
94inline IntOrFloat WTATrigObj::dR2(const WTATrigObj& o2)
95{
96 IntOrFloat d_phi = d_phi_MPI_PI(o2);
97 IntOrFloat d_eta_tmp = d_eta(o2);
98 IntOrFloat tmp = (d_phi * d_phi) + (d_eta_tmp * d_eta_tmp);
99 return tmp;
100}
101
102inline bool WTATrigObj::IsAssocdR(WTATrigObj& tower, IntOrFloat dr2){
103 auto dR2 = this->dR2(tower);
104 return dR2 <= dr2;
105}
106
107class WTAJet : public WTATrigObj{ // The class
108 public: // Access specifier
109 WTAJet (IntOrFloat pt = 0, IntOrFloat eta = 0, IntOrFloat phi = 0, IntOrFloat m = 0, int idx = -99, IntOrFloat jet_dr2 = R2PAR) :
110 WTATrigObj(pt, eta, phi, m, idx){
111 m_Seed = WTATrigObj(pt, eta, phi, m, idx);
112 m_Jet_dR2 = jet_dr2;
113 m_ConstituentList.clear();
114 m_ConstituentList.push_back(m_Seed);
115 };
116
117 const WTATrigObj& GetSeed() const {return m_Seed;};
118 void MergeConstituent(WTATrigObj &tower);
119 void MergeConstituent(WTATrigObj *tower);
120 void MergeWTAJet(WTAJet &targetjet);
122 const std::vector<WTATrigObj>& GetConstituentList() const {return m_ConstituentList;};
123 unsigned int GetConstituentCount() const {return m_ConstituentList.size();}; // Need to quickly access the jet's constituent number
124
125 private:
127 std::vector<WTATrigObj> m_ConstituentList;
128 IntOrFloat m_Jet_dR2;
129};
130
132{
133 this->pt(this->pt() + tower.pt());// Scalar sum, WTA
134 m_ConstituentList.push_back(tower);
135}
136
138{
139 this->pt(this->pt() + tower->pt());// Scalar sum, WTA
140 m_ConstituentList.push_back(*tower);
141}
142
143inline void WTAJet::MergeWTAJet(WTAJet &targetjet)
144{
145 WTATrigObj tmptower(targetjet.pt(), targetjet.eta(), targetjet.phi(), targetjet.m());
146 this->pt(this->pt() + tmptower.pt()); // Scalar sum, WTA
147 std::vector<WTATrigObj> tmp_const_list = targetjet.GetConstituentList();
148 m_ConstituentList.insert(m_ConstituentList.end(), tmp_const_list.begin(), tmp_const_list.end());
149}
150
152{
153 WTATrigObj lastconst = m_ConstituentList.back(); //std::vector::back() returns the last element
154 this->pt(this->pt() - lastconst.pt()); // Scalar subtraction, WTA
155 m_ConstituentList.pop_back(); // Popback the last element
156}
157
158#endif
static Double_t a
static void SortByPt(std::vector< T > &list)
Definition WTAObject.h:23
void MergeWTAJet(WTAJet &targetjet)
Definition WTAObject.h:143
WTATrigObj m_Seed
Definition WTAObject.h:126
void PopOutLastConstituent()
Definition WTAObject.h:151
const std::vector< WTATrigObj > & GetConstituentList() const
Definition WTAObject.h:122
IntOrFloat m_Jet_dR2
Definition WTAObject.h:128
WTAJet(IntOrFloat pt=0, IntOrFloat eta=0, IntOrFloat phi=0, IntOrFloat m=0, int idx=-99, IntOrFloat jet_dr2=R2PAR)
Definition WTAObject.h:109
const WTATrigObj & GetSeed() const
Definition WTAObject.h:117
std::vector< WTATrigObj > m_ConstituentList
Definition WTAObject.h:127
unsigned int GetConstituentCount() const
Definition WTAObject.h:123
void MergeConstituent(WTATrigObj &tower)
Definition WTAObject.h:131
friend bool operator<(const WTATrigObj &o1, const WTATrigObj &o2)
Definition WTAObject.h:56
WTATrigObj(IntOrFloat pt=0, IntOrFloat eta=0, IntOrFloat phi=0, IntOrFloat m=0, int idx=-99)
Definition WTAObject.h:35
IntOrFloat m_phi
Definition WTAObject.h:74
IntOrFloat m_pt
Definition WTAObject.h:72
friend bool operator<=(const WTATrigObj &o1, const WTATrigObj &o2)
Definition WTAObject.h:58
IntOrFloat m_eta
Definition WTAObject.h:73
IntOrFloat m() const
Definition WTAObject.h:44
int idx() const
Definition WTAObject.h:46
void m(IntOrFloat m)
Definition WTAObject.h:45
IntOrFloat pt() const
Definition WTAObject.h:38
IntOrFloat d_phi_0_2PI(const WTATrigObj &o2)
Definition WTAObject.h:80
IntOrFloat dR2(const WTATrigObj &o2)
Definition WTAObject.h:94
void pt(IntOrFloat pt)
Definition WTAObject.h:39
WTATrigObj operator+(const WTATrigObj &obj)
Definition WTAObject.h:62
IntOrFloat eta() const
Definition WTAObject.h:40
void phi(IntOrFloat phi)
Definition WTAObject.h:43
void idx(int idx)
Definition WTAObject.h:47
bool IsAssocdR(WTATrigObj &tower, IntOrFloat dr2)
Definition WTAObject.h:102
IntOrFloat m_m
Definition WTAObject.h:75
IntOrFloat d_eta(const WTATrigObj &o2)
Definition WTAObject.h:51
IntOrFloat phi() const
Definition WTAObject.h:42
friend bool operator>=(const WTATrigObj &o1, const WTATrigObj &o2)
Definition WTAObject.h:59
void eta(IntOrFloat eta)
Definition WTAObject.h:41
friend bool operator>(const WTATrigObj &o1, const WTATrigObj &o2)
Definition WTAObject.h:57
IntOrFloat d_phi_MPI_PI(const WTATrigObj &o2)
Definition WTAObject.h:87
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
const float PI