TH1::Fit is odly not plotting the function

Dear co-rooters,

I am trying to perform a simple linear fit in a certain range on a TH1D histogram which I get from a root file (The root file can be found in https://cernbox.cern.ch/index.php/s/3XnsnbWYg2obDtD)
My code is the following

#include "TCanvas.h"
#include "TStyle.h"
#include "TFile.h"
#include "TH1.h"

void fit(){

	TFile *fin = new TFile("fit.root", "OPEN");
	TH1D *h = (TH1D*) fin->Get("histo_movie");								

	gStyle->SetOptStat(0);
	TCanvas *canvas = new TCanvas("canvas", "HPGe", 500, 500);
	canvas->Divide(1, 2);
	
	
	// Pad 1
	canvas->cd(1);	
	h->Draw("histo ][");	
	h->TH1::Fit("pol1", "WCQF", "C SAME", 5.6005e6, 5.6021e6);	
	
	//Pad 2
	canvas->cd(2);
	h->Draw("histo ][");
}

Although the code compiles and runs there is no plotted curve.

Any idea on what is going on?

Thanks in advance!

Note that I am running this on lxplus7, using whichever version is the latest in the cluster.

h->Draw("][");

Thank you very much for the answer!

Although I can now see the fitting curve, the way the histogram is drawn is strange.

Any idea why?

Try:

  h->Fit("pol1", "WCQF", "HIST ][", 5.6005e6, 5.6021e6);
  h->GetFunction("pol1")->Draw("SAME");

This seems to be working!
Thank you very much!

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