]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/dNdEta/AlidNdEtaVertexRecEffSelector.cxx
fixed the way the event bias selection is done
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AlidNdEtaVertexRecEffSelector.cxx
CommitLineData
182d3a2e 1/* $Id$ */
2
3#include "AlidNdEtaVertexRecEffSelector.h"
4
5#include <TCanvas.h>
6#include <TH1F.h>
7#include <TTree.h>
8#include <TParticle.h>
9#include <TFile.h>
10
11#include <AliLog.h>
12#include <AliGenEventHeader.h>
13#include <AliHeader.h>
14#include <AliESD.h>
15#include <AliESDVertex.h>
16
17//
18// This class plots the vertex reconstruction efficiency
19// If a vertex was reconstructed is decided by the function CheckVertex()
20// In any case the *generated* multiplicity is filled into the histogram
21//
22
23ClassImp(AlidNdEtaVertexRecEffSelector)
24
25const Float_t AlidNdEtaVertexRecEffSelector::fkEtaRange = 0.9;
26
27AlidNdEtaVertexRecEffSelector::AlidNdEtaVertexRecEffSelector() :
28 AliSelector(),
29 fdNGen(0),
30 fdNRec(0),
31 fVtxGen(0),
32 fVtxRec(0)
33{
34 //
35 // Constructor. Initialization of pointers
36 //
37}
38
39AlidNdEtaVertexRecEffSelector::~AlidNdEtaVertexRecEffSelector()
40{
41 //
42 // Destructor
43 //
44
45 // histograms are in the output list and deleted when the output
46 // list is deleted by the TSelector dtor
47}
48
49void AlidNdEtaVertexRecEffSelector::SlaveBegin(TTree * tree)
50{
51 // initializes the histograms
52
53 AliSelector::SlaveBegin(tree);
54
55 fdNGen = new TH1F("dNGen", "dNGen", 90, 0, 50);
56 fdNRec = dynamic_cast<TH1F*>(fdNGen->Clone("dNRec"));
57
58 fdNGen->SetTitle("Generated Events;dN_{Gen};Count");
59 fdNRec->SetTitle("Events with reconstructed vertex;dN_{Gen};Count");
60
61 fVtxGen = new TH1F("VtxGen", "VtxGen", 200, -20, 20);
62 fVtxRec = dynamic_cast<TH1F*>(fVtxGen->Clone("VtxRec"));
63}
64
65Bool_t AlidNdEtaVertexRecEffSelector::CheckVertex()
66{
67 //
68 // check if the vertex has been reconstructed well enough
69 //
70 if (!fESD)
71 return kFALSE;
72
73 const AliESDVertex* vtxESD = fESD->GetVertex();
74
75 // the vertex should be reconstructed
76 if (strcmp(vtxESD->GetName(),"default")==0)
77 return kFALSE;
78
79 Double_t vtxRes[3];
80 vtxRes[0] = vtxESD->GetXRes();
81 vtxRes[1] = vtxESD->GetYRes();
82 vtxRes[2] = vtxESD->GetZRes();
83
84 // the resolution should be reasonable???
85 if (vtxRes[2]==0 || vtxRes[2]>0.1)
86 return kFALSE;
87
88 return kTRUE;
89}
90
91Bool_t AlidNdEtaVertexRecEffSelector::Process(Long64_t entry)
92{
93 //
94 // fills fdNGen and fdNRec
95 //
96
97 if (AliSelector::Process(entry) == kFALSE)
98 return kFALSE;
99
100 // check prerequisites
101 if (!fESD)
102 {
103 AliDebug(AliLog::kError, "ESD branch not available");
104 return kFALSE;
105 }
106
107 AliHeader* header = GetHeader();
108 if (!header)
109 {
110 AliDebug(AliLog::kError, "Header not available");
111 return kFALSE;
112 }
113
114
115 // loop over mc particles
116 TTree* particleTree = GetKinematics();
117 TParticle* particle = 0;
118 particleTree->SetBranchAddress("Particles", &particle);
119
120 Int_t nPrim = header->GetNprimary();
121 Int_t nTotal = header->GetNtrack();
122
123 Int_t n = 0;
124
125 for (Int_t iMc = nTotal - nPrim; iMc < nTotal; ++iMc)
126 {
127 particleTree->GetEntry(iMc);
128
129 if (!particle)
130 continue;
131
132 if (IsPrimaryCharged(particle, nPrim) == kFALSE)
133 continue;
134
135 if (TMath::Abs(particle->Eta()) < fkEtaRange)
136 ++n;
137 }// end of mc particle
138
139 Float_t dN = (Float_t) n / (fkEtaRange*2);
140
141 fdNGen->Fill(dN);
142
143 // check vertex reconstruction
144 if (CheckVertex() != kFALSE)
145 fdNRec->Fill(dN);
146
147 AliGenEventHeader* genHeader = header->GenEventHeader();
148
149 TArrayF vtxMC(3);
150 genHeader->PrimaryVertex(vtxMC);
151
152 fVtxGen->Fill(vtxMC[2]);
153
154 if (CheckVertex() != kFALSE)
155 fVtxRec->Fill(vtxMC[2]);
156
157 return kTRUE;
158}
159
160void AlidNdEtaVertexRecEffSelector::SlaveTerminate()
161{
162 // The SlaveTerminate() function is called after all entries or objects
163 // have been processed. When running with PROOF SlaveTerminate() is called
164 // on each slave server.
165
166 AliSelector::SlaveTerminate();
167
168 // Add the histograms to the output on each slave server
169 if (!fOutput)
170 {
171 AliDebug(AliLog::kError, "ERROR: Output list not initialized");
172 return;
173 }
174
175 fOutput->Add(fdNGen);
176 fOutput->Add(fdNRec);
177 fOutput->Add(fVtxGen);
178 fOutput->Add(fVtxRec);
179}
180
181void AlidNdEtaVertexRecEffSelector::Terminate()
182{
183 // The Terminate() function is the last function to be called during
184 // a query. It always runs on the client, it can be used to present
185 // the results graphically or save the results to file.
186
187 AliSelector::Terminate();
188
189 if (!fOutput)
190 {
191 AliDebug(AliLog::kError, "ERROR: Output list not initialized");
192 return;
193 }
194
195 fdNGen = dynamic_cast<TH1F*> (fOutput->FindObject("dNGen"));
196 fdNRec = dynamic_cast<TH1F*> (fOutput->FindObject("dNRec"));
197 fVtxGen = dynamic_cast<TH1F*> (fOutput->FindObject("VtxGen"));
198 fVtxRec = dynamic_cast<TH1F*> (fOutput->FindObject("VtxRec"));
199 if (!fdNGen || !fdNRec || !fVtxGen || !fVtxRec)
200 {
201 AliDebug(AliLog::kError, Form("ERROR: Histograms not available %p %p %p %p", (void*) fdNGen, (void*) fdNRec, (void*) fVtxGen, (void*) fVtxRec));
202 return;
203 }
204
205 TFile* fout = new TFile("vertexRecEff.root","RECREATE");
206
207 fdNGen->Write();
208 fdNRec->Write();
209
210 fVtxGen->Write();
211 fVtxRec->Write();
212
213 fout->Write();
214 fout->Close();
215
216 TCanvas* canvas = new TCanvas("dN", "dN", 900, 450);
217 canvas->Divide(2, 1);
218
219 canvas->cd(1);
220 fdNGen->Draw();
221 fdNRec->SetLineColor(kRed);
222 fdNRec->Draw("SAME");
223
224 canvas->cd(2);
225 fVtxGen->Draw();
226 fVtxRec->SetLineColor(kRed);
227 fVtxRec->Draw("SAME");
228}