25f8af65e72cebde5e31c1da55031144a0ae95eb
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDPid.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 //                                                                      //
18 // AliHMPIDPid                                                          //
19 //                                                                      //
20 // HMPID class to perfom particle identification                        //
21 //                                                                      //
22 //////////////////////////////////////////////////////////////////////////
23
24 #include "AliHMPIDPid.h"       //class header
25 #include "AliHMPIDParam.h"     //class header
26 #include "AliHMPIDRecon.h"     //class header
27 #include <AliESDtrack.h>       //FindPid()
28 #include <TRandom.h>           //Resolution()
29
30 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31 AliHMPIDPid::AliHMPIDPid():TTask("HMPIDrec","HMPIDPid")
32 {
33 //..
34 //init of data members
35 //..
36 }
37 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38 void AliHMPIDPid::FindPid(AliESDtrack *pTrk,Int_t nsp,Double_t *prob)
39 {
40 // Calculates probability to be a electron-muon-pion-kaon-proton with the "amplitude" method
41 // from the given Cerenkov angle and momentum assuming no initial particle composition
42 // (i.e. apriory probability to be the particle of the given sort is the same for all sorts)
43
44   AliPID *pPid = new AliPID();
45   Double_t thetaCerExp = pTrk->GetHMPIDsignal();                                                                           //  measured thetaCherenkov
46   
47   if(thetaCerExp<=0){                                         //HMPID does not find anything reasonable for this track, assign 0.2 for all species
48     for(Int_t iPart=0;iPart<nsp;iPart++) prob[iPart]=1.0/(Float_t)nsp;
49     return;
50   } 
51
52   Double_t pmod = pTrk->GetP();                  // Momentum of the charged particle
53   Double_t hTot=0;                               // Initialize the total height of the amplitude method
54   Double_t *h = new Double_t [nsp];              // number of charged particles to be considered
55
56   Bool_t desert = kTRUE;                                                                                                     //  Flag to evaluate if ThetaC is far ("desert") from the given Gaussians
57   
58   for(Int_t iPart=0;iPart<nsp;iPart++){                                                                                      //  for each particle
59     
60     h[iPart] = 0;                                                                                                            //  reset the height
61     Double_t mass = pPid->ParticleMass(iPart);                                                                             //  with the given mass
62     Double_t cosThetaTh = TMath::Sqrt(mass*mass+pmod*pmod)/(AliHMPIDParam::Instance()->MeanIdxRad()*pmod);                   //  evaluate the theor. Theta Cherenkov
63     if(cosThetaTh>1) continue;                                                                                               //  no light emitted, zero height
64     Double_t thetaCerTh = TMath::ACos(cosThetaTh);                                                                           //  theoretical Theta Cherenkov
65     Double_t sigmaRing = Resolution(thetaCerTh,pTrk);
66     
67     if(sigmaRing==0) {
68       for(Int_t jPart=0;jPart<nsp;jPart++) prob[jPart]=1.0/(Float_t)nsp;
69       return;
70     } 
71     
72     if(TMath::Abs(thetaCerExp-thetaCerTh)<4*sigmaRing) desert = kFALSE;                                                                //   
73     h[iPart] =TMath::Gaus(thetaCerTh,thetaCerExp,sigmaRing,kTRUE);
74     hTot    +=h[iPart]; //total height of all theoretical heights for normalization
75     
76   }//species loop
77
78   for(Int_t iPart=0;iPart<nsp;iPart++) {//species loop to assign probabilities
79     
80     if(!desert) prob[iPart]=h[iPart]/hTot;
81     else prob[iPart]=1.0/(Float_t)nsp;            //all theoretical values are far away from experemental one
82     
83   }
84   
85   delete [] h;
86   delete pPid ; pPid=0x0;
87 }
88 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
89 Double_t AliHMPIDPid::Resolution(Double_t thetaCerTh, AliESDtrack *pTrk)
90 {
91   AliHMPIDParam *pParam = AliHMPIDParam::Instance();
92       
93   AliHMPIDRecon rec;
94   Float_t xRa,yRa,thRa,phRa;
95   pTrk->GetHMPIDtrk(xRa,yRa,thRa,phRa);
96   rec.SetTrack(xRa,yRa,thRa,phRa);
97   Double_t thetaMax = TMath::ACos(1./pParam->MeanIdxRad());
98   Int_t nPhots = (Int_t)(21.*TMath::Sin(thetaCerTh)*TMath::Sin(thetaCerTh)/(TMath::Sin(thetaMax)*TMath::Sin(thetaMax))+0.01);
99
100   Double_t sigmatot = 0;
101   Int_t nTrks = 20;
102   for(Int_t iTrk=0;iTrk<nTrks;iTrk++) {
103     Double_t invSigma = 0;
104     Int_t nPhotsAcc = 0;
105     for(Int_t j=0;j<nPhots;j++){
106       Double_t phi = gRandom->Rndm()*TMath::TwoPi();
107       TVector2 pos; pos=rec.TracePhot(thetaCerTh,phi);
108       if(!pParam->IsInside(pos.X(),pos.Y())) continue;
109       if(pParam->IsInDead(pos.X(),pos.Y())) continue;
110       Double_t sigma2 = pParam->Sigma2(thRa,phRa,thetaCerTh,phi);//photon candidate sigma^2
111       if(sigma2!=0) {
112         invSigma += 1./sigma2;
113         nPhotsAcc++;
114       }
115     }      
116     if(invSigma!=0) sigmatot += 1./TMath::Sqrt(invSigma);  
117   }
118   return sigmatot/nTrks;
119 }