3 #include "dNdEtaAnalysis.h"
11 #include <TCollection.h>
12 #include <TIterator.h>
16 #include "AlidNdEtaCorrection.h"
17 #include "AliPWG0Helper.h"
19 //____________________________________________________________________
20 ClassImp(dNdEtaAnalysis)
22 //____________________________________________________________________
23 dNdEtaAnalysis::dNdEtaAnalysis() :
30 // default constructor
32 for (Int_t i=0; i<kVertexBinning; ++i)
35 fdNdEtaPtCutOffCorrected[i] = 0;
39 //____________________________________________________________________
40 dNdEtaAnalysis::dNdEtaAnalysis(Char_t* name, Char_t* title) :
49 fData = new TH3F(Form("%s_analysis", name),"Input data",80,-20,20,40,-2,2,100, 0, 10);
50 fData->SetXTitle("vtx z [cm]");
51 fData->SetYTitle("#eta");
52 fData->SetZTitle("p_{T}");
55 fDataUncorrected = dynamic_cast<TH3F*> (fData->Clone(Form("%s_analysis_uncorrected", name)));
56 fDataUncorrected->SetTitle(Form("%s uncorrected", fData->GetTitle()));
57 fVtx = dynamic_cast<TH1D*> (fData->Project3D("x"));
58 fVtx->SetName(Form("%s_vtx", name));
59 fVtx->SetTitle("Vertex distribution");
60 fVtx->GetXaxis()->SetTitle(fData->GetXaxis()->GetTitle());
63 fdNdEta[0] = dynamic_cast<TH1D*> (fData->Project3D("y"));
64 fdNdEta[0]->SetName(Form("%s_dNdEta", name));
65 fdNdEta[0]->SetTitle("dN_{ch}/d#eta");
66 fdNdEta[0]->GetXaxis()->SetTitle(fData->GetYaxis()->GetTitle());
67 fdNdEta[0]->SetYTitle("dN_{ch}/d#eta");
69 fdNdEtaPtCutOffCorrected[0] = dynamic_cast<TH1D*> (fdNdEta[0]->Clone(Form("%s_corrected", fdNdEta[0]->GetName())));
71 for (Int_t i=1; i<kVertexBinning; ++i)
73 fdNdEta[i] = dynamic_cast<TH1D*> (fdNdEta[0]->Clone(Form("%s_%d", fdNdEta[0]->GetName(), i)));
74 fdNdEtaPtCutOffCorrected[i] = dynamic_cast<TH1D*> (fdNdEtaPtCutOffCorrected[0]->Clone(Form("%s_%d", fdNdEtaPtCutOffCorrected[0]->GetName(), i)));
77 fPtDist = dynamic_cast<TH1D*> (fData->Project3D("z"));
78 fPtDist->SetName(Form("%s_pt", name));
79 fPtDist->SetTitle("p_{T} [GeV/c]");
80 fPtDist->GetXaxis()->SetTitle(fData->GetZaxis()->GetTitle());
81 fPtDist->SetYTitle("#frac{dN}{d#eta dp_{T}} [c/GeV]");
84 //____________________________________________________________________
85 dNdEtaAnalysis::~dNdEtaAnalysis()
97 delete fDataUncorrected;
107 for (Int_t i=0; i<kVertexBinning; ++i)
114 if (fdNdEtaPtCutOffCorrected[i])
116 delete fdNdEtaPtCutOffCorrected[i];
117 fdNdEtaPtCutOffCorrected[i] = 0;
128 //_____________________________________________________________________________
129 dNdEtaAnalysis::dNdEtaAnalysis(const dNdEtaAnalysis &c) :
137 // dNdEtaAnalysis copy constructor
140 ((dNdEtaAnalysis &) c).Copy(*this);
143 //_____________________________________________________________________________
144 dNdEtaAnalysis &dNdEtaAnalysis::operator=(const dNdEtaAnalysis &c)
147 // Assignment operator
150 if (this != &c) ((dNdEtaAnalysis &) c).Copy(*this);
154 //_____________________________________________________________________________
155 void dNdEtaAnalysis::Copy(TObject &c) const
161 dNdEtaAnalysis& target = (dNdEtaAnalysis &) c;
163 target.fData = dynamic_cast<TH3F*> (fData->Clone());
164 target.fDataUncorrected = dynamic_cast<TH3F*> (fDataUncorrected->Clone());
165 target.fVtx = dynamic_cast<TH1D*> (fVtx->Clone());
167 for (Int_t i=0; i<kVertexBinning; ++i)
169 target.fdNdEta[i] = dynamic_cast<TH1D*> (fdNdEta[i]->Clone());
170 target.fdNdEtaPtCutOffCorrected[i] = dynamic_cast<TH1D*> (fdNdEtaPtCutOffCorrected[i]->Clone());
173 target.fPtDist = dynamic_cast<TH1D*> (fPtDist->Clone());
175 TNamed::Copy((TNamed &) c);
178 //____________________________________________________________________
179 void dNdEtaAnalysis::FillTrack(Float_t vtx, Float_t eta, Float_t pt, Float_t weight)
181 // fills a track into the histograms
183 fDataUncorrected->Fill(vtx, eta, pt);
184 fData->Fill(vtx, eta, pt, weight);
187 //____________________________________________________________________
188 void dNdEtaAnalysis::FillEvent(Float_t vtx, Float_t weight)
190 // fills an event into the histograms
192 fVtx->Fill(vtx, weight);
195 //____________________________________________________________________
196 void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut)
198 // correct with correction values if available
200 // TODO what do we do with the error?
202 printf("INFO: No correction applied\n");
204 // In fData we have the track2particle and vertex reconstruction efficiency correction already applied
209 fData->GetXaxis()->SetRange(0, 0);
210 fData->GetYaxis()->SetRange(0, 0);
211 fData->GetZaxis()->SetRange(0, 0);
214 Int_t vertexBinBegin = fData->GetXaxis()->FindBin(-5);
215 Int_t vertexBinEnd = fData->GetXaxis()->FindBin(5);
216 fData->GetXaxis()->SetRange(vertexBinBegin, vertexBinEnd);
217 Float_t nEvents = fVtx->Integral(vertexBinBegin, vertexBinEnd);
220 fData->GetYaxis()->SetRange(fData->GetYaxis()->FindBin(-0.8), fData->GetYaxis()->FindBin(0.8));
221 Float_t etaWidth = 1.6;
223 TH1D* ptHist = dynamic_cast<TH1D*> (fData->Project3D("ze"));
225 for (Int_t i=1; i<=fPtDist->GetNbinsX(); ++i)
227 Float_t binSize = fPtDist->GetBinWidth(i);
228 fPtDist->SetBinContent(i, ptHist->GetBinContent(i) / binSize / nEvents / etaWidth);
229 fPtDist->SetBinError(i, ptHist->GetBinError(i) / binSize / nEvents / etaWidth);
236 fData->GetXaxis()->SetRange(0, 0);
237 fData->GetYaxis()->SetRange(0, 0);
238 fData->GetZaxis()->SetRange(0, 0);
240 // integrate over pt (with pt cut)
243 ptLowBin = fData->GetZaxis()->FindBin(ptCut);
245 fData->GetZaxis()->SetRange(ptLowBin, fData->GetZaxis()->GetNbins());
246 TH2D* vtxVsEta = dynamic_cast<TH2D*> (fData->Project3D("yx2e"));
247 vtxVsEta->GetXaxis()->SetTitle(fData->GetXaxis()->GetTitle());
248 vtxVsEta->GetYaxis()->SetTitle(fData->GetYaxis()->GetTitle());
252 printf("ERROR: pt integration failed\n");
257 //vtxVsEta->Draw("COLZ");
259 for (Int_t iEta=0; iEta<=vtxVsEta->GetNbinsY(); iEta++)
261 // do we have several histograms for different vertex positions?
262 Int_t vertexBinWidth = fVtx->GetNbinsX() / (kVertexBinning-1);
263 for (Int_t vertexPos=0; vertexPos<kVertexBinning; ++vertexPos)
265 Int_t vertexBinBegin = 1;
266 Int_t vertexBinEnd = fVtx->GetNbinsX() + 1;
268 // the first histogram is always for the whole vertex range
271 vertexBinBegin = 1 + vertexBinWidth * (vertexPos-1);
272 vertexBinEnd = vertexBinBegin + vertexBinWidth;
275 Float_t totalEvents = fVtx->Integral(vertexBinBegin, vertexBinEnd - 1);
276 if (totalEvents == 0)
278 printf("WARNING: No events for hist %d %d %d\n", vertexPos, vertexBinBegin, vertexBinEnd);
283 Float_t sumError2 = 0;
284 for (Int_t iVtx = vertexBinBegin; iVtx < vertexBinEnd; iVtx++)
286 if (vtxVsEta->GetBinContent(iVtx, iEta) != 0)
288 sum = sum + vtxVsEta->GetBinContent(iVtx, iEta);
289 sumError2 = sumError2 + TMath::Power(vtxVsEta->GetBinError(iVtx, iEta),2);
293 Float_t ptCutOffCorrection = 1;
295 ptCutOffCorrection = correction->GetMeasuredFraction(ptCut, vtxVsEta->GetYaxis()->GetBinCenter(iEta));
297 if (ptCutOffCorrection <= 0)
299 printf("UNEXPECTED: ptCutOffCorrection is %f for hist %d %d %d\n", ptCutOffCorrection, vertexPos, vertexBinBegin, vertexBinEnd);
303 Float_t dndeta = sum / totalEvents;
304 Float_t error = TMath::Sqrt(sumError2) / totalEvents;
306 dndeta = dndeta/fdNdEta[vertexPos]->GetBinWidth(iEta);
307 error = error/fdNdEta[vertexPos]->GetBinWidth(iEta);
309 fdNdEta[vertexPos]->SetBinContent(iEta, dndeta);
310 fdNdEta[vertexPos]->SetBinError(iEta, error);
312 dndeta /= ptCutOffCorrection;
313 error /= ptCutOffCorrection;
315 fdNdEtaPtCutOffCorrected[vertexPos]->SetBinContent(iEta, dndeta);
316 fdNdEtaPtCutOffCorrected[vertexPos]->SetBinError(iEta, error);
321 //____________________________________________________________________
322 void dNdEtaAnalysis::SaveHistograms()
324 // save the histograms to a directory with the name of this class (retrieved from TNamed)
326 gDirectory->mkdir(GetName());
327 gDirectory->cd(GetName());
332 AliPWG0Helper::CreateProjections(fData);
335 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fData is 0\n");
337 if (fDataUncorrected)
339 fDataUncorrected->Write();
340 AliPWG0Helper::CreateProjections(fDataUncorrected);
343 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fDataUncorrected is 0\n");
348 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fVtx is 0\n");
353 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fPtDist is 0\n");
355 for (Int_t i=0; i<kVertexBinning; ++i)
360 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fdNdEta[%d] is 0\n", i);
362 if (fdNdEtaPtCutOffCorrected[i])
363 fdNdEtaPtCutOffCorrected[i]->Write();
365 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fdNdEtaPtCutOffCorrected[%d] is 0\n", i);
368 gDirectory->cd("../");
371 void dNdEtaAnalysis::LoadHistograms()
373 // loads the histograms from a directory with the name of this class (retrieved from TNamed)
375 gDirectory->cd(GetName());
377 fData = dynamic_cast<TH3F*> (gDirectory->Get(fData->GetName()));
378 fDataUncorrected = dynamic_cast<TH3F*> (gDirectory->Get(fDataUncorrected->GetName()));
380 fVtx = dynamic_cast<TH1D*> (gDirectory->Get(fVtx->GetName()));
382 for (Int_t i=0; i<kVertexBinning; ++i)
384 fdNdEta[i] = dynamic_cast<TH1D*> (gDirectory->Get(fdNdEta[i]->GetName()));
385 fdNdEtaPtCutOffCorrected[i] = dynamic_cast<TH1D*> (gDirectory->Get(fdNdEtaPtCutOffCorrected[i]->GetName()));
388 fPtDist = dynamic_cast<TH1D*> (gDirectory->Get(fPtDist->GetName()));
390 gDirectory->cd("../");
393 //____________________________________________________________________
394 void dNdEtaAnalysis::DrawHistograms()
396 // draws the histograms
398 TCanvas* canvas = new TCanvas("dNdEtaAnalysis", "dNdEtaAnalysis", 800, 800);
399 canvas->Divide(2, 2);
406 if (fDataUncorrected)
407 fDataUncorrected->Draw("COLZ");*/
414 if (fdNdEtaPtCutOffCorrected[0])
415 fdNdEtaPtCutOffCorrected[0]->Draw();
419 fdNdEta[0]->SetLineColor(kRed);
420 fdNdEta[0]->Draw("SAME");
427 // histograms for different vertices?
428 if (kVertexBinning > 0)
430 // doesnt work, but i dont get it, giving up...
431 /*TCanvas* canvas2 =*/ new TCanvas("dNdEtaAnalysisVtx", "dNdEtaAnalysisVtx", 450, 450);
432 //Int_t yPads = (Int_t) TMath::Ceil(((Double_t) kVertexBinning - 1) / 2);
433 //printf("%d\n", yPads);
434 //canvas2->Divide(2, yPads);
436 TLegend* legend = new TLegend(0.7, 0.7, 0.9, 0.9);
438 for (Int_t i=0; i<kVertexBinning; ++i)
442 if (fdNdEtaPtCutOffCorrected[i])
444 fdNdEtaPtCutOffCorrected[i]->SetLineColor(i+1);
445 fdNdEtaPtCutOffCorrected[i]->Draw((i == 0) ? "" : "SAME");
446 legend->AddEntry(fdNdEtaPtCutOffCorrected[i], (i == 0) ? "Vtx All" : Form("Vtx Bin %d", i-1));
454 Long64_t dNdEtaAnalysis::Merge(TCollection* list)
456 // Merges a list of dNdEtaAnalysis objects with this one.
457 // This is needed for PROOF.
458 // Returns the number of merged objects (including this)
466 TIterator* iter = list->MakeIterator();
470 const Int_t nCollections = 2 * kVertexBinning + 4; // 4 standalone hists, two arrays of size kVertexBinning
471 TList* collections[nCollections];
472 for (Int_t i=0; i<nCollections; ++i)
473 collections[i] = new TList;
476 while ((obj = iter->Next()))
478 dNdEtaAnalysis* entry = dynamic_cast<dNdEtaAnalysis*> (obj);
482 collections[0]->Add(entry->fData);
483 if (fDataUncorrected)
484 collections[1]->Add(entry->fDataUncorrected);
485 collections[2]->Add(entry->fVtx);
486 collections[3]->Add(entry->fPtDist);
488 for (Int_t i=0; i<kVertexBinning; ++i)
490 collections[4+i]->Add(entry->fdNdEta[i]);
491 collections[4+kVertexBinning+i]->Add(entry->fdNdEtaPtCutOffCorrected[i]);
497 fData->Merge(collections[0]);
498 if (fDataUncorrected)
499 fDataUncorrected->Merge(collections[1]);
500 fVtx->Merge(collections[2]);
501 fPtDist->Merge(collections[3]);
502 for (Int_t i=0; i<kVertexBinning; ++i)
504 fdNdEta[i]->Merge(collections[4+i]);
505 fdNdEta[i]->Merge(collections[4+kVertexBinning+i]);
508 for (Int_t i=0; i<nCollections; ++i)
509 delete collections[i];