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