]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/dielectron/AliDielectronPID.cxx
Code updates with bugfixes; new PID class; filtered AOD config macro
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliDielectronPID.cxx
CommitLineData
8df8e382 1/*************************************************************************
2* Copyright(c) 1998-2009, 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///////////////////////////////////////////////////////////////////////////
17// Dielectron PID //
18// //
19// //
20/*
21Detailed description
22
23
24*/
25// //
26///////////////////////////////////////////////////////////////////////////
27
28#include <TMath.h>
29#include <TF1.h>
30
31#include <AliVParticle.h>
32#include <AliLog.h>
33#include <AliESDtrack.h>
34
35#include "AliDielectronVarManager.h"
36
37#include "AliDielectronPID.h"
38
39ClassImp(AliDielectronPID)
40
41AliDielectronPID::AliDielectronPID() :
42 AliAnalysisCuts(),
43 fNcuts(0),
44 fRequirePIDbit(kTRUE),
45 fESDpid(0x0)
46{
47 //
48 // Default Constructor
49 //
50 for (Int_t icut=0; icut<kNmaxPID; ++icut){
51 fDetType[icut]=kTPC;
52 fPartType[icut]=AliPID::kPion;
53 fNsigmaLow[icut]=0;
54 fNsigmaUp[icut]=0;
55 fPmin[icut]=0;
56 fPmax[icut]=0;
57 fExclude[icut]=kFALSE;
58 fFunUpperCut[icut]=0x0;
59 fFunLowerCut[icut]=0x0;
60 }
61}
62
63//______________________________________________
64AliDielectronPID::AliDielectronPID(const char* name, const char* title) :
65 AliAnalysisCuts(name, title),
66 fNcuts(0),
67 fRequirePIDbit(kTRUE),
68 fESDpid(0x0)
69{
70 //
71 // Named Constructor
72 //
73 for (Int_t icut=0; icut<kNmaxPID; ++icut){
74 fDetType[icut]=kTPC;
75 fPartType[icut]=AliPID::kPion;
76 fNsigmaLow[icut]=0;
77 fNsigmaUp[icut]=0;
78 fPmin[icut]=0;
79 fPmax[icut]=0;
80 fExclude[icut]=kFALSE;
81 fFunUpperCut[icut]=0x0;
82 fFunLowerCut[icut]=0x0;
83 }
84}
85
86//______________________________________________
87AliDielectronPID::~AliDielectronPID()
88{
89 //
90 // Default Destructor
91 //
92}
93
94//______________________________________________
95void AliDielectronPID::AddCut(DetType det, AliPID::EParticleType type, Double_t nSigmaLow, Double_t nSigmaUp/*=-99999.*/,
96 Double_t pMin/*=0*/, Double_t pMax/*=0*/, Bool_t exclude/*=kFALSE*/)
97{
98 //
99 // Add a pid nsigma cut
100 // use response of detector 'det' in the momentum range ('pMin') to ['pMax']
101 // use a sigma band betwee 'nSigmaLow' and 'nSigmaUp'
102 // if nSigmaUp==-99999. then nSigmaLow will be uesd as a symmetric band +- nSigmaLow
103 // specify whether to 'exclude' the given band
104 //
105
106 if (fNcuts==kNmaxPID){
107 AliError(Form("only %d pid cut ranges allowed",kNmaxPID));
108 }
109 if (TMath::Abs(nSigmaUp+99999.)<1e-20){
110 nSigmaUp=TMath::Abs(nSigmaLow);
111 nSigmaLow=-1.*nSigmaUp;
112 }
113 fDetType[fNcuts]=det;
114 fPartType[fNcuts]=type;
115 fNsigmaLow[fNcuts]=nSigmaLow;
116 fNsigmaUp[fNcuts]=nSigmaUp;
117 fPmin[fNcuts]=pMin;
118 fPmax[fNcuts]=pMax;
119 fExclude[fNcuts]=exclude;
120 ++fNcuts;
121
122}
123
124//______________________________________________
125void AliDielectronPID::AddCut(DetType det, AliPID::EParticleType type, Double_t nSigmaLow, TF1 * const funUp,
126 Double_t pMin/*=0*/, Double_t pMax/*=0*/, Bool_t exclude/*=kFALSE*/)
127{
128 //
129 // cut using a TF1 as upper cut
130 //
131 if (funUp==0x0){
132 AliError("A valid function is required for the upper cut. Not adding the cut!");
133 return;
134 }
135 fFunUpperCut[fNcuts]=funUp;
136 AddCut(det,type,nSigmaLow,0.,pMin,pMax,exclude);
137}
138
139//______________________________________________
140void AliDielectronPID::AddCut(DetType det, AliPID::EParticleType type, TF1 * const funLow, Double_t nSigmaUp,
141 Double_t pMin/*=0*/, Double_t pMax/*=0*/, Bool_t exclude/*=kFALSE*/)
142{
143 //
144 // cut using a TF1 as lower cut
145 //
146 if (funLow==0x0){
147 AliError("A valid function is required for the lower cut. Not adding the cut!");
148 return;
149 }
150 fFunLowerCut[fNcuts]=funLow;
151 AddCut(det,type,0.,nSigmaUp,pMin,pMax,exclude);
152}
153
154//______________________________________________
155void AliDielectronPID::AddCut(DetType det, AliPID::EParticleType type, TF1 * const funLow, TF1 * const funUp,
156 Double_t pMin/*=0*/, Double_t pMax/*=0*/, Bool_t exclude/*=kFALSE*/)
157{
158 //
159 // cut using a TF1 as lower and upper cut
160 //
161 if ( (funUp==0x0) || (funLow==0x0) ){
162 AliError("A valid function is required for upper and lower cut. Not adding the cut!");
163 return;
164 }
165 fFunUpperCut[fNcuts]=funUp;
166 fFunLowerCut[fNcuts]=funLow;
167 AddCut(det,type,0.,0.,pMin,pMax,exclude);
168}
169
170//______________________________________________
171Bool_t AliDielectronPID::IsSelected(TObject* track)
172{
173 //
174 // perform PID cuts
175 //
176
177 //loop over all cuts
178 AliVParticle *part=static_cast<AliVParticle*>(track);
179 //TODO: Which momentum to use?
180 // Different momenta for different detectors?
181 Double_t mom=part->P();
182
183 Bool_t selected=kFALSE;
184 fESDpid=AliDielectronVarManager::GetESDpid();
185
186 for (UChar_t icut=0; icut<fNcuts; ++icut){
187 Double_t pMin=fPmin[icut];
188 Double_t pMax=fPmax[icut];
189
190 // test momentum range. In case pMin==pMax use all momenta
191 if ( (TMath::Abs(pMin-pMax)>1e-20) && (mom<=pMin || mom>pMax) ) continue;
192
193 // test if we are supposed to use a function for the cut
194 if (fFunUpperCut[icut]) fNsigmaUp[icut] =fFunUpperCut[icut]->Eval(mom);
195 if (fFunLowerCut[icut]) fNsigmaLow[icut]=fFunLowerCut[icut]->Eval(mom);
196
197 switch (fDetType[icut]){
198 case kITS:
199 selected = IsSelectedITS(part,icut);
200 break;
201 case kTPC:
202 selected = IsSelectedTPC(part,icut);
203 break;
204 case kTRD:
205 selected = IsSelectedTRD(part,icut);
206 break;
207 case kTOF:
208 selected = IsSelectedTOF(part,icut);
209 break;
210 }
211 if (!selected) return kFALSE;
212 }
213
214 return selected;
215}
216
217//______________________________________________
218Bool_t AliDielectronPID::IsSelectedITS(AliVParticle * const part, Int_t icut) const
219{
220 //
221 // ITS part of the PID check
222 // Don't accept the track if there was no pid bit set
223 //
224 Float_t numberOfSigmas=-1000.;
225
226 if (part->IsA()==AliESDtrack::Class()){
227 // ESD case in case the PID bit is not set, don't use this track!
228 AliESDtrack *track=static_cast<AliESDtrack*>(part);
229 if (fRequirePIDbit&&!(track->GetStatus()&AliESDtrack::kITSpid)) return kFALSE;
230
231 numberOfSigmas=fESDpid->NumberOfSigmasITS(track, fPartType[icut]);
232 }else{
233 // AOD case
234 // FIXME: Is there a place to check whether the PID is was set in ESD???
235 AliAODTrack *track=static_cast<AliAODTrack*>(part);
236 numberOfSigmas=NumberOfSigmasITS(track, fPartType[icut]);
237 }
238 Bool_t selected=((numberOfSigmas>=fNsigmaLow[icut])&&(numberOfSigmas<=fNsigmaUp[icut]))^fExclude[icut];
239 return selected;
240}
241
242//______________________________________________
243Bool_t AliDielectronPID::IsSelectedTPC(AliVParticle * const part, Int_t icut) const
244{
245 //
246 // TPC part of the PID check
247 // Don't accept the track if there was no pid bit set
248 //
249 Float_t numberOfSigmas=-1000.;
250
251 if (part->IsA()==AliESDtrack::Class()){
252 // ESD case in case the PID bit is not set, don't use this track!
253 AliESDtrack *track=static_cast<AliESDtrack*>(part);
254 if (fRequirePIDbit&&!(track->GetStatus()&AliESDtrack::kTPCpid)) return kFALSE;
255
256 numberOfSigmas=fESDpid->NumberOfSigmasTPC(track, fPartType[icut]);
257 }else{
258 // AOD case
259 // FIXME: Is there a place to check whether the PID is was set in ESD???
260 AliAODTrack *track=static_cast<AliAODTrack*>(part);
261 numberOfSigmas=NumberOfSigmasTPC(track, fPartType[icut]);
262 }
263
264 Bool_t selected=((numberOfSigmas>=fNsigmaLow[icut])&&(numberOfSigmas<=fNsigmaUp[icut]))^fExclude[icut];
265 return selected;
266}
267
268//______________________________________________
269Bool_t AliDielectronPID::IsSelectedTRD(AliVParticle * const /*part*/, Int_t /*icut*/) const
270{
271 //
272 // TRD part of the pid check
273 //
274 return kFALSE;
275}
276
277//______________________________________________
278Bool_t AliDielectronPID::IsSelectedTOF(AliVParticle * const part, Int_t icut) const
279{
280 //
281 // TOF part of the PID check
282 // Don't accept the track if there was no pid bit set
283 //
284 Float_t numberOfSigmas=-1000.;
285
286 if (part->IsA()==AliESDtrack::Class()){
287 // ESD case in case the PID bit is not set, don't use this track!
288 AliESDtrack *track=static_cast<AliESDtrack*>(part);
289 if (fRequirePIDbit&&!(track->GetStatus()&AliESDtrack::kTOFpid)) return kFALSE;
290
291 numberOfSigmas=fESDpid->NumberOfSigmasTOF(track, fPartType[icut], fESDpid->GetTOFResponse().GetTimeZero());
292 }else{
293 // AOD case
294 // FIXME: Is there a place to check whether the PID is was set in ESD???
295 AliAODTrack *track=static_cast<AliAODTrack*>(part);
296 numberOfSigmas=NumberOfSigmasTOF(track, fPartType[icut]);
297 }
298
299 Bool_t selected=((numberOfSigmas>=fNsigmaLow[icut])&&(numberOfSigmas<=fNsigmaUp[icut]))^fExclude[icut];
300 return selected;
301}
302
303//______________________________________________
304void AliDielectronPID::SetDefaults(Int_t def){
305 //
306 // initialise default pid strategies
307 //
308
309 if (def==0){
310 // 2sigma bands TPC:
311 // - include e
312 // - exclude mu,K,pi,p
313 // -complete p range
314 AddCut(kTPC,AliPID::kElectron,2);
315 AddCut(kTPC,AliPID::kMuon,-2.,2.,0.,0.,kTRUE);
316 AddCut(kTPC,AliPID::kPion,-2.,2.,0.,0.,kTRUE);
317 AddCut(kTPC,AliPID::kKaon,-2.,2.,0.,0.,kTRUE);
318 AddCut(kTPC,AliPID::kProton,-2.,2.,0.,0.,kTRUE);
319 } else if (def==1) {
320 // 2sigma bands TPC:
321 // - include e 0<p<inf
322 // - exclude mu,K,pi,p 0<p<2
323
324 AddCut(kTPC,AliPID::kElectron,2.);
325 AddCut(kTPC,AliPID::kMuon,-2.,2.,0.,2.,kTRUE);
326 AddCut(kTPC,AliPID::kPion,-2.,2.,0.,2.,kTRUE);
327 AddCut(kTPC,AliPID::kKaon,-2.,2.,0.,2.,kTRUE);
328 AddCut(kTPC,AliPID::kProton,-2.,2.,0.,2.,kTRUE);
329
330 } else if (def==2) {
331 // include 2sigma e TPC
332 // 3sigma bands TOF
333 // - exclude K,P
334 AddCut(kTPC,AliPID::kElectron,2.);
335 AddCut(kTOF,AliPID::kKaon,-3.,3.,0.,0.,kTRUE);
336 AddCut(kTOF,AliPID::kProton,-3.,3.,0.,0.,kTRUE);
337
338 } else if (def==3) {
339 // include 2sigma e TPC
340 // 3sigma bands TOF
341 // - exclude K 0<p<1
342 // - exclude P 0<p<2
343 AddCut(kTPC,AliPID::kElectron,2);
344 AddCut(kTOF,AliPID::kKaon,-3.,3.,0.,1.,kTRUE);
345 AddCut(kTOF,AliPID::kProton,-6.,6.,0.,1.,kTRUE);
346 AddCut(kTOF,AliPID::kProton,-3.,3.,1.,2.,kTRUE);
347
348 } else if (def==4) {
349 // include 2sigma e TPC
350 // 3sigma bands TOF
351 // - exclude K 0<p<1
352 // - exclude P 0<p<2
353 AddCut(kTPC,AliPID::kElectron,2.);
354 AddCut(kTOF,AliPID::kKaon,-3.,3.,0.,1.,kTRUE);
355 AddCut(kTOF,AliPID::kProton,-6.,6.,0.,1.,kTRUE);
356 AddCut(kTOF,AliPID::kProton,-3.,3.,1.,2.,kTRUE);
357 fRequirePIDbit=kFALSE;
358 } else if (def==5) {
359 AddCut(kTPC,AliPID::kElectron,-0.5,3);
360 AddCut(kTOF,AliPID::kElectron,-3,3,0,1.5);
361 } else if (def==6) {
362 // lower cut TPC: parametrisation by HFE
363 // upper cut TPC: 3 sigma
364 // TOF ele band 3sigma 0<p<1.5GeV
365 TF1 *lowerCut=new TF1("lowerCut", "[0] * TMath::Exp([1]*x)", 0, 100);
366 lowerCut->SetParameters(-2.7,-0.4357);
367 AddCut(kTPC,AliPID::kElectron,lowerCut,3.);
368 AddCut(kTOF,AliPID::kElectron,-3,3,0,1.5);
369 } else if (def==7) {
370 // lower cut TPC: parametrisation by HFE
371 // upper cut TPC: 3 sigma
372 // TOF ele band 3sigma 0<p<1.5GeV
373 AddCut(kTPC,AliPID::kElectron,10.);
374 AddCut(kTOF,AliPID::kElectron,-3,3,0,1.5);
375 }
376}
377