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