ATLAS Offline Software
Functions
JetCalibTools_Example.cxx File Reference
#include <memory>
#include "AsgTools/ToolHandle.h"
#include "AsgTools/AsgTool.h"
#include "TFile.h"
#include "POOLRootAccess/TEvent.h"
#include "StoreGate/StoreGateSvc.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODJet/JetContainer.h"
#include "xAODEventShape/EventShape.h"
#include "xAODRootAccess/tools/Message.h"
#include "xAODRootAccess/tools/ReturnCheck.h"
#include "xAODCore/tools/IOStats.h"
#include "xAODCore/tools/ReadStats.h"
#include "xAODCore/ShallowCopy.h"
#include "JetCalibTools/JetCalibrationTool.h"

Go to the source code of this file.

Functions

void usage ()
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 67 of file JetCalibTools_Example.cxx.

67  {
68 
69  using namespace asg::msgUserCode;
70  ANA_CHECK_SET_TYPE (int);
71 
72  //---------------------------------------------
73  // Declaring input variables with default values
74  //---------------------------------------------
75  std::string isData = "";
76  std::string sample = "";
77  std::string jetColl = "";
78  std::string jetCalibConfig = "";
79  std::string calibSeq = "";
80  std::string calibArea = "";
81  bool devMode = false;
82  bool isCollision = false;
83 
84  //---------------------------
85  // Decoding the user settings
86  //---------------------------
87  for (int i=1; i< argc; i++){
88 
89  std::string opt(argv[i]); std::vector< std::string > v;
90 
91  std::istringstream iss(opt);
92 
93  std::string item;
94  char delim = '=';
95 
96  while (std::getline(iss, item, delim)){
97  v.push_back(item);
98  }
99 
100  if ( opt.find("--help") != std::string::npos ) {
101  usage(); return 0;
102  }
103 
104  if ( opt.find("--sample=") != std::string::npos ) sample = v[1];
105 
106  if ( opt.find("--jetColl=") != std::string::npos ) jetColl = v[1];
107 
108  if ( opt.find("--jetCalibConfig=") != std::string::npos ) jetCalibConfig = v[1];
109 
110  if ( opt.find("--calibSeq=") != std::string::npos ) calibSeq = v[1];
111 
112  if ( opt.find("--calibArea=") != std::string::npos ) calibArea = v[1];
113 
114  if ( opt.find("--isData=") != std::string::npos ) isData = v[1];
115 
116  if ( opt.find("--devMode") != std::string::npos ) devMode = true;
117 
118  }//End: Loop over input options
119 
120  if(sample.empty()){
121  std::cout << "No input xAOD file specified, exiting" << std::endl;
122  return 1;
123  }
124  if(jetColl.empty()){
125  std::cout << "No jet collection specified, exiting" << std::endl;
126  return 1;
127  }
128  if(jetCalibConfig.empty()){
129  std::cout << "No JetCalibTools config specified, exiting" << std::endl;
130  return 1;
131  }
132  if(calibSeq.empty()){
133  std::cout << "No calibration sequence specified, exiting" << std::endl;
134  return 1;
135  }
136  if(isData.empty()){
137  std::cout << "isData not specified, exiting" << std::endl;
138  return 1;
139  }
140  else if(isData=="TRUE") isCollision = true;
141 
142  //--------------------
143  // Opening input file
144  //--------------------
145  std::unique_ptr< TFile > ifile( TFile::Open( sample.c_str(), "READ" ) );
146 
147  // Create a TEvent object.
148 #ifdef XAOD_STANDALONE
149  ANA_CHECK( xAOD::Init() );
151  ANA_CHECK( event.readFrom( ifile.get() ) );
152  ANA_MSG_WARNING(calibSeq);
153  // Create ONNX service for LargeRDNN calibration
154  asg::AsgServiceConfig config ("AthOnnx::OnnxRuntimeSvc/OnnxRuntimeSvc");
155  std::shared_ptr<AthOnnx::IOnnxRuntimeSvc> service;
156  ANA_CHECK(config.makeService (service));
157 #else // Athena "Store" is the same StoreGate used by the TEvent
159  ANA_CHECK( event.readFrom( ifile.get() ) );
160 #endif
161 
162  //----------------------------------
163  // Initialization of JetCalibTools
164  //----------------------------------
165  const std::string name_JetCalibTools = "JetCalib_Example";
166 
167  // Call the constructor
168  JetCalibrationTool jetCalibrationTool(name_JetCalibTools.c_str());
169  ANA_CHECK( jetCalibrationTool.setProperty("JetCollection",jetColl.c_str()) );
170 
171  ANA_CHECK( jetCalibrationTool.setProperty("CalibSequence",calibSeq.c_str()) );
172 
173  ANA_CHECK( jetCalibrationTool.setProperty("ConfigFile",jetCalibConfig.c_str()) );
174 
175  ANA_CHECK( jetCalibrationTool.setProperty("IsData",isCollision) );
176 
177  if(!calibArea.empty()){
178  ANA_CHECK( jetCalibrationTool.setProperty("CalibArea",calibArea.c_str()) );
179  }
180 
181  ANA_CHECK( jetCalibrationTool.setProperty("DEVmode", devMode ) );
182 
183  // Initialize the tool
184  if(!(jetCalibrationTool.initialize().isSuccess())){
185  std::cout << "Initialization of JetCalibTools failed, exiting" << std::endl;
186  return 0;
187  }
188 
189  //------------------
190  // Loop over events
191  //------------------
192 
193  const Long64_t nevents = event.getEntries();
194  for(Long64_t ievent = 0; ievent < nevents; ++ievent){
195 
196  // Load the event:
197  if( event.getEntry( ievent ) < 0 ) {
198  std::cerr << "Failed to load entry " << ievent << std::endl;
199  return 1;
200  }
201 
202  // Show status
203  if(ievent % 100==0) std::cout << "Event " << ievent << " of " << nevents << std::endl;
204 
205  // Retrieve jet container
206  const xAOD::JetContainer* jets = nullptr;
207  ANA_CHECK( event.retrieve( jets, jetColl + "Jets" ) );
208 
209  // Shallow copy
210  auto jets_shallowCopy = xAOD::shallowCopyContainer( *jets );
211 
212  // Calibrate the shallow copy
213  ANA_CHECK( jetCalibrationTool.applyCalibration( *(jets_shallowCopy.first) ) );
214 
215  delete jets_shallowCopy.first;
216  delete jets_shallowCopy.second;
217 
218  }//END: Loop over events
219 
221 
222  return 0;
223 }

