ATLAS Offline Software
JetJvtTools_Example.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 /* **********************************************************************\
6  * *
7  * Name: JetJvtTools_Example *
8  * Purpose: Example code for JetJvtTools *
9  * *
10  * # Date Comments By *
11  * -- -------- -------------------------- ----------------------------- *
12  * 1 14/03/16 First Version J. Bossio (jbossios@cern.ch) *
13 \************************************************************************/
14 
15 // This will only run in RootCore
16 #ifdef ROOTCORE
17 
18 // System include(s):
19 #include <memory>
20 
21 #include "AsgTools/ToolHandle.h"
22 #include "AsgTools/AsgTool.h"
23 
24 // ROOT
25 #include "TFile.h"
26 
27 //xAOD EDM classes
29 #include "xAODJet/JetContainer.h"
30 #include "xAODRootAccess/Init.h"
31 #include "xAODRootAccess/TEvent.h"
32 #include "xAODRootAccess/TStore.h"
35 #include "xAODCore/tools/IOStats.h"
37 #include "xAODCore/ShallowCopy.h"
38 
39 //JetCalibrationTool
42 
43 void usage() {
44  std::cout << "Running options:" << std::endl;
45  std::cout << " --help : To get the help you're reading" << std::endl;
46  std::cout << " --jetColl= : Specify the jet collection" << std::endl;
47  std::cout << " --sample= : Specify input xAOD" << std::endl;
48  std::cout << " Example: Example --jetColl=AntiKt4EMTopo --sample=xAOD.root" << std::endl;
49 }
50 
51 //---------------
52 // Main Function
53 //---------------
54 
55 int main(int argc, char* argv[]){
56 
57  //---------------------------------------------
58  // Declaring input variables with default values
59  //---------------------------------------------
60  std::string sample = "";
61  std::string jetColl = "";
62 
63  //---------------------------
64  // Decoding the user settings
65  //---------------------------
66  for (int i=1; i< argc; i++){
67 
68  std::string opt(argv[i]); std::vector< std::string > v;
69 
70  std::istringstream iss(opt);
71 
72  std::string item;
73  char delim = '=';
74 
75  while (std::getline(iss, item, delim)){
76  v.push_back(item);
77  }
78 
79  if ( opt.find("--help") != std::string::npos ) {
80  usage(); return 0;
81  }
82 
83  if ( opt.find("--sample=") != std::string::npos ) sample = v[1];
84 
85  if ( opt.find("--jetColl=") != std::string::npos ) jetColl = v[1];
86 
87  }//End: Loop over input options
88 
89  if(sample==""){
90  std::cout << "No input xAOD file specified, exiting" << std::endl;
91  return 1;
92  }
93  if(jetColl==""){
94  std::cout << "No jet collection specified, exiting" << std::endl;
95  return 1;
96  }
97 
98  // Set up the job for xAOD access:
99  static const char* APP_NAME = "JetJvtTools_Example";
101 
102  //--------------------
103  // Opening input file
104  //--------------------
105  std::unique_ptr< TFile > ifile( TFile::Open( sample.c_str(), "READ" ) );
106 
107  // Create a TEvent object.
110 
111  // Create a transient object store. Needed for the tools.
113 
114  //----------------------------------
115  // Initialization of JetJvtTools
116  //----------------------------------
117  const std::string name_JetJvtTool = "JetJvt_Example";
118  const std::string name_JetfJvtTool = "JetfJvt_Example";
119 
120  // Call the constructor
121  JetVertexTaggerTool jvtTool(name_JetJvtTool.c_str());
122  JetForwardJvtTool fjvtTool(name_JetfJvtTool.c_str());
124  jvtTool.setProperty("JVTFileName",
125  "JetMomentTools/JVTlikelihood_20140805.root"));
126 
127  // Initialize the tool
128  if(!(jvtTool.initialize().isSuccess())){
129  std::cout << "Initialization of JetJvtTools failed, exiting" << std::endl;
130  return 0;
131  }
132  if(!(fjvtTool.initialize().isSuccess())){
133  std::cout << "Initialization of JetJvtTools failed, exiting" << std::endl;
134  return 0;
135  }
136 
137  //------------------
138  // Loop over events
139  //------------------
140 
141  const Long64_t nevents = event.getEntries();
142  for(Long64_t ievent = 0; ievent < nevents; ++ievent){
143 
144  // Load the event:
145  if( event.getEntry( ievent ) < 0 ) {
146  std::cerr << "Failed to load entry " << ievent << std::endl;
147  return 1;
148  }
149 
150  // Show status
151  if(ievent % 100==0) std::cout << "Event " << ievent << " of " << nevents << std::endl;
152 
153  // Retrieve jet container
154  const xAOD::JetContainer* jets = 0;
155  RETURN_CHECK( APP_NAME, event.retrieve( jets, jetColl + "Jets" ) );
156 
157  // Shallow copy
158  auto jets_shallowCopy = xAOD::shallowCopyContainer( *jets );
159 
160  // Iterate over the shallow copy
161  for( xAOD::Jet* jet : *( jets_shallowCopy.first ) ) {
162  jvtTool.updateJvt( *jet );
163  // Do something
164  }
165  RETURN_CHECK( APP_NAME, fjvtTool.modify(*( jets_shallowCopy.first )) );
166  delete jets_shallowCopy.first;
167  delete jets_shallowCopy.second;
168 
169  }//END: Loop over events
170 
172 
173  return 0;
174 }
175 
176 #endif
AtlCoolConsole.usage
tuple usage
Definition: AtlCoolConsole.py:443
ShallowCopy.h
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
RETURN_CHECK
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition: ReturnCheck.h:26
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
make_coralServer_rep.opt
opt
Definition: make_coralServer_rep.py:19
IOStats.h
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:100
JetForwardJvtTool.h
ReturnCheck.h
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
main
int main(int, char **)
Main class for all the CppUnit test classes
Definition: CppUnit_SGtestdriver.cxx:141
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ReadStats.h
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
POOL::TEvent::getEntry
int getEntry(long entry)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:185
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
Message.h
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
Init.h
JetVertexTaggerTool
James Frost November 2014.
Definition: JetVertexTaggerTool.h:81
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::ReadStats::printSmartSlimmingBranchList
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
item
Definition: ItemListSvc.h:43
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
JetVertexTaggerTool.h
python.PyAthena.v
v
Definition: PyAthena.py:154
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetForwardJvtTool
Definition: JetForwardJvtTool.h:37
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
JetContainer.h
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
LArG4GenerateShowerLib.nevents
nevents
Definition: LArG4GenerateShowerLib.py:19
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
ToolHandle.h
AsgTool.h
TStore.h
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31