[RooFit] Trouble with plot ranges


In a relatively simple case I’m not able to produce reasonalbe projections with RooFit. I want to fit two sidebands with a gap in between. The sideband definitions don’t coincide with bin integer boundaries. The fit projections ly systematically under the data.

Any ideas?

  • Moritz

Here’s the test code showing the problem, it runs interactively out of the box.

#ifndef __CINT__
#include "RooGlobalFunc.h"
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooPolynomial.h"
#include "RooAddPdf.h"
#include "RooFitResult.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit ;

void rf203_ranges()
  RooRealVar x("x","x",-10,10) ;
  RooRealVar s("s","s",-0.05,-0.08,-0.02) ;
  RooPolynomial px("px","px",x,s) ;

  // generate a dataset with gaps
  RooDataSet* modelData = px.generate(x,200000) ;
  modelData = (RooDataSet*)modelData->reduce(Cut("-9<x && x<-3 || 5<x && x<8"));

  // define fit range
  x.setRange("lo",-9,-3) ;  
  x.setRange("hi", 5, 8) ; 

  // define a normalization range which stays away from the
  // gap borders
  float f = 0.5;
  x.setRange("loN",-9.+f,-3.-f) ;  
  x.setRange("hiN", 5.+f, 8.-f) ; 

  // fit signal range
  px.fitTo(*modelData,Range("lo,hi")) ;

  // plot
  RooPlot* frame = x.frame(Title("Fitting a sub range")) ;
  // use a weird binning to cause artificial drops in the plot
  // can't avoid that in the actual situation
  modelData->plotOn(frame, Binning(53)) ;

  // different tries to get reasonable projections...
  px.plotOn(frame, LineColor(kBlue)) ;
  px.plotOn(frame, Range("loN"),   NormRange("loN"), LineColor(kRed)) ;
  px.plotOn(frame, Range("hiN"),   NormRange("hiN"), LineColor(kRed)) ;
  px.plotOn(frame, Range("lo,hi"), NormRange("loN,hiN"), LineColor(kRed+3)) ;
  px.plotOn(frame, Range(-2,2),    NormRange("lo,hi"),   LineColor(kTeal)) ;
  // Draw frame on canvas
  new TCanvas("rf203_ranges","rf203_ranges",600,600) ;
  gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;

  return ;