Assign weight to Ttree->Fill()?

Hi

I was trying to find, how would be possible after assigning values in TBranches to assign also a weight while trying to Fill the Tree - For example, after filling the TBranches with something like

 TTree *tree = new TTree ("observables", "list of observables");

for (unsigned int i = 0; i < vec.size (); i++)
    {
      var_[i] = -8888.;
      char arg[100];
      sprintf (arg, "%s/F", vec[i].c_str ());
      tree->Branch (vec[i].c_str (), &var_[i], arg);
}

 for (int i = 0; i < NofVar_; i++)
    {
      var_[i] = values.second;

    }
....
  tree->Fill ();

so, would be possible to do something like

tree->Fill(weight)

at the end ? the weight is the same for all var_[i] though for a particular loop/event.

thanks

Alex

Hi,

You could just store the weight in an additional branch and then use it
as a multiplicative factor in your selection when plotting from the
tree, e.g. like this (TNtuple since it is just easier to fill, TTree behaves
the same for the rest)

TNtuple t("t", "", "a:weight");
for (int i=0; i<100; ++i) {
  const double weight = gRandom->Rndm();
  const double a = gRandom->Gaus();
  t.Fill(a, weight);
}

t.Draw("a", "weight");       // all entries, weighted
t.Draw("a", "(a>0)*weight"); // selected entries, weight

Is that what you had in mind?

Ok, thanks…this is what I suspected, that I had to keep a separate weights TBranch - Btw, is there a way for the different TBranches , instead of doing

tree->Fill()

which loops on all defined branches and for each branch invokes the Fill function, rather than to skip filling the branch(es) given some cuts ?

thanks again

-a