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