#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 "AliESDEvent.h"
#include "AliESDVertex.h"
#include "AliESDCaloCluster.h"
#include "AliESDCaloCells.h"
#include "AliPID.h"
#include "AliLog.h"
#endif
//example macro to extract information from AliESDCaloClusters and AliESDCaloCells.
// Author: Gustavo.Conesa.Balbastre@cern.ch (INFN-LNF)
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 TestESDCaloClusterAndCell.C++
// TestESDCaloClusterAndCell(calo, number of events to process)
//=====================================================================
void TestESDCaloClusterAndCell(TString det = "EMCAL", const UInt_t eventsToProcess = 5,
TString dirName = "./",
const TString esdTreeName = "esdTree",
const char * pattern = ".")
{
if(det !="EMCAL" && det !="PHOS" )
{
cout << "Wrong detector name "<<det<<endl;
return;
}
//Create chain of esd trees
//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); // This checks also if the branch address is already set
//Define few variables to be used in macro
TString alirunName = "" ;
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
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") ;
}
AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(), "read");
rl->LoadKinematics();
rl->GetEvent(event);
AliStack *sta=rl->Stack();
//get reconstructed vertex position
Double_t vertex_position[3] ;
esd->GetVertex()->GetXYZ(vertex_position) ;
//cout<<"Event >>>>>>>>>>> "<<event<<" vertex >>> "<<vertex_position[0]<<" "<<vertex_position[1]<<" "<<vertex_position[2]<<endl;
//Get CaloCells
AliESDCaloCells &cells= *(esd->GetEMCALCells());
if(det == "PHOS") AliESDCaloCells &cells = *(esd->GetPHOSCells());
Int_t ncell = cells.GetNumberOfCells() ;
Int_t type = cells.GetType();
cout<<">>> Event "<<event<<" ncells "<<ncell<< " type "<<type<<endl;
// Uncomment to see the full list of digit amplitudes and times.
// for (Int_t icell= 0; icell < ncell; icell++) {
// cout<<"icell "<<icell<<
// " ID "<<cells.GetCellNumber(icell)<<
// " amp "<<cells.GetAmplitude(icell)<<
// " time "<<cells.GetTime(icell)<<endl;
// }// cell loop
//Get the CaloClusters
//select EMCAL clusters only
TRefArray * caloClusters = new TRefArray();
if(det == "EMCAL") esd->GetEMCALClusters(caloClusters);
else if(det == "PHOS") esd->GetPHOSClusters(caloClusters);
Int_t nclus = caloClusters->GetEntries() ;
cout<<"Event: "<<event<<"; Number of clusters "<<nclus<<endl;
for (Int_t iclus = 0; iclus < nclus; iclus++) {//////////////EMCAL cluster loop
AliESDCaloCluster * clus = (AliESDCaloCluster *) caloClusters->At(iclus) ; // retrieve cluster from esd
//cout<<">>>> Cluster >>>"<<iclus<<endl;
//Get the cluster info
Float_t energy = clus->E() ;
//Float_t disp = clus->GetClusterDisp() ;
Int_t iprim = clus->GetLabel();
clus->GetPosition(pos) ;
TVector3 vpos(pos[0],pos[1],pos[2]) ;
TLorentzVector p ;
clus->GetMomentum(p,vertex_position);
Int_t mult = clus->GetNCells() ;
UShort_t * index = clus->GetCellsAbsId() ;
Double_t * fraction = clus->GetCellsAmplitudeFraction() ;
//Print cluster info
cout<<"Cluster "<<iclus <<"; digits mult "<<mult<<"; type "<<(Int_t )clus->GetClusterType()
<<"; Energy "<<energy
<<"; Phi "<<vpos.Phi()*180/TMath::Pi()<<"; Eta "<<vpos.Eta()
<<"; label "<<iprim<<endl;
//Print primary info
if(iprim>=0 && iprim < sta->GetNtrack()){
TParticle * particle = sta->Particle(clus->GetLabel());
//Print primary values
cout<<" Primary: "<<particle->GetName()<< "; Energy "<<particle->Energy()<<endl;
}
else if( iprim >= sta->GetNtrack()) cout <<"PROBLEM, label is too large : "<<iprim<<" >= particles in stack "<< sta->GetNtrack() <<endl;
else cout<<"Negative label!!! : "<<iprim<<endl;
//Get CaloCells of cluster and print
for(Int_t i = 0; i < mult ; i++){
Int_t absId = index[i]; // or clus->GetCellNumber(i) ;
Double_t ampFract = fraction[i];
Float_t amp = cells.GetCellAmplitude(absId) ;
Float_t time = cells.GetCellTime(absId);
cout<<"AbsID : "<< absId << "; Amplitude "<< amp << "; Fraction "<<ampFract<<"; Time " <<time<<endl;
}
}// clusters
}// event loop
}
TestESDCaloClusterAndCell.C:1 TestESDCaloClusterAndCell.C:2 TestESDCaloClusterAndCell.C:3 TestESDCaloClusterAndCell.C:4 TestESDCaloClusterAndCell.C:5 TestESDCaloClusterAndCell.C:6 TestESDCaloClusterAndCell.C:7 TestESDCaloClusterAndCell.C:8 TestESDCaloClusterAndCell.C:9 TestESDCaloClusterAndCell.C:10 TestESDCaloClusterAndCell.C:11 TestESDCaloClusterAndCell.C:12 TestESDCaloClusterAndCell.C:13 TestESDCaloClusterAndCell.C:14 TestESDCaloClusterAndCell.C:15 TestESDCaloClusterAndCell.C:16 TestESDCaloClusterAndCell.C:17 TestESDCaloClusterAndCell.C:18 TestESDCaloClusterAndCell.C:19 TestESDCaloClusterAndCell.C:20 TestESDCaloClusterAndCell.C:21 TestESDCaloClusterAndCell.C:22 TestESDCaloClusterAndCell.C:23 TestESDCaloClusterAndCell.C:24 TestESDCaloClusterAndCell.C:25 TestESDCaloClusterAndCell.C:26 TestESDCaloClusterAndCell.C:27 TestESDCaloClusterAndCell.C:28 TestESDCaloClusterAndCell.C:29 TestESDCaloClusterAndCell.C:30 TestESDCaloClusterAndCell.C:31 TestESDCaloClusterAndCell.C:32 TestESDCaloClusterAndCell.C:33 TestESDCaloClusterAndCell.C:34 TestESDCaloClusterAndCell.C:35 TestESDCaloClusterAndCell.C:36 TestESDCaloClusterAndCell.C:37 TestESDCaloClusterAndCell.C:38 TestESDCaloClusterAndCell.C:39 TestESDCaloClusterAndCell.C:40 TestESDCaloClusterAndCell.C:41 TestESDCaloClusterAndCell.C:42 TestESDCaloClusterAndCell.C:43 TestESDCaloClusterAndCell.C:44 TestESDCaloClusterAndCell.C:45 TestESDCaloClusterAndCell.C:46 TestESDCaloClusterAndCell.C:47 TestESDCaloClusterAndCell.C:48 TestESDCaloClusterAndCell.C:49 TestESDCaloClusterAndCell.C:50 TestESDCaloClusterAndCell.C:51 TestESDCaloClusterAndCell.C:52 TestESDCaloClusterAndCell.C:53 TestESDCaloClusterAndCell.C:54 TestESDCaloClusterAndCell.C:55 TestESDCaloClusterAndCell.C:56 TestESDCaloClusterAndCell.C:57 TestESDCaloClusterAndCell.C:58 TestESDCaloClusterAndCell.C:59 TestESDCaloClusterAndCell.C:60 TestESDCaloClusterAndCell.C:61 TestESDCaloClusterAndCell.C:62 TestESDCaloClusterAndCell.C:63 TestESDCaloClusterAndCell.C:64 TestESDCaloClusterAndCell.C:65 TestESDCaloClusterAndCell.C:66 TestESDCaloClusterAndCell.C:67 TestESDCaloClusterAndCell.C:68 TestESDCaloClusterAndCell.C:69 TestESDCaloClusterAndCell.C:70 TestESDCaloClusterAndCell.C:71 TestESDCaloClusterAndCell.C:72 TestESDCaloClusterAndCell.C:73 TestESDCaloClusterAndCell.C:74 TestESDCaloClusterAndCell.C:75 TestESDCaloClusterAndCell.C:76 TestESDCaloClusterAndCell.C:77 TestESDCaloClusterAndCell.C:78 TestESDCaloClusterAndCell.C:79 TestESDCaloClusterAndCell.C:80 TestESDCaloClusterAndCell.C:81 TestESDCaloClusterAndCell.C:82 TestESDCaloClusterAndCell.C:83 TestESDCaloClusterAndCell.C:84 TestESDCaloClusterAndCell.C:85 TestESDCaloClusterAndCell.C:86 TestESDCaloClusterAndCell.C:87 TestESDCaloClusterAndCell.C:88 TestESDCaloClusterAndCell.C:89 TestESDCaloClusterAndCell.C:90 TestESDCaloClusterAndCell.C:91 TestESDCaloClusterAndCell.C:92 TestESDCaloClusterAndCell.C:93 TestESDCaloClusterAndCell.C:94 TestESDCaloClusterAndCell.C:95 TestESDCaloClusterAndCell.C:96 TestESDCaloClusterAndCell.C:97 TestESDCaloClusterAndCell.C:98 TestESDCaloClusterAndCell.C:99 TestESDCaloClusterAndCell.C:100 TestESDCaloClusterAndCell.C:101 TestESDCaloClusterAndCell.C:102 TestESDCaloClusterAndCell.C:103 TestESDCaloClusterAndCell.C:104 TestESDCaloClusterAndCell.C:105 TestESDCaloClusterAndCell.C:106 TestESDCaloClusterAndCell.C:107 TestESDCaloClusterAndCell.C:108 TestESDCaloClusterAndCell.C:109 TestESDCaloClusterAndCell.C:110 TestESDCaloClusterAndCell.C:111 TestESDCaloClusterAndCell.C:112 TestESDCaloClusterAndCell.C:113 TestESDCaloClusterAndCell.C:114 TestESDCaloClusterAndCell.C:115 TestESDCaloClusterAndCell.C:116 TestESDCaloClusterAndCell.C:117 TestESDCaloClusterAndCell.C:118 TestESDCaloClusterAndCell.C:119 TestESDCaloClusterAndCell.C:120 TestESDCaloClusterAndCell.C:121 TestESDCaloClusterAndCell.C:122 TestESDCaloClusterAndCell.C:123 TestESDCaloClusterAndCell.C:124 TestESDCaloClusterAndCell.C:125 TestESDCaloClusterAndCell.C:126 TestESDCaloClusterAndCell.C:127 TestESDCaloClusterAndCell.C:128 TestESDCaloClusterAndCell.C:129 TestESDCaloClusterAndCell.C:130 TestESDCaloClusterAndCell.C:131 TestESDCaloClusterAndCell.C:132 TestESDCaloClusterAndCell.C:133 TestESDCaloClusterAndCell.C:134 TestESDCaloClusterAndCell.C:135 TestESDCaloClusterAndCell.C:136 TestESDCaloClusterAndCell.C:137 TestESDCaloClusterAndCell.C:138 TestESDCaloClusterAndCell.C:139 TestESDCaloClusterAndCell.C:140 TestESDCaloClusterAndCell.C:141 TestESDCaloClusterAndCell.C:142 TestESDCaloClusterAndCell.C:143 TestESDCaloClusterAndCell.C:144 TestESDCaloClusterAndCell.C:145 TestESDCaloClusterAndCell.C:146 TestESDCaloClusterAndCell.C:147 TestESDCaloClusterAndCell.C:148 TestESDCaloClusterAndCell.C:149 TestESDCaloClusterAndCell.C:150 TestESDCaloClusterAndCell.C:151 TestESDCaloClusterAndCell.C:152 TestESDCaloClusterAndCell.C:153 TestESDCaloClusterAndCell.C:154 TestESDCaloClusterAndCell.C:155 TestESDCaloClusterAndCell.C:156 TestESDCaloClusterAndCell.C:157 TestESDCaloClusterAndCell.C:158 TestESDCaloClusterAndCell.C:159 TestESDCaloClusterAndCell.C:160 TestESDCaloClusterAndCell.C:161 TestESDCaloClusterAndCell.C:162 TestESDCaloClusterAndCell.C:163 TestESDCaloClusterAndCell.C:164 TestESDCaloClusterAndCell.C:165 TestESDCaloClusterAndCell.C:166 TestESDCaloClusterAndCell.C:167 TestESDCaloClusterAndCell.C:168 TestESDCaloClusterAndCell.C:169 TestESDCaloClusterAndCell.C:170 TestESDCaloClusterAndCell.C:171 TestESDCaloClusterAndCell.C:172 TestESDCaloClusterAndCell.C:173 TestESDCaloClusterAndCell.C:174 TestESDCaloClusterAndCell.C:175 TestESDCaloClusterAndCell.C:176 TestESDCaloClusterAndCell.C:177 TestESDCaloClusterAndCell.C:178 TestESDCaloClusterAndCell.C:179 TestESDCaloClusterAndCell.C:180 TestESDCaloClusterAndCell.C:181 TestESDCaloClusterAndCell.C:182 TestESDCaloClusterAndCell.C:183 TestESDCaloClusterAndCell.C:184 TestESDCaloClusterAndCell.C:185 TestESDCaloClusterAndCell.C:186 TestESDCaloClusterAndCell.C:187 TestESDCaloClusterAndCell.C:188 TestESDCaloClusterAndCell.C:189 TestESDCaloClusterAndCell.C:190 TestESDCaloClusterAndCell.C:191 TestESDCaloClusterAndCell.C:192 TestESDCaloClusterAndCell.C:193 TestESDCaloClusterAndCell.C:194 TestESDCaloClusterAndCell.C:195 TestESDCaloClusterAndCell.C:196 TestESDCaloClusterAndCell.C:197 TestESDCaloClusterAndCell.C:198 TestESDCaloClusterAndCell.C:199 TestESDCaloClusterAndCell.C:200 TestESDCaloClusterAndCell.C:201 TestESDCaloClusterAndCell.C:202 TestESDCaloClusterAndCell.C:203 TestESDCaloClusterAndCell.C:204 TestESDCaloClusterAndCell.C:205 TestESDCaloClusterAndCell.C:206 TestESDCaloClusterAndCell.C:207 TestESDCaloClusterAndCell.C:208 TestESDCaloClusterAndCell.C:209 TestESDCaloClusterAndCell.C:210 TestESDCaloClusterAndCell.C:211 TestESDCaloClusterAndCell.C:212 TestESDCaloClusterAndCell.C:213 TestESDCaloClusterAndCell.C:214 TestESDCaloClusterAndCell.C:215 TestESDCaloClusterAndCell.C:216