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 66 of file JetCalibTools_Example.cxx.

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

◆ 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 << " Example: Example --jetCalibConfig=JES_2015dataset_recommendation_Feb2016.config --jetColl=AntiKt4EMTopo --calibSeq=JetArea_Residual_Origin_EtaJES_GSC --isData=FALSE --sample=xAOD.root" << std::endl;
60 }
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
POOL::TEvent::kClassAccess
@ kClassAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:45
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:132
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
POOL::TEvent::getEntry
int getEntry(long entry)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:184
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:581
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:39
pmontree.opt
opt
Definition: pmontree.py:16
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:157
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:73
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:72
python.grid.isData
def isData(dataset)
Definition: grid.py:491
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
LArG4GenerateShowerLib.nevents
nevents
Definition: LArG4GenerateShowerLib.py:19
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31