ATLAS Offline Software
Loading...
Searching...
No Matches
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"
16
17// EDM include(s):
18#include "xAODEgamma/Electron.h"
20
24// To disable sending data
26
27namespace asg {
28ANA_MSG_HEADER(testEgEfficiencyCorr)
29ANA_MSG_SOURCE(testEgEfficiencyCorr, "")
30}
31
32int
33main(int argc, char* argv[])
34{
35
37 // The application's name:
38 const char* APP_NAME = argv[0];
39
40 using namespace asg::testEgEfficiencyCorr;
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!");
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:
65 xAOD::TEvent event;
66 xAOD::TStore store;
67
68 // Then the tools
70 ElEffCorrectionTool(
71 "AsgElectronEfficiencyCorrectionTool/ElEffCorrectionTool");
72 ANA_CHECK(ElEffCorrectionTool.setProperty("IdKey", "Medium"));
73 ANA_CHECK(ElEffCorrectionTool.setProperty("ForceDataType", 1));
74 ANA_CHECK(ElEffCorrectionTool.setProperty("OutputLevel", mylevel));
75 ANA_CHECK(ElEffCorrectionTool.setProperty("CorrelationModel", "FULL"));
76 ANA_CHECK(ElEffCorrectionTool.setProperty("UseRandomRunNumber", false));
77 ANA_CHECK(ElEffCorrectionTool.initialize());
78
79 // Then open the file(s)
80 ANA_CHECK(event.readFrom(ifile.get()));
81 ANA_MSG_INFO("Number of available events to read in: "
82 << static_cast<long long int>(event.getEntries()));
83
84 // Decide how many events to run over:
85 long long int entries = event.getEntries();
86 if (argc > 2) {
87 const long long int e = atoll(argv[2]);
88 if (e < entries) {
89 entries = e;
90 }
91 }
92 ANA_MSG_INFO("Number actual events to read in: " << entries);
93
94 // Loop over the events:
95 for (long long int entry = 0; entry < entries; ++entry) {
96 event.getEntry(entry);
97 ANA_MSG_INFO(" \n ==> Event " << entry);
98
99 const xAOD::ElectronContainer* electrons = nullptr;
100 ANA_CHECK(event.retrieve(electrons, "Electrons"));
101
102 for (const xAOD::Electron* el : *electrons) {
103 const xAOD::CaloCluster* cluster = el->caloCluster();
104 if (!cluster) {
105 ANA_MSG_ERROR("ERROR no cluster associated to the Electron \n");
107 }
108 if (el->pt() < 7000)
109 continue; // skip electrons outside of recommendations
110 if (std::abs(cluster->etaBE(2)) >= 2.47) {
111 continue;
112 }
113
114 int index = ElEffCorrectionTool->systUncorrVariationIndex(*el);
115 /*
116 * Set up the systematic variations
117 */
118 bool isToys = false;
119 double nominalSF{};
120 double totalNeg{};
121 double totalPos{};
122 ANA_CHECK(
124 ElEffCorrectionTool, *el, nominalSF, totalPos, totalNeg, isToys) ==
125 0);
126
127 ANA_MSG_INFO("===> electron : Pt = "
128 << el->pt() << " : eta = " << el->eta()
129 << " : Bin index = " << index << " : SF = " << nominalSF
130 << " + " << totalPos << " - " << totalNeg << " <===");
131 }
132 }
133
134 ANA_MSG_INFO("===> DONE <===\n");
135 return 0;
136}
137
#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
@ Error
Some error happened during the object correction.
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
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
Tool for accessing xAOD files outside of Athena.
static void enableDataSubmission(::Bool_t value)
Function for turning data submission on/off.
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
int result(asg::StandaloneToolHandle< IAsgElectronEfficiencyCorrectionTool > &tool, const xAOD::Electron &el, double &nominalSF, double &totalPos, double &totalNeg, const bool isToys)
Definition SFHelpers.cxx:20
Definition index.py:1
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Electron_v1 Electron
Definition of the current "egamma version".
MsgStream & msg
Definition testRead.cxx:32