1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /* $Id: AliUEHist.cxx 20164 2007-08-14 15:31:50Z morsch $ */
20 // encapsulate histogram and corrections for one underlying event histogram
23 // Author: Jan Fiete Grosse-Oetringhaus, Sara Vallero
25 #include "AliUEHist.h"
26 #include "AliCFContainer.h"
27 #include "THnSparse.h"
30 #include "TCollection.h"
40 const Int_t AliUEHist::fgkCFSteps = 10;
42 AliUEHist::AliUEHist(const char* reqHist) :
46 fTrackHistEfficiency(0),
51 fContaminationEnhancement(0),
57 for (Int_t i=0; i<fkRegions; i++)
60 if (strlen(reqHist) == 0)
63 AliLog::SetClassDebugLevel("AliCFContainer", -1);
64 AliLog::SetClassDebugLevel("AliCFGridSparse", -3);
66 const char* title = "";
69 Int_t nTrackVars = 4; // eta vs pT vs pT,lead (vs delta phi) vs multiplicity
71 Double_t* trackBins[5];
72 const char* trackAxisTitle[5];
76 Double_t etaBins[20+1];
77 for (Int_t i=0; i<=iTrackBin[0]; i++)
78 etaBins[i] = -1.0 + 0.1 * i;
79 trackBins[0] = etaBins;
80 trackAxisTitle[0] = "#eta";
84 Double_t pTBins[] = {0.0, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 100.0};
85 trackBins[1] = pTBins;
86 trackAxisTitle[1] = "p_{T} (GeV/c)";
89 const Int_t kNLeadingpTBins = 100;
90 Double_t leadingpTBins[kNLeadingpTBins+1];
91 for (Int_t i=0; i<=kNLeadingpTBins; i++)
92 leadingpTBins[i] = 0.5 * i;
95 const Int_t kNLeadingpTBins2 = 13;
96 Double_t leadingpTBins2[] = { 0.0, 0.5, 1.0, 2.0, 4.0, 6.0, 8.0, 10.0, 15.0, 20.0, 30.0, 40.0, 50.0, 100.0 };
99 const Int_t kNLeadingPhiBins = 40;
100 Double_t leadingPhiBins[kNLeadingPhiBins+1];
101 for (Int_t i=0; i<=kNLeadingPhiBins; i++)
102 leadingPhiBins[i] = -0.5 * TMath::Pi() + 1.0 / 40 * i * TMath::TwoPi();
105 const Int_t kNMultiplicityBins = 15;
106 Double_t multiplicityBins[kNMultiplicityBins+1];
107 for (Int_t i=0; i<=kNMultiplicityBins; i++)
108 multiplicityBins[i] = -0.5 + i;
109 multiplicityBins[kNMultiplicityBins] = 200;
112 const Int_t kNSpeciesBins = 4; // pi, K, p, rest
113 Double_t speciesBins[] = { -0.5, 0.5, 1.5, 2.5, 3.5 };
115 trackBins[3] = multiplicityBins;
116 iTrackBin[3] = kNMultiplicityBins;
117 trackAxisTitle[3] = "multiplicity";
119 // selection depending on requested histogram
120 Int_t axis = -1; // 0 = pT,lead, 1 = phi,lead
121 if (strcmp(reqHist, "NumberDensitypT") == 0)
124 title = "d^{2}N_{ch}/d#phid#eta";
126 else if (strcmp(reqHist, "NumberDensityPhi") == 0)
129 title = "d^{2}N_{ch}/d#phid#eta";
131 else if (strcmp(reqHist, "SumpT") == 0)
134 title = "d^{2}#Sigma p_{T}/d#phid#eta";
137 AliFatal(Form("Invalid histogram requested: %s", reqHist));
139 Int_t initRegions = fkRegions;
143 trackBins[2] = leadingpTBins;
144 iTrackBin[2] = kNLeadingpTBins;
145 trackAxisTitle[2] = "leading p_{T} (GeV/c)";
153 iTrackBin[2] = kNLeadingpTBins2;
154 trackBins[2] = leadingpTBins2;
155 trackAxisTitle[2] = "leading p_{T} (GeV/c)";
157 iTrackBin[4] = kNLeadingPhiBins;
158 trackBins[4] = leadingPhiBins;
159 trackAxisTitle[4] = "#phi w.r.t leading track";
162 for (Int_t i=0; i<initRegions; i++)
164 fTrackHist[i] = new AliCFContainer(Form("fTrackHist_%d", i), title, fgkCFSteps, nTrackVars, iTrackBin);
166 for (Int_t j=0; j<nTrackVars; j++)
168 fTrackHist[i]->SetBinLimits(j, trackBins[j]);
169 fTrackHist[i]->SetVarTitle(j, trackAxisTitle[j]);
172 SetStepNames(fTrackHist[i]);
175 // track 3rd and 4th axis --> event 1st and 2nd axis
176 fEventHist = new AliCFContainer("fEventHist", title, fgkCFSteps, 2, iTrackBin+2);
178 fEventHist->SetBinLimits(0, trackBins[2]);
179 fEventHist->SetVarTitle(0, trackAxisTitle[2]);
181 fEventHist->SetBinLimits(1, trackBins[3]);
182 fEventHist->SetVarTitle(1, trackAxisTitle[3]);
184 SetStepNames(fEventHist);
186 iTrackBin[2] = kNSpeciesBins;
188 fTrackHistEfficiency = new AliCFContainer("fTrackHistEfficiency", "Tracking efficiency", 3, 3, iTrackBin);
189 fTrackHistEfficiency->SetBinLimits(0, trackBins[0]);
190 fTrackHistEfficiency->SetVarTitle(0, trackAxisTitle[0]);
191 fTrackHistEfficiency->SetBinLimits(1, trackBins[1]);
192 fTrackHistEfficiency->SetVarTitle(1, trackAxisTitle[1]);
193 fTrackHistEfficiency->SetBinLimits(2, speciesBins);
194 fTrackHistEfficiency->SetVarTitle(2, "particle species");
197 //_____________________________________________________________________________
198 AliUEHist::AliUEHist(const AliUEHist &c) :
202 fTrackHistEfficiency(0),
207 fContaminationEnhancement(0),
212 // AliUEHist copy constructor
215 ((AliUEHist &) c).Copy(*this);
218 //____________________________________________________________________
219 void AliUEHist::SetStepNames(AliCFContainer* container)
221 // sets the names of the correction steps
223 for (Int_t i=0; i<fgkCFSteps; i++)
224 container->SetStepTitle(i, GetStepTitle((CFStep) i));
227 //____________________________________________________________________
228 AliUEHist::~AliUEHist()
232 for (Int_t i=0; i<fkRegions; i++)
236 delete fTrackHist[i];
247 if (fTrackHistEfficiency)
249 delete fTrackHistEfficiency;
250 fTrackHistEfficiency = 0;
260 //____________________________________________________________________
261 AliUEHist &AliUEHist::operator=(const AliUEHist &c)
263 // assigment operator
266 ((AliUEHist &) c).Copy(*this);
271 //____________________________________________________________________
272 void AliUEHist::Copy(TObject& c) const
276 AliUEHist& target = (AliUEHist &) c;
278 for (Int_t i=0; i<fkRegions; i++)
280 target.fTrackHist[i] = dynamic_cast<AliCFContainer*> (fTrackHist[i]->Clone());
283 target.fEventHist = dynamic_cast<AliCFContainer*> (fEventHist->Clone());
285 if (fTrackHistEfficiency)
286 target.fTrackHistEfficiency = dynamic_cast<AliCFContainer*> (fTrackHistEfficiency->Clone());
289 //____________________________________________________________________
290 Long64_t AliUEHist::Merge(TCollection* list)
292 // Merge a list of AliUEHist objects with this (needed for
294 // Returns the number of merged objects (including this).
302 TIterator* iter = list->MakeIterator();
305 // collections of objects
306 const Int_t kMaxLists = fkRegions+2;
307 TList** lists = new TList*[kMaxLists];
309 for (Int_t i=0; i<kMaxLists; i++)
310 lists[i] = new TList;
313 while ((obj = iter->Next())) {
315 AliUEHist* entry = dynamic_cast<AliUEHist*> (obj);
319 for (Int_t i=0; i<fkRegions; i++)
320 if (entry->fTrackHist[i])
321 lists[i]->Add(entry->fTrackHist[i]);
323 lists[fkRegions]->Add(entry->fEventHist);
324 lists[fkRegions+1]->Add(entry->fTrackHistEfficiency);
328 for (Int_t i=0; i<fkRegions; i++)
330 fTrackHist[i]->Merge(lists[i]);
332 fEventHist->Merge(lists[fkRegions]);
333 fTrackHistEfficiency->Merge(lists[fkRegions+1]);
335 for (Int_t i=0; i<kMaxLists; i++)
343 //____________________________________________________________________
344 void AliUEHist::SetBinLimits(AliCFGridSparse* grid)
346 // sets the bin limits in eta and pT defined by fEtaMin/Max, fPtMin/Max
348 if (fEtaMax > fEtaMin)
349 grid->SetRangeUser(0, fEtaMin, fEtaMax);
351 grid->SetRangeUser(1, fPtMin, fPtMax);
354 //____________________________________________________________________
355 void AliUEHist::ResetBinLimits(AliCFGridSparse* grid)
357 // resets all bin limits
359 for (Int_t i=0; i<grid->GetNVar(); i++)
360 if (grid->GetGrid()->GetAxis(i)->TestBit(TAxis::kAxisRange))
361 grid->SetRangeUser(i, 0, -1);
364 //____________________________________________________________________
365 void AliUEHist::CountEmptyBins(AliUEHist::CFStep step, Float_t ptLeadMin, Float_t ptLeadMax)
367 // prints the number of empty bins in the track end event histograms in the given step
372 for (Int_t i=0; i<4; i++)
375 binEnd[i] = fTrackHist[0]->GetNBins(i);
378 if (fEtaMax > fEtaMin)
380 binBegin[0] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(0)->FindBin(fEtaMin);
381 binEnd[0] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(0)->FindBin(fEtaMax);
386 binBegin[1] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(fPtMin);
387 binEnd[1] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(fPtMax);
390 if (ptLeadMax > ptLeadMin)
392 binBegin[2] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(2)->FindBin(ptLeadMin);
393 binEnd[2] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(2)->FindBin(ptLeadMax);
396 // start from multiplicity 1
397 binBegin[3] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(3)->FindBin(1);
399 for (Int_t region=0; region<fkRegions; region++)
405 for (Int_t i=0; i<4; i++)
406 vars[i] = binBegin[i];
408 AliCFGridSparse* grid = fTrackHist[region]->GetGrid(step);
411 if (grid->GetElement(vars) == 0)
413 Printf("Empty bin at eta=%.2f pt=%.2f pt_lead=%.2f mult=%.1f",
414 grid->GetBinCenter(0, vars[0]),
415 grid->GetBinCenter(1, vars[1]),
416 grid->GetBinCenter(2, vars[2]),
417 grid->GetBinCenter(3, vars[3])
423 for (Int_t i=3; i>0; i--)
425 if (vars[i] == binEnd[i]+1)
427 vars[i] = binBegin[i];
432 if (vars[0] == binEnd[0]+1)
437 Printf("Region %s has %d empty bins (out of %d bins)", GetRegionTitle((Region) region), count, total);
441 //____________________________________________________________________
442 TH1D* AliUEHist::GetUEHist(AliUEHist::CFStep step, AliUEHist::Region region, Float_t ptLeadMin, Float_t ptLeadMax)
444 // Extracts the UE histogram at the given step and in the given region by projection and dividing tracks by events
446 // ptLeadMin, ptLeadMax: Only meaningful for vs. delta phi plot (third axis is ptLead)
447 // Histogram has to be deleted by the caller of the function
450 ResetBinLimits(fTrackHist[region]->GetGrid(step));
451 ResetBinLimits(fEventHist->GetGrid(step));
453 SetBinLimits(fTrackHist[region]->GetGrid(step));
459 tracks = fTrackHist[region]->ShowProjection(2, step);
460 tracks->GetYaxis()->SetTitle(fTrackHist[region]->GetTitle());
461 if (fCombineMinMax && region == kMin)
463 ResetBinLimits(fTrackHist[kMax]->GetGrid(step));
464 SetBinLimits(fTrackHist[kMax]->GetGrid(step));
466 TH1D* tracks2 = fTrackHist[kMax]->ShowProjection(2, step);
467 tracks->Add(tracks2);
469 ResetBinLimits(fTrackHist[kMax]->GetGrid(step));
472 // normalize to get a density (deta dphi)
473 TAxis* axis = fTrackHist[region]->GetGrid(step)->GetAxis(0);
474 Float_t phiRegion = TMath::TwoPi() / 3;
475 if (!fCombineMinMax && region == kMin)
477 Float_t normalization = phiRegion * (axis->GetBinUpEdge(axis->GetLast()) - axis->GetBinLowEdge(axis->GetFirst()));
478 //Printf("Normalization: %f", normalization);
479 tracks->Scale(1.0 / normalization);
481 TH1D* events = fEventHist->ShowProjection(0, step);
482 tracks->Divide(events);
486 // the efficiency to have find an event depends on leading pT and this is not corrected for because anyway per bin we calculate tracks over events
487 // therefore the number density must be calculated here per leading pT bin and then summed
489 Int_t firstBin = fTrackHist[region]->GetAxis(2, step)->FindBin(ptLeadMin);
490 Int_t lastBin = fTrackHist[region]->GetAxis(2, step)->FindBin(ptLeadMax);
492 for (Int_t bin=firstBin; bin<=lastBin; bin++)
494 fTrackHist[region]->GetGrid(step)->GetGrid()->GetAxis(2)->SetRange(bin, bin);
495 TH1D* tracksTmp = (TH1D*) fTrackHist[region]->GetGrid(step)->Project(4);
496 Printf("Calculated histogram in bin %d --> %f tracks", bin, tracksTmp->Integral());
497 fTrackHist[region]->GetGrid(step)->SetRangeUser(2, 0, -1);
499 // normalize to get a density (deta dphi)
500 TAxis* axis = fTrackHist[region]->GetGrid(step)->GetAxis(0);
501 Float_t normalization = fTrackHist[region]->GetGrid(step)->GetAxis(4)->GetBinWidth(1) * (axis->GetBinUpEdge(axis->GetLast()) - axis->GetBinLowEdge(axis->GetFirst()));
502 //Printf("Normalization: %f", normalization);
503 tracksTmp->Scale(1.0 / normalization);
505 TH1D* events = fEventHist->ShowProjection(0, step);
506 Int_t nEvents = (Int_t) events->GetBinContent(bin);
508 tracksTmp->Scale(1.0 / nEvents);
509 Printf("Calculated histogram in bin %d --> %d events", bin, nEvents);
515 tracks->Add(tracksTmp);
521 ResetBinLimits(fTrackHist[region]->GetGrid(step));
526 //____________________________________________________________________
527 void AliUEHist::CorrectTracks(CFStep step1, CFStep step2, TH1* trackCorrection, Int_t var1, Int_t var2)
529 // corrects from step1 to step2 by multiplying the tracks with trackCorrection
530 // trackCorrection can be a function of eta (var1 == 0), pT (var1 == 1), leading pT (var1 == 2), multiplicity (var1 == 3), delta phi (var1 == 4)
531 // if var2 >= 0 a two dimension correction is assumed in trackCorrection
533 // if trackCorrection is 0, just copies content from step1 to step2
535 for (Int_t region=0; region<fkRegions; region++)
536 CorrectTracks(step1, step2, region, trackCorrection, var1, var2);
539 //____________________________________________________________________
540 void AliUEHist::CorrectTracks(CFStep step1, CFStep step2, Int_t region, TH1* trackCorrection, Int_t var1, Int_t var2)
543 // see documentation of CorrectTracks above
546 if (!fTrackHist[region])
549 THnSparse* grid = fTrackHist[region]->GetGrid(step1)->GetGrid();
550 THnSparse* target = fTrackHist[region]->GetGrid(step2)->GetGrid();
552 // clear target histogram
555 if (trackCorrection != 0)
557 if (grid->GetAxis(var1)->GetNbins() != trackCorrection->GetNbinsX())
558 AliFatal(Form("Invalid binning (var1): %d %d", grid->GetAxis(var1)->GetNbins(), trackCorrection->GetNbinsX()));
560 if (var2 >= 0 && grid->GetAxis(var2)->GetNbins() != trackCorrection->GetNbinsY())
561 AliFatal(Form("Invalid binning (var2): %d %d", grid->GetAxis(var2)->GetNbins(), trackCorrection->GetNbinsY()));
564 // optimized implementation
565 for (Int_t binIdx = 0; binIdx < grid->GetNbins(); binIdx++)
568 Double_t value = grid->GetBinContent(binIdx, bins);
569 Double_t error = grid->GetBinError(binIdx);
571 if (trackCorrection != 0)
575 value *= trackCorrection->GetBinContent(bins[var1]);
576 error *= trackCorrection->GetBinContent(bins[var1]);
580 value *= trackCorrection->GetBinContent(bins[var1], bins[var2]);
581 error *= trackCorrection->GetBinContent(bins[var1], bins[var2]);
585 target->SetBinContent(bins, value);
586 target->SetBinError(bins, error);
589 Printf("AliUEHist::CorrectTracks: Corrected from %f to %f entries. Correction histogram: %f entries (integral: %f)", grid->GetEntries(), target->GetEntries(), (trackCorrection) ? trackCorrection->GetEntries() : -1.0, (trackCorrection) ? trackCorrection->Integral() : -1.0);
592 //____________________________________________________________________
593 void AliUEHist::CorrectEvents(CFStep step1, CFStep step2, TH1D* eventCorrection, Int_t var)
595 // corrects from step1 to step2 by multiplying the events with eventCorrection
596 // eventCorrection is as function of leading pT (var == 0) or multiplicity (var == 1)
598 // if eventCorrection is 0, just copies content from step1 to step2
600 AliCFGridSparse* grid = fEventHist->GetGrid(step1);
601 AliCFGridSparse* target = fEventHist->GetGrid(step2);
603 // clear target histogram
604 target->GetGrid()->Reset();
606 if (eventCorrection != 0 && grid->GetNBins(var) != eventCorrection->GetNbinsX())
607 AliFatal(Form("Invalid binning: %d %d", grid->GetNBins(var), eventCorrection->GetNbinsX()));
610 for (Int_t x = 1; x <= grid->GetNBins(0); x++)
613 for (Int_t y = 1; y <= grid->GetNBins(1); y++)
617 Double_t value = grid->GetElement(bins);
620 Double_t error = grid->GetElementError(bins);
622 if (eventCorrection != 0)
624 value *= eventCorrection->GetBinContent(bins[var]);
625 error *= eventCorrection->GetBinContent(bins[var]);
628 target->SetElement(bins, value);
629 target->SetElementError(bins, error);
634 Printf("AliUEHist::CorrectEvents: Corrected from %f to %f entries. Correction histogram: %f entries (integral: %f)", grid->GetEntries(), target->GetEntries(), (eventCorrection) ? eventCorrection->GetEntries() : -1.0, (eventCorrection) ? eventCorrection->Integral() : -1.0);
637 //____________________________________________________________________
638 void AliUEHist::Correct(AliUEHist* corrections)
640 // applies the given corrections to extract from the step kCFStepReconstructed all previous steps
642 // in this object the data is expected in the step kCFStepReconstructed
646 // bias due to migration in leading pT (because the leading particle is not reconstructed, and the subleading is used)
647 // extracted as function of leading pT
648 for (Int_t region = 0; region < fkRegions; region++)
650 if (!fTrackHist[region])
653 const char* projAxis = "z";
654 Int_t secondBin = -1;
656 if (fTrackHist[region]->GetNVar() == 5)
663 TH1* leadingBias = (TH1*) corrections->GetBias(kCFStepReconstructed, kCFStepTracked, region, projAxis); // from MC
664 Printf("WARNING: Using MC bias correction");
666 TH1* leadingBias = (TH1*) GetBias(kCFStepBiasStudy, kCFStepReconstructed, region, projAxis); // from data
668 CorrectTracks(kCFStepReconstructed, kCFStepTracked, region, leadingBias, 2, secondBin);
669 if (region == kMin && fCombineMinMax)
671 CorrectTracks(kCFStepReconstructed, kCFStepTracked, kMax, leadingBias, 2, secondBin);
677 CorrectEvents(kCFStepReconstructed, kCFStepTracked, 0, 0);
679 // correct with kCFStepTracked --> kCFStepTrackedOnlyPrim
680 TH2D* contamination = corrections->GetTrackingContamination();
681 if (corrections->fContaminationEnhancement)
683 Printf("Applying contamination enhancement");
685 for (Int_t x=1; x<=contamination->GetNbinsX(); x++)
686 for (Int_t y=1; y<=contamination->GetNbinsX(); y++)
687 contamination->SetBinContent(x, y, contamination->GetBinContent(x, y) * corrections->fContaminationEnhancement->GetBinContent(corrections->fContaminationEnhancement->GetXaxis()->FindBin(contamination->GetYaxis()->GetBinCenter(y))));
689 CorrectTracks(kCFStepTracked, kCFStepTrackedOnlyPrim, contamination, 0, 1);
690 CorrectEvents(kCFStepTracked, kCFStepTrackedOnlyPrim, 0, 0);
691 delete contamination;
693 // correct with kCFStepTrackedOnlyPrim --> kCFStepAnaTopology
694 TH2D* efficiencyCorrection = corrections->GetTrackingEfficiencyCorrection();
695 CorrectTracks(kCFStepTrackedOnlyPrim, kCFStepAnaTopology, efficiencyCorrection, 0, 1);
696 CorrectEvents(kCFStepTrackedOnlyPrim, kCFStepAnaTopology, 0, 0);
697 delete efficiencyCorrection;
700 CorrectTracks(kCFStepAnaTopology, kCFStepVertex, 0, -1);
701 CorrectEvents(kCFStepAnaTopology, kCFStepVertex, 0, 0);
703 // vertex correction on the level of events as function of multiplicity, weighting tracks and events with the same factor
704 // practically independent of low pT cut
705 TH1D* vertexCorrection = (TH1D*) corrections->GetEventEfficiency(kCFStepVertex, kCFStepTriggered, 1);
707 // convert stage from true multiplicity to observed multiplicity by simple conversion factor
708 TH1D* vertexCorrectionObs = (TH1D*) vertexCorrection->Clone("vertexCorrection2");
709 vertexCorrectionObs->Reset();
711 TF1* func = new TF1("func", "[1]+[0]/(x-[2])");
713 func->SetParameters(0.1, 1, -0.7);
714 vertexCorrection->Fit(func, "0I", "", 0, 3);
715 for (Int_t i=1; i<=vertexCorrectionObs->GetNbinsX(); i++)
717 Float_t xPos = 1.0 / 0.77 * vertexCorrectionObs->GetXaxis()->GetBinCenter(i);
719 vertexCorrectionObs->SetBinContent(i, func->Eval(xPos));
721 vertexCorrectionObs->SetBinContent(i, vertexCorrection->Interpolate(xPos));
726 vertexCorrection->DrawCopy();
727 vertexCorrectionObs->SetLineColor(2);
728 vertexCorrectionObs->DrawCopy("same");
729 func->SetRange(0, 4);
730 func->DrawClone("same");
733 CorrectTracks(kCFStepVertex, kCFStepTriggered, vertexCorrectionObs, 3);
734 CorrectEvents(kCFStepVertex, kCFStepTriggered, vertexCorrectionObs, 1);
735 delete vertexCorrectionObs;
736 delete vertexCorrection;
740 CorrectTracks(kCFStepTriggered, kCFStepAll, 0, -1);
741 CorrectEvents(kCFStepTriggered, kCFStepAll, 0, 0);
744 //____________________________________________________________________
745 TH1* AliUEHist::GetTrackEfficiency(CFStep step1, CFStep step2, Int_t axis1, Int_t axis2, Int_t source)
747 // creates a track-level efficiency by dividing step2 by step1
748 // projected to axis1 and axis2 (optional if >= 0)
750 // source: 0 = fTrackHist; 1 = fTrackHistEfficiency
752 // integrate over regions
753 // cache it for efficiency (usually more than one efficiency is requested)
755 AliCFContainer* sourceContainer = 0;
761 fCache = (AliCFContainer*) fTrackHist[0]->Clone();
762 for (Int_t i = 1; i < fkRegions; i++)
764 fCache->Add(fTrackHist[i]);
766 sourceContainer = fCache;
768 else if (source == 1)
770 sourceContainer = fTrackHistEfficiency;
771 // step offset because we start with kCFStepAnaTopology
772 step1 = (CFStep) ((Int_t) step1 - (Int_t) kCFStepAnaTopology);
773 step2 = (CFStep) ((Int_t) step2 - (Int_t) kCFStepAnaTopology);
778 // reset all limits and set the right ones except those in axis1 and axis2
779 ResetBinLimits(sourceContainer->GetGrid(step1));
780 ResetBinLimits(sourceContainer->GetGrid(step2));
781 if (fEtaMax > fEtaMin && axis1 != 0 && axis2 != 0)
783 sourceContainer->GetGrid(step1)->SetRangeUser(0, fEtaMin, fEtaMax);
784 sourceContainer->GetGrid(step2)->SetRangeUser(0, fEtaMin, fEtaMax);
786 if (fPtMax > fPtMin && axis1 != 1 && axis2 != 1)
788 sourceContainer->GetGrid(step1)->SetRangeUser(1, fPtMin, fPtMax);
789 sourceContainer->GetGrid(step2)->SetRangeUser(1, fPtMin, fPtMax);
797 generated = sourceContainer->Project(axis1, axis2, step1);
798 measured = sourceContainer->Project(axis1, axis2, step2);
802 generated = sourceContainer->Project(axis1, step1);
803 measured = sourceContainer->Project(axis1, step2);
806 // check for bins with less than 100 entries, print warning
813 binEnd[0] = generated->GetNbinsX();
814 binEnd[1] = generated->GetNbinsY();
816 if (fEtaMax > fEtaMin)
820 binBegin[0] = generated->GetXaxis()->FindBin(fEtaMin);
821 binEnd[0] = generated->GetXaxis()->FindBin(fEtaMax);
825 binBegin[1] = generated->GetYaxis()->FindBin(fEtaMin);
826 binEnd[1] = generated->GetYaxis()->FindBin(fEtaMax);
832 // TODO this is just checking up to 15 for now
833 Float_t ptMax = TMath::Min((Float_t) 15., fPtMax);
836 binBegin[0] = generated->GetXaxis()->FindBin(fPtMin);
837 binEnd[0] = generated->GetXaxis()->FindBin(ptMax);
841 binBegin[1] = generated->GetYaxis()->FindBin(fPtMin);
842 binEnd[1] = generated->GetYaxis()->FindBin(ptMax);
850 for (Int_t i=0; i<2; i++)
851 vars[i] = binBegin[i];
853 const Int_t limit = 50;
856 if (generated->GetDimension() == 1 && generated->GetBinContent(vars[0]) < limit)
858 Printf("Empty bin at %s=%.2f (%.2f entries)", generated->GetXaxis()->GetTitle(), generated->GetXaxis()->GetBinCenter(vars[0]), generated->GetBinContent(vars[0]));
861 else if (generated->GetDimension() == 2 && generated->GetBinContent(vars[0], vars[1]) < limit)
863 Printf("Empty bin at %s=%.2f %s=%.2f (%.2f entries)",
864 generated->GetXaxis()->GetTitle(), generated->GetXaxis()->GetBinCenter(vars[0]),
865 generated->GetYaxis()->GetTitle(), generated->GetYaxis()->GetBinCenter(vars[1]),
866 generated->GetBinContent(vars[0], vars[1]));
871 if (vars[1] == binEnd[1]+1)
873 vars[1] = binBegin[1];
877 if (vars[0] == binEnd[0]+1)
882 Printf("Correction has %d empty bins (out of %d bins)", count, total);
884 measured->Divide(measured, generated, 1, 1, "B");
888 ResetBinLimits(sourceContainer->GetGrid(step1));
889 ResetBinLimits(sourceContainer->GetGrid(step2));
894 //____________________________________________________________________
895 TH1* AliUEHist::GetEventEfficiency(CFStep step1, CFStep step2, Int_t axis1, Int_t axis2, Float_t ptLeadMin, Float_t ptLeadMax)
897 // creates a event-level efficiency by dividing step2 by step1
898 // projected to axis1 and axis2 (optional if >= 0)
900 if (ptLeadMax > ptLeadMin)
902 fEventHist->GetGrid(step1)->SetRangeUser(0, ptLeadMin, ptLeadMax);
903 fEventHist->GetGrid(step2)->SetRangeUser(0, ptLeadMin, ptLeadMax);
911 generated = fEventHist->Project(axis1, axis2, step1);
912 measured = fEventHist->Project(axis1, axis2, step2);
916 generated = fEventHist->Project(axis1, step1);
917 measured = fEventHist->Project(axis1, step2);
920 measured->Divide(measured, generated, 1, 1, "B");
924 if (ptLeadMax > ptLeadMin)
926 fEventHist->GetGrid(step1)->SetRangeUser(0, 0, -1);
927 fEventHist->GetGrid(step2)->SetRangeUser(0, 0, -1);
933 //____________________________________________________________________
934 void AliUEHist::WeightHistogram(TH3* hist1, TH1* hist2)
936 // weights each entry of the 3d histogram hist1 with the 1d histogram hist2
937 // where the matching is done of the z axis of hist1 with the x axis of hist2
939 if (hist1->GetNbinsZ() != hist2->GetNbinsX())
940 AliFatal(Form("Inconsistent binning %d %d", hist1->GetNbinsZ(), hist2->GetNbinsX()));
942 for (Int_t x=1; x<=hist1->GetNbinsX(); x++)
944 for (Int_t y=1; y<=hist1->GetNbinsY(); y++)
946 for (Int_t z=1; z<=hist1->GetNbinsZ(); z++)
948 if (hist2->GetBinContent(z) > 0)
950 hist1->SetBinContent(x, y, z, hist1->GetBinContent(x, y, z) / hist2->GetBinContent(z));
951 hist1->SetBinError(x, y, z, hist1->GetBinError(x, y, z) / hist2->GetBinContent(z));
955 hist1->SetBinContent(x, y, z, 0);
956 hist1->SetBinError(x, y, z, 0);
963 //____________________________________________________________________
964 TH1* AliUEHist::GetBias(CFStep step1, CFStep step2, Int_t region, const char* axis, Float_t leadPtMin, Float_t leadPtMax)
966 // extracts the track-level bias (integrating out the multiplicity) between two steps (dividing step2 by step1)
967 // in the given region (sum over all regions is calculated if region == -1)
968 // done by weighting the track-level distribution with the number of events as function of leading pT
969 // and then calculating the ratio between the distributions
970 // projected to axis which is a TH3::Project3D string, e.g. "x", or "yx"
971 // no projection is done if axis == 0
973 AliCFContainer* tmp = 0;
977 tmp = (AliCFContainer*) fTrackHist[0]->Clone();
978 for (Int_t i = 1; i < fkRegions; i++)
980 tmp->Add(fTrackHist[i]);
982 else if (region == kMin && fCombineMinMax)
984 tmp = (AliCFContainer*) fTrackHist[kMin]->Clone();
985 tmp->Add(fTrackHist[kMax]);
988 tmp = fTrackHist[region];
990 ResetBinLimits(tmp->GetGrid(step1));
991 ResetBinLimits(fEventHist->GetGrid(step1));
992 SetBinLimits(tmp->GetGrid(step1));
994 ResetBinLimits(tmp->GetGrid(step2));
995 ResetBinLimits(fEventHist->GetGrid(step2));
996 SetBinLimits(tmp->GetGrid(step2));
998 TH1D* events1 = (TH1D*)fEventHist->Project(0, step1);
999 TH3D* hist1 = (TH3D*)tmp->Project(0, tmp->GetNVar()-1, 2, step1);
1000 WeightHistogram(hist1, events1);
1002 TH1D* events2 = (TH1D*)fEventHist->Project(0, step2);
1003 TH3D* hist2 = (TH3D*)tmp->Project(0, tmp->GetNVar()-1, 2, step2);
1004 WeightHistogram(hist2, events2);
1006 TH1* generated = hist1;
1007 TH1* measured = hist2;
1011 if (leadPtMax > leadPtMin)
1013 hist1->GetZaxis()->SetRangeUser(leadPtMin, leadPtMax);
1014 hist2->GetZaxis()->SetRangeUser(leadPtMin, leadPtMax);
1017 if (fEtaMax > fEtaMin && !TString(axis).Contains("x"))
1019 hist1->GetXaxis()->SetRangeUser(fEtaMin, fEtaMax);
1020 hist2->GetXaxis()->SetRangeUser(fEtaMin, fEtaMax);
1023 generated = hist1->Project3D(axis);
1024 measured = hist2->Project3D(axis);
1026 // delete hists here if projection has been done
1031 measured->Divide(generated);
1037 ResetBinLimits(tmp->GetGrid(step1));
1038 ResetBinLimits(tmp->GetGrid(step2));
1040 if ((region == -1) || (region == kMin && fCombineMinMax))
1046 //____________________________________________________________________
1047 TH2D* AliUEHist::GetTrackingEfficiency()
1049 // extracts the tracking efficiency by calculating the efficiency from step kCFStepAnaTopology to kCFStepTrackedOnlyPrim
1050 // integrates over the regions and all other variables than pT and eta to increase the statistics
1052 // returned histogram has to be deleted by the user
1054 return dynamic_cast<TH2D*> (GetTrackEfficiency(kCFStepAnaTopology, kCFStepTrackedOnlyPrim, 0, 1));
1057 //____________________________________________________________________
1058 TH1D* AliUEHist::GetTrackingEfficiency(Int_t axis)
1060 // extracts the tracking efficiency by calculating the efficiency from step kCFStepAnaTopology to kCFStepTrackedOnlyPrim
1061 // integrates over the regions and all other variables than pT (axis == 0) and eta (axis == 1) to increase the statistics
1063 return dynamic_cast<TH1D*> (GetTrackEfficiency(kCFStepAnaTopology, kCFStepTrackedOnlyPrim, axis));
1066 //____________________________________________________________________
1067 TH2D* AliUEHist::GetTrackingCorrection()
1069 // extracts the tracking correction by calculating the efficiency from step kCFStepAnaTopology to kCFStepTracked
1070 // integrates over the regions and all other variables than pT and eta to increase the statistics
1072 // returned histogram has to be deleted by the user
1074 return dynamic_cast<TH2D*> (GetTrackEfficiency(kCFStepTracked, kCFStepAnaTopology, 0, 1));
1077 //____________________________________________________________________
1078 TH1D* AliUEHist::GetTrackingCorrection(Int_t axis)
1080 // extracts the tracking correction by calculating the efficiency from step kCFStepAnaTopology to kCFStepTracked
1081 // integrates over the regions and all other variables than pT (axis == 0) and eta (axis == 1) to increase the statistics
1083 return dynamic_cast<TH1D*> (GetTrackEfficiency(kCFStepTracked, kCFStepAnaTopology, axis));
1086 //____________________________________________________________________
1087 TH2D* AliUEHist::GetTrackingEfficiencyCorrection()
1089 // extracts the tracking correction by calculating the efficiency from step kCFStepAnaTopology to kCFStepTracked
1090 // integrates over the regions and all other variables than pT and eta to increase the statistics
1092 // returned histogram has to be deleted by the user
1094 return dynamic_cast<TH2D*> (GetTrackEfficiency(kCFStepTrackedOnlyPrim, kCFStepAnaTopology, 0, 1));
1097 //____________________________________________________________________
1098 TH1D* AliUEHist::GetTrackingEfficiencyCorrection(Int_t axis)
1100 // extracts the tracking correction by calculating the efficiency from step kCFStepAnaTopology to kCFStepTracked
1101 // integrates over the regions and all other variables than pT (axis == 0) and eta (axis == 1) to increase the statistics
1103 return dynamic_cast<TH1D*> (GetTrackEfficiency(kCFStepTrackedOnlyPrim, kCFStepAnaTopology, axis));
1106 //____________________________________________________________________
1107 TH2D* AliUEHist::GetTrackingContamination()
1109 // extracts the tracking contamination by secondaries by calculating the efficiency from step kCFStepTrackedOnlyPrim to kCFStepTracked
1110 // integrates over the regions and all other variables than pT and eta to increase the statistics
1112 // returned histogram has to be deleted by the user
1114 return dynamic_cast<TH2D*> (GetTrackEfficiency(kCFStepTracked, kCFStepTrackedOnlyPrim, 0, 1));
1117 //____________________________________________________________________
1118 TH1D* AliUEHist::GetTrackingContamination(Int_t axis)
1120 // extracts the tracking contamination by secondaries by calculating the efficiency from step kCFStepTrackedOnlyPrim to kCFStepTracked
1121 // integrates over the regions and all other variables than pT (axis == 0) and eta (axis == 1) to increase the statistics
1123 return dynamic_cast<TH1D*> (GetTrackEfficiency(kCFStepTracked, kCFStepTrackedOnlyPrim, axis));
1126 //____________________________________________________________________
1127 const char* AliUEHist::GetRegionTitle(Region region)
1129 // returns the name of the given region
1138 return (fCombineMinMax) ? "Transverse" : "Min";
1146 //____________________________________________________________________
1147 const char* AliUEHist::GetStepTitle(CFStep step)
1149 // returns the name of the given step
1154 return "All events";
1155 case kCFStepTriggered:
1158 return "Primary Vertex";
1159 case kCFStepAnaTopology:
1160 return "Required analysis topology";
1161 case kCFStepTrackedOnlyPrim:
1162 return "Tracked (matched MC, only primaries)";
1163 case kCFStepTracked:
1164 return "Tracked (matched MC, all)";
1165 case kCFStepReconstructed:
1166 return "Reconstructed";
1167 case kCFStepRealLeading:
1168 return "Correct leading particle identified";
1169 case kCFStepBiasStudy:
1170 return "Bias study applying tracking efficiency";
1171 case kCFStepBiasStudy2:
1172 return "Bias study applying tracking efficiency in two steps";
1178 //____________________________________________________________________
1179 void AliUEHist::CopyReconstructedData(AliUEHist* from)
1181 // copies those histograms extracted from ESD to this object
1183 // TODO at present only the pointers are copied
1185 for (Int_t region=0; region<4; region++)
1187 if (!fTrackHist[region])
1190 fTrackHist[region]->SetGrid(AliUEHist::kCFStepReconstructed, from->fTrackHist[region]->GetGrid(AliUEHist::kCFStepReconstructed));
1191 //fTrackHist[region]->SetGrid(AliUEHist::kCFStepTrackedOnlyPrim, from->fTrackHist[region]->GetGrid(AliUEHist::kCFStepTrackedOnlyPrim));
1192 fTrackHist[region]->SetGrid(AliUEHist::kCFStepBiasStudy, from->fTrackHist[region]->GetGrid(AliUEHist::kCFStepBiasStudy));
1195 fEventHist->SetGrid(AliUEHist::kCFStepReconstructed, from->fEventHist->GetGrid(AliUEHist::kCFStepReconstructed));
1196 //fEventHist->SetGrid(AliUEHist::kCFStepTrackedOnlyPrim, from->fEventHist->GetGrid(AliUEHist::kCFStepTrackedOnlyPrim));
1197 fEventHist->SetGrid(AliUEHist::kCFStepBiasStudy, from->fEventHist->GetGrid(AliUEHist::kCFStepBiasStudy));
1200 //____________________________________________________________________
1201 void AliUEHist::ExtendTrackingEfficiency(Bool_t verbose)
1203 // fits the tracking efficiency at high pT with a constant and fills all bins with this tracking efficiency
1205 Float_t fitRangeBegin = 5.01;
1206 Float_t fitRangeEnd = 14.99;
1207 Float_t extendRangeBegin = 10.01;
1209 TH1* obj = GetTrackingEfficiency(1);
1212 new TCanvas; obj->Draw();
1213 obj->Fit("pol0", (verbose) ? "+" : "+0", "SAME", fitRangeBegin, fitRangeEnd);
1215 Float_t trackingEff = obj->GetFunction("pol0")->GetParameter(0);
1217 obj = GetTrackingContamination(1);
1220 new TCanvas; obj->Draw();
1221 obj->Fit("pol0", (verbose) ? "+" : "+0", "SAME", fitRangeBegin, fitRangeEnd);
1223 Float_t trackingCont = obj->GetFunction("pol0")->GetParameter(0);
1225 Printf("AliUEHist::ExtendTrackingEfficiency: Fitted efficiency between %f and %f and got %f tracking efficiency and %f tracking contamination correction. Extending from %f onwards (within %f < eta < %f)", fitRangeBegin, fitRangeEnd, trackingEff, trackingCont, extendRangeBegin, fEtaMin, fEtaMax);
1227 // extend up to pT 100
1228 for (Int_t x = fTrackHistEfficiency->GetAxis(0, 0)->FindBin(fEtaMin); x <= fTrackHistEfficiency->GetAxis(0, 0)->FindBin(fEtaMax); x++)
1229 for (Int_t y = fTrackHistEfficiency->GetAxis(1, 0)->FindBin(extendRangeBegin); y <= fTrackHistEfficiency->GetNBins(1); y++)
1230 for (Int_t z = 1; z <= fTrackHistEfficiency->GetNBins(2); z++) // particle type axis
1237 fTrackHistEfficiency->GetGrid(0)->SetElement(bins, 100);
1238 fTrackHistEfficiency->GetGrid(1)->SetElement(bins, 100.0 * trackingEff);
1239 fTrackHistEfficiency->GetGrid(2)->SetElement(bins, 100.0 * trackingEff / trackingCont);
1243 void AliUEHist::AdditionalDPhiCorrection(Int_t step)
1245 // corrects the dphi distribution with an extra factor close to dphi ~ 0
1247 Printf("WARNING: In AliUEHist::AdditionalDPhiCorrection.");
1249 THnSparse* grid = fTrackHist[0]->GetGrid(step)->GetGrid();
1251 // optimized implementation
1252 for (Int_t binIdx = 0; binIdx < grid->GetNbins(); binIdx++)
1255 Double_t value = grid->GetBinContent(binIdx, bins);
1256 Double_t error = grid->GetBinError(binIdx);
1258 Float_t binCenter = grid->GetAxis(4)->GetBinCenter(bins[4]);
1259 if (TMath::Abs(binCenter) < 0.2)
1264 else if (TMath::Abs(binCenter) < 0.3)
1270 grid->SetBinContent(bins, value);
1271 grid->SetBinError(bins, error);