ATLAS Offline Software
testEgEfficiencyCorr.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // Local includes
7 #include "SFHelpers.h"
8 // System include(s):
9 #include <memory>
10 // ROOT include(s):
11 #include <TFile.h>
12 // Infrastructure include(s):
13 #include "xAODRootAccess/Init.h"
14 #include "xAODRootAccess/TEvent.h"
15 #include "xAODRootAccess/TStore.h"
16 
17 // EDM include(s):
18 #include "xAODEgamma/Electron.h"
20 
22 #include "AsgMessaging/MsgStream.h"
24 // To disable sending data
26 
27 namespace asg {
28 ANA_MSG_HEADER(testEgEfficiencyCorr)
29 ANA_MSG_SOURCE(testEgEfficiencyCorr, "")
30 }
31 
32 int
33 main(int argc, char* argv[])
34 {
35 
37  // The application's name:
38  const char* APP_NAME = argv[0];
39 
40  using namespace asg::testEgEfficiencyCorr;
41  ANA_CHECK_SET_TYPE(int);
42  MSG::Level mylevel = MSG::INFO;
43  setMsgLevel(mylevel);
44  msg().setName(APP_NAME);
45 
46  // Check if we received a file name:
47  if (argc < 2) {
48  ANA_MSG_ERROR(APP_NAME << "No file name received!");
50  APP_NAME
51  << " Usage: <<APP_NAME << [xAOD file name] [Num of events to use]");
52  return 1;
53  }
54 
55  // Initialise the application:
57 
58  // Open the input file:
59  const TString fileName = argv[1];
60  ANA_MSG_INFO("Opening file: " << fileName.Data());
61  std::unique_ptr<TFile> ifile(TFile::Open(fileName, "READ"));
62  ANA_CHECK(ifile.get());
63 
64  // Create a TEvent object:
66 
67  // Then the tools
69  ElEffCorrectionTool(
70  "AsgElectronEfficiencyCorrectionTool/ElEffCorrectionTool");
71  ANA_CHECK(ElEffCorrectionTool.setProperty("IdKey", "Medium"));
72  ANA_CHECK(ElEffCorrectionTool.setProperty("ForceDataType", 1));
73  ANA_CHECK(ElEffCorrectionTool.setProperty("OutputLevel", mylevel));
74  ANA_CHECK(ElEffCorrectionTool.setProperty("CorrelationModel", "FULL"));
75  ANA_CHECK(ElEffCorrectionTool.setProperty("UseRandomRunNumber", false));
76  ANA_CHECK(ElEffCorrectionTool.initialize());
77 
78  // Then open the file(s)
79  ANA_CHECK(event.readFrom(ifile.get()));
80  ANA_MSG_INFO("Number of available events to read in: "
81  << static_cast<long long int>(event.getEntries()));
82 
83  // Decide how many events to run over:
84  long long int entries = event.getEntries();
85  if (argc > 2) {
86  const long long int e = atoll(argv[2]);
87  if (e < entries) {
88  entries = e;
89  }
90  }
91  ANA_MSG_INFO("Number actual events to read in: " << entries);
92 
93  // Loop over the events:
94  for (long long int entry = 0; entry < entries; ++entry) {
95  event.getEntry(entry);
96  ANA_MSG_INFO(" \n ==> Event " << entry);
97 
98  const xAOD::ElectronContainer* electrons = nullptr;
99  ANA_CHECK(event.retrieve(electrons, "Electrons"));
100 
101  for (const xAOD::Electron* el : *electrons) {
102  const xAOD::CaloCluster* cluster = el->caloCluster();
103  if (!cluster) {
104  ANA_MSG_ERROR("ERROR no cluster associated to the Electron \n");
106  }
107  if (el->pt() < 7000)
108  continue; // skip electrons outside of recommendations
109  if (std::abs(cluster->etaBE(2)) >= 2.47) {
110  continue;
111  }
112 
113  int index = ElEffCorrectionTool->systUncorrVariationIndex(*el);
114  /*
115  * Set up the systematic variations
116  */
117  bool isToys = false;
118  double nominalSF{};
119  double totalNeg{};
120  double totalPos{};
121  ANA_CHECK(
123  ElEffCorrectionTool, *el, nominalSF, totalPos, totalNeg, isToys) ==
124  0);
125 
126  ANA_MSG_INFO("===> electron : Pt = "
127  << el->pt() << " : eta = " << el->eta()
128  << " : Bin index = " << index << " : SF = " << nominalSF
129  << " + " << totalPos << " - " << totalNeg << " <===");
130  }
131  }
132 
133  ANA_MSG_INFO("===> DONE <===\n");
134  return 0;
135 }
136 
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
index
Definition: index.py:1
SFHelpers::result
int result(asg::StandaloneToolHandle< IAsgElectronEfficiencyCorrectionTool > &tool, const xAOD::Electron &el, double &nominalSF, double &totalPos, double &totalNeg, const bool isToys)
Definition: SFHelpers.cxx:20
xAOD::TFileAccessTracer::enableDataSubmission
static void enableDataSubmission(::Bool_t value)
Function for turning data submission on/off.
Definition: TFileAccessTracer.cxx:281
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
AsgElectronEfficiencyCorrectionTool.h
xAOD::CaloCluster_v1::etaBE
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
Definition: CaloCluster_v1.cxx:644
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
TFileAccessTracer.h
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
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
ElectronContainer.h
main
int main(int argc, char *argv[])
Definition: testEgEfficiencyCorr.cxx:33
asg::StandaloneToolHandle::setProperty
StatusCode setProperty(const std::string &name, T2 &&value)
Definition: StandaloneToolHandle.h:105
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:124
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
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
xAOD::Electron_v1
Definition: Electron_v1.h:34
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
IAsgElectronEfficiencyCorrectionTool::systUncorrVariationIndex
virtual int systUncorrVariationIndex(const xAOD::Electron &inputObject) const =0
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
entries
double entries
Definition: listroot.cxx:49
Electron.h
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
StandaloneToolHandle.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
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:84
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31
SFHelpers.h
MsgStream.h