updating makefile to build all PWG0libs
[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)
102{
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
165}
166
167//____________________________________________________________________
168Bool_t AliCorrectionMatrix::LoadHistograms(Char_t* fileName, Char_t* dir)
169{
170 //
171 // loads the histograms from a file
172 //
173
174 TFile* fin = TFile::Open(fileName);
175
176 if(!fin) {
177 //Info("LoadHistograms",Form(" %s file does not exist",fileName));
178 return kFALSE;
179 }
180
181 if(fhGene) {delete fhGene; fhGene=0;}
182 if(fhCorr) {delete fhCorr; fhCorr=0;}
183 if(fhMeas) {delete fhMeas; fhMeas=0;}
184
185 fhMeas = (TH2F*)fin->Get(Form("%s/meas_%s", dir,GetName()));
186 if(!fhMeas) Info("LoadHistograms","No meas hist available");
187
188 fhGene = (TH2F*)fin->Get(Form("%s/gene_%s",dir, GetName()));
189 if(!fhGene) Info("LoadHistograms","No gene hist available");
190
191 fhCorr = (TH2F*)fin->Get(Form("%s/corr_%s",dir, GetName()));
192 if(!fhCorr)
193 {
194 Info("LoadHistograms","No corr hist available");
195 return kFALSE;
196 }
197
198 return kTRUE;
199}
200
201//____________________________________________________________________
202void AliCorrectionMatrix::SaveHistograms()
203{
204 //
205 // saves the histograms
206 //
207
208 fhMeas ->Write();
209 fhGene ->Write();
210
211 if (fhCorr)
212 fhCorr->Write();
213}
214
215//____________________________________________________________________
216void AliCorrectionMatrix::DrawHistograms()
217{
218 //
219 // draws all the four histograms on one TCanvas
220 //
221
222 TCanvas* canvas = new TCanvas(Form("correction_%s",fName.Data()),
223 Form("correction_%s",fName.Data()), 800, 800);
224 canvas->Divide(2, 2);
225
226 canvas->cd(1);
227 if (fhMeas)
228 fhMeas->Draw("COLZ");
229
230 canvas->cd(2);
231 if (fhGene)
232 fhGene->Draw("COLZ");
233
234 canvas->cd(3);
235 if (fhCorr)
236 fhCorr->Draw("COLZ");
237
238 canvas->cd(4);
239
240 // add: draw here the stat. errors of the correction histogram
241}