]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/hfe/AliHFEtofPIDqa.cxx
Fixes to run w/o OCDB infotrmation (in that case the class only provides statistics...
[u/mrichter/AliRoot.git] / PWG3 / 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 "AliVParticle.h"
39
40 #include "AliHFEcollection.h"
41 #include "AliHFEpid.h"
42 #include "AliHFEpidBase.h"
43 #include "AliHFEpidQAmanager.h"
44 #include "AliHFEpidTPC.h"
45 #include "AliHFEpidTOF.h"
46 #include "AliHFEtools.h"
47 #include "AliHFEtofPIDqa.h"
48
49 ClassImp(AliHFEpidTOF)
50
51 //_________________________________________________________
52 AliHFEtofPIDqa::AliHFEtofPIDqa():
53     AliHFEdetPIDqa()
54   , fHistos(NULL)
55 {
56   //
57   // Dummy constructor
58   //
59 }
60
61 //_________________________________________________________
62 AliHFEtofPIDqa::AliHFEtofPIDqa(const char* name):
63     AliHFEdetPIDqa(name, "QA for TOF")
64   , fHistos(NULL)
65 {
66   //
67   // Default constructor
68   //
69 }
70
71 //_________________________________________________________
72 AliHFEtofPIDqa::AliHFEtofPIDqa(const AliHFEtofPIDqa &o):
73     AliHFEdetPIDqa(o)
74   , fHistos()
75 {
76   //
77   // Copy constructor
78   //
79   o.Copy(*this);
80 }
81
82 //_________________________________________________________
83 AliHFEtofPIDqa &AliHFEtofPIDqa::operator=(const AliHFEtofPIDqa &o){
84   //
85   // Do assignment
86   //
87   AliHFEdetPIDqa::operator=(o);
88   if(&o != this) o.Copy(*this);
89   return *this;
90 }
91
92 //_________________________________________________________
93 AliHFEtofPIDqa::~AliHFEtofPIDqa(){
94   //
95   // Destructor
96   //
97   if(fHistos) delete fHistos;
98 }
99
100 //_________________________________________________________
101 void AliHFEtofPIDqa::Copy(TObject &o) const {
102   //
103   // Make copy
104   //
105   AliHFEtofPIDqa &target = dynamic_cast<AliHFEtofPIDqa &>(o);
106   if(target.fHistos){
107     delete target.fHistos;
108     target.fHistos = NULL;
109   }
110   if(fHistos) target.fHistos = new AliHFEcollection(*fHistos);
111 }
112
113 //_________________________________________________________
114 Long64_t AliHFEtofPIDqa::Merge(TCollection *coll){
115   //
116   // Merge with other objects
117   //
118   if(!coll) return 0;
119   if(coll->IsEmpty()) return 1;
120
121   TIter it(coll);
122   AliHFEtofPIDqa *refQA = NULL;
123   TObject *o = NULL;
124   Long64_t count = 0;
125   TList listHistos;
126   while((o = it())){
127     refQA = dynamic_cast<AliHFEtofPIDqa *>(o);
128     if(!refQA) continue;
129
130     listHistos.Add(refQA->fHistos);
131     count++; 
132   }
133   fHistos->Merge(&listHistos);
134   return count + 1;
135 }
136
137 //_________________________________________________________
138 void AliHFEtofPIDqa::Initialize(){
139   //
140   // Define Histograms
141   //
142
143   fHistos = new AliHFEcollection("tofqahistos", "Collection of TOF QA histograms");
144
145   // Make common binning
146   const Int_t kPIDbins = AliPID::kSPECIES + 1;
147   const Int_t kSteps = 2;
148   const Double_t kMinPID = -1;
149   const Double_t kMinP = 0.;
150   const Double_t kMaxPID = (Double_t)AliPID::kSPECIES;
151   const Double_t kMaxP = 20.;
152   // Quantities where one can switch between low and high resolution
153   Int_t kPbins = fQAmanager->HasHighResolutionHistos() ?  1000 : 100;
154   Int_t kSigmaBins = fQAmanager->HasHighResolutionHistos() ? 1400 : 240;
155
156   // 1st histogram: TOF sigmas: (species, p nsigma, step)
157   Int_t nBinsSigma[4] = {kPIDbins, kPbins, kSigmaBins, kSteps};
158   Double_t minSigma[4] = {kMinPID, kMinP, -12., 0};
159   Double_t maxSigma[4] = {kMaxPID, kMaxP, 12., 2.};
160   fHistos->CreateTHnSparse("tofnSigma", "TOF signal; species; p [GeV/c]; TOF signal [a.u.]; Selection Step", 4, nBinsSigma, minSigma, maxSigma);
161
162   // 2nd histogram: TOF time - pion hypothesis (TOF Time Resolution Monitor)
163   fHistos->CreateTH2F("tofTimeRes", "Difference between measured and expected time for Pions; p [GeV/c]; #Deltat [ps]", 100, 0.1, 10, 100, -200, 200); 
164   
165   // 3rd histogram: TPC sigmas to the electron line: (species, p nsigma, step - only filled if apriori PID information available)
166   fHistos->CreateTHnSparse("tofMonitorTPC", "TPC signal; species; p [GeV/c]; TPC signal [a.u.]; Selection Step", 4, nBinsSigma, minSigma, maxSigma);
167 }
168
169 //_________________________________________________________
170 void AliHFEtofPIDqa::ProcessTrack(const AliHFEpidObject *track, AliHFEdetPIDqa::EStep_t step){
171   //
172   // Fill TPC histograms
173   //
174   AliHFEpidObject::AnalysisType_t anatype = track->IsESDanalysis() ? AliHFEpidObject::kESDanalysis : AliHFEpidObject::kAODanalysis;
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   AliHFEpidTPC *tpcpid= dynamic_cast<AliHFEpidTPC *>(fQAmanager->GetDetectorPID(AliHFEpid::kTPCpid));
181   
182   Double_t contentSignal[4];
183   contentSignal[0] = species;
184   contentSignal[1] = track->GetRecTrack()->P();
185   contentSignal[2] = tofpid ? tofpid->NumberOfSigmas(track->GetRecTrack(), AliPID::kElectron, anatype): 0.;
186   contentSignal[3] = step;
187   fHistos->Fill("tofnSigma", contentSignal);
188   if(tofpid){
189     Double_t timeTof = tofpid->GetTOFsignal(track->GetRecTrack(), anatype);
190     Double_t time0 = tofpid->GetTime0(anatype);
191     Double_t tof = timeTof - time0;
192     Double_t times[AliPID::kSPECIES]; tofpid->GetIntegratedTimes(track->GetRecTrack(), times, anatype);
193     fHistos->Fill("tofTimeRes",contentSignal[1], tof - times[AliPID::kPion]);
194   }
195   if(species > -1){
196     contentSignal[2] = tpcpid ? tpcpid->NumberOfSigmas(track->GetRecTrack(), AliPID::kElectron, anatype) : 0.;
197     fHistos->Fill("tofMonitorTPC", contentSignal);
198   }
199 }
200
201 //_________________________________________________________
202 TH2 *AliHFEtofPIDqa::MakeSpectrumNSigma(AliHFEdetPIDqa::EStep_t istep, Int_t species){
203   //
204   // Plot the Spectrum
205   //
206   THnSparseF *hSignal = dynamic_cast<THnSparseF *>(fHistos->Get("tofnSigma"));
207   if(!hSignal) return NULL;
208   hSignal->GetAxis(3)->SetRange(istep + 1, istep + 1);
209   if(species > 0 && species < AliPID::kSPECIES)
210     hSignal->GetAxis(0)->SetRange(2 + species, 2 + species);
211   TH2 *hTmp = hSignal->Projection(2,1);
212   TString hname = Form("hTPCsigma%s", istep == AliHFEdetPIDqa::kBeforePID ? "before" : "after"), 
213           htitle = Form("TPC dE/dx Spectrum[#sigma] %s selection", istep == AliHFEdetPIDqa::kBeforePID ? "before" : "after");
214   if(species > -1){
215     hname += AliPID::ParticleName(species);
216     htitle += Form(" for %ss", AliPID::ParticleName(species));
217   }
218   hTmp->SetName(hname.Data());
219   hTmp->SetTitle(htitle.Data());
220   hTmp->SetStats(kFALSE);
221   hTmp->GetXaxis()->SetTitle("p [GeV/c]");
222   hTmp->GetYaxis()->SetTitle("TOF time|_{el} - expected time|_{el} [#sigma]");
223   hSignal->GetAxis(3)->SetRange(0, hSignal->GetAxis(3)->GetNbins());
224   hSignal->GetAxis(0)->SetRange(0, hSignal->GetAxis(0)->GetNbins());
225   return hTmp;
226 }
227
228 //_________________________________________________________
229 TH1 *AliHFEtofPIDqa::GetHistogram(const char *name){
230   // 
231   // Get the histogram
232   //
233   if(!fHistos) return NULL;
234   TObject *histo = fHistos->Get(name);
235   if(!histo->InheritsFrom("TH1")) return NULL;
236   return dynamic_cast<TH1 *>(histo);
237 }
238