]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/hfe/AliHFEtrdPIDqaV1.cxx
Update of the HFE package
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliHFEtrdPIDqaV1.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 // Class AliHFEtrdPIDqaV1
17 // Monitoring TRD PID in the HFE PID montioring framework. The following
18 // quantities are monitored:
19 //   TRD electron likelihood
20 //   TRD dE/dx (Absolute values)
21 //   TPC dE/dx (Number of sigmas, control histogram)
22 // (Always as function of momentum, particle species and centrality 
23 // before and after cut)
24 // More information about the PID monitoring framework can be found in
25 // AliHFEpidQAmanager.cxx and AliHFEdetPIDqa.cxx
26 //
27 // Author:
28 //    Markus Fasel <M.Fasel@gsi.de>
29 //
30
31 #include <TAxis.h>
32 #include <TBrowser.h>
33 #include <TH2.h>
34 #include <THnSparse.h>
35 #include <TString.h>
36
37 #include "AliESDtrack.h"
38 #include "AliLog.h"
39 #include "AliPID.h"
40
41 #include "AliHFEcollection.h"
42 #include "AliHFEpidBase.h"
43 #include "AliHFEpidQAmanager.h"
44 #include "AliHFEpidTPC.h"
45 #include "AliHFEpidTRD.h"
46 #include "AliHFEtrdPIDqaV1.h"
47
48 ClassImp(AliHFEtrdPIDqaV1)
49
50 //____________________________________________________________
51 AliHFEtrdPIDqaV1::AliHFEtrdPIDqaV1():
52     AliHFEdetPIDqa(),
53     fHistos(NULL)
54 {
55   //
56   // Dummy constructor
57   //
58 }
59
60 //____________________________________________________________
61 AliHFEtrdPIDqaV1::AliHFEtrdPIDqaV1(const Char_t *name):
62     AliHFEdetPIDqa(name, "QA for TRD"),
63     fHistos(NULL)
64 {
65   //
66   // Default constructor
67   //
68 }
69
70 //____________________________________________________________
71 AliHFEtrdPIDqaV1::AliHFEtrdPIDqaV1(const AliHFEtrdPIDqaV1 &o):
72     AliHFEdetPIDqa(o),
73     fHistos(NULL)
74 {
75   //
76   // Copy constructor
77   //
78 }
79
80 //____________________________________________________________
81 AliHFEtrdPIDqaV1 &AliHFEtrdPIDqaV1::operator=(const AliHFEtrdPIDqaV1 &o){
82   //
83   // Make assignment
84   //
85   AliHFEdetPIDqa::operator=(o);
86   fHistos = o.fHistos;
87   
88   return *this;
89 }
90
91 //_________________________________________________________
92 Long64_t AliHFEtrdPIDqaV1::Merge(TCollection *coll){
93   //
94   // Merge with other objects
95   //
96   if(!coll) return 0;
97   if(coll->IsEmpty()) return 1;
98
99   TIter it(coll);
100   AliHFEtrdPIDqaV1 *refQA = NULL;
101   TObject *o = NULL;
102   Long64_t count = 0;
103   TList listHistos;
104   while((o = it())){
105     refQA = dynamic_cast<AliHFEtrdPIDqaV1 *>(o);
106     if(!refQA) continue;
107
108     listHistos.Add(refQA->fHistos);
109     count++; 
110   }
111   fHistos->Merge(&listHistos);
112   return count + 1;
113 }
114
115 //_________________________________________________________
116 void AliHFEtrdPIDqaV1::Browse(TBrowser *b){
117   //
118   // Browse the PID QA
119   //
120   if(b){
121     if(fHistos){
122       b->Add(fHistos, fHistos->GetName());
123
124       // Make Projections of the dE/dx Spectra and add them to a new Folder
125       TString specnames[4] = {"All", "Electrons", "Pions", "Protons"};
126       Int_t specind[4] = {-1, AliPID::kElectron, AliPID::kPion, AliPID::kProton};
127       TList *listTM = new TList;
128       listTM->SetOwner();
129       TList *listLike = new TList;
130       listLike->SetOwner();
131       TList *listCharge = new TList;
132       listCharge->SetOwner();
133       TList *listTPCnsigma = new TList;
134       listTPCnsigma->SetOwner();
135
136       TH2 *hptr = NULL; 
137       TList *lctm, *lclike, *lccharge, *lcTPCsig;
138       for(Int_t icent = -1; icent < 11; icent++){
139         lctm = new TList;
140         lctm->SetName(icent < 0 ? "MinBias" : Form("Centrality%d", icent));
141         lctm->SetOwner();
142         listTM->Add(lctm);
143         lclike = new TList;
144         lclike->SetName(icent < 0 ? "MinBias" : Form("Centrality%d", icent));
145         lclike->SetOwner();
146         listLike->Add(lclike);
147         lccharge = new TList;
148         lccharge->SetName(icent < 0 ? "MinBias" : Form("Centrality%d", icent));
149         lccharge->SetOwner();
150         listCharge->Add(lccharge);
151         lcTPCsig = new TList;
152         lcTPCsig->SetName(icent < 0 ? "MinBias" : Form("Centrality%d", icent));
153         lcTPCsig->SetOwner();
154         listTPCnsigma->Add(lcTPCsig);
155         for(Int_t ispec = 0; ispec < 4; ispec++){
156           for(Int_t istep = 0; istep < 2; istep++){
157             hptr = MakeTRDspectrumTM(static_cast<AliHFEdetPIDqa::EStep_t>(istep), specind[ispec], icent);
158             if(hptr){
159               hptr->SetName(Form("hTRDtm%s%s", specnames[ispec].Data(), istep == 0 ? "Before" : "After"));
160               lctm->Add(hptr);
161             }
162             hptr = MakeTRDlikelihoodDistribution(static_cast<AliHFEdetPIDqa::EStep_t>(istep), specind[ispec], icent);
163             hptr->SetName(Form("hTRDlike%s%s", specnames[ispec].Data(), istep == 0 ? "Before" : "After"));
164             lclike->Add(hptr);
165             hptr = MakeTRDchargeDistribution(static_cast<AliHFEdetPIDqa::EStep_t>(istep), specind[ispec], icent);
166             hptr->SetName(Form("hTRDcharge%s%s", specnames[ispec].Data(), istep == 0 ? "Before" : "After"));
167             lccharge->Add(hptr);
168             hptr = MakeTPCspectrumNsigma(static_cast<AliHFEdetPIDqa::EStep_t>(istep), specind[ispec], icent);
169             hptr->SetName(Form("hTPCspectrum%s%s", specnames[ispec].Data(), istep == 0 ? "Before" : "After"));
170             lcTPCsig->Add(hptr);
171           }
172         }
173       }
174         
175       b->Add(listTM, "Projections Truncated Mean");
176       b->Add(listLike, "Projections Likelihood distribution");
177       b->Add(listCharge, "Projections Tracklet Charge");
178       b->Add(listTPCnsigma, "Projections TPC spectra");
179     }
180   }
181 }
182
183 //____________________________________________________________
184 void AliHFEtrdPIDqaV1::Initialize(){
185   //
186   // Initialize QA histos for TRD PID
187   //
188
189   AliDebug(1, "Initializing PID QA for TRD");
190   // Make common binning
191   const Int_t kPIDbins = AliPID::kSPECIES + 1;
192   const Int_t kPbins = 100;
193   const Int_t kSteps = 2;
194   const Double_t kMinPID = -1;
195   const Double_t kMinP = 0.;
196   const Double_t kMaxPID = (Double_t)AliPID::kSPECIES;
197   const Double_t kMaxP = 20.;
198   const Int_t kCentralityBins = 11;
199
200   // Define number of bins
201   Int_t tpcSigmaBins = fQAmanager->HasHighResolutionHistos() ? 1400 : 140;
202   Int_t trdLikelihoodBins = fQAmanager->HasHighResolutionHistos() ? 200 : 100;
203
204   fHistos = new AliHFEcollection("trdqahistos", "Collection of TRD QA histograms");
205   
206   // Create Control Histogram monitoring the TPC sigma between the selection steps
207   Int_t nBinsTPCSigma[5] = {kPIDbins, kPbins, tpcSigmaBins, kSteps, kCentralityBins};
208   Double_t minTPCSigma[5] = {kMinPID, kMinP, -12., 0., 0.};
209   Double_t maxTPCSigma[5] = {kMaxPID, kMaxP, 12., 2., 11.};
210   fHistos->CreateTHnSparse("hTPCsigma", "TPC sigma; species p [GeV/c]; TPC dEdx - <dE/dx>|_{el} [#sigma]; selection step", 5, nBinsTPCSigma, minTPCSigma, maxTPCSigma);
211   fHistos->Sumw2("hTPCsigma");
212   // Create Monitoring histogram for the Likelihood distribution
213   Int_t nBinsTRDlike[5] = {kPIDbins, kPbins, trdLikelihoodBins, kSteps, kCentralityBins};
214   Double_t minTRDlike[5] = {kMinPID, kMinP, 0., 0., 0.};
215   Double_t maxTRDlike[5] = {kMaxPID, kMaxP, 1., 2., 11.};
216   fHistos->CreateTHnSparse("hTRDlikelihood", "TRD Likelihood Distribution; species; p [GeV/c]; TRD electron Likelihood; selection step", 5, nBinsTRDlike, minTRDlike, maxTRDlike);
217   fHistos->Sumw2("hTRDlikelihood");
218   // Create Monitoring histogram for the TRD total charge
219   const Int_t kTRDchargeBins = 1000;
220   Int_t nBinsTRDcharge[5] = {kPIDbins, kPbins, kTRDchargeBins, kSteps, kCentralityBins};
221   Double_t minTRDcharge[5] = {kMinPID, kMinP, 0., 0., 0.};
222   Double_t maxTRDcharge[5] = {kMaxPID, kMaxP, 100000., 2., 11.};
223   fHistos->CreateTHnSparse("hTRDcharge", "Total TRD charge; species; p [GeV/c]; TRD charge [a.u.]; selection step", 5, nBinsTRDcharge, minTRDcharge, maxTRDcharge);
224   fHistos->Sumw2("hTRDcharge");
225   // Monitoring of the TRD truncated mean according to version 1
226   const Int_t kTRDtmBins = 1000;
227   Int_t nBinsTRDtm[5] = {kPIDbins, kPbins, kTRDtmBins, kSteps, kCentralityBins};
228   Double_t minTRDtm[5] = {kMinPID, kMinP, 0., 0., 0.};
229   Double_t maxTRDtm[5] = {kMaxPID, kMaxP, 20000., 2., 11.};
230   fHistos->CreateTHnSparse("hTRDtruncatedMean", "TRD truncated Mean; species; p [GeV/c]; TRD signal [a.u.]; selection step", 5, nBinsTRDtm, minTRDtm, maxTRDtm);
231   fHistos->Sumw2("hTRDtruncatedMean");
232 }
233
234 //____________________________________________________________
235 void AliHFEtrdPIDqaV1::ProcessTrack(const AliHFEpidObject *track, AliHFEdetPIDqa::EStep_t step){
236   //
237   // Process the track, fill the containers 
238   //
239   AliDebug(1, Form("QA started for TRD PID for step %d", (Int_t)step));
240   Int_t species = track->GetAbInitioPID();
241   if(species >= AliPID::kSPECIES) species = -1;
242   AliHFEpidObject::AnalysisType_t anatype = track->IsESDanalysis() ? AliHFEpidObject::kESDanalysis : AliHFEpidObject::kAODanalysis;
243
244   AliHFEpidTRD *trdpid = dynamic_cast<AliHFEpidTRD *>(fQAmanager->GetDetectorPID(AliHFEpid::kTRDpid));
245   AliHFEpidTPC *tpcpid = dynamic_cast<AliHFEpidTPC *>(fQAmanager->GetDetectorPID(AliHFEpid::kTPCpid));
246  
247   Double_t container[5];
248   container[0] = species;
249   container[1] = trdpid ? trdpid->GetP(track->GetRecTrack(), anatype) : 0.;
250   container[2] = tpcpid ? tpcpid->NumberOfSigmas(track->GetRecTrack(), AliPID::kElectron, anatype) : 0.;
251   container[3] = step;
252   container[4] = track->GetCentrality();
253   fHistos->Fill("hTPCsigma", container);
254
255   container[2] = trdpid ? trdpid->GetElectronLikelihood(track->GetRecTrack(), anatype) : 0;
256   fHistos->Fill("hTRDlikelihood", container);
257
258   if(track->IsESDanalysis()){
259     container[2] = trdpid ? trdpid->GetTRDSignalV1(dynamic_cast<const AliESDtrack *>(track->GetRecTrack())) : 0;
260     fHistos->Fill("hTRDtruncatedMean", container);
261   }
262   for(UInt_t ily = 0; ily < 6; ily++){
263     container[2] = trdpid ? trdpid->GetChargeLayer(track->GetRecTrack(), ily, anatype) : 0;
264     if(container[2] < 1e-3) continue; // Filter out 0 entries
265     fHistos->Fill("hTRDcharge", container);
266   }
267 }
268
269 //_________________________________________________________
270 TH2 *AliHFEtrdPIDqaV1::MakeTPCspectrumNsigma(AliHFEdetPIDqa::EStep_t step, Int_t species, Int_t centralityClass){
271   //
272   // Get the TPC control histogram for the TRD selection step (either before or after PID)
273   //
274   THnSparseF *histo = dynamic_cast<THnSparseF *>(fHistos->Get("hTPCsigma"));
275   if(!histo){
276     AliError("QA histogram monitoring TPC nSigma not available");
277     return NULL;
278   }
279   if(species > -1 && species < AliPID::kSPECIES){
280     // cut on species (if available)
281     histo->GetAxis(0)->SetRange(species + 2, species + 2); // undef + underflow
282   }
283   TString centname, centtitle;
284   Bool_t hasCentralityInfo = kTRUE;
285   if(centralityClass > -1){
286     if(histo->GetNdimensions() < 5){
287       AliError("Centrality Information not available");
288       centname = centtitle = "MinBias";
289       hasCentralityInfo = kFALSE;
290     } else {
291       // Project centrality classes
292       // -1 is Min. Bias
293       histo->GetAxis(4)->SetRange(centralityClass+1, centralityClass+1);
294       centname = Form("Cent%d", centralityClass);
295       centtitle = Form("Centrality %d", centralityClass);
296     }
297   } else {
298     histo->GetAxis(4)->SetRange(1, histo->GetAxis(4)->GetNbins()-1);
299     centname = centtitle = "MinBias";
300     hasCentralityInfo = kTRUE;
301   }
302   histo->GetAxis(3)->SetRange(step + 1, step + 1); 
303
304   TH2 *hSpec = histo->Projection(2, 1);
305   // construct title and name
306   TString stepname = step == AliHFEdetPIDqa::kBeforePID ? "before" : "after";
307   TString speciesname = species > -1 && species < AliPID::kSPECIES ? AliPID::ParticleName(species) : "all Particles";
308   TString specID = species > -1 && species < AliPID::kSPECIES ? AliPID::ParticleName(species) : "unid";
309   TString histname = Form("hSigmaTPC%s%s%s", specID.Data(), stepname.Data(), centname.Data());
310   TString histtitle = Form("TPC Sigma for %s %s PID %s", speciesname.Data(), stepname.Data(), centtitle.Data());
311   hSpec->SetName(histname.Data());
312   hSpec->SetTitle(histtitle.Data());
313
314   // Unset range on the original histogram
315   histo->GetAxis(0)->SetRange(0, histo->GetAxis(0)->GetNbins());
316   histo->GetAxis(3)->SetRange(0, histo->GetAxis(3)->GetNbins());
317   if(hasCentralityInfo)histo->GetAxis(4)->SetRange(0, histo->GetAxis(4)->GetNbins());
318   return hSpec; 
319 }
320
321 //_________________________________________________________
322 TH2 *AliHFEtrdPIDqaV1::MakeTRDspectrumTM(AliHFEdetPIDqa::EStep_t step, Int_t species, Int_t centralityClass){
323   //
324   // Get the TPC control histogram for the TRD selection step (either before or after PID)
325   //
326   THnSparseF *histo = dynamic_cast<THnSparseF *>(fHistos->Get("hTRDtruncatedMean"));
327   if(!histo){
328     AliError("QA histogram monitoring TPC nSigma not available");
329     return NULL;
330   }
331   if(species > -1 && species < AliPID::kSPECIES){
332     // cut on species (if available)
333     histo->GetAxis(0)->SetRange(species + 2, species + 2); // undef + underflow
334   }
335   TString centname, centtitle;
336   Bool_t hasCentralityInfo = kTRUE;
337   if(centralityClass > -1){
338      if(histo->GetNdimensions() < 5){
339       AliError("Centrality Information not available");
340       centname = centtitle = "MinBias";
341       hasCentralityInfo= kFALSE;
342     } else {
343       // Project centrality classes
344       // -1 is Min. Bias
345       histo->GetAxis(4)->SetRange(centralityClass+1, centralityClass+1);
346       centname = Form("Cent%d", centralityClass);
347       centtitle = Form("Centrality %d", centralityClass);
348     }
349   } else {
350     histo->GetAxis(4)->SetRange(1, histo->GetAxis(4)->GetNbins()-1);
351     centname = centtitle = "MinBias";
352     hasCentralityInfo= kFALSE;
353   }
354   histo->GetAxis(3)->SetRange(step + 1, step + 1); 
355
356   TH2 *hSpec = histo->Projection(2, 1);
357   // construct title and name
358   TString stepname = step == AliHFEdetPIDqa::kBeforePID ? "before" : "after";
359   TString speciesname = species > -1 && species < AliPID::kSPECIES ? AliPID::ParticleName(species) : "all Particles";
360   TString specID = species > -1 && species < AliPID::kSPECIES ? AliPID::ParticleName(species) : "unid";
361   TString histname = Form("hTMTRD%s%s%s", specID.Data(), stepname.Data(), centname.Data());
362   TString histtitle = Form("TRD Truncated Mean for %s %s PID %s", speciesname.Data(), stepname.Data(), centtitle.Data());
363   hSpec->SetName(histname.Data());
364   hSpec->SetTitle(histtitle.Data());
365
366   // Unset range on the original histogram
367   histo->GetAxis(0)->SetRange(0, histo->GetAxis(0)->GetNbins());
368   histo->GetAxis(2)->SetRange(0, histo->GetAxis(2)->GetNbins());
369   if(hasCentralityInfo)histo->GetAxis(4)->SetRange(0, histo->GetAxis(4)->GetNbins());
370   return hSpec; 
371 }
372
373 //_________________________________________________________
374 TH2 *AliHFEtrdPIDqaV1::MakeTRDlikelihoodDistribution(AliHFEdetPIDqa::EStep_t step, Int_t species, Int_t centralityClass){
375   //
376   // Make Histogram for TRD Likelihood distribution
377   //
378   THnSparseF *histo = dynamic_cast<THnSparseF *>(fHistos->Get("hTRDlikelihood"));
379   if(!histo){
380     AliError("QA histogram monitoring TRD Electron Likelihood not available");
381     return NULL;
382   }
383   if(species > -1 && species < AliPID::kSPECIES){
384     // cut on species (if available)
385     histo->GetAxis(0)->SetRange(species + 2, species + 2); // undef + underflow
386   }
387   TString centname, centtitle;
388   Bool_t hasCentralityInfo = kTRUE;
389   if(centralityClass > -1){
390     if(histo->GetNdimensions() < 5){
391       AliError("Centrality Information not available");
392       centname = centtitle = "MinBias";
393       hasCentralityInfo= kFALSE;
394     } else {
395       // Project centrality classes
396       // -1 is Min. Bias
397       histo->GetAxis(4)->SetRange(centralityClass+1, centralityClass+1);
398       centname = Form("Cent%d", centralityClass);
399       centtitle = Form("Centrality %d", centralityClass);
400     }
401   } else {
402     histo->GetAxis(4)->SetRange(1, histo->GetAxis(4)->GetNbins()-1);
403     centname = centtitle = "MinBias";
404     hasCentralityInfo= kTRUE;
405   }
406   histo->GetAxis(3)->SetRange(step + 1, step + 1);
407
408   TH2 *hSpec = histo->Projection(2, 1);
409   // construct title and name
410   TString stepname = step == AliHFEdetPIDqa::kBeforePID ? "before" : "after";
411   TString speciesname = species > -1 && species < AliPID::kSPECIES ? AliPID::ParticleName(species) : "all Particles";
412   TString specID = species > -1 && species < AliPID::kSPECIES ? AliPID::ParticleName(species) : "unid";
413   TString histname = Form("hLikeElTRD%s%s%s", specID.Data(), stepname.Data(),centname.Data());
414   TString histtitle = Form("TRD electron Likelihood for %s %s PID %s", speciesname.Data(), stepname.Data(),centtitle.Data());
415   hSpec->SetName(histname.Data());
416   hSpec->SetTitle(histtitle.Data());
417
418   // Unset range on the original histogram
419   histo->GetAxis(0)->SetRange(0, histo->GetAxis(0)->GetNbins());
420   histo->GetAxis(2)->SetRange(0, histo->GetAxis(2)->GetNbins());
421   if(hasCentralityInfo)histo->GetAxis(4)->SetRange(0, histo->GetAxis(4)->GetNbins());
422   return hSpec; 
423 }
424
425 //_________________________________________________________
426 TH2 *AliHFEtrdPIDqaV1::MakeTRDchargeDistribution(AliHFEdetPIDqa::EStep_t step, Int_t species, Int_t centralityClass){
427   //
428   // Make Histogram for TRD Likelihood distribution
429   //
430   THnSparseF *histo = dynamic_cast<THnSparseF *>(fHistos->Get("hTRDcharge"));
431   if(!histo){
432     AliError("QA histogram monitoring TRD total charge not available");
433     return NULL;
434   }
435   if(species > -1 && species < AliPID::kSPECIES){
436     // cut on species (if available)
437     histo->GetAxis(0)->SetRange(species + 2, species + 2); // undef + underflow
438   }
439   TString centname, centtitle;
440   Bool_t hasCentralityInfo = kTRUE;
441   if(centralityClass > -1){
442     if(histo->GetNdimensions() < 5){
443       AliError("Centrality Information not available");
444       centname = centtitle = "MinBias";
445       hasCentralityInfo= kFALSE;
446     } else {
447       // Project centrality classes
448       // -1 is Min. Bias
449       histo->GetAxis(4)->SetRange(centralityClass+1, centralityClass+1);
450       centname = Form("Cent%d", centralityClass);
451       centtitle = Form("Centrality %d", centralityClass);
452     }
453   } else {
454     histo->GetAxis(4)->SetRange(1, histo->GetAxis(4)->GetNbins()-1);
455     centname = centtitle = "MinBias";
456     hasCentralityInfo= kTRUE;
457   }
458   histo->GetAxis(3)->SetRange(step + 1, step + 1);
459
460   TH2 *hSpec = histo->Projection(2, 1);
461   // construct title and name
462   TString stepname = step == AliHFEdetPIDqa::kBeforePID ? "before" : "after";
463   TString speciesname = species > -1 && species < AliPID::kSPECIES ? AliPID::ParticleName(species) : "all Particles";
464   TString specID = species > -1 && species < AliPID::kSPECIES ? AliPID::ParticleName(species) : "unid";
465   TString histname = Form("hChargeTRD%s%s%s", specID.Data(), stepname.Data(), centname.Data());
466   TString histtitle = Form("TRD total charge for %s %s PID %s", speciesname.Data(), stepname.Data(), centtitle.Data());
467   hSpec->SetName(histname.Data());
468   hSpec->SetTitle(histtitle.Data());
469
470   // Unset range on the original histogram
471   histo->GetAxis(0)->SetRange(0, histo->GetAxis(0)->GetNbins());
472   histo->GetAxis(2)->SetRange(0, histo->GetAxis(2)->GetNbins());
473   if(hasCentralityInfo)histo->GetAxis(4)->SetRange(0, histo->GetAxis(4)->GetNbins());
474   return hSpec; 
475 }
476