ATLAS Offline Software
Loading...
Searching...
No Matches
testIsoCorrection.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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
18#include "xAODEgamma/Photon.h"
19
20// must be changed to not be a relative path!
22//
24
25//infrastructure includes
26#ifdef ROOTCORE
29#endif //ROOTCORE
32
33//main test code
34
35int main (int argc, char* argv[])
36{
37 using namespace asg::msgUserCode;
38 // The application's name:
39 const char* APP_NAME = argv[0];
40 // Check if we received a file name:
41 if (argc < 2)
42 {
43 ANA_MSG_ERROR("No file name received!" );
44 ANA_MSG_ERROR( " Usage: %s [xAOD file name] %d Num of events to process %d (0 photons , 1 electrons)");
45 return EXIT_FAILURE;
46 }
47
48 //open input file
49 const TString fileName = argv[1];
50 ANA_MSG_INFO(APP_NAME << " Opening file: " << fileName.Data());
51 std::unique_ptr<TFile> inputFile(TFile::Open(fileName, "READ"));
52 ANA_CHECK(inputFile.get());
53
54 // Create a TEvent object (persistent store)
56 // Create a TStore object (transient store)
57 xAOD::TStore trans;
58 ANA_CHECK(pers.readFrom(inputFile.get()));
59
60 ANA_MSG_INFO("Number of events in the file: " << pers.getEntries());
61
62 // Decide how many events to run over:
63 Long64_t entries = pers.getEntries();
64 if (argc > 2)
65 {
66 const Long64_t userInputEntries = atoll(argv[2]);
67 if (userInputEntries < entries)
68 {
69 entries = userInputEntries;
70 }
71 }
72
73 //initialise the tool
74 ElectronPhotonVariableCorrectionBase fudgeTool("fudgeTool");
75 ANA_CHECK(fudgeTool.setProperty("ConfigFile","EGammaVariableCorrection/ElectronPhotonVariableCorrectionBase_ExampleIsoCorrectionConf.conf"));
76 ANA_CHECK(fudgeTool.initialize());
77
78 //crosscheck with isolationcorrectiontool
79 // check these StatusCodes once update to a newer AnalysisBase version (not 21.2.56, probably > 21.2.94)
80 CP::IsolationCorrectionTool isoCorrToolFull("isoCorrToolFull");
81 ANA_CHECK(isoCorrToolFull.setProperty("Apply_etaEDPar_mc_correction", true));
82 ANA_CHECK(isoCorrToolFull.setProperty("Apply_etaEDParPU_correction", true));
83 ANA_CHECK(isoCorrToolFull.initialize());
84
85 CP::IsolationCorrectionTool isoCorrToolStep("isoCorrToolStep");
86 ANA_CHECK(isoCorrToolStep.setProperty("Apply_etaEDPar_mc_correction", false));
87 ANA_CHECK(isoCorrToolStep.setProperty("Apply_etaEDParPU_correction", true));
88 ANA_CHECK(isoCorrToolStep.initialize());
89
90 static const SG::ConstAccessor<float> topoEtCone40OriginalAcc("topoetcone40_original");
91 static const SG::ConstAccessor<float> topoEtCone40Acc("topoetcone40");
92
93 //loop over the events
94 for (Long64_t entry = 0; entry < entries; entry++)
95 {
96 //get entry
97 pers.getEntry(entry);
98 ANA_MSG_INFO("============================");
99 ANA_MSG_INFO("Event: " << entry);
100
101 //get photon container
102 const xAOD::PhotonContainer* photons;
103 ANA_CHECK(pers.retrieve(photons, "Photons"));
104 std::pair< xAOD::PhotonContainer*, xAOD::ShallowAuxContainer* > photons_isocorr = xAOD::shallowCopyContainer( *photons );
105 std::pair< xAOD::PhotonContainer*, xAOD::ShallowAuxContainer* > photons_fudge = xAOD::shallowCopyContainer( *photons );
106
107 //loop over photon container
108 for (unsigned int idx = 0; idx < photons->size(); idx++)
109 {
110 ANA_MSG_INFO("---------------------------");
111 ANA_MSG_INFO("Photon: " << idx);
112 ANA_CHECK(isoCorrToolFull.applyCorrection(*(photons_isocorr.first->at(idx))));
113 ANA_CHECK(isoCorrToolStep.applyCorrection(*(photons_fudge.first->at(idx))));
114 ANA_CHECK(fudgeTool.applyCorrection(*(photons_fudge.first->at(idx))));
115 ANA_MSG_INFO("topoetcone40 fudge before applyCorrection: " << topoEtCone40OriginalAcc(*photons_fudge.first->at(idx)));
116 ANA_MSG_INFO("topoetcone40 fudge after applyCorrection : " << topoEtCone40Acc(*photons_fudge.first->at(idx)));
117 ANA_MSG_INFO("topoetcone40 with IsolationCorrectionTool : " << topoEtCone40Acc(*photons_isocorr.first->at(idx)));
118 } // loop over photon container
119 } // loop over events
120
121 return 0;
122}
#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
virtual StatusCode initialize() override final
virtual CP::CorrectionCode applyCorrection(xAOD::Egamma &) override final
size_type size() const noexcept
Returns the number of elements in the collection.
Class to correct electron and photon MC variables.
const CP::CorrectionCode applyCorrection(xAOD::Photon &photon) const
Apply the correction given in the conf file to the passed photon.
virtual StatusCode initialize() override
Initialize the class instance.
Helper class to provide constant type-safe access to aux data.
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".
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.