Peaks don't fit well in RooFit

Hello all,

I am trying to fit a complex function onto some peaks in a histogram. The code runs fine but the fit shape overshoots and doesn’t really fit well on the peaks. I am attaching a couple of examples of what it looks like and also my code:

void roofit_fitting(){

    TString FileNameRoot1 = "allProcessedTrees.root";
    TFile *f1 = new TFile(FileNameRoot1); 

    TH2F* hGeEnergyVsTimePP5000to2200Veto = (TH2F*)(f1->FindObjectAny("hGeEnergyVsTimePP5000to2200Veto"));
    TH1* h1 = hGeEnergyVsTimePP5000to2200Veto->ProjectionX("a",496,502);

    RooRealVar E1("E1","Energy",0,7999,"keV");
    RooPlot* frame1 = E1.frame(Title("Fitting RooFit model on the signal"));
    RooDataHist data1("data1","dataset with E",E1,h1);

    RooRealVar pi("pi","pi value = 3.14159...",3.14159265);
	RooRealVar Lw("Lw","Voigt line width of 4d5/2->2p3/2", 0.0,"keV");
    float data_numEntries   = data1.numEntries(); 
	float data_sumEntries   = data1.sumEntries();
    RooRealVar m("m","gaussian mean", 2222., 2218, 2225,"keV");
	RooRealVar s("s","gaussian sigma",1.208,"keV");
    //RooRealVar m("m","gaussian mean", 2653., 2640, 2665,"keV");
    //RooRealVar s("s","gaussian sigma",1.80,"keV");
	RooRealVar b("b","slope of exponential tail",6.0,"keV");
	RooRealVar fV("fV","Voigt fraction",0.9,0.7,1.0); // (weight) fraction of VOIGT G
	RooFormulaVar fD("fD","1-fV",RooArgList(fV));  //(weight) fraction of tail function
	RooRealVar nSig("nSig","number of events expected in Signal region",100.,data_sumEntries);
	RooRealVar A("A","A",0., "keV^{-1}");
	RooGenericPdf Sig("Sig","  fV* TMath::Voigt(E1-m,s,Lw) + fD * (1./(2.*b)) * exp( ((E1-m)/b) + (s*s)/(2.*b*b))* ROOT::Math::erfc(((E1-m)/(sqrt(2.)*s))+(s/(sqrt(2.)*b))) + A * 0.5 * ROOT::Math::erfc((E1-m)/(sqrt(2.)*s))",RooArgList(fV,pi,E1,m,Lw,s,fD,b,A));


I want it to trace the peaks. I agree the function is not straightforward and a lot of parameters go into the function. Could the values I am passing for those parameters be the reason or am I making an obvious mistake here? Any help is appreciated! Thank you!

@jonas could you have a look here?


If I understand correctly, you are limiting your peak to between 2218 and 2225 and fiting round that, which does not include the obvious peak location around 2100-2150 (has more interesting data).

Which peak are you representing with that?

Hi @shangjiaxuan, It might not be clearly visible in the screenshot here but there’s a tiny peak sitting at 2222 keV on the right shoulder of the bump at 2200. But that’s for later.
My main concern is the fit function not tracing any of the peaks which I’m trying to fit. I also tried to fit the peaks with a simple RooGaussian but that gives me the same result: The Gaussian looks taller than the peak, the way it does here for the peak at 2653 as well.

I believe the function you are fitting does not really represent the data in your range of interest. Adding a background term (a fitted constant seems appropriate?), hist = sig + bkg, bkg=A (constant, value to be fitted).

Note your fit function seems only take into account one peak and one tail, contribution from other peaks will also be part of this background if you are not taking those into account.

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