Roofit: weight scale differently in dataset, fillhistogram

Hello, I have pared this down to the most basic I can, but it seems as if the setWeight() function and fillhistogram() return two different results. Here’s my results:

slac.stanford.edu/~jmorris/twoweights.jpg

Notice that the datapoints do not match up with the histogram. Here’s my code:

{
  TTree::SetMaxTreeSize(1000*Long64_t(2000000000));
  //TFile fq("../../rootfiles/gammagamma1to6_wtruth.root");
  TFile fq("./small.root");
  gSystem->Load("libRooFit.so");
  using namespace RooFit;

  int numbins = 50;
  double d0MassLo = 1.6;
  double d0MassHi = 2.1;

  
  TTree *txCCBar = fq.Get("ccbar");
  TTree *txGammaGamma = fq.Get("gammagamma");
  TTree *txUDS = fq.Get("uds");
  TTree *txBpBm = fq.Get("bpbm");
  TTree *txB0B0Bar = fq.Get("b0b0");
  TTree *txPi0Pi0 = fq.Get("pi0pi0");
  
  //NEWVALUES AFTER ADDING RUN 7 35    0.345     0.00496108876541  0.143753743487  0.14689741529  0.908298761223  5.89990437284  0.745869599394  4.95737635792  2.72518558063  5.76406552355 
  double gamma1PCmsLo = 0.908; 
  double gamma2PCmsLo = 0.744; 
  double dStarPCmsLo = 2.725; 
  double pi0VetoLo = 0.1; 
  double delMassLo = 0.14375; 
  double delMassHi = 0.14689; 

  
  RooRealVar d0Mass("d0Mass", "D^{0} Mass", d0MassLo, d0MassHi, "GeV/c^{2}");

  RooRealVar delMass("delMass", "M(D^{*+}) - M(D^{0})", delMassLo, delMassHi, "GeV/c^{2}");
  RooRealVar gamma1PCms("gamma1PCms", "P_{CMS}(#gamma_{1})", gamma1PCmsLo, 6., "GeV/c"); 
  RooRealVar gamma2PCms("gamma2PCms", "P_{CMS}(#gamma_{2})", gamma2PCmsLo, 6., "GeV/c");   
  RooRealVar dStarPCms("dStarPCms", "P_{CMS}(D^{*+})", dStarPCmsLo, 6., "GeV/c");
  RooRealVar decayFlag3("decayFlag3", "decayFlag3", -1, 2**11);
  RooRealVar weight("weight", "weight", -0.1, 2.0);
  RooRealVar pi0background("pi0background", "pi0background", -pi0VetoLo, +pi0VetoLo);
  
  RooArgList lsBase(d0Mass, delMass, gamma1PCms, gamma2PCms, pi0background, decayFlag3, weight);

  RooDataSet dsCCBarAll("dsCCBarAll", "dsCCBarAll", txCCBar, lsBase);

  d0Mass.setBins(numbins);
  
    
  //MAKE STACK:
  TH1F *ccbarhisto = new TH1F("ccbarhisto", "ccbarhisto", numbins, d0MassLo, d0MassHi);
  TH1F *udshisto = new TH1F("udshisto", "udshisto", numbins, d0MassLo, d0MassHi);
  TH1F *bpbmhisto = new TH1F("bpbmhisto", "bpbmhisto", numbins, d0MassLo, d0MassHi);
  TH1F *b0b0histo = new TH1F("b0b0histo", "b0b0histo", numbins, d0MassLo, d0MassHi);
  ccbarhisto->SetFillColor(kBlue-10);
  udshisto->SetFillColor(kGreen-10);
  bpbmhisto->SetFillColor(kRed-10);
  b0b0histo->SetFillColor(kYellow-10);
  
  ccbarhisto->SetLineStyle(1);
  ccbarhisto->SetMarkerStyle(1);
  
  dsCCBarAll->setWeightVar(weight);
  dsCCBarAll->fillHistogram(ccbarhisto, d0Mass);
  
  
  TCanvas *bgPlot = new TCanvas("bgPlot", "bgPlot");
  TPad *plotPad = new TPad("plotPad", "plotPad", 0.0, 0.1, 1.0, 1.0);
  TPad *residPad = new TPad("residPad", "residePad", 0.0, 0.0, 1.0, 0.1);
  plotPad->SetNumber(1);
  residPad->SetNumber(2);

  plotPad->Draw();
  residPad->Draw();
  
  
  bgPlot->cd(1);    
  THStack d;
  d.Add(b0b0histo);
  d.Add(bpbmhisto);
  d.Add(udshisto);
  d.Add(ccbarhisto);
  d.Draw("hist");
  
  
  RooPlot *pBG_d0Mass = d0Mass.frame();
  dsCCBarAll->setWeightVar(weight);
  dsCCBarAll ->plotOn(pBG_d0Mass);
  
  
  RooPlot *frame2_bg = d0Mass.frame() ; // same way you made 'frame'
  frame2_bg->addObject(pBG_d0Mass->pullHist()) ;
  frame2_bg->SetMinimum(-5) ;
  frame2_bg->SetMaximum(+5) ;
  
  
  
  pBG_d0Mass -> Draw("SAME");
  bgPlot->cd(2);    
  frame2_bg->Draw(); 
  
}

Can anyone see what’s wrong?

Thanks,
james

Hi,

When you have a RooDataSet with weighted entries you should specify
that the sum-of-weights errors should be drawn, rather than the Poisson error (which can only be calculated for integer counts). In the default
Poisson drawing mode, entries are also rounded to the nearest integer, which is the discrepancy you observe. To fix do

data->plotOn(frame,DataError(RooAbsData::SumW2))

Wouter

Thanks for answering both my questions Wouter, you’ve been helpful like always.

Thanks again!
james