Right Local Reference System in theta Cerenkov reconstruction
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDRecon.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 // AliHMPIDRecon                                                         //
19 //                                                                      //
20 // HMPID class to perfom pattern recognition based on Hough transfrom    //
21 // for single chamber                                                   //
22 //////////////////////////////////////////////////////////////////////////
23
24 #include "AliHMPIDRecon.h"   //class header
25 #include "AliHMPIDParam.h"   //CkovAngle()
26 #include "AliHMPIDCluster.h" //CkovAngle()
27 #include <TRotation.h>       //TracePhot()
28 #include <TH1D.h>            //HoughResponse()
29 #include <TClonesArray.h>    //CkovAngle()
30 #include <AliESDtrack.h>     //CkovAngle()
31
32 const Double_t AliHMPIDRecon::fgkRadThick=1.5;
33 const Double_t AliHMPIDRecon::fgkWinThick=0.5;
34 const Double_t AliHMPIDRecon::fgkGapThick=8.0;
35 const Double_t AliHMPIDRecon::fgkWinIdx  =1.5787;
36 const Double_t AliHMPIDRecon::fgkGapIdx  =1.0005;
37
38 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
39 AliHMPIDRecon::AliHMPIDRecon():TTask("RichRec","RichPat"),
40   fRadNmean(1.292),  
41   fPhotCnt(-1),
42   fCkovSigma2(0),
43   fIsWEIGHT(kFALSE),
44   fDTheta(0.001),
45   fWindowWidth(0.045),
46   fTrkDir(TVector3(0,0,1)),fTrkPos(TVector2(30,40))  
47 {
48 // main ctor
49   for (Int_t i=0; i<3000; i++) {
50     fPhotFlag[i] =  0;
51     fPhotCkov[i] = -1;
52     fPhotPhi [i] = -1;
53     fPhotWei [i] =  0;
54   }
55 }
56 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57 void AliHMPIDRecon::CkovAngle(AliESDtrack *pTrk,TClonesArray *pCluLst,Double_t nmean)
58 {
59 // Pattern recognition method based on Hough transform
60 // Arguments:   pTrk     - track for which Ckov angle is to be found
61 //              pCluLst  - list of clusters for this chamber   
62 //   Returns:            - track ckov angle, [rad], 
63     
64   AliHMPIDParam *pParam=AliHMPIDParam::Instance();
65   
66   if(pCluLst->GetEntries()>pParam->MultCut()) fIsWEIGHT = kTRUE; // offset to take into account bkg in reconstruction
67   else                                        fIsWEIGHT = kFALSE;
68
69   Float_t xRa,yRa,th,ph;       
70   pTrk->GetHMPIDtrk(xRa,yRa,th,ph);        //initialize this track: th and ph angles at middle of RAD 
71   
72   th=TMath::Pi()- th;                      // right XYZ local orientation
73   SetTrack(xRa,yRa,th,ph);
74   
75   fRadNmean=nmean;
76
77   Float_t dMin=999,mipX=-1,mipY=-1;Int_t chId=-1,mipId=-1,mipQ=-1;                                                                           
78   fPhotCnt=0;                                                      
79   for (Int_t iClu=0; iClu<pCluLst->GetEntriesFast();iClu++){//clusters loop
80     AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluLst->UncheckedAt(iClu);                       //get pointer to current cluster    
81     chId=pClu->Ch();
82     if(pClu->Q()>pParam->QCut()){                                                             //charge compartible with MIP clusters      
83       Float_t dX=fPc.X()-pClu->X(),dY=fPc.Y()-pClu->Y(),d =TMath::Sqrt(dX*dX+dY*dY);          //distance between current cluster and intersection point
84       if( d < dMin) {mipId=iClu; dMin=d;mipX=pClu->X();mipY=pClu->Y();mipQ=(Int_t)pClu->Q();} //current cluster is closer, overwrite data for min cluster
85     }else{                                                                                    //charge compatible with photon cluster
86       Double_t thetaCer,phiCer;
87       if(FindPhotCkov(pClu->X(),pClu->Y(),thetaCer,phiCer)){                                  //find ckov angle for this  photon candidate
88         fPhotCkov[fPhotCnt]=thetaCer;                                                         //actual theta Cerenkov (in TRS)
89         fPhotPhi [fPhotCnt]=phiCer;                                                           //actual phi   Cerenkov (in TRS): -pi to come back to "unusual" ref system (X,Y,-Z)
90         fPhotCnt++;                                                                           //increment counter of photon candidates
91       }
92     }
93   }//clusters loop
94   Int_t iNacc=FlagPhot(HoughResponse());                                                      //flag photons according to individual theta ckov with respect to most probable
95   pTrk->SetHMPIDmip(mipX,mipY,mipQ,iNacc);                                                    //store mip info 
96
97   if(mipId==-1)              {pTrk->SetHMPIDsignal(kMipQdcCut);  return;}                     //no clusters with QDC more the threshold at all
98   if(dMin>pParam->DistCut()) {pTrk->SetHMPIDsignal(kMipDistCut); return;}                     //closest cluster with enough charge is still too far from intersection
99   pTrk->SetHMPIDcluIdx(chId,mipId);                                                           //set index of cluster
100   if(iNacc<1)    pTrk->SetHMPIDsignal(kNoPhotAccept);                                         //no photon candidates is accepted
101   else           pTrk->SetHMPIDsignal(FindRingCkov(pCluLst->GetEntries()));                   //find best Theta ckov for ring i.e. track
102   
103   pTrk->SetHMPIDchi2(fCkovSigma2);                                                            //errors squared 
104
105 }//ThetaCerenkov()
106 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107 Bool_t AliHMPIDRecon::FindPhotCkov(Double_t cluX,Double_t cluY,Double_t &thetaCer,Double_t &phiCer)
108 {
109 // Finds Cerenkov angle  for this photon candidate
110 // Arguments: cluX,cluY - position of cadidate's cluster  
111 // Returns: Cerenkov angle 
112
113   TVector3 dirCkov;
114   
115   Double_t zRad= 0.5*AliHMPIDRecon::fgkRadThick
116                     +AliHMPIDRecon::fgkWinThick
117                     +AliHMPIDRecon::fgkGapThick;                    //z position of middle of RAD
118
119   TVector3 rad(fTrkPos.X(),fTrkPos.Y(),zRad);                       //impact point at middle of RAD
120   TVector3  pc(cluX,cluY,0);                                        //mip at PC: z=0 @ PC
121   Double_t cluR = TMath::Sqrt((cluX-fTrkPos.X())*(cluX-fTrkPos.X())+
122                               (cluY-fTrkPos.Y())*(cluY-fTrkPos.Y()));//ref. distance impact RAD-CLUSTER   
123   Double_t phi=(pc-rad).Phi();                                      //phi of photon
124     
125   Double_t ckov1=0;
126   Double_t ckov2=TMath::Pi()-fTrkDir.Theta()+0.75; //start to find theta cerenkov in DRS
127   const Double_t kTol=0.01;
128   Int_t iIterCnt = 0;
129   while(1){
130     if(iIterCnt>=50) return kFALSE;
131     Double_t ckov=0.5*(ckov1+ckov2);
132     dirCkov.SetMagThetaPhi(1,TMath::Pi()-ckov,phi);
133     TVector2 posC=TraceForward(dirCkov);                      //trace photon with actual angles
134     Double_t dist=cluR-(posC-fTrkPos).Mod();                  //get distance between trial point and cluster position
135     if(posC.X()==-999) dist = - 999;                          //total reflection problem
136     iIterCnt++;                                               //counter step
137     if     (dist> kTol) ckov1=ckov;                           //cluster @ larger ckov
138     else if(dist<-kTol) ckov2=ckov;                           //cluster @ smaller ckov
139     else{                                                     //precision achived: ckov in DRS found
140       dirCkov.SetMagThetaPhi(1,ckov,phi);                     //
141       RecPhot(dirCkov,thetaCer,phiCer);                       //find ckov (in TRS:the effective Cherenkov angle!)
142       thetaCer = TMath::Pi() - thetaCer;
143       return kTRUE;
144     }
145   }
146 }//FindPhotTheta()
147 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
148 TVector2 AliHMPIDRecon::TraceForward(TVector3 dirCkov)const
149 {
150   //Trace forward a photon from (x,y) up to PC
151   // Arguments: dirCkov photon vector in LORS
152   //   Returns: pos of traced photon at PC
153   TVector2 pos(-999,-999);
154   Double_t thetaCer = TMath::Pi()-dirCkov.Theta();
155   if(thetaCer > TMath::ASin(1./fRadNmean))  return pos;            //total refraction on WIN-GAP boundary
156   Double_t zRad= 0.5*AliHMPIDRecon::fgkRadThick
157                     +AliHMPIDRecon::fgkWinThick
158                     +AliHMPIDRecon::fgkGapThick;                   //z position of middle of RAD
159   TVector3  posCkov(fTrkPos.X(),fTrkPos.Y(),zRad);                 //RAD: photon position is track position @ middle of RAD 
160   Propagate(dirCkov,posCkov,fgkWinThick+fgkGapThick);              //go to RAD-WIN boundary  
161   Refract  (dirCkov,         fRadNmean,fgkWinIdx   );              //RAD-WIN refraction
162   Propagate(dirCkov,posCkov,            fgkGapThick);              //go to WIN-GAP boundary
163   Refract  (dirCkov,         fgkWinIdx,fgkGapIdx   );              //WIN-GAP refraction
164   Propagate(dirCkov,posCkov,                      0);              //go to PC
165   pos.Set(posCkov.X(),posCkov.Y());
166   return pos;
167 }//TraceForward()
168 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169 void AliHMPIDRecon::RecPhot(TVector3 dirCkov,Double_t &thetaCer,Double_t &phiCer)
170 {
171   //Theta Cerenkov reconstruction 
172   // Arguments: (x,y) of initial point in LORS, dirCkov photon vector in LORS
173   //   Returns: thetaCer theta cerenkov reconstructed
174 //  TVector3 dirTrk;
175 //  dirTrk.SetMagThetaPhi(1,fTrkDir.Theta(),fTrkDir.Phi());
176 //  Double_t thetaCer = TMath::ACos(dirCkov*dirTrk);
177   TRotation mtheta;   mtheta.RotateY(- fTrkDir.Theta());
178   TRotation mphi;       mphi.RotateZ(- fTrkDir.Phi());
179   TRotation mrot=mtheta*mphi;
180   TVector3 dirCkovTRS;
181   dirCkovTRS=mrot*dirCkov;
182   phiCer  = dirCkovTRS.Phi();                                          //actual value of the phi of the photon
183   thetaCer= dirCkovTRS.Theta();                                        //actual value of thetaCerenkov of the photon
184 }
185 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
186 Double_t AliHMPIDRecon::FindRingArea(Double_t ckovAng)const
187 {
188 // Find area inside the cerenkov ring which lays inside PCs
189 // Arguments: ckovAng - cerenkov angle    
190 //   Returns: area of the ring in cm^2 for given theta ckov
191    
192   const Int_t kN=100;
193   Double_t area=0;
194   for(Int_t i=0;i<kN;i++){
195     TVector2 pos1=TracePhot(ckovAng,Double_t(TMath::TwoPi()*i    /kN));//trace this photon 
196     TVector2 pos2=TracePhot(ckovAng,Double_t(TMath::TwoPi()*(i+1)/kN));//trace the next photon 
197     area+=(pos1-fTrkPos)*(pos2-fTrkPos);                               //add area of the triangle... 
198   }
199   return area;
200 }//FindRingArea()
201 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
202 Double_t AliHMPIDRecon::FindRingCkov(Int_t)
203 {
204 // Loops on all Ckov candidates and estimates the best Theta Ckov for a ring formed by those candidates. Also estimates an error for that Theat Ckov
205 // collecting errors for all single Ckov candidates thetas. (Assuming they are independent)  
206 // Arguments: iNclus- total number of clusters in chamber for background estimation
207 //    Return: best estimation of track Theta ckov
208
209   Double_t wei = 0.;
210   Double_t weightThetaCerenkov = 0.;
211
212   Double_t ckovMin=9999.,ckovMax=0.;
213   Double_t sigma2 = 0;   //to collect error squared for this ring
214   
215   for(Int_t i=0;i<fPhotCnt;i++){//candidates loop
216     if(fPhotFlag[i] == 2){
217       if(fPhotCkov[i]<ckovMin) ckovMin=fPhotCkov[i];                         //find max and min Theta ckov from all candidates within probable window
218       if(fPhotCkov[i]>ckovMax) ckovMax=fPhotCkov[i]; 
219       weightThetaCerenkov += fPhotCkov[i]*fPhotWei[i];
220       wei += fPhotWei[i];                                                    //collect weight as sum of all candidate weghts   
221       
222       sigma2 += 1./Sigma2(fPhotCkov[i],fPhotPhi[i]);
223     }
224   }//candidates loop
225   
226   if(sigma2>0) fCkovSigma2=1./sigma2;
227   else         fCkovSigma2=1e10;  
228   
229   if(wei != 0.) weightThetaCerenkov /= wei; else weightThetaCerenkov = 0.;
230   return weightThetaCerenkov;
231 }//FindCkovRing()
232 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
233 Int_t AliHMPIDRecon::FlagPhot(Double_t ckov)
234 {
235 // Flag photon candidates if their individual ckov angle is inside the window around ckov angle returned by  HoughResponse()
236 // Arguments: ckov- value of most probable ckov angle for track as returned by HoughResponse()
237 //   Returns: number of photon candidates happened to be inside the window
238
239 // Photon Flag:  Flag = 0 initial set; 
240 //               Flag = 1 good candidate (charge compatible with photon); 
241 //               Flag = 2 photon used for the ring;
242   
243   Int_t steps = (Int_t)((ckov )/ fDTheta); //how many times we need to have fDTheta to fill the distance between 0  and thetaCkovHough
244
245   Double_t tmin = (Double_t)(steps - 1)*fDTheta;
246   Double_t tmax = (Double_t)(steps)*fDTheta;
247   Double_t tavg = 0.5*(tmin+tmax);
248
249   tmin = tavg - 0.5*fWindowWidth;  tmax = tavg + 0.5*fWindowWidth;
250
251   Int_t iInsideCnt = 0; //count photons which Theta ckov inside the window
252   for(Int_t i=0;i<fPhotCnt;i++){//photon candidates loop
253     if(fPhotCkov[i] >= tmin && fPhotCkov[i] <= tmax)    { 
254       fPhotFlag[i]=2;     
255       iInsideCnt++;
256     }
257   }
258   return iInsideCnt;
259 }//FlagPhot()
260 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
261 TVector2 AliHMPIDRecon::TracePhot(Double_t ckovThe,Double_t ckovPhi)const
262 {
263 // Trace a single Ckov photon from emission point somewhere in radiator up to photocathode taking into account ref indexes of materials it travereses
264 // Arguments: ckovThe,ckovPhi- photon ckov angles in DRS, [rad]    
265 //   Returns: distance between photon point on PC and track projection  
266   TRotation mtheta;   mtheta.RotateY(fTrkDir.Theta());
267   TRotation mphi;       mphi.RotateZ(fTrkDir.Phi());  
268   TRotation mrot=mphi*mtheta;
269   TVector3  dirCkov,dirCkovTors;   
270
271   ckovThe = TMath::Pi()-ckovThe;
272   
273   dirCkovTors.SetMagThetaPhi(1,ckovThe,ckovPhi);                    //initially photon is directed according to requested ckov angle
274   dirCkov=mrot*dirCkovTors;                                         //now we know photon direction in LORS
275   return TraceForward(dirCkov);
276 }//TracePhot()
277 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
278 void AliHMPIDRecon::Propagate(const TVector3 dir,TVector3 &pos,Double_t z)const
279 {
280 // Finds an intersection point between a line and XY plane shifted along Z.
281 // Arguments:  dir,pos   - vector along the line and any point of the line
282 //             z         - z coordinate of plain 
283 //   Returns:  none
284 //   On exit:  pos is the position if this intesection if any
285   static TVector3 nrm(0,0,1); 
286          TVector3 pnt(0,0,z);
287   
288   TVector3 diff=pnt-pos;
289   Double_t sint=(nrm*diff)/(nrm*dir);
290   pos+=sint*dir;
291 }//Propagate()
292 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
293 void AliHMPIDRecon::Refract(TVector3 &dir,Double_t n1,Double_t n2)const
294 {
295 // Refract direction vector according to Snell law
296 // Arguments: 
297 //            n1 - ref idx of first substance
298 //            n2 - ref idx of second substance
299 //   Returns: none
300 //   On exit: dir is new direction
301   Double_t sinref=(n1/n2)*TMath::Sin(TMath::Pi()-dir.Theta());
302   if(sinref>1.)    dir.SetXYZ(-999,-999,-999);
303   else             dir.SetTheta(TMath::Pi()-TMath::ASin(sinref));
304 }//Refract()
305 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
306 Double_t AliHMPIDRecon::HoughResponse()
307 {
308 //
309 //
310 //       
311   Double_t kThetaMax=0.75;
312   Int_t nChannels = (Int_t)(kThetaMax/fDTheta+0.5);
313   TH1D *phots   = new TH1D("Rphot"  ,"phots"         ,nChannels,0,kThetaMax);
314   TH1D *photsw  = new TH1D("RphotWeighted" ,"photsw" ,nChannels,0,kThetaMax);
315   TH1D *resultw = new TH1D("resultw","resultw"       ,nChannels,0,kThetaMax);
316   Int_t nBin = (Int_t)(kThetaMax/fDTheta);
317   Int_t nCorrBand = (Int_t)(fWindowWidth/(2*fDTheta));
318   
319   for (Int_t i=0; i< fPhotCnt; i++){//photon cadidates loop
320     Double_t angle = fPhotCkov[i];  if(angle<0||angle>kThetaMax) continue;
321     phots->Fill(angle);
322     Int_t bin = (Int_t)(0.5+angle/(fDTheta));
323     Double_t weight=1.;
324     if(fIsWEIGHT){
325       Double_t lowerlimit = ((Double_t)bin)*fDTheta - 0.5*fDTheta;  Double_t upperlimit = ((Double_t)bin)*fDTheta + 0.5*fDTheta;   
326       Double_t diffArea = FindRingArea(upperlimit)-FindRingArea(lowerlimit);
327       if(diffArea>0) weight = 1./diffArea;
328     }
329     photsw->Fill(angle,weight);
330     fPhotWei[i]=weight;
331   }//photon candidates loop 
332    
333   for (Int_t i=1; i<=nBin;i++){
334     Int_t bin1= i-nCorrBand;
335     Int_t bin2= i+nCorrBand;
336     if(bin1<1) bin1=1;
337     if(bin2>nBin)bin2=nBin;
338     Double_t sumPhots=phots->Integral(bin1,bin2);
339     if(sumPhots<3) continue;                            // if less then 3 photons don't trust to this ring
340     Double_t sumPhotsw=photsw->Integral(bin1,bin2);
341     resultw->Fill((Double_t)((i+0.5)*fDTheta),sumPhotsw);
342   } 
343 // evaluate the "BEST" theta ckov as the maximum value of histogramm
344   Double_t *pVec = resultw->GetArray();
345   Int_t locMax = TMath::LocMax(nBin,pVec);
346   phots->Delete();photsw->Delete();resultw->Delete(); // Reset and delete objects
347   
348   return (Double_t)(locMax*fDTheta+0.5*fDTheta); //final most probable track theta ckov   
349 }//HoughResponse()
350 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
351 Double_t AliHMPIDRecon::Sigma2(Double_t ckovTh, Double_t ckovPh)const
352 {
353 // Analithical calculation of total error (as a sum of localization, geometrical and chromatic errors) on Cerenkov angle for a given Cerenkov photon 
354 // created by a given MIP. Fromulae according to CERN-EP-2000-058 
355 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
356 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
357 //            MIP beta
358 //   Returns: absolute error on Cerenkov angle, [radians]    
359   
360   TVector3 v(-999,-999,-999);
361   Double_t trkBeta = 1./(TMath::Cos(ckovTh)*fRadNmean);
362
363   v.SetX(SigLoc (ckovTh,ckovPh,trkBeta));
364   v.SetY(SigGeom(ckovTh,ckovPh,trkBeta));
365   v.SetZ(SigCrom(ckovTh,ckovPh,trkBeta));
366
367   return v.Mag2();
368 }
369 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
370 Double_t AliHMPIDRecon::SigLoc(Double_t thetaC, Double_t phiC,Double_t betaM)const
371 {
372 // Analithical calculation of localization error (due to finite segmentation of PC) on Cerenkov angle for a given Cerenkov photon 
373 // created by a given MIP. Fromulae according to CERN-EP-2000-058 
374 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
375 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
376 //            MIP beta
377 //   Returns: absolute error on Cerenkov angle, [radians]    
378   Double_t phiDelta = phiC - fTrkDir.Phi();
379
380   Double_t alpha =TMath::Cos(fTrkDir.Theta())-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Theta());
381   Double_t k = 1.-fRadNmean*fRadNmean+alpha*alpha/(betaM*betaM);
382   if (k<0) return 1e10;
383
384   Double_t mu =TMath::Sin(fTrkDir.Theta())*TMath::Sin(fTrkDir.Phi())+TMath::Tan(thetaC)*(TMath::Cos(fTrkDir.Theta())*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Phi())+TMath::Sin(phiDelta)*TMath::Cos(fTrkDir.Phi()));
385   Double_t e  =TMath::Sin(fTrkDir.Theta())*TMath::Cos(fTrkDir.Phi())+TMath::Tan(thetaC)*(TMath::Cos(fTrkDir.Theta())*TMath::Cos(phiDelta)*TMath::Cos(fTrkDir.Phi())-TMath::Sin(phiDelta)*TMath::Sin(fTrkDir.Phi()));
386
387   Double_t kk = betaM*TMath::Sqrt(k)/(8*alpha);
388   Double_t dtdxc = kk*(k*(TMath::Cos(phiDelta)*TMath::Cos(fTrkDir.Phi())-TMath::Cos(fTrkDir.Theta())*TMath::Sin(phiDelta)*TMath::Sin(fTrkDir.Phi()))-(alpha*mu/(betaM*betaM))*TMath::Sin(fTrkDir.Theta())*TMath::Sin(phiDelta));
389   Double_t dtdyc = kk*(k*(TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Phi())+TMath::Cos(fTrkDir.Theta())*TMath::Sin(phiDelta)*TMath::Cos(fTrkDir.Phi()))+(alpha* e/(betaM*betaM))*TMath::Sin(fTrkDir.Theta())*TMath::Sin(phiDelta));
390
391   return  TMath::Sqrt(0.2*0.2*dtdxc*dtdxc + 0.25*0.25*dtdyc*dtdyc);
392 }
393 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
394 Double_t AliHMPIDRecon::SigCrom(Double_t thetaC, Double_t phiC,Double_t betaM)const
395 {
396 // Analithical calculation of chromatic error (due to lack of knowledge of Cerenkov photon energy) on Cerenkov angle for a given Cerenkov photon 
397 // created by a given MIP. Fromulae according to CERN-EP-2000-058 
398 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
399 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
400 //            MIP beta
401 //   Returns: absolute error on Cerenkov angle, [radians]    
402   Double_t phiDelta = phiC - fTrkDir.Phi();
403   Double_t alpha =TMath::Cos(fTrkDir.Theta())-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Theta());
404
405   Double_t dtdn = TMath::Cos(fTrkDir.Theta())*fRadNmean*betaM*betaM/(alpha*TMath::Tan(thetaC));
406             
407   Double_t f = 0.00928*(7.75-5.635)/TMath::Sqrt(12.);
408
409   return f*dtdn;
410 }//SigCrom()
411 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
412 Double_t AliHMPIDRecon::SigGeom(Double_t thetaC, Double_t phiC,Double_t betaM)const
413 {
414 // Analithical calculation of geometric error (due to lack of knowledge of creation point in radiator) on Cerenkov angle for a given Cerenkov photon 
415 // created by a given MIP. Formulae according to CERN-EP-2000-058 
416 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
417 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
418 //            MIP beta
419 //   Returns: absolute error on Cerenkov angle, [radians]    
420
421   Double_t phiDelta = phiC - fTrkDir.Phi();
422   Double_t alpha =TMath::Cos(fTrkDir.Theta())-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Theta());
423
424   Double_t k = 1.-fRadNmean*fRadNmean+alpha*alpha/(betaM*betaM);
425   if (k<0) return 1e10;
426
427   Double_t eTr = 0.5*1.5*betaM*TMath::Sqrt(k)/(8*alpha);
428   Double_t lambda = 1.-TMath::Sin(fTrkDir.Theta())*TMath::Sin(fTrkDir.Theta())*TMath::Sin(phiC)*TMath::Sin(phiC);
429
430   Double_t c = 1./(1.+ eTr*k/(alpha*alpha*TMath::Cos(thetaC)*TMath::Cos(thetaC)));
431   Double_t i = betaM*TMath::Tan(thetaC)*lambda*TMath::Power(k,1.5);
432   Double_t ii = 1.+eTr*betaM*i;
433
434   Double_t err = c * (i/(alpha*alpha*8) +  ii*(1.-lambda) / ( alpha*alpha*8*betaM*(1.+eTr)) );
435   Double_t trErr = 1.5/(TMath::Sqrt(12.)*TMath::Cos(fTrkDir.Theta()));
436
437   return trErr*err;
438 }//SigGeom()
439 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++