ATLAS Offline Software
testIsoCorrection.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
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
27 #include "xAODRootAccess/TEvent.h"
28 #include "xAODRootAccess/TStore.h"
29 #endif //ROOTCORE
31 #include "xAODCore/ShallowCopy.h"
32 
33 //main test code
34 
35 int 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  //loop over the events
91  for (Long64_t entry = 0; entry < entries; entry++)
92  {
93  //get entry
94  pers.getEntry(entry);
95  ANA_MSG_INFO("============================");
96  ANA_MSG_INFO("Event: " << entry);
97 
98  //get photon container
99  const xAOD::PhotonContainer* photons;
100  ANA_CHECK(pers.retrieve(photons, "Photons"));
101  std::pair< xAOD::PhotonContainer*, xAOD::ShallowAuxContainer* > photons_isocorr = xAOD::shallowCopyContainer( *photons );
102  std::pair< xAOD::PhotonContainer*, xAOD::ShallowAuxContainer* > photons_fudge = xAOD::shallowCopyContainer( *photons );
103 
104  //loop over photon container
105  for (unsigned int idx = 0; idx < photons->size(); idx++)
106  {
107  ANA_MSG_INFO("---------------------------");
108  ANA_MSG_INFO("Photon: " << idx);
109  ANA_CHECK(isoCorrToolFull.applyCorrection(*(photons_isocorr.first->at(idx))));
110  ANA_CHECK(isoCorrToolStep.applyCorrection(*(photons_fudge.first->at(idx))));
111  ANA_CHECK(fudgeTool.applyCorrection(*(photons_fudge.first->at(idx))));
112  ANA_MSG_INFO("topoetcone40 fudge before applyCorrection: " << photons_fudge.first->at(idx)->auxdata<float>("topoetcone40_original"));
113  ANA_MSG_INFO("topoetcone40 fudge after applyCorrection : " << photons_fudge.first->at(idx)->auxdata<float>("topoetcone40"));
114  ANA_MSG_INFO("topoetcone40 with IsolationCorrectionTool : " << photons_isocorr.first->at(idx)->auxdata<float>("topoetcone40"));
115  } // loop over photon container
116  } // loop over events
117 
118  return 0;
119 }
ShallowCopy.h
ElectronPhotonVariableCorrectionBase::initialize
virtual StatusCode initialize() override
Initialize the class instance.
Definition: ElectronPhotonVariableCorrectionBase.cxx:47
ElectronPhotonVariableCorrectionBase::applyCorrection
const CP::CorrectionCode applyCorrection(xAOD::Photon &photon) const
Apply the correction given in the conf file to the passed photon.
Definition: ElectronPhotonVariableCorrectionBase.cxx:202
main
int main(int argc, char *argv[])
Test code to compare output of ElectronPhotonVariableCorrectionBase correction to the isolation corre...
Definition: testIsoCorrection.cxx:35
CP::IsolationCorrectionTool::applyCorrection
virtual CP::CorrectionCode applyCorrection(xAOD::Egamma &) override final
Definition: IsolationCorrectionTool.cxx:209
IsolationCorrectionTool.h
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
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
AsgMessaging.h
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
Photon.h
xAOD::TEvent::getEntries
::Long64_t getEntries() const
Get how many entries are available from the current input file(s)
Definition: Control/xAODRootAccess/Root/TEvent.cxx:1293
xAOD::TEvent::getEntry
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0)
Function loading a given entry of the input TTree.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:1324
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
ElectronPhotonVariableCorrectionBase
Class to correct electron and photon MC variables.
Definition: ElectronPhotonVariableCorrectionBase.h:39
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
CP::IsolationCorrectionTool
Definition: IsolationCorrectionTool.h:27
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
PhotonAuxContainer.h
xAOD::TEvent::retrieve
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
entries
double entries
Definition: listroot.cxx:49
xAOD::TEvent::readFrom
StatusCode readFrom(::TFile *file, Bool_t useTreeCache=kTRUE, const char *treeName=EVENT_TREE_NAME)
Connect the object to a new input file.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:364
ElectronPhotonVariableCorrectionBase.h
CP::IsolationCorrectionTool::initialize
virtual StatusCode initialize() override final
Definition: IsolationCorrectionTool.cxx:46
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
PhotonContainer.h
TStore.h
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81