How to cout a certain value of a branch (only one value) of a tree?


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi all,
I am facing a problem. Now I want to print a branch of a tree. More specific , there is only one value in the branch which is a mcChannelNumber. like this:
Br 0 :mcChannelNumber : mcChannelNumber/I *
*Entries : 8463 : Total Size= 34548 bytes File Size = 426 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 79.89 *

the following is what i am trying( it doesn’t work):

void hsimpleReader() {
auto myFile = TFile::Open("./user.hucheng.17397654.XAMPP._000001.root");
auto t = (TTree*) myFile->Get(“Staus_Nominal”);
Int_t *mcChannelNumber=0;
t->SetBranchAddress(“mcChannelNumber”,&mcChannelNumber);
cout<< *mcChannelNumber<<endl;
}

{
  TFile *f = TFile::Open("user.hucheng.17397654.XAMPP._000001.root");
  if ((!f) || f->IsZombie()) { delete f; return; } // just a precaution
  TTree *t; f->GetObject("Staus_Nominal", t);
  if (!t) { delete f; return; } // just a precaution
  Int_t mcChannelNumber;
  t->SetBranchAddress("mcChannelNumber", &mcChannelNumber);
  t->GetEntry(0);
  std::cout << mcChannelNumber << std::endl;
  // t->ResetBranchAddresses(); // disconnect from local variables
  delete f; // automatically deletes "t", too
}
1 Like

Thank you very much! It does work!

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