1 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
2 //*-- Copyright © ASV
4 #include "AliL3RootTypes.h"
5 #include "AliL3Logging.h"
6 #include "AliL3Vertex.h"
7 #include "AliL3ConfMapPoint.h"
8 #include "AliL3ConfMapFit.h"
9 #include "AliL3ConfMapTrack.h"
12 //_____________________________________________________________
15 // Track class for conformal mapper
17 ClassImp(AliL3ConfMapTrack)
20 AliL3ConfMapTrack::AliL3ConfMapTrack()
29 AliL3ConfMapTrack::~AliL3ConfMapTrack()
34 void AliL3ConfMapTrack::DeleteCandidate()
36 //Deletes this track by resetting all its parameters. Does not delete
39 AliL3ConfMapPoint *curHit = (AliL3ConfMapPoint*)firstHit;
40 AliL3ConfMapPoint *nextHit;
44 nextHit = (AliL3ConfMapPoint*)curHit->nextTrackHit;
45 curHit->nextTrackHit = 0;
49 UInt_t *hit_numbers = GetHitNumbers();
50 for(Int_t i=0; i<GetNHits(); i++)
60 ComesFromMainVertex(false);
69 void AliL3ConfMapTrack::SetProperties(Bool_t usage)
71 //Set the hits to this track to 'usage'
73 for(StartLoop(); LoopDone(); GetNextHit())
75 AliL3ConfMapPoint *p = (AliL3ConfMapPoint*)currentHit;
81 void AliL3ConfMapTrack::Reset()
83 //Resets the fit parameters of this track.
105 void AliL3ConfMapTrack::UpdateParam(AliL3ConfMapPoint *thisHit)
107 //Function to update fit parameters of track
108 //Also, it updates the hit pointers.
111 //Increment the number of hits assigned to this track:
114 Int_t nhits = GetNHits();
116 SetNHits(nhits); //SetNHits(nhits++);
118 //Set the hit pointers:
123 ((AliL3ConfMapPoint*)lastHit)->nextTrackHit = thisHit;
127 s11Xy = s11Xy + thisHit->GetXYWeight() ;
128 s12Xy = s12Xy + thisHit->GetXYWeight() * thisHit->GetXprime() ;
129 s22Xy = s22Xy + thisHit->GetXYWeight() * pow((thisHit->GetXprime()),2) ;
130 g1Xy = g1Xy + thisHit->GetXYWeight() * thisHit->GetYprime() ;
131 g2Xy = g2Xy + thisHit->GetXYWeight() * thisHit->GetXprime() * thisHit->GetYprime() ;
133 ddXy = s11Xy * s22Xy - pow((s12Xy),2) ;
136 a1Xy = ( g1Xy * s22Xy - g2Xy * s12Xy ) / ddXy ;
137 a2Xy = ( g2Xy * s11Xy - g1Xy * s12Xy ) / ddXy ;
140 // Now in the sz plane
141 s11Sz = s11Sz + thisHit->GetZWeight() ;
142 s12Sz = s12Sz + thisHit->GetZWeight() * thisHit->GetS() ;
143 s22Sz = s22Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetS() ;
144 g1Sz = g1Sz + thisHit->GetZWeight() * thisHit->GetZ() ;
145 g2Sz = g2Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetZ() ;
148 ddSz = s11Sz * s22Sz - s12Sz * s12Sz ;
150 a1Sz = ( g1Sz * s22Sz - g2Sz * s12Sz ) / ddSz ;
151 a2Sz = ( g2Sz * s11Sz - g1Sz * s12Sz ) / ddSz ;
157 void AliL3ConfMapTrack::Fill(AliL3Vertex *vertex,Double_t max_Dca)
159 //Fill track variables with or without fit.
161 //fRadius = sqrt(a2Xy*a2Xy+1)/(2*fabs(a1Xy));
162 Double_t radius = sqrt(a2Xy*a2Xy+1)/(2*fabs(a1Xy));
165 //fPt = (Double_t)(BFACT * bField * fRadius);
166 Double_t pt = (Double_t)(BFACT * bField * GetRadius());
169 if(GetPt() > max_Dca) //go for fit of helix in real space
171 AliL3ConfMapFit *fit = new AliL3ConfMapFit(this,vertex);
173 UpdateToFirstPoint();
177 else if(GetPt() == 0)
178 LOG(AliL3Log::kError,"AliL3ConfMapTrack::Fill","Tracks")<<AliL3Log::kDec<<
179 "Found track with Pt=0!!!"<<ENDLOG;
182 LOG(AliL3Log::kError,"AliL3ConfMapTrack::Fill","Tracks")<<AliL3Log::kDec<<
183 "Track with pt<max_Dca :"<<GetPt()<<ENDLOG;
188 void AliL3ConfMapTrack::UpdateToFirstPoint()
190 //Update track parameters to the innermost point on the track.
191 //Basically it justs calculates the intersection of the track, and a cylinder
192 //with radius = r(innermost point). Then the parameters are updated to this point.
193 //Should be called after the helixfit (in FillTracks).
195 //AliL3ConfMapPoint *lHit = (AliL3ConfMapPoint*)fPoints->Last();
196 AliL3ConfMapPoint *lHit = (AliL3ConfMapPoint*)lastHit;
197 Double_t radius = sqrt(lHit->GetX()*lHit->GetX()+lHit->GetY()*lHit->GetY());
199 //Get the track parameters
201 Double_t tPhi0 = GetPsi() + GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
202 Double_t x0 = GetR0() * cos(GetPhi0()) ;
203 Double_t y0 = GetR0() * sin(GetPhi0()) ;
204 Double_t rc = fabs(GetPt()) / ( BFACT * bField ) ;
205 Double_t xc = x0 - rc * cos(tPhi0) ;
206 Double_t yc = y0 - rc * sin(tPhi0) ;
208 //Check helix and cylinder intersect
210 Double_t fac1 = xc*xc + yc*yc ;
211 Double_t sfac = sqrt( fac1 ) ;
213 if ( fabs(sfac-rc) > radius || fabs(sfac+rc) < radius ) {
214 LOG(AliL3Log::kError,"AliL3ConfMapTrack::UpdateToLastPoint","Tracks")<<AliL3Log::kDec<<
215 "Track does not intersect"<<ENDLOG;
221 Double_t fac2 = ( radius*radius + fac1 - rc*rc) / (2.00 * radius * sfac ) ;
222 Double_t phi = atan2(yc,xc) + GetCharge()*acos(fac2) ;
223 Double_t td = atan2(radius*sin(phi) - yc,radius*cos(phi) - xc) ;
227 if ( td < 0 ) td = td + 2. * pi ;
228 Double_t deltat = fmod((-GetCharge()*td + GetCharge()*tPhi0),2*pi) ;
229 if ( deltat < 0. ) deltat += 2. * pi ;
230 if ( deltat > 2.*pi ) deltat -= 2. * pi ;
231 Double_t z = GetZ0() + rc * GetTgl() * deltat ;
234 Double_t xExtra = radius * cos(phi) ;
235 Double_t yExtra = radius * sin(phi) ;
237 Double_t tPhi = atan2(yExtra-yc,xExtra-xc);
239 //if ( tPhi < 0 ) tPhi += 2. * M_PI ;
241 Double_t tPsi = tPhi - GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
242 if ( tPsi > 2. * pi ) tPsi -= 2. * pi ;
243 if ( tPsi < 0. ) tPsi += 2. * pi ;
245 //And finally, update the track parameters
255 Int_t AliL3ConfMapTrack::GetMCLabel()
257 //For evaluation study.
258 //Returns the MCtrackID of the belonging clusters.
259 //If MCLabel < 0, means that track is fake.
263 Int_t num_of_clusters = GetNumberOfPoints();
264 S *s=new S[num_of_clusters];
266 for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
269 for (i=0; i<num_of_clusters; i++) {
270 AliL3ConfMapPoint *c=(AliL3ConfMapPoint*)fPoints->UncheckedAt(i);
271 lab=fabs(c->fMCTrackID[0]);
273 for (j=0; j<num_of_clusters; j++)
274 if (s[j].lab==lab || s[j].max==0) break;
280 for (i=0; i<num_of_clusters; i++)
281 if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
285 for (i=0; i<num_of_clusters; i++) {
286 AliL3ConfMapPoint *c=(AliL3ConfMapPoint*)fPoints->UncheckedAt(i);
287 if (fabs(c->fMCTrackID[1]) == lab ||
288 fabs(c->fMCTrackID[2]) == lab ) max++;
291 //check if more than 10% of the clusters are incorrectly assigned (fake track):
293 if (1.-Float_t(max)/num_of_clusters > 0.10)
297 Int_t tail=Int_t(0.08*174);
298 if (num_of_clusters < tail) return lab;
301 for (i=1; i<=tail; i++) {
302 AliL3ConfMapPoint *c = (AliL3ConfMapPoint*)fPoints->UncheckedAt(num_of_clusters-i);
303 if (lab == fabs(c->fMCTrackID[0]) ||
304 lab == fabs(c->fMCTrackID[1]) ||
305 lab == fabs(c->fMCTrackID[2])) max++;
307 if (max < Int_t(0.5*tail))
309 //printf("Wrong innermost clusters\n");