Bug fix, size of array
[u/mrichter/AliRoot.git] / PWG4 / JetTasks / AliUEHistograms.cxx
CommitLineData
a75aacd6 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
16/* $Id: AliUEHistograms.cxx 20164 2007-08-14 15:31:50Z morsch $ */
17
18//
19//
20// encapsulates several AliUEHist objects for a full UE analysis plus additional control histograms
21//
22//
23// Author: Jan Fiete Grosse-Oetringhaus, Sara Vallero
24
25#include "AliUEHistograms.h"
26
27#include "AliCFContainer.h"
28#include "AliVParticle.h"
29
30#include "TList.h"
31#include "TH2F.h"
32#include "TH1F.h"
33#include "TH3F.h"
34#include "TMath.h"
35
36ClassImp(AliUEHistograms)
37
38AliUEHistograms::AliUEHistograms() :
d1c75d06 39 TObject(),
a75aacd6 40 fNumberDensitypT(0),
41 fSumpT(0),
42 fNumberDensityPhi(0),
43 fCorrelationpT(0),
44 fCorrelationEta(0),
45 fCorrelationPhi(0),
46 fCorrelationR(0),
47 fCorrelationLeading2Phi(0),
48 fCorrelationMultiplicity(0),
49 fEventCount(0),
50 fEventCountDifferential(0),
51 fVertexContributors(0)
52{
53 // Constructor
54
55 fNumberDensitypT = new AliUEHist("NumberDensitypT");
56 fSumpT = new AliUEHist("SumpT");
57 fNumberDensityPhi = new AliUEHist("NumberDensityPhi");
58
59 // do not add this hists to the directory
60 Bool_t oldStatus = TH1::AddDirectoryStatus();
61 TH1::AddDirectory(kFALSE);
62
63 fCorrelationpT = new TH2F("fCorrelationpT", ";p_{T,lead} (MC);p_{T,lead} (RECO)", 200, 0, 50, 200, 0, 50);
64 fCorrelationEta = new TH2F("fCorrelationEta", ";#eta_{T,lead} (MC);#eta_{T,lead} (RECO)", 200, -1, 1, 200, -1, 1);
65 fCorrelationPhi = new TH2F("fCorrelationPhi", ";#phi_{T,lead} (MC);#phi_{T,lead} (RECO)", 200, 0, TMath::TwoPi(), 200, 0, TMath::TwoPi());
66 fCorrelationR = new TH2F("fCorrelationR", ";R;p_{T,lead} (MC)", 200, 0, 2, 200, 0, 50);
67 fCorrelationLeading2Phi = new TH2F("fCorrelationLeading2Phi", ";#Delta #phi;p_{T,lead} (MC)", 200, -TMath::Pi(), TMath::Pi(), 200, 0, 50);
68 fCorrelationMultiplicity = new TH2F("fCorrelationMultiplicity", ";MC tracks;Reco tracks", 100, -0.5, 99.5, 100, -0.5, 99.5);
69
144bd037 70 fEventCount = new TH2F("fEventCount", ";step;event type;count", AliUEHist::fgkCFSteps+2, -2.5, -0.5 + AliUEHist::fgkCFSteps, 3, -0.5, 2.5);
a75aacd6 71 fEventCount->GetYaxis()->SetBinLabel(1, "ND");
72 fEventCount->GetYaxis()->SetBinLabel(2, "SD");
73 fEventCount->GetYaxis()->SetBinLabel(3, "DD");
74
75 fEventCountDifferential = new TH3F("fEventCountDifferential", ";p_{T,lead};step;event type", 100, 0, 50, AliUEHist::fgkCFSteps, -0.5, -0.5 + AliUEHist::fgkCFSteps, 3, -0.5, 2.5);
76 fEventCountDifferential->GetZaxis()->SetBinLabel(1, "ND");
77 fEventCountDifferential->GetZaxis()->SetBinLabel(2, "SD");
78 fEventCountDifferential->GetZaxis()->SetBinLabel(3, "DD");
79
80 fVertexContributors = new TH1F("fVertexContributors", ";contributors;count", 100, -0.5, 99.5);
81
82 TH1::AddDirectory(oldStatus);
83}
84
d1c75d06 85//_____________________________________________________________________________
86AliUEHistograms::AliUEHistograms(const AliUEHistograms &c) :
87 TObject(),
88 fNumberDensitypT(0),
89 fSumpT(0),
90 fNumberDensityPhi(0),
91 fCorrelationpT(0),
92 fCorrelationEta(0),
93 fCorrelationPhi(0),
94 fCorrelationR(0),
95 fCorrelationLeading2Phi(0),
96 fCorrelationMultiplicity(0),
97 fEventCount(0),
98 fEventCountDifferential(0),
99 fVertexContributors(0)
100{
101 //
102 // AliUEHistograms copy constructor
103 //
104
105 ((AliUEHistograms &) c).Copy(*this);
106}
107
a75aacd6 108//____________________________________________________________________
109AliUEHistograms::~AliUEHistograms()
110{
111 // Destructor
112
113 if (fNumberDensitypT)
114 {
115 delete fNumberDensitypT;
116 fNumberDensitypT = 0;
117 }
118
119 if (fSumpT)
120 {
121 delete fSumpT;
122 fSumpT = 0;
123 }
124
125 if (fNumberDensityPhi)
126 {
127 delete fNumberDensityPhi;
128 fNumberDensityPhi = 0;
129 }
130
131 if (fCorrelationpT)
132 {
133 delete fCorrelationpT;
134 fCorrelationpT = 0;
135 }
136
137 if (fCorrelationEta)
138 {
139 delete fCorrelationEta;
140 fCorrelationEta = 0;
141 }
142
143 if (fCorrelationPhi)
144 {
145 delete fCorrelationPhi;
146 fCorrelationPhi = 0;
147 }
148
149 if (fCorrelationR)
150 {
151 delete fCorrelationR;
152 fCorrelationR = 0;
153 }
154
155 if (fCorrelationLeading2Phi)
156 {
157 delete fCorrelationLeading2Phi;
158 fCorrelationLeading2Phi = 0;
159 }
160
161 if (fCorrelationMultiplicity)
162 {
163 delete fCorrelationMultiplicity;
164 fCorrelationMultiplicity = 0;
165 }
166
167 if (fEventCount)
168 {
169 delete fEventCount;
170 fEventCount = 0;
171 }
172
173 if (fEventCountDifferential)
174 {
175 delete fEventCountDifferential;
176 fEventCountDifferential = 0;
177 }
178
179 if (fVertexContributors)
180 {
181 delete fVertexContributors;
182 fVertexContributors = 0;
183 }
184}
185
186//____________________________________________________________________
187Int_t AliUEHistograms::CountParticles(TList* list, Float_t ptMin)
188{
189 // counts the number of particles in the list with a pT above ptMin
190 // TODO eta cut needed here?
191
192 Int_t count = 0;
193 for (Int_t j=0; j<list->GetEntries(); j++)
194 if (((AliVParticle*) list->At(j))->Pt() > ptMin)
195 count++;
196
197 return count;
198}
199
200//____________________________________________________________________
201void AliUEHistograms::Fill(Int_t eventType, AliUEHist::CFStep step, AliVParticle* leading, TList* toward, TList* away, TList* min, TList* max)
202{
203 // fills the UE event histograms
204 //
205 // this function needs the leading (track or jet or ...) and four lists of AliVParticles which contain the particles/tracks to be filled in the four regions
206
207 // if leading is not set, just fill event statistics
208 if (leading)
209 {
210 Int_t multiplicity = 0;
211
212 // TODO configurable?
213 Float_t ptMin = 0.15;
214 if (leading->Pt() > ptMin)
215 multiplicity++;
216
217 multiplicity += CountParticles(toward, ptMin);
218 multiplicity += CountParticles(away, ptMin);
219 multiplicity += CountParticles(min, ptMin);
220 multiplicity += CountParticles(max, ptMin);
221
222 FillRegion(AliUEHist::kToward, step, leading, toward, multiplicity);
223 FillRegion(AliUEHist::kAway, step, leading, away, multiplicity);
224 FillRegion(AliUEHist::kMin, step, leading, min, multiplicity);
225 FillRegion(AliUEHist::kMax, step, leading, max, multiplicity);
b1831bcb 226
a75aacd6 227 Double_t vars[2];
228 vars[0] = leading->Pt();
229 vars[1] = multiplicity;
230 fNumberDensitypT->GetEventHist()->Fill(vars, step);
231 fSumpT->GetEventHist()->Fill(vars, step);
232 fNumberDensityPhi->GetEventHist()->Fill(vars, step);
233
234 fEventCountDifferential->Fill(leading->Pt(), step, eventType);
235 }
236
237 FillEvent(eventType, step);
238}
239
240//____________________________________________________________________
241void AliUEHistograms::FillRegion(AliUEHist::Region region, AliUEHist::CFStep step, AliVParticle* leading, TList* list, Int_t multiplicity)
242{
243 // loops over AliVParticles in list and fills the given region at the given step
244 //
245 // See also Fill(...)
246
247 for (Int_t i=0; i<list->GetEntries(); i++)
248 {
249 AliVParticle* particle = (AliVParticle*) list->At(i);
250
251 Double_t vars[5];
252 vars[0] = particle->Eta();
253 vars[1] = particle->Pt();
254 vars[2] = leading->Pt();
255 vars[3] = multiplicity;
256 vars[4] = leading->Phi() - particle->Phi();
d4abbc90 257 if (vars[4]>TMath::Pi()/2.)vars[4]-=TMath::TwoPi();
258 if (vars[4]< - 3.*TMath::Pi()/2.)vars[4]+=TMath::TwoPi();
259
a75aacd6 260 fNumberDensitypT->GetTrackHist(region)->Fill(vars, step);
261 fSumpT->GetTrackHist(region)->Fill(vars, step, particle->Pt());
262
263 // fill all in toward region (is anyway as function of delta phi!)
264 fNumberDensityPhi->GetTrackHist(AliUEHist::kToward)->Fill(vars, step);
265 }
266}
267
268//____________________________________________________________________
269void AliUEHistograms::Fill(AliVParticle* leadingMC, AliVParticle* leadingReco)
270{
271 // fills the correlation histograms
272
273 if (leadingMC)
274 {
275 fCorrelationpT->Fill(leadingMC->Pt(), leadingReco->Pt());
276 if (leadingMC->Pt() > 0.5)
277 {
278 fCorrelationEta->Fill(leadingMC->Eta(), leadingReco->Eta());
279 fCorrelationPhi->Fill(leadingMC->Phi(), leadingReco->Phi());
280 }
281
282 Float_t phiDiff = leadingMC->Phi() - leadingReco->Phi();
283 if (phiDiff > TMath::Pi())
284 phiDiff -= TMath::TwoPi();
285 if (phiDiff < -TMath::Pi())
286 phiDiff += TMath::TwoPi();
287
288 Float_t etaDiff = leadingMC->Eta() - leadingReco->Eta();
289
290 fCorrelationR->Fill(TMath::Sqrt(phiDiff * phiDiff + etaDiff * etaDiff), leadingMC->Pt());
291 fCorrelationLeading2Phi->Fill(phiDiff, leadingMC->Pt());
292 }
293 else
294 {
295 fCorrelationpT->Fill(1.0, leadingReco->Pt());
296 if (leadingReco->Pt() > 0.5)
297 {
298 fCorrelationEta->Fill(0.0, leadingReco->Eta());
299 fCorrelationPhi->Fill(0.0, leadingReco->Phi());
300 }
301 }
302}
303
b1831bcb 304//____________________________________________________________________
305void AliUEHistograms::FillTrackingEfficiency(TObjArray* mc, TObjArray* recoPrim, TObjArray* recoAll, Int_t particleType)
306{
307 // fills the tracking efficiency objects
308 //
309 // mc: all primary MC particles
310 // recoPrim: reconstructed primaries (again MC particles)
311 // recoAll: reconstructed (again MC particles)
312 // particleType is: 0 for pion, 1 for kaon, 2 for proton, 3 for others
313
314 for (Int_t step=0; step<3; step++)
315 {
316 TObjArray* list = mc;
317 if (step == 1)
318 list = recoPrim;
319 else if (step == 2)
320 list = recoAll;
321
322 for (Int_t i=0; i<list->GetEntries(); i++)
323 {
324 AliVParticle* particle = (AliVParticle*) list->At(i);
a700ef3a 325 Double_t vars[3];
b1831bcb 326 vars[0] = particle->Eta();
327 vars[1] = particle->Pt();
328 vars[2] = particleType;
329
330 fNumberDensitypT->GetTrackHistEfficiency()->Fill(vars, step);
331 fSumpT->GetTrackHistEfficiency()->Fill(vars, step);
332 fNumberDensityPhi->GetTrackHistEfficiency()->Fill(vars, step);
333 }
334 }
335}
336
a75aacd6 337//____________________________________________________________________
338void AliUEHistograms::FillEvent(Int_t eventType, Int_t step)
339{
340 // fills the number of events at the given step and the given enty type
341 //
342 // WARNING: This function is called from Fill, so only call it for steps where Fill is not called
343
344 fEventCount->Fill(step, eventType);
345}
346
347//____________________________________________________________________
348void AliUEHistograms::SetEtaRange(Float_t etaMin, Float_t etaMax)
349{
350 // sets eta min and max for all contained AliUEHist classes
351
352 fNumberDensitypT->SetEtaRange(etaMin, etaMax);
353 fSumpT->SetEtaRange(etaMin, etaMax);
354 fNumberDensityPhi->SetEtaRange(etaMin, etaMax);
355}
356
357//____________________________________________________________________
358void AliUEHistograms::SetPtRange(Float_t ptMin, Float_t ptMax)
359{
360 // sets pT min and max for all contained AliUEHist classes
361
362 fNumberDensitypT->SetPtRange(ptMin, ptMax);
363 fSumpT->SetPtRange(ptMin, ptMax);
364 fNumberDensityPhi->SetPtRange(ptMin, ptMax);
365}
366
144bd037 367//____________________________________________________________________
368void AliUEHistograms::SetContaminationEnhancement(TH1F* hist)
369{
370 // sets the contamination enhancement histogram in all contained AliUEHist classes
371
372 fNumberDensitypT->SetContaminationEnhancement(hist);
373 fSumpT->SetContaminationEnhancement(hist);
374 fNumberDensityPhi->SetContaminationEnhancement(hist);
375}
376
a75aacd6 377//____________________________________________________________________
378void AliUEHistograms::SetCombineMinMax(Bool_t flag)
379{
380 // sets pT min and max for all contained AliUEHist classes
381
382 fNumberDensitypT->SetCombineMinMax(flag);
383 fSumpT->SetCombineMinMax(flag);
384 fNumberDensityPhi->SetCombineMinMax(flag);
385}
386
387//____________________________________________________________________
388void AliUEHistograms::Correct(AliUEHistograms* corrections)
389{
390 // corrects the contained histograms by calling AliUEHist::Correct
391
392 fNumberDensitypT->Correct(corrections->fNumberDensitypT);
393 fSumpT->Correct(corrections->fSumpT);
144bd037 394 //fNumberDensityPhi->Correct(corrections->fNumberDensityPhi);
a75aacd6 395}
396
397//____________________________________________________________________
398AliUEHistograms &AliUEHistograms::operator=(const AliUEHistograms &c)
399{
400 // assigment operator
401
402 if (this != &c)
403 ((AliUEHistograms &) c).Copy(*this);
404
405 return *this;
406}
407
408//____________________________________________________________________
409void AliUEHistograms::Copy(TObject& c) const
410{
411 // copy function
412
413 AliUEHistograms& target = (AliUEHistograms &) c;
414
415 if (fNumberDensitypT)
416 target.fNumberDensitypT = dynamic_cast<AliUEHist*> (fNumberDensitypT->Clone());
417
418 if (fSumpT)
419 target.fSumpT = dynamic_cast<AliUEHist*> (fSumpT->Clone());
420
421 if (fNumberDensityPhi)
422 target.fNumberDensityPhi = dynamic_cast<AliUEHist*> (fNumberDensityPhi->Clone());
423
424 if (fCorrelationpT)
425 target.fCorrelationpT = dynamic_cast<TH2F*> (fCorrelationpT->Clone());
426
427 if (fCorrelationEta)
428 target.fCorrelationEta = dynamic_cast<TH2F*> (fCorrelationEta->Clone());
429
430 if (fCorrelationPhi)
431 target.fCorrelationPhi = dynamic_cast<TH2F*> (fCorrelationPhi->Clone());
432
433 if (fCorrelationR)
434 target.fCorrelationR = dynamic_cast<TH2F*> (fCorrelationR->Clone());
435
436 if (fCorrelationLeading2Phi)
437 target.fCorrelationLeading2Phi = dynamic_cast<TH2F*> (fCorrelationLeading2Phi->Clone());
438
439 if (fCorrelationMultiplicity)
440 target.fCorrelationMultiplicity = dynamic_cast<TH2F*> (fCorrelationMultiplicity->Clone());
441
442 if (fEventCount)
443 target.fEventCount = dynamic_cast<TH2F*> (fEventCount->Clone());
444
445 if (fEventCountDifferential)
446 target.fEventCountDifferential = dynamic_cast<TH3F*> (fEventCountDifferential->Clone());
447
448 if (fVertexContributors)
449 target.fVertexContributors = dynamic_cast<TH1F*> (fVertexContributors->Clone());
450}
451
452//____________________________________________________________________
453Long64_t AliUEHistograms::Merge(TCollection* list)
454{
455 // Merge a list of AliUEHistograms objects with this (needed for
456 // PROOF).
457 // Returns the number of merged objects (including this).
458
459 if (!list)
460 return 0;
461
462 if (list->IsEmpty())
463 return 1;
464
465 TIterator* iter = list->MakeIterator();
466 TObject* obj;
467
468 // collections of objects
469 const Int_t kMaxLists = 12;
470 TList* lists[kMaxLists];
471
472 for (Int_t i=0; i<kMaxLists; i++)
473 lists[i] = new TList;
474
475 Int_t count = 0;
476 while ((obj = iter->Next())) {
477
478 AliUEHistograms* entry = dynamic_cast<AliUEHistograms*> (obj);
479 if (entry == 0)
480 continue;
481
482 lists[0]->Add(entry->fNumberDensitypT);
483 lists[1]->Add(entry->fSumpT);
484 lists[2]->Add(entry->fNumberDensityPhi);
485 lists[3]->Add(entry->fCorrelationpT);
486 lists[4]->Add(entry->fCorrelationEta);
487 lists[5]->Add(entry->fCorrelationPhi);
488 lists[6]->Add(entry->fCorrelationR);
489 lists[7]->Add(entry->fCorrelationLeading2Phi);
490 lists[8]->Add(entry->fCorrelationMultiplicity);
491 lists[9]->Add(entry->fEventCount);
492 lists[10]->Add(entry->fEventCountDifferential);
493 lists[11]->Add(entry->fVertexContributors);
494
495 count++;
496 }
497
498 fNumberDensitypT->Merge(lists[0]);
499 fSumpT->Merge(lists[1]);
500 fNumberDensityPhi->Merge(lists[2]);
501 fCorrelationpT->Merge(lists[3]);
502 fCorrelationEta->Merge(lists[4]);
503 fCorrelationPhi->Merge(lists[5]);
504 fCorrelationR->Merge(lists[6]);
505 fCorrelationLeading2Phi->Merge(lists[7]);
506 fCorrelationMultiplicity->Merge(lists[8]);
507 fEventCount->Merge(lists[9]);
508 fEventCountDifferential->Merge(lists[10]);
509 fVertexContributors->Merge(lists[11]);
510
511 for (Int_t i=0; i<kMaxLists; i++)
512 delete lists[i];
513
514 return count+1;
515}
b1831bcb 516
517void AliUEHistograms::CopyReconstructedData(AliUEHistograms* from)
518{
519 // copies those histograms extracted from ESD to this object
520
521 fNumberDensitypT->CopyReconstructedData(from->fNumberDensitypT);
522 fSumpT->CopyReconstructedData(from->fSumpT);
523 fNumberDensityPhi->CopyReconstructedData(from->fNumberDensityPhi);
524}