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?
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
#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();
}
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.