Cloning, adding and fitting histo produces a weird output

I am creating a histogram from an ascii file. I am appyling a fit to that and then I try to clone the histogram and subtract the fit from it. When I Draw() the cloned histogram I get a very weird output, which is the following

At first I thought it was the fitting function and tried not to draw it, but I didn’t succeed using

h1->Fit("baselineFit","W","0",0,channels);

Any idea why is this happening and how can it be fixed?

My full code is the following

[code]#include “Riostream.h”
#include

Bool_t reject;
Double_t minimum;
Int_t minimumBin;

void HistoFromAscii(){
cout << “-------------------------------------------------------------------” << endl;
gROOT->SetStyle(“Plain”);
gStyle->SetOptStat(0000);
gStyle->SetOptFit(1111);
gStyle->SetOptTitle(0);

Int_t detNum=2, evntNum=1405, movieNum=1;
Char_t dname[4]; sprintf(dname,"C6D6");
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll("HistoFromAscii.C","");
dir.ReplaceAll("/./","/");
ifstream in;
//for (evntNum=1405; evntNum<=1406; evntNum++){
	//for (Int_t movieNum=6; movieNum<=10; movieNum++){
  		TString filename = TString::Format("C6D6%d_e%d_m%d.txt", detNum, evntNum, movieNum);
            //if (filename.IsNull()) {break; cout << "No file " << filename << "found. Moving to the next one." << endl;}
  		Float_t x,y;
  		Int_t nlines = 0;
  		Int_t channels = 3075;
  		cout << "##################################" << endl;
  		cout << "Processing file " << filename << endl;
  		in.open(TString::Format("%s%s",dir.Data(),filename.Data()));
            //if (filename.IsNull()) {break; cout << "No file " << filename << "found. Moving to the next one." << endl;}
            if (in.bad()) break;
  		TH1F *h1 = new TH1F("h1","Total",channels,1,(channels+1));
  		//TH1F *h2 = new TH1F("h2","Total",channels,1,(channels+1));
     
  		while (1) {
		in >> x >> y;
    		if (!in.good()) break;
		if (nlines < 5) printf("x=%8f, y=%8f, nlines=%d\n",x,y,nlines);
		h1->Fill(nlines,y);
    		//h2->Fill(y);
		nlines++;
			}
		printf("Found %d points\n",nlines);
	in.close();

		h1->SetLineColor(kRed);
		h1->Draw();

		//~~~~~~~~~~~~~~~~~~~~~~~~~~~Baseline~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		minimum = h1->GetMinimum(0);
		cout << "The minimum value is : " << minimum << endl;
		h1->GetBinWithContent(minimum,minimumBin,0);
		cout << "The minimum value is in bin # : " << minimumBin << endl;
		reject = kTRUE;
		TF1 *baselineFit = new TF1("baselineFit",exclude,0,channels,2);
		baselineFit->SetParameters(0,0);
		h1->Fit("baselineFit","W","0",0,channels);
		reject = kFALSE;
		Double_t baseline = baselineFit->GetParameter(0);
            TH1F *hnew = (TH1F*)h1->Clone("hnew");
            hnew->Add(baselineFit, -1);
            hnew->Draw("SAME");
		cout << "Baseline is : " << baseline << endl;
		Double_t amplitude = baseline - minimum;
		cout << "Signal's amplitude is : " << amplitude << endl;
		//}
//}    
//h2->Draw();

}

Double_t exclude(Double_t *x, Double_t *par)
{
if (reject && x[0] > minimumBin-10 && x[0] < minimumBin+30) {
TF1::RejectPoint();
return 0;
}
return par[0] + par[1]*x[0];
}[/code]

Try:
h1->Fit(“baselineFit”, “WN”);

It really worked so I will mark your post as solution!
But I don’t understand what is the option “WN” and why gOption “0” doesn’t work.

TH1::Fit(TF1* f1, Option_t* option = “”, Option_t* goption = “”, Double_t xmin = 0, Double_t xmax = 0)