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