Problem accessing to PID number

Hi,
I am really new to Root so I am trying to learn using the tutorials and I am following the guides in http://root.cern.ch/drupal/content/introductory-tutorials

I have generated some events withing MadGraph (pp->t tbar) and I would like for each event to print the number of particles in the process and the relative PID number for each particle.

I have written the following code that should list the number of particle in each event (no PID code yet)

[code]#include “TFile.h”
#include “TTree.h”
#include “TBranch.h”
#include “TH1F.h”

const Int_t kMaxfParticles = 10000000;

void MyAnalyzeTree_new()
{
// List of branches
TBranch *nParticlesBranch;
TBranch *particlesNumberBranch;
TBranch *particlesPIDBranch;

// Declaration of leaf types
Int_t nParticles;
Int_t particlesNumber[kMaxfParticles];
Int_t particlesPID[kMaxfParticles];

// open the file
TFile *f = TFile::Open(“unweighted_events.root”);
if (f == 0) {
// if we cannot open the file, print an error message and return immediatly
printf(“Error: cannot open file\n”);
return;
}
// get a pointer to the tree
TTree *tree = (TTree )f->Get(“LHEF”);
// To use SetBranchAddress() with simple types (e.g. double, int)
// instead of objects (e.g. std::vector).
tree->SetMakeClass(1);
// // // /

// // // // Connect the branches with their member variables.
tree->SetBranchAddress(“Event”, &nParticles, &nParticlesBranch);
tree->SetBranchAddress(“Event.Nparticles”, particlesNumber, &particlesNumberBranch);
// // //
Long64_t nentries = tree->GetEntries();

for (Long64_t i=0;i<nentries;i++) {
// // // // // We only need the number of particles…
nParticlesBranch->GetEntry(i);
// // // // // … and their momentum
particlesNumberBranch->GetEntry(i);

  printf("Event n. %d number of particles %d PID=%d\n",i,particlesNumber[0]);

// // //
}
}[/code]

but event at this level I have a question:
What is the Branch called Event ? Which informations does it contains?
I never use it explicitally in my macro, but if I uncomment the lines

and

I get a segmentation violation using the macro. Moreover if I try to print the value nParticles is always equal to 1, so I can’t understand what kind of information this Branch contain.

And why the number of particle is written in particlesNumber[0] ?
Actually the fact that is the number of particle is my guess since I get from a print the value 4, which is the number of ext. particle in my process. If I try to print particlesNumber[1] for example it returns zero…
However I am not really sure that that number is the number of external particles in my event… Otherwise in which branch is this info?

Then, when I try to extract the PID of the particle I am using the following code (I have added just a few lines to the previous code, referring to the new branch that I would like to analyze)

[code]#include “TFile.h”
#include “TTree.h”
#include “TBranch.h”
#include “TH1F.h”

const Int_t kMaxfParticles = 10000000;

void MyAnalyzeTree_new()
{
// List of branches
TBranch *nParticlesBranch;
TBranch *particlesNumberBranch;
TBranch *particlesPIDBranch;

// Declaration of leaf types
Int_t nParticles;
Int_t particlesNumber[kMaxfParticles];
Int_t particlesPID[kMaxfParticles];

// open the file
TFile *f = TFile::Open(“unweighted_events.root”);
if (f == 0) {
// if we cannot open the file, print an error message and return immediatly
printf(“Error: cannot open file\n”);
return;
}
// get a pointer to the tree
TTree *tree = (TTree )f->Get(“LHEF”);
// To use SetBranchAddress() with simple types (e.g. double, int)
// instead of objects (e.g. std::vector).
tree->SetMakeClass(1);
// // // /

// // // // Connect the branches with their member variables.
tree->SetBranchAddress(“Event”, &nParticles, &nParticlesBranch);
tree->SetBranchAddress(“Event.Nparticles”, particlesNumber, &particlesNumberBranch);
tree->SetBranchAddress(“Particle.PID”, particlesPID, &particlesPIDBranch);
// // //
Long64_t nentries = tree->GetEntries();

for (Long64_t i=0;i<nentries;i++) {
// // // // // We only need the number of particles…
nParticlesBranch->GetEntry(i);
// // // // // … and their momentum
particlesNumberBranch->GetEntry(i);
particlesPIDBranch->GetEntry(i);

  printf("Event n. %d number of particles %d PID=%d\n",i,particlesNumber[0]);

// // //
}
}
[/code]

