ATLAS Offline Software
Loading...
Searching...
No Matches
JetReclusteringAlgo.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifdef ROOTCORE
6#include <EventLoop/Job.h>
8#include <EventLoop/Worker.h>
9
12
15
16// in case we want to write the output reclustered jet collections
18
19// ANA_CHECK macro
21
22// this is needed to distribute the algorithm to the workers
23ClassImp(JetReclusteringAlgo)
24
25JetReclusteringAlgo :: JetReclusteringAlgo () :
26 m_jetReclusteringTool("JetReclusteringTool/"+m_name)
27{}
28
29EL::StatusCode JetReclusteringAlgo :: setupJob (EL::Job& job)
30{
32 job.useXAOD();
33 ANA_CHECK(xAOD::Init()); // call before opening first file
34
35 if(!m_outputXAODName.empty()){
36 // write an output xAOD
37 EL::OutputStream output_xAOD(m_outputXAODName);
38 job.outputAdd(output_xAOD);
39 }
40
41 return EL::StatusCode::SUCCESS;
42}
43
44EL::StatusCode JetReclusteringAlgo :: histInitialize () { return EL::StatusCode::SUCCESS; }
45EL::StatusCode JetReclusteringAlgo :: fileExecute () { return EL::StatusCode::SUCCESS; }
46EL::StatusCode JetReclusteringAlgo :: changeInput (bool /*firstFile*/) { return EL::StatusCode::SUCCESS; }
47
48EL::StatusCode JetReclusteringAlgo :: initialize ()
49{
51 Info("initialize()", "JetReclusteringAlgo_%s", m_inputJetContainer.c_str() );
52 m_event = wk()->xaodEvent();
53 m_store = wk()->xaodStore();
54
55 if(m_rc_alg.empty()){
56 Info("setupJob()", "m_rc_alg is empty. Setting to `AntiKt` by default.");
57 m_rc_alg = "AntiKt";
58 }
59
60 if(!m_outputXAODName.empty()){
61 TFile *file = wk()->getOutputFile(m_outputXAODName);
62 if(!m_event->writeTo(file).isSuccess()){
63 Error("initialize()", "Could not set up an output file to write xAODs to.");
64 return EL::StatusCode::FAILURE;
65 }
66 }
67
68 // m_name needs to be set and unique or we have conflicts with multiple tools
69 if(m_name.empty()){
70 Error("initialize()", "m_name needs to be set and unique.");
71 return EL::StatusCode::FAILURE;
72 }
73
74 ANA_CHECK(ASG_MAKE_ANA_TOOL(m_jetReclusteringTool, JetReclusteringTool));
75 ANA_CHECK(m_jetReclusteringTool.setProperty("InputJetContainer", m_inputJetContainer));
76 ANA_CHECK(m_jetReclusteringTool.setProperty("OutputJetContainer", m_outputJetContainer));
77 ANA_CHECK(m_jetReclusteringTool.setProperty("ReclusterRadius", m_radius));
78 ANA_CHECK(m_jetReclusteringTool.setProperty("ReclusterAlgorithm", m_rc_alg));
79 ANA_CHECK(m_jetReclusteringTool.setProperty("VariableRMinRadius", m_varR_minR));
80 ANA_CHECK(m_jetReclusteringTool.setProperty("VariableRMassScale", m_varR_mass));
81 ANA_CHECK(m_jetReclusteringTool.setProperty("InputJetPtMin", m_ptMin_input));
82 ANA_CHECK(m_jetReclusteringTool.setProperty("RCJetPtMin", m_ptMin_rc));
83 ANA_CHECK(m_jetReclusteringTool.setProperty("RCJetPtFrac", m_ptFrac));
84 ANA_CHECK(m_jetReclusteringTool.setProperty("RCJetSubjetRadius", m_subjet_radius));
85 ANA_CHECK(m_jetReclusteringTool.setProperty("DoArea", m_doArea));
86 ANA_CHECK(m_jetReclusteringTool.setProperty("AreaAttributes", m_areaAttributes));
87 ANA_CHECK(m_jetReclusteringTool.retrieve());
88
89 if(m_debug) m_jetReclusteringTool->print();
90
91 return EL::StatusCode::SUCCESS;
92}
93
94
95EL::StatusCode JetReclusteringAlgo :: execute ()
96{
97 //ANA_CHECK_SET_TYPE (EL::StatusCode);
98 m_jetReclusteringTool->execute();
99
100 // print debugging information if needed
101 if(m_debug){
102 typedef xAOD::JetContainer jet_t;
103 const xAOD::JetContainer* smallRjets(nullptr);
104 const xAOD::JetContainer* reclusteredJets(nullptr);
105
106 if(m_store->contains<jet_t>(m_inputJetContainer)){
107 if(!m_store->retrieve( smallRjets, m_inputJetContainer ).isSuccess()) return EL::StatusCode::FAILURE;
108 } else if(m_event->contains<jet_t>(m_inputJetContainer)){
109 if(!m_event->retrieve( smallRjets, m_inputJetContainer ).isSuccess()) return EL::StatusCode::FAILURE;
110 } else {
111 Error("execute()", "Could not find the input jet container. That's weird.");
112 return EL::StatusCode::FAILURE;
113 }
114
115
116 if(m_store->contains<jet_t>(m_outputJetContainer)){
117 if(!m_store->retrieve( reclusteredJets, m_outputJetContainer ).isSuccess()) return EL::StatusCode::FAILURE;
118 } else if(m_event->contains<jet_t>(m_outputJetContainer)){
119 if(!m_event->retrieve( reclusteredJets, m_outputJetContainer ).isSuccess()) return EL::StatusCode::FAILURE;
120 } else {
121 Error("execute()", "Could not find the output jet container. Did the tool execute properly? Maybe it was misconfigured.");
122 return EL::StatusCode::FAILURE;
123 }
124
125 std::string printStr = "\tPt: %0.2f\tMass: %0.2f\tEta: %0.2f\tPhi: %0.2f\tNum Subjets: %zu";
126 Info("execute()", "%zu small-R jets", smallRjets->size());
127 for(const auto jet: *smallRjets)
128 Info("execute()", printStr.c_str(), jet->pt()/1000., jet->m()/1000., jet->eta(), jet->phi(), jet->numConstituents());
129
130 Info("execute()", "%zu reclustered jets", reclusteredJets->size());
131 for(const auto jet: *reclusteredJets)
132 Info("execute()", printStr.c_str(), jet->pt()/1000., jet->m()/1000., jet->eta(), jet->phi(), jet->numConstituents());
133 }
134
135
136 /* need to update later, must retrieve all objects include cluster sequence and pseudojets, and record them one at a time
137 if(!m_outputXAODName.empty()){
138 ANA_CHECK(m_event->copy( reclusteredJets, m_outputJetContainer ));
139
140 // fill the file
141 m_event->fill();
142 }
143 */
144
145 return EL::StatusCode::SUCCESS;
146}
147
148EL::StatusCode JetReclusteringAlgo :: postExecute () { return EL::StatusCode::SUCCESS; }
149
150EL::StatusCode JetReclusteringAlgo :: finalize () {
151 if(!m_outputXAODName.empty()){
152 TFile *file = wk()->getOutputFile(m_outputXAODName);
153 if(!m_event->finishWritingTo(file).isSuccess()){
154 Error("finalize()", "Could not finish writing to file... oh bother");
155 return EL::StatusCode::FAILURE;
156 }
157 }
158
159 return EL::StatusCode::SUCCESS;
160}
161
162EL::StatusCode JetReclusteringAlgo :: histFinalize () { return EL::StatusCode::SUCCESS; }
163#endif // ROOTCORE
#define ASG_MAKE_ANA_TOOL(handle, type)
create the tool in the given tool handle
macros for messaging and checking status codes
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
ClassImp(xAOD::Experimental::RFileChecker) namespace xAOD
Definition Job.h:51
::StatusCode StatusCode
StatusCode definition for legacy code.
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition Error.h:16
@ Info
Definition ZDCMsg.h:20
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
JetContainer_v1 JetContainer
Definition of the current "jet container version".
TFile * file