ROOT
Preparation
import ROOT st = tgraph.FindObject('stats') ROOT.gROOT.SetBatch(1)
Read Data
data = np.genfromtxt("input.dat", unpack=True) xval = np.array(data[0]) yval = np.array(data[1]) xerr = np.array(data[2]) yerr = np.array(data[3]) xerl = np.array(xerr) xerh = np.array(xerr) yerl = np.array(yerr) yerh = np.array(yerr) xmin = np.min(xval) xmax = np.max(xval) ymin = np.min(yval) ymax = np.max(yval)
Distribution
func = ROOT.TF1("poisson", 'ROOT.TMath.Poission(x, 2.00)', 0.00, 10.0) func.Draw()
Function
func = ROOT.TF1("test", 'abs(sin(x)/x)', 0.00, 10.0) func.GetXaxis().SetTitle("xaxis") func.GetYaxis().SetTitle("yaxis") func.Draw()
Histogram with Sample
hist = ROOT.TH1F("hist", "histogram", 100, 0, 0) hist_fill = hist.Fill for i in range(2000) : hist_fill(ROOT.gRandom.Gaus(0.00, 0.20))
Histogram from Data
nbin = (100) hmin = (np.min(data) - np.min(data)) hmax = (np.max(data) + np.min(data)) hist = ROOT.TH1F("hist", "histogram", nbin, hmin, hmax) hist_fill = hist.Fill for i in data : hist_fill(i)
Graph
graph = ROOT.TGraph(len(xval), xval, yval) graph = ROOT.TGraphErrors(len(xval), xval, yval, xerr, yerr) graph = ROOT.TGraphAsymmErrors(len(xval), xval, yval, xerl, xerh, yerl, yerh)
Gauss Fitting
fmin = np.min(xval) fmax = np.max(xval) graph.Fit("gaus", "", "", fmin, fmax) graph.Fit("gaus", "EM", "", fmin, fmax)
Model Fitting
class model : def __call__(self, x, param) : value = (param[0] + (x[0] * param[1])) return(value) fmin = np.min(xval) fmax = np.max(xval) func = ROOT.TF1("func", model(), fmin, fmax, 2) func.SetParameters(2.00, 5.00) graph.Fit(func, "", "", fmin, fmax) graph.Fit(func, "EM", "", fmin, fmax) func.GetChisquare() func.GetProb() func.GetNDF() func.GetParameter(0) func.GetParError(0) func.GetParameter(1) func.GetParError(1)
Plot Settings
cwid = 800 chei = 600 canv = ROOT.TCanvas("canv", "graph", 0, 0, cwid, chei) rwid = (cwid + (cwid - canv.GetWw())) rhei = (chei + (chei - canv.GetWh())) canv.SetWindowSize(rwid, rhei) graph.Draw("APL") ROOT.gStyle.SetFillColor(0) ROOT.gStyle.SetCanvasColor(0) ROOT.gStyle.SetPadBorderSize(0) ROOT.gStyle.SetLegendBorderSize(0) ROOT.gStyle.SetTitleBorderSize(0) ROOT.gStyle.SetPalette(0) ROOT.gStyle.SetOptFit(0) ROOT.gStyle.SetOptStat(0) ROOT.gStyle.SetScreenFactor(1.00) ROOT.gStyle.SetPadRightMargin(0.010) ROOT.gStyle.SetPadTopMargin(0.060) ROOT.gStyle.SetPadLeftMargin(0.085) ROOT.gStyle.SetPadBottomMargin(0.100) ROOT.gStyle.SetEndErrorSize(5) ROOT.gStyle.SetTitleOffset(0.85, "X") ROOT.gStyle.SetTitleOffset(0.78, "Y") ROOT.gROOT.ForceStyle() canv.Modified() canv.Update() canv.UseCurrentStyle() cwid = 800 chei = 600 canv = ROOT.TCanvas("canv", "graph", 0, 0, cwid, chei) rwid = (cwid + (cwid - canv.GetWw())) rhei = (chei + (chei - canv.GetWh())) canv.SetWindowSize(rwid, rhei) graph.Draw("APL") canv.SetLogx(0) canv.SetLogy(0) canv.SetGridx(1) canv.SetGridy(1) canv.SetTicks(1, 1) graph.SetLineWidth(1) graph.SetLineColor(2) graph.SetLineStyle(1) graph.SetMarkerStyle(1) graph.SetMarkerSize(0.20) graph.SetMarkerColor(2) graph.SetTitle("title") graph.SetTitle() graph.GetXaxis().SetTitle("xaxis") graph.GetYaxis().SetTitle("yaxis") graph.GetXaxis().CenterTitle(0) graph.GetYaxis().CenterTitle(0) graph.GetXaxis().SetNdivisions(510) graph.GetYaxis().SetNdivisions(510) graph.GetXaxis().SetTitleSize(0.05) graph.GetYaxis().SetTitleSize(0.05) graph.GetXaxis().SetLabelSize(0.05) graph.GetYaxis().SetLabelSize(0.05) graph.Draw("APL") canv.Print("output.pdf")
Notation
xstr = (np.min(xval)) xend = (np.max(xval)) ystr = (np.min(yval)) yend = (np.max(yval)) xcen = (xstr+((xend-xstr)*0.50)) ycen = (ystr+((yend-ystr)*0.50)) crad = ((yend-ystr)*0.50) xrad = ((xend-xstr)*0.50) yrad = ((yend-ystr)*0.50) line = ROOT.TLine(xstr, ystr, xend, yend) line.SetLineWidth(3) line.SetLineColor(2) line.SetLineStyle(2) line.Draw("SAME") lect = ROOT.TBox(xstr, ystr, xend, yend) lect.SetFillColor(3) lect.Draw("SAME") circ = ROOT.TArc(xcen, ycen, crad) circ.SetLineWidth(3) circ.SetLineColor(4) circ.SetLineStyle(1) circ.Draw("SAME") elip = ROOT.TEllipse(xcen, ycen, xrad, yrad) elip.SetLineWidth(3) elip.SetLineColor(6) elip.SetLineStyle(1) elip.Draw("SAME") mark = ROOT.TMarker(xcen, ycen, 5) mark.Draw("SAME") text = ROOT.TText(xstr, ystr, "text") text.SetTextSize(0.10) text.SetTextColor(1) text.Draw("SAME") text.DrawTextNDC(0.50, 0.50, "center")
Convert Xaxis
graph.GetXaxis().SetTickLength(0) graph.GetXaxis().SetLabelOffset(999) axis = ROOT.TGaxis(np.min(xval), 0, np.max(xval), 0, 0, 2450, 510, "", 0) graph.GetXaxis().SetTitle("xaxis(new)") axis.Draw()
Font = Roman
font = 132 ROOT.gStyle.SetStatFont(font) ROOT.gStyle.SetLabelFont(font, "XYZ") ROOT.gStyle.SetLabelFont(font, "") ROOT.gStyle.SetTitleFont(font, "XYZ") ROOT.gStyle.SetTitleFont(font, "") ROOT.gStyle.SetTextFont(font)
Acknowledgments
Daiphys is a professional-service company for research and development of leading-edge technologies in physics and engineering.
Get started accelerating your business through our deep expertise in R&D with AI, quantum computing, and space development; please get in touch with Daiphys today!
Daiphys Technologies LLC - https://www.daiphys.com/