ATLAS Offline Software
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"
13 #include "JetEDM/PseudoJetVector.h"
15 
16 #include "JetEDM/FastJetLink.h"
18 
19 
20 #include "xAODJet/JetContainerInfo.h" // DEBUG REMOVE FIXME
21 
22 using std::setw;
23 using xAOD::JetContainer;
24 using fastjet::PseudoJet;
26 
27 using PseudoJetVector = std::vector<PseudoJet>;
28 
29 //**********************************************************************
30 
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 
91 xAOD::Jet*
92 JetFromPseudojet::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 
129 xAOD::Jet*
130 JetFromPseudojet::add(const PseudoJet& pj,
131  const PseudoJetContainer& pjContainer,
133  const xAOD::Jet* pparent) const {
134  return addjet(pj, pjContainer, jets, pparent);
135 }
136 
137 //**********************************************************************
138 
139 xAOD::Jet*
140 JetFromPseudojet::addjet(const PseudoJet& pj,
141  const PseudoJetContainer& pjContainer,
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);
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 //**********************************************************************
xAOD::JetInput::PFlowCustomVtx
@ PFlowCustomVtx
Definition: JetContainerInfo.h:97
test_pyathena.px
px
Definition: test_pyathena.py:18
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
JetContainerInfo.h
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JetFromPseudojet::m_doArea
bool m_doArea
Definition: JetFromPseudojet.h:73
PseudoJetVector.h
JetFromPseudojet::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetFromPseudojet.cxx:39
skel.it
it
Definition: skel.GENtoEVGEN.py:423
test_pyathena.pt
pt
Definition: test_pyathena.py:11
xAOD::Jet_v1::jetP4
JetFourMom_t jetP4() const
The full 4-momentum of the particle : internal jet type.
Definition: Jet_v1.cxx:76
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
PseudoJetContainer
Definition: PseudoJetContainer.h:48
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::Jet_v1::getAlgorithmType
JetAlgorithmType::ID getAlgorithmType() const
Definition: Jet_v1.cxx:249
xAOD::Jet_v1::getInputType
JetInput::Type getInputType() const
Definition: Jet_v1.cxx:253
xAOD::JetInput::typeName
const std::string & typeName(Type id)
Definition: JetContainerInfo.cxx:199
xAOD::JetInput::isValidConstitType
bool isValidConstitType(Type t)
Definition: JetContainerInfo.cxx:193
xAOD::Jet_v1::getAttribute
bool getAttribute(AttributeID type, T &value) const
Retrieve attribute moment by enum.
xAOD::JetInput::EMPFlowByVertex
@ EMPFlowByVertex
Definition: JetContainerInfo.h:98
JetFromPseudojet::JetFromPseudojet
JetFromPseudojet(const std::string &name)
Definition: JetFromPseudojet.cxx:31
xAOD::Jet_v1::setJetP4
void setJetP4(const JetFourMom_t &p4)
Definition: Jet_v1.cxx:171
JetFromPseudojet::buildAndSetEMScaleMom
void buildAndSetEMScaleMom(xAOD::Jet *jet, xAOD::JetInput::Type inputtype) const
Definition: JetFromPseudojet.cxx:56
xAOD::JetConstitScaleMomentum
@ JetConstitScaleMomentum
Definition: JetTypes.h:29
JetConstituentFiller.h
xAOD::JetInput::LCPFlow
@ LCPFlow
Definition: JetContainerInfo.h:63
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::Jet_v1::setSizeParameter
void setSizeParameter(float p)
Definition: Jet_v1.cxx:257
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::Jet_v1::getSizeParameter
float getSizeParameter() const
Definition: Jet_v1.cxx:245
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::Jet_v1::getConstituentsSignalState
JetConstitScale getConstituentsSignalState() const
The state at which constituents were when this jet was found.
Definition: Jet_v1.cxx:136
xAOD::Jet_v1::setConstituentsSignalState
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
JetFromPseudojet::addjet
xAOD::Jet * addjet(const fastjet::PseudoJet &pj, const PseudoJetContainer &, xAOD::JetContainer &jets, const xAOD::Jet *pparent) const
Definition: JetFromPseudojet.cxx:140
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
xAOD::CalibratedJetConstituent
@ CalibratedJetConstituent
Definition: JetTypes.h:22
PseudoJetContainer::extractConstituents
bool extractConstituents(xAOD::Jet &, const std::vector< PseudoJet > &) const
Definition: PseudoJetContainer.cxx:48
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
xAOD::JetInput::Type
Type
Definition: JetContainerInfo.h:54
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::JetInput::EMPFlow
@ EMPFlow
Definition: JetContainerInfo.h:64
xAOD::Jet_v1::setAttribute
void setAttribute(const std::string &name, const T &v)
xAOD::JetEMScaleMomentum
@ JetEMScaleMomentum
Definition: JetTypes.h:28
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
Amg::py
@ py
Definition: GeoPrimitives.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::JetConstitScale
JetConstitScale
Definition: JetTypes.h:20
LArNewCalib_PedestalAutoCorr.cp
cp
Definition: LArNewCalib_PedestalAutoCorr.py:175
JetFromPseudojet::add
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.
xAOD::Jet_v1::setInputType
void setInputType(JetInput::Type t)
Definition: Jet_v1.cxx:259
xAOD::JetInput::EMTopo
@ EMTopo
Definition: JetContainerInfo.h:56
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
PseudoJetVector
std::vector< fastjet::PseudoJet > PseudoJetVector
Definition: JetConstituentFiller.cxx:17
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
PseudoJetContainer.h
jet::JetConstituentFiller
Definition: JetConstituentFiller.h:27
xAOD::UncalibratedJetConstituent
@ UncalibratedJetConstituent
Definition: JetTypes.h:21
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
JetFromPseudojet::print
virtual void print() const override
Print the state of the tool.
Definition: JetFromPseudojet.cxx:252
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAOD::JetInput::EMCPFlow
@ EMCPFlow
Definition: JetContainerInfo.h:65
xAOD::JetConstituentVector
A vector of jet constituents at the scale used during jet finding.
Definition: JetConstituentVector.h:117
JetFromPseudojet.h
xAOD::JetContainer
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Definition: JetContainer.h:17
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
JetFromPseudojet::m_atts
std::vector< std::string > m_atts
Definition: JetFromPseudojet.h:71
Jet_PseudoJet.icc
xAOD::Jet_v1::setPseudoJet
void setPseudoJet(const PSEUDOJET *fj)
Set the fast jet pointer.
xAOD::Jet_v1::setAlgorithmType
void setAlgorithmType(JetAlgorithmType::ID a)
Definition: Jet_v1.cxx:258
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17
JetFromPseudojet::m_doFourVecArea
bool m_doFourVecArea
Definition: JetFromPseudojet.h:74