removing checking of vertex resolution in getvertex
[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>
06e4b91b 12#include <TH3F.h>
29771dc8 13#include <TH2F.h>
14
15#include <AliLog.h>
16#include "AliCorrectionMatrix2D.h"
17#include "AliCorrectionMatrix3D.h"
18
19#include "AliCorrection.h"
20
21//____________________________________________________________________
22ClassImp(AliCorrection)
23
24//____________________________________________________________________
25AliCorrection::AliCorrection() : TNamed(),
26 fEventCorr(0),
27 fTrackCorr(0)
28{
29 // default constructor
30}
31
32//____________________________________________________________________
770a1f1d 33AliCorrection::AliCorrection(const Char_t* name, const Char_t* title, AliPWG0Helper::AnalysisMode analysisMode) : TNamed(name, title),
29771dc8 34 fEventCorr(0),
35 fTrackCorr(0)
36{
37 // constructor initializing tnamed
38
116083b1 39 Float_t* binLimitsPt = 0;
40 Int_t nBinsPt = 0;
41
42 // different binnings, better solution could be anticipated...
770a1f1d 43 if (analysisMode == AliPWG0Helper::kTPC || analysisMode == AliPWG0Helper::kTPCITS)
116083b1 44 {
45 static Float_t binLimitsPtTmp[] = {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};
46 binLimitsPt = (Float_t*) binLimitsPtTmp;
47 nBinsPt = 28;
745d6088 48 }
770a1f1d 49 else if (analysisMode == AliPWG0Helper::kSPD)
116083b1 50 {
7307d52c 51 static Float_t binLimitsPtTmp[] = {-0.5, 100.0};
116083b1 52 binLimitsPt = (Float_t*) binLimitsPtTmp;
53 nBinsPt = 1;
54 }
55
56 if (!binLimitsPt)
57 {
58 Printf("FATAL: Invalid binning");
59 return;
60 }
61
51f6de65 62 Int_t nBinsN2 = 1;
63 Float_t binLimitsN2[] = {-0.5, 1000};
64 //Int_t nBinsN2 = 21;
65 //Float_t binLimitsN2[] = {-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, 1000.5};
a67484a6 66 Int_t nBinsN = 22;
29771dc8 67 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};
a67484a6 68 //Int_t nBinsN = 52;
69 //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, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5, 25.5, 26.5, 27.5, 28.5, 29.5, 30.5, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5, 37.5, 38.5, 39.5, 40.5, 41.5, 42.5, 43.5, 44.5, 45.5, 46.5, 47.5, 48.5, 49.5, 50.5, 100.5, 300.5};
70
29771dc8 71 //Float_t binLimitsVtx[] = {-20,-15,-10,-6,-3,0,3,6,10,15,20};
083a636e 72 //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};
567160d6 73 Float_t binLimitsVtx[] = {-30,-25,-20,-15,-10,-8,-6,-4,-2,0,2,4,6,8,10,15,20,25,30};
74 Float_t binLimitsEta[] = {-3.0,-2.8,-2.6,-2.4,-2.2,
75 -2.0,-1.8,-1.6,-1.4,-1.2,
76 -1.0,-0.8,-0.6,-0.4,-0.2, 0.0,
77 0.2, 0.4, 0.6, 0.8, 1.0,
78 1.2, 1.4, 1.6, 1.8, 2.0,
79 2.2, 2.4, 2.6, 2.8, 3.0};
80// Float_t binLimitsEta[] = {-2,-1.8,-1.6,-1.4,-1.2,-1.0,-0.8,-0.6,-0.4,-0.2,0.0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0};
745d6088 81// Float_t binLimitsEta[] = {-2,-1.9,-1.8,-1.7,-1.6,-1.5,-1.4,-1.3,-1.2,-1.1,-1.0,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0};
447c325d 82// Float_t binLimitsEta[] = { -7.0, -6.9, -6.8, -6.7, -6.6, -6.5, -6.4, -6.3, -6.2, -6.1, -6.0, -5.9, -5.8, -5.7, -5.6, -5.5, -5.4, -5.3, -5.2, -5.1, -5.0, -4.9, -4.8, -4.7, -4.6, -4.5, -4.4, -4.3, -4.2, -4.1, -4.0, -3.9, -3.8, -3.7, -3.6, -3.5, -3.4, -3.3, -3.2, -3.1, -3.0, -2.9, -2.8, -2.7, -2.6, -2.5, -2.4, -2.3, -2.2, -2.1, -2.0, -1.9, -1.8, -1.7, -1.6, -1.5, -1.4, -1.3, -1.2, -1.1, -1.0, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7.0 };
06e4b91b 83
a67484a6 84 fEventCorr = new AliCorrectionMatrix2D("EventCorrection", Form("%s EventCorrection", fTitle.Data()), 18, binLimitsVtx, nBinsN, binLimitsN);
06e4b91b 85
51f6de65 86 if (analysisMode == AliPWG0Helper::kSPD)
87 {
88 TH3F* dummyBinning = new TH3F("dummyBinning","dummyBinning",18, binLimitsVtx, 30, binLimitsEta, nBinsN2, binLimitsN2);
89 fTrackCorr = new AliCorrectionMatrix3D("TrackCorrection", Form("%s TrackCorrection", fTitle.Data()), dummyBinning);
90 fTrackCorr->SetAxisTitles("vtx z [cm]", "#eta", "Ntracks");
91 delete dummyBinning;
92 }
93 else
94 {
95 TH3F* dummyBinning = new TH3F("dummyBinning","dummyBinning",18, binLimitsVtx, 30, binLimitsEta , nBinsPt, binLimitsPt);
96 fTrackCorr = new AliCorrectionMatrix3D("TrackCorrection", Form("%s TrackCorrection", fTitle.Data()), dummyBinning);
97 fTrackCorr->SetAxisTitles("vtx z [cm]", "#eta", "p_{T} [GeV/c]");
98 delete dummyBinning;
99 }
100
29771dc8 101
102 fEventCorr->SetAxisTitles("vtx z [cm]", "Ntracks");
29771dc8 103}
104
105//____________________________________________________________________
106AliCorrection::AliCorrection(const AliCorrection& c) : TNamed(c),
107 fEventCorr(0),
108 fTrackCorr(0)
109{
110 // copy constructor
111 ((AliCorrection &)c).Copy(*this);
112}
113
114//____________________________________________________________________
115AliCorrection::~AliCorrection()
116{
117 //
118 // destructor
119 //
120
121 if (fEventCorr)
122 {
123 delete fEventCorr;
124 fEventCorr = 0;
125 }
126
127 if (fTrackCorr)
128 {
129 delete fTrackCorr;
130 fTrackCorr = 0;
131 }
132}
133
134//____________________________________________________________________
135AliCorrection &AliCorrection::operator=(const AliCorrection &c)
136{
137 // assigment operator
138
139 if (this != &c)
140 ((AliCorrection &) c).Copy(*this);
141
142 return *this;
143}
144
145//____________________________________________________________________
146void AliCorrection::Copy(TObject& c) const
147{
148 // copy function
149
150 AliCorrection& target = (AliCorrection &) c;
151
152 if (fEventCorr)
153 target.fEventCorr = dynamic_cast<AliCorrectionMatrix2D*> (fEventCorr->Clone());
154
155 if (fTrackCorr)
156 target.fTrackCorr = dynamic_cast<AliCorrectionMatrix3D*> (fTrackCorr->Clone());
157}
158
159//____________________________________________________________________
160Long64_t AliCorrection::Merge(TCollection* list)
161{
162 // Merge a list of AliCorrection objects with this (needed for
163 // PROOF).
164 // Returns the number of merged objects (including this).
165
166 if (!list)
167 return 0;
168
169 if (list->IsEmpty())
170 return 1;
171
172 TIterator* iter = list->MakeIterator();
173 TObject* obj;
174
175 // collections of measured and generated histograms
176 TList* collectionEvent = new TList;
177 TList* collectionTrack = new TList;
178
179 Int_t count = 0;
180 while ((obj = iter->Next())) {
181
182 AliCorrection* entry = dynamic_cast<AliCorrection*> (obj);
183 if (entry == 0)
184 continue;
185
186 collectionEvent->Add(entry->fEventCorr);
187 collectionTrack->Add(entry->fTrackCorr);
188
189 count++;
190 }
191 fEventCorr->Merge(collectionEvent);
192 fTrackCorr->Merge(collectionTrack);
193
194 delete collectionEvent;
195 delete collectionTrack;
196
197 return count+1;
198}
199
200//____________________________________________________________________
201void AliCorrection::Divide()
202{
203 //
204 // divide the histograms to get the correction
205 //
206
207 if (!fEventCorr || !fTrackCorr)
208 return;
209
210 fEventCorr->Divide();
211 fTrackCorr->Divide();
212
dd367a14 213 Int_t emptyBins = fTrackCorr->CheckEmptyBins(-9.99, 9.99, -0.79, 0.79, 0.3, 4.9);
29771dc8 214 printf("INFO: In the central region the track correction of %s has %d empty bins\n", GetName(), emptyBins);
215}
216
217//____________________________________________________________________
2e88424e 218void AliCorrection::Add(AliCorrection* aCorrectionToAdd, Float_t c)
219{
220 //
221 // add to measured and generated the measured and generated of aCorrectionToAdd
222 // with the weight c
223
224 fEventCorr->Add(aCorrectionToAdd->GetEventCorrection(),c);
225 fTrackCorr->Add(aCorrectionToAdd->GetTrackCorrection(),c);
226}
227
228
229//____________________________________________________________________
29771dc8 230Bool_t AliCorrection::LoadHistograms(const Char_t* dir)
231{
232 //
233 // loads the histograms from a file
234 // if dir is empty a directory with the name of this object is taken (like in SaveHistogram)
235 //
236
237 if (!fEventCorr || !fTrackCorr)
238 return kFALSE;
239
240 if (!dir)
241 dir = GetName();
242
243 if (!gDirectory->cd(dir))
244 return kFALSE;
245
246 Bool_t success = fEventCorr->LoadHistograms();
247 success &= fTrackCorr->LoadHistograms();
248
249 gDirectory->cd("..");
250
251 return success;
252}
253
254//____________________________________________________________________
255void AliCorrection::SaveHistograms()
256{
257 //
258 // saves the histograms in a directory with the name of this object (GetName)
259 //
260
261 gDirectory->mkdir(GetName());
262 gDirectory->cd(GetName());
263
264 if (fEventCorr)
265 fEventCorr->SaveHistograms();
266
267 if (fTrackCorr)
268 fTrackCorr->SaveHistograms();
269
270 gDirectory->cd("..");
271}
272
273//____________________________________________________________________
274void AliCorrection::ReduceInformation()
275{
276 // this function deletes the measured and generated histograms to reduce the amount of data
277 // in memory
278
279 if (!fEventCorr || !fTrackCorr)
280 return;
281
282 fEventCorr->ReduceInformation();
283 fTrackCorr->ReduceInformation();
284}
285
286//____________________________________________________________________
287void AliCorrection::Reset(Option_t* option)
288{
289 // resets the histograms
290
291 if (fEventCorr)
292 fEventCorr->Reset(option);
293
294 if (fTrackCorr)
295 fTrackCorr->Reset(option);
296}
297
298//____________________________________________________________________
299void AliCorrection::DrawHistograms(const Char_t* name)
300{
301 // draws the corrections
302
303 if (!name)
304 name = GetName();
305
306 if (fEventCorr)
307 fEventCorr->DrawHistograms(Form("%s event", name));
308
309 if (fTrackCorr)
310 fTrackCorr->DrawHistograms(Form("%s track", name));
311}
312
dd367a14 313void AliCorrection::DrawOverview(const char* canvasName)
314{
315 // draw projection of the corrections
316 // to the 3 axis of fTrackCorr and 2 axis of fEventCorr
317
318 TString canvasNameTmp(GetName());
319 if (canvasName)
320 canvasNameTmp = canvasName;
321
322 TCanvas* canvas = new TCanvas(canvasNameTmp, canvasNameTmp, 1200, 800);
323 canvas->Divide(3, 2);
324
325 if (fTrackCorr) {
326 canvas->cd(1);
327 fTrackCorr->Get1DCorrectionHistogram("x", 0.3, 5, -1, 1)->DrawCopy()->GetYaxis()->SetRangeUser(0, 10);
328
329 canvas->cd(2);
330 fTrackCorr->Get1DCorrectionHistogram("y", 0.3, 5, 0, 0)->DrawCopy()->GetYaxis()->SetRangeUser(0, 10);
331
332 canvas->cd(3);
333 fTrackCorr->Get1DCorrectionHistogram("z", 0, -1, -1, 1)->DrawCopy()->GetYaxis()->SetRangeUser(0, 10);
334 }
335
336 if (fEventCorr)
337 {
338 canvas->cd(4);
339 fEventCorr->Get1DCorrectionHistogram("x")->DrawCopy();
340
341 canvas->cd(5);
342 fEventCorr->Get1DCorrectionHistogram("y")->DrawCopy()->GetXaxis()->SetRangeUser(0, 30);
343 }
344}
345
29771dc8 346//____________________________________________________________________
347void AliCorrection::SetCorrectionToUnity()
348{
349 // set the corrections to unity
350
351 if (fEventCorr)
352 fEventCorr->SetCorrectionToUnity();
353
354 if (fTrackCorr)
355 fTrackCorr->SetCorrectionToUnity();
356}
357
358//____________________________________________________________________
359void AliCorrection::Multiply()
360{
361 // call Multiply
362
363 if (fEventCorr)
364 {
365 fEventCorr->Multiply();
366 // now we manually copy the overflow bin of the y axis (multiplicity) over. This is important to get the event count correct
5a6310fe 367 TH2* hist = fEventCorr->GetMeasuredHistogram();
29771dc8 368 for (Int_t x = 1; x <= hist->GetNbinsX(); ++x)
369 fEventCorr->GetGeneratedHistogram()->SetBinContent(x, hist->GetNbinsY() + 1, hist->GetBinContent(x, hist->GetNbinsY() + 1));
370 }
371
372 if (fTrackCorr)
373 fTrackCorr->Multiply();
374}
dd367a14 375
376//____________________________________________________________________
377void AliCorrection::Scale(Double_t factor)
378{
379 // scales the two contained corrections
380
381 fEventCorr->Scale(factor);
382 fTrackCorr->Scale(factor);
383}
384
385//____________________________________________________________________
1c15d51a 386void AliCorrection::PrintStats(Float_t zRange, Float_t etaRange, Float_t ptCut)
dd367a14 387{
1c15d51a 388 // prints statistics and effective correction factors
389
390 Printf("AliCorrection::PrintInfo: Values in |eta| < %.2f, |vtx-z| < %.2f and pt > %.2f:", etaRange, zRange, ptCut);
391
392 // prevent to be on bin border
393 zRange -= 0.1;
394 etaRange -= 0.1;
dd367a14 395
396 TH3* measured = GetTrackCorrection()->GetMeasuredHistogram();
397 TH3* generated = GetTrackCorrection()->GetGeneratedHistogram();
398
399 TH2* measuredEvents = GetEventCorrection()->GetMeasuredHistogram();
400 TH2* generatedEvents = GetEventCorrection()->GetGeneratedHistogram();
401
1c15d51a 402 Float_t tracksM = measured->Integral(measured->GetXaxis()->FindBin(-zRange), measured->GetXaxis()->FindBin(zRange), measured->GetYaxis()->FindBin(-etaRange), measured->GetYaxis()->FindBin(etaRange), measured->GetZaxis()->FindBin(ptCut), measured->GetZaxis()->GetNbins());
403 Float_t tracksG = generated->Integral(generated->GetXaxis()->FindBin(-zRange), generated->GetXaxis()->FindBin(zRange), generated->GetYaxis()->FindBin(-etaRange), generated->GetYaxis()->FindBin(etaRange), generated->GetZaxis()->FindBin(ptCut), generated->GetZaxis()->GetNbins());
dd367a14 404
1c15d51a 405 Float_t eventsM = measuredEvents->Integral(measuredEvents->GetXaxis()->FindBin(-zRange), measuredEvents->GetXaxis()->FindBin(zRange), 1, measuredEvents->GetNbinsY());
406 Float_t eventsG = generatedEvents->Integral(generatedEvents->GetXaxis()->FindBin(-zRange), generatedEvents->GetXaxis()->FindBin(zRange), 1, generatedEvents->GetNbinsY());
3dfa46a4 407
745d6088 408 Printf("tracks measured: %.1f tracks generated: %.1f, events measured: %.1f, events generated %.1f", tracksM, tracksG, eventsM, eventsG);
dd367a14 409
3dfa46a4 410 if (tracksM > 0)
411 Printf("Effective average correction factor for TRACKS: %.3f", tracksG / tracksM);
412 if (eventsM > 0)
1c15d51a 413 Printf("Effective average correction factor for EVENTS: %.3f", eventsG / eventsM);
dd367a14 414
3dfa46a4 415 if (eventsM > 0 && eventsG > 0)
416 {
417 // normalize to number of events;
418 tracksM /= eventsM;
419 tracksG /= eventsG;
420
51f6de65 421 Printf("%.2f tracks/event measured, %.2f tracks/event after correction --> effective average correction factor is %.3f (pt cut %.2f GeV/c)", tracksM, tracksG, (tracksM > 0) ? (tracksG / tracksM) : -1, ptCut);
3dfa46a4 422 }
dd367a14 423}
1c15d51a 424
425//____________________________________________________________________
426void AliCorrection::PrintInfo(Float_t ptCut)
427{
428 // prints some stats
429
430 TH3* measured = GetTrackCorrection()->GetMeasuredHistogram();
431 TH3* generated = GetTrackCorrection()->GetGeneratedHistogram();
432
433 TH2* measuredEvents = GetEventCorrection()->GetMeasuredHistogram();
434 TH2* generatedEvents = GetEventCorrection()->GetGeneratedHistogram();
435
436 Printf("AliCorrection::PrintInfo: Whole phasespace:");
437
438 Printf("tracks measured: %.1f tracks generated: %.1f, events measured: %.1f, events generated %.1f", measured->Integral(), generated->Integral(), measuredEvents->Integral(), generatedEvents->Integral());
439
51f6de65 440 Printf("Example centered bin: tracks measured: %.1f tracks generated: %.1f, events measured: %.1f, events generated %.1f", measured->GetBinContent(measured->GetNbinsX() / 2, measured->GetNbinsY() / 2, measured->GetNbinsZ() / 2), generated->GetBinContent(measured->GetNbinsX() / 2, measured->GetNbinsY() / 2, measured->GetNbinsZ() / 2), measuredEvents->GetBinContent(measuredEvents->GetNbinsX() / 2, measuredEvents->GetNbinsY() / 2), generatedEvents->GetBinContent(measuredEvents->GetNbinsX() / 2, measuredEvents->GetNbinsY() / 2));
441
1c15d51a 442 PrintStats(10, 1.0, ptCut);
443 PrintStats(10, 1.5, ptCut);
444}