ATLAS Offline Software
Macros | Functions
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 )

Definition at line 35 of file TestIsolationCorrections.cxx.

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
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
get_generator_info.result
result
Definition: get_generator_info.py:21
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
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:132
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
lumiFormat.i
int i
Definition: lumiFormat.py:92
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:123
CHECK
#define CHECK(ARG)
Definition: TestIsolationCorrections.cxx:34
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
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::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
xAOD::Photon_v1
Definition: Photon_v1.h:37
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:73
entries
double entries
Definition: listroot.cxx:49
xAOD::Egamma_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: Egamma_v1.cxx:65
xAOD::Egamma_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: Egamma_v1.cxx:70
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31