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> 

//AliRoot include files
#include "AliESD.h"
#include "AliESDEvent.h"
#include "AliEMCALLoader.h"
#include "AliESDCaloCluster.h"
#include "AliEMCALRecPoint.h"
#include "AliPID.h"
#include "AliLog.h" 

//macros

#endif

TChain * AliReadESDfromdisk(const UInt_t eventsToRead, 
				   const TString dirName, 
				   const TString esdTreeName, 
				   const char *  pattern) 
{
  // Reads ESDs from Disk
 TChain *  rv = 0; 
  
  // 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) 
     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); 	
	cESDTree->Add(file) ;
      }
    } // while file
  
    rv = cESDTree ; 
    
  } // reading file names from directory
  return rv ; 
}

//======================================================================
TChain * AliReadESD(const UInt_t eventsToRead,
		  const TString dirName, 
		  const TString esdTreeName, 
		  const char *  pattern)  
{
  // Read AliESDs files and return a Chain of events
 
  if ( dirName == "" ) 
    return 0 ; 
  if ( esdTreeName == "" ) 
    return AliReadESDfromdisk(eventsToRead, dirName,"","") ;//Last 2 arguments are not necessary but pdsf compiler complains "","'
  else if ( strcmp(pattern, "") == 0 )
    return AliReadESDfromdisk(eventsToRead, dirName, esdTreeName,"") ;//Last argument is not necessary but pdsf compiler complains "","'
  else 
    return AliReadESDfromdisk(eventsToRead, dirName, esdTreeName, pattern) ;	    
}

