TTreeReader library missing

Hi, I have installed (from source) root 5.34.21 on ubuntu 14 (./configure --minimal)
I’m trying to do the tutorial root.cern.ch/drupal/content/intr … -tutorials but I’m stuck on “Using a Macro to Read a TTree. “
When I run the macro (”.x macroname.C”) root tells me that cannot find TTreeReader.h
"Error: cannot open file TTreeReader.h"

I think that TTreeReader is a basic library, why I don’t have it?
I try to download the library, but then another library that TTreeReader.h is missing, and so on with a series of missing library until BIT is missing and I didn’t know what to do.

I’m very new and negate in root or coding, what can I do?

Thanks for the help,
Alberto

Hi Alberto,

this tutorial is designed for ROOT6: we’ll make it clearer in all of its pages.
If you want to get the latest ROOT6 release, you can have a look to
root.cern.ch/drupal/content/roo … ease-notes

Cheers,
Danilo

So is there another way to achieve what the mentioned tutorial aims to do (read TTree from a macro) in ROOT 5.34/xx? Can anyone please share the link?

Hi guys,

I have the same problem. I am trying to run a simple Macro but I have this error message:
“Error: cannot open file TTreeReader.h”

I need help, because I can’t get stuck in the beginning of a tutorial.

Cheers,
Amine

Here’s the macro:

#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TH1F.h"
#include "TTreeReader.h"
#include "TTreeReaderArray.h"

void AnalyzeTree()
{
   // Variables used to store the data
   TH1F *hPosX;  // X position of the particles

   // open the file
   TFile *f = TFile::Open("http://lcg-heppkg.web.cern.ch/lcg-heppkg/ROOT/eventdata.root");
   if (f == 0) {
      // if we cannot open the file, print an error message and return immediatly
      printf("Error: cannot open http://lcg-heppkg.web.cern.ch/lcg-heppkg/ROOT/eventdata.root!\n");
      return;
   }

   // Create tyhe tree reader and its data containers
   TTreeReader myReader("EventTree", f);
   // The branch "fPosX" contains doubles; access them as particlesPosX.
   TTreeReaderArray<Double_t> particlesPosX(myReader, "fParticles.fPosX");
   // The branch "fMomentum" contains doubles, too; access those as particlesMomentum.
   TTreeReaderArray<Double_t> particlesMomentum(myReader, "fParticles.fMomentum");

   // create the TH1F histogram
   hPosX = new TH1F("hPosX", "Position in X", 20, -5, 5);
   // enable bin errors:
   hPosX->Sumw2();

   // Loop over all entries of the TTree or TChain.
   while (myReader.Next()) {
      // Do the analysis...
      for (int iParticle = 0; iParticle < particlesPosX.GetSize(); ++iParticle) {
         if (particlesMomentum[iParticle] > 40.0)
            hPosX->Fill(particlesPosX[iParticle]);
      }
   }

   // Fit the histogram:
   hPosX->Fit("pol2");
   // and draw it:
   hPosX->Draw();
}

Hi,

Amine: This is not the same problem - which explains why the error message is so different! Are you using ROOT6? Next time please open a new topic - to not mix issues.

In ROOT 5 you can create a TSelector and use TTree::SetBranchAddress() etc; see tutorials/tree/h1analysis.{C,h} for a complete example.

Axel.

For ROOT 5 “analysis skeleton” links (no “TTreeReader”) see, for example: