-Double_t AliEMCALTracker::AngleDiff(Double_t angle1, Double_t angle2)
-{
- //
- // [PRIVATE]
- // Given two angles in radiants, it converts them in the range 0-2pi
- // then computes their true difference, i.e. if the difference a1-a2
- // results to be larger than 180 degrees, it returns 360 - diff.
- //
-
- if (angle1 < 0.0) angle1 += TMath::TwoPi();
- if (angle1 > TMath::TwoPi()) angle1 -= TMath::TwoPi();
- if (angle2 < 0.0) angle2 += TMath::TwoPi();
- if (angle2 > TMath::TwoPi()) angle2 -= TMath::TwoPi();
-
- Double_t diff = TMath::Abs(angle1 - angle2);
- if (diff > TMath::Pi()) diff = TMath::TwoPi() - diff;
-
- if (angle2 > angle1) diff = -diff;
-
- return diff;
-}
-//
-//------------------------------------------------------------------------------
-//
-Double_t AliEMCALTracker::CheckPair
-(AliEMCALTrack *track, AliEMCALMatchCluster *cl)
-{
- //
- // Given a track and a cluster,
- // propagates the first to the radius of the second.
- // Then, checks the propagation point against all cuts.
- // If at least a cut is not passed, a valuer equal to
- // twice the maximum allowed distance is passed (so the value returned
- // will not be taken into account when creating matches)
- //
-
- // TEMP
- Bool_t isTrue = kFALSE;
-// if (tr->GetSeedLabel() == cl->Label()) {
-// isTrue = kTRUE;
-// }
-
- // copy track into temporary variable
- AliEMCALTrack *tr = new AliEMCALTrack(*track);
-
- Double_t distance = 2.0 * fMaxDist;
-
- // check against cut on difference 'alpha - phi'
- Double_t phi = TMath::ATan2(cl->Y(), cl->X());
- phi = AngleDiff(phi, tr->GetAlpha());
- if (phi < fCutAlphaMin || phi > fCutAlphaMax){
- delete tr;
- return distance;
- }
-
- // try to propagate to cluster radius
- // (return the 'distance' value if it fails)
- Double_t pos[3], &x = pos[0], &y = pos[1], &z = pos[2];
- Double_t x0, rho;
- tr->GetXYZ(pos);
- Double_t rt = TMath::Sqrt(x*x + y*y);
- Double_t rc = TMath::Sqrt(cl->X()*cl->X() + cl->Y()*cl->Y());
-
- if (fTrackCorrMode == kTrackCorrMMB) {
- Double_t pos1[3], pos2[3], param[6];
- pos1[0] = x;
- pos1[1] = y;
- pos1[2] = z;
- pos2[0] = cl->X();
- pos2[1] = cl->Y();
- pos2[2] = cl->Z();
- MeanMaterialBudget(pos1, pos2, param);
- rho = param[0]*param[4];
- x0 = param[1];
- }
- else if (fTrackCorrMode == kTrackCorrFixed) {
- rho = fRho;
- x0 = fX0;
- }
- else {
- rho = 0.0;
- x0 = 0.0;
- }
- if (fNPropSteps) {
- Int_t i;
- Double_t r;
- cout.setf(ios::fixed);
- cout.precision(5);
- if (isTrue) cout << "Init : " << rt << ' ' << x << ' ' << y << ' ' << z << endl;
- for (i = 0; i < fNPropSteps; i++) {
- r = rt + (rc - rt) * ((Double_t)(i+1)/(Double_t)fNPropSteps);
- if (!tr->PropagateTo(r, x0, rho)){
- delete tr;
- return distance;
- }
- tr->GetXYZ(pos);
- if (isTrue) cout << "Step : " << r << ' ' << x << ' ' << y << ' ' << z << endl;
- }
- if (isTrue) cout << "Clstr: " << rc << ' ' << cl->X() << ' ' << cl->Y() << ' ' << cl->Z() << endl;
- }
- else {
- // when no steps are used, no correction makes sense
- //if (!tr->PropagateTo(rc, 0.0, 0.0)) return distance;
- if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)){
- delete tr;
- return distance;
- }
- /*
- Bool_t propOK = kFALSE;
- cout << "START" << endl;
- Double_t dist, rCHK, bestDist = 10000000.0;
- for (Double_t rTMP = rc; rTMP> rc*0.95; rTMP -= 0.1) {
- if (!tr->PropagateTo(rTMP)) continue;
- propOK = kTRUE;
- tr->GetXYZ(pos);
- rCHK = TMath::Sqrt(x*x + y*y);
- dist = TMath::Abs(rCHK - rc);
- cout << rCHK << " vs. " << rc << endl;
-
- if (TMath::Abs(rCHK - rc) < 0.01) break;
- }
- cout << "STOP" << endl;
- if (!propOK) return distance;
- */
- }
-
- // get global propagation of track at end of propagation
- tr->GetXYZ(pos);
-
- // check angle cut
- TVector3 vc(cl->X(), cl->Y(), cl->Z());
- TVector3 vt(x, y, z);
- Double_t angle = TMath::Abs(vc.Angle(vt)) * TMath::RadToDeg();
- // check: where is the track?
- Double_t r, phiT, phiC;
- r = TMath::Sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
- phiT = TMath::ATan2(pos[1], pos[0]) * TMath::RadToDeg();
- phiC = vc.Phi() * TMath::RadToDeg();
- //cout << "Propagated R, phiT, phiC = " << r << ' ' << phiT << ' ' << phiC << endl;
-
- if (angle > fCutAngle) {
- //cout << "angle" << endl;
- delete tr;
- return distance;
- }
-
- // compute differences wr to each coordinate
- x -= cl->X();
- if (TMath::Abs(x) > fCutX) {
- //cout << "cut X" << endl;
- delete tr;
- return distance;
- }
- y -= cl->Y();
- if (TMath::Abs(y) > fCutY) {
- //cout << "cut Y" << endl;
- delete tr;
- return distance;
- }
- z -= cl->Z();
- if (TMath::Abs(z) > fCutZ) {
- //cout << "cut Z" << endl;
- delete tr;
- return distance;
- }
-
- // compute true distance
- distance = TMath::Sqrt(x*x + y*y + z*z);
- //Double_t temp = CheckPairV2(tr, cl);
- //if (temp < distance) return temp; else
-
- // delete temporary object
- delete tr;
-
- return distance;
-}
-//
-//------------------------------------------------------------------------------
-//
-Double_t AliEMCALTracker::CheckPairV2
-(AliEMCALTrack *tr, AliEMCALMatchCluster *cl)
-{
- //
- // Given a track and a cluster,
- // propagates the first to the radius of the second.
- // Then, checks the propagation point against all cuts.
- // If at least a cut is not passed, a valuer equal to
- // twice the maximum allowed distance is passed (so the value returned
- // will not be taken into account when creating matches)
- //
-
- // TEMP
-// Bool_t isTrue = kFALSE;
-// if (tr->GetSeedLabel() == cl->Label()) {
-// isTrue = kTRUE;
-// cout << "TRUE MATCH!!!" << endl;
-// }
-
- Double_t distance = 2.0 * fMaxDist;
-
- Double_t x0, rho;
- if (fTrackCorrMode == kTrackCorrMMB) {
- Double_t pos1[3], pos2[3], param[6];
- tr->GetXYZ(pos1);
-// pos1[0] = x;
-// pos1[1] = y;
-// pos1[2] = z;
- pos2[0] = cl->X();
- pos2[1] = cl->Y();
- pos2[2] = cl->Z();
- MeanMaterialBudget(pos1, pos2, param);
- rho = param[0]*param[4];
- x0 = param[1];
- }
- else if (fTrackCorrMode == kTrackCorrFixed) {
- rho = fRho;
- x0 = fX0;
- }
- else {
- rho = 0.0;
- x0 = 0.0;
- }
-
- // check against cut on difference 'alpha - phi'
- Double_t phi = TMath::ATan2(cl->Y(), cl->X());
- phi = AngleDiff(phi, tr->GetAlpha());
- if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
-
- // get cluster position and put them into a vector
- TVector3 vc(cl->X(), cl->Y(), cl->Z());
- // rotate the vector in order to put all clusters on a plane intersecting
- // vertically the X axis; the angle depends on the sector
- Double_t clusterRot, clusterPhi = vc.Phi() * TMath::RadToDeg();
- if (clusterPhi < 0.0) clusterPhi += 360.0;
- if (clusterPhi < 100.0) {
- clusterRot = -90.0;
- }
- else if (clusterPhi < 120.0) {
- clusterRot = -110.0;
- }
- else if (clusterPhi < 140.0) {
- clusterRot = -130.0;
- }
- else if (clusterPhi < 160.0) {
- clusterRot = -150.0;
- }
- else if (clusterPhi < 180.0) {
- clusterRot = -170.0;
- }
- else {
- clusterRot = -190.0;
- }
- vc.RotateZ(clusterRot * TMath::DegToRad());
- // generate a track from the ESD track selected
- AliEMCALTrack *track = new AliEMCALTrack(*tr);
- // compute the 'phi' coordinate of the intersection point to
- // the EMCAL surface
- Double_t x = vc.X();
- Double_t y;
- track->GetYAt(vc.X(), track->GetBz(), y);
- Double_t tmp = x*TMath::Cos(track->GetAlpha()) - y*TMath::Sin(track->GetAlpha());
- y = x*TMath::Sin(track->GetAlpha()) + y*TMath::Cos(track->GetAlpha());
- x = tmp;
- Double_t trackPhi = TMath::ATan2(y, x) * TMath::RadToDeg();
- // compute phi difference
- Double_t dphi = trackPhi - clusterPhi;
- if (TMath::Abs(dphi) > 180.0) {
- dphi = 360.0 - TMath::Abs(dphi);
- if (clusterPhi > trackPhi) dphi = -dphi;
- }
- // propagate track to the X position of rotated cluster
- // and get the vector of X, Y, Z in the local ref. frame of the track
- track->PropagateTo(vc.X(), x0, rho);
- TVector3 vt(track->GetX(), track->GetY(), track->GetZ());
- vt.RotateZ((clusterPhi - trackPhi) * TMath::DegToRad());
- TVector3 vdiff = vt-vc;
-
- // compute differences wr to each coordinate
- delete track;
- if (vdiff.X() > fCutX) return distance;
- if (vdiff.Y() > fCutY) return distance;
- if (vdiff.Z() > fCutZ) return distance;
-
- // compute true distance
- distance = vdiff.Mag();
- return distance;
-}
-//
-//------------------------------------------------------------------------------
-//
-Double_t AliEMCALTracker::CheckPairV3
-(AliEMCALTrack *track, AliEMCALMatchCluster *cl)
-{
- //
- // Given a track and a cluster,
- // propagates the first to the radius of the second.
- // Then, checks the propagation point against all cuts.
- // If at least a cut is not passed, a valuer equal to
- // twice the maximum allowed distance is passed (so the value returned
- // will not be taken into account when creating matches)
- //
-
- AliEMCALTrack tr(*track);
-
- Int_t sector;
- Double_t distance = 2.0 * fMaxDist;
- Double_t dx, dy, dz;
- Double_t phi, alpha, slope, tgtXnum, tgtXden, sectorWidth = 20.0 * TMath::DegToRad();
- Double_t xcurr, xprop, param[6] = {0., 0., 0., 0., 0., 0.}, x0, rho, bz;
- Double_t x[3], x1[3], x2[3];
-
- // get initial track position
- xcurr = tr.GetX();
-
- // evaluate the EMCAL sector number
- phi = cl->Phi();
- if (phi < 0.0) phi += TMath::TwoPi();
- sector = (Int_t)(phi / sectorWidth);
- alpha = ((Double_t)sector + 0.5) * sectorWidth;
- // evaluate the corresponding X for track propagation
- slope = TMath::Tan(alpha - 0.5*TMath::Pi());
- tgtXnum = cl->Y() - slope * cl->X();
- tgtXden = TMath::Sqrt(1.0 + slope*slope);
- xprop = TMath::Abs(tgtXnum / tgtXden);
-
- // propagate by small steps
- tr.GetXYZ(x1);
- bz = tr.GetBz();
- if (!tr.GetXYZAt(xprop, bz, x2)) return distance;
- //AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
- rho = param[0]*param[4];
- x0 = param[1];
- if (!tr.PropagateTo(xprop, x0, rho)) return distance;
- //if (!tr.PropagateTo(xprop, 0.0, 0.0)) return distance;
-
- // get propagated position at the end
- tr.GetXYZ(x);
- dx = TMath::Abs(x[0] - cl->X());
- dy = TMath::Abs(x[1] - cl->Y());
- dz = TMath::Abs(x[2] - cl->Z());
- if (dx > fCutX || dy > fCutY || dz > fCutZ) return distance;
-
- distance = TMath::Sqrt(dx*dx + dy*dy + dz*dz);
-
- return distance;
-}
-//
-//------------------------------------------------------------------------------
-//
-Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
-{
- //
- // Propagates the track to the proximity of the EMCAL surface
- //
-
- Double_t xcurr, xtemp, xprop = 438.0, step = 10.0, param[6], x0, rho, bz;
- Double_t x1[3], x2[3];
-
- // get initial track position
- xcurr = tr->GetX();
-
- // propagate by small steps
- for (xtemp = xcurr + step; xtemp < xprop; xtemp += step) {
- // to compute material budget, take current position and
- // propagated hypothesis without energy loss
- tr->GetXYZ(x1);
- bz = tr->GetBz();
- if (!tr->GetXYZAt(xtemp, bz, x2)) return kFALSE;
- MeanMaterialBudget(x1, x2, param);
- rho = param[0]*param[4];
- x0 = param[1];
- if (!tr->PropagateTo(xtemp, x0, rho)) return kFALSE;
- }
-
- return kTRUE;
-}
-//
-//------------------------------------------------------------------------------
-//
-Int_t AliEMCALTracker::CreateMatches()
-{
- //
- // Creation of matches between tracks and clusters.
- // For each ESD track collected by ReadESD(), an AliEMCALTrack is made.
- // If it finds a cluster close enough to its propagation to EMCAL,
- // which passes all cuts, its index is stored.
- // If many clusters are found which satisfy the criteria described above,
- // only the closest one is stored.
- // At this level, it is possible that two tracks share the same cluster.
- //
-
- // if matches collection is already present, it is deleted
- if (fMatches) {
- fMatches->Delete();
- delete fMatches;
- }
- fMatches = new TList;
-
- // initialize counters and indexes
- Int_t count = 0;
- Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
- Int_t it, nTracks = fTracks->GetEntries();
-
- // external loop on clusters, internal loop on tracks
- Double_t dist;
- for (ic = 0; ic < nClusters; ic++) {
- AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
- for (it = 0; it < nTracks; it++) {
- AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
- dist = CheckPair(track, cluster);
- //cout << dist << endl;
- if (dist <= fMaxDist) {
- AliEMCALMatch *candidate = new AliEMCALMatch;
- candidate->SetIndexT(it);
- candidate->SetIndexC(ic);
- candidate->SetDistance(dist);
- candidate->SetPt(track->GetSignedPt());
- fMatches->Add(candidate);
- count++;
- }
- }
- }
-
- /*
- // loop on clusters and tracks
- Int_t icBest;
- Double_t dist, distBest;
- for (it = 0; it < nTracks; it++) {
- AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
- if (!track) continue;
- icBest = -1;
- distBest = fMaxDist;
- for (ic = 0; ic < nClusters; ic++) {
- AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
- if (!cluster) continue;
- dist = CheckPair(track, cluster);
- if (dist < distBest) {
- distBest = dist;
- icBest = ic;
- }
- }
- if (icBest >= 0) {
- track->SetMatchedClusterIndex(icBest);
- track->SetMatchedClusterDist(distBest);
- count++;
- }
- else {
- track->SetMatchedClusterIndex(-1);
- }
- }
- */
-
- return count;
-}
-//
-//------------------------------------------------------------------------------
-//
-Int_t AliEMCALTracker::SolveCompetitions()
-{
- //
- // Match selector.
- // The match list is sorted from the best to the worst match, w.r. to the
- // distance between track prolongation and cluster position.
- // Based on this criterion, starting from the first (best) match, a flag
- // is set to both the involved track and cluster, and all matches containing
- // an already used track or cluster are removed, leaving only the best match
- // for each cluster.
- //
-
- // sort matches with respect to track-cluster distance
- fMatches->Sort(kSortAscending);
-
- // keep track of eliminated matches
- Int_t count = 0;
-
- // initialize flags to check repetitions
- Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
- Int_t it, nTracks = fTracks->GetEntries();
- Bool_t *usedC = new Bool_t[nClusters];
- Bool_t *usedT = new Bool_t[nTracks];
- for (ic = 0; ic < nClusters; ic++) usedC[ic] = kFALSE;
- for (it = 0; it < nTracks; it++) usedT[it] = kFALSE;
-
- // loop on matches
- TListIter iter(fMatches);
- AliEMCALMatch *match = 0;
- while ( (match = (AliEMCALMatch*)iter.Next()) ) {
- ic = match->GetIndexC();
- it = match->GetIndexT();
- if (!usedT[it] && !usedC[ic]) {
- usedT[it] = kTRUE;
- usedC[ic] = kTRUE;
- match->CanBeSaved() = kTRUE;
- }
- else {
- count++;
- }
- }
-
- /*
- Int_t it1, it2, nTracks = (Int_t)fTracks->GetEntries();
- AliEMCALTrack *track1 = 0, *track2 = 0;
- for (it1 = 0; it1 < nTracks; it1++) {
- track1 = (AliEMCALTrack*)fTracks->At(it1);
- if (!track1) continue;
- if (track1->GetMatchedClusterIndex() < 0) continue;
- for (it2 = it1+1; it2 < nTracks; it2++) {
- track2 = (AliEMCALTrack*)fTracks->At(it2);
- if (!track2) continue;
- if (track2->GetMatchedClusterIndex() < 0) continue;
- if (track1->GetMatchedClusterIndex() != track2->GetMatchedClusterIndex()) continue;
- count++;
- if (track1->GetMatchedClusterDist() < track2->GetMatchedClusterDist()) {
- track2->SetMatchedClusterIndex(-1);
- }
- else if (track2->GetMatchedClusterDist() < track1->GetMatchedClusterDist()) {
- track1->SetMatchedClusterIndex(-1);
- }
- }
- }
- */
-
- delete [] usedC;
- delete [] usedT;