#!/usr/bin/env python # coding: utf-8 # # Create, draw and fit a 2DGraphErrors # Ported to Notebook by: Theis Hansaen # In[1]: from ROOTaaS.iPyROOT import ROOT ROOT.toCpp() # ### Build, fIt and draw a 2D graph # To start off we set the style and palette of the graph. # In[2]: gStyle->SetPalette(kBird); double e = 0.3; int nd = 500; # Here we are starting to fill our Graph with a function, and we use the TF2 Type because we want our function to be bidimensional. # In[3]: TRandom3 my_random_generator; TF2 f2("f2","1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+200",-6,6,-6,6); f2.SetParameters(1,1); TGraph2DErrors dte(nd); # We use TRandom3 (seen above) to generate random numbers in [-e,e] # In[4]: double rnd, x, y, z, ex, ey, ez; for (Int_t i=0; iSetTitle("X Title"); Xaxis->SetTitleOffset(1.5); Yaxis->SetTitle("Y Title"); Yaxis->SetTitleOffset(1.5); Zaxis->SetTitle("Y Title"); Zaxis->SetTitleOffset(1.5); dte.Draw("PO Same"); # To finish off, we make the x and y projections on a new canvas using the command new with the Type TCanvas. # In[7]: TCanvas c_p("ProjCan","The Projections",1000,400); c_p.Divide(2,1); c_p.cd(1); dte.Project("x")->Draw(); c_p.cd(2); dte.Project("y")->Draw(); # In[ ]: