ATLAS Offline Software
Loading...
Searching...
No Matches
PrintPhotonSF.cxx File Reference
#include <filesystem>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include "TFile.h"
#include "TString.h"
#include "TList.h"
#include "TKey.h"
#include "TH2F.h"
#include "TMath.h"
#include "ElectronEfficiencyCorrection/TElectronEfficiencyCorrectionTool.h"
#include "AsgMessaging/MessageCheck.h"
#include "AsgTools/StandaloneToolHandle.h"

Go to the source code of this file.

Macros

#define GEV   1000.0
#define TEV   1000000.0

Functions

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

Macro Definition Documentation

◆ GEV

#define GEV   1000.0

Definition at line 25 of file PrintPhotonSF.cxx.

◆ TEV

#define TEV   1000000.0

Definition at line 26 of file PrintPhotonSF.cxx.

Function Documentation

◆ main()

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

Definition at line 31 of file PrintPhotonSF.cxx.

31 {
32
33 if(argc!=2){
34 printf("input parameters:\n./PrintPhotonSF [file] \n");
35 printf("example:\n PrintPhotonSF $ROOTCOREBIN/data/PhotonEfficiencyCorrection/INPUTFILE.root\n");
36 return 0;
37 }
38
39 // Check the input file:
40 if(!std::filesystem::exists(argv[1])){
41 printf("Error: file %s not exists\n",argv[1]);
42 return 0;
43 }
44
45 TString file(argv[1]);
46 // Check which directories (run numbers) exists
47 //Let user to deside which one to use in case of multiple
48 TList * listDirectories = TFile::Open(file)->GetListOfKeys();
49 const int ndirs = listDirectories->GetSize();
50 if(0==ndirs){
51 printf("Error: file %s does not contains any keys\n",argv[1]);
52 return 0;
53 }
54 TString dirName = listDirectories->First()->GetName();
55 if(ndirs>1) {
56 printf("Reads: %s, found %d folders:\n",argv[1],ndirs);
57 TIter next(listDirectories);
58 TKey *key;
59 while ((key = (TKey*)next())) printf("%s\n",key->GetName());
60 printf("which directory to use? (type the number from 1 to %d): ",ndirs);
61 int ndir_input=0; cin >> ndir_input;
62 if(ndir_input>ndirs || ndir_input<1)
63 printf("\nWarning... entered wrong key number, will print SF for directory: %s\n",dirName.Data());
64 else{
65 dirName = listDirectories->At(ndir_input-1)->GetName();
66 printf("\nprint SF for directory: %s\n",dirName.Data());
67 }
68 }
69 else printf("Reads: %s\nDirectory: %s\n",argv[1],dirName.Data());
70
71 // read first run number from the directory name:
72 int run_number = atoi(dirName.Tokenize("_")->First()->GetName());
73 if(getenv("ROOTCOREDIR")==nullptr){
74 cout << "Please setup RootCore before running the PrintPhotonSF [file]"<<endl;
75 return 0.;
76 }
77
78 // Create and initialize an instance for both types of photons
80 tool_SF.addFileName(file.Data());
81
82 if(!tool_SF.initialize()){
83 printf("Tool not initialized properly, check the error massages\n");
84 return 0;
85 }
86
88 if(file.Contains("AFII")) datatype=PATCore::ParticleDataType::Fast;
89
90 // Access the file to get the histogram binning:
91 TH2F * h = file.Contains("AFII") ? (TH2F*)TFile::Open(file)->Get(Form("%s/AltFast2_sf",dirName.Data())) : (TH2F*)TFile::Open(file)->Get(Form("%s/FullSim_sf",dirName.Data()));
92
93
94 const Double_t * pTbounds = h->GetXaxis()->GetXbins()->GetArray();
95 const Double_t * Etabounds = h->GetYaxis()->GetXbins()->GetArray();
96
97 const int npTbins = h->GetXaxis()->GetNbins();
98 const int nEtabins = h->GetYaxis()->GetNbins();
99
100 double pt, eta;
101
102 // loop over bins, in different pt/eta region, and print the SF
103 cout << "-----------------------------------------------------------------------------------"<<endl;
104 cout << "Table of photon ScaleFactors obtained by data-driven measurements for input file:"<<endl; cout << file <<endl;
105 cout << "-----------------------------------------------------------------------------------"<<endl;
106 TString dash_line="---------------"; for(int i=1;i<=nEtabins;i++) dash_line+="------------------";
107 cout << "| pt[GeV]\t\t|"; for(int i=1;i<=nEtabins;i++) printf("%2.2f<eta<%2.2f\t|",Etabounds[i-1],Etabounds[i]); cout<<endl;
108 cout << dash_line.Data() <<endl;
109 for (int i=1;i<=npTbins;i++){
110 pt=0.5*(pTbounds[i-1]+pTbounds[i]);
111 if(pt/GEV<100) printf("|%2.1f-%2.1f\t\t|",pTbounds[i-1]/GEV,pTbounds[i]/GEV);
112 else if(pt<TEV) printf("|%2.0f - %2.0f\t\t|",pTbounds[i-1]/GEV,pTbounds[i]/GEV);
113 else printf("|%2.0f-%2.0f\t\t|",pTbounds[i-1]/GEV,pTbounds[i]/GEV);
114 for(int j=1;j<=nEtabins;j++){
115 eta=0.5*(Etabounds[j-1]+Etabounds[j]);
117 tool_SF.calculate(datatype,run_number,eta,pt,sf,true);
118 printf("%2.2f+/-%2.4f\t|",sf.SF,sf.Total);
119 } cout << endl;
120 }
121 cout << dash_line.Data() <<endl;
122
123} // END PROGRAM
Scalar eta() const
pseudorapidity method
#define TEV
#define GEV
Header file for AthHistogramAlgorithm.
int calculate(const PATCore::ParticleDataType::DataType dataType, const unsigned int runnumber, const double cluster_eta, const double et, Result &result, const bool onlyTotal=false) const
The main calculate method: dataType PATCore::ParticleDataType::DataType (e.g DATA,...
void addFileName(const std::string &val)
This is more of an utility so the initialize is different wrt to an athena component.
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
std::string getenv(const std::string &variableName)
get an environment variable
TFile * file