ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
MCTruthClassifier
util
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
"
16
# include "
xAODRootAccess/TEvent.h
"
17
# include "
xAODRootAccess/TStore.h
"
18
#endif
// ROOTCORE
19
// EDM include(s):
20
#include "
xAODEgamma/ElectronContainer.h
"
21
#include "
xAODEgamma/PhotonContainer.h
"
22
#include "
MCTruthClassifier/MCTruthClassifier.h
"
23
#include "
TruthUtils/TruthClasses.h
"
24
25
#define CHECK( ARG ) \
26
do { \
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
35
int
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:
47
CHECK
(
xAOD::Init
(
APP_NAME
) );
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
APP_NAME
#define APP_NAME
Definition
BoostedXbbTag.cxx:25
TEvent.h
ElectronContainer.h
PhotonContainer.h
Init.h
MCTruthClassifier.h
TStore.h
TruthClasses.h
DataVector< xAOD::Electron_v1 >::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Definition
DataVector.h:838
MCTruthClassifier
Definition
MCTruthClassifier.h:56
MCTruthClassifier::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition
MCTruthClassifier.h:95
MCTruthClassifier::particleTruthClassifier
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::TruthParticle *, IMCTruthClassifier::Info *info) const override final
Definition
MCTruthClassifierGen.cxx:42
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:59
main
int main()
Definition
hello.cxx:18
entries
double entries
Definition
listroot.cxx:49
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition
Init.cxx:31
xAOD::ElectronContainer
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/ElectronContainer.h:17
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
CHECK
#define CHECK(ARG)
Definition
testClassifier.cxx:25
Generated on
for ATLAS Offline Software by
1.17.0