ATLAS Offline Software
Loading...
Searching...
No Matches
LundVariablesTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "fastjet/JetDefinition.hh"
9
10#include <queue>
11#include <cmath> //std::atan2
12
13LundVariablesTool::LundVariablesTool(const std::string& name):
14 asg::AsgTool(name)
15 {}
16
17StatusCode LundVariablesTool::decorate(const xAOD::JetContainer& jets) const {
18 for (const xAOD::Jet* injet : jets) {
19 fastjet::PseudoJet jet;
20 int n_splits = 0;
21 std::vector<float> lund_all_lnR;
22 std::vector<float> lund_all_lnkT;
23 std::vector<float> lund_all_z;
24 std::vector<float> lund_all_kt;
25 std::vector<float> lund_all_deltaR;
26 std::vector<int> lund_all_idp1;
27 std::vector<int> lund_all_idp2;
28
29 std::vector<std::vector<LundVariablesTool::Declustering>> v_LundValues;
30 auto & constit_links = injet->constituentLinks();
31 std::vector<fastjet::PseudoJet> v_pj_constituents;
32
33 v_pj_constituents.clear();
34
35 for(size_t ij = 0; ij < injet->numConstituents(); ij++) {
36 const xAOD::FlowElement* constit = dynamic_cast<const xAOD::FlowElement*>(*constit_links[ij]);
37 if (constit) {
38 TLorentzVector tlv_const;
39 tlv_const.SetPtEtaPhiE(constit->pt() / 1.e3, constit->eta(), constit->phi(), constit->e() / 1.e3);
40
41 v_pj_constituents.push_back(fastjet::PseudoJet(tlv_const.Px(), tlv_const.Py(), tlv_const.Pz(), tlv_const.E()));
42
43 }
44 else {
45 ANA_MSG_WARNING("Failed to cast truth particle ------");
46 }
47 }
48 v_LundValues.push_back(LundVariablesTool::getLundVar(std::move(v_pj_constituents)));
49
50 std::vector<double> v_jj_pt;
51 std::vector<double> v_j1_pt;
52 std::vector<double> v_j2_pt;
53 std::vector<double> v_jj_kt;
54
55
56 for (const auto & declust : v_LundValues.at(0)){
57 v_jj_pt.push_back( declust.jj.pt() );
58 v_j1_pt.push_back( declust.j1.pt() );
59 v_j2_pt.push_back( declust.j2.pt() );
60 v_jj_kt.push_back( declust.kt );
61 }
62
63 for (int id=0; id < int(v_jj_pt.size()); id++) {
64
65 int idp1 = -1;
66 int idp2 = -1;
67
68 auto itp1 = find(v_jj_pt.begin(), v_jj_pt.end(), v_j1_pt.at(id));
69 auto itp2 = find(v_jj_pt.begin(), v_jj_pt.end(), v_j2_pt.at(id));
70
71 if (itp1 != v_jj_pt.end()) {
72 idp1 = itp1 - v_jj_pt.begin();
73 if (idp1 == id){ // in case second parent has a very very small pT
74 idp1 = -1;
75 }
76 }
77 if (itp2 != v_jj_pt.end()) {
78 idp2 = itp2 - v_jj_pt.begin();
79 }
80 v_LundValues.at(0).at(id).idp1 = idp1;
81 v_LundValues.at(0).at(id).idp2 = idp2;
82 }
83
84 n_splits = 0;
85 for (const auto& split : v_LundValues[0]) {
86 if (split.delta_R > 1e-8 && split.kt > 1e-8) {
87 // save declustering data
88 lund_all_lnR.push_back(std::log(1.0 / split.delta_R));
89 lund_all_lnkT.push_back(std::log(split.kt));
90 lund_all_z.push_back(split.z);
91 lund_all_kt.push_back(split.kt);
92 lund_all_deltaR.push_back(split.delta_R);
93 lund_all_idp1.push_back(split.idp1);
94 lund_all_idp2.push_back(split.idp2);
95 n_splits++;
96 }
97 }
98
99 // Decore the jet with the ljp variables
100 const std::string prefix = m_prefix;
101
102 // Decorators (types must match the vectors you store)
103 SG::AuxElement::Decorator<std::vector<float>> decLnR(prefix + "LundAllLnR");
104 SG::AuxElement::Decorator<std::vector<float>> decLnKT(prefix + "LundAllLnKT");
105 SG::AuxElement::Decorator<std::vector<float>> decZ(prefix + "LundAllZ");
106 SG::AuxElement::Decorator<std::vector<float>> decKt(prefix + "LundAllKt");
107 SG::AuxElement::Decorator<std::vector<float>> decDR(prefix + "LundAllDeltaR");
108
109 SG::AuxElement::Decorator<std::vector<int>> decIDP1(prefix + "LundAllIDP1");
110 SG::AuxElement::Decorator<std::vector<int>> decIDP2(prefix + "LundAllIDP2");
111
112 SG::AuxElement::Decorator<int> decNSplits(prefix + "nSplits");
113
114 decLnR(*injet) = std::move(lund_all_lnR);
115 decLnKT(*injet) = std::move(lund_all_lnkT);
116 decZ(*injet) = std::move(lund_all_z);
117 decKt(*injet) = std::move(lund_all_kt);
118 decDR(*injet) = std::move(lund_all_deltaR);
119 decIDP1(*injet) = std::move(lund_all_idp1);
120 decIDP2(*injet) = std::move(lund_all_idp2);
121 decNSplits(*injet) = n_splits;
122 }
123
124 return StatusCode::SUCCESS;
125}
126
127std::vector<LundVariablesTool::Declustering> LundVariablesTool::getLundVar( std::vector<fastjet::PseudoJet> v_jcs)
128{
129 fastjet::JetDefinition jd(fastjet::cambridge_algorithm, 1.0);
130 std::vector<LundVariablesTool::Declustering> result;
131 fastjet::ClusterSequence cs(v_jcs, jd);
132 std::vector<fastjet::PseudoJet> v_pj = sorted_by_pt(cs.inclusive_jets());
133
134 fastjet::PseudoJet j = v_pj.at(0);
135
136 std::queue< fastjet::PseudoJet > jetStack;
137 jetStack.push(j);
138
139 while ( jetStack.size() > 0 ) {
140 fastjet::PseudoJet thisJ, pJLeft, pJRight;
141 thisJ = jetStack.front();
142 jetStack.pop();
143
144 bool thisJHasParents = thisJ.has_parents(pJLeft, pJRight);
145
146 if (!thisJHasParents){
147 continue;
148 }
149
150 if (pJLeft.pt2() < pJRight.pt2()) {
151 fastjet::PseudoJet jTemp;
152 jTemp = pJLeft;
153 pJLeft = pJRight;
154 pJRight = jTemp;
155 }
156
157 jetStack.push(pJLeft);
158 jetStack.push(pJRight);
159
161
162 declust.jj = thisJ;
163 declust.j1 = pJLeft;
164 declust.j2 = pJRight;
165
166 // get info about the jet
167 declust.pt = thisJ.pt();
168 declust.m = thisJ.m();
169
170 // collect info about the declustering
171 declust.pt1 = pJLeft.pt();
172 declust.pt2 = pJRight.pt();
173 declust.eta = pJRight.eta();
174 declust.E = pJRight.E();
175 declust.delta_R = pJLeft.delta_R(pJRight);
176 declust.z = declust.pt2 / (declust.pt1 + declust.pt2);
177 declust.kt = pJRight.pt() * declust.delta_R;
178
179 declust.varphi = std::atan2(pJLeft.rap() - pJRight.rap(), pJLeft.delta_phi_to(pJRight));
180 result.push_back(std::move(declust));
181 }
182
183 return result;
184}
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
static std::vector< Declustering > getLundVar(std::vector< fastjet::PseudoJet > v_jcs)
StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
LundVariablesTool(const std::string &name)
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:576
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
virtual double pt() const override
virtual double phi() const override
The azimuthal angle ( ) of the particle.
virtual double eta() const override
The pseudorapidity ( ) of the particle.
virtual double e() const override
The total energy of the particle.
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
Jet_v1 Jet
Definition of the current "jet version".
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16
JetContainer_v1 JetContainer
Definition of the current "jet container version".