ATLAS Offline Software
January2018_specialStatTerms/ParseEtaIntercalInput.py
Go to the documentation of this file.
1 from ROOT import *
2 from array import array
3 import glob
4 import re
5 import math
6 import ProviderHistoHelpers
7 
8 def GetKeyNames(self,dir=""):
9  self.cd(dir)
10  return [key.GetName() for key in gDirectory.GetListOfKeys()]
11 TFile.GetKeyNames = GetKeyNames
12 
13 SystematicNames = {'EtaIntercalibration_TotalStat' : 'EtaIntercalibration_TotalStat',\
14  'EtaIntercalibration_TotalSyst' : 'EtaIntercalibration_Modelling',\
15  'E_4TeV' : 'EtaIntercalibration_NonClosure_highE',\
16  'Eta_2p4_to_2p6' : 'EtaIntercalibration_NonClosure_posEta',\
17  'Eta_m2p6_to_m2p4' : 'EtaIntercalibration_NonClosure_negEta'
18  }
19 
20 jetDefDict = {
21  'AntiKt4EMTopo' : 'AntiKt4Topo_EMJES',
22  'AntiKt4EMPFlow' : 'AntiKt4PFlow_EMJES',
23  }
24 
26  if not dirName.endswith("/"):
27  dirName = dirName + "/"
28 
29  # Run over each file (one per jet definition)
30  histos = {}
31  files = sorted(glob.glob(dirName+"*.root"))
32  for aFileName in files:
33  # Determine the jet definition
34  jetDef = ""
35  for aFileDef,aJetDef in jetDefDict.iteritems():
36  if aFileDef in aFileName:
37  jetDef = aJetDef
38  break
39  if jetDef == "":
40  print "Failed to determine jet definition for file:",aFileName
41  return None
42  if jetDef not in histos.keys() :
43  histos[jetDef] = {}
44 
45  # Read in the histograms of interest from the file
46  inFile = TFile(aFileName,"READ")
47  contents = inFile.GetKeyNames()
48  for aName in SystematicNames.keys():
49  if not "NonClosure" in SystematicNames[aName] :
50  if "Topo" in jetDef :
51  getsystematicName = aName + "_" + jetDef.replace("Topo","")
52  else :
53  getsystematicName = aName + "_" + jetDef.replace("4PFlow","4EMPFlow").replace("_EMJES","_PFlowJES")
54  else :
55  getsystematicName = aName
56 
57  if not getsystematicName in contents :
58  continue
59 
60  histo = inFile.Get(getsystematicName)
61 
62  systematicName = SystematicNames[aName] + "_" + jetDef
63  histo.SetName(systematicName+"_old")
64 
65  # Histo has different range, extend it
66  histoNew = ProviderHistoHelpers.ExtendPtRangeOfHisto(histo,systematicName)
67  histoNew.SetDirectory(0)
68  histos[jetDef][SystematicNames[aName]] = histoNew
69 
70  # Done reading, close the file
71  inFile.Close()
72 
73  # Since histos came from a whole mix of files, make sure we got them all in the end.
74  for aName,storeName in SystematicNames.iteritems():
75  for aJetDef in histos.keys():
76  if not storeName in histos[aJetDef].keys() :
77  print "Failed to find histogram:", storeName,"for jet definition",aJetDef
78 
79  print "About to return eta intercalib histos"
80  print histos
81  print "\n"
82  return histos
83 
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
ParseEtaIntercalInput.ReadEtaIntercalibrationHistograms
def ReadEtaIntercalibrationHistograms(dirName)
Definition: Final2012/ParseEtaIntercalInput.py:19
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
ProviderHistoHelpers.ExtendPtRangeOfHisto
def ExtendPtRangeOfHisto(histo, histoName)
Definition: Final2012/ProviderHistoHelpers.py:97
ParseEtaIntercalInput.GetKeyNames
def GetKeyNames(self, dir="")
Definition: January2018_specialStatTerms/ParseEtaIntercalInput.py:8
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798