ATLAS Offline Software
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>
7 #include <EventLoop/StatusCode.h>
8 #include <EventLoop/Worker.h>
9 
12 
14 #include "xAODJet/JetContainer.h"
15 
16 // in case we want to write the output reclustered jet collections
17 #include <EventLoop/OutputStream.h>
18 
19 // ANA_CHECK macro
21 
22 // this is needed to distribute the algorithm to the workers
23 ClassImp(JetReclusteringAlgo)
24 
25 JetReclusteringAlgo :: JetReclusteringAlgo () :
26  m_jetReclusteringTool("JetReclusteringTool/"+m_name)
27 {}
28 
29 EL::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 
44 EL::StatusCode JetReclusteringAlgo :: histInitialize () { return EL::StatusCode::SUCCESS; }
45 EL::StatusCode JetReclusteringAlgo :: fileExecute () { return EL::StatusCode::SUCCESS; }
46 EL::StatusCode JetReclusteringAlgo :: changeInput (bool /*firstFile*/) { return EL::StatusCode::SUCCESS; }
47 
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 
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 
148 EL::StatusCode JetReclusteringAlgo :: postExecute () { return EL::StatusCode::SUCCESS; }
149 
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 
162 EL::StatusCode JetReclusteringAlgo :: histFinalize () { return EL::StatusCode::SUCCESS; }
163 #endif // ROOTCORE
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
EL::OutputStream
Definition: OutputStream.h:34
JetReclusteringAlgo.h
Job.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
OutputStream.h
JetReclusteringTool.h
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
JetReclusteringTool
Definition: JetReclusteringTool.h:33
ASG_MAKE_ANA_TOOL
#define ASG_MAKE_ANA_TOOL(handle, type)
create the tool in the given tool handle
Definition: AnaToolHandle.h:690
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
ClassImp
ClassImp(xAOD::TFileChecker) namespace xAOD
Definition: TFileChecker.cxx:28
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MessageCheck.h
macros for messaging and checking status codes
file
TFile * file
Definition: tile_monitor.h:29
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
EventInfo.h
JetContainer.h
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
Worker.h
StatusCode.h
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
EL::Job
Definition: Job.h:51
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31