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