_ROOT Version: 6.16
Hello,
I am having a problem fitting an histogram. To give some context it is an histogram corresponding to a 152Eu source gamma spectrum measured with a Germanium detector. I would like to fit gamma peaks combining a gaussian with a straight line. Here is my code :
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "TROOT.h"
#include "TStyle.h"
#include "TFile.h"
#include "TLeaf.h"
#include "TBranch.h"
#include "TTree.h"
#include "TChain.h"
#include "TH1.h"
#include "TObjArray.h"
#include "TMath.h"
#include "TCanvas.h"
#include "TH2.h"
#include "TLegend.h"
#include "TDirectory.h"
Double_t noise(Double_t *x, Double_t *par){
return par[0] + par[1]*x[0];
}
Double_t peakGaus(Double_t *x, Double_t *par){
return par[0]*exp(-0.5*pow((x[0]-par[1])/par[2],2));
}
Double_t functionFit(Double_t *x, Double_t *par){
return noise(x, par) + peakGaus(x, &par[2]);
}
void sum_peak(){
TFile *f = new TFile("152Eu-source-run162_0001_single_out.root");
TH1F *hist_int = (TH1F*)f->Get("h85");
hist_int->Draw();
TF1 *fctFit = new TF1("fctFit", functionFit, 5150, 5250, 5);
hist_int->Fit("fctFit");
}
The histogram extracted from the .root tree is called “h85”. When trying to fit, the canal value does not seem to be taken into account (I tried multiple combinaisons) and I have a weird curve that does not fit at all and that goes all the way through my spectrum.
Hope I am clear enough
Thanks