]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/hfe/AliHFEtofPIDqa.cxx
Transition PWG3 --> PWGHF
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliHFEtofPIDqa.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 AliHFEtofPIDqa
17 //
18 // Monitoring TOF PID in the HFE PID montioring framework. The following
19 // quantities are monitored:
20 //   TOF time distance to electron hypothesis (Number of sigmas)
21 //   TOF time distance to the pion hypothesis (Absolute value)
22 //   TPC dE/dx (Number of sigmas, as control histogram)
23 // (Always as function of momentum, particle species and centrality 
24 // before and after cut)
25 // More information about the PID monitoring framework can be found in
26 // AliHFEpidQAmanager.cxx and AliHFEdetPIDqa.cxx
27 //
28 // Author:
29 //
30 //   Markus Fasel <M.Fasel@gsi.de>
31 #include <TClass.h>
32 #include <TH2.h>
33 #include <THnSparse.h>
34 #include <TString.h>
35
36 #include "AliLog.h"
37 #include "AliPID.h"
38 #include "AliPIDResponse.h"
39 #include "AliVParticle.h"
40
41 #include "AliHFEcollection.h"
42 #include "AliHFEpid.h"
43 #include "AliHFEpidBase.h"
44 #include "AliHFEpidQAmanager.h"
45 #include "AliHFEpidTPC.h"
46 #include "AliHFEpidTOF.h"
47 #include "AliHFEtools.h"
48 #include "AliHFEtofPIDqa.h"
49
50 ClassImp(AliHFEpidTOF)
51
52 //_________________________________________________________
53 AliHFEtofPIDqa::AliHFEtofPIDqa():
54     AliHFEdetPIDqa()
55   , fHistos(NULL)
56 {
57   //
58   // Dummy constructor
59   //
60 }
61
62 //_________________________________________________________
63 AliHFEtofPIDqa::AliHFEtofPIDqa(const char* name):
64     AliHFEdetPIDqa(name, "QA for TOF")
65   , fHistos(NULL)
66 {
67   //
68   // Default constructor
69   //
70 }
71
72 //_________________________________________________________
73 AliHFEtofPIDqa::AliHFEtofPIDqa(const AliHFEtofPIDqa &o):
74     AliHFEdetPIDqa(o)
75   , fHistos()
76 {
77   //
78   // Copy constructor
79   //
80   o.Copy(*this);
81 }
82
83 //_________________________________________________________
84 AliHFEtofPIDqa &AliHFEtofPIDqa::operator=(const AliHFEtofPIDqa &o){
85   //
86   // Do assignment
87   //
88   AliHFEdetPIDqa::operator=(o);
89   if(&o != this) o.Copy(*this);
90   return *this;
91 }
92
93 //_________________________________________________________
94 AliHFEtofPIDqa::~AliHFEtofPIDqa(){
95   //
96   // Destructor
97   //
98   if(fHistos) delete fHistos;
99 }
100
101 //_________________________________________________________
102 void AliHFEtofPIDqa::Copy(TObject &o) const {
103   //
104   // Make copy
105   //
106   AliHFEtofPIDqa &target = dynamic_cast<AliHFEtofPIDqa &>(o);
107   if(target.fHistos){
108     delete target.fHistos;
109     target.fHistos = NULL;
110   }
111   if(fHistos) target.fHistos = new AliHFEcollection(*fHistos);
112 }
113
114 //_________________________________________________________
115 Long64_t AliHFEtofPIDqa::Merge(TCollection *coll){
116   //
117   // Merge with other objects
118   //
119   if(!coll) return 0;
120   if(coll->IsEmpty()) return 1;
121
122   TIter it(coll);
123   AliHFEtofPIDqa *refQA = NULL;
124   TObject *o = NULL;
125   Long64_t count = 0;
126   TList listHistos;
127   while((o = it())){
128     refQA = dynamic_cast<AliHFEtofPIDqa *>(o);
129     if(!refQA) continue;
130
131     listHistos.Add(refQA->fHistos);
132     count++; 
133   }
134   fHistos->Merge(&listHistos);
135   return count + 1;
136 }
137
138 //_________________________________________________________
139 void AliHFEtofPIDqa::Initialize(){
140   //
141   // Define Histograms
142   //
143
144   fHistos = new AliHFEcollection("tofqahistos", "Collection of TOF QA histograms");
145
146   // Make common binning
147   const Int_t kPIDbins = AliPID::kSPECIES + 1;
148   const Int_t kSteps = 2;
149   const Int_t kCentralityBins = 11;
150   const Double_t kMinPID = -1;
151   const Double_t kMinP = 0.;
152   const Double_t kMaxPID = (Double_t)AliPID::kSPECIES;
153   const Double_t kMaxP = 20.;
154   // Quantities where one can switch between low and high resolution
155   Int_t kPbins = fQAmanager->HasHighResolutionHistos() ?  1000 : 100;
156   Int_t kSigmaBins = fQAmanager->HasHighResolutionHistos() ? 1400 : 240;
157
158   // 1st histogram: TOF sigmas: (species, p nsigma, step)
159   Int_t nBinsSigma[5] = {kPIDbins, kPbins, kSigmaBins, kSteps, kCentralityBins};
160   Double_t minSigma[5] = {kMinPID, kMinP, -12., 0, 0};
161   Double_t maxSigma[5] = {kMaxPID, kMaxP, 12., 2., 11.};
162   fHistos->CreateTHnSparse("tofnSigma", "TOF signal; species; p [GeV/c]; TOF signal [a.u.]; Selection Step; Centrality", 5, nBinsSigma, minSigma, maxSigma);
163
164   // 3rd histogram: TPC sigmas to the electron line: (species, p nsigma, step - only filled if apriori PID information available)
165   fHistos->CreateTHnSparse("tofMonitorTPC", "TPC signal; species; p [GeV/c]; TPC signal [a.u.]; Selection Step; Centrality", 5, nBinsSigma, minSigma, maxSigma);
166 }
167
168 //_________________________________________________________
169 void AliHFEtofPIDqa::ProcessTrack(const AliHFEpidObject *track, AliHFEdetPIDqa::EStep_t step){
170   //
171   // Fill TPC histograms
172   //
173   //AliHFEpidObject::AnalysisType_t anatype = track->IsESDanalysis() ? AliHFEpidObject::kESDanalysis : AliHFEpidObject::kAODanalysis;
174   Float_t centrality = track->GetCentrality();
175   Int_t species = track->GetAbInitioPID();
176   if(species >= AliPID::kSPECIES) species = -1;
177
178   AliDebug(1, Form("Monitoring particle of type %d for step %d", species, step));
179   AliHFEpidTOF *tofpid= dynamic_cast<AliHFEpidTOF *>(fQAmanager->GetDetectorPID(AliHFEpid::kTOFpid));
180   
181   const AliPIDResponse *pidResponse = tofpid ? tofpid->GetPIDResponse() : NULL;
182   Double_t contentSignal[5];
183   contentSignal[0] = species;
184   contentSignal[1] = track->GetRecTrack()->P();
185   contentSignal[2] = pidResponse ? pidResponse->NumberOfSigmasTOF(track->GetRecTrack(), AliPID::kElectron): 0.;
186   contentSignal[3] = step;
187   contentSignal[4] = centrality;
188   fHistos->Fill("tofnSigma", contentSignal);
189   if(species > -1){
190     contentSignal[2] = pidResponse ? pidResponse->NumberOfSigmasTPC(track->GetRecTrack(), AliPID::kElectron) : 0.;
191     fHistos->Fill("tofMonitorTPC", contentSignal);
192   }
193 }
194
195 //_________________________________________________________
196 TH2 *AliHFEtofPIDqa::MakeSpectrumNSigma(AliHFEdetPIDqa::EStep_t istep, Int_t species){
197   //
198   // Plot the Spectrum
199   //
200   THnSparseF *hSignal = dynamic_cast<THnSparseF *>(fHistos->Get("tofnSigma"));
201   if(!hSignal) return NULL;
202   hSignal->GetAxis(3)->SetRange(istep + 1, istep + 1);
203   if(species >= 0 && species < AliPID::kSPECIES)
204     hSignal->GetAxis(0)->SetRange(2 + species, 2 + species);
205   TH2 *hTmp = hSignal->Projection(2,1);
206   TString hname = Form("hTOFsigma%s", istep == AliHFEdetPIDqa::kBeforePID ? "before" : "after"), 
207           htitle = Form("Time-of-flight spectrum[#sigma] %s selection", istep == AliHFEdetPIDqa::kBeforePID ? "before" : "after");
208   if(species > -1){
209     hname += AliPID::ParticleName(species);
210     htitle += Form(" for %ss", AliPID::ParticleName(species));
211   }
212   hTmp->SetName(hname.Data());
213   hTmp->SetTitle(htitle.Data());
214   hTmp->SetStats(kFALSE);
215   hTmp->GetXaxis()->SetTitle("p [GeV/c]");
216   hTmp->GetYaxis()->SetTitle("TOF time|_{el} - expected time|_{el} [#sigma]");
217   hSignal->GetAxis(3)->SetRange(0, hSignal->GetAxis(3)->GetNbins());
218   hSignal->GetAxis(0)->SetRange(0, hSignal->GetAxis(0)->GetNbins());
219   return hTmp;
220 }
221
222 //_________________________________________________________
223 TH1 *AliHFEtofPIDqa::GetHistogram(const char *name){
224   // 
225   // Get the histogram
226   //
227   if(!fHistos) return NULL;
228   TObject *histo = fHistos->Get(name);
229   if(!histo->InheritsFrom("TH1")) return NULL;
230   return dynamic_cast<TH1 *>(histo);
231 }
232