]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSGammaJet.cxx
Moving the Decode methods (which are used by 2 classes now) (Laurent)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGammaJet.cxx
index 24a9b1203da1d0593d8df04a712db549f9b3161b..d9e1ac70422b053f3cb1f6084fbd26d4780a4bcd 100644 (file)
  **************************************************************************/
 /* $Id$ */
 
+/* History of cvs commits:
+ *
+ * $Log$
+ * Revision 1.14  2006/08/28 10:01:56  kharlov
+ * Effective C++ warnings fixed (Timur Pocheptsov)
+ *
+ * Revision 1.13  2006/04/26 07:32:37  hristov
+ * Coding conventions, clean-up and related changes
+ *
+ * Revision 1.12  2006/03/10 13:23:36  hristov
+ * Using AliESDCaloCluster instead of AliESDtrack
+ *
+ * Revision 1.11  2006/01/31 20:30:52  hristov
+ * Including TFile.h
+ *
+ * Revision 1.10  2006/01/23 18:04:08  hristov
+ * Removing meaningless const
+ *
+ * Revision 1.9  2006/01/12 16:23:26  schutz
+ * ESD is properly read with methods of macros/AliReadESD.C copied in it
+ *
+ * Revision 1.8  2005/12/20 07:08:32  schutz
+ * corrected error in call AliReadESD
+ *
+ * Revision 1.6  2005/05/28 14:19:04  schutz
+ * Compilation warnings fixed by T.P.
+ *
+ */
+
 //_________________________________________________________________________
 // Class for the analysis of gamma-jet correlations 
 //  Basically it seaches for a prompt photon in the PHOS acceptance, 
 
 // --- ROOT system ---
 
-#include "TParticle.h"
-#include "TCanvas.h"
-#include "TPaveLabel.h"
-#include "TPad.h"
+#include <TFile.h>
+#include <TParticle.h>
+#include <TCanvas.h>
+#include <TPaveLabel.h>
+#include <TPad.h>
+#include <TH2.h>
+
 #include "AliPHOSGammaJet.h" 
 #include "AliPHOSGetter.h" 
-#include "TH2.h"
 #include "AliPHOSGeometry.h"
 #include "AliPHOSFastGlobalReconstruction.h"
-//#include "Riostream.h"
-//#include "../PYTHIA6/AliGenPythia.h"
+#include "AliESD.h"
+#include "AliESDtrack.h"
+#include "AliESDCaloCluster.h"
+#include "Riostream.h"
+
 
 ClassImp(AliPHOSGammaJet)
 
 //____________________________________________________________________________
-AliPHOSGammaJet::AliPHOSGammaJet() : TTask() 
+AliPHOSGammaJet::AliPHOSGammaJet() : 
+  TTask(), fAnyConeOrPt(0), fOptionGJ(""),
+  fOutputFile(new TFile(gDirectory->GetName())),
+  fOutputFileName(gDirectory->GetName()),
+  fInputFileName(gDirectory->GetName()),
+  fHIJINGFileName(gDirectory->GetName()),
+  fHIJING(0), fESDdata(0), fEtaCut(0.),
+  fOnlyCharged(0), fPhiMaxCut(0.),
+  fPhiMinCut(0.), fPtCut(0.),
+  fNeutralPtCut(0.), fChargedPtCut(0.),
+  fInvMassMaxCut(0.), fInvMassMinCut(0.),
+  fMinDistance(0.), fRatioMaxCut(0.), fRatioMinCut(0.),
+  fTPCCutsLikeEMCAL(0), fDirName(""), fESDTree(""),
+  fPattern(""), fJetTPCRatioMaxCut(0.),
+  fJetTPCRatioMinCut(0.), fJetRatioMaxCut(0.),
+  fJetRatioMinCut(0.), fNEvent(0), fNCone(0),
+  fNPt(0), fCone(0), fPtThreshold(0),
+  fPtJetSelectionCut(0.0),
+  fListHistos(new TObjArray(100)),
+  fFastRec(0), fOptFast(0),
+  fRan(0), fResPara1(0.), fResPara2(0.), fResPara3(0.),  
+  fPosParaA(0.), fPosParaB(0.), fAngleMaxParam(), fSelect(0)
 {
   // ctor
   fAngleMaxParam.Set(4) ;
   fAngleMaxParam.Reset(0.);
-  fAnyConeOrPt      = 0  ;
-  fEtaCut           = 0. ;
-  fFastRec          = 0  ;
-  fInvMassMaxCut    = 0. ;
-  fInvMassMinCut    = 0. ;
-  fJetRatioMaxCut   = 0. ;
-  fJetRatioMinCut   = 0. ;
-  fJetTPCRatioMaxCut   = 0. ;
-  fJetTPCRatioMinCut   = 0. ;
-  fMinDistance      = 0. ;
-  fNEvent           = 0  ;
-  fNCone            = 0  ;
-  fNPt              = 0  ;
-  fOnlyCharged      = 0  ;
-  fOptFast          = 0  ;
-  fPhiMaxCut        = 0. ;
-  fPhiMinCut        = 0. ;
-  fPtCut            = 0. ;
-  fNeutralPtCut     = 0. ;
-  fChargedPtCut     = 0. ;
-  fRatioMaxCut      = 0. ;
-  fRatioMinCut      = 0. ;
-  fCone             = 0  ;
-  fPtThreshold      = 0  ;
-  fTPCCutsLikeEMCAL = 0  ;
-  fSelect           = 0  ;
+
   for(Int_t i = 0; i<10; i++){
     fCones[i]         = 0.0 ;
     fNameCones[i]     = ""  ;
     fPtThres[i]      = 0.0 ;
-    fPtJetSelectionCut = 0.0 ;
     fNamePtThres[i]  = ""  ;
     if( i < 6 ){
       fJetXMin1[i]     = 0.0 ;
@@ -97,21 +126,7 @@ AliPHOSGammaJet::AliPHOSGammaJet() : TTask()
       }
     }
   }
