1 #include "CorrectionMatrix2D.h"
3 //____________________________________________________________________
4 ClassImp(CorrectionMatrix2D);
6 //____________________________________________________________________
7 CorrectionMatrix2D::CorrectionMatrix2D(Char_t* name) {
12 //________________________________________________________________________
13 void CorrectionMatrix2D::SetHist(Char_t* title ,Int_t nBinX, Float_t Xmin, Float_t Xmax,
14 Int_t nBinY, Float_t Ymin, Float_t Ymax)
16 //Char_t* name , Chat_t* title ,
18 hmeas = new TH2F("meas", Form("meas_%s",title), nBinX,Xmin,Xmax,nBinY,Ymin,Ymax);
19 hgene = new TH2F("gene", Form("gene_%s",title), nBinX,Xmin,Xmax,nBinY,Ymin,Ymax);
20 hcorr = new TH2F("corr", Form("corr_%s",title), nBinX,Xmin,Xmax,nBinY,Ymin,Ymax);
21 hratio = new TH2F("ratio", Form("ratio_%s",title), nBinX,Xmin,Xmax,nBinY,Ymin,Ymax);
25 void CorrectionMatrix2D::SetHist(Char_t* title ,Int_t nBinX, Float_t *X,
26 Int_t nBinY, Float_t *Y)
29 hmeas = new TH2F("meas", Form("meas_%s",title), nBinX,X,nBinY,Y);
30 hgene = new TH2F("gene", Form("gene_%s",title), nBinX,X,nBinY,Y);
31 hcorr = new TH2F("corr", Form("corr_%s",title), nBinX,X,nBinY,Y);
32 hratio = new TH2F("ratio", Form("ratio_%s",title),nBinX,X,nBinY,Y);
38 //________________________________________________________________________
39 void CorrectionMatrix2D::SetHistTitle(Char_t* titleX, Char_t* titleY)
42 hmeas ->SetXTitle(titleX); hmeas ->SetYTitle(titleY);
43 hgene ->SetXTitle(titleX); hgene ->SetYTitle(titleY);
44 hcorr ->SetXTitle(titleX); hcorr ->SetYTitle(titleY);
45 hratio->SetXTitle(titleX); hratio->SetYTitle(titleY);
50 //____________________________________________________________________
51 void CorrectionMatrix2D::Finish() {
53 if (!hmeas || !hgene) return;
55 TCanvas *c1 = new TCanvas();
62 hratio->Divide(hmeas, hgene, 1,1,"B");
63 hcorr->Divide(hgene, hmeas, 1,1,"B");
65 Int_t nBinsVtx = hcorr->GetNbinsX();
66 Int_t nBinsEta = hcorr->GetNbinsY();
68 TH2F* tmp = (TH2F*)hcorr->Clone("tmp");
71 for (Int_t bx=0; bx<=nBinsVtx; bx++) {
72 for (Int_t by=0; by<=nBinsEta; by++) {
73 if (tmp->GetBinContent(bx,by)<0.2) {
74 hcorr->SetBinContent(bx,by,0);
75 hcorr->SetBinError(bx,by,0);
77 tmp->SetBinContent(bx,by,0);
80 tmp->SetBinContent(bx,by,1);
86 //____________________________________________________________________
88 CorrectionMatrix2D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge) {
90 // remove edges of correction histogram by removing
91 // - bins with content less than cut
92 // - bins next to bins with zero bin content
94 Int_t nBinsX = hcorr->GetNbinsX();
95 Int_t nBinsY = hcorr->GetNbinsY();
97 // set bin content to zero for bins with content smaller cut
98 for (Int_t bx=0; bx<=nBinsX; bx++) {
99 for (Int_t by=0; by<=nBinsY; by++) {
100 if (hcorr->GetBinContent(bx,by)>cut) {
101 hcorr->SetBinContent(bx,by,0);
102 hcorr->SetBinError(bx,by,0);
107 // set bin content to zero for bins next to bins with zero
108 TH2F* tmp = (TH2F*)hcorr->Clone("tmp");
111 Bool_t done = kFALSE;
112 Int_t nBinsXCount = 0;
113 Int_t nBinsYCount = 0;
115 if (nBinsXCount<nBinsXedge)
116 for (Int_t bx=0; bx<=nBinsX; bx++) {
117 for (Int_t by=0; by<=nBinsY; by++) {
118 if ((hcorr->GetBinContent(bx+1,by)==0)||
119 (hcorr->GetBinContent(bx-1,by)==0))
120 tmp->SetBinContent(bx,by,1);
124 if (nBinsYCount<nBinsYedge)
125 for (Int_t bx=0; bx<=nBinsX; bx++) {
126 for (Int_t by=0; by<=nBinsY; by++) {
127 if ((hcorr->GetBinContent(bx,by+1)==0)||
128 (hcorr->GetBinContent(bx,by-1)==0))
129 tmp->SetBinContent(bx,by,1);
132 for (Int_t bx=0; bx<=nBinsX; bx++) {
133 for (Int_t by=0; by<=nBinsY; by++) {
134 if (tmp->GetBinContent(bx,by)==1) {
135 hcorr->SetBinContent(bx,by,0);
136 hcorr->SetBinError(bx,by,0);
142 if ((nBinsXCount>=nBinsXedge)&&(nBinsYCount>=nBinsYedge)) done=kTRUE;
148 //____________________________________________________________________
149 Bool_t CorrectionMatrix2D::LoadHistograms(Char_t* fileName, Char_t* dir) {
151 TFile* fin = TFile::Open(fileName);
155 //Info("LoadHistograms",Form(" %s file does not exist",fileName));
159 if(hgene) {delete hgene; hgene=0;}
160 if(hcorr) {delete hcorr; hcorr=0;}
161 if(hratio) {delete hratio; hratio=0;}
162 if(hmeas) {delete hmeas; hmeas=0;}
164 hmeas = (TH2F*)fin->Get(Form("%s/meas",dir));
165 if(!hmeas) Info("LoadHistograms","No meas hist available");
166 hgene = (TH2F*)fin->Get(Form("%s/gene",dir));
167 if(!hgene) Info("LoadHistograms","No gene hist available");
168 hratio = (TH2F*)fin->Get(Form("%s/ratio",dir));
169 if(!hratio) Info("LoadHistograms","No ratio hist available");
170 hcorr = (TH2F*)fin->Get(Form("%s/corr",dir));
171 if(!hcorr) {Info("LoadHistograms","No corr hist available");
178 //____________________________________________________________________
180 CorrectionMatrix2D::SaveHistograms() {
182 gDirectory->mkdir(fName.Data());
183 gDirectory->cd(fName.Data());
194 gDirectory->cd("../");
197 //____________________________________________________________________
198 void CorrectionMatrix2D::DrawHistograms()
200 TCanvas* canvas = new TCanvas("Correction", "Correction", 800, 800);
201 canvas->Divide(2, 2);
213 hratio->Draw("COLZ");