DAS  3.0
Das Analysis System
TPS.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <array>
7 #include <algorithm>
8 #include <list>
9 #include <vector>
10 #include <numeric>
11 #include "Math/Vector2D.h"
12 #include "Math/Vector4D.h"
13 #include "Math/VectorUtil.h"
14 
16 
17 #include <darwin.h>
18 
19 namespace DE = Darwin::Exceptions;
20 
21 namespace DAS::TPS {
22 
34 template<class Jet>
35 struct MultiJets {
36 
37  std::vector<Jet> jets;
39 
41  std::array<std::array<float, 6>, 6> pt_pair_asymm_vec;
43  std::array<std::array<float, 6>, 6> pt_pair_asymm_abs;
45  std::array<std::array<float, 6>, 6> Delta_eta_pair;
47  std::array<std::array<float, 6>, 6> Delta_phi_pair;
49  std::array<std::array<float, 6>, 6> m_inv;
50 
56  float S_pt = 0, S_pt_min = 0;
57  std::array<float, 15> S_pt_perm{};
62  std::array<float, 3> S_pt_4{}, S_pt_4_min{};
64  std::array<std::array<float, 3>, 3> S_pt_4_perm;
65 
71  float S_phi = 0, S_phi_min = 0;
72  std::array<float, 15> S_phi_perm{};
77  std::array<float, 3> S_phi_4{}, S_phi_4_min{};
79  std::array<std::array<float, 3>, 3> S_phi_4_perm;
80 
81  MultiJets(const std::vector<Jet>& inputJets, int minpt):
82  jets(PhaseSpaceSelection(inputJets, minpt))
83  {
84  if (jets.size() > 1){
85  leading_dijet = make_di(jets.at(0), jets.at(1));
86  }
87  if (jets.size() >= 6) FillFeatures();
88  }
89 
90  // At least 2 jets
91  explicit operator bool() const {
92  return jets.size() > 1;
93  }
94 
95  double jetswgt() const {
96  return accumulate(jets.begin(), jets.end(), 1.0,
97  [] (float w, const Jet& j) {
98  return w * j.weights.front();
99  });
100  }
101 
102  float Ht () const
103  {
104  return accumulate(jets.begin(), jets.end(), 0.0,
105  [](float sum, const auto& jet) {
106  return sum + jet.CorrPt();
107  });
108  }
109 
110 private:
113  void FillFeatures() {
114  LoopOverPairs();
117  }
118 
120  void LoopOverPairs() {
121  for (size_t i = 0; i < 6; ++i) {
122  for (size_t j = 0; j < 6; ++j) {
123  pt_pair_asymm_abs[i][j] = abs(jets[i].CorrPt() - jets[j].CorrPt()) / (jets[i].CorrPt() + jets[j].CorrPt());
124  auto dijet = make_di(jets[i], jets[j]);
125  pt_pair_asymm_vec[i][j] = dijet.CorrPt() / (jets[i].CorrPt() + jets[j].CorrPt());
126  Delta_eta_pair[i][j] = dijet.DeltaEta();
127  Delta_phi_pair[i][j] = dijet.DeltaPhi();
128  m_inv[i][j] = dijet.CorrP4().M();
129  }
130  }
131  }
132 
135  int i = 0;
136  for (const auto& triple : jetCombinations) {
137  for (auto& pr : triple) {
138  auto dijet = make_di(jets[pr.first], jets[pr.second]);
139  S_phi_perm[i] += pow(dijet.DeltaPhi(), 2);
140  S_pt_perm[i] += pow(dijet.CorrPt() / (jets[pr.first].CorrPt() + jets[pr.second].CorrPt()), 2);
141  }
142  S_phi_perm[i] = sqrt(S_phi_perm[i] / 3.0);
143  S_pt_perm[i] = sqrt(S_pt_perm[i] / 3.0);
144  i++;
145  }
146  S_phi = std::accumulate(S_phi_perm.begin(), S_phi_perm.end(), 0.0) / static_cast<float>(S_phi_perm.size());
147  S_pt = std::accumulate(S_pt_perm.begin(), S_pt_perm.end(), 0.0) / static_cast<float>(S_pt_perm.size());
148  S_phi_min = *std::min_element(S_phi_perm.begin(), S_phi_perm.end());
149  S_pt_min = *std::min_element( S_pt_perm.begin(), S_pt_perm.end());
150  }
151 
154  std::array<std::array<int,4>, 3> group4 = {{
155  {{0, 1, 2, 3}},
156  {{0, 1, 4, 5}},
157  {{2, 3, 4, 5}}
158  }};
159  for (size_t j = 0; j < group4.size(); ++j) {
160  auto partitions = GetJetQuadPartitions(group4[j]);
161  for (size_t i = 0; i < partitions.size(); ++i) {
162  auto [p1, p2] = partitions[i];
163  auto dijet1 = make_di(jets[p1.first], jets[p1.second]);
164  auto dijet2 = make_di(jets[p2.first], jets[p2.second]);
165  float a = dijet1.CorrPt() / (jets[p1.first].CorrPt() + jets[p1.second].CorrPt());
166  float b = dijet2.CorrPt() / (jets[p2.first].CorrPt() + jets[p2.second].CorrPt());
167  S_pt_4_perm[j][i] = std::sqrt(0.5 * (pow(a, 2) + pow(b, 2)));
168  S_phi_4_perm[j][i] = std::sqrt(0.5 * (pow(dijet1.DeltaPhi(), 2) + pow(dijet2.DeltaPhi(), 2)));
169  }
170  S_pt_4[j] = std::accumulate(S_pt_4_perm[j].begin(), S_pt_4_perm[j].end(), 0.0) / static_cast<float>(S_pt_4_perm[j].size());
171  S_phi_4[j] = std::accumulate(S_phi_4_perm[j].begin(), S_phi_4_perm[j].end(), 0.0) / static_cast<float>(S_phi_4_perm[j].size());
172  S_pt_4_min[j] = *std::min_element(S_pt_4_perm[j].begin(), S_pt_4_perm[j].end());
173  S_phi_4_min[j] = *std::min_element(S_phi_4_perm[j].begin(), S_phi_4_perm[j].end());
174  }
175 
176  }
177 
178  // Generates all possible partitions of 4 jets into 2 pairs
179  std::array<std::pair<std::pair<int, int>, std::pair<int, int>>, 3>
180  GetJetQuadPartitions(const std::array<int, 4>& index) {
181  return {{
182  {{index[0], index[1]}, {index[2], index[3]}},
183  {{index[0], index[2]}, {index[1], index[3]}},
184  {{index[0], index[3]}, {index[1], index[2]}}
185  }};
186  }
187 
188  // Generates all 15 unique pairings of 6 elements (labelled 0..5),
189  // Each result is a vector of 3 std::pairs<int,int>.
190  static const std::vector<std::vector<std::pair<int, int>>>& getJetPairings() {
191  static const auto jetPairs = []() {
192  std::vector<int> elements{0, 1, 2, 3, 4, 5};
193  std::vector<std::pair<int, int>> current;
194  std::vector<std::vector<std::pair<int, int>>> results;
195 
196  // Helper function that recursively generates all ways to partition 'elements'
197  // into pairs. Each unique partition is pushed into 'allPairs' as a list of
198  // (a,b) pairs, stored in current recursion via 'current'.
199  auto pairJetsIndices = [](const std::vector<int>& elements,
200  std::vector<std::pair<int, int>>& current,
201  std::vector<std::vector<std::pair<int, int>>>& results,
202  auto&& self) -> void {
203  // If no elements remain, we've formed all pairs for this arrangement
204  if (elements.empty()) {
205  results.push_back(current);
206  return;
207  }
208  // Take the first element
209  int first = elements.front();
210  // Remaining elements
211  std::vector<int> rest(elements.begin() + 1, elements.end());
212 
213  // Try pairing 'first' with each of the others
214  for (size_t i = 0; i < rest.size(); ++i) {
215  int partner = rest[i];
216  // Add this pair to 'current'
217  current.emplace_back(first, partner);
218 
219  // Build the list for the next recursion by removing 'partner'
220  std::vector<int> next;
221  next.reserve(rest.size() - 1);
222  for (size_t j = 0; j < rest.size(); ++j) {
223  if (j != i)
224  next.push_back(rest[j]);
225  }
226 
227  // Recurse with the remaining elements
228  self(next, current, results, self);
229  current.pop_back();
230  }
231  };
232  // Start the recursion
233  pairJetsIndices(elements, current, results, pairJetsIndices);
234  return results;
235  }();
236  return jetPairs;
237  }
238 
239  // `jetCombinations` stores all possible unique ways of dividing six elements into three pairs.
240  const std::vector<std::vector<std::pair<int, int>>>& jetCombinations = getJetPairings();
241 
242 };
243 
244 } // end of namespace DAS::TPS
DAS::TPS::MultiJets::MultiJets
MultiJets(const std::vector< Jet > &inputJets, int minpt)
Definition: TPS.h:81
DAS::TPS::MultiJets::S_phi_4
std::array< float, 3 > S_phi_4
Definition: TPS.h:77
DAS::TPS::MultiJets::S_pt
float S_pt
Definition: TPS.h:56
DAS::TPS::MultiJets::m_inv
std::array< std::array< float, 6 >, 6 > m_inv
$m_{inv} = M_{i} + M_{j}$
Definition: TPS.h:49
DAS::TPS::MultiJets::Delta_eta_pair
std::array< std::array< float, 6 >, 6 > Delta_eta_pair
$\Delta \eta_{pair} = \eta_{i}-\eta_{j}$
Definition: TPS.h:45
DAS::TPS::MultiJets::jetswgt
double jetswgt() const
Definition: TPS.h:95
DAS::TPS::MultiJets::S_pt_4_min
std::array< float, 3 > S_pt_4_min
Definition: TPS.h:62
DAS::TPS::MultiJets::S_phi_4_perm
std::array< std::array< float, 3 >, 3 > S_phi_4_perm
Detailed phi balance values for all possible pairings within each 4-jet quartet.
Definition: TPS.h:79
DAS::TPS::MultiJets::pt_pair_asymm_abs
std::array< std::array< float, 6 >, 6 > pt_pair_asymm_abs
$p_{T,asymm,abs} = \frac{|\vec{p}_{T, i}|-|\vec{p}_{T, j}|}{|\vec{p}_{T, i}|+|\vec{p}_{T,...
Definition: TPS.h:43
DAS::TPS
Definition: applyEventMixing.cc:36
DAS::TPS::MultiJets::S_phi_4_min
std::array< float, 3 > S_phi_4_min
Definition: TPS.h:77
DAS::TPS::MultiJets::pt_pair_asymm_vec
std::array< std::array< float, 6 >, 6 > pt_pair_asymm_vec
$p_{T,asymm,vec} = \frac{|\vec{p}_{T, i}+\vec{p}_{T, j}|}{|\vec{p}_{T, i}|+|\vec{p}_{T,...
Definition: TPS.h:41
DAS::TPS::MultiJets::S_pt_min
float S_pt_min
Definition: TPS.h:56
DAS::TPS::MultiJets::GetJetQuadPartitions
std::array< std::pair< std::pair< int, int >, std::pair< int, int > >, 3 > GetJetQuadPartitions(const std::array< int, 4 > &index)
Definition: TPS.h:180
Jet.h
DAS::TPS::MultiJets::S_phi_perm
std::array< float, 15 > S_phi_perm
Definition: TPS.h:72
DAS::TPS::MultiJets::Delta_phi_pair
std::array< std::array< float, 6 >, 6 > Delta_phi_pair
$\Delta \phi_{pair} = \phi_{i}-\phi_{j}$
Definition: TPS.h:47
DAS::MN::minpt
static const double minpt
Definition: getMNobservables.cc:39
Darwin::Exceptions
Handling of exceptions.
Definition: darwin.h:38
DAS::TPS::MultiJets::getJetPairings
static const std::vector< std::vector< std::pair< int, int > > > & getJetPairings()
Definition: TPS.h:190
DAS::Di< const Jet, const Jet >
DAS::TPS::MultiJets::jetCombinations
const std::vector< std::vector< std::pair< int, int > > > & jetCombinations
Definition: TPS.h:240
DAS::TPS::MultiJets::S_pt_perm
std::array< float, 15 > S_pt_perm
Definition: TPS.h:57
DAS::TPS::MultiJets::FillFeatures
void FillFeatures()
Fill 6jet's member variables by calling the appropriate loop methods.
Definition: TPS.h:113
DAS::TPS::MultiJets::S_pt_4_perm
std::array< std::array< float, 3 >, 3 > S_pt_4_perm
Detailed pT balance values for all possible pairings within each 4-jet quartet.
Definition: TPS.h:64
DAS::TPS::MultiJets::LoopOverQuartets
void LoopOverQuartets()
Loops over all quartets of jets and computes the quartet-based balance observables.
Definition: TPS.h:153
DAS::TPS::MultiJets::LoopOverTriplets
void LoopOverTriplets()
Loops over all triplets of jets and computes the triplet-based balance observables.
Definition: TPS.h:134
Di.h
DAS::TPS::MultiJets::leading_dijet
Di< const Jet, const Jet > leading_dijet
Definition: TPS.h:38
DAS::TPS::PhaseSpaceSelection
std::vector< Jet > PhaseSpaceSelection(const std::vector< Jet > &jets, float minpt)
Definition: common.h:24
DAS::TPS::MultiJets::jets
std::vector< Jet > jets
Definition: TPS.h:37
DAS::TPS::MultiJets::S_phi
float S_phi
Definition: TPS.h:71
DAS::TPS::MultiJets::S_phi_min
float S_phi_min
Definition: TPS.h:71
DAS::TPS::MultiJets::Ht
float Ht() const
Definition: TPS.h:102
make_di
auto make_di(Obj1 &o1, Obj2 &o2)
Definition: Di.h:99
DAS::TPS::MultiJets::S_pt_4
std::array< float, 3 > S_pt_4
Definition: TPS.h:62
DAS::TPS::MultiJets
Definition: TPS.h:35
DAS::TPS::MultiJets::LoopOverPairs
void LoopOverPairs()
Loops over all pairs of jets and computes the pairwise features.
Definition: TPS.h:120
common.h