ATLAS Offline Software
Loading...
Searching...
No Matches
ICHEP2016/ParseHighPtInput.py
Go to the documentation of this file.
1# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2
3from ROOT import *
4from array import array
5import glob
6import re
7import math
8import ProviderHistoHelpers
9
10
11def GetKeyNames(self,dir=""):
12 self.cd(dir)
13 return [key.GetName() for key in gDirectory.GetListOfKeys()]
14TFile.GetKeyNames = GetKeyNames
15
16jetDefList = ['AntiKt4Topo_EMJES',"AntiKt4Topo_LCJES"]#,'AntiKt6Topo_EMJES','AntiKt4Topo_LCJES','AntiKt6Topo_LCJES']
17
19
20 histos = {}
21 for jetDef in jetDefList :
22 histos[jetDef] = {}
23 inFile = TFile(fileName,"READ")
24 uncNames = ["SingleParticle_HighPt"]
25 jetCollections = {"AntiKt4EMTopo" : "AntiKt4Topo_EMJES", "AntiKt4LCTopo" : "AntiKt4Topo_LCJES"}
26 for name in uncNames :
27 for jetCollection in jetCollections.keys() :
28 getJetType = jetCollections[jetCollection]
29 fetchName = name+"_"+getJetType
30 hist = inFile.Get(fetchName)
31 print "retrieved",fetchName
32 hist.SetDirectory(0)
33 histos[jetCollections[jetCollection]][name] = hist
34
35 return histos
36
37def ReadHighPtHistograms(dirName):
38
39 if os.path.isdir(dirName):
40 fileList = sorted(glob.glob(dirName+"*.root"))
41 if len(fileList) > 1 :
42 print "Nope!!!"
43 return {}
44 else :
45 file = TFile(fileList[0],"READ")
46 else :
47 file = TFile(dirName,"READ")
48
49 # Run over the file
50# emFileList = sorted(glob.glob(dirName+"EM*/*.root"))
51# lcFileList = sorted(glob.glob(dirName+"LC*/*.root"))
52# if len(emFileList) != 1:
53# print "Found a number of EM root files not equal to 1 in dir:",dirName
54# return None
55# if len(lcFileList) != 1:
56# print "Found a number of LC root files not equal to 1 in dir:",dirName
57# return None
58# emFile = TFile(emFileList[0],"READ")
59# lcFile = TFile(lcFileList[0],"READ")
60
61 histos = {}
62 for aJetDef in jetDefList:
63 histos[aJetDef] = {}
64
65# rootFile = None
66# if "EMJES" in aJetDef:
67# rootFile = emFile
68# elif "LCJES" in aJetDef:
69# rootFile = lcFile
70# else:
71# print "Unexpected jet def:",aJetDef
72# return None
73
74 rootFile = file
75
76 for histName in rootFile.GetKeyNames():
77 if aJetDef not in histName: continue
78 histo = rootFile.Get(histName)
79 if histo is None:
80 print "Failed to get histogram:",histName
81 return None
82 histo.SetName(histName+"_1D")
83
84 histos[aJetDef][re.sub("_%s"%(aJetDef),"",histName)] = ProviderHistoHelpers.ConvertPtHistoToProviderHisto(histo,histName)
85 histos[aJetDef][re.sub("_%s"%(aJetDef),"",histName)].SetDirectory(0)
86
87 lcFile.Close()
88 emFile.Close()
89
90 return histos
91
ConvertPtHistoToProviderHisto(histo1D, histoName)