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