b141614d5b68e81d47ecd85070550265e0b67e6b
[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 <TRandom3.h>
9
10 #include "AliAODEvent.h"
11 #include "AliAODTrack.h"
12 #include "AliAnalysisManager.h"
13 #include "AliESDtrack.h"
14 #include "AliESDtrackCuts.h"
15 #include "AliLog.h"
16 #include "AliPicoTrack.h"
17 #include "AliVTrack.h"
18 #include "AliEmcalPicoTrackMaker.h"
19
20 ClassImp(AliEmcalPicoTrackMaker)
21
22 //________________________________________________________________________
23 AliEmcalPicoTrackMaker::AliEmcalPicoTrackMaker() : 
24   AliAnalysisTaskSE("AliEmcalPicoTrackMaker"),
25   fESDtrackCuts(0),
26   fTracksOutName("PicoTracks"),
27   fTracksInName("tracks"),
28   fMinTrackPt(0),
29   fMaxTrackPt(1000),
30   fMinTrackEta(-0.9),
31   fMaxTrackEta(0.9),
32   fMinTrackPhi(-10),
33   fMaxTrackPhi(10),
34   fTrackEfficiency(1),
35   fTracksIn(0),
36   fTracksOut(0)
37 {
38   // Constructor.
39
40   fAODfilterBits[0] = 0;
41   fAODfilterBits[1] = 0;
42 }
43
44 //________________________________________________________________________
45 AliEmcalPicoTrackMaker::AliEmcalPicoTrackMaker(const char *name) : 
46   AliAnalysisTaskSE(name),
47   fESDtrackCuts(0),
48   fTracksOutName("PicoTracks"),
49   fTracksInName("tracks"),
50   fMinTrackPt(0),
51   fMaxTrackPt(1000),
52   fMinTrackEta(-0.9),
53   fMaxTrackEta(0.9),
54   fMinTrackPhi(-10),
55   fMaxTrackPhi(10),
56   fTrackEfficiency(1),
57   fTracksIn(0),
58   fTracksOut(0)
59 {
60   // Constructor.
61
62   fAODfilterBits[0] = 0;
63   fAODfilterBits[1] = 0;
64   fBranchNames = "ESD:AliESDHeader.,AliESDRun.,SPDVertex.,Tracks";
65 }
66
67 //________________________________________________________________________
68 AliEmcalPicoTrackMaker::~AliEmcalPicoTrackMaker()
69 {
70   // Destructor.
71 }
72
73 //________________________________________________________________________
74 void AliEmcalPicoTrackMaker::UserCreateOutputObjects()
75 {
76   // Create my user objects.
77
78   fTracksOut = new TClonesArray("AliPicoTrack");
79   fTracksOut->SetName(fTracksOutName);
80 }
81
82 //________________________________________________________________________
83 void AliEmcalPicoTrackMaker::UserExec(Option_t *) 
84 {
85   // Main loop, called for each event.
86
87   AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
88   if (!am) {
89     AliError("Manager zero, returning");
90     return;
91   }
92
93   // retrieve tracks from input.
94   if (!fTracksIn) { 
95     fTracksIn = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksInName));
96     if (!fTracksIn) {
97       AliError(Form("Could not retrieve tracks %s!", fTracksInName.Data())); 
98       return;
99     }
100     if (!fTracksIn->GetClass()->GetBaseClass("AliVParticle")) {
101       AliError(Form("%s: Collection %s does not contain AliVParticle objects!", GetName(), fTracksInName.Data())); 
102       return;
103     }
104   }
105
106   // add tracks to event if not yet there
107   if (!(InputEvent()->FindListObject(fTracksOutName))) {
108     InputEvent()->AddObject(fTracksOut);
109   }
110
111   // clear container (normally a null operation as the event should clean it already)
112   fTracksOut->Clear();
113
114   // test if we are in ESD or AOD mode
115   Bool_t esdMode = kTRUE;
116   if (dynamic_cast<AliAODEvent*>(InputEvent())!=0)
117     esdMode = kFALSE;
118  
119   // loop over tracks
120   const Int_t Ntracks = fTracksIn->GetEntriesFast();
121   for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
122
123     AliVTrack *track = static_cast<AliVTrack*>(fTracksIn->At(iTracks));
124
125     if (!track)
126       continue;
127
128     if (track->Pt() > fMaxTrackPt || track->Pt() < fMinTrackPt)
129       continue;
130
131     if (track->Eta() < fMinTrackEta || track->Eta() > fMaxTrackEta || 
132         track->Phi() < fMinTrackPhi || track->Phi() > fMaxTrackPhi)
133       continue;
134
135     Bool_t isEmc = kFALSE;
136     Int_t label = -1;
137     if (esdMode) {
138       if (fESDtrackCuts) {
139         AliESDtrack *esdtrack = static_cast<AliESDtrack*>(track);
140         if (!fESDtrackCuts->AcceptTrack(esdtrack))
141           continue;
142       }
143       label = track->GetLabel();
144       isEmc = track->IsEMCAL();
145     } else {
146       AliAODTrack *aodtrack = static_cast<AliAODTrack*>(track);
147       if (aodtrack->TestFilterBit(fAODfilterBits[0]))
148         label = 0;
149       else if (aodtrack->TestFilterBit(fAODfilterBits[1]))
150         label = 3;
151       else /*not a good track*/
152         continue;
153
154       if (TMath::Abs(track->GetTrackEtaOnEMCal()) < 0.75 && 
155           track->GetTrackPhiOnEMCal() > 70 * TMath::DegToRad() && 
156           track->GetTrackPhiOnEMCal() < 190 * TMath::DegToRad())
157         isEmc = kTRUE;
158     }
159
160     if (fTrackEfficiency < 1) {
161       Double_t r = gRandom->Rndm();
162       if (fTrackEfficiency < r) 
163         continue;
164     }
165
166     /*AliPicoTrack *picotrack =*/ new ((*fTracksOut)[nacc]) AliPicoTrack(track->Pt(), 
167                                                                      track->Eta(), 
168                                                                      track->Phi(), 
169                                                                      track->Charge(), 
170                                                                      label, 
171                                                                      track->GetTrackEtaOnEMCal(), 
172                                                                      track->GetTrackPhiOnEMCal(), 
173                                                                      isEmc);
174     ++nacc;
175   }
176 }