ATLAS Offline Software
ilumi2histo.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 from ROOT import *
4 import argparse,sys,os
5 
6 def ilumi2histo(ifile, ofile, relunc=3.2):
7  """!
8  Read in a ilumicalc file and output a file with a histogram that contains the
9  luminosity per run.
10  """
11  lumi_map = {}
12 
13  try:
14  m_file = TFile.Open(ifile,'read')
15 
16  for k in m_file.GetListOfKeys():
17  if '_intlumi' in k.GetName():
18 
19  run = m_file.Get(k.GetName()).GetTitle().split()[-1]
20 
21  #OLD WAY (look at histogram title)
22  #if not 'Delivered' in m_file.Get(k.GetName()).GetTitle():
23  # print 'WARNING : No lumi provided for run ',run
24  # continue
25  #lumi = m_file.Get(k.GetName()).GetTitle().split('=')[1]
26  #lumi = float(lumi.split('/')[0])
27 
28 
29  #NEW WAY (look at last filled bin)
30  h = m_file.Get(k.GetName())
31  lumi = h.GetBinContent( h.GetNbinsX()-9 )
32 
33  lumi_map[run] = float(lumi)*1e-6
34 
35  except IOError as e:
36  print('IlumiCalc file not found!')
37  print(os.strerror(e.errno))
38 
39 
40  lumi_histo = TH1F('lumi_histo',';;Int. Luminosity [pb]',len(lumi_map.keys()),0.,float(len(lumi_map.keys())))
41  lumi_histo.Sumw2()
42 
43  ib=1
44  lsrt = lumi_map.keys()
45  lsrt.sort()
46  for k in lsrt:
47  lumi_histo.SetBinContent(ib, float(lumi_map[k]))
48  if relunc > 0:
49  lumi_histo.SetBinError(ib, float(lumi_map[k])*float(relunc)/100.)
50  lumi_histo.GetXaxis().SetBinLabel(ib, k)
51  ib+=1
52 
53  lumi_histo.SaveAs(ofile)
54 
55 
56 if __name__ == '__main__':
57 
58 
59  parser = argparse.ArgumentParser()
60  parser.add_argument('--ifile', help='input ilumicalc file', dest='ifile', default='')
61  parser.add_argument('--ofile', help='output file', dest='ofile', default='ilumi2histo.root')
62  parser.add_argument('--relunc', help='luminosity relative uncertainty [%]', dest='relunc', default=3.2)
63 
64  config = parser.parse_args()
65 
66  if not config.ifile:
67  sys.exit('** You need to provide an iLumiCalc input file!')
68 
69 
70  ilumi2histo(config.ifile, config.ofile, config.relunc)
ilumi2histo.ilumi2histo
def ilumi2histo(ifile, ofile, relunc=3.2)
Read in a ilumicalc file and output a file with a histogram that contains the luminosity per run.
Definition: ilumi2histo.py:6
ilumi2histo
Definition: ilumi2histo.py:1
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38