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
c4a9715d 80 // Add tracks to event if not yet there
81 if (!(InputEvent()->FindListObject(fTracksOutName))) {
680855e5 82 InputEvent()->AddObject(fTracksOut);
c4a9715d 83 }
84 else {
85 // IMPORTANT: if it is not an AliESDEvent, non-std TClonesArray will not be cleared automatically!
86 if (!(InputEvent()->InheritsFrom("AliESDEvent")))
87 fTracksOut->Delete();
88 }
89
90 RetrieveEventObjects();
680855e5 91
92 Int_t Ntracks = GetNumberOfTracks();
93 for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
94 AliVTrack *track = GetTrack(iTracks);
95
96 if (!AcceptTrack(track))
97 continue;
98
c4a9715d 99 Int_t label = -1;
680855e5 100
101 if (track->InheritsFrom("AliAODTrack")) {
102 AliAODTrack *aodtrack = dynamic_cast<AliAODTrack*>(track);
103 if (aodtrack->TestFilterBit(fAODfilterBits[0]))
104 label = 0;
c4a9715d 105 else //if (aodtrack->TestFilterBit(fAODfilterBits[1]))
106 label = 3;
680855e5 107 }
108 else {
109 label = track->GetLabel();
110 }
111
112 AliPicoTrack *picotrack = new ((*fTracksOut)[nacc]) AliPicoTrack(track->Pt(), track->Eta(), track->Phi(),
113 track->Charge(), label,
114 track->GetTrackEtaOnEMCal(), track->GetTrackPhiOnEMCal(), track->IsEMCAL());
115 if (track->IsEMCAL()) {
116 picotrack->SetEMCALcluster(track->GetEMCALcluster());
117 }
118 //cout << iTracks << " - is emcal = " << track->IsEMCAL() << ", phiemc = " << track->GetTrackPhiOnEMCal() << ", etaemc = " << track->GetTrackEtaOnEMCal() << ", emcid = " << track->GetEMCALcluster() << endl;
119 ++nacc;
120 }
121}
122
680855e5 123//________________________________________________________________________
124Bool_t AliEmcalPicoTrackMaker::AcceptTrack(AliVTrack *track)
125{
126 if (!track)
127 return kFALSE;
128
129 if (track->InheritsFrom("AliAODTrack")) {
130 AliAODTrack *aodtrack = dynamic_cast<AliAODTrack*>(track);
131 if (aodtrack) {
132 //cout << "filter bit = " << fFilterBit << ", filter map = " << aodtrack->GetFilterMap() << endl;
c4a9715d 133 //cout << fAODfilterBits[0]+fAODfilterBits[1] << endl;
134 return aodtrack->TestFilterBit(fAODfilterBits[0] | fAODfilterBits[1]);
135 //return aodtrack->IsHybridGlobalConstrainedGlobal();
680855e5 136 }
137 else {
138 AliError("Could not cast AOD track!");
139 return kFALSE;
140 }
141 }
142 else if (track->InheritsFrom("AliESDtrack")) {
143 if (fESDtrackCuts) {
144 AliESDtrack *esdtrack = dynamic_cast<AliESDtrack*>(track);
145 if (esdtrack) {
146 return fESDtrackCuts->AcceptTrack(esdtrack);
147 }
148 else {
149 AliError("Could not cast ESD track!");
150 return kFALSE;
151 }
152 }
153 else {
154 return kTRUE;
155 }
156 }
c4a9715d 157 else {
158 AliWarning("Track type not recognized: nothing to filter!");
680855e5 159 return kTRUE;
160 }
161}
162
163//________________________________________________________________________
164void AliEmcalPicoTrackMaker::RetrieveEventObjects()
165{
166 fTracksIn = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksInName));
167
168 if (!fTracksIn) {
169 AliError(Form("ERROR: Could not retrieve tracks %s!", fTracksInName.Data()));
170 }
171}
172
173//________________________________________________________________________
174AliVTrack* AliEmcalPicoTrackMaker::GetTrack(const Int_t i) const
175{
176 if (fTracksIn)
177 return dynamic_cast<AliVTrack*>(fTracksIn->At(i));
178 else
179 return 0;
180}
181
182//________________________________________________________________________
183Int_t AliEmcalPicoTrackMaker::GetNumberOfTracks() const
184{
185 if (fTracksIn)
186 return fTracksIn->GetEntriesFast();
187 else
188 return 0;
189}