ATLAS Offline Software
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
28 #include "xAODCore/tools/IOStats.h"
30 
31 
32 
33 // Infrastructure include(s):
34 #ifdef ROOTCORE
35 # include "xAODRootAccess/Init.h"
36 # include "xAODRootAccess/TEvent.h"
37 # include "xAODRootAccess/TStore.h"
38 #endif // ROOTCORE
39 
40 //Define msg functionality using AsgMessaging
41 //---------------------------------------------------
42 namespace{
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
63 int 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 
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) {
178  if(ph->author() != xAOD::EgammaParameters::AuthorCaloTopo35){
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 
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
AsgPhotonIsEMSelector::initialize
virtual StatusCode initialize()
AlgTool initialize method.
Definition: AsgPhotonIsEMSelector.cxx:89
AsgElectronLikelihoodTool.h
main
int main(int argc, char *argv[])
Definition: testEGChargeIDSelector.cxx:63
MSG_INFO
#define MSG_INFO(ARG)
Definition: testEGChargeIDSelector.cxx:47
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
AsgForwardElectronIsEMSelector.h
xAOD::TEvent::kAthenaAccess
@ kAthenaAccess
Access containers/objects like Athena does.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:98
AsgElectronLikelihoodTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *part) const override final
The main accept method: using the generic interface.
Definition: AsgElectronLikelihoodTool.cxx:868
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
IOStats.h
MSG_ERROR
#define MSG_ERROR(ARG)
Definition: testEGChargeIDSelector.cxx:49
AsgMessaging.h
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ReadStats.h
AsgElectronChargeIDSelectorTool::initialize
virtual StatusCode initialize() override
Gaudi Service Interface method implementations.
Definition: AsgElectronChargeIDSelectorTool.cxx:81
ElectronContainer.h
AsgPhotonIsEMSelector::accept
virtual asg::AcceptData accept(const xAOD::IParticle *part) const
Accept with generic interface.
Definition: AsgPhotonIsEMSelector.cxx:227
xAOD::EgammaParameters::AuthorCaloTopo35
const uint16_t AuthorCaloTopo35
Photon reconstructed by SW CaloTopo35 seeded clusters.
Definition: EgammaDefs.h:38
Photon.h
xAOD::TEvent::getEntries
::Long64_t getEntries() const
Get how many entries are available from the current input file(s)
Definition: Control/xAODRootAccess/Root/TEvent.cxx:1293
xAOD::TEvent::getEntry
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0)
Function loading a given entry of the input TTree.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:1324
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:13
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
Init.h
AsgElectronChargeIDSelectorTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *part) const override final
Method to get the plain AcceptInfo.
Definition: AsgElectronChargeIDSelectorTool.cxx:614
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
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
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
CHECK
#define CHECK(ARG)
Definition: testEGChargeIDSelector.cxx:52
xAOD::Electron_v1
Definition: Electron_v1.h:34
AsgPhotonIsEMSelector.h
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
xAOD::Photon_v1
Definition: Photon_v1.h:37
xAOD::TEvent::retrieve
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
AsgElectronChargeIDSelectorTool.h
entries
double entries
Definition: listroot.cxx:49
xAOD::TEvent::readFrom
StatusCode readFrom(::TFile *file, Bool_t useTreeCache=kTRUE, const char *treeName=EVENT_TREE_NAME)
Connect the object to a new input file.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:364
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
Electron.h
AsgElectronLikelihoodTool::initialize
virtual StatusCode initialize() override
Gaudi Service Interface method implementations.
Definition: AsgElectronLikelihoodTool.cxx:80
test_pyathena.counter
counter
Definition: test_pyathena.py:15
PhotonContainer.h
TStore.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
AsgElectronIsEMSelector.h
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31