ATLAS Offline Software
Loading...
Searching...
No Matches
testElectronPhotonVariableCorrectionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11// ROOT includes
12#include "TFile.h"
13#include "TString.h"
14
15//EDM includes
19#include "xAODEgamma/Electron.h"
20#include "xAODEgamma/Photon.h"
21
24
26
28#ifdef ROOTCORE
31#endif //ROOTCORE
32
33// main test code
34
35int main(int argc, char* argv[])
36{
37 using namespace asg::msgUserCode;
38
39 // The application's name:
40 const char* APP_NAME = argv[0];
41
42 // Check if we received a file name:
43 if (argc < 2)
44 {
45 ANA_MSG_ERROR("No file name received!" );
46 ANA_MSG_ERROR( " Usage: %s [xAOD file name] %d Num of events to process %d (0 photons , 1 electrons)");
47 return EXIT_FAILURE;
48 }
49
50 //open input file
51 const TString fileName = argv[1];
52 ANA_MSG_INFO(APP_NAME << " Opening file: " << fileName.Data());
53 std::unique_ptr<TFile> inputFile(TFile::Open(fileName, "READ")); //probably rather "READ"?
54 ANA_CHECK(inputFile.get());
55
56 // Create a TEvent object (persistent store)
58 // Create a TStore object (transient store)
59 xAOD::TStore trans;
60 ANA_CHECK(pers.readFrom(inputFile.get()));
61 //
62 ANA_MSG_INFO("Number of events in the file: " << pers.getEntries());
63
64 // Decide how many events to run over:
65 Long64_t entries = pers.getEntries();
66 if (argc > 2)
67 {
68 const Long64_t userInputEntries = atoll(argv[2]);
69 if (userInputEntries < entries)
70 {
71 entries = userInputEntries;
72 }
73 }
74 ANA_MSG_INFO("Running over " << entries << " events.");
75
76 // initialize the tool
77 asg::StandaloneToolHandle<IElectronPhotonShowerShapeFudgeTool> myTool("ElectronPhotonVariableCorrectionTool/myTestTool");
78 std::string configFile = "EGammaVariableCorrection/EGammaVariableCorrectionTool_ExampleConf.conf";
79 ANA_CHECK(myTool.setProperty("ConfigFile", configFile));
80 ANA_CHECK(myTool.initialize());
81
82 // loop over the events
83 for (Long64_t entry = 0; entry < entries; entry++)
84 {
85 //get entry
86 pers.getEntry(entry);
87
88 // ====================================
89 // Photons
90 // ====================================
91
92 //get photon container
93 const xAOD::PhotonContainer* photons;
94 ANA_CHECK(pers.retrieve(photons, "Photons"));
95
96 // Make a deep copy of the photon container
97 // Create the new container and its auxiliary store.
98 auto photons_copy = std::make_unique<xAOD::PhotonContainer>();
99 auto photons_copy_aux = std::make_unique<xAOD::AuxContainerBase>();
100 photons_copy->setStore (photons_copy_aux.get()); //< Connect the two
101
102 //copy photons over
103 for (auto photon : *photons) {
104 // Copy this photon to the output container:
105 xAOD::Photon* photon_copy = new xAOD::Photon();
106 photons_copy->push_back (photon_copy); // photon acquires the photon_copy auxstore
107 *photon_copy = *photon; // copies auxdata from one auxstore to the other
108 }
109 // end make deep copy
110
111 //loop over deep copy of photon container
112 for (unsigned int photon_itr = 0; photon_itr < photons_copy->size(); photon_itr++)
113 {
114 xAOD::Photon* photon = photons_copy->at(photon_itr);
115
116 //apply correction
117 ANA_CHECK(myTool->applyCorrection(*photon));
118
119 } // loop over deep copy of photon container
120
121 // ====================================
122 // Electrons
123 // ====================================
124
125 //get electron container
126 const xAOD::ElectronContainer* electrons;
127 ANA_CHECK(pers.retrieve(electrons, "Electrons"));
128
129 // Make a deep copy of the electron container
130 // Create the new container and its auxiliary store.
131 auto electrons_copy = std::make_unique<xAOD::ElectronContainer>();
132 auto electrons_copy_aux = std::make_unique<xAOD::AuxContainerBase>();
133 electrons_copy->setStore (electrons_copy_aux.get()); //< Connect the two
134
135 //copy electrons over
136 for (auto electron : *electrons) {
137 // Copy this electron to the output container:
138 xAOD::Electron* electron_copy = new xAOD::Electron();
139 electrons_copy->push_back (electron_copy); // electron acquires the electron_copy auxstore
140 *electron_copy = *electron; // copies auxdata from one auxstore to the other
141 }
142 // end make deep copy
143
144 //loop over deep copy of electron container
145 for (unsigned int electron_itr = 0; electron_itr < electrons_copy->size(); electron_itr++)
146 {
147 xAOD::Electron* electron = electrons_copy->at(electron_itr);
148
149 //apply correction
150 ANA_CHECK(myTool->applyCorrection(*electron));
151
152 } // loop over deep copy of electrone container
153
154 } // loop over events
155
156 return 0;
157}
#define APP_NAME
#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
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.
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
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".