3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Jacek Otwinowski (Jacek.Otwinowski@gsi.de) *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTGlobalTrackMatcher.cxx
22 @brief The HLT class Matching Calorimeter clusters to TPC tracks
25 //#include "AliTPCReconstructor.h"
27 #include "AliHLTGlobalTrackMatcher.h"
28 #include "AliExternalTrackParam.h"
29 #include "AliHLTCaloClusterDataStruct.h"
30 #include "AliHLTCaloClusterReader.h"
31 #include "AliPHOSGeoUtils.h"
32 #include "AliESDEvent.h"
34 //struct AliHLTCaloClusterHeaderStruct;
40 ClassImp(AliHLTGlobalTrackMatcher)
42 AliHLTGlobalTrackMatcher::AliHLTGlobalTrackMatcher() :
46 fMaxX(72. + 72.*TMath::Sin(20) + 72.*TMath::Sin(40) +10. ),
50 fMatchDistanceSq(400),
52 fBestMatchesArray(NULL),
53 fTrackDistanceArray(NULL)
55 fClusterReader= new AliHLTCaloClusterReader();
56 fPHOSGeom = new AliPHOSGeoUtils("PHOS", "noCPV");
59 //_____________________________________________________________________________
60 AliHLTGlobalTrackMatcher::~AliHLTGlobalTrackMatcher()
68 delete fClusterReader;
69 fClusterReader = NULL;
72 //_____________________________________________________________________________
73 Bool_t AliHLTGlobalTrackMatcher::Match(AliESDEvent* esdEvent, AliHLTCaloClusterHeaderStruct * clusterHeader)
76 Double_t fNormVector[5][3] = {
80 {10*TMath::Cos(20), 10*TMath::Sin(20), 0},
81 {10*TMath::Cos(40), 10*TMath::Sin(40), 0},
84 fClusterReader->SetMemory(clusterHeader);
86 int nClusters = clusterHeader->fNClusters;
91 Double_t tDistance[nClusters];
93 for(int i = 0; i < nClusters; i++) {
97 //Position of track intersection with cylindrical plane defined by PHOS radius
98 Double_t trackPos[3] = {0,0,0};
100 Double_t bz = esdEvent->GetMagneticField();
101 int nt = esdEvent->GetNumberOfTracks();
102 for (int it = 0; it < nt; it++ ) {
104 AliExternalTrackParam * track = static_cast<AliExternalTrackParam*> (esdEvent->GetTrack(it)) ;
106 //See if track is even close to detector volume
107 if (! (track->GetXYZAt(fDetRadius, bz, trackPos)) )
110 if (trackPos[3] > fMaxZ || trackPos[3] < -fMaxZ)
113 if (trackPos[0] > fMaxX || trackPos[0] < fMinX)
116 //Track is close to Detector volume
117 //loop over clusters to find clusters that are fairly close to track
119 fClusterReader->SetMemory(clusterHeader);
120 int clusterIndex = -1;
121 AliHLTCaloClusterDataStruct* cluster;
122 while( (cluster = fClusterReader->NextCluster()) ) {
125 //Get approximate distance between cluster and track
126 Double_t clusterPos[3] = {cluster->fGlobalPos[0], cluster->fGlobalPos[1], cluster->fGlobalPos[2]};
127 Double_t distanceSq = 0;
128 for(int i = 0; i < 3; i++) {
129 Float_t distance = trackPos[i] - clusterPos[1];
130 distanceSq += distance*distance;
133 if (distanceSq >( fMatchDistanceSq + 60) )
136 //We have a cluster in relatively close proximity to the track, do more accurate matching
138 //Get the module where the cluster is located
139 //Need CellId of one of the cells of the cluster;
140 UShort_t cellId = -1;
141 Double_t cellAmp = -1;
143 //Get a (any) cell in the cluster
144 fClusterReader->GetCell(cluster, cellId, cellAmp, (UInt_t) (0) );
146 //Use cellId to find module nr;
147 Int_t relNumbering[4];
148 fPHOSGeom->AbsToRelNumbering(cellId, relNumbering);
150 //Project the track to the plane defined by the module geometry and find intersection point
151 track->Intersect(clusterPos, fNormVector[relNumbering[0]], bz);
153 //Is the track closer to the cluster than previous matches?
154 distanceSq = clusterPos[0]*clusterPos[0] + clusterPos[2]* clusterPos[2];
156 //Is track close enough to be considered a match?
157 if( distanceSq < fMatchDistanceSq) {
159 //Is this a better match than previous best match?
160 if ( distanceSq < tDistance[clusterIndex] ) {
162 //Yes, add track label at beginning of array of matching track
163 if( !(cluster->fTracksMatched) ) {
164 cluster->fTracksMatched = new TArrayI(1);
165 cluster->fTracksMatched->AddAt(track->GetLabel(), 0);
167 //Increase Array size by one
168 cluster->fTracksMatched->Set(cluster->fTracksMatched->GetSize() + 1);
169 //Move previous best match to last spot
170 cluster->fTracksMatched->AddAt(cluster->fTracksMatched->GetAt(0), cluster->fTracksMatched->GetSize() - 1);
171 //Finally add the new best to first spot
172 cluster->fTracksMatched->AddAt(track->GetLabel(), 0);
175 //This is the new standard for best match
176 tDistance[clusterIndex] = distanceSq;
180 //It's a match, but not best match
181 //Increase Array size by one
182 cluster->fTracksMatched->Set(cluster->fTracksMatched->GetSize() + 1);
183 //Add new track at back of the array
184 cluster->fTracksMatched->AddAt(track->GetLabel(), cluster->fTracksMatched->GetSize() - 1);
188 } // if (distanceSq < fMaxDistanceSq)