1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //////////////////////////////////////////////////////////////////////////
20 // RICH class to perfom pattern recognition based on Hough transfrom //
21 // for single chamber //
22 //////////////////////////////////////////////////////////////////////////
24 #include "AliRICHRecon.h" //class header
25 #include "AliRICHCluster.h" //CkovAngle()
26 #include <AliLog.h> //AliInfo()
27 #include <TMath.h> //many
28 #include <TRotation.h> //
29 #include <TH1D.h> //HoughResponse()
30 #include <TClonesArray.h> //CkovAngle()
32 const Double_t AliRICHRecon::fkRadThick=1.5;
33 const Double_t AliRICHRecon::fkWinThick=0.5;
34 const Double_t AliRICHRecon::fkGapThick=8.0;
35 const Double_t AliRICHRecon::fkRadIdx =1.292;
36 const Double_t AliRICHRecon::fkWinIdx =1.5787;
37 const Double_t AliRICHRecon::fkGapIdx =1.0005;
40 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 AliRICHRecon::AliRICHRecon():TTask("RichRec","RichPat"),
47 fTrkDir(TVector3(0,0,1)),fTrkPos(TVector2(30,40))
50 for (Int_t i=0; i<3000; i++) {
57 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
58 Double_t AliRICHRecon::CkovAngle(TClonesArray *pCluLst,Int_t &iNaccepted)
60 // Pattern recognition method based on Hough transform
61 // Arguments: pCluLst - list of clusters for this chamber
62 // Returns: - track ckov angle, [rad],
64 if(pCluLst->GetEntries()>200) fIsWEIGHT = kTRUE; // offset to take into account bkg in reconstruction
65 else fIsWEIGHT = kFALSE;
67 // Photon Flag: Flag = 0 initial set; Flag = 1 good candidate (charge compatible with photon); Flag = 2 photon used for the ring;
70 for (Int_t iClu=0; iClu<pCluLst->GetEntriesFast();iClu++){//clusters loop
71 AliRICHCluster *pClu=(AliRICHCluster*)pCluLst->UncheckedAt(iClu); //get pointer to current cluster
72 if(pClu->Q()>100) continue; //avoid MIP clusters from bkg
74 fPhotCkov[fPhotCnt]=FindPhotCkov(pClu->X(),pClu->Y()); //find ckov angle for this photon candidate
75 fPhotCnt++; //increment counter of photon candidates
78 iNaccepted=FlagPhot(HoughResponse()); //flag photons according to individual theta ckov with respect to most probable track theta ckov
79 if(iNaccepted<1) return -11;
80 else return FindRingCkov(pCluLst->GetEntries()); //find best Theta ckov for ring i.e. track
82 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
83 Double_t AliRICHRecon::FindPhotCkov(Double_t cluX,Double_t cluY)
85 // Finds Cerenkov angle for this photon candidate
86 // Arguments: cluX,cluY - position of cadidate's cluster
87 // Returns: Cerenkov angle
89 TVector2 pos(cluX,cluY); Double_t cluR=(pos-fTrkPos).Mod(); Double_t phi=FindPhotPhi(cluX,cluY);
90 Printf("new dist %f phi %f",cluR,phi);
91 Double_t ckov1=0,ckov2=0.75;
92 const Double_t kTol=0.05;
95 if(iIterCnt>=50) return -1;
96 Double_t ckov=0.5*(ckov1+ckov2);
97 Double_t dist=cluR-TracePhoton(ckov,phi,pos); iIterCnt++; //get distance between trial point and cluster position
98 Printf("New: phi %f ckov %f dist %f",phi,ckov,dist);
99 if (dist> kTol) ckov1=ckov; //cluster @ larger ckov
100 else if(dist<-kTol) ckov2=ckov; //cluster @ smaller ckov
101 else return ckov; //precision achived
104 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
105 Double_t AliRICHRecon::FindPhotPhi(Double_t cluX,Double_t cluY)
107 // Finds phi angle og photon candidate by considering the cluster's position of this candudate w.r.t track position
110 return fPhotPhi[fPhotCnt]=TMath::ATan2(cluY-fTrkPos.Y()-emiss*TMath::Tan(fTrkDir.Theta())*TMath::Sin(fTrkDir.Phi()),
111 cluX-fTrkPos.X()-emiss*TMath::Tan(fTrkDir.Theta())*TMath::Cos(fTrkDir.Phi()));
113 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
114 Double_t AliRICHRecon::FindRingArea(Double_t ckovAng)const
116 // Find area inside the cerenkov ring which lays inside PCs
117 // Arguments: ckovThe - cernkov
118 // Returns: area of the ring in cm^2 for given theta ckov
125 for(Int_t i=0;i<kN;i++){
126 TracePhoton(ckovAng,Double_t(TMath::TwoPi()*i /kN),pos1);//trace this photon
127 TracePhoton(ckovAng,Double_t(TMath::TwoPi()*(i+1)/kN),pos2);//trace this photon
128 area+=(pos1-fTrkPos)*(pos2-fTrkPos);
133 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
134 Double_t AliRICHRecon::TracePhoton(Double_t ckovThe,Double_t ckovPhi,TVector2 &pos)const
136 // Trace a single Ckov photon from emission point somewhere in radiator up to photocathode taking into account ref indexes of materials it travereses
137 // Arguments: ckovThe,ckovPhi- photon ckov angles, [rad] (warning: not photon theta and phi)
138 // Returns: distance between photon point on PC and track projection
139 TRotation mtheta; mtheta.RotateY(fTrkDir.Theta());
140 TRotation mphi; mphi.RotateZ(fTrkDir.Phi());
141 TRotation mrot=mphi*mtheta;
143 TVector3 posCkov(fTrkPos.X(),fTrkPos.Y(),-0.5*fkRadThick-fkWinThick-fkGapThick); //RAD: photon position is track position @ middle of RAD
144 TVector3 dirCkov; dirCkov.SetMagThetaPhi(1,ckovThe,ckovPhi); //initially photon is directed according to requested ckov angle
145 dirCkov=mrot*dirCkov; //now we know photon direction in LORS
146 dirCkov.SetPhi(ckovPhi);
147 if(dirCkov.Theta() > TMath::ASin(1./fkRadIdx)) return -999;//total refraction on WIN-GAP boundary
149 Propagate(dirCkov,posCkov,-fkWinThick-fkGapThick); //go to RAD-WIN boundary remeber that z=0 is PC plane
150 Refract (dirCkov, fkRadIdx,fkWinIdx ); //RAD-WIN refraction
151 Propagate(dirCkov,posCkov,-fkGapThick ); //go to WIN-GAP boundary
152 Refract (dirCkov, fkWinIdx,fkGapIdx ); //WIN-GAP refraction
153 Propagate(dirCkov,posCkov,0 ); //go to PC
155 pos.Set(posCkov.X(),posCkov.Y());
156 return (pos-fTrkPos).Mod();
158 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
159 void AliRICHRecon::Propagate(const TVector3 &dir,TVector3 &pos,Double_t z)const
161 // Finds an intersection point between a line and XY plane shifted along Z.
162 // Arguments: dir,pos - vector along the line and any point of the line
163 // z - z coordinate of plain
165 // On exit: pos is the position if this intesection if any
166 static TVector3 nrm(0,0,1);
169 TVector3 diff=pnt-pos;
170 Double_t sint=(nrm*diff)/(nrm*dir);
173 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
174 void AliRICHRecon::Refract(TVector3 &dir,Double_t n1,Double_t n2)const
176 // Refract direction vector according to Snell law
178 // n1 - ref idx of first substance
179 // n2 - ref idx of second substance
181 // On exit: dir is new direction
182 Double_t sinref=(n1/n2)*TMath::Sin(dir.Theta());
183 if(sinref>1.) dir.SetXYZ(-999,-999,-999);
184 else dir.SetTheta(TMath::ASin(sinref));
186 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
187 Double_t AliRICHRecon::HoughResponse()
192 Double_t kThetaMax=0.75;
193 Int_t nChannels = (Int_t)(kThetaMax/fDTheta+0.5);
194 TH1D *phots = new TH1D("Rphot" ,"phots" ,nChannels,0,kThetaMax);
195 TH1D *photsw = new TH1D("RphotWeighted" ,"photsw" ,nChannels,0,kThetaMax);
196 TH1D *resultw = new TH1D("resultw","resultw" ,nChannels,0,kThetaMax);
197 Int_t nBin = (Int_t)(kThetaMax/fDTheta);
198 Int_t nCorrBand = (Int_t)(fWindowWidth/(2*fDTheta));
200 for (Int_t i=0; i< fPhotCnt; i++){//photon cadidates loop
201 Double_t angle = fPhotCkov[i]; if(angle<0||angle>kThetaMax) continue;
203 Int_t bin = (Int_t)(0.5+angle/(fDTheta));
206 Double_t lowerlimit = ((Double_t)bin)*fDTheta - 0.5*fDTheta; Double_t upperlimit = ((Double_t)bin)*fDTheta + 0.5*fDTheta;
207 Double_t diffArea = FindRingArea(upperlimit)-FindRingArea(lowerlimit);
208 if(diffArea>0) weight = 1./diffArea;
210 photsw->Fill(angle,weight);
212 }//photon candidates loop
214 for (Int_t i=1; i<=nBin;i++){
215 Int_t bin1= i-nCorrBand;
216 Int_t bin2= i+nCorrBand;
218 if(bin2>nBin)bin2=nBin;
219 Double_t sumPhots=phots->Integral(bin1,bin2);
220 if(sumPhots<3) continue; // if less then 3 photons don't trust to this ring
221 Double_t sumPhotsw=photsw->Integral(bin1,bin2);
222 resultw->Fill((Double_t)((i+0.5)*fDTheta),sumPhotsw);
224 // evaluate the "BEST" theta ckov as the maximum value of histogramm
225 Double_t *pVec = resultw->GetArray();
226 Int_t locMax = TMath::LocMax(nBin,pVec);
227 phots->Delete();photsw->Delete();resultw->Delete(); // Reset and delete objects
229 return (Double_t)(locMax*fDTheta+0.5*fDTheta); //final most probable track theta ckov
231 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
232 Double_t AliRICHRecon::FindRingCkov(Int_t)
234 // 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
235 // collecting errors for all single Ckov candidates thetas. (Assuming they are independent)
236 // Arguments: iNclus- total number of clusters in chamber for background estimation
237 // Return: best estimation of track Theta ckov
240 Double_t weightThetaCerenkov = 0.;
242 Double_t ckovMin=9999.,ckovMax=0.;
243 Double_t sigma2 = 0; //to collect error squared for this ring
245 for(Int_t i=0;i<fPhotCnt;i++){//candidates loop
246 if(fPhotFlag[i] == 2){
247 if(fPhotCkov[i]<ckovMin) ckovMin=fPhotCkov[i]; //find max and min Theta ckov from all candidates within probable window
248 if(fPhotCkov[i]>ckovMax) ckovMax=fPhotCkov[i];
249 weightThetaCerenkov += fPhotCkov[i]*fPhotWei[i]; wei += fPhotWei[i]; //collect weight as sum of all candidate weghts
251 //Double_t phiref=(GetPhiPoint()-GetTrackPhi());
252 if(fPhotCkov[i]<=0) continue;//?????????????????Flag photos = 2 may imply CkovEta = 0??????????????
254 sigma2 += 1./Sigma2(fPhotCkov[i],fPhotPhi[i],fTrkDir.Theta(),fTrkDir.Phi());
258 if(sigma2>0) fCkovSigma2=1./sigma2;
259 else fCkovSigma2=1e10;
262 if(wei != 0.) weightThetaCerenkov /= wei; else weightThetaCerenkov = 0.;
263 return weightThetaCerenkov;
265 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
266 Int_t AliRICHRecon::FlagPhot(Double_t ckov)
268 // Flag photon candidates if their individual ckov angle is inside the window around ckov angle returned by HoughResponse()
269 // Arguments: ckov- value of most probable ckov angle for track as returned by HoughResponse()
270 // Returns: number of photon candidates happened to be inside the window
273 Int_t steps = (Int_t)((ckov )/ fDTheta); //how many times we need to have fDTheta to fill the distance between 0 and thetaCkovHough
275 Double_t tmin = (Double_t)(steps - 1)*fDTheta;
276 Double_t tmax = (Double_t)(steps)*fDTheta;
277 Double_t tavg = 0.5*(tmin+tmax);
279 tmin = tavg - 0.5*fWindowWidth; tmax = tavg + 0.5*fWindowWidth;
281 Int_t iInsideCnt = 0; //count photons which Theta ckov inside the window
282 for(Int_t i=0;i<fPhotCnt;i++){//photon candidates loop
283 if(fPhotCkov[i] >= tmin && fPhotCkov[i] <= tmax) {
290 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
291 Double_t AliRICHRecon::Sigma2(Double_t ckovTh, Double_t ckovPh, Double_t trkTh, Double_t trkPh)const
293 // Analithical calculation of total error (as a sum of localization, geometrical and chromatic errors) on Cerenkov angle for a given Cerenkov photon
294 // created by a given MIP. Fromulae according to CERN-EP-2000-058
295 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
296 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
298 // Returns: absolute error on Cerenkov angle, [radians]
300 TVector3 v(-999,-999,-999);
301 Double_t trkBeta = 1./(TMath::Cos(ckovTh)*fkRadIdx);
303 v.SetX(SigLoc (ckovTh,ckovPh,trkTh,trkPh,trkBeta));
304 v.SetY(SigGeom(ckovTh,ckovPh,trkTh,trkPh,trkBeta));
305 v.SetZ(SigCrom(ckovTh,ckovPh,trkTh,trkPh,trkBeta));
309 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
310 Double_t AliRICHRecon::SigLoc(Double_t thetaC, Double_t phiC, Double_t thetaM, Double_t phiM, Double_t betaM)const
312 // Analithical calculation of localization error (due to finite segmentation of PC) on Cerenkov angle for a given Cerenkov photon
313 // created by a given MIP. Fromulae according to CERN-EP-2000-058
314 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
315 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
317 // Returns: absolute error on Cerenkov angle, [radians]
318 Double_t phiDelta = phiC - phiM;
320 Double_t alpha =TMath::Cos(thetaM)-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(thetaM);
321 Double_t k = 1.-fkRadIdx*fkRadIdx+alpha*alpha/(betaM*betaM);
322 if (k<0) return 1e10;
324 Double_t mu =TMath::Sin(thetaM)*TMath::Sin(phiM)+TMath::Tan(thetaC)*(TMath::Cos(thetaM)*TMath::Cos(phiDelta)*TMath::Sin(phiM)+TMath::Sin(phiDelta)*TMath::Cos(phiM));
325 Double_t e =TMath::Sin(thetaM)*TMath::Cos(phiM)+TMath::Tan(thetaC)*(TMath::Cos(thetaM)*TMath::Cos(phiDelta)*TMath::Cos(phiM)-TMath::Sin(phiDelta)*TMath::Sin(phiM));
327 Double_t kk = betaM*TMath::Sqrt(k)/(8*alpha);
328 Double_t dtdxc = kk*(k*(TMath::Cos(phiDelta)*TMath::Cos(phiM)-TMath::Cos(thetaM)*TMath::Sin(phiDelta)*TMath::Sin(phiM))-(alpha*mu/(betaM*betaM))*TMath::Sin(thetaM)*TMath::Sin(phiDelta));
329 Double_t dtdyc = kk*(k*(TMath::Cos(phiDelta)*TMath::Sin(phiM)+TMath::Cos(thetaM)*TMath::Sin(phiDelta)*TMath::Cos(phiM))+(alpha* e/(betaM*betaM))*TMath::Sin(thetaM)*TMath::Sin(phiDelta));
331 return TMath::Sqrt(0.2*0.2*dtdxc*dtdxc + 0.25*0.25*dtdyc*dtdyc);
333 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
334 Double_t AliRICHRecon::SigCrom(Double_t thetaC, Double_t phiC, Double_t thetaM, Double_t phiM, Double_t betaM)const
336 // Analithical calculation of chromatic error (due to lack of knowledge of Cerenkov photon energy) on Cerenkov angle for a given Cerenkov photon
337 // created by a given MIP. Fromulae according to CERN-EP-2000-058
338 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
339 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
341 // Returns: absolute error on Cerenkov angle, [radians]
342 Double_t phiDelta = phiC - phiM;
343 Double_t alpha =TMath::Cos(thetaM)-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(thetaM);
345 Double_t dtdn = TMath::Cos(thetaM)*fkRadIdx*betaM*betaM/(alpha*TMath::Tan(thetaC));
347 Double_t f = 0.00928*(7.75-5.635)/TMath::Sqrt(12.);
351 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
352 Double_t AliRICHRecon::SigGeom(Double_t thetaC, Double_t phiC, Double_t thetaM, Double_t phiM, Double_t betaM)const
354 // Analithical calculation of geometric error (due to lack of knowledge of creation point in radiator) on Cerenkov angle for a given Cerenkov photon
355 // created by a given MIP. Formulae according to CERN-EP-2000-058
356 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
357 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
359 // Returns: absolute error on Cerenkov angle, [radians]
361 Double_t phiDelta = phiC - phiM;
362 Double_t alpha =TMath::Cos(thetaM)-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(thetaM);
364 Double_t k = 1.-fkRadIdx*fkRadIdx+alpha*alpha/(betaM*betaM);
365 if (k<0) return 1e10;
367 Double_t eTr = 0.5*1.5*betaM*TMath::Sqrt(k)/(8*alpha);
368 Double_t lambda = 1.-TMath::Sin(thetaM)*TMath::Sin(thetaM)*TMath::Sin(phiC)*TMath::Sin(phiC);
370 Double_t c = 1./(1.+ eTr*k/(alpha*alpha*TMath::Cos(thetaC)*TMath::Cos(thetaC)));
371 Double_t i = betaM*TMath::Tan(thetaC)*lambda*TMath::Power(k,1.5);
372 Double_t ii = 1.+eTr*betaM*i;
374 Double_t err = c * (i/(alpha*alpha*8) + ii*(1.-lambda) / ( alpha*alpha*8*betaM*(1.+eTr)) );
375 Double_t trErr = 1.5/(TMath::Sqrt(12.)*TMath::Cos(thetaM));
379 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++