ATLAS Offline Software
Loading...
Searching...
No Matches
JetFromPseudojet.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// JetFromPseudojet.cxx
6
9#include <iomanip>
10#include "fastjet/PseudoJet.hh"
11#include "fastjet/AreaDefinition.hh"
12#include "fastjet/ClusterSequence.hh"
15
16#include "JetEDM/FastJetLink.h"
18
19
20#include "xAODJet/JetContainerInfo.h" // DEBUG REMOVE FIXME
21
22using std::setw;
24using fastjet::PseudoJet;
26
27using PseudoJetVector = std::vector<PseudoJet>;
28
29//**********************************************************************
30
31JetFromPseudojet::JetFromPseudojet(const std::string& name)
32 : AsgTool(name), m_doArea(false), m_doFourVecArea(false) {
33 declareProperty("Attributes", m_atts);
34
35}
36
37//**********************************************************************
38
40
41 for (const std::string & att : m_atts) {
42 if ( att == "ActiveArea" ) m_doArea = true;
43 else if ( att == "ActiveArea4vec" ) m_doFourVecArea = true;
44 else if ( att == "ActiveAreaFourVector" ) m_doFourVecArea = true;
45 else ATH_MSG_WARNING("Unrecognized attribute name ignored: " << att);
46 }
47 ATH_MSG_INFO(" Record area: " << m_doArea);
48 ATH_MSG_INFO(" Record four-vector area: " << m_doFourVecArea);
49 return StatusCode::SUCCESS;
50
51}
52
53
54//**********************************************************************
57 xAOD::JetInput::Type inputtype) const {
58
59 if ( jet->getConstituentsSignalState() == xAOD::UncalibratedJetConstituent ) {
60 // If constituents are already uncalibrated, the momentum is the same.
61 jet->setJetP4(xAOD::JetEMScaleMomentum, jet->jetP4());
62 ATH_MSG_DEBUG(" EM scale momentum set to jet scale");
63 } else if (isValidConstitType(inputtype) || (inputtype == xAOD::JetInput::LCPFlow) || (inputtype == xAOD::JetInput::EMCPFlow)) {
64 // fetch and sum the uncalibrated constituent momenta
65 xAOD::JetConstituentVector vec = jet->getConstituents();
66 if(! vec.isValid() ) {
67 ATH_MSG_ERROR("Jet constituent vector is invalid. Can't set EM scale momentum");
68 return;
69 }
70
71 xAOD::JetFourMom_t emscaleSum;
73 // just sum 4-vectors:
74 ATH_MSG_VERBOSE(" Summing four vectors.");
75 for (auto it=vec.begin(uncal); it != vec.end(uncal); ++it) {
76 emscaleSum +=**it;
77 }
78
79 ATH_MSG_VERBOSE(" Setting EM scale momentum");
80 jet->setJetP4(xAOD::JetEMScaleMomentum, emscaleSum);
81 ATH_MSG_DEBUG(" EM scale momentum set with uncalibrated constituents.");
82
83 } else {
84 ATH_MSG_DEBUG(" EM scale momentum not set.");
85 }
86
87}
88
89//**********************************************************************
90
92JetFromPseudojet::add(const PseudoJet& pj,
93 const PseudoJetContainer& pjContainer,
95 xAOD::JetInput::Type inputtype) const {
96 const xAOD::Jet* pparent = nullptr;
97 xAOD::Jet* pjet = addjet(pj, pjContainer, jets, pparent);
98 if ( pjet == nullptr ) return pjet;
99 // Set the jet's input type.
100 ATH_MSG_VERBOSE("Setting input type.");
101 pjet->setInputType(inputtype);
102 // Set the jet's constituent scale.
103 // Calibrated for all but EMTopo.
104 ATH_MSG_VERBOSE("Done add with input");
105
106 //DEBUG REMOVE !! FIXME!!
107 ATH_MSG_VERBOSE("Supplied input type: " <<
108 xAOD::JetInput::typeName(inputtype));
109
110 if ( (inputtype == xAOD::JetInput::EMTopo ) ||
111 (inputtype == xAOD::JetInput::EMPFlow ) ||
112 (inputtype == xAOD::JetInput::PFlowCustomVtx ) ||
113 (inputtype == xAOD::JetInput::EMPFlowByVertex) ) {
114 ATH_MSG_VERBOSE("Setting constituent state to uncalibrated state");
116 } else {
117 ATH_MSG_VERBOSE("Setting constituent state to calibrated state");
119 }
120 // Set the jet momentum at uncalibrated constituent scale.
121 ATH_MSG_VERBOSE("Setting EM scale momentum");
122 buildAndSetEMScaleMom(pjet, inputtype );
123 ATH_MSG_VERBOSE("Done add with input");
124 return pjet;
125}
126
127//**********************************************************************
128
130JetFromPseudojet::add(const PseudoJet& pj,
131 const PseudoJetContainer& pjContainer,
132 xAOD::JetContainer& jets,
133 const xAOD::Jet* pparent) const {
134 return addjet(pj, pjContainer, jets, pparent);
135}
136
137//**********************************************************************
138
140JetFromPseudojet::addjet(const PseudoJet& pj,
141 const PseudoJetContainer& pjContainer,
142 xAOD::JetContainer& jets,
143 const xAOD::Jet* pparent) const {
144 ATH_MSG_VERBOSE("Creating jet from PseudoJet @ " << &pj);
145 double px = pj.px();
146 double py = pj.py();
147 double pz = pj.pz();
148 double e = pj.e();
149 double m = pj.m();
150 double pt = pj.pt();
151 double eta = pj.eta();
152 double phi = pj.phi_std();
153 double p2 = px*px + py*py + pz*pz;
154 double p = sqrt(p2);
155 double dpovere = p/e - 1.0;
156 if ( m < 0.0 ) {
157 if ( dpovere > 1.e-6 ) { // Worse than float rounding error
158 ATH_MSG_WARNING("...........................");
159 ATH_MSG_WARNING("Found jet with negative mass: E, p, m, p/E-1 = "
160 << e << ", " << p << ", " << m << ", " << p/e-1.0);
161 ATH_MSG_WARNING(setw(12) << "px" << setw(12) << "py" << setw(12) << "pz"
162 << setw(12) << "E" << setw(12) << "p");
163 ATH_MSG_WARNING(setw(12) << "---" << setw(12) << "---" << setw(12) << "---"
164 << setw(12) << "---" << setw(12) << "---");
165 const PseudoJetVector cons = pj.constituents();
166 for ( PseudoJetVector::const_iterator icon=cons.begin(); icon!=cons.end(); ++icon ) {
167 double cpx = icon->px();
168 double cpy = icon->py();
169 double cpz = icon->pz();
170 double ce = icon->e();
171 double cp2 = cpx*cpx + cpy*cpy + cpz*cpz;
172 double cp = sqrt(cp2);
173 ATH_MSG_WARNING(setw(12) << int(cpx) << setw(12) << int(cpy) << setw(12) << int(cpz)
174 << setw(12) << int(ce) << setw(12) << int(cp));
175 }
176 ATH_MSG_WARNING("...........................");
177 } else { // Rounding error
178 m = 0.0;
179 }
180 }
181 ATH_MSG_VERBOSE(" Jet has pT = " << pt << " MeV, m = " << m << " MeV, eta = " << eta );
182 //<< ", area = " << area << ", FV area pT = " << fvarea.Pt() << " MeV");
183 xAOD::Jet* pjet = new xAOD::Jet();
184 jets.push_back(pjet);
185 pjet->setJetP4( xAOD::JetFourMom_t(pt,eta,phi,m) );
186
187 if ( pj.associated_cluster_sequence() == nullptr ) {
188 ATH_MSG_VERBOSE("Pseudojet does not have a cluster sequence and so cannot be copied to Jet.");
189 }
190 pjet->setPseudoJet(&pj);
191
192 // Record the jet-finding momentum, i.e. the one used to find/groom the jet.
194
195 if ( m_doArea || m_doFourVecArea ) {
196 if ( pj.has_area() ) {
197 if ( m_doArea ) {
198 pjet->setAttribute("ActiveArea", pj.area());
199 ATH_MSG_VERBOSE("Recording jet area: " << pj.has_area());
200 }
201 if ( m_doFourVecArea ) {
202 fastjet::PseudoJet pja = pj.area_4vector();
203 xAOD::JetFourMom_t fvarea(pja.pt(), pja.eta(), pja.phi(), pja.m());
204 pjet->setAttribute("ActiveArea4vec", fvarea);
205 ATH_MSG_VERBOSE("Recording jet four-vector area.");
206 }
207 } else {
208 ATH_MSG_WARNING("Save of active area attribute requested for jet without area.");
209 }
210 } else {
211 if ( pj.has_area() ) {
212 ATH_MSG_VERBOSE("No area recorded for jet with area.");
213 }
214 }
215
216 const PseudoJetVector pjcons = pj.constituents();
217 ATH_MSG_VERBOSE(" Adding constituents: multiplicity is " << pjcons.size());
218 if ( pparent != nullptr ) {
219 ATH_MSG_VERBOSE(" Adding parent jet properties");
220 const JetContainer* pcon = dynamic_cast<const JetContainer*>(pparent->container());
221 if ( pcon == nullptr ) {
222 ATH_MSG_WARNING("Unable to find parent jet container.");
223 } else {
224 ATH_MSG_VERBOSE(" Creating parent link.");
225 ElementLink<JetContainer> el(*pcon, pparent->index());
226 ATH_MSG_VERBOSE(" Setting parent.");
227 pjet->setAttribute("Parent", el);
228 //pjet->setAssociatedObject("Parent", pparent);
229 }
230 ATH_MSG_VERBOSE(" Setting input type from parent.");
231 xAOD::JetInput::Type inputtype = pparent->getInputType();
232 pjet->setInputType(inputtype);
233 ATH_MSG_VERBOSE(" Setting algorithm type from parent.");
234 pjet->setAlgorithmType(pparent->getAlgorithmType());
235 ATH_MSG_VERBOSE(" Setting size parameter from parent.");
236 pjet->setSizeParameter(pparent->getSizeParameter());
237 ATH_MSG_VERBOSE(" Setting signal state from parent.");
239 ATH_MSG_VERBOSE(" Setting ghost area from parent.");
240 pjet->setAttribute("JetGhostArea", pparent->getAttribute<float>("JetGhostArea"));
241
242 ATH_MSG_VERBOSE(" Setting EM scale momentum.");
243 buildAndSetEMScaleMom(pjet, inputtype );
244 }
245 ATH_MSG_VERBOSE("Done add with parent");
246 pjContainer.extractConstituents(*pjet, pj);
247 return pjet;
248}
249
250//**********************************************************************
251
253 ATH_MSG_INFO(" Attribute count: " << m_atts.size());
254 for ( std::vector<std::string>::const_iterator inam=m_atts.begin();
255 inam!=m_atts.end(); ++inam ) {
256 const std::string& name = *inam;
257 ATH_MSG_INFO(" " << name);
258 }
259}
260
261//**********************************************************************
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
std::vector< fastjet::PseudoJet > PseudoJetVector
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual void print() const override
Print the state of the tool.
std::vector< std::string > m_atts
virtual xAOD::Jet * add(const fastjet::PseudoJet &, const PseudoJetContainer &, xAOD::JetContainer &, xAOD::JetInput::Type inputtype) const override
Method to construct an ATLAS jet from a pseudojet, input type and vector of ghost labels.
JetFromPseudojet(const std::string &name)
xAOD::Jet * addjet(const fastjet::PseudoJet &pj, const PseudoJetContainer &, xAOD::JetContainer &jets, const xAOD::Jet *pparent) const
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
void buildAndSetEMScaleMom(xAOD::Jet *jet, xAOD::JetInput::Type inputtype) const
bool extractConstituents(xAOD::Jet &, const std::vector< PseudoJet > &) const
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
A vector of jet constituents at the scale used during jet finding.
void setAlgorithmType(JetAlgorithmType::ID a)
Definition Jet_v1.cxx:258
void setAttribute(const std::string &name, const T &v)
JetAlgorithmType::ID getAlgorithmType() const
Definition Jet_v1.cxx:249
void setJetP4(const JetFourMom_t &p4)
Definition Jet_v1.cxx:171
JetConstitScale getConstituentsSignalState() const
The state at which constituents were when this jet was found.
Definition Jet_v1.cxx:136
void setConstituentsSignalState(JetConstitScale t)
Set the state at which constituents were when this jet was found. This function is called by jet buil...
Definition Jet_v1.cxx:141
float getSizeParameter() const
Definition Jet_v1.cxx:245
void setPseudoJet(const PSEUDOJET *fj)
Set the fast jet pointer.
void setSizeParameter(float p)
Definition Jet_v1.cxx:257
bool getAttribute(AttributeID type, T &value) const
Retrieve attribute moment by enum.
void setInputType(JetInput::Type t)
Definition Jet_v1.cxx:259
JetInput::Type getInputType() const
Definition Jet_v1.cxx:253
JetFourMom_t jetP4() const
The full 4-momentum of the particle : internal jet type.
Definition Jet_v1.cxx:76
const std::string & typeName(Type id)
Jet_v1 Jet
Definition of the current "jet version".
@ JetEMScaleMomentum
Definition JetTypes.h:28
@ JetConstitScaleMomentum
Definition JetTypes.h:29
JetContainer_v1 JetContainer
Definition of the current "jet container version".
JetConstitScale
Definition JetTypes.h:20
@ UncalibratedJetConstituent
Definition JetTypes.h:21
@ CalibratedJetConstituent
Definition JetTypes.h:22
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17