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...")
etichetta.SetTextSize(0.04) etichetta.SetTextColor(418) etichetta.SetTextFont(102) etichetta.DrawLatex( 0.2, 0.8, "#splitline{SL1_L1 HV scan}{Runs: " + str(run_interval) + "}") can_HV_scan_SL1_L1.Update() can_HV_scan_SL1_L1.Print(outpath + "HVScan_SL1_L1_" + str(run_interval) + options.optionalstring + ".png") can_HV_scan_SL1_L1.Print(outpath + "HVScan_SL1_L1_" + str(run_interval) + options.optionalstring + ".pdf") graph_HV_L1.SetName("HV_scan_SL1_L1_" + run_interval) new_file_HV_scan_SL1_L1 = TFile( outpath + "Graph_HV_scan_SL1_L1_" + run_interval + options.optionalstring + ".root", 'RECREATE') graph_HV_L1.Write() graph_HV_L1.Set(0) print "Graph_HV_scan_SL1_L1_" + run_interval + options.optionalstring + ".root written in " + outpath ##Prepare the canvas to plot the HV scan for SL1_L4 can_HV_scan_SL1_L4 = TCanvas("can_HV_scan_SL1_L4", "can_HV_scan_SL1_L4", 1000, 800) can_HV_scan_SL1_L4.SetGrid() can_HV_scan_SL1_L4.cd() ##Prepare summary TGraph graph_HV_L4 = TGraphAsymmErrors() n = 0 for a in sorted(HV_scan_L4): #for a in sorted(run_parameters): ##Fill the TGraph with threshold (x-axis) and rate (y-axis) #######graph.SetPoint(n,int(run_parameters[a]['VTHR']),float(run_parameters[a]['RATE_SL4_L4'])) graph_HV_L4.SetPoint(n, int(a), float(HV_scan_L4[a]))
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...")
latex.SetTextSize(0.04) latex.SetTextFont(62) latex.DrawLatex(0.30, 0.96, "GIF++") etichetta = TLatex() etichetta.SetNDC() etichetta.SetTextSize(0.04) etichetta.SetTextColor(4) etichetta.SetTextFont(102) etichetta.DrawLatex(0.45, 0.8, "#splitline{SL1_L1 threshold scan}{Runs: "+str(run_interval)+"}") can_scan_SL1_L1.Update() can_scan_SL1_L1.Print(outpath + "ThresholdScan_SL1_L1_"+run_interval+".png") can_scan_SL1_L1.Print(outpath + "ThresholdScan_SL1_L1_"+run_interval+".pdf") graph.SetName("ThresholdScan_SL1_L1_"+run_interval) new_file_SL1_L1 = TFile(outpath + "Graph_thresholdScan_SL1_L1_"+run_interval+ ".root",'RECREATE') graph.Write() graph.Set(0) #SL1_L4 can_scan_SL1_L4 = TCanvas("can_scan_SL1_L4","can_scan_SL1_L4", 1000, 800) can_scan_SL1_L4.SetGrid() can_scan_SL1_L4.cd() graph = TGraphAsymmErrors() n=0 for a in sorted(scan_SL1_L4): #print scan_SL1_L4[a] graph.SetPoint(n,a,scan_SL1_L4[a]) n = n+1 graph.SetMarkerSize(1.) graph.SetMarkerStyle(21) graph.SetMarkerColor(862) graph.SetFillColor(868)
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...")