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