Simultaneous fit to a binned dataset in RooFit

Dear All,

I am trying to fit a simultaneous PDF to a binned dataset : there is one fit variable (the mass) and a bunch of categories reflecting different datataking periods, magnet polarities, decay modes, etc. I first make an unbinned dataset containing all the events and then bin it

RooDataHist binneddata("binneddata","binneddata",RooArgSet(qval,rswscat,compptcat,btaucat,channelcat,magpolcat,yearcat,bflavcat),data);

“qval” is the mass variable, the rest are categories. The eventual PDF contains various functions of the mass variable, whose parameters I want to variously split and/or share depending on the values of the various categories. All events have the qval and the various categories set when I create the dataset.

Then I try to make a simultaneous PDF (note the following is python code)

SimPdfTool = RooSimWSTool(fitworkspace)
SimWSPDF   = SimPdfTool.build("SimWSPDF","WSPDF",RooFit.SplitParam(varstosplit,"compptcat,yearcat,channelcat"))

I don’t split in the simultaneous fit on all the categories. This gives the following type of error once I try to fit

[#0] ERROR:InputArguments -- RooCategory::isStateInRange(rswscat) ERROR: must specificy valid range name and state name [#0] ERROR:InputArguments -- RooCategory::isStateInRange(btaucat) ERROR: must specificy valid range name and state name [#0] ERROR:InputArguments -- RooCategory::isStateInRange(magpolcat) ERROR: must specificy valid range name and state name [#0] ERROR:InputArguments -- RooCategory::isStateInRange(bflavcat) ERROR: must specificy valid range name and state name

I have tried modifying the tutorial related to the RooSimWSTool, and I can reproduce the problem in a toy case : if I bin the dataset the problem is there, and if I do the same thing with the unbinned dataset then the problem is not there.

I would be grateful if someone could explain where I am going wrong. I am using ROOT v5.34/04. Doing an unbinned fit is not an option because of the size of the dataset.

Many thanks,

Vava

Hello,

in case it helps, here is the modified tutorial script which reproduces the problem. If you replace “binneddata” by “combData” in the “fitTo” line, the fit works fine.

Thanks,

Vava

/////////////////////////////////////////////////////////////////////////
//
// 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #504
// 
// Using RooSimWSTool to construct a simultaneous p.d.f that is built
// of variations of an input p.d.f
//
//
// 07/2008 - Wouter Verkerke 
//
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooCategory.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooPolynomial.h"
#include "RooSimultaneous.h"
#include "RooAddPdf.h"
#include "RooWorkspace.h"
#include "RooSimWSTool.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TFile.h"
#include "TH1.h"
using namespace RooFit ;


void rf504_simwstool()
{
  // C r e a t e   m a s t e r   p d f 
  // ---------------------------------
  
  RooRealVar x("x","x",-8,8) ;

  // Construct signal pdf
  RooRealVar mean("mean","mean",0,-8,8) ;
  RooRealVar sigma("sigma","sigma",0.3,0.1,10) ;
  RooGaussian gx("gx","gx",x,mean,sigma) ;

  // Construct background pdf
  RooRealVar a0("a0","a0",-0.1,-1,1) ;
  RooRealVar a1("a1","a1",0.004,-1,1) ;
  RooChebychev px("px","px",x,RooArgSet(a0,a1)) ;

  // Construct composite pdf
  RooRealVar f("f","f",0.2,0.,1.) ;
  RooAddPdf model("model","model",RooArgList(gx,px),f) ;

  // C r e a t e   m o d e l   f o r   c o n t r o l   s a m p l e
  // --------------------------------------------------------------

  // Construct signal pdf. 
  // NOTE that sigma is shared with the signal sample model
  RooRealVar mean_ctl("mean_ctl","mean_ctl",-3,-8,8) ;
  RooGaussian gx_ctl("gx_ctl","gx_ctl",x,mean_ctl,sigma) ;

  // Construct the background pdf
  RooRealVar a0_ctl("a0_ctl","a0_ctl",-0.1,-1,1) ;
  RooRealVar a1_ctl("a1_ctl","a1_ctl",0.5,-0.1,1) ;
  RooChebychev px_ctl("px_ctl","px_ctl",x,RooArgSet(a0_ctl,a1_ctl)) ;

  // Construct the composite model
  RooRealVar f_ctl("f_ctl","f_ctl",0.5,0.,1.) ;
  RooAddPdf model_ctl("model_ctl","model_ctl",RooArgList(gx_ctl,px_ctl),f_ctl) ;

  // G e n e r a t e   e v e n t s   f o r   b o t h   s a m p l e s 
  // ---------------------------------------------------------------

  // C r e a t e   c a t e g o r y   o b s e r v a b l e s   f o r   s p l i t t i n g
  // ----------------------------------------------------------------------------------

  // Define two categories that can be used for splitting
  RooCategory c("c","c") ;
  c.defineType("run1",1) ;
  c.defineType("run2",2) ;

  RooCategory d("d","d") ;
  d.defineType("foo",1) ;
  d.defineType("bar",2) ;


  // Generate 1000 events in x and y from model
  RooDataSet *data = model.generate(RooArgSet(x),100) ;
  RooDataSet *data_ctl = model_ctl.generate(RooArgSet(x),2000) ;

  // S e t u p   S i m W S T o o l 
  // -----------------------------

  // Import ingredients in a workspace
  RooWorkspace w("w","w") ;
  w.import(RooArgSet(model,c,d)) ;

  // Make Sim builder tool
  RooSimWSTool sct(w) ;

  // B u i l d   a   s i m u l t a n e o u s   m o d e l   w i t h   p r o d u c t   s p l i t
  // -----------------------------------------------------------------------------------------

  // Build another simultaneous p.d.f using a composite split in states c X d
  RooSimultaneous* model_sim2 = sct.build("model_sim2","model",SplitParam("mean,a1,a0,f","d")) ;

  // Print tree structure of this model
  model_sim2->Print("t") ;

  RooDataSet combData("combData","combined data",x,Index(d),Import("foo",*data),Import("bar",*data_ctl)) ;

  RooDataHist binneddata("binneddata","binneddata",RooArgSet(x,c,d),combData);  

  model_sim2->fitTo(binneddata);

}

Dear all,

I have the same problem. The fit works and I do not get these “RooCategory::isStateInRange(tag) ERROR” messages when I switch to an unbinned fit. However, also for me this is not a real option given the size of my data set. Any help is appreciated.

Thanks
Jeroen

Dear all,

The bug is fixed by Wouter on the 22th of March. When I get the latest patch (svn co root.cern.ch/svn/root/branches/v5-34-00-patches) and compile it the problem is fixed and I can happily fit to binned data sets.

Cheers
Jeroen

Since I am also hit by this bug (while trying to reduce a dataset with roodatahists) the actual patch is at root.cern.ch/viewvc/branches/v5- … 2&r2=48913