ATLAS Offline Software
Loading...
Searching...
No Matches
testEGChargeIDSelector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 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
14// EDM include(s):
17#include "xAODEgamma/Electron.h"
18#include "xAODEgamma/Photon.h"
19
26
27// Derivation include
30
31
32
33// Infrastructure include(s):
34#ifdef ROOTCORE
35# include "xAODRootAccess/Init.h"
38#endif // ROOTCORE
39
40//Define msg functionality using AsgMessaging
41//---------------------------------------------------
42namespace{
43 asg::AsgMessaging dummymsg("");
44}
45#define DUMMY_MSG( lvl, ARG ) {dummymsg.msg(lvl)<<ARG<<endmsg ;}
46#define MSG_DEBUG( ARG ) {DUMMY_MSG(MSG::DEBUG, ARG);}
47#define MSG_INFO( ARG ) {DUMMY_MSG(MSG::INFO, ARG);}
48#define MSG_WARNING( ARG ) {DUMMY_MSG(MSG::WARNING, ARG);}
49#define MSG_ERROR( ARG ) {DUMMY_MSG(MSG::ERROR, ARG);}
50#define MSG_FATAL( ARG ) {DUMMY_MSG(MSG::FATAL, ARG);}
51#define MSG_ABORT( ARG ) {DUMMY_MSG(MSG::FATAL, ARG); std::abort();}
52#define CHECK( ARG ) \
53 do { \
54 const bool result = ARG; \
55 if( ! result ) { \
56 MSG_ERROR("FAILED to execute" <<#ARG); \
57 return EXIT_FAILURE; \
58 } \
59 } while( false )
60//---------------------------------------------------
61
62//main test code
63int main( int argc, char* argv[] ) {
64
65 // The application's name:
66 const char* APP_NAME = argv[ 0 ];
67
68 MSG::Level mylevel=MSG::DEBUG;
69 dummymsg.msg().setLevel(mylevel);
70 dummymsg.msg().setName(APP_NAME);
71 // Check if we received a file name:
72 if( argc < 2 ) {
73 MSG_ERROR("No file name received!" );
74 MSG_ERROR( " Usage: %s [xAOD file name]");
75 return EXIT_FAILURE;
76 }
77
78 // Initialise the application:
80
81 // Open the input file:
82 const TString fileName = argv[ 1 ];
83 Info( APP_NAME, "Opening file: %s", fileName.Data() );
84 std::unique_ptr< TFile > ifile( TFile::Open( fileName, "READ" ) );
85 CHECK( ifile.get() );
86
87 // Check if we want to process Electron or Photon
88 bool isElectron = true;
89 if( argc < 4 ) {
90 Info (APP_NAME, "By default looking to Electron" );
91 } else {
92 int argv1 = atoi(argv[ 3 ]);
93 if(argv1 == 0) isElectron = false;
94 if(isElectron) Info( APP_NAME, "We are lookign to Electron-ID: %i", isElectron );
95 else Info( APP_NAME, "We are looking to Photon-ID" );
96 }
97 // Create a TEvent object (persistent store)
98
99 //For 2.4.5 testing
101 //For 2.3
102 //xAOD::TEvent pers( xAOD::TEvent::kBranchAccess );
103
104 // Create a TStore object (transient store)
105 xAOD::TStore trans;
106 CHECK( pers.readFrom( ifile.get() ) );
107 //
108 MSG_INFO("Number of events in the file: "<< pers.getEntries());
109
110 // Decide how many events to run over:
111 Long64_t entries = pers.getEntries();
112 if( argc > 2 ) {
113 const Long64_t e = atoll( argv[ 2 ] );
114 if( e < entries ) {
115 entries = e;
116 }
117 }
118
119
120 if (isElectron) {
121 //tight ECIDS
122 std::unique_ptr<AsgElectronChargeIDSelectorTool> m_electronECIDS = std::make_unique<AsgElectronChargeIDSelectorTool> ("tightECIDS");
123 std::string trainingfile = std::string(std::getenv("ROOTCOREBIN")) + "/data/ElectronPhotonSelectorTools/ECIDS_20161125for2017Moriond.root";
124 CHECK(m_electronECIDS->setProperty("TrainingFile", trainingfile));
125 CHECK(m_electronECIDS->setProperty("CutOnBDT", 0));
126 m_electronECIDS->msg().setLevel(mylevel);
127 CHECK(m_electronECIDS->initialize());
128
129 //Tight Likelihood electron
130 std::unique_ptr<AsgElectronLikelihoodTool> m_TightLH = std::make_unique<AsgElectronLikelihoodTool> ("TightLH");
131 CHECK(m_TightLH->setProperty("WorkingPoint", "TightLHElectron"));
132 m_TightLH->msg().setLevel(mylevel);
133 CHECK(m_TightLH->initialize());
134
135 // Loop over the events:
136 for( Long64_t entry = 0; entry < entries; ++entry ) {
137
138 // Tell the object which entry to look at:
139 pers.getEntry( entry );
140 MSG_INFO("============================");
141 MSG_INFO("Event: " <<entry);
142
143 const xAOD::ElectronContainer* electrons;
144 CHECK(pers.retrieve(electrons, "Electrons"));
145
146 unsigned int counter=0;
147 for (const xAOD::Electron* el : *electrons) {
148 MSG_INFO("---------------------------");
149 MSG_INFO("Electron: " << counter);
150 MSG_INFO("Electron LH Tight accept result: " <<m_TightLH->accept(el));
151 // MSG_INFO("Electron stored LH Tight: " << el->passSelection("LHTight") );
152 MSG_INFO("Electron Cut ECIDS accept result: " <<m_electronECIDS->accept(el));
153 MSG_INFO("Electron stored Tight: " << el->passSelection("Tight") );
154 ++counter;
155 }
156 } // loop entries
157
158 } // is electron
159 else {
160 //Tight cut based photon
161 std::unique_ptr<AsgPhotonIsEMSelector> m_photonTightIsEMSelector = std::make_unique<AsgPhotonIsEMSelector> ("photonTightIsEMSelector");
162 CHECK(m_photonTightIsEMSelector->setProperty("WorkingPoint", "TightPhoton"));
163 m_photonTightIsEMSelector->msg().setLevel(mylevel);
164 CHECK(m_photonTightIsEMSelector->initialize());
165
166 // Loop over the events:
167 for( Long64_t entry = 0; entry < entries; ++entry ) {
168
169 // Tell the object which entry to look at:
170 pers.getEntry( entry );
171 MSG_INFO("============================");
172 MSG_INFO("Event: " <<entry);
173
174 const xAOD::PhotonContainer* photons;
175 CHECK(pers.retrieve(photons, "Photons"));
176 unsigned int counter=0;
177 for (const xAOD::Photon* ph : *photons) {
179 MSG_INFO("---------------------------");
180 MSG_INFO("Photon: " << counter);
181 MSG_INFO("Photon Tight accept result: " <<m_photonTightIsEMSelector->accept(ph));
182 ++counter;
183 }
184 }
185 }// loop entries
186 }
187
188
190 return 0;
191}
192
193
194
bool isElectron(const T &p)
Definition AtlasPID.h:202
#define APP_NAME
Class mimicking the AthMessaging class from the offline software.
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
ReadStats & stats()
Access the object belonging to the current thread.
Definition IOStats.cxx:17
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
Tool for accessing xAOD files outside of Athena.
@ kAthenaAccess
Access containers/objects like Athena does.
::Long64_t getEntries() const
Get how many entries are available from the current input file(s)
StatusCode readFrom(::TFile *file, bool useTreeCache=true, std::string_view treeName=EVENT_TREE_NAME)
Connect the object to a new input file.
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0)
Function loading a given entry of the input TTree.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
int main()
Definition hello.cxx:18
double entries
Definition listroot.cxx:49
const uint16_t AuthorCaloTopo35
Photon reconstructed by SW CaloTopo35 seeded clusters.
Definition EgammaDefs.h:38
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".
#define MSG_INFO(ARG)
#define CHECK(ARG)
#define MSG_ERROR(ARG)