Hi all,
I have a TTree with quite a few branches, and this one particular which I need to use is an array, but I’m only interested in the first element of the array, in this case it’s B_M[0].
I know that it’s still not possible to import data from an array in TTree to RooDataSet. So I get the data entry by entry and add them to RooDataSet. But it doesn’t work. As when I plot the data set, it gives 0 entry at all point except point which get all the entries (see the first plot).
This is the code I use right now:
f = TFile("myfile.root")
tree = f.Get("MyTree")
mass = array('d',[0])
branch = tree.GetBranch("B_M")
branch.SetAddress(mass)
numEntry = tree.GetEntries()
m = RooRealVar("B_M","mass",5300., 5450.)
m_arg = RooArgSet(m)
data = RooDataSet("data", "data", m_arg)
for i in range(numEntry):
tree.GetEvent(i)
m = mass[0]
data.add(m_arg, 1.0)
But when I tried the same thing in interactive ROOT, it works normally (see the second plot)
TFile f("tree.root");
TTree *datatree = (TTree*)(f.Get("MyTree"));
TBranch *branch = tree->GetBranch("B_M");
numEntry = branch->GetEntries();
Float_t mass[100];
branch->SetAddress(mass);
RooRealVar m("B_M","mass",5300., 5450.);
RooArgSet m_arg(m,"m_args");
RooDataSet * dataset = new RooDataSet("dataset","dataset",m_arg);
for(int i=0;i<datatree->GetEntries();i++){
tree->GetEvent(i);
m = mass[0];
dataset->add(m_arg,1.0);
}
Could anyone please help me with this?
Thanks,
Ryan
P/s: I’m using python 2.7.10 and root 6.08.06