Making macro using makeClass

Hi Everyone,
I would like to generate a myClass.C macro from my tree by using a makeClass so I did this:

TFile* f = new TFile("run8TeV.0.txt.root");
TTree *redTree;
 f->GetObject("redTree",redTree);
 redTree->MakeClass("MyClass")

But I get all this error

Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron0_p4In.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron0_p4In.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron0_p4In.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron0_p4In.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron0_p4Out.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron0_p4Out.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron0_p4Out.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron0_p4Out.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron0_trk_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron0_trk_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron0_trk_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron0_trk_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron0_vrtx_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron0_vrtx_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron0_vrtx_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron0_vrtx_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron0_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron0_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron0_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron0_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named electron0_id2012_tight (full path name: electron0_id2012_tight) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named electron0_id2012_tight (full path name: electron0_id2012_tight) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named electron0_id2012_tight (full path name: electron0_id2012_tight) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron1_p4In.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron1_p4In.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron1_p4In.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron1_p4In.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron1_p4Out.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron1_p4Out.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron1_p4Out.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron1_p4Out.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron1_trk_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron1_trk_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron1_trk_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron1_trk_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron1_vrtx_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron1_vrtx_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron1_vrtx_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron1_vrtx_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: electron1_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: electron1_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: electron1_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: electron1_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named electron1_id2012_tight (full path name: electron1_id2012_tight) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named electron1_id2012_tight (full path name: electron1_id2012_tight) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named electron1_id2012_tight (full path name: electron1_id2012_tight) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: conversion0_refitPairMom_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: conversion0_refitPairMom_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: conversion0_refitPairMom_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: conversion0_refitPairMom_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: conversion0_vtxpos.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: conversion0_vtxpos.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: conversion0_vtxpos.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: conversion0_vtxpos.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: conversion1_refitPairMom_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: conversion1_refitPairMom_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: conversion1_refitPairMom_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: conversion1_refitPairMom_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: conversion1_vtxpos.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: conversion1_vtxpos.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: conversion1_vtxpos.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: conversion1_vtxpos.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: supercluster0_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: supercluster0_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: supercluster0_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: supercluster0_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: supercluster0_pos_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: supercluster0_pos_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: supercluster0_pos_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: supercluster0_pos_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: supercluster0_vtx_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: supercluster0_vtx_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: supercluster0_vtx_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: supercluster0_vtx_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: supercluster1_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: supercluster1_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: supercluster1_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: supercluster1_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: supercluster1_pos_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: supercluster1_pos_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: supercluster1_pos_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: supercluster1_pos_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: supercluster1_vtx_p4.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: supercluster1_vtx_p4.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: supercluster1_vtx_p4.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: supercluster1_vtx_p4.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: vertex_position.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: vertex_position.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: vertex_position.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: vertex_position.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fX (full path name: vertex_covMatrix.fCoordinates.fX) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fY (full path name: vertex_covMatrix.fCoordinates.fY) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fZ (full path name: vertex_covMatrix.fCoordinates.fZ) is hidden by another branch of the same name and its data will not be loaded.
Error in <TTreePlayer::MakeClass>: The branch named fCoordinates.fT (full path name: vertex_covMatrix.fCoordinates.fT) is hidden by another branch of the same name and its data will not be loaded.

So I will really appreciate if someone could explain why I get this error and to solve it. This is the link to access to the root file dropbox.com/s/j28vp30wqv063 … .root?dl=0

Hi,

this topic has been treated already in other posts, e.g. Reading a tree containing vector<TLorentzVector> .
If intervening manually on the generated class is too lengthy for you, you can always resort to pyroot. This trivial example prints the transverse momentum of all “first” electrons in your tree:

import ROOT
f=ROOT.TFile("run8TeV.0.txt.root")
for e in f.redTree:
    print e.electron0_p4In.Pt()

Cheers,
Danilo

Thanks Danilo for replying, I gonna consult the link.
Cheers

Hi Danilo,
In fact I follow your suggestion by changing it manually and it works but it’s really very very slow and I thing there is something I missed. For instance in root tutorial about makeclass, after changing the makeclass::Loop() and adapt it in my case I should do:

But I skip the first line because it give an error like this:

and I do only
[/quote]

Do you think this skip could cause why it takes so long time?
Here is the MyClass.C for instance

#define MyClass_cxx
#include "MyClass.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

