Avoid warning
[u/mrichter/AliRoot.git] / TPC / AliTPCPid.cxx
CommitLineData
733304f0 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
88cb7938 16/* $Id$ */
733304f0 17
b8def77a 18#include "AliTPCPid.h"
19#include "TMath.h"
ad350af6 20//#include <TVector.h>
21#include <TF1.h>
22#include <TClonesArray.h>
b8def77a 23//#include "AliITSIOTrack.h"
16a5b018 24#include "Riostream.h"
b8def77a 25ClassImp(AliTPCPid)
26// Correction 13.01.2003 Z.S.,Dubna
27// 22.01.2003
28//------------------------------------------------------------
ad350af6 29// pid class by B. Batyunya
30// stupid corrections by M.K.
31//
32//________________________________________________________
33 AliTPCPid::AliTPCPid( const AliTPCPid& r):TObject(r)
b8def77a 34{
ad350af6 35 // dummy copy constructor
36}
37Float_t AliTPCPid::Qcorr(Float_t xc)
38{
39 //
40 // charge correction
41 //
b8def77a 42 assert(0);
43 Float_t fcorr;
44 fcorr=( 0.766 +0.9692*xc -1.267*xc*xc )*( 1.-TMath::Exp(-xc*64.75) );
45 if(fcorr<=0.1)fcorr=0.1;
ad350af6 46return fqtot/fcorr;
b8def77a 47}
48//-----------------------------------------------------------
ad350af6 49Float_t AliTPCPid::Qtrm(Int_t track) const
b8def77a 50{
ad350af6 51 //
52 // dummy comment (Boris!!!)
53 //
b8def77a 54 TVector q(*( this->GetVec(track) ));
55 Int_t ml=(Int_t)q(0);
56 if(ml<1)return 0.;
57 if(ml>6)ml=6;
58 float vf[6];
59 Int_t nl=0; for(Int_t i=0;i<ml;i++){if(q(i)>fSigmin){vf[nl]=q(i+1);nl++;}}
60 if(nl==0)return 0.;
61 switch(nl){
62 case 1:q(6)=q(1); break;
63 case 2:q(6)=(q(1)+q(2))/2.; break;
64 default:
65 for(int fi=0;fi<2;fi++){
66 Int_t swap;
67 do{ swap=0; float qmin=vf[fi];
68 for(int j=fi+1;j<nl;j++)
69 if(qmin>vf[j]){qmin=vf[j];vf[j]=vf[fi];vf[fi]=qmin;swap=1;};
70 }while(swap==1);
71 }
72 q(6)= (vf[0]+vf[1])/2.;
73 break;
74 }
75 for(Int_t i=0;i<nl;i++){q(i+1)=vf[i];} this->SetVec(track,q);
76 return (q(6));
ad350af6 77}// --- End AliTPCPid::Qtrm ---
b8def77a 78
ad350af6 79Float_t AliTPCPid::Qtrm(Float_t qarr[6],Int_t narr)
b8def77a 80{
81 //..................
82 Float_t q[6],qm,qmin;
83 Int_t nl,ml;
84 if(narr>0&&narr<7){ml=narr;}else{return 0;};
85 nl=0; for(Int_t i=0;i<ml;i++){if(qarr[i]>fSigmin){q[nl]=qarr[i];nl++;}}
86 if(nl==0)return 0.;
87 switch(nl){
88 case 1:qm=q[0]; break;
89 case 2:qm=(q[0]+q[1])/2.; break;
90 default:
91 Int_t swap;
92 for(int fi=0;fi<2;fi++){
93 do{ swap=0; qmin=q[fi];
94 for(int j=fi+1;j<nl;j++)
95 if(qmin>q[j]){qmin=q[j];q[j]=q[fi];q[fi]=qmin;swap=1;};
96 }while(swap==1);
97 }
98 qm= (q[0]+q[1])/2.;
99 break;
100 }
101 return qm;
ad350af6 102}// --- End AliTPCPid::Qtrm ---
b8def77a 103
ad350af6 104Int_t AliTPCPid::Wpik(Int_t nc,Float_t q)
b8def77a 105{
ad350af6 106 //
107 // pi-k
108 //
b8def77a 109 Float_t qmpi,qmk,sigpi,sigk,dpi,dk,ppi,pk;
110 Float_t appi,apk;
ad350af6 111 qmpi =fcut[nc][1];
112 sigpi=fcut[nc][2];
113 qmk =fcut[nc][3];
114 sigk =fcut[nc][4];
115 appi = faprob[0][nc-5];
116 apk = faprob[1][nc-5];
b8def77a 117 if( !fSilent ){
118 cout<<"qmpi,sigpi,qmk,sigk="<<qmpi<<" "<<sigpi<<" "<<qmk<<" "<<sigk<<endl;
119 cout<<"appi,apk="<<appi<<","<<apk<<endl;
120 }
121 Float_t dqpi=(q-qmpi)/sigpi;
122 Float_t dqk =(q-qmk )/sigk;
9dec0e81 123 dpi =TMath::Abs(dqpi);
124 dk =TMath::Abs(dqk);
b8def77a 125 Double_t dn=appi*TMath::Gaus(q,qmpi,sigpi)+apk*TMath::Gaus(q,qmk,sigk);
126 if(dn>0.){
127 ppi=appi*TMath::Gaus(q,qmpi,sigpi)/dn;
128 pk = apk*TMath::Gaus(q,qmk, sigk )/dn;
ad350af6 129 }else{fWpi=1;return Pion();}
b8def77a 130 Float_t rpik=ppi/(pk+0.0000001);
131 if( !fSilent )
ad350af6 132 cout<<"q,dqpi,dqk, Wpik: ppi,pk,rpik="
b8def77a 133 <<q<<" "<<dqpi<<" "<<dqk<<" "<<ppi<<" "<<pk<<" "<<rpik<<endl;
134
135 fWp=0.; fWpi=ppi; fWk=pk;
ad350af6 136 if( pk>ppi){return Kaon();}else{return Pion();}
b8def77a 137}
138//-----------------------------------------------------------
ad350af6 139Int_t AliTPCPid::Wpikp(Int_t nc,Float_t q)
b8def77a 140{
ad350af6 141 //
142 // pi-k-p
143 //
b8def77a 144 Float_t qmpi,qmk,qmp,sigpi,sigk,sigp,ppi,pk,pp;
145 Float_t appi,apk,app;
146
ad350af6 147 qmpi =fcut[nc][1];
148 sigpi=fcut[nc][2];
149 qmk =fcut[nc][3];
150 sigk =fcut[nc][4];
151 qmp =fcut[nc][5];
152 sigp =fcut[nc][6];
b8def77a 153
154 //appi = apk = app = 1.;
ad350af6 155 appi = faprob[0][nc-5];
156 apk = faprob[1][nc-5];
157 app = faprob[2][nc-5];
b8def77a 158
159 Double_t dn= appi*TMath::Gaus(q,qmpi,sigpi)
160 +apk*TMath::Gaus(q,qmk,sigk)+app*TMath::Gaus(q,qmp,sigp);
161 if(dn>0.){
162 ppi=appi*TMath::Gaus(q,qmpi,sigpi)/dn;
163 pk = apk*TMath::Gaus(q,qmk, sigk )/dn;
164 pp = app*TMath::Gaus(q,qmp, sigp )/dn;
165 }
ad350af6 166 else{fWpi=1;return Pion();}
b8def77a 167 fWp=pp; fWpi=ppi; fWk=pk;
168 if( !fSilent ){
ad350af6 169cout<<" Wpikp: mid,sig pi,k,p="<<qmpi<<" "<<sigpi<<"; "<<qmk<<" "<<sigk<<"; "
b8def77a 170 <<qmp<<" "<<sigp<<"; "<<endl;
ad350af6 171cout<<" faprob: "<<appi<<" "<<apk<<" "<<app<<endl;
b8def77a 172cout<<" ppi,pk,pp="<<ppi<<" "<<pk<<" "<<pp<<endl;
173 }
ad350af6 174 if( ppi>pk&&ppi>pp ) { return Pion(); }
175 if(pk>pp){return Kaon();}else{return Proton();}
b8def77a 176}
177//-----------------------------------------------------------
ad350af6 178Int_t AliTPCPid::GetPcode(TClonesArray* /*rps*/,Float_t /*pm*/) const
b8def77a 179{
ad350af6 180 //
181 // dummy ???
182 //
b8def77a 183 return 0;
184}
185//-----------------------------------------------------------
186Int_t AliTPCPid::GetPcode(AliTPCtrack *track)
187{
ad350af6 188 //
189 // get particle code
190 //
b8def77a 191 Double_t xk,par[5]; track->GetExternalParameters(xk,par);
192 Float_t phi=TMath::ASin(par[2]) + track->GetAlpha();
193 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
194 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
195 Float_t lam=TMath::ATan(par[3]);
ad350af6 196 Float_t pt1=TMath::Abs(par[4]);
197 Float_t mom=1./(pt1*TMath::Cos(lam));
b8def77a 198 Float_t dedx=track->GetdEdx();
199 Int_t pcode=GetPcode(dedx/40.,mom);
200 cout<<"TPCtrack dedx,mom,pcode="<<dedx<<","<<mom<<","<<pcode<<endl;
201 return pcode?pcode:211;
202 }
203//-----------------------------------------------------------
204Int_t AliTPCPid::GetPcode(AliITStrackV2 *track)
205{
ad350af6 206 //
207 // get particle code
208 //
b8def77a 209 if(track==0)return 0;
210 // track->Propagate(track->GetAlpha(),3.,0.1/65.19*1.848,0.1*1.848);
211 track->PropagateTo(3.,0.0028,65.19);
212 track->PropagateToVertex();
213 Double_t xk,par[5]; track->GetExternalParameters(xk,par);
214 Float_t lam=TMath::ATan(par[3]);
ad350af6 215 Float_t pt1=TMath::Abs(par[4]);
b8def77a 216 Float_t mom=0.;
ad350af6 217 if( (pt1*TMath::Cos(lam))!=0. ){ mom=1./(pt1*TMath::Cos(lam)); }else{mom=0.;};
b8def77a 218 Float_t dedx=track->GetdEdx();
ad350af6 219 cout<<"lam,pt1,mom,dedx="<<lam<<","<<pt1<<","<<mom<<","<<dedx<<endl;
b8def77a 220 Int_t pcode=GetPcode(dedx,mom);
221 cout<<"ITS V2 dedx,mom,pcode="<<dedx<<","<<mom<<","<<pcode<<endl;
222return pcode?pcode:211;
223}
224//-----------------------------------------------------------
225Int_t AliTPCPid::GetPcode(Float_t q,Float_t pm)
226{
ad350af6 227 //
228 // get particle code
229 //
b8def77a 230 fWpi=fWk=fWp=0.; fPcode=0;
231//1)---------------------- 0-120 MeV/c --------------
ad350af6 232 if ( pm<=fcut[1][0] )
233 { fWpi=1.; return Pion(); }
b8def77a 234//2)----------------------120-200 Mev/c ( 29.7.2002 ) -------------
ad350af6 235 if ( pm<=fcut[2][0] )
236 { if( q<fCutKa->Eval(pm) ){fWpi=1.; return Pion(); }
237 else {fWk =1.; return Kaon();} }
b8def77a 238//3)----------------------200-400 Mev/c -------------
ad350af6 239 if ( pm<=fcut[3][0] )
b8def77a 240 if( q<fCutKa->Eval(pm) )
ad350af6 241 { fWpi=1.;return Pion(); }
b8def77a 242 else
243 { if ( q<=fCutPr->Eval(pm) )
ad350af6 244 {fWk=1.;return Kaon();}
245 else {fWp=1.;return Proton();}
b8def77a 246 }
247//4)----------------------400-450 Mev/c -------------
ad350af6 248 if ( pm<=fcut[4][0] )
b8def77a 249 if( q<fCutKaTune*fCutKa->Eval(pm) )
ad350af6 250 { fWpi=1.;return Pion(); }
b8def77a 251 else
252 { if( q<fCutPr->Eval(pm) )
ad350af6 253 {fWk=1.;return Kaon();} else {fWp=1.;return Proton(); }
b8def77a 254 }
255//5)----------------------450-500 Mev/c -------------
ad350af6 256 if ( pm<=fcut[5][0] )
b8def77a 257 if ( q>fCutPr->Eval(pm) )
ad350af6 258 {fWp=1.;return Proton();} else {return Wpik(5,q);};
b8def77a 259//6)----------------------500-550 Mev/c -------------
ad350af6 260 if ( pm<=fcut[6][0] )
b8def77a 261 if ( q>fCutPr->Eval(pm) )
ad350af6 262 {fWp=1.;return Proton();} else {return Wpik(6,q);};
b8def77a 263//7)----------------------550-600 Mev/c -------------
ad350af6 264 if ( pm<=fcut[7][0] )
b8def77a 265 if ( q>fCutPr->Eval(pm) )
ad350af6 266 {fWp=1.;return Proton();} else {return Wpik(7,q);};
b8def77a 267//8)----------------------600-650 Mev/c -------------
ad350af6 268 if ( pm<=fcut[8][0] )
269 if ( q>fCutPrTune*fCutPr->Eval(pm) ){fWp=1.;return Proton();}
270 else {return Wpik(8,q);};
b8def77a 271//9)----------------------650-730 Mev/c -------------
ad350af6 272 if ( pm<=fcut[9][0] )
273 if ( q>fCutPrTune*fCutPr->Eval(pm) ){fWp=1.;return Proton();}
274 else {return Wpik(9,q);};
b8def77a 275//10)----------------------730-830 Mev/c -------------
ad350af6 276 if( pm<=fcut[10][0] )
277 if ( q>fCutPrTune*fCutPr->Eval(pm) ){fWp=1.;return Proton();}
278 else {return Wpik(10,q);};
b8def77a 279//11)----------------------830-930 Mev/c -------------
ad350af6 280 if( pm<=fcut[11][0] ){ return Wpikp(11,q); }
b8def77a 281//12)----------------------930-1030 Mev/c -------------
ad350af6 282 if( pm<=fcut[12][0] )
283 { return Wpikp(12,q); };
b8def77a 284
285 return fPcode;
286}
287//-----------------------------------------------------------
288void AliTPCPid::SetCut(Int_t n,Float_t pm,Float_t pilo,Float_t pihi,
289 Float_t klo,Float_t khi,Float_t plo,Float_t phi)
290{
ad350af6 291 //
292 // set cuts
293 //
294 fcut[n][0]=pm;
295 fcut[n][1]=pilo;
296 fcut[n][2]=pihi;
297 fcut[n][3]=klo;
298 fcut[n][4]=khi;
299 fcut[n][5]=plo;
300 fcut[n][6]=phi;
b8def77a 301 return ;
302}
303//------------------------------------------------------------
ad350af6 304void AliTPCPid::SetVec(Int_t ntrack,TVector info) const
b8def77a 305{
ad350af6 306 //
307 // new track vector
308 //
b8def77a 309TClonesArray& arr=*trs;
310 new( arr[ntrack] ) TVector(info);
311}
312//-----------------------------------------------------------
ad350af6 313TVector* AliTPCPid::GetVec(Int_t ntrack) const
b8def77a 314{
ad350af6 315 //
316 // get track vector
317 //
b8def77a 318TClonesArray& arr=*trs;
319 return (TVector*)arr[ntrack];
320}
321//-----------------------------------------------------------
322void AliTPCPid::SetEdep(Int_t track,Float_t Edep)
323{
ad350af6 324 //
325 // energy deposit
326 //
b8def77a 327 TVector xx(0,11);
328 if( ((TVector*)trs->At(track))->IsValid() )
329 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
330 Int_t j=(Int_t)xx(0); if(j>4)return;
331 xx(++j)=Edep;xx(0)=j;
332 TClonesArray &arr=*trs;
333 new(arr[track])TVector(xx);
334}
335//-----------------------------------------------------------
336void AliTPCPid::SetPmom(Int_t track,Float_t Pmom)
337{
ad350af6 338 //
339 // set part. momentum
340 //
b8def77a 341 TVector xx(0,11);
342 if( ((TVector*)trs->At(track))->IsValid() )
343 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
344 xx(10)=Pmom;
345 TClonesArray &arr=*trs;
346 new(arr[track])TVector(xx);
347}
348//-----------------------------------------------------------
349void AliTPCPid::SetPcod(Int_t track,Int_t partcode)
350{
ad350af6 351 //
352 // set part. code
353 //
b8def77a 354 TVector xx(0,11);
355 if( ((TVector*)trs->At(track))->IsValid() )
356 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
357 if(xx(11)==0)
ad350af6 358 {xx(11)=partcode; fmxtrs++;
b8def77a 359 TClonesArray &arr=*trs;
360 new(arr[track])TVector(xx);
361 }
362}
363//-----------------------------------------------------------
364void AliTPCPid::Print(Int_t track)
ad350af6 365{
366 //
367 // control print
368 //
369cout<<fmxtrs<<" tracks in AliITSPid obj."<<endl;
b8def77a 370 if( ((TVector*)trs->At(track))->IsValid() )
371 {TVector xx( *((TVector*)trs->At(track)) );
372 xx.Print();
373 }
374 else
375 {cout<<"No data for track "<<track<<endl;return;}
376}
377//-----------------------------------------------------------
378void AliTPCPid::Tab(void)
379{
ad350af6 380 //
381 // fill table
382 //
b8def77a 383if(trs->GetEntries()==0){cout<<"No entries in TAB"<<endl;return;}
384cout<<"------------------------------------------------------------------------"<<endl;
385cout<<"Nq"<<" q1 "<<" q2 "<<" q3 "<<" q4 "<<" q5 "<<
386 " Qtrm " <<" Wpi "<<" Wk "<<" Wp "<<"Pmom "<<endl;
387cout<<"------------------------------------------------------------------------"<<endl;
388for(Int_t i=0;i<trs->GetEntries();i++)
389{
390 TVector xx( *((TVector*)trs->At(i)) );
391 if( xx.IsValid() && xx(0)>0 )
392 {
393 TVector xx( *((TVector*)trs->At(i)) );
394 if(xx(0)>=2)
395 {
396// 1)Calculate Qtrm
ad350af6 397 xx(6)=(this->Qtrm(i));
b8def77a 398
399 }else{
400 xx(6)=xx(1);
401 }
402// 2)Calculate Wpi,Wk,Wp
403 this->GetPcode(xx(6),xx(10)/1000.);
404 xx(7)=GetWpi();
405 xx(8)=GetWk();
406 xx(9)=GetWp();
407// 3)Print table
408 if(xx(0)>0){
409 cout<<xx(0)<<" ";
410 for(Int_t j=1;j<11;j++){
411 cout.width(7);cout.precision(5);cout<<xx(j);
412 }
413 cout<<endl;
414 }
415// 4)Update data in TVector
416 TClonesArray &arr=*trs;
417 new(arr[i])TVector(xx);
418 }
419 else
420 {/*cout<<"No data for track "<<i<<endl;*/}
421}// End loop for tracks
422}
423void AliTPCPid::Reset(void)
424{
ad350af6 425 //
426 // reset
427 //
b8def77a 428 for(Int_t i=0;i<trs->GetEntries();i++){
429 TVector xx(0,11);
430 TClonesArray &arr=*trs;
431 new(arr[i])TVector(xx);
432 }
433}
434//-----------------------------------------------------------
435AliTPCPid::AliTPCPid(Int_t ntrack)
436{
437 trs = new TClonesArray("TVector",ntrack);
438 TClonesArray &arr=*trs;
439 for(Int_t i=0;i<ntrack;i++)new(arr[i])TVector(0,11);
ad350af6 440 fmxtrs=0;
b8def77a 441
442 //fCutKa = new TF1("fkaons","[0]/x/x+[1]",0.1,1.2);
443 //fCutPr = new TF1("fprotons","[0]/x/x +[1]",0.2,1.2);
ad350af6 444 TF1 *frmska=0;
176aff27 445
ad350af6 446 frmska = new TF1("x_frmska","1.46-7.82*x+16.78*x^2-15.53*x^3+5.24*x^4 ",
b8def77a 447 0.1,1.2);
448 fCutKa = new TF1("fkaons",
449 "1.25+0.044/x/x+1.25+0.044*x-13.87*x^2+22.37*x^3-10.05*x^4-2.5*x_frmska",
450 0.1,1.2);
451 fCutPr = new TF1("fprotons",
452 "0.83*(15.32-56.094*x+89.962*x^2-66.1856*x^3+18.4052*x^4)",
453 0.2,1.2);
454 fCutKaTune=1.1; // 0.92;
455 fCutPrTune=1.0; //0.80;
456
ad350af6 457const int kinf=10;
b8def77a 458// Ncut Pmom pilo pihi klo khi plo phi
ad350af6 459// fcut[j] [0] [1] [2] [3] [4] [5] [6]
b8def77a 460//----------------------------------------------------------------
ad350af6 461 SetCut( 1, 0.120, 0. , 0. , kinf , kinf , kinf , kinf );
462 SetCut( 2, 0.200, 0. , 6.0 , 6.0 , kinf , kinf , kinf ); //120-200
463 SetCut( 3, 0.400, 0. , 3.5 , 3.5 , 9.0 , 9.0 , kinf ); //200-400
464 SetCut( 4, 0.450, 0. , 1.9 , 1.9 , 4.0 , 4.0 , kinf ); //400-450
b8def77a 465//----------------------------------------------------------------
ad350af6 466 SetCut( 5, 0.500, 0.976, 0.108, 1.484 , 0.159 , 3.5 , kinf ); //450-500
467 SetCut( 6, 0.550, 0.979, 0.108, 1.376 , 0.145 , 3.0 , kinf ); //500-550
b8def77a 468//----------------------------------------------------------------
ad350af6 469 SetCut( 7, 0.600, 0.984, 0.111, 1.295 , 0.146 , 2.7 , kinf ); //550-600
470 SetCut( 8, 0.650, 0.989, 0.113, 1.239 , 0.141 , 2.5 , kinf ); //600-650
471 SetCut( 9, 0.730, 0.995, 0.109, 1.172 , 0.132 , 2.0 , kinf ); //650-730
b8def77a 472//----------------------------------------------------------------
473 SetCut( 10, 0.830, 1.008, 0.116, 1.117 , 0.134 , 1.703, 0.209 ); //730-830
474 SetCut( 11, 0.930, 1.019, 0.115, 1.072 , 0.121 , 1.535, 0.215 ); //830-930
475 SetCut( 12, 1.230, 1.035, 0.117, 1.053 , 0.140 ,1.426, 0.270); //930-1030
476 //------------------------ pi,K ---------------------
ad350af6 477 faprob[0][0]=33219.; faprob[1][0]=1971.; // faprob[0][i] - pions
478 faprob[0][1]=28828.; faprob[1][1]=1973.; // faprob[1][i] - kaons
b8def77a 479 //---------------------------------------------------
ad350af6 480 faprob[0][2]=24532.; faprob[1][2]=1932.; faprob[2][2]=1948.;
481 faprob[0][3]=20797.; faprob[1][3]=1823.; faprob[2][3]=1970.;
482 faprob[0][4]=27017.; faprob[1][4]=2681.; faprob[2][4]=2905.;
b8def77a 483 //------------------------ pi,K,p -------------------
ad350af6 484 faprob[0][5]= 24563.; faprob[1][5]=2816.; faprob[2][5]=3219.;
485 faprob[0][6]= 16877.; faprob[1][6]=2231.; faprob[2][6]=2746.;
486 faprob[0][7]= 11557.; faprob[1][7]=1681; faprob[2][7]=2190.;
b8def77a 487
488 fSilent=kTRUE;
489}
490//-----------------------------------------------------------
491
492
493