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