Default changed: SPD chips thickness is 150 microns
[u/mrichter/AliRoot.git] / PWG0 / CorrectionMatrix2D.cxx
CommitLineData
ddec1c19 1#include "CorrectionMatrix2D.h"
2
3//____________________________________________________________________
4ClassImp(CorrectionMatrix2D);
5
6//____________________________________________________________________
b6d3306b 7CorrectionMatrix2D::CorrectionMatrix2D(Char_t* name, Char_t* title,
8 Int_t nBinX, Float_t Xmin, Float_t Xmax,
9 Int_t nBinY, Float_t Ymin, Float_t Ymax)
10 : TNamed(name, title)
ddec1c19 11{
ddec1c19 12
b6d3306b 13 fhMeas = new TH2F(Form("meas_%s",name), Form("meas_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
14 fhGene = new TH2F(Form("gene_%s",name), Form("gene_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
15 fhCorr = new TH2F(Form("corr_%s",name), Form("corr_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
16 fhRatio = new TH2F(Form("ratio_%s",name),Form("ratio_%s",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
ddec1c19 17}
18
b6d3306b 19//____________________________________________________________________
20CorrectionMatrix2D::CorrectionMatrix2D(Char_t* name,Char_t* title,
21 Int_t nBinX, Float_t *X, Int_t nBinY, Float_t *Y)
22 : TNamed(name, title)
ddec1c19 23{
b6d3306b 24 fhMeas = new TH2F(Form("meas_%s",name), Form("meas_%s",title), nBinX, X, nBinY, Y);
25 fhGene = new TH2F(Form("gene_%s",name), Form("gene_%s",title), nBinX, X, nBinY, Y);
26 fhCorr = new TH2F(Form("corr_%s",name), Form("corr_%s",title), nBinX, X, nBinY, Y);
27 fhRatio = new TH2F(Form("ratio_%s",name),Form("ratio_%s",title), nBinX, X, nBinY, Y);
ddec1c19 28}
29
30
b6d3306b 31//____________________________________________________________________
32CorrectionMatrix2D::~CorrectionMatrix2D() {
33 // Destructor
34 //
35 if (fhMeas) delete fhMeas;
36 if (fhGene) delete fhCorr;
37 if (fhRatio) delete fhRatio;
38 if (fhCorr) delete fhCorr;
39}
ddec1c19 40
ddec1c19 41
b6d3306b 42//________________________________________________________________________
43void CorrectionMatrix2D::SetAxisTitles(Char_t* titleX, Char_t* titleY)
44{
45 fhMeas ->SetXTitle(titleX); fhMeas ->SetYTitle(titleY);
46 fhGene ->SetXTitle(titleX); fhGene ->SetYTitle(titleY);
47 fhCorr ->SetXTitle(titleX); fhCorr ->SetYTitle(titleY);
48 fhRatio->SetXTitle(titleX); fhRatio->SetYTitle(titleY);
ddec1c19 49}
50
51
52//____________________________________________________________________
53void CorrectionMatrix2D::Finish() {
54
b6d3306b 55if (!fhMeas || !fhGene) return;
ddec1c19 56
ddec1c19 57
b6d3306b 58 fhRatio->Divide(fhMeas, fhGene, 1,1,"B");
59 fhCorr->Divide(fhGene, fhMeas, 1,1,"B");
ddec1c19 60
b6d3306b 61 Int_t nBinsVtx = fhCorr->GetNbinsX();
62 Int_t nBinsEta = fhCorr->GetNbinsY();
ddec1c19 63
b6d3306b 64 TH2F* tmp = (TH2F*)fhCorr->Clone("tmp");
ddec1c19 65
66 // cut at 0.2
67 for (Int_t bx=0; bx<=nBinsVtx; bx++) {
68 for (Int_t by=0; by<=nBinsEta; by++) {
69 if (tmp->GetBinContent(bx,by)<0.2) {
b6d3306b 70 fhCorr->SetBinContent(bx,by,0);
71 fhCorr->SetBinError(bx,by,0);
ddec1c19 72
73 tmp->SetBinContent(bx,by,0);
74 }
75 else
76 tmp->SetBinContent(bx,by,1);
77 }
78 }
79
80}
81
82//____________________________________________________________________
83void
84CorrectionMatrix2D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge) {
85
86 // remove edges of correction histogram by removing
87 // - bins with content less than cut
88 // - bins next to bins with zero bin content
89
b6d3306b 90 Int_t nBinsX = fhCorr->GetNbinsX();
91 Int_t nBinsY = fhCorr->GetNbinsY();
ddec1c19 92
93 // set bin content to zero for bins with content smaller cut
94 for (Int_t bx=0; bx<=nBinsX; bx++) {
95 for (Int_t by=0; by<=nBinsY; by++) {
b6d3306b 96 if (fhCorr->GetBinContent(bx,by)>cut) {
97 fhCorr->SetBinContent(bx,by,0);
98 fhCorr->SetBinError(bx,by,0);
ddec1c19 99 }
100 }
101 }
102
103 // set bin content to zero for bins next to bins with zero
b6d3306b 104 TH2F* tmp = (TH2F*)fhCorr->Clone("tmp");
ddec1c19 105 tmp->Reset();
106
107 Bool_t done = kFALSE;
108 Int_t nBinsXCount = 0;
109 Int_t nBinsYCount = 0;
110 while (!done) {
111 if (nBinsXCount<nBinsXedge)
112 for (Int_t bx=0; bx<=nBinsX; bx++) {
113 for (Int_t by=0; by<=nBinsY; by++) {
b6d3306b 114 if ((fhCorr->GetBinContent(bx+1,by)==0)||
115 (fhCorr->GetBinContent(bx-1,by)==0))
ddec1c19 116 tmp->SetBinContent(bx,by,1);
117
118 }
119 }
120 if (nBinsYCount<nBinsYedge)
121 for (Int_t bx=0; bx<=nBinsX; bx++) {
122 for (Int_t by=0; by<=nBinsY; by++) {
b6d3306b 123 if ((fhCorr->GetBinContent(bx,by+1)==0)||
124 (fhCorr->GetBinContent(bx,by-1)==0))
ddec1c19 125 tmp->SetBinContent(bx,by,1);
126 }
127 }
128 for (Int_t bx=0; bx<=nBinsX; bx++) {
129 for (Int_t by=0; by<=nBinsY; by++) {
130 if (tmp->GetBinContent(bx,by)==1) {
b6d3306b 131 fhCorr->SetBinContent(bx,by,0);
132 fhCorr->SetBinError(bx,by,0);
ddec1c19 133 }
134 }
135 }
136 nBinsXCount++;
137 nBinsYCount++;
138 if ((nBinsXCount>=nBinsXedge)&&(nBinsYCount>=nBinsYedge)) done=kTRUE;
139 }
140 tmp->Delete();
141
142}
143
144//____________________________________________________________________
145Bool_t CorrectionMatrix2D::LoadHistograms(Char_t* fileName, Char_t* dir) {
146
147 TFile* fin = TFile::Open(fileName);
148
149 if(!fin)
150 {
151 //Info("LoadHistograms",Form(" %s file does not exist",fileName));
152 return kFALSE;
153 }
154
b6d3306b 155 if(fhGene) {delete fhGene; fhGene=0;}
156 if(fhCorr) {delete fhCorr; fhCorr=0;}
157 if(fhRatio) {delete fhRatio; fhRatio=0;}
158 if(fhMeas) {delete fhMeas; fhMeas=0;}
ddec1c19 159
b6d3306b 160 fhMeas = (TH2F*)fin->Get(Form("%s/meas",dir));
161 if(!fhMeas) Info("LoadHistograms","No meas hist available");
162 fhGene = (TH2F*)fin->Get(Form("%s/gene",dir));
163 if(!fhGene) Info("LoadHistograms","No gene hist available");
164 fhRatio = (TH2F*)fin->Get(Form("%s/ratio",dir));
165 if(!fhRatio) Info("LoadHistograms","No ratio hist available");
166 fhCorr = (TH2F*)fin->Get(Form("%s/corr",dir));
167 if(!fhCorr) {Info("LoadHistograms","No corr hist available");
ddec1c19 168 return kFALSE;}
169
170 return kTRUE;
171}
172
173
174//____________________________________________________________________
175void
176CorrectionMatrix2D::SaveHistograms() {
177
178 gDirectory->mkdir(fName.Data());
179 gDirectory->cd(fName.Data());
180
b6d3306b 181 fhMeas ->Write();
182 fhGene ->Write();
ddec1c19 183
b6d3306b 184 if (fhCorr)
185 fhCorr->Write();
ddec1c19 186
b6d3306b 187 if (fhRatio)
188 fhRatio->Write();
ddec1c19 189
190 gDirectory->cd("../");
191}
192
193//____________________________________________________________________
194void CorrectionMatrix2D::DrawHistograms()
195{
196 TCanvas* canvas = new TCanvas("Correction", "Correction", 800, 800);
197 canvas->Divide(2, 2);
198
199 canvas->cd(1);
b6d3306b 200 if (fhMeas)
201 fhMeas->Draw("COLZ");
ddec1c19 202
203 canvas->cd(2);
b6d3306b 204 if (fhGene)
205 fhGene->Draw("COLZ");
ddec1c19 206
207 canvas->cd(3);
b6d3306b 208 if (fhRatio)
209 fhRatio->Draw("COLZ");
ddec1c19 210
211 canvas->cd(4);
b6d3306b 212 if (fhCorr)
213 fhCorr->Draw("COLZ");
ddec1c19 214}
215
216