4 from array
import array
11 dx = (math.log(highVal)-math.log(lowVal))/numBins
13 for iBin
in range(0,numBins+1):
14 bins.append(math.exp(math.log(lowVal)+iBin*dx))
19 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]
21 for aVal
in etaValuesAsym:
22 etaValuesSym.append(aVal)
23 if math.fabs(aVal) > 1.e-4:
24 etaValuesSym.append(-aVal)
26 return sorted(etaValuesSym)
30 return [values[0]*0.5,values[0]*1.5]
33 for iVal
in range(0,len(values)-1):
34 binList.append(values[iVal]+(values[iVal+1]-values[iVal])/2.0)
35 binList.insert(0,values[0]-(values[1]-values[0])/2.0)
36 binList.append(values[-1]+(values[-1]-values[-2])/2.0)
41 return TH2D(histoName,histoName,len(ptBins)-1,
array(
'd',ptBins),len(etaBins)-1,
array(
'd',etaBins))
47 oldMinPt = histo1D.GetXaxis().GetBinLowEdge(1)
48 oldMaxPt = histo1D.GetXaxis().GetBinLowEdge(histo1D.GetNbinsX()+1)
50 for ptBin
in range(1,histo2D.GetNbinsX()+1):
51 pt = histo2D.GetXaxis().GetBinCenter(ptBin)
54 unc = histo1D.Interpolate(oldMinPt+tolerance)
56 unc = histo1D.Interpolate(oldMaxPt+tolerance)
58 unc = histo1D.Interpolate(pt)
60 for etaBin
in range(1,histo2D.GetNbinsY()+1):
61 histo2D.SetBinContent(ptBin,etaBin,unc)
68 for iPoint
in range(0,graph.GetN()):
71 graph.GetPoint(iPoint,px,py)
81 pointsX.inset(0,(bins[0]+bins[1])/2.0)
82 pointsY.insert(0,pointsY[0])
86 pointsX.append((bins[-1]+bins[-2])/2.0)
87 pointsY.append(pointsY[-1])
91 for ptBin
in range(1,histo.GetNbinsX()+1):
92 for etaBin
in range(1,histo.GetNbinsY()+1):
93 histo.SetBinContent(ptBin,etaBin,pointsY[ptBin-1])
100 for xBin
in range(1,histo.GetNbinsX()+2):
101 ptBins.append(histo.GetXaxis().GetBinLowEdge(xBin))
104 if math.fabs(ptBins[-1] - 2500) < 1.e-4:
105 print "Histo already went to 2500 GeV, doing nothing"
107 elif ptBins[-1] > 2500:
108 print "Histo beyond range, cannot extend"
114 for yBin
in range(1,histo.GetNbinsY()+2):
115 etaBins.append(histo.GetYaxis().GetBinLowEdge(yBin))
119 for xBin
in range(1,histo.GetNbinsX()+1):
120 for yBin
in range(1,histo.GetNbinsY()+1):
121 newHisto.SetBinContent(xBin,yBin,histo.GetBinContent(xBin,yBin))
122 for yBin
in range(1,histo.GetNbinsY()+1):
123 newHisto.SetBinContent(histo.GetNbinsX()+1,yBin,histo.GetBinContent(histo.GetNbinsX(),yBin))
130 for yBin
in range(1,histo.GetNbinsY()+2):
131 etaVal = histo.GetYaxis().GetBinLowEdge(yBin)
132 if math.fabs(etaVal) > 1.e-4:
133 etaBins.append(-etaVal)
134 etaBins.append(etaVal)
139 for xBin
in range(1,histo.GetNbinsX()+2):
140 ptBins.append(histo.GetXaxis().GetBinLowEdge(xBin))
144 for xBin
in range(1,histo.GetNbinsX()+1):
145 xVal = histo.GetXaxis().GetBinCenter(xBin)
146 for yBin
in range(1,histo.GetNbinsY()+1):
147 yVal = histo.GetYaxis().GetBinCenter(yBin)
148 newHisto.SetBinContent(newHisto.GetXaxis().
FindBin(xVal),newHisto.GetYaxis().
FindBin(-yVal),histo.GetBinContent(xBin,yBin))
149 newHisto.SetBinContent(newHisto.GetXaxis().
FindBin(xVal),newHisto.GetYaxis().
FindBin(yVal),histo.GetBinContent(xBin,yBin))
160 for aHisto
in histos[1:]:
161 if aHisto.GetNbinsX() != histos[0].GetNbinsX():
162 print "Input histograms have different number of x bins - can't do quadrature sum safely"
164 elif aHisto.GetNbinsY() != histos[0].GetNbinsY():
165 print "Input histograms have different number of y bins - can't do quadrature sum safely"
167 for xBin
in range(1,histos[0].GetNbinsX()+2):
169 for aHisto
in histos:
171 edge = aHisto.GetXaxis().GetBinLowEdge(xBin)
172 elif math.fabs(edge-aHisto.GetXaxis().GetBinLowEdge(xBin)) > tolerance:
173 print "Input histograms have different x binning - can't do quadrature sum safely"
175 for yBin
in range(1,histos[0].GetNbinsY()+2):
177 for aHisto
in histos:
179 edge = aHisto.GetYaxis().GetBinLowEdge(yBin)
180 elif math.fabs(edge-aHisto.GetYaxis().GetBinLowEdge(yBin)) > tolerance:
181 print "Input histograms have different y binning - can't do quadrature sum safely"
186 quadSumHisto = histos[0].Clone()
187 for xBin
in range(1,quadSumHisto.GetNbinsX()+1):
188 for yBin
in range(1,quadSumHisto.GetNbinsY()+1):
190 for aHisto
in histos:
191 quadSum +=
pow(aHisto.GetBinContent(xBin,yBin),2)
192 quadSumHisto.SetBinContent(xBin,yBin,sqrt(quadSum))