Update
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AlidNdEtaCorrection.cxx
CommitLineData
d560b581 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
55e05544 16/* $Id$ */
17
18#include "AlidNdEtaCorrection.h"
19
74fd10b3 20#include <AliLog.h>
55e05544 21#include <TCanvas.h>
847489f7 22#include <TH3F.h>
47ab1f70 23#include <TH2F.h>
847489f7 24#include <TH1D.h>
d560b581 25#include <TDirectory.h>
74fd10b3 26#include <AliCorrection.h>
27#include <AliCorrectionMatrix2D.h>
28#include <AliCorrectionMatrix3D.h>
55e05544 29
30//____________________________________________________________________
31ClassImp(AlidNdEtaCorrection)
32
33//____________________________________________________________________
8b3563f4 34AlidNdEtaCorrection::AlidNdEtaCorrection()
35 : TNamed(),
36 fTrack2ParticleCorrection(0),
37 fVertexRecoCorrection(0),
7584d357 38 fTriggerBiasCorrectionMBToINEL(0),
39 fTriggerBiasCorrectionMBToNSD(0),
81be4ee8 40 fTriggerBiasCorrectionMBToND(0),
41 fTriggerBiasCorrectionMBToOnePart(0)
8b3563f4 42{
43 // default constructor
44}
45
46//____________________________________________________________________
770a1f1d 47AlidNdEtaCorrection::AlidNdEtaCorrection(const Char_t* name, const Char_t* title, AliPWG0Helper::AnalysisMode analysis)
8b3563f4 48 : TNamed(name, title),
38233af1 49 fTrack2ParticleCorrection(0),
50 fVertexRecoCorrection(0),
7584d357 51 fTriggerBiasCorrectionMBToINEL(0),
52 fTriggerBiasCorrectionMBToNSD(0),
81be4ee8 53 fTriggerBiasCorrectionMBToND(0),
54 fTriggerBiasCorrectionMBToOnePart(0)
8b3563f4 55{
74fd10b3 56 //
55e05544 57 // constructor
58 //
59
0f67a57c 60 fTrack2ParticleCorrection = new AliCorrection("Track2Particle", "Track2Particle", analysis);
61 fVertexRecoCorrection = new AliCorrection("VertexReconstruction", "VertexReconstruction", analysis);
1afae8ff 62
0f67a57c 63 fTriggerBiasCorrectionMBToINEL = new AliCorrection("TriggerBias_MBToINEL", "TriggerBias_MBToINEL", analysis);
64 fTriggerBiasCorrectionMBToNSD = new AliCorrection("TriggerBias_MBToNSD", "TriggerBias_MBToNSD", analysis);
65 fTriggerBiasCorrectionMBToND = new AliCorrection("TriggerBias_MBToND", "TriggerBias_MBToND", analysis);
81be4ee8 66 fTriggerBiasCorrectionMBToOnePart = new AliCorrection("TriggerBias_MBToOnePart", "TriggerBias_MBToOnePart", analysis);
55e05544 67}
68
69//____________________________________________________________________
38233af1 70AlidNdEtaCorrection::~AlidNdEtaCorrection()
71{
72 // destructor
73
7584d357 74 if (fTrack2ParticleCorrection) {
38233af1 75 delete fTrack2ParticleCorrection;
76 fTrack2ParticleCorrection = 0;
77 }
78
7584d357 79 if (fVertexRecoCorrection) {
38233af1 80 delete fVertexRecoCorrection;
81 fVertexRecoCorrection = 0;
82 }
83
7584d357 84 if (fTriggerBiasCorrectionMBToINEL) {
85 delete fTriggerBiasCorrectionMBToINEL;
86 fTriggerBiasCorrectionMBToINEL = 0;
38233af1 87 }
88
7584d357 89 if (fTriggerBiasCorrectionMBToNSD) {
90 delete fTriggerBiasCorrectionMBToNSD;
91 fTriggerBiasCorrectionMBToNSD = 0;
92 }
93
94 if (fTriggerBiasCorrectionMBToND) {
95 delete fTriggerBiasCorrectionMBToND;
96 fTriggerBiasCorrectionMBToND = 0;
38233af1 97 }
81be4ee8 98
99 if (fTriggerBiasCorrectionMBToOnePart) {
100 delete fTriggerBiasCorrectionMBToOnePart;
101 fTriggerBiasCorrectionMBToOnePart = 0;
102 }
38233af1 103}
104
105//____________________________________________________________________
55e05544 106void
45e97e28 107AlidNdEtaCorrection::Finish() {
55e05544 108 //
109 // finish method
110 //
45e97e28 111 // divide the histograms in the AliCorrectionMatrix2D objects to get the corrections
55e05544 112
45e97e28 113 fTrack2ParticleCorrection->Divide();
55e05544 114 fVertexRecoCorrection->Divide();
7584d357 115 fTriggerBiasCorrectionMBToINEL->Divide();
116 fTriggerBiasCorrectionMBToNSD->Divide();
117 fTriggerBiasCorrectionMBToND->Divide();
81be4ee8 118 fTriggerBiasCorrectionMBToOnePart->Divide();
55e05544 119}
120
121//____________________________________________________________________
74fd10b3 122Long64_t AlidNdEtaCorrection::Merge(TCollection* list)
123{
55e05544 124 // Merge a list of dNdEtaCorrection objects with this (needed for
7af955da 125 // PROOF).
55e05544 126 // Returns the number of merged objects (including this).
127
128 if (!list)
129 return 0;
7af955da 130
55e05544 131 if (list->IsEmpty())
132 return 1;
133
134 TIterator* iter = list->MakeIterator();
135 TObject* obj;
136
137 // collections of measured and generated histograms
7584d357 138 TList* collectionNtrackToNparticle = new TList;
139 TList* collectionVertexReco = new TList;
140 TList* collectionTriggerBiasMBToINEL = new TList;
141 TList* collectionTriggerBiasMBToNSD = new TList;
142 TList* collectionTriggerBiasMBToND = new TList;
81be4ee8 143 TList* collectionTriggerBiasMBToOnePart = new TList;
55e05544 144
145 Int_t count = 0;
146 while ((obj = iter->Next())) {
7af955da 147
55e05544 148 AlidNdEtaCorrection* entry = dynamic_cast<AlidNdEtaCorrection*> (obj);
7af955da 149 if (entry == 0)
55e05544 150 continue;
151
74fd10b3 152 collectionNtrackToNparticle ->Add(entry->fTrack2ParticleCorrection);
153 collectionVertexReco ->Add(entry->fVertexRecoCorrection);
154 collectionTriggerBiasMBToINEL->Add(entry->fTriggerBiasCorrectionMBToINEL);
155 collectionTriggerBiasMBToNSD ->Add(entry->fTriggerBiasCorrectionMBToNSD);
156 collectionTriggerBiasMBToND ->Add(entry->fTriggerBiasCorrectionMBToND);
81be4ee8 157 collectionTriggerBiasMBToOnePart ->Add(entry->fTriggerBiasCorrectionMBToOnePart);
55e05544 158
159 count++;
160 }
7584d357 161 fTrack2ParticleCorrection ->Merge(collectionNtrackToNparticle);
162 fVertexRecoCorrection ->Merge(collectionVertexReco);
163 fTriggerBiasCorrectionMBToINEL ->Merge(collectionTriggerBiasMBToINEL);
164 fTriggerBiasCorrectionMBToNSD ->Merge(collectionTriggerBiasMBToNSD);
165 fTriggerBiasCorrectionMBToND ->Merge(collectionTriggerBiasMBToND);
81be4ee8 166 fTriggerBiasCorrectionMBToOnePart->Merge(collectionTriggerBiasMBToOnePart);
10ebe68d 167
55e05544 168 delete collectionNtrackToNparticle;
169 delete collectionVertexReco;
7584d357 170 delete collectionTriggerBiasMBToINEL;
171 delete collectionTriggerBiasMBToNSD;
172 delete collectionTriggerBiasMBToND;
81be4ee8 173 delete collectionTriggerBiasMBToOnePart;
10ebe68d 174
55e05544 175 return count+1;
176}
177
55e05544 178//____________________________________________________________________
2e88424e 179void AlidNdEtaCorrection::Add(AlidNdEtaCorrection* aCorrectionsToAdd, Float_t c) {
180 //
181 // adds the measured and generated of aCorrectionsToAdd to measured and generated
182 // of all corrections in this
183
184 fTrack2ParticleCorrection ->Add(aCorrectionsToAdd->GetTrack2ParticleCorrection() ,c);
185 fVertexRecoCorrection ->Add(aCorrectionsToAdd->GetVertexRecoCorrection() ,c);
186 fTriggerBiasCorrectionMBToINEL ->Add(aCorrectionsToAdd->GetTriggerBiasCorrectionINEL(),c);
187 fTriggerBiasCorrectionMBToNSD ->Add(aCorrectionsToAdd->GetTriggerBiasCorrectionNSD() ,c);
188 fTriggerBiasCorrectionMBToND ->Add(aCorrectionsToAdd->GetTriggerBiasCorrectionND() ,c);
81be4ee8 189 fTriggerBiasCorrectionMBToOnePart ->Add(aCorrectionsToAdd->GetTriggerBiasCorrectionOnePart() ,c);
190}
191
192//____________________________________________________________________
193void AlidNdEtaCorrection::Scale(Float_t c)
194{
195 //
196 // scales all contained corrections
197 //
198
199 fTrack2ParticleCorrection ->Scale(c);
200 fVertexRecoCorrection ->Scale(c);
201 fTriggerBiasCorrectionMBToINEL ->Scale(c);
202 fTriggerBiasCorrectionMBToNSD ->Scale(c);
203 fTriggerBiasCorrectionMBToND ->Scale(c);
204 fTriggerBiasCorrectionMBToOnePart ->Scale(c);
2e88424e 205}
206
207//____________________________________________________________________
208void AlidNdEtaCorrection::Reset(void) {
209 //
210 // reset all corrections
211 //
212
213 fTrack2ParticleCorrection ->Reset();
214 fVertexRecoCorrection ->Reset();
215 fTriggerBiasCorrectionMBToINEL ->Reset();
216 fTriggerBiasCorrectionMBToNSD ->Reset();
217 fTriggerBiasCorrectionMBToND ->Reset();
81be4ee8 218 fTriggerBiasCorrectionMBToOnePart ->Reset();
2e88424e 219}
220
221
222
223//____________________________________________________________________
74fd10b3 224Bool_t AlidNdEtaCorrection::LoadHistograms(const Char_t* dir)
225{
55e05544 226 //
227 // loads the histograms
74fd10b3 228 // if dir is empty a directory with the name of this object is taken (like in SaveHistogram)
55e05544 229 //
230
74fd10b3 231 if (!dir)
232 dir = GetName();
7584d357 233
74fd10b3 234 if (!gDirectory->cd(dir))
235 return kFALSE;
236
237 fTrack2ParticleCorrection ->LoadHistograms();
238 fVertexRecoCorrection ->LoadHistograms();
239 fTriggerBiasCorrectionMBToINEL ->LoadHistograms();
240 fTriggerBiasCorrectionMBToNSD ->LoadHistograms();
241 fTriggerBiasCorrectionMBToND ->LoadHistograms();
81be4ee8 242 fTriggerBiasCorrectionMBToOnePart ->LoadHistograms();
74fd10b3 243
244 gDirectory->cd("..");
1afae8ff 245
55e05544 246 return kTRUE;
247}
248
55e05544 249//____________________________________________________________________
74fd10b3 250void AlidNdEtaCorrection::SaveHistograms()
251{
55e05544 252 //
253 // save the histograms
254 //
255
256 gDirectory->mkdir(fName.Data());
257 gDirectory->cd(fName.Data());
258
7584d357 259 fTrack2ParticleCorrection ->SaveHistograms();
260 fVertexRecoCorrection ->SaveHistograms();
261 fTriggerBiasCorrectionMBToINEL->SaveHistograms();
262 fTriggerBiasCorrectionMBToNSD ->SaveHistograms();
263 fTriggerBiasCorrectionMBToND ->SaveHistograms();
81be4ee8 264 fTriggerBiasCorrectionMBToOnePart->SaveHistograms();
55e05544 265
74fd10b3 266 gDirectory->cd("..");
55e05544 267}
268
269//____________________________________________________________________
270void AlidNdEtaCorrection::DrawHistograms()
271{
272 //
dd367a14 273 // call the draw histogram method of the corrections
74fd10b3 274 //
55e05544 275
7584d357 276 fTrack2ParticleCorrection ->DrawHistograms();
277 fVertexRecoCorrection ->DrawHistograms();
278 fTriggerBiasCorrectionMBToINEL->DrawHistograms();
279 fTriggerBiasCorrectionMBToNSD ->DrawHistograms();
280 fTriggerBiasCorrectionMBToND ->DrawHistograms();
81be4ee8 281 fTriggerBiasCorrectionMBToOnePart ->DrawHistograms();
7584d357 282}
283
284//____________________________________________________________________
dd367a14 285void AlidNdEtaCorrection::DrawOverview(const char* canvasName)
286{
287 //
288 // call the DrawOverview histogram method of the corrections
289 //
290
291 fTrack2ParticleCorrection ->DrawOverview(canvasName);
292 fVertexRecoCorrection ->DrawOverview(canvasName);
293 fTriggerBiasCorrectionMBToINEL->DrawOverview(canvasName);
294 fTriggerBiasCorrectionMBToNSD ->DrawOverview(canvasName);
295 fTriggerBiasCorrectionMBToND ->DrawOverview(canvasName);
81be4ee8 296 fTriggerBiasCorrectionMBToOnePart ->DrawOverview(canvasName);
dd367a14 297}
298
299//____________________________________________________________________
74fd10b3 300void AlidNdEtaCorrection::FillMCParticle(Float_t vtx, Float_t eta, Float_t pt, Bool_t trigger, Bool_t vertex, Int_t processType)
7584d357 301{
74fd10b3 302 // fills a particle in the corrections
303 // it is filled in generated or measured depending of the flags
7584d357 304
74fd10b3 305 fTriggerBiasCorrectionMBToINEL->GetTrackCorrection()->FillGene(vtx, eta, pt);
7584d357 306
81be4ee8 307 if ((processType & AliPWG0Helper::kSD) == 0)
74fd10b3 308 fTriggerBiasCorrectionMBToNSD->GetTrackCorrection()->FillGene(vtx, eta, pt);
309
81be4ee8 310 if (processType & AliPWG0Helper::kND )
74fd10b3 311 fTriggerBiasCorrectionMBToND->GetTrackCorrection()->FillGene(vtx, eta, pt);
312
81be4ee8 313 if (processType & AliPWG0Helper::kOnePart)
314 fTriggerBiasCorrectionMBToOnePart->GetTrackCorrection()->FillGene(vtx, eta, pt);
315
74fd10b3 316 if (!trigger)
317 return;
318
319 fTriggerBiasCorrectionMBToINEL->GetTrackCorrection()->FillMeas(vtx, eta, pt);
320 fTriggerBiasCorrectionMBToNSD->GetTrackCorrection()->FillMeas(vtx, eta, pt);
321 fTriggerBiasCorrectionMBToND->GetTrackCorrection()->FillMeas(vtx, eta, pt);
81be4ee8 322 fTriggerBiasCorrectionMBToOnePart->GetTrackCorrection()->FillMeas(vtx, eta, pt);
74fd10b3 323 fVertexRecoCorrection->GetTrackCorrection()->FillGene(vtx, eta, pt);
324
325 if (!vertex)
326 return;
327
328 fVertexRecoCorrection->GetTrackCorrection()->FillMeas(vtx, eta, pt);
329 fTrack2ParticleCorrection->GetTrackCorrection()->FillGene(vtx, eta, pt);
7584d357 330}
55e05544 331
7584d357 332//____________________________________________________________________
68fa248f 333void AlidNdEtaCorrection::FillTrackedParticle(Float_t vtx, Float_t eta, Float_t pt, Double_t weight)
7584d357 334{
74fd10b3 335 // fills a tracked particle in the corrections
336
68fa248f 337 fTrack2ParticleCorrection->GetTrackCorrection()->FillMeas(vtx, eta, pt, weight);
55e05544 338}
847489f7 339
340//____________________________________________________________________
74fd10b3 341void AlidNdEtaCorrection::FillEvent(Float_t vtx, Float_t n, Bool_t trigger, Bool_t vertex, Int_t processType)
7584d357 342{
74fd10b3 343 // fills an event int he correction
344 // it is filled in generated or measured depending of the flags
345
346 fTriggerBiasCorrectionMBToINEL->GetEventCorrection()->FillGene(vtx, n);
347
81be4ee8 348 if ((processType & AliPWG0Helper::kSD) == 0)
74fd10b3 349 fTriggerBiasCorrectionMBToNSD->GetEventCorrection()->FillGene(vtx, n);
7584d357 350
81be4ee8 351 if (processType & AliPWG0Helper::kND )
74fd10b3 352 fTriggerBiasCorrectionMBToND->GetEventCorrection()->FillGene(vtx, n);
353
81be4ee8 354 if (processType & AliPWG0Helper::kOnePart)
355 fTriggerBiasCorrectionMBToOnePart->GetEventCorrection()->FillGene(vtx, n);
356
74fd10b3 357 if (!trigger)
358 return;
359
360 fTriggerBiasCorrectionMBToINEL->GetEventCorrection()->FillMeas(vtx, n);
361 fTriggerBiasCorrectionMBToNSD->GetEventCorrection()->FillMeas(vtx, n);
362 fTriggerBiasCorrectionMBToND->GetEventCorrection()->FillMeas(vtx, n);
81be4ee8 363 fTriggerBiasCorrectionMBToOnePart->GetEventCorrection()->FillMeas(vtx, n);
74fd10b3 364 fVertexRecoCorrection->GetEventCorrection()->FillGene(vtx, n);
365
366 if (!vertex)
367 return;
368
369 fVertexRecoCorrection->GetEventCorrection()->FillMeas(vtx, n);
370}
7584d357 371
372//____________________________________________________________________
c17301f3 373Float_t AlidNdEtaCorrection::GetMeasuredFraction(CorrectionType correctionType, Float_t ptCutOff, Float_t eta, Int_t vertexBegin, Int_t vertexEnd, Bool_t debug)
847489f7 374{
375 // calculates the fraction of particles measured (some are missed due to the pt cut off)
74fd10b3 376 //
377 // uses the generated particle histogram from the correction passed, e.g. pass GetTrack2ParticleCorrection()
847489f7 378
0448e811 379 if (!GetCorrection(correctionType))
380 return -1;
381
5a6310fe 382 const TH3* generated = GetCorrection(correctionType)->GetTrackCorrection()->GetGeneratedHistogram();
847489f7 383
384 // find eta borders, if eta is negative assume -0.8 ... 0.8
385 Int_t etaBegin = 0;
386 Int_t etaEnd = 0;
72e597d7 387 if (eta < -99)
847489f7 388 {
389 etaBegin = generated->GetYaxis()->FindBin(-0.8);
390 etaEnd = generated->GetYaxis()->FindBin(0.8);
391 }
392 else
393 {
394 etaBegin = generated->GetYaxis()->FindBin(eta);
395 etaEnd = etaBegin;
396 }
397
c17301f3 398 if (vertexBegin == -1)
399 vertexBegin = generated->GetXaxis()->FindBin(-9.99);
400
401 if (vertexEnd == -1)
402 vertexEnd = generated->GetXaxis()->FindBin(9.99);
847489f7 403
92d2d8ad 404 TH1D* ptProj = dynamic_cast<TH1D*> (generated->ProjectionZ(Form("%s_pt", generated->GetName()), vertexBegin, vertexEnd, etaBegin, etaEnd));
b4b9cacc 405 //printf("GetMeasuredFraction: bin range %d %d %d %d\n", vertexBegin, vertexEnd, etaBegin, etaEnd);
1afae8ff 406 ptProj->GetXaxis()->SetTitle(generated->GetZaxis()->GetTitle());
847489f7 407
408 Int_t ptBin = ptProj->FindBin(ptCutOff);
b4b9cacc 409 //printf("GetMeasuredFraction: bin range %d %d\n", ptBin, ptProj->GetNbinsX());
7307d52c 410 Float_t abovePtCut = ptProj->Integral(ptBin, ptProj->GetNbinsX()+1);
411 Float_t all = ptProj->Integral(1, ptProj->GetNbinsX()+1);
847489f7 412
413 if (all == 0)
414 return -1;
415
416 Float_t fraction = abovePtCut / all;
417
b4b9cacc 418 //printf("GetMeasuredFraction: all %f above %f fraction %f\n", all, abovePtCut, fraction);
74fd10b3 419
847489f7 420 if (debug)
421 {
422 new TCanvas;
423 ptProj->Draw();
424 }
92d2d8ad 425 else
426 delete ptProj;
847489f7 427
72e597d7 428 if (debug)
429 printf("AlidNdEtaCorrection::GetMeasuredFraction: pt cut off = %f, eta = %f, => fraction = %f\n", ptCutOff, eta, fraction);
430
847489f7 431 return fraction;
432}
433
74fd10b3 434//____________________________________________________________________
3dfa46a4 435TH1* AlidNdEtaCorrection::GetMeasuredEventFraction(CorrectionType correctionType, Int_t multCut)
436{
437 // calculates the fraction of events above multCut (but including it)
438 //
439 // uses the generated event histogram from the correction passed, e.g. pass GetTrack2ParticleCorrection()
440
441 if (!GetCorrection(correctionType))
442 return 0;
443
5a6310fe 444 const TH2* generated = GetCorrection(correctionType)->GetEventCorrection()->GetGeneratedHistogram();
3dfa46a4 445
446 TH1* allEvents = generated->ProjectionX(Form("%s_all", generated->GetName()), 1, generated->GetNbinsY());
447 TH1* aboveEvents = generated->ProjectionX(Form("%s_above", generated->GetName()), generated->GetYaxis()->FindBin(multCut), generated->GetNbinsY());
448
449 aboveEvents->Divide(aboveEvents, allEvents, 1, 1, "B");
450
451 return aboveEvents;
452}
453
454//____________________________________________________________________
0ab29cfa 455void AlidNdEtaCorrection::ReduceInformation()
456{
457 // this function deletes the measured and generated histograms from the corrections to reduce the amount of data
458 // in memory
459
460 // these are needed for GetMeasuredFraction(): fTrack2ParticleCorrection->ReduceInformation();
7584d357 461 fVertexRecoCorrection ->ReduceInformation();
462 fTriggerBiasCorrectionMBToINEL ->ReduceInformation();
463 fTriggerBiasCorrectionMBToNSD ->ReduceInformation();
464 fTriggerBiasCorrectionMBToND ->ReduceInformation();
81be4ee8 465 fTriggerBiasCorrectionMBToOnePart ->ReduceInformation();
0ab29cfa 466}
7af955da 467
0448e811 468//____________________________________________________________________
469AliCorrection* AlidNdEtaCorrection::GetCorrection(CorrectionType correctionType)
470{
471 // returns the given correction
472
473 switch (correctionType)
474 {
475 case kNone : return 0;
476 case kTrack2Particle : return fTrack2ParticleCorrection;
477 case kVertexReco : return fVertexRecoCorrection;
478 case kINEL : return fTriggerBiasCorrectionMBToINEL;
479 case kNSD : return fTriggerBiasCorrectionMBToNSD;
480 case kND : return fTriggerBiasCorrectionMBToND;
81be4ee8 481 case kOnePart : return fTriggerBiasCorrectionMBToOnePart;
0448e811 482 }
483
484 return 0;
485}