How can i draw graph is this code?

Hi experts.
I fitted histograms of signal and background with gaussian and pol0, respectively. And I wanna draw the graph(gaus) only signal part that came out as a result of the fitting on the same spectrum.

This is the code what i used. And the last six lines are what i tried to draw the only signal part.
But nothing was drawn. What should i do?

TCanvas *c = new TCanvas("K40","K40",800,600);

TFile *f = new TFile("NaI37_boxcut3.root");
TH1F *N_new = new TH1F("N_new","N_new",20,0,10);
TH1F *N_37 = (TH1F*)f->Get("N_37");
N_37->Draw("E");

Double_t par1[13];

TF1 *fp = new TF1("fp","pol0",1.5,10);
N_37->Fit(fp,"R");

TF1 *fg = new TF1("fg","gaus",2,4);
fg->FixParameter(1, 3.5);
//fg->FixParameter(2, 6.76268e-1);
fg->FixParameter(2, 0.179234);
N_37->Fit(fg,"B","R+");



TF1 *f1 = new TF1("f1","pol0(0)+gaus(1)",1.5,10);
f1->Draw("same");
f1->SetLineColor(kRed);
fp->GetParameters(&par1[0]);
fg->GetParameters(&par1[1]);
f1->SetParameters(par1);
f1->FixParameter(1, f1->GetParameter(1)-f1->GetParameter(0));
f1->FixParameter(2, f1->GetParameter(2));
f1->FixParameter(3, f1->GetParameter(3));

f1->SetLineColor(kRed);
N_37->Fit(f1,"B","R+",1.5,10);


TF1 *f2 = new TF1("f2","pol0",1.5,10);
f2->Draw("same"); 
f2->SetLineColor(kBlue);
f2->SetParameters(par1);
f2->FixParameter(0, f1->GetParameter(0));
 
N_37->Fit(f2,"B","R+",1.5,10); 
 
TF1 *signal = new TF1("signal","gaus",1,10); 
signal->FixParameter(0, f1->GetParameter(1)-f1->GetParameter(0));
signal->FixParameter(1, f1->GetParameter(2));
signal->FixParameter(2, f1->GetParameter(3));
Draw("signal>>N_37");
signal->SetLineColor(kRed);

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


What is “Draw” in that case ? You have this function defined elsewhere ?

Thanks for reply.
No That’s just what i try to draw the signal graph.
So that code show error.

Can you post a macro we can run reproducing these errors ?

Maybe: signal->Draw("same");

Thanks for reply! I try it. But it doesn’t show.

As I said before we would need a running example (macro and data) to help you further.

Actually data is come from our lab cluster. So i can’t share the root file.

Can you make a reproducer without these data ?

Yes but how can i share the macro?

Just copy/paste the code here or attach the macro file … as usual.

TCanvas *c = new TCanvas("K40","K40",800,600);

TH1F *N_new = new TH1F("N_new","N_new",20,0,10);
TH1F *N_37 = (TH1F*)f->Get("N_37");
N_37->Draw("E");

Double_t par1[13];

TF1 *fp = new TF1("fp","pol0",1.5,10);
N_37->Fit(fp,"R");

TF1 *fg = new TF1("fg","gaus",2,4);
fg->FixParameter(1, 3.5);
//fg->FixParameter(2, 6.76268e-1);
fg->FixParameter(2, 0.179234);
N_37->Fit(fg,"B","R+");



TF1 *f1 = new TF1("f1","pol0(0)+gaus(1)",1.5,10);
f1->Draw("same");
f1->SetLineColor(kRed);
fp->GetParameters(&par1[0]);
fg->GetParameters(&par1[1]);
f1->SetParameters(par1);
f1->FixParameter(1, f1->GetParameter(1)-f1->GetParameter(0));
f1->FixParameter(2, f1->GetParameter(2));
f1->FixParameter(3, f1->GetParameter(3));

f1->SetLineColor(kRed);
N_37->Fit(f1,"B","R+",1.5,10);


TF1 *f2 = new TF1("f2","pol0",1.5,10);
f2->Draw("same"); 
f2->SetLineColor(kBlue);
f2->SetParameters(par1);
f2->FixParameter(0, f1->GetParameter(0));
 
N_37->Fit(f2,"B","R+",1.5,10); 
 
TF1 *signal = new TF1("signal","gaus",1,10); 
signal->FixParameter(0, f1->GetParameter(1)-f1->GetParameter(0));
signal->FixParameter(1, f1->GetParameter(2));
signal->FixParameter(2, f1->GetParameter(3));
signal->Draw("same");
signal->SetLineColor(kRed);

f is not defined.

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