ATLAS Offline Software
Loading...
Searching...
No Matches
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
30#include "xAODRootAccess/Init.h"
38
39//JetCalibrationTool
42
43void 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
55int 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.
109 RETURN_CHECK( APP_NAME, event.readFrom( ifile.get() ) );
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
#define APP_NAME
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition ReturnCheck.h:26
James Frost November 2014.
ReadStats & stats()
Access the object belonging to the current thread.
Definition IOStats.cxx:17
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
StatusCode usage()
int main()
Definition hello.cxx:18
TestStore store
Definition TestStore.cxx:23
Jet_v1 Jet
Definition of the current "jet version".
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.
JetContainer_v1 JetContainer
Definition of the current "jet container version".