ATLAS Offline Software
Loading...
Searching...
No Matches
testElectronPhotonVariableCorrectionTool.cxx File Reference

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 Test if ElectronPhotonVariableCorrectionTool runs fine on electrons and (un-)converted photons.

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Test if ElectronPhotonVariableCorrectionTool runs fine on electrons and (un-)converted photons.

Author
Nils Gillwald (DESY) nils..nosp@m.gill.nosp@m.wald@.nosp@m.desy.nosp@m..de
Date
February 2020

Definition at line 35 of file testElectronPhotonVariableCorrectionTool.cxx.

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
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
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
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".