protections against failures in deleting event content
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalPicoTrackMaker.cxx
CommitLineData
980821ba 1// $Id$
680855e5 2//
3// Class to make PicoTracks in AOD/ESD events.
4//
cd231d42 5// Author: S.Aiola, C.Loizides
680855e5 6
7#include <TClonesArray.h>
11d18b51 8#include <TRandom3.h>
9
a070db7d 10#include "AliAODEvent.h"
680855e5 11#include "AliAODTrack.h"
a070db7d 12#include "AliAnalysisManager.h"
680855e5 13#include "AliESDtrack.h"
14#include "AliESDtrackCuts.h"
15#include "AliLog.h"
a070db7d 16#include "AliPicoTrack.h"
17#include "AliVTrack.h"
680855e5 18#include "AliEmcalPicoTrackMaker.h"
19
20ClassImp(AliEmcalPicoTrackMaker)
21
22//________________________________________________________________________
23AliEmcalPicoTrackMaker::AliEmcalPicoTrackMaker() :
24 AliAnalysisTaskSE("AliEmcalPicoTrackMaker"),
25 fESDtrackCuts(0),
26 fTracksOutName("PicoTracks"),
27 fTracksInName("tracks"),
9733b37f 28 fMinTrackPt(0),
11d18b51 29 fMaxTrackPt(1000),
9733b37f 30 fMinTrackEta(-0.9),
31 fMaxTrackEta(0.9),
32 fMinTrackPhi(-10),
33 fMaxTrackPhi(10),
11d18b51 34 fTrackEfficiency(1),
680855e5 35 fTracksIn(0),
36 fTracksOut(0)
37{
38 // Constructor.
ab292aef 39
1187666b 40 fAODfilterBits[0] = -1;
41 fAODfilterBits[1] = -1;
680855e5 42}
43
44//________________________________________________________________________
45AliEmcalPicoTrackMaker::AliEmcalPicoTrackMaker(const char *name) :
a070db7d 46 AliAnalysisTaskSE(name),
680855e5 47 fESDtrackCuts(0),
48 fTracksOutName("PicoTracks"),
49 fTracksInName("tracks"),
9733b37f 50 fMinTrackPt(0),
11d18b51 51 fMaxTrackPt(1000),
9733b37f 52 fMinTrackEta(-0.9),
53 fMaxTrackEta(0.9),
54 fMinTrackPhi(-10),
55 fMaxTrackPhi(10),
11d18b51 56 fTrackEfficiency(1),
680855e5 57 fTracksIn(0),
58 fTracksOut(0)
59{
60 // Constructor.
61
1187666b 62 fAODfilterBits[0] = -1;
63 fAODfilterBits[1] = -1;
680855e5 64 fBranchNames = "ESD:AliESDHeader.,AliESDRun.,SPDVertex.,Tracks";
65}
66
67//________________________________________________________________________
68AliEmcalPicoTrackMaker::~AliEmcalPicoTrackMaker()
69{
a070db7d 70 // Destructor.
680855e5 71}
72
73//________________________________________________________________________
74void AliEmcalPicoTrackMaker::UserCreateOutputObjects()
75{
a070db7d 76 // Create my user objects.
680855e5 77
78 fTracksOut = new TClonesArray("AliPicoTrack");
79 fTracksOut->SetName(fTracksOutName);
80}
81
82//________________________________________________________________________
83void 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
a070db7d 93 // retrieve tracks from input.
e44e8726 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 }
a070db7d 104 }
105
106 // add tracks to event if not yet there
71c1dd76 107 fTracksOut->Delete();
c4a9715d 108 if (!(InputEvent()->FindListObject(fTracksOutName))) {
680855e5 109 InputEvent()->AddObject(fTracksOut);
c4a9715d 110 }
c4a9715d 111
a070db7d 112 // clear container (normally a null operation as the event should clean it already)
113 fTracksOut->Clear();
680855e5 114
a070db7d 115 // test if we are in ESD or AOD mode
116 Bool_t esdMode = kTRUE;
117 if (dynamic_cast<AliAODEvent*>(InputEvent())!=0)
118 esdMode = kFALSE;
119
120 // loop over tracks
121 const Int_t Ntracks = fTracksIn->GetEntriesFast();
680855e5 122 for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
85fbcc1d 123
e44e8726 124 AliVTrack *track = static_cast<AliVTrack*>(fTracksIn->At(iTracks));
85fbcc1d 125
a070db7d 126 if (!track)
680855e5 127 continue;
85fbcc1d 128
9733b37f 129 if (track->Pt() > fMaxTrackPt || track->Pt() < fMinTrackPt)
130 continue;
131
132 if (track->Eta() < fMinTrackEta || track->Eta() > fMaxTrackEta ||
133 track->Phi() < fMinTrackPhi || track->Phi() > fMaxTrackPhi)
85fbcc1d 134 continue;
11d18b51 135
376d84a3 136 Bool_t isEmc = kFALSE;
c4a9715d 137 Int_t label = -1;
a070db7d 138 if (esdMode) {
139 if (fESDtrackCuts) {
140 AliESDtrack *esdtrack = static_cast<AliESDtrack*>(track);
141 if (!fESDtrackCuts->AcceptTrack(esdtrack))
142 continue;
143 }
144 label = track->GetLabel();
376d84a3 145 isEmc = track->IsEMCAL();
a070db7d 146 } else {
147 AliAODTrack *aodtrack = static_cast<AliAODTrack*>(track);
1187666b 148 if (fAODfilterBits[0] < 0) {
149 if (aodtrack->IsHybridGlobalConstrainedGlobal())
150 label = 3;
151 else /*not a good track*/
152 continue;
153 }
154 else {
155 if (aodtrack->TestFilterBit(fAODfilterBits[0]))
156 label = 0;
157 else if (aodtrack->TestFilterBit(fAODfilterBits[1]))
158 label = 3;
159 else /*not a good track*/
160 continue;
161 }
376d84a3 162
163 if (TMath::Abs(track->GetTrackEtaOnEMCal()) < 0.75 &&
164 track->GetTrackPhiOnEMCal() > 70 * TMath::DegToRad() &&
165 track->GetTrackPhiOnEMCal() < 190 * TMath::DegToRad())
166 isEmc = kTRUE;
680855e5 167 }
168
11d18b51 169 if (fTrackEfficiency < 1) {
170 Double_t r = gRandom->Rndm();
171 if (fTrackEfficiency < r)
172 continue;
173 }
174
5cb6a7e6 175 /*AliPicoTrack *picotrack =*/ new ((*fTracksOut)[nacc]) AliPicoTrack(track->Pt(),
a070db7d 176 track->Eta(),
177 track->Phi(),
178 track->Charge(),
179 label,
180 track->GetTrackEtaOnEMCal(),
181 track->GetTrackPhiOnEMCal(),
376d84a3 182 isEmc);
680855e5 183 ++nacc;
184 }
185}