ATLAS Offline Software
Macros | Functions
FsrPhotonToolTester.cxx File Reference
#include <TFile.h>
#include <TError.h>
#include "xAODRootAccess/Init.h"
#include "xAODRootAccess/TEvent.h"
#include "xAODRootAccess/TStore.h"
#include "xAODCore/ShallowCopy.h"
#include "xAODBase/IParticleHelpers.h"
#include "xAODMuon/MuonContainer.h"
#include "xAODEgamma/ElectronContainer.h"
#include "xAODEgamma/PhotonContainer.h"
#include "ElectronPhotonFourMomentumCorrection/EgammaCalibrationAndSmearingTool.h"
#include "FsrUtils/FsrPhotonTool.h"
#include "xAODCore/tools/IOStats.h"
#include "xAODCore/tools/ReadStats.h"

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 30 of file FsrPhotonToolTester.cxx.

Function Documentation

◆ main()

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

Definition at line 53 of file FsrPhotonToolTester.cxx.

54 {
55 
56  // The application's name
57  const char* APP_NAME = argv[ 0 ];
58 
59  // Check if we received a file name
60  if(argc < 2) {
61  Error( APP_NAME, "No file name received!" );
62  Error( APP_NAME, " Usage: %s [xAOD file name]", APP_NAME );
63  return 1;
64  }
65 
66  // Initialise the application
68  StatusCode::enableFailure();
69 
70  // Open the input file
71  const TString fileName = argv[ 1 ];
72  Info(APP_NAME, "Opening file: %s", fileName.Data());
73  std::unique_ptr<TFile> ifile(TFile::Open(fileName, "READ"));
74  CHECK( ifile.get() );
75 
76  // Create a TEvent object
78  CHECK( event.readFrom(ifile.get()) );
79  Info(APP_NAME, "Number of events in the file: %i",
80  static_cast<int>(event.getEntries()));
81 
82  // Create a Store object for shallow copies
84 
85 
86  // Decide how many events to run over
87  Long64_t entries = event.getEntries();
88  if(argc > 2) {
89  const Long64_t e = atoll(argv[2]);
90  if(e < entries) {
91  entries = e;
92  }
93  }
94 
95  // Must provide and egamma calib tool to the FSRTool
96  CP::EgammaCalibrationAndSmearingTool * energyRescaler =
97  new CP::EgammaCalibrationAndSmearingTool("EgammaCalibrationAndSmearingTool");
98  std::string esModel = "es2017_R21_v1"; // move to v1, 2018/09/04
99  CHECK( energyRescaler->setProperty( "ESModel", esModel) );
100  CHECK( energyRescaler->initialize() );
101  ToolHandle<CP::IEgammaCalibrationAndSmearingTool> energyRescalerTool(energyRescaler->name());
102 
103  // Create and configure the tool
104  FSR::FsrPhotonTool fsrTool("FsrPhotonTool");
105  CHECK( fsrTool.setProperty<double>("far_fsr_drcut", 0.12) );
106  fsrTool.msg().setLevel(MSG::DEBUG);
107  CHECK( fsrTool.setProperty( "egCalibToolName", energyRescaler->name()) );
108  CHECK( fsrTool.initialize() );
109 
110 
111  FSR::FsrCandidate candidate;
112 
113  // Loop over the events
114  for(Long64_t entry = 0; entry < entries; ++entry) {
115 
116  store->clear(); // must clear store each event
117 
118  // Tell the object which entry to look at
119  event.getEntry(entry);
120 
121  // Print some event information for fun
122  // Need to link against xAODEventInfo for this to work
123  //const xAOD::EventInfo* ei = 0;
124  //CHECK( event.retrieve(ei, "EventInfo") );
125  //Info( APP_NAME,
126  // "===>>> start processing event #%i, "
127  // "run #%i %i events processed so far <<<===",
128  // static_cast<int>(ei->eventNumber()),
129  // static_cast<int>(ei->runNumber()),
130  // static_cast<int>(entry));
131 
132  // Retrieve the muons
133  const xAOD::MuonContainer* muons = 0;
134  CHECK( event.retrieve( muons, "Muons" ) );
135 
136  // get ElectronContainer and clone it in order to apply corrections
137  const xAOD::ElectronContainer* els = 0;
138  CHECK( event.retrieve( els, "Electrons" ) );
139 
140  std::pair< xAOD::ElectronContainer*, xAOD::ShallowAuxContainer* > electrons_shallowCopy =
142 
143  // Record then in the Store
144  CHECK( store->record( electrons_shallowCopy.first, "ElectronsCorr" ) );
145  CHECK( store->record( electrons_shallowCopy.second, "ElectronsCorrAux." ) );
146 
147  xAOD::ElectronContainer* elsCorr = electrons_shallowCopy.first;
148 
149  // Must set links between shallow copy and original container
150  if (!xAOD::setOriginalObjectLink( *els, *elsCorr )) {
151  Error(APP_NAME, "Unable to setOriginalObjectLink for electron containers ");
152  return 1;
153  }
154 
155  // get PhotonContainer and clone it in order to apply corrections
156  const xAOD::PhotonContainer* phs = 0;
157  CHECK( event.retrieve( phs, "Photons" ) );
158 
159  std::pair< xAOD::PhotonContainer*, xAOD::ShallowAuxContainer* > photons_shallowCopy =
161 
162  // Record then in the Store
163  CHECK( store->record( photons_shallowCopy.first, "PhotonsCorr" ) );
164  CHECK( store->record( photons_shallowCopy.second, "PhotonsCorrAux." ) );
165  xAOD::PhotonContainer* phsCorr = photons_shallowCopy.first;
166  // Must set links between shallow copy and original container
167  if (!xAOD::setOriginalObjectLink( *phs, *phsCorr )) {
168  Error(APP_NAME, "Unable to setOriginalObjectLink for photon containers ");
169  return 1;
170  }
171 
172 
173  //std::vector<const xAOD::Muon*> selectedMuons;
174  double tmp_energy = -999.;
175  double fsr_energy = 0.;
176  TLorentzVector fsr_tlv;
177 
178  // Loop over muons
179  for( auto muon : *muons ) {
180 
181  if (CP::CorrectionCode::Ok != fsrTool.getFsrPhoton(muon, candidate, phsCorr, elsCorr))
182  {
183  Info( APP_NAME, " FSR candidate found !!!!!!!! ");
184  Info( APP_NAME, " container = %s deltaR = %f Et = %f f1 = %f"
185  " eta = %f phi = %f phIso = %f fsrtype = %i",
186  candidate.container.c_str(),
187  candidate.deltaR, candidate.Et, candidate.f1,
188  candidate.eta, candidate.phi,
189  candidate.phIso, candidate.type );
190  }
191 
192  if (candidate.container == "photon" ) {
193  const xAOD::Photon* photon = dynamic_cast<const xAOD::Photon*>(candidate.particle);
194  if (photon) fsr_energy = photon->e();
195  }
196  else if (candidate.container == "electron" ) {
197  const xAOD::Electron* electron = dynamic_cast<const xAOD::Electron*>(candidate.particle);
198  if (electron) fsr_energy = electron->e();
199  } else
200  Info(APP_NAME, " FSR candidate particle is unknown " );
201 
202  if ( fsr_energy > tmp_energy ) {
203  tmp_energy = fsr_energy;
204  fsr_tlv.SetPtEtaPhiE(candidate.Et, candidate.eta, candidate.phi, fsr_energy);
205  }
206 
207  }
208 
210 
211  }
212 
213  delete store;
214 
215  return EXIT_SUCCESS;
216 
217 }
StoreGateSvc::record
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
FSR::FsrCandidate::Et
double Et
Definition: IFsrPhotonTool.h:36
get_generator_info.result
result
Definition: get_generator_info.py:21
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
FSR::FsrCandidate::container
std::string container
Definition: IFsrPhotonTool.h:33
CHECK
#define CHECK(ARG)
Definition: FsrPhotonToolTester.cxx:29
FSR::FsrCandidate::deltaR
double deltaR
Definition: IFsrPhotonTool.h:35
FSR::FsrPhotonTool
Implementation for the "FSR" provider tool.
Definition: FsrPhotonTool.h:30
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
FSR::FsrCandidate::f1
double f1
Definition: IFsrPhotonTool.h:37
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)
CP::EgammaCalibrationAndSmearingTool::initialize
StatusCode initialize() override
Definition: EgammaCalibrationAndSmearingTool.cxx:315
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:123
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
FSR::FsrCandidate::phIso
double phIso
Definition: IFsrPhotonTool.h:40
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::ReadStats::printSmartSlimmingBranchList
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
FSR::FsrCandidate::particle
const xAOD::IParticle * particle
Definition: IFsrPhotonTool.h:34
xAOD::Electron_v1
Definition: Electron_v1.h:34
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
CP::EgammaCalibrationAndSmearingTool
Definition: EgammaCalibrationAndSmearingTool.h:81
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
FSR::FsrCandidate::type
FsrType type
Definition: IFsrPhotonTool.h:41
FSR::FsrCandidate
Simple interface for searching the FSR candidate.
Definition: IFsrPhotonTool.h:27
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:199
xAOD::Photon_v1
Definition: Photon_v1.h:37
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:73
xAOD::setOriginalObjectLink
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
Definition: IParticleHelpers.cxx:30
DEBUG
#define DEBUG
Definition: page_access.h:11
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
entries
double entries
Definition: listroot.cxx:49
FSR::FsrCandidate::phi
double phi
Definition: IFsrPhotonTool.h:39
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
FSR::FsrCandidate::eta
double eta
Definition: IFsrPhotonTool.h:38
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31