How to read a only one branch from a tree?

Hi,
I am reading the Roofit manual:
Unbinned data can be imported in RooFit much along the same lines and is stored in class RooDataSet

and the code:

TTree* tree = (TTree*) gDirectory->Get(“atree”) ;
RooRealVar x(“x”,”x”,-10,10) ;
RooDataSet data(“data”,”dataset with x”,tree,x) ;

I am confused here, if my tree includes many branches and how can I only feed one of the branches? I tried the following code but it doesn’t work:

t->SetBranchStatus("*",0);
t->SetBranchStatus("ScalarHT.HT", 1);

RooRealVar HT("HT", "HT", 0, 2000);
RooDataSet dataHT("data", "dataset with HT", t, HT);

it doesn’t feed the branch ScalarHT.HT as I want. What can I do with that?

Best,
Li

__
ROOT Version: ROOT 6
Platform: Not Provided
Compiler: Not Provided


Hi Li,

I’m pretty sure that you have to define the RooReadVar variable to have the exact same name as the name of the branch.

https://root.cern.ch/doc/v614/classRooDataSet.html#abae58ac22fc0bf170d96842141ce90b6

I.e. you should try:

RooRealVar HT("ScalarHT.HT", "HT", 0, 2000);

Though I’ve never defined a dataset like this, I have to admit…

Hello @Li_Huang,

In the documentation
https://root.cern.ch/doc/master/classRooDataSet.html#abae58ac22fc0bf170d96842141ce90b6
it says that the name of the variable needs to be the same as the branch you want to import. In this case the variable needs to be named ScalarHT.HT

@Attila_Krasznahorkay

Hi all,
Thank you.
I tried and the following error appears:

[#0] ERROR:Eval – RooAbsReal::attachToTree(ScalarHT.HT) ERROR: TTree branch ScalarHT.HT is an array and cannot be attached to a RooAbsReal

I afraid that that’s because I used Delphes classes, so I did the following things:

gInterpreter->AddIncludePath("/home/lihuang/tools/packages/madgraph/Delphes/");
gInterpreter->AddIncludePath("/home/lihuang/tools/packages/madgraph/Delphes/external/");
gSystem->Load("/home/lihuang/tools/packages/madgraph/Delphes/libDelphes.so");

gInterpreter->Declare('#include "/Users/lihuang/tools/packages/madgraph/Delphes/classes/DelphesClasses.h"');
gInterpreter->Declare('#include "/Users/lihuang/tools/packages/madgraph/Delphes/external/ExRootAnalysis/ExRootAnalysisLinkDef.h"');

which I want is to tell Root interpreter where to find the Delphes classes. However some errors occur,

/Users/lihuang/work/6t2/analysis/test.C:19:27: error: cannot initialize a parameter of type 'const char ’ with an rvalue of type
‘int’
…‘#include “/Users/lihuang/tools/packages/madgraph/Delphes/classes/DelphesClasses.h”’);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/lihuang/tools/root6/include/TInterpreter.h:119:41: note: passing argument to parameter ‘code’ here
virtual Bool_t Declare(const char
code) = 0;
^
In file included from input_line_10:1:
/Users/lihuang/work/6t2/analysis/test.C:20:27: warning: multi-character character constant [-Wmultichar]

When using Python, the similar code always give the right path and .h files, what shall I do in C++?

Best,
Li

Hi Li,

I’m fairly sure that that error has nothing to do with your ntuple having been produced by Delphes.

I’m afraid that RooDataSet is not willing to read an array/vector variable like this. I’m afraid you’ll have to do something more elaborate to feed a vector variable such as this one into your fit.

It does beg the question though: How do you want to use this variable exactly? “HT” in my understanding is an “event-wide” variable. So the only reason for it to be an array in your ntuple should be because different elements of the array describe HT calculated in different ways. (That’s what we do in ATLAS with MET variables, that’s why I’m guessing this…) If that is the case, you’ll definitely have to write your own interface between that variable and RooFit.

Or, depending on the size of your ntuple, you could just create another ntuple from this one which contains all your variables of interest as simple primitives. (One value per event/entry.) Then you’d just need to write the code for creating that derived ntuple, and you could read the variables with RooDataSet with this formalism.

Cheers,
Attila

Hi,
Thank you very much.
I am not really know how Delphes calculate it ( though I think the definition is uniform for every entries but I don’t check the source code ). I guess what you suggest is to write a new tree with a single branch with this “HT”? I don’t understand if I can feed a ntuple to Roofit since it said “tree” explicitly. However, I afraid copy a branch to a new tree will be slow and occupy too much memory.

Best,
Li

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.