Get the order of libs right
[u/mrichter/AliRoot.git] / ITS / AliITSPid.cxx
CommitLineData
23efe5f1 1#include "AliITSPid.h"
2#include "TMath.h"
79b921e1 3#include "AliITSIOTrack.h"
23efe5f1 4#include <iostream.h>
5ClassImp(AliITSPid)
6
7//-----------------------------------------------------------
8Float_t AliITSPid::qcorr(Float_t xc)
9{
10 assert(0);
11 Float_t fcorr;
12 fcorr=( 0.766 +0.9692*xc -1.267*xc*xc )*( 1.-TMath::Exp(-xc*64.75) );
13 if(fcorr<=0.1)fcorr=0.1;
14return qtot/fcorr;
15}
23efe5f1 16//-----------------------------------------------------------
ac314db7 17//PH #include "vector.h"
18#include <vector>
23efe5f1 19#include <algorithm>
20Float_t AliITSPid::qtrm(Int_t track)
21{
22 TVector q(*( this->GetVec(track) ));
23 Int_t nl=(Int_t)q(0);
24 if(nl<1)return 0.;
25 vector<float> vf(nl);
26 switch(nl){
27 case 1:q(6)=q(1); break;
28 case 2:q(6)=(q(1)+q(2))/2.; break;
29 default:
30 for(Int_t i=0;i<nl;i++){vf[i]=q(i+1);}
31 sort(vf.begin(),vf.end());
32 q(6)= (vf[0]+vf[1])/2.;
33 break;
34 }
35 for(Int_t i=0;i<nl;i++){q(i+1)=vf[i];} this->SetVec(track,q);
36 return (q(6));
37}
79b921e1 38//........................................................
39Float_t AliITSPid::qtrm(Float_t qarr[6],Int_t narr)
40{
41 Float_t q[6],qm;
42 Int_t nl,ml;
43 narr>6?ml=6:ml=narr;
44 nl=0; for(Int_t i=0;i<ml;i++){if(qarr[i]>0.){q[i]=qarr[i];nl++;}}
45 if(nl==0)return 0.;
46 vector<float> vf(nl);
47 switch(nl){
48 case 1:qm=q[0]; break;
49 case 2:qm=(q[0]+q[1])/2.; break;
50 default:
51 for(Int_t i=0;i<nl;i++){vf[i]=q[i];}
52 sort(vf.begin(),vf.end());
53 qm= (vf[0]+vf[1])/2.;
54 break;
55 }
56 return qm;
57}
23efe5f1 58//-----------------------------------------------------------
79b921e1 59//inline
23efe5f1 60Int_t AliITSPid::wpik(Int_t nc,Float_t q)
61{
62 return pion();
63
64 Float_t qmpi,qmk,sigpi,sigk,dpi,dk,ppi,pk;
65 qmpi =cut[nc][1];
66 sigpi=cut[nc][2];
67 qmk =cut[nc][3];
68 sigk =cut[nc][4];
69 Float_t dqpi=(q-qmpi)/sigpi;
70 Float_t dqk =(q-qmk )/sigk;
71 if( dqk<-1. )return pion();
2f804294 72 dpi =TMath::Abs(dqpi);
73 dk =TMath::Abs(dqk);
23efe5f1 74 ppi =1.- TMath::Erf(dpi); // +0.5;
75 pk =1.- TMath::Erf(dk); // +0.5;
76 Float_t rpik=ppi/(pk+0.0000001);
77 cout<<"q,dqpi,dqk, wpik: ppi,pk,rpik="
78 <<q<<" "<<dqpi<<" "<<dqk<<" "<<ppi<<" "<<pk<<" "<<rpik<<endl;
79 if( rpik>=1000. ){return pion();}
80 if( rpik>0.001 ){fWk=1./(rpik+1.); fWpi=1.-fWk;return 0;}
81 return pion();
82}
83//-----------------------------------------------------------
79b921e1 84//inline
23efe5f1 85Int_t AliITSPid::wpikp(Int_t nc,Float_t q)
86{
87 return pion();
88
89 Float_t qmpi,qmk,qmp,sigpi,sigk,sigp,ppi,pka,ppr,rppi,rpka;
90
91 qmpi =cut[nc][1];
92 sigpi=cut[nc][2];
93 qmk =cut[nc][3];
94 sigk =cut[nc][4];
95 qmp =cut[nc][5];
96 sigp =cut[nc][6];
97
98 ppi =TMath::Erf( TMath::Abs((q-qmpi)/sigpi) )+0.5;
99 pka =TMath::Erf( TMath::Abs((q-qmk )/sigk) )+0.5;
100 ppr =TMath::Erf( TMath::Abs((q-qmp )/sigp) )+0.5;
101
102 rppi=ppr/ppi;
103 rpka=ppr/pka;
104 Float_t rp;
105 if( rppi>rpka ) { rp=rpka; }
106 else{ rp=rppi; }
107 if( rp>=1000. ){ return proton(); }
108 if( rp>0.001 ){ fWp=rp/(rp+1.);return proton(); }
109
110 return 0;
111}
112//-----------------------------------------------------------
113Int_t AliITSPid::GetPcode(TClonesArray* rps,Float_t pm)
114{
115 return 0;
116}
117//-----------------------------------------------------------
79b921e1 118Int_t AliITSPid::GetPcode(AliTPCtrack *track)
119{
120 Double_t xk,par[5]; track->GetExternalParameters(xk,par);
121 Float_t phi=TMath::ASin(par[2]) + track->GetAlpha();
122 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
123 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
124 Float_t lam=TMath::ATan(par[3]);
125 Float_t pt_1=TMath::Abs(par[4]);
126 Float_t mom=1./(pt_1*TMath::Cos(lam));
127 Float_t dedx=track->GetdEdx();
128 Int_t pcode=GetPcode(dedx/40.,mom);
129 cout<<"TPCtrack dedx,mom,pcode="<<dedx<<","<<mom<<","<<pcode<<endl;
130 return pcode?pcode:211;
131 }
132//------------------------------------------------------------
133/*
134Int_t AliITSPid::GetPcode(AliITSIOTrack *track)
135{
136 Double_t px,py,pz;
137 px=track->GetPx();
138 py=track->GetPy();
139 pz=track->GetPz();
140 Float_t mom=TMath::Sqrt(px*px+py*py+pz*pz);
141//???????????????????
142 // Float_t dedx=1.0;
143 Float_t dedx=track->GetdEdx();
144//???????????????????
145 Int_t pcode=GetPcode(dedx,mom);
146 cout<<"ITSV1 dedx,mom,pcode="<<dedx<<","<<mom<<","<<pcode<<endl;
147return pcode?pcode:211;
148}
149*/
150//-----------------------------------------------------------
151Int_t AliITSPid::GetPcode(AliITStrackV2 *track)
152{
153 if(track==0)return 0;
154 //track->Propagate(track->GetAlpha(),3.,0.1/65.19*1.848,0.1*1.848);
155 track->PropagateTo(3.,0.0028,65.19);
156
157 track->PropagateToVertex();
158 Double_t xk,par[5]; track->GetExternalParameters(xk,par);
159 Float_t lam=TMath::ATan(par[3]);
160 Float_t pt_1=TMath::Abs(par[4]);
161 Float_t mom=0.;
162 if( (pt_1*TMath::Cos(lam))!=0. ){ mom=1./(pt_1*TMath::Cos(lam)); }else{mom=0.;};
163 Float_t dedx=track->GetdEdx();
164 //cout<<"lam,pt_1,mom,dedx="<<lam<<","<<pt_1<<","<<mom<<","<<dedx<<endl;
165 Int_t pcode=GetPcode(dedx,mom);
166 //cout<<"ITS V2 dedx,mom,pcode="<<dedx<<","<<mom<<","<<pcode<<endl;
167return pcode?pcode:211;
168}
169//-----------------------------------------------------------
23efe5f1 170Int_t AliITSPid::GetPcode(Float_t q,Float_t pm)
171{
172 fWpi=fWk=fWp=-1.; fPcode=0;
173//1)
174 if ( pm<=cut[1][0] )
175 { return pion(); }
176//2)
177 if ( pm<=cut[2][0] )
178 { if( q<cut[2][2] ){ return pion(); } else { return kaon();} }
179//3)
180 if ( pm<=cut[3][0] )
181 if( q<cut[3][2])
182 { return pion(); }
183 else
184 { if ( q<=cut[3][5] ) {return kaon();} else {return proton();}}
185//4)
186 if ( pm<=cut[4][0] )
187 if( q<cut[4][2] )
188 { return pion(); }
189 else
190 { if( q<=cut[4][4] ) {return kaon();} else {return proton(); }}
191//5)
192 if ( pm<=cut[5][0] )
193 if ( q>cut[5][5] ) {return proton();} else {return wpik(5,q);};
194//6)
195 if ( pm<=cut[6][0] )
196 if ( q>cut[6][5] ) {return proton();} else {return wpik(6,q);};
197//7)
198 if ( pm<=cut[7][0] )
199 if ( q<=cut[7][5] ) {return fPcode;} else {return proton();};
200//8)
201 if ( pm<=cut[8][0] )
202 if ( q<=cut[8][5] ) {return fPcode;} else {return proton();};
203//9)
204 if ( pm<=cut[9][0] )
205 if ( q<=cut[9][5] ) {return fPcode;} else {return proton();};
206//10)
207 if( pm<=cut[10][0] ){ return wpikp(10,q); }
208//11)
209 if( pm<=cut[11][0] ){ return wpikp(11,q); }
210//12)
211 if( pm<=cut[12][0] ){ return wpikp(12,q); }
212
213 return fPcode;
214}
215//-----------------------------------------------------------
216void AliITSPid::SetCut(Int_t n,Float_t pm,Float_t pilo,Float_t pihi,
217 Float_t klo,Float_t khi,Float_t plo,Float_t phi)
218{
219 cut[n][0]=pm;
220 cut[n][1]=pilo;
221 cut[n][2]=pihi;
222 cut[n][3]=klo;
223 cut[n][4]=khi;
224 cut[n][5]=plo;
225 cut[n][6]=phi;
226 return ;
227}
228//-----------------------------------------------------------
229void AliITSPid::SetVec(Int_t ntrack,TVector info)
230{
231TClonesArray& arr=*trs;
232 new( arr[ntrack] ) TVector(info);
233}
234//-----------------------------------------------------------
235TVector* AliITSPid::GetVec(Int_t ntrack)
236{
237TClonesArray& arr=*trs;
238 return (TVector*)arr[ntrack];
239}
240//-----------------------------------------------------------
241void AliITSPid::SetEdep(Int_t track,Float_t Edep)
242{
243 TVector xx(0,11);
244 if( ((TVector*)trs->At(track))->IsValid() )
245 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
246 Int_t j=(Int_t)xx(0); if(j>4)return;
247 xx(++j)=Edep;xx(0)=j;
248 TClonesArray &arr=*trs;
249 new(arr[track])TVector(xx);
250}
251//-----------------------------------------------------------
252void AliITSPid::SetPmom(Int_t track,Float_t Pmom)
253{
254 TVector xx(0,11);
255 if( ((TVector*)trs->At(track))->IsValid() )
256 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
257 xx(10)=Pmom;
258 TClonesArray &arr=*trs;
259 new(arr[track])TVector(xx);
260}
261//-----------------------------------------------------------
262void AliITSPid::SetPcod(Int_t track,Int_t partcode)
263{
264 TVector xx(0,11);
265 if( ((TVector*)trs->At(track))->IsValid() )
266 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
267 if(xx(11)==0)
268 {xx(11)=partcode; mxtrs++;
269 TClonesArray &arr=*trs;
270 new(arr[track])TVector(xx);
271 }
272}
273//-----------------------------------------------------------
274void AliITSPid::Print(Int_t track)
275{cout<<mxtrs<<" tracks in AliITSPid obj."<<endl;
276 if( ((TVector*)trs->At(track))->IsValid() )
277 {TVector xx( *((TVector*)trs->At(track)) );
278 xx.Print();
279 }
280 else
281 {cout<<"No data for track "<<track<<endl;return;}
282}
283//-----------------------------------------------------------
284void AliITSPid::Tab(void)
285{
286if(trs->GetEntries()==0){cout<<"No entries in TAB"<<endl;return;}
287cout<<"------------------------------------------------------------------------"<<endl;
288cout<<"Nq"<<" q1 "<<" q2 "<<" q3 "<<" q4 "<<" q5 "<<
289 " Qtrm " <<" Wpi "<<" Wk "<<" Wp "<<"Pmom "<<endl;
290cout<<"------------------------------------------------------------------------"<<endl;
291for(Int_t i=0;i<trs->GetEntries();i++)
292{
293 TVector xx( *((TVector*)trs->At(i)) );
294 if( xx.IsValid() && xx(0)>0 )
295 {
296 TVector xx( *((TVector*)trs->At(i)) );
297 if(xx(0)>=2)
298 {
299// 1)Calculate Qtrm
300 xx(6)=(this->qtrm(i));
301
302 }else{
303 xx(6)=xx(1);
304 }
305// 2)Calculate Wpi,Wk,Wp
306 this->GetPcode(xx(6),xx(10)/1000.);
307 xx(7)=GetWpi();
308 xx(8)=GetWk();
309 xx(9)=GetWp();
310// 3)Print table
311 if(xx(0)>0){
312 cout<<xx(0)<<" ";
313 for(Int_t j=1;j<11;j++){
314 cout.width(7);cout.precision(5);cout<<xx(j);
315 }
316 cout<<endl;
317 }
318// 4)Update data in TVector
319 TClonesArray &arr=*trs;
320 new(arr[i])TVector(xx);
321 }
322 else
323 {/*cout<<"No data for track "<<i<<endl;*/}
324}// End loop for tracks
325}
326void AliITSPid::Reset(void)
327{
328 for(Int_t i=0;i<trs->GetEntries();i++){
329 TVector xx(0,11);
330 TClonesArray &arr=*trs;
331 new(arr[i])TVector(xx);
332 }
333}
334//-----------------------------------------------------------
335AliITSPid::AliITSPid(Int_t ntrack)
336{
337 trs = new TClonesArray("TVector",ntrack);
338 TClonesArray &arr=*trs;
339 for(Int_t i=0;i<ntrack;i++)new(arr[i])TVector(0,11);
340 mxtrs=0;
341const int inf=10;
342// Ncut Pmom pilo pihi klo khi plo phi
343// cut[j] [0] [1] [2] [3] [4] [5] [6]
344//----------------------------------------------------------------
345 SetCut( 1, 0.12 , 0. , 0. , inf , inf , inf , inf );
346 SetCut( 2, 0.20 , 0. , 6.0 , 6.0 , inf , inf , inf );
347 SetCut( 3, 0.30 , 0. , 3.5 , 3.5 , 9.0 , 9.0 , inf );
348 SetCut( 4, 0.41 , 0. , 1.9 , 1.9 , 4.0 , 4.0 , inf );
349//----------------------------------------------------------------
350 SetCut( 5, 0.47 , 1. , 0.12, 1.98 , 0.17 , 3.5 , inf );
351 SetCut( 6, 0.53 , 1. , 0.12, 1.75 , 0.16 , 3.0 , inf );
352//----------------------------------------------------------------
353 SetCut( 7, 0.59 , 0. , 0. , 1.18 , 0.125 , 2.7 , inf );
354 SetCut( 8, 0.65 , 0. , 0. , 1.18 , 0.125 , 2.5 , inf );
355 SetCut( 9, 0.73 , 0. , 0. , 0. , 0.125 , 2.0 , inf );
356//----------------------------------------------------------------
357 SetCut( 10, 0.83 , 0. , 0. , 1.25 , 0.13 , 2.14 , 0.20 );
358 SetCut( 11, 0.93 , 0. , 0. , 1.18 , 0.125 , 1.88 , 0.18 );
359 SetCut( 12, 1.03 , 0. , 0. , 1.13 , 0.12 , 1.68 , 0.155);
360}
361//-----------------------------------------------------------
362