Trouble Importing an unbinned histogram and fitting it

Hello I am trying to import a leaf from a root file I created. With the leaf, which is an unbinned histogram (I am assuming) I am then trying to fit a Gaussian plus a line to it. When I attempt the fit I get the following error: ERROR:InputArguments – RooDataSet::moment(dh) WARNING: empty dataset
So obviously something is going wrong with the importing of the unbinned data set. Here is my code

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooDataHist.h"
#include "RooGaussian.h"
#include "TCanvas.h"
#include "RooPlot.h"
#include "TTree.h"
#include "TH1D.h"
#include "TRandom.h"
using namespace RooFit ;

TH1F* makeTH1F() ;
TTree* makeTTree() ;


void rf102_dataimport()
{

// Import TTree
TFile *file = new TFile("PS_Decay_Full_Set4.13.2016.root");
TTree* tree = (TTree*)file->Get("BsCanidatesTree/miT_Bs_min_chiSquared_mass");

  // Declare observable x
  RooRealVar x("x","x",4000,6500) ;

  // Create a binned dataset that imports contents of TH1 and associates its contents to observable 'x'
  RooDataSet dh("dh","dh",RooArgSet(x),Import(*tree)) ; 

  // Make plot of binned dataset showing Poisson error bars (RooFit default)
  RooPlot* frame = x.frame(Title("Imported TH1 with Poisson error bars")) ;
  dh.plotOn(frame) ; 

// Fit a Gaussian p.d.f to the data
  RooRealVar mean("mean","mean",5366.77,4000,6500) ;
  RooRealVar sigma1("sigma1","sigma1",1.5) ;
  RooRealVar slope("slope","slope",15.0);
  RooRealVar intercept("intercept","intercept",15000);
  RooGenericPdf dbgauss("dbgauss","Bs mass","exp(-0.5*(x-mean)*(x-mean)/sigma1)+slope*x+intercept",RooArgSet(x,mean,sigma1,slope,intercept));
  
  mean.setConstant(kTRUE); 
  sigma1.setConstant(kFALSE);
  slope.setConstant(kFALSE);
  intercept.setConstant(kFALSE);
  
  dbgauss.fitTo(dh) ;
  dbgauss.plotOn(frame) ;
 
  dbgauss.paramOn(frame);
  dh.statOn(frame);

  sigma1.Print();
  mean.Print();
 
TCanvas* c = new TCanvas("rf102_dataimport","rf102_dataimport",800,800) ;
frame->GetYaxis()->SetTitleOffset(1.4) ;
frame->Draw() ;


}



Any help would be great.
Thanks,
Neil McFadden

Hi,

Without having access to your tree it is difficult to understand the problem. Are you sure you have a branch named “x” which is a simple branch containing real values ?

Best Regards

Lorenzo

Thanks for the response. I cannot attach the root file because it is very large, but I did take a screen shot of the accessed branch. Based on what you are saying about my “x” variable, I should remain it to the name of the accessed branch miT_Bs_min_chiSquared?


The RooRealVar name for your observable must be equal to the branch name, otherwise there is no way to know which branch to import in the RooDataSet

Lorenzo