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