but now I always get the “segmentation violation” and I can’t understand why since from a LHEF->Print() in root I get

[code]******************************************************************************
*Tree :LHEF : Analysis tree *
*Entries : 10000 : Total = 6751309 bytes File Size = 2040115 *

  •    :          : Tree compression factor =   3.31                       *
    

*Br 0 :Event : Int_t Event_ *
*Entries : 10000 : Total Size= 86395 bytes File Size = 12506 *
*Baskets : 2 : Basket Size= 64000 bytes Compression= 6.41 *

*Br 1 :Event.fUniqueID : UInt_t fUniqueID[Event_] *
*Entries : 10000 : Total Size= 80774 bytes File Size = 12516 *
*Baskets : 2 : Basket Size= 64000 bytes Compression= 6.41 *

*Br 2 :Event.fBits : UInt_t fBits[Event_] *
*Entries : 10000 : Total Size= 80750 bytes File Size = 12534 *
*Baskets : 2 : Basket Size= 64000 bytes Compression= 6.40 *

*Br 3 :Event.Number : Long64_t Number[Event_] *
*Entries : 10000 : Total Size= 120843 bytes File Size = 32118 *
*Baskets : 3 : Basket Size= 64000 bytes Compression= 3.74 *

*Br 4 :Event.Nparticles : Int_t Nparticles[Event_] *
*Entries : 10000 : Total Size= 80780 bytes File Size = 12542 *
*Baskets : 2 : Basket Size= 64000 bytes Compression= 6.39 *

*Br 5 :Event.ProcessID : Int_t ProcessID[Event_] *
*Entries : 10000 : Total Size= 80774 bytes File Size = 12536 *
*Baskets : 2 : Basket Size= 64000 bytes Compression= 6.40 *

*Br 6 :Event.Weight : Double_t Weight[Event_] *
*Entries : 10000 : Total Size= 120843 bytes File Size = 12304 *
*Baskets : 3 : Basket Size= 64000 bytes Compression= 9.77 *

*Br 7 :Event.ScalePDF : Double_t ScalePDF[Event_] *
*Entries : 10000 : Total Size= 120857 bytes File Size = 59187 *
*Baskets : 3 : Basket Size= 64000 bytes Compression= 2.03 *

*Br 8 :Event.CouplingQED : Double_t CouplingQED[Event_] *
*Entries : 10000 : Total Size= 120878 bytes File Size = 12321 *
*Baskets : 3 : Basket Size= 64000 bytes Compression= 9.76 *

*Br 9 :Event.CouplingQCD : Double_t CouplingQCD[Event_] *
*Entries : 10000 : Total Size= 120878 bytes File Size = 85301 *
*Baskets : 3 : Basket Size= 64000 bytes Compression= 1.41 *

*Br 10 :Event_size : Event_size/I *
*Entries : 10000 : Total Size= 40648 bytes File Size = 420 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 95.60 *

*Br 11 :Particle : Int_t Particle_ *
*Entries : 10000 : Total Size= 92370 bytes File Size = 12526 *
*Baskets : 2 : Basket Size= 64000 bytes Compression= 6.40 *

*Br 12 :Particle.fUniqueID : UInt_t fUniqueID[Particle_] *
*Entries : 10000 : Total Size= 200984 bytes File Size = 12552 *
*Baskets : 4 : Basket Size= 64000 bytes Compression= 15.96 *

