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