-
-  fOptionGJ       = "" ;
-  fOutputFile     = new TFile(gDirectory->GetName()) ;
-  fInputFileName  = gDirectory->GetName() ;
-  fOutputFileName = gDirectory->GetName() ;
-  fHIJINGFileName = gDirectory->GetName() ;
-  fHIJING        = 0 ;
-  fPosParaA      = 0. ;                      
-  fPosParaB      = 0. ;
-  fRan           = 0 ;                            
-  fResPara1      = 0. ;                       
-  fResPara2      = 0. ;                        
-  fResPara3      = 0. ;  
         
-  fListHistos     = new TObjArray(100) ;
   TList * list = gDirectory->GetListOfKeys() ; 
   TIter next(list) ; 
   TH2F * h = 0 ;
@@ -126,61 +141,67 @@ AliPHOSGammaJet::AliPHOSGammaJet() : TTask()
 
 //____________________________________________________________________________
 AliPHOSGammaJet::AliPHOSGammaJet(const TString inputfilename) : 
-  TTask("GammaJet","Analysis of gamma-jet correlations")
+  TTask("GammaJet","Analysis of gamma-jet correlations"),
+  fAnyConeOrPt(0), fOptionGJ(),
+  fOutputFile(0),
+  fOutputFileName(),
+  fInputFileName(),
+  fHIJINGFileName(),
+  fHIJING(0), fESDdata(0), fEtaCut(0.),
+  fOnlyCharged(0), fPhiMaxCut(0.),
+  fPhiMinCut(0.), fPtCut(0.),
+  fNeutralPtCut(0.), fChargedPtCut(0.),
+  fInvMassMaxCut(0.), fInvMassMinCut(0.),
+  fMinDistance(0.), fRatioMaxCut(0.), fRatioMinCut(0.),
+  fTPCCutsLikeEMCAL(0), fDirName(), fESDTree(),
+  fPattern(), fJetTPCRatioMaxCut(0.),
+  fJetTPCRatioMinCut(0.), fJetRatioMaxCut(0.),
+  fJetRatioMinCut(0.), fNEvent(0), fNCone(0),
+  fNPt(0), fCone(0), fPtThreshold(0),
+  fPtJetSelectionCut(0.0),
+  fListHistos(0),
+  fFastRec(0), fOptFast(0),
+  fRan(0), fResPara1(0.), fResPara2(0.), fResPara3(0.),  
+  fPosParaA(0.), fPosParaB(0.), fAngleMaxParam(), fSelect(0)
+
 {
-  // ctor 
+  // ctor
   fInputFileName = inputfilename;
   fFastRec = new AliPHOSFastGlobalReconstruction(fInputFileName);  
   AliPHOSGetter *  gime = AliPHOSGetter::Instance(fInputFileName) ;
   fNEvent = gime->MaxEvent();
   InitParameters();
-  fListHistos = 0 ;
 }
 
 //____________________________________________________________________________
