4 // plots for the note about multplicity measurements
7 #if !defined(__CINT__) || defined(__MAKECINT__)
19 #include <TStopwatch.h>
23 #include <TPaveText.h>
27 #include "AliMultiplicityCorrection.h"
28 #include "AliCorrection.h"
29 #include "AliCorrectionMatrix3D.h"
33 const char* correctionFile = "multiplicityMC.root";
34 const char* measuredFile = "multiplicityESD.root";
36 Int_t displayRange = 80; // axis range
37 Int_t ratioRange = 151; // range to calculate difference
38 Int_t longDisplayRange = 120;
40 const char* correctionFileTPC = "multiplicityMC_TPC_1.4M.root";
41 const char* measuredFileTPC = "multiplicityMC_TPC_0.6M.root";
42 Int_t etaRangeTPC = 1;
46 gSystem->Load("libANALYSIS");
47 gSystem->Load("libPWG0base");
52 correctionFile = correctionFileTPC;
53 measuredFile = measuredFileTPC;
54 etaRange = etaRangeTPC;
57 longDisplayRange = 100;
60 const char* GetMultLabel(Int_t etaR = -1, Bool_t trueM = kTRUE)
65 TString tmpStr((trueM) ? "True " : "Measured ");
67 tmpStr += "multiplicity";
68 //return Form("%s", tmpStr.Data());
72 tmpStr += " (full phase space)";
75 tmpStr += Form(" in |#eta| < %.1f", (etaR+1)* 0.5);
76 return Form("%s", tmpStr.Data());
79 void Smooth(TH1* hist, Int_t windowWidth = 20)
81 TH1* clone = (TH1*) hist->Clone("clone");
82 for (Int_t bin=2; bin<=clone->GetNbinsX(); ++bin)
84 Int_t min = TMath::Max(2, bin-windowWidth);
85 Int_t max = TMath::Min(clone->GetNbinsX(), bin+windowWidth);
86 Float_t average = clone->Integral(min, max) / (max - min + 1);
88 hist->SetBinContent(bin, average);
89 hist->SetBinError(bin, 0);
95 void responseMatrixPlot(const char* fileName = 0)
99 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
102 fileName = correctionFile;
104 TFile::Open(fileName);
105 mult->LoadHistograms("Multiplicity");
107 // empty under/overflow bins in x, otherwise Project3D takes them into account
108 TH1* hist = mult->GetCorrelation(etaRange);
109 for (Int_t y=0; y<=hist->GetYaxis()->GetNbins()+1; ++y)
111 for (Int_t z=0; z<=hist->GetZaxis()->GetNbins()+1; ++z)
113 hist->SetBinContent(0, y, z, 0);
114 hist->SetBinContent(hist->GetXaxis()->GetNbins()+1, y, z, 0);
117 hist = ((TH3*) mult->GetCorrelation(etaRange))->Project3D("zy");
118 hist->SetStats(kFALSE);
120 hist->SetTitle(Form(";%s;%s;Entries", GetMultLabel(), GetMultLabel(etaRange, kFALSE)));
121 hist->GetXaxis()->SetRangeUser(0, longDisplayRange);
122 hist->GetYaxis()->SetRangeUser(0, longDisplayRange);
124 hist->GetYaxis()->SetTitleOffset(1.3);
125 hist->GetZaxis()->SetTitleOffset(1.2);
127 TCanvas* canvas = new TCanvas("c1", "c1", 600, 600);
128 canvas->SetRightMargin(0.15);
129 canvas->SetTopMargin(0.05);
134 canvas->SaveAs("responsematrix.eps");
137 void multPythiaPhojet()
141 TFile::Open("LHC08c11_10TeV_0.5T/mb1/spd/multiplicity.root");
142 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
143 mult->LoadHistograms("Multiplicity");
144 hist1 = mult->GetMultiplicityINEL(1)->ProjectionY();
147 TFile::Open("LHC08c15_10TeV_0.5T_Phojet/mb1/spd/multiplicity.root");
148 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
149 mult->LoadHistograms("Multiplicity");
150 hist2 = mult->GetMultiplicityINEL(1)->ProjectionY();
153 legend = new TLegend(0.6, 0.7, 0.9, 0.9);
154 legend->SetFillColor(0);
155 legend->SetTextSize(0.04);
156 legend->AddEntry(hist1, "Pythia", "L");
157 legend->AddEntry(hist2, "Phojet", "L");
159 c1 = new TCanvas("c", "c", 600, 600);
160 c1->SetTopMargin(0.05);
161 c1->SetRightMargin(0.05);
162 c1->SetLeftMargin(0.12);
167 //hist1->SetMarkerStyle(20);
168 //hist2->SetMarkerStyle(24);
169 //hist2->SetMarkerColor(2);
170 hist1->SetLineWidth(2);
171 hist2->SetLineWidth(2);
172 hist2->SetLineStyle(2);
173 hist2->SetLineColor(2);
175 hist1->Scale(1.0 / hist1->Integral());
176 hist2->Scale(1.0 / hist2->Integral());
179 hist1->GetYaxis()->SetTitleOffset(1.3);
180 hist1->GetXaxis()->SetRangeUser(0, 100);
181 hist1->SetTitle(";N_{ch};P(N_{ch})");
187 c1->SaveAs("mult_pythia_phojet.eps");
190 TCanvas* DrawResultRatio(TH1* mcHist, TH1* result, TString epsName)
192 // normalize unfolded result to mc hist
193 result->Scale(1.0 / result->Integral(2, displayRange));
194 result->Scale(mcHist->Integral(2, displayRange));
196 TCanvas* canvas = new TCanvas(epsName, epsName, 800, 600);
197 canvas->Range(0, 0, 1, 1);
199 TPad* pad1 = new TPad(Form("%s_pad1", epsName.Data()), "", 0, 0.5, 0.98, 0.98);
202 TPad* pad2 = new TPad(Form("%s_pad2", epsName.Data()), "", 0, 0.02, 0.98, 0.5);
205 pad1->SetRightMargin(0.05);
206 pad2->SetRightMargin(0.05);
208 // no border between them
209 pad1->SetBottomMargin(0);
210 pad2->SetTopMargin(0);
216 mcHist->GetXaxis()->SetLabelSize(0.06);
217 mcHist->GetYaxis()->SetLabelSize(0.06);
218 mcHist->GetXaxis()->SetTitleSize(0.06);
219 mcHist->GetYaxis()->SetTitleSize(0.06);
220 mcHist->GetYaxis()->SetTitleOffset(0.6);
222 mcHist->GetXaxis()->SetRangeUser(0, displayRange);
224 mcHist->SetTitle(Form(";%s;Entries", GetMultLabel()));
225 mcHist->SetStats(kFALSE);
227 mcHist->DrawCopy("HIST E");
230 result->SetLineColor(2);
231 result->SetMarkerColor(2);
232 result->SetMarkerStyle(5);
233 result->DrawCopy("SAME PE");
235 TLegend* legend = new TLegend(0.6, 0.65, 0.95, 0.9);
236 legend->AddEntry(mcHist, "True distribution");
237 legend->AddEntry(result, "Unfolded distribution", "P");
238 legend->SetFillColor(0);
242 pad2->SetBottomMargin(0.15);
246 TH1* ratio = (TH1*) mcHist->Clone("ratio");
248 ratio->Divide(ratio, result, 1, 1, "");
249 ratio->GetYaxis()->SetTitle("Ratio (true / unfolded)");
250 ratio->GetYaxis()->SetRangeUser(0.55, 1.45);
254 // get average of ratio
256 for (Int_t i=2; i<=ratioRange; ++i)
258 sum += TMath::Abs(ratio->GetBinContent(i) - 1);
262 printf("Average (2..%d) of |ratio - 1| is %f\n", ratioRange, sum);
264 TLine* line = new TLine(0, 1, displayRange, 1);
265 line->SetLineWidth(2);
268 line = new TLine(0, 1.1, displayRange, 1.1);
269 line->SetLineWidth(2);
270 line->SetLineStyle(2);
272 line = new TLine(0, 0.9, displayRange, 0.9);
273 line->SetLineWidth(2);
274 line->SetLineStyle(2);
279 canvas->SaveAs(epsName);
284 TCanvas* Draw2ResultRatio(TH1* mcHist, TH1* result1, TH1* result2, TString epsName)
286 // draws the 3 plots in the upper plot
287 // draws the ratio between result1 and result2 in the lower plot
289 // normalize unfolded result to mc hist
290 result1->Scale(1.0 / result1->Integral(2, displayRange));
291 result1->Scale(mcHist->Integral(2, displayRange));
292 result2->Scale(1.0 / result2->Integral(2, displayRange));
293 result2->Scale(mcHist->Integral(2, displayRange));
295 TCanvas* canvas = new TCanvas(epsName, epsName, 800, 600);
296 canvas->Range(0, 0, 1, 1);
298 TPad* pad1 = new TPad(Form("%s_pad1", epsName.Data()), "", 0, 0.5, 0.98, 0.98);
301 TPad* pad2 = new TPad(Form("%s_pad2", epsName.Data()), "", 0, 0.02, 0.98, 0.5);
304 pad1->SetRightMargin(0.05);
305 pad2->SetRightMargin(0.05);
307 // no border between them
308 pad1->SetBottomMargin(0);
309 pad2->SetTopMargin(0);
315 mcHist->GetXaxis()->SetLabelSize(0.06);
316 mcHist->GetYaxis()->SetLabelSize(0.06);
317 mcHist->GetXaxis()->SetTitleSize(0.06);
318 mcHist->GetYaxis()->SetTitleSize(0.06);
319 mcHist->GetYaxis()->SetTitleOffset(0.6);
321 mcHist->GetXaxis()->SetRangeUser(0, displayRange);
323 mcHist->SetTitle(";true multiplicity;Entries");
324 mcHist->SetStats(kFALSE);
326 mcHist->DrawCopy("HIST E");
329 result1->SetLineColor(2);
330 result1->SetMarkerStyle(24);
331 result1->DrawCopy("SAME HISTE");
333 result2->SetLineColor(4);
334 result2->SetMarkerColor(4);
335 result2->DrawCopy("SAME HISTE");
337 TLegend* legend = new TLegend(0.5, 0.6, 0.95, 0.9);
338 legend->AddEntry(mcHist, "True distribution");
339 legend->AddEntry(result1, "Unfolded distribution (syst)", "P");
340 legend->AddEntry(result2, "Unfolded distribution (normal)", "P");
341 legend->SetFillColor(0);
342 legend->SetTextSize(0.06);
346 pad2->SetBottomMargin(0.15);
350 result1->GetXaxis()->SetLabelSize(0.06);
351 result1->GetYaxis()->SetLabelSize(0.06);
352 result1->GetXaxis()->SetTitleSize(0.06);
353 result1->GetYaxis()->SetTitleSize(0.06);
354 result1->GetYaxis()->SetTitleOffset(0.6);
356 result1->GetXaxis()->SetRangeUser(0, displayRange);
358 result1->SetTitle(Form(";%s;Entries", GetMultLabel()));
359 result1->SetStats(kFALSE);
363 TH1* ratio = (TH1*) result1->Clone("ratio");
365 ratio->Divide(ratio, result2, 1, 1, "");
366 ratio->SetLineColor(1);
367 ratio->SetMarkerColor(1);
368 ratio->SetMarkerStyle(0);
369 ratio->GetYaxis()->SetTitle("Ratio (syst / normal)");
370 ratio->GetYaxis()->SetRangeUser(0.55, 1.45);
374 // get average of ratio
376 for (Int_t i=2; i<=ratioRange; ++i)
378 sum += TMath::Abs(ratio->GetBinContent(i) - 1);
382 printf("Average (2..%d) of |ratio - 1| is %f\n", ratioRange, sum);
384 TLine* line = new TLine(0, 1, displayRange, 1);
385 line->SetLineWidth(2);
388 line = new TLine(0, 1.1, displayRange, 1.1);
389 line->SetLineWidth(2);
390 line->SetLineStyle(2);
392 line = new TLine(0, 0.9, displayRange, 0.9);
393 line->SetLineWidth(2);
394 line->SetLineStyle(2);
399 canvas->SaveAs(epsName);
404 TCanvas* Draw2ResultRatios(TH1* mcHist, TH1* result1, TH1* result2, TH1* ratio2, TH1* ratio3, TString epsName)
406 // draws the 3 plots in the upper plot
407 // draws the ratio between result1 and result2 in the lower plot
408 // also draws ratio2 and ratio3 in the lower plot, uses their name for the legend
410 // normalize unfolded result to mc hist
411 result1->Scale(1.0 / result1->Integral(2, 200));
412 result1->Scale(mcHist->Integral(2, 200));
413 result2->Scale(1.0 / result2->Integral(2, 200));
414 result2->Scale(mcHist->Integral(2, 200));
416 TCanvas* canvas = new TCanvas(epsName, epsName, 800, 600);
417 canvas->Range(0, 0, 1, 1);
419 TPad* pad1 = new TPad(Form("%s_pad1", epsName.Data()), "", 0, 0.5, 0.98, 0.98);
422 TPad* pad2 = new TPad(Form("%s_pad2", epsName.Data()), "", 0, 0.02, 0.98, 0.5);
425 pad1->SetRightMargin(0.05);
426 pad2->SetRightMargin(0.05);
428 // no border between them
429 pad1->SetBottomMargin(0);
430 pad2->SetTopMargin(0);
436 mcHist->GetXaxis()->SetLabelSize(0.06);
437 mcHist->GetYaxis()->SetLabelSize(0.06);
438 mcHist->GetXaxis()->SetTitleSize(0.06);
439 mcHist->GetYaxis()->SetTitleSize(0.06);
440 mcHist->GetYaxis()->SetTitleOffset(0.6);
442 mcHist->GetXaxis()->SetRangeUser(0, displayRange);
444 mcHist->SetTitle(";True multiplicity;Entries");
445 mcHist->SetStats(kFALSE);
447 mcHist->DrawCopy("HIST E");
450 result1->SetLineColor(2);
451 result1->SetMarkerColor(2);
452 result1->SetMarkerStyle(24);
453 result1->DrawCopy("SAME HISTE");
455 result2->SetLineColor(4);
456 result2->SetMarkerColor(4);
457 result2->SetMarkerStyle(5);
458 result2->DrawCopy("SAME HISTE");
460 TLegend* legend = new TLegend(0.55, 0.6, 0.95, 0.9);
461 legend->AddEntry(mcHist, "True distribution");
462 legend->AddEntry(result1, "Unfolded distribution (5%)", "P");
463 legend->AddEntry(result2, "Unfolded distribution (normal)", "P");
464 legend->SetFillColor(0);
465 legend->SetTextSize(0.06);
469 pad2->SetBottomMargin(0.15);
473 result1->GetXaxis()->SetLabelSize(0.06);
474 result1->GetYaxis()->SetLabelSize(0.06);
475 result1->GetXaxis()->SetTitleSize(0.06);
476 result1->GetYaxis()->SetTitleSize(0.06);
477 result1->GetYaxis()->SetTitleOffset(0.6);
479 result1->GetXaxis()->SetRangeUser(0, displayRange);
481 result1->SetTitle(Form(";%s;Entries", GetMultLabel()));
482 result1->SetStats(kFALSE);
486 TH1* ratio = (TH1*) result1->Clone("ratio");
488 ratio->Divide(ratio, result2, 1, 1, "");
489 ratio->SetLineColor(1);
490 ratio->SetMarkerColor(1);
491 ratio->SetMarkerStyle(24);
492 ratio->GetYaxis()->SetTitle("Ratio (change / normal)");
493 ratio->GetYaxis()->SetRangeUser(0.55, 1.45);
495 ratio2->SetLineColor(2);
496 ratio2->SetMarkerColor(2);
497 ratio2->SetMarkerStyle(25);
499 ratio3->SetLineColor(4);
500 ratio3->SetMarkerColor(4);
501 ratio3->SetMarkerStyle(26);
504 ratio2->DrawCopy("SAME");
505 ratio3->DrawCopy("SAME");
507 legend2 = new TLegend(0.3, 0.8, 0.8, 0.95);
508 legend2->SetNColumns(3);
509 legend2->SetFillColor(0);
510 legend2->SetTextSize(0.06);
511 legend2->AddEntry(ratio, "5% change", "P");
512 legend2->AddEntry(ratio2, "2% change", "P");
513 legend2->AddEntry(ratio3, "1% change", "P");
516 // get average of ratio
518 for (Int_t i=2; i<=ratioRange; ++i)
520 sum += TMath::Abs(ratio->GetBinContent(i) - 1);
524 printf("Average (2..%d) of |ratio - 1| is %f\n", ratioRange, sum);
526 TLine* line = new TLine(0, 1, displayRange, 1);
527 line->SetLineWidth(2);
530 line = new TLine(0, 1.1, displayRange, 1.1);
531 line->SetLineWidth(2);
532 line->SetLineStyle(2);
534 line = new TLine(0, 0.9, displayRange, 0.9);
535 line->SetLineWidth(2);
536 line->SetLineStyle(2);
541 canvas->SaveAs(epsName);
546 TCanvas* DrawRatio(TH1* result, Int_t nResultSyst, TH1** resultSyst, TString epsName, Bool_t firstMarker = kFALSE, const char** legendStrings = 0, Bool_t errors = kFALSE)
548 // compares n results with first results. E.g. one gained with the default response, another with a changed one to study
549 // a systematic effect
552 result->Scale(1.0 / result->Integral(2, 200));
554 TCanvas* canvas = new TCanvas(epsName, epsName, 800, 500);
555 canvas->SetTopMargin(0.05);
556 canvas->SetRightMargin(0.05);
560 result->GetXaxis()->SetRangeUser(0, displayRange);
561 result->GetYaxis()->SetRangeUser(0.55, 1.45);
562 result->SetStats(kFALSE);
564 // to get the axis how we want it
565 TH1* dummy = (TH1*) result->Clone("dummy");
567 dummy->SetTitle(Form(";%s;Ratio", GetMultLabel()));
571 Int_t colors[] = {1, 2, 4, 6, 7, 8, 9, 10};
573 TLegend* legend = new TLegend(0.2, 0.7, 0.7, 0.93);
574 legend->SetFillColor(0);
575 legend->SetTextSize(0.04);
577 legend->SetNColumns(2);
579 for (Int_t n=0; n<nResultSyst; ++n)
581 resultSyst[n]->Scale(1.0 / resultSyst[n]->Integral(2, 200));
584 TH1* ratio = (TH1*) result->Clone("ratio");
585 ratio->Divide(ratio, resultSyst[n], 1, 1, "");
586 ratio->GetXaxis()->SetRangeUser(0, displayRange);
589 ratio->SetMarkerStyle(5);
591 ratio->SetLineColor(colors[n / 2]);
593 ratio->SetLineStyle(2);
595 TString drawStr("SAME HIST");
596 if (n == 0 && firstMarker)
601 ratio->DrawCopy(drawStr);
603 if (legendStrings && legendStrings[n])
604 legend->AddEntry(ratio, legendStrings[n], "L");
606 // get average of ratio
608 for (Int_t i=2; i<=ratioRange; ++i)
609 sum += TMath::Abs(ratio->GetBinContent(i) - 1);
612 printf("%d) Average (2..%d) of |ratio - 1| is %f\n", n, ratioRange, sum);
618 TLine* line = new TLine(-0.5, 1, displayRange, 1);
619 line->SetLineWidth(2);
622 line = new TLine(-0.5, 1.1, displayRange, 1.1);
623 line->SetLineWidth(2);
624 line->SetLineStyle(2);
626 line = new TLine(-0.5, 0.9, displayRange, 0.9);
627 line->SetLineWidth(2);
628 line->SetLineStyle(2);
631 canvas->SaveAs(epsName);
632 canvas->SaveAs(Form("%s.gif", epsName.Data()));
637 TCanvas* DrawRatio(Int_t nResultSyst, TH1** mc, TH1** result, TString epsName, Bool_t smooth = kFALSE, Bool_t dashed = kFALSE)
639 // draws the ratios of each mc to the corresponding result
641 TCanvas* canvas = new TCanvas(epsName, epsName, 800, 400);
642 canvas->SetRightMargin(0.05);
643 canvas->SetTopMargin(0.05);
645 for (Int_t n=0; n<nResultSyst; ++n)
648 result[n]->Scale(1.0 / result[n]->Integral(2, 200));
649 mc[n]->Scale(1.0 / mc[n]->Integral(2, 200));
651 result[n]->GetXaxis()->SetRangeUser(0, displayRange);
652 result[n]->SetStats(kFALSE);
655 TH1* ratio = (TH1*) result[n]->Clone("ratio");
656 ratio->Divide(mc[n], ratio, 1, 1, "B");
658 // SetRangeUser(1, ...) would be the same, but the 0 should be still on the axis...
659 ratio->SetBinContent(1, 1); ratio->SetBinError(1, 0);
664 ratio->SetTitle(Form(";true multiplicity;Ratio (true / unfolded)%s", ((smooth) ? " (smoothed)" : "")));
665 ratio->GetYaxis()->SetRangeUser(0.55, 1.45);
669 ratio->SetLineColor((n/2)+1);
670 ratio->SetLineStyle((n%2)+1);
673 ratio->SetLineColor(n+1);
675 ratio->DrawCopy((n == 0) ? "HIST" : "SAME HIST");
677 // get average of ratio
679 for (Int_t i=2; i<=ratioRange; ++i)
680 sum += TMath::Abs(ratio->GetBinContent(i) - 1);
683 printf("%d) Average (2..%d) of |ratio - 1| is %f\n", n, ratioRange, sum);
686 TLine* line = new TLine(0, 1, displayRange, 1);
687 line->SetLineWidth(2);
690 line = new TLine(0, 1.1, displayRange, 1.1);
691 line->SetLineWidth(2);
692 line->SetLineStyle(2);
694 line = new TLine(0, 0.9, displayRange, 0.9);
695 line->SetLineWidth(2);
696 line->SetLineStyle(2);
701 canvas->SaveAs(epsName);
702 canvas->SaveAs(Form("%s.gif", epsName.Data()));
707 TCanvas* DrawRatioDeduct(TH1* mcBase, TH1* resultBase, Int_t nResultSyst, TH1** mc, TH1** result, TString epsName)
709 // draws the ratios of each mc to the corresponding result
710 // deducts from each ratio the ratio of mcBase / resultBase
713 resultBase->Scale(1.0 / resultBase->Integral(2, 200));
714 mcBase->Scale(1.0 / mcBase->Integral(2, 200));
717 TH1* ratioBase = (TH1*) resultBase->Clone("ratioBase");
718 ratioBase->Divide(mcBase, ratioBase, 1, 1, "B");
720 TCanvas* canvas = new TCanvas(epsName, epsName, 800, 400);
721 canvas->SetRightMargin(0.05);
722 canvas->SetTopMargin(0.05);
724 for (Int_t n=0; n<nResultSyst; ++n)
727 result[n]->Scale(1.0 / result[n]->Integral(2, 200));
728 mc[n]->Scale(1.0 / mc[n]->Integral(2, 200));
730 result[n]->GetXaxis()->SetRangeUser(0, displayRange);
731 result[n]->SetStats(kFALSE);
734 TH1* ratio = (TH1*) result[n]->Clone("ratio");
735 ratio->Divide(mc[n], ratio, 1, 1, "B");
736 ratio->Add(ratioBase, -1);
738 ratio->SetTitle(";true multiplicity;Ratio_{syst} (t/u) - Ratio (t/u)");
739 ratio->GetYaxis()->SetRangeUser(-1, 1);
740 ratio->SetLineColor(n+1);
741 ratio->DrawCopy((n == 0) ? "HIST" : "SAME HIST");
743 // get average of ratio
745 for (Int_t i=2; i<=ratioRange; ++i)
746 sum += TMath::Abs(ratio->GetBinContent(i));
749 printf("%d) Average (2..%d) of |ratio - ratioBase| is %f\n", n, ratioRange, sum);
752 TLine* line = new TLine(0, 0, displayRange, 0);
753 line->SetLineWidth(2);
756 line = new TLine(0, 0.1, displayRange, 0.1);
757 line->SetLineWidth(2);
758 line->SetLineStyle(2);
760 line = new TLine(0, -0.1, displayRange, -0.1);
761 line->SetLineWidth(2);
762 line->SetLineStyle(2);
767 canvas->SaveAs(epsName);
768 canvas->SaveAs(Form("%s.gif", epsName.Data()));
773 TCanvas* DrawRatioDeductSmooth(TH1* mcBase, TH1* resultBase, Int_t nResultSyst, TH1** mc, TH1** result, TString epsName)
775 // draws the ratios of each mc to the corresponding result
776 // deducts from each ratio the ratio of mcBase / resultBase
777 // smoothens the ratios by a sliding window
780 resultBase->Scale(1.0 / resultBase->Integral(2, 200));
781 mcBase->Scale(1.0 / mcBase->Integral(2, 200));
784 TH1* ratioBase = (TH1*) resultBase->Clone("ratioBase");
785 ratioBase->Divide(mcBase, ratioBase, 1, 1, "B");
787 TCanvas* canvas = new TCanvas(epsName, epsName, 800, 400);
788 canvas->SetRightMargin(0.05);
789 canvas->SetTopMargin(0.05);
791 for (Int_t n=0; n<nResultSyst; ++n)
794 result[n]->Scale(1.0 / result[n]->Integral(2, 200));
795 mc[n]->Scale(1.0 / mc[n]->Integral(2, 200));
797 result[n]->GetXaxis()->SetRangeUser(0, displayRange);
798 result[n]->SetStats(kFALSE);
801 TH1* ratio = (TH1*) result[n]->Clone("ratio");
802 ratio->Divide(mc[n], ratio, 1, 1, "B");
803 ratio->Add(ratioBase, -1);
805 //new TCanvas; ratio->DrawCopy();
807 ratio->SetBinContent(1, 0); ratio->SetBinError(1, 0);
811 //ratio->SetLineColor(1); ratio->DrawCopy("SAME");
814 ratio->SetTitle(";true multiplicity;Ratio_{syst} (t/u) - Ratio (t/u) (smoothed)");
815 ratio->GetYaxis()->SetRangeUser(-0.3, 0.3);
816 ratio->SetLineColor((n / 2)+1);
817 ratio->SetLineStyle((n % 2)+1);
818 ratio->DrawCopy((n == 0) ? "HIST" : "SAME HIST");
820 // get average of ratio
822 for (Int_t i=2; i<=150; ++i)
823 sum += TMath::Abs(ratio->GetBinContent(i));
826 printf("%d) Average (2..150) of |ratio - ratioBase| is %f\n", n, sum);
829 TLine* line = new TLine(0, 0, displayRange, 0);
830 line->SetLineWidth(2);
833 line = new TLine(0, 0.1, displayRange, 0.1);
834 line->SetLineWidth(2);
835 line->SetLineStyle(2);
837 line = new TLine(0, -0.1, displayRange, -0.1);
838 line->SetLineWidth(2);
839 line->SetLineStyle(2);
844 canvas->SaveAs(epsName);
845 canvas->SaveAs(Form("%s.gif", epsName.Data()));
850 void DrawResiduals(const char* fileName, const char* epsName)
854 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
855 TFile::Open(fileName);
856 mult->LoadHistograms("Multiplicity");
858 TH1* measured = mult->GetMultiplicityESD(etaRange)->ProjectionY("myesd", 1, 1);
859 TH1* unfoldedFolded = mult->CalculateMultiplicityESD(mult->GetMultiplicityESDCorrected(etaRange), etaRange)->ProjectionY("myfolded", 1, 1);
862 unfoldedFolded->Scale(1.0 / unfoldedFolded->Integral(2, displayRange+1));
863 unfoldedFolded->Scale(measured->Integral(2, displayRange+1));
865 TCanvas* canvas = new TCanvas(epsName, epsName, 800, 600);
866 canvas->Range(0, 0, 1, 1);
868 TPad* pad1 = new TPad(Form("%s_pad1", epsName), "", 0, 0.5, 1, 1);
873 TPad* pad2 = new TPad(Form("%s_pad2", epsName), "", 0, 0.02, 1, 0.5);
878 TPad* pad3 = new TPad(Form("%s_pad3", epsName), "", 0.15, 0.5, 0.35, 0.75);
881 pad3->SetRightMargin(0.05);
882 pad3->SetTopMargin(0.05);
885 pad1->SetRightMargin(0.05);
886 pad2->SetRightMargin(0.05);
888 // no border between them
889 pad1->SetBottomMargin(0);
890 pad2->SetTopMargin(0);
894 measured->GetXaxis()->SetLabelSize(0.06);
895 measured->GetYaxis()->SetLabelSize(0.06);
896 measured->GetXaxis()->SetTitleSize(0.06);
897 measured->GetYaxis()->SetTitleSize(0.06);
898 measured->GetYaxis()->SetTitleOffset(0.6);
900 measured->GetXaxis()->SetRangeUser(0, displayRange);
902 measured->SetTitle(Form(";%s;Entries", GetMultLabel(etaRange, kFALSE)));
903 measured->SetStats(kFALSE);
905 measured->DrawCopy("HIST");
908 unfoldedFolded->SetMarkerStyle(5);
909 unfoldedFolded->SetMarkerColor(2);
910 unfoldedFolded->SetLineColor(2);
911 unfoldedFolded->DrawCopy("SAME PHIST");
913 TLegend* legend = new TLegend(0.6, 0.65, 0.95, 0.9);
914 legend->AddEntry(measured, "Measured distribution", "L");
915 legend->AddEntry(unfoldedFolded, "R #otimes unfolded distribution", "P");
916 legend->SetFillColor(0);
917 legend->SetTextSize(0.06);
921 pad2->SetBottomMargin(0.15);
925 TH1* residual = (TH1*) measured->Clone("residual");
926 unfoldedFolded->Sumw2();
928 residual->Add(unfoldedFolded, -1);
931 TH1* residualHist = new TH1F("residualHist", ";", 11, -3, 3);
932 residualHist->Sumw2();
935 for (Int_t i=1; i<=displayRange+1; ++i)
937 if (measured->GetBinError(i) > 0)
939 residual->SetBinContent(i, residual->GetBinContent(i) / measured->GetBinError(i));
940 residual->SetBinError(i, 1);
942 residualHist->Fill(residual->GetBinContent(i));
943 chi2 += residual->GetBinContent(i) * residual->GetBinContent(i);
947 residual->SetBinContent(i, 0);
948 residual->SetBinError(i, 0);
952 Printf("chi2 / ndf = %f / %d = %f", chi2, displayRange+1, chi2 / (displayRange+1));
954 residual->GetYaxis()->SetTitle("Residuals: (1/e) (M - R #otimes U)");
955 residual->GetYaxis()->SetRangeUser(-4.5, 4.5);
956 residual->DrawCopy();
958 TLine* line = new TLine(-0.5, 0, displayRange + 0.5, 0);
959 line->SetLineWidth(2);
963 residualHist->SetStats(kFALSE);
964 residualHist->SetLabelSize(0.08, "xy");
965 residualHist->Fit("gaus");
966 residualHist->Draw("HIST");
967 residualHist->FindObject("gaus")->Draw("SAME");
970 canvas->SaveAs(canvas->GetName());
972 //const char* epsName2 = "proj.eps";
973 //TCanvas* canvas = new TCanvas(epsName2, epsName2, 800, 600);
974 //canvas->SetGridx();
975 //canvas->SetGridy();
977 //canvas->SaveAs(canvas->GetName());
980 void chi2FluctuationResult()
984 TFile::Open("chi2_noregularization.root");
985 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
986 mult->LoadHistograms("Multiplicity");
988 TH1* mcHist = mult->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, 1);
990 mult->DrawComparison("MinuitChi2", etaRange, kFALSE, kTRUE, mcHist, kTRUE);
992 TCanvas* canvas = (TCanvas*) gROOT->FindObject("MinuitChi2_DrawComparison_1");
993 ((TH1*) canvas->FindObject("proj"))->GetXaxis()->SetRangeUser(0, displayRange);
994 ((TH1*) canvas->FindObject("fCurrentESD"))->GetXaxis()->SetRangeUser(0, displayRange);
995 //((TH1*) canvas->FindObject("proj"))->GetXaxis()->SetTitle(GetMultTitle());
996 //((TH1*) canvas->FindObject("fCurrentESD"))->GetXaxis()->->SetTitle(GetMultTitle(etaRange, kFALSE));
997 canvas->SaveAs("chi2FluctuationResult.eps");
1000 void DrawUnfolded(const char* fileName, const char* eps)
1004 TFile::Open(fileName);
1006 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
1007 mult->LoadHistograms("Multiplicity");
1009 TH1* mcHist = mult->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, mult->GetMultiplicityVtx(etaRange)->GetNbinsX());
1010 TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
1012 DrawResultRatio(mcHist, result, eps);
1015 void minimizationInfluenceAlpha()
1019 TFile::Open(measuredFile);
1020 AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
1021 mult2->LoadHistograms("Multiplicity");
1023 TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, mult2->GetMultiplicityVtx(etaRange)->GetNbinsX());
1024 mcHist->Scale(1.0 / mcHist->Integral());
1025 mcHist->SetStats(kFALSE);
1026 mcHist->SetTitle(";True multiplicity n in |#eta| < 1.0;P(n)");
1028 TCanvas* canvas = new TCanvas("minimizationInfluenceAlpha", "minimizationInfluenceAlpha", 1000, 350);
1029 canvas->Divide(3, 1, 0.005);
1031 TFile::Open("chi2compare-influencealpha/EvaluateChi2Method.root");
1033 TH1* hist1 = (TH1*) gFile->Get("MinuitChi2_00_2_3.162278");
1034 TH1* hist2 = (TH1*) gFile->Get("MinuitChi2_07_2_10000.000000");
1035 TH1* hist3 = (TH1*) gFile->Get("MinuitChi2_13_2_10000000.000000");
1037 /*mcHist->Rebin(2); mcHist->Scale(0.5);
1038 hist1->Rebin(2); hist1->Scale(0.5);
1039 hist2->Rebin(2); hist2->Scale(0.5);
1040 hist3->Rebin(2); hist3->Scale(0.5);*/
1042 mcHist->GetXaxis()->SetRangeUser(0, displayRange);
1043 mcHist->SetLabelSize(0.06, "xy");
1044 mcHist->SetTitleSize(0.06, "xy");
1045 mcHist->GetYaxis()->SetTitleOffset(1.5);
1050 gPad->SetRightMargin(0.03);
1051 gPad->SetLeftMargin(0.19);
1052 gPad->SetTopMargin(0.05);
1053 gPad->SetBottomMargin(0.13);
1057 hist1->SetMarkerStyle(5);
1058 hist1->SetMarkerColor(2);
1059 hist1->Draw("SAME PE");
1062 gPad->SetRightMargin(0.03);
1063 gPad->SetLeftMargin(0.19);
1064 gPad->SetTopMargin(0.05);
1065 gPad->SetBottomMargin(0.13);
1070 hist2->SetMarkerStyle(5);
1071 hist2->SetMarkerColor(2);
1072 hist2->Draw("SAME PE");
1075 gPad->SetRightMargin(0.03);
1076 gPad->SetLeftMargin(0.19);
1077 gPad->SetTopMargin(0.05);
1078 gPad->SetBottomMargin(0.13);
1083 hist3->SetMarkerStyle(5);
1084 hist3->SetMarkerColor(2);
1085 hist3->Draw("SAME PE");
1087 canvas->SaveAs("minimizationInfluenceAlpha.eps");
1092 gSystem->Load("libPWG0base");
1094 TFile::Open(correctionFile);
1095 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
1096 mult->LoadHistograms("Multiplicity");
1098 TH1* fCurrentESD = mult->GetMultiplicityVtx(etaRange)->ProjectionY();
1099 fCurrentESD->Sumw2();
1100 fCurrentESD->Scale(1.0 / fCurrentESD->Integral());
1102 TF1* func = new TF1("nbd", "[0] * TMath::Binomial([2]+TMath::Nint(x)-1, [2]-1) * pow([1] / ([1]+[2]), TMath::Nint(x)) * pow(1 + [1]/[2], -[2])");
1103 func->SetParNames("scaling", "averagen", "k");
1104 func->SetParLimits(0, 0.001, fCurrentESD->GetMaximum() * 1000);
1105 func->SetParLimits(1, 0.001, 1000);
1106 func->SetParLimits(2, 0.001, 1000);
1107 func->SetParameters(fCurrentESD->GetMaximum() * 100, 10, 2);
1109 TF1* lognormal = new TF1("lognormal", "[0]*exp(-(log(x)-[1])^2/(2*[2]^2))/(x*[2]*TMath::Sqrt(2*TMath::Pi()))", 0.01, 500);
1110 lognormal->SetParNames("scaling", "mean", "sigma");
1111 lognormal->SetParameters(1, 1, 1);
1112 lognormal->SetParLimits(0, 0, 10);
1113 lognormal->SetParLimits(1, 0, 100);
1114 lognormal->SetParLimits(2, 1e-3, 10);
1116 TCanvas* canvas = new TCanvas("c1", "c1", 700, 400);
1117 fCurrentESD->SetStats(kFALSE);
1118 fCurrentESD->GetYaxis()->SetTitleOffset(1.3);
1119 fCurrentESD->SetTitle(";true multiplicity (N);P_{N}");
1120 fCurrentESD->Draw("HIST");
1121 fCurrentESD->GetXaxis()->SetRangeUser(0, 200);
1122 fCurrentESD->Fit(func, "W0", "", 0, 50);
1123 func->SetRange(0, 100);
1125 printf("chi2 = %f\n", func->GetChisquare());
1127 fCurrentESD->Fit(lognormal, "W0", "", 0.01, 100);
1128 lognormal->SetLineColor(2);
1129 lognormal->SetLineStyle(2);
1130 lognormal->SetRange(0, 100);
1131 lognormal->Draw("SAME");
1133 canvas->SaveAs("NBDFit.eps");
1136 void StartingConditions()
1138 // data generated by runMultiplicitySelector.C StartingConditions
1140 const char* name = "StartingConditions";
1142 TFile* file = TFile::Open(Form("%s.root", name));
1144 TCanvas* canvas = new TCanvas(name, name, 1200, 600);
1145 canvas->Divide(2, 1);
1147 TH1* mc = (TH1*) file->Get("mc");
1149 mc->Scale(1.0 / mc->Integral(2, displayRange));
1151 //Int_t marker[] = {24, 25, 26, 27, 28, 2, 3, 4, 5};
1153 TLegend* legend = new TLegend(0.6, 0.7, 0.99, 0.99);
1154 legend->SetFillColor(0);
1155 legend->SetTextSize(0.04);
1157 const char* names[] = { "True", "Measured 1", "Measured 2", "Measured 3", "NBD", "Flat" };
1159 for (Int_t i=0; i<6; ++i)
1165 TH1* chi2Result = (TH1*) file->Get(Form("chi2Result_%d", id));
1166 TH1* bayesResult = (TH1*) file->Get(Form("bayesResult_%d", id));
1168 chi2Result->Scale(1.0 / chi2Result->Integral(2, displayRange));
1169 bayesResult->Scale(1.0 / bayesResult->Integral(2, displayRange));
1171 chi2Result->Divide(mc, chi2Result, 1, 1, "");
1172 bayesResult->Divide(mc, bayesResult, 1, 1, "");
1174 chi2Result->SetTitle(Form("a) #chi^{2}-minimization;%s;MC / unfolded", GetMultLabel()));
1175 chi2Result->GetXaxis()->SetRangeUser(0, displayRange);
1176 chi2Result->GetYaxis()->SetRangeUser(0.7, 1.3);
1177 chi2Result->GetYaxis()->SetTitleOffset(1.7);
1178 //chi2Result->SetMarkerStyle(marker[i]);
1179 chi2Result->SetLineColor(i+1);
1180 chi2Result->SetMarkerColor(i+1);
1181 chi2Result->SetStats(kFALSE);
1183 bayesResult->SetTitle(Form("b) Bayesian unfolding;%s;MC / unfolded", GetMultLabel()));
1184 bayesResult->GetXaxis()->SetRangeUser(0, displayRange);
1185 bayesResult->GetYaxis()->SetRangeUser(0.7, 1.3);
1186 bayesResult->GetYaxis()->SetTitleOffset(1.7);
1187 bayesResult->SetStats(kFALSE);
1188 //bayesResult->SetLineColor(2);
1189 bayesResult->SetLineColor(i+1);
1192 gPad->SetRightMargin(0.05);
1193 gPad->SetLeftMargin(0.12);
1196 chi2Result->DrawCopy((i == 0) ? "HIST" : "HIST SAME");
1199 gPad->SetRightMargin(0.05);
1200 gPad->SetLeftMargin(0.12);
1203 bayesResult->DrawCopy((i == 0) ? "HIST" : "HIST SAME");
1205 //TLine* line = new TLine(0, 1, 150, 1);
1208 legend->AddEntry(chi2Result, names[i]);
1215 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
1218 void StatisticsPlot()
1220 const char* name = "StatisticsPlot";
1222 TFile* file = TFile::Open(Form("%s.root", name));
1224 TCanvas* canvas = new TCanvas(name, name, 600, 400);
1226 TGraph* fitResultsChi2 = (TGraph*) file->Get("fitResultsChi2");
1227 fitResultsChi2->SetTitle(";number of measured events;P_{1}");
1228 fitResultsChi2->GetYaxis()->SetRangeUser(0, 2);
1229 fitResultsChi2->Draw("AP");
1231 TF1* f = new TF1("f", "[0]/x", 1, 1e4);
1232 fitResultsChi2->Fit(f);
1234 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
1239 const char* plotname = "chi2Result";
1241 name = "StatisticsPlotRatios";
1242 canvas = new TCanvas(name, name, 600, 400);
1244 for (Int_t i=0; i<5; ++i)
1246 mc[i] = (TH1*) file->Get(Form("mc_%d", i));
1247 result[i] = (TH1*) file->Get(Form("%s_%d", plotname, i));
1249 result[i]->SetLineColor(i+1);
1250 result[i]->Draw(((i == 0) ? "" : "SAME"));
1254 void Draw2Unfolded(const char* file1, const char* file2, const char* output)
1259 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
1260 mult->LoadHistograms("Multiplicity");
1262 // result with systematic effect
1264 AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
1265 mult2->LoadHistograms("Multiplicity");
1267 TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, 1);
1268 TH1* result1 = (TH1*) mult2->GetMultiplicityESDCorrected(etaRange)->Clone("result1"); // from file2 (with syst)
1269 TH1* result2 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("result2"); // from file1 (without syst)
1271 DrawResultRatio(mcHist, result1, "tmp1.eps");
1272 DrawResultRatio(mcHist, result2, "tmp2.eps");
1273 Draw2ResultRatio(mcHist, result1, result2, output);
1281 Draw2Unfolded("self.root", "pythia.root", "test.eps");
1283 canvas = (TCanvas*) gROOT->GetListOfCanvases()->Last();
1284 pad1 = (TCanvas*)canvas->GetListOfPrimitives()->First();
1285 pad2 = (TCanvas*)canvas->GetListOfPrimitives()->Last();
1286 legend = (TLegend*)pad1->GetListOfPrimitives()->Last();
1288 ((TH1*)pad2->GetListOfPrimitives()->At(1))->GetYaxis()->SetTitle("Ratio (Pythia / Phojet)");
1289 ((TLegendEntry*)legend->GetListOfPrimitives()->At(1))->SetLabel("Unfolded distribution (Pythia)");
1290 ((TLegendEntry*)legend->GetListOfPrimitives()->At(2))->SetLabel("Unfolded distribution (Phojet)");
1291 canvas->SaveAs("PythiaPhojet.eps");
1298 Draw2Unfolded("chi2_ideal.root", "chi2_misaligned.root", "test.eps");
1300 canvas = (TCanvas*) gROOT->GetListOfCanvases()->Last();
1301 pad1 = (TCanvas*)canvas->GetListOfPrimitives()->First();
1302 pad2 = (TCanvas*)canvas->GetListOfPrimitives()->Last();
1303 legend = (TLegend*)pad1->GetListOfPrimitives()->Last();
1305 ((TH1*)pad2->GetListOfPrimitives()->At(1))->GetYaxis()->SetTitle("Ratio (misaligned / realigned)");
1306 ((TLegendEntry*)legend->GetListOfPrimitives()->At(1))->SetLabel("Unfolded distribution (misaligned)");
1307 ((TLegendEntry*)legend->GetListOfPrimitives()->At(2))->SetLabel("Unfolded distribution (realigned)");
1308 canvas->SaveAs("SystematicMisalignment.eps");
1311 void SystematicLowEfficiency()
1313 Draw2Unfolded("chi2.root", "chi2_loweff_5.root", "SystematicLowEfficiency.eps");
1316 void SystematicLowEfficiency2()
1320 AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open("chi2.root");
1321 TH1* result2 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("result2");
1322 TH1* mcHist = mult->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, 1);
1323 result2->Scale(1.0 / result2->Integral(2, displayRange));
1324 result2->Scale(mcHist->Integral(2, displayRange));
1326 mult = AliMultiplicityCorrection::Open("chi2_loweff_5.root");
1327 TH1* result1 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("result1");
1329 mult = AliMultiplicityCorrection::Open("chi2_loweff_2.root");
1330 TH1* ratio2 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("ratio2");
1331 ratio2->Scale(1.0 / ratio2->Integral(2, displayRange));
1332 ratio2->Scale(mcHist->Integral(2, displayRange));
1333 ratio2->Divide(result2);
1335 mult = AliMultiplicityCorrection::Open("chi2_loweff_1.root");
1336 TH1* ratio3 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("ratio3");
1337 ratio3->Scale(1.0 / ratio3->Integral(2, displayRange));
1338 ratio3->Scale(mcHist->Integral(2, displayRange));
1339 ratio3->Divide(result2);
1341 Draw2ResultRatios(mcHist, result1, result2, ratio2, ratio3, "SystematicLowEfficiency2.eps");
1344 void SystematicMisalignment()
1346 gSystem->Load("libPWG0base");
1348 TFile::Open(correctionFile);
1349 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
1350 mult->LoadHistograms("Multiplicity");
1352 TFile::Open("multiplicityMC_100k_fullmis.root");
1353 AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
1354 mult2->LoadHistograms("Multiplicity");
1356 mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
1357 mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
1358 mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
1360 TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
1361 TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
1363 DrawResultRatio(mcHist, result, "SystematicMisalignment.eps");
1366 void SystematicMisalignmentTPC()
1368 gSystem->Load("libPWG0base");
1372 TFile::Open(correctionFile);
1373 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
1374 mult->LoadHistograms("Multiplicity");
1376 TFile::Open("multiplicityMC_TPC_100k_fullmis.root");
1377 AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
1378 mult2->LoadHistograms("Multiplicity");
1380 mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
1381 mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
1382 mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
1384 TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
1385 TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
1387 DrawResultRatio(mcHist, result, "SystematicMisalignmentTPC.eps");
1390 void LowMomentumEffectSPD()
1392 // this function increases/reduces the correction as function of pt between 0 and 0.2 gev by +-50% to 0% and checks the effect on the overall correction factor
1393 // only a normal acceptance region is considered to not get a bias by the edges
1396 TFile::Open("multiplicity.root");
1399 AliCorrection* correction[8];
1402 for (Int_t loop=0; loop<3; loop++)
1405 Float_t sumMeas = 0;
1407 Printf("loop %d", loop);
1408 for (Int_t i=0; i<4; ++i)
1410 Printf("correction %d", i);
1412 TString name; name.Form("correction_%d", i);
1413 correction[i] = new AliCorrection(name, name);
1414 correction[i]->LoadHistograms();
1416 TH3* gene = correction[i]->GetTrackCorrection()->GetGeneratedHistogram();
1417 TH3* meas = correction[i]->GetTrackCorrection()->GetMeasuredHistogram();
1419 Float_t vtxRange = 5.9;
1420 gene->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
1421 meas->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
1423 Float_t etaRange = 0.99;
1424 gene->GetYaxis()->SetRangeUser(-etaRange, etaRange);
1425 meas->GetYaxis()->SetRangeUser(-etaRange, etaRange);
1427 TH1* genePt = gene->Project3D(Form("z_%d", i));
1428 TH1* measPt = meas->Project3D(Form("z_%d", i));
1432 for (Int_t x=1; x<=genePt->GetNbinsX(); x++)
1434 Float_t pt = genePt->GetXaxis()->GetBinCenter(x);
1440 factor = 1.5 - pt / 0.2 * 0.5;
1442 factor = 0.5 + pt / 0.2 * 0.5;
1443 //Printf("%f", factor);
1444 genePt->SetBinContent(x, genePt->GetBinContent(x) * factor);
1445 measPt->SetBinContent(x, measPt->GetBinContent(x) * factor);
1450 //new TCanvas; genePt->DrawCopy(); measPt->DrawCopy("SAME");
1452 sumGen += genePt->Integral();
1453 sumMeas += measPt->Integral();
1455 Float_t average = measPt->Integral() / genePt->Integral();
1457 Printf("The average efficiency of this correction is %f", average);
1460 Float_t average = sumMeas / sumGen;
1462 Printf("The average efficiency of all corrections is %f", average);
1463 values[loop] = average;
1466 Printf("relative is %f and %f", values[1] / values[0], values[2] / values[0]);
1470 void EfficiencySpecies(Bool_t addDecayStopped = kFALSE)
1474 Int_t marker[] = {24, 25, 26, 27};
1475 Int_t color[] = {1, 2, 4, 3};
1478 //const char* fileName[] = { "multiplicityMC_400k_syst.root", "multiplicityMC_TPC_4kfiles_syst.root" };
1479 const char* fileName[] = { "LHC09b9_0.9TeV_0T/mb1/spd/multiplicity.root", "LHC09b8_0.9TeV_0.5T/mb1/tpc/multiplicity.root" };
1480 //const char* fileName[] = { "spd/multiplicity.root", "tpc/multiplicity.root" };
1481 //const char* fileName[] = { "multiplicity.root", "multiplicity.root" };
1482 Float_t etaRangeArr[] = {0.49, 0.9};
1483 const char* titles[] = { "SPD Tracklets", "TPC Tracks" };
1485 TCanvas* canvas = new TCanvas("EfficiencySpecies", "EfficiencySpecies", 1000, 500);
1486 canvas->Divide(2, 1);
1488 TCanvas* canvas3 = new TCanvas("EfficiencySpecies_comb", "EfficiencySpecies_comb", 600, 600);
1491 gPad->SetRightMargin(0.05);
1492 gPad->SetTopMargin(0.05);
1494 TLegend* legends[2];
1496 for (Int_t loop=0; loop<2; ++loop)
1498 Printf("%s", fileName[loop]);
1500 TCanvas* canvas2 = new TCanvas(Form("EfficiencySpecies_%d", loop), Form("EfficiencySpecies_%d", loop), 600, 600);
1503 gPad->SetRightMargin(0.05);
1504 gPad->SetTopMargin(0.05);
1506 AliCorrection* correction[8];
1512 gPad->SetRightMargin(0.05);
1514 TLegend* legend = new TLegend(0.6, 0.4, 0.85, 0.6);
1515 legend->SetFillColor(0);
1516 legend->SetEntrySeparation(0.2);
1517 legend->SetTextSize(gStyle->GetTextSize());
1519 legends[loop] = new TLegend(0.4+loop*0.3, 0.2, 0.6+loop*0.3, 0.5);
1520 legends[loop]->SetFillColor(0);
1521 legends[loop]->SetEntrySeparation(0.2);
1522 legends[loop]->SetTextSize(gStyle->GetTextSize());
1523 legends[loop]->SetHeader((loop == 0) ? "SPD" : "TPC");
1528 TFile* file = TFile::Open(fileName[loop]);
1531 Printf("Could not open %s", fileName[loop]);
1536 Float_t sumMeas = 0;
1538 Float_t sumGenAbove02 = 0;
1539 Float_t sumMeasAbove02 = 0;
1541 for (Int_t i=0; i<3; ++i)
1543 Printf("correction %d", i);
1545 TString name; name.Form("correction_%d", i);
1546 correction[i] = new AliCorrection(name, name);
1547 correction[i]->LoadHistograms();
1549 TH3* gene = correction[i]->GetTrackCorrection()->GetGeneratedHistogram();
1550 TH3* meas = correction[i]->GetTrackCorrection()->GetMeasuredHistogram();
1553 Float_t vtxRange = 3.9;
1554 gene->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
1555 meas->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
1557 // empty over/underflow bin in eta, setting range to +-2 is not enough because this is the maximum range, Project3D takes them into account then (might be a bug)
1558 /*for (Int_t x = 1; x <= gene->GetNbinsX(); x++)
1559 for (Int_t z = 1; z <= gene->GetNbinsZ(); z++)
1561 gene->SetBinContent(x, 0, z, 0);
1562 gene->SetBinContent(x, gene->GetNbinsY()+1, z, 0);
1563 meas->SetBinContent(x, 0, z, 0);
1564 meas->SetBinContent(x, gene->GetNbinsY()+1, z, 0);
1568 Float_t etaBegin = -etaRangeArr[loop];
1569 Float_t etaEnd = etaRangeArr[loop];
1572 gene->GetYaxis()->SetRangeUser(etaBegin, etaEnd);
1573 meas->GetYaxis()->SetRangeUser(etaBegin, etaEnd);
1575 TH1* genePt = gene->Project3D(Form("z_%d", i));
1576 TH1* measPt = meas->Project3D(Form("z_%d", i));
1580 Printf("WARNING: Rebinning for protons!");
1588 for (Int_t x=0; x<=genePt->GetNbinsX()+1; x++)
1590 genePt->SetBinError(x, TMath::Sqrt(genePt->GetBinContent(x)));
1591 measPt->SetBinError(x, TMath::Sqrt(measPt->GetBinContent(x)));
1594 sumGen += genePt->Integral();
1595 sumMeas += measPt->Integral();
1597 sumGenAbove02 += genePt->Integral(genePt->GetXaxis()->FindBin(0.21), genePt->GetNbinsX());
1598 sumMeasAbove02 += measPt->Integral(genePt->GetXaxis()->FindBin(0.21), genePt->GetNbinsX());
1600 TH1* effPt = (TH1*) genePt->Clone(Form("effPt_%d", i));
1602 effPt->Divide(measPt, genePt, 1, 1, "B");
1605 for (bin=20; bin>=1; bin--)
1607 if (effPt->GetBinContent(bin) < 0.5)
1611 Printf("Eff. below 50%% at bin %d, i.e. %.3f GeV/c", bin, effPt->GetXaxis()->GetBinUpEdge(bin));
1613 Float_t fraction = genePt->Integral(1, bin) / genePt->Integral();
1614 Printf("%.4f of the particles are below that momentum", fraction);
1616 below += genePt->Integral(1, bin);
1617 total += genePt->Integral();
1619 effPt->SetLineColor(color[i]);
1620 effPt->SetMarkerColor(color[i]);
1621 effPt->SetMarkerStyle(marker[i]);
1622 effPt->SetMarkerSize(2);
1624 effPt->GetXaxis()->SetRangeUser(0, 1);
1625 effPt->GetYaxis()->SetRangeUser(0.001, 1);
1627 effPt->GetXaxis()->SetTitleOffset(1.1);
1628 effPt->GetYaxis()->SetTitleOffset(1.2);
1630 effPt->GetXaxis()->SetTitle("p_{T} (GeV/c)");
1632 effPt->SetStats(kFALSE);
1633 effPt->SetTitle(titles[loop]);
1634 effPt->GetYaxis()->SetTitle("Efficiency");
1637 effPt->DrawCopy((i == 0) ? "" : "SAME");
1640 effPt->SetTitle("");
1641 effPt->DrawCopy((i == 0) ? "" : "SAME");
1644 effPtClone = (TH1*) effPt->Clone("effPtClone");
1645 effPtClone->SetMarkerStyle(marker[i]-4*loop);
1646 effPtClone->DrawCopy((i == 0 && loop == 0) ? "" : "SAME");
1648 legend->AddEntry(effPt, ((i == 0) ? "#pi^{#pm}" : ((i == 1) ? "K^{#pm}" : "p,#bar{p}")), "P");
1649 legends[loop]->AddEntry(effPtClone, ((i == 0) ? "#pi^{#pm}" : ((i == 1) ? "K^{#pm}" : "p,#bar{p}")), "P");
1650 //legend2->AddEntry(effPt, Form("%s %s", (loop == 0) ? "SPD" : "TPC", ((i == 0) ? "#pi^{#pm}" : ((i == 1) ? "K^{#pm}" : "p,#bar{p}"))), "P");
1652 if (addDecayStopped)
1654 name.Form("correction_%d", i+4);
1655 corr = new AliCorrection(name, name);
1656 corr->LoadHistograms();
1658 TH3* gene = corr->GetTrackCorrection()->GetGeneratedHistogram();
1659 TH3* meas = corr->GetTrackCorrection()->GetMeasuredHistogram();
1662 gene->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
1663 meas->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
1664 gene->GetYaxis()->SetRangeUser(-etaRangeArr[loop], etaRangeArr[loop]);
1665 meas->GetYaxis()->SetRangeUser(-etaRangeArr[loop], etaRangeArr[loop]);
1667 TH1* decayed = gene->Project3D(Form("z_%d", i+4));
1668 TH1* stopped = meas->Project3D(Form("z_%d", i+4));
1670 Printf("%d: %d decayed, %d stopped, out of %d", i, (Int_t) decayed->Integral(), (Int_t) stopped->Integral(), (Int_t) genePt->Integral());
1672 decayed->Divide(decayed, genePt, 1, 1, "B");
1673 stopped->Divide(stopped, genePt, 1, 1, "B");
1675 decayed->SetMarkerStyle(20);
1676 stopped->SetMarkerStyle(21);
1677 stopped->SetMarkerColor(2);
1679 new TCanvas(Form("all_%d_%d", loop, i), Form("all_%d_%d", loop, i), 600, 600);
1681 decayed->DrawCopy("SAME");
1682 stopped->DrawCopy("SAME");
1684 decayed->Add(stopped);
1685 decayed->Add(effPt);
1686 decayed->SetMarkerStyle(22);
1687 decayed->SetMarkerColor(4);
1688 decayed->DrawCopy("SAME");
1693 Printf("In total %.4f of the particles are below their effective pt cut off", (Float_t) below / total);
1695 Printf("%f measured, %f generated, effiency: %f", sumGen, sumMeas, sumMeas / sumGen);
1696 Printf("Above 0.2 GeV/c: %f measured, %f generated, effiency: %f", sumGenAbove02, sumMeasAbove02, sumMeasAbove02 / sumGenAbove02);
1703 canvas2->SaveAs(Form("%s.eps", canvas2->GetName()));
1707 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
1712 canvas3->SaveAs(Form("%s.eps", canvas3->GetName()));
1718 aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt_ref.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
1719 mv unfolded.root chi2_ptref.root
1720 aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt0.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
1721 mv unfolded.root chi2_pt0.root
1722 aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt1.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
1723 mv unfolded.root chi2_pt1.root
1724 aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt0_25.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
1725 mv unfolded.root chi2_pt0_25.root
1726 aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt1_25.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
1727 mv unfolded.root chi2_pt1_25.root
1733 const char* files[] = { "chi2_ptref.root", "chi2_pt0.root", "chi2_pt1.root", "chi2_pt0_25.root", "chi2_pt1_25.root"};
1736 for (Int_t i = 0; i<nMax; ++i)
1738 AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open(files[i]);
1739 results[i] = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone(Form("result_%d", i));
1742 const char* legendStrings[] = { "Reduced 50%", "Enhanced 50%", "Reduced 25%", "Enhanced 25%" };
1743 DrawRatio(results[0], nMax-1, results+1, "LowMomentumSyst.eps", kFALSE, legendStrings);
1746 void ParticleSpeciesComparison()
1753 // loop over cases (normal, enhanced/reduced ratios)
1755 for (Int_t i = 0; i<nMax; ++i)
1757 AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open(Form("chi2_species_%d.root", i), Form("Multiplicity_%d", i));
1759 mc = mult->GetMultiplicityVtx(etaRange)->ProjectionY("mymchist", 1, 1);
1760 results[i] = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone(Form("result_%d", i));
1763 DrawResultRatio(mc, results[0], "ParticleSpeciesComparison1_1.eps");
1765 for (Int_t i=1; i<=results[0]->GetNbinsX(); i++)
1767 results[0]->SetBinError(i, 0);
1768 mc->SetBinError(i, 0);
1771 const char* legendStrings[] = { "K #times 0.5", "K #times 1.5", "p #times 0.5", "p #times 1.5", "K #times 0.5, p #times 0.5", "K #times 1.5, p #times 1.5", "K #times 0.5, p #times 1.5", "K #times 1.5, p #times 0.5" };
1773 DrawRatio(results[0], nMax-1, results+1, "ParticleSpeciesComparison1_2.eps", kFALSE, legendStrings);
1775 //not valid: draw chi2 uncertainty on top!
1776 /*TFile::Open("bayesianUncertainty_400k_100k_syst.root");
1777 TH1* errorHist = (TH1*) gFile->Get("errorBoth");
1778 errorHist->SetLineColor(1);
1779 errorHist->SetLineWidth(2);
1780 TH1* errorHist2 = (TH1*) errorHist->Clone("errorHist2");
1781 for (Int_t i=1; i<=errorHist->GetNbinsX(); i++)
1783 errorHist->SetBinContent(i, errorHist->GetBinContent(i) + 1);
1784 errorHist2->SetBinContent(i, 1 - errorHist2->GetBinContent(i));
1787 errorHist->DrawCopy("SAME");
1788 errorHist2->DrawCopy("SAME");*/
1790 //canvas->SaveAs(canvas->GetName());
1792 DrawRatio(mc, nMax, results, "ParticleSpeciesComparison1_3.eps", kTRUE, 0);
1794 //errorHist->DrawCopy("SAME");
1795 //errorHist2->DrawCopy("SAME");
1797 //canvas2->SaveAs(canvas2->GetName());
1800 /*void ParticleSpeciesComparison2()
1802 gSystem->Load("libPWG0base");
1804 const char* fileNameMC = "multiplicityMC_400k_syst.root";
1805 const char* fileNameESD = "out.root"; // based on multiplicityMC_100k_syst.root
1808 TFile::Open(fileNameMC);
1809 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
1810 mult->LoadHistograms();
1815 // loop over cases (normal, enhanced/reduced ratios)
1817 for (Int_t i = 0; i<nMax; ++i)
1820 folder.Form("Multiplicity_%d", i);
1822 AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection(folder, folder);
1824 TFile::Open(fileNameESD);
1825 mult2->LoadHistograms();
1827 mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
1831 mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 1e4);
1832 mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, kFALSE);
1833 //mult->DrawComparison(Form("ParticleSpeciesComparison_MinuitChi2_%d", i), etaRange, kFALSE, kTRUE, hist2->ProjectionY("mymchist"));
1837 mult->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100);
1838 //mult->DrawComparison(Form("ParticleSpeciesComparison_Bayesian_%d", i), etaRange, kFALSE, kTRUE, hist2->ProjectionY("mymchist2"));
1841 //Float_t averageRatio = 0;
1842 //mult->GetComparisonResults(0, 0, 0, &averageRatio);
1844 results[i] = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone(Form("result_%d", i));
1846 TH2F* hist2 = mult2->GetMultiplicityVtx(etaRange);
1847 mc[i] = (TH1*) hist2->ProjectionY(Form("mymchist_%d", i), -1, -1, "e");
1849 //TString fileName; fileName.Form("ParticleSpeciesComparison2_%d.eps", i);
1850 //DrawResultRatio(hist2->ProjectionY("mymchist", -1, -1, "e"), results[i], fileName);
1852 //Printf("Case %d. Average ratio is %f", i, averageRatio);
1855 DrawRatio(nMax, mc, results, "ParticleSpeciesComparison2.eps");
1858 TH1* Invert(TH1* eff)
1860 // calculate corr = 1 / eff
1862 TH1* corr = (TH1*) eff->Clone(Form("%s_invert", eff->GetName()));
1865 for (Int_t i=1; i<=eff->GetNbinsX(); i++)
1867 if (eff->GetBinContent(i) > 0)
1869 corr->SetBinContent(i, 1.0 / eff->GetBinContent(i));
1870 corr->SetBinError(i, eff->GetBinError(i) / eff->GetBinContent(i) * corr->GetBinContent(i));
1877 void TriggerVertexCorrection()
1880 // plots the correction performed on the unfolded spectrum to gain the spectrum for the full inelastic sample
1885 TFile::Open(correctionFile);
1886 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
1887 mult->LoadHistograms("Multiplicity");
1889 TH1* corrINEL = Invert(mult->GetEfficiency(etaRange, AliMultiplicityCorrection::kINEL));
1890 TH1* corrNSD = Invert(mult->GetEfficiency(etaRange, AliMultiplicityCorrection::kNSD));
1891 TH1* corrMB = Invert(mult->GetEfficiency(etaRange, AliMultiplicityCorrection::kMB));
1893 TCanvas* canvas = new TCanvas("TriggerVertexCorrection", "TriggerVertexCorrection", 800, 500);
1896 gPad->SetTopMargin(0.05);
1897 gPad->SetRightMargin(0.05);
1899 corrINEL->SetStats(kFALSE);
1900 corrINEL->GetXaxis()->SetRangeUser(0, 12);
1901 corrINEL->GetYaxis()->SetRangeUser(0, 8);
1902 corrINEL->SetTitle(Form(";%s;Correction factor", GetMultLabel()));
1903 corrINEL->SetMarkerStyle(22);
1904 corrINEL->Draw("PE");
1906 corrMB->SetStats(kFALSE);
1907 corrMB->SetLineColor(2);
1908 corrMB->SetMarkerStyle(25);
1909 corrMB->SetMarkerColor(2);
1910 corrMB->Draw("SAME PE");
1912 corrNSD->SetLineColor(4);
1913 corrNSD->SetMarkerStyle(24);
1914 corrNSD->SetMarkerColor(4);
1915 corrNSD->Draw("SAME PE");
1917 Printf(" MB INEL NSD");
1918 Printf("bin 0: %f %f %f", corrMB->GetBinContent(1), corrINEL->GetBinContent(1), corrNSD->GetBinContent(1));
1919 Printf("bin 1: %f %f %f", corrMB->GetBinContent(2), corrINEL->GetBinContent(2), corrNSD->GetBinContent(2));
1921 TLegend* legend = new TLegend(0.3, 0.6, 0.85, 0.85);
1922 legend->SetFillColor(0);
1923 legend->AddEntry(corrINEL, "Correction to inelastic sample");
1924 legend->AddEntry(corrNSD, "Correction to NSD sample");
1925 legend->AddEntry(corrMB, "Correction to triggered sample");
1926 legend->SetTextSize(0.04);
1930 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
1933 void StatisticalUncertainty(Int_t methodType, Bool_t mc = kFALSE)
1937 TFile::Open(correctionFile);
1938 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
1939 mult->LoadHistograms("Multiplicity");
1941 TFile::Open(measuredFile);
1942 AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
1943 mult2->LoadHistograms("Multiplicity");
1945 mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
1947 TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, 1);
1949 AliUnfolding::SetNbins(70, 70);
1950 //AliUnfolding::SetNbins(35, 35);
1951 AliUnfolding::SetChi2Regularization(AliUnfolding::kPol0, 1e3);
1952 AliUnfolding::SetBayesianParameters(1, 10);
1954 TH1* errorMeasured = (TH1*) mult->StatisticalUncertainty((AliUnfolding::MethodType) methodType, etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, kTRUE, kFALSE, ((mc) ? mcHist : 0))->Clone("errorMeasured");
1956 new TCanvas; errorMeasured->Draw();
1959 mult->GetMultiplicityESDCorrected(etaRange)->Scale(1.0 / mult->GetMultiplicityESDCorrected(etaRange)->Integral());
1960 mult->GetMultiplicityESDCorrected(etaRange)->Draw();
1961 mcHist->Scale(1.0 / mcHist->Integral());
1962 mcHist->SetLineColor(2);
1963 mcHist->Draw("SAME");
1968 TH1* errorResponse = (TH1*) mult->StatisticalUncertainty((AliUnfolding::MethodType) methodType, etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, kFALSE, kTRUE, ((mc) ? mcHist : 0))->Clone("errorResponse");
1970 TH1* errorBoth = (TH1*) mult->StatisticalUncertainty((AliUnfolding::MethodType) methodType, etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, kTRUE, kTRUE, ((mc) ? mcHist : 0))->Clone("errorBoth");
1974 TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
1975 DrawResultRatio(mcHist, result, "StatisticalUncertainty2.eps");
1978 TFile* file = new TFile(Form("StatisticalUncertaintySPD%s.root", (methodType == 0) ? "Chi2" : "Bayesian"), "RECREATE");
1979 errorResponse->Write();
1980 errorMeasured->Write();
1985 void DrawStatisticalUncertainty()
1987 TFile::Open("StatisticalUncertainty.root");
1989 errorResponse = (TH1*) gFile->Get("errorResponse");
1990 errorMeasured = (TH1*) gFile->Get("errorMeasured");
1991 errorBoth = (TH1*) gFile->Get("errorBoth");
1993 TCanvas* canvas = new TCanvas("StatisticalUncertainty", "StatisticalUncertainty", 600, 400);
1996 canvas->SetRightMargin(0.05);
1997 canvas->SetTopMargin(0.05);
1999 errorResponse->SetLineColor(1);
2000 errorResponse->GetXaxis()->SetRangeUser(0, longDisplayRange);
2001 errorResponse->GetYaxis()->SetRangeUser(0, 0.3);
2002 errorResponse->SetStats(kFALSE);
2003 errorResponse->SetTitle(";true multiplicity;Uncertainty");
2005 errorResponse->Draw();
2007 errorMeasured->SetLineColor(2);
2008 errorMeasured->Draw("SAME");
2010 errorBoth->SetLineColor(4);
2011 errorBoth->Draw("SAME");
2013 Printf("Average errorResponse: %f", errorResponse->Integral(2, displayRange) / (displayRange - 1));
2014 Printf("Average errorMeasured: %f", errorMeasured->Integral(2, displayRange) / (displayRange - 1));
2015 Printf("Average errorBoth: %f", errorBoth->Integral(2, displayRange) / (displayRange - 1));
2017 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
2020 void StatisticalUncertaintyCompare(const char* det = "SPD")
2022 TFile* file1 = TFile::Open(Form("StatisticalUncertainty%sBayesian.root", det));
2023 TH1* errorResponse = (TH1*) file1->Get("errorResponse");
2024 TH1* errorMeasured = (TH1*) file1->Get("errorMeasured");
2025 TH1* errorBoth = (TH1*) file1->Get("errorBoth");
2028 str.Form("StatisticalUncertaintyCompare%s", det);
2030 TCanvas* canvas = new TCanvas(str, str, 800, 500);
2033 canvas->SetRightMargin(0.05);
2034 canvas->SetTopMargin(0.05);
2036 errorResponse->Scale(1.0 / sqrt(2));
2037 errorMeasured->Scale(1.0 / sqrt(2));
2038 errorBoth->Scale(1.0 / sqrt(2));
2040 errorResponse->SetLineColor(1);
2041 errorResponse->GetXaxis()->SetRangeUser(0, displayRange);
2042 errorResponse->GetYaxis()->SetRangeUser(0, 0.18);
2043 errorResponse->SetStats(kFALSE);
2044 errorResponse->GetYaxis()->SetTitleOffset(1.2);
2045 errorResponse->SetTitle(Form(";%s;#sqrt{2}^{-1} #sigma(unfolded - unfolded_{0}) / unfolded_{0}", GetMultLabel()));
2047 errorResponse->Draw();
2049 errorMeasured->SetLineColor(2);
2050 errorMeasured->Draw("SAME");
2052 errorBoth->SetLineColor(4);
2053 errorBoth->Draw("SAME");
2055 TFile* file2 = TFile::Open(Form("StatisticalUncertainty%sChi2.root", det));
2056 TH1* errorResponse2 = (TH1*) file2->Get("errorResponse");
2057 TH1* errorMeasured2 = (TH1*) file2->Get("errorMeasured");
2058 TH1* errorBoth2 = (TH1*) file2->Get("errorBoth");
2060 errorResponse2->Scale(1.0 / sqrt(2));
2061 errorMeasured2->Scale(1.0 / sqrt(2));
2062 errorBoth2->Scale(1.0 / sqrt(2));
2064 errorResponse2->SetLineStyle(2);
2065 errorResponse2->Draw("SAME");
2067 errorMeasured2->SetLineColor(2);
2068 errorMeasured2->SetLineStyle(2);
2069 errorMeasured2->Draw("SAME");
2071 errorBoth2->SetLineColor(4);
2072 errorBoth2->SetLineStyle(2);
2073 errorBoth2->Draw("SAME");
2075 TLegend* legend = new TLegend(0.2, 0.5, 0.8, 0.9);
2076 legend->SetFillColor(0);
2077 legend->SetTextSize(0.04);
2078 legend->AddEntry(errorBoth, "Both (Bayesian unfolding)");
2079 legend->AddEntry(errorMeasured, "Measured (Bayesian unfolding)");
2080 legend->AddEntry(errorResponse, "Response matrix (Bayesian unfolding)");
2081 legend->AddEntry(errorBoth2, "Both (#chi^{2}-minimization)");
2082 legend->AddEntry(errorMeasured2, "Measured (#chi^{2}-minimization)");
2083 legend->AddEntry(errorResponse2, "Response matrix (#chi^{2}-minimization)");
2086 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
2089 void EfficiencyComparison(Int_t eventType = 2, Bool_t uncertainty = kTRUE)
2091 const char* files[] = { "multiplicityMC_nd.root", "multiplicityMC_sd.root", "multiplicityMC_dd.root", "multiplicityMC_xsection.root" };
2095 TCanvas* canvas = new TCanvas("EfficiencyComparison", "EfficiencyComparison", 800, 600);
2098 canvas->SetRightMargin(0.05);
2099 canvas->SetTopMargin(0.05);
2101 AliMultiplicityCorrection* data[4];
2103 TH1* effErrorArray[2];
2105 Int_t markers[] = { 24, 25, 26, 5 };
2106 //Int_t markers[] = { 2, 25, 24, 5 };
2107 Int_t colors[] = { 1, 2, 4, 6 };
2108 //Int_t colors[] = { 1, 1, 1, 1 };
2110 //TLegend* legend = new TLegend(0.45, 0.45, 0.9, 0.7);
2111 TLegend* legend = new TLegend(0.3, 0.3, 0.9, 0.6);
2112 legend->SetTextSize(0.04);
2113 legend->SetFillColor(0);
2115 for (Int_t i=0; i<4; ++i)
2118 name.Form("Multiplicity_%d", i);
2120 TFile::Open(files[i]);
2121 data[i] = new AliMultiplicityCorrection(name, name);
2125 data[i]->LoadHistograms("Multiplicity");
2128 data[i]->LoadHistograms("Multiplicity_0");
2131 if (eventType == -1)
2133 eff = (TH1*) data[i]->GetTriggerEfficiency(etaRange)->Clone(Form("eff_%d", i));
2136 eff = (TH1*) data[i]->GetEfficiency(etaRange, (AliMultiplicityCorrection::EventType) eventType)->Clone(Form("eff_%d", i));
2139 eff->GetXaxis()->SetRangeUser(0, 15);
2140 eff->GetYaxis()->SetRangeUser(0, 1.19);
2141 eff->SetStats(kFALSE);
2142 eff->GetXaxis()->SetTitle(GetMultLabel());
2143 eff->GetYaxis()->SetTitle("Efficiency");
2145 eff->SetLineColor(colors[i]);
2146 eff->SetMarkerColor(colors[i]);
2147 eff->SetMarkerStyle(markers[i]);
2151 // once for INEL, once for NSD
2152 for (AliMultiplicityCorrection::EventType eventType2 = AliMultiplicityCorrection::kINEL; eventType2 <= AliMultiplicityCorrection::kNSD; eventType2++)
2154 effDiff = (TH1*) data[i]->GetEfficiency(etaRange, eventType2)->Clone(Form("effDiff_%d", i));
2156 for (Int_t bin=1; bin<=effDiff->GetNbinsX(); bin++)
2157 effDiff->SetBinError(bin, 0);
2159 // loop over cross section combinations
2160 for (Int_t j=1; j<7; ++j)
2162 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multtmp", "Multtmp");
2163 mult->LoadHistograms(Form("Multiplicity_%d", j));
2165 TH1* eff2 = mult->GetEfficiency(etaRange, eventType2);
2167 for (Int_t bin=1; bin<=effDiff->GetNbinsX(); bin++)
2169 // TODO we could also do asymmetric errors here
2170 Float_t deviation = TMath::Abs(effDiff->GetBinContent(bin) - eff2->GetBinContent(bin));
2172 effDiff->SetBinError(bin, TMath::Max(effDiff->GetBinError(bin), (Double_t) deviation));
2176 for (Int_t bin=1; bin<=effDiff->GetNbinsX(); bin++)
2178 //if (eventType2 == AliMultiplicityCorrection::kINEL)
2179 //eff->SetBinError(bin, 0);
2180 //eff->SetBinError(bin, effDiff->GetBinError(bin));
2181 if (bin < 20 && effDiff->GetBinContent(bin) > 0)
2182 Printf("Bin %d: Error: %.2f", bin, 100.0 * effDiff->GetBinError(bin) / effDiff->GetBinContent(bin));
2186 TH1* effError = (TH1*) effDiff->Clone(Form("effError_%s", (eventType2 == AliMultiplicityCorrection::kINEL) ? "INEL" : "NSD"));
2187 effErrorArray[eventType2 - AliMultiplicityCorrection::kINEL] = effError;
2190 for (Int_t bin=1; bin<=effDiff->GetNbinsX(); bin++)
2191 if (effDiff->GetBinContent(bin) > 0)
2192 effError->SetBinContent(bin, 1.0 * effDiff->GetBinError(bin) / effDiff->GetBinContent(bin));
2194 effError->SetLineColor(1);
2195 effError->SetMarkerStyle(1);
2197 if (eventType2 == AliMultiplicityCorrection::kNSD)
2198 effError->SetLineStyle(2);
2200 effError->DrawCopy("SAME HIST");
2211 eff->DrawCopy("SAME P");
2213 legend->AddEntry(eff, (((i == 0) ? "Non-diffractive" : ((i == 1) ? "Single-diffractive" : ((i == 2) ? "Double-diffractive" : "Pythia combined")))));
2218 legend->AddEntry(effErrorArray[0], "Relative syst. uncertainty: inelastic");
2219 legend->AddEntry(effErrorArray[1], "Relative syst. uncertainty: NSD");
2221 file = TFile::Open("uncertainty_xsection.root", "RECREATE");
2222 effErrorArray[0]->Write();
2223 effErrorArray[1]->Write();
2229 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
2232 void ModelDependencyPlot()
2236 TFile::Open("multiplicityMC.root");
2237 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
2238 mult->LoadHistograms("Multiplicity");
2240 hist = mult->GetCorrelation(etaRange);
2242 for (Int_t y=0; y<=hist->GetYaxis()->GetNbins()+1; ++y)
2244 for (Int_t z=0; z<=hist->GetZaxis()->GetNbins()+1; ++z)
2246 hist->SetBinContent(0, y, z, 0);
2247 hist->SetBinContent(hist->GetXaxis()->GetNbins()+1, y, z, 0);
2251 TH2* proj = (TH2*) hist->Project3D("zy");
2253 TCanvas* canvas = new TCanvas("ModelDependencyPlot", "ModelDependencyPlot", 1200, 600);
2255 canvas->Divide(2, 1);
2261 gPad->SetTopMargin(0.05);
2262 gPad->SetRightMargin(0.05);
2264 Int_t selectedMult = 30;
2267 TH1* full = proj->ProjectionX("full");
2268 TH1* selected = proj->ProjectionY("selected", proj->GetXaxis()->FindBin(selectedMult), proj->GetXaxis()->FindBin(selectedMult));
2270 full->SetStats(kFALSE);
2271 full->GetXaxis()->SetRangeUser(0, displayRange);
2272 full->GetYaxis()->SetRangeUser(5, yMax);
2273 full->SetTitle(";Multiplicity;Entries");
2275 selected->SetLineColor(0);
2276 selected->SetMarkerColor(2);
2277 selected->SetMarkerStyle(5);
2280 selected->Draw("SAME P");
2282 TLegend* legend = new TLegend(0.5, 0.65, 0.85, 0.85);
2283 legend->SetFillColor(0);
2284 legend->AddEntry(full, "True");
2285 legend->AddEntry(selected, "Measured");
2288 TLine* line = new TLine(selectedMult, 5, selectedMult, yMax);
2289 line->SetLineWidth(2);
2296 gPad->SetTopMargin(0.05);
2297 gPad->SetRightMargin(0.05);
2299 full = proj->ProjectionY("full2");
2300 selected = proj->ProjectionX("selected2", proj->GetYaxis()->FindBin(selectedMult), proj->GetYaxis()->FindBin(selectedMult));
2302 full->SetStats(kFALSE);
2303 full->GetXaxis()->SetRangeUser(0, displayRange);
2304 full->GetYaxis()->SetRangeUser(5, yMax);
2305 full->SetTitle(";Multiplicity;Entries");
2307 full->SetLineColor(0);
2308 full->SetMarkerColor(2);
2309 full->SetMarkerStyle(5);
2312 selected->Draw("SAME");
2316 line = new TLine(selectedMult, 5, selectedMult, yMax);
2317 line->SetLineWidth(2);
2320 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
2323 void SystematicpTSpectrum()
2325 gSystem->Load("libPWG0base");
2327 TFile::Open("multiplicityMC_400k_syst_ptspectrum.root");
2328 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
2329 mult->LoadHistograms("Multiplicity");
2331 TFile::Open("multiplicityMC_100k_syst.root");
2332 AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
2333 mult2->LoadHistograms("Multiplicity");
2335 mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
2336 mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
2337 mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
2339 TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
2340 TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
2342 DrawResultRatio(mcHist, result, "SystematicpTSpectrum.eps");
2345 void FitPt(const char* fileName)
2347 // needs a MC file from the dNdEta analysis
2349 TFile::Open(fileName);
2351 TH1* genePt = (TH1*) gFile->Get("fdNdpT");
2353 genePt->SetTitle(";p_{T} (GeV/c);1/p_{T} dN_{ch}/dp_{T} (GeV/c)^{-2}");
2355 genePt->Scale(1.0 / 287800);
2357 genePt->Scale(1.0 / genePt->GetXaxis()->GetBinWidth(1));
2359 genePt->GetXaxis()->SetRangeUser(0, 0.4);
2361 TF1* func = new TF1("func", "[1]*x*exp(x*[0])");
2362 func->SetParameters(-1, 1);
2364 genePt->SetMarkerStyle(25);
2365 genePt->SetTitle("");
2366 genePt->SetStats(kFALSE);
2369 genePt->DrawCopy("P");
2370 func->DrawCopy("SAME");
2373 genePt->Fit(func, "0", "", 0, 0.25);
2374 genePt->Fit(func, "0", "", 0, 0.25);
2376 TCanvas* canvas = new TCanvas("FitPt", "FitPt", 600, 600);
2380 gPad->SetLeftMargin(0.13);
2381 gPad->SetRightMargin(0.05);
2382 gPad->SetTopMargin(0.05);
2384 //genePt->GetXaxis()->SetRangeUser(0, 1);
2385 genePt->GetYaxis()->SetRangeUser(2, 200);
2386 genePt->GetYaxis()->SetTitleOffset(1.4);
2387 genePt->GetXaxis()->SetTitleOffset(1.1);
2388 genePt->DrawCopy("P");
2389 //func->SetRange(0, 0.3);
2390 func->DrawCopy("SAME");
2393 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
2395 TH1* first = (TH1*) func->GetHistogram()->Clone("first");
2397 TCanvas* canvas2 = new TCanvas("FitPt2", "FitPt2", 600, 400);
2399 TFile* file = TFile::Open("ptspectrum_fit.root", "RECREATE");
2401 for (Int_t param=0; param<2; param++)
2403 for (Int_t sign=0; sign<2; sign++)
2405 TF1* func2 = (TF1*) func->Clone(Form("func_%d_%d", param, sign)); // new TF1(Form("func_%d_%d", param, sign), &FitPtFunc, 0, 2, 6);
2406 func2->SetParameters(func->GetParameters());
2407 //TF1* func2 = (TF1*) func->Clone(); // SetParameter after this does not work
2409 Float_t factor = ((sign == 0) ? 0.75 : 1.25);
2410 func2->SetParameter(param, func2->GetParameter(param) * factor);
2414 func2->SetLineWidth(2);
2415 func2->SetLineColor(2);
2416 func2->SetLineStyle(2);
2417 func2->DrawCopy("SAME");
2420 TH1* second = func2->GetHistogram();
2421 second->Divide(first);
2422 second->SetLineColor(param + 1);
2423 // set to 1 above 0.2 GeV
2424 for (Int_t bin=second->GetXaxis()->FindBin(0.20001); bin<=second->GetNbinsX(); bin++)
2425 second->SetBinContent(bin, 1);
2426 second->GetYaxis()->SetRangeUser(0, 2);
2427 second->DrawCopy((param == 0 && sign == 0) ? "" : "SAME");
2428 second->Clone(Form("ptspectrum_%d_%d", param, sign))->Write();
2432 canvas->SaveAs(Form("%s.eps", canvas->GetName()));
2433 canvas2->SaveAs(Form("%s.eps", canvas2->GetName()));
2438 void DrawSystematicpT()
2440 TFile* file = TFile::Open("SystematicpT.root");
2442 TH1* mcHist2 = (TH1*) file->Get("mymc_unity");
2443 TH1* result2 = (TH1*) file->Get("result_unity");
2450 for (Int_t id=0; id<nParams*2; ++id)
2452 mcHist[id] = (TH1*) file->Get(Form("mymc_%d_%d.root", id / 2, id % 2));
2453 result[id] = (TH1*) file->Get(Form("result_%d_%d.root", id / 2, id % 2));
2456 DrawResultRatio(mcHist2, result2, "SystematicpT_OK.eps");
2458 //DrawRatioDeduct(mcHist2, result2, nParams*2, mcHist, result, "SystematicpT_Summary.eps");
2460 DrawRatio(nParams*2, mcHist, result, "SystematicpT_Ratios.eps", kTRUE, kTRUE);
2462 //DrawRatioDeductSmooth(mcHist2, result2, nParams*2, mcHist, result, "SystematicpT_Summary.eps");
2464 // does not make sense: mc is different
2465 //Draw2ResultRatio(mcHist, result1, result2, "SystematicpT.eps");
2468 void SystematicpT(Bool_t chi2 = 1)
2470 gSystem->Load("libPWG0base");
2472 TFile::Open("ptspectrum900.root");
2473 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
2474 mult->LoadHistograms("Multiplicity");
2476 AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
2483 for (Int_t param=0; param<nParams; param++)
2485 for (Int_t sign=0; sign<2; sign++)
2487 // calculate result with systematic effect
2488 TFile::Open(Form("ptspectrum100_%d_%d.root", param, sign));
2489 mult2->LoadHistograms("Multiplicity");
2491 mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
2495 mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
2496 mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
2499 mult->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100, 0);
2501 Int_t id = param * 2 + sign;
2503 mcHist[id] = mult2->GetMultiplicityVtx(etaRange)->ProjectionY(Form("mymc_%d_%d.root", param, sign));
2504 result[id] = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone(Form("result_%d_%d.root", param, sign));
2506 TString tmp; tmp.Form("SystematicpT_%d_%d.eps", param, sign);
2507 DrawResultRatio(mcHist[id], result[id], tmp);
2511 // calculate normal result
2512 TFile::Open("ptspectrum100_1.root");
2513 mult2->LoadHistograms("Multiplicity");
2514 TH1* mcHist2 = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc_unity");
2516 mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
2520 mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
2523 mult->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100);
2525 TH1* result2 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("result_unity");
2527 TFile* file = TFile::Open("SystematicpT.root", "RECREATE");
2530 for (Int_t id=0; id<nParams*2; ++id)
2532 mcHist[id]->Write();
2533 result[id]->Write();
2540 void DrawSystematicpT2()
2542 //displayRange = 200;
2545 TFile* file = TFile::Open("SystematicpT2.root");
2546 TH1* mcHist = (TH1*) file->Get("mymc");
2548 result[0] = (TH1*) file->Get("result_unity");
2550 for (Int_t id=0; id<nParams*2; ++id)
2551 result[id+1] = (TH1*) file->Get(Form("result_%d_%d", id / 2, id % 2));
2553 DrawResultRatio((TH1*) mcHist->Clone(), (TH1*) result[0]->Clone(), "SystematicpT_OK.eps");
2554 DrawRatio(mcHist, nParams*2+1, result, "SystematicpT_Ratios_MC.eps", kTRUE);
2555 DrawRatio(result[0], nParams*2, result+1, "SystematicpT_Ratios.eps");
2558 void SystematicpT2(Bool_t tpc = kTRUE, Bool_t chi2 = kTRUE)
2560 gSystem->Load("libPWG0base");
2565 TFile::Open("multiplicityMC_TPC_0.6M_syst_pt_unity.root");
2568 TFile::Open("ptspectrum100_1.root");
2570 AliMultiplicityCorrection* measured = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
2571 measured->LoadHistograms("Multiplicity");
2572 TH1* mcHist = measured->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
2578 // -1 = unity change, 0...4 parameters
2579 for (Int_t id=-1; id<nParams*2; id++)
2581 Int_t param = id / 2;
2582 Int_t sign = id % 2;
2590 idStr.Form("%d_%d", param, sign);
2592 // calculate result with systematic effect
2595 TFile::Open(Form("multiplicityMC_TPC_1.3M_syst_pt_%s.root", idStr.Data()));
2598 TFile::Open(Form("ptspectrum900_%s.root", idStr.Data()));
2600 AliMultiplicityCorrection* response = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
2601 response->LoadHistograms("Multiplicity");
2603 response->SetMultiplicityESD(etaRange, measured->GetMultiplicityESD(etaRange));
2607 response->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
2608 response->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
2611 response->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100, 0);
2613 result[id+1] = (TH1*) response->GetMultiplicityESDCorrected(etaRange)->Clone(Form("result_%s", idStr.Data()));
2615 TString tmp; tmp.Form("SystematicpT_%s.eps", idStr.Data());
2616 DrawResultRatio(mcHist, result[id+1], tmp);
2619 TFile* file = TFile::Open("SystematicpT2.root", "RECREATE");
2621 for (Int_t id=0; id<nParams*2+1; ++id)
2622 result[id]->Write();
2625 DrawSystematicpT2();
2628 void SystematicpTCutOff(Bool_t chi2 = kTRUE)
2630 // only needed for TPC
2633 gSystem->Load("libPWG0base");
2635 TFile::Open("multiplicityMC_TPC_1.3M_syst_pt_unity.root");
2636 AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
2637 mult->LoadHistograms("Multiplicity");
2639 TFile::Open("multiplicityMC_TPC_0.6M_syst_pt_unity.root");
2640 AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
2641 mult2->LoadHistograms("Multiplicity");
2644 mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
2648 mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
2649 mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
2652 mult->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100);
2654 TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
2655 TH1* result1 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("result1");
2659 // change of pt spectrum (down)
2660 TFile::Open("multiplicityMC_TPC_1.3M_syst_pt_red.root");
2661 AliMultiplicityCorrection* mult3 = new AliMultiplicityCorrection("Multiplicity3", "Multiplicity3");
2662 mult3->LoadHistograms("Multiplicity");
2663 mult3->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
2666 mult3->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
2667 mult3->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
2670 mult3->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100);
2671 syst[0] = (TH1*) mult3->GetMultiplicityESDCorrected(etaRange)->Clone("result2");
2673 // change of pt spectrum (up)
2674 TFile::Open("multiplicityMC_TPC_1.3M_syst_pt_inc.root");
2675 AliMultiplicityCorrection* mult4 = new AliMultiplicityCorrection("Multiplicity4", "Multiplicity4");
2676 mult4->LoadHistograms("Multiplicity");
2677 mult4->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
2680 mult4->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
2681 mult4->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
2684 mult4->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100);
2685 syst[1] = (TH1*) mult4->GetMultiplicityESDCorrected(etaRange)->Clone("result3");
2687 DrawRatio(result1, 2, syst, "SystematicpTCutOff.eps", kFALSE, 0, kTRUE);
2689 Draw2ResultRatio(mcHist, result1, syst[0], "SystematicpTCutOff1.eps");
2690 Draw2ResultRatio(mcHist, result1, syst[1], "SystematicpTCutOff2.eps");
2693 TH1* SystematicsSummary(Bool_t tpc = 0, Bool_t nsd = kTRUE)
2698 const char** names = 0;
2699 Int_t colors[] = { 1, 2, 4, 1, 2, 4 };
2700 Int_t styles[] = { 1, 2, 3, 1, 2, 3 };
2701 Int_t widths[] = { 1, 1, 1, 2, 2, 2 };
2702 Int_t markers[] = { 20, 21, 22, 23, 24, 25, 26 };
2704 TH1* dummy = new TH2F("dummy", Form(";%s;Uncertainty", GetMultLabel()), 202, -1.5, 200.5, 100, 0, 0.4);
2707 for (Int_t i=0; i<nEffects; ++i)
2708 effects[i] = new TH1F("SystematicsSummary", Form(";%s;Uncertainty", GetMultLabel()), 201, -0.5, 200.5);
2714 const char* namesTPC[] = { "Unfolding method (#chi^{2})", "Rel. cross-section", "Particle composition", "p_{t} cut off", "Track selection", "Secondaries", "p_{t} spectrum" };
2718 TFile* file = TFile::Open("StatisticalUncertaintyTPCChi2.root");
2719 TH1* hist = (TH1*) file->Get("errorBoth");
2721 // smooth a bit, but skip 0 bin
2722 effects[0]->SetBinContent(2, hist->GetBinContent(2));
2723 for (Int_t i=3; i<=200; ++i)
2724 effects[0]->SetBinContent(i, (hist->GetBinContent(i) + hist->GetBinContent(i+1)) / 2);
2726 // relative x-section
2727 effects[1]->SetBinContent(2, 0.005);
2728 effects[1]->SetBinContent(3, 0.0025);
2729 effects[1]->SetBinContent(4, 0.0025);
2731 // particle composition
2732 for (Int_t i=2; i<=101; ++i)
2736 effects[2]->SetBinContent(i, 0.01);
2740 effects[2]->SetBinContent(i, 0.02);
2743 effects[2]->SetBinContent(i, 0.02 + 0.08 / 25 * (i - 76));
2746 // pt cut off (only tpc)
2747 for (Int_t i=2; i<=101; ++i)
2751 effects[3]->SetBinContent(i, 0.05);
2755 effects[3]->SetBinContent(i, 0.01);
2758 effects[3]->SetBinContent(i, 0.01 + 0.1 / 30 * (i - 51));
2761 // track selection (only tpc)
2762 for (Int_t i=2; i<=101; ++i)
2763 effects[4]->SetBinContent(i, 0.03);
2766 for (Int_t i=2; i<=101; ++i)
2767 effects[5]->SetBinContent(i, 0.01);
2770 for (Int_t i=2; i<=101; ++i)
2774 effects[6]->SetBinContent(i, 0.05);
2778 effects[6]->SetBinContent(i, 0.02);
2781 effects[6]->SetBinContent(i, 0.02 + 0.13 / 25 * (i - 51));
2789 //const char* namesSPD[] = { "Particle composition", "p_{t} cut-off", "Unfolding Method (#chi^{2})", "Relative cross-sections (INEL)", "Relative cross-sections (NSD)"};
2790 const char* namesSPD[] = { "Unfolding Method (#chi^{2})", "Relative cross-sections (INEL)", "Relative cross-sections (NSD)", "Particle composition", "p_{t} cut-off"};
2796 TFile* file = TFile::Open("StatisticalUncertaintySPDChi2.root");
2797 TH1* hist = (TH1*) file->Get("errorBoth");
2798 hist->Scale(1.0 / sqrt(2));
2800 // smooth a bit, but skip 0 bin
2801 /*effects[currentEffect]->SetBinContent(1, hist->GetBinContent(1));
2802 for (Int_t i=2; i<=201; ++i)
2803 effects[currentEffect]->SetBinContent(i, (hist->GetBinContent(i) + hist->GetBinContent(i+1)) / 2);*/
2804 effects[currentEffect] = hist;
2808 // relative x-section
2809 file = TFile::Open("uncertainty_xsection.root");
2810 effects[currentEffect++] = (TH1*) file->Get("effError_INEL");
2811 effects[currentEffect] = (TH1*) file->Get("effError_NSD");
2812 effects[currentEffect]->SetLineStyle(1);
2813 //effects[2]->SetBinContent(1, 0.20);
2814 //effects[2]->SetBinContent(2, 0.01);
2815 //effects[2]->SetBinContent(3, 0.002);
2819 // particle composition
2820 effects[currentEffect]->SetBinContent(1, 0.16);
2821 for (Int_t i=2; i<=81; ++i)
2823 effects[currentEffect]->SetBinContent(i, 0.01 + 0.05 * i / 81);
2829 effects[currentEffect]->SetBinContent(1, 0.06);
2830 effects[currentEffect]->SetBinContent(2, 0.03);
2831 for (Int_t i=3; i<=81; ++i)
2835 effects[currentEffect]->SetBinContent(i, 0.01);
2839 effects[currentEffect]->SetBinContent(i, 0.01 + 0.05 * (i - 61) / 20);
2845 // // material budget
2846 // for (Int_t i=1; i<=81; ++i)
2849 // effects[currentEffect]->SetBinContent(i, 0.05 - 0.01 * i);
2851 // effects[currentEffect]->SetBinContent(i, 0.05 * (i - 50) / 30);
2858 TCanvas* canvas = new TCanvas("SystematicsSummary.eps", "SystematicsSummary.eps", 800, 500);
2859 canvas->SetRightMargin(0.05);
2860 canvas->SetTopMargin(0.05);
2861 //canvas->SetGridx();
2863 TLegend* legend = new TLegend(0.2, 0.4, 0.7, 0.4 + 0.5 * nEffects / 7);
2864 legend->SetFillColor(0);
2865 legend->SetTextSize(0.04);
2867 dummy->GetXaxis()->SetRangeUser(0, displayRange);
2869 for (Int_t i=0; i<nEffects; ++i)
2871 TH1* current = (TH1*) effects[i]->Clone(Form("current_%d", i));
2873 for (Int_t j=0; j<nEffects-i; ++j)
2874 current->Add(effects[j]);*/
2876 current->SetLineColor(colors[i]);
2877 current->SetLineStyle(styles[i]);
2878 current->SetLineWidth(widths[i]);
2879 //current->SetFillColor(colors[i]);
2880 current->SetMarkerColor(colors[i]);
2881 //current->SetMarkerStyle(markers[i]);
2883 current->SetStats(kFALSE);
2884 current->GetYaxis()->SetRangeUser(0, 0.4);
2885 current->DrawCopy("SAME");
2886 legend->AddEntry(current, names[i]);
2888 //TLatex* text = new TLatex(displayRange+2, current->GetBinContent(displayRange+1), names[i]);
2889 TLatex* text = new TLatex(displayRange+2, 0.1 - i * 0.02, names[i]);
2890 text->SetTextSize(0.04);
2891 text->SetTextColor(colors[i]);
2895 // add total in square
2896 TH1* totalINEL = (TH1*) effects[0]->Clone("totalINEL");
2898 TH1* totalNSD = (TH1*) totalINEL->Clone("totalNSD");
2900 for (Int_t i=0; i<nEffects; ++i)
2902 //Printf("%d %f", i, effects[i]->GetBinContent(20));
2903 effects[i]->Multiply(effects[i]);
2906 totalINEL->Add(effects[i]);
2908 totalNSD->Add(effects[i]);
2911 for (Int_t i=1; i<=totalINEL->GetNbinsX(); ++i)
2913 totalINEL->SetBinError(i, 0);
2914 if (totalINEL->GetBinContent(i) > 0)
2915 totalINEL->SetBinContent(i, TMath::Min(sqrt(totalINEL->GetBinContent(i)), 1.0));
2916 totalNSD->SetBinError(i, 0);
2917 if (totalNSD->GetBinContent(i) > 0)
2918 totalNSD->SetBinContent(i, TMath::Min(sqrt(totalNSD->GetBinContent(i)), 1.0));
2921 //Printf("%f", total->GetBinContent(20));
2923 totalINEL->SetMarkerStyle(5);
2924 totalINEL->SetMarkerColor(1);
2925 legend->AddEntry(totalINEL, "Total (INEL)", "P");
2927 totalNSD->SetMarkerStyle(24);
2928 totalNSD->SetMarkerColor(2);
2929 legend->AddEntry(totalNSD, "Total (NSD)", "P");
2931 Printf("total in bin 0 is INEL: %f NSD: %f", totalINEL->GetBinContent(1), totalNSD->GetBinContent(1));
2932 totalINEL->DrawCopy("SAME P"); //->SetBinContent(1, 0);
2933 totalNSD->DrawCopy("SAME P"); //->SetBinContent(1, 0);
2937 canvas->SaveAs(canvas->GetName());
2939 file = TFile::Open(Form("%s_syst_error.root", (tpc) ? "tpc" : "spd"), "RECREATE");
2940 totalINEL->Write("inel_1");
2941 totalNSD->Write("nsd_1");
2944 return (nsd) ? totalNSD : totalINEL;
2947 void finalPlot(Bool_t tpc = 0, Bool_t small = kFALSE)
2954 //TH1* errorNSD = SystematicsSummary(tpc, 1);
2956 TCanvas* canvas = new TCanvas("finalPlot.eps", "finalPlot.eps", 800, 500);
2957 canvas->SetRightMargin(0.05);
2958 canvas->SetTopMargin(0.05);
2962 legend = new TLegend(0.5, 0.6, 0.9, 0.8);
2963 legend->SetFillColor(0);
2964 legend->SetTextSize(0.04);
2966 for (AliMultiplicityCorrection::EventType eventType = AliMultiplicityCorrection::kINEL; eventType <= AliMultiplicityCorrection::kNSD; eventType++)
2968 AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open((eventType == AliMultiplicityCorrection::kINEL) ? "chi2_inel.root" : "chi2_nsd.root");
2969 TH1* mcHist = mult->GetMultiplicityMC(etaRange, eventType)->ProjectionY("mymc");
2970 TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
2972 DrawResultRatio(mcHist, result, Form("finalPlotCheck_%d.eps", (Int_t) eventType));
2975 //result->Scale(1.0 / result->Integral(2, displayRange));
2977 result->GetXaxis()->SetRangeUser(0, displayRange);
2978 //result->SetBinContent(1, 0); result->SetBinError(1, 0);
2979 result->SetTitle(Form(";True multiplicity in |#eta| < %.1f;Entries", (etaRange+1) * 0.5));
2980 result->SetMarkerStyle(0);
2981 result->SetLineColor(1);
2982 result->SetStats(kFALSE);
2985 TH1* error = SystematicsSummary(tpc, (eventType == AliMultiplicityCorrection::kNSD));
2987 TH1* systError = (TH1*) result->Clone("systError");
2988 for (Int_t i=1; i<=systError->GetNbinsX(); ++i)
2989 systError->SetBinError(i, systError->GetBinContent(i) * error->GetBinContent(i));
2991 // change error drawing style
2992 systError->SetFillColor(15);
2994 if (eventType == AliMultiplicityCorrection::kNSD)
2996 result->SetLineColor(2);
2997 result->SetMarkerColor(2);
2998 result->SetMarkerStyle(5);
3002 systError->DrawCopy(Form("E2 ][ %s", (eventType == AliMultiplicityCorrection::kINEL) ? "" : "SAME"));
3003 result->DrawCopy("SAME E ][");
3006 legend->AddEntry(result, (eventType == AliMultiplicityCorrection::kINEL) ? "Inelastic cross-section" : "NSD cross-section", (eventType == AliMultiplicityCorrection::kINEL) ? "L" : "P");
3011 //TPaveText* text = new TPaveText(10, 1e-3, 50, 1e-4, "B");
3012 TPaveText* text = new TPaveText(0.15, 0.2, 0.5, 0.4, "B NDC");
3013 text->SetFillColor(0);
3014 text->SetTextAlign(12);
3015 text->AddText("Systematic errors summed quadratically");
3016 text->AddText("0.6 million minimum bias events");
3017 text->AddText("corrected to inelastic events");
3020 TPaveText* text2 = new TPaveText(0.4, 0.7, 0.6, 0.85, "B NDC");
3021 text2->SetFillColor(0);
3022 text2->SetTextAlign(12);
3023 text2->AddText("#sqrt{s} = 14 TeV");
3026 text2->AddText("|#eta| < 0.9");
3029 text2->AddText("|#eta| < 2.0");
3030 text2->AddText("simulated data (PYTHIA)");
3035 TText* text3 = new TText(0.75, 0.6, "TPC - full tracking");
3041 TText* text3 = new TText(0.75, 0.6, "SPD - Tracklets");
3047 TPad* pad = new TPad("pad", "pad", 0.8, 0.7, 0.9, 0.9);
3050 TImage* img = TImage::Open("$HOME/alice.png");
3051 img->SetImageQuality(TAttImage::kImgBest);
3057 /* TText* text = new TText(10, 1e-4, "Systematic errors summed quadratically");
3058 text->SetTextSize(0.04);
3059 text->DrawText(10, 5e-5, "0.6 #cdot 10^{6} minimum bias events");
3060 text->DrawText(10, 3e-5, "TPC tracks in |#eta| < 0.9");
3061 text->DrawText(10, 1e-5, "corrected to ineleastic events in |#eta| < 0.9");
3065 canvas->SaveAs(canvas->GetName());
3068 void finalPlot2(Bool_t tpc = 0)
3075 //TH1* errorNSD = SystematicsSummary(tpc, 1);
3077 TCanvas* canvas = new TCanvas("finalPlot2.eps", "finalPlot2.eps", 800, 600);
3078 canvas->SetRightMargin(0.05);
3079 canvas->SetTopMargin(0.05);
3084 legend = new TLegend(0.5, 0.7, 0.9, 0.9);
3085 legend->SetFillColor(0);
3086 legend->SetTextSize(0.04);
3088 Int_t displayRanges[] = { 30, 45, 65 };
3090 TH2* dummy = new TH2F("dummy", ";True multiplicity N_{ch};P(N_{ch})", 100, -0.5, displayRanges[2]+10, 1000, 5e-6, 5);
3097 file = TFile::Open(Form("%s_syst_error.root", (tpc) ? "tpc" : "spd"));
3098 TH1* totalINEL = (TH1*) file->Get("inel_1");
3099 TH1* totalNSD = (TH1*) file->Get("nsd_1");
3102 for (AliMultiplicityCorrection::EventType eventType = AliMultiplicityCorrection::kINEL; eventType <= AliMultiplicityCorrection::kNSD; eventType++)
3104 AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open((eventType == AliMultiplicityCorrection::kINEL) ? "chi2_inel.root" : "chi2_nsd.root");
3105 //TH1* mcHist = mult->GetMultiplicityMC(etaRange, eventType)->ProjectionY("mymc");
3106 for (Int_t etaR = 0; etaR <= 2; etaR++)
3108 TH1* result = mult->GetMultiplicityESDCorrected(etaR);
3110 //DrawResultRatio(mcHist, result, Form("finalPlotCheck_%d.eps", (Int_t) eventType));
3113 result->Scale(TMath::Power(5, etaR) / result->Integral(1, displayRanges[etaR]));
3115 result->GetXaxis()->SetRangeUser(0, displayRanges[etaR]);
3116 //result->SetBinContent(1, 0); result->SetBinError(1, 0);
3117 //result->SetTitle(Form(""));
3118 result->SetMarkerStyle(0);
3119 result->SetLineColor(1);
3120 result->SetLineWidth(2);
3121 //result->SetMarkerStyle(4);
3122 //result->SetStats(kFALSE);
3125 //TH1* error = SystematicsSummary(tpc, (eventType == AliMultiplicityCorrection::kNSD));
3126 TH1* error = (eventType == AliMultiplicityCorrection::kNSD) ? totalNSD : totalINEL;
3128 TH1* systError = (TH1*) result->Clone("systError");
3129 // small hack until we have syst. errors for all eta ranges
3130 Float_t factor = 80.0 / displayRanges[etaR];
3131 for (Int_t i=1; i<=systError->GetNbinsX(); ++i)
3133 systError->SetBinError(i, systError->GetBinContent(i) * error->GetBinContent(factor * i));
3136 // change error drawing style
3137 systError->SetFillColor(15);
3139 if (eventType == AliMultiplicityCorrection::kNSD)
3141 result->SetLineColor(2);
3142 result->SetMarkerColor(2);
3143 result->SetMarkerStyle(5);
3147 systError->GetXaxis()->SetRangeUser(0, displayRanges[etaR]);
3148 systError->DrawCopy("E2 ][ SAME");
3151 if (eventType == AliMultiplicityCorrection::kINEL)
3153 TLatex* Tl = new TLatex;
3154 Tl->SetTextSize(0.04);
3155 //Tl->SetBit(TLatex::kTextNDC);
3156 Tl->SetTextAlign(32);
3158 Float_t etaRangeArr[] = { 0.5, 1.0, 1.4 };
3160 tmpStr.Form("|#eta| < %.1f (x %d)", etaRangeArr[etaR], (Int_t) TMath::Power(5, etaR));
3162 Tl->DrawLatex(15, result->GetBinContent(20), tmpStr);
3165 Tl->SetTextAlign(12);
3166 Tl->DrawLatex(40, result->GetBinContent(40), tmpStr);
3170 Tl->SetTextAlign(12);
3171 Tl->DrawLatex(60, result->GetBinContent(50), tmpStr);
3176 legend->AddEntry(result, (eventType == AliMultiplicityCorrection::kINEL) ? "Inelastic events" : "NSD events", (eventType == AliMultiplicityCorrection::kINEL) ? "L" : "P");
3182 for (Int_t i=0; i<list.GetEntries(); i++)
3183 ((TH1*) list.At(i))->DrawCopy("SAME E ][");
3187 canvas->SaveAs(canvas->GetName());
3190 TMatrixD* NonInvertable()
3192 const Int_t kSize = 5;
3194 TMatrixD matrix(kSize, kSize);
3195 for (Int_t x=0; x<kSize; x++)
3197 for (Int_t y=0; y<kSize; y++)
3201 if (x == 0 || x == kSize -1)
3203 matrix(x, y) = 0.75;
3208 else if (TMath::Abs(x - y) == 1)
3210 matrix(x, y) = 0.25;
3217 //TMatrixD inverted(matrix);
3218 //inverted.Invert();
3222 return new TMatrixD(matrix);
3225 void BlobelUnfoldingExample()
3227 const Int_t kSize = 20;
3229 TMatrixD matrix(kSize, kSize);
3230 for (Int_t x=0; x<kSize; x++)
3232 for (Int_t y=0; y<kSize; y++)
3236 if (x == 0 || x == kSize -1)
3238 matrix(x, y) = 0.75;
3243 else if (TMath::Abs(x - y) == 1)
3245 matrix(x, y) = 0.25;
3252 TMatrixD inverted(matrix);
3257 TH1F* inputDist = new TH1F("inputDist", ";t;Entries", kSize, -0.5, (Float_t) kSize - 0.5);
3258 TVectorD inputDistVector(kSize);
3259 TH1F* unfolded = inputDist->Clone("unfolded");
3260 TH1F* measuredIdealDist = inputDist->Clone("measuredIdealDist");
3261 measuredIdealDist->SetTitle(";m;Entries");
3262 TH1F* measuredDist = measuredIdealDist->Clone("measuredDist");
3264 TF1* gaus = new TF1("func", "gaus(0)", -0.5, kSize);
3265 // norm: 1/(sqrt(2pi)sigma)
3266 gaus->SetParameters(10000 / sqrt(2 * TMath::Pi()) / ((Float_t) kSize / 8), (Float_t) kSize / 2, (Float_t) kSize / 8);
3269 for (Int_t x=1; x<=inputDist->GetNbinsX(); x++)
3271 Float_t value = gaus->Eval(inputDist->GetBinCenter(x));
3272 inputDist->SetBinContent(x, value);
3273 inputDistVector(x-1) = value;
3276 TVectorD measuredDistIdealVector = matrix * inputDistVector;
3278 for (Int_t x=1; x<=measuredIdealDist->GetNbinsX(); x++)
3279 measuredIdealDist->SetBinContent(x, measuredDistIdealVector(x-1));
3281 measuredDist->FillRandom(measuredIdealDist, 10000);
3283 // fill error matrix before scaling
3284 TMatrixD covarianceMatrixMeasured(kSize, kSize);
3285 for (Int_t x=1; x<=unfolded->GetNbinsX(); x++)
3286 covarianceMatrixMeasured(x-1, x-1) = TMath::Sqrt(measuredDist->GetBinContent(x));
3288 TMatrixD covarianceMatrix = inverted * covarianceMatrixMeasured * inverted;
3289 //covarianceMatrix.Print();
3291 TVectorD measuredDistVector(kSize);
3292 for (Int_t x=1; x<=measuredDist->GetNbinsX(); x++)
3293 measuredDistVector(x-1) = measuredDist->GetBinContent(x);
3295 TVectorD unfoldedVector = inverted * measuredDistVector;
3296 for (Int_t x=1; x<=unfolded->GetNbinsX(); x++)
3297 unfolded->SetBinContent(x, unfoldedVector(x-1));
3299 TCanvas* canvas = new TCanvas("BlobelUnfoldingExample", "BlobelUnfoldingExample", 1200, 600);
3300 canvas->SetTopMargin(0.05);
3301 canvas->Divide(2, 1);
3304 canvas->cd(1)->SetLeftMargin(0.15);
3305 canvas->cd(1)->SetRightMargin(0.05);
3306 canvas->cd(1)->SetTopMargin(0.05);
3309 measuredDist->GetYaxis()->SetRangeUser(-600, 2799);
3310 measuredDist->GetYaxis()->SetTitleOffset(1.9);
3311 measuredDist->SetStats(0);
3312 measuredDist->DrawCopy();
3316 canvas->cd(2)->SetLeftMargin(0.15);
3317 canvas->cd(2)->SetRightMargin(0.05);
3318 canvas->cd(2)->SetTopMargin(0.05);
3321 unfolded->GetYaxis()->SetRangeUser(-600, 2799);
3322 unfolded->GetYaxis()->SetTitleOffset(1.9);
3323 unfolded->SetStats(0);
3324 unfolded->DrawCopy();
3327 canvas->SaveAs("BlobelUnfoldingExample.eps");
3331 // now unfold this with Bayesian
3334 // fill a multiplicity object
3335 mult = new AliMultiplicityCorrection("mult", "mult");
3336 for (Int_t x=0; x<kSize; x++)
3338 mult->GetMultiplicityVtx(0)->SetBinContent(1, x+1, inputDistVector(x));
3339 mult->GetMultiplicityESD(0)->SetBinContent(1, x+1, measuredDistVector(x)*10000);
3340 for (Int_t y=0; y<kSize; y++)
3341 mult->GetCorrelation(0)->SetBinContent(1, x+1, y+1, matrix(x, y));
3344 //mult->DrawHistograms();
3346 mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol0, 0);
3347 //mult->SetCreateBigBin(kFALSE);
3348 mult->ApplyMinuitFit(0, kFALSE, AliMultiplicityCorrection::kTrVtx, kFALSE); //hist2->ProjectionY("mymchist"));
3350 //mult->ApplyBayesianMethod(0, kFALSE, AliMultiplicityCorrection::kTrVtx, 0, -1, 0, kFALSE);
3352 mult->DrawComparison("BlobelExample", 0, kFALSE, kTRUE, mult->GetMultiplicityVtx(0)->ProjectionY("mcmchist", 1, mult->GetMultiplicityVtx(0)->GetNbinsX()));
3355 void TestWithDiagonalMatrix()
3357 const Int_t kSize = 20;
3359 TMatrixD matrix(kSize, kSize);
3360 for (Int_t x=0; x<kSize; x++)
3365 for (Int_t x=0; x<kSize; x++)
3367 for (Int_t y=0; y<kSize; y++)
3371 if (x == 0 || x == kSize -1)
3373 matrix(x, y) = 0.75;
3378 else if (TMath::Abs(x - y) == 1)
3380 matrix(x, y) = 0.25;
3388 TH1F* inputDist = new TH1F("inputDist", ";t;Entries", kSize, -0.5, (Float_t) kSize - 0.5);
3389 TVectorD inputDistVector(kSize);
3391 TH1F* measuredIdealDist = inputDist->Clone("measuredIdealDist");
3392 measuredIdealDist->SetTitle(";m;Entries");
3393 TH1F* measuredDist = measuredIdealDist->Clone("measuredDist");
3395 TF1* gaus = new TF1("func", "gaus(0)", -0.5, kSize);
3396 // norm: 1/(sqrt(2pi)sigma)
3397 gaus->SetParameters(10000 / sqrt(2 * TMath::Pi()) / ((Float_t) kSize / 8), (Float_t) kSize / 2, (Float_t) kSize / 8);
3400 for (Int_t x=1; x<=inputDist->GetNbinsX(); x++)
3402 Float_t value = gaus->Eval(inputDist->GetBinCenter(x));
3403 inputDist->SetBinContent(x, value);
3404 inputDistVector(x-1) = value;
3407 TVectorD measuredDistIdealVector = matrix * inputDistVector;
3409 for (Int_t x=1; x<=measuredIdealDist->GetNbinsX(); x++)
3410 measuredIdealDist->SetBinContent(x, measuredDistIdealVector(x-1));
3413 //measuredDist->FillRandom(measuredIdealDist, 10000);
3414 measuredDist = measuredIdealDist;
3415 measuredDist->Sumw2();
3417 for (Int_t x=0; x<kSize; x++)
3418 Printf("bin %d %.2f +- %.2f", x+1, measuredDist->GetBinContent(x+1), measuredDist->GetBinError(x+1));
3423 // fill a multiplicity object
3424 mult = new AliMultiplicityCorrection("mult", "mult");
3425 for (Int_t x=0; x<kSize; x++)
3427 mult->GetMultiplicityVtx(0)->SetBinContent(1, x+1, inputDistVector(x));
3428 mult->GetMultiplicityESD(0)->SetBinContent(1, x+1, measuredDist->GetBinContent(x+1));
3429 for (Int_t y=0; y<kSize; y++)
3430 mult->GetCorrelation(0)->SetBinContent(1, x+1, y+1, matrix(x, y));
3433 //mult->DrawHistograms();
3435 AliUnfolding::SetNbins(20, 20);
3436 AliUnfolding::SetChi2Regularization(AliUnfolding::kNone, 0);
3437 AliUnfolding::SetChi2Regularization(AliUnfolding::kPol1, 1e-14);
3438 //mult->SetCreateBigBin(kFALSE);
3439 mult->ApplyMinuitFit(0, kFALSE, AliMultiplicityCorrection::kTrVtx, kFALSE); //hist2->ProjectionY("mymchist"));
3441 //mult->ApplyBayesianMethod(0, kFALSE, AliMultiplicityCorrection::kTrVtx, 0, -1, 0, kFALSE);
3443 mult->DrawComparison("TestWithDiagonalMatrix", 0, kFALSE, kTRUE, mult->GetMultiplicityVtx(0)->ProjectionY("mcmchist", 1, mult->GetMultiplicityVtx(0)->GetNbinsX()));
3449 TH1* fCurrentESD = new TH1F("mult", "mult", 501, -0.5, 500.5);
3450 fCurrentESD->Sumw2();
3452 // Open the input stream
3454 in.open("e735data.txt");
3461 //Printf("%f %f %f", x, y, ye);
3462 fCurrentESD->SetBinContent(fCurrentESD->FindBin(x), y);
3463 fCurrentESD->SetBinError(fCurrentESD->FindBin(x), ye);
3468 //new TCanvas; fCurrentESD->DrawCopy(); gPad->SetLogy();
3470 fCurrentESD->Scale(1.0 / fCurrentESD->Integral());
3472 TF1* func = new TF1("nbd", "[0] * TMath::Binomial([2]+TMath::Nint(x)-1, [2]-1) * pow([1] / ([1]+[2]), TMath::Nint(x)) * pow(1 + [1]/[2], -[2])");
3473 func->SetParNames("scaling", "averagen", "k");
3474 func->SetParLimits(0, 0.001, fCurrentESD->GetMaximum() * 1000);
3475 func->SetParLimits(1, 0.001, 1000);
3476 func->SetParLimits(2, 0.001, 1000);
3477 func->SetParameters(fCurrentESD->GetMaximum() * 100, 10, 2);
3479 TF1* lognormal = new TF1("lognormal", "[0]*exp(-(log(x)-[1])^2/(2*[2]^2))/(x*[2]*TMath::Sqrt(2*TMath::Pi()))", 0.01, 500);
3480 lognormal->SetParNames("scaling", "mean", "sigma");
3481 lognormal->SetParameters(1, 1, 1);
3482 lognormal->SetParLimits(0, 0, 10);
3483 lognormal->SetParLimits(1, 0, 100);
3484 lognormal->SetParLimits(2, 1e-3, 10);
3486 TCanvas* canvas = new TCanvas("c1", "c1", 700, 400);
3487 fCurrentESD->SetStats(kFALSE);
3488 fCurrentESD->SetMarkerStyle(0);
3489 fCurrentESD->SetLineColor(1);
3490 fCurrentESD->GetYaxis()->SetTitleOffset(1.3);
3491 fCurrentESD->SetTitle(";true multiplicity (N);P_{N}");
3492 fCurrentESD->Draw("");
3493 fCurrentESD->GetXaxis()->SetRangeUser(0, 250);
3494 fCurrentESD->Fit(func, "0", "", 0, 150);
3495 func->SetRange(0, 250);
3497 printf("chi2 = %f\n", func->GetChisquare());
3499 fCurrentESD->Fit(lognormal, "0", "", 0.01, 150);
3500 lognormal->SetLineColor(2);
3501 lognormal->SetLineStyle(2);
3502 lognormal->SetRange(0, 250);
3503 lognormal->Draw("SAME");
3507 canvas->SaveAs("E735Fit.eps");
3510 void DifferentSamples()
3515 const char* filesChi2[] = { "chi2_100k_1.root", "chi2_100k_2.root" };
3516 const char* filesBayesian[] = { "bayesian_100k_1.root", "bayesian_100k_2.root" };
3518 TCanvas* canvas = new TCanvas("DifferentSamples", "DifferentSamples", 1200, 600);
3519 canvas->Divide(2, 1);
3521 legend = new TLegend(0.15, 0.7, 0.65, 0.9);
3522 legend->SetFillColor(0);
3523 legend->SetTextSize(0.04);
3525 for (Int_t i=0; i<n; i++)
3527 AliMultiplicityCorrection* chi2 = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
3528 TFile::Open(filesChi2[i]);
3529 chi2->LoadHistograms("Multiplicity");
3531 AliMultiplicityCorrection* bayesian = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
3532 TFile::Open(filesBayesian[i]);
3533 bayesian->LoadHistograms("Multiplicity");
3535 chi2Hist = chi2->GetMultiplicityESDCorrected(etaRange);
3536 bayesianHist = bayesian->GetMultiplicityESDCorrected(etaRange);
3538 mc = chi2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, 1);
3540 // normalize and divide
3541 chi2Hist->Scale(1.0 / chi2Hist->Integral(2, displayRange+1) * mc->Integral(2, displayRange));
3542 bayesianHist->Scale(1.0 / bayesianHist->Integral(2, displayRange+1) * mc->Integral(2, displayRange));
3544 chi2Hist->Divide(mc, chi2Hist);
3545 bayesianHist->Divide(mc, bayesianHist);
3548 gPad->SetTopMargin(0.05);
3549 gPad->SetRightMargin(0.05);
3550 //gPad->SetLeftMargin(0.12);
3554 chi2Hist->GetXaxis()->SetRangeUser(0, displayRange);
3555 chi2Hist->GetYaxis()->SetTitleOffset(1.3);
3556 chi2Hist->SetStats(0);
3557 chi2Hist->SetTitle(Form(";%s;MC / unfolded", GetMultLabel()));
3558 chi2Hist->GetYaxis()->SetRangeUser(0.2, 1.8);
3559 chi2Hist->Draw("HIST");
3561 for (Int_t x=1; x<=bayesianHist->GetNbinsX(); x++)
3562 bayesianHist->SetBinError(x, 1e-6);
3564 bayesianHist->SetLineColor(2);
3565 bayesianHist->SetMarkerColor(2);
3566 bayesianHist->SetMarkerStyle(5);
3567 bayesianHist->Draw("HIST E SAME");
3571 legend->AddEntry(chi2Hist, "#chi^{2}-minimization", "L");
3572 legend->AddEntry(bayesianHist, "Bayesian unfolding", "LP");
3577 canvas->SaveAs("DifferentSamples.eps");
3584 AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open("multiplicityMC.root");
3585 hist2d = mult->GetMultiplicityMC(etaRange, AliMultiplicityCorrection::kINEL);
3586 mult1 = hist2d->ProjectionY("mult1", 1, hist2d->GetNbinsX());
3588 conv = (TH1*) mult1->Clone("conv");
3591 mult1->Scale(1.0 / mult1->Integral());
3593 for (Int_t i=1; i<=mult1->GetNbinsX(); i++)
3594 for (Int_t j=1; j<=mult1->GetNbinsX(); j++)
3595 conv->Fill(mult1->GetBinCenter(i)+mult1->GetBinCenter(j), mult1->GetBinContent(i) * mult1->GetBinContent(j));
3597 conv->Scale(1.0 / conv->Integral());
3599 c = new TCanvas("c", "c", 800, 500);
3601 gPad->SetTopMargin(0.05);
3602 gPad->SetRightMargin(0.05);
3603 mult1->SetTitle(Form(";%s;Probability", GetMultLabel()));
3608 mult1->GetYaxis()->SetRangeUser(1e-7, 2 * mult1->GetMaximum());
3609 mult1->GetXaxis()->SetRangeUser(0, displayRange);
3610 mult1->GetXaxis()->SetTitleOffset(1.15);
3611 conv->SetLineColor(2);
3612 conv->SetMarkerColor(2);
3613 conv->SetMarkerStyle(5);
3614 conv->DrawCopy("SAME P");
3616 conv->Scale(0.00058);
3617 conv->DrawCopy("SAME P");
3619 legend = new TLegend(0.73, 0.73, 0.93, 0.93);
3620 legend->SetFillColor(0);
3621 legend->SetTextSize(0.04);
3622 legend->AddEntry(mult1, "1 collision");
3623 legend->AddEntry(conv, "2 collisions", "P");
3626 c->SaveAs("pileup.eps");
3629 conv->Divide(mult1);
3633 void TestErrorDetermination(Int_t nRandomizations)
3635 TF1* func = new TF1("nbd", "exp(log([0]) + TMath::LnGamma([2]+x) - TMath::LnGamma([2]) - TMath::LnGamma(x+1) + log([1] / ([1]+[2])) * x + log(1.0 + [1]/[2]) * -[2])", 0, 100);
3636 func->SetParNames("scaling", "averagen", "k");
3637 func->SetParameters(1, 15, 2);
3639 TF1* func2 = new TF1("nbd2", "exp(log([0]) + TMath::LnGamma([2]+x) - TMath::LnGamma([2]) - TMath::LnGamma(x+1) + log([1] / ([1]+[2])) * x + log(1.0 + [1]/[2]) * -[2])", 0, 100);
3640 func2->SetParNames("scaling", "averagen", "k");
3641 func2->SetParLimits(0, 0.5, 2);
3642 func2->SetParLimits(1, 1, 50);
3643 func2->SetParLimits(2, 1, 10);
3644 func2->SetParameters(1, 15, 2);
3645 //func2->FixParameter(0, 1);
3647 //new TCanvas; func->Draw("L");
3649 hist1 = new TH1F("hist1", "", 100, 0.5, 100.5);
3650 hist2 = new TH1F("hist2", "", 100, 0.5, 100.5);
3654 params[0] = new TH1F("param_0", Form("param_%d", 0), 100, 0.95, 1.05);
3655 params[1] = new TH1F("param_1", Form("param_%d", 1), 100, 14, 16);
3656 params[2] = new TH1F("param_2", Form("param_%d", 2), 100, 1.8, 2.2);
3658 const Int_t nTries = 1000;
3659 for (Int_t i=0; i<nTries; i++)
3663 if (nRandomizations == 1)
3665 hist1->FillRandom("nbd", 10000);
3667 else if (nRandomizations == 2)
3670 hist2->FillRandom("nbd", 10000);
3671 hist1->FillRandom(hist2, 10000);
3673 else if (nRandomizations == 3)
3676 hist1->FillRandom("nbd", 10000);
3677 hist2->FillRandom(hist1, 10000);
3679 hist1->FillRandom(hist2, 10000);
3684 //new TCanvas; hist1->Draw();
3686 hist1->Scale(1.0 / hist1->Integral());
3687 hist1->Fit(func2, "NQ");
3688 hist1->Fit(func2, "NQ");
3689 for (Int_t j=0; j<3; j++)
3690 params[j]->Fill(func2->GetParameter(j));
3693 for (Int_t j=0; j<3; j++)
3695 new TCanvas; params[j]->Draw();
3696 params[j]->Fit("gaus");
3697 Printf("sigma of param %d if %f", j, ((TF1*) params[j]->FindObject("gaus"))->GetParameter(2));
3701 void DrawRawDistributions(const char* fileName = "multiplicityESD.root")
3705 AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open(fileName);
3707 c = new TCanvas("c", "c", 600, 600);
3709 dummy = new TH2F("dummy", ";measured multiplicity", 100, -0.5, 149.5, 100, 0.5, 4e4);
3716 Int_t colors[] = { 1, 2, 4 };
3718 for (Int_t i=2; i>=0; i--)
3720 hist = mult->GetMultiplicityESD(i)->ProjectionY();
3722 hist->SetLineColor(colors[i]);
3723 hist->DrawCopy("SAME");
3729 void FindUnfoldedLimit()
3733 AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open("multiplicityMC.root");
3734 AliMultiplicityCorrection* esd = AliMultiplicityCorrection::Open("multiplicityESD.root");
3736 TH1* hist = mult->GetCorrelation(etaRange);
3737 for (Int_t y=0; y<=hist->GetYaxis()->GetNbins()+1; ++y)
3739 for (Int_t z=0; z<=hist->GetZaxis()->GetNbins()+1; ++z)
3741 hist->SetBinContent(0, y, z, 0);
3742 hist->SetBinContent(hist->GetXaxis()->GetNbins()+1, y, z, 0);
3745 TH2* corr = (TH2*) ((TH3*) mult->GetCorrelation(etaRange))->Project3D("zy");
3747 TH1* esd_proj = esd->GetMultiplicityESD(etaRange)->ProjectionY("esd_proj", 1, esd->GetMultiplicityESD(etaRange)->GetNbinsX());
3748 //esd_proj = corr->ProjectionY("esd_proj", 1, corr->GetNbinsX());
3750 new TCanvas; corr->Draw("COLZ");
3751 new TCanvas; esd_proj->DrawCopy();
3753 TH1* percentage = (TH1*) (esd_proj->Clone("percentage"));
3754 percentage->Reset();
3756 for (Int_t i=1; i<=esd_proj->GetNbinsX(); i++)
3757 if (esd_proj->GetBinContent(i) > 0)
3758 esd_proj->SetBinContent(i, 1);
3760 for (Int_t i=1; i<=percentage->GetNbinsX(); i++)
3762 TH1* binResponse = corr->ProjectionY("proj", i, i);
3763 if (binResponse->Integral() <= 0)
3765 binResponse->Scale(1.0 / binResponse->Integral());
3766 binResponse->Multiply(esd_proj);
3767 //new TCanvas; binResponse->Draw();
3768 percentage->SetBinContent(i, binResponse->Integral());
3772 new TCanvas; percentage->Draw();
3774 mc = esd->GetMultiplicityVtx(etaRange)->ProjectionY("mc", 1, esd->GetMultiplicityVtx(etaRange)->GetNbinsX());
3775 mc->SetLineColor(2);
3779 void CompareUnfoldedWithMC()
3783 AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open("unfolded.root");
3785 //mult->GetMultiplicityESDCorrected(etaRange)->Scale(1.0 / mult->GetMultiplicityESDCorrected(etaRange)->Integral());
3786 mult->GetMultiplicityESDCorrected(etaRange)->SetTitle(";multiplicity;events");
3787 mult->GetMultiplicityESDCorrected(etaRange)->SetStats(0);
3788 mult->GetMultiplicityESDCorrected(etaRange)->Draw();
3789 //mcHist->Scale(1.0 / mcHist->Integral());
3790 mcHist = mult->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, 1);
3791 mcHist->SetLineColor(2);
3792 mcHist->Draw("SAME");