ATLAS Offline Software
Macros | Functions
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 "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 30 of file PrintPhotonSF.cxx.

30  {
31 
32  if(argc!=2){
33  printf("input parameters:\n./PrintPhotonSF [file] \n");
34  printf("example:\n PrintPhotonSF $ROOTCOREBIN/data/PhotonEfficiencyCorrection/INPUTFILE.root\n");
35  return 0;
36  }
37 
38  // Check the input file:
40  printf("Error: file %s not exists\n",argv[1]);
41  return 0;
42  }
43 
44  TString file(argv[1]);
45  // Check which directories (run numbers) exists
46  //Let user to deside which one to use in case of multiple
47  TList * listDirectories = TFile::Open(file)->GetListOfKeys();
48  const int ndirs = listDirectories->GetSize();
49  if(0==ndirs){
50  printf("Error: file %s does not contains any keys\n",argv[1]);
51  return 0;
52  }
53  TString dirName = listDirectories->First()->GetName();
54  if(ndirs>1) {
55  printf("Reads: %s, found %d folders:\n",argv[1],ndirs);
56  TIter next(listDirectories);
57  TKey *key;
58  while ((key = (TKey*)next())) printf("%s\n",key->GetName());
59  printf("which directory to use? (type the number from 1 to %d): ",ndirs);
60  int ndir_input=0; cin >> ndir_input;
61  if(ndir_input>ndirs || ndir_input<1)
62  printf("\nWarning... entered wrong key number, will print SF for directory: %s\n",dirName.Data());
63  else{
64  dirName = listDirectories->At(ndir_input-1)->GetName();
65  printf("\nprint SF for directory: %s\n",dirName.Data());
66  }
67  }
68  else printf("Reads: %s\nDirectory: %s\n",argv[1],dirName.Data());
69 
70  // read first run number from the directory name:
71  int run_number = atoi(dirName.Tokenize("_")->First()->GetName());
72  if(getenv("ROOTCOREDIR")==nullptr){
73  cout << "Please setup RootCore before running the PrintPhotonSF [file]"<<endl;
74  return 0.;
75  }
76 
77  // Create and initialize an instance for both types of photons
79  tool_SF.addFileName(file.Data());
80 
81  if(!tool_SF.initialize()){
82  printf("Tool not initialized properly, check the error massages\n");
83  return 0;
84  }
85 
87  if(file.Contains("AFII")) datatype=PATCore::ParticleDataType::Fast;
88 
89  // Access the file to get the histogram binning:
90  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()));
91 
92 
93  const Double_t * pTbounds = h->GetXaxis()->GetXbins()->GetArray();
94  const Double_t * Etabounds = h->GetYaxis()->GetXbins()->GetArray();
95 
96  const int npTbins = h->GetXaxis()->GetNbins();
97  const int nEtabins = h->GetYaxis()->GetNbins();
98 
99  double pt, eta;
100 
101  // loop over bins, in different pt/eta region, and print the SF
102  cout << "-----------------------------------------------------------------------------------"<<endl;
103  cout << "Table of photon ScaleFactors obtained by data-driven measurements for input file:"<<endl; cout << file <<endl;
104  cout << "-----------------------------------------------------------------------------------"<<endl;
105  TString dash_line="---------------"; for(int i=1;i<=nEtabins;i++) dash_line+="------------------";
106  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;
107  cout << dash_line.Data() <<endl;
108  for (int i=1;i<=npTbins;i++){
109  pt=0.5*(pTbounds[i-1]+pTbounds[i]);
110  if(pt/GEV<100) printf("|%2.1f-%2.1f\t\t|",pTbounds[i-1]/GEV,pTbounds[i]/GEV);
111  else if(pt<TEV) printf("|%2.0f - %2.0f\t\t|",pTbounds[i-1]/GEV,pTbounds[i]/GEV);
112  else printf("|%2.0f-%2.0f\t\t|",pTbounds[i-1]/GEV,pTbounds[i]/GEV);
113  for(int j=1;j<=nEtabins;j++){
114  eta=0.5*(Etabounds[j-1]+Etabounds[j]);
116  tool_SF.calculate(datatype,run_number,eta,pt,sf,true);
117  printf("%2.2f+/-%2.4f\t|",sf.SF,sf.Total);
118  } cout << endl;
119  }
120  cout << dash_line.Data() <<endl;
121 
122 } // END PROGRAM
plotting.plot_kinematics.run_number
run_number
Definition: plot_kinematics.py:29
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
PATCore::ParticleDataType::Fast
@ Fast
Definition: PATCoreEnums.h:22
test_pyathena.pt
pt
Definition: test_pyathena.py:11
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
PATCore::ParticleDataType::DataType
DataType
Definition: PATCoreEnums.h:22
PATCore::ParticleDataType::Full
@ Full
Definition: PATCoreEnums.h:22
Root::TElectronEfficiencyCorrectionTool::Result
Definition: TElectronEfficiencyCorrectionTool.h:42
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
lumiFormat.i
int i
Definition: lumiFormat.py:85
h
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
file
TFile * file
Definition: tile_monitor.h:29
GEV
#define GEV
Definition: PrintPhotonSF.cxx:24
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
Root::TElectronEfficiencyCorrectionTool
Definition: TElectronEfficiencyCorrectionTool.h:36
Root::TElectronEfficiencyCorrectionTool::initialize
int initialize()
Initialize this class.
Definition: TElectronEfficiencyCorrectionTool.cxx:87
Root::TElectronEfficiencyCorrectionTool::addFileName
void addFileName(const std::string &val)
This is more of an utility so the initialize is different wrt to an athena component.
Definition: TElectronEfficiencyCorrectionTool.h:66
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
TEV
#define TEV
Definition: PrintPhotonSF.cxx:25
Root::TElectronEfficiencyCorrectionTool::calculate
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,...
Definition: TElectronEfficiencyCorrectionTool.cxx:160
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37