ATLAS Offline Software
Loading...
Searching...
No Matches
TestIsolationCorrections.cxx File Reference
#include <memory>
#include <cstdlib>
#include <TFile.h>
#include <TError.h>
#include <TString.h>
#include "xAODEventInfo/EventInfo.h"
#include "xAODEgamma/PhotonContainer.h"
#include "xAODEgamma/Egamma.h"
#include "xAODEgamma/EgammaxAODHelpers.h"
#include "IsolationCorrections/IsolationCorrectionTool.h"
#include "xAODCore/ShallowCopy.h"
#include "PathResolver/PathResolver.h"
#include <PATInterfaces/SystematicsUtil.h>
#include <iostream>
#include <string>

Go to the source code of this file.

Macros

#define CHECK(ARG)

Functions

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

Macro Definition Documentation

◆ CHECK

#define CHECK ( ARG)
Value:
do { \
const bool result = ARG; \
if( ! result ) { \
::Error( APP_NAME, "Failed to execute: \"%s\"", \
#ARG ); \
return 1; \
} \
} while( false )
#define APP_NAME

Definition at line 34 of file TestIsolationCorrections.cxx.

34#define CHECK( ARG ) \
35do { \
36 const bool result = ARG; \
37 if( ! result ) { \
38 ::Error( APP_NAME, "Failed to execute: \"%s\"", \
39#ARG ); \
40 return 1; \
41 } \
42 } while( false )

Function Documentation

◆ main()

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

Definition at line 45 of file TestIsolationCorrections.cxx.

45 {
46
47 // The application's name:
48 const char* APP_NAME = argv[ 0 ];
49
50 // Check if we received a file name:
51 if( argc < 2 ) {
52 Error( APP_NAME, "No file name received!" );
53 Error( APP_NAME, " Usage: %s [xAOD file name]", APP_NAME );
54 return 1;
55 }
56
57 // Initialise the application:
59
60 // Open the input file:
61 const TString fileName = argv[ 1 ];
62 Info( APP_NAME, "Opening file: %s", fileName.Data() );
63 std::unique_ptr< TFile > ifile( TFile::Open( fileName, "READ" ) );
64 CHECK( ifile.get() );
65
66 // Create a TEvent object:
67 // xAOD::TEvent event( xAOD::TEvent::kBranchAccess ); //will work for a sample produced in devval
69 CHECK( event.readFrom( ifile.get() ) );
70 Info( APP_NAME, "Number of events in the file: %i",
71 static_cast< int >( event.getEntries() ) );
72
73
74 // Decide how many events to run over:
75 Long64_t entries = event.getEntries();
76 if( argc > 2 ) {
77 const Long64_t e = atoll( argv[ 2 ] );
78 if( e < entries ) {
79 entries = e;
80 }
81 }
82
83 // Initialize photonFS tool
84 CP::IsolationCorrectionTool m_isoCorrTool ("isoCorrTool");
85
86 CHECK( m_isoCorrTool.setProperty("IsMC", true) ); //if MC, else false
87
88 std::string file_unc = PathResolverFindCalibFile("IsolationCorrections/v1/isolation_ptcorrections_rel207.root");
89 CHECK(m_isoCorrTool.setProperty("CorrFile",file_unc));
90
91 if(!m_isoCorrTool.initialize()){
92 std::cout <<"Failed to initialize the tool, check for errors"<<std::endl;
93 return 0;
94 }
95
96
97 // Loop over the events:
98 std::cout << "loop on " << entries << " entries"<<std::endl;
99 for( int entry = 0; entry < entries; ++entry ) {
100
101 // Tell the object which entry to look at:
102 event.getEntry( entry );
103
104 // Get the EventInfo (run number...):
105 const xAOD::EventInfo* ei = 0;
106 CHECK( event.retrieve( ei, "EventInfo" ) );
107 //std::cout << "Event number = " << ei->eventNumber() << std::endl;
108
109 // Get the Photon container from the event:
110 const xAOD::PhotonContainer *photons = 0;
111 CHECK( event.retrieve( photons, "Photons" ) );
112
113 //Clone
114 std::pair< xAOD::PhotonContainer*, xAOD::ShallowAuxContainer* > photons_shallowCopy = xAOD::shallowCopyContainer( *photons );
115
116 //Iterate over the shallow copy
117 xAOD::PhotonContainer* phsCorr = photons_shallowCopy.first;
118 xAOD::PhotonContainer::iterator ph_itr = phsCorr->begin();
119 xAOD::PhotonContainer::iterator ph_end = phsCorr->end();
120
121 unsigned int i = 0;
122 for( ; ph_itr != ph_end; ++ph_itr, ++i ) {
123 xAOD::Photon* ph = *ph_itr;
124
125 // skip photons with pt outsize the acceptance
126 if(ph->pt()<10000.0) continue;
127 if( fabs(ph->eta())>2.47) continue;
128 Info (APP_NAME,"Event #%d, Photon #%d", entry, i);
129 Info (APP_NAME,"xAOD/raw pt = %f, eta = %f ", ph->pt(), ph->eta() );
130
131 //dudu
132 CHECK(m_isoCorrTool.applyCorrection(*ph));
133 Info (APP_NAME,"after the Iso correction ");
134
135
136 } // END LOOP ON PHOTONS
137
138 } // END LOOP ON EVENTS
139 CHECK(m_isoCorrTool.finalize());
140
141 // Return gracefully:
142 return 1;
143} // END PROGRAM
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
#define CHECK(ARG)
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition Egamma_v1.cxx:66
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition Egamma_v1.cxx:71
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
double entries
Definition listroot.cxx:49
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition Error.h:16
@ Info
Definition ZDCMsg.h:20
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
EventInfo_v1 EventInfo
Definition of the latest event info 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.
Photon_v1 Photon
Definition of the current "egamma version".