Remove AliPHOSGammaJet due to its migration to PWG4
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDRecon.cxx
CommitLineData
d3da6dc4 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
a591e55f 24#include "AliHMPIDRecon.h" //class header
25#include "AliHMPIDParam.h" //CkovAngle()
d3da6dc4 26#include "AliHMPIDCluster.h" //CkovAngle()
43400d2d 27#include <TMinuit.h> //FitEllipse()
a591e55f 28#include <TRotation.h> //TracePhot()
29#include <TH1D.h> //HoughResponse()
30#include <TClonesArray.h> //CkovAngle()
31#include <AliESDtrack.h> //CkovAngle()
d3da6dc4 32
33const Double_t AliHMPIDRecon::fgkRadThick=1.5;
34const Double_t AliHMPIDRecon::fgkWinThick=0.5;
35const Double_t AliHMPIDRecon::fgkGapThick=8.0;
d3da6dc4 36const Double_t AliHMPIDRecon::fgkWinIdx =1.5787;
37const Double_t AliHMPIDRecon::fgkGapIdx =1.0005;
38
d3da6dc4 39//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40AliHMPIDRecon::AliHMPIDRecon():TTask("RichRec","RichPat"),
abb5f786 41 fRadNmean(1.292),
d3da6dc4 42 fPhotCnt(-1),
43 fCkovSigma2(0),
44 fIsWEIGHT(kFALSE),
45 fDTheta(0.001),
46 fWindowWidth(0.045),
47 fTrkDir(TVector3(0,0,1)),fTrkPos(TVector2(30,40))
48{
49// main ctor
50 for (Int_t i=0; i<3000; i++) {
51 fPhotFlag[i] = 0;
52 fPhotCkov[i] = -1;
53 fPhotPhi [i] = -1;
54 fPhotWei [i] = 0;
55 }
611e810d 56//hidden algorithm
5b2b2013 57 fMipX=fMipY=fThTrkFit=fPhTrkFit=fCkovFit=fMipQ=fRadX=fRadY=-999;
611e810d 58 fIdxMip=fNClu=0;
3b49956b 59 fCkovSig2=0;
5b2b2013 60 for (Int_t i=0; i<100; i++) {
611e810d 61 fXClu[i] = fYClu[i] = 0;
5b2b2013 62 fClCk[i] = kTRUE;
611e810d 63 }
d3da6dc4 64}
65//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
a591e55f 66void AliHMPIDRecon::CkovAngle(AliESDtrack *pTrk,TClonesArray *pCluLst,Double_t nmean)
d3da6dc4 67{
68// Pattern recognition method based on Hough transform
59280a5a 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],
a591e55f 72
73 AliHMPIDParam *pParam=AliHMPIDParam::Instance();
d3da6dc4 74
a591e55f 75 if(pCluLst->GetEntries()>pParam->MultCut()) fIsWEIGHT = kTRUE; // offset to take into account bkg in reconstruction
76 else fIsWEIGHT = kFALSE;
d3da6dc4 77
611e810d 78 Float_t xRa,yRa,th,ph;
a591e55f 79 pTrk->GetHMPIDtrk(xRa,yRa,th,ph); //initialize this track: th and ph angles at middle of RAD
a591e55f 80 SetTrack(xRa,yRa,th,ph);
611e810d 81
abb5f786 82 fRadNmean=nmean;
d3da6dc4 83
59280a5a 84 Float_t dMin=999,mipX=-1,mipY=-1;Int_t chId=-1,mipId=-1,mipQ=-1;
d3da6dc4 85 fPhotCnt=0;
86 for (Int_t iClu=0; iClu<pCluLst->GetEntriesFast();iClu++){//clusters loop
87 AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluLst->UncheckedAt(iClu); //get pointer to current cluster
59280a5a 88 chId=pClu->Ch();
a591e55f 89 if(pClu->Q()>pParam->QCut()){ //charge compartible with MIP clusters
90 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
91 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
92 }else{ //charge compatible with photon cluster
93 Double_t thetaCer,phiCer;
94 if(FindPhotCkov(pClu->X(),pClu->Y(),thetaCer,phiCer)){ //find ckov angle for this photon candidate
95 fPhotCkov[fPhotCnt]=thetaCer; //actual theta Cerenkov (in TRS)
b4ad85e9 96 fPhotPhi [fPhotCnt]=phiCer; //actual phi Cerenkov (in TRS): -pi to come back to "unusual" ref system (X,Y,-Z)
a591e55f 97 fPhotCnt++; //increment counter of photon candidates
98 }
59280a5a 99 }
d3da6dc4 100 }//clusters loop
a591e55f 101 Int_t iNacc=FlagPhot(HoughResponse()); //flag photons according to individual theta ckov with respect to most probable
102 pTrk->SetHMPIDmip(mipX,mipY,mipQ,iNacc); //store mip info
59280a5a 103
a591e55f 104 if(mipId==-1) {pTrk->SetHMPIDsignal(kMipQdcCut); return;} //no clusters with QDC more the threshold at all
105 if(dMin>pParam->DistCut()) {pTrk->SetHMPIDsignal(kMipDistCut); return;} //closest cluster with enough charge is still too far from intersection
106 pTrk->SetHMPIDcluIdx(chId,mipId); //set index of cluster
107 if(iNacc<1) pTrk->SetHMPIDsignal(kNoPhotAccept); //no photon candidates is accepted
108 else pTrk->SetHMPIDsignal(FindRingCkov(pCluLst->GetEntries())); //find best Theta ckov for ring i.e. track
611e810d 109
a591e55f 110 pTrk->SetHMPIDchi2(fCkovSigma2); //errors squared
d3da6dc4 111
43400d2d 112}//CkovAngle()
d3da6dc4 113//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
a591e55f 114Bool_t AliHMPIDRecon::FindPhotCkov(Double_t cluX,Double_t cluY,Double_t &thetaCer,Double_t &phiCer)
d3da6dc4 115{
116// Finds Cerenkov angle for this photon candidate
117// Arguments: cluX,cluY - position of cadidate's cluster
a591e55f 118// Returns: Cerenkov angle
d3da6dc4 119
a591e55f 120 TVector3 dirCkov;
121
67a1c24c 122 Double_t zRad= -0.5*fgkRadThick-0.5*fgkWinThick; //z position of middle of RAD
123 TVector3 rad(fTrkPos.X(),fTrkPos.Y(),zRad); //impact point at middle of RAD
124 TVector3 pc(cluX,cluY,0.5*fgkWinThick+fgkGapIdx); //mip at PC
a591e55f 125 Double_t cluR = TMath::Sqrt((cluX-fTrkPos.X())*(cluX-fTrkPos.X())+
126 (cluY-fTrkPos.Y())*(cluY-fTrkPos.Y()));//ref. distance impact RAD-CLUSTER
67a1c24c 127 Double_t phi=(pc-rad).Phi(); //phi of photon
a591e55f 128
b4ad85e9 129 Double_t ckov1=0;
67a1c24c 130 Double_t ckov2=0.75+fTrkDir.Theta(); //start to find theta cerenkov in DRS
b4ad85e9 131 const Double_t kTol=0.01;
d3da6dc4 132 Int_t iIterCnt = 0;
133 while(1){
a591e55f 134 if(iIterCnt>=50) return kFALSE;
d3da6dc4 135 Double_t ckov=0.5*(ckov1+ckov2);
67a1c24c 136 dirCkov.SetMagThetaPhi(1,ckov,phi);
a591e55f 137 TVector2 posC=TraceForward(dirCkov); //trace photon with actual angles
138 Double_t dist=cluR-(posC-fTrkPos).Mod(); //get distance between trial point and cluster position
139 if(posC.X()==-999) dist = - 999; //total reflection problem
140 iIterCnt++; //counter step
b4ad85e9 141 if (dist> kTol) ckov1=ckov; //cluster @ larger ckov
d3da6dc4 142 else if(dist<-kTol) ckov2=ckov; //cluster @ smaller ckov
a591e55f 143 else{ //precision achived: ckov in DRS found
144 dirCkov.SetMagThetaPhi(1,ckov,phi); //
145 RecPhot(dirCkov,thetaCer,phiCer); //find ckov (in TRS:the effective Cherenkov angle!)
146 return kTRUE;
147 }
d3da6dc4 148 }
149}//FindPhotTheta()
150//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
a591e55f 151TVector2 AliHMPIDRecon::TraceForward(TVector3 dirCkov)const
d3da6dc4 152{
a591e55f 153 //Trace forward a photon from (x,y) up to PC
154 // Arguments: dirCkov photon vector in LORS
155 // Returns: pos of traced photon at PC
156 TVector2 pos(-999,-999);
67a1c24c 157 Double_t thetaCer = dirCkov.Theta();
158 if(thetaCer > TMath::ASin(1./fRadNmean)) return pos; //total refraction on WIN-GAP boundary
159 Double_t zRad= -0.5*fgkRadThick-0.5*fgkWinThick; //z position of middle of RAD
160 TVector3 posCkov(fTrkPos.X(),fTrkPos.Y(),zRad); //RAD: photon position is track position @ middle of RAD
161 Propagate(dirCkov,posCkov, -0.5*fgkWinThick); //go to RAD-WIN boundary
162 Refract (dirCkov, fRadNmean,fgkWinIdx); //RAD-WIN refraction
163 Propagate(dirCkov,posCkov, 0.5*fgkWinThick); //go to WIN-GAP boundary
164 Refract (dirCkov, fgkWinIdx,fgkGapIdx); //WIN-GAP refraction
165 Propagate(dirCkov,posCkov,0.5*fgkWinThick+fgkGapThick); //go to PC
a591e55f 166 pos.Set(posCkov.X(),posCkov.Y());
167 return pos;
168}//TraceForward()
169//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170void AliHMPIDRecon::RecPhot(TVector3 dirCkov,Double_t &thetaCer,Double_t &phiCer)
171{
172 //Theta Cerenkov reconstruction
173 // Arguments: (x,y) of initial point in LORS, dirCkov photon vector in LORS
174 // Returns: thetaCer theta cerenkov reconstructed
175// TVector3 dirTrk;
176// dirTrk.SetMagThetaPhi(1,fTrkDir.Theta(),fTrkDir.Phi());
177// Double_t thetaCer = TMath::ACos(dirCkov*dirTrk);
178 TRotation mtheta; mtheta.RotateY(- fTrkDir.Theta());
179 TRotation mphi; mphi.RotateZ(- fTrkDir.Phi());
180 TRotation mrot=mtheta*mphi;
181 TVector3 dirCkovTRS;
182 dirCkovTRS=mrot*dirCkov;
183 phiCer = dirCkovTRS.Phi(); //actual value of the phi of the photon
184 thetaCer= dirCkovTRS.Theta(); //actual value of thetaCerenkov of the photon
d3da6dc4 185}
186//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
187Double_t AliHMPIDRecon::FindRingArea(Double_t ckovAng)const
188{
189// Find area inside the cerenkov ring which lays inside PCs
a591e55f 190// Arguments: ckovAng - cerenkov angle
d3da6dc4 191// Returns: area of the ring in cm^2 for given theta ckov
192
d3da6dc4 193 const Int_t kN=100;
194 Double_t area=0;
195 for(Int_t i=0;i<kN;i++){
a591e55f 196 TVector2 pos1=TracePhot(ckovAng,Double_t(TMath::TwoPi()*i /kN));//trace this photon
197 TVector2 pos2=TracePhot(ckovAng,Double_t(TMath::TwoPi()*(i+1)/kN));//trace the next photon
198 area+=(pos1-fTrkPos)*(pos2-fTrkPos); //add area of the triangle...
d3da6dc4 199 }
200 return area;
201}//FindRingArea()
202//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
203Double_t AliHMPIDRecon::FindRingCkov(Int_t)
204{
205// 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
206// collecting errors for all single Ckov candidates thetas. (Assuming they are independent)
207// Arguments: iNclus- total number of clusters in chamber for background estimation
208// Return: best estimation of track Theta ckov
209
210 Double_t wei = 0.;
211 Double_t weightThetaCerenkov = 0.;
212
213 Double_t ckovMin=9999.,ckovMax=0.;
214 Double_t sigma2 = 0; //to collect error squared for this ring
215
216 for(Int_t i=0;i<fPhotCnt;i++){//candidates loop
217 if(fPhotFlag[i] == 2){
a591e55f 218 if(fPhotCkov[i]<ckovMin) ckovMin=fPhotCkov[i]; //find max and min Theta ckov from all candidates within probable window
d3da6dc4 219 if(fPhotCkov[i]>ckovMax) ckovMax=fPhotCkov[i];
a591e55f 220 weightThetaCerenkov += fPhotCkov[i]*fPhotWei[i];
221 wei += fPhotWei[i]; //collect weight as sum of all candidate weghts
d3da6dc4 222
d3da6dc4 223 sigma2 += 1./Sigma2(fPhotCkov[i],fPhotPhi[i]);
224 }
225 }//candidates loop
226
227 if(sigma2>0) fCkovSigma2=1./sigma2;
228 else fCkovSigma2=1e10;
229
b4ad85e9 230 if(wei != 0.) weightThetaCerenkov /= wei; else weightThetaCerenkov = 0.;
d3da6dc4 231 return weightThetaCerenkov;
232}//FindCkovRing()
233//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
234Int_t AliHMPIDRecon::FlagPhot(Double_t ckov)
235{
236// Flag photon candidates if their individual ckov angle is inside the window around ckov angle returned by HoughResponse()
237// Arguments: ckov- value of most probable ckov angle for track as returned by HoughResponse()
238// Returns: number of photon candidates happened to be inside the window
239
a591e55f 240// Photon Flag: Flag = 0 initial set;
241// Flag = 1 good candidate (charge compatible with photon);
242// Flag = 2 photon used for the ring;
d3da6dc4 243
244 Int_t steps = (Int_t)((ckov )/ fDTheta); //how many times we need to have fDTheta to fill the distance between 0 and thetaCkovHough
245
246 Double_t tmin = (Double_t)(steps - 1)*fDTheta;
247 Double_t tmax = (Double_t)(steps)*fDTheta;
248 Double_t tavg = 0.5*(tmin+tmax);
249
250 tmin = tavg - 0.5*fWindowWidth; tmax = tavg + 0.5*fWindowWidth;
251
252 Int_t iInsideCnt = 0; //count photons which Theta ckov inside the window
253 for(Int_t i=0;i<fPhotCnt;i++){//photon candidates loop
254 if(fPhotCkov[i] >= tmin && fPhotCkov[i] <= tmax) {
255 fPhotFlag[i]=2;
256 iInsideCnt++;
257 }
258 }
259 return iInsideCnt;
260}//FlagPhot()
261//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
a591e55f 262TVector2 AliHMPIDRecon::TracePhot(Double_t ckovThe,Double_t ckovPhi)const
d3da6dc4 263{
264// Trace a single Ckov photon from emission point somewhere in radiator up to photocathode taking into account ref indexes of materials it travereses
a591e55f 265// Arguments: ckovThe,ckovPhi- photon ckov angles in DRS, [rad]
d3da6dc4 266// Returns: distance between photon point on PC and track projection
267 TRotation mtheta; mtheta.RotateY(fTrkDir.Theta());
268 TRotation mphi; mphi.RotateZ(fTrkDir.Phi());
269 TRotation mrot=mphi*mtheta;
a591e55f 270 TVector3 dirCkov,dirCkovTors;
271
272 dirCkovTors.SetMagThetaPhi(1,ckovThe,ckovPhi); //initially photon is directed according to requested ckov angle
273 dirCkov=mrot*dirCkovTors; //now we know photon direction in LORS
274 return TraceForward(dirCkov);
275}//TracePhot()
d3da6dc4 276//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
a591e55f 277void AliHMPIDRecon::Propagate(const TVector3 dir,TVector3 &pos,Double_t z)const
d3da6dc4 278{
279// Finds an intersection point between a line and XY plane shifted along Z.
280// Arguments: dir,pos - vector along the line and any point of the line
281// z - z coordinate of plain
282// Returns: none
283// On exit: pos is the position if this intesection if any
284 static TVector3 nrm(0,0,1);
285 TVector3 pnt(0,0,z);
286
287 TVector3 diff=pnt-pos;
288 Double_t sint=(nrm*diff)/(nrm*dir);
289 pos+=sint*dir;
290}//Propagate()
291//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
292void AliHMPIDRecon::Refract(TVector3 &dir,Double_t n1,Double_t n2)const
293{
294// Refract direction vector according to Snell law
295// Arguments:
296// n1 - ref idx of first substance
297// n2 - ref idx of second substance
298// Returns: none
299// On exit: dir is new direction
67a1c24c 300 Double_t sinref=(n1/n2)*TMath::Sin(dir.Theta());
d3da6dc4 301 if(sinref>1.) dir.SetXYZ(-999,-999,-999);
67a1c24c 302 else dir.SetTheta(TMath::ASin(sinref));
d3da6dc4 303}//Refract()
304//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
305Double_t AliHMPIDRecon::HoughResponse()
306{
307//
611e810d 308// fIdxMip = mipId;
309
d3da6dc4 310//
311 Double_t kThetaMax=0.75;
312 Int_t nChannels = (Int_t)(kThetaMax/fDTheta+0.5);
313 TH1D *phots = new TH1D("Rphot" ,"phots" ,nChannels,0,kThetaMax);
314 TH1D *photsw = new TH1D("RphotWeighted" ,"photsw" ,nChannels,0,kThetaMax);
315 TH1D *resultw = new TH1D("resultw","resultw" ,nChannels,0,kThetaMax);
316 Int_t nBin = (Int_t)(kThetaMax/fDTheta);
317 Int_t nCorrBand = (Int_t)(fWindowWidth/(2*fDTheta));
318
319 for (Int_t i=0; i< fPhotCnt; i++){//photon cadidates loop
320 Double_t angle = fPhotCkov[i]; if(angle<0||angle>kThetaMax) continue;
321 phots->Fill(angle);
322 Int_t bin = (Int_t)(0.5+angle/(fDTheta));
323 Double_t weight=1.;
324 if(fIsWEIGHT){
325 Double_t lowerlimit = ((Double_t)bin)*fDTheta - 0.5*fDTheta; Double_t upperlimit = ((Double_t)bin)*fDTheta + 0.5*fDTheta;
326 Double_t diffArea = FindRingArea(upperlimit)-FindRingArea(lowerlimit);
327 if(diffArea>0) weight = 1./diffArea;
328 }
329 photsw->Fill(angle,weight);
330 fPhotWei[i]=weight;
331 }//photon candidates loop
332
333 for (Int_t i=1; i<=nBin;i++){
334 Int_t bin1= i-nCorrBand;
335 Int_t bin2= i+nCorrBand;
336 if(bin1<1) bin1=1;
337 if(bin2>nBin)bin2=nBin;
338 Double_t sumPhots=phots->Integral(bin1,bin2);
339 if(sumPhots<3) continue; // if less then 3 photons don't trust to this ring
340 Double_t sumPhotsw=photsw->Integral(bin1,bin2);
341 resultw->Fill((Double_t)((i+0.5)*fDTheta),sumPhotsw);
342 }
343// evaluate the "BEST" theta ckov as the maximum value of histogramm
344 Double_t *pVec = resultw->GetArray();
345 Int_t locMax = TMath::LocMax(nBin,pVec);
346 phots->Delete();photsw->Delete();resultw->Delete(); // Reset and delete objects
347
348 return (Double_t)(locMax*fDTheta+0.5*fDTheta); //final most probable track theta ckov
349}//HoughResponse()
350//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
351Double_t AliHMPIDRecon::Sigma2(Double_t ckovTh, Double_t ckovPh)const
352{
353// Analithical calculation of total error (as a sum of localization, geometrical and chromatic errors) on Cerenkov angle for a given Cerenkov photon
354// created by a given MIP. Fromulae according to CERN-EP-2000-058
355// Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
356// dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
357// MIP beta
358// Returns: absolute error on Cerenkov angle, [radians]
359
360 TVector3 v(-999,-999,-999);
abb5f786 361 Double_t trkBeta = 1./(TMath::Cos(ckovTh)*fRadNmean);
d3da6dc4 362
363 v.SetX(SigLoc (ckovTh,ckovPh,trkBeta));
364 v.SetY(SigGeom(ckovTh,ckovPh,trkBeta));
365 v.SetZ(SigCrom(ckovTh,ckovPh,trkBeta));
366
367 return v.Mag2();
368}
369//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
370Double_t AliHMPIDRecon::SigLoc(Double_t thetaC, Double_t phiC,Double_t betaM)const
371{
372// Analithical calculation of localization error (due to finite segmentation of PC) on Cerenkov angle for a given Cerenkov photon
373// created by a given MIP. Fromulae according to CERN-EP-2000-058
374// Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
375// dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
376// MIP beta
377// Returns: absolute error on Cerenkov angle, [radians]
378 Double_t phiDelta = phiC - fTrkDir.Phi();
379
380 Double_t alpha =TMath::Cos(fTrkDir.Theta())-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Theta());
abb5f786 381 Double_t k = 1.-fRadNmean*fRadNmean+alpha*alpha/(betaM*betaM);
d3da6dc4 382 if (k<0) return 1e10;
383
384 Double_t mu =TMath::Sin(fTrkDir.Theta())*TMath::Sin(fTrkDir.Phi())+TMath::Tan(thetaC)*(TMath::Cos(fTrkDir.Theta())*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Phi())+TMath::Sin(phiDelta)*TMath::Cos(fTrkDir.Phi()));
385 Double_t e =TMath::Sin(fTrkDir.Theta())*TMath::Cos(fTrkDir.Phi())+TMath::Tan(thetaC)*(TMath::Cos(fTrkDir.Theta())*TMath::Cos(phiDelta)*TMath::Cos(fTrkDir.Phi())-TMath::Sin(phiDelta)*TMath::Sin(fTrkDir.Phi()));
386
387 Double_t kk = betaM*TMath::Sqrt(k)/(8*alpha);
388 Double_t dtdxc = kk*(k*(TMath::Cos(phiDelta)*TMath::Cos(fTrkDir.Phi())-TMath::Cos(fTrkDir.Theta())*TMath::Sin(phiDelta)*TMath::Sin(fTrkDir.Phi()))-(alpha*mu/(betaM*betaM))*TMath::Sin(fTrkDir.Theta())*TMath::Sin(phiDelta));
389 Double_t dtdyc = kk*(k*(TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Phi())+TMath::Cos(fTrkDir.Theta())*TMath::Sin(phiDelta)*TMath::Cos(fTrkDir.Phi()))+(alpha* e/(betaM*betaM))*TMath::Sin(fTrkDir.Theta())*TMath::Sin(phiDelta));
390
391 return TMath::Sqrt(0.2*0.2*dtdxc*dtdxc + 0.25*0.25*dtdyc*dtdyc);
392}
393//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
394Double_t AliHMPIDRecon::SigCrom(Double_t thetaC, Double_t phiC,Double_t betaM)const
395{
396// Analithical calculation of chromatic error (due to lack of knowledge of Cerenkov photon energy) on Cerenkov angle for a given Cerenkov photon
397// created by a given MIP. Fromulae according to CERN-EP-2000-058
398// Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
399// dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
400// MIP beta
401// Returns: absolute error on Cerenkov angle, [radians]
402 Double_t phiDelta = phiC - fTrkDir.Phi();
403 Double_t alpha =TMath::Cos(fTrkDir.Theta())-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Theta());
404
abb5f786 405 Double_t dtdn = TMath::Cos(fTrkDir.Theta())*fRadNmean*betaM*betaM/(alpha*TMath::Tan(thetaC));
d3da6dc4 406
407 Double_t f = 0.00928*(7.75-5.635)/TMath::Sqrt(12.);
408
409 return f*dtdn;
410}//SigCrom()
411//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
412Double_t AliHMPIDRecon::SigGeom(Double_t thetaC, Double_t phiC,Double_t betaM)const
413{
414// Analithical calculation of geometric error (due to lack of knowledge of creation point in radiator) on Cerenkov angle for a given Cerenkov photon
415// created by a given MIP. Formulae according to CERN-EP-2000-058
416// Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
417// dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]
418// MIP beta
419// Returns: absolute error on Cerenkov angle, [radians]
420
421 Double_t phiDelta = phiC - fTrkDir.Phi();
422 Double_t alpha =TMath::Cos(fTrkDir.Theta())-TMath::Tan(thetaC)*TMath::Cos(phiDelta)*TMath::Sin(fTrkDir.Theta());
423
abb5f786 424 Double_t k = 1.-fRadNmean*fRadNmean+alpha*alpha/(betaM*betaM);
d3da6dc4 425 if (k<0) return 1e10;
426
427 Double_t eTr = 0.5*1.5*betaM*TMath::Sqrt(k)/(8*alpha);
428 Double_t lambda = 1.-TMath::Sin(fTrkDir.Theta())*TMath::Sin(fTrkDir.Theta())*TMath::Sin(phiC)*TMath::Sin(phiC);
429
430 Double_t c = 1./(1.+ eTr*k/(alpha*alpha*TMath::Cos(thetaC)*TMath::Cos(thetaC)));
431 Double_t i = betaM*TMath::Tan(thetaC)*lambda*TMath::Power(k,1.5);
432 Double_t ii = 1.+eTr*betaM*i;
433
434 Double_t err = c * (i/(alpha*alpha*8) + ii*(1.-lambda) / ( alpha*alpha*8*betaM*(1.+eTr)) );
435 Double_t trErr = 1.5/(TMath::Sqrt(12.)*TMath::Cos(fTrkDir.Theta()));
436
437 return trErr*err;
438}//SigGeom()
439//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
43400d2d 440//
611e810d 441// From here HTA....
43400d2d 442//
443//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5b2b2013 444Bool_t AliHMPIDRecon::CkovHiddenTrk(AliESDtrack *pTrk,TClonesArray *pCluLst,Double_t nmean)
43400d2d 445{
611e810d 446// Pattern recognition method without any infos from tracking:HTA (Hidden Track Algorithm)...
43400d2d 447// The method finds in the chmber the cluster with the highest charge
448// compatibile with a MIP, then the strategy is applied
611e810d 449// Arguments: pTrk - pointer to ESD track
450// pCluLs - list of clusters for a given chamber
451// nmean - mean freon ref. index
452// Returns: - 0=ok,1=not fitted
453
454 AliHMPIDParam *pParam=AliHMPIDParam::Instance();
43400d2d 455
456 fRadNmean=nmean;
457
3b49956b 458 if(pCluLst->GetEntriesFast()>100) return kFALSE; //boundary check for CluX,CluY...
43400d2d 459 Float_t mipX=-1,mipY=-1;Int_t mipId=-1,mipQ=-1;
43400d2d 460 Double_t qRef = 0;
3b49956b 461 Int_t nCh=0;
5b2b2013 462 for (Int_t iClu=0;iClu<pCluLst->GetEntriesFast();iClu++){ //clusters loop
43400d2d 463 AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluLst->UncheckedAt(iClu); //get pointer to current cluster
3b49956b 464 nCh = pClu->Ch();
43400d2d 465 fXClu[iClu] = pClu->X();fYClu[iClu] = pClu->Y(); //store x,y for fitting procedure
5b2b2013 466 fClCk[iClu] = kTRUE; //all cluster are accepted at this stage to be reconstructed
43400d2d 467 if(pClu->Q()>qRef){ //searching the highest charge to select a MIP
468 qRef = pClu->Q();
469 mipId=iClu; mipX=pClu->X();mipY=pClu->Y();mipQ=(Int_t)pClu->Q();
470 }
471 }//clusters loop
43400d2d 472
5b2b2013 473 fNClu = pCluLst->GetEntriesFast();
3b49956b 474 if(qRef>pParam->QCut()){ //charge compartible with MIP clusters
611e810d 475 fIdxMip = mipId;
5b2b2013 476 fClCk[mipId] = kFALSE;
611e810d 477 fMipX = mipX; fMipY=mipY; fMipQ = qRef;
3b49956b 478 if(!DoRecHiddenTrk(pCluLst)) {
479 pTrk->SetHMPIDsignal(kNoPhotAccept);
480 return kFALSE;
481 } //Do track and ring reconstruction,if problems returns 1
482 pTrk->SetHMPIDtrk(fRadX,fRadY,fThTrkFit,fPhTrkFit); //store track intersection info
483 pTrk->SetHMPIDmip(fMipX,fMipY,(Int_t)fMipQ,fNClu); //store mip info
484 pTrk->SetHMPIDcluIdx(nCh,fIdxMip); //set cham number and index of cluster
485 pTrk->SetHMPIDsignal(fCkovFit); //find best Theta ckov for ring i.e. track
486 pTrk->SetHMPIDchi2(fCkovSig2); //errors squared
487// Printf(" n clusters tot %i accepted %i",pCluLst->GetEntriesFast(),fNClu);
5b2b2013 488 return kTRUE;
611e810d 489 }
3b49956b 490
5b2b2013 491 return kFALSE;
43400d2d 492}//CkovHiddenTrk()
493//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5b2b2013 494Bool_t AliHMPIDRecon::DoRecHiddenTrk(TClonesArray *pCluLst)
43400d2d 495{
496// Pattern recognition method without any infos from tracking...
611e810d 497// First a preclustering filter to avoid part of the noise
43400d2d 498// Then only ellipsed-rings are fitted (no possibility,
611e810d 499// for the moment, to reconstruct very inclined tracks)
500// Finally a fitting with (th,ph) free, starting by very close values
43400d2d 501// previously evaluated.
502// Arguments: none
503// Returns: none
504 Double_t phiRec;
5b2b2013 505 if(!CluPreFilter(pCluLst)) {return kFALSE;}
611e810d 506 if(!FitEllipse(phiRec)) {return kFALSE;}
5b2b2013 507 Int_t nClTmp1 = pCluLst->GetEntriesFast()-1; //minus MIP...
508 Int_t nClTmp2 = 0;
509 while(nClTmp1 != nClTmp2){
510 SetNClu(pCluLst->GetEntriesFast());
511 if(!FitFree(phiRec)) {return kFALSE;}
512 nClTmp2 = NClu();
513 if(nClTmp2!=nClTmp1) {nClTmp1=nClTmp2;nClTmp2=0;}
514 }
515 fNClu = nClTmp2;
516 return kTRUE;
517}//DoRecHiddenTrk()
43400d2d 518//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5b2b2013 519Bool_t AliHMPIDRecon::CluPreFilter(TClonesArray *pCluLst)
43400d2d 520{
521// Filter of bkg clusters
522// based on elliptical-shapes...
523//
5b2b2013 524 if(pCluLst->GetEntriesFast()>50||pCluLst->GetEntriesFast()<4) return kFALSE;
525 else return kTRUE;
43400d2d 526}
527//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
528Bool_t AliHMPIDRecon::FitEllipse(Double_t &phiRec)
529{
530//Fit a set of clusters with an analitical conical section function:
531 //
532 // Ax^2 + B*y^2 + 2Hxy + 2Gx + 2Fy + 1 = 0 ---> conical section
533 //
534 // H*H - A*B > 0 hyperbola
535 // < 0 ellipse
536 // = 0 parabola
537 //
538 // tan 2alfa = 2H/(A-B) alfa=angle of rotation
539 //
540 // coordinate of the centre of the conical section:
541 // x = x' + a
542 // y = y' + b
543 //
544 // HF - BG
545 // a = ---------
546 // AB - H^2
547 //
548 // HG - AF
549 // b = --------
550 // AB - H^2
43400d2d 551 Double_t cA,cB,cF,cG,cH;
611e810d 552 Double_t aArg=-1; Int_t iErrFlg; //tmp vars for TMinuit
43400d2d 553
611e810d 554 if(!gMinuit) gMinuit = new TMinuit(5); //init MINUIT with this number of parameters (5 params)
43400d2d 555 gMinuit->mncler(); // reset Minuit list of paramters
556 gMinuit->SetObjectFit((TObject*)this); gMinuit->SetFCN(AliHMPIDRecon::FunMinEl); //set fit function
c0d7adf8 557 gMinuit->mnexcm("SET PRI",&aArg,1,iErrFlg); //suspend all printout from TMinuit
558 gMinuit->mnexcm("SET NOW",&aArg,0,iErrFlg); //suspend all warning printout from TMinuit
43400d2d 559
560 Double_t d1,d2,d3;
561 TString sName;
562
611e810d 563 gMinuit->mnparm(0," A ",1,0.01,0,0,iErrFlg);
564 gMinuit->mnparm(1," B ",1,0.01,0,0,iErrFlg);
565 gMinuit->mnparm(2," H ",1,0.01,0,0,iErrFlg);
566 gMinuit->mnparm(3," G ",1,0.01,0,0,iErrFlg);
567 gMinuit->mnparm(4," F ",1,0.01,0,0,iErrFlg);
43400d2d 568
3b49956b 569 gMinuit->mnexcm("SIMPLEX",&aArg,0,iErrFlg);
43400d2d 570 gMinuit->mnexcm("MIGRAD" ,&aArg,0,iErrFlg);
571 gMinuit->mnpout(0,sName,cA,d1,d2,d3,iErrFlg);
572 gMinuit->mnpout(1,sName,cB,d1,d2,d3,iErrFlg);
573 gMinuit->mnpout(2,sName,cH,d1,d2,d3,iErrFlg);
574 gMinuit->mnpout(3,sName,cG,d1,d2,d3,iErrFlg);
575 gMinuit->mnpout(4,sName,cF,d1,d2,d3,iErrFlg);
576 delete gMinuit;
577
578 Double_t i2 = cA*cB-cH*cH; //quartic invariant : i2 > 0 ellipse, i2 < 0 hyperbola
096ddc3f 579 if(i2<=0) return kFALSE;
43400d2d 580 Double_t aX = (cH*cF-cB*cG)/i2; //x centre of the canonical section
581 Double_t bY = (cH*cG-cA*cF)/i2; //y centre of the canonical section
582 Double_t alfa1 = TMath::ATan(2*cH/(cA-cB)); //alpha = angle of rotation of the conical section
583 if(alfa1<0) alfa1+=TMath::Pi();
584 alfa1*=0.5;
3b49956b 585// Double_t alfa2 = alfa1+TMath::Pi();
586 Double_t phiref = TMath::ATan2(bY-fMipY,aX-fMipX); //evaluate in a unique way the angle of rotation comparing it
587 if(phiref<0) phiref+=TMath::TwoPi(); //with the vector that points to the centre from the mip
43400d2d 588 if(i2<0) phiref+=TMath::Pi();
589 if(phiref>TMath::TwoPi()) phiref-=TMath::TwoPi();
590
591// Printf(" alfa1 %f",alfa1*TMath::RadToDeg());
592// Printf(" alfa2 %f",alfa2*TMath::RadToDeg());
593// Printf(" firef %f",phiref*TMath::RadToDeg());
3b49956b 594// if(TMath::Abs(alfa1-phiref)<TMath::Abs(alfa2-phiref)) phiRec = alfa1; else phiRec = alfa2;
43400d2d 595
3b49956b 596// Printf("FitEllipse: phi reconstructed %f",phiRec*TMath::RadToDeg());
597 phiRec=phiref;
096ddc3f 598 return kTRUE;
43400d2d 599//
600}
601//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
611e810d 602Bool_t AliHMPIDRecon::FitFree(Double_t phiRec)
43400d2d 603{
604// Fit performed by minimizing RMS/sqrt(n) of the
605// photons reconstructed. First phi is fixed and theta
606// is fouond, then (th,ph) of the track
607// as free parameters
608// Arguments: PhiRec phi of the track
609// Returns: none
611e810d 610 Double_t aArg=-1; Int_t iErrFlg; //tmp vars for TMinuit
611 if(!gMinuit) gMinuit = new TMinuit(2); //init MINUIT with this number of parameters (5 params)
43400d2d 612 gMinuit->mncler(); // reset Minuit list of paramters
613 gMinuit->SetObjectFit((TObject*)this); gMinuit->SetFCN(AliHMPIDRecon::FunMinPhot); //set fit function
614 gMinuit->mnexcm("SET PRI",&aArg,1,iErrFlg); //suspend all printout from TMinuit
615 gMinuit->mnexcm("SET NOW",&aArg,0,iErrFlg); //suspend all warning printout from TMinuit
616
617 Double_t d1,d2,d3;
618 TString sName;
619 Double_t th,ph;
620
611e810d 621 gMinuit->mnparm(0," theta ", 0.01,0.01,0,TMath::PiOver2(),iErrFlg);
622 gMinuit->mnparm(1," phi ",phiRec,0.01,0,TMath::TwoPi() ,iErrFlg);
43400d2d 623
624 gMinuit->FixParameter(1);
625 gMinuit->mnexcm("SIMPLEX" ,&aArg,0,iErrFlg);
626 gMinuit->mnexcm("MIGRAD" ,&aArg,0,iErrFlg);
627 gMinuit->Release(1);
628 gMinuit->mnexcm("MIGRAD" ,&aArg,0,iErrFlg);
629
630 gMinuit->mnpout(0,sName,th,d1,d2,d3,iErrFlg);
631 gMinuit->mnpout(1,sName,ph,d1,d2,d3,iErrFlg);
611e810d 632
633 Double_t outPar[2] = {th,ph}; Double_t g; Double_t f;Int_t flag = 3;
634 gMinuit->Eval(2, &g, f, outPar,flag);
635
636 SetTrkFit(th,ph);
43400d2d 637
611e810d 638 return kTRUE;
43400d2d 639}
640//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
641Double_t AliHMPIDRecon::FunConSect(Double_t *c,Double_t x,Double_t y)
642{
643 return c[0]*x*x+c[1]*y*y+2*c[2]*x*y+2*c[3]*x+2*c[4]*y+1;
644}
645//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
646void AliHMPIDRecon::FunMinEl(Int_t &/* */,Double_t* /* */,Double_t &f,Double_t *par,Int_t /* */)
647{
648 AliHMPIDRecon *pRec=(AliHMPIDRecon*)gMinuit->GetObjectFit();
649 Double_t minFun = 0;
650 Int_t np = pRec->NClu();
651 for(Int_t i=0;i<np;i++) {
652 if(i==pRec->IdxMip()) continue;
653 Double_t el = pRec->FunConSect(par,pRec->XClu(i),pRec->YClu(i));
654 minFun +=el*el;
655 }
656 f = minFun;
657}
658//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
611e810d 659void AliHMPIDRecon::FunMinPhot(Int_t &/* */,Double_t* /* */,Double_t &f,Double_t *par,Int_t iflag)
43400d2d 660{
661 AliHMPIDRecon *pRec=(AliHMPIDRecon*)gMinuit->GetObjectFit();
611e810d 662 Double_t sizeCh = 0.5*fgkRadThick+fgkWinThick+fgkGapThick;
43400d2d 663 Double_t thTrk = par[0];
664 Double_t phTrk = par[1];
665 Double_t xrad = pRec->MipX() - sizeCh*TMath::Tan(thTrk)*TMath::Cos(phTrk);
666 Double_t yrad = pRec->MipY() - sizeCh*TMath::Tan(thTrk)*TMath::Sin(phTrk);
611e810d 667 pRec->SetRadXY(xrad,yrad);
43400d2d 668 pRec->SetTrack(xrad,yrad,thTrk,phTrk);
669
5b2b2013 670 Double_t meanCkov =0;
43400d2d 671 Double_t meanCkov2=0;
672 Double_t thetaCer,phiCer;
5b2b2013 673 Int_t nClAcc = 0;
674 Int_t nClTot=pRec->NClu();
675
676 for(Int_t i=0;i<nClTot;i++) {
677 if(!(pRec->ClCk(i))) continue;
43400d2d 678 pRec->FindPhotCkov(pRec->XClu(i),pRec->YClu(i),thetaCer,phiCer);
43400d2d 679 meanCkov += thetaCer;
680 meanCkov2 += thetaCer*thetaCer;
5b2b2013 681 nClAcc++;
43400d2d 682 }
096ddc3f 683 if(nClAcc==0) {f=999;return;}
5b2b2013 684 meanCkov/=nClAcc;
096ddc3f 685 Double_t rms = (meanCkov2 - meanCkov*meanCkov*nClAcc)/nClAcc;
686 if(rms<0) Printf(" rms2 = %f, strange!!!",rms);
687 rms = TMath::Sqrt(rms);
5b2b2013 688 f = rms/TMath::Sqrt(nClAcc);
611e810d 689
5b2b2013 690
691 if(iflag==3) {
692 Printf("FunMinPhot before: photons candidates %i used %i",nClTot,nClAcc);
693 nClAcc = 0;
694 Double_t meanCkov1=0;
3b49956b 695 Double_t meanCkov2=0;
5b2b2013 696 for(Int_t i=0;i<nClTot;i++) {
697 if(!(pRec->ClCk(i))) continue;
698 pRec->FindPhotCkov(pRec->XClu(i),pRec->YClu(i),thetaCer,phiCer);
699 if(TMath::Abs(thetaCer-meanCkov)<2*rms) {
3b49956b 700 meanCkov1 += thetaCer;
701 meanCkov2 += thetaCer*thetaCer;
5b2b2013 702 nClAcc++;
703 } else pRec->SetClCk(i,kFALSE);
704 }
705 meanCkov1/=nClAcc;
3b49956b 706 Double_t rms2 = (meanCkov2 - meanCkov*meanCkov*nClAcc)/nClAcc;
5b2b2013 707 Printf("FunMinPhot after: photons candidates %i used %i thetaCer %f",nClTot,nClAcc,meanCkov1);
708 pRec->SetCkovFit(meanCkov1);
3b49956b 709 pRec->SetCkovSig2(rms2);
5b2b2013 710 pRec->SetNClu(nClAcc);
711 }
43400d2d 712}//FunMinPhot()
611e810d 713//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
714//
715// ended Hidden track algorithm....
716//
717//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++