]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/AliCorrection.cxx
added constructors
[u/mrichter/AliRoot.git] / PWG0 / AliCorrection.cxx
CommitLineData
29771dc8 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#include "AliCorrectionMatrix2D.h"
16#include "AliCorrectionMatrix3D.h"
17
18#include "AliCorrection.h"
19
20//____________________________________________________________________
21ClassImp(AliCorrection)
22
23//____________________________________________________________________
24AliCorrection::AliCorrection() : TNamed(),
25 fEventCorr(0),
26 fTrackCorr(0)
27{
28 // default constructor
29}
30
31//____________________________________________________________________
32AliCorrection::AliCorrection(const Char_t* name, const Char_t* title) : TNamed(name, title),
33 fEventCorr(0),
34 fTrackCorr(0)
35{
36 // constructor initializing tnamed
37
38 Float_t binLimitsPt[] = {0.0, 0.05, 0.1, 0.125, 0.15, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3, 0.325, 0.35, 0.375, 0.4, 0.425, 0.45, 0.475, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.5, 2.0, 5.0, 10.0, 100.0};
39 Float_t binLimitsN[] = {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 12.5, 14.5, 16.5, 18.5, 20.5, 25.5, 30.5, 40.5, 50.5, 100.5, 300.5};
40 //Float_t binLimitsVtx[] = {-20,-15,-10,-6,-3,0,3,6,10,15,20};
083a636e 41 //Float_t binLimitsVtx[] = {-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
42 Float_t binLimitsVtx[] = {-20,-15,-10,-8,-6,-4,-2,0,2,4,6,8,10,15,20};
29771dc8 43
083a636e 44 fEventCorr = new AliCorrectionMatrix2D("EventCorrection", Form("%s EventCorrection", title), 14, binLimitsVtx, 22, binLimitsN);
45 fTrackCorr = new AliCorrectionMatrix3D("TrackCorrection", Form("%s TrackCorrection", title), 14, binLimitsVtx, 40, -2, 2, 28, binLimitsPt);
29771dc8 46
47 fEventCorr->SetAxisTitles("vtx z [cm]", "Ntracks");
48 fTrackCorr->SetAxisTitles("vtx z [cm]", "#eta", "p_{T} [GeV/c]");
49}
50
51//____________________________________________________________________
52AliCorrection::AliCorrection(const AliCorrection& c) : TNamed(c),
53 fEventCorr(0),
54 fTrackCorr(0)
55{
56 // copy constructor
57 ((AliCorrection &)c).Copy(*this);
58}
59
60//____________________________________________________________________
61AliCorrection::~AliCorrection()
62{
63 //
64 // destructor
65 //
66
67 if (fEventCorr)
68 {
69 delete fEventCorr;
70 fEventCorr = 0;
71 }
72
73 if (fTrackCorr)
74 {
75 delete fTrackCorr;
76 fTrackCorr = 0;
77 }
78}
79
80//____________________________________________________________________
81AliCorrection &AliCorrection::operator=(const AliCorrection &c)
82{
83 // assigment operator
84
85 if (this != &c)
86 ((AliCorrection &) c).Copy(*this);
87
88 return *this;
89}
90
91//____________________________________________________________________
92void AliCorrection::Copy(TObject& c) const
93{
94 // copy function
95
96 AliCorrection& target = (AliCorrection &) c;
97
98 if (fEventCorr)
99 target.fEventCorr = dynamic_cast<AliCorrectionMatrix2D*> (fEventCorr->Clone());
100
101 if (fTrackCorr)
102 target.fTrackCorr = dynamic_cast<AliCorrectionMatrix3D*> (fTrackCorr->Clone());
103}
104
105//____________________________________________________________________
106Long64_t AliCorrection::Merge(TCollection* list)
107{
108 // Merge a list of AliCorrection objects with this (needed for
109 // PROOF).
110 // Returns the number of merged objects (including this).
111
112 if (!list)
113 return 0;
114
115 if (list->IsEmpty())
116 return 1;
117
118 TIterator* iter = list->MakeIterator();
119 TObject* obj;
120
121 // collections of measured and generated histograms
122 TList* collectionEvent = new TList;
123 TList* collectionTrack = new TList;
124
125 Int_t count = 0;
126 while ((obj = iter->Next())) {
127
128 AliCorrection* entry = dynamic_cast<AliCorrection*> (obj);
129 if (entry == 0)
130 continue;
131
132 collectionEvent->Add(entry->fEventCorr);
133 collectionTrack->Add(entry->fTrackCorr);
134
135 count++;
136 }
137 fEventCorr->Merge(collectionEvent);
138 fTrackCorr->Merge(collectionTrack);
139
140 delete collectionEvent;
141 delete collectionTrack;
142
143 return count+1;
144}
145
146//____________________________________________________________________
147void AliCorrection::Divide()
148{
149 //
150 // divide the histograms to get the correction
151 //
152
153 if (!fEventCorr || !fTrackCorr)
154 return;
155
156 fEventCorr->Divide();
157 fTrackCorr->Divide();
158
159 Int_t emptyBins = fTrackCorr->CheckEmptyBins(-9.99, 9.99, -0.79, 0.79, 0.3, 9.9);
160 printf("INFO: In the central region the track correction of %s has %d empty bins\n", GetName(), emptyBins);
161}
162
163//____________________________________________________________________
164Bool_t AliCorrection::LoadHistograms(const Char_t* dir)
165{
166 //
167 // loads the histograms from a file
168 // if dir is empty a directory with the name of this object is taken (like in SaveHistogram)
169 //
170
171 if (!fEventCorr || !fTrackCorr)
172 return kFALSE;
173
174 if (!dir)
175 dir = GetName();
176
177 if (!gDirectory->cd(dir))
178 return kFALSE;
179
180 Bool_t success = fEventCorr->LoadHistograms();
181 success &= fTrackCorr->LoadHistograms();
182
183 gDirectory->cd("..");
184
185 return success;
186}
187
188//____________________________________________________________________
189void AliCorrection::SaveHistograms()
190{
191 //
192 // saves the histograms in a directory with the name of this object (GetName)
193 //
194
195 gDirectory->mkdir(GetName());
196 gDirectory->cd(GetName());
197
198 if (fEventCorr)
199 fEventCorr->SaveHistograms();
200
201 if (fTrackCorr)
202 fTrackCorr->SaveHistograms();
203
204 gDirectory->cd("..");
205}
206
207//____________________________________________________________________
208void AliCorrection::ReduceInformation()
209{
210 // this function deletes the measured and generated histograms to reduce the amount of data
211 // in memory
212
213 if (!fEventCorr || !fTrackCorr)
214 return;
215
216 fEventCorr->ReduceInformation();
217 fTrackCorr->ReduceInformation();
218}
219
220//____________________________________________________________________
221void AliCorrection::Reset(Option_t* option)
222{
223 // resets the histograms
224
225 if (fEventCorr)
226 fEventCorr->Reset(option);
227
228 if (fTrackCorr)
229 fTrackCorr->Reset(option);
230}
231
232//____________________________________________________________________
233void AliCorrection::DrawHistograms(const Char_t* name)
234{
235 // draws the corrections
236
237 if (!name)
238 name = GetName();
239
240 if (fEventCorr)
241 fEventCorr->DrawHistograms(Form("%s event", name));
242
243 if (fTrackCorr)
244 fTrackCorr->DrawHistograms(Form("%s track", name));
245}
246
247//____________________________________________________________________
248void AliCorrection::SetCorrectionToUnity()
249{
250 // set the corrections to unity
251
252 if (fEventCorr)
253 fEventCorr->SetCorrectionToUnity();
254
255 if (fTrackCorr)
256 fTrackCorr->SetCorrectionToUnity();
257}
258
259//____________________________________________________________________
260void AliCorrection::Multiply()
261{
262 // call Multiply
263
264 if (fEventCorr)
265 {
266 fEventCorr->Multiply();
267 // now we manually copy the overflow bin of the y axis (multiplicity) over. This is important to get the event count correct
268 TH2F* hist = fEventCorr->GetMeasuredHistogram();
269 for (Int_t x = 1; x <= hist->GetNbinsX(); ++x)
270 fEventCorr->GetGeneratedHistogram()->SetBinContent(x, hist->GetNbinsY() + 1, hist->GetBinContent(x, hist->GetNbinsY() + 1));
271 }
272
273 if (fTrackCorr)
274 fTrackCorr->Multiply();
275}