23def ReadFlavourHistograms(dirName,freezepT=False):
24 if not dirName.endswith("/") and not dirName.endswith(".root"):
25 dirName = dirName + "/"
26 if dirName.endswith("/") :
27 files = sorted(glob.glob(dirName+"*.root"))
28 else :
29 files = [dirName]
30
31
32 histos = {}
33 for aFileName in files:
34
35 jetDef = ""
36 for jetDef in jetDefDict.keys() :
37 print "Beginning jetDef",jetDef
38 if jetDefDict[jetDef] not in histos:
39 histos[jetDefDict[jetDef]] = {}
40
41
42
43
44 inFile = TFile(aFileName,"READ")
45 for histName in inFile.GetKeyNames():
46 systName = histName.split("_")[0]
47 if not systName in SystematicNames :
48 print "Error!!!"
49 continue
50 if not jetDef in histName :
51 continue
52 systematicName = systName + "_" + jetDefDict[jetDef]
53 histo = inFile.Get(histName)
54 if histo is None:
55 print "Failed to get histogram:",systematicName
56 return None
57
58 if freezepT :
59
60 for ybin in range(histo.GetNbinsY()+2) :
61
62 freezeval = 0
63 for xbin in range(histo.GetNbinsX()+2) :
64 inbin = histo.GetBinContent(xbin,ybin)
65
66
67 if inbin > 0 :
68 freezeval = inbin
69 else :
70 histo.SetBinContent(xbin,ybin,freezeval)
71
72 if systName.find("FlavorResponse")!=-1 :
73 histo.Scale(-1.0)
74
76 histoSym.SetDirectory(0)
77 histos[jetDefDict[jetDef]][systName] = histoSym
78
79
80 inFile.Close()
81
82 return histos