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