3 #ifndef ALIHLTGLOBALTRACKMATCHER_H
4 #define ALIHLTGLOBALTRACKMATCHER_H
7 //* This file is property of and copyright by the ALICE HLT Project *
8 //* ALICE Experiment at CERN, All rights reserved. *
9 //* See cxx source for full Copyright notice *
11 /** @file AliHLTGlobalTrackMatcher.h
12 @author Svein Lindal (svein.lindal@fys.uio.no)
14 @brief The HLT class matching TPC tracks to calorimeter clusters
19 #include "AliHLTLogging.h"
20 #include "AliESDtrack.h"
21 #include "TObjArray.h"
24 #include "AliTrackerBase.h" // Marcel: for EMCal track-matching
26 class AliHLTGlobalTrackMatcher : public AliHLTLogging{
29 AliHLTGlobalTrackMatcher();
32 virtual ~AliHLTGlobalTrackMatcher();
34 //Main function, loops over tracks and calls appropriate functions to establish matches
36 Int_t Match( TObjArray * trackArray, vector<T*> &phosClustersVector, vector<T*> &emcalClustersVector, Double_t bz, Int_t Method );
43 //Loops over clusters and decides if track is a good match to any of these
45 Int_t MatchTrackToClusters( AliExternalTrackParam * track, vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz);
48 Int_t MatchTrackToEMCalClusters( AliExternalTrackParam * track, vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz, Int_t Method); // EMCal Track-Matching from recoUtils::ExtrapolateTracktoCluster
50 //Add track Id to cluster's list of matching tracks
51 Int_t AddTrackToCluster(Int_t tId, Int_t* clustersArray, Bool_t bestMatch, Int_t nMatches);
52 Int_t AddTrackToCluster(Int_t tId, TArrayI* clustersArray, Bool_t bestMatch, Int_t nMatches);
54 //Projects track to detector volume and decides if it's anywhere near calorimeter volume
55 Bool_t IsTrackCloseToDetector(AliExternalTrackParam * track, Double_t bz, Double_t fMaxX, Bool_t ySign, Double_t fMaxZ, Double_t dRadius);
57 // Geometrical cut off values used to decide whether track is anywhere near calorimeter volumes
58 Float_t fPhosMaxZ; // max Z track (cm)
59 Float_t fPhosMaxX; // max X track (cm)
60 Float_t fEmcalMaxZ; // max Z track (cm)
61 Float_t fEmcalMaxX; // max X track (cm)
63 Float_t fMatchDistance; // Square of maximum distance where track is considered a match to cluster (cm^2)
64 Float_t fMatchDistanceEMCal; // Square of maximum distance where track is considered a match to cluster (EtaxPhi space)
66 const Double_t fPhosRadius; // Radial position of PHOS
67 const Double_t fEmcalRadius; // Radial position of EMCAL
69 Float_t fStep; // Step for EMCal Extrapolation Calculation
70 Float_t fMass; // Mass for EMCal Extrapolation hipothesis
72 AliHLTGlobalTrackMatcher(const AliHLTGlobalTrackMatcher & );
73 AliHLTGlobalTrackMatcher & operator = (const AliHLTGlobalTrackMatcher &);
75 ClassDef(AliHLTGlobalTrackMatcher,1)
80 Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*> &phosClustersVector, vector<T*> &emcalClustersVector, Double_t bz, Int_t Method ) {
81 //Method for extrapolation EMcal
82 //See above for documentation
84 Int_t nTracks = trackArray->GetEntriesFast();
85 Int_t nPhosClusters = phosClustersVector.size();
86 Int_t nEmcalClusters = emcalClustersVector.size();
89 //HLTError("tracks phos emcal %d %d %d", nTracks, nPhosClusters, nEmcalClusters);
91 //See if there are tracks and clusters to match
94 } else if ( (nEmcalClusters <= 0) && (nPhosClusters <= 0)) {
99 Float_t bestMatchPhos[nPhosClusters];
100 for(int ic = 0; ic < nPhosClusters; ic++) {
101 bestMatchPhos[ic] = 999999;
104 Float_t bestMatchEmcal[nEmcalClusters];
105 for(int ic = 0; ic < nEmcalClusters; ic++) {
106 bestMatchEmcal[ic] = 999999;
110 for (int it = 0; it < nTracks; it++ ) {
111 AliExternalTrackParam * track = static_cast<AliExternalTrackParam*>(trackArray->At(it));
113 if ( IsTrackCloseToDetector(track, bz, fEmcalMaxX, kTRUE, fEmcalMaxZ, fEmcalRadius ) ) {
114 if(Method!=1&&Method!=2){
115 HLTError("\n Method %d is not valid",Method);
116 return 0; // No method defined
118 MatchTrackToEMCalClusters( track, emcalClustersVector, nEmcalClusters, bestMatchEmcal, bz,Method); //With Method
120 } else if ( IsTrackCloseToDetector(track, bz, fPhosMaxX, kFALSE, fPhosMaxZ, fPhosRadius ) ) {
121 MatchTrackToClusters( track, phosClustersVector, nPhosClusters, bestMatchPhos, bz);
130 Int_t AliHLTGlobalTrackMatcher::MatchTrackToEMCalClusters( AliExternalTrackParam * track, vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz, Int_t Method ) {
132 //See header file for documentation
134 Float_t clusterPosition[3];
136 for(int ic = 0; ic < nClusters; ic++) {
138 T * cluster = clustersVector.at(ic);
140 if(cluster->E()<1.)continue;
141 /* The lines below correspond to the method for Track-matching from RecoUtils:ExtrapolatetoCluster
142 In principle, the method ExtrapolateToCluster should be called directly from RecoUtils. The problems is that This method requires AliVCluster
143 which would have to be created inside the GlobalMatcher, since the information this class obtains from the Cluster comes from the
144 data struct with the cluster information. In order to avoid the whole creation of a AliVCluster object, the code from RecoUtils
145 was brought here in the same way it is written there.
147 cluster->GetPosition(clusterPosition);
148 TVector3 vec(clusterPosition[0],clusterPosition[1],clusterPosition[2]);
149 if(clusterPosition[1]<0.) continue;
150 if(TMath::Abs(track->Eta()-vec.Eta())>0.3) continue;
152 AliExternalTrackParam *trkParam = new AliExternalTrackParam(*track);//Retrieve the starting point every time before the extrapolation
153 Double_t trkPos[3] = {0, 0, 0};
154 Double_t alpha = ((int)(vec.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad();
155 vec.RotateZ(-alpha); //Rotate the cluster to the local extrapolation coordinate system
156 trkParam->Rotate(alpha); //Rotate the track to the same local extrapolation system
157 if(1==Method&&!trkParam->GetXYZAt(vec.X(), bz, trkPos)) continue; // Simpler extrapolation
159 if(!AliTrackerBase::PropagateTrackToBxByBz(trkParam, vec.X(), fMass, fStep,kFALSE, 0.8, -1)) continue;
160 trkParam->GetXYZ(trkPos); //Get the extrapolated global position
163 TVector3 clsPosVec(clusterPosition[0],clusterPosition[1],clusterPosition[2]);
164 TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
166 // track cluster matching
167 Double_t tmpPhi = clsPosVec.DeltaPhi(trkPosVec); // tmpPhi is between -pi and pi
168 Double_t tmpEta = clsPosVec.Eta()-trkPosVec.Eta(); // track cluster matching
169 Double_t match=TMath::Sqrt(tmpEta*tmpEta + tmpPhi*tmpPhi);//MARCEL
171 if( match > fMatchDistanceEMCal )continue;
173 if (match < bestMatch[ic]) {
174 bestMatch[ic] = match;
175 cluster->SetEmcCpvDistance(TMath::Sqrt(match));
178 cluster->SetTrackDistance(dx,dz);
180 //Add track to cluster's array of matching tracks
181 Int_t nTracksMatched = cluster->GetNTracksMatched();
182 iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched);
189 Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * track, vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz) {
191 //See header file for documentation
194 Float_t clusterPosition[3];
195 Double_t trackPosition[3];
197 for(int ic = 0; ic < nClusters; ic++) {
199 T * cluster = clustersVector.at(ic);
201 //Get cluster global coordinates
202 cluster->GetPosition(clusterPosition);
204 Double_t rCluster = TMath::Sqrt(clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1]);
206 //Rotate tracking system to the angle of the cluster
207 TVector3 cVec(clusterPosition);
208 if (! (track->Rotate(cVec.Phi())) ) {
212 if(! (track->GetXYZAt(rCluster, bz, trackPosition)) ) {
216 //Calculate track - cluster residuals
218 for(int i = 0; i < 3; i++) {
219 Double_t dd = trackPosition[i] - clusterPosition[i];
224 if( match > fMatchDistance ) {
228 if (match < bestMatch[ic]) {
230 bestMatch[ic] = match;
231 cluster->SetEmcCpvDistance(TMath::Sqrt(match));
233 Double_t dx = trackPosition[0] - clusterPosition[0];
234 Double_t dy = trackPosition[1] - clusterPosition[1];
235 Double_t dz = trackPosition[2] - clusterPosition[2];
236 cluster->SetTrackDistance( ((dx > 0) ? 1 : -1 )*TMath::Sqrt(dx*dx + dy*dy), dz);
239 //Add track to cluster's array of matching tracks
240 Int_t nTracksMatched = cluster->GetNTracksMatched();
241 iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched);