]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEERBase/AliHMPIDPIDResponse.cxx
Refined the tuning of the TOF tail parameterization for analysis (in particular for...
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliHMPIDPIDResponse.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 // Class AliHMPIDPIDResponse
18 //
19 // HMPID class to perfom particle identification
20 // 
21 // Author: G. Volpe, giacomo.volpe@cern.ch
22 //***********************************************************
23
24
25 #include "AliHMPIDPIDResponse.h"  //class header
26 #include "AliPID.h"               //FindPid()
27 #include "AliVTrack.h"            //FindPid()
28 #include "AliLog.h"               //general
29 #include <TRandom.h>              //Resolution()
30 #include <TVector2.h>             //Resolution()
31 #include <TRotation.h>
32 #include <TF1.h>
33 #include <TGeoManager.h>          //Instance()
34 #include <TGeoMatrix.h>           //Instance()
35 #include <TGeoPhysicalNode.h>     //ctor
36 #include <TGeoBBox.h>
37 #include <TObjArray.h>
38
39 Float_t AliHMPIDPIDResponse::fgkMinPcX[]={0.,0.,0.,0.,0.,0.};
40 Float_t AliHMPIDPIDResponse::fgkMaxPcX[]={0.,0.,0.,0.,0.,0.};
41 Float_t AliHMPIDPIDResponse::fgkMinPcY[]={0.,0.,0.,0.,0.,0.};
42 Float_t AliHMPIDPIDResponse::fgkMaxPcY[]={0.,0.,0.,0.,0.,0.};
43
44 Float_t AliHMPIDPIDResponse::fgCellX=0.;
45 Float_t AliHMPIDPIDResponse::fgCellY=0.;
46
47 Float_t AliHMPIDPIDResponse::fgPcX=0;
48 Float_t AliHMPIDPIDResponse::fgPcY=0;
49
50 Float_t AliHMPIDPIDResponse::fgAllX=0;
51 Float_t AliHMPIDPIDResponse::fgAllY=0;
52
53 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54 AliHMPIDPIDResponse::AliHMPIDPIDResponse():
55   TNamed("HMPIDPIDResponseRec","HMPIDPIDResponsePid"),    
56   fRefIdx(1.28947),
57   fTrkDir(0,0,1),  
58   fTrkPos(30,40),  
59   fRefIndexArray(0x0)
60 {
61   //
62   // ctor
63   //
64   
65   Float_t dead=2.6;// cm of the dead zones between PCs-> See 2CRC2099P1
66
67   fgCellX=0.8; fgCellY=0.84;
68   
69   fgPcX  = 80.*fgCellX;      fgPcY = 48.*fgCellY;
70   fgAllX = 2.*fgPcX+dead;
71   fgAllY = 3.*fgPcY+2.*dead;
72
73   fgkMinPcX[1]=fgPcX+dead; fgkMinPcX[3]=fgkMinPcX[1];  fgkMinPcX[5]=fgkMinPcX[3];
74   fgkMaxPcX[0]=fgPcX;      fgkMaxPcX[2]=fgkMaxPcX[0];  fgkMaxPcX[4]=fgkMaxPcX[2];
75   fgkMaxPcX[1]=fgAllX;     fgkMaxPcX[3]=fgkMaxPcX[1];  fgkMaxPcX[5]=fgkMaxPcX[3];
76
77   fgkMinPcY[2]=fgPcY+dead;       fgkMinPcY[3]=fgkMinPcY[2];  
78   fgkMinPcY[4]=2.*fgPcY+2.*dead; fgkMinPcY[5]=fgkMinPcY[4];
79   fgkMaxPcY[0]=fgPcY;            fgkMaxPcY[1]=fgkMaxPcY[0];  
80   fgkMaxPcY[2]=2.*fgPcY+dead;    fgkMaxPcY[3]=fgkMaxPcY[2]; 
81   fgkMaxPcY[4]=fgAllY;           fgkMaxPcY[5]=fgkMaxPcY[4];   
82     
83   for(Int_t i=kMinCh;i<=kMaxCh;i++)
84     if(gGeoManager && gGeoManager->IsClosed()) {
85       TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(Form("/HMPID/Chamber%i",i));
86       if (!pne) {
87         AliErrorClass(Form("The symbolic volume %s does not correspond to any physical entry!",Form("HMPID_%i",i)));
88         fM[i]=new TGeoHMatrix;
89         IdealPosition(i,fM[i]);
90       } else {
91         TGeoPhysicalNode *pnode = pne->GetPhysicalNode();
92         if(pnode) fM[i]=new TGeoHMatrix(*(pnode->GetMatrix()));
93         else {
94           fM[i]=new TGeoHMatrix;
95           IdealPosition(i,fM[i]);
96         }
97       }
98     } else{
99       fM[i]=new TGeoHMatrix;
100       IdealPosition(i,fM[i]);
101     } 
102     
103 }//ctor
104 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
105 AliHMPIDPIDResponse::AliHMPIDPIDResponse(const AliHMPIDPIDResponse& c):
106   TNamed(c), 
107   fRefIdx(c.fRefIdx),
108   fTrkDir(c.fTrkDir),  
109   fTrkPos(c.fTrkPos),  
110   fRefIndexArray(c.fRefIndexArray)
111  {
112    //
113    // copy ctor
114    //
115    
116    for(Int_t i=0; i<6; i++) {
117       
118       fgkMinPcX[i] = c.fgkMinPcX[i];
119       fgkMinPcY[i] = c.fgkMinPcY[i];
120       fgkMaxPcX[i] = c.fgkMaxPcX[i];
121       fgkMaxPcY[i] = c.fgkMaxPcY[i];
122      }
123    
124    for(Int_t i=0; i<7; i++) fM[i] = c.fM[i];
125  }
126 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
127 AliHMPIDPIDResponse& AliHMPIDPIDResponse::operator=(const AliHMPIDPIDResponse& c) {
128
129    //
130    // assignment operator
131    //       
132   if(this!=&c){
133      TNamed::operator=(c);
134      fgCellX = c.fgCellX;
135      fgCellY = c.fgCellY;
136      fgPcX   = c.fgPcX;
137      fgPcY   = c.fgPcY;
138      fgAllX  = c.fgAllX;
139      fgAllY  = c.fgAllY;
140      fRefIdx = c.fRefIdx;
141      fTrkDir = c.fTrkDir;  
142      fTrkPos = c.fTrkPos;  
143      fRefIndexArray = c.fRefIndexArray;
144      for(Int_t i=0; i<6; i++) {    
145       fgkMinPcX[i] = c.fgkMinPcX[i];
146       fgkMinPcY[i] = c.fgkMinPcY[i];
147       fgkMaxPcX[i] = c.fgkMaxPcX[i];
148       fgkMaxPcY[i] = c.fgkMaxPcY[i];
149      }   
150      for(Int_t i=0; i<7; i++) fM[i] = c.fM[i];                 
151     } 
152     
153   return *this; 
154 }    
155 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
156 void AliHMPIDPIDResponse::IdealPosition(Int_t iCh, TGeoHMatrix *pMatrix) {
157
158 // Construct ideal position matrix for a given chamber
159 // Arguments: iCh- chamber ID; pMatrix- pointer to precreated unity matrix where to store the results
160 // Returns: none
161
162   const Double_t kAngHor=19.5;        //  horizontal angle between chambers  19.5 grad
163   const Double_t kAngVer=20;          //  vertical angle between chambers    20   grad     
164   const Double_t kAngCom=30;          //  common HMPID rotation with respect to x axis  30   grad     
165   const Double_t kTrans[3]={490,0,0}; //  center of the chamber is on window-gap surface
166   pMatrix->RotateY(90);               //  rotate around y since initial position is in XY plane -> now in YZ plane
167   pMatrix->SetTranslation(kTrans);    //  now plane in YZ is shifted along x 
168   switch(iCh){
169     case 0:                pMatrix->RotateY(kAngHor);  pMatrix->RotateZ(-kAngVer);  break; //right and down 
170     case 1:                                            pMatrix->RotateZ(-kAngVer);  break; //down              
171     case 2:                pMatrix->RotateY(kAngHor);                               break; //right 
172     case 3:                                                                         break; //no rotation
173     case 4:                pMatrix->RotateY(-kAngHor);                              break; //left   
174     case 5:                                            pMatrix->RotateZ(kAngVer);   break; //up
175     case 6:                pMatrix->RotateY(-kAngHor); pMatrix->RotateZ(kAngVer);   break; //left and up 
176   }
177   pMatrix->RotateZ(kAngCom);     //apply common rotation  in XY plane    
178    
179 }
180 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
181 Double_t AliHMPIDPIDResponse::GetExpectedSignal(const AliVTrack *vTrk, AliPID::EParticleType specie) const {
182   
183   // expected Cherenkov angle calculation
184   
185   const Double_t nmean = GetNMean(vTrk);
186   return ExpectedSignal(vTrk,nmean,specie);
187 }
188 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
189 Double_t AliHMPIDPIDResponse::GetExpectedSigma(const AliVTrack *vTrk, AliPID::EParticleType specie) const {
190   
191   // expected resolution calculation
192   
193   const Double_t nmean = GetNMean(vTrk);
194   return ExpectedSigma(vTrk,nmean,specie);
195 }
196 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
197 Double_t AliHMPIDPIDResponse::ExpectedSignal(const AliVTrack *vTrk, Double_t nmean, AliPID::EParticleType specie) const {
198   
199   // expected Cherenkov angle calculation
200   
201   Double_t thetaTheor = -999.;
202   
203   Double_t p[3] = {0}, mom = 0;
204   if(vTrk->GetOuterHmpPxPyPz(p))  mom = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]+p[2]*p[2]);  // Momentum of the charged particle    
205   else return thetaTheor;
206     
207   const Double_t mass = AliPID::ParticleMass(specie); 
208   const Double_t cosTheta = TMath::Sqrt(mass*mass+mom*mom)/(nmean*mom);
209    
210   if(cosTheta>1) return thetaTheor;
211                   
212   else thetaTheor = TMath::ACos(cosTheta);
213   
214   return thetaTheor;                                                                                          //  evaluate the theor. Theta Cherenkov
215 }
216 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
217 Double_t AliHMPIDPIDResponse::ExpectedSigma(const AliVTrack *vTrk, Double_t nmean, AliPID::EParticleType specie) const {
218   
219   // expected resolution calculation
220   
221   Float_t x=0., y=0.;
222   Int_t q=0, nph=0;
223   Float_t xPc=0.,yPc=0.,thRa=0.,phRa=0.;
224   
225   vTrk->GetHMPIDmip(x,y,q,nph);  
226   vTrk->GetHMPIDtrk(xPc,yPc,thRa,phRa);
227       
228   const Double_t xRa = xPc - (RadThick()+WinThick()+GapThick())*TMath::Cos(phRa)*TMath::Tan(thRa);  //just linear extrapolation back to RAD
229   const Double_t yRa = yPc - (RadThick()+WinThick()+GapThick())*TMath::Sin(phRa)*TMath::Tan(thRa);  //just linear extrapolation back to RAD
230   
231   const Double_t thetaCerTh = ExpectedSignal(vTrk,nmean,specie);
232   const Double_t occupancy  = vTrk->GetHMPIDoccupancy();
233   const Double_t thetaMax   = TMath::ACos(1./nmean);
234   const Int_t    nPhotsTh   = (Int_t)(12.*TMath::Sin(thetaCerTh)*TMath::Sin(thetaCerTh)/(TMath::Sin(thetaMax)*TMath::Sin(thetaMax))+0.01);
235
236   Double_t sigmatot = 0;
237   Int_t nTrks = 20;
238   for(Int_t iTrk=0;iTrk<nTrks;iTrk++) {
239     Double_t invSigma = 0;
240     Int_t nPhotsAcc = 0;
241     
242     Int_t nPhots = 0; 
243     if(nph<nPhotsTh+TMath::Sqrt(nPhotsTh) && nph>nPhotsTh-TMath::Sqrt(nPhotsTh)) nPhots = nph;
244     else nPhots = gRandom->Poisson(nPhotsTh);
245     
246     for(Int_t j=0;j<nPhots;j++){
247       Double_t phi = gRandom->Rndm()*TMath::TwoPi();
248       TVector2 pos; pos = TracePhot(xRa,yRa,thRa,phRa,thetaCerTh,phi);
249       if(!IsInside(pos.X(),pos.Y())) continue;
250       if(IsInDead(pos.X(),pos.Y()))  continue;
251       Double_t sigma2 = Sigma2(thRa,thRa,thetaCerTh,phi); //photon candidate sigma^2
252       
253       if(sigma2!=0) {
254         invSigma += 1./sigma2;
255         nPhotsAcc++;
256       }
257     }      
258     if(invSigma!=0) sigmatot += 1./TMath::Sqrt(invSigma);  
259   }
260     
261   return (sigmatot/nTrks)*SigmaCorrFact(specie,occupancy);
262 }
263 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
264 Double_t AliHMPIDPIDResponse::GetNumberOfSigmas(const AliVTrack *vTrk, AliPID::EParticleType specie) const {
265
266   // Number of sigmas calculation
267     
268   Double_t nSigmas = -999.;
269
270   if(vTrk->GetHMPIDsignal()<0.) return nSigmas;
271     
272   const Double_t nmean = GetNMean(vTrk);
273   
274   const Double_t expSigma = ExpectedSigma(vTrk, nmean, specie);
275   
276   if(expSigma > 0.) nSigmas = (vTrk->GetHMPIDsignal() - ExpectedSignal(vTrk,nmean,specie))/expSigma;
277                          
278   return nSigmas;
279     
280 }
281 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
282 void AliHMPIDPIDResponse::GetProbability(const AliVTrack *vTrk,Int_t nSpecies,Double_t *prob) const {
283
284 // Calculates probability to be a electron-muon-pion-kaon-proton with the "amplitude" method
285 // from the given Cerenkov angle and momentum assuming no initial particle composition
286   
287   const Double_t thetaCerExp = vTrk->GetHMPIDsignal();                                                                           
288
289   const Double_t nmean = GetNMean(vTrk);
290     
291   if(thetaCerExp<=0){                                                                                     // HMPID does not find anything reasonable for this track, assign 0.2 for all species
292     for(Int_t iPart=0;iPart<nSpecies;iPart++) prob[iPart]=1.0/(Float_t)nSpecies;
293     return;
294   } 
295   
296   Double_t p[3] = {0,0,0};
297   
298   if(!(vTrk->GetOuterHmpPxPyPz(p))) for(Int_t iPart=0;iPart<nSpecies;iPart++) prob[iPart]=1.0/(Float_t)nSpecies;
299   
300   Double_t hTot=0;                                                                                        // Initialize the total height of the amplitude method
301   Double_t *h = new Double_t [nSpecies];                                                                  // number of charged particles to be considered
302
303   Bool_t desert = kTRUE;                                                                                  // Flag to evaluate if ThetaC is far ("desert") from the given Gaussians
304   
305   for(Int_t iPart=0;iPart<nSpecies;iPart++){                                                              // for each particle
306
307         
308     h[iPart] = 0;                                                                                         // reset the height
309     Double_t thetaCerTh = ExpectedSignal(vTrk,nmean,(AliPID::EParticleType)iPart);                        // theoretical Theta Cherenkov
310     if(thetaCerTh>900.) continue;                                                                         // no light emitted, zero height
311     Double_t sigmaRing = ExpectedSigma(vTrk,nmean,(AliPID::EParticleType)iPart);
312     
313     if(sigmaRing==0) continue;
314       
315     if(TMath::Abs(thetaCerExp-thetaCerTh)<4*sigmaRing) desert = kFALSE;                                                               
316     h[iPart] =TMath::Gaus(thetaCerTh,thetaCerExp,sigmaRing,kTRUE);
317     hTot    +=h[iPart];                                                                                   // total height of all theoretical heights for normalization
318     
319   }//species loop
320
321   for(Int_t iPart=0;iPart<nSpecies;iPart++) {                                                             // species loop to assign probabilities
322      
323     if(!desert) prob[iPart]=h[iPart]/hTot;
324     else        prob[iPart]=1.0/(Float_t)nSpecies;                                                        // all theoretical values are far away from experemental one
325     
326   }
327   
328   delete [] h;
329 }
330 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
331 Double_t AliHMPIDPIDResponse::GetSignalDelta(const AliVTrack *vTrk, AliPID::EParticleType specie, Bool_t ratio/*=kFALSE*/) const {
332   
333   //
334   // calculation of Experimental Cherenkov angle - Theoretical Cherenkov angle  
335   //
336   const Double_t signal    = vTrk->GetHMPIDsignal();
337   const Double_t expSignal = GetExpectedSignal(vTrk,specie);
338
339   Double_t delta = -9999.;
340   if (!ratio) delta=signal-expSignal;
341   else if (expSignal>1.e-20) delta=signal/expSignal;
342   
343   return delta;
344 }
345 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
346 TVector2 AliHMPIDPIDResponse::TracePhot(Double_t xRa, Double_t yRa, Double_t thRa, Double_t phRa, Double_t ckovThe,Double_t ckovPhi) const {
347
348 // Trace a single Ckov photon from emission point somewhere in radiator up to photocathode taking into account ref indexes of materials it travereses
349 // Returns: distance between photon point on PC and track projection  
350   
351   Double_t theta=0.,phi=0.;
352   TVector3  dirTRS,dirLORS;
353   dirTRS.SetMagThetaPhi(1,ckovThe,ckovPhi);                     //photon in TRS
354   Trs2Lors(thRa,phRa,dirTRS,theta,phi);
355   dirLORS.SetMagThetaPhi(1,theta,phi);                          //photon in LORS
356   return TraceForward(xRa,yRa,dirLORS);                                 //now foward tracing
357 }//TracePhot()
358 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
359 TVector2 AliHMPIDPIDResponse::TraceForward(Double_t xRa, Double_t yRa, TVector3 dirCkov) const {
360
361 // Trace forward a photon from (x,y) up to PC
362 // Returns: pos of traced photon at PC
363   
364   TVector2 pos(-999,-999);
365   Double_t thetaCer = dirCkov.Theta();
366   if(thetaCer > TMath::ASin(1./GetRefIdx())) return pos;          //total refraction on WIN-GAP boundary
367   Double_t zRad= -0.5*RadThick()-0.5*WinThick();          //z position of middle of RAD
368   TVector3  posCkov(xRa,yRa,zRad);                        //RAD: photon position is track position @ middle of RAD 
369   Propagate(dirCkov,posCkov,           -0.5*WinThick());          //go to RAD-WIN boundary  
370   Refract  (dirCkov,         GetRefIdx(),WinIdx());       //RAD-WIN refraction
371   Propagate(dirCkov,posCkov,            0.5*WinThick());          //go to WIN-GAP boundary
372   Refract  (dirCkov,         WinIdx(),GapIdx());          //WIN-GAP refraction
373   Propagate(dirCkov,posCkov,0.5*WinThick()+GapThick());   //go to PC
374   pos.Set(posCkov.X(),posCkov.Y());
375   return pos;
376 }//TraceForward()
377 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
378 void AliHMPIDPIDResponse::Propagate(const TVector3 dir,TVector3 &pos,Double_t z) const {
379   
380 // Finds an intersection point between a line and XY plane shifted along Z.
381 // Arguments:  dir,pos   - vector along the line and any point of the line
382 //             z         - z coordinate of plain 
383 // Returns:  none
384 // On exit:  pos is the position if this intesection if any
385
386   static TVector3 nrm(0,0,1); 
387          TVector3 pnt(0,0,z);
388   
389   TVector3 diff=pnt-pos;
390   Double_t sint=(nrm*diff)/(nrm*dir);
391   pos+=sint*dir;
392 }//Propagate()
393 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
394 void AliHMPIDPIDResponse::Refract(TVector3 &dir,Double_t n1,Double_t n2) const {
395
396 // Refract direction vector according to Snell law
397 // Arguments: 
398 //            n1 - ref idx of first substance
399 //            n2 - ref idx of second substance
400 //   Returns: none
401 //   On exit: dir is new direction
402   
403   Double_t sinref=(n1/n2)*TMath::Sin(dir.Theta());
404   if(TMath::Abs(sinref)>1.) dir.SetXYZ(-999,-999,-999);
405   else             dir.SetTheta(TMath::ASin(sinref));
406 }//Refract()
407 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
408 void AliHMPIDPIDResponse::Trs2Lors(Double_t thRa, Double_t phRa, TVector3 dirCkov,Double_t &thetaCer,Double_t &phiCer) const {
409
410   // Theta Cerenkov reconstruction 
411   // Returns: thetaCer of photon in LORS
412   //          phiCer of photon in LORS
413   
414   TRotation mtheta;   mtheta.RotateY(thRa);
415   TRotation mphi;       mphi.RotateZ(phRa);
416   TRotation mrot=mphi*mtheta;
417   TVector3 dirCkovLORS;
418   dirCkovLORS=mrot*dirCkov;
419   phiCer  = dirCkovLORS.Phi();                                          //actual value of the phi of the photon
420   thetaCer= dirCkovLORS.Theta();                                        //actual value of thetaCerenkov of the photon
421 }
422 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
423 Bool_t AliHMPIDPIDResponse::IsInDead(Float_t x,Float_t y)  {
424   
425 // Check is the current point is outside of sensitive area or in dead zones
426 // Arguments: x,y -position
427 // Returns: 1 if not in sensitive zone
428              
429   for(Int_t iPc=0;iPc<6;iPc++)
430     if(x>=fgkMinPcX[iPc] && x<=fgkMaxPcX[iPc] && y>=fgkMinPcY[iPc] && y<=fgkMaxPcY [iPc]) return kFALSE; //in current pc
431   
432   return kTRUE;
433 }
434 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
435 Double_t AliHMPIDPIDResponse::Sigma2(Double_t trkTheta,Double_t trkPhi,Double_t ckovTh, Double_t ckovPh) const {
436   
437 // Analithical calculation of total error (as a sum of localization, geometrical and chromatic errors) on Cerenkov angle for a given Cerenkov photon 
438 // created by a given MIP. Formules according to CERN-EP-2000-058 
439 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
440 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
441 //            MIP beta
442 // Returns: absolute error on Cerenkov angle, [radians]    
443   
444   TVector3 v(-999,-999,-999);
445   Double_t trkBeta = 1./(TMath::Cos(ckovTh)*GetRefIdx());
446   
447   if(trkBeta > 1) trkBeta = 1;                 //protection against bad measured thetaCer  
448   if(trkBeta < 0) trkBeta = 0.0001;            //
449
450   v.SetX(SigLoc (trkTheta,trkPhi,ckovTh,ckovPh,trkBeta));
451   v.SetY(SigGeom(trkTheta,trkPhi,ckovTh,ckovPh,trkBeta));
452   v.SetZ(SigCrom(trkTheta,ckovTh,ckovPh,trkBeta));
453
454   return v.Mag2();
455 }
456 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
457 Double_t AliHMPIDPIDResponse::SigLoc(Double_t trkTheta,Double_t trkPhi,Double_t thetaC, Double_t phiC,Double_t betaM) const {
458   
459 // Analitical calculation of localization error (due to finite segmentation of PC) on Cerenkov angle for a given Cerenkov photon 
460 // created by a given MIP. Fromulae according to CERN-EP-2000-058 
461 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
462 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
463 //            MIP beta
464 // Returns: absolute error on Cerenkov angle, [radians]    
465   
466   Double_t phiDelta = phiC;
467
468   Double_t sint     = TMath::Sin(trkTheta);
469   Double_t cost     = TMath::Cos(trkTheta);
470   Double_t sinf     = TMath::Sin(trkPhi);
471   Double_t cosf     = TMath::Cos(trkPhi);
472   Double_t sinfd    = TMath::Sin(phiDelta);
473   Double_t cosfd    = TMath::Cos(phiDelta);
474   Double_t tantheta = TMath::Tan(thetaC);
475   
476   Double_t alpha =cost-tantheta*cosfd*sint;                                                    // formula (11)
477   Double_t k = 1.-GetRefIdx()*GetRefIdx()+alpha*alpha/(betaM*betaM);                           // formula (after 8 in the text)
478   if (k<0) return 1e10;
479   Double_t mu =sint*sinf+tantheta*(cost*cosfd*sinf+sinfd*cosf);                                // formula (10)
480   Double_t e  =sint*cosf+tantheta*(cost*cosfd*cosf-sinfd*sinf);                                // formula (9)
481
482   Double_t kk = betaM*TMath::Sqrt(k)/(GapThick()*alpha);                                       // formula (6) and (7)
483   Double_t dtdxc = kk*(k*(cosfd*cosf-cost*sinfd*sinf)-(alpha*mu/(betaM*betaM))*sint*sinfd);    // formula (6)           
484   Double_t dtdyc = kk*(k*(cosfd*sinf+cost*sinfd*cosf)+(alpha* e/(betaM*betaM))*sint*sinfd);    // formula (7)            pag.4
485   
486   Double_t errX = 0.2,errY=0.25;                                                                //end of page 7
487   return  TMath::Sqrt(errX*errX*dtdxc*dtdxc + errY*errY*dtdyc*dtdyc); 
488 }
489 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
490 Double_t AliHMPIDPIDResponse::SigCrom(Double_t trkTheta,Double_t thetaC, Double_t phiC,Double_t betaM) const {
491
492 // Analitical calculation of chromatic error (due to lack of knowledge of Cerenkov photon energy) on Cerenkov angle for a given Cerenkov photon 
493 // created by a given MIP. Fromulae according to CERN-EP-2000-058 
494 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
495 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
496 //            MIP beta
497 //   Returns: absolute error on Cerenkov angle, [radians]    
498   
499   Double_t phiDelta = phiC;
500
501   Double_t sint     = TMath::Sin(trkTheta);
502   Double_t cost     = TMath::Cos(trkTheta);
503   Double_t cosfd    = TMath::Cos(phiDelta);
504   Double_t tantheta = TMath::Tan(thetaC);
505   
506   Double_t alpha =cost-tantheta*cosfd*sint;                                         // formula (11)
507   Double_t dtdn = cost*GetRefIdx()*betaM*betaM/(alpha*tantheta);                    // formula (12)
508             
509   Double_t f = 0.0172*(7.75-5.635)/TMath::Sqrt(24.);
510
511   return f*dtdn;
512 }//SigCrom()
513 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
514 Double_t AliHMPIDPIDResponse::SigGeom(Double_t trkTheta,Double_t trkPhi,Double_t thetaC, Double_t phiC,Double_t betaM) const {
515   
516 // Analitical calculation of geometric error (due to lack of knowledge of creation point in radiator) on Cerenkov angle for a given Cerenkov photon 
517 // created by a given MIP. Formulae according to CERN-EP-2000-058 
518 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
519 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
520 //            MIP beta
521 //   Returns: absolute error on Cerenkov angle, [radians]    
522
523   Double_t phiDelta = phiC;
524
525   Double_t sint     = TMath::Sin(trkTheta);
526   Double_t cost     = TMath::Cos(trkTheta);
527   Double_t sinf     = TMath::Sin(trkPhi);
528   Double_t cosfd    = TMath::Cos(phiDelta);
529   Double_t costheta = TMath::Cos(thetaC);
530   Double_t tantheta = TMath::Tan(thetaC);
531   
532   Double_t alpha =cost-tantheta*cosfd*sint;                                                // formula (11)
533   
534   Double_t k = 1.-GetRefIdx()*GetRefIdx()+alpha*alpha/(betaM*betaM);                       // formula (after 8 in the text)
535   if (k<0) return 1e10;
536
537   Double_t eTr = 0.5*RadThick()*betaM*TMath::Sqrt(k)/(GapThick()*alpha);                    // formula (14)
538   Double_t lambda = (1.-sint*sinf)*(1.+sint*sinf);                                          // formula (15)
539
540   Double_t c1 = 1./(1.+ eTr*k/(alpha*alpha*costheta*costheta));                             // formula (13.a)
541   Double_t c2 = betaM*TMath::Power(k,1.5)*tantheta*lambda/(GapThick()*alpha*alpha);         // formula (13.b)
542   Double_t c3 = (1.+eTr*k*betaM*betaM)/((1+eTr)*alpha*alpha);                               // formula (13.c)
543   Double_t c4 = TMath::Sqrt(k)*tantheta*(1-lambda)/(GapThick()*betaM);                      // formula (13.d)
544   Double_t dtdT = c1 * (c2+c3*c4);
545   Double_t trErr = RadThick()/(TMath::Sqrt(12.)*cost);
546
547   return trErr*dtdT;
548 }//SigGeom()
549 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
550 Double_t AliHMPIDPIDResponse::GetNMean(const AliVTrack *vTrk) const {
551
552   // 
553   // mean refractive index calculation
554   //
555   Double_t nmean = -999.; 
556   
557   Float_t xPc=0.,yPc=0.,thRa=0.,phRa=0.;
558   vTrk->GetHMPIDtrk(xPc,yPc,thRa,phRa);
559   
560   const Int_t ch = vTrk->GetHMPIDcluIdx()/1000000;
561   
562   const Double_t yRa = yPc - (RadThick()+WinThick()+GapThick())*TMath::Sin(phRa)*TMath::Tan(thRa);  //just linear extrapolation back to RAD
563       
564   TF1 *RefIndex=0x0;
565   
566   if(GetRefIndexArray()) RefIndex = (TF1*)(GetRefIndexArray()->At(ch));
567   else return nmean;
568   
569   if(RefIndex) nmean = RefIndex->Eval(yRa);
570   else return nmean;
571   
572   return nmean;   
573 }  
574 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
575 Double_t AliHMPIDPIDResponse::SigmaCorrFact  (Int_t iPart, Double_t occupancy) {
576
577 // calculation of sigma correction factor
578   
579   Double_t corr = 1.0;
580        
581   switch(iPart) {
582     case 0: corr = 0.115*occupancy + 1.166; break; 
583     case 1: corr = 0.115*occupancy + 1.166; break;
584     case 2: corr = 0.115*occupancy + 1.166; break;
585     case 3: corr = 0.065*occupancy + 1.137; break;
586     case 4: corr = 0.048*occupancy + 1.202; break;
587   }                                                                                                                           
588  return corr; 
589 }
590