3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliHLTTPCStandardIncludes.h"
8 #include "AliHLTTPCRootTypes.h"
9 #include "AliHLTTPCLogging.h"
10 #include "AliHLTTPCVertex.h"
11 #include "AliHLTTPCConfMapPoint.h"
12 #include "AliHLTTPCConfMapFit.h"
13 #include "AliHLTTPCConfMapTrack.h"
14 #include "AliHLTTPCTransform.h"
15 #include "AliHLTTPC.h"
17 /** \class AliHLTTPCConfMapTrack
19 //_____________________________________________________________
20 // AliHLTTPCConfMapTrack
22 // Track class for conformal mapper
26 ClassImp(AliHLTTPCConfMapTrack)
29 AliHLTTPCConfMapTrack::AliHLTTPCConfMapTrack()
37 AliHLTTPCConfMapTrack::~AliHLTTPCConfMapTrack()
42 void AliHLTTPCConfMapTrack::DeleteCandidate()
44 //Deletes this track by resetting all its parameters. Does not delete
47 AliHLTTPCConfMapPoint *curHit = (AliHLTTPCConfMapPoint*)firstHit;
48 AliHLTTPCConfMapPoint *nextHit;
52 nextHit = (AliHLTTPCConfMapPoint*)curHit->nextTrackHit;
53 curHit->nextTrackHit = 0;
57 UInt_t *hit_numbers = GetHitNumbers();
58 for(Int_t i=0; i<GetNHits(); i++)
68 ComesFromMainVertex(false);
77 void AliHLTTPCConfMapTrack::SetProperties(Bool_t usage)
79 //Set the hits to this track to 'usage'
81 for(StartLoop(); LoopDone(); GetNextHit())
83 AliHLTTPCConfMapPoint *p = (AliHLTTPCConfMapPoint*)currentHit;
89 void AliHLTTPCConfMapTrack::Reset()
91 //Resets the fit parameters of this track.
112 void AliHLTTPCConfMapTrack::UpdateParam(AliHLTTPCConfMapPoint *thisHit)
114 //Function to update fit parameters of track
115 //Also, it updates the hit pointers.
118 //Increment the number of hits assigned to this track:
121 Int_t nhits = GetNHits();
123 SetNHits(nhits); //SetNHits(nhits++);
125 //Set the hit pointers:
130 ((AliHLTTPCConfMapPoint*)lastHit)->nextTrackHit = thisHit;
134 s11Xy = s11Xy + thisHit->GetXYWeight() ;
135 s12Xy = s12Xy + thisHit->GetXYWeight() * thisHit->GetXprime() ;
136 s22Xy = s22Xy + thisHit->GetXYWeight() * pow((thisHit->GetXprime()),2) ;
137 g1Xy = g1Xy + thisHit->GetXYWeight() * thisHit->GetYprime() ;
138 g2Xy = g2Xy + thisHit->GetXYWeight() * thisHit->GetXprime() * thisHit->GetYprime() ;
140 ddXy = s11Xy * s22Xy - pow((s12Xy),2) ;
143 a1Xy = ( g1Xy * s22Xy - g2Xy * s12Xy ) / ddXy ;
144 a2Xy = ( g2Xy * s11Xy - g1Xy * s12Xy ) / ddXy ;
147 // Now in the sz plane
148 s11Sz = s11Sz + thisHit->GetZWeight() ;
149 s12Sz = s12Sz + thisHit->GetZWeight() * thisHit->GetS() ;
150 s22Sz = s22Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetS() ;
151 g1Sz = g1Sz + thisHit->GetZWeight() * thisHit->GetZ() ;
152 g2Sz = g2Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetZ() ;
155 ddSz = s11Sz * s22Sz - s12Sz * s12Sz ;
157 a1Sz = ( g1Sz * s22Sz - g2Sz * s12Sz ) / ddSz ;
158 a2Sz = ( g2Sz * s11Sz - g1Sz * s12Sz ) / ddSz ;
163 void AliHLTTPCConfMapTrack::Fill(AliHLTTPCVertex *vertex,Double_t max_Dca)
165 //Fill track variables with or without fit.
167 //fRadius = sqrt(a2Xy*a2Xy+1)/(2*fabs(a1Xy));
168 Double_t radius = sqrt(a2Xy*a2Xy+1)/(2*fabs(a1Xy));
171 //fPt = (Double_t)(BFACT * AliHLTTPCTransform::GetBField() * fRadius);
172 Double_t pt = (Double_t)(BFACT * AliHLTTPCTransform::GetBField() * GetRadius());
175 if(GetPt() > max_Dca) //go for fit of helix in real space
177 AliHLTTPCConfMapFit *fit = new AliHLTTPCConfMapFit(this,vertex);
180 AliHLTTPCConfMapPoint *lHit = (AliHLTTPCConfMapPoint*)lastHit;
181 AliHLTTPCConfMapPoint *fHit = (AliHLTTPCConfMapPoint*)firstHit;
183 if(AliHLTTPC::IsTracksAtFirstPoint())
185 //Z0 should not be overwritten here, since it is used as a starting
186 //point for the track swim in UpdateToFirstPoint. fFirstPointX and Y
187 //will be overwritten in UpdateToFirstPoint with the track fit
189 SetFirstPoint(lHit->GetX(),lHit->GetY(),GetZ0());
190 UpdateToFirstPoint();
194 SetFirstPoint(vertex->GetX(),vertex->GetY(),vertex->GetZ());
197 SetLastPoint(fHit->GetX(),fHit->GetY(),fHit->GetZ());
200 else if(GetPt() == 0)
201 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapTrack::Fill","Tracks")<<AliHLTTPCLog::kDec<<
202 "Found track with Pt=0!!!"<<ENDLOG;
205 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapTrack::Fill","Tracks")<<AliHLTTPCLog::kDec<<
206 "Track with pt<max_Dca :"<<GetPt()<<ENDLOG;
210 void AliHLTTPCConfMapTrack::UpdateToFirstPoint()
212 //Update track parameters to the innermost point on the track.
213 //Basically it justs calculates the intersection of the track, and a cylinder
214 //with radius = r(innermost point). Then the parameters are updated to this point.
215 //Should be called after the helixfit (in FillTracks).
217 //AliHLTTPCConfMapPoint *lHit = (AliHLTTPCConfMapPoint*)fPoints->Last();
218 AliHLTTPCConfMapPoint *lHit = (AliHLTTPCConfMapPoint*)lastHit;
219 Double_t radius = sqrt(lHit->GetX()*lHit->GetX()+lHit->GetY()*lHit->GetY());
221 //Get the track parameters
223 Double_t tPhi0 = GetPsi() + GetCharge() * 0.5 * pi / abs(GetCharge()) ;
224 Double_t x0 = GetR0() * cos(GetPhi0()) ;
225 Double_t y0 = GetR0() * sin(GetPhi0()) ;
226 Double_t rc = fabs(GetPt()) / ( BFACT * AliHLTTPCTransform::GetBField() ) ;
227 Double_t xc = x0 - rc * cos(tPhi0) ;
228 Double_t yc = y0 - rc * sin(tPhi0) ;
230 //Check helix and cylinder intersect
232 Double_t fac1 = xc*xc + yc*yc ;
233 Double_t sfac = sqrt( fac1 ) ;
235 if ( fabs(sfac-rc) > radius || fabs(sfac+rc) < radius ) {
236 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapTrack::UpdateToLastPoint","Tracks")<<AliHLTTPCLog::kDec<<
237 "Track does not intersect"<<ENDLOG;
243 Double_t fac2 = ( radius*radius + fac1 - rc*rc) / (2.00 * radius * sfac ) ;
244 Double_t phi = atan2(yc,xc) + GetCharge()*acos(fac2) ;
245 Double_t td = atan2(radius*sin(phi) - yc,radius*cos(phi) - xc) ;
249 if ( td < 0 ) td = td + 2. * pi ;
250 Double_t deltat = fmod((-GetCharge()*td + GetCharge()*tPhi0),2*pi) ;
251 if ( deltat < 0. ) deltat += 2. * pi ;
252 if ( deltat > 2.*pi ) deltat -= 2. * pi ;
253 Double_t z = GetZ0() + rc * GetTgl() * deltat ;
256 Double_t xExtra = radius * cos(phi) ;
257 Double_t yExtra = radius * sin(phi) ;
259 Double_t tPhi = atan2(yExtra-yc,xExtra-xc);
261 //if ( tPhi < 0 ) tPhi += 2. * M_PI ;
263 Double_t tPsi = tPhi - GetCharge() * 0.5 * pi / abs(GetCharge()) ;
264 if ( tPsi > 2. * pi ) tPsi -= 2. * pi ;
265 if ( tPsi < 0. ) tPsi += 2. * pi ;
267 //And finally, update the track parameters
277 Int_t AliHLTTPCConfMapTrack::GetMCLabel()
279 //For evaluation study.
280 //Returns the MCtrackID of the belonging clusters.
281 //If MCLabel < 0, means that track is fake.
285 Int_t num_of_clusters = GetNumberOfPoints();
286 S *s=new S[num_of_clusters];
288 for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
291 for (i=0; i<num_of_clusters; i++) {
292 AliHLTTPCConfMapPoint *c=(AliHLTTPCConfMapPoint*)fPoints->UncheckedAt(i);
293 lab=fabs(c->fMCTrackID[0]);
295 for (j=0; j<num_of_clusters; j++)
296 if (s[j].lab==lab || s[j].max==0) break;
302 for (i=0; i<num_of_clusters; i++)
303 if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
307 for (i=0; i<num_of_clusters; i++) {
308 AliHLTTPCConfMapPoint *c=(AliHLTTPCConfMapPoint*)fPoints->UncheckedAt(i);
309 if (fabs(c->fMCTrackID[1]) == lab ||
310 fabs(c->fMCTrackID[2]) == lab ) max++;
313 //check if more than 10% of the clusters are incorrectly assigned (fake track):
315 if (1.-Float_t(max)/num_of_clusters > 0.10)
319 Int_t tail=Int_t(0.08*174);
320 if (num_of_clusters < tail) return lab;
323 for (i=1; i<=tail; i++) {
324 AliHLTTPCConfMapPoint *c = (AliHLTTPCConfMapPoint*)fPoints->UncheckedAt(num_of_clusters-i);
325 if (lab == fabs(c->fMCTrackID[0]) ||
326 lab == fabs(c->fMCTrackID[1]) ||
327 lab == fabs(c->fMCTrackID[2])) max++;
329 if (max < Int_t(0.5*tail))
331 //printf("Wrong innermost clusters\n");