]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/AliCorrectionMatrix3D.cxx
adding helper function to count empty bins in AliCorrectionMatrix
[u/mrichter/AliRoot.git] / PWG0 / AliCorrectionMatrix3D.cxx
1 /* $Id$ */
2
3 // ------------------------------------------------------
4 //
5 // Class to handle 3d-corrections.
6 //
7 // ------------------------------------------------------
8 //
9
10 #include <TH3F.h>
11 #include <TH1F.h>
12
13 #include <AliLog.h>
14
15 #include "AliCorrectionMatrix3D.h"
16 #include "AliPWG0Helper.h"
17
18 //____________________________________________________________________
19 ClassImp(AliCorrectionMatrix3D)
20
21 //____________________________________________________________________
22 AliCorrectionMatrix3D::AliCorrectionMatrix3D() :
23   AliCorrectionMatrix()
24 {
25   // default constructor
26 }
27
28 //____________________________________________________________________
29 AliCorrectionMatrix3D::AliCorrectionMatrix3D(const AliCorrectionMatrix3D& c)
30   : AliCorrectionMatrix(c)
31 {
32   // copy constructor
33   ((AliCorrectionMatrix3D &)c).Copy(*this);
34 }
35
36 //____________________________________________________________________
37 AliCorrectionMatrix3D &AliCorrectionMatrix3D::operator=(const AliCorrectionMatrix3D &c)
38 {
39   // assigment operator
40
41   if (this != &c)
42     ((AliCorrectionMatrix3D &) c).Copy(*this);
43
44   return *this;
45 }
46
47 //____________________________________________________________________
48 AliCorrectionMatrix3D::AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
49               Int_t nBinX, Float_t Xmin, Float_t Xmax,
50               Int_t nBinY, Float_t Ymin, Float_t Ymax,
51               Int_t nBinZ, Float_t Zmin, Float_t Zmax)
52   : AliCorrectionMatrix(name, title)
53 {
54   //
55   // constructor
56   //
57
58   fhMeas  = new TH3F(Form("meas_%s",name), Form("meas_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
59   fhGene  = new TH3F(Form("gene_%s",name), Form("gene_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
60   fhCorr  = new TH3F(Form("corr_%s",name), Form("corr_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
61
62   fhMeas->Sumw2();
63   fhGene->Sumw2();
64   fhCorr->Sumw2();
65 }
66
67 AliCorrectionMatrix3D::AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
68       Int_t nBinX, Float_t Xmin, Float_t Xmax,
69       Int_t nBinY, Float_t Ymin, Float_t Ymax,
70       Int_t nBinZ, const Float_t* zbins)
71   : AliCorrectionMatrix(name, title)
72 {
73   // constructor with variable bin sizes
74
75   Float_t* binLimitsX = new Float_t[nBinX+1];
76   for (Int_t i=0; i<=nBinX; ++i)
77     binLimitsX[i] = Xmin + (Xmax - Xmin) / nBinX * i;
78
79   Float_t* binLimitsY = new Float_t[nBinY+1];
80   for (Int_t i=0; i<=nBinY; ++i)
81     binLimitsY[i] = Ymin + (Ymax - Ymin) / nBinY * i;
82
83   fhMeas  = new TH3F(Form("meas_%s",name), Form("meas_%s",title), nBinX, binLimitsX, nBinY, binLimitsY, nBinZ, zbins);
84   fhGene  = new TH3F(Form("gene_%s",name), Form("gene_%s",title), nBinX, binLimitsX, nBinY, binLimitsY, nBinZ, zbins);
85   fhCorr  = new TH3F(Form("corr_%s",name), Form("corr_%s",title), nBinX, binLimitsX, nBinY, binLimitsY, nBinZ, zbins);
86
87   delete[] binLimitsX;
88   delete[] binLimitsY;
89
90   fhMeas->Sumw2();
91   fhGene->Sumw2();
92   fhCorr->Sumw2();
93 }
94
95 //____________________________________________________________________
96 AliCorrectionMatrix3D::~AliCorrectionMatrix3D()
97 {
98   //
99   // destructor
100   //
101
102   // histograms already deleted in base class
103 }
104
105 //____________________________________________________________________
106 TH3F* AliCorrectionMatrix3D::GetGeneratedHistogram()
107 {
108   // return generated histogram casted to correct type
109   return dynamic_cast<TH3F*> (fhGene);
110 }
111
112 //____________________________________________________________________
113 TH3F* AliCorrectionMatrix3D::GetMeasuredHistogram()
114 {
115   // return measured histogram casted to correct type
116   return dynamic_cast<TH3F*> (fhMeas);
117 }
118
119 //____________________________________________________________________
120 TH3F* AliCorrectionMatrix3D::GetCorrectionHistogram()
121 {
122   // return correction histogram casted to correct type
123   return dynamic_cast<TH3F*> (fhCorr);
124 }
125
126 //____________________________________________________________________
127 void AliCorrectionMatrix3D::FillMeas(Float_t ax, Float_t ay, Float_t az)
128 {
129   // add value to measured histogram
130   GetMeasuredHistogram()->Fill(ax, ay, az);
131 }
132
133 //____________________________________________________________________
134 void AliCorrectionMatrix3D::FillGene(Float_t ax, Float_t ay, Float_t az)
135 {
136   // add value to generated histogram
137   GetGeneratedHistogram()->Fill(ax, ay, az);
138 }
139
140 //____________________________________________________________________
141 Float_t AliCorrectionMatrix3D::GetCorrection(Float_t ax, Float_t ay, Float_t az) const
142 {
143   // returns a value of the correction map
144   return fhCorr->GetBinContent(fhCorr->FindBin(ax, ay, az));
145 }
146
147 //____________________________________________________________________
148 //void AliCorrectionMatrix3D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge, Int_t nBinsZedge)
149 void AliCorrectionMatrix3D::RemoveEdges(Float_t, Int_t, Int_t, Int_t)
150 {
151   // so what do we do here...
152 }
153
154 //____________________________________________________________________
155 void AliCorrectionMatrix3D::SaveHistograms()
156 {
157   //
158   // saves the histograms
159   //
160
161   AliCorrectionMatrix::SaveHistograms();
162
163   if (GetGeneratedHistogram() && GetMeasuredHistogram())
164     AliPWG0Helper::CreateDividedProjections(GetGeneratedHistogram(), GetMeasuredHistogram());
165 }
166
167 //____________________________________________________________________
168 Int_t AliCorrectionMatrix3D::CheckEmptyBins(Float_t xmin, Float_t xmax, Float_t ymin, Float_t ymax, Float_t zmin, Float_t zmax, Bool_t quiet)
169 {
170   //
171   // counts the number of empty Bins in a given region
172   //
173
174   TH3F* hist = GetGeneratedHistogram();
175   if (!hist)
176     return -1;
177
178   Int_t emptyBins = 0;
179   for (Int_t x=hist->GetXaxis()->FindBin(xmin); x<=hist->GetXaxis()->FindBin(xmax); ++x)
180     for (Int_t y=hist->GetYaxis()->FindBin(ymin); y<=hist->GetYaxis()->FindBin(ymax); ++y)
181       for (Int_t z=hist->GetZaxis()->FindBin(zmin); z<=hist->GetZaxis()->FindBin(zmax); ++z)
182         if (hist->GetBinContent(x, y, z) == 0)
183         {
184           if (!quiet)
185             printf("Empty bin in %s at vtx = %f, eta = %f, pt = %f\n", GetName(), hist->GetXaxis()->GetBinCenter(x), hist->GetYaxis()->GetBinCenter(y), hist->GetZaxis()->GetBinCenter(z));
186           ++emptyBins;
187         }
188
189   return emptyBins;
190 }
191
192 //____________________________________________________________________
193 TH1F* AliCorrectionMatrix3D::PlotBinErrors(Float_t xmin, Float_t xmax, Float_t ymin, Float_t ymax, Float_t zmin, Float_t zmax)
194 {
195   //
196   // makes a 1d plots of the relative bin errors
197   //
198
199   TH3F* hist = GetCorrectionHistogram();
200   if (!hist)
201     return 0;
202     
203   TH1F* target = new TH1F("relerrors", "relerrors", 100, 0, 10);
204
205   for (Int_t x=hist->GetXaxis()->FindBin(xmin); x<=hist->GetXaxis()->FindBin(xmax); ++x)
206     for (Int_t y=hist->GetYaxis()->FindBin(ymin); y<=hist->GetYaxis()->FindBin(ymax); ++y)
207       for (Int_t z=hist->GetZaxis()->FindBin(zmin); z<=hist->GetZaxis()->FindBin(zmax); ++z)
208         if (hist->GetBinContent(x, y, z) != 0)
209           target->Fill(100 * hist->GetBinError(x, y, z) / hist->GetBinContent(x, y, z));
210
211   return target;
212 }
213