Reading a tree with vectors problem

Please provide the following information:


ROOT Version (e.g. 6.12/02):
Platform, compiler (e.g. CentOS 7.3, gcc6.2):


Hi,
I have a problem with reading a tree with vectors !!! I searched everywhere but i didnt find anything interesting,Here is a part of my code

vector *jet_eta =nullptr;

tree->SetBranchStatus(“jet_eta”, 1);
tree->SetBranchAdress(“jet_eta” ,&jet_eta);

for Int_t i=0; i<N ;i++ {

h->Fill(jet_eta) //How to make an histogram with this variable ??

h->Fill((*jet_eta[])) //i also tried this but it didn’t work either !!
}
Thank you guys,
panos

Hi Panos,

I propose to solve this with TDataFrame, the reccomended way of dealing with ROOT datasets:

ROOT::Experimental::TDataFrame d("yourTree", "yourFile.root"); // Will not be Experimental with 6.14, to be released in a few weeks.
auto h = d.Histo1D("jet_eta");
h->Draw();

Cheers,
Danilo

Hi Danilo ,
Thank you for your help, let me show you my code after your recomedation,it didnt work either .

vector *jet_eta =nullptr;
TFile *f= new TFile(g+“myfile.root”);
TTree *t = (TTree *) f ->Get(“mytree”);
ROOT::Experimental::TDataFrame d(“mytree”, “myfile.root”);
TH1F *h=new TH1F(“h”,“h”,10,0,100);

;

tree->SetBranchStatus(“jet_eta”, 1);
tree->SetBranchAdress(“jet_eta” ,&jet_eta);
Int_t N =t->GetEntries();
for Int_t i=0; i<N ;i++ {

auto h = d.Histo1D(“jet_eta”);

}

h->Draw();

Hi,

what was the error?

Cheers,
Danilo

Hi,

I just realised the code you used cannot work. It is necessary to just use the following one:

ROOT::Experimental::TDataFrame d(“mytree”, “myfile.root”);
auto h = d.Histo1D(“jet_eta”);
h->Draw();

Cheers,
D

hi,
The problem is that i have to fill histogram with jet_eta per event(entry) so i have to do a loop here,otherwise i wil have an empty canvas!!!
thank you for your help !!!
Panos

Hi Panos,
what about this code: it should do what you want, all loops are handled for you automatically:

ROOT::Experimental::TDataFrame d(“mytree”, “myfile.root”);
auto h = d.Histo1D(“jet_eta”);
h->Draw();

Cheers,
D

1 Like

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