Problems passing arguments to RooFit Objects

Hiya,

I’ve just converted to RooFit to do my simple ‘Histo’ fitting, but find myself lacking an understanding of why my code (snippets taken from a tutorial by Wouter Verkerke: " RooFit Tutorial – Topical Lectures June 2007" ) fails when I pass arguments the RooAddPdf objects.

Two Specific examples (full code below) are:

  1. RooFitResult* r = sum->fitTo(*data,Extended(kTRUE),Minos(kFALSE),Save(kTRUE)) ;

  2. sum->plotOn(CDMassFrame, Components(argus),LineStyle(kDashed));

For (1) I get a work around via:

1.sol) RooFitResult* r = sum->fitTo(*data,“ehr”);

Not sure how I solve (2).

Any help in understanding this problem, not sure if its the root version or if Im missing some typedef, would be appreciated.

Regards,

Colin.

Im using Root v16.00 and RooFit v2.11. My code is as follows:

 #include "RooAbsPdf.h"
#include "RooRealProxy.h"
#include "RooAbsReal.h"
#include "RooAbsCategory.h"
#include "RooCategoryProxy.h"
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooCategory.h"
#include "RooComplex.h"
#include "RooMath.h"
#include "RooArgSet.h"
#include "RooArgList.h"
#include "RooDataSet.h"
#include "RooPlot.h"
#include "RooFitResult.h"
#include "RooFitResult.h"
#include "RooMCStudy.h"

#include "RooGaussian.h"
#include "RooArgusBG.h"
#include "RooAddPdf.h"
#include "RooCBShape.h"

#include "RooNumConvPdf.h"
#include "RooSimultaneous.h"

#include "TROOT.h"
#include "TFile.h"
#include "TDirectory.h"
#include "TTree.h"
#include "TPave.h"
#include <cmath>
#include <TCanvas.h>

#define PI 3.1415927

using namespace RooFit ;

TFile *infile;
TDirectory *g1;
TTree *t1;

void RooMain( const char *inputfile ){

  RooRealVar CDMass("CDMass","CDMass",5280.0,5450.0,"MeV");
  RooArgSet ntupleVarSet(CDMass);

  infile = new TFile(inputfile);

  if (infile->IsOpen()) {std::cout << "AcceptanceAnalyzer> input file open. " << std::string(inputfile) << std::endl;}
  else { std::cout << "AcceptanceAnalyzer> could not open input file. "<< std::endl;
  exit(1);
  }
  
  
  infile->cd();
  TDirectory *g1 = (TDirectory*)gROOT->FindObject("Bs2JpsiPhi");
  g1->cd();
  t1 = (TTree*)gROOT->FindObject("1");

  if(!t1){ std::cout << "AcceptanceAnalyzer> Could not get the TTree." << std::endl; exit(1);}
  else{std::cout << "got tree: " << t1->GetName() << std::endl;}

  
  //Reading data
  RooDataSet *data = new RooDataSet("data","data",t1,ntupleVarSet);

  // --- Build Gaussian PDFs --- 
  RooRealVar sigmean("sigmean","B^{0}_{s} mass",5300.0, 5280.0,5450.0);
  RooRealVar sigwidth("sigwidth","B^{0}_{s} width",50.0,0,1000.) ;
  RooGaussian gauss("gauss","gaussian PDF",CDMass,sigmean,sigwidth) ;

    // --- Build Argus background PDF ---
  RooRealVar argpar("argpar","argus shape parameter",-20.0,-100.,-1.) ;
  RooRealVar cutoff("cutoff","argus cutoff",5.291) ;
  RooArgusBG argus("argus","Argus PDF",CDMass,cutoff,argpar) ;

  // --- Construct composite PDF --- 
  RooRealVar nsig("nsig","number of signal events",0.,10000) ;//200,0.,10000) ;
  RooRealVar nbkg("nbkg","number of background events",800,0.,10000) ;
  RooAddPdf *sum = new RooAddPdf("sum","gauss+argus",RooArgList(gauss,argus),RooArgList(nsig,nbkg)) ;


  // --- Perform extended ML fit of composite PDF to toy data, skip
  // minos ---
  //RooFitResult* r = sum.fitTo(*data,Extended(kTRUE),Minos(kFALSE),Save(kTRUE)) ; //<-- Fails with Extended(..) arg
  //Note the use of old style arguments
  //e=Extended(true)
  //h=HESSE(true)
  //r=Save(true)
  RooFitResult* r = sum->fitTo(*data,"ehr");

  //create canvas
  TCanvas* cv1 = new TCanvas();
  cv1->Divide(1,1);
  cv1->cd(1);

  //plot
  RooPlot *CDMassFrame= CDMass.frame(60);
  data->plotOn(CDMassFrame);
  sum->plotOn(CDMassFrame);

  // --- Add box with subset of fit parameters to plot frame ---  
  RooArgSet plotset( nsig, sigmean, sigwidth);
  nsig.setPlotLabel("N(B^{0}_{s})") ;
  sigmean.setPlotLabel("B^{0}_{s} mass") ;
  
  //sum.paramOn(CDMassFrame,Parameters(RooArgSet(nsig,sigmean,sigwidth)),Layout(0.15,0.55,0.85)); //<-- Fails with Layout arg
  sum->paramOn(CDMassFrame);
  sum->plotOn(CDMassFrame, Components(argus),LineStyle(kDashed)); //<-- Fails with LineStyle arg 
  
  CDMassFrame->Draw(); // Put our plot on the canvas.
  cv1->Update();

  r->Print("v");

  delete data;
}

Hi,

I assume you are compiling your code, judging from the
many #includes in your source example.

In that case you should also add #include "RooGlobalFunc.h"
which declares the helper functions like Minos() and
Components() that are used in your fitTo() and plotOn()
calls.

Wouter

Hi,

That’s grand. The code now complies and works.

Thanks Wouter.

Colin.