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(const Char_t* name, const Char_t* title,
36 Int_t nBinX, Float_t Xmin, Float_t Xmax,
37 Int_t nBinY, Float_t Ymin, Float_t Ymax)
38 : AliCorrectionMatrix(name, title)
44 fhMeas = new TH2F(Form("meas_%s",name), Form("meas_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
45 fhGene = new TH2F(Form("gene_%s",name), Form("gene_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
46 fhCorr = new TH2F(Form("corr_%s",name), Form("corr_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
53 //____________________________________________________________________
54 AliCorrectionMatrix2D::AliCorrectionMatrix2D(const Char_t* name, const Char_t* title,
55 Int_t nBinX, Float_t *X, Int_t nBinY, Float_t *Y)
56 : AliCorrectionMatrix(name, title)
62 fhMeas = new TH2F(Form("meas_%s",name), Form("meas_%s",title), nBinX, X, nBinY, Y);
63 fhGene = new TH2F(Form("gene_%s",name), Form("gene_%s",title), nBinX, X, nBinY, Y);
64 fhCorr = new TH2F(Form("corr_%s",name), Form("corr_%s",title), nBinX, X, nBinY, Y);
71 //____________________________________________________________________
72 AliCorrectionMatrix2D::~AliCorrectionMatrix2D()
78 // histograms already deleted in base class
81 TH2F* AliCorrectionMatrix2D::GetGeneratedHistogram() const
83 // return generated histogram casted to correct type
84 return dynamic_cast<TH2F*> (fhGene);
87 TH2F* AliCorrectionMatrix2D::GetMeasuredHistogram() const
89 // return measured histogram casted to correct type
90 return dynamic_cast<TH2F*> (fhMeas);
93 //____________________________________________________________________
94 TH1F* AliCorrectionMatrix2D::Get1DCorrection(Char_t* opt)
97 // integrate the correction over one variable
103 if (strcmp(opt,"x")==0) {
104 meas1D = GetMeasuredHistogram()->ProjectionX();
105 gene1D = GetGeneratedHistogram()->ProjectionX();
107 if (strcmp(opt,"y")==0) {
108 meas1D = GetMeasuredHistogram()->ProjectionY();
109 gene1D = GetGeneratedHistogram()->ProjectionY();
113 gene1D->SetName(Form("corr_1D_%s",fName.Data()));
114 gene1D->SetTitle(Form("corr_1D_%s",fName.Data()));
116 gene1D->Divide(gene1D, meas1D, 1, 1, "B");
118 return (TH1F*)gene1D;
121 //____________________________________________________________________
122 void AliCorrectionMatrix2D::FillMeas(Float_t ax, Float_t ay)
124 // add value to measured histogram
125 GetMeasuredHistogram()->Fill(ax, ay);
128 //____________________________________________________________________
129 void AliCorrectionMatrix2D::FillGene(Float_t ax, Float_t ay)
131 // add value to generated histogram
132 GetGeneratedHistogram()->Fill(ax, ay);
135 //____________________________________________________________________
136 Float_t AliCorrectionMatrix2D::GetCorrection(Float_t ax, Float_t ay) const
138 // returns a value of the correction map
139 return fhCorr->GetBinContent(fhCorr->FindBin(ax,ay));
142 //____________________________________________________________________
143 void AliCorrectionMatrix2D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge)
145 // remove edges of correction histogram by removing
146 // - bins with content less than cut
147 // - bins next to bins with zero bin content
149 Int_t nBinsX = fhCorr->GetNbinsX();
150 Int_t nBinsY = fhCorr->GetNbinsY();
152 // set bin content to zero for bins with content smaller cut
153 for (Int_t bx=0; bx<=nBinsX; bx++) {
154 for (Int_t by=0; by<=nBinsY; by++) {
155 if (fhCorr->GetBinContent(bx,by)>cut) {
156 fhCorr->SetBinContent(bx,by,0);
157 fhCorr->SetBinError(bx,by,0);
162 // set bin content to zero for bins next to bins with zero
163 TH2F* tmp = (TH2F*)fhCorr->Clone("tmp");
166 Bool_t done = kFALSE;
167 Int_t nBinsXCount = 0;
168 Int_t nBinsYCount = 0;
170 if (nBinsXCount<nBinsXedge)
171 for (Int_t bx=0; bx<=nBinsX; bx++) {
172 for (Int_t by=0; by<=nBinsY; by++) {
173 if ((fhCorr->GetBinContent(bx+1,by)==0)||
174 (fhCorr->GetBinContent(bx-1,by)==0))
175 tmp->SetBinContent(bx,by,1);
179 if (nBinsYCount<nBinsYedge)
180 for (Int_t bx=0; bx<=nBinsX; bx++) {
181 for (Int_t by=0; by<=nBinsY; by++) {
182 if ((fhCorr->GetBinContent(bx,by+1)==0)||
183 (fhCorr->GetBinContent(bx,by-1)==0))
184 tmp->SetBinContent(bx,by,1);
187 for (Int_t bx=0; bx<=nBinsX; bx++) {
188 for (Int_t by=0; by<=nBinsY; by++) {
189 if (tmp->GetBinContent(bx,by)==1) {
190 fhCorr->SetBinContent(bx,by,0);
191 fhCorr->SetBinError(bx,by,0);
197 if ((nBinsXCount>=nBinsXedge)&&(nBinsYCount>=nBinsYedge)) done=kTRUE;