simplification
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliEmcalPicoTrackMaker.cxx
CommitLineData
980821ba 1// $Id$
680855e5 2//
3// Class to make PicoTracks in AOD/ESD events.
4//
cd231d42 5// Author: S.Aiola, C.Loizides
680855e5 6
7#include <TClonesArray.h>
a070db7d 8#include "AliAODEvent.h"
680855e5 9#include "AliAODTrack.h"
a070db7d 10#include "AliAnalysisManager.h"
680855e5 11#include "AliESDtrack.h"
12#include "AliESDtrackCuts.h"
13#include "AliLog.h"
a070db7d 14#include "AliPicoTrack.h"
15#include "AliVTrack.h"
680855e5 16#include "AliEmcalPicoTrackMaker.h"
17
18ClassImp(AliEmcalPicoTrackMaker)
19
20//________________________________________________________________________
21AliEmcalPicoTrackMaker::AliEmcalPicoTrackMaker() :
22 AliAnalysisTaskSE("AliEmcalPicoTrackMaker"),
23 fESDtrackCuts(0),
24 fTracksOutName("PicoTracks"),
25 fTracksInName("tracks"),
85fbcc1d 26 fMaxTrackPt(100),
680855e5 27 fTracksIn(0),
28 fTracksOut(0)
29{
30 // Constructor.
ab292aef 31
32 fAODfilterBits[0] = 0;
33 fAODfilterBits[1] = 0;
680855e5 34}
35
36//________________________________________________________________________
37AliEmcalPicoTrackMaker::AliEmcalPicoTrackMaker(const char *name) :
a070db7d 38 AliAnalysisTaskSE(name),
680855e5 39 fESDtrackCuts(0),
40 fTracksOutName("PicoTracks"),
41 fTracksInName("tracks"),
85fbcc1d 42 fMaxTrackPt(100),
680855e5 43 fTracksIn(0),
44 fTracksOut(0)
45{
46 // Constructor.
47
ab292aef 48 fAODfilterBits[0] = 0;
49 fAODfilterBits[1] = 0;
680855e5 50 fBranchNames = "ESD:AliESDHeader.,AliESDRun.,SPDVertex.,Tracks";
51}
52
53//________________________________________________________________________
54AliEmcalPicoTrackMaker::~AliEmcalPicoTrackMaker()
55{
a070db7d 56 // Destructor.
680855e5 57}
58
59//________________________________________________________________________
60void AliEmcalPicoTrackMaker::UserCreateOutputObjects()
61{
a070db7d 62 // Create my user objects.
680855e5 63
64 fTracksOut = new TClonesArray("AliPicoTrack");
65 fTracksOut->SetName(fTracksOutName);
66}
67
68//________________________________________________________________________
69void AliEmcalPicoTrackMaker::UserExec(Option_t *)
70{
71 // Main loop, called for each event.
72
73 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
74 if (!am) {
75 AliError("Manager zero, returning");
76 return;
77 }
78
a070db7d 79 // retrieve tracks from input.
80 fTracksIn = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksInName));
81 if (!fTracksIn) {
82 AliError(Form("Could not retrieve tracks %s!", fTracksInName.Data()));
83 return;
84 }
85
86 // add tracks to event if not yet there
c4a9715d 87 if (!(InputEvent()->FindListObject(fTracksOutName))) {
680855e5 88 InputEvent()->AddObject(fTracksOut);
c4a9715d 89 }
c4a9715d 90
a070db7d 91 // clear container (normally a null operation as the event should clean it already)
92 fTracksOut->Clear();
680855e5 93
a070db7d 94 // test if we are in ESD or AOD mode
95 Bool_t esdMode = kTRUE;
96 if (dynamic_cast<AliAODEvent*>(InputEvent())!=0)
97 esdMode = kFALSE;
98
99 // loop over tracks
100 const Int_t Ntracks = fTracksIn->GetEntriesFast();
680855e5 101 for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
85fbcc1d 102
a070db7d 103 AliVTrack *track = dynamic_cast<AliVTrack*>(fTracksIn->At(iTracks));
85fbcc1d 104
a070db7d 105 if (!track)
680855e5 106 continue;
85fbcc1d 107
108 if (track->Pt() > fMaxTrackPt)
109 continue;
110
c4a9715d 111 Int_t label = -1;
a070db7d 112 if (esdMode) {
113 if (fESDtrackCuts) {
114 AliESDtrack *esdtrack = static_cast<AliESDtrack*>(track);
115 if (!fESDtrackCuts->AcceptTrack(esdtrack))
116 continue;
117 }
118 label = track->GetLabel();
119 } else {
120 AliAODTrack *aodtrack = static_cast<AliAODTrack*>(track);
680855e5 121 if (aodtrack->TestFilterBit(fAODfilterBits[0]))
122 label = 0;
a070db7d 123 else if (aodtrack->TestFilterBit(fAODfilterBits[1]))
c4a9715d 124 label = 3;
a070db7d 125 else /*not a good track*/
126 continue;
680855e5 127 }
128
a070db7d 129 AliPicoTrack *picotrack = new ((*fTracksOut)[nacc]) AliPicoTrack(track->Pt(),
130 track->Eta(),
131 track->Phi(),
132 track->Charge(),
133 label,
134 track->GetTrackEtaOnEMCal(),
135 track->GetTrackPhiOnEMCal(),
136 track->IsEMCAL());
680855e5 137 if (track->IsEMCAL()) {
138 picotrack->SetEMCALcluster(track->GetEMCALcluster());
139 }
680855e5 140 ++nacc;
141 }
142}