Dear rooters .Help me to add two TH1 histograms from gausian.And how can creat TH1 hist from gausian wich center of its situated not at (0,0) ,at (0,x).Thanks to all.
{
TCanvas *c1 = new TCanvas("c1","",600,800);
TH1F* h1 = new TH1F("h1","Random Gaussian",100,-2,2);
h1->FillRandom("gaus",10000);
TH1F* h2 = new TH1F("h2","Random Gaussian",100,-2,2);
h2->FillRandom("gaus",10000);
h2->Add(h1,1);
h1->SetFillColor(19);
h1->SetFillStyle(1000);
h2->SetFillColor(4);
h2->SetFillStyle(3007);
h2->Draw();
h1->Draw("same");
}
Thank you Couet.That worked well.
How can i change the center(e.g the maximum of gausian) of gausian.These gausian’s center is situeted at (0,0).How can i change the center of first gausian from (0.0) to (0.9,0)and seconds to (1.3,0).
Thanks.
You have two possibilities
solution 1
{
TCanvas *c1 = new TCanvas("c1","",600,800);
TH1F* h1 = new TH1F("h1","Random Gaussian",100,-2,2);
TF1 *f1 = new TF1("f1","TMath::Gaus(x,0.9,.1)",-2,2);
h1->FillRandom("f1",10000);
TH1F* h2 = new TH1F("h2","Random Gaussian",100,-2,2);
TF1 *f2 = new TF1("f2","TMath::Gaus(x,1.3,.1)",-2,2);
h2->FillRandom("f2",10000);
h2->Add(h1,1);
h1->SetFillColor(19);
h1->SetFillStyle(1000);
h2->SetFillColor(4);
h2->SetFillStyle(3007);
h2->Draw();
h1->Draw("same");
}
solution 2
{
TCanvas *c1 = new TCanvas("c1","",600,800);
TH1F* h1 = new TH1F("h1","Random Gaussian",100,-2,2);
TH1F* h2 = new TH1F("h2","Random Gaussian",100,-2,2);
TRandom3 r;
{
for (int i=0;i<10000;i++) {
h1->Fill(r.Gaus(0.9,0.1));
h2->Fill(r.Gaus(1.3,0.1));
}
}
h2->Add(h1,1);
h1->SetFillColor(19);
h1->SetFillStyle(1000);
h2->SetFillColor(4);
h2->SetFillStyle(3007);
h2->Draw();
h1->Draw("same");
}
Rene
Thank you very much mr.Rene
Thet worked very vell.
Can i change interval of y-axis Example from (0,80) to (0.000,0.035).And the figure(vision) of hists will has kept.
Thanks
If I understand your request correctly, simply normalize each histogram to the number of entries, ie add the two lines
h1->Scale(1./10000.);
h2->Scale(1./10000.);
just before drawing the histograms
Rene
You have undestood me correctly.Al are well.Thank you.
I have just written :
h2->(h1,0.7);
But my first histogram hasn’t changed its height.I want to add with different coifficient of height.Help me please.
Have anybody to help me?