]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/JetTasks/AliUEHistograms.cxx
added corrections for delta phi UE event distribution
[u/mrichter/AliRoot.git] / PWG4 / JetTasks / AliUEHistograms.cxx
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
36 ClassImp(AliUEHistograms)
37
38 AliUEHistograms::AliUEHistograms() : 
39   TObject(),
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   
70   fEventCount = new TH2F("fEventCount", ";step;event type;count", AliUEHist::fgkCFSteps+2, -2.5, -0.5 + AliUEHist::fgkCFSteps, 3, -0.5, 2.5);
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
85 //_____________________________________________________________________________
86 AliUEHistograms::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
108 //____________________________________________________________________
109 AliUEHistograms::~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 AliUEHist* AliUEHistograms::GetUEHist(Int_t id)
187 {
188   // returns AliUEHist object, useful for loops
189   
190   switch (id)
191   {
192     case 0: return fNumberDensitypT; break;
193     case 1: return fSumpT; break;
194     case 2: return fNumberDensityPhi; break;
195   }
196   
197   return 0;
198 }
199
200 //____________________________________________________________________
201 Int_t AliUEHistograms::CountParticles(TList* list, Float_t ptMin)
202 {
203   // counts the number of particles in the list with a pT above ptMin
204   // TODO eta cut needed here?
205   
206   Int_t count = 0;
207   for (Int_t j=0; j<list->GetEntries(); j++)
208     if (((AliVParticle*) list->At(j))->Pt() > ptMin)
209       count++;
210       
211   return count;
212 }
213   
214 //____________________________________________________________________
215 void AliUEHistograms::Fill(Int_t eventType, AliUEHist::CFStep step, AliVParticle* leading, TList* toward, TList* away, TList* min, TList* max)
216 {
217   // fills the UE event histograms
218   //
219   // 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
220   
221   // if leading is not set, just fill event statistics
222   if (leading)
223   {
224     Int_t multiplicity = 0;
225     
226     // TODO configurable?
227     Float_t ptMin = 0.15;
228     if (leading->Pt() > ptMin)
229       multiplicity++;
230     
231     multiplicity += CountParticles(toward, ptMin);
232     multiplicity += CountParticles(away, ptMin);
233     multiplicity += CountParticles(min, ptMin);
234     multiplicity += CountParticles(max, ptMin);
235      
236     FillRegion(AliUEHist::kToward, step, leading, toward, multiplicity);
237     FillRegion(AliUEHist::kAway,   step, leading, away, multiplicity);
238     FillRegion(AliUEHist::kMin,    step, leading, min, multiplicity);
239     FillRegion(AliUEHist::kMax,    step, leading, max, multiplicity);
240  
241     Double_t vars[2];
242     vars[0] = leading->Pt();
243     vars[1] = multiplicity;
244     fNumberDensitypT->GetEventHist()->Fill(vars, step);
245     fSumpT->GetEventHist()->Fill(vars, step);
246     fNumberDensityPhi->GetEventHist()->Fill(vars, step);
247   
248     fEventCountDifferential->Fill(leading->Pt(), step, eventType);
249   }
250   
251   FillEvent(eventType, step);
252 }
253   
254 //____________________________________________________________________
255 void AliUEHistograms::FillRegion(AliUEHist::Region region, AliUEHist::CFStep step, AliVParticle* leading, TList* list, Int_t multiplicity)
256 {
257   // loops over AliVParticles in list and fills the given region at the given step
258   //
259   // See also Fill(...)
260
261   for (Int_t i=0; i<list->GetEntries(); i++)
262   {
263     AliVParticle* particle = (AliVParticle*) list->At(i);
264     
265     Double_t vars[5];
266     vars[0] = particle->Eta();
267     vars[1] = particle->Pt();
268     vars[2] = leading->Pt();
269     vars[3] = multiplicity;
270     vars[4] = leading->Phi() - particle->Phi();
271     if (vars[4]>TMath::Pi()/2.)vars[4]-=TMath::TwoPi();
272     if (vars[4]< - 3.*TMath::Pi()/2.)vars[4]+=TMath::TwoPi();
273
274     fNumberDensitypT->GetTrackHist(region)->Fill(vars, step);
275     fSumpT->GetTrackHist(region)->Fill(vars, step, particle->Pt());
276     
277     // fill all in toward region (is anyway as function of delta phi!)
278     fNumberDensityPhi->GetTrackHist(AliUEHist::kToward)->Fill(vars, step);
279   }
280 }
281
282 //____________________________________________________________________
283 void AliUEHistograms::Fill(AliVParticle* leadingMC, AliVParticle* leadingReco)
284 {
285   // fills the correlation histograms
286   
287   if (leadingMC)
288   {
289     fCorrelationpT->Fill(leadingMC->Pt(), leadingReco->Pt());
290     if (leadingMC->Pt() > 0.5)
291     {
292       fCorrelationEta->Fill(leadingMC->Eta(), leadingReco->Eta());
293       fCorrelationPhi->Fill(leadingMC->Phi(), leadingReco->Phi());
294     }
295     
296     Float_t phiDiff = leadingMC->Phi() - leadingReco->Phi();
297     if (phiDiff > TMath::Pi())
298       phiDiff -= TMath::TwoPi();
299     if (phiDiff < -TMath::Pi())
300       phiDiff += TMath::TwoPi();
301       
302     Float_t etaDiff = leadingMC->Eta() - leadingReco->Eta();
303     
304     fCorrelationR->Fill(TMath::Sqrt(phiDiff * phiDiff + etaDiff * etaDiff), leadingMC->Pt());
305     fCorrelationLeading2Phi->Fill(phiDiff, leadingMC->Pt());
306   }
307   else
308   {
309     fCorrelationpT->Fill(1.0, leadingReco->Pt());
310     if (leadingReco->Pt() > 0.5)
311     {
312       fCorrelationEta->Fill(0.0, leadingReco->Eta());
313       fCorrelationPhi->Fill(0.0, leadingReco->Phi());
314     }
315   }
316 }
317   
318 //____________________________________________________________________
319 void AliUEHistograms::FillTrackingEfficiency(TObjArray* mc, TObjArray* recoPrim, TObjArray* recoAll, Int_t particleType)
320 {
321   // fills the tracking efficiency objects
322   //
323   // mc: all primary MC particles
324   // recoPrim: reconstructed primaries (again MC particles)
325   // recoAll: reconstructed (again MC particles)
326   // particleType is: 0 for pion, 1 for kaon, 2 for proton, 3 for others
327   
328   for (Int_t step=0; step<3; step++)
329   {
330     TObjArray* list = mc;
331     if (step == 1)
332       list = recoPrim;
333     else if (step == 2)
334       list = recoAll;
335       
336     for (Int_t i=0; i<list->GetEntries(); i++)
337     {
338       AliVParticle* particle = (AliVParticle*) list->At(i);
339       Double_t vars[3];
340       vars[0] = particle->Eta();
341       vars[1] = particle->Pt();
342       vars[2] = particleType;
343       
344       fNumberDensitypT->GetTrackHistEfficiency()->Fill(vars, step);
345       fSumpT->GetTrackHistEfficiency()->Fill(vars, step);
346       fNumberDensityPhi->GetTrackHistEfficiency()->Fill(vars, step);
347     }
348   }
349 }
350
351 //____________________________________________________________________
352 void AliUEHistograms::FillEvent(Int_t eventType, Int_t step)
353 {
354   // fills the number of events at the given step and the given enty type
355   //
356   // WARNING: This function is called from Fill, so only call it for steps where Fill is not called
357   
358   fEventCount->Fill(step, eventType);
359 }
360
361 //____________________________________________________________________
362 void AliUEHistograms::SetEtaRange(Float_t etaMin, Float_t etaMax)
363 {
364   // sets eta min and max for all contained AliUEHist classes
365   
366   fNumberDensitypT->SetEtaRange(etaMin, etaMax);
367   fSumpT->SetEtaRange(etaMin, etaMax);
368   fNumberDensityPhi->SetEtaRange(etaMin, etaMax);
369 }
370
371 //____________________________________________________________________
372 void AliUEHistograms::SetPtRange(Float_t ptMin, Float_t ptMax)
373 {
374   // sets pT min and max for all contained AliUEHist classes
375   
376   fNumberDensitypT->SetPtRange(ptMin, ptMax);
377   fSumpT->SetPtRange(ptMin, ptMax);
378   fNumberDensityPhi->SetPtRange(ptMin, ptMax);
379 }
380
381 //____________________________________________________________________
382 void AliUEHistograms::SetContaminationEnhancement(TH1F* hist)
383 {
384   // sets the contamination enhancement histogram in all contained AliUEHist classes
385   
386   fNumberDensitypT->SetContaminationEnhancement(hist);
387   fSumpT->SetContaminationEnhancement(hist);
388   fNumberDensityPhi->SetContaminationEnhancement(hist);
389 }  
390
391 //____________________________________________________________________
392 void AliUEHistograms::SetCombineMinMax(Bool_t flag)
393 {
394   // sets pT min and max for all contained AliUEHist classes
395   
396   fNumberDensitypT->SetCombineMinMax(flag);
397   fSumpT->SetCombineMinMax(flag);
398   fNumberDensityPhi->SetCombineMinMax(flag);
399 }
400
401 //____________________________________________________________________
402 void AliUEHistograms::Correct(AliUEHistograms* corrections)
403 {
404   // corrects the contained histograms by calling AliUEHist::Correct
405   
406   fNumberDensitypT->Correct(corrections->fNumberDensitypT);
407   fSumpT->Correct(corrections->fSumpT);
408   fNumberDensityPhi->Correct(corrections->fNumberDensityPhi);
409 }
410
411 //____________________________________________________________________
412 AliUEHistograms &AliUEHistograms::operator=(const AliUEHistograms &c)
413 {
414   // assigment operator
415
416   if (this != &c)
417     ((AliUEHistograms &) c).Copy(*this);
418
419   return *this;
420 }
421
422 //____________________________________________________________________
423 void AliUEHistograms::Copy(TObject& c) const
424 {
425   // copy function
426
427   AliUEHistograms& target = (AliUEHistograms &) c;
428
429   if (fNumberDensitypT)
430     target.fNumberDensitypT = dynamic_cast<AliUEHist*> (fNumberDensitypT->Clone());
431
432   if (fSumpT)
433     target.fSumpT = dynamic_cast<AliUEHist*> (fSumpT->Clone());
434
435   if (fNumberDensityPhi)
436     target.fNumberDensityPhi = dynamic_cast<AliUEHist*> (fNumberDensityPhi->Clone());
437
438   if (fCorrelationpT)
439     target.fCorrelationpT = dynamic_cast<TH2F*> (fCorrelationpT->Clone());
440
441   if (fCorrelationEta)
442     target.fCorrelationEta = dynamic_cast<TH2F*> (fCorrelationEta->Clone());
443
444   if (fCorrelationPhi)
445     target.fCorrelationPhi = dynamic_cast<TH2F*> (fCorrelationPhi->Clone());
446
447   if (fCorrelationR)
448     target.fCorrelationR = dynamic_cast<TH2F*> (fCorrelationR->Clone());
449
450   if (fCorrelationLeading2Phi)
451     target.fCorrelationLeading2Phi = dynamic_cast<TH2F*> (fCorrelationLeading2Phi->Clone());
452
453   if (fCorrelationMultiplicity)
454     target.fCorrelationMultiplicity = dynamic_cast<TH2F*> (fCorrelationMultiplicity->Clone());
455   
456   if (fEventCount)
457     target.fEventCount = dynamic_cast<TH2F*> (fEventCount->Clone());
458
459   if (fEventCountDifferential)
460     target.fEventCountDifferential = dynamic_cast<TH3F*> (fEventCountDifferential->Clone());
461     
462   if (fVertexContributors)
463     target.fVertexContributors = dynamic_cast<TH1F*> (fVertexContributors->Clone());
464 }
465
466 //____________________________________________________________________
467 Long64_t AliUEHistograms::Merge(TCollection* list)
468 {
469   // Merge a list of AliUEHistograms objects with this (needed for
470   // PROOF). 
471   // Returns the number of merged objects (including this).
472
473   if (!list)
474     return 0;
475   
476   if (list->IsEmpty())
477     return 1;
478
479   TIterator* iter = list->MakeIterator();
480   TObject* obj;
481
482   // collections of objects
483   const Int_t kMaxLists = 12;
484   TList* lists[kMaxLists];
485   
486   for (Int_t i=0; i<kMaxLists; i++)
487     lists[i] = new TList;
488   
489   Int_t count = 0;
490   while ((obj = iter->Next())) {
491     
492     AliUEHistograms* entry = dynamic_cast<AliUEHistograms*> (obj);
493     if (entry == 0) 
494       continue;
495
496     lists[0]->Add(entry->fNumberDensitypT);
497     lists[1]->Add(entry->fSumpT);
498     lists[2]->Add(entry->fNumberDensityPhi);
499     lists[3]->Add(entry->fCorrelationpT);
500     lists[4]->Add(entry->fCorrelationEta);
501     lists[5]->Add(entry->fCorrelationPhi);
502     lists[6]->Add(entry->fCorrelationR);
503     lists[7]->Add(entry->fCorrelationLeading2Phi);
504     lists[8]->Add(entry->fCorrelationMultiplicity);
505     lists[9]->Add(entry->fEventCount);
506     lists[10]->Add(entry->fEventCountDifferential);
507     lists[11]->Add(entry->fVertexContributors);
508
509     count++;
510   }
511     
512   fNumberDensitypT->Merge(lists[0]);
513   fSumpT->Merge(lists[1]);
514   fNumberDensityPhi->Merge(lists[2]);
515   fCorrelationpT->Merge(lists[3]);
516   fCorrelationEta->Merge(lists[4]);
517   fCorrelationPhi->Merge(lists[5]);
518   fCorrelationR->Merge(lists[6]);
519   fCorrelationLeading2Phi->Merge(lists[7]);
520   fCorrelationMultiplicity->Merge(lists[8]);
521   fEventCount->Merge(lists[9]);
522   fEventCountDifferential->Merge(lists[10]);
523   fVertexContributors->Merge(lists[11]);
524   
525   for (Int_t i=0; i<kMaxLists; i++)
526     delete lists[i];
527
528   return count+1;
529 }
530
531 void AliUEHistograms::CopyReconstructedData(AliUEHistograms* from)
532 {
533   // copies those histograms extracted from ESD to this object
534   
535   fNumberDensitypT->CopyReconstructedData(from->fNumberDensitypT);
536   fSumpT->CopyReconstructedData(from->fSumpT);
537   fNumberDensityPhi->CopyReconstructedData(from->fNumberDensityPhi);
538 }