MIP cluster size added (compacted word) and infos re-arranganged in HMPID
[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 "AliHMPIDCluster.h" //CkovAngle()
26 #include <TRotation.h>       //TracePhot()
27 #include <TH1D.h>            //HoughResponse()
28 #include <TClonesArray.h>    //CkovAngle()
29 #include <AliESDtrack.h>     //CkovAngle()
30
31 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32 AliHMPIDRecon::AliHMPIDRecon():
33   TTask("RichRec","RichPat"),
34   fPhotCnt(-1),
35   fPhotFlag(0x0),
36   fPhotCkov(0x0),
37   fPhotPhi(0x0),
38   fPhotWei(0x0),
39   fCkovSigma2(0),
40   fIsWEIGHT(kFALSE),
41   fDTheta(0.001),
42   fWindowWidth(0.045),
43   fRingArea(0),
44   fRingAcc(0),
45   fTrkDir(0,0,1),  // Just for test
46   fTrkPos(30,40),  // Just for test
47   fMipPos(0,0),
48   fPc(0,0),
49   fParam(AliHMPIDParam::Instance())
50 {
51 //..
52 //init of data members
53 //..
54   
55   fParam->SetRefIdx(fParam->MeanIdxRad()); // initialization of ref index to a default one
56 }
57 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
58 void AliHMPIDRecon::InitVars(Int_t n)
59 {
60 //..
61 //Init some variables
62 //..
63   if(n<0) return;
64   fPhotFlag = new Int_t[n];
65   fPhotCkov = new Double_t[n];
66   fPhotPhi  = new Double_t[n];
67   fPhotWei  = new Double_t[n];
68 //
69 }
70 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
71 void AliHMPIDRecon::DeleteVars()const
72 {
73 //..
74 //Delete variables
75 //..
76   delete fPhotFlag;
77   delete fPhotCkov;
78   delete fPhotPhi;
79   delete fPhotWei;
80 }
81 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
82 void AliHMPIDRecon::CkovAngle(AliESDtrack *pTrk,TClonesArray *pCluLst,Double_t nmean,Double_t qthre)
83 {
84 // Pattern recognition method based on Hough transform
85 // Arguments:   pTrk     - track for which Ckov angle is to be found
86 //              pCluLst  - list of clusters for this chamber   
87 //   Returns:            - track ckov angle, [rad], 
88     
89
90   const Int_t nMinPhotAcc = 3;                      // Minimum number of photons required to perform the pattern recognition
91   
92   
93   Int_t nClusTot = pCluLst->GetEntries();
94   if(nClusTot>fParam->MultCut()) fIsWEIGHT = kTRUE; // offset to take into account bkg in reconstruction
95   else                           fIsWEIGHT = kFALSE;
96
97   InitVars(nClusTot);
98   
99   Float_t xRa,yRa,th,ph;
100   pTrk->GetHMPIDtrk(xRa,yRa,th,ph);        //initialize this track: th and ph angles at middle of RAD 
101   SetTrack(xRa,yRa,th,ph);
102
103   fParam->SetRefIdx(nmean);
104
105   Float_t dMin=999,mipX=-1,mipY=-1;Int_t chId=-1,mipId=-1,mipQ=-1;
106   Int_t sizeClu = -1;
107   fPhotCnt=0;
108   for (Int_t iClu=0; iClu<pCluLst->GetEntriesFast();iClu++){//clusters loop
109     AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluLst->UncheckedAt(iClu);                       //get pointer to current cluster    
110     chId=pClu->Ch();
111     if(pClu->Q()>qthre){                                                                      //charge compartible with MIP clusters      
112       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
113       if( d < dMin) {mipId=iClu; dMin=d;mipX=pClu->X();
114                      mipY=pClu->Y();mipQ=(Int_t)pClu->Q();sizeClu=pClu->Size();}              //current cluster is closer, overwrite data for min cluster
115     }else{                                                                                    //charge compatible with photon cluster
116       Double_t thetaCer,phiCer;
117       if(FindPhotCkov(pClu->X(),pClu->Y(),thetaCer,phiCer)){                                  //find ckov angle for this  photon candidate
118         fPhotCkov[fPhotCnt]=thetaCer;                                                         //actual theta Cerenkov (in TRS)
119         fPhotPhi [fPhotCnt]=phiCer;                                                           //actual phi   Cerenkov (in TRS): -pi to come back to "unusual" ref system (X,Y,-Z)
120         //PH        Printf("photon n. %i reconstructed theta = %f",fPhotCnt,fPhotCkov[fPhotCnt]);
121         fPhotCnt++;                                                                           //increment counter of photon candidates
122       }
123     }
124   }//clusters loop
125
126   pTrk->SetHMPIDmip(mipX,mipY,mipQ,fPhotCnt);                                                //store mip info in any case 
127      
128   if(fPhotCnt<=nMinPhotAcc) {                                                                 //no reconstruction with <=3 photon candidates
129     pTrk->SetHMPIDsignal(kNoPhotAccept);                                                      //set the appropriate flag
130     pTrk->SetHMPIDcluIdx(chId,mipId+1000*sizeClu);                                            //set index of cluster
131     return;
132   }
133   
134   if(mipId==-1) {
135     pTrk->SetHMPIDcluIdx(chId,9999);                                                          //set index of cluster
136     pTrk->SetHMPIDsignal(kMipQdcCut);
137     return;
138   }                                                                                           //no clusters with QDC more the threshold at all
139     pTrk->SetHMPIDcluIdx(chId,mipId+1000*sizeClu);                                            //set chamber, index of cluster + cluster size
140     if(dMin>fParam->DistCut()) {pTrk->SetHMPIDsignal(kMipDistCut); return;}                   //closest cluster with enough charge is still too far from intersection
141   
142   fMipPos.Set(mipX,mipY);
143   
144   
145 //PATTERN RECOGNITION STARTED: 
146   
147   Int_t iNrec=FlagPhot(HoughResponse());                                                      //flag photons according to individual theta ckov with respect to most probable
148   pTrk->SetHMPIDmip(mipX,mipY,mipQ,iNrec);                                                    //store mip info 
149
150   if(iNrec<1){
151     pTrk->SetHMPIDsignal(kNoPhotAccept);                                                      //no photon candidates are accepted
152     return;
153   }
154   Double_t thetaC = FindRingCkov(pCluLst->GetEntries());                                    //find the best reconstructed theta Cherenkov
155 //    FindRingGeom(thetaC,2);
156   pTrk->SetHMPIDsignal(thetaC);                                                             //store theta Cherenkov
157   pTrk->SetHMPIDchi2(fCkovSigma2);                                                          //store errors squared
158
159   DeleteVars();
160 }//CkovAngle()
161 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
162 Bool_t AliHMPIDRecon::FindPhotCkov(Double_t cluX,Double_t cluY,Double_t &thetaCer,Double_t &phiCer)
163 {
164 // Finds Cerenkov angle  for this photon candidate
165 // Arguments: cluX,cluY - position of cadidate's cluster  
166 // Returns: Cerenkov angle 
167
168   TVector3 dirCkov;
169   
170   Double_t zRad= -0.5*fParam->RadThick()-0.5*fParam->WinThick();     //z position of middle of RAD
171   TVector3 rad(fTrkPos.X(),fTrkPos.Y(),zRad);                        //impact point at middle of RAD
172   TVector3  pc(cluX,cluY,0.5*fParam->WinThick()+fParam->GapIdx());   //mip at PC
173   Double_t cluR = TMath::Sqrt((cluX-fTrkPos.X())*(cluX-fTrkPos.X())+
174                               (cluY-fTrkPos.Y())*(cluY-fTrkPos.Y()));//ref. distance impact RAD-CLUSTER   
175   Double_t phi=(pc-rad).Phi();                                       //phi of photon
176     
177   Double_t ckov1=0;
178   Double_t ckov2=0.75+fTrkDir.Theta();                        //start to find theta cerenkov in DRS
179   const Double_t kTol=0.01;
180   Int_t iIterCnt = 0;
181   while(1){
182     if(iIterCnt>=50) return kFALSE;
183     Double_t ckov=0.5*(ckov1+ckov2);
184     dirCkov.SetMagThetaPhi(1,ckov,phi);
185     TVector2 posC=TraceForward(dirCkov);                      //trace photon with actual angles
186     Double_t dist=cluR-(posC-fTrkPos).Mod();                  //get distance between trial point and cluster position
187     if(posC.X()==-999) dist = - 999;                          //total reflection problem
188     iIterCnt++;                                               //counter step
189     if     (dist> kTol) ckov1=ckov;                           //cluster @ larger ckov
190     else if(dist<-kTol) ckov2=ckov;                           //cluster @ smaller ckov
191     else{                                                     //precision achived: ckov in DRS found
192       dirCkov.SetMagThetaPhi(1,ckov,phi);                     //
193       Lors2Trs(dirCkov,thetaCer,phiCer);                       //find ckov (in TRS:the effective Cherenkov angle!)
194       return kTRUE;
195     }
196   }
197 }//FindPhotTheta()
198 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
199 TVector2 AliHMPIDRecon::TraceForward(TVector3 dirCkov)const
200 {
201   //Trace forward a photon from (x,y) up to PC
202   // Arguments: dirCkov photon vector in LORS
203   //   Returns: pos of traced photon at PC
204   
205   TVector2 pos(-999,-999);
206   Double_t thetaCer = dirCkov.Theta();
207   if(thetaCer > TMath::ASin(1./fParam->GetRefIdx())) return pos;          //total refraction on WIN-GAP boundary
208   Double_t zRad= -0.5*fParam->RadThick()-0.5*fParam->WinThick();          //z position of middle of RAD
209   TVector3  posCkov(fTrkPos.X(),fTrkPos.Y(),zRad);                        //RAD: photon position is track position @ middle of RAD 
210   Propagate(dirCkov,posCkov,           -0.5*fParam->WinThick());          //go to RAD-WIN boundary  
211   Refract  (dirCkov,         fParam->GetRefIdx(),fParam->WinIdx());       //RAD-WIN refraction
212   Propagate(dirCkov,posCkov,            0.5*fParam->WinThick());          //go to WIN-GAP boundary
213   Refract  (dirCkov,         fParam->WinIdx(),fParam->GapIdx());          //WIN-GAP refraction
214   Propagate(dirCkov,posCkov,0.5*fParam->WinThick()+fParam->GapThick());   //go to PC
215   pos.Set(posCkov.X(),posCkov.Y());
216   return pos;
217 }//TraceForward()
218 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
219 void AliHMPIDRecon::Lors2Trs(TVector3 dirCkov,Double_t &thetaCer,Double_t &phiCer)const
220 {
221   //Theta Cerenkov reconstruction 
222   // Arguments: dirCkov photon vector in LORS
223   //   Returns: thetaCer of photon in TRS
224   //              phiCer of photon in TRS
225 //  TVector3 dirTrk;
226 //  dirTrk.SetMagThetaPhi(1,fTrkDir.Theta(),fTrkDir.Phi());
227 //  Double_t thetaCer = TMath::ACos(dirCkov*dirTrk);
228   TRotation mtheta;   mtheta.RotateY(-fTrkDir.Theta());
229   TRotation mphi;       mphi.RotateZ(-fTrkDir.Phi());
230   TRotation mrot=mtheta*mphi;
231   TVector3 dirCkovTRS;
232   dirCkovTRS=mrot*dirCkov;
233   phiCer  = dirCkovTRS.Phi();                                          //actual value of the phi of the photon
234   thetaCer= dirCkovTRS.Theta();                                        //actual value of thetaCerenkov of the photon
235 }
236 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
237 void AliHMPIDRecon::Trs2Lors(TVector3 dirCkov,Double_t &thetaCer,Double_t &phiCer)const
238 {
239   //Theta Cerenkov reconstruction 
240   // Arguments: dirCkov photon vector in TRS
241   //   Returns: thetaCer of photon in LORS
242   //              phiCer of photon in LORS
243   TRotation mtheta;   mtheta.RotateY(fTrkDir.Theta());
244   TRotation mphi;       mphi.RotateZ(fTrkDir.Phi());
245   TRotation mrot=mphi*mtheta;
246   TVector3 dirCkovLORS;
247   dirCkovLORS=mrot*dirCkov;
248   phiCer  = dirCkovLORS.Phi();                                          //actual value of the phi of the photon
249   thetaCer= dirCkovLORS.Theta();                                        //actual value of thetaCerenkov of the photon
250 }
251 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
252 void AliHMPIDRecon::FindRingGeom(Double_t ckovAng,Int_t level)
253 {
254 // Find area covered in the PC acceptance
255 // Arguments: ckovAng - cerenkov angle
256 //            level   - precision in finding area and portion of ring accepted (multiple of 50)
257 //   Returns: area of the ring in cm^2 for given theta ckov
258    
259   Int_t kN=50*level;
260   Int_t nPoints = 0;
261   Double_t area=0;
262   
263   Bool_t first=kFALSE;
264   TVector2 pos1;
265   
266   for(Int_t i=0;i<kN;i++){
267    if(!first) {
268       pos1=TracePhot(ckovAng,Double_t(TMath::TwoPi()*(i+1)/kN));                                    //find a good trace for the first photon
269      if(pos1.X()==-999) continue;                                                                   //no area: open ring                  
270      if(!fParam->IsInside(pos1.X(),pos1.Y(),0)) {
271        pos1 = IntWithEdge(fMipPos,pos1);                                                            // find the very first intersection...
272      } else {
273        if(!AliHMPIDParam::IsInDead(pos1.X(),pos1.Y())) nPoints++;                                   //photon is accepted if not in dead zone
274      }
275      first=kTRUE;
276      continue;
277    }
278    TVector2 pos2=TracePhot(ckovAng,Double_t(TMath::TwoPi()*(i+1)/kN));                              //trace the next photon
279    if(pos2.X()==-999) continue;                                                                     //no area: open ring             
280    if(!fParam->IsInside(pos2.X(),pos2.Y(),0)) {
281      pos2 = IntWithEdge(fMipPos,pos2);
282    } else {
283      if(!AliHMPIDParam::IsInDead(pos2.X(),pos2.Y())) nPoints++;                                     //photon is accepted if not in dead zone
284    }
285    area+=TMath::Abs((pos1-fMipPos).X()*(pos2-fMipPos).Y()-(pos1-fMipPos).Y()*(pos2-fMipPos).X());   //add area of the triangle...            
286    pos1 = pos2;
287   }
288 //---  find area and length of the ring;
289   fRingAcc = (Double_t)nPoints/(Double_t)kN;
290   area*=0.5;
291   fRingArea = area;
292 }//FindRingGeom()
293 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
294 TVector2 AliHMPIDRecon::IntWithEdge(TVector2 p1,TVector2 p2)const
295 {
296 // It finds the intersection of the line for 2 points traced as photons
297 // and the edge of a given PC
298 // Arguments: 2 points obtained tracing the photons
299 //   Returns: intersection point with detector (PC) edges
300
301   Double_t xmin = (p1.X()<p2.X())? p1.X():p2.X(); 
302   Double_t xmax = (p1.X()<p2.X())? p2.X():p1.X(); 
303   Double_t ymin = (p1.Y()<p2.Y())? p1.Y():p2.Y(); 
304   Double_t ymax = (p1.Y()<p2.Y())? p2.Y():p1.Y(); 
305   
306   Double_t m = TMath::Tan((p2-p1).Phi());
307   TVector2 pint;
308   //intersection with low  X
309   pint.Set((Double_t)(p1.X() + (0-p1.Y())/m),0.);
310   if(pint.X()>=0 && pint.X()<=fParam->SizeAllX() &&
311      pint.X()>=xmin && pint.X()<=xmax            &&
312      pint.Y()>=ymin && pint.Y()<=ymax) return pint;
313   //intersection with high X  
314   pint.Set((Double_t)(p1.X() + (fParam->SizeAllY()-p1.Y())/m),(Double_t)(fParam->SizeAllY()));
315   if(pint.X()>=0 && pint.X()<=fParam->SizeAllX() &&
316      pint.X()>=xmin && pint.X()<=xmax            &&
317      pint.Y()>=ymin && pint.Y()<=ymax) return pint;
318   //intersection with left Y  
319   pint.Set(0.,(Double_t)(p1.Y() + m*(0-p1.X())));
320   if(pint.Y()>=0 && pint.Y()<=fParam->SizeAllY() &&
321      pint.Y()>=ymin && pint.Y()<=ymax            &&
322      pint.X()>=xmin && pint.X()<=xmax) return pint;
323   //intersection with righ Y  
324   pint.Set((Double_t)(fParam->SizeAllX()),(Double_t)(p1.Y() + m*(fParam->SizeAllX()-p1.X())));
325   if(pint.Y()>=0 && pint.Y()<=fParam->SizeAllY() &&
326      pint.Y()>=ymin && pint.Y()<=ymax            &&
327      pint.X()>=xmin && pint.X()<=xmax) return pint;
328   return p1;
329 }//IntWithEdge()
330 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
331 Double_t AliHMPIDRecon::FindRingCkov(Int_t)
332 {
333 // 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
334 // collecting errors for all single Ckov candidates thetas. (Assuming they are independent)  
335 // Arguments: iNclus- total number of clusters in chamber for background estimation
336 //    Return: best estimation of track Theta ckov
337
338   Double_t wei = 0.;
339   Double_t weightThetaCerenkov = 0.;
340
341   Double_t ckovMin=9999.,ckovMax=0.;
342   Double_t sigma2 = 0;   //to collect error squared for this ring
343   
344   for(Int_t i=0;i<fPhotCnt;i++){//candidates loop
345     if(fPhotFlag[i] == 2){
346       if(fPhotCkov[i]<ckovMin) ckovMin=fPhotCkov[i];                         //find max and min Theta ckov from all candidates within probable window
347       if(fPhotCkov[i]>ckovMax) ckovMax=fPhotCkov[i]; 
348       weightThetaCerenkov += fPhotCkov[i]*fPhotWei[i];
349       wei += fPhotWei[i];                                                    //collect weight as sum of all candidate weghts   
350       
351       sigma2 += 1./fParam->Sigma2(fTrkDir.Theta(),fTrkDir.Phi(),fPhotCkov[i],fPhotPhi[i]);
352     }
353   }//candidates loop
354   
355   if(sigma2>0) fCkovSigma2=1./sigma2;
356   else         fCkovSigma2=1e10;  
357   
358   if(wei != 0.) weightThetaCerenkov /= wei; else weightThetaCerenkov = 0.;
359   return weightThetaCerenkov;
360 }//FindCkovRing()
361 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
362 Int_t AliHMPIDRecon::FlagPhot(Double_t ckov)
363 {
364 // Flag photon candidates if their individual ckov angle is inside the window around ckov angle returned by  HoughResponse()
365 // Arguments: ckov- value of most probable ckov angle for track as returned by HoughResponse()
366 //   Returns: number of photon candidates happened to be inside the window
367
368 // Photon Flag:  Flag = 0 initial set; 
369 //               Flag = 1 good candidate (charge compatible with photon); 
370 //               Flag = 2 photon used for the ring;
371   
372   Int_t steps = (Int_t)((ckov )/ fDTheta); //how many times we need to have fDTheta to fill the distance between 0  and thetaCkovHough
373
374   Double_t tmin = (Double_t)(steps - 1)*fDTheta;
375   Double_t tmax = (Double_t)(steps)*fDTheta;
376   Double_t tavg = 0.5*(tmin+tmax);
377
378   tmin = tavg - 0.5*fWindowWidth;  tmax = tavg + 0.5*fWindowWidth;
379
380   Int_t iInsideCnt = 0; //count photons which Theta ckov inside the window
381   for(Int_t i=0;i<fPhotCnt;i++){//photon candidates loop
382     fPhotFlag[i] = 0;
383     if(fPhotCkov[i] >= tmin && fPhotCkov[i] <= tmax)    { 
384       fPhotFlag[i]=2;     
385       iInsideCnt++;
386     }
387   }
388   return iInsideCnt;
389 }//FlagPhot()
390 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
391 TVector2 AliHMPIDRecon::TracePhot(Double_t ckovThe,Double_t ckovPhi)const
392 {
393 // Trace a single Ckov photon from emission point somewhere in radiator up to photocathode taking into account ref indexes of materials it travereses
394 // Arguments: ckovThe,ckovPhi- photon ckov angles in TRS, [rad]
395 //   Returns: distance between photon point on PC and track projection  
396   
397   Double_t theta,phi;
398   TVector3  dirTRS,dirLORS;   
399   dirTRS.SetMagThetaPhi(1,ckovThe,ckovPhi);                     //photon in TRS
400   Trs2Lors(dirTRS,theta,phi);
401   dirLORS.SetMagThetaPhi(1,theta,phi);                          //photon in LORS
402   return TraceForward(dirLORS);                                 //now foward tracing
403 }//TracePhot()
404 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
405 void AliHMPIDRecon::Propagate(const TVector3 dir,TVector3 &pos,Double_t z)const
406 {
407 // Finds an intersection point between a line and XY plane shifted along Z.
408 // Arguments:  dir,pos   - vector along the line and any point of the line
409 //             z         - z coordinate of plain 
410 //   Returns:  none
411 //   On exit:  pos is the position if this intesection if any
412   static TVector3 nrm(0,0,1); 
413          TVector3 pnt(0,0,z);
414   
415   TVector3 diff=pnt-pos;
416   Double_t sint=(nrm*diff)/(nrm*dir);
417   pos+=sint*dir;
418 }//Propagate()
419 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
420 void AliHMPIDRecon::Refract(TVector3 &dir,Double_t n1,Double_t n2)const
421 {
422 // Refract direction vector according to Snell law
423 // Arguments: 
424 //            n1 - ref idx of first substance
425 //            n2 - ref idx of second substance
426 //   Returns: none
427 //   On exit: dir is new direction
428   Double_t sinref=(n1/n2)*TMath::Sin(dir.Theta());
429   if(TMath::Abs(sinref)>1.) dir.SetXYZ(-999,-999,-999);
430   else             dir.SetTheta(TMath::ASin(sinref));
431 }//Refract()
432 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
433 Double_t AliHMPIDRecon::HoughResponse()
434 {
435 //
436 //    fIdxMip = mipId;
437
438 //       
439   Double_t kThetaMax=0.75;
440   Int_t nChannels = (Int_t)(kThetaMax/fDTheta+0.5);
441   TH1D *phots   = new TH1D("Rphot"  ,"phots"         ,nChannels,0,kThetaMax);
442   TH1D *photsw  = new TH1D("RphotWeighted" ,"photsw" ,nChannels,0,kThetaMax);
443   TH1D *resultw = new TH1D("resultw","resultw"       ,nChannels,0,kThetaMax);
444   Int_t nBin = (Int_t)(kThetaMax/fDTheta);
445   Int_t nCorrBand = (Int_t)(fWindowWidth/(2*fDTheta));
446   
447   for (Int_t i=0; i< fPhotCnt; i++){//photon cadidates loop
448     Double_t angle = fPhotCkov[i];  if(angle<0||angle>kThetaMax) continue;
449     phots->Fill(angle);
450     Int_t bin = (Int_t)(0.5+angle/(fDTheta));
451     Double_t weight=1.;
452     if(fIsWEIGHT){
453       Double_t lowerlimit = ((Double_t)bin)*fDTheta - 0.5*fDTheta;  Double_t upperlimit = ((Double_t)bin)*fDTheta + 0.5*fDTheta;
454       FindRingGeom(lowerlimit);
455       Double_t areaLow  = GetRingArea();
456       FindRingGeom(upperlimit);
457       Double_t areaHigh = GetRingArea();
458       Double_t diffArea = areaHigh - areaLow;
459       if(diffArea>0) weight = 1./diffArea;
460     }
461     photsw->Fill(angle,weight);
462     fPhotWei[i]=weight;
463   }//photon candidates loop 
464    
465   for (Int_t i=1; i<=nBin;i++){
466     Int_t bin1= i-nCorrBand;
467     Int_t bin2= i+nCorrBand;
468     if(bin1<1) bin1=1;
469     if(bin2>nBin)bin2=nBin;
470     Double_t sumPhots=phots->Integral(bin1,bin2);
471     if(sumPhots<3) continue;                            // if less then 3 photons don't trust to this ring
472     Double_t sumPhotsw=photsw->Integral(bin1,bin2);
473     resultw->Fill((Double_t)((i+0.5)*fDTheta),sumPhotsw);
474   } 
475 // evaluate the "BEST" theta ckov as the maximum value of histogramm
476   Double_t *pVec = resultw->GetArray();
477   Int_t locMax = TMath::LocMax(nBin,pVec);
478   delete phots;delete photsw;delete resultw; // Reset and delete objects
479   
480   return (Double_t)(locMax*fDTheta+0.5*fDTheta); //final most probable track theta ckov   
481 }//HoughResponse()
482 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++