void MyClass::Loop()
{
//   In a ROOT session, you can do:
//      root> .L MyClass.C
//      root> MyClass t
//      root> t.GetEntry(12); // Fill t data members with entry number 12
//      root> t.Show();       // Show values of entry 12
//      root> t.Show(16);     // Read and show values of entry 16
//      root> t.Loop();       // Loop on all entries
//

//     This is the loop skeleton where:
//    jentry is the global entry number in the chain
//    ientry is the entry number in the current Tree
//  Note that the argument to GetEntry must be:
//    jentry for TChain::GetEntry
//    ientry for TTree::GetEntry and TBranch::GetEntry
//
//       To read only selected branches, Insert statements like:
// METHOD1:
//    fChain->SetBranchStatus("*",0);  // disable all branches
//    fChain->SetBranchStatus("branchname",1);  // activate branchname
// METHOD2: replace line
//    fChain->GetEntry(jentry);       //read all branches
//by  b_branchname->GetEntry(ientry); //read only this branch

 TCanvas *c1 = new TCanvas("c1", "c1",10,54,700,530);
   gStyle->SetOptFit(1);
   gStyle->SetOptTitle(0);
   c1->Range(-0.65,0.975,0.65,1.025);
   c1->SetFillStyle(4000);
   c1->SetBorderMode(0);
   c1->SetBorderSize(2);
   c1->SetFrameFillColor(0);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);

   if (fChain == 0) return;

   Long64_t nentries = fChain->GetEntriesFast();
   TH2F *eOpinHisto  = new TH2F("eOpinHisto","eOpin vs eta 1RG",60,-0.441,0.441,60, 0,1.2);
   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      GetEntry(jentry);
if (electron0_p4.eta() > -0.441 && electron0_p4.eta() < 0.441  && electron0_class == 0 && dielectron_mass > 60. && dielectron_mass < 120. && electron0_r9 > 0.94)
  {
    
  
      
    eOpinHisto->Fill(electron0_p4.e()/sqrt(pow(electron0_p4In.px(),2)+pow(electron0_p4In.py(),2)+pow(electron0_p4In.pz(),2)),electron0_p4.eta());
  }
  
      if (ientry < 0) break;
       nb = fChain->GetEntry(jentry);   nbytes += nb;
      // if (Cut(ientry) < 0) continue;
   }
 eOpinHisto->Draw("prof");
 
}

Hi,

glad it worked for you.
Now, I understand the issue is runtime performance. Unfortunately here a plethora of possibilities are on the table, so let’s kick this off with some questions:
Why do you say it’s slow?
Where is the time spent?
Are you reading a local file?
Is it on afs or another distributed file system?
Are you alone on the machine where you are running?

Cheers,
Danilo

Hi Danilo,
here are my responses

because if I did for instance:

it takes less than 10 mn and if I use MyClass.C to plot the same histo it takes almost 1h:30.

yes it’s a local file.

It’s in my own computer, I copied the data from my lxplus account because of a matter of capacity.

yes I am alone on it.
Cheers

Hi,
I think the problem is related to the TLorentz because even if it doesn’t display any error after I changed them manually but the variables related to the Tlorentz are empty for instance if I printed electron0_p4.eta() or electron0_p4.e()…etc… they display zero. I changed them manually but I don’t know they are empty.
Cheers

Hi,

I do not get this last comment, sorry.
Did you try to enable only the branches you are reading with

    fChain->SetBranchStatus("*",0);  // disable all branches
    fChain->SetBranchStatus("branchname",1);  // activate branchname

TTree::Draw does that implicitly.

Danilo

Hi,
the lines code reduce a lot the timing, it’s magic :slight_smile: . For instance now I can plot the histogram mass in 12 mn by doing:

myHisto->Fill(dielectron_mass)

But In my previous message I said that the vector lorentz members are empty for instance if I wanna plot by doing

myHisto->Fill(electron0_p4.eta())
or
myHisto->Fill(electron0_p4.e())

they are all empty.
I changed them manually but they are empty and in fact I need more these variables.
Cheers

Hi Danilo,
Do you have any idea why the vectors lorentz members are empty, after I changed them manually?
Cheers

Dear all,
I am struggling with my code, it gets some evolutions because it works without errors now, but I can’t still get what I need so I would appreciate any help from you please.
In fact as in my previous messages I am trying to use makeClass but since I have some Lorentzvector in my case it gave me some errors, and with suggestions I get from Danilo, I changed it manually and it works without errors and I can have some plots of all the variables except the members of the LorentzVectors like the energy, pt, px,…(via electron0_p4.e(),electron0_p4.pt()…) because it displays 0 for this variables. So maybe it’s the way I changed it that root doesn’t like or not. Here is the Myclass.C and MyClass.h:
MyClass.C

#define MyClass_cxx
#include "MyClass.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

