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