ATLAS Offline Software
Loading...
Searching...
No Matches
testEGIdentificationPoints.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
14// EDM include(s):
17#include "xAODEgamma/Electron.h"
18#include "xAODEgamma/Photon.h"
20#include "PATCore/AcceptData.h"
21
27//
30// Derivation include
33
34// Infrastructure include(s):
35#ifdef ROOTCORE
36# include "xAODRootAccess/Init.h"
39#endif // ROOTCORE
40
41namespace asg{
42 ANA_MSG_HEADER (msgSelectorCheck)
43 ANA_MSG_SOURCE (msgSelectorCheck, "EgammaSelectorCheck")
44}
45
46//main test code
47int main( int argc, char* argv[] ) {
48
49 //
50 using namespace asg::msgSelectorCheck;
52 MSG::Level mylevel=MSG::INFO;
53 setMsgLevel(mylevel);
54 //
55
56 // The application's name:
57 const char* APP_NAME = argv[ 0 ];
58
59 // Check if we received a file name:
60 if( argc < 2 ) {
61 ANA_MSG_ERROR("No file name received!" );
62 ANA_MSG_ERROR( " Usage: %s [xAOD file name]");
63 return EXIT_FAILURE;
64 }
65
66 // Initialise the application:
68
69 // Open the input file:
70 const TString fileName = argv[ 1 ];
71 Info( APP_NAME, "Opening file: %s", fileName.Data() );
72 std::unique_ptr< TFile > ifile( TFile::Open( fileName, "READ" ) );
73 ANA_CHECK( ifile.get() );
74
75 // Check if we want to process Electron or Photon
76 bool isElectron = true;
77 if( argc < 4 ) {
78 Info (APP_NAME, "By default looking to Electron" );
79 } else {
80 int argv1 = atoi(argv[ 3 ]);
81 if(argv1 == 0) isElectron = false;
82 if(isElectron) Info( APP_NAME, "We are looking to Electron-ID: %i", isElectron );
83 else Info( APP_NAME, "We are looking to Photon-ID" );
84 }
85 // Create a TEvent object (persistent store)
86
88
89 // Create a TStore object (transient store)
90 xAOD::TStore trans;
91 ANA_CHECK( pers.readFrom( ifile.get() ) );
92 //
93 ANA_MSG_INFO("Number of events in the file: "<< pers.getEntries());
94
95 // Decide how many events to run over:
96 Long64_t entries = pers.getEntries();
97 if( argc > 2 ) {
98 const Long64_t e = atoll( argv[ 2 ] );
99 if( e < entries ) {
100 entries = e;
101 }
102 }
103
104
105 if (isElectron) {
106 //Medium cut based Electrons
107
108 asg::StandaloneToolHandle<IAsgElectronIsEMSelector> electronMediumIsEMSelector ("AsgElectronIsEMSelector/electronMediumIsEMSelector");
109 ANA_CHECK(electronMediumIsEMSelector.setProperty("WorkingPoint", "MediumElectron"));
110 ANA_CHECK(electronMediumIsEMSelector.setProperty("OutputLevel", mylevel));
111 ANA_CHECK(electronMediumIsEMSelector.initialize());
112
113 asg::StandaloneToolHandle<IAsgElectronLikelihoodTool> electronMediumLHSelector ("AsgElectronLikelihoodTool/electronMediumLHSelector");
114 ANA_CHECK(electronMediumLHSelector.setProperty("WorkingPoint", "MediumLHElectron"));
115 ANA_CHECK(electronMediumLHSelector.setProperty("OutputLevel", mylevel));
116 ANA_CHECK(electronMediumLHSelector.initialize());
117
118 asg::StandaloneToolHandle<IAsgElectronLikelihoodTool> electronMediumDNNSelector ("AsgElectronSelectorTool/electronMediumDNNSelector");
119 ANA_CHECK(electronMediumDNNSelector.setProperty("WorkingPoint", "MediumDNNElectron"));
120 ANA_CHECK(electronMediumDNNSelector.setProperty("OutputLevel", mylevel));
121 ANA_CHECK(electronMediumDNNSelector.initialize());
122
123 // Loop over the events:
124 for( Long64_t entry = 0; entry < entries; ++entry ) {
125
126 // Tell the object which entry to look at:
127 pers.getEntry( entry );
128 ANA_MSG_INFO("============================");
129 ANA_MSG_INFO("Event: " <<entry);
130
131 const xAOD::ElectronContainer* electrons;
132 ANA_CHECK(pers.retrieve(electrons, "Electrons"));
133
134 unsigned int counter=0;
135 for (const xAOD::Electron* el : *electrons) {
136 ANA_MSG_INFO("---------------------------");
137 ANA_MSG_INFO("Electron: " << counter);
138 ANA_MSG_INFO("Electron LH Medium accept result: " <<bool(electronMediumLHSelector->accept(el)));
139 ANA_MSG_INFO("Electron DNN Medium accept result: " <<bool(electronMediumDNNSelector->accept(el)));
140 ANA_MSG_INFO("Electron Cut Medium accept result: " <<bool(electronMediumIsEMSelector->accept(el)));
141
142 //Bitset manipulation
143 ANA_MSG_INFO("Decision as a bitset: ");
144 std::bitset<32> decision = electronMediumIsEMSelector->accept(el).getCutResultBitSet();
145 ANA_MSG_INFO("Result bitset: " <<decision);
146 std::bitset<32> isEMdecision = electronMediumIsEMSelector->accept(el).getCutResultInvertedBitSet() ;
147 ANA_MSG_INFO("isEM Result bitset: " << isEMdecision);
148 //
149 ANA_MSG_INFO("Masks: " );
150 std::bitset<32> MediumMask(egammaPID::ElectronMediumPP);
151 ANA_MSG_INFO("Medium mask: " << MediumMask);
152
153 std::bitset<32> HadLeakageOnlyMask( 0x1 << egammaPID::ClusterHadronicLeakage_Electron);
154 ANA_MSG_INFO("HadLeakageOnly mask: " << HadLeakageOnlyMask);
155 //
156 std::bitset<32> MediumWithouHadLeakageMask( egammaPID::ElectronMediumPP ^ (0x1 << egammaPID::ClusterHadronicLeakage_Electron));
157 ANA_MSG_INFO("Medium Without Had Leakage mask: " << MediumWithouHadLeakageMask);
158 //
159
160 bool passALLDecisionisem= (isEMdecision&MediumMask)==0;
161 std::bitset<32> passALLDecisionisemBitSet(isEMdecision&MediumMask);
162 ANA_MSG_INFO("Electron check all cuts via isem: "<< passALLDecisionisem << " ,bitset " << passALLDecisionisemBitSet);
163
164 bool checkOnlyHadLeakageisem= (isEMdecision&HadLeakageOnlyMask)==0;
165 std::bitset<32> checkOnlyHadLeakageisemBitSet(isEMdecision&HadLeakageOnlyMask);
166 ANA_MSG_INFO("Electron check Only Had Leakage via isem:: "<< checkOnlyHadLeakageisem << " ,bitset " << checkOnlyHadLeakageisemBitSet);
167
168 bool ignoreHadLeakageisem= (isEMdecision&MediumWithouHadLeakageMask)==0;
169 std::bitset<32> ignoreHadLeakageisemBitSet(isEMdecision&MediumWithouHadLeakageMask);
170 ANA_MSG_INFO("Electron ignore Had Leakage check all else via isem:: "<< ignoreHadLeakageisem << " ,bitset " << ignoreHadLeakageisemBitSet);
171
172 ++counter;
173
174
175 }
176 } // loop entries
177 }// is electron
178 else {
179 //Tight cut based photon
180
181 asg::StandaloneToolHandle<IAsgPhotonIsEMSelector> photonTightIsEMSelector ("AsgPhotonIsEMSelector/photonTightIsEMSelector");
182 ANA_CHECK(photonTightIsEMSelector.setProperty("WorkingPoint", "MediumPhoton"));
183 ANA_CHECK(photonTightIsEMSelector.setProperty("OutputLevel", mylevel));
184 ANA_CHECK(photonTightIsEMSelector.initialize());
185 // Loop over the events:
186 for( Long64_t entry = 0; entry < entries; ++entry ) {
187
188 // Tell the object which entry to look at:
189 pers.getEntry( entry );
190 ANA_MSG_INFO("============================");
191 ANA_MSG_INFO("Event: " <<entry);
192
193 const xAOD::PhotonContainer* photons;
194 ANA_CHECK(pers.retrieve(photons, "Photons"));
195 unsigned int counter=0;
196 for (const xAOD::Photon* ph : *photons) {
197 ANA_MSG_INFO("---------------------------");
198 ANA_MSG_INFO("Photon: " << counter);
199 ANA_MSG_INFO("Photon Tight accept result: " <<bool(photonTightIsEMSelector->accept(ph)));
200 ++counter;
201 }
202 }// loop entries
203 }
204
206 return 0;
207}
208
209
210
bool isElectron(const T &p)
Definition AtlasPID.h:202
#define APP_NAME
macros for messaging and checking status codes
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_MSG_HEADER(NAME)
for standalone code this creates a new message category
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
an "initializing" ToolHandle for stand-alone applications
StatusCode setProperty(const std::string &name, T2 &&value)
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized
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.
@ kClassAccess
Access auxiliary data using the aux containers.
::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 unsigned int ElectronMediumPP
Medium++ electron selecton.
@ ClusterHadronicLeakage_Electron
cluster leakage into the hadronic calorimeter
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".