void MyClass::Loop()
{
 if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
   // TH2F *eOpinHisto  = new TH2F("eOpinHisto","eOpin vs eta 1RG",60,-0.441,0.441,60, 0,1.2);
   Long64_t nbytes = 0, nb = 0;
TH1F *myHisto  = new TH1F("myHisto","fPx", 60, 60,120);
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      GetEntry(jentry);
      if (ientry < 0) break;
       nb = fChain->GetEntry(jentry);   nbytes += nb;
     // if (Cut(ientry) < 0) continue;
     cout << electron0_p4.e() << endl;
	
   }
}
//////////////////////////////////////////////////////////
// This class has been automatically generated on
// Wed Jun 15 15:26:01 2016 by ROOT version 6.06/02
// from TTree redTree/a small Tree
// found on file: DataTreeMergerd.root
//////////////////////////////////////////////////////////

#ifndef MyClass_h
#define MyClass_h

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include "Math/LorentzVector.h"
#include "Math/Point3D.h"
#include "TMath.h"
#include <vector> 
#include "TLorentzVector.h"
typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > LorentzVector;

// Header file for the classes stored in the TTree if any.

class MyClass {
public :
   TTree          *fChain;   //!pointer to the analyzed TTree or TChain
   Int_t           fCurrent; //!current Tree number in a TChain

// Fixed size dimensions of array or collections stored in the TTree if any.

   // Declaration of leaf types
// ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > *dielectron_p4;
 LorentzVector     dielectron_p4;
   Float_t         dielectron_mass;
   Float_t	   dielectron_pt;
   Float_t	   scale1fb;
   Int_t	   run;
   Long64_t	   event;
   Int_t	   lumi;
 //ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > *electron0_p4In;
 LorentzVector electron0_p4In;
 //ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > *electron0_p4Out;
  LorentzVector electron0_p4Out;
 //ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > *electron0_trk_p4;
   LorentzVector electron0_trk_p4;
 //ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > *electron0_vrtx_p4;
   LorentzVector electron0_vrtx_p4;
//ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > *electron0_p4;
   LorentzVector electron0_p4;
   Int_t           electron0_class;
   Float_t	   electron0_fbrem;
   Float_t	   electron0_eSC;
   Float_t	   electron0_z0;
   Float_t	   electron0_lostHits;
   Bool_t	   electron0_pass[4];
   Float_t	   electron0_ecalEnergy;
   Float_t	   electron0_eSCPresh;
   Float_t	   electron0_HoE;
   Float_t	   electron0_dEtaIn;
   Float_t	   electron0_dEtaOut;
   Float_t	   electron0_dPhiIn;
   Float_t	   electron0_dPhiOut;
   Float_t         electron0_r9;

 TBranch        *b_dielectron_p4;   //!
   TBranch        *b_dielectron_mass;   //!
   TBranch	  *b_dielectron_pt;   //!
   TBranch	  *b_scale1fb;	 //!
   TBranch	  *b_run;   //!
   TBranch	  *b_event;   //!
   TBranch	  *b_lumi;   //!
   TBranch        *b_electron0_p4In;   //!
   TBranch	  *b_electron0_p4Out;	//!
   TBranch	  *b_electron0_trk_p4;	 //!
   TBranch	  *b_electron0_vrtx_p4;	  //!
   TBranch        *b_electron0_p4;   //!
   TBranch        *b_electron0_class;   //!
   TBranch	  *b_electron0_fbrem;	//!
   TBranch	  *b_electron0_eSC;   //!
   TBranch	  *b_electron0_z0;   //!
   TBranch	  *b_electron0_lostHits;   //!
   TBranch	  *b_electron0_pass;   //!
   TBranch	  *b_electron0_ecalEnergy;   //!
   TBranch	  *b_electron0_eSCPresh;   //!
   TBranch	  *b_electron0_HoE;   //!
   TBranch	  *b_electron0_dEtaIn;	 //!
   TBranch	  *b_electron0_dEtaOut;	  //!
   TBranch	  *b_electron0_dPhiIn;	 //!
   TBranch	  *b_electron0_dPhiOut;	  //!
   TBranch        *b_electron0_r9;   //!
   };

#endif

#ifdef MyClass_cxx
MyClass::MyClass(TTree *tree) : fChain(0) 
{
// if parameter tree is not specified (or zero), connect the file
// used to generate this class and read the Tree.
   if (tree == 0) {
      TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("DataTreeMergerd.root");
      if (!f || !f->IsOpen()) {
         f = new TFile("DataTreeMergerd.root");
      }
      f->GetObject("redTree",tree);

   }
   Init(tree);
}

MyClass::~MyClass()
{
   if (!fChain) return;
   delete fChain->GetCurrentFile();
}

