ATLAS Offline Software
Loading...
Searching...
No Matches
WTAConeParallelHelper.h
Go to the documentation of this file.
1/*
2* Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef WTAConeParallelHelper_h
5#define WTAConeParallelHelper_h
6
7
8
9#include "./WTAObject.h" // Use the WTAObject
10#include "./WTAConeMaker.h" // The base class
11#include <vector>
12#include <memory>
13
14#ifdef BITWISE_SIMULATION
15// 1: Integer type for bitwise simulation
16const IntOrFloat ETA_MIN = 0;
17const IntOrFloat ETA_MAX = 99;
18const IntOrFloat ETA_LEN = 100; // 100 x 64 grid
19const IntOrFloat PHI_MIN = 0;
20const IntOrFloat PHI_MAX = 63;
21const IntOrFloat PHI_LEN = 64;
22const IntOrFloat CORE_DIST = 8;
23#elif defined(FLOATING_POINT_SIMULATION)
24// 2: Floating point for athena simulation
25const IntOrFloat ETA_MIN = -2.5;
26const IntOrFloat ETA_MAX = 2.5;
27const IntOrFloat ETA_LEN = 5.0;
28const IntOrFloat PHI_MIN = -PI;
29const IntOrFloat PHI_MAX = PI;
30const IntOrFloat PHI_LEN = 2 * PI;
31const IntOrFloat CORE_DIST = 0.8;
32#else
33#error "Simulation type not defined. Define either BITWISE_SIMULATION or FLOATING_POINT_SIMULATION."
34#endif
35
37 public:
38 WTAConeParallelHelper(unsigned int block_n = 1):
39 m_BlockN(block_n), m_DivideByEta(false)
40 {SetBlockN(m_BlockN);}; // Constructor
41 ~WTAConeParallelHelper () {}; // Destructor
42
43 void SetBlockN(unsigned int block_n); // Call SetBlockN in the constructor
44 void SetDivideByEta(bool divide_by_eta){m_DivideByEta = divide_by_eta;}
45 IntOrFloat PhiWrap(IntOrFloat phi);
46 bool CheckInsideRegion(const WTATrigObj& tower, IntOrFloat min, IntOrFloat max);
47 void CreateBlocks(const std::vector<WTATrigObj>& all_towers);
48 unsigned int GetBlockN(){return m_BlockN;};
49 template<typename WTAClassType>
50 void RunParallelWTA(std::unique_ptr<WTAClassType>& AnyWTAClass); // Run this N times, without argument
51 void CheckJetInCore();
52 std::vector<WTAJet> GetAllJets();
53
54 private:
55 unsigned int m_BlockN;
57 std::vector<std::vector<WTATrigObj>> m_InputTowersPerBlock;
58 std::vector<std::vector<WTAJet>> m_OutputJetsPerBlock;
59
60};
61
62inline void WTAConeParallelHelper::SetBlockN(unsigned int block_n)
63{
64 m_BlockN = block_n;
66 for(unsigned int i = 0; i < m_BlockN; i++)
67 {
68 m_InputTowersPerBlock.emplace_back();
69 m_OutputJetsPerBlock.emplace_back();
70 }
71}
72
73inline IntOrFloat WTAConeParallelHelper::PhiWrap(IntOrFloat phi)
74{
75 while(phi >= PHI_MAX)phi -= 2*PI;
76 while(phi < PHI_MIN)phi += 2*PI;
77 return phi;
78}
79
80
81inline bool WTAConeParallelHelper::CheckInsideRegion(const WTATrigObj& tower, IntOrFloat min, IntOrFloat max)
82{
83 bool inside = false;
85 {
86 IntOrFloat this_eta = tower.eta();
87 inside = (this_eta >= min) && (this_eta < max);
88 }
89 else
90 { // Watchout for the PhiWrapping
91 IntOrFloat this_phi = PhiWrap(tower.phi());
92 IntOrFloat min_wrap = PhiWrap(min);
93 IntOrFloat max_wrap = PhiWrap(max);
94 if(min_wrap <= max_wrap){
95 inside = (this_phi >= min_wrap) && (this_phi < max_wrap);
96 }
97 else{ // E.g) Block0 has min = -PI - 0.8, max = PI + 0.8
98 inside = !((this_phi >= max_wrap) && (this_phi < min_wrap));
99 }
100 }
101 return inside;
102}
103
104inline void WTAConeParallelHelper::CreateBlocks(const std::vector<WTATrigObj>& all_towers)
105{
106 IntOrFloat BlockLow = -99;
107 IntOrFloat BlockHigh = -99;
108 const unsigned tower_n = all_towers.size();
109 for(unsigned int i = 0; i < m_BlockN; i++)
110 {
111 if(m_DivideByEta)
112 {
113 BlockLow = ETA_MIN - CORE_DIST + i * (float)(ETA_LEN / m_BlockN);
114 BlockHigh = ETA_MAX + CORE_DIST - (m_BlockN - 1 - i) * (float)(ETA_LEN / m_BlockN);
115 }
116 else
117 {
118 BlockLow = PHI_MIN - CORE_DIST + i * (float)(PHI_LEN / m_BlockN);
119 BlockHigh = PHI_MAX + CORE_DIST - (m_BlockN - 1 - i) * (float)(PHI_LEN / m_BlockN);
120 }
121 for(unsigned int t = 0; t < tower_n; t++)
122 {
123 if(CheckInsideRegion(all_towers.at(t), BlockLow, BlockHigh))
124 {
125 m_InputTowersPerBlock.at(i).push_back(all_towers.at(t));
126 }
127 }
128 }
129}
130
131
132
133template<typename WTAClassType>
134inline void WTAConeParallelHelper::RunParallelWTA(std::unique_ptr<WTAClassType>& MyWTAMakerClass)
135{
136 for(unsigned int i = 0; i < m_BlockN; i++)
137 {
138 MyWTAMakerClass->InitiateInputs(m_InputTowersPerBlock.at(i));
139 MyWTAMakerClass->SeedCleaning();
140 MyWTAMakerClass->MergeConstsToSeeds();
141 m_OutputJetsPerBlock.at(i) = MyWTAMakerClass->GetSeedList(); // Define the ith vector, not push_back
142 }
143}
144
145inline void WTAConeParallelHelper::CheckJetInCore() // DON'T CALL THIS FOR SINGLE REGION!!
146{
147 IntOrFloat BlockLow = -99;
148 IntOrFloat BlockHigh = -99;
149 std::vector<WTAJet> all_jets;
150 for(unsigned int i = 0; i < m_BlockN; i++)
151 {
152 if(m_DivideByEta)
153 {
154 BlockLow = ETA_MIN + i * (float)(ETA_LEN / m_BlockN);
155 BlockHigh = ETA_MAX - (m_BlockN - 1 - i) * (float)(ETA_LEN / m_BlockN);
156 }
157 else
158 { // Remember, Cores should be equivalent with linspace(4, PHI_MIN, PHI_MAX)
159 BlockLow = PHI_MIN + i * (float)(PHI_LEN / m_BlockN);
160 BlockHigh = PHI_MAX - (m_BlockN - 1 - i) * (float)(PHI_LEN / m_BlockN);
161 }
162 unsigned int this_block_jet_n = m_OutputJetsPerBlock.at(i).size();
163 if(this_block_jet_n) // Only run if there are jets in the ith ROI
164 {
165 for(int j = this_block_jet_n - 1; j >= 0; j--) // Because we are erasing, read from right to left
166 {
167 WTAJet jet = m_OutputJetsPerBlock.at(i).at(j);
168 if(!CheckInsideRegion(jet, BlockLow, BlockHigh))m_OutputJetsPerBlock.at(i).erase(m_OutputJetsPerBlock.at(i).begin() + j);
169 }
170 }
171 }
172}
173
174inline std::vector<WTAJet> WTAConeParallelHelper::GetAllJets()
175{
176 std::vector<WTAJet> all_jets;
177 for(unsigned int i = 0; i < m_BlockN; i++)
178 {
179 all_jets.insert(all_jets.end(), m_OutputJetsPerBlock.at(i).begin(), m_OutputJetsPerBlock.at(i).end());
180 }
181 SortByPt(all_jets);
182 return all_jets;
183}
184
185#endif
Scalar phi() const
phi method
static void SortByPt(std::vector< T > &list)
Definition WTAObject.h:23
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
std::vector< WTAJet > GetAllJets()
IntOrFloat PhiWrap(IntOrFloat phi)
std::vector< std::vector< WTAJet > > m_OutputJetsPerBlock
void RunParallelWTA(std::unique_ptr< WTAClassType > &AnyWTAClass)
WTAConeParallelHelper(unsigned int block_n=1)
void CreateBlocks(const std::vector< WTATrigObj > &all_towers)
bool CheckInsideRegion(const WTATrigObj &tower, IntOrFloat min, IntOrFloat max)
void SetBlockN(unsigned int block_n)
std::vector< std::vector< WTATrigObj > > m_InputTowersPerBlock
void SetDivideByEta(bool divide_by_eta)
IntOrFloat eta() const
Definition WTAObject.h:40
IntOrFloat phi() const
Definition WTAObject.h:42
const float PI