fix
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliEmcalPicoTrackMaker.cxx
CommitLineData
680855e5 1// $Id: AliEmcalPicoTrackMaker.cxx $
2//
3// Class to make PicoTracks in AOD/ESD events.
4//
5//
6
7#include <TClonesArray.h>
8
9#include "AliAnalysisManager.h"
10#include "AliVEvent.h"
11#include "AliPicoTrack.h"
12#include "AliVTrack.h"
13#include "AliAODTrack.h"
14#include "AliESDtrack.h"
15#include "AliESDtrackCuts.h"
16#include "AliLog.h"
17
18#include "AliEmcalPicoTrackMaker.h"
19
20ClassImp(AliEmcalPicoTrackMaker)
21
22//________________________________________________________________________
23AliEmcalPicoTrackMaker::AliEmcalPicoTrackMaker() :
24 AliAnalysisTaskSE("AliEmcalPicoTrackMaker"),
25 fESDtrackCuts(0),
26 fTracksOutName("PicoTracks"),
27 fTracksInName("tracks"),
28 fTracksIn(0),
29 fTracksOut(0)
30{
31 // Constructor.
32}
33
34//________________________________________________________________________
35AliEmcalPicoTrackMaker::AliEmcalPicoTrackMaker(const char *name) :
36 AliAnalysisTaskSE("AliEmcalPicoTrackMaker"),
37 fESDtrackCuts(0),
38 fTracksOutName("PicoTracks"),
39 fTracksInName("tracks"),
40 fTracksIn(0),
41 fTracksOut(0)
42{
43 // Constructor.
44
45 if (!name)
46 return;
47
48 SetName(name);
49
50 fBranchNames = "ESD:AliESDHeader.,AliESDRun.,SPDVertex.,Tracks";
51}
52
53//________________________________________________________________________
54AliEmcalPicoTrackMaker::~AliEmcalPicoTrackMaker()
55{
56 //Destructor
57
58}
59
60//________________________________________________________________________
61void AliEmcalPicoTrackMaker::UserCreateOutputObjects()
62{
63 // Create histograms.
64
65 fTracksOut = new TClonesArray("AliPicoTrack");
66 fTracksOut->SetName(fTracksOutName);
67}
68
69//________________________________________________________________________
70void AliEmcalPicoTrackMaker::UserExec(Option_t *)
71{
72 // Main loop, called for each event.
73
74 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
75 if (!am) {
76 AliError("Manager zero, returning");
77 return;
78 }
79
80 RetrieveEventObjects();
81
82 // add tracks to event if not yet there
83 if (!(InputEvent()->FindListObject(fTracksOutName)))
84 InputEvent()->AddObject(fTracksOut);
85
86 Int_t Ntracks = GetNumberOfTracks();
87 for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
88 AliVTrack *track = GetTrack(iTracks);
89
90 if (!AcceptTrack(track))
91 continue;
92
93 Int_t label = 0;
94
95 if (track->InheritsFrom("AliAODTrack")) {
96 AliAODTrack *aodtrack = dynamic_cast<AliAODTrack*>(track);
97 if (aodtrack->TestFilterBit(fAODfilterBits[0]))
98 label = 0;
99 else if (aodtrack->TestFilterBit(fAODfilterBits[1]))
100 label = 1;
101 else //if (aodtrack->TestFilterBit(fAODfilterBits[2]))
102 label = 2;
103 }
104 else {
105 label = track->GetLabel();
106 }
107
108 AliPicoTrack *picotrack = new ((*fTracksOut)[nacc]) AliPicoTrack(track->Pt(), track->Eta(), track->Phi(),
109 track->Charge(), label,
110 track->GetTrackEtaOnEMCal(), track->GetTrackPhiOnEMCal(), track->IsEMCAL());
111 if (track->IsEMCAL()) {
112 picotrack->SetEMCALcluster(track->GetEMCALcluster());
113 }
114 //cout << iTracks << " - is emcal = " << track->IsEMCAL() << ", phiemc = " << track->GetTrackPhiOnEMCal() << ", etaemc = " << track->GetTrackEtaOnEMCal() << ", emcid = " << track->GetEMCALcluster() << endl;
115 ++nacc;
116 }
117}
118
680855e5 119//________________________________________________________________________
120Bool_t AliEmcalPicoTrackMaker::AcceptTrack(AliVTrack *track)
121{
122 if (!track)
123 return kFALSE;
124
125 if (track->InheritsFrom("AliAODTrack")) {
126 AliAODTrack *aodtrack = dynamic_cast<AliAODTrack*>(track);
127 if (aodtrack) {
128 //cout << "filter bit = " << fFilterBit << ", filter map = " << aodtrack->GetFilterMap() << endl;
f22cb876 129 //return aodtrack->TestFilterBit(fAODfilterBits[0]+fAODfilterBits[1]+fAODfilterBits[2]);
130 return aodtrack->IsHybridGlobalConstrainedGlobal();
680855e5 131 }
132 else {
133 AliError("Could not cast AOD track!");
134 return kFALSE;
135 }
136 }
137 else if (track->InheritsFrom("AliESDtrack")) {
138 if (fESDtrackCuts) {
139 AliESDtrack *esdtrack = dynamic_cast<AliESDtrack*>(track);
140 if (esdtrack) {
141 return fESDtrackCuts->AcceptTrack(esdtrack);
142 }
143 else {
144 AliError("Could not cast ESD track!");
145 return kFALSE;
146 }
147 }
148 else {
149 return kTRUE;
150 }
151 }
152 else if (track->InheritsFrom("PicoTrack")) {
153 AliWarning("PicoTrack: nothing to filter!");
154 return kTRUE;
155 }
156}
157
158//________________________________________________________________________
159void AliEmcalPicoTrackMaker::RetrieveEventObjects()
160{
161 fTracksIn = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksInName));
162
163 if (!fTracksIn) {
164 AliError(Form("ERROR: Could not retrieve tracks %s!", fTracksInName.Data()));
165 }
166}
167
168//________________________________________________________________________
169AliVTrack* AliEmcalPicoTrackMaker::GetTrack(const Int_t i) const
170{
171 if (fTracksIn)
172 return dynamic_cast<AliVTrack*>(fTracksIn->At(i));
173 else
174 return 0;
175}
176
177//________________________________________________________________________
178Int_t AliEmcalPicoTrackMaker::GetNumberOfTracks() const
179{
180 if (fTracksIn)
181 return fTracksIn->GetEntriesFast();
182 else
183 return 0;
184}