pad2 = TPad( 'pad2', 'The pad with the histogram', 0.05, 0.05, 0.95, 0.45, 21 ) pad1.Draw() pad2.Draw() pad1.cd() gBenchmark.Start( 'fillrandom' ) # # A function (any dimension) or a formula may reference # an already defined formula # form1 = TFormula( 'form1', 'abs(sin(x)/x)' ) sqroot = TF1( 'sqroot', 'x*gaus(0) + [3]*form1', 0, 10 ) sqroot.SetParameters( 10, 4, 1, 20 ) pad1.SetGridx() pad1.SetGridy() pad1.GetFrame().SetFillColor( 42 ) pad1.GetFrame().SetBorderMode( -1 ) pad1.GetFrame().SetBorderSize( 5 ) sqroot.SetLineColor( 4 ) sqroot.SetLineWidth( 6 ) sqroot.Draw() lfunction = TPaveLabel( 5, 39, 9.8, 46, 'The sqroot function' ) lfunction.SetFillColor( 41 ) lfunction.Draw() c1.Update() # # Create a one dimensional histogram (one float per bin) # and fill it following the distribution in function sqroot. # pad2.cd();
pad3.Draw() pad4.Draw() # # Change default style for the statistics box gStyle.SetStatW(0.30) gStyle.SetStatH(0.20) gStyle.SetStatColor(42) # # Display a function of one ntuple column imposing a condition # on another column. pad1.cd() pad1.SetGrid() pad1.SetLogy() pad1.GetFrame().SetFillColor(15) ntuple = gROOT.FindObject('ntuple') ntuple.SetLineColor(1) ntuple.SetFillStyle(1001) ntuple.SetFillColor(45) ntuple.Draw('3*px+2', 'px**2+py**2>1') ntuple.SetFillColor(38) ntuple.Draw('2*px+2', 'pz>2', 'same') ntuple.SetFillColor(5) ntuple.Draw('1.3*px+2', '(px^2+py^2>4) && py>0', 'same') c1.Update() # # Display the profile of two columns # The profile histogram produced is saved in the current directory with # the name hprofs
# We connect the ROOT file generated in a previous tutorial # see begin_html <a href="hsimple.C.html">An example creating/filling/saving histograms/ntuples on file</a> end_html # example = TFile('py-hsimple.root') example.ls() # Draw a global picture title title = TPaveLabel(0.1, 0.94, 0.9, 0.98, 'Drawing options for one dimensional histograms') title.SetFillColor(16) title.SetTextFont(52) title.Draw() # # Draw histogram hpx in first pad with the default option. pad1.cd() pad1.GetFrame().SetFillColor(18) hpx = gROOT.FindObject('hpx') hpx.SetFillColor(45) hpx.DrawCopy() label1 = TPaveLabel(-3.5, 700, -1, 800, 'Default option') label1.SetFillColor(42) label1.Draw() # # Draw hpx as a lego. Clicking on the lego area will show # a "transparent cube" to guide you rotating the lego in real time. pad2.cd() hpx.DrawCopy('lego1') label2 = TPaveLabel(-0.72, 0.74, -0.22, 0.88, 'option Lego1') label2.SetFillColor(42) label2.Draw() label2a = TPaveLabel(-0.93, -1.08, 0.25, -0.92, 'Click on lego to rotate')
class EEG_Graph(object): def __init__(self, maxpoints=60): self.maxpoints = maxpoints self.gq = False self.canvas = TCanvas('c1', 'A Simple Graph Example', 200, 10, 700, 500) self.canvas_1 = TPad("c1_1", "c1_1", 0.01, 0.67, 0.99, 0.99) self.canvas_2 = TPad("c1_2", "c1_2", 0.01, 0.01, 0.99, 0.66) self.canvas_1.SetGrid() self.canvas_2.SetGridx() self.canvas_1.Draw() self.canvas_2.Draw() self.data = [0] self.data_time = [time.time()] n = 1 x = array('d') y = array('d') x.append(0) y.append(0) self.canvas_1.cd() self.graph = TGraph(n, x, y) self.graph.SetLineColor(2) self.graph.SetLineWidth(4) self.graph.SetMarkerColor(4) self.graph.SetMarkerStyle(2) self.graph.SetTitle('EEG Signal') self.graph.GetXaxis().SetTitle('Time') self.graph.GetYaxis().SetTitle('Amplitude') self.graph.GetYaxis().SetRangeUser(-2000, 2000) self.graph.Draw('ACP') self.canvas_2.cd() TVirtualFFT.SetTransform(0) self.fft = TH1F("fft", "eeg_fft", 3, 0, 3) self.fft.SetTitle("EEG FFT") self.fft.Fill("1 Hz", 0) self.fft.Fill("2 Hz", 0) self.fft.SetMinimum(0) self.fft.SetMaximum(100000) self.fft.SetFillStyle(3001) self.fft.SetFillColor(30) self.fft.Draw("B HIST") self.ampmax = 100000 self.fft.SetStats(False) self.fft.GetXaxis().SetLabelSize(0.05) self.fft.GetYaxis().SetLabelSize(0.05) def setQuality(self, good): self.gq = good def append(self, timep, num): n = self.graph.GetN() if len(self.data) < 2048: self.data = self.data + [num] self.data_time = self.data_time + [time.time()] else: self.data = self.data[1:] + [num] self.data_time = self.data_time[1:] + [time.time()] if n < self.maxpoints: self.graph.Set(n + 1) self.graph.SetPoint(n, timep, num) else: self.graph.RemovePoint(0) self.graph.Set(n) self.graph.SetPoint(n - 1, timep, num) self.data_fft = np.abs(np.fft.fft(self.data)) self.fft.Reset() if len(self.data_fft) > 256: delta = self.data_time[-1] - self.data_time[0] for i in range(50): amp = np.sum(self.data_fft[round(i * delta):round(i * delta + delta)]) self.fft.Fill("%i Hz" % (i + 1, ), amp) if amp > self.ampmax: self.ampmax = amp self.fft.SetMaximum(amp) self.update() def update(self): self.canvas_1.cd() if self.gq: self.canvas_1.GetFrame().SetFillColor(30) else: self.canvas_1.GetFrame().SetFillColor(46) self.canvas.GetFrame().SetBorderSize(12) self.graph.GetYaxis().SetRangeUser(-2000, 2000) self.canvas_2.Modified() self.canvas.Modified() self.canvas.Update()