AliRoot Core  edcc906 (edcc906)
TestESDCaloClusterAndCell.C
Go to the documentation of this file.
1 
12 #if !defined(__CINT__) || defined(__MAKECINT__)
13 // Root include files
14 #include <Riostream.h>
15 #include <TFile.h>
16 #include <TChain.h>
17 #include <TParticle.h>
18 #include <TNtuple.h>
19 #include <TCanvas.h>
20 #include <TObjArray.h>
21 #include <TSystem.h>
22 #include <TString.h>
23 #include <TH1F.h>
24 #include <TVector.h>
25 #include <TParticle.h>
26 #include <TRefArray.h>
27 #include <TArrayS.h>
28 
29 // AliRoot include files
30 #include "AliRunLoader.h"
31 #include "AliStack.h"
32 #include "AliESDEvent.h"
33 #include "AliESDVertex.h"
34 #include "AliESDCaloCluster.h"
35 #include "AliESDCaloCells.h"
36 #include "AliPID.h"
37 #include "AliLog.h"
38 
39 #endif
40 
46 TChain * AliReadESDfromdisk(const UInt_t eventsToRead,
47  const TString dirName,
48  const TString esdTreeName,
49  const char * pattern)
50 {
51  TChain * rv = 0;
52 
53  // Create a TChain of all the files
54  TChain * cESDTree = new TChain(esdTreeName) ;
55 
56  // Read from the directory file until the require number of events are collected
57  void * from = gSystem->OpenDirectory(dirName) ;
58  if (!from)
59  rv = 0 ;
60  else
61  { // reading file names from directory
62  const char * subdir ;
63 
64  // search all subdirectories witch matching pattern
65  while( (subdir = gSystem->GetDirEntry(from)) &&
66  (cESDTree->GetEntries() < eventsToRead))
67  {
68  if ( strstr(subdir, pattern) != 0 ) {
69  char file[200] ;
70  sprintf(file, "%s%s/AliESDs.root", dirName.Data(), subdir);
71  cESDTree->Add(file) ;
72  }
73  } // while file
74 
75  rv = cESDTree ;
76 
77  } // reading file names from directory
78 
79  return rv ;
80 }
81 
84 //======================================================================
85 TChain * AliReadESD(const UInt_t eventsToRead,
86  const TString dirName,
87  const TString esdTreeName,
88  const char * pattern)
89 {
90  if ( dirName == "" )
91  return 0 ;
92 
93  if ( esdTreeName == "" )
94  return AliReadESDfromdisk(eventsToRead, dirName,"","") ;
95  else if ( strcmp(pattern, "") == 0 )
96  return AliReadESDfromdisk(eventsToRead, dirName, esdTreeName,"") ;
97  else
98  return AliReadESDfromdisk(eventsToRead, dirName, esdTreeName, pattern) ;
99 }
100 
101 //=====================================================================
111 //=====================================================================
113 (
114  TString det = "EMCAL", const UInt_t eventsToProcess = 5,
115  TString dirName = "./",
116  const TString esdTreeName = "esdTree",
117  const char * pattern = "."
118 )
119 {
120  if(det !="EMCAL" && det !="PHOS" )
121  {
122  cout << "Wrong detector name "<<det<<endl;
123  return;
124  }
125 
126  //Create chain of esd trees
127  //By default the root files are in the same directory
128  TChain * t = AliReadESD(eventsToProcess, dirName,esdTreeName,pattern) ;
129 
130  // ESD
131  AliESDEvent * esd = new AliESDEvent();
132  esd->ReadFromTree(t); // This checks also if the branch address is already set
133 
134 
135  // Define few variables to be used in macro
136  TString alirunName = "" ;
137  UInt_t event ;
138  Float_t pos[3] ;
139 
140  // Event loop
141  for (event = 0; event < eventsToProcess; event++)
142  {
143  //AliInfo( Form("Event %d \n",event) );
144  Int_t nbytes = t->GetEntry(event); // store event in esd
145  if ( nbytes == 0 ) //If nothing in ESD
146  break ;
147 
148  // Check that name of file is correct
149  if (alirunName != t->GetFile()->GetName())
150  {
151  alirunName = t->GetFile()->GetName() ;
152  alirunName.ReplaceAll("galice.root", "AliESDs.root") ;
153  }
154 
155  AliRunLoader *rl = AliRunLoader::Open("galice.root",
157  "read");
158  rl->LoadKinematics();
159  rl->GetEvent(event);
160  AliStack *sta=rl->Stack();
161 
162  // Get reconstructed vertex position
163  Double_t vertex_position[3] ;
164  esd->GetVertex()->GetXYZ(vertex_position) ;
165 
166  //cout<<"Event >>>>>>>>>>> "<<event<<" vertex >>> "<<vertex_position[0]<<" "<<vertex_position[1]<<" "<<vertex_position[2]<<endl;
167 
168  // Get CaloCells
169  AliESDCaloCells &cells= *(esd->GetEMCALCells());
170  if(det == "PHOS")
171  AliESDCaloCells &cells = *(esd->GetPHOSCells());
172 
173  Int_t ncell = cells.GetNumberOfCells() ;
174  Int_t type = cells.GetType();
175 
176  cout<<">>> Event "<<event<<" ncells "<<ncell<< " type "<<type<<endl;
177  // Uncomment to see the full list of digit amplitudes and times.
178  // for (Int_t icell= 0; icell < ncell; icell++) {
179  // cout<<"icell "<<icell<<
180  // " ID "<<cells.GetCellNumber(icell)<<
181  // " amp "<<cells.GetAmplitude(icell)<<
182  // " time "<<cells.GetTime(icell)<<endl;
183 
184  // }// cell loop
185 
186  //Get the CaloClusters
187 
188  //select EMCAL clusters only
189  TRefArray * caloClusters = new TRefArray();
190 
191  if(det == "EMCAL") esd->GetEMCALClusters(caloClusters);
192  else if(det == "PHOS") esd->GetPHOSClusters(caloClusters);
193 
194  Int_t nclus = caloClusters->GetEntries() ;
195 
196  cout<<"Event: "<<event<<"; Number of clusters "<<nclus<<endl;
197 
199  for (Int_t iclus = 0; iclus < nclus; iclus++)
200  {
201  // Retrieve cluster from esd
202  AliESDCaloCluster * clus = (AliESDCaloCluster *) caloClusters->At(iclus) ;
203  //cout<<">>>> Cluster >>>"<<iclus<<endl;
204 
205  // Get the cluster info
206  Float_t energy = clus->E() ;
207  //Float_t disp = clus->GetClusterDisp() ;
208  Int_t iprim = clus->GetLabel();
209 
210  clus->GetPosition(pos) ;
211  TVector3 vpos(pos[0],pos[1],pos[2]) ;
212  TLorentzVector p ;
213  clus->GetMomentum(p,vertex_position);
214 
215  Int_t mult = clus->GetNCells() ;
216  UShort_t * index = clus->GetCellsAbsId() ;
217  Double_t * fraction = clus->GetCellsAmplitudeFraction() ;
218 
219  // Print cluster info
220  cout<<"Cluster "<<iclus <<"; digits mult "<<mult<<"; type "<<(Int_t )clus->GetType()
221  <<"; Energy "<<energy
222  <<"; Phi "<<(vpos.Phi()*180/TMath::Pi())<<"; Eta "<<vpos.Eta()
223  <<"; label "<<iprim<<endl;
224 
225  // Print primary info
226  if(iprim>=0 && iprim < sta->GetNtrack())
227  {
228  TParticle * particle = sta->Particle(clus->GetLabel());
229  //Print primary values
230  cout<<" Primary: "<<particle->GetName()<< "; Energy "<<particle->Energy()<<endl;
231  }
232  else if( iprim >= sta->GetNtrack() )
233  cout <<"PROBLEM, label is too large : "<<iprim
234  <<" >= particles in stack "<< sta->GetNtrack() <<endl;
235  else
236  cout<<"Negative label!!! : "<<iprim<<endl;
237 
238  // Get CaloCells of cluster and print
239  for(Int_t i = 0; i < mult ; i++)
240  {
241  Int_t absId = index[i]; // or clus->GetCellNumber(i) ;
242  Double_t ampFract = fraction[i];
243  Float_t amp = cells.GetCellAmplitude(absId) ;
244  Float_t time = cells.GetCellTime(absId);
245 
246  cout<<"AbsID : "<< absId << "; Amplitude "<< amp
247  << "; Fraction "<<ampFract<<"; Time " <<time<<endl;
248  }
249 
250  }// clusters
251 
252  }// event loop
253 
254 }
255 
256 
static const TString & GetDefaultEventFolderName()
Definition: AliConfig.h:58
void TestESDCaloClusterAndCell(TString det="EMCAL", const UInt_t eventsToProcess=5, TString dirName="./", const TString esdTreeName="esdTree", const char *pattern=".")
virtual void GetXYZ(Double_t position[3]) const
Definition: AliVertex.cxx:119
Char_t GetType() const
Float_t p[]
Definition: kNNTest.C:133
static AliRunLoader * Open(const char *filename="galice.root", const char *eventfoldername=AliConfig::GetDefaultEventFolderName(), Option_t *option="READ")
UShort_t * GetCellsAbsId()
void GetMomentum(TLorentzVector &p, const Double_t *vertexPosition) const
virtual Int_t GetNtrack() const
Definition: AliStack.h:134
TChain * AliReadESDfromdisk(const UInt_t eventsToRead, const TString dirName, const TString esdTreeName, const char *pattern)
AliESDCaloCells * GetPHOSCells() const
Definition: AliESDEvent.h:507
AliESDCaloCells * GetEMCALCells() const
Definition: AliESDEvent.h:506
Int_t GetEMCALClusters(TRefArray *clusters) const
Double_t GetCellAmplitude(Short_t cellNumber)
Char_t GetType() const
Calorimeter cluster data container.
Int_t GetEvent(Int_t evno)
TParticle * Particle(Int_t id, Bool_t useInEmbedding=kFALSE)
Definition: AliStack.cxx:688
Double_t E() const
void ReadFromTree(TTree *tree, Option_t *opt="")
Int_t GetNCells() const
const AliESDVertex * GetVertex() const
Definition: AliESDEvent.h:308
Short_t GetNumberOfCells() const
Class for calorimeter cell ESD data handling.
Int_t GetLabel() const
Double32_t * GetCellsAmplitudeFraction()
void GetPosition(Float_t *x) const
Int_t LoadKinematics(Option_t *option="READ")
Double_t GetCellTime(Short_t cellNumber)
AliStack * Stack() const
Definition: AliRunLoader.h:95
TChain * AliReadESD(const UInt_t eventsToRead, const TString dirName, const TString esdTreeName, const char *pattern)
Read AliESDs files and return a Chain of events.
Int_t GetPHOSClusters(TRefArray *clusters) const