ROOT logo
#if !defined(__CINT__) || defined(__MAKECINT__)

//Root include files 
#include <Riostream.h>
#include <TFile.h>
#include <TChain.h>
#include <TParticle.h>
#include <TNtuple.h>
#include <TCanvas.h>
#include <TObjArray.h>
#include <TSystem.h>
#include <TString.h>
#include <TH1F.h>
#include <TVector.h>
#include <TParticle.h>
#include <TRefArray.h>
#include <TArrayS.h>

//AliRoot include files 
#include "AliRunLoader.h"
#include "AliStack.h"
#include "AliAODEvent.h"
#include "AliAODVertex.h"
#include "AliAODCaloCluster.h"
#include "AliAODCaloCells.h"
#include "AliPID.h"
#include "AliLog.h"

#endif

Bool_t kPrintCaloCells    = kTRUE;
Bool_t kPrintCaloClusters = kTRUE;


void TestAOD() {

  TFile* f = new TFile("AliAOD.root");
  TTree* aodTree = (TTree*)f->Get("aodTree");
  
  AliAODEvent* aod = new AliAODEvent();
  aod->ReadFromTree(aodTree);

  Int_t nEvt = aodTree->GetEntries();

  for(Int_t iev = 0; iev < nEvt; iev++) {
    cout << "Event: " << iev+1 << "/" << nEvt << endl;
    aodTree->GetEvent(iev);

    //get reconstructed vertex position
    Double_t vertex_position[3] = { aod->GetPrimaryVertex()->GetX(),
				    aod->GetPrimaryVertex()->GetY(),
				    aod->GetPrimaryVertex()->GetZ()};

    //------------------------------------------------------
    // Clusters loop
    //------------------------------------------------------
    if(kPrintCaloClusters)
    {  
      TRefArray* caloClusters = new TRefArray();
      aod->GetEMCALClusters(caloClusters);

      Int_t nclus = caloClusters->GetEntries();
      for (Int_t icl = 0; icl < nclus; icl++) 
      {
        
        AliAODCaloCluster* clus = (AliAODCaloCluster*)caloClusters->At(icl);
        Float_t energy = clus->E();
        Float_t time   = clus->GetTOF()*1.e9;
        TLorentzVector p;
        clus->GetMomentum(p,vertex_position);
        Int_t nMatched = clus->GetNTracksMatched();
        
        cout << "Cluster: " << icl+1 << "/" << nclus << " - Energy: " << energy << "; Time "<<time
             <<"; Phi: " << p.Phi() << "; Eta: " << p.Eta() << "; #Matches: " << nMatched << endl;
        
      }
    }
    
    //------------------------------------------------------
    // Cells loop
    //------------------------------------------------------ 
    
    if(kPrintCaloCells)
    {  
      AliVCaloCells &cells= *(aod->GetEMCALCells());
      
      Int_t nTotalCells = cells.GetNumberOfCells() ;  
      //Int_t type        = cells.GetType();
      for (Int_t icell=  0; icell <  nTotalCells; icell++) {
        cout<<"Cell   : "<<icell<<"/"<<nTotalCells<<" - ID: "<<cells.GetCellNumber(icell)<<"; Amplitude: "<<cells.GetAmplitude(icell)<<"; Time: "<<cells.GetTime(icell)*1e9;
        cout << "; MC label "<<cells.GetMCLabel(icell)<<"; Embeded E fraction "<<cells.GetEFraction(icell);
        cout<<endl;	  
      }// cell loop
    }
    

  }



}
 TestAOD.C:1
 TestAOD.C:2
 TestAOD.C:3
 TestAOD.C:4
 TestAOD.C:5
 TestAOD.C:6
 TestAOD.C:7
 TestAOD.C:8
 TestAOD.C:9
 TestAOD.C:10
 TestAOD.C:11
 TestAOD.C:12
 TestAOD.C:13
 TestAOD.C:14
 TestAOD.C:15
 TestAOD.C:16
 TestAOD.C:17
 TestAOD.C:18
 TestAOD.C:19
 TestAOD.C:20
 TestAOD.C:21
 TestAOD.C:22
 TestAOD.C:23
 TestAOD.C:24
 TestAOD.C:25
 TestAOD.C:26
 TestAOD.C:27
 TestAOD.C:28
 TestAOD.C:29
 TestAOD.C:30
 TestAOD.C:31
 TestAOD.C:32
 TestAOD.C:33
 TestAOD.C:34
 TestAOD.C:35
 TestAOD.C:36
 TestAOD.C:37
 TestAOD.C:38
 TestAOD.C:39
 TestAOD.C:40
 TestAOD.C:41
 TestAOD.C:42
 TestAOD.C:43
 TestAOD.C:44
 TestAOD.C:45
 TestAOD.C:46
 TestAOD.C:47
 TestAOD.C:48
 TestAOD.C:49
 TestAOD.C:50
 TestAOD.C:51
 TestAOD.C:52
 TestAOD.C:53
 TestAOD.C:54
 TestAOD.C:55
 TestAOD.C:56
 TestAOD.C:57
 TestAOD.C:58
 TestAOD.C:59
 TestAOD.C:60
 TestAOD.C:61
 TestAOD.C:62
 TestAOD.C:63
 TestAOD.C:64
 TestAOD.C:65
 TestAOD.C:66
 TestAOD.C:67
 TestAOD.C:68
 TestAOD.C:69
 TestAOD.C:70
 TestAOD.C:71
 TestAOD.C:72
 TestAOD.C:73
 TestAOD.C:74
 TestAOD.C:75
 TestAOD.C:76
 TestAOD.C:77
 TestAOD.C:78
 TestAOD.C:79
 TestAOD.C:80
 TestAOD.C:81
 TestAOD.C:82
 TestAOD.C:83
 TestAOD.C:84
 TestAOD.C:85
 TestAOD.C:86
 TestAOD.C:87
 TestAOD.C:88
 TestAOD.C:89
 TestAOD.C:90
 TestAOD.C:91
 TestAOD.C:92
 TestAOD.C:93
 TestAOD.C:94
 TestAOD.C:95
 TestAOD.C:96
 TestAOD.C:97
 TestAOD.C:98
 TestAOD.C:99
 TestAOD.C:100
 TestAOD.C:101
 TestAOD.C:102