# Adding histogram to multigraph

Good Morning Root Users!
I am learning to use TMultiGraph in order to draw multiple plots.
As long as I try to draw multiple functions (like f(x)=x^2 and g(x)=1-x) everything works just fine.
However, if I try to draw a function and a histogram (like in the code below) I get an error.
Thanks for the help!

[code]# include

# include “TRandom1.h”

#define NP 100000 //number of points in the x^2 plot in the interval [0,1)
#define NBIN 10 //number of bins in the histogram
#define NE 10 //number of events in the histogram

void multi(){
using namespace std;

``````TRandom1 r(0);

double x[NP],y[NP]; //abscissas and ordinates of x^2
int i;

for(i=0;i<NP;i++){
x[i] = (double)i/(double)NP; //abscissas of x^2
y[i] = pow((double)i/(double)NP,2.); //ordinates of x^2
}

TGraph *gr1 = new TGraph(NP,x,y); //plot of x^2

TH1F *histo = new TH1F("histo","Flat distribution", NBIN, 0., 1.);
for (i = 0; i < NE; i++) histo->Fill(r.Uniform()); //flat histogram

TMultiGraph *mg = new TMultiGraph();

//IF YOU UN-COMMENT THE FOLLOWING LINE YOU GET AN ERROR
//END OF COMMENT

mg-> SetTitle("Quadratic function and flat histogram");
TCanvas* c1 = new TCanvas ("c1", "Multiple Plot");
mg-> Draw ();

//IF YOU UN-COMMENT THE FOLLOWING LINE THE HISTOGRAM PLOT WILL COVER THE FUNCTION PLOT
//histo-> Draw ();
//END OF COMMENT

return;
``````

}[/code]

histo->Draw(“SAME”); // root.cern.ch/root/html534/THistPainter.html

Thank you very much.