more plots
[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
12 #include <AliLog.h>
13
14 #include "AliCorrectionMatrix3D.h"
15 #include "AliPWG0Helper.h"
16
17 //____________________________________________________________________
18 ClassImp(AliCorrectionMatrix3D)
19
20 //____________________________________________________________________
21 AliCorrectionMatrix3D::AliCorrectionMatrix3D() :
22   AliCorrectionMatrix()
23 {
24   // default constructor
25 }
26
27 //____________________________________________________________________
28 AliCorrectionMatrix3D::AliCorrectionMatrix3D(const AliCorrectionMatrix3D& c)
29   : AliCorrectionMatrix(c)
30 {
31   // copy constructor
32   ((AliCorrectionMatrix3D &)c).Copy(*this);
33 }
34
35 //____________________________________________________________________
36 AliCorrectionMatrix3D::AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
37               Int_t nBinX, Float_t Xmin, Float_t Xmax,
38               Int_t nBinY, Float_t Ymin, Float_t Ymax,
39               Int_t nBinZ, Float_t Zmin, Float_t Zmax)
40   : AliCorrectionMatrix(name, title)
41 {
42   //
43   // constructor
44   //
45
46   fhMeas  = new TH3F(Form("meas_%s",name), Form("meas_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
47   fhGene  = new TH3F(Form("gene_%s",name), Form("gene_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
48   fhCorr  = new TH3F(Form("corr_%s",name), Form("corr_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
49
50   fhMeas->Sumw2();
51   fhGene->Sumw2();
52   fhCorr->Sumw2();
53 }
54
55 AliCorrectionMatrix3D::AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
56       Int_t nBinX, Float_t Xmin, Float_t Xmax,
57       Int_t nBinY, Float_t Ymin, Float_t Ymax,
58       Int_t nBinZ, const Float_t* zbins)
59   : AliCorrectionMatrix(name, title)
60 {
61   // constructor with variable bin sizes
62
63   Float_t* binLimitsX = new Float_t[nBinX+1];
64   for (Int_t i=0; i<=nBinX; ++i)
65     binLimitsX[i] = Xmin + (Xmax - Xmin) / nBinX * i;
66
67   Float_t* binLimitsY = new Float_t[nBinY+1];
68   for (Int_t i=0; i<=nBinY; ++i)
69     binLimitsY[i] = Ymin + (Ymax - Ymin) / nBinY * i;
70
71   fhMeas  = new TH3F(Form("meas_%s",name), Form("meas_%s",title), nBinX, binLimitsX, nBinY, binLimitsY, nBinZ, zbins);
72   fhGene  = new TH3F(Form("gene_%s",name), Form("gene_%s",title), nBinX, binLimitsX, nBinY, binLimitsY, nBinZ, zbins);
73   fhCorr  = new TH3F(Form("corr_%s",name), Form("corr_%s",title), nBinX, binLimitsX, nBinY, binLimitsY, nBinZ, zbins);
74
75   delete[] binLimitsX;
76   delete[] binLimitsY;
77
78   fhMeas->Sumw2();
79   fhGene->Sumw2();
80   fhCorr->Sumw2();
81 }
82
83 //____________________________________________________________________
84 AliCorrectionMatrix3D::~AliCorrectionMatrix3D()
85 {
86   //
87   // destructor
88   //
89
90   // histograms already deleted in base class
91 }
92
93 //____________________________________________________________________
94 TH3F* AliCorrectionMatrix3D::GetGeneratedHistogram()
95 {
96   // return generated histogram casted to correct type
97   return dynamic_cast<TH3F*> (fhGene);
98 }
99
100 //____________________________________________________________________
101 TH3F* AliCorrectionMatrix3D::GetMeasuredHistogram()
102 {
103   // return measured histogram casted to correct type
104   return dynamic_cast<TH3F*> (fhMeas);
105 }
106
107 //____________________________________________________________________
108 TH3F* AliCorrectionMatrix3D::GetCorrectionHistogram()
109 {
110   // return correction histogram casted to correct type
111   return dynamic_cast<TH3F*> (fhCorr);
112 }
113
114 //____________________________________________________________________
115 void AliCorrectionMatrix3D::FillMeas(Float_t ax, Float_t ay, Float_t az)
116 {
117   // add value to measured histogram
118   GetMeasuredHistogram()->Fill(ax, ay, az);
119 }
120
121 //____________________________________________________________________
122 void AliCorrectionMatrix3D::FillGene(Float_t ax, Float_t ay, Float_t az)
123 {
124   // add value to generated histogram
125   GetGeneratedHistogram()->Fill(ax, ay, az);
126 }
127
128 //____________________________________________________________________
129 Float_t AliCorrectionMatrix3D::GetCorrection(Float_t ax, Float_t ay, Float_t az) const
130 {
131   // returns a value of the correction map
132   return fhCorr->GetBinContent(fhCorr->FindBin(ax, ay, az));
133 }
134
135 //____________________________________________________________________
136 //void AliCorrectionMatrix3D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge, Int_t nBinsZedge)
137 void AliCorrectionMatrix3D::RemoveEdges(Float_t, Int_t, Int_t, Int_t)
138 {
139   // so what do we do here...
140 }
141
142 //____________________________________________________________________
143 void AliCorrectionMatrix3D::SaveHistograms()
144 {
145   //
146   // saves the histograms
147   //
148
149   AliCorrectionMatrix::SaveHistograms();
150
151   if (GetGeneratedHistogram() && GetMeasuredHistogram())
152     AliPWG0Helper::CreateDividedProjections(GetGeneratedHistogram(), GetMeasuredHistogram());
153 }