Access values from leaf

I have a tree and I am able to get the histogram of a leaf. But I am trying to print out the values of the leaf using a for loop but I am getting all the entries as 0.

tree->SetBranchAddress(“Imp”, &Imp);

for(Int_t i = 0; i<entries; i++){
tree->GetEntry(i);
cout << Imp[i] << endl;
}

Thanks!

Can you post a more complete example ?

https://drive.google.com/file/d/1KEwynNDrXrOGenniBhYhZFwGuFHTtAAu/view?usp=sharing

So here is the root file I am trying to access. It contains a leaf called Imp with 10k entries. I want tthe array Imp and I am trying to print out all the 10k entries of Imp[ ].

TFile *input = new TFile(“AuAu200GeV_SM_NT3_DecaysOff_0_20fm_file0.root”, “read”);
TTree tree = (TTree)input->Get(“tr”);
Float_t Imp[12000];
tree->SetBranchAddress(“Imp”, &Imp);
for(Int_t i = 0; i<entries; i++){
tree->GetEntry(i);
cout << Imp[i] << endl;
}

void shree() {
   TFile *input = new TFile("AuAu200GeV_SM_NT3_DecaysOff_0_20fm_file0.root", "read");
   TTree *tree = (TTree*)input->Get("tr");
   float Imp;
   tree->SetBranchAddress("Imp", &Imp);
   int entries = tree->GetEntries();
   TH1F *myhist = new TH1F("myhist", "myhist", 100, 0., 0.);
   for (int i = 1; i<=entries; i++) {
      tree->GetEntry(i);
      myhist->Fill(Imp);
      cout << i << " : "<< Imp << endl;
   }
   myhist->Draw();
}

1 Like

Thank you very much! :grin:

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