-AliPHOSGammaJet::AliPHOSGammaJet(const AliPHOSGammaJet & gj) : TTask(gj)
+AliPHOSGammaJet::AliPHOSGammaJet(const AliPHOSGammaJet & gj) : 
+  TTask(gj),
+  fAnyConeOrPt(gj.fAnyConeOrPt), fOptionGJ(gj.fOptionGJ),
+  fOutputFile(gj.fOutputFile),
+  fOutputFileName(gj.fOutputFileName),
+  fInputFileName(gj.fInputFileName),
+  fHIJINGFileName(gj.fHIJINGFileName),
+  fHIJING(gj.fHIJING), fESDdata(gj.fESDdata), fEtaCut(gj.fEtaCut),
+  fOnlyCharged(gj.fOnlyCharged), fPhiMaxCut(gj.fPhiMaxCut),
+  fPhiMinCut(gj.fPhiMinCut), fPtCut(gj.fPtCut),
+  fNeutralPtCut(gj.fNeutralPtCut), fChargedPtCut(gj.fChargedPtCut),
+  fInvMassMaxCut(gj.fInvMassMaxCut), fInvMassMinCut(gj.fInvMassMinCut),
+  fMinDistance(gj.fMinDistance), fRatioMaxCut(gj.fRatioMaxCut), 
+  fRatioMinCut(gj.fRatioMinCut), fTPCCutsLikeEMCAL(gj.fTPCCutsLikeEMCAL), 
+  fDirName(gj.fDirName), fESDTree(gj.fESDTree),
+  fPattern(gj.fPattern), fJetTPCRatioMaxCut(gj.fJetTPCRatioMaxCut),
+  fJetTPCRatioMinCut(gj.fJetTPCRatioMinCut), fJetRatioMaxCut(gj.fJetRatioMaxCut),
+  fJetRatioMinCut(gj.fJetRatioMinCut), fNEvent(gj.fNEvent), fNCone(gj.fNCone),
+  fNPt(gj.fNPt), fCone(gj.fCone), fPtThreshold(gj.fPtThreshold),
+  fPtJetSelectionCut(gj.fPtJetSelectionCut),
+  fListHistos(0),//?????
+  fFastRec(gj.fFastRec), fOptFast(gj.fOptFast),
+  fRan(0), //???
+  fResPara1(gj.fResPara1), fResPara2(gj.fResPara2), fResPara3(gj.fResPara3),  
+  fPosParaA(gj.fPosParaA), fPosParaB(gj.fPosParaB), 
+  fAngleMaxParam(gj.fAngleMaxParam), fSelect(gj.fSelect)
 {
   // cpy ctor
-  fAngleMaxParam     = gj.fAngleMaxParam;
-  fAnyConeOrPt       = gj.fAnyConeOrPt;
-  fEtaCut            = gj.fEtaCut ;
-  fInvMassMaxCut     = gj.fInvMassMaxCut ;
-  fInvMassMinCut     = gj.fInvMassMinCut ;
-  fFastRec           = gj.fFastRec ;
-  fOptionGJ          = gj.fOptionGJ ;
-  fMinDistance       = gj.fMinDistance ;
-  fOptFast           = gj.fOptFast ;
-  fOnlyCharged       = gj.fOnlyCharged ;
-  fOutputFile        = gj.fOutputFile ;
-  fInputFileName     = gj.fInputFileName ;
-  fOutputFileName    = gj.fOutputFileName ;
-  fHIJINGFileName    = gj.fHIJINGFileName ;
-  fHIJING            = gj.fHIJING ;
-  fRatioMaxCut       = gj.fRatioMaxCut ;
-  fRatioMinCut       = gj.fRatioMinCut ;
-  fJetRatioMaxCut    = gj.fJetRatioMaxCut ;
-  fJetRatioMinCut    = gj.fJetRatioMinCut ;
-  fJetTPCRatioMaxCut = gj.fJetRatioMaxCut ;
-  fJetTPCRatioMinCut = gj.fJetRatioMinCut ;
-  fNEvent            = gj.fNEvent ;  
-  fNCone             = gj.fNCone ;
-  fNPt               = gj.fNPt ;
-  fResPara1          = gj.fResPara1 ;    
-  fResPara2          = gj.fResPara2 ; 
-  fResPara3          = gj.fResPara3 ; 
-  fPtCut             = gj.fPtCut ;
-  fNeutralPtCut      = gj.fNeutralPtCut ;
-  fChargedPtCut      = gj.fChargedPtCut ;
-  fPtJetSelectionCut = gj.fPtJetSelectionCut ;
-  fPhiMaxCut         = gj.fPhiMaxCut  ;
-  fPhiMinCut         = gj.fPhiMinCut ;
-  fPosParaA          = gj.fPosParaA ;    
-  fPosParaB          = gj.fPosParaB ;
-  fSelect            = gj.fSelect   ; 
-  fTPCCutsLikeEMCAL  = gj.fTPCCutsLikeEMCAL ;
-  fCone              = gj.fCone ;
-  fPtThreshold       = gj.fPtThreshold  ;
-
   SetName (gj.GetName()) ; 
   SetTitle(gj.GetTitle()) ; 
 
@@ -211,15 +232,13 @@ AliPHOSGammaJet::AliPHOSGammaJet(const AliPHOSGammaJet & gj) : TTask(gj)
 AliPHOSGammaJet::~AliPHOSGammaJet() 
 {
   fOutputFile->Close() ;
-
 }
 
 //____________________________________________________________________________
 void AliPHOSGammaJet::AddHIJINGToList(Int_t iEvent, TClonesArray * particleList, 
                                      TClonesArray * plCh, 
                                      TClonesArray * plNe,  
-                                     TClonesArray * plNePHOS,
-                                     const AliPHOSGeometry * geom )
+                                     TClonesArray * plNePHOS)
 {
 
   // List of particles copied to a root file.
@@ -256,6 +275,13 @@ void AliPHOSGammaJet::AddHIJINGToList(Int_t iEvent, TClonesArray * particleList,
   Int_t m = 0;
   Double_t x = 0., z = 0.;
   //  cout<<"bkg entries "<<t->GetEntries()<<endl;
+
+  AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
+  const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
+
+//DP. To be fixed: extract vertex position
+  Double_t vtx[3]={0.,0.,0.} ;
+
   if(!fOptFast){
     for (iParticle=0 ; iParticle < t->GetEntries() ; iParticle++) {
       t->GetEvent(iParticle) ;
@@ -284,7 +310,7 @@ void AliPHOSGammaJet::AddHIJINGToList(Int_t iEvent, TClonesArray * particleList,
          }
        }
        else if((charge == 0) && (particle->Pt() > fNeutralPtCut) ){
-         geom->ImpactOnEmc(particle->Theta(),particle->Phi(), m,z,x);
+         geom->ImpactOnEmc(vtx,particle->Theta(),particle->Phi(), m,z,x);
         
          if(m != 0)
            {//Is in PHOS
@@ -347,7 +373,7 @@ void AliPHOSGammaJet::AddHIJINGToList(Int_t iEvent, TClonesArray * particleList,
        indexCh++ ;
       }
       else if(charge == 0){
-       geom->ImpactOnEmc(particle->Theta(),particle->Phi(), m,z,x);
+       geom->ImpactOnEmc(vtx,particle->Theta(),particle->Phi(), m,z,x);
        if((particle->GetPdgCode() != 111) && (particle->Pt() > fNeutralPtCut) &&
           (TMath::Abs(particle->Eta())<fEtaCut) ){
          TLorentzVector part(particle->Px(),particle->Py(),
@@ -447,7 +473,7 @@ void AliPHOSGammaJet::AddHIJINGToList(Int_t iEvent, TClonesArray * particleList,
                  TParticle * photon1 = 
                    new TParticle(22,1,0,0,0,0,pGamma1.Px(),pGamma1.Py(),
                                  pGamma1.Pz(),pGamma1.E(),0,0,0,0);
-                 geom->ImpactOnEmc(photon1->Theta(),photon1->Phi(), m,z,x);
+                 geom->ImpactOnEmc(vtx,photon1->Theta(),photon1->Phi(), m,z,x);
                  if( photon1->Phi()>fPhiEMCALCut[0] && photon1->Phi()<fPhiEMCALCut[1]
                      && m == 0){
                    if(strstr(fOptionGJ,"deb all") || strstr(fOptionGJ,"deb"))
@@ -481,7 +507,7 @@ void AliPHOSGammaJet::AddHIJINGToList(Int_t iEvent, TClonesArray * particleList,
                  TParticle * photon2 =
                    new TParticle(22,1,0,0,0,0,pGamma2.Px(), pGamma2.Py(),
                                  pGamma2.Pz(),pGamma2.E(),0,0,0,0);
-                 geom->ImpactOnEmc(photon2->Theta(),photon2->Phi(), m,z,x);
+                 geom->ImpactOnEmc(vtx,photon2->Theta(),photon2->Phi(), m,z,x);
                  if(photon2->Phi()>fPhiEMCALCut[0] && 
                     photon2->Phi()<fPhiEMCALCut[1] && m == 0){
                    if(strstr(fOptionGJ,"deb all") || strstr(fOptionGJ,"deb"))
@@ -543,13 +569,16 @@ void AliPHOSGammaJet::CreateParticleList(Int_t iEvent,
                                         TClonesArray * particleList, 
                                         TClonesArray * plCh, 
                                         TClonesArray * plNe,  
-                                        TClonesArray * plNePHOS,
-                                        const AliPHOSGeometry * geom )
+                                        TClonesArray * plNePHOS)
 {
   //Info("CreateParticleList","Inside");
-  AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileName) ; 
+  AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileName) ;
+  const AliPHOSGeometry * geom = gime->PHOSGeometry() ; 
   gime->Event(iEvent, "X") ;
 
+  //DP to be fixed: extract true vertex here
+  Double_t vtx[3]={0.,0.,0.} ;
+
   Int_t index = particleList->GetEntries() ; 
   Int_t indexCh     = plCh->GetEntries() ;
   Int_t indexNe     = plNe->GetEntries() ;
@@ -584,7 +613,7 @@ void AliPHOSGammaJet::CreateParticleList(Int_t iEvent,
            new((*particleList)[index++]) TParticle(*particle) ;
          }
          else if((charge == 0) && (particle->Pt() > fNeutralPtCut)){
-           geom->ImpactOnEmc(particle->Theta(),particle->Phi(), m,z,x);
+           geom->ImpactOnEmc(vtx,particle->Theta(),particle->Phi(), m,z,x);
            if(m != 0)
              {//Is in PHOS
                if(strstr(fOptionGJ,"deb all")|| strstr(fOptionGJ,"deb"))
@@ -633,7 +662,7 @@ void AliPHOSGammaJet::CreateParticleList(Int_t iEvent,
            new((*particleList)[index++]) TParticle(*particle) ;
          }
          else if(charge == 0) {
-           geom->ImpactOnEmc(particle->Theta(),particle->Phi(), m,z,x);
+           geom->ImpactOnEmc(vtx,particle->Theta(),particle->Phi(), m,z,x);
            if((particle->GetPdgCode() != 111) && particle->Pt() > 0 &&
               (TMath::Abs(particle->Eta())<fEtaCut))
            {                
@@ -729,7 +758,7 @@ void AliPHOSGammaJet::CreateParticleList(Int_t iEvent,
                      TParticle * photon1 = 
                        new TParticle(22,1,0,0,0,0,pGamma1.Px(),pGamma1.Py(),
                                      pGamma1.Pz(),pGamma1.E(),0,0,0,0);
-                     geom->ImpactOnEmc(photon1->Theta(),photon1->Phi(), m,z,x);
+                     geom->ImpactOnEmc(vtx,photon1->Theta(),photon1->Phi(), m,z,x);
                      if( photon1->Phi()>fPhiEMCALCut[0] && photon1->Phi()<fPhiEMCALCut[1]
                          && m == 0){
                      if(strstr(fOptionGJ,"deb all") || strstr(fOptionGJ,"deb"))
@@ -756,7 +785,7 @@ void AliPHOSGammaJet::CreateParticleList(Int_t iEvent,
                      TParticle * photon2 =
                        new TParticle(22,1,0,0,0,0,pGamma2.Px(), pGamma2.Py(),
                                      pGamma2.Pz(),pGamma2.E(),0,0,0,0);
-                     geom->ImpactOnEmc(photon2->Theta(),photon2->Phi(), m,z,x);
+                     geom->ImpactOnEmc(vtx,photon2->Theta(),photon2->Phi(), m,z,x);
                      if(photon2->Phi()>fPhiEMCALCut[0] && 
                         photon2->Phi()<fPhiEMCALCut[1] && m == 0){
                        if(strstr(fOptionGJ,"deb all") || strstr(fOptionGJ,"deb"))
@@ -789,6 +818,135 @@ void AliPHOSGammaJet::CreateParticleList(Int_t iEvent,
     }//OptFast
   //gime->Delete() ; 
 }
+//____________________________________________________________________________
+void AliPHOSGammaJet::CreateParticleListFromESD(TClonesArray * pl, 
+                                               TClonesArray * plCh, 
+                                               TClonesArray * plNe,  
+                                               TClonesArray * plNePHOS,
+                                               const AliESD * esd){
+  
+  //Create a list of particles from the ESD. These particles have been measured 
+  //by the Central Tracking system (TPC), PHOS and EMCAL 
+  //(EMCAL not available for the moment). 
+  //Info("CreateParticleListFromESD","Inside");
+
+  Int_t index = pl->GetEntries() ; 
+  Int_t npar  = 0 ;
+  Float_t *pid = new Float_t[AliPID::kSPECIESN];  
+
+  //########### PHOS ##############
+  //Info("CreateParticleListFromESD","Fill ESD PHOS list");
+  Int_t begphos = esd->GetFirstPHOSCluster();  
+  Int_t endphos = esd->GetFirstPHOSCluster() + 
+    esd->GetNumberOfPHOSClusters() ;  
+  Int_t indexNePHOS = plNePHOS->GetEntries() ;
+  if(strstr(fOptionGJ,"deb all"))
+    Info("CreateParticleListFromESD","PHOS: first particle %d, last particle %d",
+        begphos,endphos);
+
+  for (npar =  begphos; npar <  endphos; npar++) {//////////////PHOS track loop
+      AliESDCaloCluster * clus = esd->GetCaloCluster(npar) ; // retrieve track from esd
+   
+    //Create a TParticle to fill the particle list
+
+    Float_t en = clus->GetClusterEnergy() ;
+    Float_t *p = new Float_t();
+    clus->GetGlobalPosition(p) ;
+    TVector3 pos(p[0],p[1],p[2]) ; 
+    Double_t phi  = pos.Phi();
+    Double_t theta= pos.Theta();
+    Double_t px = en*TMath::Cos(phi)*TMath::Sin(theta);;
+    Double_t py = en*TMath::Sin(phi)*TMath::Sin(theta);
+    Double_t pz = en*TMath::Cos(theta);
+
+    TParticle * particle = new TParticle() ;
+    particle->SetMomentum(px,py,pz,en) ;
+
+    //Select only photons
+    
+    pid=clus->GetPid();
+    //cout<<"pid "<<pid[AliPID::kPhoton]<<endl ;
+    if( pid[AliPID::kPhoton] > 0.75)
+      new((*plNePHOS)[indexNePHOS++])   TParticle(*particle) ;
+  }
+
+  //########### TPC #####################
+  //Info("CreateParticleListFromESD","Fill ESD TPC list");
+  Int_t begtpc = 0 ;  
+  Int_t endtpc = esd->GetNumberOfTracks() ;
+  Int_t indexCh     = plCh->GetEntries() ;
+  if(strstr(fOptionGJ,"deb all"))
+    Info("CreateParticleListFromESD","TPC: first particle %d, last particle %d",
+        begtpc,endtpc);
+
+  for (npar =  begtpc; npar <  endtpc; npar++) {////////////// track loop
+    AliESDtrack * track = esd->GetTrack(npar) ; // retrieve track from esd
+    
+    Double_t en = track ->GetTPCsignal() ;
+    Double_t mom[3];
+    track->GetPxPyPz(mom) ;
+    Double_t px = mom[0];
+    Double_t py = mom[1];
+    Double_t pz = mom[2]; //Check with TPC people if this is correct.
+
+    //cout<<"TPC signal "<<en<<endl;
+    //cout<<"px "<<px<<"; py "<<py<<"; pz "<<pz<<endl;
+    TParticle * particle = new TParticle() ;
+    particle->SetMomentum(px,py,pz,en) ;
+
+    new((*plCh)[indexCh++])       TParticle(*particle) ;    
+    new((*pl)[index++])           TParticle(*particle) ;
+
+  }
+
+  //################ EMCAL ##############
+  Double_t v[3] ; //vertex ;
+  esd->GetVertex()->GetXYZ(v) ; 
+  //##########Uncomment when ESD for EMCAL works ##########  
+  //Info("CreateParticleListFromESD","Fill ESD EMCAL list");
+  Int_t begem = esd->GetFirstEMCALCluster();  
+  Int_t endem = esd->GetFirstEMCALCluster() + 
+    esd->GetNumberOfEMCALClusters() ;  
+  Int_t indexNe  = plNe->GetEntries() ; 
+  if(strstr(fOptionGJ,"deb all"))
+    Info("CreateParticleListFromESD","EMCAL: first particle %d, last particle %d",
+        begem,endem);
+   
+  for (npar =  begem; npar <  endem; npar++) {//////////////EMCAL track loop
+     AliESDCaloCluster * clus = esd->GetCaloCluster(npar) ; // retrieve track from esd
+  
+    Float_t en = clus->GetClusterEnergy() ;
+    Float_t *p = new Float_t();
+    clus->GetGlobalPosition(p) ;
+    TVector3 pos(p[0],p[1],p[2]) ;
+    Double_t phi  = pos.Phi();
+    Double_t theta= pos.Theta();
+    Double_t px = en*TMath::Cos(phi)*TMath::Sin(theta);;
+    Double_t py = en*TMath::Sin(phi)*TMath::Sin(theta);
+    Double_t pz = en*TMath::Cos(theta);
+    //cout<<"EMCAL signal "<<en<<endl;
+    //cout<<"px "<<px<<"; py "<<py<<"; pz "<<pz<<endl;
+    //TParticle * particle = new TParticle() ;
+    //particle->SetMomentum(px,py,pz,en) ;
+  
+    Int_t pdg = 0;
+    //  //Uncomment if PID IS WORKING, photon and pi0 idenitification.
+    //  //if( pid[AliPID::kPhoton] > 0.75) //This has to be fixen.
+    //  //pdg = 22;
+    //  //else if( pid[AliPID::kPi0] > 0.75)
+    //  //pdg = 111;
+    pdg = 22; //No PID, assume all photons
+    TParticle * particle = new TParticle(pdg, 1, -1, -1, -1, -1, 
+                                        px, py, pz, en, v[0], v[1], v[2], 0);
+
+    new((*plNe)[indexNe++])       TParticle(*particle) ; 
+    new((*pl)[index++])           TParticle(*particle) ;
+  }
+  
+  //  Info("CreateParticleListFromESD","End Inside");
+  
+}
 
 
 
@@ -798,10 +956,24 @@ void AliPHOSGammaJet::Exec(Option_t *option)
   // does the job
   fOptionGJ = option;
   MakeHistos() ; 
+  
+  AliESD * esd = 0;
+  TChain * t = 0 ;
+
+  if(fESDdata){
+    // Create chain of esd trees
+    const UInt_t kNevent = static_cast<UInt_t>(GetNEvent()) ; 
+    t = ReadESD(kNevent, fDirName, fESDTree, fPattern) ; 
+    if(!t) {
+      AliError("Could not create the TChain") ; 
+      //break ;
+    }
+    
+    // ESD  
+    t->SetBranchAddress("ESD",&esd); // point to the container esd where to put the event from the esdTree  
 
-  AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
-  const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
-
+  }
 
 //   AliGenPythia* pyth = (AliGenPythia*) gAlice->Generator();
 //   pyth->Init();
@@ -823,41 +995,52 @@ void AliPHOSGammaJet::Exec(Option_t *option)
  
     TLorentzVector jet   (0,0,0,0);
     TLorentzVector jettpc(0,0,0,0);
-    
-    CreateParticleList(iEvent, particleList, plCh,plNe,plNePHOS, geom ); 
 
-//    TLorentzVector pyjet(0,0,0,0);
+    if(fESDdata){
 
-//     Int_t nJ, nJT;
-//     Float_t jets[4][10];
-//     pyth->SetJetReconstructionMode(1);
-//     pyth->LoadEvent();
-//     pyth->GetJets(nJ, nJT, jets);
-    
-//     Float_t pxJ = jets[0][0];
-//     Float_t pyJ = jets[1][0];
-//     Float_t pzJ = jets[2][0];
-//     Float_t eJ  = jets[3][0];
-//     pyjet.SetPxPyPzE(pxJ,pyJ,pzJ,eJ ) ;
-    
-//     if(nJT > 1){
-//       //Info("Exec",">>>>>>>>>>Number of jets !!!!   %d",nJT);
-//       for (Int_t iJ = 1; iJ < nJT; iJ++) {
-//     Float_t pxJ = jets[0][iJ];
-//     Float_t pyJ = jets[1][iJ];
-//     Float_t pzJ = jets[2][iJ];
-//     Float_t eJ  = jets[3][iJ];
-//     pyjet.SetPxPyPzE(pxJ,pyJ,pzJ,eJ ) ;
-//     //Info("Exec",">>>>>Pythia Jet: %d, Phi %f, Eta %f, Pt %f",
-//     //           iJ,pyjet.Phi(),pyjet.Eta(),pyjet.Pt());
-//       }
+      Int_t iNbytes = t->GetEntry(iEvent); // store event in esd
+      //cout<<"nbytes "<<iNbytes<<endl;
+      if ( iNbytes == 0 ) {
+       AliError("Empty TChain") ; 
+       break ;
+      }      
+      CreateParticleListFromESD(particleList, plCh,plNe,plNePHOS, esd); //,iEvent);
+    }
+    else{   
+      CreateParticleList(iEvent, particleList, plCh,plNe,plNePHOS); 
+      
+      //    TLorentzVector pyjet(0,0,0,0);
+      
+      //     Int_t nJ, nJT;
+      //     Float_t jets[4][10];
+      //     pyth->SetJetReconstructionMode(1);
+      //     pyth->LoadEvent();
+      //     pyth->GetJets(nJ, nJT, jets);
+      
+      //     Float_t pxJ = jets[0][0];
+      //     Float_t pyJ = jets[1][0];
+      //     Float_t pzJ = jets[2][0];
+      //     Float_t eJ  = jets[3][0];
+      //     pyjet.SetPxPyPzE(pxJ,pyJ,pzJ,eJ ) ;
+      
+      //     if(nJT > 1){
+      //       //Info("Exec",">>>>>>>>>>Number of jets !!!!   %d",nJT);
+      //       for (Int_t iJ = 1; iJ < nJT; iJ++) {
+      //       Float_t pxJ = jets[0][iJ];
+      //       Float_t pyJ = jets[1][iJ];
+      //       Float_t pzJ = jets[2][iJ];
+      //       Float_t eJ  = jets[3][iJ];
+      //       pyjet.SetPxPyPzE(pxJ,pyJ,pzJ,eJ ) ;
+      //       //Info("Exec",">>>>>Pythia Jet: %d, Phi %f, Eta %f, Pt %f",
+      //       //           iJ,pyjet.Phi(),pyjet.Eta(),pyjet.Pt());
+      //       }
       
-//     }
+      //     }
+      
+      if(fHIJING)
+       AddHIJINGToList(iEvent, particleList, plCh,plNe, plNePHOS);
+    }
     
-    if(fHIJING)
-      AddHIJINGToList(iEvent, particleList, plCh,plNe, plNePHOS, geom);
-
-
     Bool_t iIsInPHOS = kFALSE ;
     GetGammaJet(plNePHOS, ptg, phig, etag, iIsInPHOS) ; 
 
@@ -1082,15 +1265,12 @@ void AliPHOSGammaJet::GetGammaJet(TClonesArray * pl, Double_t &pt,
   for(Int_t ipr = 0;ipr < pl->GetEntries() ; ipr ++ ){
     TParticle * particle = dynamic_cast<TParticle *>(pl->At(ipr)) ;
 
-    if( (particle->Pt() > fPtCut ) && ( particle->GetStatusCode() == 1) 
-       && ( particle->GetPdgCode() == 22 || particle->GetPdgCode() == 111) ){
-       
-      if (particle->Pt() > pt) {
-       pt  = particle->Pt();          
-       phi = particle->Phi() ;
-       eta = particle->Eta() ;
-       Is  = kTRUE;
-      }
+    if((particle->Pt() > fPtCut) && (particle->Pt() > pt)){
+
+      pt  = particle->Pt();          
+      phi = particle->Phi() ;
+      eta = particle->Eta() ;
+      Is  = kTRUE;
     }
   }
 }
@@ -1213,8 +1393,7 @@ void  AliPHOSGammaJet::GetLeadingPi0(TClonesArray * pl,
 
     while ( (particle = (TParticle*)next()) ) {
       iPrimary++;        
-      //     if(particle->GetStatusCode() == 1){
-
+    
       ksPdg = particle->GetPdgCode();
       ptl  = particle->Pt();
       if(ksPdg == 111){ //2 gamma
@@ -1337,6 +1516,7 @@ void AliPHOSGammaJet::InitParameters()
   fInvMassMinCut  = 0.12 ;
   fOnlyCharged    = kFALSE ;
   fOptFast        = kFALSE ;
+  fESDdata        = kTRUE ;
   fPhiEMCALCut[0] = 60. *TMath::Pi()/180.;
   fPhiEMCALCut[1] = 180.*TMath::Pi()/180.;
   fPhiMaxCut      = 3.4 ;
@@ -1355,6 +1535,10 @@ void AliPHOSGammaJet::InitParameters()
   fJetTPCRatioMinCut = 0.3 ;
   fSelect         = kFALSE  ;
 
+  fDirName      = "./" ;
+  fESDTree      = "esdTree" ;
+  fPattern      = "." ;
+
   //Cut depending on gamma energy
 
   fPtJetSelectionCut = 20.; //For Low pt jets+BKG, another limits applyed
@@ -2537,7 +2721,7 @@ void AliPHOSGammaJet::Plot(TString what, Option_t * option) const
 }
 
 //____________________________________________________________________________
-void AliPHOSGammaJet::Print(char * opt) 
+void AliPHOSGammaJet::Print(const Option_t * opt) const
 {
 
   //Print some relevant parameters set for the analysis
@@ -2561,6 +2745,67 @@ void AliPHOSGammaJet::Print(char * opt)
  
 } 
 
+//__________________________________________________________________________
+TChain * AliPHOSGammaJet::ReadESDfromdisk(const UInt_t eventsToRead, 
+                        const TString dirName, 
+                        const TString esdTreeName, 
+                        const char *  pattern) 
+{
+  // Reads ESDs from Disk
+ TChain *  rv = 0; 
+
+  AliInfo( Form("\nReading files in %s \nESD tree name is %s \nReading %d events", 
+               dirName.Data(), esdTreeName.Data(), eventsToRead) ) ;
+  
+  // create a TChain of all the files 
+  TChain * cESDTree = new TChain(esdTreeName) ; 
+
+  // read from the directory file until the require number of events are collected
+  void * from = gSystem->OpenDirectory(dirName) ;
+  if (!from) {
+    AliError( Form("Directory %s does not exist") ) ;
+    rv = 0 ;
+  }
+  else{ // reading file names from directory
+    const char * subdir ; 
+    // search all subdirectories witch matching pattern
+    while( (subdir = gSystem->GetDirEntry(from))  && 
+          (cESDTree->GetEntries() < eventsToRead)) {
+      if ( strstr(subdir, pattern) != 0 ) { 
+       char file[200] ; 
+        sprintf(file, "%s%s/AliESDs.root", dirName.Data(), subdir);    
+       AliInfo( Form("Adding %s\n", file) );
+       cESDTree->Add(file) ;
+      }
+    } // while file
+  
+    AliInfo( Form(" %d events read", cESDTree->GetEntriesFast()) ) ;
+    rv = cESDTree ; 
+    
+  } // reading file names from directory
+  return rv ; 
+}
+
+//__________________________________________________________________________
+TChain * AliPHOSGammaJet::ReadESD(const UInt_t eventsToRead,
+                 const TString dirName, 
+                 const TString esdTreeName, 
+                 const char *  pattern)  
+{
+  // Read AliESDs files and return a Chain of events
+  if ( dirName == "" ) {
+    AliError("Give the name of the DIR where to find files") ; 
+    return 0 ; 
+  }
+  if ( esdTreeName == "" ) 
+    return ReadESDfromdisk(eventsToRead, dirName) ;
+  else if ( strcmp(pattern, "") == 0 )
+    return ReadESDfromdisk(eventsToRead, dirName, esdTreeName) ;
+  else 
+    return ReadESDfromdisk(eventsToRead, dirName, esdTreeName, pattern) ;          
+}
+
 //___________________________________________________________________
 void AliPHOSGammaJet::SetJet(TParticle * part, Bool_t & b, Float_t cone, 
                             Double_t eta, Double_t phi)