Hi, I want to Print a array in Branch but it Print the address!
``TFile *myfile= new TFile(“ttbar.root”,“READ”);
//TTree tree= (TTree myfile)->Get(“LHEF”);
TTree *tree = (TTree *) myfile->Get(“LHEF”);
using namespace std;
Double_t Px[12], Py[12], Pz[12];
Int_t PID[12];
Double_t E[12];
tree->SetBranchAddress(“Particle.Px”, Px);
tree->SetBranchAddress(“Particle.Pz”, &Pz);
tree->SetBranchAddress(“Particle.Py”, &Py);
tree->SetBranchAddress(“Particle.PID”, &PID);
tree->SetBranchAddress(“Particle.E”, &E);
Long64_t nentries = tree->GetEntries();
for (int j=0; j<nentries; j++){
tree->GetEntry(j);
cout << Px << “\n”;} ___ Please read tips for efficient and successful posting and posting code
ROOT Version: 6.18 Platform: Not Provided Compiler: Not Provided
I figured out how to print these Particle.Px values. Not with TTree::SetBranchAddress() functionality though, but with TTreeReader one. Hope that’s okay:
TFile* myfile = TFile::Open("ttbar.root");
TTreeReader myReader("LHEF", myfile);
TTreeReaderArray<Double_t> particlePx(myReader, "Particle.Px");
while (myReader.Next())
{
if (myReader.GetCurrentEntry() % 10000 == 0)
{
printf("\tProcessing entry #%05lli out of %05lli: %lu particle(s)...\n", myReader.GetCurrentEntry(), myReader.GetEntries(false), particlePx.GetSize());
for (unsigned short pxIt = 0; pxIt < particlePx.GetSize(); ++pxIt)
printf("\t\tParticle #%02u: Px = %f\n", pxIt, particlePx[pxIt]);
}
}
myfile->Close();