ATLAS Offline Software
Loading...
Searching...
No Matches
ICHEP2016/Parse2012Input.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# Dictionary to translate from Bogan's names to provider names
11useJetCollections = {"AntiKt4EMTopo": "AntiKt4Topo_EMJES", "AntiKt4LCTopo": "AntiKt4Topo_LCJES"}
12
13haveUpdatedVersions = ["FlavorResponse",
14 "flavorCompGlu",
15 "flavorCompLight",
16 "Pileup_OffsetMu",
17 "Pileup_OffsetNPV",
18 "Pileup_PtTerm_Mu",
19 "Pileup_PtTerm_NPV",
20# "PunchThrough_AFII",
21# "PunchThrough_MC12",
22 "RelativeNonClosure_AFII",
23 "RelativeNonClosure_MC12",
24 "EtaIntercalibration_Modelling",
25 "EtaIntercalibration_TotalStat",]
26
27def GetKeyNames(self,dir=""):
28 self.cd(dir)
29 return [key.GetName() for key in gDirectory.GetListOfKeys()]
30TFile.GetKeyNames = GetKeyNames
31
32def Read2012Histograms(dirName,scaleEtaInter3Regions=False,scaleEtaInter2Regions=False):
33 removeInSitu = False
34 if not dirName.endswith("/"):
35 dirName = dirName + "/"
36
37 # Just one file here with everything in it.
38 aSystFile = dirName + "JESUncertainty_2012.root"
39 systematicFile = TFile(aSystFile,"READ")
40
41 histos = {}
42 for key in systematicFile.GetKeyNames() :
43
44 # Formatting is all already correct.
45
46 # Only keep things of the jet collections we are using.
47 jettype = key.split("_")[-1]
48 if jettype not in useJetCollections.keys() :
49 continue
50 elif useJetCollections[jettype] not in histos :
51 print "Adding extra dict..."
52 histos[useJetCollections[jettype]] = {}
53
54 # Only keep things for which we do not have a more current version.
55 systname = key.replace("_"+jettype,"")
56 if systname in haveUpdatedVersions :
57 continue
58
59 histo = systematicFile.Get(key)
60 histo.SetDirectory(0)
61
62 if key.find("EtaIntercalibration_Modelling")!=-1 and (scaleEtaInter3Regions or scaleEtaInter2Regions) :
63
64 print "OH NO!!!"
65 return
66
67 # Loop over pT bins.
68 for xbin in range(histo.GetNbinsX()+2) :
69 # Loop out in eta.
70 for ybin in range(histo.GetNbinsY()+2) :
71 run1val = histo.GetBinContent(xbin,ybin)
72 #print "Bin at pT ",histo.GetXaxis().GetBinCenter(xbin)," and [ylow,y,yhigh] = ", binYLow, histo.GetYaxis().GetBinCenter(ybin), binYHigh
73 # Store bin contents as we go out: last one is one we want as frozen value.
74 if abs(histo.GetYaxis().GetBinCenter(ybin)) < 0.8 :
75 continue
76 elif 0.8 < abs(histo.GetYaxis().GetBinCenter(ybin)) < 2.5 :
77 if scaleEtaInter3Regions :
78 histo.SetBinContent(xbin,ybin,2.0*run1val)
79 else :
80 continue
81 else :
82 histo.SetBinContent(xbin,ybin,3.0*run1val)
83
84 if (key.find("LAr_")!=-1 or key.find("Zjet_")!=-1 or key.find("Gjet")!=-1) and removeInSitu :
85
86 # Loop over all bins. If outside eta range, set to "no uncertainty" = 0
87 for xbin in range(histo.GetNbinsX()+2) :
88 for ybin in range(histo.GetNbinsY()+2) :
89 # Set to zero if outside of eta range.
90 #print 'Eta is', abs(histo.GetYaxis().GetBinCenter(ybin))
91 if abs(histo.GetYaxis().GetBinCenter(ybin)) > 0.8 :
92 histo.SetBinContent(xbin,ybin,0.0)
93 else :
94 continue
95 #print "Leaving bin content."
96
97 if key.find("PunchThrough")!=-1 :
98
99 # Find maximum value on old histogram: we will use this everywhere
100 maxVal = histo.GetMaximum()
101 print "For punchthrough, using max val",maxVal
102
103 # Loop over all bins in x, y, z.
104 for xbin in range(histo.GetNbinsX()+2) :
105 for ybin in range(histo.GetNbinsY()+2) :
106 for zbin in range(histo.GetNbinsZ()+2) :
107 # Permitted regions are only:
108 # - pT > 50 GeV
109 # - eta < 2.7
110 # - NSegments > 20
111
112 # x axis is pT.
113 # y axis is nSegments
114 # z axis is eta
115 if histo.GetXaxis().GetBinCenter(xbin) < 50 or \
116 histo.GetYaxis().GetBinCenter(ybin) < 20 or \
117 histo.GetZaxis().GetBinCenter(zbin) > 2.7 :
118 histo.SetBinContent(xbin,ybin,zbin,0.0)
119
120 else :
121 # Set to maximum value
122 histo.SetBinContent(xbin,ybin,zbin,maxVal)
123
124 if key.find("MC12") :
125 # New histo
126 newhist = histo.Clone()
127 oldname = histo.GetName()
128 newname = oldname.replace("MC12","MC15")
129 newhist.SetName(newname)
130 newkey = systname.replace("MC12","MC15")
131 newhist.SetDirectory(0)
132 histos[useJetCollections[jettype]][newkey] = newhist
133 continue
134
135 histos[useJetCollections[jettype]][systname] = histo
136
137 # Done, return dictionary of histos
138 return histos
139
140
141
142
Read2012Histograms(dirName, scaleEtaInter3Regions=False, scaleEtaInter2Regions=False)