RooHistPdf from weighted data

Hi,
I have a flat tree with observables I want to use for my pdf (and some other variables). The tree also contains a leaf ‘wgt’ designating event weight - it is different for each event.
I want to construct RooHistPdf out of this dataset.

I proceed like this:
I declare:
RooRealVar* wgt=new RooRealVar(“wgt”,“wgt”,0.0,1.0);

then read files trees etc… then make a dataset:

RooDataSet* sig_train_data_var1= new RooDataSet
 "name","title"
   t_sig_selected_var2,
   RooArgSet(var1,var2,*wgt)
   ,0,wname);

where wname is a const char* = “wgt”

then I make RooDataHist and RooHistPdf:

      RooDataHist* hist_sig_var1=new RooDataHist
  ("anothername","anothertitle",
   RooArgList(var1),*sig_train_data_var1);


RooHistPdf* sig_PDF_var1=new RooHistPdf
  ("yetanothername","yetanothertitle",
   RooArgSet(var1),*hist_sig_var1);

I do the same for var2 (applying different selections etc) and then make a product pdf.

I plot the pdf and the data it was derrived from and I dont get what I expect at all - namely the pdf looks like the unweighted pdf scaled by 0.5. If I do something like: (*wgt)=0.9; somewhere up front it looks like all the points are multiplied equally by 0.9.

If I don’t declare the variable wgt and don’t include it in the RooArgSet containing the set of variables making up the RooDataSet I get a warning:

WARNING: designated weight variable wgt not found in set of variables, no weighting will be assigned

How do I make this behave correctly? I.e. assing not a global weight but a per-event weight???
Thanks,
Wojtek

Hi Wojtek,

What version of ROOT are you using? If run the following test macro in 5.27/04, it appears all works
fine

void wgthist()
{
// Build toy model to generate x and distribution of weights that is x dependent
RooWorkspace w(“w”,1) ;
w.factory(“Uniform::ux(x[-10,10])”) ;
w.factory(“Gaussian::gw(w[0,10],expr(‘x+10’,x),3)”) ;
w.factory(“PROD::model(gw|x,ux)”) ;
RooDataSet* data = w::model.generate(RooArgSet(w::x,w::w),10000) ;

RooDataSet wgtdata(“wgtdata”,“wgtdata”,RooArgSet(w::x,w::w),Import(*data),WeightVar(w::w)) ;
RooDataHist wgthist(“wgthist”,“wgthist”,w::x,wgtdata) ;
RooHistPdf pdf(“pdf”,“pdf”,w::x,wgthist) ;

RooPlot* frame = w::x.frame() ;
wgtdata.plotOn(frame) ;
wgthist.plotOn(frame,LineColor(kGreen),MarkerColor(kGreen)) ;
pdf.plotOn(frame) ;
data->plotOn(frame,LineColor(kRed),MarkerColor(kRed)) ;
frame->Draw() ;

}

Wouter

Hi Wouter
I am using 5.26.00c
So fairly recent…
I am not sure I understand your example - is it somewhat equivalent to what I am doing or do you think there is something wrong with my usage? I notice that you don’t give a name of the variable to RooDataSet constructor but a function WeightVar - does that make a difference?

I tried your example script in CINT but it didn’t work:
(I put it in eg.C)

root [0] using namespace RooHist;

RooFit v3.12 – Developed by Wouter Verkerke and David Kirkby
Copyright © 2000-2009 NIKHEF, University of California & Stanford University
All rights reserved, please read roofit.sourceforge.net/license.txt

root [1] .L eg.C
root [2] wgthist()
[#1] INFO:ObjectHandling – RooWorkspace::exportToCint(w) INFO: references to all objects in this workspace will be created in CINT in 'namespace w’
Error: Function Import(*data) is not defined in current scope eg.C:11:
*** Interpreter error recovered ***

I will try to run my code and your example in 5.27/04 -but I will need to install that first…
Thanks,
w

Hi,
With 5.27/4 I get the same error when running your script:

.L eg.C

root [1] wgthist()

RooFit v3.13 – Developed by Wouter Verkerke and David Kirkby
Copyright © 2000-2010 NIKHEF, University of California & Stanford University
All rights reserved, please read roofit.sourceforge.net/license.txt

[#1] INFO:ObjectHandling – RooWorkspace::exportToCint(w) INFO: references to all objects in this workspace will be created in CINT in 'namespace w’
Error: Function Import(*data) is not defined in current scope eg.C:11:
*** Interpreter error recovered ***

cheers,
w

Hi,

If you add a ‘using namespace RooFit’ the Import() function will be defined.

Wouter