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