ATLAS Offline Software
Final2012/ParsePunchthroughInput.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2 
3 from ROOT import *
4 from array import array
5 import glob
6 import re
7 import math
8 import ProviderHistoHelpers
9 
10 def GetKeyNames(self,dir=""):
11  self.cd(dir)
12  return [key.GetName() for key in gDirectory.GetListOfKeys()]
13 TFile.GetKeyNames = GetKeyNames
14 
15 SystematicNameDictionary = {
16  'PunchThroughUncertainties_interpolation_resp_eta_0' : 'PunchThroughCentral',
17  'PunchThroughUncertainties_interpolation_resp_eta_1' : 'PunchThroughCrack',
18  'PunchThroughUncertainties_interpolation_resp_eta_2' : 'PunchThroughForward'
19  }
20 
21 jetDefDict = {
22  'AntiKt4TopoEM' : 'AntiKt4Topo_EMJES',
23  'AntiKt6TopoEM' : 'AntiKt6Topo_EMJES',
24  'AntiKt4LCTopo' : 'AntiKt4Topo_LCJES',
25  'AntiKt6LCTopo' : 'AntiKt6Topo_LCJES'
26  }
27 
28 #SystematicNameList = ['PunchThroughCentral','PunchThroughCrack','PunchThroughForward']
29 #jetDefList = ['AntiKt4Topo_EMJES','AntiKt6Topo_EMJES','AntiKt4Topo_LCJES','AntiKt6Topo_LCJES']
30 
32  if not dirName.endswith("/"):
33  dirName = dirName + "/"
34 
35  # Run over the one file
36  rootFileList = sorted(glob.glob(dirName+"*.root"))
37  if len(rootFileList) != 1:
38  print "Found a number of root files not equal to 1 in dir:",dirName
39  return None
40  rootFile = TFile(rootFileList[0],"READ")
41 
42  histos = {}
43  for aJetDef,aJetDefProv in jetDefDict.iteritems():
44  histos[aJetDefProv] = {}
45 
46  for histName in rootFile.GetKeyNames():
47  if aJetDef not in histName: continue
48  for aKey,aVal in SystematicNameDictionary.iteritems():
49  histName = aJetDef+"_"+aKey
50  histo = rootFile.Get(histName)
51  if histo is None:
52  print "Failed to get histogram:",histName
53  return None
54  histo.SetName(aVal+"_"+aJetDefProv)
55  histo.SetDirectory(0)
56 
57  histos[aJetDefProv][aVal] = histo
58 
59  # Done reading, close the file
60  rootFile.Close()
61 
62 
76 
77  return histos
78 
ParsePunchthroughInput.ReadPunchthroughHistograms
def ReadPunchthroughHistograms(dirName)
Definition: Final2012/ParsePunchthroughInput.py:31
ParsePunchthroughInput.GetKeyNames
def GetKeyNames(self, dir="")
Definition: Final2012/ParsePunchthroughInput.py:10
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.