]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliEmcalAodTrackFilterTask.cxx
8abb969b1802bdec43c66dc08a3b772eb77d575b
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalAodTrackFilterTask.cxx
1 // $Id: AliEmcalAodTrackFilterTask.cxx | Fri Dec 6 10:29:20 2013 +0100 | Constantin Loizides  $
2 //
3 // Class to filter Aod tracks
4 //
5 // Author: C.Loizides
6
7 #include "AliEmcalAodTrackFilterTask.h"
8 #include <TClonesArray.h>
9 #include <TRandom3.h>
10 #include <AliAODEvent.h>
11 #include <AliAODTrack.h>
12 #include <AliAnalysisManager.h>
13 #include <AliEMCALRecoUtils.h>
14 #include <AliLog.h>
15
16 ClassImp(AliEmcalAodTrackFilterTask)
17
18 //________________________________________________________________________
19 AliEmcalAodTrackFilterTask::AliEmcalAodTrackFilterTask() : 
20   AliAnalysisTaskSE("AliEmcalAodTrackFilterTask"),
21   fTracksOutName("PicoTracks"),
22   fTracksInName("tracks"),
23   fIncludeNoITS(kTRUE),
24   fCutMaxFrShTPCClus(0),
25   fUseNegativeLabels(kTRUE),
26   fIsMC(kFALSE),
27   fDoPropagation(kFALSE),
28   fAttemptProp(kFALSE),
29   fAttemptPropMatch(kFALSE),
30   fDist(440),
31   fTracksIn(0),
32   fTracksOut(0)
33 {
34   // Constructor.
35
36   fAODfilterBits[0] = -1;
37   fAODfilterBits[1] = -1;
38 }
39
40 //________________________________________________________________________
41 AliEmcalAodTrackFilterTask::AliEmcalAodTrackFilterTask(const char *name) : 
42   AliAnalysisTaskSE(name),
43   fTracksOutName("PicoTracks"),
44   fTracksInName("tracks"),
45   fIncludeNoITS(kTRUE),
46   fCutMaxFrShTPCClus(0),
47   fUseNegativeLabels(kTRUE),
48   fIsMC(kFALSE),
49   fDoPropagation(kFALSE),
50   fAttemptProp(kFALSE),
51   fAttemptPropMatch(kFALSE),
52   fDist(440),
53   fTracksIn(0),
54   fTracksOut(0)
55 {
56   // Constructor.
57
58   fAODfilterBits[0] = -1;
59   fAODfilterBits[1] = -1;
60   fBranchNames = "AOD:tracks";
61 }
62
63 //________________________________________________________________________
64 AliEmcalAodTrackFilterTask::~AliEmcalAodTrackFilterTask()
65 {
66   // Destructor.
67 }
68
69 //________________________________________________________________________
70 void AliEmcalAodTrackFilterTask::UserCreateOutputObjects()
71 {
72   // Create my user objects.
73
74   fTracksOut = new TClonesArray("AliAODTrack");
75   fTracksOut->SetName(fTracksOutName);
76 }
77
78 //________________________________________________________________________
79 void AliEmcalAodTrackFilterTask::UserExec(Option_t *) 
80 {
81   // Main loop, called for each event.
82
83   AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
84   if (!am) {
85     AliError("Manager zero, returning");
86     return;
87   }
88
89   // retrieve tracks from input.
90   if (!fTracksIn) { 
91     fTracksIn = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksInName));
92     if (!fTracksIn) {
93       AliError(Form("Could not retrieve tracks %s!", fTracksInName.Data())); 
94       return;
95     }
96     if (!fTracksIn->GetClass()->GetBaseClass("AliVParticle")) {
97       AliError(Form("%s: Collection %s does not contain AliVParticle objects!", GetName(), fTracksInName.Data())); 
98       return;
99     }
100   }
101
102   // add tracks to event if not yet there
103   fTracksOut->Delete();
104   if (!(InputEvent()->FindListObject(fTracksOutName))) {
105     InputEvent()->AddObject(fTracksOut);
106   }
107
108   // loop over tracks
109   const Int_t Ntracks = fTracksIn->GetEntriesFast();
110   for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
111
112     AliAODTrack *track = static_cast<AliAODTrack*>(fTracksIn->At(iTracks));
113
114     if (!track)
115       continue;
116     Int_t type = -1;
117     if (fAODfilterBits[0] < 0) {
118       if (track->IsHybridGlobalConstrainedGlobal())
119         type = 3;
120       else /*not a good track*/
121         continue;
122     } else {
123       if (track->TestFilterBit(fAODfilterBits[0])) {
124         type = 0;
125       } else if (track->TestFilterBit(fAODfilterBits[1])) {
126         if ((track->GetStatus()&AliVTrack::kITSrefit)==0) {
127           if (fIncludeNoITS)
128             type = 2;
129           else
130             continue;
131         } else {
132           type = 1;
133         }
134       }
135       else {/*not a good track*/
136         continue;
137       }
138     }
139
140     if (fCutMaxFrShTPCClus > 0) {
141       Double_t frac = Double_t(track->GetTPCnclsS()) / Double_t(track->GetTPCncls());
142       if (frac > fCutMaxFrShTPCClus) {
143         continue;
144       }
145     }
146
147     AliAODTrack *newt = new ((*fTracksOut)[nacc]) AliAODTrack(*track);
148     Bool_t propthistrack = kFALSE;
149     if (fDoPropagation)
150       propthistrack = kTRUE;
151     else if (!newt->IsExtrapolatedToEMCAL()) {
152       if (fAttemptProp)
153         propthistrack = kTRUE;
154       else if (fAttemptPropMatch && !newt->IsEMCAL())
155         propthistrack = kTRUE;
156     }
157     if (propthistrack)
158       AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(newt,fDist);
159
160     Int_t label = 0;
161     if (fIsMC) {
162       if (fUseNegativeLabels)
163         label = track->GetLabel();
164       else 
165         label = TMath::Abs(track->GetLabel());
166       if (label == 0) 
167         AliDebug(2,Form("Track %d with label==0", iTracks));
168     }
169     if (type==0) {
170       newt->SetBit(BIT(22),0);
171       newt->SetBit(BIT(23),0);
172     } else if (type==1) {
173       newt->SetBit(BIT(22),1);
174       newt->SetBit(BIT(23),0);
175     } else if (type==2) {
176       newt->SetBit(BIT(22),0);
177       newt->SetBit(BIT(23),1);
178     } else if (type==3) {
179       newt->SetBit(BIT(22),1);
180       newt->SetBit(BIT(23),1);
181     }
182     ++nacc;
183   }
184 }