]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/AliCorrectionMatrix.cxx
Updates needed to be in synch with TDPMjet.
[u/mrichter/AliRoot.git] / PWG0 / AliCorrectionMatrix.cxx
CommitLineData
bf21645b 1/* $Id$ */
2
3// ------------------------------------------------------
4//
5// Class to handle corrections.
6//
7// ------------------------------------------------------
8//
9
10#include <TFile.h>
11#include <TCanvas.h>
12#include <TH2F.h>
13
14#include <AliLog.h>
15
16#include "AliCorrectionMatrix.h"
17
18//____________________________________________________________________
19ClassImp(AliCorrectionMatrix)
20
21//____________________________________________________________________
22AliCorrectionMatrix::AliCorrectionMatrix() : TNamed(),
23 fhMeas(0),
24 fhGene(0),
25 fhCorr(0)
26{
27 // default constructor
28}
29
30AliCorrectionMatrix::AliCorrectionMatrix(const Char_t* name, const Char_t* title) : TNamed(name, title),
31 fhMeas(0),
32 fhGene(0),
33 fhCorr(0)
34{
35 // constructor initializing tnamed
36}
37
38//____________________________________________________________________
39AliCorrectionMatrix::AliCorrectionMatrix(const AliCorrectionMatrix& c)
40 : TNamed(c)
41{
42 // copy constructor
43 ((AliCorrectionMatrix &)c).Copy(*this);
44}
45
46//____________________________________________________________________
47AliCorrectionMatrix::~AliCorrectionMatrix()
48{
49 //
50 // destructor
51 //
52
53 if (fhMeas)
54 {
55 delete fhMeas;
56 fhMeas = 0;
57 }
58
59 if (fhGene)
60 {
61 delete fhGene;
62 fhGene = 0;
63 }
64
65 if (fhCorr)
66 {
67 delete fhCorr;
68 fhCorr = 0;
69 }
70}
71
72//____________________________________________________________________
73AliCorrectionMatrix &AliCorrectionMatrix::operator=(const AliCorrectionMatrix &c)
74{
75 // assigment operator
76
77 if (this != &c)
78 ((AliCorrectionMatrix &) c).Copy(*this);
79
80 return *this;
81}
82
83//____________________________________________________________________
84void AliCorrectionMatrix::Copy(TObject& c) const
85{
86 // copy function
87
88 AliCorrectionMatrix& target = (AliCorrectionMatrix &) c;
89
90 if (fhMeas)
91 target.fhMeas = dynamic_cast<TH1*> (fhMeas->Clone());
92
93 if (fhGene)
94 target.fhGene = dynamic_cast<TH1*> (fhGene->Clone());
95
96 if (fhCorr)
97 target.fhCorr = dynamic_cast<TH1*> (fhCorr->Clone());
98}
99
100//________________________________________________________________________
101void AliCorrectionMatrix::SetAxisTitles(const Char_t* titleX, const Char_t* titleY, const Char_t* titleZ)
0ab29cfa 102{
bf21645b 103 //
104 // method for setting the axis titles of the histograms
105 //
106
107 fhMeas ->SetXTitle(titleX); fhMeas ->SetYTitle(titleY); fhMeas ->SetZTitle(titleZ);
108 fhGene ->SetXTitle(titleX); fhGene ->SetYTitle(titleY); fhGene ->SetZTitle(titleZ);
109 fhCorr ->SetXTitle(titleX); fhCorr ->SetYTitle(titleY); fhCorr ->SetZTitle(titleZ);
110}
111
112//____________________________________________________________________
113Long64_t AliCorrectionMatrix::Merge(TCollection* list)
114{
115 // Merge a list of AliCorrectionMatrix objects with this (needed for
116 // PROOF).
117 // Returns the number of merged objects (including this).
118
119 if (!list)
120 return 0;
121
122 if (list->IsEmpty())
123 return 1;
124
125 TIterator* iter = list->MakeIterator();
126 TObject* obj;
127
128 // collections of measured and generated histograms
129 TList* collectionMeas = new TList;
130 TList* collectionGene = new TList;
131
132 Int_t count = 0;
133 while ((obj = iter->Next())) {
134
135 AliCorrectionMatrix* entry = dynamic_cast<AliCorrectionMatrix*> (obj);
136 if (entry == 0)
137 continue;
138
139 collectionMeas->Add(entry->GetMeasuredHistogram());
140 collectionGene->Add(entry->GetGeneratedHistogram());
141
142 count++;
143 }
144 fhMeas->Merge(collectionMeas);
145 fhGene->Merge(collectionGene);
146
147 delete collectionMeas;
148 delete collectionGene;
149
150 return count+1;
151}
152
153//____________________________________________________________________
154void AliCorrectionMatrix::Divide()
155{
156 //
157 // divide the histograms to get the correction
158 //
159
160 if (!fhMeas || !fhGene)
161 return;
162
163 fhCorr->Divide(fhGene, fhMeas, 1, 1, "B");
164
1afae8ff 165 Int_t emptyBins = 0;
166 for (Int_t x=1; x<=fhCorr->GetNbinsX(); ++x)
167 for (Int_t y=1; y<=fhCorr->GetNbinsY(); ++y)
168 for (Int_t z=1; z<=fhCorr->GetNbinsZ(); ++z)
169 if (fhCorr->GetBinContent(x, y, z) == 0)
170 ++emptyBins;
171
172 if (emptyBins > 0)
173 printf("INFO: In %s we have %d empty bins (of %d) in the correction map\n", GetName(), emptyBins, fhCorr->GetNbinsX() * fhCorr->GetNbinsY() * fhCorr->GetNbinsZ());
bf21645b 174}
175
176//____________________________________________________________________
0ab29cfa 177Bool_t AliCorrectionMatrix::LoadHistograms(const Char_t* fileName, const Char_t* dir)
bf21645b 178{
179 //
180 // loads the histograms from a file
181 //
1afae8ff 182
183 TFile* fin = TFile::Open(fileName);
184
bf21645b 185 if(!fin) {
186 //Info("LoadHistograms",Form(" %s file does not exist",fileName));
187 return kFALSE;
188 }
189
190 if(fhGene) {delete fhGene; fhGene=0;}
191 if(fhCorr) {delete fhCorr; fhCorr=0;}
192 if(fhMeas) {delete fhMeas; fhMeas=0;}
193
0ab29cfa 194 fhMeas = dynamic_cast<TH1*> (fin->Get(Form("%s/meas_%s", dir,GetName())));
bf21645b 195 if(!fhMeas) Info("LoadHistograms","No meas hist available");
0ab29cfa 196
197 fhGene = dynamic_cast<TH1*> (fin->Get(Form("%s/gene_%s",dir, GetName())));
bf21645b 198 if(!fhGene) Info("LoadHistograms","No gene hist available");
0ab29cfa 199
200 fhCorr = dynamic_cast<TH1*> (fin->Get(Form("%s/corr_%s",dir, GetName())));
bf21645b 201 if(!fhCorr)
202 {
203 Info("LoadHistograms","No corr hist available");
204 return kFALSE;
205 }
206
207 return kTRUE;
208}
209
210//____________________________________________________________________
211void AliCorrectionMatrix::SaveHistograms()
212{
213 //
214 // saves the histograms
215 //
216
217 fhMeas ->Write();
218 fhGene ->Write();
219
220 if (fhCorr)
221 fhCorr->Write();
222}
223
224//____________________________________________________________________
225void AliCorrectionMatrix::DrawHistograms()
226{
227 //
228 // draws all the four histograms on one TCanvas
229 //
230
231 TCanvas* canvas = new TCanvas(Form("correction_%s",fName.Data()),
232 Form("correction_%s",fName.Data()), 800, 800);
233 canvas->Divide(2, 2);
234
235 canvas->cd(1);
236 if (fhMeas)
237 fhMeas->Draw("COLZ");
238
239 canvas->cd(2);
240 if (fhGene)
241 fhGene->Draw("COLZ");
242
243 canvas->cd(3);
244 if (fhCorr)
245 fhCorr->Draw("COLZ");
246
247 canvas->cd(4);
248
249 // add: draw here the stat. errors of the correction histogram
250}
0ab29cfa 251
252//____________________________________________________________________
253void AliCorrectionMatrix::ReduceInformation()
254{
255 // this function deletes the measured and generated histograms to reduce the amount of data
256 // in memory
257
258 if (fhMeas)
259 {
260 delete fhMeas;
261 fhMeas = 0;
262 }
263
264 if (fhGene)
265 {
266 delete fhGene;
267 fhGene = 0;
268 }
269}