ATLAS Offline Software
Loading...
Searching...
No Matches
testClassifier.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// System include(s):
6#include <memory>
7#include <cstdlib>
8
9// ROOT include(s):
10#include <TFile.h>
11#include <TError.h>
12#include <TString.h>
13// Infrastructure include(s):
14#ifdef ROOTCORE
15# include "xAODRootAccess/Init.h"
18#endif // ROOTCORE
19// EDM include(s):
24
25#define CHECK( ARG ) \
26do { \
27 const bool result = ARG; \
28 if( ! result ) { \
29 ::Error( APP_NAME, "Failed to execute: \"%s\"", \
30#ARG ); \
31 return 1; \
32 } \
33 } while( false )
34
35int main( int argc, char* argv[] ) {
36
37 // The application's name:
38 const char* APP_NAME = argv[ 0 ];
39 // Check if we received a file name:
40 if( argc < 2 ) {
41 Error( APP_NAME, "No file name received!" );
42 Error( APP_NAME, " Usage: %s [xAOD file name]", APP_NAME );
43 return 1;
44 }
45
46 // Initialise the application:
48
49 // Open the input file:
50 const TString fileName = argv[ 1 ];
51 Info( APP_NAME, "Opening file: %s", fileName.Data() );
52 std::unique_ptr< TFile > ifile( TFile::Open( fileName, "READ" ) );
53 CHECK( ifile.get() );
54
55 // Create a TEvent object:
56 xAOD::TEvent event;
57 CHECK( event.readFrom( ifile.get() ) );
58 Info( APP_NAME, "Number of events in the file: %i",
59 static_cast< int >( event.getEntries() ) );
60
61 // Decide how many events to run over:
62 Long64_t entries = event.getEntries();
63 if( argc > 2 ) {
64 const Long64_t e = atoll( argv[ 2 ] );
65 if( e < entries ) {
66 entries = e;
67 }
68 }
69
70 MCTruthClassifier myClassifier ("myClassifier");
71 CHECK( myClassifier.initialize() );
72
73 // Loop over the events:
74 for( Long64_t entry = 0; entry < entries; ++entry ) {
75
76 // Tell the object which entry to look at:
77 event.getEntry( entry );
78
79 std::cout << "=================NEXT EVENT==========================" << std::endl;
80
81 //Electrons
82 const xAOD::ElectronContainer* electrons = 0 ;
83 CHECK( event.retrieve(electrons, "Electrons") );
84
85 xAOD::ElectronContainer::const_iterator el_it = electrons->begin();
86 xAOD::ElectronContainer::const_iterator el_it_last = electrons->end();
87 unsigned int i = 0;
88
89 for (; el_it != el_it_last; ++el_it, ++i) {
90 const xAOD::Electron* el = (*el_it);
91 std::cout << "Electron " << el << " Num " << i << std::endl;
92 std::cout << "xAOD pt = " << (*el_it)->pt() << std::endl;
93 Info (APP_NAME,"Electron #%d", i);
94 std::pair<MCTruthPartClassifier::ParticleType,MCTruthPartClassifier::ParticleOrigin>
95 classification = myClassifier.particleTruthClassifier(*el_it);
96
97 static SG::AuxElement::Accessor<int> tT("truthType") ;
98 if (tT.isAvailable(**el_it)){;
99 Info (APP_NAME,"Electron Type from Reco returns %d ", tT(**el_it) );
100 }
101 Info (APP_NAME,"Electron Type from Analysis Base returns %d ", classification.first );
102 static SG::AuxElement::Accessor<int> tO("truthOrigin") ;
103 if (tO.isAvailable(**el_it)){;
104 Info (APP_NAME,"Electron Origin from Reco returns %d ", tO(**el_it) );
105 }
106 Info (APP_NAME,"Electron Origin from Analysis Base returns %d ", classification.second );
107 }
108 Info( APP_NAME, "===>>> done processing event #%lld ",entry);
109 }
110
111 // Return gracefully:
112 return 0;
113}
114
115// LocalWords: const
#define APP_NAME
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::TruthParticle *, MCTruthPartClassifier::Info *info=nullptr) const override final
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Tool for accessing xAOD files outside of Athena.
int main()
Definition hello.cxx:18
double entries
Definition listroot.cxx:49
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Electron_v1 Electron
Definition of the current "egamma version".
#define CHECK(ARG)