Data weighing according to RooFormulaVar

Hi,

I have a problem using RooFit to weigh data wrt. a RooFormulaVar. I need to weigh a RooDataSet wrt. the quotient of two RooRealVar’s that I’ve got from a RooDataSet times a constant. The problem is that the weights from data seems to be forgotten. Here is a code example:

[code]#ifndef CINT
#include “RooGlobalFunc.h”
#endif
#include “RooRealVar.h”
#include “RooDataSet.h”
#include “TFile.h”
#include “TH1.h”

using namespace RooFit ;

void example(){

//Start out by importing data from .root file and by getting the relevant tree
TFile *f = new TFile("someFile.root");
TTree * T = (TTree*)f->Get("t");

//Declare RooRealVars
RooRealVar x("x","x",0,3000);

RooRealVar C1("C1","C1",-1000,100000);
RooRealVar C2("C2","C2",-1000,100000);
RooRealVar C3("C3","C3",-1000,100000);

RooRealVar k("k","k",0.1,0,1000); //Initial guess is 1. This is subject to change...

//Make datasets from the tree T
RooDataSet data("data","Some dataset consisting of the observable x and the three coefficients C1,C2,C3",T,RooArgSet(x,C1,C2,C3));


//Now we need to make datasets, each weighed according to k and the C's in a different way

RooDataSet *dataSet1 = (RooDataSet*) data.reduce(RooArgSet(x));

RooFormulaVar n1Func("n1","@1/@0",RooArgList(C1,C1));//This is the weighing coefficient
RooRealVar * n1Var = (RooRealVar*) dataSet1->addColumn(n1Func);

RooDataSet firstSet(dataSet1->GetName(),"Observable weighed acc. to n1",dataSet1,*dataSet1->get(),0,n1Func.GetName());

firstSet.Print(); //We get the number of events in x, both weighed and unweighed (as we should!)

//The second one uses weighing wrt. k as well	
RooDataSet *dataSet2 = (RooDataSet*) data.reduce(RooArgSet(x));

RooFormulaVar n2Func("n2","@1/@0",RooArgList(C1,C2,k));//This is the weighing coefficient
RooRealVar * n2Var = (RooRealVar*) dataSet2->addColumn(n2Func);

RooDataSet secondSet(dataSet2->GetName(),"Observable weighed acc. to n2",dataSet2,*dataSet2->get(),0,n2Func.GetName());

secondSet.Print(); //We get the number of events in x unweighed, but as weighed we only get the same number * k. ie the factor of C2/C1 is forgotten

}
[/code]

I would greatly appreciate any help on this,
Christian