Including TH2F.h
[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),
40 fTriggerBiasCorrectionMBToND(0)
8b3563f4 41{
42 // default constructor
43}
44
45//____________________________________________________________________
770a1f1d 46AlidNdEtaCorrection::AlidNdEtaCorrection(const Char_t* name, const Char_t* title, AliPWG0Helper::AnalysisMode analysis)
8b3563f4 47 : TNamed(name, title),
38233af1 48 fTrack2ParticleCorrection(0),
49 fVertexRecoCorrection(0),
7584d357 50 fTriggerBiasCorrectionMBToINEL(0),
51 fTriggerBiasCorrectionMBToNSD(0),
52 fTriggerBiasCorrectionMBToND(0)
8b3563f4 53{
74fd10b3 54 //
55e05544 55 // constructor
56 //
57
0f67a57c 58 fTrack2ParticleCorrection = new AliCorrection("Track2Particle", "Track2Particle", analysis);
59 fVertexRecoCorrection = new AliCorrection("VertexReconstruction", "VertexReconstruction", analysis);
1afae8ff 60
0f67a57c 61 fTriggerBiasCorrectionMBToINEL = new AliCorrection("TriggerBias_MBToINEL", "TriggerBias_MBToINEL", analysis);
62 fTriggerBiasCorrectionMBToNSD = new AliCorrection("TriggerBias_MBToNSD", "TriggerBias_MBToNSD", analysis);
63 fTriggerBiasCorrectionMBToND = new AliCorrection("TriggerBias_MBToND", "TriggerBias_MBToND", analysis);
55e05544 64}
65
38233af1 66//____________________________________________________________________
67AlidNdEtaCorrection::~AlidNdEtaCorrection()
68{
69 // destructor
70
7584d357 71 if (fTrack2ParticleCorrection) {
38233af1 72 delete fTrack2ParticleCorrection;
73 fTrack2ParticleCorrection = 0;
74 }
75
7584d357 76 if (fVertexRecoCorrection) {
38233af1 77 delete fVertexRecoCorrection;
78 fVertexRecoCorrection = 0;
79 }
80
7584d357 81 if (fTriggerBiasCorrectionMBToINEL) {
82 delete fTriggerBiasCorrectionMBToINEL;
83 fTriggerBiasCorrectionMBToINEL = 0;
38233af1 84 }
85
7584d357 86 if (fTriggerBiasCorrectionMBToNSD) {
87 delete fTriggerBiasCorrectionMBToNSD;
88 fTriggerBiasCorrectionMBToNSD = 0;
89 }
90
91 if (fTriggerBiasCorrectionMBToND) {
92 delete fTriggerBiasCorrectionMBToND;
93 fTriggerBiasCorrectionMBToND = 0;
38233af1 94 }
95}
96
55e05544 97//____________________________________________________________________
98void
45e97e28 99AlidNdEtaCorrection::Finish() {
55e05544 100 //
101 // finish method
102 //
45e97e28 103 // divide the histograms in the AliCorrectionMatrix2D objects to get the corrections
55e05544 104
45e97e28 105 fTrack2ParticleCorrection->Divide();
55e05544 106 fVertexRecoCorrection->Divide();
7584d357 107 fTriggerBiasCorrectionMBToINEL->Divide();
108 fTriggerBiasCorrectionMBToNSD->Divide();
109 fTriggerBiasCorrectionMBToND->Divide();
55e05544 110}
111
112//____________________________________________________________________
74fd10b3 113Long64_t AlidNdEtaCorrection::Merge(TCollection* list)
114{
55e05544 115 // Merge a list of dNdEtaCorrection objects with this (needed for
7af955da 116 // PROOF).
55e05544 117 // Returns the number of merged objects (including this).
118
119 if (!list)
120 return 0;
7af955da 121
55e05544 122 if (list->IsEmpty())
123 return 1;
124
125 TIterator* iter = list->MakeIterator();
126 TObject* obj;
127
128 // collections of measured and generated histograms
7584d357 129 TList* collectionNtrackToNparticle = new TList;
130 TList* collectionVertexReco = new TList;
131 TList* collectionTriggerBiasMBToINEL = new TList;
132 TList* collectionTriggerBiasMBToNSD = new TList;
133 TList* collectionTriggerBiasMBToND = new TList;
55e05544 134
135 Int_t count = 0;
136 while ((obj = iter->Next())) {
7af955da 137
55e05544 138 AlidNdEtaCorrection* entry = dynamic_cast<AlidNdEtaCorrection*> (obj);
7af955da 139 if (entry == 0)
55e05544 140 continue;
141
74fd10b3 142 collectionNtrackToNparticle ->Add(entry->fTrack2ParticleCorrection);
143 collectionVertexReco ->Add(entry->fVertexRecoCorrection);
144 collectionTriggerBiasMBToINEL->Add(entry->fTriggerBiasCorrectionMBToINEL);
145 collectionTriggerBiasMBToNSD ->Add(entry->fTriggerBiasCorrectionMBToNSD);
146 collectionTriggerBiasMBToND ->Add(entry->fTriggerBiasCorrectionMBToND);
55e05544 147
148 count++;
149 }
7584d357 150 fTrack2ParticleCorrection ->Merge(collectionNtrackToNparticle);
151 fVertexRecoCorrection ->Merge(collectionVertexReco);
152 fTriggerBiasCorrectionMBToINEL ->Merge(collectionTriggerBiasMBToINEL);
153 fTriggerBiasCorrectionMBToNSD ->Merge(collectionTriggerBiasMBToNSD);
154 fTriggerBiasCorrectionMBToND ->Merge(collectionTriggerBiasMBToND);
10ebe68d 155
55e05544 156 delete collectionNtrackToNparticle;
157 delete collectionVertexReco;
7584d357 158 delete collectionTriggerBiasMBToINEL;
159 delete collectionTriggerBiasMBToNSD;
160 delete collectionTriggerBiasMBToND;
10ebe68d 161
55e05544 162 return count+1;
163}
164
2e88424e 165//____________________________________________________________________
166void AlidNdEtaCorrection::Add(AlidNdEtaCorrection* aCorrectionsToAdd, Float_t c) {
167 //
168 // adds the measured and generated of aCorrectionsToAdd to measured and generated
169 // of all corrections in this
170
171 fTrack2ParticleCorrection ->Add(aCorrectionsToAdd->GetTrack2ParticleCorrection() ,c);
172 fVertexRecoCorrection ->Add(aCorrectionsToAdd->GetVertexRecoCorrection() ,c);
173 fTriggerBiasCorrectionMBToINEL ->Add(aCorrectionsToAdd->GetTriggerBiasCorrectionINEL(),c);
174 fTriggerBiasCorrectionMBToNSD ->Add(aCorrectionsToAdd->GetTriggerBiasCorrectionNSD() ,c);
175 fTriggerBiasCorrectionMBToND ->Add(aCorrectionsToAdd->GetTriggerBiasCorrectionND() ,c);
176
177}
178
179//____________________________________________________________________
180void AlidNdEtaCorrection::Reset(void) {
181 //
182 // reset all corrections
183 //
184
185 fTrack2ParticleCorrection ->Reset();
186 fVertexRecoCorrection ->Reset();
187 fTriggerBiasCorrectionMBToINEL ->Reset();
188 fTriggerBiasCorrectionMBToNSD ->Reset();
189 fTriggerBiasCorrectionMBToND ->Reset();
190
191}
192
193
194
55e05544 195//____________________________________________________________________
74fd10b3 196Bool_t AlidNdEtaCorrection::LoadHistograms(const Char_t* dir)
197{
55e05544 198 //
199 // loads the histograms
74fd10b3 200 // if dir is empty a directory with the name of this object is taken (like in SaveHistogram)
55e05544 201 //
202
74fd10b3 203 if (!dir)
204 dir = GetName();
7584d357 205
74fd10b3 206 if (!gDirectory->cd(dir))
207 return kFALSE;
208
209 fTrack2ParticleCorrection ->LoadHistograms();
210 fVertexRecoCorrection ->LoadHistograms();
211 fTriggerBiasCorrectionMBToINEL ->LoadHistograms();
212 fTriggerBiasCorrectionMBToNSD ->LoadHistograms();
213 fTriggerBiasCorrectionMBToND ->LoadHistograms();
214
215 gDirectory->cd("..");
1afae8ff 216
55e05544 217 return kTRUE;
218}
219
55e05544 220//____________________________________________________________________
74fd10b3 221void AlidNdEtaCorrection::SaveHistograms()
222{
55e05544 223 //
224 // save the histograms
225 //
226
227 gDirectory->mkdir(fName.Data());
228 gDirectory->cd(fName.Data());
229
7584d357 230 fTrack2ParticleCorrection ->SaveHistograms();
231 fVertexRecoCorrection ->SaveHistograms();
232 fTriggerBiasCorrectionMBToINEL->SaveHistograms();
233 fTriggerBiasCorrectionMBToNSD ->SaveHistograms();
234 fTriggerBiasCorrectionMBToND ->SaveHistograms();
55e05544 235
74fd10b3 236 gDirectory->cd("..");
55e05544 237}
238
239//____________________________________________________________________
240void AlidNdEtaCorrection::DrawHistograms()
241{
242 //
dd367a14 243 // call the draw histogram method of the corrections
74fd10b3 244 //
55e05544 245
7584d357 246 fTrack2ParticleCorrection ->DrawHistograms();
247 fVertexRecoCorrection ->DrawHistograms();
248 fTriggerBiasCorrectionMBToINEL->DrawHistograms();
249 fTriggerBiasCorrectionMBToNSD ->DrawHistograms();
250 fTriggerBiasCorrectionMBToND ->DrawHistograms();
7584d357 251}
252
dd367a14 253//____________________________________________________________________
254void AlidNdEtaCorrection::DrawOverview(const char* canvasName)
255{
256 //
257 // call the DrawOverview histogram method of the corrections
258 //
259
260 fTrack2ParticleCorrection ->DrawOverview(canvasName);
261 fVertexRecoCorrection ->DrawOverview(canvasName);
262 fTriggerBiasCorrectionMBToINEL->DrawOverview(canvasName);
263 fTriggerBiasCorrectionMBToNSD ->DrawOverview(canvasName);
264 fTriggerBiasCorrectionMBToND ->DrawOverview(canvasName);
265}
266
7584d357 267//____________________________________________________________________
74fd10b3 268void AlidNdEtaCorrection::FillMCParticle(Float_t vtx, Float_t eta, Float_t pt, Bool_t trigger, Bool_t vertex, Int_t processType)
7584d357 269{
74fd10b3 270 // fills a particle in the corrections
271 // it is filled in generated or measured depending of the flags
7584d357 272
74fd10b3 273 fTriggerBiasCorrectionMBToINEL->GetTrackCorrection()->FillGene(vtx, eta, pt);
7584d357 274
74fd10b3 275 if (processType != 92 && processType != 93)
276 fTriggerBiasCorrectionMBToNSD->GetTrackCorrection()->FillGene(vtx, eta, pt);
277
278 if (processType!=92 && processType!=93 && processType!=94)
279 fTriggerBiasCorrectionMBToND->GetTrackCorrection()->FillGene(vtx, eta, pt);
280
281 if (!trigger)
282 return;
283
284 fTriggerBiasCorrectionMBToINEL->GetTrackCorrection()->FillMeas(vtx, eta, pt);
285 fTriggerBiasCorrectionMBToNSD->GetTrackCorrection()->FillMeas(vtx, eta, pt);
286 fTriggerBiasCorrectionMBToND->GetTrackCorrection()->FillMeas(vtx, eta, pt);
287 fVertexRecoCorrection->GetTrackCorrection()->FillGene(vtx, eta, pt);
288
289 if (!vertex)
290 return;
291
292 fVertexRecoCorrection->GetTrackCorrection()->FillMeas(vtx, eta, pt);
293 fTrack2ParticleCorrection->GetTrackCorrection()->FillGene(vtx, eta, pt);
7584d357 294}
55e05544 295
7584d357 296//____________________________________________________________________
74fd10b3 297void AlidNdEtaCorrection::FillTrackedParticle(Float_t vtx, Float_t eta, Float_t pt)
7584d357 298{
74fd10b3 299 // fills a tracked particle in the corrections
300
301 fTrack2ParticleCorrection->GetTrackCorrection()->FillMeas(vtx, eta, pt);
55e05544 302}
847489f7 303
7584d357 304//____________________________________________________________________
74fd10b3 305void AlidNdEtaCorrection::FillEvent(Float_t vtx, Float_t n, Bool_t trigger, Bool_t vertex, Int_t processType)
7584d357 306{
74fd10b3 307 // fills an event int he correction
308 // it is filled in generated or measured depending of the flags
309
310 fTriggerBiasCorrectionMBToINEL->GetEventCorrection()->FillGene(vtx, n);
311
312 if (processType != 92 && processType != 93)
313 fTriggerBiasCorrectionMBToNSD->GetEventCorrection()->FillGene(vtx, n);
7584d357 314
74fd10b3 315 if (processType!=92 && processType!=93 && processType!=94)
316 fTriggerBiasCorrectionMBToND->GetEventCorrection()->FillGene(vtx, n);
317
318 if (!trigger)
319 return;
320
321 fTriggerBiasCorrectionMBToINEL->GetEventCorrection()->FillMeas(vtx, n);
322 fTriggerBiasCorrectionMBToNSD->GetEventCorrection()->FillMeas(vtx, n);
323 fTriggerBiasCorrectionMBToND->GetEventCorrection()->FillMeas(vtx, n);
324 fVertexRecoCorrection->GetEventCorrection()->FillGene(vtx, n);
325
326 if (!vertex)
327 return;
328
329 fVertexRecoCorrection->GetEventCorrection()->FillMeas(vtx, n);
330}
7584d357 331
847489f7 332//____________________________________________________________________
74fd10b3 333Float_t AlidNdEtaCorrection::GetMeasuredFraction(CorrectionType correctionType, Float_t ptCutOff, Float_t eta, Bool_t debug)
847489f7 334{
335 // calculates the fraction of particles measured (some are missed due to the pt cut off)
74fd10b3 336 //
337 // uses the generated particle histogram from the correction passed, e.g. pass GetTrack2ParticleCorrection()
847489f7 338
0448e811 339 if (!GetCorrection(correctionType))
340 return -1;
341
342 const TH3F* generated = GetCorrection(correctionType)->GetTrackCorrection()->GetGeneratedHistogram();
847489f7 343
344 // find eta borders, if eta is negative assume -0.8 ... 0.8
345 Int_t etaBegin = 0;
346 Int_t etaEnd = 0;
72e597d7 347 if (eta < -99)
847489f7 348 {
349 etaBegin = generated->GetYaxis()->FindBin(-0.8);
350 etaEnd = generated->GetYaxis()->FindBin(0.8);
351 }
352 else
353 {
354 etaBegin = generated->GetYaxis()->FindBin(eta);
355 etaEnd = etaBegin;
356 }
357
3dfa46a4 358 //Printf("AlidNdEtaCorrection::GetMeasuredFraction: Using vtx range of +- 10 cm");
0448e811 359 Int_t vertexBegin = generated->GetXaxis()->FindBin(-9.99);
360 Int_t vertexEnd = generated->GetXaxis()->FindBin(9.99);
847489f7 361
92d2d8ad 362 TH1D* ptProj = dynamic_cast<TH1D*> (generated->ProjectionZ(Form("%s_pt", generated->GetName()), vertexBegin, vertexEnd, etaBegin, etaEnd));
b4b9cacc 363 //printf("GetMeasuredFraction: bin range %d %d %d %d\n", vertexBegin, vertexEnd, etaBegin, etaEnd);
1afae8ff 364 ptProj->GetXaxis()->SetTitle(generated->GetZaxis()->GetTitle());
847489f7 365
366 Int_t ptBin = ptProj->FindBin(ptCutOff);
b4b9cacc 367 //printf("GetMeasuredFraction: bin range %d %d\n", ptBin, ptProj->GetNbinsX());
7307d52c 368 Float_t abovePtCut = ptProj->Integral(ptBin, ptProj->GetNbinsX()+1);
369 Float_t all = ptProj->Integral(1, ptProj->GetNbinsX()+1);
847489f7 370
371 if (all == 0)
372 return -1;
373
374 Float_t fraction = abovePtCut / all;
375
b4b9cacc 376 //printf("GetMeasuredFraction: all %f above %f fraction %f\n", all, abovePtCut, fraction);
74fd10b3 377
847489f7 378 if (debug)
379 {
380 new TCanvas;
381 ptProj->Draw();
382 }
92d2d8ad 383 else
384 delete ptProj;
847489f7 385
72e597d7 386 if (debug)
387 printf("AlidNdEtaCorrection::GetMeasuredFraction: pt cut off = %f, eta = %f, => fraction = %f\n", ptCutOff, eta, fraction);
388
847489f7 389 return fraction;
390}
391
3dfa46a4 392//____________________________________________________________________
393TH1* AlidNdEtaCorrection::GetMeasuredEventFraction(CorrectionType correctionType, Int_t multCut)
394{
395 // calculates the fraction of events above multCut (but including it)
396 //
397 // uses the generated event histogram from the correction passed, e.g. pass GetTrack2ParticleCorrection()
398
399 if (!GetCorrection(correctionType))
400 return 0;
401
402 const TH2F* generated = GetCorrection(correctionType)->GetEventCorrection()->GetGeneratedHistogram();
403
404 TH1* allEvents = generated->ProjectionX(Form("%s_all", generated->GetName()), 1, generated->GetNbinsY());
405 TH1* aboveEvents = generated->ProjectionX(Form("%s_above", generated->GetName()), generated->GetYaxis()->FindBin(multCut), generated->GetNbinsY());
406
407 aboveEvents->Divide(aboveEvents, allEvents, 1, 1, "B");
408
409 return aboveEvents;
410}
411
74fd10b3 412//____________________________________________________________________
0ab29cfa 413void AlidNdEtaCorrection::ReduceInformation()
414{
415 // this function deletes the measured and generated histograms from the corrections to reduce the amount of data
416 // in memory
417
418 // these are needed for GetMeasuredFraction(): fTrack2ParticleCorrection->ReduceInformation();
7584d357 419 fVertexRecoCorrection ->ReduceInformation();
420 fTriggerBiasCorrectionMBToINEL ->ReduceInformation();
421 fTriggerBiasCorrectionMBToNSD ->ReduceInformation();
422 fTriggerBiasCorrectionMBToND ->ReduceInformation();
0ab29cfa 423}
7af955da 424
0448e811 425//____________________________________________________________________
426AliCorrection* AlidNdEtaCorrection::GetCorrection(CorrectionType correctionType)
427{
428 // returns the given correction
429
430 switch (correctionType)
431 {
432 case kNone : return 0;
433 case kTrack2Particle : return fTrack2ParticleCorrection;
434 case kVertexReco : return fVertexRecoCorrection;
435 case kINEL : return fTriggerBiasCorrectionMBToINEL;
436 case kNSD : return fTriggerBiasCorrectionMBToNSD;
437 case kND : return fTriggerBiasCorrectionMBToND;
438 }
439
440 return 0;
441}