Part of new PID code from Boris Batyunya
[u/mrichter/AliRoot.git] / ITS / AliITSPid.cxx
CommitLineData
23efe5f1 1#include "AliITSPid.h"
2#include "TMath.h"
3#include <iostream.h>
4ClassImp(AliITSPid)
5
6//-----------------------------------------------------------
7Float_t AliITSPid::qcorr(Float_t xc)
8{
9 assert(0);
10 Float_t fcorr;
11 fcorr=( 0.766 +0.9692*xc -1.267*xc*xc )*( 1.-TMath::Exp(-xc*64.75) );
12 if(fcorr<=0.1)fcorr=0.1;
13return qtot/fcorr;
14}
15
16//-----------------------------------------------------------
17#include "vector.h"
18#include <algorithm>
19Float_t AliITSPid::qtrm(Int_t track)
20{
21 TVector q(*( this->GetVec(track) ));
22 Int_t nl=(Int_t)q(0);
23 if(nl<1)return 0.;
24 vector<float> vf(nl);
25 switch(nl){
26 case 1:q(6)=q(1); break;
27 case 2:q(6)=(q(1)+q(2))/2.; break;
28 default:
29 for(Int_t i=0;i<nl;i++){vf[i]=q(i+1);}
30 sort(vf.begin(),vf.end());
31 q(6)= (vf[0]+vf[1])/2.;
32 break;
33 }
34 for(Int_t i=0;i<nl;i++){q(i+1)=vf[i];} this->SetVec(track,q);
35 return (q(6));
36}
37//-----------------------------------------------------------
38inline
39Int_t AliITSPid::wpik(Int_t nc,Float_t q)
40{
41 return pion();
42
43 Float_t qmpi,qmk,sigpi,sigk,dpi,dk,ppi,pk;
44 qmpi =cut[nc][1];
45 sigpi=cut[nc][2];
46 qmk =cut[nc][3];
47 sigk =cut[nc][4];
48 Float_t dqpi=(q-qmpi)/sigpi;
49 Float_t dqk =(q-qmk )/sigk;
50 if( dqk<-1. )return pion();
51 dpi =fabs(dqpi);
52 dk =fabs(dqk);
53 ppi =1.- TMath::Erf(dpi); // +0.5;
54 pk =1.- TMath::Erf(dk); // +0.5;
55 Float_t rpik=ppi/(pk+0.0000001);
56 cout<<"q,dqpi,dqk, wpik: ppi,pk,rpik="
57 <<q<<" "<<dqpi<<" "<<dqk<<" "<<ppi<<" "<<pk<<" "<<rpik<<endl;
58 if( rpik>=1000. ){return pion();}
59 if( rpik>0.001 ){fWk=1./(rpik+1.); fWpi=1.-fWk;return 0;}
60 return pion();
61}
62//-----------------------------------------------------------
63inline
64Int_t AliITSPid::wpikp(Int_t nc,Float_t q)
65{
66 return pion();
67
68 Float_t qmpi,qmk,qmp,sigpi,sigk,sigp,ppi,pka,ppr,rppi,rpka;
69
70 qmpi =cut[nc][1];
71 sigpi=cut[nc][2];
72 qmk =cut[nc][3];
73 sigk =cut[nc][4];
74 qmp =cut[nc][5];
75 sigp =cut[nc][6];
76
77 ppi =TMath::Erf( TMath::Abs((q-qmpi)/sigpi) )+0.5;
78 pka =TMath::Erf( TMath::Abs((q-qmk )/sigk) )+0.5;
79 ppr =TMath::Erf( TMath::Abs((q-qmp )/sigp) )+0.5;
80
81 rppi=ppr/ppi;
82 rpka=ppr/pka;
83 Float_t rp;
84 if( rppi>rpka ) { rp=rpka; }
85 else{ rp=rppi; }
86 if( rp>=1000. ){ return proton(); }
87 if( rp>0.001 ){ fWp=rp/(rp+1.);return proton(); }
88
89 return 0;
90}
91//-----------------------------------------------------------
92Int_t AliITSPid::GetPcode(TClonesArray* rps,Float_t pm)
93{
94 return 0;
95}
96//-----------------------------------------------------------
97Int_t AliITSPid::GetPcode(Float_t q,Float_t pm)
98{
99 fWpi=fWk=fWp=-1.; fPcode=0;
100//1)
101 if ( pm<=cut[1][0] )
102 { return pion(); }
103//2)
104 if ( pm<=cut[2][0] )
105 { if( q<cut[2][2] ){ return pion(); } else { return kaon();} }
106//3)
107 if ( pm<=cut[3][0] )
108 if( q<cut[3][2])
109 { return pion(); }
110 else
111 { if ( q<=cut[3][5] ) {return kaon();} else {return proton();}}
112//4)
113 if ( pm<=cut[4][0] )
114 if( q<cut[4][2] )
115 { return pion(); }
116 else
117 { if( q<=cut[4][4] ) {return kaon();} else {return proton(); }}
118//5)
119 if ( pm<=cut[5][0] )
120 if ( q>cut[5][5] ) {return proton();} else {return wpik(5,q);};
121//6)
122 if ( pm<=cut[6][0] )
123 if ( q>cut[6][5] ) {return proton();} else {return wpik(6,q);};
124//7)
125 if ( pm<=cut[7][0] )
126 if ( q<=cut[7][5] ) {return fPcode;} else {return proton();};
127//8)
128 if ( pm<=cut[8][0] )
129 if ( q<=cut[8][5] ) {return fPcode;} else {return proton();};
130//9)
131 if ( pm<=cut[9][0] )
132 if ( q<=cut[9][5] ) {return fPcode;} else {return proton();};
133//10)
134 if( pm<=cut[10][0] ){ return wpikp(10,q); }
135//11)
136 if( pm<=cut[11][0] ){ return wpikp(11,q); }
137//12)
138 if( pm<=cut[12][0] ){ return wpikp(12,q); }
139
140 return fPcode;
141}
142//-----------------------------------------------------------
143void AliITSPid::SetCut(Int_t n,Float_t pm,Float_t pilo,Float_t pihi,
144 Float_t klo,Float_t khi,Float_t plo,Float_t phi)
145{
146 cut[n][0]=pm;
147 cut[n][1]=pilo;
148 cut[n][2]=pihi;
149 cut[n][3]=klo;
150 cut[n][4]=khi;
151 cut[n][5]=plo;
152 cut[n][6]=phi;
153 return ;
154}
155//-----------------------------------------------------------
156void AliITSPid::SetVec(Int_t ntrack,TVector info)
157{
158TClonesArray& arr=*trs;
159 new( arr[ntrack] ) TVector(info);
160}
161//-----------------------------------------------------------
162TVector* AliITSPid::GetVec(Int_t ntrack)
163{
164TClonesArray& arr=*trs;
165 return (TVector*)arr[ntrack];
166}
167//-----------------------------------------------------------
168void AliITSPid::SetEdep(Int_t track,Float_t Edep)
169{
170 TVector xx(0,11);
171 if( ((TVector*)trs->At(track))->IsValid() )
172 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
173 Int_t j=(Int_t)xx(0); if(j>4)return;
174 xx(++j)=Edep;xx(0)=j;
175 TClonesArray &arr=*trs;
176 new(arr[track])TVector(xx);
177}
178//-----------------------------------------------------------
179void AliITSPid::SetPmom(Int_t track,Float_t Pmom)
180{
181 TVector xx(0,11);
182 if( ((TVector*)trs->At(track))->IsValid() )
183 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
184 xx(10)=Pmom;
185 TClonesArray &arr=*trs;
186 new(arr[track])TVector(xx);
187}
188//-----------------------------------------------------------
189void AliITSPid::SetPcod(Int_t track,Int_t partcode)
190{
191 TVector xx(0,11);
192 if( ((TVector*)trs->At(track))->IsValid() )
193 {TVector yy( *((TVector*)trs->At(track)) );xx=yy; }
194 if(xx(11)==0)
195 {xx(11)=partcode; mxtrs++;
196 TClonesArray &arr=*trs;
197 new(arr[track])TVector(xx);
198 }
199}
200//-----------------------------------------------------------
201void AliITSPid::Print(Int_t track)
202{cout<<mxtrs<<" tracks in AliITSPid obj."<<endl;
203 if( ((TVector*)trs->At(track))->IsValid() )
204 {TVector xx( *((TVector*)trs->At(track)) );
205 xx.Print();
206 }
207 else
208 {cout<<"No data for track "<<track<<endl;return;}
209}
210//-----------------------------------------------------------
211void AliITSPid::Tab(void)
212{
213if(trs->GetEntries()==0){cout<<"No entries in TAB"<<endl;return;}
214cout<<"------------------------------------------------------------------------"<<endl;
215cout<<"Nq"<<" q1 "<<" q2 "<<" q3 "<<" q4 "<<" q5 "<<
216 " Qtrm " <<" Wpi "<<" Wk "<<" Wp "<<"Pmom "<<endl;
217cout<<"------------------------------------------------------------------------"<<endl;
218for(Int_t i=0;i<trs->GetEntries();i++)
219{
220 TVector xx( *((TVector*)trs->At(i)) );
221 if( xx.IsValid() && xx(0)>0 )
222 {
223 TVector xx( *((TVector*)trs->At(i)) );
224 if(xx(0)>=2)
225 {
226// 1)Calculate Qtrm
227 xx(6)=(this->qtrm(i));
228
229 }else{
230 xx(6)=xx(1);
231 }
232// 2)Calculate Wpi,Wk,Wp
233 this->GetPcode(xx(6),xx(10)/1000.);
234 xx(7)=GetWpi();
235 xx(8)=GetWk();
236 xx(9)=GetWp();
237// 3)Print table
238 if(xx(0)>0){
239 cout<<xx(0)<<" ";
240 for(Int_t j=1;j<11;j++){
241 cout.width(7);cout.precision(5);cout<<xx(j);
242 }
243 cout<<endl;
244 }
245// 4)Update data in TVector
246 TClonesArray &arr=*trs;
247 new(arr[i])TVector(xx);
248 }
249 else
250 {/*cout<<"No data for track "<<i<<endl;*/}
251}// End loop for tracks
252}
253void AliITSPid::Reset(void)
254{
255 for(Int_t i=0;i<trs->GetEntries();i++){
256 TVector xx(0,11);
257 TClonesArray &arr=*trs;
258 new(arr[i])TVector(xx);
259 }
260}
261//-----------------------------------------------------------
262AliITSPid::AliITSPid(Int_t ntrack)
263{
264 trs = new TClonesArray("TVector",ntrack);
265 TClonesArray &arr=*trs;
266 for(Int_t i=0;i<ntrack;i++)new(arr[i])TVector(0,11);
267 mxtrs=0;
268const int inf=10;
269// Ncut Pmom pilo pihi klo khi plo phi
270// cut[j] [0] [1] [2] [3] [4] [5] [6]
271//----------------------------------------------------------------
272 SetCut( 1, 0.12 , 0. , 0. , inf , inf , inf , inf );
273 SetCut( 2, 0.20 , 0. , 6.0 , 6.0 , inf , inf , inf );
274 SetCut( 3, 0.30 , 0. , 3.5 , 3.5 , 9.0 , 9.0 , inf );
275 SetCut( 4, 0.41 , 0. , 1.9 , 1.9 , 4.0 , 4.0 , inf );
276//----------------------------------------------------------------
277 SetCut( 5, 0.47 , 1. , 0.12, 1.98 , 0.17 , 3.5 , inf );
278 SetCut( 6, 0.53 , 1. , 0.12, 1.75 , 0.16 , 3.0 , inf );
279//----------------------------------------------------------------
280 SetCut( 7, 0.59 , 0. , 0. , 1.18 , 0.125 , 2.7 , inf );
281 SetCut( 8, 0.65 , 0. , 0. , 1.18 , 0.125 , 2.5 , inf );
282 SetCut( 9, 0.73 , 0. , 0. , 0. , 0.125 , 2.0 , inf );
283//----------------------------------------------------------------
284 SetCut( 10, 0.83 , 0. , 0. , 1.25 , 0.13 , 2.14 , 0.20 );
285 SetCut( 11, 0.93 , 0. , 0. , 1.18 , 0.125 , 1.88 , 0.18 );
286 SetCut( 12, 1.03 , 0. , 0. , 1.13 , 0.12 , 1.68 , 0.155);
287}
288//-----------------------------------------------------------
289