1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliTPCPid.h"
20 //#include <TVector.h>
22 #include <TClonesArray.h>
23 //#include "AliITSIOTrack.h"
24 #include "AliKalmanTrack.h"
25 #include "Riostream.h"
27 // Correction 13.01.2003 Z.S.,Dubna
29 //------------------------------------------------------------
30 // pid class by B. Batyunya
31 // stupid corrections by M.K.
33 //________________________________________________________
34 AliTPCPid::AliTPCPid( const AliTPCPid& r):TObject(r)
36 // dummy copy constructor
38 Float_t AliTPCPid::Qcorr(Float_t xc)
45 fcorr=( 0.766 +0.9692*xc -1.267*xc*xc )*( 1.-TMath::Exp(-xc*64.75) );
46 if(fcorr<=0.1)fcorr=0.1;
49 //-----------------------------------------------------------
50 Float_t AliTPCPid::Qtrm(Int_t track) const
53 // dummy comment (Boris!!!)
55 TVector q(*( this->GetVec(track) ));
60 Int_t nl=0; for(Int_t i=0;i<ml;i++){if(q(i)>fSigmin){vf[nl]=q(i+1);nl++;}}
63 case 1:q(6)=q(1); break;
64 case 2:q(6)=(q(1)+q(2))/2.; break;
66 for(int fi=0;fi<2;fi++){
68 do{ swap=0; float qmin=vf[fi];
69 for(int j=fi+1;j<nl;j++)
70 if(qmin>vf[j]){qmin=vf[j];vf[j]=vf[fi];vf[fi]=qmin;swap=1;};
73 q(6)= (vf[0]+vf[1])/2.;
76 for(Int_t i=0;i<nl;i++){q(i+1)=vf[i];} this->SetVec(track,q);
78 }// --- End AliTPCPid::Qtrm ---
80 Float_t AliTPCPid::Qtrm(Float_t qarr[6],Int_t narr)
85 if(narr>0&&narr<7){ml=narr;}else{return 0;};
86 nl=0; for(Int_t i=0;i<ml;i++){if(qarr[i]>fSigmin){q[nl]=qarr[i];nl++;}}
89 case 1:qm=q[0]; break;
90 case 2:qm=(q[0]+q[1])/2.; break;
93 for(int fi=0;fi<2;fi++){
94 do{ swap=0; qmin=q[fi];
95 for(int j=fi+1;j<nl;j++)
96 if(qmin>q[j]){qmin=q[j];q[j]=q[fi];q[fi]=qmin;swap=1;};
103 }// --- End AliTPCPid::Qtrm ---
105 Int_t AliTPCPid::Wpik(Int_t nc,Float_t q)
110 Float_t qmpi,qmk,sigpi,sigk,dpi,dk,ppi,pk;
116 appi = faprob[0][nc-5];
117 apk = faprob[1][nc-5];
119 cout<<"qmpi,sigpi,qmk,sigk="<<qmpi<<" "<<sigpi<<" "<<qmk<<" "<<sigk<<endl;
120 cout<<"appi,apk="<<appi<<","<<apk<<endl;
122 Float_t dqpi=(q-qmpi)/sigpi;
123 Float_t dqk =(q-qmk )/sigk;
124 dpi =TMath::Abs(dqpi);
126 Double_t dn=appi*TMath::Gaus(q,qmpi,sigpi)+apk*TMath::Gaus(q,qmk,sigk);
128 ppi=appi*TMath::Gaus(q,qmpi,sigpi)/dn;
129 pk = apk*TMath::Gaus(q,qmk, sigk )/dn;
130 }else{fWpi=1;return Pion();}
131 Float_t rpik=ppi/(pk+0.0000001);
133 cout<<"q,dqpi,dqk, Wpik: ppi,pk,rpik="
134 <<q<<" "<<dqpi<<" "<<dqk<<" "<<ppi<<" "<<pk<<" "<<rpik<<endl;
136 fWp=0.; fWpi=ppi; fWk=pk;
137 if( pk>ppi){return Kaon();}else{return Pion();}
139 //-----------------------------------------------------------
140 Int_t AliTPCPid::Wpikp(Int_t nc,Float_t q)
145 Float_t qmpi,qmk,qmp,sigpi,sigk,sigp,ppi,pk,pp;
146 Float_t appi,apk,app;
155 //appi = apk = app = 1.;
156 appi = faprob[0][nc-5];
157 apk = faprob[1][nc-5];
158 app = faprob[2][nc-5];
160 Double_t dn= appi*TMath::Gaus(q,qmpi,sigpi)
161 +apk*TMath::Gaus(q,qmk,sigk)+app*TMath::Gaus(q,qmp,sigp);
163 ppi=appi*TMath::Gaus(q,qmpi,sigpi)/dn;
164 pk = apk*TMath::Gaus(q,qmk, sigk )/dn;
165 pp = app*TMath::Gaus(q,qmp, sigp )/dn;
167 else{fWpi=1;return Pion();}
168 fWp=pp; fWpi=ppi; fWk=pk;
170 cout<<" Wpikp: mid,sig pi,k,p="<<qmpi<<" "<<sigpi<<"; "<<qmk<<" "<<sigk<<"; "
171 <<qmp<<" "<<sigp<<"; "<<endl;
172 cout<<" faprob: "<<appi<<" "<<apk<<" "<<app<<endl;
173 cout<<" ppi,pk,pp="<<ppi<<" "<<pk<<" "<<pp<<endl;
175 if( ppi>pk&&ppi>pp ) { return Pion(); }
176 if(pk>pp){return Kaon();}else{return Proton();}
178 //-----------------------------------------------------------
179 Int_t AliTPCPid::GetPcode(TClonesArray* /*rps*/,Float_t /*pm*/) const
186 //-----------------------------------------------------------
187 Int_t AliTPCPid::GetPcode(AliTPCtrack *track)
192 Double_t xk,par[5]; track->GetExternalParameters(xk,par);
193 Float_t phi=TMath::ASin(par[2]) + track->GetAlpha();
194 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
195 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
196 Float_t lam=TMath::ATan(par[3]);
197 Float_t pt1=TMath::Abs(par[4]);
198 Float_t mom=1./(pt1*TMath::Cos(lam));
199 Float_t dedx=track->GetdEdx();
200 Int_t pcode=GetPcode(dedx/40.,mom);
201 cout<<"TPCtrack dedx,mom,pcode="<<dedx<<","<<mom<<","<<pcode<<endl;
202 return pcode?pcode:211;
204 //-----------------------------------------------------------
205 Int_t AliTPCPid::GetPcode(AliKalmanTrack *track)
210 if(track==0)return 0;
211 // track->Propagate(track->GetAlpha(),3.,0.1/65.19*1.848,0.1*1.848);
212 track->PropagateTo(3.,0.0028,65.19);
213 track->PropagateToVertex();
214 Double_t xk,par[5]; track->GetExternalParameters(xk,par);
215 Float_t lam=TMath::ATan(par[3]);
216 Float_t pt1=TMath::Abs(par[4]);
218 if( (pt1*TMath::Cos(lam))!=0. ){ mom=1./(pt1*TMath::Cos(lam)); }else{mom=0.;};
219 Float_t dedx=track->GetdEdx();
220 cout<<"lam,pt1,mom,dedx="<<lam<<","<<pt1<<","<<mom<<","<<dedx<<endl;
221 Int_t pcode=GetPcode(dedx,mom);
222 cout<<"ITS V2 dedx,mom,pcode="<<dedx<<","<<mom<<","<<pcode<<endl;
223 return pcode?pcode:211;
225 //-----------------------------------------------------------
226 Int_t AliTPCPid::GetPcode(Float_t q,Float_t pm)
231 fWpi=fWk=fWp=0.; fPcode=0;
232 //1)---------------------- 0-120 MeV/c --------------
233 if ( pm<=fcut[1][0] )
234 { fWpi=1.; return Pion(); }
235 //2)----------------------120-200 Mev/c ( 29.7.2002 ) -------------
236 if ( pm<=fcut[2][0] )
237 { if( q<fCutKa->Eval(pm) ){fWpi=1.; return Pion(); }
238 else {fWk =1.; return Kaon();} }
239 //3)----------------------200-400 Mev/c -------------
240 if ( pm<=fcut[3][0] )
241 if( q<fCutKa->Eval(pm) )
242 { fWpi=1.;return Pion(); }
244 { if ( q<=fCutPr->Eval(pm) )
245 {fWk=1.;return Kaon();}
246 else {fWp=1.;return Proton();}
248 //4)----------------------400-450 Mev/c -------------
249 if ( pm<=fcut[4][0] )
250 if( q<fCutKaTune*fCutKa->Eval(pm) )
251 { fWpi=1.;return Pion(); }
253 { if( q<fCutPr->Eval(pm) )
254 {fWk=1.;return Kaon();} else {fWp=1.;return Proton(); }
256 //5)----------------------450-500 Mev/c -------------
257 if ( pm<=fcut[5][0] )
258 if ( q>fCutPr->Eval(pm) )
259 {fWp=1.;return Proton();} else {return Wpik(5,q);};
260 //6)----------------------500-550 Mev/c -------------
261 if ( pm<=fcut[6][0] )
262 if ( q>fCutPr->Eval(pm) )
263 {fWp=1.;return Proton();} else {return Wpik(6,q);};
264 //7)----------------------550-600 Mev/c -------------
265 if ( pm<=fcut[7][0] )
266 if ( q>fCutPr->Eval(pm) )
267 {fWp=1.;return Proton();} else {return Wpik(7,q);};
268 //8)----------------------600-650 Mev/c -------------
269 if ( pm<=fcut[8][0] )
270 if ( q>fCutPrTune*fCutPr->Eval(pm) ){fWp=1.;return Proton();}
271 else {return Wpik(8,q);};
272 //9)----------------------650-730 Mev/c -------------
273 if ( pm<=fcut[9][0] )
274 if ( q>fCutPrTune*fCutPr->Eval(pm) ){fWp=1.;return Proton();}
275 else {return Wpik(9,q);};
276 //10)----------------------730-830 Mev/c -------------
277 if( pm<=fcut[10][0] )
278 if ( q>fCutPrTune*fCutPr->Eval(pm) ){fWp=1.;return Proton();}
279 else {return Wpik(10,q);};
280 //11)----------------------830-930 Mev/c -------------
281 if( pm<=fcut[11][0] ){ return Wpikp(11,q); }
282 //12)----------------------930-1030 Mev/c -------------
283 if( pm<=fcut[12][0] )
284 { return Wpikp(12,q); };
288 //-----------------------------------------------------------
289 void AliTPCPid::SetCut(Int_t n,Float_t pm,Float_t pilo,Float_t pihi,
290 Float_t klo,Float_t khi,Float_t plo,Float_t phi)
304 //------------------------------------------------------------
305 void AliTPCPid::SetVec(Int_t ntrack,TVector info) const
310 TClonesArray& arr=*trs;
311 new( arr[ntrack] ) TVector(info);
313 //-----------------------------------------------------------
314 TVector* AliTPCPid::GetVec(Int_t ntrack) const
319 TClonesArray& arr=*trs;
320 return (TVector*)arr[ntrack];
322 //-----------------------------------------------------------
323 void AliTPCPid::SetEdep(Int_t track,Float_t Edep)
329 if( ((TVector*)trs->At(track))->IsValid() )
330 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
331 Int_t j=(Int_t)xx(0); if(j>4)return;
332 xx(++j)=Edep;xx(0)=j;
333 TClonesArray &arr=*trs;
334 new(arr[track])TVector(xx);
336 //-----------------------------------------------------------
337 void AliTPCPid::SetPmom(Int_t track,Float_t Pmom)
340 // set part. momentum
343 if( ((TVector*)trs->At(track))->IsValid() )
344 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
346 TClonesArray &arr=*trs;
347 new(arr[track])TVector(xx);
349 //-----------------------------------------------------------
350 void AliTPCPid::SetPcod(Int_t track,Int_t partcode)
356 if( ((TVector*)trs->At(track))->IsValid() )
357 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
359 {xx(11)=partcode; fmxtrs++;
360 TClonesArray &arr=*trs;
361 new(arr[track])TVector(xx);
364 //-----------------------------------------------------------
365 void AliTPCPid::Print(Int_t track)
370 cout<<fmxtrs<<" tracks in AliITSPid obj."<<endl;
371 if( ((TVector*)trs->At(track))->IsValid() )
372 {TVector xx( *((TVector*)trs->At(track)) );
376 {cout<<"No data for track "<<track<<endl;return;}
378 //-----------------------------------------------------------
379 void AliTPCPid::Tab(void)
384 if(trs->GetEntries()==0){cout<<"No entries in TAB"<<endl;return;}
385 cout<<"------------------------------------------------------------------------"<<endl;
386 cout<<"Nq"<<" q1 "<<" q2 "<<" q3 "<<" q4 "<<" q5 "<<
387 " Qtrm " <<" Wpi "<<" Wk "<<" Wp "<<"Pmom "<<endl;
388 cout<<"------------------------------------------------------------------------"<<endl;
389 for(Int_t i=0;i<trs->GetEntries();i++)
391 TVector xx( *((TVector*)trs->At(i)) );
392 if( xx.IsValid() && xx(0)>0 )
394 TVector xx( *((TVector*)trs->At(i)) );
398 xx(6)=(this->Qtrm(i));
403 // 2)Calculate Wpi,Wk,Wp
404 this->GetPcode(xx(6),xx(10)/1000.);
411 for(Int_t j=1;j<11;j++){
412 cout.width(7);cout.precision(5);cout<<xx(j);
416 // 4)Update data in TVector
417 TClonesArray &arr=*trs;
418 new(arr[i])TVector(xx);
421 {/*cout<<"No data for track "<<i<<endl;*/}
422 }// End loop for tracks
424 void AliTPCPid::Reset(void)
429 for(Int_t i=0;i<trs->GetEntries();i++){
431 TClonesArray &arr=*trs;
432 new(arr[i])TVector(xx);
435 //-----------------------------------------------------------
436 AliTPCPid::AliTPCPid(Int_t ntrack)
438 trs = new TClonesArray("TVector",ntrack);
439 TClonesArray &arr=*trs;
440 for(Int_t i=0;i<ntrack;i++)new(arr[i])TVector(0,11);
443 //fCutKa = new TF1("fkaons","[0]/x/x+[1]",0.1,1.2);
444 //fCutPr = new TF1("fprotons","[0]/x/x +[1]",0.2,1.2);
447 frmska = new TF1("x_frmska","1.46-7.82*x+16.78*x^2-15.53*x^3+5.24*x^4 ",
449 fCutKa = new TF1("fkaons",
450 "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",
452 fCutPr = new TF1("fprotons",
453 "0.83*(15.32-56.094*x+89.962*x^2-66.1856*x^3+18.4052*x^4)",
455 fCutKaTune=1.1; // 0.92;
456 fCutPrTune=1.0; //0.80;
459 // Ncut Pmom pilo pihi klo khi plo phi
460 // fcut[j] [0] [1] [2] [3] [4] [5] [6]
461 //----------------------------------------------------------------
462 SetCut( 1, 0.120, 0. , 0. , kinf , kinf , kinf , kinf );
463 SetCut( 2, 0.200, 0. , 6.0 , 6.0 , kinf , kinf , kinf ); //120-200
464 SetCut( 3, 0.400, 0. , 3.5 , 3.5 , 9.0 , 9.0 , kinf ); //200-400
465 SetCut( 4, 0.450, 0. , 1.9 , 1.9 , 4.0 , 4.0 , kinf ); //400-450
466 //----------------------------------------------------------------
467 SetCut( 5, 0.500, 0.976, 0.108, 1.484 , 0.159 , 3.5 , kinf ); //450-500
468 SetCut( 6, 0.550, 0.979, 0.108, 1.376 , 0.145 , 3.0 , kinf ); //500-550
469 //----------------------------------------------------------------
470 SetCut( 7, 0.600, 0.984, 0.111, 1.295 , 0.146 , 2.7 , kinf ); //550-600
471 SetCut( 8, 0.650, 0.989, 0.113, 1.239 , 0.141 , 2.5 , kinf ); //600-650
472 SetCut( 9, 0.730, 0.995, 0.109, 1.172 , 0.132 , 2.0 , kinf ); //650-730
473 //----------------------------------------------------------------
474 SetCut( 10, 0.830, 1.008, 0.116, 1.117 , 0.134 , 1.703, 0.209 ); //730-830
475 SetCut( 11, 0.930, 1.019, 0.115, 1.072 , 0.121 , 1.535, 0.215 ); //830-930
476 SetCut( 12, 1.230, 1.035, 0.117, 1.053 , 0.140 ,1.426, 0.270); //930-1030
477 //------------------------ pi,K ---------------------
478 faprob[0][0]=33219.; faprob[1][0]=1971.; // faprob[0][i] - pions
479 faprob[0][1]=28828.; faprob[1][1]=1973.; // faprob[1][i] - kaons
480 //---------------------------------------------------
481 faprob[0][2]=24532.; faprob[1][2]=1932.; faprob[2][2]=1948.;
482 faprob[0][3]=20797.; faprob[1][3]=1823.; faprob[2][3]=1970.;
483 faprob[0][4]=27017.; faprob[1][4]=2681.; faprob[2][4]=2905.;
484 //------------------------ pi,K,p -------------------
485 faprob[0][5]= 24563.; faprob[1][5]=2816.; faprob[2][5]=3219.;
486 faprob[0][6]= 16877.; faprob[1][6]=2231.; faprob[2][6]=2746.;
487 faprob[0][7]= 11557.; faprob[1][7]=1681; faprob[2][7]=2190.;
491 //-----------------------------------------------------------