- Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
- Int_t * maxAt = new Int_t[nMultipl] ;
- Float_t * maxAtEnergy = new Float_t[nMultipl] ;
- Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
-
- if(nMax <= 1 ) // if cluster is very flat (no pronounced maximum) then nMax = 0
- emcOut->Add(emcRecPoint) ;
- else if (fUnfoldFlag) {
- UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy, emcOut) ;
- emcIn->Remove(emcRecPoint);
- emcIn->Compress() ;
- nEmcUnfolded-- ;
- index-- ;
+ if(trackindex>=0)
+ AliDebug(1,Form("\t\tBest match for (xClu,zClu,eClu)=(%.3f,%.3f,%.3f): iTrack=%d, dR=%.3f",
+ locClu.X(),locClu.Z(),emcClu->GetEnergy(),
+ trackindex,TMath::Sqrt(dx*dx+dz*dz)));
+ return;
+
+ Float_t distance2Track = fRtpc ;
+
+ trackindex = -1 ; // closest track within fRCpv
+
+ TVector3 vecEmc ; // Local position of EMC recpoint
+ TVector3 vecPloc ; // Momentum direction at CPV plain
+
+ //toofar = kTRUE ;
+ if(emcClu->GetPHOSMod() != cpvClu->GetPHOSMod()){
+ dx=999. ;
+ dz=999. ;
+ return ;
+ }
+
+ emcClu->GetLocalPosition(vecEmc) ;
+
+ Double_t xCPV,zCPV ; //EMC-projected coordinates of CPV cluster
+ TVector3 cpvGlobal; // Global position of the CPV recpoint
+ fGeom->GetGlobalPHOS((AliPHOSRecPoint*)cpvClu,cpvGlobal);
+ Double_t vtxCPV[3]={cpvGlobal.X(),cpvGlobal.Y(),cpvGlobal.Z()} ;
+ Int_t dummyMod ;
+
+ if (fESD == 0x0) {
+ //if no track information available, assume straight line from IP to emcal
+ fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
+ dx=xCPV - vecEmc.X() ;
+ dz=zCPV - vecEmc.Z() ;
+ return ;
+ }
+
+ //if there is ESD try to correct distance using TPC information on particle direct in CPV
+ if (fESD != 0x0) {
+
+ Double_t rCPV = cpvGlobal.Pt() ;// Radius from IP to current point
+
+ // Extrapolate the global track direction if any to CPV and find the closest track
+ Int_t iClosestTrack = -1;
+ TVector3 inPHOS ;
+
+ for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
+ track = fESD->GetTrack(iTrack);
+ if (!track->GetXYZAt(rCPV, fESD->GetMagneticField(), xyz))
+ continue; //track coord on the cylinder of PHOS radius
+ if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
+ continue;
+ //Check if this track hits PHOS
+ inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
+ distance2Track = inPHOS.Angle(cpvGlobal) ;
+ // Find the closest track to the CPV recpoint
+ if (distance2Track < minDistance) {
+ minDistance = distance2Track;
+ iClosestTrack = iTrack;
+ }
+ }
+
+ if (iClosestTrack != -1) {
+ track = fESD->GetTrack(iClosestTrack);
+ if (track->GetPxPyPzAt(rCPV, fESD->GetMagneticField(), pxyz)) { // track momentum ibid.
+ vecP.SetXYZ(pxyz[0],pxyz[1],pxyz[2]);
+ fGeom->ImpactOnEmc(vtxCPV,vecP.Theta(),vecP.Phi(),dummyMod,zCPV,xCPV) ;
+ }