]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/dNdEta/dNdEtaAnalysis.cxx
Record changes.
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / dNdEtaAnalysis.cxx
CommitLineData
dc740de4 1/* $Id$ */
2
75ec0f41 3#include "dNdEtaAnalysis.h"
4
ceb5d1b5 5#include <TFile.h>
45e97e28 6#include <TH3F.h>
847489f7 7#include <TH2D.h>
ceb5d1b5 8#include <TH1D.h>
9#include <TMath.h>
10#include <TCanvas.h>
7029240a 11#include <TCollection.h>
12#include <TIterator.h>
13#include <TList.h>
fcf2fb36 14#include <TLegend.h>
15
45e97e28 16#include "AlidNdEtaCorrection.h"
847489f7 17#include "AliPWG0Helper.h"
ceb5d1b5 18
75ec0f41 19//____________________________________________________________________
b7f4a1fd 20ClassImp(dNdEtaAnalysis)
75ec0f41 21
1afae8ff 22//____________________________________________________________________
23dNdEtaAnalysis::dNdEtaAnalysis() :
24 TNamed(),
25 fData(0),
26 fDataUncorrected(0),
27 fVtx(0),
28 fPtDist(0)
29{
30 // default constructor
31
32 for (Int_t i=0; i<kVertexBinning; ++i)
33 {
34 fdNdEta[i] = 0;
35 fdNdEtaPtCutOffCorrected[i] = 0;
36 }
37}
38
75ec0f41 39//____________________________________________________________________
7029240a 40dNdEtaAnalysis::dNdEtaAnalysis(Char_t* name, Char_t* title) :
16e24ca3 41 TNamed(name, title),
45e97e28 42 fData(0),
43 fDataUncorrected(0),
1afae8ff 44 fVtx(0),
45 fPtDist(0)
7029240a 46{
6bf0714d 47 // constructor
4dd2ad81 48
1afae8ff 49 fData = new TH3F(Form("%s_analysis", name),"Input data",80,-20,20,120,-6,6,100, 0, 10);
45e97e28 50 fData->SetXTitle("vtx z [cm]");
51 fData->SetYTitle("#eta");
52 fData->SetZTitle("p_{T}");
6bf0714d 53
45e97e28 54 fDataUncorrected = dynamic_cast<TH3F*> (fData->Clone(Form("%s_analysis_uncorrected", name)));
1afae8ff 55 fDataUncorrected->SetTitle(Form("%s uncorrected", fData->GetTitle()));
45e97e28 56 fVtx = dynamic_cast<TH1D*> (fData->Project3D("x"));
1afae8ff 57 fVtx->SetName(Form("%s_vtx", name));
58 fVtx->SetTitle("Vertex distribution");
59 fVtx->GetXaxis()->SetTitle(fData->GetXaxis()->GetTitle());
45e97e28 60
61 fdNdEta[0] = dynamic_cast<TH1D*> (fData->Project3D("y"));
1afae8ff 62 fdNdEta[0]->SetName(Form("%s_dNdEta", name));
63 fdNdEta[0]->SetTitle("dN/d#eta");
64 fdNdEta[0]->GetXaxis()->SetTitle(fData->GetYaxis()->GetTitle());
65 fdNdEta[0]->SetYTitle("dN/d#eta");
66
67 fdNdEtaPtCutOffCorrected[0] = dynamic_cast<TH1D*> (fdNdEta[0]->Clone(Form("%s_corrected", fdNdEta[0]->GetName())));
68
45e97e28 69 for (Int_t i=1; i<kVertexBinning; ++i)
7029240a 70 {
45e97e28 71 fdNdEta[i] = dynamic_cast<TH1D*> (fdNdEta[0]->Clone(Form("%s_%d", fdNdEta[0]->GetName(), i)));
1afae8ff 72 fdNdEtaPtCutOffCorrected[i] = dynamic_cast<TH1D*> (fdNdEtaPtCutOffCorrected[0]->Clone(Form("%s_%d", fdNdEtaPtCutOffCorrected[0]->GetName(), i)));
7029240a 73 }
75ec0f41 74
1afae8ff 75 fPtDist = dynamic_cast<TH1D*> (fData->Project3D("z"));
76 fPtDist->SetName(Form("%s_pt", name));
77 fPtDist->SetTitle("p_{T}");
78 fPtDist->GetXaxis()->SetTitle(fData->GetZaxis()->GetTitle());
79 fPtDist->SetYTitle("#frac{1}{p_{T}} #frac{dN}{d#eta dp_{T}}");
80
45e97e28 81 fData->Sumw2();
6bf0714d 82 fVtx->Sumw2();
75ec0f41 83}
84
16e24ca3 85//____________________________________________________________________
86dNdEtaAnalysis::~dNdEtaAnalysis()
87{
88 // destructor
89
45e97e28 90 delete fData;
91 fData = 0;
16e24ca3 92
45e97e28 93 delete fDataUncorrected;
94 fDataUncorrected = 0;
16e24ca3 95
96 delete fVtx;
97 fVtx = 0;
98
99 for (Int_t i=0; i<kVertexBinning; ++i)
100 {
101 delete fdNdEta[i];
102 fdNdEta[i] = 0;
1afae8ff 103 delete fdNdEtaPtCutOffCorrected[i];
104 fdNdEtaPtCutOffCorrected[i] = 0;
16e24ca3 105 }
1afae8ff 106
107 delete fPtDist;
108 fPtDist = 0;
16e24ca3 109}
110
111//_____________________________________________________________________________
112dNdEtaAnalysis::dNdEtaAnalysis(const dNdEtaAnalysis &c) :
113 TNamed(c),
45e97e28 114 fData(0),
115 fDataUncorrected(0),
1afae8ff 116 fVtx(0),
117 fPtDist(0)
16e24ca3 118{
119 //
120 // dNdEtaAnalysis copy constructor
121 //
122
123 ((dNdEtaAnalysis &) c).Copy(*this);
124}
125
126//_____________________________________________________________________________
127dNdEtaAnalysis &dNdEtaAnalysis::operator=(const dNdEtaAnalysis &c)
128{
129 //
130 // Assignment operator
131 //
132
133 if (this != &c) ((dNdEtaAnalysis &) c).Copy(*this);
134 return *this;
135}
136
137//_____________________________________________________________________________
138void dNdEtaAnalysis::Copy(TObject &c) const
139{
140 //
141 // Copy function
142 //
143
144 dNdEtaAnalysis& target = (dNdEtaAnalysis &) c;
145
45e97e28 146 target.fData = dynamic_cast<TH3F*> (fData->Clone());
147 target.fDataUncorrected = dynamic_cast<TH3F*> (fDataUncorrected->Clone());
16e24ca3 148 target.fVtx = dynamic_cast<TH1D*> (fVtx->Clone());
149
150 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 151 {
16e24ca3 152 target.fdNdEta[i] = dynamic_cast<TH1D*> (fdNdEta[i]->Clone());
1afae8ff 153 target.fdNdEtaPtCutOffCorrected[i] = dynamic_cast<TH1D*> (fdNdEtaPtCutOffCorrected[i]->Clone());
154 }
16e24ca3 155
1afae8ff 156 target.fPtDist = dynamic_cast<TH1D*> (fPtDist->Clone());
45e97e28 157
16e24ca3 158 TNamed::Copy((TNamed &) c);
159}
160
75ec0f41 161//____________________________________________________________________
45e97e28 162void dNdEtaAnalysis::FillTrack(Float_t vtx, Float_t eta, Float_t pt, Float_t weight)
6bf0714d 163{
164 // fills a track into the histograms
165
45e97e28 166 fDataUncorrected->Fill(vtx, eta, pt);
167 fData->Fill(vtx, eta, pt, weight);
75ec0f41 168}
169
170//____________________________________________________________________
45e97e28 171void dNdEtaAnalysis::FillEvent(Float_t vtx, Float_t weight)
6bf0714d 172{
173 // fills an event into the histograms
174
847489f7 175 fVtx->Fill(vtx, weight);
75ec0f41 176}
177
178//____________________________________________________________________
847489f7 179void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut)
fcf2fb36 180{
181 // correct with correction values if available
6bf0714d 182
fcf2fb36 183 // TODO what do we do with the error?
184 if (!correction)
185 printf("INFO: No correction applied\n");
186
847489f7 187 // In fData we have the track2particle and vertex reconstruction efficiency correction already applied
fcf2fb36 188
1afae8ff 189
190 // create pt hist
191 {
192 // reset all ranges
193 fData->GetXaxis()->SetRange(0, 0);
194 fData->GetYaxis()->SetRange(0, 0);
195 fData->GetZaxis()->SetRange(0, 0);
196
197 // vtx cut
198 Int_t vertexBinBegin = fData->GetXaxis()->FindBin(-5);
199 Int_t vertexBinEnd = fData->GetXaxis()->FindBin(5);
200 fData->GetXaxis()->SetRange(vertexBinBegin, vertexBinEnd);
201 Float_t nEvents = fVtx->Integral(vertexBinBegin, vertexBinEnd);
202
203 // eta cut
204 fData->GetYaxis()->SetRange(fData->GetYaxis()->FindBin(-0.8), fData->GetYaxis()->FindBin(0.8));
205 Float_t etaWidth = 1.6;
206
207 TH1D* ptHist = dynamic_cast<TH1D*> (fData->Project3D("ze"));
208
209 for (Int_t i=1; i<=fPtDist->GetNbinsX(); ++i)
210 {
211 Float_t binSize = fPtDist->GetBinWidth(i);
212 fPtDist->SetBinContent(i, ptHist->GetBinContent(i) / binSize / nEvents / etaWidth);
213 fPtDist->SetBinError(i, ptHist->GetBinError(i) / binSize / nEvents / etaWidth);
214 }
215
216 delete ptHist;
217 }
218
219 // reset all ranges
220 fData->GetXaxis()->SetRange(0, 0);
221 fData->GetYaxis()->SetRange(0, 0);
222 fData->GetZaxis()->SetRange(0, 0);
223
847489f7 224 // integrate over pt (with pt cut)
1afae8ff 225 Int_t ptLowBin = 1;
226 if (ptCut > 0)
227 ptLowBin = fData->GetZaxis()->FindBin(ptCut);
228
229 fData->GetZaxis()->SetRange(ptLowBin, fData->GetZaxis()->GetNbins());
230 TH2D* vtxVsEta = dynamic_cast<TH2D*> (fData->Project3D("yx2e"));
231 vtxVsEta->GetXaxis()->SetTitle(fData->GetXaxis()->GetTitle());
232 vtxVsEta->GetYaxis()->SetTitle(fData->GetYaxis()->GetTitle());
233
847489f7 234 if (vtxVsEta == 0)
235 {
236 printf("ERROR: pt integration failed\n");
237 return;
fcf2fb36 238 }
239
847489f7 240 new TCanvas;
241 vtxVsEta->Draw("COLZ");
242
243 for (Int_t iEta=0; iEta<=vtxVsEta->GetNbinsY(); iEta++)
5af55649 244 {
7029240a 245 // do we have several histograms for different vertex positions?
6bf0714d 246 Int_t vertexBinWidth = fVtx->GetNbinsX() / (kVertexBinning-1);
7029240a 247 for (Int_t vertexPos=0; vertexPos<kVertexBinning; ++vertexPos)
248 {
5af55649 249 Int_t vertexBinBegin = 1;
6bf0714d 250 Int_t vertexBinEnd = fVtx->GetNbinsX() + 1;
fcf2fb36 251
252 // the first histogram is always for the whole vertex range
253 if (vertexPos > 0)
254 {
5af55649 255 vertexBinBegin = 1 + vertexBinWidth * (vertexPos-1);
fcf2fb36 256 vertexBinEnd = vertexBinBegin + vertexBinWidth;
257 }
7029240a 258
6bf0714d 259 Float_t totalEvents = fVtx->Integral(vertexBinBegin, vertexBinEnd - 1);
5af55649 260 if (totalEvents == 0)
261 {
262 printf("WARNING: No events for hist %d %d %d\n", vertexPos, vertexBinBegin, vertexBinEnd);
263 continue;
7029240a 264 }
7029240a 265
5af55649 266 Float_t sum = 0;
267 Float_t sumError2 = 0;
268 for (Int_t iVtx = vertexBinBegin; iVtx < vertexBinEnd; iVtx++)
269 {
847489f7 270 if (vtxVsEta->GetBinContent(iVtx, iEta) != 0)
5af55649 271 {
847489f7 272 sum = sum + vtxVsEta->GetBinContent(iVtx, iEta);
273 sumError2 = sumError2 + TMath::Power(vtxVsEta->GetBinError(iVtx, iEta),2);
5af55649 274 }
275 }
7029240a 276
1afae8ff 277 Float_t ptCutOffCorrection = 1;
278 if (correction)
279 ptCutOffCorrection = correction->GetMeasuredFraction(ptCut, vtxVsEta->GetYaxis()->GetBinCenter(iEta));
280
847489f7 281 if (ptCutOffCorrection <= 0)
282 {
283 printf("UNEXPECTED: ptCutOffCorrection is %f for hist %d %d %d\n", ptCutOffCorrection, vertexPos, vertexBinBegin, vertexBinEnd);
284 continue;
285 }
286
1afae8ff 287 Float_t dndeta = sum / totalEvents;
288 Float_t error = TMath::Sqrt(sumError2) / totalEvents;
7029240a 289
6bf0714d 290 dndeta = dndeta/fdNdEta[vertexPos]->GetBinWidth(iEta);
291 error = error/fdNdEta[vertexPos]->GetBinWidth(iEta);
7029240a 292
6bf0714d 293 fdNdEta[vertexPos]->SetBinContent(iEta, dndeta);
294 fdNdEta[vertexPos]->SetBinError(iEta, error);
1afae8ff 295
296 dndeta /= ptCutOffCorrection;
297 error /= ptCutOffCorrection;
298
299 fdNdEtaPtCutOffCorrected[vertexPos]->SetBinContent(iEta, dndeta);
300 fdNdEtaPtCutOffCorrected[vertexPos]->SetBinError(iEta, error);
75ec0f41 301 }
847489f7 302 }
75ec0f41 303}
304
75ec0f41 305//____________________________________________________________________
6bf0714d 306void dNdEtaAnalysis::SaveHistograms()
307{
308 // save the histograms to a directory with the name of this class (retrieved from TNamed)
75ec0f41 309
7029240a 310 gDirectory->mkdir(GetName());
311 gDirectory->cd(GetName());
5fbd0b17 312
1afae8ff 313 if (fData)
314 {
315 fData->Write();
316 AliPWG0Helper::CreateProjections(fData);
317 }
318 else
319 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fData is 0\n");
320
321 if (fDataUncorrected)
322 {
323 fDataUncorrected->Write();
324 AliPWG0Helper::CreateProjections(fDataUncorrected);
325 }
326 else
327 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fDataUncorrected is 0\n");
328
329 if (fData)
330 fVtx ->Write();
331 else
332 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fVtx is 0\n");
847489f7 333
7029240a 334 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 335 {
336 if (fdNdEta[i])
337 fdNdEta[i]->Write();
338 else
339 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fdNdEta[%d] is 0\n", i);
340
341 if (fdNdEtaPtCutOffCorrected[i])
342 fdNdEtaPtCutOffCorrected[i]->Write();
343 else
344 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fdNdEtaPtCutOffCorrected[%d] is 0\n", i);
345 }
75ec0f41 346
347 gDirectory->cd("../");
348}
349
5fbd0b17 350void dNdEtaAnalysis::LoadHistograms()
351{
6bf0714d 352 // loads the histograms from a directory with the name of this class (retrieved from TNamed)
353
5fbd0b17 354 gDirectory->cd(GetName());
355
45e97e28 356 fData = dynamic_cast<TH3F*> (gDirectory->Get(fData->GetName()));
357 fDataUncorrected = dynamic_cast<TH3F*> (gDirectory->Get(fDataUncorrected->GetName()));
5fbd0b17 358
6bf0714d 359 fVtx = dynamic_cast<TH1D*> (gDirectory->Get(fVtx->GetName()));
5fbd0b17 360
361 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 362 {
6bf0714d 363 fdNdEta[i] = dynamic_cast<TH1D*> (gDirectory->Get(fdNdEta[i]->GetName()));
1afae8ff 364 fdNdEtaPtCutOffCorrected[i] = dynamic_cast<TH1D*> (gDirectory->Get(fdNdEtaPtCutOffCorrected[i]->GetName()));
365 }
5fbd0b17 366
367 gDirectory->cd("../");
368}
369
ceb5d1b5 370//____________________________________________________________________
371void dNdEtaAnalysis::DrawHistograms()
372{
6bf0714d 373 // draws the histograms
374
5fbd0b17 375 TCanvas* canvas = new TCanvas("dNdEtaAnalysis", "dNdEtaAnalysis", 800, 800);
376 canvas->Divide(2, 2);
ceb5d1b5 377
378 canvas->cd(1);
45e97e28 379 if (fData)
380 fData->Draw("COLZ");
ceb5d1b5 381
1afae8ff 382 /*canvas->cd(2);
45e97e28 383 if (fDataUncorrected)
1afae8ff 384 fDataUncorrected->Draw("COLZ");*/
ceb5d1b5 385
1afae8ff 386 canvas->cd(2);
6bf0714d 387 if (fVtx)
388 fVtx->Draw();
ceb5d1b5 389
1afae8ff 390 canvas->cd(3);
391 if (fdNdEtaPtCutOffCorrected[0])
392 fdNdEtaPtCutOffCorrected[0]->Draw();
393
6bf0714d 394 if (fdNdEta[0])
1afae8ff 395 {
396 fdNdEta[0]->SetLineColor(kRed);
397 fdNdEta[0]->Draw("SAME");
398 }
399
400 canvas->cd(4);
401 if (fPtDist)
402 fPtDist->Draw();
fcf2fb36 403
404 // histograms for different vertices?
405 if (kVertexBinning > 0)
406 {
407 // doesnt work, but i dont get it, giving up...
408 /*TCanvas* canvas2 =*/ new TCanvas("dNdEtaAnalysisVtx", "dNdEtaAnalysisVtx", 450, 450);
409 //Int_t yPads = (Int_t) TMath::Ceil(((Double_t) kVertexBinning - 1) / 2);
410 //printf("%d\n", yPads);
411 //canvas2->Divide(2, yPads);
412
413 TLegend* legend = new TLegend(0.7, 0.7, 0.9, 0.9);
414
5af55649 415 for (Int_t i=0; i<kVertexBinning; ++i)
fcf2fb36 416 {
417 //canvas2->cd(i-1);
418 //printf("%d\n", i);
1afae8ff 419 if (fdNdEtaPtCutOffCorrected[i])
fcf2fb36 420 {
1afae8ff 421 fdNdEtaPtCutOffCorrected[i]->SetLineColor(i+1);
422 fdNdEtaPtCutOffCorrected[i]->Draw((i == 0) ? "" : "SAME");
423 legend->AddEntry(fdNdEtaPtCutOffCorrected[i], (i == 0) ? "Vtx All" : Form("Vtx Bin %d", i-1));
fcf2fb36 424 }
425 }
426
427 legend->Draw();
428 }
7029240a 429}
430
431Long64_t dNdEtaAnalysis::Merge(TCollection* list)
432{
433 // Merges a list of dNdEtaAnalysis objects with this one.
434 // This is needed for PROOF.
435 // Returns the number of merged objects (including this)
436
437 if (!list)
438 return 0;
439
440 if (list->IsEmpty())
441 return 1;
442
443 TIterator* iter = list->MakeIterator();
444 TObject* obj;
445
446 // sub collections
1afae8ff 447 const Int_t nCollections = 2 * kVertexBinning + 4; // 4 standalone hists, two arrays of size kVertexBinning
7029240a 448 TList* collections[nCollections];
449 for (Int_t i=0; i<nCollections; ++i)
450 collections[i] = new TList;
451
452 Int_t count = 0;
453 while ((obj = iter->Next()))
454 {
455 dNdEtaAnalysis* entry = dynamic_cast<dNdEtaAnalysis*> (obj);
456 if (entry == 0)
457 continue;
458
45e97e28 459 collections[0]->Add(entry->fData);
460 collections[1]->Add(entry->fDataUncorrected);
6bf0714d 461 collections[2]->Add(entry->fVtx);
1afae8ff 462 collections[3]->Add(entry->fPtDist);
7029240a 463
464 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 465 {
466 collections[4+i]->Add(entry->fdNdEta[i]);
467 collections[4+kVertexBinning+i]->Add(entry->fdNdEtaPtCutOffCorrected[i]);
468 }
7029240a 469
470 ++count;
471 }
472
45e97e28 473 fData->Merge(collections[0]);
474 fDataUncorrected->Merge(collections[1]);
6bf0714d 475 fVtx->Merge(collections[2]);
1afae8ff 476 fPtDist->Merge(collections[3]);
7029240a 477 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 478 {
479 fdNdEta[i]->Merge(collections[4+i]);
480 fdNdEta[i]->Merge(collections[4+kVertexBinning+i]);
481 }
7029240a 482
483 for (Int_t i=0; i<nCollections; ++i)
484 delete collections[i];
485
486 return count+1;
ceb5d1b5 487}