◆ usage()

void usage ( )

Definition at line 49 of file JetCalibTools_Example.cxx.

49  {
50  std::cout << "Running options:" << std::endl;
51  std::cout << " --help : To get the help you're reading" << std::endl;
52  std::cout << " --jetCalibConfig= : Specify the JetCalibTools config" << std::endl;
53  std::cout << " --jetColl= : Specify the jet collection" << std::endl;
54  std::cout << " --calibSeq= : Specify the calibration sequence for JetCalibTools" << std::endl;
55  std::cout << " --calibArea : Specify the calibration area for JetCalibTools" << std::endl;
56  std::cout << " --isData=TRUE : Specify isData true for JetCalibTools" << std::endl;
57  std::cout << " --isData=FALSE : Specify isData false for JetCalibTools" << std::endl;
58  std::cout << " --sample= : Specify input xAOD" << std::endl;
59  std::cout << " --devMode : Set dev mode for calibration sequence" << std::endl;
60  std::cout << " Example: Example --jetCalibConfig=JES_2015dataset_recommendation_Feb2016.config --jetColl=AntiKt4EMTopo --calibSeq=JetArea_Residual_Origin_EtaJES_GSC --isData=FALSE --sample=xAOD.root" << std::endl;
61 }
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
python.base_data.config
config
Definition: base_data.py:21
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:101
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
POOL::TEvent::kClassAccess
@ kClassAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:46
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:113
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
usage
void usage()
Definition: JetCalibTools_Example.cxx:49
JetCalibrationTool
Definition: JetCalibrationTool.h:34
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
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:794
xAOD::ReadStats::printSmartSlimmingBranchList
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
POOL::TEvent
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:40
item
Definition: ItemListSvc.h:43
asg::AsgServiceConfig
an object that can create a AsgService
Definition: AsgServiceConfig.h:25
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
python.PyAthena.v
v
Definition: PyAthena.py:154
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
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
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:85
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31