leg.SetTextFont(42) leg.SetTextSize(0.05) leg.Draw() can2 = TCanvas('can_TrigEff', 'can_TrigEff', 900, 600) eff = TEfficiency('efficiency', 'efficiency', hRef.GetNbinsX(), 0, 2000) eff.SetPassedHistogram(hSig, 'f') eff.SetTotalHistogram(hRef, 'f') eff.SetLineColor(ROOT.kBlack) eff.SetMarkerColor(ROOT.kBlack) eff.SetMarkerStyle(20) fit = TF1('fit', '(1-[2])+[2]*TMath::Erf((x-[0])/[1])', xmin, xmax) fit.SetParameters(800, 100, 0.3) fit.SetLineColor(ROOT.kBlue) eff.Fit(fit, 'RQ') line = TF1('line', '1', xmin, xmax) line.GetXaxis().SetTitle('m_{jj} (GeV)') line.GetYaxis().SetTitle('Trigger Efficiency') line.SetLineColor(ROOT.kBlack) line.SetLineStyle(2) line.SetMinimum(0.3) line.SetMaximum(1.1) line.Draw() eff.Draw('samePE1') gPad.Update() x0 = fit.GetX(0.99) cut = TLine(x0, gPad.GetFrame().GetY1(), x0, gPad.GetFrame().GetY2()) cut.SetLineColor(ROOT.kRed)
#efffunc.SetParameter(0,1.0) #efffunc.SetParameter(1,500) massArr = array.array('d') zeroArr = array.array('d') xintArr = array.array('d') yintArr = array.array('d') xintErrArr = array.array('d') yintErrArr = array.array('d') for iy in range(1, cleanhist.GetNbinsY() + 1): cleanslice = cleanhist.ProjectionX("cleanslice", iy, iy) messyslice = messycleanhist.ProjectionX("messyslice", iy, iy) sliceeff = TEfficiency(messyslice, cleanslice) efffunc.SetParameters(1.0, 500) efffunc.FixParameter(0, 1.0) s = sliceeff.Fit(efffunc, "S") sliceeff.Draw("AP") #c.Print(outfilename+".pdf"); if s.Get() and s.Get().IsValid() and s.Get().CovMatrixStatus() == 3: massArr.append(cleanhist.GetYaxis().GetBinCenter(iy)) zeroArr.append(0) xintArr.append(s.Parameter(1)) yintArr.append(s.Parameter(0)) xintErrArr.append(s.ParError(1)) yintErrArr.append(s.ParError(0)) xintgraph = TGraphErrors(len(massArr), massArr, xintArr, zeroArr, xintErrArr) xintgraph.SetTitle("X-intercept;mass [GeV];D1") xintgraph.SetName("xintgraph") xintgraph.Write()
def RunAnalysis(input_name, output_name=""): # Check output name, set by default if not passed to the function if not output_name: output_name = input_name.split("_")[0] + "_analysed.root" print("INPUT:", input_name, "\nOUTPUT:", output_name) # Configuring thresholds (thr_start, thr_end, thr_step) = (0.3, 8, 0.1) thr_range = np.arange(thr_start, thr_end + thr_step, thr_step) n_thr = len(thr_range) # Get hit dictionary hit_dict = GetHitDict(input_name) # Open root file to write the results into write_file = TFile("data/" + output_name, "recreate") write_file.cd() # Initialize efficiency and cluster size objects eff = TEfficiency("Efficiency", "Efficiency;Threshold [fC];Efficiency", n_thr, thr_start, thr_end) clus_graph = TGraphErrors(n_thr) clus_graph.SetNameTitle("Average_cluster_size", "Average_cluster_size") clus_graph.GetXaxis().SetTitle("Threshold [fC]") clus_graph.GetYaxis().SetTitle("Average cluster size") # Perform threshold scanning for thr in thr_range: thrE = thr * 6242.2 print("Threshold scanning:", round(thr / thr_end * 100, 1), "%", end="\r") # Scan a threshold and obtain a list of clusters cluster_list = ScanThreshold(hit_dict, thrE) # Analyze cluster list and fill TEfficiency object for cluster in cluster_list: eff.Fill(bool(cluster), thr) # Replace zeros with NaN to obtain proper average later cluster_list = [ np.nan if cluster == 0 else cluster for cluster in cluster_list ] try: # Calculate average cluster size and add points to clus_graph cluster_size = np.nanmean(cluster_list) N = np.count_nonzero(~np.isnan(cluster_list)) err = np.nanstd(cluster_list) / sqrt(N - 1) clus_graph.SetPoint(int(np.where(thr_range == thr)[0][0]), thr, cluster_size) clus_graph.SetPointError(int(np.where(thr_range == thr)[0][0]), ex=0, ey=err) except RuntimeWarning: pass print("\nDone.") # Efficiency fit fit_form = "0.5*[0]*TMath::Erfc((x-[1])/(TMath::Sqrt(2)*[2])*(1-0.6*TMath::TanH([3]*(x-[1])/TMath::Sqrt(2)*[2])))" fit_func = TF1("Efficiency_fit", fit_form, 0, 8) # Set initial parameter values and limits fit_func.SetParameters(1, 4, 1, 1, 0.5) fit_func.SetParLimits(1, 0, 5) fit_func.SetParLimits(2, 0, 2) fit_func.SetParLimits(3, 0, 2) fit_func.SetParLimits(4, 0.5, 0.7) # Perform fit eff.Fit(fit_func, "R") # Write outputs to file eff.Write() clus_graph.Write() # Collect info source = "allpix" angle = input_name.split("-")[0] descr = input_name.split("_")[0].strip("0deg-") n_events = str(int(eff.GetTotalHistogram().GetEntries() / n_thr)) title = source + "," + angle + "," + descr + "(" + str(n_events) + "ev)" vt50 = str(fit_func.GetParameter(1)) vt50_err = str(fit_func.GetParError(1)) thr_range = str(thr_start) + ":" + str(thr_end) + ":" + str(thr_step) # Write info to Info directory info_dir = write_file.mkdir("Info") info_dir.cd() info_dir.WriteObject(TString(source), "source") info_dir.WriteObject(TString(angle), "angle") info_dir.WriteObject(TString(descr), "descr") info_dir.WriteObject(TString(n_events), "n_events") info_dir.WriteObject(TString(title), "title") info_dir.WriteObject(TString(vt50), "vt50") info_dir.WriteObject(TString(vt50), "vt50_err") info_dir.WriteObject(TString(thr_range), "thr_range") write_file.Close()