ATLAS Offline Software
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
9 typedef long long int IntOrFloat;
10 const IntOrFloat PI = 32;
11 const IntOrFloat R2PAR = 16;
12 #elif defined(FLOATING_POINT_SIMULATION)
13 // 2: Floating point for athena simulation
14 // typedef double IntOrFloat;
15 typedef float IntOrFloat;
16 const IntOrFloat PI = 3.14159265;
17 const IntOrFloat R2PAR = 0.16;
18 #else
19 #error "Simulation type not defined. Define either BITWISE_SIMULATION or FLOATING_POINT_SIMULATION."
20 #endif
21 
22 template <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 
33 class WTATrigObj{
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 
80 inline 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 }
87 inline 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 }
94 inline 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 
102 inline bool WTATrigObj::IsAssocdR(WTATrigObj& tower, IntOrFloat dr2){
103  auto dR2 = this->dR2(tower);
104  return dR2 <= dr2;
105 }
106 
107 class 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);
121  void PopOutLastConstituent();
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 
143 inline 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
WTAJet::MergeWTAJet
void MergeWTAJet(WTAJet &targetjet)
Definition: WTAObject.h:143
WTATrigObj::phi
IntOrFloat phi() const
Definition: WTAObject.h:42
WTATrigObj::m_phi
IntOrFloat m_phi
Definition: WTAObject.h:74
WTATrigObj::m_m
IntOrFloat m_m
Definition: WTAObject.h:75
PI
const float PI
Definition: test_isolaitonTool.cxx:61
WTATrigObj::d_eta
IntOrFloat d_eta(const WTATrigObj &o2)
Definition: WTAObject.h:51
WTAJet::m_Seed
WTATrigObj m_Seed
Definition: WTAObject.h:123
WTAJet::GetConstituentCount
unsigned int GetConstituentCount() const
Definition: WTAObject.h:123
std::stable_sort
void stable_sort(std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, std::reverse_iterator< DataModel_detail::iterator< DVL > > end, Compare comp)
Specialization of stable_sort for DataVector/List.
Definition: DVL_algorithms.h:711
WTATrigObj::pt
IntOrFloat pt() const
Definition: WTAObject.h:38
WTATrigObj::IsAssocdR
bool IsAssocdR(WTATrigObj &tower, IntOrFloat dr2)
Definition: WTAObject.h:102
WTAJet::m_ConstituentList
std::vector< WTATrigObj > m_ConstituentList
Definition: WTAObject.h:127
WTATrigObj::m_pt
IntOrFloat m_pt
Definition: WTAObject.h:69
WTATrigObj::dR2
IntOrFloat dR2(const WTATrigObj &o2)
Definition: WTAObject.h:94
WTATrigObj::operator+
WTATrigObj operator+(const WTATrigObj &obj)
Definition: WTAObject.h:62
WTAJet::MergeConstituent
void MergeConstituent(WTATrigObj &tower)
Definition: WTAObject.h:131
WTATrigObj::m
IntOrFloat m() const
Definition: WTAObject.h:44
WTAJet::PopOutLastConstituent
void PopOutLastConstituent()
Definition: WTAObject.h:151
WTATrigObj::idx
void idx(int idx)
Definition: WTAObject.h:47
WTATrigObj::phi
void phi(IntOrFloat phi)
Definition: WTAObject.h:43
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
WTATrigObj::eta
void eta(IntOrFloat eta)
Definition: WTAObject.h:41
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
WTATrigObj::pt
void pt(IntOrFloat pt)
Definition: WTAObject.h:39
WTAJet::WTAJet
WTAJet(IntOrFloat pt=0, IntOrFloat eta=0, IntOrFloat phi=0, IntOrFloat m=0, int idx=-99, IntOrFloat jet_dr2=R2PAR)
Definition: WTAObject.h:109
WTATrigObj::WTATrigObj
WTATrigObj(IntOrFloat pt=0, IntOrFloat eta=0, IntOrFloat phi=0, IntOrFloat m=0, int idx=-99)
Definition: WTAObject.h:35
WTATrigObj::d_phi_MPI_PI
IntOrFloat d_phi_MPI_PI(const WTATrigObj &o2)
Definition: WTAObject.h:87
WTATrigObj::d_phi_0_2PI
IntOrFloat d_phi_0_2PI(const WTATrigObj &o2)
Definition: WTAObject.h:80
WTATrigObj::operator>
friend bool operator>(const WTATrigObj &o1, const WTATrigObj &o2)
Definition: WTAObject.h:57
WTATrigObj
Definition: WTAObject.h:33
WTATrigObj::operator<
friend bool operator<(const WTATrigObj &o1, const WTATrigObj &o2)
Definition: WTAObject.h:56
WTAJet
Definition: WTAObject.h:107
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
WTAJet::GetConstituentList
const std::vector< WTATrigObj > & GetConstituentList() const
Definition: WTAObject.h:122
python.changerun.o2
o2
Definition: changerun.py:43
a
TList * a
Definition: liststreamerinfos.cxx:10
WTATrigObj::eta
IntOrFloat eta() const
Definition: WTAObject.h:40
WTATrigObj::m_eta
IntOrFloat m_eta
Definition: WTAObject.h:73
WTAJet::m_Jet_dR2
IntOrFloat m_Jet_dR2
Definition: WTAObject.h:128
WTATrigObj::operator<=
friend bool operator<=(const WTATrigObj &o1, const WTATrigObj &o2)
Definition: WTAObject.h:58
python.changerun.o1
o1
Definition: changerun.py:42
WTATrigObj::idx
int idx() const
Definition: WTAObject.h:46
python.PyAthena.obj
obj
Definition: PyAthena.py:132
WTATrigObj::m
void m(IntOrFloat m)
Definition: WTAObject.h:45
WTAJet::GetSeed
const WTATrigObj & GetSeed() const
Definition: WTAObject.h:117
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
WTATrigObj::operator>=
friend bool operator>=(const WTATrigObj &o1, const WTATrigObj &o2)
Definition: WTAObject.h:59
WTATrigObj::m_idx
int m_idx
Definition: WTAObject.h:76