macro dir
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliEmcalMCTrackSelector.cxx
CommitLineData
578adbef 1// $Id$
2//
3// Class to select tracks in MC events.
4//
5// Author: S. Aiola
6
7#include "AliEmcalMCTrackSelector.h"
8
9#include <TClonesArray.h>
10
11#include "AliAnalysisManager.h"
12#include "AliVEvent.h"
13#include "AliMCEvent.h"
14#include "AliVParticle.h"
15#include "AliLog.h"
16
17ClassImp(AliEmcalMCTrackSelector)
18
19//________________________________________________________________________
20AliEmcalMCTrackSelector::AliEmcalMCTrackSelector() :
21 AliAnalysisTaskSE("AliEmcalMCTrackSelector"),
22 fTracksOutName("PicoTracks"),
23 fRejectNK(kFALSE),
24 fChargedMC(kFALSE),
25 fTracksOut(0)
26{
27 // Constructor.
28}
29
30//________________________________________________________________________
31AliEmcalMCTrackSelector::AliEmcalMCTrackSelector(const char *name) :
32 AliAnalysisTaskSE(name),
33 fTracksOutName("PicoTracks"),
34 fRejectNK(kFALSE),
35 fChargedMC(kFALSE),
36 fTracksOut(0)
37{
38 // Constructor.
39}
40
41//________________________________________________________________________
42AliEmcalMCTrackSelector::~AliEmcalMCTrackSelector()
43{
44 // Destructor.
45}
46
47//________________________________________________________________________
48void AliEmcalMCTrackSelector::UserCreateOutputObjects()
49{
50 // Create my user objects.
51
52 fTracksOut = new TClonesArray("AliMCParticle");
53 fTracksOut->SetName(fTracksOutName);
54}
55
56//________________________________________________________________________
57void AliEmcalMCTrackSelector::UserExec(Option_t *)
58{
59 // Main loop, called for each event.
60
61 AliMCEvent *mcevent = MCEvent();
62 AliVEvent *event = InputEvent();
63
64 if (!event) {
65 AliError("Could not retrieve event! Returning");
66 return;
67 }
68
69 if (!mcevent) {
70 AliError("Could not retrieve MC event! Returning");
71 return;
72 }
73
74 // add tracks to event if not yet there
75 if (!(event->FindListObject(fTracksOutName))) {
76 event->AddObject(fTracksOut);
77 }
78
79 // clear container (normally a null operation as the event should clean it already)
80 fTracksOut->Clear();
81
82 // loop over tracks
83 const Int_t Ntracks = mcevent->GetNumberOfTracks();
84 for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) {
85
86 if (!mcevent->IsPhysicalPrimary(iTracks))
87 continue;
88
89 AliMCParticle* track = dynamic_cast<AliMCParticle*>(mcevent->GetTrack(iTracks));
90
91 if (!track)
92 continue;
93
94 if (TMath::Abs(track->Eta()) > 1)
95 continue;
96
97 Int_t pdgCode = track->PdgCode();
98 if (fRejectNK && (pdgCode == 130 || pdgCode == 2112)) continue;
99
100 if (fChargedMC && track->Charge() == 0) continue;
101
102 new ((*fTracksOut)[nacc]) AliMCParticle(track->Particle(), 0, track->Label());
103 ++nacc;
104 }
105}