*Br 13 :Particle.fBits : UInt_t fBits[Particle_] *
*Entries : 10000 : Total Size= 200952 bytes File Size = 12627 *
*Baskets : 4 : Basket Size= 64000 bytes Compression= 15.87 *

*Br 14 :Particle.PID : Int_t PID[Particle_] *
*Entries : 10000 : Total Size= 200936 bytes File Size = 18895 *
*Baskets : 4 : Basket Size= 64000 bytes Compression= 10.60 *

*Br 15 :Particle.Status : Int_t Status[Particle_] *
*Entries : 10000 : Total Size= 200960 bytes File Size = 12875 *
*Baskets : 4 : Basket Size= 64000 bytes Compression= 15.56 *

*Br 16 :Particle.Mother1 : Int_t Mother1[Particle_] *
*Entries : 10000 : Total Size= 200968 bytes File Size = 13184 *
*Baskets : 4 : Basket Size= 64000 bytes Compression= 15.20 *

*Br 17 :Particle.Mother2 : Int_t Mother2[Particle_] *
*Entries : 10000 : Total Size= 200968 bytes File Size = 13181 *
*Baskets : 4 : Basket Size= 64000 bytes Compression= 15.20 *

*Br 18 :Particle.ColorLine1 : Int_t ColorLine1[Particle_] *
*Entries : 10000 : Total Size= 200992 bytes File Size = 24089 *
*Baskets : 4 : Basket Size= 64000 bytes Compression= 8.32 *

*Br 19 :Particle.ColorLine2 : Int_t ColorLine2[Particle_] *
*Entries : 10000 : Total Size= 200992 bytes File Size = 25905 *
*Baskets : 4 : Basket Size= 64000 bytes Compression= 7.74 *

*Br 20 :Particle.Px : Double_t Px[Particle_] *
*Entries : 10000 : Total Size= 361186 bytes File Size = 117075 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 3.08 *

*Br 21 :Particle.Py : Double_t Py[Particle_] *
*Entries : 10000 : Total Size= 361186 bytes File Size = 117056 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 3.08 *

*Br 22 :Particle.Pz : Double_t Pz[Particle_] *
*Entries : 10000 : Total Size= 361186 bytes File Size = 320185 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 1.13 *

*Br 23 :Particle.E : Double_t E[Particle_] *
*Entries : 10000 : Total Size= 361175 bytes File Size = 319800 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 1.13 *

*Br 24 :Particle.M : Double_t M[Particle_] *
*Entries : 10000 : Total Size= 361175 bytes File Size = 19724 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 18.28 *

*Br 25 :Particle.PT : Double_t PT[Particle_] *
*Entries : 10000 : Total Size= 361186 bytes File Size = 114171 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 3.16 *

*Br 26 :Particle.Eta : Double_t Eta[Particle_] *
*Entries : 10000 : Total Size= 361197 bytes File Size = 188899 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 1.91 *

*Br 27 :Particle.Phi : Double_t Phi[Particle_] *
*Entries : 10000 : Total Size= 361197 bytes File Size = 188580 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 1.91 *

*Br 28 :Particle.Rapidity : Double_t Rapidity[Particle_] *
*Entries : 10000 : Total Size= 361252 bytes File Size = 187467 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 1.92 *

*Br 29 :Particle.LifeTime : Double_t LifeTime[Particle_] *
*Entries : 10000 : Total Size= 361252 bytes File Size = 14194 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 25.41 *

*Br 30 :Particle.Spin : Double_t Spin[Particle_] *
*Entries : 10000 : Total Size= 361208 bytes File Size = 38320 *
*Baskets : 7 : Basket Size= 64000 bytes Compression= 9.41 *

*Br 31 :Particle_size : Particle_size/I *
*Entries : 10000 : Total Size= 40666 bytes File Size = 427 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 94.05 *

[/code]

and looks like I am referring in the correct way…

Does anybody knows what I am doing wrong?

Thanks in advance

Daniele