//=====================================================================
//  Do:
//  .L TestESDCaloCluster.C++
//  TestESDCaloCluster(number of events to process)
//=====================================================================
void TestESDCaloCluster(const UInt_t eventsToProcess = 5, 
			TString dirName = "./", 
			const TString esdTreeName = "esdTree", 
			const char *  pattern = ".") 
{ 
  
  //Create chain of esd trees
  //AliReadESD(eventsToProcess, directoryName,esdTreeName,patternOfDirectory) ;
  //By default the root files are in the same directory 
  TChain * t = AliReadESD(eventsToProcess, dirName,esdTreeName,pattern) ; 
 
  
  // ESD
  AliESDEvent * esd = new AliESDEvent();
  esd->ReadFromTree(t);
  
  //Define few variables to be used in macro
  TString alirunName = "" ; 

  //Define example histograms
  TH1F * hEnergy = new TH1F("hEnergy","Energy Distribution",100,0.,100.);   
  TH1F * hEta    = new TH1F("hEta","Eta Distribution",100,-0.7,0.7);
  TH1F * hPhi    = new TH1F("hPhi","Phi Distribution",100,0,2*TMath::Pi());

  Int_t beg, end ;
  UInt_t event ;
  Float_t pos[3] ; 

  for (event = 0; event < eventsToProcess; event++) {//event loop
    //AliInfo( Form("Event %d \n",event) );  
    Int_t nbytes = t->GetEntry(event); // store event in esd
    //cout<<"nbytes "<<nbytes<<endl;
    if ( nbytes == 0 ) //If nothing in ESD 
      break ; 
    
    // Check that name of file is correct
    if (alirunName != t->GetFile()->GetName()) {        
      alirunName = t->GetFile()->GetName() ; 
      alirunName.ReplaceAll("galice.root", "AliESDs.root") ;
    }
    
    //get reconstructed vertex position 
    
    //Double_t vertex_position[3] ; 
    //    esd->GetVertex()->GetXYZ(vertex_position) ; 
    
    cout<<"Event >>>>>>>>>>> "<<event<<endl;
    

    //select EMCAL tracks only 
    end = esd->GetNumberOfCaloClusters() ;  
    beg = 0;
    Int_t nphP ;
    //cout<<"begin "<<beg<<" end "<<end<<endl;
    Int_t iclus = 0;
    for (nphP =  beg; nphP <  end; nphP++) {//////////////EMCAL cluster loop
      AliESDCaloCluster * clus = esd->GetCaloCluster(nphP) ; // retrieve cluster from esd
      
      //Get the cluster parameters
      Float_t energy   = clus->E() ;
      cout << "Cluster " << nphP << " energy = " << energy << endl;

	//	Int_t mult       = clus->GetNumberOfDigits() ;
	//	Float_t disp     = clus->GetClusterDisp() ;
	// 	UShort_t * amp   = clus->GetDigitAmplitude() ;
	// 	UShort_t * time  = clus->GetDigitTime() ;
	// 	UShort_t * index = clus->GetDigitIndex() ;
	//	Int_t iprim = clus->GetPrimaryIndex();

      /*
      clus->GetPosition(pos) ;
      TVector3 vpos(pos[0],pos[1],pos[2]) ;
      //Print values on screen
      cout<<"ESD cluster "<<iclus <<"; Energy "<<energy
	  <<"; Phi "<<vpos.Phi()*180/TMath::Pi()<<"; Eta "<<vpos.Eta()<<endl;
      //cout<<"Dispersion "<<disp<<"; multiplicity "<<mult<<endl;
      //Get the parent main values
      */
      //Fill histograms
      hEnergy->Fill(energy) ;
      //      hEta->Fill(vpos.Eta()) ;
      //hPhi->Fill(vpos.Phi()) ;

    }// track loop 
  }//////////////////////////////////////////event loop
  hEnergy->Draw();//Draw histogram on screen
  //Write histograms in Root file 
  TFile outf("histo.root","recreate") ;
  hEnergy->Write() ;
  hPhi->Write() ;
  hEta->Write() ;
  outf.Close() ;
}


 TestESDCaloCluster.C:1
 TestESDCaloCluster.C:2
 TestESDCaloCluster.C:3
 TestESDCaloCluster.C:4
 TestESDCaloCluster.C:5
 TestESDCaloCluster.C:6
 TestESDCaloCluster.C:7
 TestESDCaloCluster.C:8
 TestESDCaloCluster.C:9
 TestESDCaloCluster.C:10
 TestESDCaloCluster.C:11
 TestESDCaloCluster.C:12
 TestESDCaloCluster.C:13
 TestESDCaloCluster.C:14
 TestESDCaloCluster.C:15
 TestESDCaloCluster.C:16
 TestESDCaloCluster.C:17
 TestESDCaloCluster.C:18
 TestESDCaloCluster.C:19
 TestESDCaloCluster.C:20
 TestESDCaloCluster.C:21
 TestESDCaloCluster.C:22
 TestESDCaloCluster.C:23
 TestESDCaloCluster.C:24
 TestESDCaloCluster.C:25
 TestESDCaloCluster.C:26
 TestESDCaloCluster.C:27
 TestESDCaloCluster.C:28
 TestESDCaloCluster.C:29
 TestESDCaloCluster.C:30
 TestESDCaloCluster.C:31
 TestESDCaloCluster.C:32
 TestESDCaloCluster.C:33
 TestESDCaloCluster.C:34
 TestESDCaloCluster.C:35
 TestESDCaloCluster.C:36
 TestESDCaloCluster.C:37
 TestESDCaloCluster.C:38
 TestESDCaloCluster.C:39
 TestESDCaloCluster.C:40
 TestESDCaloCluster.C:41
 TestESDCaloCluster.C:42
 TestESDCaloCluster.C:43
 TestESDCaloCluster.C:44
 TestESDCaloCluster.C:45
 TestESDCaloCluster.C:46
 TestESDCaloCluster.C:47
 TestESDCaloCluster.C:48
 TestESDCaloCluster.C:49
 TestESDCaloCluster.C:50
 TestESDCaloCluster.C:51
 TestESDCaloCluster.C:52
 TestESDCaloCluster.C:53
 TestESDCaloCluster.C:54
 TestESDCaloCluster.C:55
 TestESDCaloCluster.C:56
 TestESDCaloCluster.C:57
 TestESDCaloCluster.C:58
 TestESDCaloCluster.C:59
 TestESDCaloCluster.C:60
 TestESDCaloCluster.C:61
 TestESDCaloCluster.C:62
 TestESDCaloCluster.C:63
 TestESDCaloCluster.C:64
 TestESDCaloCluster.C:65
 TestESDCaloCluster.C:66
 TestESDCaloCluster.C:67
 TestESDCaloCluster.C:68
 TestESDCaloCluster.C:69
 TestESDCaloCluster.C:70
 TestESDCaloCluster.C:71
 TestESDCaloCluster.C:72
 TestESDCaloCluster.C:73
 TestESDCaloCluster.C:74
 TestESDCaloCluster.C:75
 TestESDCaloCluster.C:76
 TestESDCaloCluster.C:77
 TestESDCaloCluster.C:78
 TestESDCaloCluster.C:79
 TestESDCaloCluster.C:80
 TestESDCaloCluster.C:81
 TestESDCaloCluster.C:82
 TestESDCaloCluster.C:83
 TestESDCaloCluster.C:84
 TestESDCaloCluster.C:85
 TestESDCaloCluster.C:86
 TestESDCaloCluster.C:87
 TestESDCaloCluster.C:88
 TestESDCaloCluster.C:89
 TestESDCaloCluster.C:90
 TestESDCaloCluster.C:91
 TestESDCaloCluster.C:92
 TestESDCaloCluster.C:93
 TestESDCaloCluster.C:94
 TestESDCaloCluster.C:95
 TestESDCaloCluster.C:96
 TestESDCaloCluster.C:97
 TestESDCaloCluster.C:98
 TestESDCaloCluster.C:99
 TestESDCaloCluster.C:100
 TestESDCaloCluster.C:101
 TestESDCaloCluster.C:102
 TestESDCaloCluster.C:103
 TestESDCaloCluster.C:104
 TestESDCaloCluster.C:105
 TestESDCaloCluster.C:106
 TestESDCaloCluster.C:107
 TestESDCaloCluster.C:108
 TestESDCaloCluster.C:109
 TestESDCaloCluster.C:110
 TestESDCaloCluster.C:111
 TestESDCaloCluster.C:112
 TestESDCaloCluster.C:113
 TestESDCaloCluster.C:114
 TestESDCaloCluster.C:115
 TestESDCaloCluster.C:116
 TestESDCaloCluster.C:117
 TestESDCaloCluster.C:118
 TestESDCaloCluster.C:119
 TestESDCaloCluster.C:120
 TestESDCaloCluster.C:121
 TestESDCaloCluster.C:122
 TestESDCaloCluster.C:123
 TestESDCaloCluster.C:124
 TestESDCaloCluster.C:125
 TestESDCaloCluster.C:126
 TestESDCaloCluster.C:127
 TestESDCaloCluster.C:128
 TestESDCaloCluster.C:129
 TestESDCaloCluster.C:130
 TestESDCaloCluster.C:131
 TestESDCaloCluster.C:132
 TestESDCaloCluster.C:133
 TestESDCaloCluster.C:134
 TestESDCaloCluster.C:135
 TestESDCaloCluster.C:136
 TestESDCaloCluster.C:137
 TestESDCaloCluster.C:138
 TestESDCaloCluster.C:139
 TestESDCaloCluster.C:140
 TestESDCaloCluster.C:141
 TestESDCaloCluster.C:142
 TestESDCaloCluster.C:143
 TestESDCaloCluster.C:144
 TestESDCaloCluster.C:145
 TestESDCaloCluster.C:146
 TestESDCaloCluster.C:147
 TestESDCaloCluster.C:148
 TestESDCaloCluster.C:149
 TestESDCaloCluster.C:150
 TestESDCaloCluster.C:151
 TestESDCaloCluster.C:152
 TestESDCaloCluster.C:153
 TestESDCaloCluster.C:154
 TestESDCaloCluster.C:155
 TestESDCaloCluster.C:156
 TestESDCaloCluster.C:157
 TestESDCaloCluster.C:158
 TestESDCaloCluster.C:159
 TestESDCaloCluster.C:160
 TestESDCaloCluster.C:161
 TestESDCaloCluster.C:162
 TestESDCaloCluster.C:163
 TestESDCaloCluster.C:164
 TestESDCaloCluster.C:165
 TestESDCaloCluster.C:166
 TestESDCaloCluster.C:167
 TestESDCaloCluster.C:168
 TestESDCaloCluster.C:169
 TestESDCaloCluster.C:170
 TestESDCaloCluster.C:171
 TestESDCaloCluster.C:172
 TestESDCaloCluster.C:173
 TestESDCaloCluster.C:174
 TestESDCaloCluster.C:175
 TestESDCaloCluster.C:176
 TestESDCaloCluster.C:177
 TestESDCaloCluster.C:178
 TestESDCaloCluster.C:179
 TestESDCaloCluster.C:180
 TestESDCaloCluster.C:181