2 from array
import array
9 dx = (math.log(highVal)-math.log(lowVal))/numBins
11 for iBin
in range(0,numBins+1):
12 bins.append(math.exp(math.log(lowVal)+iBin*dx))
17 etaValuesAsym = [0,0.15,0.3,0.8,1.0,1.2,1.65,2.1,2.45,2.8,3.0,3.2,3.6,4.5]
19 for aVal
in etaValuesAsym:
20 etaValuesSym.append(aVal)
21 if math.fabs(aVal) > 1.e-4:
22 etaValuesSym.append(-aVal)
24 return sorted(etaValuesSym)
28 return [values[0]*0.5,values[0]*1.5]
31 for iVal
in range(0,len(values)-1):
32 binList.append(values[iVal]+(values[iVal+1]-values[iVal])/2.0)
33 binList.insert(0,values[0]-(values[1]-values[0])/2.0)
34 binList.append(values[-1]+(values[-1]-values[-2])/2.0)
39 return TH2D(histoName,histoName,len(ptBins)-1,
array(
'd',ptBins),len(etaBins)-1,
array(
'd',etaBins))
45 oldMinPt = histo1D.GetXaxis().GetBinLowEdge(1)
46 oldMaxPt = histo1D.GetXaxis().GetBinLowEdge(histo1D.GetNbinsX()+1)
48 for ptBin
in range(1,histo2D.GetNbinsX()+1):
49 pt = histo2D.GetXaxis().GetBinCenter(ptBin)
52 unc = histo1D.Interpolate(oldMinPt+tolerance)
54 unc = histo1D.Interpolate(oldMaxPt+tolerance)
56 unc = histo1D.Interpolate(pt)
58 for etaBin
in range(1,histo2D.GetNbinsY()+1):
59 histo2D.SetBinContent(ptBin,etaBin,unc)
66 for iPoint
in range(0,graph.GetN()):
69 graph.GetPoint(iPoint,px,py)
79 pointsX.inset(0,(bins[0]+bins[1])/2.0)
80 pointsY.insert(0,pointsY[0])
84 pointsX.append((bins[-1]+bins[-2])/2.0)
85 pointsY.append(pointsY[-1])
89 for ptBin
in range(1,histo.GetNbinsX()+1):
90 for etaBin
in range(1,histo.GetNbinsY()+1):
91 histo.SetBinContent(ptBin,etaBin,pointsY[ptBin-1])
98 for xBin
in range(1,histo.GetNbinsX()+2):
99 ptBins.append(histo.GetXaxis().GetBinLowEdge(xBin))
102 if math.fabs(ptBins[-1] - 2500) < 1.e-4:
103 print "Histo already went to 2500 GeV, doing nothing"
105 elif ptBins[-1] > 2500:
106 print "Histo beyond range, cannot extend"
112 for yBin
in range(1,histo.GetNbinsY()+2):
113 etaBins.append(histo.GetYaxis().GetBinLowEdge(yBin))
117 for xBin
in range(1,histo.GetNbinsX()+1):
118 for yBin
in range(1,histo.GetNbinsY()+1):
119 newHisto.SetBinContent(xBin,yBin,histo.GetBinContent(xBin,yBin))
120 for yBin
in range(1,histo.GetNbinsY()+1):
121 newHisto.SetBinContent(histo.GetNbinsX()+1,yBin,histo.GetBinContent(histo.GetNbinsX(),yBin))
128 for yBin
in range(1,histo.GetNbinsY()+2):
129 etaVal = histo.GetYaxis().GetBinLowEdge(yBin)
130 if math.fabs(etaVal) > 1.e-4:
131 etaBins.append(-etaVal)
132 etaBins.append(etaVal)
137 for xBin
in range(1,histo.GetNbinsX()+2):
138 ptBins.append(histo.GetXaxis().GetBinLowEdge(xBin))
142 for xBin
in range(1,histo.GetNbinsX()+1):
143 xVal = histo.GetXaxis().GetBinCenter(xBin)
144 for yBin
in range(1,histo.GetNbinsY()+1):
145 yVal = histo.GetYaxis().GetBinCenter(yBin)
146 newHisto.SetBinContent(newHisto.GetXaxis().
FindBin(xVal),newHisto.GetYaxis().
FindBin(-yVal),histo.GetBinContent(xBin,yBin))
147 newHisto.SetBinContent(newHisto.GetXaxis().
FindBin(xVal),newHisto.GetYaxis().
FindBin(yVal),histo.GetBinContent(xBin,yBin))
158 for aHisto
in histos[1:]:
159 if aHisto.GetNbinsX() != histos[0].GetNbinsX():
160 print "Input histograms have different number of x bins - can't do quadrature sum safely"
162 elif aHisto.GetNbinsY() != histos[0].GetNbinsY():
163 print "Input histograms have different number of y bins - can't do quadrature sum safely"
165 for xBin
in range(1,histos[0].GetNbinsX()+2):
167 for aHisto
in histos:
169 edge = aHisto.GetXaxis().GetBinLowEdge(xBin)
170 elif math.fabs(edge-aHisto.GetXaxis().GetBinLowEdge(xBin)) > tolerance:
171 print "Input histograms have different x binning - can't do quadrature sum safely"
173 for yBin
in range(1,histos[0].GetNbinsY()+2):
175 for aHisto
in histos:
177 edge = aHisto.GetYaxis().GetBinLowEdge(yBin)
178 elif math.fabs(edge-aHisto.GetYaxis().GetBinLowEdge(yBin)) > tolerance:
179 print "Input histograms have different y binning - can't do quadrature sum safely"
184 quadSumHisto = histos[0].Clone()
185 for xBin
in range(1,quadSumHisto.GetNbinsX()+1):
186 for yBin
in range(1,quadSumHisto.GetNbinsY()+1):
188 for aHisto
in histos:
189 quadSum +=
pow(aHisto.GetBinContent(xBin,yBin),2)
190 quadSumHisto.SetBinContent(xBin,yBin,sqrt(quadSum))