3 // ------------------------------------------------------
5 // Class to handle 2d-corrections.
7 // ------------------------------------------------------
15 #include "AliCorrectionMatrix2D.h"
17 //____________________________________________________________________
18 ClassImp(AliCorrectionMatrix2D)
20 //____________________________________________________________________
21 AliCorrectionMatrix2D::AliCorrectionMatrix2D() :
24 // default constructor
27 //____________________________________________________________________
28 AliCorrectionMatrix2D::AliCorrectionMatrix2D(const AliCorrectionMatrix2D& c)
29 : AliCorrectionMatrix(c)
32 ((AliCorrectionMatrix2D &)c).Copy(*this);
35 //____________________________________________________________________
36 AliCorrectionMatrix2D &AliCorrectionMatrix2D::operator=(const AliCorrectionMatrix2D &c)
41 ((AliCorrectionMatrix2D &) c).Copy(*this);
46 //____________________________________________________________________
47 AliCorrectionMatrix2D::AliCorrectionMatrix2D(const Char_t* name, const Char_t* title,
48 Int_t nBinX, Float_t Xmin, Float_t Xmax,
49 Int_t nBinY, Float_t Ymin, Float_t Ymax)
50 : AliCorrectionMatrix(name, title)
56 // do not add this hists to the directory
57 Bool_t oldStatus = TH1::AddDirectoryStatus();
58 TH1::AddDirectory(kFALSE);
60 fhMeas = new TH2F("measured", Form("%s measured", GetTitle()), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
61 fhGene = new TH2F("generated", Form("%s generated", GetTitle()), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
62 fhCorr = new TH2F("correction", Form("%s correction", GetTitle()), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
64 TH1::AddDirectory(oldStatus);
71 //____________________________________________________________________
72 AliCorrectionMatrix2D::AliCorrectionMatrix2D(const Char_t* name, const Char_t* title,
73 Int_t nBinX, Float_t *X, Int_t nBinY, Float_t *Y)
74 : AliCorrectionMatrix(name, title)
80 // do not add this hists to the directory
81 Bool_t oldStatus = TH1::AddDirectoryStatus();
82 TH1::AddDirectory(kFALSE);
84 fhMeas = new TH2F("measured", Form("%s measured",title), nBinX, X, nBinY, Y);
85 fhGene = new TH2F("generated", Form("%s generated",title), nBinX, X, nBinY, Y);
86 fhCorr = new TH2F("correction", Form("%s correction",title), nBinX, X, nBinY, Y);
88 TH1::AddDirectory(oldStatus);
95 //____________________________________________________________________
96 AliCorrectionMatrix2D::~AliCorrectionMatrix2D()
102 // histograms already deleted in base class
105 TH2* AliCorrectionMatrix2D::GetGeneratedHistogram() const
107 // return generated histogram casted to correct type
108 return dynamic_cast<TH2*> (fhGene);
111 TH2* AliCorrectionMatrix2D::GetMeasuredHistogram() const
113 // return measured histogram casted to correct type
114 return dynamic_cast<TH2*> (fhMeas);
117 //____________________________________________________________________
118 TH1* AliCorrectionMatrix2D::Get1DCorrectionHistogram(const Char_t* opt, Float_t min, Float_t max, Bool_t binomialErrors)
121 // integrate the correction over one variable
127 if (strcmp(opt,"x")==0) {
128 Int_t binMin = fhMeas->GetYaxis()->FindBin(min);
129 Int_t binMax = fhGene->GetYaxis()->FindBin(max);
132 meas1D = ((TH2F*)fhMeas)->ProjectionX();
133 gene1D = ((TH2F*)fhGene)->ProjectionX();
136 Printf("Getting 1D map. Including y-bins %d to %d", binMin, binMax);
138 meas1D = ((TH2F*)fhMeas)->ProjectionX(Form("%s_x_pm", GetName()),binMin,binMax);
139 gene1D = ((TH2F*)fhGene)->ProjectionX(Form("%s_x_pg", GetName()),binMin,binMax);
142 else if (strcmp(opt,"y")==0) {
143 Int_t binMin = fhMeas->GetXaxis()->FindBin(min);
144 Int_t binMax = fhMeas->GetXaxis()->FindBin(max);
147 meas1D = ((TH2F*)fhMeas)->ProjectionY();
148 gene1D = ((TH2F*)fhGene)->ProjectionY();
151 Printf("Getting 1D map. Including x-bins %d to %d \n", binMin, binMax);
153 meas1D = ((TH2F*)fhMeas)->ProjectionY(Form("%s_y_pm", GetName()), binMin, binMax);
154 gene1D = ((TH2F*)fhGene)->ProjectionY(Form("%s_y_pg", GetName()), binMin, binMax);
158 Printf("ERROR: Invalid option");
164 // set the errors on gene manually, and clear the ones on meas.
166 for (Int_t bin=0; bin <= gene1D->GetNbinsX()+1; bin++)
168 gene1D->SetBinError(bin, TMath::Sqrt(gene1D->GetBinContent(bin)));
169 meas1D->SetBinError(bin, 0);
173 gene1D->SetName(Form("corr_1D_%s",fName.Data()));
174 gene1D->SetTitle(Form("corr_1D_%s",fName.Data()));
176 TH1* divided = (TH1*) gene1D->Clone(Form("corr_1D_%s",fName.Data()));
179 divided->Divide(gene1D, meas1D, 1, 1, (binomialErrors) ? "B" : "");
181 Printf("%p %p", gene1D, meas1D);
183 return (TH1F*)divided;
186 //____________________________________________________________________
187 void AliCorrectionMatrix2D::FillMeas(Float_t ax, Float_t ay)
189 // add value to measured histogram
190 ((TH2F*)fhMeas)->Fill(ax, ay);
193 //____________________________________________________________________
194 void AliCorrectionMatrix2D::FillGene(Float_t ax, Float_t ay)
196 // add value to generated histogram
197 ((TH2F*)fhGene)->Fill(ax, ay);
200 //____________________________________________________________________
201 Float_t AliCorrectionMatrix2D::GetCorrection(Float_t ax, Float_t ay) const
203 // returns a value of the correction map
204 return fhCorr->GetBinContent(fhCorr->FindBin(ax,ay));
207 //____________________________________________________________________
208 void AliCorrectionMatrix2D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge)
210 // remove edges of correction histogram by removing
211 // - bins with content less than cut
212 // - bins next to bins with zero bin content
214 Int_t nBinsX = fhCorr->GetNbinsX();
215 Int_t nBinsY = fhCorr->GetNbinsY();
217 // set bin content to zero for bins with content smaller cut
218 for (Int_t bx=0; bx<=nBinsX; bx++) {
219 for (Int_t by=0; by<=nBinsY; by++) {
220 if (fhCorr->GetBinContent(bx,by)>cut) {
221 fhCorr->SetBinContent(bx,by,0);
222 fhCorr->SetBinError(bx,by,0);
227 // set bin content to zero for bins next to bins with zero
228 TH2F* tmp = (TH2F*)fhCorr->Clone("tmp");
231 Bool_t done = kFALSE;
232 Int_t nBinsXCount = 0;
233 Int_t nBinsYCount = 0;
235 if (nBinsXCount<nBinsXedge)
236 for (Int_t bx=0; bx<=nBinsX; bx++) {
237 for (Int_t by=0; by<=nBinsY; by++) {
238 if ((fhCorr->GetBinContent(bx+1,by)==0)||
239 (fhCorr->GetBinContent(bx-1,by)==0))
240 tmp->SetBinContent(bx,by,1);
244 if (nBinsYCount<nBinsYedge)
245 for (Int_t bx=0; bx<=nBinsX; bx++) {
246 for (Int_t by=0; by<=nBinsY; by++) {
247 if ((fhCorr->GetBinContent(bx,by+1)==0)||
248 (fhCorr->GetBinContent(bx,by-1)==0))
249 tmp->SetBinContent(bx,by,1);
252 for (Int_t bx=0; bx<=nBinsX; bx++) {
253 for (Int_t by=0; by<=nBinsY; by++) {
254 if (tmp->GetBinContent(bx,by)==1) {
255 fhCorr->SetBinContent(bx,by,0);
256 fhCorr->SetBinError(bx,by,0);
262 if ((nBinsXCount>=nBinsXedge)&&(nBinsYCount>=nBinsYedge)) done=kTRUE;
268 //____________________________________________________________________
269 void AliCorrectionMatrix2D::Rebin(Int_t x, Int_t y)
271 // rebins the histograms, recalculates the correction
273 GetGeneratedHistogram()->Rebin2D(x, y);
274 GetMeasuredHistogram()->Rebin2D(x, y);
275 GetCorrectionHistogram()->Rebin2D(x, y);