3 // ------------------------------------------------------
5 // Class to handle 2d-corrections.
7 // ------------------------------------------------------
14 #include "AliCorrectionMatrix2D.h"
16 //____________________________________________________________________
17 ClassImp(AliCorrectionMatrix2D)
19 //____________________________________________________________________
20 AliCorrectionMatrix2D::AliCorrectionMatrix2D() :
23 // default constructor
26 //____________________________________________________________________
27 AliCorrectionMatrix2D::AliCorrectionMatrix2D(const AliCorrectionMatrix2D& c)
28 : AliCorrectionMatrix(c)
31 ((AliCorrectionMatrix2D &)c).Copy(*this);
34 //____________________________________________________________________
35 AliCorrectionMatrix2D &AliCorrectionMatrix2D::operator=(const AliCorrectionMatrix2D &c)
40 ((AliCorrectionMatrix2D &) c).Copy(*this);
45 //____________________________________________________________________
46 AliCorrectionMatrix2D::AliCorrectionMatrix2D(const Char_t* name, const Char_t* title,
47 Int_t nBinX, Float_t Xmin, Float_t Xmax,
48 Int_t nBinY, Float_t Ymin, Float_t Ymax)
49 : AliCorrectionMatrix(name, title)
55 fhMeas = new TH2F(Form("meas_%s",name), Form("meas_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
56 fhGene = new TH2F(Form("gene_%s",name), Form("gene_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
57 fhCorr = new TH2F(Form("corr_%s",name), Form("corr_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
64 //____________________________________________________________________
65 AliCorrectionMatrix2D::AliCorrectionMatrix2D(const Char_t* name, const Char_t* title,
66 Int_t nBinX, Float_t *X, Int_t nBinY, Float_t *Y)
67 : AliCorrectionMatrix(name, title)
73 fhMeas = new TH2F(Form("meas_%s",name), Form("meas_%s",title), nBinX, X, nBinY, Y);
74 fhGene = new TH2F(Form("gene_%s",name), Form("gene_%s",title), nBinX, X, nBinY, Y);
75 fhCorr = new TH2F(Form("corr_%s",name), Form("corr_%s",title), nBinX, X, nBinY, Y);
82 //____________________________________________________________________
83 AliCorrectionMatrix2D::~AliCorrectionMatrix2D()
89 // histograms already deleted in base class
92 TH2F* AliCorrectionMatrix2D::GetGeneratedHistogram() const
94 // return generated histogram casted to correct type
95 return dynamic_cast<TH2F*> (fhGene);
98 TH2F* AliCorrectionMatrix2D::GetMeasuredHistogram() const
100 // return measured histogram casted to correct type
101 return dynamic_cast<TH2F*> (fhMeas);
104 //____________________________________________________________________
105 TH1F* AliCorrectionMatrix2D::Get1DCorrection(Char_t* opt, Float_t min, Float_t max)
108 // integrate the correction over one variable
114 if (strcmp(opt,"x")==0) {
115 Int_t binMin = GetMeasuredHistogram()->GetYaxis()->FindBin(min);
116 Int_t binMax = GetMeasuredHistogram()->GetYaxis()->FindBin(max);
118 if (min==0 && max==0) {
119 meas1D = GetMeasuredHistogram()->ProjectionX();
120 gene1D = GetGeneratedHistogram()->ProjectionX();
123 AliDebug(AliLog::kDebug+1, Form("Getting 1D map. Including y-bins %d to %d \n", binMin, binMax));
125 meas1D = GetMeasuredHistogram()->ProjectionX("pm",binMin,binMax);
126 gene1D = GetGeneratedHistogram()->ProjectionX("pg",binMin,binMax);
129 if (strcmp(opt,"y")==0) {
130 Int_t binMin = GetMeasuredHistogram()->GetXaxis()->FindBin(min);
131 Int_t binMax = GetMeasuredHistogram()->GetXaxis()->FindBin(max);
133 if (min==0 && max==0) {
134 meas1D = GetMeasuredHistogram()->ProjectionY();
135 gene1D = GetGeneratedHistogram()->ProjectionY();
138 AliDebug(AliLog::kDebug+1, Form("Getting 1D map. Including x-bins %d to %d \n", binMin, binMax));
140 meas1D = GetMeasuredHistogram()->ProjectionY("pm", binMin, binMax);
141 gene1D = GetGeneratedHistogram()->ProjectionY("pg", binMin, binMax);
146 gene1D->SetName(Form("corr_1D_%s",fName.Data()));
147 gene1D->SetTitle(Form("corr_1D_%s",fName.Data()));
149 gene1D->Divide(gene1D, meas1D, 1, 1, "B");
151 return (TH1F*)gene1D;
154 //____________________________________________________________________
155 void AliCorrectionMatrix2D::FillMeas(Float_t ax, Float_t ay)
157 // add value to measured histogram
158 GetMeasuredHistogram()->Fill(ax, ay);
161 //____________________________________________________________________
162 void AliCorrectionMatrix2D::FillGene(Float_t ax, Float_t ay)
164 // add value to generated histogram
165 GetGeneratedHistogram()->Fill(ax, ay);
168 //____________________________________________________________________
169 Float_t AliCorrectionMatrix2D::GetCorrection(Float_t ax, Float_t ay) const
171 // returns a value of the correction map
172 return fhCorr->GetBinContent(fhCorr->FindBin(ax,ay));
175 //____________________________________________________________________
176 void AliCorrectionMatrix2D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge)
178 // remove edges of correction histogram by removing
179 // - bins with content less than cut
180 // - bins next to bins with zero bin content
182 Int_t nBinsX = fhCorr->GetNbinsX();
183 Int_t nBinsY = fhCorr->GetNbinsY();
185 // set bin content to zero for bins with content smaller cut
186 for (Int_t bx=0; bx<=nBinsX; bx++) {
187 for (Int_t by=0; by<=nBinsY; by++) {
188 if (fhCorr->GetBinContent(bx,by)>cut) {
189 fhCorr->SetBinContent(bx,by,0);
190 fhCorr->SetBinError(bx,by,0);
195 // set bin content to zero for bins next to bins with zero
196 TH2F* tmp = (TH2F*)fhCorr->Clone("tmp");
199 Bool_t done = kFALSE;
200 Int_t nBinsXCount = 0;
201 Int_t nBinsYCount = 0;
203 if (nBinsXCount<nBinsXedge)
204 for (Int_t bx=0; bx<=nBinsX; bx++) {
205 for (Int_t by=0; by<=nBinsY; by++) {
206 if ((fhCorr->GetBinContent(bx+1,by)==0)||
207 (fhCorr->GetBinContent(bx-1,by)==0))
208 tmp->SetBinContent(bx,by,1);
212 if (nBinsYCount<nBinsYedge)
213 for (Int_t bx=0; bx<=nBinsX; bx++) {
214 for (Int_t by=0; by<=nBinsY; by++) {
215 if ((fhCorr->GetBinContent(bx,by+1)==0)||
216 (fhCorr->GetBinContent(bx,by-1)==0))
217 tmp->SetBinContent(bx,by,1);
220 for (Int_t bx=0; bx<=nBinsX; bx++) {
221 for (Int_t by=0; by<=nBinsY; by++) {
222 if (tmp->GetBinContent(bx,by)==1) {
223 fhCorr->SetBinContent(bx,by,0);
224 fhCorr->SetBinError(bx,by,0);
230 if ((nBinsXCount>=nBinsXedge)&&(nBinsYCount>=nBinsYedge)) done=kTRUE;