3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright © ASV
7 #include "AliL3RootTypes.h"
8 #include "AliL3Logging.h"
9 #include "AliL3Vertex.h"
10 #include "AliL3ConfMapPoint.h"
11 #include "AliL3ConfMapFit.h"
12 #include "AliL3ConfMapTrack.h"
15 //_____________________________________________________________
18 // Track class for conformal mapper
20 ClassImp(AliL3ConfMapTrack)
23 AliL3ConfMapTrack::AliL3ConfMapTrack()
32 AliL3ConfMapTrack::~AliL3ConfMapTrack()
37 void AliL3ConfMapTrack::DeleteCandidate()
39 //Deletes this track by resetting all its parameters. Does not delete
42 AliL3ConfMapPoint *curHit = (AliL3ConfMapPoint*)firstHit;
43 AliL3ConfMapPoint *nextHit;
47 nextHit = (AliL3ConfMapPoint*)curHit->nextTrackHit;
48 curHit->nextTrackHit = 0;
52 UInt_t *hit_numbers = GetHitNumbers();
53 for(Int_t i=0; i<GetNHits(); i++)
63 ComesFromMainVertex(false);
72 void AliL3ConfMapTrack::SetProperties(Bool_t usage)
74 //Set the hits to this track to 'usage'
76 for(StartLoop(); LoopDone(); GetNextHit())
78 AliL3ConfMapPoint *p = (AliL3ConfMapPoint*)currentHit;
84 void AliL3ConfMapTrack::Reset()
86 //Resets the fit parameters of this track.
108 void AliL3ConfMapTrack::UpdateParam(AliL3ConfMapPoint *thisHit)
110 //Function to update fit parameters of track
111 //Also, it updates the hit pointers.
114 //Increment the number of hits assigned to this track:
117 Int_t nhits = GetNHits();
119 SetNHits(nhits); //SetNHits(nhits++);
121 //Set the hit pointers:
126 ((AliL3ConfMapPoint*)lastHit)->nextTrackHit = thisHit;
130 s11Xy = s11Xy + thisHit->GetXYWeight() ;
131 s12Xy = s12Xy + thisHit->GetXYWeight() * thisHit->GetXprime() ;
132 s22Xy = s22Xy + thisHit->GetXYWeight() * pow((thisHit->GetXprime()),2) ;
133 g1Xy = g1Xy + thisHit->GetXYWeight() * thisHit->GetYprime() ;
134 g2Xy = g2Xy + thisHit->GetXYWeight() * thisHit->GetXprime() * thisHit->GetYprime() ;
136 ddXy = s11Xy * s22Xy - pow((s12Xy),2) ;
139 a1Xy = ( g1Xy * s22Xy - g2Xy * s12Xy ) / ddXy ;
140 a2Xy = ( g2Xy * s11Xy - g1Xy * s12Xy ) / ddXy ;
143 // Now in the sz plane
144 s11Sz = s11Sz + thisHit->GetZWeight() ;
145 s12Sz = s12Sz + thisHit->GetZWeight() * thisHit->GetS() ;
146 s22Sz = s22Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetS() ;
147 g1Sz = g1Sz + thisHit->GetZWeight() * thisHit->GetZ() ;
148 g2Sz = g2Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetZ() ;
151 ddSz = s11Sz * s22Sz - s12Sz * s12Sz ;
153 a1Sz = ( g1Sz * s22Sz - g2Sz * s12Sz ) / ddSz ;
154 a2Sz = ( g2Sz * s11Sz - g1Sz * s12Sz ) / ddSz ;
160 void AliL3ConfMapTrack::Fill(AliL3Vertex *vertex,Double_t max_Dca)
162 //Fill track variables with or without fit.
164 //fRadius = sqrt(a2Xy*a2Xy+1)/(2*fabs(a1Xy));
165 Double_t radius = sqrt(a2Xy*a2Xy+1)/(2*fabs(a1Xy));
168 //fPt = (Double_t)(BFACT * BField * fRadius);
169 Double_t pt = (Double_t)(BFACT * BField * GetRadius());
172 if(GetPt() > max_Dca) //go for fit of helix in real space
174 AliL3ConfMapFit *fit = new AliL3ConfMapFit(this,vertex);
176 UpdateToFirstPoint();
180 else if(GetPt() == 0)
181 LOG(AliL3Log::kError,"AliL3ConfMapTrack::Fill","Tracks")<<AliL3Log::kDec<<
182 "Found track with Pt=0!!!"<<ENDLOG;
185 LOG(AliL3Log::kError,"AliL3ConfMapTrack::Fill","Tracks")<<AliL3Log::kDec<<
186 "Track with pt<max_Dca :"<<GetPt()<<ENDLOG;
191 void AliL3ConfMapTrack::UpdateToFirstPoint()
193 //Update track parameters to the innermost point on the track.
194 //Basically it justs calculates the intersection of the track, and a cylinder
195 //with radius = r(innermost point). Then the parameters are updated to this point.
196 //Should be called after the helixfit (in FillTracks).
198 //AliL3ConfMapPoint *lHit = (AliL3ConfMapPoint*)fPoints->Last();
199 AliL3ConfMapPoint *lHit = (AliL3ConfMapPoint*)lastHit;
200 Double_t radius = sqrt(lHit->GetX()*lHit->GetX()+lHit->GetY()*lHit->GetY());
202 //Get the track parameters
204 Double_t tPhi0 = GetPsi() + GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
205 Double_t x0 = GetR0() * cos(GetPhi0()) ;
206 Double_t y0 = GetR0() * sin(GetPhi0()) ;
207 Double_t rc = fabs(GetPt()) / ( BFACT * BField ) ;
208 Double_t xc = x0 - rc * cos(tPhi0) ;
209 Double_t yc = y0 - rc * sin(tPhi0) ;
211 //Check helix and cylinder intersect
213 Double_t fac1 = xc*xc + yc*yc ;
214 Double_t sfac = sqrt( fac1 ) ;
216 if ( fabs(sfac-rc) > radius || fabs(sfac+rc) < radius ) {
217 LOG(AliL3Log::kError,"AliL3ConfMapTrack::UpdateToLastPoint","Tracks")<<AliL3Log::kDec<<
218 "Track does not intersect"<<ENDLOG;
224 Double_t fac2 = ( radius*radius + fac1 - rc*rc) / (2.00 * radius * sfac ) ;
225 Double_t phi = atan2(yc,xc) + GetCharge()*acos(fac2) ;
226 Double_t td = atan2(radius*sin(phi) - yc,radius*cos(phi) - xc) ;
230 if ( td < 0 ) td = td + 2. * pi ;
231 Double_t deltat = fmod((-GetCharge()*td + GetCharge()*tPhi0),2*pi) ;
232 if ( deltat < 0. ) deltat += 2. * pi ;
233 if ( deltat > 2.*pi ) deltat -= 2. * pi ;
234 Double_t z = GetZ0() + rc * GetTgl() * deltat ;
237 Double_t xExtra = radius * cos(phi) ;
238 Double_t yExtra = radius * sin(phi) ;
240 Double_t tPhi = atan2(yExtra-yc,xExtra-xc);
242 //if ( tPhi < 0 ) tPhi += 2. * M_PI ;
244 Double_t tPsi = tPhi - GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
245 if ( tPsi > 2. * pi ) tPsi -= 2. * pi ;
246 if ( tPsi < 0. ) tPsi += 2. * pi ;
248 //And finally, update the track parameters
258 Int_t AliL3ConfMapTrack::GetMCLabel()
260 //For evaluation study.
261 //Returns the MCtrackID of the belonging clusters.
262 //If MCLabel < 0, means that track is fake.
266 Int_t num_of_clusters = GetNumberOfPoints();
267 S *s=new S[num_of_clusters];
269 for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
272 for (i=0; i<num_of_clusters; i++) {
273 AliL3ConfMapPoint *c=(AliL3ConfMapPoint*)fPoints->UncheckedAt(i);
274 lab=fabs(c->fMCTrackID[0]);
276 for (j=0; j<num_of_clusters; j++)
277 if (s[j].lab==lab || s[j].max==0) break;
283 for (i=0; i<num_of_clusters; i++)
284 if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
288 for (i=0; i<num_of_clusters; i++) {
289 AliL3ConfMapPoint *c=(AliL3ConfMapPoint*)fPoints->UncheckedAt(i);
290 if (fabs(c->fMCTrackID[1]) == lab ||
291 fabs(c->fMCTrackID[2]) == lab ) max++;
294 //check if more than 10% of the clusters are incorrectly assigned (fake track):
296 if (1.-Float_t(max)/num_of_clusters > 0.10)
300 Int_t tail=Int_t(0.08*174);
301 if (num_of_clusters < tail) return lab;
304 for (i=1; i<=tail; i++) {
305 AliL3ConfMapPoint *c = (AliL3ConfMapPoint*)fPoints->UncheckedAt(num_of_clusters-i);
306 if (lab == fabs(c->fMCTrackID[0]) ||
307 lab == fabs(c->fMCTrackID[1]) ||
308 lab == fabs(c->fMCTrackID[2])) max++;
310 if (max < Int_t(0.5*tail))
312 //printf("Wrong innermost clusters\n");