I'm writing a ROOT macro to read a tree, this tree contains many branches but I'm only interested in three particular ones. The problem is that when I try to read them I get wrong values, in fact if I type "h76->Show(1)" it prints out the value of the branches for the entry 1. When I try to read it from my macro and print, it gives me a wrong value. This is my code:
#define N_PID 10000
void pTdist()
{
Double_t pT;
int i;
Int_t PID[N_PID];
Int_t ntrack; //Number of particles in one event
TFile *file = new TFile("PROVA0.root","read");
file->ls();
TTree * Tout= (TTree*)file->Get("h76");
Tout->Print();
Int_t nentries=Tout->GetEntries();
Tout->SetBranchStatus("*", false);
//Tout->SetBranchStatus("ntrack", true); //In the ROOT tutorial it says that this operation is necessary but if I do it gives me error
//Tout->SetBranchStatus("PID", true);
//Tout->SetBranchStatus("pT", true);
cout << " nentries = " << nentries << endl; //Here prints the correct number of entries
Tout->SetBranchAddress("ntrack",&ntrack);
Tout->SetBranchAddress("pT",&pT);
Tout->SetBranchAddress("PID",&PID); //Fino a qui funziona tutto in teoria
for( i=0;i< 10;i++)
{
//cout << i << endl;
Tout->GetEntry(i); //
printf("%d %d\n",ntrack,i);
}
}
What am I missing here? Thanks to everyone who will answer.
I tried to print the "ntrack" value for each entry comparing it with the one I get from the command show() but they don't match.
with Tout->SetBranchStatus("*", false); you're disabling all the branches, so you can't access them after that