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

{
  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