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