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 "AliHMPIDParam.h" //CkovAngle()
26 #include "AliHMPIDCluster.h" //CkovAngle()
27 #include <TMinuit.h> //FitEllipse()
28 #include <TRotation.h> //TracePhot()
29 #include <TH1D.h> //HoughResponse()
30 #include <TClonesArray.h> //CkovAngle()
31 #include <AliESDtrack.h> //CkovAngle()
33 const Double_t AliHMPIDRecon::fgkRadThick=1.5;
34 const Double_t AliHMPIDRecon::fgkWinThick=0.5;
35 const Double_t AliHMPIDRecon::fgkGapThick=8.0;
36 const Double_t AliHMPIDRecon::fgkWinIdx =1.5787;
37 const Double_t AliHMPIDRecon::fgkGapIdx =1.0005;
39 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40 AliHMPIDRecon::AliHMPIDRecon():TTask("RichRec","RichPat"),
47 fTrkDir(TVector3(0,0,1)),fTrkPos(TVector2(30,40))
50 for (Int_t i=0; i<3000; i++) {
57 fMipX=fMipY=fThTrkFit=fPhTrkFit=fCkovFit=fMipQ=fRadX=fRadY=-999;
60 for (Int_t i=0; i<100; i++) {
61 fXClu[i] = fYClu[i] = 0;
65 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66 void AliHMPIDRecon::CkovAngle(AliESDtrack *pTrk,TClonesArray *pCluLst,Double_t nmean,Double_t qthre)
68 // Pattern recognition method based on Hough transform
69 // Arguments: pTrk - track for which Ckov angle is to be found
70 // pCluLst - list of clusters for this chamber
71 // Returns: - track ckov angle, [rad],
73 AliHMPIDParam *pParam=AliHMPIDParam::Instance();
75 if(pCluLst->GetEntries()>pParam->MultCut()) fIsWEIGHT = kTRUE; // offset to take into account bkg in reconstruction
76 else fIsWEIGHT = kFALSE;
80 Float_t xRa,yRa,th,ph;
81 pTrk->GetHMPIDtrk(xRa,yRa,th,ph); //initialize this track: th and ph angles at middle of RAD
82 SetTrack(xRa,yRa,th,ph);
86 Float_t dMin=999,mipX=-1,mipY=-1;Int_t chId=-1,mipId=-1,mipQ=-1;
88 for (Int_t iClu=0; iClu<pCluLst->GetEntriesFast();iClu++){//clusters loop
89 AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluLst->UncheckedAt(iClu); //get pointer to current cluster
91 if(pClu->Q()>qthre){ //charge compartible with MIP clusters
92 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
93 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
94 }else{ //charge compatible with photon cluster
95 Double_t thetaCer,phiCer;
96 if(FindPhotCkov(pClu->X(),pClu->Y(),thetaCer,phiCer)){ //find ckov angle for this photon candidate
97 fPhotCkov[fPhotCnt]=thetaCer; //actual theta Cerenkov (in TRS)
98 fPhotPhi [fPhotCnt]=phiCer; //actual phi Cerenkov (in TRS): -pi to come back to "unusual" ref system (X,Y,-Z)
99 //PH Printf("photon n. %i reconstructed theta = %f",fPhotCnt,fPhotCkov[fPhotCnt]);
100 fPhotCnt++; //increment counter of photon candidates
104 fMipPos.Set(mipX,mipY);
105 if(fPhotCnt<=3) pTrk->SetHMPIDsignal(kNoPhotAccept); //no reconstruction with <=3 photon candidates
106 Int_t iNacc=FlagPhot(HoughResponse()); //flag photons according to individual theta ckov with respect to most probable
107 pTrk->SetHMPIDmip(mipX,mipY,mipQ,iNacc); //store mip info
109 if(mipId==-1) {pTrk->SetHMPIDsignal(kMipQdcCut); return;} //no clusters with QDC more the threshold at all
110 if(dMin>pParam->DistCut()) {pTrk->SetHMPIDsignal(kMipDistCut); return;} //closest cluster with enough charge is still too far from intersection
111 pTrk->SetHMPIDcluIdx(chId,mipId); //set index of cluster
113 pTrk->SetHMPIDsignal(kNoPhotAccept); //no photon candidates is accepted
116 pTrk->SetHMPIDsignal(FindRingCkov(pCluLst->GetEntries())); //find best Theta ckov for ring i.e. track
117 pTrk->SetHMPIDchi2(fCkovSigma2); //errors squared
121 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122 Bool_t AliHMPIDRecon::FindPhotCkov(Double_t cluX,Double_t cluY,Double_t &thetaCer,Double_t &phiCer)
124 // Finds Cerenkov angle for this photon candidate
125 // Arguments: cluX,cluY - position of cadidate's cluster
126 // Returns: Cerenkov angle
130 Double_t zRad= -0.5*fgkRadThick-0.5*fgkWinThick; //z position of middle of RAD
131 TVector3 rad(fTrkPos.X(),fTrkPos.Y(),zRad); //impact point at middle of RAD
132 TVector3 pc(cluX,cluY,0.5*fgkWinThick+fgkGapIdx); //mip at PC
133 Double_t cluR = TMath::Sqrt((cluX-fTrkPos.X())*(cluX-fTrkPos.X())+
134 (cluY-fTrkPos.Y())*(cluY-fTrkPos.Y()));//ref. distance impact RAD-CLUSTER
135 Double_t phi=(pc-rad).Phi(); //phi of photon
138 Double_t ckov2=0.75+fTrkDir.Theta(); //start to find theta cerenkov in DRS
139 const Double_t kTol=0.01;
142 if(iIterCnt>=50) return kFALSE;
143 Double_t ckov=0.5*(ckov1+ckov2);
144 dirCkov.SetMagThetaPhi(1,ckov,phi);
145 TVector2 posC=TraceForward(dirCkov); //trace photon with actual angles
146 Double_t dist=cluR-(posC-fTrkPos).Mod(); //get distance between trial point and cluster position
147 if(posC.X()==-999) dist = - 999; //total reflection problem
148 iIterCnt++; //counter step
149 if (dist> kTol) ckov1=ckov; //cluster @ larger ckov
150 else if(dist<-kTol) ckov2=ckov; //cluster @ smaller ckov
151 else{ //precision achived: ckov in DRS found
152 dirCkov.SetMagThetaPhi(1,ckov,phi); //
153 RecPhot(dirCkov,thetaCer,phiCer); //find ckov (in TRS:the effective Cherenkov angle!)
158 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
159 TVector2 AliHMPIDRecon::TraceForward(TVector3 dirCkov)const
161 //Trace forward a photon from (x,y) up to PC
162 // Arguments: dirCkov photon vector in LORS
163 // Returns: pos of traced photon at PC
164 TVector2 pos(-999,-999);
165 Double_t thetaCer = dirCkov.Theta();
166 if(thetaCer > TMath::ASin(1./fRadNmean)) return pos; //total refraction on WIN-GAP boundary
167 Double_t zRad= -0.5*fgkRadThick-0.5*fgkWinThick; //z position of middle of RAD
168 TVector3 posCkov(fTrkPos.X(),fTrkPos.Y(),zRad); //RAD: photon position is track position @ middle of RAD
169 Propagate(dirCkov,posCkov, -0.5*fgkWinThick); //go to RAD-WIN boundary
170 Refract (dirCkov, fRadNmean,fgkWinIdx); //RAD-WIN refraction
171 Propagate(dirCkov,posCkov, 0.5*fgkWinThick); //go to WIN-GAP boundary
172 Refract (dirCkov, fgkWinIdx,fgkGapIdx); //WIN-GAP refraction
173 Propagate(dirCkov,posCkov,0.5*fgkWinThick+fgkGapThick); //go to PC
174 pos.Set(posCkov.X(),posCkov.Y());
177 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
178 void AliHMPIDRecon::RecPhot(TVector3 dirCkov,Double_t &thetaCer,Double_t &phiCer)
180 //Theta Cerenkov reconstruction
181 // Arguments: (x,y) of initial point in LORS, dirCkov photon vector in LORS
182 // Returns: thetaCer theta cerenkov reconstructed
184 // dirTrk.SetMagThetaPhi(1,fTrkDir.Theta(),fTrkDir.Phi());
185 // Double_t thetaCer = TMath::ACos(dirCkov*dirTrk);
186 TRotation mtheta; mtheta.RotateY(- fTrkDir.Theta());
187 TRotation mphi; mphi.RotateZ(- fTrkDir.Phi());
188 TRotation mrot=mtheta*mphi;
190 dirCkovTRS=mrot*dirCkov;
191 phiCer = dirCkovTRS.Phi(); //actual value of the phi of the photon
192 thetaCer= dirCkovTRS.Theta(); //actual value of thetaCerenkov of the photon
194 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
195 Double_t AliHMPIDRecon::FindRingArea(Double_t ckovAng)const
197 // Find area covered in the PC acceptance
198 // Arguments: ckovAng - cerenkov angle
199 // Returns: area of the ring in cm^2 for given theta ckov
205 for(Int_t i=0;i<kN;i++){
207 pos1=TracePhot(ckovAng,Double_t(TMath::TwoPi()*(i+1)/kN)); //find a good trace for the first photon
208 if(pos1.X()==-999) continue; //no area: open ring
209 if(!AliHMPIDParam::IsInside(pos1.X(),pos1.Y(),0)) pos1 = IntWithEdge(fMipPos,pos1); // ffind the very first intersection...
213 TVector2 pos2=TracePhot(ckovAng,Double_t(TMath::TwoPi()*(i+1)/kN)); //trace the next photon
214 if(pos2.X()==-999) continue; //no area: open ring
215 if(!AliHMPIDParam::IsInside(pos2.X(),pos2.Y(),0)) {
216 pos2 = IntWithEdge(fMipPos,pos2);
218 area+=TMath::Abs((pos1-fMipPos).X()*(pos2-fMipPos).Y()-(pos1-fMipPos).Y()*(pos2-fMipPos).X()); //add area of the triangle...
221 //--- find points from ring
225 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
226 TVector2 AliHMPIDRecon::IntWithEdge(TVector2 p1,TVector2 p2)const
228 // It finds the intersection of the line for 2 points traced as photons
229 // and the edge of a given PC
230 // Arguments: 2 points obtained tracing the photons
231 // Returns: intersection point with detector (PC) edges
233 AliHMPIDParam *pParam = AliHMPIDParam::Instance();
235 Double_t xmin = (p1.X()<p2.X())? p1.X():p2.X();
236 Double_t xmax = (p1.X()<p2.X())? p2.X():p1.X();
237 Double_t ymin = (p1.Y()<p2.Y())? p1.Y():p2.Y();
238 Double_t ymax = (p1.Y()<p2.Y())? p2.Y():p1.Y();
240 Double_t m = TMath::Tan((p2-p1).Phi());
242 //intersection with low X
243 pint.Set((Double_t)(p1.X() + (0-p1.Y())/m),0.);
244 if(pint.X()>=0 && pint.X()<=pParam->SizeAllX() &&
245 pint.X()>=xmin && pint.X()<=xmax &&
246 pint.Y()>=ymin && pint.Y()<=ymax) return pint;
247 //intersection with high X
248 pint.Set((Double_t)(p1.X() + (pParam->SizeAllY()-p1.Y())/m),(Double_t)(pParam->SizeAllY()));
249 if(pint.X()>=0 && pint.X()<=pParam->SizeAllX() &&
250 pint.X()>=xmin && pint.X()<=xmax &&
251 pint.Y()>=ymin && pint.Y()<=ymax) return pint;
252 //intersection with left Y
253 pint.Set(0.,(Double_t)(p1.Y() + m*(0-p1.X())));
254 if(pint.Y()>=0 && pint.Y()<=pParam->SizeAllY() &&
255 pint.Y()>=ymin && pint.Y()<=ymax &&
256 pint.X()>=xmin && pint.X()<=xmax) return pint;
257 //intersection with righ Y
258 pint.Set((Double_t)(pParam->SizeAllX()),(Double_t)(p1.Y() + m*(pParam->SizeAllX()-p1.X())));
259 if(pint.Y()>=0 && pint.Y()<=pParam->SizeAllY() &&
260 pint.Y()>=ymin && pint.Y()<=ymax &&
261 pint.X()>=xmin && pint.X()<=xmax) return pint;
264 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
265 Double_t AliHMPIDRecon::FindRingCkov(Int_t)
267 // 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
268 // collecting errors for all single Ckov candidates thetas. (Assuming they are independent)
269 // Arguments: iNclus- total number of clusters in chamber for background estimation
270 // Return: best estimation of track Theta ckov
273 Double_t weightThetaCerenkov = 0.;
275 Double_t ckovMin=9999.,ckovMax=0.;
276 Double_t sigma2 = 0; //to collect error squared for this ring
278 for(Int_t i=0;i<fPhotCnt;i++){//candidates loop
279 if(fPhotFlag[i] == 2){
280 if(fPhotCkov[i]<ckovMin) ckovMin=fPhotCkov[i]; //find max and min Theta ckov from all candidates within probable window
281 if(fPhotCkov[i]>ckovMax) ckovMax=fPhotCkov[i];
282 weightThetaCerenkov += fPhotCkov[i]*fPhotWei[i];
283 wei += fPhotWei[i]; //collect weight as sum of all candidate weghts
285 sigma2 += 1./Sigma2(fPhotCkov[i],fPhotPhi[i]);
289 if(sigma2>0) fCkovSigma2=1./sigma2;
290 else fCkovSigma2=1e10;
292 if(wei != 0.) weightThetaCerenkov /= wei; else weightThetaCerenkov = 0.;
293 return weightThetaCerenkov;
295 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
296 Int_t AliHMPIDRecon::FlagPhot(Double_t ckov)
298 // Flag photon candidates if their individual ckov angle is inside the window around ckov angle returned by HoughResponse()
299 // Arguments: ckov- value of most probable ckov angle for track as returned by HoughResponse()
300 // Returns: number of photon candidates happened to be inside the window
302 // Photon Flag: Flag = 0 initial set;
303 // Flag = 1 good candidate (charge compatible with photon);
304 // Flag = 2 photon used for the ring;
306 Int_t steps = (Int_t)((ckov )/ fDTheta); //how many times we need to have fDTheta to fill the distance between 0 and thetaCkovHough
308 Double_t tmin = (Double_t)(steps - 1)*fDTheta;
309 Double_t tmax = (Double_t)(steps)*fDTheta;
310 Double_t tavg = 0.5*(tmin+tmax);
312 tmin = tavg - 0.5*fWindowWidth; tmax = tavg + 0.5*fWindowWidth;
314 Int_t iInsideCnt = 0; //count photons which Theta ckov inside the window
315 for(Int_t i=0;i<fPhotCnt;i++){//photon candidates loop
317 if(fPhotCkov[i] >= tmin && fPhotCkov[i] <= tmax) {
324 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
325 TVector2 AliHMPIDRecon::TracePhot(Double_t ckovThe,Double_t ckovPhi)const
327 // Trace a single Ckov photon from emission point somewhere in radiator up to photocathode taking into account ref indexes of materials it travereses
328 // Arguments: ckovThe,ckovPhi- photon ckov angles in DRS, [rad]
329 // Returns: distance between photon point on PC and track projection
330 TRotation mtheta; mtheta.RotateY(fTrkDir.Theta());
331 TRotation mphi; mphi.RotateZ(fTrkDir.Phi());
332 TRotation mrot=mphi*mtheta;
333 TVector3 dirCkov,dirCkovTors;
335 dirCkovTors.SetMagThetaPhi(1,ckovThe,ckovPhi); //initially photon is directed according to requested ckov angle
336 dirCkov=mrot*dirCkovTors; //now we know photon direction in LORS
337 return TraceForward(dirCkov);
339 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
340 void AliHMPIDRecon::Propagate(const TVector3 dir,TVector3 &pos,Double_t z)const
342 // Finds an intersection point between a line and XY plane shifted along Z.
343 // Arguments: dir,pos - vector along the line and any point of the line
344 // z - z coordinate of plain
346 // On exit: pos is the position if this intesection if any
347 static TVector3 nrm(0,0,1);
350 TVector3 diff=pnt-pos;
351 Double_t sint=(nrm*diff)/(nrm*dir);
354 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
355 void AliHMPIDRecon::Refract(TVector3 &dir,Double_t n1,Double_t n2)const
357 // Refract direction vector according to Snell law
359 // n1 - ref idx of first substance
360 // n2 - ref idx of second substance
362 // On exit: dir is new direction
363 Double_t sinref=(n1/n2)*TMath::Sin(dir.Theta());
364 if(TMath::Abs(sinref)>1.) dir.SetXYZ(-999,-999,-999);
365 else dir.SetTheta(TMath::ASin(sinref));
367 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
368 Double_t AliHMPIDRecon::HoughResponse()
374 Double_t kThetaMax=0.75;
375 Int_t nChannels = (Int_t)(kThetaMax/fDTheta+0.5);
376 TH1D *phots = new TH1D("Rphot" ,"phots" ,nChannels,0,kThetaMax);
377 TH1D *photsw = new TH1D("RphotWeighted" ,"photsw" ,nChannels,0,kThetaMax);
378 TH1D *resultw = new TH1D("resultw","resultw" ,nChannels,0,kThetaMax);
379 Int_t nBin = (Int_t)(kThetaMax/fDTheta);
380 Int_t nCorrBand = (Int_t)(fWindowWidth/(2*fDTheta));
382 for (Int_t i=0; i< fPhotCnt; i++){//photon cadidates loop
383 Double_t angle = fPhotCkov[i]; if(angle<0||angle>kThetaMax) continue;
385 Int_t bin = (Int_t)(0.5+angle/(fDTheta));
388 Double_t lowerlimit = ((Double_t)bin)*fDTheta - 0.5*fDTheta; Double_t upperlimit = ((Double_t)bin)*fDTheta + 0.5*fDTheta;
389 Double_t diffArea = FindRingArea(upperlimit)-FindRingArea(lowerlimit);
390 if(diffArea>0) weight = 1./diffArea;
392 photsw->Fill(angle,weight);
394 }//photon candidates loop
396 for (Int_t i=1; i<=nBin;i++){
397 Int_t bin1= i-nCorrBand;
398 Int_t bin2= i+nCorrBand;
400 if(bin2>nBin)bin2=nBin;
401 Double_t sumPhots=phots->Integral(bin1,bin2);
402 if(sumPhots<3) continue; // if less then 3 photons don't trust to this ring
403 Double_t sumPhotsw=photsw->Integral(bin1,bin2);
404 resultw->Fill((Double_t)((i+0.5)*fDTheta),sumPhotsw);
406 // evaluate the "BEST" theta ckov as the maximum value of histogramm
407 Double_t *pVec = resultw->GetArray();
408 Int_t locMax = TMath::LocMax(nBin,pVec);
409 delete phots;delete photsw;delete resultw; // Reset and delete objects
411 return (Double_t)(locMax*fDTheta+0.5*fDTheta); //final most probable track theta ckov
413 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
414 Double_t AliHMPIDRecon::Sigma2(Double_t ckovTh, Double_t ckovPh)const
416 // Analithical calculation of total error (as a sum of localization, geometrical and chromatic errors) on Cerenkov angle for a given Cerenkov photon
417 // created by a given MIP. Fromulae according to CERN-EP-2000-058
418 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
419 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
421 // Returns: absolute error on Cerenkov angle, [radians]
423 TVector3 v(-999,-999,-999);
424 Double_t trkBeta = 1./(TMath::Cos(ckovTh)*fRadNmean);
426 if(trkBeta > 1) trkBeta = 1; //protection against bad measured thetaCer
427 if(trkBeta < 0) trkBeta = 0.0001; //
429 v.SetX(SigLoc (ckovTh,ckovPh,trkBeta));
430 v.SetY(SigGeom(ckovTh,ckovPh,trkBeta));
431 v.SetZ(SigCrom(ckovTh,ckovPh,trkBeta));
435 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
436 Double_t AliHMPIDRecon::SigLoc(Double_t thetaC, Double_t phiC,Double_t betaM)const
438 // Analithical calculation of localization error (due to finite segmentation of PC) on Cerenkov angle for a given Cerenkov photon
439 // created by a given MIP. Fromulae according to CERN-EP-2000-058
440 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
441 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
443 // Returns: absolute error on Cerenkov angle, [radians]
445 Double_t phiDelta = phiC - fTrkDir.Phi();
447 Double_t sint = TMath::Sin(fTrkDir.Theta());
448 Double_t cost = TMath::Cos(fTrkDir.Theta());
449 Double_t sinf = TMath::Sin(fTrkDir.Phi());
450 Double_t cosf = TMath::Cos(fTrkDir.Phi());
451 Double_t sinfd = TMath::Sin(phiDelta);
452 Double_t cosfd = TMath::Cos(phiDelta);
453 Double_t tantheta = TMath::Tan(thetaC);
455 Double_t alpha =cost-tantheta*cosfd*sint; // formula (11)
456 Double_t k = 1.-fRadNmean*fRadNmean+alpha*alpha/(betaM*betaM); // formula (after 8 in the text)
457 if (k<0) return 1e10;
458 Double_t mu =sint*sinf+tantheta*(cost*cosfd*sinf+sinfd*cosf); // formula (10)
459 Double_t e =sint*cosf+tantheta*(cost*cosfd*cosf-sinfd*sinf); // formula (9)
461 Double_t kk = betaM*TMath::Sqrt(k)/(fgkGapThick*alpha); // formula (6) and (7)
462 Double_t dtdxc = kk*(k*(cosfd*cosf-cost*sinfd*sinf)-(alpha*mu/(betaM*betaM))*sint*sinfd); // formula (6)
463 Double_t dtdyc = kk*(k*(cosfd*sinf+cost*sinfd*cosf)+(alpha* e/(betaM*betaM))*sint*sinfd); // formula (7) pag.4
465 Double_t errX = 0.2,errY=0.25; //end of page 7
466 return TMath::Sqrt(errX*errX*dtdxc*dtdxc + errY*errY*dtdyc*dtdyc);
468 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
469 Double_t AliHMPIDRecon::SigCrom(Double_t thetaC, Double_t phiC,Double_t betaM)const
471 // Analithical calculation of chromatic error (due to lack of knowledge of Cerenkov photon energy) on Cerenkov angle for a given Cerenkov photon
472 // created by a given MIP. Fromulae according to CERN-EP-2000-058
473 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
474 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
476 // Returns: absolute error on Cerenkov angle, [radians]
478 Double_t phiDelta = phiC - fTrkDir.Phi();
480 Double_t sint = TMath::Sin(fTrkDir.Theta());
481 Double_t cost = TMath::Cos(fTrkDir.Theta());
482 Double_t cosfd = TMath::Cos(phiDelta);
483 Double_t tantheta = TMath::Tan(thetaC);
485 Double_t alpha =cost-tantheta*cosfd*sint; // formula (11)
486 Double_t dtdn = cost*fRadNmean*betaM*betaM/(alpha*tantheta); // formula (12)
488 // Double_t f = 0.00928*(7.75-5.635)/TMath::Sqrt(12.);
489 Double_t f = 0.0172*(7.75-5.635)/TMath::Sqrt(24.);
493 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
494 Double_t AliHMPIDRecon::SigGeom(Double_t thetaC, Double_t phiC,Double_t betaM)const
496 // Analithical calculation of geometric error (due to lack of knowledge of creation point in radiator) on Cerenkov angle for a given Cerenkov photon
497 // created by a given MIP. Formulae according to CERN-EP-2000-058
498 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
499 // dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
501 // Returns: absolute error on Cerenkov angle, [radians]
503 Double_t phiDelta = phiC - fTrkDir.Phi();
505 Double_t sint = TMath::Sin(fTrkDir.Theta());
506 Double_t cost = TMath::Cos(fTrkDir.Theta());
507 Double_t sinf = TMath::Sin(fTrkDir.Phi());
508 Double_t cosfd = TMath::Cos(phiDelta);
509 Double_t costheta = TMath::Cos(thetaC);
510 Double_t tantheta = TMath::Tan(thetaC);
512 Double_t alpha =cost-tantheta*cosfd*sint; // formula (11)
514 Double_t k = 1.-fRadNmean*fRadNmean+alpha*alpha/(betaM*betaM); // formula (after 8 in the text)
515 if (k<0) return 1e10;
517 Double_t eTr = 0.5*fgkRadThick*betaM*TMath::Sqrt(k)/(fgkGapThick*alpha); // formula (14)
518 Double_t lambda = 1.-sint*sint*sinf*sinf; // formula (15)
520 Double_t c1 = 1./(1.+ eTr*k/(alpha*alpha*costheta*costheta)); // formula (13.a)
521 Double_t c2 = betaM*TMath::Power(k,1.5)*tantheta*lambda/(fgkGapThick*alpha*alpha); // formula (13.b)
522 Double_t c3 = (1.+eTr*k*betaM*betaM)/((1+eTr)*alpha*alpha); // formula (13.c)
523 Double_t c4 = TMath::Sqrt(k)*tantheta*(1-lambda)/(fgkGapThick*betaM); // formula (13.d)
524 Double_t dtdT = c1 * (c2+c3*c4);
525 Double_t trErr = fgkRadThick/(TMath::Sqrt(12.)*cost);
529 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
533 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
534 Bool_t AliHMPIDRecon::CkovHiddenTrk(AliESDtrack *pTrk,TClonesArray *pCluLst,Double_t nmean, Double_t qthre)
536 // Pattern recognition method without any infos from tracking:HTA (Hidden Track Algorithm)...
537 // The method finds in the chmber the cluster with the highest charge
538 // compatibile with a MIP, then the strategy is applied
539 // Arguments: pTrk - pointer to ESD track
540 // pCluLs - list of clusters for a given chamber
541 // nmean - mean freon ref. index
542 // Returns: - 0=ok,1=not fitted
546 if(pCluLst->GetEntriesFast()>100) return kFALSE; //boundary check for CluX,CluY...
547 Float_t mipX=-1,mipY=-1;Int_t mipId=-1,mipQ=-1;
550 for (Int_t iClu=0;iClu<pCluLst->GetEntriesFast();iClu++){ //clusters loop
551 AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluLst->UncheckedAt(iClu); //get pointer to current cluster
553 fXClu[iClu] = pClu->X();fYClu[iClu] = pClu->Y(); //store x,y for fitting procedure
554 fClCk[iClu] = kTRUE; //all cluster are accepted at this stage to be reconstructed
555 if(pClu->Q()>qRef){ //searching the highest charge to select a MIP
557 mipId=iClu; mipX=pClu->X();mipY=pClu->Y();mipQ=(Int_t)pClu->Q();
561 fNClu = pCluLst->GetEntriesFast();
562 if(qRef>qthre){ //charge compartible with MIP clusters
564 fClCk[mipId] = kFALSE;
565 fMipX = mipX; fMipY=mipY; fMipQ = qRef;
566 if(!DoRecHiddenTrk(pCluLst)) {
567 pTrk->SetHMPIDsignal(kNoPhotAccept);
569 } //Do track and ring reconstruction,if problems returns 1
570 pTrk->SetHMPIDtrk(fRadX,fRadY,fThTrkFit,fPhTrkFit); //store track intersection info
571 pTrk->SetHMPIDmip(fMipX,fMipY,(Int_t)fMipQ,fNClu); //store mip info
572 pTrk->SetHMPIDcluIdx(nCh,fIdxMip); //set cham number and index of cluster
573 pTrk->SetHMPIDsignal(fCkovFit); //find best Theta ckov for ring i.e. track
574 pTrk->SetHMPIDchi2(fCkovSig2); //errors squared
575 // Printf(" n clusters tot %i accepted %i",pCluLst->GetEntriesFast(),fNClu);
581 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
582 Bool_t AliHMPIDRecon::DoRecHiddenTrk(TClonesArray *pCluLst)
584 // Pattern recognition method without any infos from tracking...
585 // First a preclustering filter to avoid part of the noise
586 // Then only ellipsed-rings are fitted (no possibility,
587 // for the moment, to reconstruct very inclined tracks)
588 // Finally a fitting with (th,ph) free, starting by very close values
589 // previously evaluated.
593 if(!CluPreFilter(pCluLst)) {return kFALSE;}
594 if(!FitEllipse(phiRec)) {return kFALSE;}
595 Int_t nClTmp1 = pCluLst->GetEntriesFast()-1; //minus MIP...
597 while(nClTmp1 != nClTmp2){
598 SetNClu(pCluLst->GetEntriesFast());
599 if(!FitFree(phiRec)) {return kFALSE;}
601 if(nClTmp2!=nClTmp1) {nClTmp1=nClTmp2;nClTmp2=0;}
606 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
607 Bool_t AliHMPIDRecon::CluPreFilter(TClonesArray *pCluLst)
609 // Filter of bkg clusters
610 // based on elliptical-shapes...
612 if(pCluLst->GetEntriesFast()>50||pCluLst->GetEntriesFast()<4) return kFALSE;
615 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
616 Bool_t AliHMPIDRecon::FitEllipse(Double_t &phiRec)
618 //Fit a set of clusters with an analitical conical section function:
620 // Ax^2 + B*y^2 + 2Hxy + 2Gx + 2Fy + 1 = 0 ---> conical section
622 // H*H - A*B > 0 hyperbola
626 // tan 2alfa = 2H/(A-B) alfa=angle of rotation
628 // coordinate of the centre of the conical section:
639 Double_t cA,cB,cF,cG,cH;
640 Double_t aArg=-1; Int_t iErrFlg; //tmp vars for TMinuit
642 if(!gMinuit) gMinuit = new TMinuit(5); //init MINUIT with this number of parameters (5 params)
643 gMinuit->mncler(); // reset Minuit list of paramters
644 gMinuit->SetObjectFit((TObject*)this); gMinuit->SetFCN(AliHMPIDRecon::FunMinEl); //set fit function
645 gMinuit->mnexcm("SET PRI",&aArg,1,iErrFlg); //suspend all printout from TMinuit
646 gMinuit->mnexcm("SET NOW",&aArg,0,iErrFlg); //suspend all warning printout from TMinuit
651 gMinuit->mnparm(0," A ",1,0.01,0,0,iErrFlg);
652 gMinuit->mnparm(1," B ",1,0.01,0,0,iErrFlg);
653 gMinuit->mnparm(2," H ",1,0.01,0,0,iErrFlg);
654 gMinuit->mnparm(3," G ",1,0.01,0,0,iErrFlg);
655 gMinuit->mnparm(4," F ",1,0.01,0,0,iErrFlg);
657 gMinuit->mnexcm("SIMPLEX",&aArg,0,iErrFlg);
658 gMinuit->mnexcm("MIGRAD" ,&aArg,0,iErrFlg);
659 gMinuit->mnpout(0,sName,cA,d1,d2,d3,iErrFlg);
660 gMinuit->mnpout(1,sName,cB,d1,d2,d3,iErrFlg);
661 gMinuit->mnpout(2,sName,cH,d1,d2,d3,iErrFlg);
662 gMinuit->mnpout(3,sName,cG,d1,d2,d3,iErrFlg);
663 gMinuit->mnpout(4,sName,cF,d1,d2,d3,iErrFlg);
666 Double_t i2 = cA*cB-cH*cH; //quartic invariant : i2 > 0 ellipse, i2 < 0 hyperbola
667 if(i2<=0) return kFALSE;
668 Double_t aX = (cH*cF-cB*cG)/i2; //x centre of the canonical section
669 Double_t bY = (cH*cG-cA*cF)/i2; //y centre of the canonical section
670 Double_t alfa1 = TMath::ATan(2*cH/(cA-cB)); //alpha = angle of rotation of the conical section
671 if(alfa1<0) alfa1+=TMath::Pi();
673 // Double_t alfa2 = alfa1+TMath::Pi();
674 Double_t phiref = TMath::ATan2(bY-fMipY,aX-fMipX); //evaluate in a unique way the angle of rotation comparing it
675 if(phiref<0) phiref+=TMath::TwoPi(); //with the vector that points to the centre from the mip
676 if(i2<0) phiref+=TMath::Pi();
677 if(phiref>TMath::TwoPi()) phiref-=TMath::TwoPi();
679 // Printf(" alfa1 %f",alfa1*TMath::RadToDeg());
680 // Printf(" alfa2 %f",alfa2*TMath::RadToDeg());
681 // Printf(" firef %f",phiref*TMath::RadToDeg());
682 // if(TMath::Abs(alfa1-phiref)<TMath::Abs(alfa2-phiref)) phiRec = alfa1; else phiRec = alfa2;
684 // Printf("FitEllipse: phi reconstructed %f",phiRec*TMath::RadToDeg());
689 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
690 Bool_t AliHMPIDRecon::FitFree(Double_t phiRec)
692 // Fit performed by minimizing RMS/sqrt(n) of the
693 // photons reconstructed. First phi is fixed and theta
694 // is fouond, then (th,ph) of the track
695 // as free parameters
696 // Arguments: PhiRec phi of the track
698 Double_t aArg=-1; Int_t iErrFlg; //tmp vars for TMinuit
699 if(!gMinuit) gMinuit = new TMinuit(2); //init MINUIT with this number of parameters (5 params)
700 gMinuit->mncler(); // reset Minuit list of paramters
701 gMinuit->SetObjectFit((TObject*)this); gMinuit->SetFCN(AliHMPIDRecon::FunMinPhot); //set fit function
702 gMinuit->mnexcm("SET PRI",&aArg,1,iErrFlg); //suspend all printout from TMinuit
703 gMinuit->mnexcm("SET NOW",&aArg,0,iErrFlg); //suspend all warning printout from TMinuit
709 gMinuit->mnparm(0," theta ", 0.01,0.01,0,TMath::PiOver2(),iErrFlg);
710 gMinuit->mnparm(1," phi ",phiRec,0.01,0,TMath::TwoPi() ,iErrFlg);
712 gMinuit->FixParameter(1);
713 gMinuit->mnexcm("SIMPLEX" ,&aArg,0,iErrFlg);
714 gMinuit->mnexcm("MIGRAD" ,&aArg,0,iErrFlg);
716 gMinuit->mnexcm("MIGRAD" ,&aArg,0,iErrFlg);
718 gMinuit->mnpout(0,sName,th,d1,d2,d3,iErrFlg);
719 gMinuit->mnpout(1,sName,ph,d1,d2,d3,iErrFlg);
721 Double_t outPar[2] = {th,ph}; Double_t g; Double_t f;Int_t flag = 3;
722 gMinuit->Eval(2, &g, f, outPar,flag);
728 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
729 Double_t AliHMPIDRecon::FunConSect(Double_t *c,Double_t x,Double_t y)
731 return c[0]*x*x+c[1]*y*y+2*c[2]*x*y+2*c[3]*x+2*c[4]*y+1;
733 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
734 void AliHMPIDRecon::FunMinEl(Int_t &/* */,Double_t* /* */,Double_t &f,Double_t *par,Int_t /* */)
736 AliHMPIDRecon *pRec=(AliHMPIDRecon*)gMinuit->GetObjectFit();
738 Int_t np = pRec->NClu();
739 for(Int_t i=0;i<np;i++) {
740 if(i==pRec->IdxMip()) continue;
741 Double_t el = pRec->FunConSect(par,pRec->XClu(i),pRec->YClu(i));
746 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
747 void AliHMPIDRecon::FunMinPhot(Int_t &/* */,Double_t* /* */,Double_t &f,Double_t *par,Int_t iflag)
749 AliHMPIDRecon *pRec=(AliHMPIDRecon*)gMinuit->GetObjectFit();
750 Double_t sizeCh = 0.5*fgkRadThick+fgkWinThick+fgkGapThick;
751 Double_t thTrk = par[0];
752 Double_t phTrk = par[1];
753 Double_t xrad = pRec->MipX() - sizeCh*TMath::Tan(thTrk)*TMath::Cos(phTrk);
754 Double_t yrad = pRec->MipY() - sizeCh*TMath::Tan(thTrk)*TMath::Sin(phTrk);
755 pRec->SetRadXY(xrad,yrad);
756 pRec->SetTrack(xrad,yrad,thTrk,phTrk);
758 Double_t meanCkov =0;
759 Double_t meanCkov2=0;
760 Double_t thetaCer,phiCer;
762 Int_t nClTot=pRec->NClu();
764 for(Int_t i=0;i<nClTot;i++) {
765 if(!(pRec->ClCk(i))) continue;
766 pRec->FindPhotCkov(pRec->XClu(i),pRec->YClu(i),thetaCer,phiCer);
767 meanCkov += thetaCer;
768 meanCkov2 += thetaCer*thetaCer;
771 if(nClAcc==0) {f=999;return;}
773 Double_t rms = (meanCkov2 - meanCkov*meanCkov*nClAcc)/nClAcc;
774 if(rms<0) Printf(" rms2 = %f, strange!!!",rms);
775 rms = TMath::Sqrt(rms);
776 f = rms/TMath::Sqrt(nClAcc);
780 Printf("FunMinPhot before: photons candidates %i used %i",nClTot,nClAcc);
782 Double_t meanCkov1=0;
783 Double_t meanCkov2=0;
784 for(Int_t i=0;i<nClTot;i++) {
785 if(!(pRec->ClCk(i))) continue;
786 pRec->FindPhotCkov(pRec->XClu(i),pRec->YClu(i),thetaCer,phiCer);
787 if(TMath::Abs(thetaCer-meanCkov)<2*rms) {
788 meanCkov1 += thetaCer;
789 meanCkov2 += thetaCer*thetaCer;
791 } else pRec->SetClCk(i,kFALSE);
794 Double_t rms2 = (meanCkov2 - meanCkov*meanCkov*nClAcc)/nClAcc;
795 Printf("FunMinPhot after: photons candidates %i used %i thetaCer %f",nClTot,nClAcc,meanCkov1);
796 pRec->SetCkovFit(meanCkov1);
797 pRec->SetCkovSig2(rms2);
798 pRec->SetNClu(nClAcc);
801 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
803 // ended Hidden track algorithm....
805 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++