ATLAS Offline Software
Functions
test_JetQGTaggerBDT.cxx File Reference
#include <string>
#include <TFile.h>
#include <TString.h>
#include <TTree.h>
#include <TChain.h>
#include "AsgTools/StandaloneToolHandle.h"
#include "xAODCore/ShallowAuxContainer.h"
#include "xAODCore/ShallowCopy.h"
#include "xAODCore/tools/IOStats.h"
#include "BoostedJetTaggers/JetQGTaggerBDT.h"

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 34 of file test_JetQGTaggerBDT.cxx.

34  {
35 
36  ANA_CHECK_SET_TYPE (int); // makes ANA_CHECK return ints if exiting function
37 
38  // The application's name:
39  char* APP_NAME = argv[ 0 ];
40 
41  // arguments
42  TString fileName = "/eos/atlas/atlascerngroupdisk/perf-jets/ReferenceFiles/mc16_13TeV.361028.Pythia8EvtGen_A14NNPDF23LO_jetjet_JZ8W.deriv.DAOD_FTAG1.e3569_s3126_r9364_r9315_p3260/DAOD_FTAG1.12133096._000074.pool.root.1";
43  int ievent=-1;
44  int nevents=-1;
45  bool verbose=false;
46 
47 
48  Info( APP_NAME, "==============================================" );
49  Info( APP_NAME, "Usage: $> %s [xAOD file name]", APP_NAME );
50  Info( APP_NAME, " $> %s | Run on default file", APP_NAME );
51  Info( APP_NAME, " $> %s -f X | Run on xAOD file X", APP_NAME );
52  Info( APP_NAME, " $> %s -n X | X = number of events you want to run on", APP_NAME );
53  Info( APP_NAME, " $> %s -e X | X = specific number of the event to run on - for debugging", APP_NAME );
54  Info( APP_NAME, " $> %s -v | run in verbose mode ", APP_NAME );
55  Info( APP_NAME, "==============================================" );
56 
57  // Check if we received a file name:
58  if( argc < 2 ) {
59  Info( APP_NAME, "No arguments - using default file" );
60  Info( APP_NAME, "Executing on : %s", fileName.Data() );
61  }
62 
64  //::: parse the options
66  std::string options;
67  for( int i=0; i<argc; i++){
68  options+=(argv[i]);
69  }
70 
71  if(options.find("-f")!=std::string::npos){
72  for( int ipos=0; ipos<argc ; ipos++ ) {
73  if(std::string(argv[ipos]).compare("-f")==0){
74  fileName = argv[ipos+1];
75  Info( APP_NAME, "Argument (-f) : Running on file # %s", fileName.Data() );
76  break;
77  }
78  }
79  }
80 
81  if(options.find("-event")!=std::string::npos){
82  for( int ipos=0; ipos<argc ; ipos++ ) {
83  if(std::string(argv[ipos]).compare("-event")==0){
84  ievent = atoi(argv[ipos+1]);
85  Info( APP_NAME, "Argument (-event) : Running only on event # %i", ievent );
86  break;
87  }
88  }
89  }
90 
91  if(options.find("-n")!=std::string::npos){
92  for( int ipos=0; ipos<argc ; ipos++ ) {
93  if(std::string(argv[ipos]).compare("-n")==0){
94  nevents = atoi(argv[ipos+1]);
95  Info( APP_NAME, "Argument (-n) : Running on NEvents = %i", nevents );
96  break;
97  }
98  }
99  }
100 
101  if(options.find("-v")!=std::string::npos){
102  verbose=true;
103  Info( APP_NAME, "Argument (-v) : Setting verbose");
104  }
105 
106 
108  //::: initialize the application and get the event
110  if(! xAOD::Init( APP_NAME ) )
111  return 1;
112  StatusCode::enableFailure();
113 
114  // Open the input file:
115  std::unique_ptr<TFile> ifile( TFile::Open( fileName, "READ" ) );
116  if( !ifile ){
117  Error( APP_NAME, "Cannot find file %s",fileName.Data() );
118  return 1;
119  }
120  ifile->Close();
121  ifile.reset( TFile::Open( fileName, "READ" ) );
122 
123  // Create a TEvent object:
125  Info( APP_NAME, "Number of events in the file: %i", static_cast< int >( event.getEntries() ) );
126 
127  // Create a transient object store. Needed for the tools.
129 
130  // Decide how many events to run over:
131  Long64_t entries = event.getEntries();
132 
133  // Fill a validation true with the tag return value
134  std::unique_ptr<TFile> outputFile(TFile::Open( "output_JetQGTaggerBDT.root", "recreate" ));
135  int pass;
136  TTree* Tree = new TTree( "tree", "test_tree" );
137  Tree->SetDirectory( outputFile.get() );
138  Tree->Branch( "pass", &pass, "pass/I" );
139 
143 
145  //::: Tool setup
146  // setup the tool handle as per the
147  // recommendation by ASG - https://twiki.cern.ch/twiki/bin/view/AtlasProtected/AthAnalysisBase#How_to_use_AnaToolHandle
149  std::cout<<"Initializing QG BDT Tagger"<<std::endl;
151  m_Tagger.setTypeAndName("CP::JetQGTaggerBDT/MyTagger");
152  if(verbose) ANA_CHECK( m_Tagger.setProperty("OutputLevel", MSG::DEBUG) );
153  if(! m_Tagger.setProperty( "CalibArea", "JetQGTaggerBDT/Oct18/") ) return 1;
154  if(! m_Tagger.setProperty( "ConfigFile", "JetQGTaggerBDT50Gluon.dat") ) return 1;
155  if(! m_Tagger.setProperty( "UseJetVars", 0) ) return 1;
156  if(! m_Tagger.retrieve() ) return 1;
157 
159  // Loop over the events
161 
162  //weighted number of quark, gluon jets and tags
163  float w_nGluon = 0.;
164  float w_nQuark = 0.;
165  float w_nGluonTaggedANDisGluon = 0.;
166  float w_nQuarkTaggedANDisQuark = 0.;
167  float w_nGluonTaggedANDisQuark = 0.;
168  float w_nQuarkTaggedANDisGluon = 0.;
169  float eventweight = 0.;
170 
171  for( Long64_t entry = 0; entry < entries; ++entry ) {
172 
173  if( nevents!=-1 && entry > nevents ) break;
174  // Tell the object which entry to look at:
175  event.getEntry( entry );
176 
177  // Print some event information
178  const xAOD::EventInfo* evtInfo = 0;
179  if( ! event.retrieve( evtInfo, "EventInfo" ).isSuccess() ) {
180  continue;
181  }
182  if(ievent!=-1 && static_cast <int> (evtInfo->eventNumber())!=ievent) {
183  continue;
184  }
185  eventweight = evtInfo->mcEventWeight();
186 
187  // Get the jets
188  const xAOD::JetContainer* myJets = 0;
189  if( ! event.retrieve( myJets, "AntiKt4EMTopoJets" ).isSuccess() ) {
190  continue ;
191  }
192 
193  // Loop over jet container
194  for(const xAOD::Jet* jet : * myJets ){
195  int truthlabel = jet->getAttribute<int>("PartonTruthLabelID");
196  if(jet->pt()<20000 || TMath::Abs(jet->eta())>2.5 || truthlabel==-1 || truthlabel==5)
197  continue;
198  if(verbose) std::cout<<std::endl;
199 
200  ANA_CHECK( m_Tagger->tag( *jet ) );
201  if(verbose) {
202  std::cout << "Testing QG BDT Tagger " << std::endl;
203  std::cout << "RunningTag : " << jet->auxdata<bool>("Tagged") << " jet truth label: " << truthlabel << std::endl;
204  }
205 
206  //--------------------------------------------------------------------------------
207  switch (truthlabel) {
208  case -1:
209  break;
210  case 1:
211  case 2:
212  case 3:
213  case 4:
214  w_nQuark += eventweight;
215  if(jet->auxdata<bool>("Tagged")==1){
216  w_nQuarkTaggedANDisQuark += eventweight;
217  }
218  else{
219  w_nGluonTaggedANDisQuark += eventweight;
220  }
221  break;
222  case 5:
223  break;
224  case 21:
225  w_nGluon += eventweight;
226  if(jet->auxdata<bool>("Tagged")==1){
227  w_nQuarkTaggedANDisGluon += eventweight;
228  }
229  else{
230  w_nGluonTaggedANDisGluon += eventweight;
231  }
232  break;
233  default:
234  break;
235  }
236  //--------------------------------------------------------------------------------
237 
238  pass = jet->auxdata<bool>("Tagged");
239 
240  Tree->Fill();
241  }
242 
243  if( nevents!=-1 && entry%100 == 0) Info( APP_NAME, "===>>> done processing event #%i, run #%i %i events processed so far <<<===", static_cast< int >( evtInfo->eventNumber() ), static_cast< int >( evtInfo->runNumber() ), static_cast< int >( entry + 1 ) );
244  }
248 
249  if(verbose){
250  std::cout<<"gluons: "<<w_nGluon<<"\n";
251  std::cout<<"lights: "<<w_nQuark<<"\n";
252  std::cout<<"efficiencies for gluon WP:"<<"\n";
253  std::cout<<"gluon efficiency: "<<w_nGluonTaggedANDisGluon/w_nGluon<<"\n";
254  std::cout<<"quark efficiency: "<<w_nGluonTaggedANDisQuark/w_nQuark<<"\n";
255  std::cout<<"efficiencies for quark WP:"<<"\n";
256  std::cout<<"quark efficiency: "<<w_nQuarkTaggedANDisQuark/w_nQuark<<"\n";
257  std::cout<<"gluon efficiency: "<<w_nQuarkTaggedANDisGluon/w_nGluon<<"\n";
258  }
259 
260  // write the tree to the output file
261  outputFile->cd();
262  Tree->Write();
263  outputFile->Close();
264 
265  // print the branches that were used for help with smart slimming
266  std::cout<<std::endl<<std::endl;
267  std::cout<<"Smart Slimming Checker :"<<std::endl;
269  std::cout<<std::endl<<std::endl;
270 
271  return 0;
272 
273 }
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
Amg::compare
std::pair< int, int > compare(const AmgSymMatrix(N) &m1, const AmgSymMatrix(N) &m2, double precision=1e-9, bool relative=false)
compare two matrices, returns the indices of the first element that fails the condition,...
Definition: EventPrimitivesHelpers.h:109
CP::JetQGTaggerBDT::tag
virtual StatusCode tag(const xAOD::Jet &jet) const override
IBoostedJetTagger interface.
Definition: JetQGTaggerBDT.cxx:109
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
Tree
Definition: Tree.h:18
xAOD::TEvent::kAthenaAccess
@ kAthenaAccess
Access containers/objects like Athena does.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:98
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
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
compareGeometries.outputFile
string outputFile
Definition: compareGeometries.py:25
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
asg::StandaloneToolHandle::setProperty
StatusCode setProperty(const std::string &name, T2 &&value)
Definition: StandaloneToolHandle.h:105
lumiFormat.i
int i
Definition: lumiFormat.py:92
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:123
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:379
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
asg::StandaloneToolHandle::retrieve
StatusCode retrieve()
initialize the tool, will succeed if the tool was already initialized
Definition: StandaloneToolHandle.h:147
xAOD::ReadStats::printSmartSlimmingBranchList
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
asg::StandaloneToolHandle::setTypeAndName
void setTypeAndName(const std::string &typeAndName)
Definition: StandaloneToolHandle.h:101
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
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
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
DEBUG
#define DEBUG
Definition: page_access.h:11
entries
double entries
Definition: listroot.cxx:49
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
LArG4GenerateShowerLib.nevents
nevents
Definition: LArG4GenerateShowerLib.py:19
xAOD::EventInfo_v1::mcEventWeight
float mcEventWeight(size_t i=0) const
The weight of one specific MC event used in the simulation.
Definition: EventInfo_v1.cxx:203
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