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