3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright © ASV
6 #include "AliL3RootTypes.h"
7 #include "AliL3Logging.h"
8 #include "AliL3Vertex.h"
9 #include "AliL3ConfMapPoint.h"
10 #include "AliL3ConfMapFit.h"
11 #include "AliL3ConfMapTrack.h"
12 #include "AliL3Transform.h"
15 //_____________________________________________________________
18 // Track class for conformal mapper
20 ClassImp(AliL3ConfMapTrack)
23 AliL3ConfMapTrack::AliL3ConfMapTrack()
31 AliL3ConfMapTrack::~AliL3ConfMapTrack()
36 void AliL3ConfMapTrack::DeleteCandidate()
38 //Deletes this track by resetting all its parameters. Does not delete
41 AliL3ConfMapPoint *curHit = (AliL3ConfMapPoint*)firstHit;
42 AliL3ConfMapPoint *nextHit;
46 nextHit = (AliL3ConfMapPoint*)curHit->nextTrackHit;
47 curHit->nextTrackHit = 0;
51 UInt_t *hit_numbers = GetHitNumbers();
52 for(Int_t i=0; i<GetNHits(); i++)
62 ComesFromMainVertex(false);
71 void AliL3ConfMapTrack::SetProperties(Bool_t usage)
73 //Set the hits to this track to 'usage'
75 for(StartLoop(); LoopDone(); GetNextHit())
77 AliL3ConfMapPoint *p = (AliL3ConfMapPoint*)currentHit;
83 void AliL3ConfMapTrack::Reset()
85 //Resets the fit parameters of this track.
106 void AliL3ConfMapTrack::UpdateParam(AliL3ConfMapPoint *thisHit)
108 //Function to update fit parameters of track
109 //Also, it updates the hit pointers.
112 //Increment the number of hits assigned to this track:
115 Int_t nhits = GetNHits();
117 SetNHits(nhits); //SetNHits(nhits++);
119 //Set the hit pointers:
124 ((AliL3ConfMapPoint*)lastHit)->nextTrackHit = thisHit;
128 s11Xy = s11Xy + thisHit->GetXYWeight() ;
129 s12Xy = s12Xy + thisHit->GetXYWeight() * thisHit->GetXprime() ;
130 s22Xy = s22Xy + thisHit->GetXYWeight() * pow((thisHit->GetXprime()),2) ;
131 g1Xy = g1Xy + thisHit->GetXYWeight() * thisHit->GetYprime() ;
132 g2Xy = g2Xy + thisHit->GetXYWeight() * thisHit->GetXprime() * thisHit->GetYprime() ;
134 ddXy = s11Xy * s22Xy - pow((s12Xy),2) ;
137 a1Xy = ( g1Xy * s22Xy - g2Xy * s12Xy ) / ddXy ;
138 a2Xy = ( g2Xy * s11Xy - g1Xy * s12Xy ) / ddXy ;
141 // Now in the sz plane
142 s11Sz = s11Sz + thisHit->GetZWeight() ;
143 s12Sz = s12Sz + thisHit->GetZWeight() * thisHit->GetS() ;
144 s22Sz = s22Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetS() ;
145 g1Sz = g1Sz + thisHit->GetZWeight() * thisHit->GetZ() ;
146 g2Sz = g2Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetZ() ;
149 ddSz = s11Sz * s22Sz - s12Sz * s12Sz ;
151 a1Sz = ( g1Sz * s22Sz - g2Sz * s12Sz ) / ddSz ;
152 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 * AliL3Transform::GetBField() * fRadius);
166 Double_t pt = (Double_t)(BFACT * AliL3Transform::GetBField() * 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;
187 void AliL3ConfMapTrack::UpdateToFirstPoint()
189 //Update track parameters to the innermost point on the track.
190 //Basically it justs calculates the intersection of the track, and a cylinder
191 //with radius = r(innermost point). Then the parameters are updated to this point.
192 //Should be called after the helixfit (in FillTracks).
194 //AliL3ConfMapPoint *lHit = (AliL3ConfMapPoint*)fPoints->Last();
195 AliL3ConfMapPoint *lHit = (AliL3ConfMapPoint*)lastHit;
196 Double_t radius = sqrt(lHit->GetX()*lHit->GetX()+lHit->GetY()*lHit->GetY());
198 //Get the track parameters
200 Double_t tPhi0 = GetPsi() + GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
201 Double_t x0 = GetR0() * cos(GetPhi0()) ;
202 Double_t y0 = GetR0() * sin(GetPhi0()) ;
203 Double_t rc = fabs(GetPt()) / ( BFACT * AliL3Transform::GetBField() ) ;
204 Double_t xc = x0 - rc * cos(tPhi0) ;
205 Double_t yc = y0 - rc * sin(tPhi0) ;
207 //Check helix and cylinder intersect
209 Double_t fac1 = xc*xc + yc*yc ;
210 Double_t sfac = sqrt( fac1 ) ;
212 if ( fabs(sfac-rc) > radius || fabs(sfac+rc) < radius ) {
213 LOG(AliL3Log::kError,"AliL3ConfMapTrack::UpdateToLastPoint","Tracks")<<AliL3Log::kDec<<
214 "Track does not intersect"<<ENDLOG;
220 Double_t fac2 = ( radius*radius + fac1 - rc*rc) / (2.00 * radius * sfac ) ;
221 Double_t phi = atan2(yc,xc) + GetCharge()*acos(fac2) ;
222 Double_t td = atan2(radius*sin(phi) - yc,radius*cos(phi) - xc) ;
226 if ( td < 0 ) td = td + 2. * pi ;
227 Double_t deltat = fmod((-GetCharge()*td + GetCharge()*tPhi0),2*pi) ;
228 if ( deltat < 0. ) deltat += 2. * pi ;
229 if ( deltat > 2.*pi ) deltat -= 2. * pi ;
230 Double_t z = GetZ0() + rc * GetTgl() * deltat ;
233 Double_t xExtra = radius * cos(phi) ;
234 Double_t yExtra = radius * sin(phi) ;
236 Double_t tPhi = atan2(yExtra-yc,xExtra-xc);
238 //if ( tPhi < 0 ) tPhi += 2. * M_PI ;
240 Double_t tPsi = tPhi - GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
241 if ( tPsi > 2. * pi ) tPsi -= 2. * pi ;
242 if ( tPsi < 0. ) tPsi += 2. * pi ;
244 //And finally, update the track parameters
254 Int_t AliL3ConfMapTrack::GetMCLabel()
256 //For evaluation study.
257 //Returns the MCtrackID of the belonging clusters.
258 //If MCLabel < 0, means that track is fake.
262 Int_t num_of_clusters = GetNumberOfPoints();
263 S *s=new S[num_of_clusters];
265 for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
268 for (i=0; i<num_of_clusters; i++) {
269 AliL3ConfMapPoint *c=(AliL3ConfMapPoint*)fPoints->UncheckedAt(i);
270 lab=fabs(c->fMCTrackID[0]);
272 for (j=0; j<num_of_clusters; j++)
273 if (s[j].lab==lab || s[j].max==0) break;
279 for (i=0; i<num_of_clusters; i++)
280 if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
284 for (i=0; i<num_of_clusters; i++) {
285 AliL3ConfMapPoint *c=(AliL3ConfMapPoint*)fPoints->UncheckedAt(i);
286 if (fabs(c->fMCTrackID[1]) == lab ||
287 fabs(c->fMCTrackID[2]) == lab ) max++;
290 //check if more than 10% of the clusters are incorrectly assigned (fake track):
292 if (1.-Float_t(max)/num_of_clusters > 0.10)
296 Int_t tail=Int_t(0.08*174);
297 if (num_of_clusters < tail) return lab;
300 for (i=1; i<=tail; i++) {
301 AliL3ConfMapPoint *c = (AliL3ConfMapPoint*)fPoints->UncheckedAt(num_of_clusters-i);
302 if (lab == fabs(c->fMCTrackID[0]) ||
303 lab == fabs(c->fMCTrackID[1]) ||
304 lab == fabs(c->fMCTrackID[2])) max++;
306 if (max < Int_t(0.5*tail))
308 //printf("Wrong innermost clusters\n");