def setTDRStyle(force): gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(600) gStyle.SetCanvasDefW(600) gStyle.SetCanvasDefX(0) gStyle.SetCanvasDefY(0) gStyle.SetPadBorderMode(0) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(False) gStyle.SetPadGridY(False) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillColor(0) gStyle.SetFrameFillStyle(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) if force: gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(1) gStyle.SetEndErrorSize(2) gStyle.SetErrorX(0.) gStyle.SetMarkerStyle(20) gStyle.SetOptFit(1) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) gStyle.SetOptDate(0) gStyle.SetOptFile(0) gStyle.SetOptStat(0) gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.04) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.2) gStyle.SetPadTopMargin(0.05) gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.04) gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.05) gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.06, "XYZ") gStyle.SetTitleXOffset(0.9) gStyle.SetTitleYOffset(1.25) gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") gStyle.SetLabelSize(0.05, "XYZ") gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) gStyle.SetPaperSize(20.,20.) gROOT.ForceStyle()
def initialize2(self): # For the canvas: gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(600) #Height of canvas gStyle.SetCanvasDefW(600) #Width of canvas gStyle.SetCanvasDefX(0) #POsition on screen gStyle.SetCanvasDefY(0) # For the Pad: gStyle.SetPadBorderMode(0) # gStyle.SetPadBorderSize(Width_t size = 1) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(False) gStyle.SetPadGridY(False) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) # For the frame: gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillStyle(1000) gStyle.SetFrameFillColor(0) gStyle.SetFrameFillStyle(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) # For the histo: # gStyle.SetHistFillColor(1) # gStyle.SetHistFillStyle(0) gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(1) # gStyle.SetLegoInnerR(Float_t rad = 0.5) # gStyle.SetNumberContours(Int_t number = 20) gStyle.SetEndErrorSize(2) # gStyle.SetErrorMarker(20) gStyle.SetErrorX(0.) gStyle.SetMarkerStyle(20) #For the fit/function: gStyle.SetOptFit(1) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) #For the date: gStyle.SetOptDate(0) # gStyle.SetDateX(Float_t x = 0.01) # gStyle.SetDateY(Float_t y = 0.01) # For the statistics box: gStyle.SetOptFile(0) gStyle.SetOptStat( 0) # To display the mean and RMS: SetOptStat("mr") gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.025) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.15) # gStyle.SetStatStyle(Style_t style = 1001) # gStyle.SetStatX(Float_t x = 0) # gStyle.SetStatY(Float_t y = 0) # Margins: gStyle.SetPadTopMargin(0.05) gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.02) # For the Global title: gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.05) # gStyle.SetTitleH(0) # Set the height of the title box # gStyle.SetTitleW(0) # Set the width of the title box # gStyle.SetTitleX(0) # Set the position of the title box # gStyle.SetTitleY(0.985) # Set the position of the title box # gStyle.SetTitleStyle(Style_t style = 1001) # gStyle.SetTitleBorderSize(2) # For the axis titles: gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.06, "XYZ") # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size? # gStyle.SetTitleYSize(Float_t size = 0.02) gStyle.SetTitleXOffset(0.9) gStyle.SetTitleYOffset(1.25) # gStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset # For the axis labels: gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") gStyle.SetLabelSize(0.05, "XYZ") # For the axis: gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX( 1) # To get tick marks on the opposite side of the frame gStyle.SetPadTickY(1) # Change for log plots: gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) # Postscript options: gStyle.SetPaperSize(20., 20.)
def main(argv): LOADTREE_ANADIR = "/net/user/jfeintzeig/2012/PointSources/FinalFiles/MonteCarlo/" tr = TChain("MasterTree") tr.Add(LOADTREE_ANADIR + "PrunedNugenUpgoing4866.root") tr.Add(LOADTREE_ANADIR + "PrunedNugenDowngoing4866.root") tr.GetEntries() MCzenith = ctypes.c_double(0) tr.SetBranchAddress("MCPrimary1.zenith", MCzenith) MCazimuth = ctypes.c_double(0) tr.SetBranchAddress("MCPrimary1.azimuth", MCazimuth) eneMC = ctypes.c_double(0) tr.SetBranchAddress("MCPrimary1.energy", eneMC) SMPEzenith = ctypes.c_double(0) tr.SetBranchAddress("SplineMPE.zenith", SMPEzenith) SMPEazimuth = ctypes.c_double(0) tr.SetBranchAddress("SplineMPE.azimuth", SMPEazimuth) ene = ctypes.c_double(0) tr.SetBranchAddress("SplineMPEMuEXDifferential.energy", ene) err1 = ctypes.c_double(0) tr.SetBranchAddress("SplineMPEParaboloidFitParams.err1", err1) err2 = ctypes.c_double(0) tr.SetBranchAddress("SplineMPEParaboloidFitParams.err2", err2) oneW = ctypes.c_double(0) tr.SetBranchAddress("I3MCWeightDict.OneWeight", oneW) nEv = ctypes.c_double(0) tr.SetBranchAddress("I3MCWeightDict.NEvents", nEv) h = TH2D("pull", "pull", 50, 1, 9, 100, 0.01, 20) h.SetStats(0) h.GetXaxis().SetTitle("log_{10}(MuEx_energy [GeV])") h.GetYaxis().SetTitle("Pull: #Delta#Psi/#sigma_{parab.}") g = TGraphAsymmErrors(50) medians = [[] for i in range(0, 50)] mediansW = [[] for i in range(0, 50)] go = TGraph(50) go.SetMarkerStyle(22) go.SetMarkerColor(4) hEneW = TH1D( "hEneW", "MCPrimary energy; log_{10}(E [GeV]); #frac{d#Phi}{dE} [GeV^{-1} cm^{-2} s^{-1} sr^{-1} ( #frac{E}{GeV} )^{-2} ", 100, 1, 9.5) hREneW = TH1D( "hREneW", "Reco energy SplineMPEMuEXDiff; log_{10}(E [GeV]); #frac{d#Phi}{dE} [GeV^{-1} cm^{-2} s^{-1} sr^{-1} ( #frac{E}{GeV} )^{-2}", 100, 1, 9) for i in range(0, tr.GetEntries()): tr.GetEntry(i) #if not hem(SMPEzenith.value): # continue #if pSigma(err1.value,err2.value)>np.radians(5.): # continue w = weight(oneW.value, eneMC.value, nEv.value) hEneW.Fill(log10(eneMC.value), w) hREneW.Fill(log10(ene.value), w) dAngle = SpaceAngleRad(MCzenith.value, MCazimuth.value, SMPEzenith.value, SMPEazimuth.value) h.Fill(log10(ene.value), dAngle / pSigma(err1.value, err2.value), w) if h.GetXaxis().FindBin(log10(ene.value)) > 0 and h.GetXaxis().FindBin( log10(ene.value)) < 51: medians[h.GetXaxis().FindBin(log10(ene.value)) - 1].append( dAngle / pSigma(err1.value, err2.value)) mediansW[h.GetXaxis().FindBin(log10(ene.value)) - 1].append(w) #if i>200: #break npoints = 0 for i in range(1, h.GetNbinsX() + 1): if len(medians[i - 1]) > 3: g.SetPoint( npoints, h.GetXaxis().GetBinCenter(i), weighted_percentile(0.5, np.asarray(medians[i - 1]), np.asarray(mediansW[i - 1]))) g.SetPointError( npoints, 0., 0., weighted_percentile(0.5 - 0.341, np.asarray(medians[i - 1]), np.asarray(mediansW[i - 1])), weighted_percentile(0.5 + 0.341, np.asarray(medians[i - 1]), np.asarray(mediansW[i - 1]))) npoints += 1 c0 = TCanvas() hEneW.Draw() g.Set(npoints) g.SetMarkerStyle(20) gStyle.SetPalette(1) gStyle.SetOptLogz(1) spline = TSpline5("spl", TGraph(g)) filename = "SplineforCorr_IC86I.root" #if hem(0.): # filename=filename+"down.root" #else: # filename=filename+"up.root" fout = TFile(filename, "RECREATE") spline.Write() fout.Close() print "loading RescaledSigma_IC86_SplineMPE.C" ROOT.gROOT.ProcessLine(".L RescaledSigma_IC86_SplineMPE.C+") try: ROOT.loadSplines() except: pass npoints = 0 for i in range(1, h.GetNbinsX() + 1): if len(medians[i - 1]) > 3: #if hem(0.): #plotZen=0. #else: #plotZen=100. go.SetPoint( npoints, h.GetXaxis().GetBinCenter(i), ROOT.RescaledSigma_IC86_SplineMPE( 1., pow(10, h.GetXaxis().GetBinCenter(i)))) npoints += 1 go.Set(npoints) del medians[:] del medians del mediansW[:] del mediansW c = TCanvas() c.SetLogy() c.SetGridx() c.SetGridy() h.SetMinimum(1) h.Draw("colz") g.Draw("pl same") go.Draw("pl same") spline.Draw("lp same") h2 = TH2D("pull - corrected", "pull - corrected", 50, 1, 9, 100, 0.01, 20) h2.GetXaxis().SetTitle("log_{10}(E [GeV])") h2.GetYaxis().SetTitle("Pull_{corr}: #Delta#Psi/f_{corr}(#sigma_{parab.})") g2 = TGraphAsymmErrors(50) medians2 = [[] for i in range(0, 50)] medians2W = [[] for i in range(0, 50)] g2.SetMarkerStyle(20) for i in range(0, tr.GetEntries()): tr.GetEntry(i) #if not hem(SMPEzenith.value): continue #if pSigma(err1.value,err2.value)>np.radians(5.): # continue w = weight(oneW.value, eneMC.value, nEv.value) dAngle = SpaceAngleRad(MCzenith.value, MCazimuth.value, SMPEzenith.value, SMPEazimuth.value) h2.Fill( log10(ene.value), dAngle / (pSigma(err1.value, err2.value) * spline.Eval(log10(ene.value))), w) if h.GetXaxis().FindBin(log10(ene.value)) > 0 and h.GetXaxis().FindBin( log10(ene.value)) < 51: medians2[h.GetXaxis().FindBin(log10(ene.value)) - 1].append( dAngle / (pSigma(err1.value, err2.value) * spline.Eval(log10(ene.value)))) medians2W[h.GetXaxis().FindBin(log10(ene.value)) - 1].append(w) #if i>200: #break npoints = 0 for i in range(1, h2.GetNbinsX() + 1): if len(medians2[i - 1]) > 3: g2.SetPoint( npoints, h.GetXaxis().GetBinCenter(i), weighted_percentile(0.5, np.asarray(medians2[i - 1]), np.asarray(medians2W[i - 1]))) g2.SetPointError( npoints, 0., 0., weighted_percentile(0.5 - 0.341, np.asarray(medians2[i - 1]), np.asarray(medians2W[i - 1])), weighted_percentile(0.5 + 0.341, np.asarray(medians2[i - 1]), np.asarray(medians2W[i - 1]))) npoints += 1 del medians2[:] del medians2 del medians2W[:] del medians2W g2.Set(npoints) c2 = TCanvas() c2.SetLogy() c2.SetGridx() c2.SetGridy() h2.SetStats(0) h2.SetMinimum(1) h2.Draw("colz") g2.Draw("pl same") h3 = TH2D("pull - corrected xcheck", "pull - corrected xcheck", 50, 1, 9, 100, 0.01, 20) h3.GetXaxis().SetTitle("log_{10}(E [GeV])") h3.GetYaxis().SetTitle("Pull_{corr}: #Delta#Psi/f_{corr}(#sigma_{parab.})") g3 = TGraphAsymmErrors(50) medians3 = [[] for i in range(0, 50)] medians3W = [[] for i in range(0, 50)] g3.SetMarkerStyle(20) SigmaBins = [(0.5, 0.6, 1), (0.6, 0.7, 2), (0.7, 0.9, 4), (0.9, 1.3, 1), (1.3, 1.7, 2)] h_pdf_corr = [] for b in range(len(SigmaBins)): h_pdf_corr.append( TH1D("h_pdf_corr" + str(b), "h_pdf_corr" + str(b) + ";#Delta#Psi [deg]", 50, 0, 3)) h_pdf_corr[-1].SetLineColor(SigmaBins[b][2]) h_pdf_corr[-1].SetLineWidth(2) for i in range(0, tr.GetEntries()): tr.GetEntry(i) #if not hem(SMPEzenith.value): continue #if pSigma(err1.value,err2.value)>np.radians(5.): # continue w = weight(oneW.value, eneMC.value, nEv.value) dAngle = SpaceAngleRad(MCzenith.value, MCazimuth.value, SMPEzenith.value, SMPEazimuth.value) pull = dAngle / ROOT.RescaledSigma_IC86_SplineMPE( pSigma(err1.value, err2.value), ene.value) s_cor = ROOT.RescaledSigma_IC86_SplineMPE( pSigma(err1.value, err2.value), ene.value) h3.Fill(log10(ene.value), pull, w) for b in range(len(SigmaBins)): if SigmaBins[b][0] <= np.degrees( s_cor) and SigmaBins[b][1] > np.degrees(s_cor): h_pdf_corr[b].Fill(np.degrees(dAngle), w) if h.GetXaxis().FindBin(log10(ene.value)) > 0 and h.GetXaxis().FindBin( log10(ene.value)) < 51: medians3[h.GetXaxis().FindBin(log10(ene.value)) - 1].append(pull) medians3W[h.GetXaxis().FindBin(log10(ene.value)) - 1].append(w) #if i>200: #break npoints = 0 for i in range(1, h2.GetNbinsX() + 1): if len(medians3[i - 1]) > 3: g3.SetPoint( npoints, h.GetXaxis().GetBinCenter(i), weighted_percentile(0.5, np.asarray(medians3[i - 1]), np.asarray(medians3W[i - 1]))) g3.SetPointError( npoints, 0., 0., weighted_percentile(0.5 - 0.341, np.asarray(medians3[i - 1]), np.asarray(medians3W[i - 1])), weighted_percentile(0.5 + 0.341, np.asarray(medians3[i - 1]), np.asarray(medians3W[i - 1]))) npoints += 1 c30 = TCanvas() leg = ROOT.TLegend(0.7, 0.7, 1., 1.) ffunc = [] for b in range(3): h_pdf_corr[b].Sumw2() if b == 0: h_pdf_corr[b].Draw("HIST") else: h_pdf_corr[b].Draw("same HIST") ffunc.append(TF1("ffunc" + str(b), CircGaus, 0.001, 3., 2)) ffunc[-1].SetLineColor(SigmaBins[b][2]) ffunc[-1].SetParameter(0, 1.) ffunc[-1].SetParameter(1, 1.) h_pdf_corr[b].Fit(ffunc[-1], "R") ffunc[-1].Draw("same") leg.AddEntry( h_pdf_corr[b], "range: " + str(SigmaBins[b][0]) + " to " + str(SigmaBins[b][1]) + " #sigma_{fit}=" + '{:.2f}'.format(ffunc[-1].GetParameter(0)), "l") leg.Draw() c31 = TCanvas() leg1 = ROOT.TLegend(0.7, 0.7, 1., 1.) ffunc = [] for b in range(3, 5): h_pdf_corr[b].Sumw2() if b == 0: h_pdf_corr[b].Draw("HIST") else: h_pdf_corr[b].Draw("same HIST") ffunc.append(TF1("ffunc" + str(b), CircGaus, 0.001, 3., 2)) ffunc[-1].SetLineColor(SigmaBins[b][2]) ffunc[-1].SetParameter(0, 1.) ffunc[-1].SetParameter(1, 1.) h_pdf_corr[b].Fit(ffunc[-1], "R") ffunc[-1].Draw("same") leg1.AddEntry( h_pdf_corr[b], "range: " + str(SigmaBins[b][0]) + " to " + str(SigmaBins[b][1]) + " #sigma_{fit}=" + '{:.2f}'.format(ffunc[-1].GetParameter(0)), "l") leg1.Draw() g3.Set(npoints) c3 = TCanvas() c3.SetLogy() c3.SetGridx() c3.SetGridy() h3.SetStats(0) h3.SetMinimum(1) h3.Draw("colz") g3.Draw("pl same") c3.SaveAs("RescaledSigma_IC86_SplineMPE_corrected.png") raw_input("Press Enter to continue...")
def initStyle(): gROOT.SetStyle("Plain") # For the canvas: gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(700) #Height of canvas gStyle.SetCanvasDefW(700) #Width of canvas gStyle.SetCanvasDefX(0) #Position on screen gStyle.SetCanvasDefY(0) # For the line: gStyle.SetLineWidth(2) # For the Pad: gStyle.SetPadBorderMode(0) # gStyle.SetPadBorderSize(Width_t size = 1) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(True) gStyle.SetPadGridY(True) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) # For the frame: gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillColor(0) gStyle.SetFrameFillStyle(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) # For the histo: # gStyle.SetHistFillColor(1) # gStyle.SetHistFillStyle(0) gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(2) # gStyle.SetLegoInnerR(Float_t rad = 0.5) # gStyle.SetNumberContours(Int_t number = 20) gStyle.SetEndErrorSize(2) #gStyle.SetErrorMarker(20) gStyle.SetErrorX(0.) gStyle.SetMarkerStyle(8) gStyle.SetMarkerSize(1) #For the fit/function: gStyle.SetOptFit(0) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) #For the date: gStyle.SetOptDate(0) # gStyle.SetDateX(Float_t x = 0.01) # gStyle.SetDateY(Float_t y = 0.01) # For the statistics box: gStyle.SetOptFile(0) gStyle.SetOptStat(0) # To display the mean and RMS: SetOptStat("mr") gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.025) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.15) # gStyle.SetStatStyle(Style_t style = 1001) # gStyle.SetStatX(Float_t x = 0) # gStyle.SetStatY(Float_t y = 0) # Margins: gStyle.SetPadTopMargin(0.11) gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.17) gStyle.SetPadRightMargin(0.07) # For the Global title: gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.04) # gStyle.SetTitleH(0) # Set the height of the title box # gStyle.SetTitleW(0) # Set the width of the title box #gStyle.SetTitleX(0.35) # Set the position of the title box #gStyle.SetTitleY(0.986) # Set the position of the title box # gStyle.SetTitleStyle(Style_t style = 1001) #gStyle.SetTitleBorderSize(0) # For the axis titles: gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.05, "XYZ") # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size? # gStyle.SetTitleYSize(Float_t size = 0.02) gStyle.SetTitleXOffset(1.) gStyle.SetTitleYOffset(1.3) #gStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset # For the axis labels: gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") gStyle.SetLabelSize(0.035, "XYZ") # For the axis: gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX( 1) # To get tick marks on the opposite side of the frame gStyle.SetPadTickY(1) # Change for log plots: gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) gStyle.SetPalette(1) #(1,0) # another top group addition gStyle.SetHatchesSpacing(1.0) # Postscript options: gStyle.SetPaperSize(20., 20.) #gStyle.SetPaperSize(TStyle.kA4) #gStyle.SetPaperSize(27., 29.7) #TGaxis.SetMaxDigits(3) # gStyle.SetLineScalePS(Float_t scale = 3) # gStyle.SetLineStyleString(Int_t i, const char* text) # gStyle.SetHeaderPS(const char* header) # gStyle.SetTitlePS(const char* pstitle) #gStyle.SetColorModelPS(1) # gStyle.SetBarOffset(Float_t baroff = 0.5) # gStyle.SetBarWidth(Float_t barwidth = 0.5) # gStyle.SetPaintTextFormat(const char* format = "g") # gStyle.SetPalette(Int_t ncolors = 0, Int_t* colors = 0) # gStyle.SetTimeOffset(Double_t toffset) # gStyle.SetHistMinimumZero(kTRUE) #gStyle.cd() print "TDR Style initialized"
def main(argv): LOADTREE_ANADIR= "/net/user/tcarver/Data/PS/IC86_2012/"; tr = TChain("MasterTree") tr.Add("/net/user/tcarver/Data/PS/MESE/Nugen/MergedNugenMillipede_3999.root") tr.GetEntries() use11070=True tr1 = TChain("MasterTree") tr1.Add("/net/user/tcarver/Data/PS/MESE/Nugen/MESE_Merged_11070_Nfiles_4999.root") tr1.GetEntries() MCzenith=ctypes.c_double(0) tr.SetBranchAddress("MCPrimary1.zenith",MCzenith) MCazimuth=ctypes.c_double(0) tr.SetBranchAddress("MCPrimary1.azimuth",MCazimuth) eneMC=ctypes.c_double(0) tr.SetBranchAddress("MCPrimary1.energy",eneMC) oneW=ctypes.c_double(0) tr.SetBranchAddress("I3MCWeightDict.OneWeight",oneW) tr1.SetBranchAddress("I3MCWeightDict.OneWeight",oneW) nEv=ctypes.c_double(0) tr.SetBranchAddress("I3MCWeightDict.NEvents",nEv) tr1.SetBranchAddress("I3MCWeightDict.NEvents",nEv) maxMCE=ctypes.c_double(0) tr.SetBranchAddress("I3MCWeightDict.MaxEnergyLog",maxMCE) tr1.SetBranchAddress("I3MCWeightDict.MaxEnergyLog",maxMCE) tr1.SetBranchAddress("I3MCWeightDict.PrimaryNeutrinoZenith",MCzenith) tr1.SetBranchAddress("I3MCWeightDict.PrimaryNeutrinoAzimuth",MCazimuth) tr1.SetBranchAddress("I3MCWeightDict.PrimaryNeutrinoEnergy",eneMC) SMPEzenith=ctypes.c_double(0) tr.SetBranchAddress("SplineMPE.zenith",SMPEzenith) SMPEazimuth=ctypes.c_double(0) tr.SetBranchAddress("SplineMPE.azimuth",SMPEazimuth) tr1.SetBranchAddress("SplineMPE.zenith",SMPEzenith) tr1.SetBranchAddress("SplineMPE.azimuth",SMPEazimuth) LineFitzenith=ctypes.c_double(0) tr.SetBranchAddress("LineFit.zenith",LineFitzenith) LineFitazimuth=ctypes.c_double(0) tr.SetBranchAddress("LineFit.azimuth",LineFitazimuth) ene=ctypes.c_double(0) tr.SetBranchAddress("SplineMPEMuEXDifferential.energy",ene) tr1.SetBranchAddress("SplineMPEMuEXDifferential.energy",ene) err1=ctypes.c_double(0) tr.SetBranchAddress("SplineMPEParaboloidFitParams.err1",err1) err2=ctypes.c_double(0) tr.SetBranchAddress("SplineMPEParaboloidFitParams.err2",err2) tr1.SetBranchAddress("SplineMPEParaboloidFitParams.err1",err1) tr1.SetBranchAddress("SplineMPEParaboloidFitParams.err2",err2) FirstLoss_XYDist=ctypes.c_double(0) tr.SetBranchAddress("Millipede_FirstLoss_XYDist.value",FirstLoss_XYDist) FirstLoss_ZDist=ctypes.c_double(0) tr.SetBranchAddress("Millipede_FirstLoss_ZDist.value",FirstLoss_ZDist) h=TH2D("pull","pull",50,2,9,200,0.01,50) h.SetStats(0) h.GetXaxis().SetTitle("log_{10}(MuEx_energy [GeV])") h.GetYaxis().SetTitle("Pull: #Delta#Psi/#sigma_{parab.}") g=TGraphAsymmErrors(50) medians=[[] for i in range(0,50)] mediansW=[[] for i in range(0,50)] go=TGraph(50) go.SetMarkerStyle(22) go.SetMarkerColor(4) hEneW1=TH1D("hEneW1","MCPrimary energy; log_{10}(E [GeV]); #frac{d#Phi}{dE} [GeV^{-1} cm^{-2} s^{-1} sr^{-1} ( #frac{E}{GeV} )^{-2} ",100,1,9) hEneW2=TH1D("hEneW2","MCPrimary energy; log_{10}(E [GeV]); #frac{d#Phi}{dE} [GeV^{-1} cm^{-2} s^{-1} sr^{-1} ( #frac{E}{GeV} )^{-2} ",100,1,9) hEneW2.SetLineColor(2) hREneW1=TH1D("hREneW1","Reco energy SplineMPEMuEXDiff; log_{10}(E [GeV]); #frac{d#Phi}{dE} [GeV^{-1} cm^{-2} s^{-1} sr^{-1} ( #frac{E}{GeV} )^{-2}",100,1,9) hREneW2=TH1D("hREneW2","Reco energy SplineMPEMuEXDiff; log_{10}(E [GeV]); #frac{d#Phi}{dE} [GeV^{-1} cm^{-2} s^{-1} sr^{-1} ( #frac{E}{GeV} )^{-2}",100,1,9) hREneW2.SetLineColor(2) h_dAngle1=TH1D("h_dAngle1","h_dAngle1",100,0,0.2) h_Sigma1=TH1D("h_Sigma1","h_Sigma1",100,0,0.2) h_dAngle2=TH1D("h_dAngle2","h_dAngle2",100,0,0.2) h_dAngle2.SetLineColor(2) h_Sigma2=TH1D("h_Sigma2","h_Sigma2",100,0,0.2) h_Sigma2.SetLineColor(2) for i in range(0,tr.GetEntries()): tr.GetEntry(i) if not MESECut(FirstLoss_XYDist.value,FirstLoss_ZDist.value,ene.value,LineFitzenith.value,LineFitazimuth.value,SMPEzenith.value,SMPEazimuth.value): continue dAngle=SpaceAngleRad(MCzenith.value,MCazimuth.value , SMPEzenith.value, SMPEazimuth.value) if dAngle>np.radians(10.):continue w=weight(oneW.value,eneMC.value,nEv.value,maxMCE.value) hEneW1.Fill(log10(eneMC.value),w) hREneW1.Fill(log10(ene.value),w) h_dAngle1.Fill(dAngle,w) h_Sigma1.Fill(pSigma(err1.value,err2.value),w) h.Fill(log10(ene.value),dAngle/pSigma(err1.value,err2.value),w) if h.GetXaxis().FindBin(log10(ene.value))>0 and h.GetXaxis().FindBin(log10(ene.value))<51: medians[h.GetXaxis().FindBin(log10(ene.value))-1].append(dAngle/pSigma(err1.value,err2.value)) mediansW[h.GetXaxis().FindBin(log10(ene.value))-1].append(w) if use11070: for i in range(0,tr1.GetEntries()): tr1.GetEntry(i) dAngle=SpaceAngleRad(MCzenith.value,MCazimuth.value , SMPEzenith.value, SMPEazimuth.value) if dAngle>np.radians(10.):continue w=weight(oneW.value,eneMC.value,nEv.value,maxMCE.value) hEneW2.Fill(log10(eneMC.value),w) hREneW2.Fill(log10(ene.value),w) h_dAngle2.Fill(dAngle,w) h_Sigma2.Fill(pSigma(err1.value,err2.value),w) h.Fill(log10(ene.value),dAngle/pSigma(err1.value,err2.value),w) if h.GetXaxis().FindBin(log10(ene.value))>0 and h.GetXaxis().FindBin(log10(ene.value))<51: medians[h.GetXaxis().FindBin(log10(ene.value))-1].append(dAngle/pSigma(err1.value,err2.value)) mediansW[h.GetXaxis().FindBin(log10(ene.value))-1].append(w) npoints=0 for i in range(1,h.GetNbinsX()+1): if len(medians[i-1])>3: g.SetPoint(npoints,h.GetXaxis().GetBinCenter(i),weighted_percentile(0.5, np.asarray(medians[i-1]), np.asarray(mediansW[i-1]))) g.SetPointError(npoints,0.,0.,weighted_percentile(0.5-0.341, np.asarray(medians[i-1]), np.asarray(mediansW[i-1])), weighted_percentile(0.5+0.341, np.asarray(medians[i-1]), np.asarray(mediansW[i-1]))) npoints+=1 c0=TCanvas() hEneW1.Draw() if use11070: hEneW2.Draw("same") c00=TCanvas() hREneW1.Draw() if use11070: hREneW2.Draw("same") c01=TCanvas() h_dAngle1.Draw() if use11070: h_dAngle2.Draw("same") c02=TCanvas() h_Sigma1.Draw() if use11070: h_Sigma2.Draw("same") g.Set(npoints) g.SetMarkerStyle(20) gStyle.SetPalette(1) gStyle.SetOptLogz(1) spline= TSpline5("spl", TGraph(g)) fout=TFile("SplineMPEPullCorrectionMESE_out.root","RECREATE") spline.Write() fout.Close() ROOT.gROOT.ProcessLine(".L RescaledSigma_IC79_86_I_to_IV_SplineMPE_MESE.C+") try: ROOT.loadSplines() except: pass npoints=0 for i in range(1,h.GetNbinsX()+1): if len(medians[i-1])>3: go.SetPoint(npoints,h.GetXaxis().GetBinCenter(i),ROOT.RescaledSigma_IC79_86_I_to_IV_SplineMPE_MESE(1.,pow(10,h.GetXaxis().GetBinCenter(i)))) npoints+=1 go.Set(npoints) del medians[:] del medians del mediansW[:] del mediansW c=TCanvas() c.SetLogy() c.SetGridx() c.SetGridy() h.SetMinimum(1) h.Draw("colz") g.Draw("pl same") go.Draw("pl same") spline.Draw("lp same") h2=TH2D("pull - corrected","pull - corrected",50,2,9,200,0.01,50) h2.GetXaxis().SetTitle("log_{10}(E [GeV])") h2.GetYaxis().SetTitle("Pull_{corr}: #Delta#Psi/f_{corr}(#sigma_{parab.})") g2=TGraphAsymmErrors(50) medians2=[[] for i in range(0,50)] medians2W=[[] for i in range(0,50)] g2.SetMarkerStyle(20) for i in range(0,tr.GetEntries()): tr.GetEntry(i) if not MESECut(FirstLoss_XYDist.value,FirstLoss_ZDist.value,ene.value,LineFitzenith.value,LineFitazimuth.value,SMPEzenith.value,SMPEazimuth.value): continue dAngle=SpaceAngleRad(MCzenith.value,MCazimuth.value , SMPEzenith.value, SMPEazimuth.value) if dAngle>np.radians(10.):continue w=weight(oneW.value,eneMC.value,nEv.value,maxMCE.value) h2.Fill(log10(ene.value),dAngle/(pSigma(err1.value,err2.value)*spline.Eval(log10(ene.value))),w) if h.GetXaxis().FindBin(log10(ene.value))>0 and h.GetXaxis().FindBin(log10(ene.value))<51: medians2[h.GetXaxis().FindBin(log10(ene.value))-1].append(dAngle/(pSigma(err1.value,err2.value)*spline.Eval(log10(ene.value)))) medians2W[h.GetXaxis().FindBin(log10(ene.value))-1].append(w) if use11070: for i in range(0,tr1.GetEntries()): tr1.GetEntry(i) w=weight(oneW.value,eneMC.value,nEv.value,maxMCE.value) dAngle=SpaceAngleRad(MCzenith.value,MCazimuth.value , SMPEzenith.value, SMPEazimuth.value) if dAngle>np.radians(10.):continue h2.Fill(log10(ene.value),dAngle/(pSigma(err1.value,err2.value)*spline.Eval(log10(ene.value))),w) if h.GetXaxis().FindBin(log10(ene.value))>0 and h.GetXaxis().FindBin(log10(ene.value))<51: medians2[h.GetXaxis().FindBin(log10(ene.value))-1].append(dAngle/(pSigma(err1.value,err2.value)*spline.Eval(log10(ene.value)))) medians2W[h.GetXaxis().FindBin(log10(ene.value))-1].append(w) npoints=0 for i in range(1,h2.GetNbinsX()+1): if len(medians2[i-1])>3: g2.SetPoint(npoints,h.GetXaxis().GetBinCenter(i),weighted_percentile(0.5, np.asarray(medians2[i-1]), np.asarray(medians2W[i-1]))) g2.SetPointError(npoints,0.,0.,weighted_percentile(0.5-0.341, np.asarray(medians2[i-1]), np.asarray(medians2W[i-1])), weighted_percentile(0.5+0.341, np.asarray(medians2[i-1]), np.asarray(medians2W[i-1]))) npoints+=1 del medians2[:] del medians2 del medians2W[:] del medians2W g2.Set(npoints) go.Set(npoints) c2=TCanvas() c2.SetLogy() c2.SetGridx() c2.SetGridy() h2.SetStats(0) h2.SetMinimum(1) h2.Draw("colz") g2.Draw("pl same") h3=TH2D("pull - corrected xcheck","pull - corrected xcheck",50,2,9,200,0.01,50) h3.GetXaxis().SetTitle("log_{10}(E [GeV])") h3.GetYaxis().SetTitle("Pull_{corr}: #Delta#Psi/f_{corr}(#sigma_{parab.})") g3=TGraphAsymmErrors(50) medians3=[[] for i in range(0,50)] medians3W=[[] for i in range(0,50)] g3.SetMarkerStyle(20) SigmaBins=[(0.5,0.9),(0.9,1.3),(1.3,1.7)] h_pdf_corr=[] for b in range(len(SigmaBins)): h_pdf_corr.append(TH1D("h_pdf_corr"+str(b),"h_pdf_corr"+str(b)+";#Delta#Psi [deg]",100,0,3)) h_pdf_corr[-1].SetLineColor(b+1) for i in range(0,tr.GetEntries()): tr.GetEntry(i) if not MESECut(FirstLoss_XYDist.value,FirstLoss_ZDist.value,ene.value,LineFitzenith.value,LineFitazimuth.value,SMPEzenith.value,SMPEazimuth.value): continue dAngle=SpaceAngleRad(MCzenith.value,MCazimuth.value , SMPEzenith.value, SMPEazimuth.value) if dAngle>np.radians(10.):continue w=weight(oneW.value,eneMC.value,nEv.value,maxMCE.value) pull=dAngle/ROOT.RescaledSigma_IC79_86_I_to_IV_SplineMPE_MESE(pSigma(err1.value,err2.value),ene.value) h3.Fill(log10(ene.value),pull,w) s_cor=ROOT.RescaledSigma_IC79_86_I_to_IV_SplineMPE_MESE(pSigma(err1.value,err2.value),ene.value) for b in range(len(SigmaBins)): if SigmaBins[b][0]<=np.degrees(s_cor) and SigmaBins[b][1]>np.degrees(s_cor): h_pdf_corr[b].Fill(np.degrees(dAngle),w) if h.GetXaxis().FindBin(log10(ene.value))>0 and h.GetXaxis().FindBin(log10(ene.value))<51: medians3[h.GetXaxis().FindBin(log10(ene.value))-1].append(pull) medians3W[h.GetXaxis().FindBin(log10(ene.value))-1].append(w) #if i>200: #break if use11070: for i in range(0,tr1.GetEntries()): tr1.GetEntry(i) dAngle=SpaceAngleRad(MCzenith.value,MCazimuth.value , SMPEzenith.value, SMPEazimuth.value) if dAngle>np.radians(10.):continue w=weight(oneW.value,eneMC.value,nEv.value,maxMCE.value) pull=dAngle/ROOT.RescaledSigma_IC79_86_I_to_IV_SplineMPE_MESE(pSigma(err1.value,err2.value),ene.value) h3.Fill(log10(ene.value),pull,w) s_cor=ROOT.RescaledSigma_IC79_86_I_to_IV_SplineMPE_MESE(pSigma(err1.value,err2.value),ene.value) for b in range(len(SigmaBins)): if SigmaBins[b][0]<=np.degrees(s_cor) and SigmaBins[b][1]>np.degrees(s_cor): h_pdf_corr[b].Fill(np.degrees(dAngle),w) if h.GetXaxis().FindBin(log10(ene.value))>0 and h.GetXaxis().FindBin(log10(ene.value))<51: medians3[h.GetXaxis().FindBin(log10(ene.value))-1].append(pull) medians3W[h.GetXaxis().FindBin(log10(ene.value))-1].append(w) npoints=0 for i in range(1,h2.GetNbinsX()+1): if len(medians3[i-1])>3: g3.SetPoint(npoints,h.GetXaxis().GetBinCenter(i),weighted_percentile(0.5, np.asarray(medians3[i-1]), np.asarray(medians3W[i-1]))) g3.SetPointError(npoints,0.,0.,weighted_percentile(0.5-0.341, np.asarray(medians3[i-1]), np.asarray(medians3W[i-1])), weighted_percentile(0.5+0.341, np.asarray(medians3[i-1]), np.asarray(medians3W[i-1]))) npoints+=1 c30=TCanvas() leg=ROOT.TLegend(0.7,0.7,1.,1.) ffunc=[] for b in range(len(SigmaBins)): if b==0: h_pdf_corr[b].Draw() else: h_pdf_corr[b].Draw("same") ffunc.append(TF1("ffunc"+str(b),CircGaus,0.001,3.,2)) ffunc[-1].SetLineColor(b+1) ffunc[-1].SetParameter(0,1.) ffunc[-1].SetParameter(1,1.) h_pdf_corr[b].Fit(ffunc[-1],"R") leg.AddEntry(h_pdf_corr[b], "range: "+str(SigmaBins[b][0])+" to "+str(SigmaBins[b][1])+" #sigma_{fit}="+'{:.2f}'.format(ffunc[-1].GetParameter(0)),"l") leg.Draw() g3.Set(npoints) c3=TCanvas() c3.SetLogy() c3.SetGridx() c3.SetGridy() h3.SetStats(0) h3.SetMinimum(1) h3.Draw("colz") g3.Draw("pl same") c3.SaveAs("RescaledSigma_IC79_86_I_to_IV_SplineMPE_MESE_corrcted.png") raw_input("Press Enter to continue...")
def main(argv): LOADTREE_ANADIR = "/net/user/mrameez/trunk/rootfiles/IC40/" tr = TChain("Level2") tr.Add(LOADTREE_ANADIR + "/CutA6_v1_nugen_numu_2075_01000_small.root") tr.Add(LOADTREE_ANADIR + "/CutA6_v1_nugen_numu_2082_01000_small.root") tr.Add(LOADTREE_ANADIR + "/CutA6_v1_nugen_numu_3311_08000_small.root") tr.GetEntries() MCzenith = ctypes.c_double(0) tr.SetBranchAddress("mcZr", MCzenith) MCazimuth = ctypes.c_double(0) tr.SetBranchAddress("mcAr", MCazimuth) eneMC = ctypes.c_double(0) tr.SetBranchAddress("mcEn", eneMC) SMPEzenith = ctypes.c_double(0) tr.SetBranchAddress("mZd", SMPEzenith) SMPEazimuth = ctypes.c_double(0) tr.SetBranchAddress("mAd", SMPEazimuth) ene = ctypes.c_double(0) tr.SetBranchAddress("mmueEn", ene) sigma = ctypes.c_double(0) tr.SetBranchAddress("mpfSigmaDeg", sigma) oneW = ctypes.c_double(0) tr.SetBranchAddress("OW", oneW) nEv = ctypes.c_double(0) tr.SetBranchAddress("NEvents", nEv) h = TH2D("pull", "pull", 50, 1, 9, 1000, 0.01, 300) h.SetStats(0) h.GetXaxis().SetTitle("log_{10}(MuEx_energy [GeV])") h.GetYaxis().SetTitle("Pull: #Delta#Psi/#sigma_{parab.}") g = TGraphAsymmErrors(50) medians = [[] for i in range(0, 50)] mediansW = [[] for i in range(0, 50)] go = TGraph(50) go.SetMarkerStyle(22) go.SetMarkerColor(4) hEneW = TH1D( "hEneW", "MCPrimary energy; log_{10}(E [GeV]); #frac{d#Phi}{dE} [GeV^{-1} cm^{-2} s^{-1} sr^{-1} ( #frac{E}{GeV} )^{-2} ", 100, 1, 9.5) hREneW = TH1D( "hREneW", "Reco energy SplineMPEMuEXDiff; log_{10}(E [GeV]); #frac{d#Phi}{dE} [GeV^{-1} cm^{-2} s^{-1} sr^{-1} ( #frac{E}{GeV} )^{-2}", 100, 1, 9) for i in range(0, tr.GetEntries()): tr.GetEntry(i) #if not hem(np.radians(SMPEzenith.value)): # continue #if np.radians(sigma.value)>np.radians(5.): # continue w = weight(oneW.value, eneMC.value, nEv.value) hEneW.Fill(log10(eneMC.value), w) hREneW.Fill(log10(ene.value), w) dAngle = SpaceAngleRad(MCzenith.value, MCazimuth.value, np.radians(SMPEzenith.value), np.radians(SMPEazimuth.value)) h.Fill(log10(ene.value), dAngle / np.radians(sigma.value), w) if h.GetXaxis().FindBin(log10(ene.value)) > 0 and h.GetXaxis().FindBin( log10(ene.value)) < 51: medians[h.GetXaxis().FindBin(log10(ene.value)) - 1].append( dAngle / np.radians(sigma.value)) mediansW[h.GetXaxis().FindBin(log10(ene.value)) - 1].append(w) #if i>200: #break npoints = 0 for i in range(1, h.GetNbinsX() + 1): if len(medians[i - 1]) > 3: wp = weighted_percentile(0.5, np.asarray(medians[i - 1]), np.asarray(mediansW[i - 1])) if wp > 30.: continue print wp g.SetPoint(npoints, h.GetXaxis().GetBinCenter(i), wp) g.SetPointError( npoints, 0., 0., weighted_percentile(0.5 - 0.341, np.asarray(medians[i - 1]), np.asarray(mediansW[i - 1])), weighted_percentile(0.5 + 0.341, np.asarray(medians[i - 1]), np.asarray(mediansW[i - 1]))) npoints += 1 c0 = TCanvas() hEneW.Draw() c01 = TCanvas() hREneW.Draw() g.Set(npoints) g.SetMarkerStyle(20) gStyle.SetPalette(1) gStyle.SetOptLogz(1) spline = TSpline5("spl", TGraph(g)) filename = "SplineforCorr_IC40.root" #if hem(0.): # filename=filename+"down.root" #else: # filename=filename+"up.root" fout = TFile(filename, "RECREATE") spline.Write() fout.Close() #print "loading mpfSigmaDegRescaledIC40.C" #ROOT.gROOT.ProcessLine(".L mpfSigmaDegRescaledIC40.C+") print "loading RescaledSigma_IC40.C" ROOT.gROOT.ProcessLine(".L RescaledSigma_IC40.C+") try: ROOT.loadSplines_IC40() except: pass npoints = 0 for i in range(1, h.GetNbinsX() + 1): if len(medians[i - 1]) > 3: wp = weighted_percentile(0.5, np.asarray(medians[i - 1]), np.asarray(mediansW[i - 1])) #if wp>30.: continue #if hem(0.): #plotZen=0. #else: #plotZen=100. #go.SetPoint(npoints,h.GetXaxis().GetBinCenter(i),ROOT.mpfSigmaDegRescaled2(1.,pow(10,h.GetXaxis().GetBinCenter(i)))) go.SetPoint( npoints, h.GetXaxis().GetBinCenter(i), ROOT.RescaledSigma_IC40(1., pow(10, h.GetXaxis().GetBinCenter(i)))) npoints += 1 go.Set(npoints) del medians[:] del medians del mediansW[:] del mediansW c = TCanvas() c.SetLogy() c.SetGridx() c.SetGridy() h.SetMinimum(1) h.Draw("colz") g.Draw("pl same") go.Draw("pl same") # spline.Draw("lp same") h2 = TH2D("pull - corrected", "pull - corrected", 50, 1, 9, 100, 0.01, 30) h2.GetXaxis().SetTitle("log_{10}(E [GeV])") h2.GetYaxis().SetTitle("Pull_{corr}: #Delta#Psi/f_{corr}(#sigma_{parab.})") g2 = TGraphAsymmErrors(50) medians2 = [[] for i in range(0, 50)] medians2W = [[] for i in range(0, 50)] g2.SetMarkerStyle(20) for i in range(0, tr.GetEntries()): tr.GetEntry(i) #if not hem(np.radians(SMPEzenith.value)): continue #if np.radians(sigma.value)>np.radians(5.): # continue w = weight(oneW.value, eneMC.value, nEv.value) dAngle = SpaceAngleRad(MCzenith.value, MCazimuth.value, np.radians(SMPEzenith.value), np.radians(SMPEazimuth.value)) h2.Fill( log10(ene.value), dAngle / (np.radians(sigma.value) * spline.Eval(log10(ene.value))), w) if h.GetXaxis().FindBin(log10(ene.value)) > 0 and h.GetXaxis().FindBin( log10(ene.value)) < 51: medians2[h.GetXaxis().FindBin(log10(ene.value)) - 1].append( dAngle / (np.radians(sigma.value) * spline.Eval(log10(ene.value)))) medians2W[h.GetXaxis().FindBin(log10(ene.value)) - 1].append(w) #if i>200: #break npoints = 0 for i in range(1, h2.GetNbinsX() + 1): if len(medians2[i - 1]) > 3: wp = weighted_percentile(0.5, np.asarray(medians2[i - 1]), np.asarray(medians2W[i - 1])) #if wp>30.: continue g2.SetPoint(npoints, h.GetXaxis().GetBinCenter(i), wp) g2.SetPointError( npoints, 0., 0., weighted_percentile(0.5 - 0.341, np.asarray(medians2[i - 1]), np.asarray(medians2W[i - 1])), weighted_percentile(0.5 + 0.341, np.asarray(medians2[i - 1]), np.asarray(medians2W[i - 1]))) npoints += 1 del medians2[:] del medians2 del medians2W[:] del medians2W g2.Set(npoints) c2 = TCanvas() c2.SetLogy() c2.SetGridx() c2.SetGridy() h2.SetStats(0) h2.SetMinimum(1) h2.Draw("colz") g2.Draw("pl same") h3 = TH2D("pull - corrected xcheck", "pull - corrected xcheck", 50, 1, 9, 100, 0.01, 30) h3.GetXaxis().SetTitle("log_{10}(E [GeV])") h3.GetYaxis().SetTitle("Pull_{corr}: #Delta#Psi/f_{corr}(#sigma_{parab.})") g3 = TGraphAsymmErrors(50) medians3 = [[] for i in range(0, 50)] medians3W = [[] for i in range(0, 50)] g3.SetMarkerStyle(20) SigmaBins = [(0.5, 0.6, 1), (0.6, 0.7, 2), (0.7, 0.9, 4), (0.9, 1.3, 1), (1.3, 1.7, 2)] h_pdf_corr = [] for b in range(len(SigmaBins)): h_pdf_corr.append( TH1D("h_pdf_corr" + str(b), "h_pdf_corr" + str(b) + ";#Delta#Psi [deg]", 50, 0, 3)) h_pdf_corr[-1].SetLineColor(SigmaBins[b][2]) h_pdf_corr[-1].SetLineWidth(2) for i in range(0, tr.GetEntries()): tr.GetEntry(i) #if not hem(np.radians(SMPEzenith.value)): continue #if np.radians(sigma.value)>np.radians(5.): # continue w = weight(oneW.value, eneMC.value, nEv.value) dAngle = SpaceAngleRad(MCzenith.value, MCazimuth.value, np.radians(SMPEzenith.value), np.radians(SMPEazimuth.value)) #pull=dAngle/ROOT.mpfSigmaDegRescaled2(np.radians(sigma.value),ene.value) #s_cor=ROOT.mpfSigmaDegRescaled2(np.radians(sigma.value),ene.value) pull = dAngle / ROOT.RescaledSigma_IC40(np.radians(sigma.value), ene.value) s_cor = ROOT.RescaledSigma_IC40(np.radians(sigma.value), ene.value) h3.Fill(log10(ene.value), pull, w) for b in range(len(SigmaBins)): if SigmaBins[b][0] <= np.degrees( s_cor) and SigmaBins[b][1] > np.degrees(s_cor): h_pdf_corr[b].Fill(np.degrees(dAngle), w) if h.GetXaxis().FindBin(log10(ene.value)) > 0 and h.GetXaxis().FindBin( log10(ene.value)) < 51: medians3[h.GetXaxis().FindBin(log10(ene.value)) - 1].append(pull) medians3W[h.GetXaxis().FindBin(log10(ene.value)) - 1].append(w) #if i>200: #break npoints = 0 for i in range(1, h2.GetNbinsX() + 1): if len(medians3[i - 1]) > 3: wp = weighted_percentile(0.5, np.asarray(medians3[i - 1]), np.asarray(medians3W[i - 1])) #if wp>30.: continue g3.SetPoint(npoints, h.GetXaxis().GetBinCenter(i), wp) g3.SetPointError( npoints, 0., 0., weighted_percentile(0.5 - 0.341, np.asarray(medians3[i - 1]), np.asarray(medians3W[i - 1])), weighted_percentile(0.5 + 0.341, np.asarray(medians3[i - 1]), np.asarray(medians3W[i - 1]))) npoints += 1 c30 = TCanvas() leg = ROOT.TLegend(0.7, 0.7, 1., 1.) ffunc = [] for b in range(3): h_pdf_corr[b].Sumw2() if b == 0: h_pdf_corr[b].Draw("HIST") else: h_pdf_corr[b].Draw("same HIST") ffunc.append(TF1("ffunc" + str(b), CircGaus, 0.001, 3., 2)) ffunc[-1].SetLineColor(SigmaBins[b][2]) ffunc[-1].SetParameter(0, 1.) ffunc[-1].SetParameter(1, 1.) h_pdf_corr[b].Fit(ffunc[-1], "R") ffunc[-1].Draw("same") leg.AddEntry( h_pdf_corr[b], "range: " + str(SigmaBins[b][0]) + " to " + str(SigmaBins[b][1]) + " #sigma_{fit}=" + '{:.2f}'.format(ffunc[-1].GetParameter(0)), "l") leg.Draw() c31 = TCanvas() leg1 = ROOT.TLegend(0.7, 0.7, 1., 1.) ffunc = [] for b in range(3, 5): h_pdf_corr[b].Sumw2() if b == 0: h_pdf_corr[b].Draw("HIST") else: h_pdf_corr[b].Draw("same HIST") ffunc.append(TF1("ffunc" + str(b), CircGaus, 0.001, 3., 2)) ffunc[-1].SetLineColor(SigmaBins[b][2]) ffunc[-1].SetParameter(0, 1.) ffunc[-1].SetParameter(1, 1.) h_pdf_corr[b].Fit(ffunc[-1], "R") ffunc[-1].Draw("same") leg1.AddEntry( h_pdf_corr[b], "range: " + str(SigmaBins[b][0]) + " to " + str(SigmaBins[b][1]) + " #sigma_{fit}=" + '{:.2f}'.format(ffunc[-1].GetParameter(0)), "l") leg1.Draw() g3.Set(npoints) c3 = TCanvas() c3.SetLogy() c3.SetGridx() c3.SetGridy() h3.SetStats(0) h3.SetMinimum(1) h3.Draw("colz") g3.Draw("pl same") #c3.SaveAs("mpfSigmaDegRescaledIC79V2_corrected.png") raw_input("Press Enter to continue...")
def initialize(fitresults=True, grid=False): gROOT.SetStyle("Plain") gStyle.SetOptFit() gStyle.SetOptStat(0) # For the canvas: gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(600) #Height of canvas gStyle.SetCanvasDefW(600) #Width of canvas gStyle.SetCanvasDefX(0) #POsition on screen gStyle.SetCanvasDefY(0) # For the Pad: gStyle.SetPadBorderMode(0) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(False) gStyle.SetPadGridY(False) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) # For the frame: gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillColor(kWhite) gStyle.SetFrameFillStyle(1000) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) # For the histo: gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(2) gStyle.SetEndErrorSize(2) gStyle.SetErrorX(0.) gStyle.SetMarkerStyle(20) #For the fit/function: gStyle.SetOptFit(1) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) #For the date: gStyle.SetOptDate(0) # For the statistics box: gStyle.SetOptFile(0) gStyle.SetOptStat(0) # To display the mean and RMS: SetOptStat("mr") gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.025) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.15) # Margins: gStyle.SetPadTopMargin(0.05) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.04) # top group adaption, original is 0.02 gStyle.SetPadBottomMargin(0.13) # For the Global title: gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.05) # For the axis titles: gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.06, "XYZ") gStyle.SetTitleXOffset(0.9) gStyle.SetTitleYOffset(1.25) # For the axis labels: gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") gStyle.SetLabelSize(0.05, "XYZ") #gStyle.SetLabelSize(0.04, "XYZ") # For the axis: gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX(1) # To get tick marks on the opposite side of the frame gStyle.SetPadTickY(1) # Change for log plots: gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) gStyle.SetPalette(1) #(1,0) # another top group addition gStyle.SetHatchesSpacing(1.0) # Postscript options: gStyle.SetPaperSize(20., 20.) # For graphs gStyle.SetErrorX(0) # suppress error along x if grid: gStyle.SetPadGridX(gridOn) gStyle.SetPadGridY(gridOn) gStyle.SetGridColor(kGray)