]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliEmcalTrackingQATask.cxx
Merge remote-tracking branch 'origin/flatdev' into mergeFlat2Master
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalTrackingQATask.cxx
1 // Track QA task (efficiency and pt resolution)
2 //
3 // Author: S.Aiola
4
5 #include <TH3F.h>
6 #include <THnSparse.h>
7 #include <TMath.h>
8 #include <TString.h>
9 #include <Riostream.h>
10
11 #include "AliPicoTrack.h"
12 #include "AliESDtrack.h"
13 #include "AliAODMCParticle.h"
14 #include "AliParticleContainer.h"
15 #include "AliLog.h"
16
17 #include "AliEmcalTrackingQATask.h"
18
19 ClassImp(AliEmcalTrackingQATask)
20
21 //________________________________________________________________________
22 AliEmcalTrackingQATask::AliEmcalTrackingQATask() : 
23   AliAnalysisTaskEmcal("AliEmcalTrackingQA", kTRUE),
24   fSelectHIJING(kTRUE),
25   fDoSigma1OverPt(kFALSE),
26   fDoSigmaPtOverPtGen(kFALSE),
27   fGeneratorLevel(0),
28   fDetectorLevel(0),
29   fNPtHistBins(0),
30   fPtHistBins(0),
31   fNEtaHistBins(0),
32   fEtaHistBins(0),
33   fNPhiHistBins(0),
34   fPhiHistBins(0),
35   fNCentHistBins(0),
36   fCentHistBins(0),
37   fNPtRelDiffHistBins(0),
38   fPtRelDiffHistBins(0),
39   fNPtResHistBins(0),
40   fPtResHistBins(0),
41   f1OverPtResHistBins(0),
42   fN1OverPtResHistBins(0),
43   fNIntegerHistBins(0),
44   fIntegerHistBins(0),
45   fTracks(0),
46   fParticlesPhysPrim(0),
47   fParticlesMatched(0)
48 {
49   // Default constructor.
50
51   SetMakeGeneralHistograms(kTRUE);
52
53   GenerateHistoBins();
54 }
55
56 //________________________________________________________________________
57 AliEmcalTrackingQATask::AliEmcalTrackingQATask(const char *name) : 
58   AliAnalysisTaskEmcal(name, kTRUE),
59   fSelectHIJING(kTRUE),
60   fDoSigma1OverPt(kFALSE),
61   fDoSigmaPtOverPtGen(kFALSE),
62   fGeneratorLevel(0),
63   fDetectorLevel(0),
64   fNPtHistBins(0),
65   fPtHistBins(0),
66   fNEtaHistBins(0),
67   fEtaHistBins(0),
68   fNPhiHistBins(0),
69   fPhiHistBins(0),
70   fNCentHistBins(0),
71   fCentHistBins(0),
72   fNPtRelDiffHistBins(0),
73   fPtRelDiffHistBins(0),
74   fNPtResHistBins(0),
75   fPtResHistBins(0),
76   f1OverPtResHistBins(0),
77   fN1OverPtResHistBins(0),
78   fNIntegerHistBins(0),
79   fIntegerHistBins(0),
80   fTracks(0),
81   fParticlesPhysPrim(0),
82   fParticlesMatched(0)
83 {
84   // Standard constructor.
85
86   SetMakeGeneralHistograms(kTRUE);
87
88   GenerateHistoBins();
89 }
90
91 //________________________________________________________________________
92 AliEmcalTrackingQATask::~AliEmcalTrackingQATask()
93 {
94   // Destructor.
95 }
96
97 //________________________________________________________________________
98 void AliEmcalTrackingQATask::GenerateHistoBins()
99 {
100   fNPtHistBins = 82;
101   fPtHistBins = new Double_t[fNPtHistBins+1];
102   GenerateFixedBinArray(6, 0, 0.3, fPtHistBins);
103   GenerateFixedBinArray(7, 0.3, 1, fPtHistBins+6);
104   GenerateFixedBinArray(10, 1, 3, fPtHistBins+13);
105   GenerateFixedBinArray(14, 3, 10, fPtHistBins+23);
106   GenerateFixedBinArray(10, 10, 20, fPtHistBins+37);
107   GenerateFixedBinArray(15, 20, 50, fPtHistBins+47);
108   GenerateFixedBinArray(20, 50, 150, fPtHistBins+62);
109
110   fNEtaHistBins = 100;
111   fEtaHistBins = new Double_t[fNEtaHistBins+1];
112   GenerateFixedBinArray(fNEtaHistBins, -1, 1, fEtaHistBins);
113
114   fNPhiHistBins = 101;
115   fPhiHistBins = new Double_t[fNPhiHistBins+1];
116   GenerateFixedBinArray(fNPhiHistBins, 0, TMath::Pi() * 2.02, fPhiHistBins);
117
118   fNCentHistBins = 4;
119   fCentHistBins = new Double_t[fNCentHistBins+1];
120   fCentHistBins[0] = 0;
121   fCentHistBins[1] = 10;
122   fCentHistBins[2] = 30;
123   fCentHistBins[3] = 50;
124   fCentHistBins[4] = 90;
125
126   fNPtResHistBins = 175;
127   fPtResHistBins = new Double_t[fNPtResHistBins+1];
128   GenerateFixedBinArray(50, 0, 0.05, fPtResHistBins);
129   GenerateFixedBinArray(25, 0.05, 0.10, fPtResHistBins+50);
130   GenerateFixedBinArray(25, 0.10, 0.20, fPtResHistBins+75);
131   GenerateFixedBinArray(30, 0.20, 0.50, fPtResHistBins+100);
132   GenerateFixedBinArray(25, 0.50, 1.00, fPtResHistBins+130);
133   GenerateFixedBinArray(20, 1.00, 2.00, fPtResHistBins+155);
134
135   fNPtRelDiffHistBins = 200;
136   fPtRelDiffHistBins = new Double_t[fNPtRelDiffHistBins+1];
137   GenerateFixedBinArray(fNPtRelDiffHistBins, -2, 2, fPtRelDiffHistBins);
138
139   fN1OverPtResHistBins = 385;
140   f1OverPtResHistBins = new Double_t[fN1OverPtResHistBins+1];
141   GenerateFixedBinArray(100, 0, 0.02, f1OverPtResHistBins);
142   GenerateFixedBinArray(60, 0.02, 0.05, f1OverPtResHistBins+100);
143   GenerateFixedBinArray(50, 0.05, 0.1, f1OverPtResHistBins+160);
144   GenerateFixedBinArray(50, 0.1, 0.2, f1OverPtResHistBins+210);
145   GenerateFixedBinArray(75, 0.2, 0.5, f1OverPtResHistBins+260);
146   GenerateFixedBinArray(50, 0.5, 1.5, f1OverPtResHistBins+335);
147
148   fNIntegerHistBins = 10;
149   fIntegerHistBins = new Double_t[fNIntegerHistBins+1];
150   GenerateFixedBinArray(fNIntegerHistBins, -0.5, 9.5, fIntegerHistBins);
151 }
152
153 //________________________________________________________________________
154 void AliEmcalTrackingQATask::UserCreateOutputObjects()
155 {
156   // Create my user objects.
157
158   AliAnalysisTaskEmcal::UserCreateOutputObjects();
159
160   if (fParticleCollArray.GetEntriesFast() < 1) {
161     AliFatal("This task needs at least one particle container!");
162   }
163
164   if (!fDetectorLevel) {
165     fDetectorLevel = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
166     fDetectorLevel->SetClassName("AliPicoTrack");
167   }
168
169   if (!fGeneratorLevel && fParticleCollArray.GetEntriesFast() > 1) {
170     fGeneratorLevel = static_cast<AliParticleContainer*>(fParticleCollArray.At(1));
171     fGeneratorLevel->SetClassName("AliAODMCParticle");
172   }
173
174   AllocateDetectorLevelTHnSparse();
175
176   if (fGeneratorLevel) {
177     AllocateGeneratorLevelTHnSparse();
178     AllocateMatchedParticlesTHnSparse();
179   }
180 }
181
182 //________________________________________________________________________
183 void AliEmcalTrackingQATask::AllocateDetectorLevelTHnSparse()
184 {
185   Int_t dim = 0;
186   TString title[20];
187   Int_t nbins[20] = {0};
188   Double_t *binEdges[20] = {0};
189   
190   if (fForceBeamType != AliAnalysisTaskEmcal::kpp) {
191     title[dim] = "Centrality %";
192     nbins[dim] = fNCentHistBins;
193     binEdges[dim] = fCentHistBins;
194     dim++;
195   }
196
197   title[dim] = "#it{p}_{T} (GeV/#it{c})";
198   nbins[dim] = fNPtHistBins;
199   binEdges[dim] = fPtHistBins;
200   dim++;
201
202   title[dim] = "#eta";
203   nbins[dim] = fNEtaHistBins;
204   binEdges[dim] = fEtaHistBins;
205   dim++;
206
207   title[dim] = "#phi";
208   nbins[dim] = fNPhiHistBins;
209   binEdges[dim] = fPhiHistBins;
210   dim++;
211
212   if (fSelectHIJING) {
213     title[dim] = "MC Generator";
214     nbins[dim] = 2;
215     binEdges[dim] = fIntegerHistBins;
216     dim++;
217   }
218
219   title[dim] = "track type";
220   nbins[dim] = 3;
221   binEdges[dim] = fIntegerHistBins;
222   dim++;
223
224   if (fIsEsd) {
225     if (fDoSigma1OverPt) {
226       title[dim] = "#sigma(1/#it{p}_{T}) (GeV/#it{c})^{-1}";
227       nbins[dim] = fN1OverPtResHistBins;
228       binEdges[dim] = f1OverPtResHistBins;
229       dim++;
230     }
231     else {
232       title[dim] = "#sigma(#it{p}_{T}) / #it{p}_{T}";
233       nbins[dim] = fNPtResHistBins;
234       binEdges[dim] = fPtResHistBins;
235       dim++;
236     }    
237   }
238  
239   fTracks = new THnSparseF("fTracks","fTracks",dim,nbins);
240   for (Int_t i = 0; i < dim; i++) {
241     fTracks->GetAxis(i)->SetTitle(title[i]);
242     fTracks->SetBinEdges(i, binEdges[i]);
243   }
244
245   fOutput->Add(fTracks);
246 }
247
248 //________________________________________________________________________
249 void AliEmcalTrackingQATask::AllocateGeneratorLevelTHnSparse()
250 {
251   Int_t dim = 0;
252   TString title[20];
253   Int_t nbins[20] = {0};
254   Double_t *binEdges[20] = {0};
255   
256   if (fForceBeamType != AliAnalysisTaskEmcal::kpp) {
257     title[dim] = "Centrality %";
258     nbins[dim] = fNCentHistBins;
259     binEdges[dim] = fCentHistBins;
260     dim++;
261   }
262
263   title[dim] = "#it{p}_{T} (GeV/#it{c})";
264   nbins[dim] = fNPtHistBins;
265   binEdges[dim] = fPtHistBins;
266   dim++;
267
268   title[dim] = "#eta";
269   nbins[dim] = fNEtaHistBins;
270   binEdges[dim] = fEtaHistBins;
271   dim++;
272
273   title[dim] = "#phi";
274   nbins[dim] = fNPhiHistBins;
275   binEdges[dim] = fPhiHistBins;
276   dim++;
277
278   if (fSelectHIJING) {
279     title[dim] = "MC Generator";
280     nbins[dim] = 2;
281     binEdges[dim] = fIntegerHistBins;
282     dim++;
283   }
284
285   title[dim] = "Findable";
286   nbins[dim] = 2;
287   binEdges[dim] = fIntegerHistBins;
288   dim++;
289  
290   fParticlesPhysPrim = new THnSparseF("fParticlesPhysPrim","fParticlesPhysPrim",dim,nbins);
291   for (Int_t i = 0; i < dim; i++) {
292     fParticlesPhysPrim->GetAxis(i)->SetTitle(title[i]);
293     fParticlesPhysPrim->SetBinEdges(i, binEdges[i]);
294   }
295
296   fOutput->Add(fParticlesPhysPrim);
297 }
298
299 //________________________________________________________________________
300 void AliEmcalTrackingQATask::AllocateMatchedParticlesTHnSparse()
301 {
302   Int_t dim = 0;
303   TString title[20];
304   Int_t nbins[20] = {0};
305   Double_t *binEdges[20] = {0};
306   
307   if (fForceBeamType != AliAnalysisTaskEmcal::kpp) {
308     title[dim] = "Centrality %";
309     nbins[dim] = fNCentHistBins;
310     binEdges[dim] = fCentHistBins;
311     dim++;
312   }
313
314   title[dim] = "#it{p}_{T}^{gen} (GeV/#it{c})";
315   nbins[dim] = fNPtHistBins;
316   binEdges[dim] = fPtHistBins;
317   dim++;
318
319   title[dim] = "#eta^{gen}";
320   nbins[dim] = fNEtaHistBins;
321   binEdges[dim] = fEtaHistBins;
322   dim++;
323
324   title[dim] = "#phi^{gen}";
325   nbins[dim] = fNPhiHistBins;
326   binEdges[dim] = fPhiHistBins;
327   dim++;
328
329   title[dim] = "#it{p}_{T}^{det} (GeV/#it{c})";
330   nbins[dim] = fNPtHistBins;
331   binEdges[dim] = fPtHistBins;
332   dim++;
333
334   title[dim] = "#eta^{det}";
335   nbins[dim] = fNEtaHistBins;
336   binEdges[dim] = fEtaHistBins;
337   dim++;
338
339   title[dim] = "#phi^{det}";
340   nbins[dim] = fNPhiHistBins;
341   binEdges[dim] = fPhiHistBins;
342   dim++;
343
344   if (fDoSigmaPtOverPtGen) {
345     title[dim] = "(#it{p}_{T}^{gen} - #it{p}_{T}^{det}) / #it{p}_{T}^{gen}";
346     nbins[dim] = fNPtRelDiffHistBins;
347     binEdges[dim] = fPtRelDiffHistBins;
348     dim++;
349   }
350   else {
351     title[dim] = "(#it{p}_{T}^{gen} - #it{p}_{T}^{det}) / #it{p}_{T}^{det}";
352     nbins[dim] = fNPtRelDiffHistBins;
353     binEdges[dim] = fPtRelDiffHistBins;
354     dim++;
355   }
356
357   title[dim] = "track type";
358   nbins[dim] = 3;
359   binEdges[dim] = fIntegerHistBins;
360   dim++;
361
362   fParticlesMatched = new THnSparseF("fParticlesMatched","fParticlesMatched",dim,nbins);
363   for (Int_t i = 0; i < dim; i++) {
364     fParticlesMatched->GetAxis(i)->SetTitle(title[i]);
365     fParticlesMatched->SetBinEdges(i, binEdges[i]);
366   }
367
368   fOutput->Add(fParticlesMatched);
369 }
370
371 //________________________________________________________________________
372 void AliEmcalTrackingQATask::SetGeneratorLevelName(const char* name)
373 {
374   if (!fDetectorLevel) {
375     AliError("Please, first set the detector level array!");
376     return;
377   }
378   if (!fGeneratorLevel) {  // first check if the generator level array is set
379     fGeneratorLevel = static_cast<AliParticleContainer*>(fParticleCollArray.At(1));
380     if (fGeneratorLevel) {  // now check if the first collection array has been added already
381       fGeneratorLevel->SetArrayName(name);
382     }
383     else {
384       fGeneratorLevel = AddParticleContainer(name);
385     }
386     fGeneratorLevel->SetClassName("AliAODMCParticle");
387     fGeneratorLevel->SelectPhysicalPrimaries(kTRUE);
388     fGeneratorLevel->SetParticlePtCut(0);
389   }
390   fGeneratorLevel->SetArrayName(name);
391 }
392
393 //________________________________________________________________________
394 void AliEmcalTrackingQATask::SetDetectorLevelName(const char* name)
395 {
396   if (!fDetectorLevel) {  // first check if the detector level array is set
397     fDetectorLevel = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
398     if (fDetectorLevel) {  // now check if the second collection array has been added already
399       fDetectorLevel->SetArrayName(name);
400     }
401     else {
402       fDetectorLevel = AddParticleContainer(name);
403     }
404     fDetectorLevel->SetClassName("AliPicoTrack");
405   }
406   fDetectorLevel->SetArrayName(name);
407 }
408
409 //________________________________________________________________________
410 void AliEmcalTrackingQATask::ExecOnce()
411 {
412   // Init the analysis.
413
414   AliAnalysisTaskEmcal::ExecOnce();
415 }
416
417 //________________________________________________________________________
418 void AliEmcalTrackingQATask::FillDetectorLevelTHnSparse(Double_t cent, Double_t trackEta, Double_t trackPhi, Double_t trackPt, 
419                                                         Double_t sigma1OverPt, Int_t mcGen, Byte_t trackType)
420 {
421   Double_t contents[20]={0};
422
423   for (Int_t i = 0; i < fTracks->GetNdimensions(); i++) {
424     TString title(fTracks->GetAxis(i)->GetTitle());
425     if (title=="Centrality %")
426       contents[i] = cent;
427     else if (title=="#it{p}_{T} (GeV/#it{c})")
428       contents[i] = trackPt;
429     else if (title=="#eta")
430       contents[i] = trackEta;
431     else if (title=="#phi")
432       contents[i] = trackPhi;
433     else if (title=="#sigma(1/#it{p}_{T}) (GeV/#it{c})^{-1}")
434       contents[i] = sigma1OverPt;
435     else if (title=="#sigma(#it{p}_{T}) / #it{p}_{T}")
436       contents[i] = sigma1OverPt*trackPt;
437     else if (title=="MC Generator")
438       contents[i] = mcGen;
439     else if (title=="track type")
440       contents[i] = trackType;
441     else 
442       AliWarning(Form("Unable to fill dimension %s of histogram %s!", title.Data(), fTracks->GetName()));
443   }
444
445   fTracks->Fill(contents);
446 }
447
448 //________________________________________________________________________
449 void AliEmcalTrackingQATask::FillGeneratorLevelTHnSparse(Double_t cent, Double_t partEta, Double_t partPhi, Double_t partPt, Int_t mcGen, Byte_t findable)
450 {
451   Double_t contents[20]={0};
452
453   for (Int_t i = 0; i < fParticlesPhysPrim->GetNdimensions(); i++) {
454     TString title(fParticlesPhysPrim->GetAxis(i)->GetTitle());
455     if (title=="Centrality %")
456       contents[i] = cent;
457     else if (title=="#it{p}_{T} (GeV/#it{c})")
458       contents[i] = partPt;
459     else if (title=="#eta")
460       contents[i] = partEta;
461     else if (title=="#phi")
462       contents[i] = partPhi;
463     else if (title=="MC Generator")
464       contents[i] = mcGen;
465     else if (title=="Findable")
466       contents[i] = findable;
467     else 
468       AliWarning(Form("Unable to fill dimension %s of histogram %s!", title.Data(), fParticlesPhysPrim->GetName()));
469   }
470
471   fParticlesPhysPrim->Fill(contents);
472 }
473
474 //________________________________________________________________________
475 void AliEmcalTrackingQATask::FillMatchedParticlesTHnSparse(Double_t cent, Double_t partEta, Double_t partPhi, Double_t partPt,
476                                                            Double_t trackEta, Double_t trackPhi, Double_t trackPt, Byte_t trackType)
477 {
478   Double_t contents[20]={0};
479
480   for (Int_t i = 0; i < fParticlesMatched->GetNdimensions(); i++) {
481     TString title(fParticlesMatched->GetAxis(i)->GetTitle());
482     if (title=="Centrality %")
483       contents[i] = cent;
484     else if (title=="#it{p}_{T}^{gen} (GeV/#it{c})")
485       contents[i] = partPt;
486     else if (title=="#eta^{gen}")
487       contents[i] = partEta;
488     else if (title=="#phi^{gen}")
489       contents[i] = partPhi;
490     else if (title=="#it{p}_{T}^{det} (GeV/#it{c})")
491       contents[i] = trackPt;
492     else if (title=="#eta^{det}")
493       contents[i] = trackEta;
494     else if (title=="#phi^{det}")
495       contents[i] = trackPhi;
496     else if (title=="(#it{p}_{T}^{gen} - #it{p}_{T}^{det}) / #it{p}_{T}^{gen}")
497       contents[i] = (partPt - trackPt) / partPt;
498     else if (title=="(#it{p}_{T}^{gen} - #it{p}_{T}^{det}) / #it{p}_{T}^{det}")
499       contents[i] = (partPt - trackPt) / trackPt;
500     else if (title=="track type")
501       contents[i] = (Double_t)trackType;
502     else 
503       AliWarning(Form("Unable to fill dimension %s of histogram %s!", title.Data(), fParticlesMatched->GetName()));
504   }
505
506   fParticlesMatched->Fill(contents);
507 }
508
509 //________________________________________________________________________
510 Bool_t AliEmcalTrackingQATask::FillHistograms()
511 {
512   // Fill the histograms.
513
514   AliPicoTrack *track = static_cast<AliPicoTrack*>(fDetectorLevel->GetNextAcceptParticle(0));
515   while (track != 0) {
516     Byte_t type = track->GetTrackType();
517     if (type <= 2) {
518       Double_t sigma = 0;
519       if (fIsEsd) {
520         AliESDtrack *esdTrack = dynamic_cast<AliESDtrack*>(track->GetTrack());
521         if (esdTrack) sigma = TMath::Sqrt(esdTrack->GetSigma1Pt2());
522       }
523
524       Int_t label = TMath::Abs(track->GetLabel());
525       Int_t mcGen = 1;
526       // reject particles generated from other generators in the cocktail but keep fake tracks (label == 0)
527       if (fSelectHIJING && (label==0 || track->GetGeneratorIndex() == 0)) mcGen = 0;
528
529       FillDetectorLevelTHnSparse(fCent, track->Eta(), track->Phi(), track->Pt(), sigma, mcGen, type);
530       
531       if (fGeneratorLevel && label > 0) {
532         AliAODMCParticle *part =  static_cast<AliAODMCParticle*>(fGeneratorLevel->GetAcceptParticleWithLabel(label));
533         if (part) {
534           if (!fSelectHIJING || part->GetGeneratorIndex() == 0) {
535             Int_t pdg = TMath::Abs(part->PdgCode());
536             // select charged pions, protons, kaons , electrons, muons
537             if (pdg == 211 || pdg == 2212 || pdg == 321 || pdg == 11 || pdg == 13) {
538               FillMatchedParticlesTHnSparse(fCent, part->Eta(), part->Phi(), part->Pt(), track->Eta(), track->Phi(), track->Pt(), type);
539             }
540           }
541         }
542       }
543     }
544     else {
545       AliError(Form("Track %d has type %d not recognized!", fDetectorLevel->GetCurrentID(), type));
546     }
547
548     track = static_cast<AliPicoTrack*>(fDetectorLevel->GetNextAcceptParticle());
549   }
550
551   if (fGeneratorLevel) {
552     AliAODMCParticle *part = static_cast<AliAODMCParticle*>(fGeneratorLevel->GetNextAcceptParticle(0));
553     while (part != 0) {
554       Int_t mcGen = 1;
555       Byte_t findable = 0;
556       
557       if (fSelectHIJING && part->GetGeneratorIndex() == 0) mcGen = 0;
558
559       Int_t pdg = TMath::Abs(part->PdgCode());
560       // select charged pions, protons, kaons , electrons, muons
561       if (pdg == 211 || pdg == 2212 || pdg == 321 || pdg == 11 || pdg == 13) findable = 1;
562
563       FillGeneratorLevelTHnSparse(fCent, part->Eta(), part->Phi(), part->Pt(), mcGen, findable);    
564       part = static_cast<AliAODMCParticle*>(fGeneratorLevel->GetNextAcceptParticle());
565     }
566   }
567
568   return kTRUE;
569 }