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