ATLAS Offline Software
JetSoftDropTools.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "fastjet/PseudoJet.hh"
8 #include "fastjet/tools/Filter.hh"
9 #include "fastjet/contrib/SoftDrop.hh"
10 #include "fastjet/contrib/RecursiveSoftDrop.hh"
11 #include "fastjet/contrib/BottomUpSoftDrop.hh"
12 #include "fastjet/Selector.hh"
13 
14 #include "JetEDM/PseudoJetVector.h"
15 
17 
18 using namespace JetGrooming;
19 
20 namespace {
21  // tool implementing the operations to convert fastjet::PseudoJet -> xAOD::Jet
22  const static PseudoJetTranslator s_pjTranslator(false, false); // false => do not save jet areas
23 
24 
25 
27  template<typename SDHELPER>
28  xAOD::Jet & buildAndInsertSDJet(SDHELPER& sdhelper, const xAOD::Jet& parentjet, const PseudoJetContainer& inpjcont, xAOD::JetContainer& outcont, PseudoJetVector& groomedpjvec ){
29 
30  const static SG::AuxElement::Accessor<const fastjet::PseudoJet*> s_pjAcc("PseudoJet");
31  const static SG::AuxElement::ConstAccessor<const fastjet::PseudoJet*> s_pjConstAcc("PseudoJet");
32 
33  // retrieve the PseudoJet from the parent :
34  const fastjet::PseudoJet& parentPJ = *s_pjConstAcc(parentjet);
35 
36  // call the sdhelper to build the groomed PSeudoJet
37  fastjet::PseudoJet groomedPJ = sdhelper(parentPJ);
38 
39  // build the xAOD::Jet from the PseudoJet, and put it in the container
40  xAOD::Jet& jet = s_pjTranslator.translate(groomedPJ, inpjcont, outcont, parentjet);
41 
42  // now assign the groomedPJ to its vector
43  // Note: the caller (JetGroomer) guarantees groomedpjvec has the correct size,
44  // however, it is not 100% sure (?) that parentjet.index()==jet.index(), so we can't assign before
45  groomedpjvec[jet.index()] = groomedPJ;
46 
47  // decorate with the pointer to the PJ we keep in the evt store.
48  // (the decoration is done in the PseudoJetTranslator but we have to redo-it here since we must point to
49  // the instance instance inside groomedpjvec)
50  s_pjAcc(jet) = & groomedpjvec[jet.index()];
51 
52  return jet;
53  }
54 }
55 
56 // a shortcut to check variable range with a 1-liner (We can't use CheckedProperty...)
57 #define CHECK_VAR_RANGE( name, var, expr ) \
58  if( ! ( expr ) ) { \
59  ATH_MSG_ERROR("Property "<< name << " = "<< var << " out of range"); \
60  return StatusCode::SUCCESS; }
61 
62 //**********************************************************************
63 
66 
67  CHECK_VAR_RANGE("ZCut", m_zcut, (m_zcut>=0)&&(m_zcut<=10.) );
68  CHECK_VAR_RANGE("beta", m_beta, (m_beta>=0)&&(m_beta<=10.) );
69  CHECK_VAR_RANGE("R0", m_R0, (m_R0>=0)&&(m_R0<=10.) );
70 
71  return StatusCode::SUCCESS;
72 }
73 
74 
75 //**********************************************************************
78  CHECK_VAR_RANGE("N", m_N, (m_zcut>-1) );
79  return StatusCode::SUCCESS;
80 }
81 
82 
83 void SoftDrop::insertGroomedJet(const xAOD::Jet& parentjet, const PseudoJetContainer& inpjcont, xAOD::JetContainer& outcont, PseudoJetVector& groomedpjvec) const {
84 
85  //configure soft drop tool
86  // see http://fastjet.hepforge.org/svn/contrib/contribs/RecursiveTools/tags/1.0.0/SoftDrop.hh
87  fastjet::contrib::SoftDrop softdropper(m_beta, m_zcut, m_R0);
88 
89  xAOD::Jet & jet = buildAndInsertSDJet(softdropper,
90  parentjet, inpjcont, outcont, groomedpjvec);
91 
92  if(m_saveSDatt) {
93  setSoftDropAttributes(jet, groomedpjvec[jet.index()].pieces().size() );
94  }
95 }
96 
97 void SoftDrop::setSoftDropAttributes(xAOD::Jet& groomedjet, int nsdsubjets) const {
98  groomedjet.setAttribute<float>("ZCut", m_zcut);
99  groomedjet.setAttribute<float>("SoftDropBeta", m_beta);
100  groomedjet.setAttribute<float>("SoftDropR0", m_R0);
101  groomedjet.setAttribute<int>("NSoftDropSubjets", nsdsubjets);
102 }
103 
104 
105 
106 
107 //**********************************************************************
108 
109 void RecSoftDrop::insertGroomedJet(const xAOD::Jet& parentjet, const PseudoJetContainer& inpjcont, xAOD::JetContainer& outcont, PseudoJetVector& groomedpjvec) const {
110 
111  //configure recursive soft drop tool
112  //https://fastjet.hepforge.org/trac/browser/contrib/contribs/RecursiveTools/tags/2.0.0-beta1
113  fastjet::contrib::RecursiveSoftDrop softdropper(m_beta, m_zcut, m_N, m_R0);
114 
115  xAOD::Jet & jet = buildAndInsertSDJet(softdropper,
116  parentjet, inpjcont, outcont, groomedpjvec);
117 
118  if(m_saveSDatt) {
119  setSoftDropAttributes(jet, groomedpjvec[jet.index()].pieces().size() );
120  jet.setAttribute<int>("RSoftDropN", m_N);
121  }
122 }
123 
124 
125 
126 //**********************************************************************
127 void BottomUpSoftDrop::insertGroomedJet(const xAOD::Jet& parentjet, const PseudoJetContainer& inpjcont, xAOD::JetContainer& outcont, PseudoJetVector& groomedpjvec) const {
128 
129  //configure recursive soft drop tool
130  //https://fastjet.hepforge.org/trac/browser/contrib/contribs/RecursiveTools/tags/2.0.0-beta1
131  fastjet::contrib::BottomUpSoftDrop softdropper(m_beta, m_zcut, m_R0);
132 
133  xAOD::Jet & jet = buildAndInsertSDJet(softdropper,
134  parentjet, inpjcont, outcont, groomedpjvec);
135 
136  if(m_saveSDatt) {
137  setSoftDropAttributes(jet, groomedpjvec[jet.index()].pieces().size() );
138  }
139 }
140 
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
CHECK_VAR_RANGE
#define CHECK_VAR_RANGE(name, var, expr)
Definition: JetSoftDropTools.cxx:57
JetSoftDropTools.h
PseudoJetVector.h
JetGrooming::SoftDrop::m_R0
Gaudi::Property< float > m_R0
Definition: JetSoftDropTools.h:62
JetGrooming
Definition: JetGroomer.h:33
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
PseudoJetContainer
Definition: PseudoJetContainer.h:48
JetGrooming::SoftDrop::setSoftDropAttributes
void setSoftDropAttributes(xAOD::Jet &groomedjet, int nsdsubjets) const
Definition: JetSoftDropTools.cxx:97
JetGrooming::SoftDrop::m_beta
Gaudi::Property< float > m_beta
Definition: JetSoftDropTools.h:61
JetGrooming::SoftDrop::insertGroomedJet
virtual void insertGroomedJet(const xAOD::Jet &, const PseudoJetContainer &, xAOD::JetContainer &, PseudoJetVector &) const override
Definition: JetSoftDropTools.cxx:83
PseudoJetTranslator
Definition: PseudoJetTranslator.h:12
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
JetGrooming::RecSoftDrop::m_N
Gaudi::Property< int > m_N
Definition: JetSoftDropTools.h:83
PseudoJetTranslator.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
JetGrooming::SoftDrop::initialize
StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetSoftDropTools.cxx:64
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::Jet_v1::setAttribute
void setAttribute(const std::string &name, const T &v)
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetGrooming::JetGroomer::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetGroomer.cxx:16
PseudoJetVector
std::vector< fastjet::PseudoJet > PseudoJetVector
Definition: JetConstituentFiller.cxx:17
JetGrooming::BottomUpSoftDrop::insertGroomedJet
virtual void insertGroomedJet(const xAOD::Jet &, const PseudoJetContainer &, xAOD::JetContainer &, PseudoJetVector &) const override final
Definition: JetSoftDropTools.cxx:127
JetGrooming::SoftDrop::m_saveSDatt
Gaudi::Property< bool > m_saveSDatt
Definition: JetSoftDropTools.h:64
JetGrooming::SoftDrop::m_zcut
Gaudi::Property< float > m_zcut
Definition: JetSoftDropTools.h:60
JetGrooming::RecSoftDrop::insertGroomedJet
virtual void insertGroomedJet(const xAOD::Jet &, const PseudoJetContainer &, xAOD::JetContainer &, PseudoJetVector &) const override final
Definition: JetSoftDropTools.cxx:109
JetGrooming::RecSoftDrop::initialize
StatusCode initialize() override final
Dummy implementation of the initialisation function.
Definition: JetSoftDropTools.cxx:76