RooFit: RooDataSet weight is always 1

Dear all,
I am trying to use RooFit to fit a weighted data-set, trough a RooDataSet.
I am loading the data from a TTree: since my variables are not in “flat” branches, I am doing that manually, looping over the TTree (see code).
However, it seems to me all the weights in the RooDataSet are fixed to 1.
My root version: 5.32

The code I am using:


    RooRealVar vx("omega_mass","omega_mass",0.78,0.78-0.15,0.78+0.15);
    RooRealVar qq("qq_value","qq_value",0,1);
    RooArgSet arg(vx,qq);
    RooDataSet data("data","data",arg,WeightVar("qq_value"));
     
    data.Print("v");
    t->SetBranchAddress("event",&m_event);
    for (int jj=0;jj<t->GetEntries();jj++){
      t->GetEntry(jj);
      vx.setVal(m_event.omega_mass);
      qq.setVal(m_event.q_value);
      data.add(arg);
      cout<<qq.getValV()<<endl;
      cout<<data.weight()<<endl;
      cin.get();
    }

Where “t” is a TTree containing a Branch “event”, where “event” is a C-structure:

  struct{	
	unsigned int run_number,event_number,tree_number;
	float q_value,eq_value;
	float mc_weight;
	float W;
	float e_gamma;
	float t;
	float cos_cm;
	float theta_adair,phi_adair;
	float s_omega,t_omega,u_omega;	
	float omega_mass;
	float m2_ep;
	float lambda; //the lambda method.
  }m_event;

When I execute the code, I see:

DataStore data (data)
  Contains 0 entries
  Observables:
    1)  omega_mass = 0.7557  L(0.63 - 0.93)  "omega_mass"
  Dataset variable "qq_value" is interpreted as the event weight

That is, the RooDataSet “recognizes” that qq is the weight var. However, at each loop execution, I see that the “qq.getValV()” returns the correct value (between 0 and 1), while the “data.weight()” always returns 1.

(Later on in the code I am also plotting the RooDataSet, and I confirm that the values are ploted with constant weight = 1)

Am I making any mistake?

Thanks!

Andrea

I found a work-around:

  1. Create the “first” RooDataSet that get filled during the loop, without declaring any “weight”
 RooRealVar omega_mean("Omega Mean","Omega Mean",0.78,0.78-0.15,0.78+0.15);
  RooRealVar omega_width("Omega Width","Omega Width",8.49E-3); //the nominal omega width
  RooRealVar detector_res("Detector Resolution","Detector Resolution",0.005,0.002,0.02);
  RooRealVar omega_mass("omega_mass","omega_mass",0.78,0.78-0.15,0.78+0.15);
  RooRealVar q_value("q_value","q_value",1.,0.,1.);
  RooArgSet argset(omega_mass,q_value,"dataset");

 RooDataSet *data=new RooDataSet("data","data",argset);
  1. Fill it

for (int jj=0;jj<t->GetEntries();jj++){ t->GetEntry(jj); omega_mass.setVal(m_event.omega_mass); q_value.setVal(m_event.q_value); data->add(argset); }

  1. Create a new RooDataSet, copying the previous one, and declaring there the weight:
   RooDataSet dataNew("data","data",data,*data->get(),0,"q_value");

It seems that the “weight” of a RooData set get properly configured with the creator method, and not later on. Is this the way RooFit is supposed to work? If so, is this documented (probably I’ve not seen this!)