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