]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/global/AliHLTGlobalTrackMatcher.h
Updated track matcher to do PHOS and EMCAL in one instance
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalTrackMatcher.h
CommitLineData
434146d0 1//$Id$
2
3cfb9c56 3#ifndef ALIHLTGLOBALTRACKMATCHER_H
4#define ALIHLTGLOBALTRACKMATCHER_H
434146d0 5
6
3cfb9c56 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 *
10
11/** @file AliHLTGlobalTrackMatcher.h
12 @author Svein Lindal (svein.lindal@fys.uio.no)
13 @date
b3e7198f 14 @brief The HLT class matching TPC tracks to calorimeter clusters
3cfb9c56 15*/
16
17
3cfb9c56 18#include "AliHLTLogging.h"
19#include "AliESDtrack.h"
2a24cbbe 20#include "TObjArray.h"
21#include "TArrayI.h"
3cfb9c56 22
a46c7ba5 23class AliHLTGlobalTrackMatcher : public AliHLTLogging{
b3e7198f 24
3cfb9c56 25public:
26 AliHLTGlobalTrackMatcher();
b3e7198f 27
a46c7ba5 28 /** destructor */
3cfb9c56 29 virtual ~AliHLTGlobalTrackMatcher();
30
a46c7ba5 31 //Main function, loops over tracks and calls appropriate functions to establish matches
2a24cbbe 32 template <class T>
ec54c698 33 Int_t Match( TObjArray * trackArray, vector<T*> &phosClustersVector, vector<T*> &emcalClustersVector, Double_t bz );
a46c7ba5 34
35private:
36
434146d0 37 void DoInit();
bad7877b 38
2a24cbbe 39 //Loops over clusters and decides if track is a good match to any of these
40 template <class T>
41 Int_t MatchTrackToClusters( AliExternalTrackParam * track, vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz);
bad7877b 42
2a24cbbe 43 //Add track Id to cluster's list of matching tracks
44 Int_t AddTrackToCluster(Int_t tId, Int_t* clustersArray, Bool_t bestMatch, Int_t nMatches);
45 Int_t AddTrackToCluster(Int_t tId, TArrayI* clustersArray, Bool_t bestMatch, Int_t nMatches);
46
47 //Projects track to detector volume and decides if it's anywhere near calorimeter volume
48 Bool_t IsTrackCloseToDetector(AliExternalTrackParam * track, Double_t bz, Double_t fMaxX, Bool_t ySign, Double_t fMaxZ, Double_t dRadius);
49
50 // Geometrical cut off values used to decide whether track is anywhere near calorimeter volumes
a46c7ba5 51 Float_t fPhosMaxZ; // max Z track (cm)
52 Float_t fPhosMaxX; // max X track (cm)
53 Float_t fEmcalMaxZ; // max Z track (cm)
54 Float_t fEmcalMaxX; // max X track (cm)
55
56 Float_t fMatchDistance; // Square of maximum distance where track is considered a match to cluster (cm^2)
3cfb9c56 57
a46c7ba5 58 const Double_t fPhosRadius; // Radial position of PHOS
59 const Double_t fEmcalRadius; // Radial position of EMCAL
bad7877b 60
bc72e5b9 61 AliHLTGlobalTrackMatcher(const AliHLTGlobalTrackMatcher & );
62 AliHLTGlobalTrackMatcher & operator = (const AliHLTGlobalTrackMatcher &);
63
2a24cbbe 64 ClassDef(AliHLTGlobalTrackMatcher,1)
3cfb9c56 65};
66
2a24cbbe 67
68template <class T>
ec54c698 69Int_t AliHLTGlobalTrackMatcher::Match( TObjArray * trackArray, vector<T*> &phosClustersVector, vector<T*> &emcalClustersVector, Double_t bz ) {
2a24cbbe 70 //See above for documentation
71
ec54c698 72
2a24cbbe 73 Int_t nTracks = trackArray->GetEntriesFast();
ec54c698 74 Int_t nPhosClusters = phosClustersVector.size();
75 Int_t nEmcalClusters = emcalClustersVector.size();
a46c7ba5 76
ec54c698 77
78 //See if there are tracks and clusters to match
2a24cbbe 79 if ( nTracks <= 0 ) {
2a24cbbe 80 return 0;
ec54c698 81 } else if ( (nEmcalClusters <= 0) && (nPhosClusters <= 0)) {
2a24cbbe 82 return 0;
83 }
84
a46c7ba5 85 Float_t bestMatchPhos[nPhosClusters];
86 for(int ic = 0; ic < nPhosClusters; ic++) {
87 bestMatchPhos[ic] = 999999;
2a24cbbe 88 }
ec54c698 89
90 Float_t bestMatchEmcal[nEmcalClusters];
91 for(int ic = 0; ic < nEmcalClusters; ic++) {
92 bestMatchEmcal[ic] = 999999;
93 }
94
a46c7ba5 95 //Loop over tracks
2a24cbbe 96 for (int it = 0; it < nTracks; it++ ) {
97 AliExternalTrackParam * track = static_cast<AliExternalTrackParam*>(trackArray->At(it));
a46c7ba5 98
99 if ( IsTrackCloseToDetector(track, bz, fPhosMaxX, kFALSE, fPhosMaxZ, fPhosRadius ) ) {
ec54c698 100 MatchTrackToClusters( track, phosClustersVector, nPhosClusters, bestMatchPhos, bz);
101
102 } else if ( IsTrackCloseToDetector(track, bz, fEmcalMaxX, kTRUE, fEmcalMaxZ, fEmcalRadius ) ) {
103 MatchTrackToClusters( track, emcalClustersVector, nEmcalClusters, bestMatchEmcal, bz);
2a24cbbe 104 }
a46c7ba5 105
ec54c698 106 }
a46c7ba5 107
2a24cbbe 108 return 0;
a46c7ba5 109}
2a24cbbe 110
111
112
113template <class T>
114Int_t AliHLTGlobalTrackMatcher::MatchTrackToClusters( AliExternalTrackParam * track, vector<T*> &clustersVector, Int_t nClusters, Float_t * bestMatch, Double_t bz) {
a46c7ba5 115
2a24cbbe 116 //See header file for documentation
117 Int_t iResult = 0;
118
119 Float_t clusterPosition[3];
120 Double_t trackPosition[3];
121
a46c7ba5 122
123 for(int ic = 0; ic < nClusters; ic++) {
2a24cbbe 124
125 T * cluster = clustersVector.at(ic);
126
a46c7ba5 127 //Get cluster global coordinates
2a24cbbe 128 cluster->GetPosition(clusterPosition);
129
130 //Get track postion at radius of cluster
ec54c698 131 Double_t rCluster = TMath::Sqrt(clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1] + clusterPosition[2]*clusterPosition[2]);
2a24cbbe 132 if (! (track->GetXYZAt(rCluster, bz, trackPosition)) ) {
ff9f0a1f 133 HLTInfo("Track reached detector but not cluster!!!!!!");
2a24cbbe 134 continue;
135 }
70cad768 136
a46c7ba5 137 //Get residual in z= 0 plane (squared)
2a24cbbe 138 Double_t dxy = 0;
139 for(int i = 0; i < 2; i++) {
140 Double_t dd = trackPosition[i] - clusterPosition[i];
141 dxy += dd*dd;
142 }
143
a46c7ba5 144 //Get z residual (squared)
2a24cbbe 145 Double_t dd = trackPosition[2] - clusterPosition[2];
146 Double_t dz = dd*dd;
147
148 Double_t match = dz + dxy;
70cad768 149
2a24cbbe 150 if( match > fMatchDistance ) {
151 continue;
152 }
153
a46c7ba5 154
2a24cbbe 155 if (match < bestMatch[ic]) {
156 bestMatch[ic] = match;
157 cluster->SetEmcCpvDistance(TMath::Sqrt(match));
23af1553 158 cluster->SetTrackDistance(TMath::Sqrt(dxy), TMath::Sqrt(dz));
2a24cbbe 159 }
160
a46c7ba5 161 //Add track to cluster's array of matching tracks
2a24cbbe 162 Int_t nTracksMatched = cluster->GetNTracksMatched();
163 iResult = AddTrackToCluster(track->GetID(), cluster->GetTracksMatched(), match < bestMatch[ic], nTracksMatched);
2a24cbbe 164 }
165
166 return iResult;
167}
168
3cfb9c56 169#endif