ATLAS Offline Software
SkimmingToolEXOT5.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // Based on DerivationFramework::SkimmingToolExample
7 // Author: Valentinos Christodoulou (valentinos.christodoulou@cern.ch)
9 
12 #include "xAODJet/JetContainer.h"
14 #include "xAODCore/ShallowCopy.h"
15 
16 struct DescendingPt:std::function<bool(const xAOD::IParticle*, const xAOD::IParticle*)> {
17  bool operator()(const xAOD::IParticle* l, const xAOD::IParticle* r) const {
18  return l->pt() > r->pt();
19  }
20 };
21 
22 template<typename T, typename... Args>
23 std::unique_ptr<T> make_unique(Args&&... args) {
24  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
25 }
26 
28  const std::string& n,
29  const IInterface* p) :
30  AthAlgTool(t, n, p),
31  m_ntot(0),
32  m_npass(0)
33 {
34 
35  declareInterface<DerivationFramework::ISkimmingTool>(this);
36 
37  declareProperty("JetContainer", m_jetSGKey = "AntiKt4EMTopoJets");
38 
39  declareProperty("UncalibMonoJetPtCut", m_uncalibMonoJetPt = 100000.);
40  declareProperty("MonoJetPtCut", m_monoJetPt = 100000.);
41  declareProperty("LeadingJetPtCut", m_leadingJetPt = 40000.);
42  declareProperty("SubleadingJetPtCut", m_subleadingJetPt = 40000.);
43  declareProperty("DiJetMassCut", m_Mjj = 150000.);
44 }
45 
47 }
48 
50 {
51  ATH_MSG_VERBOSE("initialize() ..");
52 
53  m_jetCalibrationTool.setTypeAndName("JetCalibrationTool/EXOT5JESTool");
54  CHECK(m_jetCalibrationTool.retrieve());
55  ATH_MSG_INFO("Retrieved tool: " << m_jetCalibrationTool);
56 
57  return StatusCode::SUCCESS;
58 }
59 
61 {
62  ATH_MSG_VERBOSE("finalize() ...");
63  ATH_MSG_INFO("Processed " << m_ntot << " events, " << m_npass << " events passed filter ");
64 
65  return StatusCode::SUCCESS;
66 
67 }
68 
70 {
71 
72  m_ntot++;
73 
74  const xAOD::EventInfo* eventInfo = nullptr;
75  ATH_CHECK(evtStore()->retrieve(eventInfo), false);
76 
77  const xAOD::JetContainer* jets = nullptr;
78  ATH_CHECK(evtStore()->retrieve(jets, m_jetSGKey), false);
79 
80  bool passUncalibMonojetCut = false;
81  bool passRecoJetCuts = false;
82  bool passTruthJetCuts = false;
83 
84  std::unique_ptr<xAOD::JetContainer> recoJets = make_unique<xAOD::JetContainer>();
85  std::unique_ptr<xAOD::JetAuxContainer> recoJetsAux = make_unique<xAOD::JetAuxContainer>();
86  recoJets->setStore(recoJetsAux.get());
87 
88  std::pair<xAOD::JetContainer*, xAOD::ShallowAuxContainer*> jets_shallowCopy = xAOD::shallowCopyContainer(*jets);
89  for (const auto jet : *jets_shallowCopy.first) {
90  if (jet->pt() > 100000.) passUncalibMonojetCut = true;
91  }
92  if (m_jetCalibrationTool->applyCalibration(*jets_shallowCopy.first).isFailure()) {
93  ATH_MSG_ERROR("Problem applying jet calibration");
94  return false;
95  }
96  for (const auto jet : *jets_shallowCopy.first) {
97  xAOD::Jet* newJet = new xAOD::Jet();
98  newJet->makePrivateStore(*jet);
99  recoJets->push_back(newJet);
100  }
101  delete jets_shallowCopy.first;
102  delete jets_shallowCopy.second;
103 
104  if (recoJets->size() > 1) std::partial_sort(recoJets->begin(), recoJets->begin()+2, recoJets->end(), DescendingPt());
105  float mjj = 0;
106  if (recoJets->size() > 1) {
107  TLorentzVector jet1 = recoJets->at(0)->p4();
108  TLorentzVector jet2 = recoJets->at(1)->p4();
109  auto dijet = jet1 + jet2;
110  mjj = dijet.M();
111  }
112  if ((recoJets->size() > 0 && recoJets->at(0)->pt() > m_monoJetPt) || (recoJets->size() > 1 && recoJets->at(0)->pt() > m_leadingJetPt && recoJets->at(1)->pt() > m_subleadingJetPt && mjj > m_Mjj)) passRecoJetCuts = true;
113 
114  if (eventInfo->eventType(xAOD::EventInfo::IS_SIMULATION)) {
115  const xAOD::JetContainer* truthJetContainer = nullptr;
116  ATH_CHECK(evtStore()->retrieve(truthJetContainer, "AntiKt4TruthJets"), false);
117 
118  std::unique_ptr<xAOD::JetContainer> truthJets = make_unique<xAOD::JetContainer>();
119  std::unique_ptr<xAOD::JetAuxContainer> truthJetsAux = make_unique<xAOD::JetAuxContainer>();
120  truthJets->setStore(truthJetsAux.get());
121 
122  for (const auto truthJet : *truthJetContainer) {
123  xAOD::Jet* newTruthJet = new xAOD::Jet();
124  newTruthJet->makePrivateStore(*truthJet);
125  truthJets->push_back(newTruthJet);
126  }
127 
128  if (truthJets->size() > 1) std::partial_sort(truthJets->begin(), truthJets->begin()+2, truthJets->end(), DescendingPt());
129  float truthMjj = 0;
130  if (truthJets->size() > 1) {
131  TLorentzVector truthJet1 = truthJets->at(0)->p4();
132  TLorentzVector truthJet2 = truthJets->at(1)->p4();
133  auto truthDijet = truthJet1 + truthJet2;
134  truthMjj = truthDijet.M();
135  }
136  if ((truthJets->size() > 0 && truthJets->at(0)->pt() > m_monoJetPt) || (truthJets->size() > 1 && truthJets->at(0)->pt() > m_leadingJetPt && truthJets->at(1)->pt() > m_subleadingJetPt && truthMjj > m_Mjj)) passTruthJetCuts = true;
137  }
138 
139  bool acceptEvent = passUncalibMonojetCut || passRecoJetCuts || passTruthJetCuts;
140 
141  m_npass++;
142  return acceptEvent;
143 
144 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ShallowCopy.h
beamspotman.r
def r
Definition: beamspotman.py:676
SkimmingToolEXOT5.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::SkimmingToolEXOT5::eventPassesFilter
virtual bool eventPassesFilter() const override
Check that the current event passes this filter.
Definition: SkimmingToolEXOT5.cxx:69
DerivationFramework::SkimmingToolEXOT5::m_Mjj
double m_Mjj
Definition: SkimmingToolEXOT5.h:43
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Args
Definition: test_lwtnn_fastgraph.cxx:12
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
DescendingPt
Definition: SkimmingToolEXOT5.cxx:16
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
DerivationFramework::SkimmingToolEXOT5::m_subleadingJetPt
double m_subleadingJetPt
Definition: SkimmingToolEXOT5.h:42
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::SkimmingToolEXOT5::finalize
virtual StatusCode finalize() override
Definition: SkimmingToolEXOT5.cxx:60
DerivationFramework::SkimmingToolEXOT5::m_monoJetPt
double m_monoJetPt
Definition: SkimmingToolEXOT5.h:40
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework::SkimmingToolEXOT5::m_jetSGKey
std::string m_jetSGKey
Definition: SkimmingToolEXOT5.h:37
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DescendingPt::operator()
bool operator()(const xAOD::IParticle *l, const xAOD::IParticle *r) const
Definition: SkimmingToolEXOT5.cxx:17
DerivationFramework::SkimmingToolEXOT5::SkimmingToolEXOT5
SkimmingToolEXOT5(const std::string &t, const std::string &n, const IInterface *p)
Definition: SkimmingToolEXOT5.cxx:27
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:172
DerivationFramework::SkimmingToolEXOT5::m_uncalibMonoJetPt
double m_uncalibMonoJetPt
Definition: SkimmingToolEXOT5.h:39
DerivationFramework::SkimmingToolEXOT5::initialize
virtual StatusCode initialize() override
Definition: SkimmingToolEXOT5.cxx:49
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
DerivationFramework::SkimmingToolEXOT5::m_leadingJetPt
double m_leadingJetPt
Definition: SkimmingToolEXOT5.h:41
JetContainer.h
JetAuxContainer.h
DerivationFramework::SkimmingToolEXOT5::~SkimmingToolEXOT5
~SkimmingToolEXOT5()
Definition: SkimmingToolEXOT5.cxx:46
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
AthAlgTool
Definition: AthAlgTool.h:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.