ATLAS Offline Software
Loading...
Searching...
No Matches
WTAConeMaker.h
Go to the documentation of this file.
1#ifndef WTAConeMaker_h
2#define WTAConeMaker_h
3
4#include <iostream>
5#include <algorithm>
6#include <map>
7#include "./WTAObject.h" // Use the WTATrigObj
8
9class WTAParameters{ // Stores common WTAParameters, should be a protected variable of WTAConeMaker class
10 public:
11 WTAParameters(IntOrFloat const_et_cut = 2000, IntOrFloat seed_et_cut = 5000, IntOrFloat jet_dr2 = R2PAR,
12 unsigned int max_const_n = 250, unsigned int max_seed_sorting_n = 50, unsigned int max_seed_n = 10, unsigned int max_const_per_jet_n = 99,
13 bool add_const_first = true) : // Takes 8 arguments, sets 9 parameters!
14 m_ConstEtCut(const_et_cut), m_SeedEtCut(seed_et_cut), m_Jet_dR2(jet_dr2), m_Iso_dR2(jet_dr2),
15 m_MaxConstN(max_const_n), m_MaxSeedSortingN(max_seed_sorting_n), m_MaxSeedN(max_seed_n), m_MaxConstPerJetN(max_const_per_jet_n),
16 m_AddConstFirst(add_const_first), m_max_input_towers(6400)
17 {}; // Constructor
18
19 void SetConstEtCut(IntOrFloat ConstEtCut){m_ConstEtCut = ConstEtCut;};
20 void SetSeedEtCut(IntOrFloat SeedEtCut){m_SeedEtCut = SeedEtCut;};
21 void SetIso_dR2(IntOrFloat Iso_dR2){m_Iso_dR2 = Iso_dR2;}; // Default is jet_are = Iso_dR2. Use this for different Isolation condition
22 void SetJet_dR2(IntOrFloat Jet_dR2){m_Jet_dR2 = Jet_dR2;};
23 void SetMaxConstN(int MaxConstN){m_MaxConstN = MaxConstN;};
24 void SetMaxSeedSortingN(int MaxSeedSortingN){m_MaxSeedSortingN = MaxSeedSortingN;};
25 void SetMaxSeedN(int MaxSeedN){m_MaxSeedN = MaxSeedN;};
26 void SetMaxConstPerJetN(int MaxConstPerJetN){m_MaxConstPerJetN = MaxConstPerJetN;};
27 void SetAddConstFirst(bool add_const_first){m_AddConstFirst = add_const_first;};
28 void SetMaxInputTowers(int max_input_towers){m_max_input_towers = max_input_towers;}
29
30 IntOrFloat GetConstEtCut(){return m_ConstEtCut;};
31 IntOrFloat GetSeedEtCut(){return m_SeedEtCut;};
32 IntOrFloat GetIso_dR2(){return m_Iso_dR2;};
33 IntOrFloat GetJet_dR2(){return m_Jet_dR2;};
34 unsigned int GetMaxConstN(){return m_MaxConstN;};
35 unsigned int GetMaxSeedSortingN(){return m_MaxSeedSortingN;};
36 unsigned int GetMaxSeedN(){return m_MaxSeedN;};
37 unsigned int GetMaxConstPerJetN(){return m_MaxConstPerJetN;};
39 unsigned int GetMaxInputTowers(){return m_max_input_towers;}
40
41 private:
42 IntOrFloat m_ConstEtCut; // What's integer unit of the GeV?
43 IntOrFloat m_SeedEtCut;
44 IntOrFloat m_Jet_dR2; // Merge Constituents < m_Jet_dR2
45 IntOrFloat m_Iso_dR2; // Merge Seeds < m_Iso_dR2
46 unsigned int m_MaxConstN; // Can take maximum 240 topotowers, and then separate them into two lists
47 unsigned int m_MaxSeedSortingN;
48 unsigned int m_MaxSeedN;
49 unsigned int m_MaxConstPerJetN;
50 bool m_AddConstFirst; // Default: True, failed seeds are insereted to the const-list first. Meaning, it will read the hard towers first
51 unsigned int m_max_input_towers;
52};
53
55 public:
56 WTAConeMaker(bool debug = false, bool verbose = false):
58 {}; // Constructor
59 virtual ~WTAConeMaker() = default; // Destructor, make it polymorphic
60
63 void ResizeSeedList();
66 void ClearLists(){m_ConstituentList.clear(); m_SeedSortingList.clear(); m_SeedList.clear();};
67 void PrintSeedList();
70 const std::vector<WTATrigObj>& GetConstituentList() const {return m_ConstituentList;}; // Access these lists whenever we need
71 const std::vector<WTATrigObj>& GetSeedSortingList() const {return m_SeedSortingList;};
72 const std::vector<WTAJet>& GetSeedList() const {return m_SeedList;};
73 std::vector<int> GetAssociateBits(WTATrigObj incoming_seed, int& max_pt_index); // Common seed-SeedList asso.bits
74
75 std::vector<WTATrigObj> LoadInputs(const std::vector<IntOrFloat>& ptVec, const std::vector<IntOrFloat>& etaVec, const std::vector<IntOrFloat>& phiVec, const std::vector<IntOrFloat>& mVec);
76 virtual void FillLists(const std::vector<WTATrigObj>& InputTowers); // Overwritten in the 2Pass
77 void InitiateInputs(const std::vector<IntOrFloat>& ptVec, const std::vector<IntOrFloat>& etaVec, const std::vector<IntOrFloat>& phiVec, const std::vector<IntOrFloat>& mVec); // LoadInputs() + FillLists()
78 void InitiateInputs(const std::vector<WTATrigObj>& InputTowers); // LoadInputs() + FillLists()
79
80 void InsertToConstList(const WTATrigObj& obj);
81 virtual void SeedCleaning(); // Do baseline cleaning
82 virtual void MergeConstsToSeeds(); // Can be overwritten
83
84 void SetDEBUG(){m_DEBUG = true;}; // Printout for debug
85 void SetVERBOSE(){m_DEBUG = true; m_VERBOSE = true;};
86 bool GetDEBUG(){return m_DEBUG;}; // Printout for debug
87 bool GetVERBOSE(){return m_VERBOSE;};
88
89 WTAParameters m_WTAConeMakerParameter; // This should be accesible, in order to update the parameters
90
91 protected:
92 std::vector<WTATrigObj> m_ConstituentList;
93 std::vector<WTATrigObj> m_SeedSortingList;
94 std::vector<WTAJet> m_SeedList; // Max top-10 seeds
95
96 bool m_DEBUG;
98
99};
100
101inline std::vector<WTATrigObj> WTAConeMaker::LoadInputs(const std::vector<IntOrFloat>& ptVec, const std::vector<IntOrFloat>& etaVec, const std::vector<IntOrFloat>& phiVec, const std::vector<IntOrFloat>& mVec)
102{
103 std::vector<WTATrigObj> input_towers;
104 unsigned int tower_n = ptVec.size();
105 for(unsigned int t = 0; t < tower_n; t++)
106 {
107 WTATrigObj this_tower(ptVec.at(t), etaVec.at(t), phiVec.at(t), mVec.at(t));
108 input_towers.push_back(this_tower);
109 }
110 return input_towers;
111
112}
113
114inline void WTAConeMaker::FillLists(const std::vector<WTATrigObj>& InputTowers) // Baseline FillLists()
115{
116 m_ConstituentList.clear(); m_SeedSortingList.clear();
117 const unsigned int MaxSeedSortingN = m_WTAConeMakerParameter.GetMaxSeedSortingN();
118 const unsigned int MaxConstN = m_WTAConeMakerParameter.GetMaxConstN();
119 const int MaxTowersToReadPerEvent = m_WTAConeMakerParameter.GetMaxInputTowers();
120 if(m_DEBUG) std::cout << "MaxTowersToReadPerEvent = " << MaxTowersToReadPerEvent << ", Size of event = " << InputTowers.size() << std::endl;
121 int nTowers = 0;
122 for(const auto& tower: InputTowers)
123 {
124 if(tower.pt() < m_WTAConeMakerParameter.GetConstEtCut())continue; // Skip Et < 2GeV
125 if(tower.pt() >= m_WTAConeMakerParameter.GetSeedEtCut())m_SeedSortingList.push_back(tower); // Harmonize >=
126 else m_ConstituentList.push_back(tower); // Initially, always put soft tower at the back of the m_ConstituentList
127
128 // We can read only first N towers out of entier event
129 nTowers++;
130 if(nTowers>MaxTowersToReadPerEvent) break;
131 }
132 if(m_SeedSortingList.size() > MaxSeedSortingN)m_SeedSortingList.resize(MaxSeedSortingN);
133 if(m_ConstituentList.size() > MaxConstN)m_ConstituentList.resize(MaxConstN); // Resize lists accordingly
134}
135
136inline void WTAConeMaker::InitiateInputs(const std::vector<IntOrFloat>& ptVec, const std::vector<IntOrFloat>& etaVec, const std::vector<IntOrFloat>& phiVec, const std::vector<IntOrFloat>& mVec)
137{
138 std::vector<WTATrigObj> InputTowers = LoadInputs(ptVec, etaVec, phiVec, mVec);
139 FillLists(InputTowers);
140 if(m_VERBOSE)std::cout << "InputN, ConstN, SeedN = " << InputTowers.size() << " , " << m_ConstituentList.size() << " , " << m_SeedSortingList.size() << std::endl;
141}
142
143inline void WTAConeMaker::InitiateInputs(const std::vector<WTATrigObj>& InputTowers)
144{
145 FillLists(InputTowers);
146 if(m_VERBOSE)std::cout << "InputN, ConstN, SeedN = " << InputTowers.size() << " , " << m_ConstituentList.size() << " , " << m_SeedSortingList.size() << std::endl;
147}
148
150{
151 int AllJetConstN = 0;
152 for(const auto& jet: m_SeedList)
153 {
154 AllJetConstN += jet.GetConstituentCount();
155 std::cout << "Jet pT, eta, phi, constN = " << jet.pt() << " , " << jet.eta() << " , " << jet.phi() << " , " << jet.GetConstituentCount() << std::endl;
156 }
157 std::cout << "PrintSeedList..." << " , SeedN, AllJetConstN, ConstN = " << m_SeedList.size() << " , " << AllJetConstN << " , " << m_ConstituentList.size() << std::endl;
158 std::cout << "+++++++++++++++++++++++++" << std::endl;
159}
160
162{
163 if(m_WTAConeMakerParameter.GetAddConstFirst())m_ConstituentList.insert(m_ConstituentList.begin(), obj); // Insert obj at the beginnning
164 else m_ConstituentList.push_back(obj); // Insert obj at the end
165}
166
168{
169 const unsigned int MaxConstN = m_WTAConeMakerParameter.GetMaxConstN();
170 while(m_ConstituentList.size() > MaxConstN)m_ConstituentList.pop_back();
171}
172
174{
175 const unsigned int MaxSeedSortingN = m_WTAConeMakerParameter.GetMaxSeedSortingN();
176 while(m_SeedSortingList.size() > MaxSeedSortingN)m_SeedSortingList.pop_back();
177}
178
180{
181 const unsigned int MaxConstPerJetN = m_WTAConeMakerParameter.GetMaxConstPerJetN();
182 while(jet.GetConstituentCount() > MaxConstPerJetN)
183 {
184 jet.PopOutLastConstituent(); // Erase the last constituent, it is NOT appended to the Const list
185 }
186}
187
189{
190 const unsigned int MaxSeedN = m_WTAConeMakerParameter.GetMaxSeedN();
191 while(m_SeedList.size() > MaxSeedN)
192 {
194 m_SeedList.pop_back();
195 }
196}
197
199{
200 WTAJet thisjet(obj.pt(), obj.eta(), obj.phi(), obj.m(), obj.idx());
201 return thisjet;
202}
203
205{
206 WTATrigObj thisobj(jet.pt(), jet.eta(), jet.phi(), jet.m(), jet.idx());
207 return thisobj;
208}
209
210inline std::vector<int> WTAConeMaker::GetAssociateBits(WTATrigObj tower, int& MaxPtIndex)
211{
212 int jet_N = m_SeedList.size();
213 std::vector<int> associate_bit(jet_N, 0);
214 IntOrFloat MaxPt = tower.pt(); MaxPtIndex = -1;
215 for(int j = 0; j < jet_N; j++)
216 {
217 if(m_VERBOSE)std::cout << "deta, dphi, dR2 = " << tower.d_eta(m_SeedList.at(j)) << " , " << tower.d_phi_MPI_PI(m_SeedList.at(j)) << " , " << tower.dR2(m_SeedList.at(j)) << std::endl;
218 if(tower.IsAssocdR(m_SeedList.at(j), m_WTAConeMakerParameter.GetIso_dR2())) // e.g) dR2 < 0.16, association
219 {
220 associate_bit.at(j) = 1;
221 if(m_SeedList.at(j).pt() > MaxPt)
222 {
223 MaxPtIndex = j;
224 MaxPt = m_SeedList.at(j).pt(); // Update the counter
225 }
226 }
227 } // associate_bit filling done
228 return associate_bit;
229}
230
232{
233 m_SeedList.clear();
234 if(m_DEBUG)std::cout << "Baseline Seed Cleaning......" << std::endl;
235 for(const auto& seed: m_SeedSortingList)
236 {
237 int jet_N = m_SeedList.size();
238 if(jet_N == 0)
239 {
240 m_SeedList.push_back(WTATrigObjToWTAJet(seed)); // Take first seed as jet
241 }
242 else
243 {
244 int MaxPtIndex = -1;
245 std::vector<int> associate_bit = GetAssociateBits(seed, MaxPtIndex); // Associate_bit filling done
246 if(std::find(associate_bit.begin(), associate_bit.end(), 1) != associate_bit.end())
247 { // When there is at least one association
248 if(MaxPtIndex == -1)
249 { // Incoming Seed is the highest et, do the seed cleaning
250 WTAJet IncomingSeedAsJet = WTATrigObjToWTAJet(seed);
251 for(int j = jet_N - 1; j >= 0; j--)
252 { // It's important to read bits from the right, lower et jets first
253 if(associate_bit.at(j) == 1)
254 { // If Incoming seed is the highest, and there is an associated old jth jet, pop out jth jet
255 InsertToConstList(WTAJetToWTATrigObj(m_SeedList.at(j))); // Move jth jet to constituent list
256 m_SeedList.erase(m_SeedList.begin() + j); // Then, erase jth jet
257 }
258 }
259 m_SeedList.push_back(std::move(IncomingSeedAsJet)); // Add this new incoming seed as Jet, well localized protojet
260 }
261 else
262 { // Incoming Seed is not the highest et, add seed to the ConstituentList
263 InsertToConstList(seed);
264 }
265 } // At least one association loop
266 else
267 { // When there is no association
268 WTAJet IncomingSeedAsJet = WTATrigObjToWTAJet(seed);
269 m_SeedList.push_back(std::move(IncomingSeedAsJet)); // Add seed to the SeedList
270 }
271 } // Main merging loop
272 SortByPt(m_SeedList); // PtSort the SeedList. This is important for Baseline seed cleaning!
273 ResizeSeedNConstLists(); // Resize SeedList, and ConstList
274 if(m_VERBOSE)PrintSeedList(); // Print SeedList, for debug
275 } // seed loop
276 if(m_DEBUG){
278 std::cout << "Baseline Seed Cleaning Done......" << std::endl;
279 }
280}
281
283{
284 for(auto constituent: m_ConstituentList)
285 {
286 for(unsigned int j = 0; j < m_SeedList.size(); j++) // Assume Seeds are pT sorted, WTA means more energetic jet eats constituent first
287 {
288 IntOrFloat dR2 = constituent.dR2(m_SeedList.at(j));
289 if(dR2 != 0 && constituent.IsAssocdR(m_SeedList.at(j), m_WTAConeMakerParameter.GetJet_dR2())) // Thistime, the condition is m_Jet_dR2, the usual R2Par, **WARNING: dR2!=0 IS TEMPORARY, NEED TO KNOW TOPOTOWER CREATION
290 {
291 m_SeedList.at(j).MergeConstituent(constituent);
292 ResizeThisJetConstituents(m_SeedList.at(j)); // Check JetConstituent N
293 break; // Break the jet loop, move to the next constituent
294 }
295 }
296 }
297}
298
299#endif
const bool debug
static void SortByPt(std::vector< T > &list)
Definition WTAObject.h:23
const std::vector< WTATrigObj > & GetConstituentList() const
bool GetDEBUG()
virtual void SeedCleaning()
void ResizeSeedNConstLists()
bool GetVERBOSE()
void ResizeThisJetConstituents(WTAJet &jet)
std::vector< WTAJet > m_SeedList
void ResizeSeedList()
WTAConeMaker(bool debug=false, bool verbose=false)
virtual void FillLists(const std::vector< WTATrigObj > &InputTowers)
void SetDEBUG()
WTAParameters m_WTAConeMakerParameter
void ResizeSeedSortingList()
void InsertToConstList(const WTATrigObj &obj)
std::vector< int > GetAssociateBits(WTATrigObj incoming_seed, int &max_pt_index)
void ResizeConstituentList()
std::vector< WTATrigObj > m_SeedSortingList
std::vector< WTATrigObj > m_ConstituentList
WTATrigObj WTAJetToWTATrigObj(const WTAJet &jet)
WTAJet WTATrigObjToWTAJet(const WTATrigObj &obj)
virtual ~WTAConeMaker()=default
void SetVERBOSE()
void ClearLists()
const std::vector< WTATrigObj > & GetSeedSortingList() const
std::vector< WTATrigObj > LoadInputs(const std::vector< IntOrFloat > &ptVec, const std::vector< IntOrFloat > &etaVec, const std::vector< IntOrFloat > &phiVec, const std::vector< IntOrFloat > &mVec)
virtual void MergeConstsToSeeds()
void PrintSeedList()
const std::vector< WTAJet > & GetSeedList() const
void InitiateInputs(const std::vector< IntOrFloat > &ptVec, const std::vector< IntOrFloat > &etaVec, const std::vector< IntOrFloat > &phiVec, const std::vector< IntOrFloat > &mVec)
IntOrFloat GetSeedEtCut()
IntOrFloat GetConstEtCut()
unsigned int m_MaxSeedSortingN
IntOrFloat m_Jet_dR2
IntOrFloat m_Iso_dR2
unsigned int GetMaxSeedN()
unsigned int m_MaxConstPerJetN
unsigned int GetMaxSeedSortingN()
IntOrFloat m_SeedEtCut
void SetMaxConstPerJetN(int MaxConstPerJetN)
IntOrFloat m_ConstEtCut
void SetAddConstFirst(bool add_const_first)
IntOrFloat GetIso_dR2()
unsigned int GetMaxInputTowers()
WTAParameters(IntOrFloat const_et_cut=2000, IntOrFloat seed_et_cut=5000, IntOrFloat jet_dr2=R2PAR, unsigned int max_const_n=250, unsigned int max_seed_sorting_n=50, unsigned int max_seed_n=10, unsigned int max_const_per_jet_n=99, bool add_const_first=true)
unsigned int GetMaxConstPerJetN()
void SetMaxConstN(int MaxConstN)
void SetIso_dR2(IntOrFloat Iso_dR2)
void SetMaxInputTowers(int max_input_towers)
IntOrFloat GetJet_dR2()
void SetSeedEtCut(IntOrFloat SeedEtCut)
unsigned int GetMaxConstN()
void SetJet_dR2(IntOrFloat Jet_dR2)
unsigned int m_max_input_towers
unsigned int m_MaxSeedN
unsigned int m_MaxConstN
void SetMaxSeedSortingN(int MaxSeedSortingN)
void SetMaxSeedN(int MaxSeedN)
void SetConstEtCut(IntOrFloat ConstEtCut)
bool GetAddConstFirst()
IntOrFloat pt() const
Definition WTAObject.h:38
IntOrFloat dR2(const WTATrigObj &o2)
Definition WTAObject.h:94
bool IsAssocdR(WTATrigObj &tower, IntOrFloat dr2)
Definition WTAObject.h:102
IntOrFloat d_eta(const WTATrigObj &o2)
Definition WTAObject.h:51
IntOrFloat d_phi_MPI_PI(const WTATrigObj &o2)
Definition WTAObject.h:87
bool verbose
Definition hcg.cxx:73