2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
17 // Class for spectrum correction
18 // Subtraction of hadronic background, Unfolding of the data and
19 // Renormalization done here
20 // The following containers have to be set:
21 // - Correction framework container for real data
22 // - Correction framework container for MC (Efficiency Map)
23 // - Correction framework container for background coming from data
24 // - Correction framework container for background coming from MC
27 // Raphaelle Bailhache <R.Bailhache@gsi.de>
33 #include <TObjArray.h>
41 #include <TGraphErrors.h>
48 #include "AliCFContainer.h"
49 #include "AliCFDataGrid.h"
50 #include "AliCFEffGrid.h"
51 #include "AliCFGridSparse.h"
52 #include "AliCFUnfolding.h"
55 #include "AliHFEBeautySpectrumQA.h"
56 #include "AliHFECorrectSpectrumBase.h"
57 #include "AliHFEcuts.h"
58 #include "AliHFEcontainer.h"
59 #include "AliHFEtools.h"
61 ClassImp(AliHFEBeautySpectrumQA)
63 const Char_t *AliHFEBeautySpectrumQA::fgkNameCanvas[AliHFEBeautySpectrumQA::kNTypeEfficiency] = {
65 "ParametrizedEfficiency"
68 //____________________________________________________________
69 AliHFEBeautySpectrumQA::AliHFEBeautySpectrumQA():
76 // Default constructor
79 fListOfResult = new TObjArray(kNResults);
80 fListOfResult->SetName("ListOfResults");
84 //____________________________________________________________
85 AliHFEBeautySpectrumQA::AliHFEBeautySpectrumQA(const char *name):
92 // Default constructor
95 fListOfResult = new TObjArray(kNResults);
96 fListOfResult->SetName("ListOfResults");
101 //____________________________________________________________
102 AliHFEBeautySpectrumQA::~AliHFEBeautySpectrumQA(){
106 if(fListOfResult) delete fListOfResult;
109 //____________________________________________________________
110 void AliHFEBeautySpectrumQA::AddResultAt(TObject *obj,Int_t index)
113 // Init what we need for the correction:
116 if(fListOfResult) fListOfResult->AddAt(obj,index);
119 //____________________________________________________________
120 TObject *AliHFEBeautySpectrumQA::GetResult(Int_t index)
126 if(fListOfResult) return fListOfResult->UncheckedAt(index);
130 //____________________________________________________________
131 void AliHFEBeautySpectrumQA::DrawProjections() const
134 // get spectrum for beauty 2nd method
137 AliCFContainer *data = (AliCFContainer *) fListOfResult->UncheckedAt(kDataProjection);
138 THnSparseF *correlation = (THnSparseF *) fListOfResult->UncheckedAt(kCMProjection);
139 if(!data || !correlation) return;
141 Int_t ndimcont = data->GetNVar();
142 Int_t ndimcor = correlation->GetNdimensions();
144 Int_t centrality = 5;
147 TCanvas * canvas = new TCanvas("Projections","Projections",1000,700);
149 if(charge < ndimcont) n++;
150 if(centrality < ndimcont) n++;
151 if(eta < ndimcont) n++;
155 if(charge < ndimcont) {
158 TH1 *checkcharge = (TH1 *) data->Project(data->GetNStep()-1,charge);
162 TH2F* projectioncharge = (TH2F *) correlation->Projection(charge,charge+((Int_t)(ndimcor/2.)));
163 projectioncharge->Draw("colz");
168 if(centrality < ndimcont) {
170 TH1 *checkcentrality = (TH1 *) data->Project(data->GetNStep()-1,centrality);
171 checkcentrality->Draw();
174 TH2F *projectioncentrality = (TH2F *) correlation->Projection(centrality,centrality+((Int_t)(ndimcor/2.)));
175 projectioncentrality->Draw("colz");
181 TH1 *checketa = (TH1 *) data->Project(data->GetNStep()-1,eta);
185 TH2D* projectioneta = (TH2D *) correlation->Projection(eta,eta+((Int_t)(ndimcor/2.)));
186 projectioneta->Draw("colz");
191 //____________________________________________________________
192 void AliHFEBeautySpectrumQA::DrawSubtractContamination() const
195 // get spectrum for beauty 2nd method
198 TH1D *measuredTH1Daftersubstraction = (TH1D *) fListOfResult->UncheckedAt(kAfterSC);
199 TH1D *measuredTH1Dbeforesubstraction = (TH1D *) fListOfResult->UncheckedAt(kBeforeSC);
200 TH1D *measuredTH1background = (TH1D *) fListOfResult->UncheckedAt(kMeasBG);
201 if(!measuredTH1Daftersubstraction || !measuredTH1Dbeforesubstraction) return;
205 TCanvas * cbackgroundsubtraction = new TCanvas("backgroundsubtraction","backgroundsubtraction",1000,700);
206 cbackgroundsubtraction->Divide(3,1);
207 cbackgroundsubtraction->cd(1);
210 measuredTH1Daftersubstraction->SetStats(0);
211 measuredTH1Daftersubstraction->SetTitle("");
212 measuredTH1Daftersubstraction->GetYaxis()->SetTitleOffset(1.5);
213 measuredTH1Daftersubstraction->GetYaxis()->SetTitle("dN/dp_{T} [(GeV/c)^{-1}]");
214 measuredTH1Daftersubstraction->GetXaxis()->SetTitle("p^{rec}_{T} [GeV/c]");
215 //measuredTH1Daftersubstraction->GetXaxis()->SetRangeUser(0.0,fPtMax);
216 //measuredTH1Daftersubstraction->SetMarkerStyle(25);
217 //measuredTH1Daftersubstraction->SetMarkerColor(kBlack);
218 //measuredTH1Daftersubstraction->SetLineColor(kBlack);
219 measuredTH1Dbeforesubstraction->SetStats(0);
220 measuredTH1Dbeforesubstraction->SetTitle("");
221 measuredTH1Dbeforesubstraction->GetYaxis()->SetTitle("dN/dp_{T} [(GeV/c)^{-1}]");
222 measuredTH1Dbeforesubstraction->GetXaxis()->SetTitle("p^{rec}_{T} [GeV/c]");
223 //measuredTH1Dbeforesubstraction->GetXaxis()->SetRangeUser(0.0,fPtMax);
224 //measuredTH1Dbeforesubstraction->SetMarkerStyle(24);
225 //measuredTH1Dbeforesubstraction->SetMarkerColor(kBlue);
226 //measuredTH1Dbeforesubstraction->SetLineColor(kBlue);
227 measuredTH1Daftersubstraction->Draw();
228 measuredTH1Dbeforesubstraction->Draw("same");
229 TLegend *legsubstraction = new TLegend(0.4,0.6,0.89,0.89);
230 legsubstraction->AddEntry(measuredTH1Dbeforesubstraction,"With hadron contamination","p");
231 legsubstraction->AddEntry(measuredTH1Daftersubstraction,"Without hadron contamination ","p");
232 legsubstraction->SetFillStyle(0);
233 legsubstraction->SetLineStyle(0);
234 legsubstraction->SetLineColor(0);
235 legsubstraction->Draw("same");
236 cbackgroundsubtraction->cd(2);
239 TH1D* ratiomeasuredcontamination = (TH1D*)measuredTH1Dbeforesubstraction->Clone();
240 ratiomeasuredcontamination->SetName("ratiomeasuredcontamination");
241 ratiomeasuredcontamination->SetTitle("");
242 ratiomeasuredcontamination->GetYaxis()->SetTitleOffset(1.5);
243 ratiomeasuredcontamination->GetYaxis()->SetTitle("(with contamination - without contamination) / with contamination");
244 ratiomeasuredcontamination->GetXaxis()->SetTitle("p^{rec}_{T} [GeV/c]");
245 ratiomeasuredcontamination->GetYaxis()->SetRangeUser(0.8,1.2);
246 ratiomeasuredcontamination->GetXaxis()->SetRangeUser(0.0,fPtMax);
247 ratiomeasuredcontamination->Sumw2();
248 ratiomeasuredcontamination->Add(measuredTH1Daftersubstraction,-1.0);
249 ratiomeasuredcontamination->Divide(measuredTH1Dbeforesubstraction);
250 ratiomeasuredcontamination->SetStats(0);
251 ratiomeasuredcontamination->SetMarkerStyle(26);
252 ratiomeasuredcontamination->SetMarkerColor(kBlack);
253 ratiomeasuredcontamination->SetLineColor(kBlack);
254 for(Int_t k=0; k < ratiomeasuredcontamination->GetNbinsX(); k++){
255 ratiomeasuredcontamination->SetBinError(k+1,0.0);
257 ratiomeasuredcontamination->Draw("P");
258 cbackgroundsubtraction->cd(3);
259 measuredTH1background->SetStats(0);
260 measuredTH1background->SetTitle("");
261 measuredTH1background->GetYaxis()->SetTitle("dN/dp_{T} [(GeV/c)^{-1}]");
262 measuredTH1background->GetXaxis()->SetTitle("p_{T} [GeV/c]");
263 measuredTH1background->SetMarkerStyle(26);
264 measuredTH1background->SetMarkerColor(kBlack);
265 measuredTH1background->SetLineColor(kBlack);
266 measuredTH1background->Draw();
267 if(fWriteToFile) cbackgroundsubtraction->SaveAs("BackgroundSubtracted.png");
272 //____________________________________________________________
273 void AliHFEBeautySpectrumQA::DrawCorrectWithEfficiency(Int_t typeeff) const
276 // Correct the spectrum for efficiency and unfolding
277 // with both method and compare
282 TH1D *efficiencyDproj = 0x0;
283 TF1 *efficiencyparametrized = 0x0;
286 afterE = (TH1D *) fListOfResult->UncheckedAt(kAfterMCE);
287 beforeE = (TH1D *) fListOfResult->UncheckedAt(kBeforeMCE);
288 efficiencyDproj = (TH1D *) fListOfResult->UncheckedAt(kMCEfficiency);
290 if(typeeff== kParametrized) {
291 afterE = (TH1D *) fListOfResult->UncheckedAt(kAfterPE);
292 beforeE = (TH1D *) fListOfResult->UncheckedAt(kBeforePE);
293 efficiencyparametrized = (TF1 *) fListOfResult->UncheckedAt(kPEfficiency);
296 if(!afterE || !beforeE) return;
298 if(typeeff==kMC && !efficiencyDproj) return;
299 if(typeeff==kParametrized && !efficiencyparametrized) return;
303 TCanvas * cEfficiency = new TCanvas(AliHFEBeautySpectrumQA::fgkNameCanvas[typeeff],AliHFEBeautySpectrumQA::fgkNameCanvas[typeeff],1000,700);
304 cEfficiency->Divide(2,1);
309 afterE->SetTitle("");
310 afterE->GetYaxis()->SetTitleOffset(1.5);
311 afterE->GetYaxis()->SetTitle("dN/dp_{T} [(GeV/c)^{-1}]");
312 afterE->GetXaxis()->SetTitle("p^{rec}_{T} [GeV/c]");
313 afterE->GetXaxis()->SetRangeUser(0.0,fPtMax);
314 afterE->SetMarkerStyle(25);
315 afterE->SetMarkerColor(kBlack);
316 afterE->SetLineColor(kBlack);
317 beforeE->SetStats(0);
318 beforeE->SetTitle("");
319 beforeE->GetYaxis()->SetTitle("dN/dp_{T} [(GeV/c)^{-1}]");
320 beforeE->GetXaxis()->SetTitle("p_{T} [GeV/c]");
321 beforeE->GetXaxis()->SetRangeUser(0.0,fPtMax);
322 beforeE->SetMarkerStyle(24);
323 beforeE->SetMarkerColor(kBlue);
324 beforeE->SetLineColor(kBlue);
326 beforeE->Draw("same");
327 TLegend *legefficiency = new TLegend(0.4,0.6,0.89,0.89);
328 legefficiency->AddEntry(beforeE,"Before Efficiency correction","p");
329 legefficiency->AddEntry(afterE,"After Efficiency correction","p");
330 legefficiency->SetFillStyle(0);
331 legefficiency->SetLineStyle(0);
332 legefficiency->SetLineColor(0);
333 legefficiency->Draw("same");
337 if(efficiencyDproj) {
338 efficiencyDproj->SetTitle("");
339 efficiencyDproj->SetStats(0);
340 efficiencyDproj->GetYaxis()->SetTitleOffset(1.5);
341 efficiencyDproj->GetYaxis()->SetRangeUser(0.0,1.0);
342 efficiencyDproj->GetYaxis()->SetTitle("Efficiency");
343 efficiencyDproj->GetXaxis()->SetTitle("p^{rec}_{T} [GeV/c]");
344 efficiencyDproj->GetXaxis()->SetRangeUser(0.0,fPtMax);
345 efficiencyDproj->SetMarkerStyle(25);
346 efficiencyDproj->Draw();
349 if(typeeff==kParametrized) {
350 if(efficiencyparametrized) efficiencyparametrized->Draw();
354 if(typeeff==kMC) cEfficiency->SaveAs("EfficiencyMC.png");
355 if(typeeff==kParametrized) cEfficiency->SaveAs("EfficiencyParametrized.png");
360 //____________________________________________________________
361 void AliHFEBeautySpectrumQA::DrawUnfolding() const
366 TH1D *measuredspectrumD = (TH1D *) fListOfResult->UncheckedAt(kBeforeU);
367 TH1D *residualspectrumD = (TH1D *) fListOfResult->UncheckedAt(kResidualU);
368 TH1D *efficiencyDproj = (TH1D *) fListOfResult->UncheckedAt(kUEfficiency);
369 THnSparseF *correlation = (THnSparseF *) fListOfResult->UncheckedAt(kCMProjection);
371 if(!measuredspectrumD || !residualspectrumD || !efficiencyDproj || !correlation) return;
373 Int_t ndimcor = (Int_t) correlation->GetNdimensions()/2.;
377 TCanvas * cunfolding = new TCanvas("unfolding","unfolding",1000,700);
378 cunfolding->Divide(2,2);
382 residualspectrumD->GetYaxis()->SetTitle("dN/dp_{T} [(GeV/c)^{-1}]");
383 residualspectrumD->GetXaxis()->SetTitle("p^{rec}_{T} [GeV/c]");
384 residualspectrumD->GetXaxis()->SetRangeUser(0.0,fPtMax);
385 residualspectrumD->SetStats(0);
386 residualspectrumD->SetTitle("");
387 residualspectrumD->GetYaxis()->SetTitleOffset(1.5);
388 residualspectrumD->SetMarkerStyle(26);
389 residualspectrumD->SetMarkerColor(kBlue);
390 residualspectrumD->SetLineColor(kBlue);
391 residualspectrumD->Sumw2();
392 residualspectrumD->Draw("P");
393 measuredspectrumD->SetStats(0);
394 measuredspectrumD->SetTitle("");
395 measuredspectrumD->GetYaxis()->SetTitleOffset(1.5);
396 measuredspectrumD->SetMarkerStyle(25);
397 measuredspectrumD->SetMarkerColor(kBlack);
398 measuredspectrumD->SetLineColor(kBlack);
399 measuredspectrumD->Draw("same");
400 TLegend *legres = new TLegend(0.4,0.6,0.89,0.89);
401 legres->AddEntry(residualspectrumD,"Residual","p");
402 legres->AddEntry(measuredspectrumD,"Measured","p");
403 legres->SetFillStyle(0);
404 legres->SetLineStyle(0);
405 legres->SetLineColor(0);
406 legres->Draw("same");
409 TH1D* ratioresidual = (TH1D*)residualspectrumD->Clone();
410 ratioresidual->SetName("ratioresidual");
411 ratioresidual->SetTitle("");
412 ratioresidual->GetYaxis()->SetRangeUser(0.6,1.4);
413 ratioresidual->GetYaxis()->SetTitle("Folded/Measured");
414 ratioresidual->GetXaxis()->SetTitle("p_{T} [GeV/c]");
415 ratioresidual->Divide(measuredspectrumD);
416 ratioresidual->SetStats(0);
417 ratioresidual->Draw();
420 efficiencyDproj->GetYaxis()->SetTitle("Efficiency");
421 efficiencyDproj->GetXaxis()->SetTitle("p^{MC}_{T} [GeV/c]");
422 efficiencyDproj->GetXaxis()->SetRangeUser(0.0,fPtMax);
423 efficiencyDproj->GetYaxis()->SetRangeUser(0.0,1.0);
424 efficiencyDproj->SetStats(0);
425 efficiencyDproj->SetTitle("");
426 efficiencyDproj->GetYaxis()->SetTitleOffset(1.5);
427 efficiencyDproj->SetMarkerStyle(26);
428 efficiencyDproj->SetMarkerColor(kBlue);
429 efficiencyDproj->SetLineColor(kBlue);
430 efficiencyDproj->Sumw2();
431 efficiencyDproj->Draw("P");
433 TH2F *projectioncorr = (TH2F *) correlation->Projection(0,ndimcor);
434 projectioncorr->GetYaxis()->SetTitle("p^{ESD}_{T} [GeV/c]");
435 projectioncorr->GetXaxis()->SetTitle("p^{MC}_{T} [GeV/c]");
436 projectioncorr->GetXaxis()->SetRangeUser(0.0,fPtMax);
437 projectioncorr->GetYaxis()->SetRangeUser(0.0,fPtMax);
438 projectioncorr->SetStats(0);
439 projectioncorr->SetTitle("");
440 projectioncorr->Draw("colz");
443 cunfolding->SaveAs("Unfolding.png");
447 //____________________________________________________________
448 void AliHFEBeautySpectrumQA::DrawResult()
453 TGraphErrors* correctedspectrumD = (TGraphErrors *) fListOfResult->UncheckedAt(kFinalResultUnfolded);
454 TGraphErrors* alltogetherspectrumD = (TGraphErrors *) fListOfResult->UncheckedAt(kFinalResultDirectEfficiency);
455 THnSparse* correctedspectrum = (THnSparse *) fListOfResult->UncheckedAt(kFinalResultUnfSparse);
456 AliCFDataGrid* alltogetherCorrection = (AliCFDataGrid *) fListOfResult->UncheckedAt( kFinalResultDirectEffSparse);
457 if(!correctedspectrumD || !alltogetherspectrumD) return;
461 TCanvas * ccorrected = new TCanvas("corrected","corrected",1000,700);
462 ccorrected->Divide(2,1);
465 correctedspectrumD->SetTitle("");
466 correctedspectrumD->GetYaxis()->SetTitleOffset(1.5);
467 correctedspectrumD->GetYaxis()->SetRangeUser(0.000000001,1.0);
468 correctedspectrumD->SetMarkerStyle(26);
469 correctedspectrumD->SetMarkerColor(kBlue);
470 correctedspectrumD->SetLineColor(kBlue);
471 correctedspectrumD->Draw("AP");
472 alltogetherspectrumD->SetTitle("");
473 alltogetherspectrumD->GetYaxis()->SetTitleOffset(1.5);
474 alltogetherspectrumD->GetYaxis()->SetRangeUser(0.000000001,1.0);
475 alltogetherspectrumD->SetMarkerStyle(25);
476 alltogetherspectrumD->SetMarkerColor(kBlack);
477 alltogetherspectrumD->SetLineColor(kBlack);
478 alltogetherspectrumD->Draw("P");
479 TLegend *legcorrected = new TLegend(0.4,0.6,0.89,0.89);
480 legcorrected->AddEntry(correctedspectrumD,"Corrected","p");
481 legcorrected->AddEntry(alltogetherspectrumD,"Alltogether","p");
482 legcorrected->Draw("same");
484 TH1D *correctedTH1D = correctedspectrum->Projection(0);
485 TH1D *alltogetherTH1D = (TH1D *) alltogetherCorrection->Project(0);
486 TH1D* ratiocorrected = (TH1D*)correctedTH1D->Clone();
487 ratiocorrected->SetName("ratiocorrected");
488 ratiocorrected->SetTitle("");
489 ratiocorrected->GetYaxis()->SetTitle("Unfolded/DirectCorrected");
490 ratiocorrected->GetXaxis()->SetTitle("p_{T} [GeV/c]");
491 ratiocorrected->Divide(correctedTH1D,alltogetherTH1D,1,1);
492 ratiocorrected->SetStats(0);
493 ratiocorrected->Draw();
495 ccorrected->SaveAs("CorrectedBeauty.eps");
497 out = new TFile("finalSpectrum.root","recreate");
500 correctedspectrumD->SetName("UnfoldingCorrectedSpectrum");
501 correctedspectrumD->Write();
502 alltogetherspectrumD->SetName("AlltogetherSpectrum");
503 alltogetherspectrumD->Write();
504 ratiocorrected->SetName("RatioUnfoldingAlltogetherSpectrum");
505 ratiocorrected->Write();
512 //____________________________________________________________
513 TH1D *AliHFEBeautySpectrumQA::DivideSpectra(TGraphErrors *ga, TGraphErrors *gb)
519 TH1D *afterE = (TH1D *) fListOfResult->UncheckedAt(kAfterMCE);
520 if(!afterE) return 0x0;
522 TH1D *histoB = (TH1D*) afterE->Clone();
524 histoB->SetName("ratio");
525 TH1D *histoa = (TH1D*) afterE->Clone();
527 histoa->SetName("a");
528 TH1D *histob = (TH1D*) afterE->Clone();
530 histob->SetName("b");
532 double xa,ya,xb,yb,eya,eyb;
533 Int_t npointsa = ga->GetN();
534 Int_t npointsb = gb->GetN();
535 if(npointsa != npointsb) {
536 printf("Problem the two spectra have not the same number of points\n");
539 for(Int_t k = 0; k < npointsa; k++){
540 ga->GetPoint(k,xa,ya);
541 gb->GetPoint(k,xb,yb);
543 Double_t centerhisto = histoa->GetBinCenter(k+1);
545 if((TMath::Abs(xa-xb) > 0.0001) || (TMath::Abs(xa-centerhisto) > 0.0001)) {
546 printf("Problem not the same x axis\n");
549 histoa->SetBinContent(k+1,ya);
550 histob->SetBinContent(k+1,yb);
552 eya = ga->GetErrorY(k);
553 eyb = gb->GetErrorY(k);
555 histoa->SetBinError(k+1,eya);
556 histob->SetBinError(k+1,eyb);
561 histoB->Divide(histoa,histob,1.0,1.0,"B");
566 //__________________________________________
567 void AliHFEBeautySpectrumQA::SetStyle() const
573 gStyle->SetPalette(1);
574 gStyle->SetOptStat(1111);
575 gStyle->SetPadBorderMode(0);
576 gStyle->SetCanvasColor(10);
577 gStyle->SetPadLeftMargin(0.13);
578 gStyle->SetPadRightMargin(0.13);