3 // ------------------------------------------------------
5 // Class to handle 3d-corrections.
7 // ------------------------------------------------------
15 #include "AliCorrectionMatrix3D.h"
16 #include "AliPWG0Helper.h"
18 //____________________________________________________________________
19 ClassImp(AliCorrectionMatrix3D)
21 //____________________________________________________________________
22 AliCorrectionMatrix3D::AliCorrectionMatrix3D() :
25 // default constructor
28 //____________________________________________________________________
29 AliCorrectionMatrix3D::AliCorrectionMatrix3D(const AliCorrectionMatrix3D& c)
30 : AliCorrectionMatrix(c)
33 ((AliCorrectionMatrix3D &)c).Copy(*this);
36 //____________________________________________________________________
37 AliCorrectionMatrix3D &AliCorrectionMatrix3D::operator=(const AliCorrectionMatrix3D &c)
42 ((AliCorrectionMatrix3D &) c).Copy(*this);
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)
58 // do not add this hists to the directory
59 Bool_t oldStatus = TH1::AddDirectoryStatus();
60 TH1::AddDirectory(kFALSE);
62 fhMeas = new TH3F("measured", Form("%s measured",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
63 fhGene = new TH3F("generated", Form("%s generated",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
64 fhCorr = new TH3F("correction", Form("%s correction",title), nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
66 TH1::AddDirectory(oldStatus);
73 AliCorrectionMatrix3D::AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
74 Int_t nBinX, Float_t Xmin, Float_t Xmax,
75 Int_t nBinY, Float_t Ymin, Float_t Ymax,
76 Int_t nBinZ, const Float_t* zbins)
77 : AliCorrectionMatrix(name, title)
79 // constructor with variable bin sizes
81 Float_t* binLimitsX = new Float_t[nBinX+1];
82 for (Int_t i=0; i<=nBinX; ++i)
83 binLimitsX[i] = Xmin + (Xmax - Xmin) / nBinX * i;
85 Float_t* binLimitsY = new Float_t[nBinY+1];
86 for (Int_t i=0; i<=nBinY; ++i)
87 binLimitsY[i] = Ymin + (Ymax - Ymin) / nBinY * i;
89 // do not add this hists to the directory
90 Bool_t oldStatus = TH1::AddDirectoryStatus();
91 TH1::AddDirectory(kFALSE);
93 fhMeas = new TH3F("measured", Form("%s measured",title), nBinX, binLimitsX, nBinY, binLimitsY, nBinZ, zbins);
94 fhGene = new TH3F("generated", Form("%s generated",title), nBinX, binLimitsX, nBinY, binLimitsY, nBinZ, zbins);
95 fhCorr = new TH3F("correction", Form("%s correction",title), nBinX, binLimitsX, nBinY, binLimitsY, nBinZ, zbins);
97 TH1::AddDirectory(oldStatus);
107 //____________________________________________________________________
108 AliCorrectionMatrix3D::~AliCorrectionMatrix3D()
114 // histograms already deleted in base class
117 //____________________________________________________________________
118 TH3F* AliCorrectionMatrix3D::GetGeneratedHistogram()
120 // return generated histogram casted to correct type
121 return dynamic_cast<TH3F*> (fhGene);
124 //____________________________________________________________________
125 TH3F* AliCorrectionMatrix3D::GetMeasuredHistogram()
127 // return measured histogram casted to correct type
128 return dynamic_cast<TH3F*> (fhMeas);
131 //____________________________________________________________________
132 TH3F* AliCorrectionMatrix3D::GetCorrectionHistogram()
134 // return correction histogram casted to correct type
135 return dynamic_cast<TH3F*> (fhCorr);
138 //____________________________________________________________________
139 void AliCorrectionMatrix3D::FillMeas(Float_t ax, Float_t ay, Float_t az)
141 // add value to measured histogram
142 GetMeasuredHistogram()->Fill(ax, ay, az);
145 //____________________________________________________________________
146 void AliCorrectionMatrix3D::FillGene(Float_t ax, Float_t ay, Float_t az)
148 // add value to generated histogram
149 GetGeneratedHistogram()->Fill(ax, ay, az);
152 //____________________________________________________________________
153 Float_t AliCorrectionMatrix3D::GetCorrection(Float_t ax, Float_t ay, Float_t az) const
155 // returns a value of the correction map
156 return fhCorr->GetBinContent(fhCorr->FindBin(ax, ay, az));
159 //____________________________________________________________________
160 //void AliCorrectionMatrix3D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge, Int_t nBinsZedge)
161 void AliCorrectionMatrix3D::RemoveEdges(Float_t, Int_t, Int_t, Int_t)
163 // so what do we do here...
166 //____________________________________________________________________
167 void AliCorrectionMatrix3D::SaveHistograms()
170 // saves the histograms
173 AliCorrectionMatrix::SaveHistograms();
175 if (GetGeneratedHistogram() && GetMeasuredHistogram())
177 gDirectory->cd(GetName());
179 AliPWG0Helper::CreateDividedProjections(GetGeneratedHistogram(), GetMeasuredHistogram(), 0, kFALSE, kTRUE);
181 gDirectory->cd("..");
185 //____________________________________________________________________
186 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)
189 // counts the number of empty Bins in a given region
192 TH3F* hist = GetGeneratedHistogram();
197 for (Int_t x=hist->GetXaxis()->FindBin(xmin); x<=hist->GetXaxis()->FindBin(xmax); ++x)
198 for (Int_t y=hist->GetYaxis()->FindBin(ymin); y<=hist->GetYaxis()->FindBin(ymax); ++y)
199 for (Int_t z=hist->GetZaxis()->FindBin(zmin); z<=hist->GetZaxis()->FindBin(zmax); ++z)
200 if (hist->GetBinContent(x, y, z) == 0)
203 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));
210 //____________________________________________________________________
211 TH1F* AliCorrectionMatrix3D::PlotBinErrors(Float_t xmin, Float_t xmax, Float_t ymin, Float_t ymax, Float_t zmin, Float_t zmax)
214 // makes a 1d plots of the relative bin errors
217 TH3F* hist = GetCorrectionHistogram();
221 TH1F* target = new TH1F("relerrors", "relerrors", 100, 0, 10);
223 for (Int_t x=hist->GetXaxis()->FindBin(xmin); x<=hist->GetXaxis()->FindBin(xmax); ++x)
224 for (Int_t y=hist->GetYaxis()->FindBin(ymin); y<=hist->GetYaxis()->FindBin(ymax); ++y)
225 for (Int_t z=hist->GetZaxis()->FindBin(zmin); z<=hist->GetZaxis()->FindBin(zmax); ++z)
226 if (hist->GetBinContent(x, y, z) != 0)
227 target->Fill(100 * hist->GetBinError(x, y, z) / hist->GetBinContent(x, y, z));