ATLAS Offline Software
Loading...
Searching...
No Matches
January2018_specialStatTerms/ParseCrossCalInput.py
Go to the documentation of this file.
1from ROOT import *
2from array import array
3import glob
4import re
5import math
6import ProviderHistoHelpers
7
8SystematicNameDictionary = {
9 'Xcalib_50nsVs25ns_AntiKt4EMTopo':'Xcalib_50nsVs25ns',
10 'Xcalib_5Vs4sample_AntiKt4EMTopo':'Xcalib_5Vs4sample',
11 'Xcalib_TopoClustering_AntiKt4EMTopo':'Xcalib_TopoClustering',
12 'Xcalib_EarlyData_AntiKt4EMTopo':'Xcalib_EarlyData',
13 'Xcalib_NoiseThreshold_AntiKt4EMTopo':'Xcalib_NoiseThreshold',
14 'Xcalib_UnderlyingEvent_AntiKt4EMTopo':'Xcalib_UnderlyingEvent'
15 }
16
17jetDefDict = {
18 '' : 'AntiKt4Topo_EMJES',
19 }
20
21def ReadCrossCalHistograms(dirName,scaleCrossCalVal=1.0,freezeCrossCalAll=False,freezeCrossCalBarrel=False,freezeCrossCalCentral=False):
22 if not dirName.endswith("/"):
23 dirName = dirName + "/"
24
25 # Run over each file (one per jet definition)
26 histos = {}
27 files = sorted(glob.glob(dirName+"*.root"))
28 for aFileName in files:
29 # Determine the jet definition
30 jetDef = ""
31 for aFileDef,aJetDef in jetDefDict.iteritems():
32 if aFileDef in aFileName:
33 jetDef = aJetDef
34 break
35 if jetDef == "":
36 print "Failed to determine jet definition for file:",aFileName
37 return None
38
39 histos[jetDef] = {}
40
41 # Read in the histograms of interest from the file
42 inFile = TFile(aFileName,"READ")
43
44 for histName in inFile.GetKeyNames():
45
46 # Skip validity histograms.
47 if 'valid' in histName :
48 continue
49
50 systematicName = SystematicNameDictionary[histName]+"_"+jetDef
51 histo = inFile.Get(histName)
52 if histo is None:
53 print "Failed to get histogram:",systematicName
54 return None
55 histo.SetName(systematicName+"_old")
56
57 if freezeCrossCalAll or freezeCrossCalBarrel or freezeCrossCalCentral :
58 # Loop over pT bins.
59 for xbin in range(histo.GetNbinsX()+2) :
60 # Loop out in eta.
61 freezeval = 0
62 for ybin in range(histo.GetNbinsY()+2) :
63 #print "Bin at pT ",histo.GetXaxis().GetBinCenter(xbin)," and [ylow,y,yhigh] = ", binYLow, histo.GetYaxis().GetBinCenter(ybin), binYHigh
64 # Store bin contents as we go out: last one is one we want as frozen value.
65 eta = abs(histo.GetYaxis().GetBinCenter(ybin))
66 if eta < 0.8 :
67 freezeval = histo.GetBinContent(xbin,ybin)
68 else :
69 if (eta < 2.5 and freezeCrossCalBarrel) or freezeCrossCalAll :
70 histo.SetBinContent(xbin,ybin,freezeval*scaleCrossCalVal)
71 else :
72 histo.SetBinContent(xbin,ybin,0)
73
74
75 # Histo has different range, extend it
76 histoNew = ProviderHistoHelpers.ExtendPtRangeOfHisto(histo,systematicName)
77 histoSym = ProviderHistoHelpers.SymmetrizeHistoInEta(histoNew,systematicName)
78 histoSym.SetDirectory(0)
79
80 # If this is the 50 vs 25 ns histogram, we need to separate it by eta region.
81 if '50nsVs25ns' in histName :
82 CentralHist = histo.Clone()
83 CentralHist.SetName("Central_holder")
84 ForwardHist = histo.Clone()
85 ForwardHist.SetName("Forward_holder")
86 # Loop over pT bins.
87 for xbin in range(histo.GetNbinsX()+2) :
88 # Loop out in eta.
89 freezeval = 0
90 for ybin in range(histo.GetNbinsY()+2) :
91 #print "Bin at pT ",histo.GetXaxis().GetBinCenter(xbin)," and [ylow,y,yhigh] = ", binYLow, histo.GetYaxis().GetBinCenter(ybin), binYHigh
92 # Store bin contents as we go out: last one is one we want as frozen value.
93 eta = abs(histo.GetYaxis().GetBinCenter(ybin))
94 if eta < 0.8 :
95 freezeval = histo.GetBinContent(xbin,ybin)
96 ForwardHist.SetBinContent(xbin,ybin,0.0)
97 CentralHist.SetBinContent(xbin,ybin,freezeval)
98 else :
99 ForwardHist.SetBinContent(xbin,ybin,freezeval)
100 CentralHist.SetBinContent(xbin,ybin,0.0)
101
102 # Now do symmetrization for these hists and write to file.
103 NewCentral = ProviderHistoHelpers.ExtendPtRangeOfHisto(CentralHist,systematicName+"holder")
104 CentralSym = ProviderHistoHelpers.SymmetrizeHistoInEta(NewCentral,SystematicNameDictionary[histName]+"_Central_"+jetDef)
105 CentralSym.SetDirectory(0)
106 histos[jetDef][SystematicNameDictionary[histName]+"_Central"] = CentralSym
107 NewForward = ProviderHistoHelpers.ExtendPtRangeOfHisto(ForwardHist,systematicName+"holder")
108 ForwardSym = ProviderHistoHelpers.SymmetrizeHistoInEta(NewForward,SystematicNameDictionary[histName]+"_Forward_"+jetDef)
109 ForwardSym.SetDirectory(0)
110 histos[jetDef][SystematicNameDictionary[histName]+"_Forward"] = ForwardSym
111
112 # If this is the early data histogram, we need to deactivate it in the central region for 25 ns data.
113 if 'EarlyData' in histName :
114 ForwardHist = histo.Clone()
115 ForwardHist.SetName("EarlyData_Forward_holder")
116 # Loop over pT bins.
117 for xbin in range(histo.GetNbinsX()+2) :
118 # Loop out in eta.
119 for ybin in range(histo.GetNbinsY()+2) :
120 #print "Bin at pT ",histo.GetXaxis().GetBinCenter(xbin)," and [ylow,y,yhigh] = ", binYLow, histo.GetYaxis().GetBinCenter(ybin), binYHigh
121 # Store bin contents as we go out: last one is one we want as frozen value.
122 eta = abs(histo.GetYaxis().GetBinCenter(ybin))
123 if eta < 0.8 :
124 ForwardHist.SetBinContent(xbin,ybin,0.0)
125
126 # Now do symmetrization and write to file.
127 NewForward = ProviderHistoHelpers.ExtendPtRangeOfHisto(ForwardHist,systematicName+"holder")
128 ForwardSym = ProviderHistoHelpers.SymmetrizeHistoInEta(NewForward,SystematicNameDictionary[histName]+"_Forward_"+jetDef)
129 ForwardSym.SetDirectory(0)
130 histos[jetDef][SystematicNameDictionary[histName]+"_Forward"] = ForwardSym
131 histos[jetDef][SystematicNameDictionary[histName]] = histoSym
132
133 else :
134 histos[jetDef][SystematicNameDictionary[histName]] = histoSym
135
136 # Done reading, close the file
137 inFile.Close()
138
139 return histos
140
141def ReadCrossCalValidityHistograms(dirName):
142 if not dirName.endswith("/"):
143 dirName = dirName + "/"
144
145 # Run over each file (one per jet definition)
146 histos = {}
147 files = sorted(glob.glob(dirName+"*.root"))
148 for aFileName in files:
149 # Determine the jet definition
150 jetDef = ""
151 for aFileDef,aJetDef in jetDefDict.iteritems():
152 if aFileDef in aFileName:
153 jetDef = aJetDef
154 break
155 if jetDef == "":
156 print "Failed to determine jet definition for file:",aFileName
157 return None
158 histos[jetDef] = {}
159
160 # Read in the histograms of interest from the file
161 inFile = TFile(aFileName,"READ")
162 for histName in inFile.GetKeyNames():
163 if 'valid' not in histName :
164 continue
165 dictkey = histName.replace("valid_","")
166 systematicName = "valid_"+SystematicNameDictionary[dictkey]+"_"+jetDef
167 histo = inFile.Get(histName)
168 if histo is None:
169 print "Failed to get histogram:",systematicName
170 return None
171 histo.SetName(systematicName+"_old")
172
173 # Histo has different range, extend it
174 histoNew = ProviderHistoHelpers.ExtendPtRangeOfHisto(histo,"valid_"+systematicName)
175 histoSym = ProviderHistoHelpers.SymmetrizeHistoInEta(histoNew,"valid_"+systematicName)
176 histoSym.SetDirectory(0)
177 histos[jetDef][SystematicNameDictionary[dictkey]] = histoSym
178
179 # Done reading, close the file
180 inFile.Close()
181
182 return histos