create general emcal task lib
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalParticleMaker.cxx
CommitLineData
70d53162 1// $Id$
43d99a73 2//
3// Class to make emcal particles in AOD/ESD events.
4//
5// Author: S.Aiola
6
7#include <TClonesArray.h>
8
9#include "AliLog.h"
10#include "AliVTrack.h"
11#include "AliVCluster.h"
12#include "AliEmcalParticle.h"
13
14#include "AliEmcalParticleMaker.h"
15
16ClassImp(AliEmcalParticleMaker)
17
18//________________________________________________________________________
19AliEmcalParticleMaker::AliEmcalParticleMaker() :
a18c300f 20 AliAnalysisTaskEmcal("AliEmcalParticleMaker",kFALSE),
43d99a73 21 fTracksOutName("EmcalTracks"),
22 fCaloOutName("EmcalClusters"),
23 fTracksOut(0),
24 fCaloClustersOut(0)
25{
26 // Constructor.
27}
28
29//________________________________________________________________________
30AliEmcalParticleMaker::AliEmcalParticleMaker(const char *name) :
a18c300f 31 AliAnalysisTaskEmcal(name,kFALSE),
43d99a73 32 fTracksOutName("EmcalTracks"),
33 fCaloOutName("EmcalClusters"),
34 fTracksOut(0),
35 fCaloClustersOut(0)
36{
37 // Constructor.
38
39}
40
41//________________________________________________________________________
42AliEmcalParticleMaker::~AliEmcalParticleMaker()
43{
44 // Destructor.
45}
46
47//________________________________________________________________________
48void AliEmcalParticleMaker::UserCreateOutputObjects()
49{
50 // Create my user objects.
51
52 fTracksOut = new TClonesArray("AliEmcalParticle");
53 fTracksOut->SetName(fTracksOutName);
54
55 fCaloClustersOut = new TClonesArray("AliEmcalParticle");
56 fCaloClustersOut->SetName(fCaloOutName);
57}
58
59//________________________________________________________________________
60Bool_t AliEmcalParticleMaker::Run()
61{
62 // Create th emcal particles
63
64 // add tracks to event if not yet there
65 if (!(InputEvent()->FindListObject(fTracksOutName))) {
66 InputEvent()->AddObject(fTracksOut);
67 }
68 if (!(InputEvent()->FindListObject(fCaloOutName))) {
69 InputEvent()->AddObject(fCaloClustersOut);
70 }
71
72 // clear container (normally a null operation as the event should clean it already)
73 fTracksOut->Delete();
74 fCaloClustersOut->Delete();
75
2bddb6ae 76 if (fTracks) {
77 // loop over tracks
78 const Int_t Ntracks = fTracks->GetEntries();
79 for (Int_t iTracks = 0; iTracks < Ntracks; ++iTracks) {
80
81 AliVTrack *track = dynamic_cast<AliVTrack*>(fTracks->At(iTracks));
82 new ((*fTracksOut)[iTracks]) AliEmcalParticle(track, iTracks);
83 }
43d99a73 84 }
85
2bddb6ae 86 if (fCaloClusters) {
87 // loop over clusters
88 const Int_t Nclusters = fCaloClusters->GetEntries();
89 for (Int_t iClusters = 0; iClusters < Nclusters; ++iClusters) {
90
91 AliVCluster *cluster = dynamic_cast<AliVCluster*>(fCaloClusters->At(iClusters));
92 new ((*fCaloClustersOut)[iClusters]) AliEmcalParticle(cluster, iClusters, fVertex[0], fVertex[1], fVertex[2]);
93 }
43d99a73 94 }
43d99a73 95 return kTRUE;
96}