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