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 // HMPID class to perfom pattern recognition based on Hough transfrom //
21 // for single chamber //
22 //////////////////////////////////////////////////////////////////////////
24 #include "AliHMPIDRecon.h" //class header
25 #include "AliHMPIDCluster.h" //CkovAngle()
26 #include <TRotation.h> //TracePhoton()
27 #include <TH1D.h> //HoughResponse()
28 #include <TClonesArray.h> //CkovAngle()
29 #include <AliESDtrack.h> //CkovAngle()
31 const Double_t AliHMPIDRecon::fgkRadThick=1.5;
32 const Double_t AliHMPIDRecon::fgkWinThick=0.5;
33 const Double_t AliHMPIDRecon::fgkGapThick=8.0;
34 const Double_t AliHMPIDRecon::fgkRadIdx =1.292;
35 const Double_t AliHMPIDRecon::fgkWinIdx =1.5787;
36 const Double_t AliHMPIDRecon::fgkGapIdx =1.0005;
39 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40 AliHMPIDRecon::AliHMPIDRecon():TTask("RichRec","RichPat"),
46 fTrkDir(TVector3(0,0,1)),fTrkPos(TVector2(30,40))
49 for (Int_t i=0; i<3000; i++) {
56 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57 void AliHMPIDRecon::CkovAngle(AliESDtrack *pTrk,TClonesArray *pCluLst)
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],
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;
68 Float_t xPc,yPc,th,ph; pTrk->GetHMPIDtrk(xPc,yPc,th,ph); SetTrack(xPc,yPc,th,ph); //initialize this track
72 Float_t dMin=999,mipX=-1,mipY=-1;Int_t chId=-1,mipId=-1,mipQ=-1;
74 for (Int_t iClu=0; iClu<pCluLst->GetEntriesFast();iClu++){//clusters loop
75 AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluLst->UncheckedAt(iClu); //get pointer to current cluster
77 if(pClu->Q()>100){ //charge compartible with MIP clusters
78 Float_t dX=xPc-pClu->X(),dY=yPc-pClu->Y(),d =TMath::Sqrt(dX*dX+dY*dY); //distance between current cluster and intersection point
79 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
80 }else{ //charge compartible with photon cluster
81 fPhotCkov[fPhotCnt]=FindPhotCkov(pClu->X(),pClu->Y()); //find ckov angle for this photon candidate
82 fPhotCnt++; //increment counter of photon candidates
85 Int_t iNacc=FlagPhot(HoughResponse()); //flag photons according to individual theta ckov with respect to most probable
87 pTrk->SetHMPIDmip (mipX,mipY,mipQ,iNacc); //store mip info
89 if(mipId==-1) {pTrk->SetHMPIDsignal (kMipQdcCut); return;} //no clusters with QDC more the threshold at all
90 if(dMin>1) {pTrk->SetHMPIDsignal (kMipDistCut); return;} //closest cluster with enough charge is still too far from intersection
91 pTrk->SetHMPIDcluIdx(chId,mipId);
92 if(iNacc<1) pTrk->SetHMPIDsignal(kNoPhotAccept); //no photon candidates is accepted
93 else pTrk->SetHMPIDsignal(FindRingCkov(pCluLst->GetEntries())); //find best Theta ckov for ring i.e. track
95 pTrk->SetHMPIDchi2(fCkovSigma2); //error squared
98 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99 Double_t AliHMPIDRecon::FindPhotCkov(Double_t cluX,Double_t cluY)
101 // Finds Cerenkov angle for this photon candidate
102 // Arguments: cluX,cluY - position of cadidate's cluster
103 // Returns: Cerenkov angle
105 TVector2 pos(cluX,cluY); Double_t cluR=(pos-fTrkPos).Mod(); Double_t phi=FindPhotPhi(cluX,cluY);
106 Double_t ckov1=0,ckov2=0.75;
107 const Double_t kTol=0.05;
110 if(iIterCnt>=50) return -1;
111 Double_t ckov=0.5*(ckov1+ckov2);
112 Double_t dist=cluR-TracePhot(ckov,phi,pos); iIterCnt++; //get distance between trial point and cluster position
113 if (dist> kTol) ckov1=ckov; //cluster @ larger ckov
114 else if(dist<-kTol) ckov2=ckov; //cluster @ smaller ckov
115 else return ckov; //precision achived
118 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
119 Double_t AliHMPIDRecon::FindPhotPhi(Double_t cluX,Double_t cluY)
121 // Finds phi angle og photon candidate by considering the cluster's position of this candudate w.r.t track position
124 return fPhotPhi[fPhotCnt]=TMath::ATan2(cluY-fTrkPos.Y()-emiss*TMath::Tan(fTrkDir.Theta())*TMath::Sin(fTrkDir.Phi()),
125 cluX-fTrkPos.X()-emiss*TMath::Tan(fTrkDir.Theta())*TMath::Cos(fTrkDir.Phi()));
127 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
128 Double_t AliHMPIDRecon::FindRingArea(Double_t ckovAng)const
130 // Find area inside the cerenkov ring which lays inside PCs
131 // Arguments: ckovThe - cernkov
132 // Returns: area of the ring in cm^2 for given theta ckov
139 for(Int_t i=0;i<kN;i++){
140 TracePhot(ckovAng,Double_t(TMath::TwoPi()*i /kN),pos1);//trace this photon
141 TracePhot(ckovAng,Double_t(TMath::TwoPi()*(i+1)/kN),pos2);//trace this photon
142 area+=(pos1-fTrkPos)*(pos2-fTrkPos);
147 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
148 Double_t AliHMPIDRecon::FindRingCkov(Int_t)
150 // 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
151 // collecting errors for all single Ckov candidates thetas. (Assuming they are independent)
152 // Arguments: iNclus- total number of clusters in chamber for background estimation
153 // Return: best estimation of track Theta ckov
156 Double_t weightThetaCerenkov = 0.;
158 Double_t ckovMin=9999.,ckovMax=0.;
159 Double_t sigma2 = 0; //to collect error squared for this ring
161 for(Int_t i=0;i<fPhotCnt;i++){//candidates loop
162 if(fPhotFlag[i] == 2){
163 if(fPhotCkov[i]<=0) continue;//?????????????????Flag photos = 2 may imply CkovEta = 0??????????????
164 if(fPhotCkov[i]<ckovMin) ckovMin=fPhotCkov[i]; //find max and min Theta ckov from all candidates within probable window
165 if(fPhotCkov[i]>ckovMax) ckovMax=fPhotCkov[i];
166 weightThetaCerenkov += fPhotCkov[i]*fPhotWei[i]; wei += fPhotWei[i]; //collect weight as sum of all candidate weghts
168 sigma2 += 1./Sigma2(fPhotCkov[i],fPhotPhi[i]);
172 if(sigma2>0) fCkovSigma2=1./sigma2;
173 else fCkovSigma2=1e10;
175 if(wei != 0.) weightThetaCerenkov /= wei; else weightThetaCerenkov = 0.;
176 return weightThetaCerenkov;
178 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
179 Int_t AliHMPIDRecon::FlagPhot(Double_t ckov)
181 // Flag photon candidates if their individual ckov angle is inside the window around ckov angle returned by HoughResponse()
182 // Arguments: ckov- value of most probable ckov angle for track as returned by HoughResponse()
183 // Returns: number of photon candidates happened to be inside the window
186 Int_t steps = (Int_t)((ckov )/ fDTheta); //how many times we need to have fDTheta to fill the distance between 0 and thetaCkovHough
188 Double_t tmin = (Double_t)(steps - 1)*fDTheta;
189 Double_t tmax = (Double_t)(steps)*fDTheta;
190 Double_t tavg = 0.5*(tmin+tmax);
192 tmin = tavg - 0.5*fWindowWidth; tmax = tavg + 0.5*fWindowWidth;
194 Int_t iInsideCnt = 0; //count photons which Theta ckov inside the window
195 for(Int_t i=0;i<fPhotCnt;i++){//photon candidates loop
196 if(fPhotCkov[i] >= tmin && fPhotCkov[i] <= tmax) {
203 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
204 Double_t AliHMPIDRecon::TracePhot(Double_t ckovThe,Double_t ckovPhi,TVector2 &pos)const
206 // Trace a single Ckov photon from emission point somewhere in radiator up to photocathode taking into account ref indexes of materials it travereses
207 // Arguments: ckovThe,ckovPhi- photon ckov angles, [rad] (warning: not photon theta and phi)
208 // Returns: distance between photon point on PC and track projection
209 TRotation mtheta; mtheta.RotateY(fTrkDir.Theta());
210 TRotation mphi; mphi.RotateZ(fTrkDir.Phi());
211 TRotation mrot=mphi*mtheta;
213 TVector3 posCkov(fTrkPos.X(),fTrkPos.Y(),-0.5*fgkRadThick-fgkWinThick-fgkGapThick); //RAD: photon position is track position @ middle of RAD
214 TVector3 dirCkov; dirCkov.SetMagThetaPhi(1,ckovThe,ckovPhi); //initially photon is directed according to requested ckov angle
215 dirCkov=mrot*dirCkov; //now we know photon direction in LORS
216 dirCkov.SetPhi(ckovPhi);
217 if(dirCkov.Theta() > TMath::ASin(1./fgkRadIdx)) return -999;//total refraction on WIN-GAP boundary
219 Propagate(dirCkov,posCkov,-fgkWinThick-fgkGapThick); //go to RAD-WIN boundary remeber that z=0 is PC plane
220 Refract (dirCkov, fgkRadIdx,fgkWinIdx ); //RAD-WIN refraction
221 Propagate(dirCkov,posCkov,-fgkGapThick ); //go to WIN-GAP boundary
222 Refract (dirCkov, fgkWinIdx,fgkGapIdx ); //WIN-GAP refraction
223 Propagate(dirCkov,posCkov,0 ); //go to PC
225 pos.Set(posCkov.X(),posCkov.Y());
226 return (pos-fTrkPos).Mod();
228 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
229 void AliHMPIDRecon::Propagate(const TVector3 &dir,TVector3 &pos,Double_t z)const
231 // Finds an intersection point between a line and XY plane shifted along Z.
232 // Arguments: dir,pos - vector along the line and any point of the line
233 // z - z coordinate of plain
235 // On exit: pos is the position if this intesection if any
236 static TVector3 nrm(0,0,1);
239 TVector3 diff=pnt-pos;
240 Double_t sint=(nrm*diff)/(nrm*dir);
243 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
244 void AliHMPIDRecon::Refract(TVector3 &dir,Double_t n1,Double_t n2)const
246 // Refract direction vector according to Snell law
248 // n1 - ref idx of first substance
249 // n2 - ref idx of second substance
251 // On exit: dir is new direction
252 Double_t sinref=(n1/n2)*TMath::Sin(dir.Theta());
253 if(sinref>1.) dir.SetXYZ(-999,-999,-999);
254 else dir.SetTheta(TMath::ASin(sinref));
256 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
257 Double_t AliHMPIDRecon::HoughResponse()
262 Double_t kThetaMax=0.75;
263 Int_t nChannels = (Int_t)(kThetaMax/fDTheta+0.5);
264 TH1D *phots = new TH1D("Rphot" ,"phots" ,nChannels,0,kThetaMax);
265 TH1D *photsw = new TH1D("RphotWeighted" ,"photsw" ,nChannels,0,kThetaMax);
266 TH1D *resultw = new TH1D("resultw","resultw" ,nChannels,0,kThetaMax);
267 Int_t nBin = (Int_t)(kThetaMax/fDTheta);
268 Int_t nCorrBand = (Int_t)(fWindowWidth/(2*fDTheta));
270 for (Int_t i=0; i< fPhotCnt; i++){//photon cadidates loop
271 Double_t angle = fPhotCkov[i]; if(angle<0||angle>kThetaMax) continue;
273 Int_t bin = (Int_t)(0.5+angle/(fDTheta));
276 Double_t lowerlimit = ((Double_t)bin)*fDTheta - 0.5*fDTheta; Double_t upperlimit = ((Double_t)bin)*fDTheta + 0.5*fDTheta;
277 Double_t diffArea = FindRingArea(upperlimit)-FindRingArea(lowerlimit);
278 if(diffArea>0) weight = 1./diffArea;
280 photsw->Fill(angle,weight);
282 }//photon candidates loop
284 for (Int_t i=1; i<=nBin;i++){
285 Int_t bin1= i-nCorrBand;
286 Int_t bin2= i+nCorrBand;
288 if(bin2>nBin)bin2=nBin;
289 Double_t sumPhots=phots->Integral(bin1,bin2);
290 if(sumPhots<3) continue; // if less then 3 photons don't trust to this ring
291 Double_t sumPhotsw=photsw->Integral(bin1,bin2);
292 resultw->Fill((Double_t)((i+0.5)*fDTheta),sumPhotsw);
294 // evaluate the "BEST" theta ckov as the maximum value of histogramm
295 Double_t *pVec = resultw->GetArray();
296 Int_t locMax = TMath::LocMax(nBin,pVec);
297 phots->Delete();photsw->Delete();resultw->Delete(); // Reset and delete objects
299 return (Double_t)(locMax*fDTheta+0.5*fDTheta); //final most probable track theta ckov
301 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
302 Double_t AliHMPIDRecon::Sigma2(Double_t ckovTh, Double_t ckovPh)const
304 // Analithical calculation of total error (as a sum of localization, geometrical and chromatic errors) on Cerenkov angle for a given Cerenkov photon
305 // created by a given MIP. Fromulae according to CERN-EP-2000-058
306 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
307 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
309 // Returns: absolute error on Cerenkov angle, [radians]
311 TVector3 v(-999,-999,-999);
312 Double_t trkBeta = 1./(TMath::Cos(ckovTh)*fgkRadIdx);
314 v.SetX(SigLoc (ckovTh,ckovPh,trkBeta));
315 v.SetY(SigGeom(ckovTh,ckovPh,trkBeta));
316 v.SetZ(SigCrom(ckovTh,ckovPh,trkBeta));
320 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
321 Double_t AliHMPIDRecon::SigLoc(Double_t thetaC, Double_t phiC,Double_t betaM)const
323 // Analithical calculation of localization error (due to finite segmentation of PC) on Cerenkov angle for a given Cerenkov photon
324 // created by a given MIP. Fromulae according to CERN-EP-2000-058
325 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
326 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
328 // Returns: absolute error on Cerenkov angle, [radians]
329 Double_t phiDelta = phiC - fTrkDir.Phi();
331 Double_t alpha =TMath::Cos(fTrkDir.Theta())-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Theta());
332 Double_t k = 1.-fgkRadIdx*fgkRadIdx+alpha*alpha/(betaM*betaM);
333 if (k<0) return 1e10;
335 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()));
336 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()));
338 Double_t kk = betaM*TMath::Sqrt(k)/(8*alpha);
339 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));
340 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));
342 return TMath::Sqrt(0.2*0.2*dtdxc*dtdxc + 0.25*0.25*dtdyc*dtdyc);
344 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
345 Double_t AliHMPIDRecon::SigCrom(Double_t thetaC, Double_t phiC,Double_t betaM)const
347 // Analithical calculation of chromatic error (due to lack of knowledge of Cerenkov photon energy) on Cerenkov angle for a given Cerenkov photon
348 // created by a given MIP. Fromulae according to CERN-EP-2000-058
349 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
350 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
352 // Returns: absolute error on Cerenkov angle, [radians]
353 Double_t phiDelta = phiC - fTrkDir.Phi();
354 Double_t alpha =TMath::Cos(fTrkDir.Theta())-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Theta());
356 Double_t dtdn = TMath::Cos(fTrkDir.Theta())*fgkRadIdx*betaM*betaM/(alpha*TMath::Tan(thetaC));
358 Double_t f = 0.00928*(7.75-5.635)/TMath::Sqrt(12.);
362 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
363 Double_t AliHMPIDRecon::SigGeom(Double_t thetaC, Double_t phiC,Double_t betaM)const
365 // Analithical calculation of geometric error (due to lack of knowledge of creation point in radiator) on Cerenkov angle for a given Cerenkov photon
366 // created by a given MIP. Formulae according to CERN-EP-2000-058
367 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
368 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
370 // Returns: absolute error on Cerenkov angle, [radians]
372 Double_t phiDelta = phiC - fTrkDir.Phi();
373 Double_t alpha =TMath::Cos(fTrkDir.Theta())-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Theta());
375 Double_t k = 1.-fgkRadIdx*fgkRadIdx+alpha*alpha/(betaM*betaM);
376 if (k<0) return 1e10;
378 Double_t eTr = 0.5*1.5*betaM*TMath::Sqrt(k)/(8*alpha);
379 Double_t lambda = 1.-TMath::Sin(fTrkDir.Theta())*TMath::Sin(fTrkDir.Theta())*TMath::Sin(phiC)*TMath::Sin(phiC);
381 Double_t c = 1./(1.+ eTr*k/(alpha*alpha*TMath::Cos(thetaC)*TMath::Cos(thetaC)));
382 Double_t i = betaM*TMath::Tan(thetaC)*lambda*TMath::Power(k,1.5);
383 Double_t ii = 1.+eTr*betaM*i;
385 Double_t err = c * (i/(alpha*alpha*8) + ii*(1.-lambda) / ( alpha*alpha*8*betaM*(1.+eTr)) );
386 Double_t trErr = 1.5/(TMath::Sqrt(12.)*TMath::Cos(fTrkDir.Theta()));
390 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++