]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalTrackMatcher.cxx
adding TSystem header, needed for the component to be ported to v4-17-Release
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalTrackMatcher.cxx
1 //$Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Jacek Otwinowski (Jacek.Otwinowski@gsi.de)            *
8  *                  for The ALICE HLT Project.                            *
9  *                                                                        *
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  **************************************************************************/
18
19 /** @file   AliHLTGlobalTrackMatcher.cxx
20     @author Svein Lindal
21     @date   
22     @brief  The HLT class Matching Calorimeter clusters to TPC tracks
23 */
24
25 //#include "AliTPCReconstructor.h"
26
27 #include "AliHLTGlobalTrackMatcher.h"
28 #include "AliExternalTrackParam.h"
29 #include "AliHLTCaloClusterDataStruct.h"
30 #include "AliHLTCaloClusterReader.h"
31 #include "AliPHOSGeoUtils.h"
32 #include "AliESDEvent.h"
33
34 //struct AliHLTCaloClusterHeaderStruct;
35
36 #if __GNUC__>= 3
37 using namespace std;
38 #endif
39
40 ClassImp(AliHLTGlobalTrackMatcher)
41
42 AliHLTGlobalTrackMatcher::AliHLTGlobalTrackMatcher() :
43   fClusterReader(NULL),
44   fPHOSGeom(NULL), 
45   fMaxZ(64.+10.),
46   fMaxX(72. + 72.*TMath::Sin(20) + 72.*TMath::Sin(40) +10. ), 
47   fMinX(-72.-10.),
48
49   fDetRadius(-99999),
50   fMatchDistanceSq(400),
51   fNModules(3),
52   fBestMatchesArray(NULL),
53   fTrackDistanceArray(NULL)
54 {
55   fClusterReader= new AliHLTCaloClusterReader();
56   fPHOSGeom = new AliPHOSGeoUtils("PHOS", "noCPV");
57 }
58
59 //_____________________________________________________________________________
60 AliHLTGlobalTrackMatcher::~AliHLTGlobalTrackMatcher()
61 {
62   //Destructor
63   if (fPHOSGeom)
64     delete fPHOSGeom;
65   fPHOSGeom = NULL;
66
67   if (fClusterReader)
68     delete fClusterReader;
69   fClusterReader = NULL;
70 }
71
72 //_____________________________________________________________________________
73 Bool_t AliHLTGlobalTrackMatcher::Match(AliESDEvent* esdEvent, AliHLTCaloClusterHeaderStruct * clusterHeader)
74 {
75
76   Double_t fNormVector[5][3] = {
77     {0, 0, 0}, 
78     {0, 0, 0}, 
79     {0, 10, 0}, 
80     {10*TMath::Cos(20), 10*TMath::Sin(20), 0}, 
81     {10*TMath::Cos(40), 10*TMath::Sin(40), 0}, 
82   };
83   
84   fClusterReader->SetMemory(clusterHeader);
85   
86   int nClusters = clusterHeader->fNClusters;
87   if( !(nClusters> 0) )
88     return 0;
89   
90   
91   Double_t tDistance[nClusters];
92
93   for(int i = 0; i < nClusters; i++) {
94     tDistance[i] = 99999;
95   }
96   
97   //Position of track intersection with cylindrical plane defined by PHOS radius
98   Double_t trackPos[3] = {0,0,0};
99   
100   Double_t bz = esdEvent->GetMagneticField();
101   int nt = esdEvent->GetNumberOfTracks();
102   for (int it = 0; it < nt; it++ ) {
103     
104     AliExternalTrackParam * track = static_cast<AliExternalTrackParam*> (esdEvent->GetTrack(it)) ;
105  
106     //See if track is even close to detector volume
107     if (! (track->GetXYZAt(fDetRadius, bz, trackPos)) )
108       continue;
109
110     if (trackPos[3] > fMaxZ || trackPos[3] < -fMaxZ)
111       continue;
112   
113     if (trackPos[0] > fMaxX || trackPos[0] < fMinX)
114       continue;
115  
116     //Track is close to Detector volume
117     //loop over clusters to find clusters that are fairly close to track
118     
119     fClusterReader->SetMemory(clusterHeader);
120     int clusterIndex = -1;
121     AliHLTCaloClusterDataStruct* cluster;
122     while( (cluster = fClusterReader->NextCluster()) ) {
123       clusterIndex++;
124       
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;
131       }
132     
133       if (distanceSq >( fMatchDistanceSq + 60) ) 
134         continue;
135       
136       //We have a cluster in relatively close proximity to the track, do more accurate matching
137
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;
142     
143       //Get a (any) cell in the cluster
144       fClusterReader->GetCell(cluster, cellId, cellAmp, (UInt_t) (0) );
145     
146       //Use cellId to find module nr;
147       Int_t relNumbering[4];
148       fPHOSGeom->AbsToRelNumbering(cellId, relNumbering);
149     
150       //Project the track to the plane defined by the module geometry and find intersection point
151       track->Intersect(clusterPos, fNormVector[relNumbering[0]], bz);
152     
153       //Is the track closer to the cluster than previous matches?
154       distanceSq = clusterPos[0]*clusterPos[0] + clusterPos[2]* clusterPos[2];
155      
156       //Is track close enough to be considered a match?
157       if( distanceSq < fMatchDistanceSq) {
158         
159         //Is this a better match than previous best match?
160         if ( distanceSq  < tDistance[clusterIndex] )  {
161         
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);
166           } else {
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);
173           }
174           
175           //This is the new standard for best match
176           tDistance[clusterIndex] = distanceSq;
177           
178         }  else {
179           
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);
185         
186         }
187
188       } // if (distanceSq < fMaxDistanceSq)  
189     
190     } //cluster loopx
191   } // track loop 
192
193   return 0;
194
195 }