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 const char* title = "";
66 Int_t nTrackVars = 4; // eta vs pT vs pT,lead (vs delta phi) vs multiplicity
68 Double_t* trackBins[5];
69 const char* trackAxisTitle[5];
73 Double_t etaBins[20+1];
74 for (Int_t i=0; i<=iTrackBin[0]; i++)
75 etaBins[i] = -1.0 + 0.1 * i;
76 trackBins[0] = etaBins;
77 trackAxisTitle[0] = "#eta";
81 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};
82 trackBins[1] = pTBins;
83 trackAxisTitle[1] = "p_{T} (GeV/c)";
86 const Int_t kNLeadingpTBins = 100;
87 Double_t leadingpTBins[kNLeadingpTBins+1];
88 for (Int_t i=0; i<=kNLeadingpTBins; i++)
89 leadingpTBins[i] = 0.5 * i;
92 const Int_t kNLeadingpTBins2 = 13;
93 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 };
96 const Int_t kNLeadingPhiBins = 40;
97 Double_t leadingPhiBins[kNLeadingPhiBins+1];
98 for (Int_t i=0; i<=kNLeadingPhiBins; i++)
99 leadingPhiBins[i] = -1.5 * TMath::Pi() + 1.0 / 40 * i * TMath::TwoPi();
102 const Int_t kNMultiplicityBins = 15;
103 Double_t multiplicityBins[kNMultiplicityBins+1];
104 for (Int_t i=0; i<=kNMultiplicityBins; i++)
105 multiplicityBins[i] = -0.5 + i;
106 multiplicityBins[kNMultiplicityBins] = 200;
109 const Int_t kNSpeciesBins = 4; // pi, K, p, rest
110 Double_t speciesBins[] = { -0.5, 0.5, 1.5, 2.5, 3.5 };
112 trackBins[3] = multiplicityBins;
113 iTrackBin[3] = kNMultiplicityBins;
114 trackAxisTitle[3] = "multiplicity";
116 // selection depending on requested histogram
117 Int_t axis = -1; // 0 = pT,lead, 1 = phi,lead
118 if (strcmp(reqHist, "NumberDensitypT") == 0)
121 title = "d^{2}N_{ch}/d#phid#eta";
123 else if (strcmp(reqHist, "NumberDensityPhi") == 0)
126 title = "d^{2}N_{ch}/d#phid#eta";
128 else if (strcmp(reqHist, "SumpT") == 0)
131 title = "d^{2}#Sigma p_{T}/d#phid#eta";
134 AliFatal(Form("Invalid histogram requested: %s", reqHist));
136 Int_t initRegions = fkRegions;
140 trackBins[2] = leadingpTBins;
141 iTrackBin[2] = kNLeadingpTBins;
142 trackAxisTitle[2] = "leading p_{T} (GeV/c)";
150 iTrackBin[2] = kNLeadingpTBins2;
151 trackBins[2] = leadingpTBins2;
152 trackAxisTitle[2] = "leading p_{T} (GeV/c)";
154 iTrackBin[4] = kNLeadingPhiBins;
155 trackBins[4] = leadingPhiBins;
156 trackAxisTitle[4] = "#phi w.r.t leading track";
159 for (Int_t i=0; i<initRegions; i++)
161 fTrackHist[i] = new AliCFContainer(Form("fTrackHist_%d", i), title, fgkCFSteps, nTrackVars, iTrackBin);
163 for (Int_t j=0; j<nTrackVars; j++)
165 fTrackHist[i]->SetBinLimits(j, trackBins[j]);
166 fTrackHist[i]->SetVarTitle(j, trackAxisTitle[j]);
169 SetStepNames(fTrackHist[i]);
172 // track 3rd and 4th axis --> event 1st and 2nd axis
173 fEventHist = new AliCFContainer("fEventHist", title, fgkCFSteps, 2, iTrackBin+2);
175 fEventHist->SetBinLimits(0, trackBins[2]);
176 fEventHist->SetVarTitle(0, trackAxisTitle[2]);
178 fEventHist->SetBinLimits(1, trackBins[3]);
179 fEventHist->SetVarTitle(1, trackAxisTitle[3]);
181 SetStepNames(fEventHist);
183 iTrackBin[2] = kNSpeciesBins;
185 fTrackHistEfficiency = new AliCFContainer("fTrackHistEfficiency", "Tracking efficiency", 3, 3, iTrackBin);
186 fTrackHistEfficiency->SetBinLimits(0, trackBins[0]);
187 fTrackHistEfficiency->SetVarTitle(0, trackAxisTitle[0]);
188 fTrackHistEfficiency->SetBinLimits(1, trackBins[1]);
189 fTrackHistEfficiency->SetVarTitle(1, trackAxisTitle[1]);
190 fTrackHistEfficiency->SetBinLimits(2, speciesBins);
191 fTrackHistEfficiency->SetVarTitle(2, "particle species");
194 //_____________________________________________________________________________
195 AliUEHist::AliUEHist(const AliUEHist &c) :
199 fTrackHistEfficiency(0),
204 fContaminationEnhancement(0),
209 // AliUEHist copy constructor
212 ((AliUEHist &) c).Copy(*this);
215 //____________________________________________________________________
216 void AliUEHist::SetStepNames(AliCFContainer* container)
218 // sets the names of the correction steps
220 for (Int_t i=0; i<fgkCFSteps; i++)
221 container->SetStepTitle(i, GetStepTitle((CFStep) i));
224 //____________________________________________________________________
225 AliUEHist::~AliUEHist()
229 for (Int_t i=0; i<fkRegions; i++)
233 delete fTrackHist[i];
244 if (fTrackHistEfficiency)
246 delete fTrackHistEfficiency;
247 fTrackHistEfficiency = 0;
257 //____________________________________________________________________
258 AliUEHist &AliUEHist::operator=(const AliUEHist &c)
260 // assigment operator
263 ((AliUEHist &) c).Copy(*this);
268 //____________________________________________________________________
269 void AliUEHist::Copy(TObject& c) const
273 AliUEHist& target = (AliUEHist &) c;
275 for (Int_t i=0; i<fkRegions; i++)
277 target.fTrackHist[i] = dynamic_cast<AliCFContainer*> (fTrackHist[i]->Clone());
280 target.fEventHist = dynamic_cast<AliCFContainer*> (fEventHist->Clone());
282 if (fTrackHistEfficiency)
283 target.fTrackHistEfficiency = dynamic_cast<AliCFContainer*> (fTrackHistEfficiency->Clone());
286 //____________________________________________________________________
287 Long64_t AliUEHist::Merge(TCollection* list)
289 // Merge a list of AliUEHist objects with this (needed for
291 // Returns the number of merged objects (including this).
299 TIterator* iter = list->MakeIterator();
302 // collections of objects
303 const Int_t kMaxLists = fkRegions+2;
304 TList** lists = new TList*[kMaxLists];
306 for (Int_t i=0; i<kMaxLists; i++)
307 lists[i] = new TList;
310 while ((obj = iter->Next())) {
312 AliUEHist* entry = dynamic_cast<AliUEHist*> (obj);
316 for (Int_t i=0; i<fkRegions; i++)
317 if (entry->fTrackHist[i])
318 lists[i]->Add(entry->fTrackHist[i]);
320 lists[fkRegions]->Add(entry->fEventHist);
321 lists[fkRegions+1]->Add(entry->fTrackHistEfficiency);
325 for (Int_t i=0; i<fkRegions; i++)
327 fTrackHist[i]->Merge(lists[i]);
329 fEventHist->Merge(lists[fkRegions]);
330 fTrackHistEfficiency->Merge(lists[fkRegions+1]);
332 for (Int_t i=0; i<kMaxLists; i++)
340 //____________________________________________________________________
341 void AliUEHist::SetBinLimits(AliCFGridSparse* grid)
343 // sets the bin limits in eta and pT defined by fEtaMin/Max, fPtMin/Max
345 if (fEtaMax > fEtaMin)
346 grid->SetRangeUser(0, fEtaMin, fEtaMax);
348 grid->SetRangeUser(1, fPtMin, fPtMax);
351 //____________________________________________________________________
352 void AliUEHist::ResetBinLimits(AliCFGridSparse* grid)
354 // resets all bin limits
356 for (Int_t i=0; i<grid->GetNVar(); i++)
357 if (grid->GetGrid()->GetAxis(i)->TestBit(TAxis::kAxisRange))
358 grid->SetRangeUser(i, 0, -1);
361 //____________________________________________________________________
362 void AliUEHist::CountEmptyBins(AliUEHist::CFStep step, Float_t ptLeadMin, Float_t ptLeadMax)
364 // prints the number of empty bins in the track end event histograms in the given step
369 for (Int_t i=0; i<4; i++)
372 binEnd[i] = fTrackHist[0]->GetNBins(i);
375 if (fEtaMax > fEtaMin)
377 binBegin[0] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(0)->FindBin(fEtaMin);
378 binEnd[0] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(0)->FindBin(fEtaMax);
383 binBegin[1] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(fPtMin);
384 binEnd[1] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(fPtMax);
387 if (ptLeadMax > ptLeadMin)
389 binBegin[2] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(2)->FindBin(ptLeadMin);
390 binEnd[2] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(2)->FindBin(ptLeadMax);
393 // start from multiplicity 1
394 binBegin[3] = fTrackHist[0]->GetGrid(step)->GetGrid()->GetAxis(3)->FindBin(1);
396 for (Int_t region=0; region<fkRegions; region++)
402 for (Int_t i=0; i<4; i++)
403 vars[i] = binBegin[i];
405 AliCFGridSparse* grid = fTrackHist[region]->GetGrid(step);
408 if (grid->GetElement(vars) == 0)
410 Printf("Empty bin at eta=%.2f pt=%.2f pt_lead=%.2f mult=%.1f",
411 grid->GetBinCenter(0, vars[0]),
412 grid->GetBinCenter(1, vars[1]),
413 grid->GetBinCenter(2, vars[2]),
414 grid->GetBinCenter(3, vars[3])
420 for (Int_t i=3; i>0; i--)
422 if (vars[i] == binEnd[i]+1)
424 vars[i] = binBegin[i];
429 if (vars[0] == binEnd[0]+1)
434 Printf("Region %s has %d empty bins (out of %d bins)", GetRegionTitle((Region) region), count, total);
438 //____________________________________________________________________
439 TH1D* AliUEHist::GetUEHist(AliUEHist::CFStep step, AliUEHist::Region region, Float_t ptLeadMin, Float_t ptLeadMax)
441 // Extracts the UE histogram at the given step and in the given region by projection and dividing tracks by events
443 // ptLeadMin, ptLeadMax: Only meaningful for vs. delta phi plot (third axis is ptLead)
444 // Histogram has to be deleted by the caller of the function
447 ResetBinLimits(fTrackHist[region]->GetGrid(step));
448 ResetBinLimits(fEventHist->GetGrid(step));
450 SetBinLimits(fTrackHist[region]->GetGrid(step));
456 tracks = fTrackHist[region]->ShowProjection(2, step);
457 tracks->GetYaxis()->SetTitle(fTrackHist[region]->GetTitle());
458 if (fCombineMinMax && region == kMin)
460 ResetBinLimits(fTrackHist[kMax]->GetGrid(step));
461 SetBinLimits(fTrackHist[kMax]->GetGrid(step));
463 TH1D* tracks2 = fTrackHist[kMax]->ShowProjection(2, step);
464 tracks->Add(tracks2);
466 ResetBinLimits(fTrackHist[kMax]->GetGrid(step));
469 // normalize to get a density (deta dphi)
470 TAxis* axis = fTrackHist[region]->GetGrid(step)->GetAxis(0);
471 Float_t phiRegion = TMath::TwoPi() / 3;
472 if (!fCombineMinMax && region == kMin)
474 Float_t normalization = phiRegion * (axis->GetBinUpEdge(axis->GetLast()) - axis->GetBinLowEdge(axis->GetFirst()));
475 //Printf("Normalization: %f", normalization);
476 tracks->Scale(1.0 / normalization);
478 TH1D* events = fEventHist->ShowProjection(0, step);
479 tracks->Divide(events);
483 fTrackHist[region]->GetGrid(step)->SetRangeUser(2, ptLeadMin, ptLeadMax);
484 tracks = fTrackHist[region]->GetGrid(step)->Project(4);
485 Printf("Calculated histogram in %.2f <= pT <= %.2f --> %f entries", ptLeadMin, ptLeadMax, tracks->Integral());
486 fTrackHist[region]->GetGrid(step)->SetRangeUser(2, 0, -1);
488 // normalize to get a density (deta dphi)
489 TAxis* axis = fTrackHist[region]->GetGrid(step)->GetAxis(0);
490 Float_t normalization = fTrackHist[region]->GetGrid(step)->GetAxis(4)->GetBinWidth(1) * (axis->GetBinUpEdge(axis->GetLast()) - axis->GetBinLowEdge(axis->GetFirst()));
491 //Printf("Normalization: %f", normalization);
492 tracks->Scale(1.0 / normalization);
494 TH1D* events = fEventHist->ShowProjection(0, step);
495 Int_t nEvents = (Int_t) events->Integral(events->FindBin(ptLeadMin), events->FindBin(ptLeadMax));
497 tracks->Scale(1.0 / nEvents);
500 ResetBinLimits(fTrackHist[region]->GetGrid(step));
505 //____________________________________________________________________
506 void AliUEHist::CorrectTracks(CFStep step1, CFStep step2, TH1* trackCorrection, Int_t var1, Int_t var2)
508 // corrects from step1 to step2 by multiplying the tracks with trackCorrection
509 // trackCorrection can be a function of eta (var1 == 0), pT (var1 == 1), leading pT (var1 == 2), multiplicity (var1 == 3), delta phi (var1 == 4)
510 // if var2 >= 0 a two dimension correction is assumed in trackCorrection
512 // if trackCorrection is 0, just copies content from step1 to step2
514 for (Int_t region=0; region<fkRegions; region++)
515 CorrectTracks(step1, step2, region, trackCorrection, var1, var2);
518 //____________________________________________________________________
519 void AliUEHist::CorrectTracks(CFStep step1, CFStep step2, Int_t region, TH1* trackCorrection, Int_t var1, Int_t var2)
522 // see documentation of CorrectTracks above
525 if (!fTrackHist[region])
528 THnSparse* grid = fTrackHist[region]->GetGrid(step1)->GetGrid();
529 THnSparse* target = fTrackHist[region]->GetGrid(step2)->GetGrid();
531 // clear target histogram
534 if (trackCorrection != 0)
536 if (grid->GetAxis(var1)->GetNbins() != trackCorrection->GetNbinsX())
537 AliFatal(Form("Invalid binning (var1): %d %d", grid->GetAxis(var1)->GetNbins(), trackCorrection->GetNbinsX()));
539 if (var2 >= 0 && grid->GetAxis(var2)->GetNbins() != trackCorrection->GetNbinsY())
540 AliFatal(Form("Invalid binning (var2): %d %d", grid->GetAxis(var2)->GetNbins(), trackCorrection->GetNbinsY()));
543 // optimized implementation
544 for (Int_t binIdx = 0; binIdx < grid->GetNbins(); binIdx++)
547 Double_t value = grid->GetBinContent(binIdx, bins);
548 Double_t error = grid->GetBinError(binIdx);
550 if (trackCorrection != 0)
554 value *= trackCorrection->GetBinContent(bins[var1]);
555 error *= trackCorrection->GetBinContent(bins[var1]);
559 value *= trackCorrection->GetBinContent(bins[var1], bins[var2]);
560 error *= trackCorrection->GetBinContent(bins[var1], bins[var2]);
564 target->SetBinContent(bins, value);
565 target->SetBinError(bins, error);
569 //____________________________________________________________________
570 void AliUEHist::CorrectEvents(CFStep step1, CFStep step2, TH1D* eventCorrection, Int_t var)
572 // corrects from step1 to step2 by multiplying the events with eventCorrection
573 // eventCorrection is as function of leading pT (var == 0) or multiplicity (var == 1)
575 // if eventCorrection is 0, just copies content from step1 to step2
577 AliCFGridSparse* grid = fEventHist->GetGrid(step1);
578 AliCFGridSparse* target = fEventHist->GetGrid(step2);
580 // clear target histogram
581 target->GetGrid()->Reset();
583 if (eventCorrection != 0 && grid->GetNBins(var) != eventCorrection->GetNbinsX())
584 AliFatal(Form("Invalid binning: %d %d", grid->GetNBins(var), eventCorrection->GetNbinsX()));
587 for (Int_t x = 1; x <= grid->GetNBins(0); x++)
590 for (Int_t y = 1; y <= grid->GetNBins(1); y++)
594 Double_t value = grid->GetElement(bins);
597 Double_t error = grid->GetElementError(bins);
599 if (eventCorrection != 0)
601 value *= eventCorrection->GetBinContent(bins[var]);
602 error *= eventCorrection->GetBinContent(bins[var]);
605 target->SetElement(bins, value);
606 target->SetElementError(bins, error);
612 //____________________________________________________________________
613 void AliUEHist::Correct(AliUEHist* corrections)
615 // applies the given corrections to extract from the step kCFStepReconstructed all previous steps
617 // in this object the data is expected in the step kCFStepReconstructed
621 // bias due to migration in leading pT (because the leading particle is not reconstructed, and the subleading is used)
622 // extracted as function of leading pT
623 for (Int_t region = 0; region < fkRegions; region++)
625 if (!fTrackHist[region])
628 const char* projAxis = "z";
629 Int_t secondBin = -1;
631 if (fTrackHist[region]->GetNVar() == 5)
638 TH1* leadingBias = (TH1*) corrections->GetBias(kCFStepReconstructed, kCFStepTracked, region, projAxis); // from MC
639 Printf("WARNING: Using MC bias correction");
641 TH1* leadingBias = (TH1*) GetBias(kCFStepBiasStudy, kCFStepReconstructed, region, projAxis); // from data
643 CorrectTracks(kCFStepReconstructed, kCFStepTracked, region, leadingBias, 2, secondBin);
644 if (region == kMin && fCombineMinMax)
646 CorrectTracks(kCFStepReconstructed, kCFStepTracked, kMax, leadingBias, 2, secondBin);
652 CorrectEvents(kCFStepReconstructed, kCFStepTracked, 0, 0);
654 // correct with kCFStepTracked --> kCFStepTrackedOnlyPrim
655 TH2D* contamination = corrections->GetTrackingContamination();
656 if (corrections->fContaminationEnhancement)
658 Printf("Applying contamination enhancement");
660 for (Int_t x=1; x<=contamination->GetNbinsX(); x++)
661 for (Int_t y=1; y<=contamination->GetNbinsX(); y++)
662 contamination->SetBinContent(x, y, contamination->GetBinContent(x, y) * corrections->fContaminationEnhancement->GetBinContent(corrections->fContaminationEnhancement->GetXaxis()->FindBin(contamination->GetYaxis()->GetBinCenter(y))));
664 CorrectTracks(kCFStepTracked, kCFStepTrackedOnlyPrim, contamination, 0, 1);
665 CorrectEvents(kCFStepTracked, kCFStepTrackedOnlyPrim, 0, 0);
666 delete contamination;
668 // correct with kCFStepTrackedOnlyPrim --> kCFStepAnaTopology
669 TH2D* efficiencyCorrection = corrections->GetTrackingEfficiencyCorrection();
670 CorrectTracks(kCFStepTrackedOnlyPrim, kCFStepAnaTopology, efficiencyCorrection, 0, 1);
671 CorrectEvents(kCFStepTrackedOnlyPrim, kCFStepAnaTopology, 0, 0);
672 delete efficiencyCorrection;
675 CorrectTracks(kCFStepAnaTopology, kCFStepVertex, 0, -1);
676 CorrectEvents(kCFStepAnaTopology, kCFStepVertex, 0, 0);
678 // vertex correction on the level of events as function of multiplicity, weighting tracks and events with the same factor
679 // practically independent of low pT cut
680 TH1D* vertexCorrection = (TH1D*) corrections->GetEventEfficiency(kCFStepVertex, kCFStepTriggered, 1);
682 // convert stage from true multiplicity to observed multiplicity by simple conversion factor
683 TH1D* vertexCorrectionObs = (TH1D*) vertexCorrection->Clone("vertexCorrection2");
684 vertexCorrectionObs->Reset();
686 TF1* func = new TF1("func", "[1]+[0]/(x-[2])");
687 vertexCorrection->Fit(func, "0", "", 0, 3);
689 for (Int_t i=1; i<=vertexCorrectionObs->GetNbinsX(); i++)
691 Float_t xPos = 1.0 / 0.77 * vertexCorrectionObs->GetXaxis()->GetBinCenter(i);
693 vertexCorrectionObs->SetBinContent(i, func->Eval(xPos));
695 vertexCorrectionObs->SetBinContent(i, vertexCorrection->Interpolate(xPos));
700 vertexCorrection->DrawCopy();
701 vertexCorrectionObs->SetLineColor(2);
702 vertexCorrectionObs->DrawCopy("same");
703 func->SetRange(0, 4);
704 func->DrawClone("same");
707 CorrectTracks(kCFStepVertex, kCFStepTriggered, vertexCorrectionObs, 3);
708 CorrectEvents(kCFStepVertex, kCFStepTriggered, vertexCorrectionObs, 1);
709 delete vertexCorrectionObs;
710 delete vertexCorrection;
714 CorrectTracks(kCFStepTriggered, kCFStepAll, 0, -1);
715 CorrectEvents(kCFStepTriggered, kCFStepAll, 0, 0);
718 //____________________________________________________________________
719 TH1* AliUEHist::GetTrackEfficiency(CFStep step1, CFStep step2, Int_t axis1, Int_t axis2, Int_t source)
721 // creates a track-level efficiency by dividing step2 by step1
722 // projected to axis1 and axis2 (optional if >= 0)
724 // source: 0 = fTrackHist; 1 = fTrackHistEfficiency
726 // integrate over regions
727 // cache it for efficiency (usually more than one efficiency is requested)
729 AliCFContainer* sourceContainer = 0;
735 fCache = (AliCFContainer*) fTrackHist[0]->Clone();
736 for (Int_t i = 1; i < fkRegions; i++)
738 fCache->Add(fTrackHist[i]);
740 sourceContainer = fCache;
742 else if (source == 1)
744 sourceContainer = fTrackHistEfficiency;
745 // step offset because we start with kCFStepAnaTopology
746 step1 = (CFStep) ((Int_t) step1 - (Int_t) kCFStepAnaTopology);
747 step2 = (CFStep) ((Int_t) step2 - (Int_t) kCFStepAnaTopology);
752 // reset all limits and set the right ones except those in axis1 and axis2
753 ResetBinLimits(sourceContainer->GetGrid(step1));
754 ResetBinLimits(sourceContainer->GetGrid(step2));
755 if (fEtaMax > fEtaMin && axis1 != 0 && axis2 != 0)
757 sourceContainer->GetGrid(step1)->SetRangeUser(0, fEtaMin, fEtaMax);
758 sourceContainer->GetGrid(step2)->SetRangeUser(0, fEtaMin, fEtaMax);
760 if (fPtMax > fPtMin && axis1 != 1 && axis2 != 1)
762 sourceContainer->GetGrid(step1)->SetRangeUser(1, fPtMin, fPtMax);
763 sourceContainer->GetGrid(step2)->SetRangeUser(1, fPtMin, fPtMax);
771 generated = sourceContainer->Project(axis1, axis2, step1);
772 measured = sourceContainer->Project(axis1, axis2, step2);
776 generated = sourceContainer->Project(axis1, step1);
777 measured = sourceContainer->Project(axis1, step2);
780 // check for bins with less than 100 entries, print warning
787 binEnd[0] = generated->GetNbinsX();
788 binEnd[1] = generated->GetNbinsY();
790 if (fEtaMax > fEtaMin)
794 binBegin[0] = generated->GetXaxis()->FindBin(fEtaMin);
795 binEnd[0] = generated->GetXaxis()->FindBin(fEtaMax);
799 binBegin[1] = generated->GetYaxis()->FindBin(fEtaMin);
800 binEnd[1] = generated->GetYaxis()->FindBin(fEtaMax);
806 // TODO this is just checking up to 15 for now
807 Float_t ptMax = TMath::Min((Float_t) 15., fPtMax);
810 binBegin[0] = generated->GetXaxis()->FindBin(fPtMin);
811 binEnd[0] = generated->GetXaxis()->FindBin(ptMax);
815 binBegin[1] = generated->GetYaxis()->FindBin(fPtMin);
816 binEnd[1] = generated->GetYaxis()->FindBin(ptMax);
824 for (Int_t i=0; i<2; i++)
825 vars[i] = binBegin[i];
827 const Int_t limit = 50;
830 if (generated->GetDimension() == 1 && generated->GetBinContent(vars[0]) < limit)
832 Printf("Empty bin at %s=%.2f (%.2f entries)", generated->GetXaxis()->GetTitle(), generated->GetXaxis()->GetBinCenter(vars[0]), generated->GetBinContent(vars[0]));
835 else if (generated->GetDimension() == 2 && generated->GetBinContent(vars[0], vars[1]) < limit)
837 Printf("Empty bin at %s=%.2f %s=%.2f (%.2f entries)",
838 generated->GetXaxis()->GetTitle(), generated->GetXaxis()->GetBinCenter(vars[0]),
839 generated->GetYaxis()->GetTitle(), generated->GetYaxis()->GetBinCenter(vars[1]),
840 generated->GetBinContent(vars[0], vars[1]));
845 if (vars[1] == binEnd[1]+1)
847 vars[1] = binBegin[1];
851 if (vars[0] == binEnd[0]+1)
856 Printf("Correction has %d empty bins (out of %d bins)", count, total);
858 measured->Divide(measured, generated, 1, 1, "B");
862 ResetBinLimits(sourceContainer->GetGrid(step1));
863 ResetBinLimits(sourceContainer->GetGrid(step2));
868 //____________________________________________________________________
869 TH1* AliUEHist::GetEventEfficiency(CFStep step1, CFStep step2, Int_t axis1, Int_t axis2, Float_t ptLeadMin, Float_t ptLeadMax)
871 // creates a event-level efficiency by dividing step2 by step1
872 // projected to axis1 and axis2 (optional if >= 0)
874 if (ptLeadMax > ptLeadMin)
876 fEventHist->GetGrid(step1)->SetRangeUser(0, ptLeadMin, ptLeadMax);
877 fEventHist->GetGrid(step2)->SetRangeUser(0, ptLeadMin, ptLeadMax);
885 generated = fEventHist->Project(axis1, axis2, step1);
886 measured = fEventHist->Project(axis1, axis2, step2);
890 generated = fEventHist->Project(axis1, step1);
891 measured = fEventHist->Project(axis1, step2);
894 measured->Divide(measured, generated, 1, 1, "B");
898 if (ptLeadMax > ptLeadMin)
900 fEventHist->GetGrid(step1)->SetRangeUser(0, 0, -1);
901 fEventHist->GetGrid(step2)->SetRangeUser(0, 0, -1);
907 //____________________________________________________________________
908 void AliUEHist::WeightHistogram(TH3* hist1, TH1* hist2)
910 // weights each entry of the 3d histogram hist1 with the 1d histogram hist2
911 // where the matching is done of the z axis of hist1 with the x axis of hist2
913 if (hist1->GetNbinsZ() != hist2->GetNbinsX())
914 AliFatal(Form("Inconsistent binning %d %d", hist1->GetNbinsZ(), hist2->GetNbinsX()));
916 for (Int_t x=1; x<=hist1->GetNbinsX(); x++)
918 for (Int_t y=1; y<=hist1->GetNbinsY(); y++)
920 for (Int_t z=1; z<=hist1->GetNbinsZ(); z++)
922 if (hist2->GetBinContent(z) > 0)
924 hist1->SetBinContent(x, y, z, hist1->GetBinContent(x, y, z) / hist2->GetBinContent(z));
925 hist1->SetBinError(x, y, z, hist1->GetBinError(x, y, z) / hist2->GetBinContent(z));
929 hist1->SetBinContent(x, y, z, 0);
930 hist1->SetBinError(x, y, z, 0);
937 //____________________________________________________________________
938 TH1* AliUEHist::GetBias(CFStep step1, CFStep step2, Int_t region, const char* axis, Float_t leadPtMin, Float_t leadPtMax)
940 // extracts the track-level bias (integrating out the multiplicity) between two steps (dividing step2 by step1)
941 // in the given region (sum over all regions is calculated if region == -1)
942 // done by weighting the track-level distribution with the number of events as function of leading pT
943 // and then calculating the ratio between the distributions
944 // projected to axis which is a TH3::Project3D string, e.g. "x", or "yx"
945 // no projection is done if axis == 0
947 AliCFContainer* tmp = 0;
951 tmp = (AliCFContainer*) fTrackHist[0]->Clone();
952 for (Int_t i = 1; i < fkRegions; i++)
954 tmp->Add(fTrackHist[i]);
956 else if (region == kMin && fCombineMinMax)
958 tmp = (AliCFContainer*) fTrackHist[kMin]->Clone();
959 tmp->Add(fTrackHist[kMax]);
962 tmp = fTrackHist[region];
964 ResetBinLimits(tmp->GetGrid(step1));
965 ResetBinLimits(fEventHist->GetGrid(step1));
966 SetBinLimits(tmp->GetGrid(step1));
968 ResetBinLimits(tmp->GetGrid(step2));
969 ResetBinLimits(fEventHist->GetGrid(step2));
970 SetBinLimits(tmp->GetGrid(step2));
972 TH1D* events1 = fEventHist->Project(0, step1);
973 TH3D* hist1 = tmp->Project(0, tmp->GetNVar()-1, 2, step1);
974 WeightHistogram(hist1, events1);
976 TH1D* events2 = fEventHist->Project(0, step2);
977 TH3D* hist2 = tmp->Project(0, tmp->GetNVar()-1, 2, step2);
978 WeightHistogram(hist2, events2);
980 TH1* generated = hist1;
981 TH1* measured = hist2;
985 if (leadPtMax > leadPtMin)
987 hist1->GetZaxis()->SetRangeUser(leadPtMin, leadPtMax);
988 hist2->GetZaxis()->SetRangeUser(leadPtMin, leadPtMax);
991 if (fEtaMax > fEtaMin && !TString(axis).Contains("x"))
993 hist1->GetXaxis()->SetRangeUser(fEtaMin, fEtaMax);
994 hist2->GetXaxis()->SetRangeUser(fEtaMin, fEtaMax);
997 generated = hist1->Project3D(axis);
998 measured = hist2->Project3D(axis);
1000 // delete hists here if projection has been done
1005 measured->Divide(generated);
1011 ResetBinLimits(tmp->GetGrid(step1));
1012 ResetBinLimits(tmp->GetGrid(step2));
1014 if ((region == -1) || (region == kMin && fCombineMinMax))
1020 //____________________________________________________________________
1021 TH2D* AliUEHist::GetTrackingEfficiency()
1023 // extracts the tracking efficiency by calculating the efficiency from step kCFStepAnaTopology to kCFStepTrackedOnlyPrim
1024 // integrates over the regions and all other variables than pT and eta to increase the statistics
1026 // returned histogram has to be deleted by the user
1028 return dynamic_cast<TH2D*> (GetTrackEfficiency(kCFStepAnaTopology, kCFStepTrackedOnlyPrim, 0, 1));
1031 //____________________________________________________________________
1032 TH1D* AliUEHist::GetTrackingEfficiency(Int_t axis)
1034 // extracts the tracking efficiency by calculating the efficiency from step kCFStepAnaTopology to kCFStepTrackedOnlyPrim
1035 // integrates over the regions and all other variables than pT (axis == 0) and eta (axis == 1) to increase the statistics
1037 return dynamic_cast<TH1D*> (GetTrackEfficiency(kCFStepAnaTopology, kCFStepTrackedOnlyPrim, axis));
1040 //____________________________________________________________________
1041 TH2D* AliUEHist::GetTrackingCorrection()
1043 // extracts the tracking correction by calculating the efficiency from step kCFStepAnaTopology to kCFStepTracked
1044 // integrates over the regions and all other variables than pT and eta to increase the statistics
1046 // returned histogram has to be deleted by the user
1048 return dynamic_cast<TH2D*> (GetTrackEfficiency(kCFStepTracked, kCFStepAnaTopology, 0, 1));
1051 //____________________________________________________________________
1052 TH1D* AliUEHist::GetTrackingCorrection(Int_t axis)
1054 // extracts the tracking correction by calculating the efficiency from step kCFStepAnaTopology to kCFStepTracked
1055 // integrates over the regions and all other variables than pT (axis == 0) and eta (axis == 1) to increase the statistics
1057 return dynamic_cast<TH1D*> (GetTrackEfficiency(kCFStepTracked, kCFStepAnaTopology, axis));
1060 //____________________________________________________________________
1061 TH2D* AliUEHist::GetTrackingEfficiencyCorrection()
1063 // extracts the tracking correction by calculating the efficiency from step kCFStepAnaTopology to kCFStepTracked
1064 // integrates over the regions and all other variables than pT and eta to increase the statistics
1066 // returned histogram has to be deleted by the user
1068 return dynamic_cast<TH2D*> (GetTrackEfficiency(kCFStepTrackedOnlyPrim, kCFStepAnaTopology, 0, 1));
1071 //____________________________________________________________________
1072 TH1D* AliUEHist::GetTrackingEfficiencyCorrection(Int_t axis)
1074 // extracts the tracking correction by calculating the efficiency from step kCFStepAnaTopology to kCFStepTracked
1075 // integrates over the regions and all other variables than pT (axis == 0) and eta (axis == 1) to increase the statistics
1077 return dynamic_cast<TH1D*> (GetTrackEfficiency(kCFStepTrackedOnlyPrim, kCFStepAnaTopology, axis));
1080 //____________________________________________________________________
1081 TH2D* AliUEHist::GetTrackingContamination()
1083 // extracts the tracking contamination by secondaries by calculating the efficiency from step kCFStepTrackedOnlyPrim to kCFStepTracked
1084 // integrates over the regions and all other variables than pT and eta to increase the statistics
1086 // returned histogram has to be deleted by the user
1088 return dynamic_cast<TH2D*> (GetTrackEfficiency(kCFStepTracked, kCFStepTrackedOnlyPrim, 0, 1));
1091 //____________________________________________________________________
1092 TH1D* AliUEHist::GetTrackingContamination(Int_t axis)
1094 // extracts the tracking contamination by secondaries by calculating the efficiency from step kCFStepTrackedOnlyPrim to kCFStepTracked
1095 // integrates over the regions and all other variables than pT (axis == 0) and eta (axis == 1) to increase the statistics
1097 return dynamic_cast<TH1D*> (GetTrackEfficiency(kCFStepTracked, kCFStepTrackedOnlyPrim, axis));
1100 //____________________________________________________________________
1101 const char* AliUEHist::GetRegionTitle(Region region)
1103 // returns the name of the given region
1112 return (fCombineMinMax) ? "Transverse" : "Min";
1120 //____________________________________________________________________
1121 const char* AliUEHist::GetStepTitle(CFStep step)
1123 // returns the name of the given step
1128 return "All events";
1129 case kCFStepTriggered:
1132 return "Primary Vertex";
1133 case kCFStepAnaTopology:
1134 return "Required analysis topology";
1135 case kCFStepTrackedOnlyPrim:
1136 return "Tracked (matched MC, only primaries)";
1137 case kCFStepTracked:
1138 return "Tracked (matched MC, all)";
1139 case kCFStepReconstructed:
1140 return "Reconstructed";
1141 case kCFStepRealLeading:
1142 return "Correct leading particle identified";
1143 case kCFStepBiasStudy:
1144 return "Bias study applying tracking efficiency";
1145 case kCFStepBiasStudy2:
1146 return "Bias study applying tracking efficiency in two steps";
1152 //____________________________________________________________________
1153 void AliUEHist::CopyReconstructedData(AliUEHist* from)
1155 // copies those histograms extracted from ESD to this object
1157 // TODO at present only the pointers are copied
1159 for (Int_t region=0; region<4; region++)
1161 if (!fTrackHist[region])
1164 fTrackHist[region]->SetGrid(AliUEHist::kCFStepReconstructed, from->fTrackHist[region]->GetGrid(AliUEHist::kCFStepReconstructed));
1165 fTrackHist[region]->SetGrid(AliUEHist::kCFStepBiasStudy, from->fTrackHist[region]->GetGrid(AliUEHist::kCFStepBiasStudy));
1168 fEventHist->SetGrid(AliUEHist::kCFStepReconstructed, from->fEventHist->GetGrid(AliUEHist::kCFStepReconstructed));
1169 fEventHist->SetGrid(AliUEHist::kCFStepBiasStudy, from->fEventHist->GetGrid(AliUEHist::kCFStepBiasStudy));