]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/hfe/AliHFEtpcPIDqa.cxx
Update
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliHFEtpcPIDqa.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 AliHFEtpcPIDqa
17 // Monitoring TPC PID in the HFE PID montioring framework. The following
18 // quantities are monitored:
19 //   TPC dE/dx (Number of sigmas)
20 //   TPC dE/dx (Absolute values)
21 // (Always as function of momentum, particle species and centrality 
22 // before and after cut)
23 // More information about the PID monitoring framework can be found in
24 // AliHFEpidQAmanager.cxx and AliHFEdetPIDqa.cxx
25 //
26 // Author:
27 //    Markus Fasel <M.Fasel@gsi.de>
28 //
29 #include <TBrowser.h>
30 #include <TClass.h>
31 #include <TH2.h>
32 #include <THnSparse.h>
33 #include <TString.h>
34
35 #include "AliAODTrack.h"
36 #include "AliESDtrack.h"
37 #include "AliLog.h"
38 #include "AliPID.h"
39 #include "AliPIDResponse.h"
40
41 #include "AliHFEcollection.h"
42 #include "AliHFEpidBase.h"
43 #include "AliHFEpidQAmanager.h"
44 #include "AliHFEpidTPC.h"
45 #include "AliHFEtools.h"
46 #include "AliHFEtpcPIDqa.h"
47
48 ClassImp(AliHFEtpcPIDqa)
49
50 //_________________________________________________________
51 AliHFEtpcPIDqa::AliHFEtpcPIDqa():
52     AliHFEdetPIDqa()
53   , fHistos(NULL)
54   , fBrowseCentrality(-1)
55 {
56   //
57   // Dummy constructor
58   //
59 }
60
61 //_________________________________________________________
62 AliHFEtpcPIDqa::AliHFEtpcPIDqa(const char* name):
63     AliHFEdetPIDqa(name, "QA for TPC")
64   , fHistos(NULL)
65   , fBrowseCentrality(-1)
66 {
67   //
68   // Default constructor
69   //
70 }
71
72 //_________________________________________________________
73 AliHFEtpcPIDqa::AliHFEtpcPIDqa(const AliHFEtpcPIDqa &o):
74     AliHFEdetPIDqa(o)
75   , fHistos(NULL)
76   , fBrowseCentrality(o.fBrowseCentrality)
77 {
78   //
79   // Copy constructor
80   //
81   o.Copy(*this);
82 }
83
84 //_________________________________________________________
85 AliHFEtpcPIDqa &AliHFEtpcPIDqa::operator=(const AliHFEtpcPIDqa &o){
86   //
87   // Do assignment
88   //
89   AliHFEdetPIDqa::operator=(o);
90   if(&o != this) o.Copy(*this);
91   return *this;
92 }
93
94 //_________________________________________________________
95 AliHFEtpcPIDqa::~AliHFEtpcPIDqa(){
96   //
97   // Destructor
98   //
99   if(fHistos) delete fHistos;
100 }
101
102 //_________________________________________________________
103 void AliHFEtpcPIDqa::Copy(TObject &o) const {
104   //
105   // Make copy
106   //
107   AliHFEtpcPIDqa &target = dynamic_cast<AliHFEtpcPIDqa &>(o);
108   if(target.fHistos){
109     delete target.fHistos;
110     target.fHistos = NULL;
111   }
112   if(fHistos) target.fHistos = new AliHFEcollection(*fHistos);
113   target.fBrowseCentrality = fBrowseCentrality;
114 }
115
116 //_________________________________________________________
117 Long64_t AliHFEtpcPIDqa::Merge(TCollection *coll){
118   //
119   // Merge with other objects
120   //
121   if(!coll) return 0;
122   if(coll->IsEmpty()) return 1;
123
124   TIter it(coll);
125   AliHFEtpcPIDqa *refQA = NULL;
126   TObject *o = NULL;
127   Long64_t count = 0;
128   TList listHistos;
129   while((o = it())){
130     refQA = dynamic_cast<AliHFEtpcPIDqa *>(o);
131     if(!refQA) continue;
132
133     listHistos.Add(refQA->fHistos);
134     count++; 
135   }
136   fHistos->Merge(&listHistos);
137   return count + 1;
138 }
139
140 //_________________________________________________________
141 void AliHFEtpcPIDqa::Browse(TBrowser *b){
142   //
143   // Browse the PID QA
144   //
145   if(b){
146     if(fHistos){
147       b->Add(fHistos, fHistos->GetName());
148
149       // Make Projections of the dE/dx Spectra and add them to a new Folder
150       TString specnames[AliPID::kSPECIES+1] = {"All", "Electrons", "Muon", "Pions", "Kaon", "Protons"};
151       Int_t specind[AliPID::kSPECIES+1] = {-1, AliPID::kElectron, AliPID::kMuon, AliPID::kPion, AliPID::kKaon, AliPID::kProton};
152       TList *listdEdx = new TList;
153       listdEdx->SetOwner();
154       TList *listNsigma = new TList;
155       listNsigma->SetOwner();
156
157       TH2 *hptr = NULL; 
158       for(Int_t ispec = 0; ispec < AliPID::kSPECIES+1; ispec++){
159         for(Int_t istep = 0; istep < 2; istep++){
160           hptr = MakeSpectrumdEdx(static_cast<AliHFEdetPIDqa::EStep_t>(istep), specind[ispec], fBrowseCentrality);
161           hptr->SetName(Form("hTPCdEdx%s%s%s", specnames[ispec].Data(), istep == 0 ? "Before" : "After" , fBrowseCentrality == -1 ? "MinBias" : Form("Cent%d", fBrowseCentrality)));
162           listdEdx->Add(hptr);
163           hptr = MakeSpectrumNSigma(static_cast<AliHFEdetPIDqa::EStep_t>(istep), specind[ispec], fBrowseCentrality);
164           hptr->SetName(Form("hTPCnsigma%s%s%s", specnames[ispec].Data(), istep == 0 ? "Before" : "After", fBrowseCentrality == -1 ? "MinBias" : Form("Cent%d", fBrowseCentrality)));
165           listNsigma->Add(hptr);
166         }
167       }
168       
169       b->Add(listdEdx, "Projections dE/dx");
170       b->Add(listNsigma, "Projections NSigma");
171     }
172   }
173 }
174
175 //_________________________________________________________
176 void AliHFEtpcPIDqa::Initialize(){
177   //
178   // Define Histograms
179   //
180
181   fHistos = new AliHFEcollection("tpcqahistos", "Collection of TPC QA histograms");
182
183   // Make common binning
184   const Int_t kNdim = 6;
185   const Int_t kPIDbins = AliPID::kSPECIES + 1;
186   const Int_t kSteps = 2;
187   const Int_t kCentralityBins = 11;
188   const Int_t kEtabins=18;
189   const Double_t kMinPID = -1;
190   const Double_t kMinP = 0.;
191   const Double_t kMaxPID = (Double_t)AliPID::kSPECIES;
192   const Double_t kMaxP = 20.;
193   const Double_t kMinEta = -0.9;
194   const Double_t kMaxEta = 0.9;
195
196   // Quantities where one can switch between low and high resolution
197   Int_t kPbins = fQAmanager->HasHighResolutionHistos() ? 1000 : 100;
198   Int_t kDedxbins = fQAmanager->HasHighResolutionHistos() ? 400 : 200;
199   Int_t kSigmaBins = fQAmanager->HasHighResolutionHistos() ? 1400 : 240;
200  
201   // 1st histogram: TPC dEdx: (species, p, dEdx, step)
202   Int_t nBinsdEdx[kNdim] = {kPIDbins, kPbins, kDedxbins, kSteps, kCentralityBins, kEtabins};
203   Double_t mindEdx[kNdim] =  {kMinPID, kMinP, 0., 0., 0., kMinEta};
204   Double_t maxdEdx[kNdim] =  {kMaxPID, kMaxP, 200, 2., 11., kMaxEta};
205   fHistos->CreateTHnSparse("tpcDedx", "TPC signal; species; p [GeV/c]; TPC signal [a.u.]; Selection Step; Centrality; Eta", kNdim, nBinsdEdx, mindEdx, maxdEdx);
206   // 2nd histogram: TPC sigmas: (species, p nsigma, step)
207   Int_t nBinsSigma[kNdim] = {kPIDbins, kPbins, kSigmaBins, kSteps, kCentralityBins, kEtabins};
208   Double_t minSigma[kNdim] = {kMinPID, kMinP, -12., 0., 0., kMinEta};
209   Double_t maxSigma[kNdim] = {kMaxPID, kMaxP, 12., 2., 11., kMaxEta};
210   fHistos->CreateTHnSparse("tpcnSigma", "TPC signal; species; p [GeV/c]; TPC signal [a.u.]; Selection Step; Centrality; Eta", kNdim, nBinsSigma, minSigma, maxSigma);
211
212   // General TPC QA
213 }
214
215 //_________________________________________________________
216 void AliHFEtpcPIDqa::ProcessTrack(const AliHFEpidObject *track, AliHFEdetPIDqa::EStep_t step){
217   //
218   // Fill TPC histograms
219   //
220   AliDebug(1, Form("QA started for TPC PID for step %d", (Int_t)step));
221   AliHFEpidObject::AnalysisType_t anatype = track->IsESDanalysis() ? AliHFEpidObject::kESDanalysis : AliHFEpidObject::kAODanalysis;
222   Float_t centrality = track->GetCentrality();
223   Int_t species = track->GetAbInitioPID();
224   if(species >= AliPID::kSPECIES) species = -1;
225
226   AliHFEpidTPC *tpcpid = dynamic_cast<AliHFEpidTPC *>(fQAmanager->GetDetectorPID(AliHFEpid::kTPCpid));
227   const AliPIDResponse *pidResponse = tpcpid ? tpcpid->GetPIDResponse() : NULL;
228   Double_t contentSignal[6];
229   contentSignal[0] = species;
230   contentSignal[1] = tpcpid ? tpcpid->GetP(track->GetRecTrack(), anatype) : 0.;
231   contentSignal[2] = GetTPCsignal(track->GetRecTrack(), anatype);
232   contentSignal[3] = step;
233   contentSignal[4] = centrality;
234   contentSignal[5] = GetEta(track->GetRecTrack(), anatype);
235   fHistos->Fill("tpcDedx", contentSignal);
236
237   contentSignal[2] = pidResponse ? pidResponse->NumberOfSigmasTPC(track->GetRecTrack(), AliPID::kElectron) : -100.; 
238   fHistos->Fill("tpcnSigma", contentSignal);
239 }
240
241 //_________________________________________________________
242 Double_t AliHFEtpcPIDqa::GetTPCsignal(const AliVParticle *track, AliHFEpidObject::AnalysisType_t anatype){
243   //
244   // Get TPC signal for ESD and AOD track
245   //
246   Double_t tpcSignal = 0.;
247   if(anatype == AliHFEpidObject::kESDanalysis){
248     const AliESDtrack *esdtrack = static_cast<const AliESDtrack *>(track);
249     tpcSignal = esdtrack->GetTPCsignal();
250   } else {
251     const AliAODTrack *aodtrack = static_cast<const AliAODTrack *>(track);
252     tpcSignal = aodtrack->GetDetPid() ? aodtrack->GetDetPid()->GetTPCsignal() : 0.;
253   }
254   return tpcSignal;
255 }
256
257
258 //_________________________________________________________
259 Double_t AliHFEtpcPIDqa::GetEta(const AliVParticle *track, AliHFEpidObject::AnalysisType_t anatype){
260   //
261   // Get TPC signal for ESD and AOD track
262   //
263   Double_t eta = 0.;
264   if(anatype == AliHFEpidObject::kESDanalysis){
265     const AliESDtrack *esdtrack = static_cast<const AliESDtrack *>(track);
266     eta = esdtrack->Eta();
267   } else {
268     const AliAODTrack *aodtrack = static_cast<const AliAODTrack *>(track);
269     eta = aodtrack->Eta(); 
270   }
271   return eta;
272 }
273
274 //_________________________________________________________
275 TH2 *AliHFEtpcPIDqa::MakeSpectrumdEdx(AliHFEdetPIDqa::EStep_t istep, Int_t species, Int_t centralityClass){
276   //
277   // Plot the Spectrum
278   //
279   THnSparseF *hSignal = dynamic_cast<THnSparseF *>(fHistos->Get("tpcDedx"));
280   if(!hSignal) return NULL;
281   hSignal->GetAxis(3)->SetRange(istep + 1, istep + 1);
282   if(species >= 0 && species < AliPID::kSPECIES)
283     hSignal->GetAxis(0)->SetRange(2 + species, 2 + species);
284   TString hname = Form("hTPCsignal%s", istep == AliHFEdetPIDqa::kBeforePID ? "before" : "after"), 
285           htitle = Form("TPC dE/dx Spectrum %s selection", istep == AliHFEdetPIDqa::kBeforePID ? "before" : "after");
286   if(species > -1){
287     hname += AliPID::ParticleName(species);
288     htitle += Form(" for %ss", AliPID::ParticleName(species));
289   }
290   TString centname, centtitle;
291   Bool_t hasCentralityInfo = kTRUE;
292   if(centralityClass > -1){
293     if(hSignal->GetNdimensions() < 5){
294       AliError("Centrality Information not available");
295       centname = centtitle = "MinBias";
296       hasCentralityInfo= kFALSE;
297     } else {
298       // Project centrality classes
299       // -1 is Min. Bias
300       hSignal->GetAxis(4)->SetRange(centralityClass+1, centralityClass+1);
301       centname = Form("Cent%d", centralityClass);
302       centtitle = Form(" Centrality %d", centralityClass);
303     }
304   } else {
305     centname = centtitle = "MinBias";
306     hasCentralityInfo= kFALSE;
307   }
308   hname += centtitle;
309   htitle += centtitle;
310
311   TH2 *hTmp = hSignal->Projection(2,1);
312   hTmp->SetName(hname.Data());
313   hTmp->SetTitle(htitle.Data());
314   hTmp->SetStats(kFALSE);
315   hTmp->GetXaxis()->SetTitle("p [GeV/c]");
316   hTmp->GetYaxis()->SetTitle("TPC signal [a.u.]");
317   hSignal->GetAxis(3)->SetRange(0, hSignal->GetAxis(3)->GetNbins());
318   hSignal->GetAxis(0)->SetRange(0, hSignal->GetAxis(0)->GetNbins());
319   if(hasCentralityInfo) hSignal->GetAxis(4)->SetRange(0, hSignal->GetAxis(4)->GetNbins());
320   return hTmp;
321 }
322
323 //_________________________________________________________
324 TH2 *AliHFEtpcPIDqa::MakeSpectrumNSigma(AliHFEdetPIDqa::EStep_t istep, Int_t species, Int_t centralityClass){
325   //
326   // Plot the Spectrum
327   //
328   THnSparseF *hSignal = dynamic_cast<THnSparseF *>(fHistos->Get("tpcnSigma"));
329   if(!hSignal) return NULL;
330   hSignal->GetAxis(3)->SetRange(istep + 1, istep + 1);
331   if(species >= 0 && species < AliPID::kSPECIES)
332     hSignal->GetAxis(0)->SetRange(2 + species, 2 + species);
333   TString hname = Form("hTPCsigma%s", istep == AliHFEdetPIDqa::kBeforePID ? "before" : "after"), 
334           htitle = Form("TPC dE/dx Spectrum[#sigma] %s selection", istep == AliHFEdetPIDqa::kBeforePID ? "before" : "after");
335   if(species > -1){
336     hname += AliPID::ParticleName(species);
337     htitle += Form(" for %ss", AliPID::ParticleName(species));
338   }
339   TString centname, centtitle;
340   Bool_t hasCentralityInfo = kTRUE;
341   if(centralityClass > -1){
342     if(hSignal->GetNdimensions() < 5){
343       AliError("Centrality Information not available");
344       centname = centtitle = "MinBias";
345       hasCentralityInfo= kFALSE;
346     } else {
347       // Project centrality classes
348       // -1 is Min. Bias
349       hSignal->GetAxis(4)->SetRange(centralityClass+1, centralityClass+1);
350       centname = Form("Cent%d", centralityClass);
351       centtitle = Form(" Centrality %d", centralityClass);
352     }
353   } else {
354     centname = centtitle = "MinBias";
355     hasCentralityInfo= kFALSE;
356   }
357   hname += centtitle;
358   htitle += centtitle;
359
360   TH2 *hTmp = hSignal->Projection(2,1);
361   hTmp->SetName(hname.Data());
362   hTmp->SetTitle(htitle.Data());
363   hTmp->SetStats(kFALSE);
364   hTmp->GetXaxis()->SetTitle("p [GeV/c]");
365   hTmp->GetYaxis()->SetTitle("TPC dE/dx - <dE/dx>|_{el} [#sigma]");
366   hSignal->GetAxis(3)->SetRange(0, hSignal->GetAxis(3)->GetNbins());
367   hSignal->GetAxis(0)->SetRange(0, hSignal->GetAxis(0)->GetNbins());
368   if(hasCentralityInfo) hSignal->GetAxis(4)->SetRange(0, hSignal->GetAxis(4)->GetNbins());
369   return hTmp;
370 }
371