How to do overlapping histogram

Hi I am having trouble with overlapping 3 Histograms in one drawing. Do you have any documentation or could you provide input on my code:

void Distribution(){
TRandom3 a;
TH1D *h = new TH1D(“h”, “h”, 100, 500, 600);
for(int i = 0; i<100000; i++){
double val1 = a.Gaus(550, 16);
//double val2 = a.Gaus(550, 8);
//double total = val1+val2;
h->Fill(val1);
}
TH1D *f = new TH1D(“f”, “f”, 100, 500, 600);
for(int i = 0; i<100000; i++){
//double val1 = a.Gaus(550, 16);
double val2 = a.Gaus(550, 8);
//double total = val1+val2;
h->Fill(val2);
}
TH1D *d = new TH1D(“d”, “d”, 100, 500, 600);
for(int i = 0; i<100000; i++){
double val1 = a.Gaus(550, 16);
double val2 = a.Gaus(550, 8);
double total = val1+val2;
h->Fill(total);
}
TH1D *c = new TH1D(“c”, “Overlap”, 100, 500, 600);
c->Add(h, f, d);

c->Draw();
}

You draw the 1st histogram without any option and all the next Draw with option “SAME”…
Or use THStack.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.