This branch does not exist?


Please read tips for efficient and successful posting and posting code

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


I have a ROOT file with a TNtuple.

I need to read off the day, hour, minute, second, and nanosecond from each row individually (i.e. I need to read off day/hour/min/sec/nsec from the first row, store each of those in a variable and do something with that, and then continue for the remaining rows). I’ve started out with the following code:

{
 
   // Open the file containing the tree.
   auto myFile = TFile::Open("./path/to/file.root");
   if (!myFile || myFile->IsZombie()) {
      return;
   }
   // Create a TTreeReader for the tree, for instance by passing the
   // TTree's name and the TDirectory / TFile it is in.
   TTreeReader myReader("N", myFile);
 
   // The branch "px" contains floats; access them as myPx.
   TTreeReaderValue<Float_t> myPx(myReader, "0");
 
   // Loop over all entries of the TTree or TChain.
   while (myReader.Next()) {
      // Just access the data as if myPx and myPy were iterators (note the '*'
      // in front of them):
      std::cout << *myPx;
   }
 
}

But I get the error:
Error in <TTreeReaderValueBase::CreateProxy()>: The tree does not have a branch called 0. You could check with TTree::Print() for available branches.

Maybe something like this:

   TTreeReaderValue<Float_t> myDay(myReader, "day");
   TTreeReaderValue<Float_t> myHr(myReader,  "hr");
   TTreeReaderValue<Float_t> myMin(myReader, "min");
   TTreeReaderValue<Float_t> mySec(myReader, "sec");