ATLAS Offline Software
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 //
29 #include "AsgMessaging/MsgStream.h"
30 // Derivation include
31 #include "xAODCore/tools/IOStats.h"
33 
34 // Infrastructure include(s):
35 #ifdef ROOTCORE
36 # include "xAODRootAccess/Init.h"
37 # include "xAODRootAccess/TEvent.h"
38 # include "xAODRootAccess/TStore.h"
39 #endif // ROOTCORE
40 
41 namespace asg{
42  ANA_MSG_HEADER (msgSelectorCheck)
43  ANA_MSG_SOURCE (msgSelectorCheck, "EgammaSelectorCheck")
44 }
45 
46 //main test code
47 int main( int argc, char* argv[] ) {
48 
49  //
50  using namespace asg::msgSelectorCheck;
51  ANA_CHECK_SET_TYPE (int);
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 
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 
asg::AcceptData::getCutResultInvertedBitSet
std::bitset< NBITS > getCutResultInvertedBitSet() const
Get an inverted bitset of the cut result.
Definition: AcceptData.h:119
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
egammaPIDdefs.h
main
int main(int argc, char *argv[])
Definition: testEGIdentificationPoints.cxx:47
IAsgForwardElectronIsEMSelector.h
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
IAsgPhotonIsEMSelector.h
asg
Definition: DataHandleTestTool.h:28
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
IOStats.h
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
egammaPID::ClusterHadronicLeakage_Electron
@ ClusterHadronicLeakage_Electron
cluster leakage into the hadronic calorimeter
Definition: egammaPIDdefs.h:100
IAsgElectronLikelihoodTool.h
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
asg::StandaloneToolHandle::initialize
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized
Definition: StandaloneToolHandle.h:158
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ReadStats.h
IAsgEGammaIsEMSelector::accept
virtual asg::AcceptData accept(const xAOD::IParticle *part) const =0
accept with pointer to IParticle so as to not hide the IAsgSelectionTool one
ElectronContainer.h
asg::StandaloneToolHandle::setProperty
StatusCode setProperty(const std::string &name, T2 &&value)
Definition: StandaloneToolHandle.h:105
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
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:12
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
MessageCheck.h
macros for messaging and checking status codes
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
Init.h
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
AcceptData.h
xAOD::ReadStats::printSmartSlimmingBranchList
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
asg::ANA_MSG_HEADER
ANA_MSG_HEADER(msgSTT) ANA_MSG_SOURCE(msgSTT
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
ANA_MSG_SOURCE
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:133
asg::AcceptData::getCutResultBitSet
std::bitset< NBITS > getCutResultBitSet() const
Get the cut result bitset.
Definition: AcceptData.h:112
xAOD::Electron_v1
Definition: Electron_v1.h:34
IAsgElectronIsEMSelector.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
xAOD::Photon_v1
Definition: Photon_v1.h:37
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
egammaPID::ElectronMediumPP
const unsigned int ElectronMediumPP
Medium++ electron selecton.
Definition: egammaPIDdefs.h:320
xAOD::TEvent::retrieve
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
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
StandaloneToolHandle.h
IAsgElectronLikelihoodTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *part) const =0
accept with pointer to IParticle so as to not hide the IAsgSelectionTool one
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
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31
MsgStream.h