b486000878b749ec03cd9aaff26f6439856b2176
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AlidNdEtaAnalysisMCSelector.cxx
1 /* $Id$ */
2
3 #include "AlidNdEtaAnalysisMCSelector.h"
4
5 #include <TStyle.h>
6 #include <TSystem.h>
7 #include <TCanvas.h>
8 #include <TParticle.h>
9 #include <TParticlePDG.h>
10 #include <TVector3.h>
11 #include <TH3F.h>
12 #include <TTree.h>
13
14 #include <AliLog.h>
15 #include <AliGenEventHeader.h>
16 #include <AliHeader.h>
17
18 #include "dNdEtaAnalysis.h"
19
20
21 ClassImp(AlidNdEtaAnalysisMCSelector)
22
23 AlidNdEtaAnalysisMCSelector::AlidNdEtaAnalysisMCSelector() :
24   AlidNdEtaAnalysisSelector(),
25   fVertex(0)
26 {
27   //
28   // Constructor. Initialization of pointers
29   //
30 }
31
32 AlidNdEtaAnalysisMCSelector::~AlidNdEtaAnalysisMCSelector()
33 {
34   //
35   // Destructor
36   //
37 }
38
39 void AlidNdEtaAnalysisMCSelector::Init(TTree *tree)
40 {
41    AlidNdEtaAnalysisSelector::Init(tree);
42
43   tree->SetBranchStatus("ESD", 0);
44
45   fVertex = new TH3F("vertex", "vertex", 50, -50, 50, 50, -50, 50, 50, -50, 50);
46 }
47
48 Bool_t AlidNdEtaAnalysisMCSelector::Process(Long64_t entry)
49 {
50   //
51
52   if (AliSelector::Process(entry) == kFALSE)
53     return kFALSE;
54
55   TTree* particleTree = GetKinematics();
56   if (!particleTree)
57   {
58     AliDebug(AliLog::kError, "Kinematics not available");
59     return kFALSE;
60   }
61
62   AliHeader* header = GetHeader();
63   if (!header)
64   {
65     AliDebug(AliLog::kError, "Header not available");
66     return kFALSE;
67   }
68
69   // get the MC vertex
70   AliGenEventHeader* genHeader = header->GenEventHeader();
71
72   TArrayF vtxMC(3);
73   genHeader->PrimaryVertex(vtxMC);
74
75   particleTree->SetBranchStatus("*", 0);
76   particleTree->SetBranchStatus("fDaughter[2]", 1);
77   particleTree->SetBranchStatus("fPdgCode", 1);
78   particleTree->SetBranchStatus("fPx", 1);
79   particleTree->SetBranchStatus("fPy", 1);
80   particleTree->SetBranchStatus("fPz", 1);
81   particleTree->SetBranchStatus("fVx", 1);
82   particleTree->SetBranchStatus("fVy", 1);
83   particleTree->SetBranchStatus("fVz", 1);
84
85   TParticle* particle = 0;
86   particleTree->SetBranchAddress("Particles", &particle);
87
88   Int_t nPrim  = header->GetNprimary();
89   Int_t nTotal = header->GetNtrack();
90
91   for (Int_t i_mc = nTotal - nPrim; i_mc < nTotal; ++i_mc)
92   {
93     particleTree->GetEntry(i_mc);
94
95     if (!particle)
96       continue;
97
98     if (IsPrimaryCharged(particle, nPrim) == kFALSE)
99       continue;
100
101     AliDebug(AliLog::kDebug+1, Form("Accepted primary %d, unique ID: %d", i_mc, particle->GetUniqueID()));
102
103     fdNdEtaAnalysis->FillTrack(vtxMC[2], particle->Eta(), 1);
104     fVertex->Fill(particle->Vx(), particle->Vy(), particle->Vz());
105   }
106   fdNdEtaAnalysis->FillEvent(vtxMC[2]);
107
108   return kTRUE;
109 }
110
111 void AlidNdEtaAnalysisMCSelector::Terminate()
112 {
113   AlidNdEtaAnalysisSelector::Terminate();
114
115   new TCanvas;
116   fVertex->Draw();
117 }