ATLAS Offline Software
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 
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
29 #include "xAODRootAccess/TEvent.h"
30 #include "xAODRootAccess/TStore.h"
31 #endif //ROOTCORE
32 
33 // main test code
34 
35 int 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
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
151 
152  } // loop over deep copy of electrone container
153 
154  } // loop over events
155 
156  return 0;
157 }
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
taskman.configFile
configFile
Definition: taskman.py:311
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
IElectronPhotonShowerShapeFudgeTool.h
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
asg::StandaloneToolHandle::initialize
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized
Definition: StandaloneToolHandle.h:158
IElectronPhotonShowerShapeFudgeTool::applyCorrection
virtual const CP::CorrectionCode applyCorrection(xAOD::Photon &ph) const =0
Declare the interface that the class provides.
ElectronContainer.h
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
asg::StandaloneToolHandle::setProperty
StatusCode setProperty(const std::string &name, T2 &&value)
Definition: StandaloneToolHandle.h:105
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
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
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
PhotonAuxContainer.h
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:199
xAOD::Photon_v1
Definition: Photon_v1.h:37
xAOD::TEvent::retrieve
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
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
Electron.h
StandaloneToolHandle.h
PhotonContainer.h
main
int main(int argc, char *argv[])
Test if ElectronPhotonVariableCorrectionTool runs fine on electrons and (un-)converted photons.
Definition: testElectronPhotonVariableCorrectionTool.cxx:35
TStore.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81