From 34f814131fb4a3f0e3caf78114e8e42a3db3aea0 Mon Sep 17 00:00:00 2001 From: gustavo Date: Thu, 6 Dec 2007 09:18:52 +0000 Subject: [PATCH] Example macro to read ESDCaloClusters and ESDCaloCells --- EMCAL/macros/TestESDCaloClusterAndCell.C | 215 +++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 EMCAL/macros/TestESDCaloClusterAndCell.C diff --git a/EMCAL/macros/TestESDCaloClusterAndCell.C b/EMCAL/macros/TestESDCaloClusterAndCell.C new file mode 100644 index 00000000000..48a3f783a62 --- /dev/null +++ b/EMCAL/macros/TestESDCaloClusterAndCell.C @@ -0,0 +1,215 @@ +#if !defined(__CINT__) || defined(__MAKECINT__) + +//Root include files +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//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 "<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 >>>>>>>>>>> "<>> "<GetEMCALCells()); + if(det == "PHOS") AliESDCaloCells &cells = *(esd->GetPHOSCells()); + Int_t ncell = cells.GetNumberOfCells() ; + Int_t type = cells.GetType(); + cout<<">>> Event "<GetEMCALClusters(caloClusters); + else if(det == "PHOS") esd->GetPHOSClusters(caloClusters); + + Int_t nclus = caloClusters->GetEntries() ; + + cout<<"Event: "<At(iclus) ; // retrieve cluster from esd + //cout<<">>>> Cluster >>>"<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 "<GetClusterType() + <<"; Energy "<=0 && iprim < sta->GetNtrack()){ + TParticle * particle = sta->Particle(clus->GetLabel()); + //Print primary values + cout<<" Primary: "<GetName()<< "; Energy "<Energy()<= sta->GetNtrack()) cout <<"PROBLEM, label is too large : "<= particles in stack "<< sta->GetNtrack() <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 "<