Int_t MyClass::GetEntry(Long64_t entry)
{
// Read contents of entry.
   if (!fChain) return 0;
   return fChain->GetEntry(entry);
}
Long64_t MyClass::LoadTree(Long64_t entry)
{
// Set the environment to read one entry
   if (!fChain) return -5;
   Long64_t centry = fChain->LoadTree(entry);
   if (centry < 0) return centry;
   if (fChain->GetTreeNumber() != fCurrent) {
      fCurrent = fChain->GetTreeNumber();
      Notify();
   }
   return centry;
}
void MyClass::Init(TTree *tree)
{
   // The Init() function is called when the selector needs to initialize
   // a new tree or chain. Typically here the branch addresses and branch
   // pointers of the tree will be set.
   // It is normally not necessary to make changes to the generated
   // code, but the routine can be extended by the user if needed.
   // Init() will be called many times when running on PROOF
   // (once per file to be processed).

   // Set branch addresses and branch pointers
   if (!tree) return;
   fChain = tree;
   fCurrent = -1;
   fChain->SetMakeClass(1);
   // fChain->SetBranchStatus("*",0);  // disable all branches
   // fChain->SetBranchStatus("dielectron_mass",1);  // activate branchname
   fChain->SetBranchAddress("dielectron_p4", &dielectron_p4, &b_dielectron_p4);
   fChain->SetBranchAddress("dielectron_mass", &dielectron_mass, &b_dielectron_mass);
   fChain->SetBranchAddress("dielectron_pt", &dielectron_pt, &b_dielectron_pt);
   fChain->SetBranchAddress("scale1fb", &scale1fb, &b_scale1fb);
   fChain->SetBranchAddress("run", &run, &b_run);
   fChain->SetBranchAddress("event", &event, &b_event);
   fChain->SetBranchAddress("lumi", &lumi, &b_lumi);
   fChain->SetBranchAddress("electron0_p4In", &electron0_p4In, &b_electron0_p4In);
   fChain->SetBranchAddress("electron0_p4Out", &electron0_p4Out, &b_electron0_p4Out);
   fChain->SetBranchAddress("electron0_trk_p4", &electron0_trk_p4, &b_electron0_trk_p4);
   fChain->SetBranchAddress("electron0_vrtx_p4", &electron0_vrtx_p4, &b_electron0_vrtx_p4);
   fChain->SetBranchAddress("electron0_p4", &electron0_p4,&b_electron0_p4);
   fChain->SetBranchAddress("electron0_class", &electron0_class, &b_electron0_class);
   fChain->SetBranchAddress("electron0_fbrem", &electron0_fbrem, &b_electron0_fbrem);
   fChain->SetBranchAddress("electron0_eSC", &electron0_eSC, &b_electron0_eSC);
   fChain->SetBranchAddress("electron0_z0", &electron0_z0, &b_electron0_z0);
   fChain->SetBranchAddress("electron0_lostHits", &electron0_lostHits, &b_electron0_lostHits);
   fChain->SetBranchAddress("electron0_pass", electron0_pass, &b_electron0_pass);
   fChain->SetBranchAddress("electron0_ecalEnergy", &electron0_ecalEnergy, &b_electron0_ecalEnergy);
   fChain->SetBranchAddress("electron0_eSCPresh", &electron0_eSCPresh, &b_electron0_eSCPresh);
   fChain->SetBranchAddress("electron0_HoE", &electron0_HoE, &b_electron0_HoE);
   fChain->SetBranchAddress("electron0_dEtaIn", &electron0_dEtaIn, &b_electron0_dEtaIn);
   fChain->SetBranchAddress("electron0_dEtaOut", &electron0_dEtaOut, &b_electron0_dEtaOut);
   fChain->SetBranchAddress("electron0_dPhiIn", &electron0_dPhiIn, &b_electron0_dPhiIn);
   fChain->SetBranchAddress("electron0_dPhiOut", &electron0_dPhiOut, &b_electron0_dPhiOut);
   fChain->SetBranchAddress("electron0_r9", &electron0_r9, &b_electron0_r9);
  Notify();
}

Bool_t MyClass::Notify()
{
   // The Notify() function is called when a new file is opened. This
   // can be either for a new TTree in a TChain or when when a new TTree
   // is started when using PROOF. It is normally not necessary to make changes
   // to the generated code, but the routine can be extended by the
   // user if needed. The return value is currently not used.

   return kTRUE;
}

void MyClass::Show(Long64_t entry)
{
// Print contents of entry.
// If entry is not specified, print current entry
   if (!fChain) return;
   fChain->Show(entry);
}
Int_t MyClass::Cut(Long64_t entry)
{
// This function may be called from Loop.
// returns  1 if entry is accepted.
// returns -1 otherwise.
   return 1;
}
#endif // #ifdef MyClass_cxx

Thanks in advance.
–Diallo