2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
17 // Class for spectrum correction
18 // Subtraction of hadronic background, Unfolding of the data and
19 // Renormalization done here
20 // The following containers have to be set:
21 // - Correction framework container for real data
22 // - Correction framework container for MC (Efficiency Map)
23 // - Correction framework container for background coming from data
24 // - Correction framework container for background coming from MC
27 // Raphaelle Bailhache <R.Bailhache@gsi.de>
28 // Markus Fasel <M.Fasel@gsi.de>
34 #include <TObjArray.h>
41 #include <TGraphErrors.h>
48 #include "AliCFContainer.h"
49 #include "AliCFDataGrid.h"
50 #include "AliCFEffGrid.h"
51 #include "AliCFGridSparse.h"
52 #include "AliCFUnfolding.h"
55 #include "AliHFECorrectSpectrumBase.h"
56 #include "AliHFEcuts.h"
57 #include "AliHFEcontainer.h"
58 #include "AliHFEtools.h"
60 ClassImp(AliHFECorrectSpectrumBase)
62 //____________________________________________________________
63 AliHFECorrectSpectrumBase::AliHFECorrectSpectrumBase(const char *name):
65 fCFContainers(new TObjArray(kDataContainerV0+1)),
67 fEfficiencyFunction(NULL),
69 fSetSmoothing(kFALSE),
75 fStepBeforeCutsV0(-1),
77 fStepGuessedUnfolding(-1),
78 fNumberOfIterations(10),
79 fChargeChoosen(kAllCharge),
80 fTestCentralityLow(-1),
81 fTestCentralityHigh(-1)
84 // Default constructor
87 memset(fEtaRange, 0, sizeof(Double_t) * 2);
88 memset(fEtaRangeNorm, 0, sizeof(Double_t) * 2);
91 //____________________________________________________________
92 AliHFECorrectSpectrumBase::AliHFECorrectSpectrumBase(const AliHFECorrectSpectrumBase &ref):
96 fEfficiencyFunction(NULL),
97 fEtaSelected(ref.fEtaSelected),
98 fSetSmoothing(ref.fSetSmoothing),
99 fNbDimensions(ref.fNbDimensions),
100 fNEvents(ref.fNEvents),
101 fStepMC(ref.fStepMC),
102 fStepTrue(ref.fStepTrue),
103 fStepData(ref.fStepData),
104 fStepBeforeCutsV0(ref.fStepBeforeCutsV0),
105 fStepAfterCutsV0(ref.fStepAfterCutsV0),
106 fStepGuessedUnfolding(ref.fStepGuessedUnfolding),
107 fNumberOfIterations(ref.fNumberOfIterations),
108 fChargeChoosen(ref.fChargeChoosen),
109 fTestCentralityLow(ref.fTestCentralityLow),
110 fTestCentralityHigh(ref.fTestCentralityHigh)
118 //____________________________________________________________
119 AliHFECorrectSpectrumBase &AliHFECorrectSpectrumBase::operator=(const AliHFECorrectSpectrumBase &ref){
121 // Assignment operator
127 //____________________________________________________________
128 void AliHFECorrectSpectrumBase::Copy(TObject &o) const {
130 // Copy into object o
132 AliHFECorrectSpectrumBase &target = dynamic_cast<AliHFECorrectSpectrumBase &>(o);
133 target.fCFContainers = fCFContainers;
134 target.fCorrelation = fCorrelation;
135 target.fEfficiencyFunction = fEfficiencyFunction;
136 target.fEtaSelected = fEtaSelected;
137 target.fSetSmoothing = fSetSmoothing;
138 target.fNbDimensions = fNbDimensions;
139 target.fNEvents = fNEvents;
140 target.fStepMC = fStepMC;
141 target.fStepTrue = fStepTrue;
142 target.fStepData = fStepData;
143 target.fStepBeforeCutsV0 = fStepBeforeCutsV0;
144 target.fStepAfterCutsV0 = fStepAfterCutsV0;
145 target.fStepGuessedUnfolding = fStepGuessedUnfolding;
146 target.fNumberOfIterations = fNumberOfIterations;
147 target.fChargeChoosen = fChargeChoosen;
148 target.fTestCentralityLow = fTestCentralityLow;
149 target.fTestCentralityHigh = fTestCentralityHigh;
150 target.fEtaRange[0] = fEtaRange[0];
151 target.fEtaRange[1] = fEtaRange[1];
152 target.fEtaRangeNorm[0] = fEtaRangeNorm[0];
153 target.fEtaRangeNorm[1] = fEtaRangeNorm[1];
157 //____________________________________________________________
158 AliHFECorrectSpectrumBase::~AliHFECorrectSpectrumBase(){
162 if(fCFContainers) delete fCFContainers;
165 //__________________________________________________________________________________
166 TGraphErrors *AliHFECorrectSpectrumBase::Normalize(THnSparse * const spectrum) const {
168 // Normalize the spectrum to 1/(2*Pi*p_{T})*dN/dp_{T} (GeV/c)^{-2}
169 // Give the final pt spectrum to be compared
174 TH1D* projection = spectrum->Projection(0);
175 CorrectFromTheWidth(projection);
176 TGraphErrors *graphError = NormalizeTH1(projection);
185 //__________________________________________________________________________________
186 TGraphErrors *AliHFECorrectSpectrumBase::Normalize(AliCFDataGrid * const spectrum) const {
188 // Normalize the spectrum to 1/(2*Pi*p_{T})*dN/dp_{T} (GeV/c)^{-2}
189 // Give the final pt spectrum to be compared
193 TH1D* projection = (TH1D *) spectrum->Project(0);
194 CorrectFromTheWidth(projection);
195 TGraphErrors *graphError = NormalizeTH1(projection);
205 //__________________________________________________________________________________
206 TGraphErrors *AliHFECorrectSpectrumBase::NormalizeTH1(TH1 *input) const {
208 // Normalize the spectrum to 1/(2*Pi*p_{T})*dN/dp_{T} (GeV/c)^{-2}
209 // Give the final pt spectrum to be compared
211 Double_t chargecoefficient = 0.5;
212 if(fChargeChoosen != 0) chargecoefficient = 1.0;
214 Double_t etarange = fEtaSelected ? fEtaRangeNorm[1] - fEtaRangeNorm[0] : 1.6;
215 printf("Normalizing Eta Range %f\n", etarange);
218 TGraphErrors *spectrumNormalized = new TGraphErrors(input->GetNbinsX());
219 Double_t p = 0, dp = 0; Int_t point = 1;
220 Double_t n = 0, dN = 0;
221 Double_t nCorr = 0, dNcorr = 0;
222 Double_t errdN = 0, errdp = 0;
223 for(Int_t ibin = input->GetXaxis()->GetFirst(); ibin <= input->GetXaxis()->GetLast(); ibin++){
224 point = ibin - input->GetXaxis()->GetFirst();
225 p = input->GetXaxis()->GetBinCenter(ibin);
226 dp = input->GetXaxis()->GetBinWidth(ibin)/2.;
227 n = input->GetBinContent(ibin);
228 dN = input->GetBinError(ibin);
230 nCorr = chargecoefficient * 1./etarange * 1./(Double_t)(fNEvents) * 1./(2. * TMath::Pi() * p) * n;
231 errdN = 1./(2. * TMath::Pi() * p);
232 errdp = 1./(2. * TMath::Pi() * p*p) * n;
233 dNcorr = chargecoefficient * 1./etarange * 1./(Double_t)(fNEvents) * TMath::Sqrt(errdN * errdN * dN *dN + errdp *errdp * dp *dp);
235 spectrumNormalized->SetPoint(point, p, nCorr);
236 spectrumNormalized->SetPointError(point, dp, dNcorr);
238 spectrumNormalized->GetXaxis()->SetTitle("p_{T} [GeV/c]");
239 spectrumNormalized->GetYaxis()->SetTitle("#frac{1}{2 #pi p_{T}} #frac{dN}{dp_{T}} / [GeV/c]^{-2}");
240 spectrumNormalized->SetMarkerStyle(22);
241 spectrumNormalized->SetMarkerColor(kBlue);
242 spectrumNormalized->SetLineColor(kBlue);
244 return spectrumNormalized;
252 //____________________________________________________________
253 void AliHFECorrectSpectrumBase::SetContainer(AliCFContainer *cont, AliHFECorrectSpectrumBase::CFContainer_t type){
255 // Set the container for a given step to the
257 if(!fCFContainers) fCFContainers = new TObjArray(kDataContainerV0+1);
258 fCFContainers->AddAt(cont, type);
261 //____________________________________________________________
262 AliCFContainer *AliHFECorrectSpectrumBase::GetContainer(AliHFECorrectSpectrumBase::CFContainer_t type){
264 // Get Correction Framework Container for given type
266 if(!fCFContainers) return NULL;
267 return dynamic_cast<AliCFContainer *>(fCFContainers->At(type));
269 //____________________________________________________________
270 AliCFContainer *AliHFECorrectSpectrumBase::GetSlicedContainer(AliCFContainer *container, Int_t nDim, Int_t *dimensions,Int_t source,Chargetype_t charge, Int_t centralitylow, Int_t centralityhigh) {
272 // Slice bin for a given source of electron
273 // nDim is the number of dimension the corrections are done
274 // dimensions are the definition of the dimensions
275 // source is if we want to keep only one MC source (-1 means we don't cut on the MC source)
276 // positivenegative if we want to keep positive (1) or negative (0) or both (-1)
277 // centrality (-1 means we do not cut on centrality)
280 Double_t *varMin = new Double_t[container->GetNVar()],
281 *varMax = new Double_t[container->GetNVar()];
284 for(Int_t ivar = 0; ivar < container->GetNVar(); ivar++){
286 binLimits = new Double_t[container->GetNBins(ivar)+1];
287 container->GetBinLimits(ivar,binLimits);
288 varMin[ivar] = binLimits[0];
289 varMax[ivar] = binLimits[container->GetNBins(ivar)];
292 if((source>= 0) && (source<container->GetNBins(ivar))) {
293 varMin[ivar] = binLimits[source];
294 varMax[ivar] = binLimits[source];
299 if(charge != kAllCharge) varMin[ivar] = varMax[ivar] = charge;
303 for(Int_t ic = 1; ic <= container->GetAxis(1,0)->GetLast(); ic++)
304 AliDebug(1, Form("eta bin %d, min %f, max %f\n", ic, container->GetAxis(1,0)->GetBinLowEdge(ic), container->GetAxis(1,0)->GetBinUpEdge(ic)));
306 varMin[ivar] = fEtaRange[0];
307 varMax[ivar] = fEtaRange[1];
311 fEtaRangeNorm[0] = container->GetAxis(1,0)->GetBinLowEdge(container->GetAxis(1,0)->FindBin(fEtaRange[0]));
312 fEtaRangeNorm[1] = container->GetAxis(1,0)->GetBinUpEdge(container->GetAxis(1,0)->FindBin(fEtaRange[1]));
313 AliInfo(Form("Normalization done in eta range [%f,%f]\n", fEtaRangeNorm[0], fEtaRangeNorm[0]));
317 if((centralitylow>= 0) && (centralitylow<container->GetNBins(ivar)) && (centralityhigh>= 0) && (centralityhigh<container->GetNBins(ivar))) {
318 varMin[ivar] = binLimits[centralitylow];
319 varMax[ivar] = binLimits[centralityhigh];
321 TAxis *axistest = container->GetAxis(5,0);
322 AliDebug(1, Form("Number of bin in centrality direction %d\n",axistest->GetNbins()));
323 AliDebug(1, Form("Project from %f to %f\n",binLimits[centralitylow],binLimits[centralityhigh]));
324 Double_t lowcentrality = axistest->GetBinLowEdge(axistest->FindBin(binLimits[centralitylow]));
325 Double_t highcentrality = axistest->GetBinUpEdge(axistest->FindBin(binLimits[centralityhigh]));
326 AliDebug(1, Form("Low centrality %f and high centrality %f\n",lowcentrality,highcentrality));
335 AliCFContainer *k = container->MakeSlice(nDim, dimensions, varMin, varMax);
336 delete[] varMin; delete[] varMax;
342 //_________________________________________________________________________
343 THnSparseF *AliHFECorrectSpectrumBase::GetSlicedCorrelation(THnSparseF *correlationmatrix, Int_t nDim, Int_t *dimensions,Chargetype_t charge,Int_t centralitylow, Int_t centralityhigh) const {
348 Int_t ndimensions = correlationmatrix->GetNdimensions();
349 //printf("Number of dimension %d correlation map\n",ndimensions);
350 if(ndimensions < (2*nDim)) {
351 AliError("Problem in the dimensions");
355 // Cut in centrality is centrality > -1
356 if((5+((Int_t)(ndimensions/2.))) < ndimensions) {
357 if((centralitylow >=0) && (centralityhigh >=0)) {
359 TAxis *axiscentrality0 = correlationmatrix->GetAxis(5);
360 TAxis *axiscentrality1 = correlationmatrix->GetAxis(5+((Int_t)(ndimensions/2.)));
362 Int_t bins0 = axiscentrality0->GetNbins();
363 Int_t bins1 = axiscentrality1->GetNbins();
365 AliDebug(1, Form("Number of centrality bins: %d and %d\n",bins0,bins1));
367 AliError("Problem in the dimensions");
371 if((centralitylow>= 0) && (centralitylow<bins0) && (centralityhigh>= 0) && (centralityhigh<bins0)) {
372 axiscentrality0->SetRangeUser(centralitylow,centralityhigh);
373 axiscentrality1->SetRangeUser(centralitylow,centralityhigh);
375 Double_t lowcentrality0 = axiscentrality0->GetBinLowEdge(axiscentrality0->FindBin(centralitylow));
376 Double_t highcentrality0 = axiscentrality0->GetBinUpEdge(axiscentrality0->FindBin(centralityhigh));
377 Double_t lowcentrality1 = axiscentrality1->GetBinLowEdge(axiscentrality1->FindBin(centralitylow));
378 Double_t highcentrality1 = axiscentrality1->GetBinUpEdge(axiscentrality1->FindBin(centralityhigh));
379 AliDebug(1,Form("0 Low centrality %f and high centrality %f\n",lowcentrality0,highcentrality0));
380 AliDebug(1,Form("1 Low centrality %f and high centrality %f\n",lowcentrality1,highcentrality1));
388 if((1+((Int_t)(ndimensions/2.))) < ndimensions) {
390 TAxis *axiseta0 = correlationmatrix->GetAxis(1);
391 TAxis *axiseta1 = correlationmatrix->GetAxis(1+((Int_t)(ndimensions/2.)));
393 Int_t bins0 = axiseta0->GetNbins();
394 Int_t bins1 = axiseta1->GetNbins();
396 AliDebug(1, Form("Number of eta bins: %d and %d\n",bins0,bins1));
398 AliError("Problem in the dimensions");
402 axiseta0->SetRangeUser(fEtaRange[0],fEtaRange[1]);
403 axiseta1->SetRangeUser(fEtaRange[0],fEtaRange[1]);
405 Double_t loweta0 = axiseta0->GetBinLowEdge(axiseta0->FindBin(fEtaRange[0]));
406 Double_t higheta0 = axiseta0->GetBinUpEdge(axiseta0->FindBin(fEtaRange[1]));
407 Double_t loweta1 = axiseta1->GetBinLowEdge(axiseta1->FindBin(fEtaRange[0]));
408 Double_t higheta1 = axiseta1->GetBinUpEdge(axiseta1->FindBin(fEtaRange[1]));
409 AliInfo(Form("0 Low eta %f and high eta %f\n",loweta0,higheta0));
410 AliInfo(Form("1 Low eta %f and high eta %f\n",loweta1,higheta1));
416 if(charge != kAllCharge) {
417 if((3+((Int_t)(ndimensions/2.))) < ndimensions) {
419 TAxis *axischarge0 = correlationmatrix->GetAxis(3);
420 TAxis *axischarge1 = correlationmatrix->GetAxis(3+((Int_t)(ndimensions/2.)));
422 Int_t bins0 = axischarge0->GetNbins();
423 Int_t bins1 = axischarge1->GetNbins();
425 AliDebug(1, Form("Number of charge bins: %d and %d\n",bins0,bins1));
427 AliError("Problem in the dimensions");
431 axischarge0->SetRangeUser(charge,charge);
432 axischarge1->SetRangeUser(charge,charge);
434 Double_t lowcharge0 = axischarge0->GetBinLowEdge(axischarge0->FindBin(charge));
435 Double_t highcharge0 = axischarge0->GetBinUpEdge(axischarge0->FindBin(charge));
436 Double_t lowcharge1 = axischarge1->GetBinLowEdge(axischarge1->FindBin(charge));
437 Double_t highcharge1 = axischarge1->GetBinUpEdge(axischarge1->FindBin(charge));
438 AliInfo(Form("0 Low charge %f and high charge %f\n",lowcharge0,highcharge0));
439 AliInfo(Form("1 Low charge %f and high charge %f\n",lowcharge1,highcharge1));
445 Int_t ndimensionsContainer = (Int_t) ndimensions/2;
447 Int_t *dim = new Int_t[nDim*2];
448 for(Int_t iter=0; iter < nDim; iter++){
449 dim[iter] = dimensions[iter];
450 dim[iter+nDim] = ndimensionsContainer + dimensions[iter];
453 THnSparseF *k = (THnSparseF *) correlationmatrix->Projection(nDim*2,dim);
459 //___________________________________________________________________________
460 void AliHFECorrectSpectrumBase::CorrectFromTheWidth(TH1D *h1) const {
462 // Correct from the width of the bins --> dN/dp_{T} (GeV/c)^{-1}
465 TAxis *axis = h1->GetXaxis();
466 Int_t nbinX = h1->GetNbinsX();
468 for(Int_t i = 1; i <= nbinX; i++) {
470 Double_t width = axis->GetBinWidth(i);
471 Double_t content = h1->GetBinContent(i);
472 Double_t error = h1->GetBinError(i);
473 h1->SetBinContent(i,content/width);
474 h1->SetBinError(i,error/width);
479 //___________________________________________________________________________
480 void AliHFECorrectSpectrumBase::CorrectStatErr(AliCFDataGrid *backgroundGrid) const {
482 // Correct statistical error
485 TH1D *h1 = (TH1D*)backgroundGrid->Project(0);
486 Int_t nbinX = h1->GetNbinsX();
488 for(Long_t i = 1; i <= nbinX; i++) {
490 Float_t content = h1->GetBinContent(i);
492 Float_t error = TMath::Sqrt(content);
493 backgroundGrid->SetElementError(bins, error);
497 //_________________________________________________________________________
498 TObject* AliHFECorrectSpectrumBase::GetSpectrum(const AliCFContainer * const c, Int_t step) {
499 AliCFDataGrid* data = new AliCFDataGrid("data","",*c, step);
502 //_________________________________________________________________________
503 TObject* AliHFECorrectSpectrumBase::GetEfficiency(const AliCFContainer * const c, Int_t step, Int_t step0){
505 // Create efficiency grid and calculate efficiency
511 AliCFEffGrid* eff = new AliCFEffGrid((const char*)name,"",*c);
512 eff->CalculateEfficiency(step,step0);