1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 #include "AliMUONTrackK.h"
18 #include <Riostream.h>
19 #include <TClonesArray.h>
22 #include <stdlib.h> // for exit()
24 #include "AliCallf77.h"
26 #include "AliMUONChamber.h"
27 #include "AliMUONEventReconstructor.h"
28 #include "AliMUONSegment.h"
29 #include "AliMUONHitForRec.h"
30 #include "AliMUONRawCluster.h"
31 #include "AliMUONTrackParam.h"
35 void mnvertLocalK(Double_t* a, Int_t l, Int_t m, Int_t n, Int_t& ifail);
37 ClassImp(AliMUONTrackK) // Class implementation in ROOT context
39 // A few calls in Fortran or from Fortran (extrap.F).
41 # define extrap_onestep_helix extrap_onestep_helix_
42 # define extrap_onestep_helix3 extrap_onestep_helix3_
43 # define extrap_onestep_rungekutta extrap_onestep_rungekutta_
44 # define gufld_double gufld_double_
46 # define extrap_onestep_helix EXTRAP_ONESTEP_HELIX
47 # define extrap_onestep_helix3 EXTRAP_ONESTEP_HELIX3
48 # define extrap_onestep_rungekutta EXTRAP_ONESTEP_RUNGEKUTTA
49 # define gufld_double GUFLD_DOUBLE
53 void type_of_call extrap_onestep_helix
54 (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
56 void type_of_call extrap_onestep_helix3
57 (Double_t &Field, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
59 void type_of_call extrap_onestep_rungekutta
60 (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
62 void type_of_call gufld_double(Double_t *Position, Double_t *Field);
63 /* void type_of_call gufld_double(Double_t *Position, Double_t *Field) {
64 // interface to "gAlice->Field()->Field" for arguments in double precision
66 x[0] = Position[0]; x[1] = Position[1]; x[2] = Position[2];
67 gAlice->Field()->Field(x, b);
68 Field[0] = b[0]; Field[1] = b[1]; Field[2] = b[2];
73 Int_t AliMUONTrackK::fgNOfPoints = 0;
74 AliMUON* AliMUONTrackK::fgMUON = NULL;
75 AliMUONEventReconstructor* AliMUONTrackK::fgEventReconstructor = NULL;
76 TClonesArray* AliMUONTrackK::fgHitForRec = NULL;
78 //__________________________________________________________________________
79 AliMUONTrackK::AliMUONTrackK()
81 // Default constructor
83 fgEventReconstructor = NULL; // pointer to event reconstructor
84 fgMUON = NULL; // pointer to Muon module
85 fgHitForRec = NULL; // pointer to points
86 fgNOfPoints = 0; // number of points
100 //__________________________________________________________________________
101 AliMUONTrackK::AliMUONTrackK(AliMUONEventReconstructor *EventReconstructor, TClonesArray *hitForRec)
105 fgEventReconstructor = EventReconstructor; // pointer to event reconstructor
106 fgMUON = (AliMUON*) gAlice->GetModule("MUON"); // pointer to Muon module
107 fgHitForRec = hitForRec; // pointer to points
108 fgNOfPoints = fgHitForRec->GetEntriesFast(); // number of points
110 fStartSegment = NULL;
111 fTrackHitsPtr = NULL;
123 //__________________________________________________________________________
124 AliMUONTrackK::AliMUONTrackK(AliMUONSegment *segment)
126 // Constructor from a segment
128 AliMUONHitForRec *hit1, *hit2;
129 AliMUONRawCluster *clus;
130 TClonesArray *rawclusters;
132 fStartSegment = segment;
134 // Pointers to hits from the segment
135 hit1 = segment->GetHitForRec1();
136 hit2 = segment->GetHitForRec2();
137 hit1->SetNTrackHits(hit1->GetNTrackHits()+1); // mark hit as being on track
138 hit2->SetNTrackHits(hit2->GetNTrackHits()+1); // mark hit as being on track
139 // check sorting in Z
140 if (hit1->GetZ() > hit2->GetZ()) {
142 hit2 = segment->GetHitForRec1();
144 // memory allocation for the TObjArray of pointers to reconstructed TrackHit's
145 fTrackHitsPtr = new TObjArray(10);
149 fTrackPar = new TMatrixD(kSize,1); // track parameters
150 fTrackParNew = new TMatrixD(kSize,1); // track parameters
151 fCovariance = new TMatrixD(kSize,kSize); // covariance matrix
152 fWeight = new TMatrixD(kSize,kSize); // weight matrix (inverse of covariance)
154 // Fill array of track parameters
155 if (hit1->GetChamberNumber() > 7) {
156 // last tracking station
157 (*fTrackPar)(0,0) = hit1->GetBendingCoor(); // y
158 (*fTrackPar)(1,0) = hit1->GetNonBendingCoor(); // x
159 fPosition = hit1->GetZ(); // z
160 fTrackHitsPtr->Add((TObjArray*)hit2); // add hit 2
161 fTrackHitsPtr->Add((TObjArray*)hit1); // add hit 1
164 // last but one tracking station
165 (*fTrackPar)(0,0) = hit2->GetBendingCoor(); // y
166 (*fTrackPar)(1,0) = hit2->GetNonBendingCoor(); // x
167 fPosition = hit2->GetZ(); // z
168 fTrackHitsPtr->Add((TObjArray*)hit1); // add hit 1
169 fTrackHitsPtr->Add((TObjArray*)hit2); // add hit 2
172 dZ = hit2->GetZ() - hit1->GetZ();
173 dY = hit2->GetBendingCoor() - hit1->GetBendingCoor();
174 dX = hit2->GetNonBendingCoor() - hit1->GetNonBendingCoor();
175 (*fTrackPar)(2,0) = TMath::ATan2(dY,dZ); // alpha
176 (*fTrackPar)(3,0) = TMath::ATan2(dX,dZ/TMath::Cos((*fTrackPar)(2,0))); // beta
177 (*fTrackPar)(4,0) = 1/fgEventReconstructor->GetBendingMomentumFromImpactParam(segment->GetBendingImpact()); // 1/Pt
178 (*fTrackPar)(4,0) *= TMath::Cos((*fTrackPar)(3,0)); // 1/p
179 cout << fgEventReconstructor->GetBendingMomentumFromImpactParam(segment->GetBendingImpact()) << " " << 1/(*fTrackPar)(4,0) << " ";
180 if (fgEventReconstructor->GetRecGeantHits()) {
182 cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetTHTrack() << "<-->" << ((AliMUONHitForRec*)((*fTrackHitsPtr)[1]))->GetTHTrack() << endl;
185 for (Int_t i=0; i<2; i++) {
186 hit1 = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
187 rawclusters = fgMUON->RawClustAddress(hit1->GetChamberNumber());
188 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit1->GetHitNumber());
189 cout << clus->fTracks[1]-1;
190 if (clus->fTracks[2] != 0) cout << " " << clus->fTracks[2]-1;
191 if (i == 0) cout << " <--> ";
195 // Evaluate covariance (and weight) matrix
201 //__________________________________________________________________________
202 AliMUONTrackK::~AliMUONTrackK()
207 delete fTrackHitsPtr; // delete the TObjArray of pointers to TrackHit's
208 fTrackHitsPtr = NULL;
210 delete fTrackPar; delete fTrackParNew; delete fCovariance;
214 //__________________________________________________________________________
215 AliMUONTrackK::AliMUONTrackK (const AliMUONTrackK& source)
217 // Dummy copy constructor
220 //__________________________________________________________________________
221 AliMUONTrackK & AliMUONTrackK::operator=(const AliMUONTrackK& source)
223 // Assignment operator
225 if(&source == this) return *this;
226 fStartSegment = source.fStartSegment;
227 fNTrackHits = source.fNTrackHits;
228 fChi2 = source.fChi2;
229 fPosition = source.fPosition;
230 fPositionNew = source.fPositionNew;
231 fTrackDir = source.fTrackDir;
232 fBPFlag = source.fBPFlag;
233 fRecover = source.fRecover;
234 fSkipHit = source.fSkipHit;
237 fTrackHitsPtr = new TObjArray(*source.fTrackHitsPtr);
238 //source.fTrackHitsPtr->Dump();
239 //fTrackHitsPtr->Dump();
241 fTrackPar = new TMatrixD(*source.fTrackPar); // track parameters
242 fTrackParNew = new TMatrixD(*source.fTrackParNew); // track parameters
243 fCovariance = new TMatrixD(*source.fCovariance); // covariance matrix
244 fWeight = new TMatrixD(*source.fWeight); // weight matrix (inverse of covariance)
249 //__________________________________________________________________________
250 void AliMUONTrackK::EvalCovariance(Double_t dZ)
252 // Evaluate covariance (and weight) matrix for track candidate
253 Double_t sigmaB, sigmaNonB, tanA, tanB, dAdY, rad, dBdX, dBdY;
255 sigmaB = fgEventReconstructor->GetBendingResolution(); // bending resolution
256 sigmaNonB = fgEventReconstructor->GetNonBendingResolution(); // non-bending resolution
258 (*fWeight)(0,0) = sigmaB*sigmaB; // <yy>
260 (*fWeight)(1,1) = sigmaNonB*sigmaNonB; // <xx>
262 tanA = TMath::Tan((*fTrackPar)(2,0));
263 dAdY = 1/(1+tanA*tanA)/dZ;
264 (*fWeight)(2,2) = dAdY*dAdY*(*fWeight)(0,0)*2; // <aa>
265 (*fWeight)(0,2) = dAdY*(*fWeight)(0,0); // <ya>
266 (*fWeight)(2,0) = (*fWeight)(0,2);
268 rad = dZ/TMath::Cos((*fTrackPar)(2,0));
269 tanB = TMath::Tan((*fTrackPar)(3,0));
270 dBdX = 1/(1+tanB*tanB)/rad;
272 (*fWeight)(3,3) = dBdX*dBdX*(*fWeight)(1,1)*2; // <bb>
273 (*fWeight)(1,3) = dBdX*(*fWeight)(1,1); // <xb>
274 (*fWeight)(3,1) = (*fWeight)(1,3);
276 //(*fWeight)(4,4) = ((*fTrackPar)(4,0)*0.2)*((*fTrackPar)(4,0)*0.2); // error 20%
277 (*fWeight)(4,4) = ((*fTrackPar)(4,0)*0.5)*((*fTrackPar)(4,0)*0.5); // error 50%
279 // check whether the Invert method returns flag if matrix cannot be inverted,
280 // and do not calculate the Determinant in that case !!!!
281 if (fWeight->Determinant() != 0) {
283 // fWeight->Invert();
286 mnvertLocalK(&((*fWeight)(0,0)), kSize,kSize,kSize,ifailWeight);
288 cout << " ***** Warning in EvalCovariance: Determinant fWeight=0:" << endl;
293 //__________________________________________________________________________
294 Bool_t AliMUONTrackK::KalmanFilter(Int_t ichamBeg, Int_t ichamEnd, Bool_t Back, Double_t zDipole1, Double_t zDipole2)
296 // Follows track through detector stations
297 Bool_t miss, success;
298 Int_t ichamb, iFB, iMin, iMax, dChamb, ichambOK, i;
299 Int_t ihit, firstIndx, lastIndx, currIndx, dChambMiss, iDindx=0;
300 Double_t zEnd, dChi2;
301 AliMUONHitForRec *hitAdd, *firstHit, *lastHit, *hit;
302 AliMUONRawCluster *clus;
303 TClonesArray *rawclusters;
304 hit = 0; clus = 0; rawclusters = 0;
309 iFB = TMath::Sign(1,ichamEnd-ichamBeg);
310 iMin = TMath::Min(ichamEnd,ichamBeg);
311 iMax = TMath::Max(ichamEnd,ichamBeg);
315 // Get indices of the 1'st and last hits on the track candidate
316 firstHit = (AliMUONHitForRec*) fTrackHitsPtr->First();
317 lastHit = (AliMUONHitForRec*) fTrackHitsPtr->Last();
318 firstIndx = fgHitForRec->IndexOf(firstHit);
319 lastIndx = fgHitForRec->IndexOf(lastHit);
320 currIndx = TMath::Abs (TMath::Max(firstIndx*iFB,lastIndx*iFB));
326 // find hit with the highest Z
328 for (i=0; i<fNTrackHits; i++) {
329 hitAdd = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
330 zEnd = hitAdd->GetZ();
331 if (zEnd > zbeg) zbeg = zEnd;
333 currIndx = fNTrackHits - i + 2; //???
338 } else if (fRecover != 0) {
339 Back = kTRUE; // dirty trick
341 if (ichamBeg == 7 || ichamBeg == 8) currIndx = fNTrackHits - 2;
343 Double_t zbeg = ((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetZ();
344 for (i=1; i<fNTrackHits; i++) {
345 hitAdd = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
346 zEnd = hitAdd->GetZ();
347 if (zEnd < zbeg) break;
349 currIndx = fNTrackHits - i; //???
353 while (ichamb>=iMin && ichamb<=iMax) {
354 // Find the closest hit in Z, not belonging to the current plane
357 hitAdd = (AliMUONHitForRec*) ((*fTrackHitsPtr)[fNTrackHits-currIndx]);
358 zEnd = hitAdd->GetZ();
361 for (ihit=currIndx+iFB; ihit>=0 && ihit<fgNOfPoints; ihit+=iFB) {
362 hitAdd = (AliMUONHitForRec*) ((*fgHitForRec)[ihit]);
363 //if (TMath::Abs(hitAdd->GetZ()-fPosition) > 0.1) {
364 if (TMath::Abs(hitAdd->GetZ()-fPosition) > 0.5) {
365 zEnd = hitAdd->GetZ();
371 if (zEnd<-999 && ichamb==ichamEnd) endOfProp = 1; // end-of-propagation
373 // Check if there is a missing chamber
374 if (zEnd<-999 || TMath::Abs(hitAdd->GetChamberNumber()-ichamb) > 1) {
375 if (!Back && zEnd>-999) currIndx -= iFB;
377 zEnd = (&(fgMUON->Chamber(ichamb)))->Z();
380 ichamb = hitAdd->GetChamberNumber();
384 if (ichamb<iMin || ichamb>iMax) break;
385 // Check for missing station
387 dChamb = TMath::Abs(ichamb-ichambOK);
389 dChambMiss = endOfProp;
390 //Check if (iFB > 0) dChambMiss++;
392 if (TMath::Odd(ichambOK)) dChambMiss++;
395 //cout << dChamb << " " << ichambOK << " " << fgNOfPoints << endl;
396 if (TMath::Odd(ichambOK) && dChamb > 3-dChambMiss) {
397 // missing station - abandon track
398 //cout << dChamb << " " << ichambOK << " " << fgNOfPoints << " " << 1/(*fTrackPar)(4,0) << endl;
400 for (Int_t i1=0; i1<fgNOfPoints; i1++) {
401 cout << " Hit #" << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetChamberNumber() << " ";
402 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetBendingCoor() << " ";
403 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetNonBendingCoor() << " ";
404 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetZ() << " " << " ";
405 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetTHTrack() << endl;
410 cout << fNTrackHits << endl;
411 for (Int_t i1=0; i1<fNTrackHits; i1++) {
412 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
413 printf(" * %d %10.4f %10.4f %10.4f",
414 hit->GetChamberNumber(), hit->GetBendingCoor(),
415 hit->GetNonBendingCoor(), hit->GetZ());
416 if (fgEventReconstructor->GetRecGeantHits()) {
418 printf(" %3d %3d \n", hit->GetGeantSignal(), hit->GetTHTrack());
421 rawclusters = fgMUON->RawClustAddress(hit->GetChamberNumber());
422 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
423 printf("%3d", clus->fTracks[1]-1);
424 if (clus->fTracks[2] != 0) printf("%3d \n", clus->fTracks[2]-1);
429 if (fNTrackHits>2 && fRecover==0 && !(ichambOK==((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetChamberNumber())) {
430 // try to recover track later
435 //Check else if (TMath::Even(ichambOK) && dChamb > 2-endOfProp) {
436 else if (TMath::Even(ichambOK) && dChamb > 2-dChambMiss) {
437 // missing station - abandon track
438 //cout << dChamb << " " << ichambOK << " " << fgNOfPoints << " " << 1/(*fTrackPar)(4,0) << endl;
440 for (Int_t i1=0; i1<fgNOfPoints; i1++) {
441 cout << " Hit #" << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetChamberNumber() << " ";
442 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetBendingCoor() << " ";
443 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetNonBendingCoor() << " ";
444 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetZ() << " " << " ";
445 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetTHTrack() << endl;
450 cout << fNTrackHits << endl;
451 for (Int_t i1=0; i1<fNTrackHits; i1++) {
452 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
453 printf(" * %d %10.4f %10.4f %10.4f",
454 hit->GetChamberNumber(), hit->GetBendingCoor(),
455 hit->GetNonBendingCoor(), hit->GetZ());
456 if (fgEventReconstructor->GetRecGeantHits()) {
458 printf(" %3d %3d \n", hit->GetGeantSignal(), hit->GetTHTrack());
461 rawclusters = fgMUON->RawClustAddress(hit->GetChamberNumber());
462 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
463 printf("%3d", clus->fTracks[1]-1);
464 if (clus->fTracks[2] != 0) printf("%3d \n", clus->fTracks[2]-1);
469 if (fNTrackHits>2 && fRecover==0 && !(ichambOK==((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetChamberNumber())) {
470 // try to recover track later
477 if (endOfProp != 0) break;
479 // propagate to the found Z
481 // Check if track steps into dipole
482 if (fPosition>zDipole2 && zEnd<zDipole2) {
483 //LinearPropagation(zDipole2-zBeg);
484 ParPropagation(zDipole2);
485 MSThin(1); // multiple scattering in the chamber
486 WeightPropagation(zDipole2); // propagate weight matrix
487 fPosition = fPositionNew;
488 *fTrackPar = *fTrackParNew;
489 //MagnetPropagation(zEnd);
490 ParPropagation(zEnd);
491 WeightPropagation(zEnd);
492 fPosition = fPositionNew;
494 // Check if track steps out of dipole
495 else if (fPosition>zDipole1 && zEnd<zDipole1) {
496 //MagnetPropagation(zDipole1-zBeg);
497 ParPropagation(zDipole1);
498 MSThin(1); // multiple scattering in the chamber
499 WeightPropagation(zDipole1);
500 fPosition = fPositionNew;
501 *fTrackPar = *fTrackParNew;
502 //LinearPropagation(zEnd-zDipole1);
503 ParPropagation(zEnd);
504 WeightPropagation(zEnd);
505 fPosition = fPositionNew;
507 ParPropagation(zEnd);
508 //MSThin(1); // multiple scattering in the chamber
509 if (TMath::Abs(zEnd-fPosition) > 5) MSThin(1); // multiple scattering in the chamber
510 WeightPropagation(zEnd);
511 fPosition = fPositionNew;
515 if (fRecover != 0 && hitAdd == fSkipHit && !miss) {
516 // recovered track - remove the hit
518 ichamb = hitAdd->GetChamberNumber();
520 // remove the last hit
521 fTrackHitsPtr->Remove((TObjArray*)hitAdd); // remove hit
523 hitAdd->SetNTrackHits(hitAdd->GetNTrackHits()-1); // unmark hit
526 for (i=fNTrackHits-1; i>1; i--) {
527 hitAdd = (AliMUONHitForRec*)((*fTrackHitsPtr)[i]);
528 fTrackHitsPtr->Remove((TObjArray*)hitAdd); // remove hit
529 hitAdd->SetNTrackHits(hitAdd->GetNTrackHits()-1); // unmark hit
531 if (hitAdd == fSkipHit) break;
532 } // for (i=fNTrackHits-1;
535 fRecover =0; // ????????? Dec-17-2001
536 ichambOK = ((AliMUONHitForRec*)((*fTrackHitsPtr)[fNTrackHits-1]))->GetChamberNumber();
537 currIndx = fgHitForRec->IndexOf(fSkipHit);
541 // backward propagator
542 TMatrixD pointWeight(kSize,kSize);
543 TMatrixD point(kSize,1);
544 TMatrixD trackParTmp = point;
545 point(0,0) = hitAdd->GetBendingCoor();
546 point(1,0) = hitAdd->GetNonBendingCoor();
547 pointWeight(0,0) = 1/hitAdd->GetBendingReso2();
548 pointWeight(1,1) = 1/hitAdd->GetNonBendingReso2();
549 TryPoint(point,pointWeight,trackParTmp,dChi2);
550 *fTrackPar = trackParTmp;
551 *fWeight += pointWeight;
552 fChi2 += dChi2; // Chi2
553 if (ichamb==ichamEnd) break;
556 // forward propagator
557 if (miss || !FindPoint(ichamb,zEnd,currIndx,iFB,hitAdd)) {
559 *fTrackPar = *fTrackParNew;
562 fTrackHitsPtr->Add((TObjArray*)hitAdd); // add hit
564 hitAdd->SetNTrackHits(hitAdd->GetNTrackHits()+1); // mark hit as being on track
566 currIndx = fgHitForRec->IndexOf(hitAdd); // Check
570 cout << fNTrackHits << " " << fChi2 << " " << 1/(*fTrackPar)(4,0) << " " << fPosition << endl;
574 //__________________________________________________________________________
575 void AliMUONTrackK::ParPropagation(Double_t zEnd)
577 // Propagation of track parameters to zEnd
579 Double_t dZ, step, distance, charge;
580 Double_t vGeant3[7], vGeant3New[7];
583 // First step using linear extrapolation
584 dZ = zEnd - fPosition;
585 iFB = (Int_t)TMath::Sign(Double_t(1.0),dZ);
586 step = dZ/TMath::Cos((*fTrackPar)(2,0))/TMath::Cos((*fTrackPar)(3,0)); // linear estimate
587 charge = iFB*TMath::Sign(Double_t(1.0),(*fTrackPar)(4,0));
588 fPositionNew = fPosition;
589 *fTrackParNew = *fTrackPar;
590 SetGeantParam(vGeant3,iFB);
594 step = TMath::Abs(step);
595 // Propagate parameters
596 extrap_onestep_rungekutta(charge,step,vGeant3,vGeant3New);
597 distance = zEnd - vGeant3New[2];
598 step *= dZ/(vGeant3New[2]-fPositionNew);
600 } while (distance*iFB < 0 && TMath::Abs(distance) > kEpsilon);
602 GetFromGeantParam(vGeant3New,iFB);
604 // Position ajustment (until within tolerance)
605 while (TMath::Abs(distance) > kEpsilon) {
606 dZ = zEnd - fPositionNew;
607 iFB = (Int_t)TMath::Sign(Double_t(1.0),dZ);
608 step = dZ/TMath::Cos((*fTrackParNew)(2,0))/TMath::Cos((*fTrackParNew)(3,0));
609 step = TMath::Abs(step);
610 SetGeantParam(vGeant3,iFB);
613 // Propagate parameters
614 extrap_onestep_rungekutta(charge,step,vGeant3,vGeant3New);
615 distance = zEnd - vGeant3New[2];
618 if (nTries > kTriesMax) {
619 cout << " ***** ParPropagation: too many tries " << nTries << endl;
622 } while (distance*iFB < 0);
624 GetFromGeantParam(vGeant3New,iFB);
626 //cout << nTries << endl;
630 //__________________________________________________________________________
631 void AliMUONTrackK::WeightPropagation(void)
633 // Propagation of the weight matrix
634 // W = DtWD, where D is Jacobian
636 // !!! not implemented TMatrixD weight1(*fJacob,TMatrixD::kAtBA,*fWeight); // DtWD
637 TMatrixD weight1(*fWeight,TMatrixD::kMult,*fJacob); // WD
638 *fWeight = TMatrixD(*fJacob,TMatrixD::kTransposeMult,weight1); // DtWD
642 //__________________________________________________________________________
643 void AliMUONTrackK::WeightPropagation(Double_t zEnd)
645 // Propagation of the weight matrix
646 // W = DtWD, where D is Jacobian
650 TMatrixD Jacob(kSize,kSize);
653 // Save initial and propagated parameters
654 TMatrixD trackPar0 = *fTrackPar;
655 TMatrixD trackParNew0 = *fTrackParNew;
656 Double_t savePosition = fPositionNew;
658 // Get covariance matrix
659 *fCovariance = *fWeight;
660 // check whether the Invert method returns flag if matrix cannot be inverted,
661 // and do not calculate the Determinant in that case !!!!
662 if (fCovariance->Determinant() != 0) {
663 // fCovariance->Invert();
665 mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
667 cout << " ***** Warning in WeightPropagation: Determinant fCovariance=0:" << endl;
670 // Loop over parameters to find change of the initial vs propagated ones
672 fPosition = fPositionNew;
673 for (i=0; i<kSize; i++) {
674 dPar = TMath::Sqrt((*fCovariance)(i,i));
675 *fTrackPar = trackParNew0;
676 (*fTrackPar)(i,0) += dPar;
677 ParPropagation(zEnd);
678 for (j=0; j<kSize; j++) {
679 Jacob(j,i) = ((*fTrackParNew)(j,0)-trackPar0(j,0))/dPar;
684 //trackParNew0.Print();
685 //TMatrixD par1(Jacob,TMatrixD::kMult,trackPar0); //
688 if (Jacob.Determinant() != 0) {
691 cout << " ***** Warning in WeightPropagation: Determinant Jacob=0:" << endl;
694 TMatrixD weight1(*fWeight,TMatrixD::kMult,Jacob); // WD
695 *fWeight = TMatrixD(Jacob,TMatrixD::kTransposeMult,weight1); // DtWD
698 // Restore initial and propagated parameters
699 *fTrackPar = trackPar0;
700 *fTrackParNew = trackParNew0;
702 fPositionNew = savePosition;
706 //__________________________________________________________________________
707 Bool_t AliMUONTrackK::FindPoint(Int_t ichamb, Double_t zEnd, Int_t currIndx, Int_t iFB, AliMUONHitForRec *&hitAdd)
709 // Picks up point within a window for the chamber No ichamb
710 // Split the track if there are more than 1 hit
711 Int_t ihit, nRecTracks;
712 Double_t WindowB, WindowNonB, dChi2Tmp=0, dChi2, y, x, savePosition=0;
713 TClonesArray *trackPtr;
714 AliMUONHitForRec *hit, *hitLoop;
715 AliMUONTrackK *trackK;
718 //sigmaB = fgEventReconstructor->GetBendingResolution(); // bending resolution
719 //sigmaNonB = fgEventReconstructor->GetNonBendingResolution(); // non-bending resolution
720 *fCovariance = *fWeight;
721 // check whether the Invert method returns flag if matrix cannot be inverted,
722 // and do not calculate the Determinant in that case !!!!
723 if (fCovariance->Determinant() != 0) {
724 // fCovariance->Invert();
727 mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
729 cout << " ***** Warning in FindPoint: Determinant fCovariance=0:" << endl;
731 //WindowB = kNSigma*TMath::Sqrt((*fCovariance)(0,0)+sigmaB*sigmaB);
732 //WindowNonB = kNSigma*TMath::Sqrt((*fCovariance)(1,1)+sigmaNonB*sigmaNonB);
733 // Loop over all hits and take hits from the chamber
734 TMatrixD pointWeight(kSize,kSize);
735 TMatrixD saveWeight = pointWeight;
736 TMatrixD pointWeightTmp = pointWeight;
737 TMatrixD point(kSize,1);
738 TMatrixD trackPar = point;
739 TMatrixD trackParTmp = point;
742 for (ihit=currIndx; ihit>=0 && ihit<fgNOfPoints; ihit+=iFB) {
743 hit = (AliMUONHitForRec*) ((*fgHitForRec)[ihit]);
744 if (hit->GetChamberNumber() == ichamb) {
745 //if (TMath::Abs(hit->GetZ()-zEnd) < 0.1) {
746 if (TMath::Abs(hit->GetZ()-zEnd) < 0.5) {
747 if (TMath::Abs(hit->GetZ()-zEnd) > 0.1) {
748 // adjust position: for multiple hits in the chamber
749 // (mostly (only?) for GEANT hits)
751 *fTrackPar = *fTrackParNew;
752 ParPropagation(zEnd);
753 WeightPropagation(zEnd);
754 fPosition = fPositionNew;
755 *fTrackPar = *fTrackParNew;
757 *fCovariance = *fWeight;
758 if (fCovariance->Determinant() != 0) {
759 //fCovariance->Invert();
761 mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
763 cout << " ***** Warning in FindPoint: Determinant fCovariance=0:" << endl;
766 y = hit->GetBendingCoor();
767 x = hit->GetNonBendingCoor();
768 WindowB = kNSigma*TMath::Sqrt((*fCovariance)(0,0)+hit->GetBendingReso2());
769 WindowNonB = kNSigma*TMath::Sqrt((*fCovariance)(1,1)+hit->GetNonBendingReso2());
770 if (TMath::Abs((*fTrackParNew)(0,0)-y) <= WindowB &&
771 TMath::Abs((*fTrackParNew)(1,0)-x) <= WindowNonB) {
772 // Vector of measurements and covariance matrix
776 pointWeight(0,0) = 1/hit->GetBendingReso2();
777 pointWeight(1,1) = 1/hit->GetNonBendingReso2();
778 TryPoint(point,pointWeight,trackPar,dChi2);
779 if (TMath::Abs(1./(trackPar)(4,0)) < fgEventReconstructor->GetMinBendingMomentum()) continue; // p < p_min - next hit
782 //if (nHitsOK > -1) {
784 // Save current members
785 saveWeight = *fWeight;
786 savePosition = fPosition;
787 // temporary storage for the current track
789 trackParTmp = trackPar;
790 pointWeightTmp = pointWeight;
793 // branching: create a new track
794 trackPtr = fgEventReconstructor->GetRecTracksPtr();
795 nRecTracks = fgEventReconstructor->GetNRecTracks();
796 trackK = new ((*trackPtr)[nRecTracks])
797 AliMUONTrackK(*this); // dummy copy constructor
799 fgEventReconstructor->SetNRecTracks(nRecTracks+1);
800 //cout << " ******** New track: " << ichamb << " " << hit->GetTHTrack() << " " << 1/(trackPar)(4,0) << " " << hit->GetBendingCoor() << " " << fNTrackHits << " " << nRecTracks << endl;
801 trackK->fRecover = 0;
802 *(trackK->fTrackPar) = trackPar;
803 *(trackK->fWeight) += pointWeight;
804 trackK->fChi2 += dChi2;
805 // Mark hits as being on 2 tracks
806 for (Int_t i=0; i<fNTrackHits; i++) {
807 hitLoop = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
808 hitLoop->SetNTrackHits(hitLoop->GetNTrackHits()+1);
811 cout << hitLoop->GetChamberNumber() << " ";
812 cout << hitLoop->GetBendingCoor() << " ";
813 cout << hitLoop->GetNonBendingCoor() << " ";
814 cout << hitLoop->GetZ() << " " << " ";
815 cout << hitLoop->GetGeantSignal() << " " << " ";
816 cout << hitLoop->GetTHTrack() << endl;
817 printf(" ** %d %10.4f %10.4f %10.4f %d %d \n",
818 hitLoop->GetChamberNumber(), hitLoop->GetBendingCoor(),
819 hitLoop->GetNonBendingCoor(), hitLoop->GetZ(),
820 hitLoop->GetGeantSignal(), hitLoop->GetTHTrack());
824 trackK->fTrackHitsPtr->Add((TObjArray*)hit); // add hit
825 trackK->fNTrackHits ++;
826 hit->SetNTrackHits(hit->GetNTrackHits()+1); // mark hit as being on track
829 trackK->fTrackDir = -1;
830 trackK->fBPFlag = kTRUE;
835 } else break; // different chamber
836 } // for (ihit=currIndx;
838 *fTrackPar = trackParTmp;
839 *fWeight = saveWeight;
840 *fWeight += pointWeightTmp;
841 fChi2 += dChi2Tmp; // Chi2
843 fPosition = savePosition;
848 //__________________________________________________________________________
849 void AliMUONTrackK::TryPoint(TMatrixD &point, const TMatrixD &pointWeight, TMatrixD &trackParTmp, Double_t &dChi2)
851 // Adds a measurement point (modifies track parameters and computes
854 // Solving linear system (W+U)p' = U(m-p) + (W+U)p
855 TMatrixD wu = *fWeight;
856 wu += pointWeight; // W+U
858 trackParTmp -= *fTrackParNew; // m-p
859 TMatrixD right(pointWeight,TMatrixD::kMult,trackParTmp); // U(m-p)
860 TMatrixD right1(wu,TMatrixD::kMult,*fTrackParNew); // (W+U)p
861 right += right1; // U(m-p) + (W+U)p
863 // check whether the Invert method returns flag if matrix cannot be inverted,
864 // and do not calculate the Determinant in that case !!!!
865 if (wu.Determinant() != 0) {
869 mnvertLocalK(&((wu)(0,0)), kSize,kSize,kSize,ifailWU);
871 cout << " ***** Warning in TryPoint: Determinant wu=0:" << endl;
873 trackParTmp = TMatrixD(wu,TMatrixD::kMult,right);
875 right1 = trackParTmp;
876 right1 -= point; // p'-m
878 point -= *fTrackParNew; // p'-p
879 right = TMatrixD(*fWeight,TMatrixD::kMult,point); // W(p'-p)
880 TMatrixD value(point,TMatrixD::kTransposeMult,right); // (p'-p)'W(p'-p)
882 right = TMatrixD(pointWeight,TMatrixD::kMult,right1); // U(p'-m)
883 value = TMatrixD(right1,TMatrixD::kTransposeMult,right); // (p'-m)'U(p'-m)
888 //__________________________________________________________________________
889 void AliMUONTrackK::MSThin(Int_t sign)
891 // Adds multiple scattering in a thin layer (only angles are affected)
892 Double_t cosAlph, cosBeta, momentum, velo, path, theta0;
894 // check whether the Invert method returns flag if matrix cannot be inverted,
895 // and do not calculate the Determinant in that case !!!!
896 if (fWeight->Determinant() != 0) {
897 //fWeight->Invert(); // covariance
900 mnvertLocalK(&((*fWeight)(0,0)), kSize,kSize,kSize,ifailWeight);
902 cout << " ***** Warning in MSThin: Determinant fWeight=0:" << endl;
905 cosAlph = TMath::Cos((*fTrackParNew)(2,0));
906 cosBeta = TMath::Cos((*fTrackParNew)(3,0));
907 momentum = 1/(*fTrackParNew)(4,0); // particle momentum
908 //velo = momentum/TMath::Sqrt(momentum*momentum+muonMass*muonMass); // velocity/c for muon hypothesis
909 velo = 1; // relativistic
910 path = fgEventReconstructor->GetChamberThicknessInX0()/cosAlph/cosBeta; // path length
911 theta0 = 0.0136/velo/momentum*TMath::Sqrt(path)*(1+0.038*TMath::Log(path)); // projected scattering angle
913 (*fWeight)(2,2) += sign*theta0/cosBeta*theta0/cosBeta; // alpha
914 (*fWeight)(3,3) += sign*theta0*theta0; // beta
915 //fWeight->Invert(); // weight
918 mnvertLocalK(&((*fWeight)(0,0)), kSize,kSize,kSize,ifailWeight);
921 //__________________________________________________________________________
922 void AliMUONTrackK::StartBack(void)
924 // Starts backpropagator
928 for (Int_t i=0; i<kSize; i++) {
929 for (Int_t j=0; j<kSize; j++) {
930 if (j==i) (*fWeight)(i,i) /= 100;
931 //if (j==i) (*fWeight)(i,i) /= fNTrackHits*fNTrackHits;
932 else (*fWeight)(j,i) = 0;
937 //__________________________________________________________________________
938 void AliMUONTrackK::SetGeantParam(Double_t *VGeant3, Int_t iFB)
940 // Set vector of Geant3 parameters pointed to by "VGeant3"
941 // from track parameters
943 VGeant3[0] = (*fTrackParNew)(1,0); // X
944 VGeant3[1] = (*fTrackParNew)(0,0); // Y
945 VGeant3[2] = fPositionNew; // Z
946 VGeant3[3] = iFB*TMath::Sin((*fTrackParNew)(3,0)); // Px/Ptot
947 VGeant3[4] = iFB*TMath::Cos((*fTrackParNew)(3,0))*TMath::Sin((*fTrackParNew)(2,0)); // Py/Ptot
948 VGeant3[5] = iFB*TMath::Sqrt(1.0-VGeant3[3]*VGeant3[3]-VGeant3[4]*VGeant3[4]); // Pz/Ptot
949 VGeant3[6] = 1/TMath::Abs((*fTrackParNew)(4,0)); // Ptot
952 //__________________________________________________________________________
953 void AliMUONTrackK::GetFromGeantParam(Double_t *VGeant3, Int_t iFB)
955 // Get track parameters from vector of Geant3 parameters pointed
958 fPositionNew = VGeant3[2]; // Z
959 (*fTrackParNew)(0,0) = VGeant3[1]; // Y
960 (*fTrackParNew)(1,0) = VGeant3[0]; // X
961 (*fTrackParNew)(3,0) = TMath::ASin(iFB*VGeant3[3]); // beta
962 (*fTrackParNew)(2,0) = TMath::ASin(iFB*VGeant3[4]/TMath::Cos((*fTrackParNew)(3,0))); // alpha
963 (*fTrackParNew)(4,0) = 1/VGeant3[6]*TMath::Sign(Double_t(1.0),(*fTrackPar)(4,0)); // 1/Ptot
966 //__________________________________________________________________________
967 void AliMUONTrackK::SetTrackQuality(Int_t iChi2)
969 // Computes "track quality" from Chi2 (if iChi2==0) or vice versa
972 cout << " ***** Too high Chi2: " << fChi2 << endl;
976 if (iChi2 == 0) fChi2 = fNTrackHits + (250.-fChi2)/251;
977 else fChi2 = 250 - (fChi2-fNTrackHits)*251;
980 //__________________________________________________________________________
981 Int_t AliMUONTrackK::Compare(const TObject* trackK) const
983 // "Compare" function to sort with decreasing "track quality".
984 // Returns +1 (0, -1) if quality of current track
985 // is smaller than (equal to, larger than) quality of trackK
987 if (fChi2 < ((AliMUONTrackK*)trackK)->fChi2) return(+1);
988 else if (fChi2 == ((AliMUONTrackK*)trackK)->fChi2) return(0);
992 //__________________________________________________________________________
993 Bool_t AliMUONTrackK::KeepTrack(AliMUONTrackK* track0)
995 // Check whether or not to keep current track
996 // (keep, if it has less than half of common hits with track0)
997 Int_t hitsInCommon, nHits0, i, j, nTrackHits2;
998 AliMUONHitForRec *hit0, *hit1;
1001 nHits0 = track0->fNTrackHits;
1002 nTrackHits2 = fNTrackHits/2;
1004 for (i=0; i<nHits0; i++) {
1005 // Check if hit belongs to several tracks
1006 hit0 = (AliMUONHitForRec*) (*track0->fTrackHitsPtr)[i];
1007 if (hit0->GetNTrackHits() == 1) continue;
1008 for (j=0; j<fNTrackHits; j++) {
1009 hit1 = (AliMUONHitForRec*) (*fTrackHitsPtr)[j];
1010 if (hit1->GetNTrackHits() == 1) continue;
1013 if (hitsInCommon >= nTrackHits2) return kFALSE;
1021 //__________________________________________________________________________
1022 void AliMUONTrackK::Kill(void)
1024 // Kill track candidate
1026 AliMUONHitForRec *hit;
1028 if (fTrackHitsPtr) {
1029 // Remove track mark from hits
1030 for (i=0; i<fNTrackHits; i++) {
1031 hit = (AliMUONHitForRec*) (*fTrackHitsPtr)[i];
1032 hit->SetNTrackHits(hit->GetNTrackHits()-1);
1035 fgEventReconstructor->GetRecTracksPtr()->Remove(this);
1038 //__________________________________________________________________________
1039 void AliMUONTrackK::Branson(void)
1041 // Propagates track to the vertex thru absorber using Branson correction
1042 // (makes use of the AliMUONTrackParam class)
1044 AliMUONTrackParam *trackParam = new AliMUONTrackParam();
1045 trackParam->SetBendingCoor((*fTrackPar)(0,0));
1046 trackParam->SetNonBendingCoor((*fTrackPar)(1,0));
1047 trackParam->SetBendingSlope(TMath::Tan((*fTrackPar)(2,0)));
1048 trackParam->SetNonBendingSlope(TMath::Tan((*fTrackPar)(3,0))/TMath::Cos((*fTrackPar)(2,0)));
1049 trackParam->SetInverseBendingMomentum((*fTrackPar)(4,0)/TMath::Cos((*fTrackPar)(3,0)));
1050 trackParam->SetZ(fPosition);
1052 trackParam->ExtrapToVertex();
1054 (*fTrackPar)(0,0) = trackParam->GetBendingCoor();
1055 (*fTrackPar)(1,0) = trackParam->GetNonBendingCoor();
1056 (*fTrackPar)(2,0) = TMath::ATan(trackParam->GetBendingSlope());
1057 (*fTrackPar)(3,0) = TMath::ATan(TMath::Cos((*fTrackPar)(2,0))*trackParam->GetNonBendingSlope());
1058 (*fTrackPar)(4,0) = TMath::Cos((*fTrackPar)(3,0))*trackParam->GetInverseBendingMomentum();
1059 fPosition = trackParam->GetZ();
1061 cout << 1/(*fTrackPar)(4,0) << " " << fPosition << " " << (*fTrackPar)(0,0) << endl;
1063 // Get covariance matrix
1064 *fCovariance = *fWeight;
1065 if (fCovariance->Determinant() != 0) {
1066 // fCovariance->Invert();
1069 mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
1071 cout << " ***** Warning in Branson: Determinant fCovariance=0:" << endl;
1075 //__________________________________________________________________________
1076 void AliMUONTrackK::GoToZ(Double_t zEnd)
1078 // Propagates track to given Z
1080 ParPropagation(zEnd);
1081 MSThin(1); // multiple scattering in the chamber
1082 WeightPropagation(zEnd);
1083 fPosition = fPositionNew;
1084 *fTrackPar = *fTrackParNew;
1087 //__________________________________________________________________________
1088 void AliMUONTrackK::GoToVertex(void)
1091 // Propagates track to the vertex
1092 // All material constants are taken from AliRoot
1094 static Double_t x01[5] = { 24.282, // C
1099 // inner part theta < 3 degrees
1100 static Double_t x02[5] = { 30413, // Air
1105 // z positions of the materials inside the absober outer part theta > 3 degres
1106 static Double_t zPos[10] = {90, 105, 315, 443, 468};
1110 Double_t dZ, r0Norm, X0, deltaP, dChi2, pTotal, pOld;
1111 AliMUONHitForRec *hit;
1112 AliMUONRawCluster *clus;
1113 TClonesArray *rawclusters;
1115 // First step to the rear end of the absorber
1116 Double_t zRear = 503;
1118 Double_t tan3 = TMath::Tan(3./180*TMath::Pi());
1120 // Go through absorber
1121 pOld = 1/(*fTrackPar)(4,0);
1122 Double_t r0Rear = (*fTrackPar)(0,0)*(*fTrackPar)(0,0) +
1123 (*fTrackPar)(1,0)*(*fTrackPar)(1,0);
1124 r0Rear = TMath::Sqrt(r0Rear)/fPosition/tan3;
1126 for (Int_t i=4; i>=0; i--) {
1127 ParPropagation(zPos[i]);
1128 WeightPropagation(zPos[i]);
1129 dZ = TMath::Abs (fPositionNew-fPosition);
1130 if (r0Norm > 1) X0 = x01[i];
1132 MSLine(dZ,X0); // multiple scattering in the medium (linear approximation)
1133 fPosition = fPositionNew;
1134 *fTrackPar = *fTrackParNew;
1135 r0Norm = (*fTrackPar)(0,0)*(*fTrackPar)(0,0) +
1136 (*fTrackPar)(1,0)*(*fTrackPar)(1,0);
1137 r0Norm = TMath::Sqrt(r0Norm)/fPosition/tan3;
1139 // Correct momentum for energy losses
1140 pTotal = 1/TMath::Abs((*fTrackPar)(4,0));
1141 Double_t p0 = pTotal;
1142 for (Int_t j=0; j<2; j++) {
1146 deltaP = 2.164 + 0.145e-1*p0 - 0.417e-3*p0*p0;
1148 deltaP = 2.275 + 0.102e-2*p0 - 0.674e-6*p0*p0;
1152 deltaP = 2.581 + 0.188e-1*p0 - 0.398e-3*p0*p0;
1154 deltaP = 2.727 + 0.356e-2*p0 + 0.242e-5*p0*p0;
1161 deltaP = 2.737 + 0.0494*p0 - 0.001123*p0*p0;
1163 deltaP = 3.0643 + 0.01346*p0;
1168 deltaP = 2.1380 + 0.0351*p0 - 0.000853*p0*p0;
1170 deltaP = 2.407 + 0.00702*p0;
1174 p0 = pTotal + deltaP/TMath::Cos((*fTrackPar)(2,0))/TMath::Cos((*fTrackPar)(3,0));
1176 (*fTrackPar)(4,0) = 1/p0*TMath::Sign((Double_t)1.,(*fTrackPar)(4,0));
1179 ParPropagation((Double_t)0.);
1180 WeightPropagation((Double_t)0.);
1181 fPosition = fPositionNew;
1182 //*fTrackPar = *fTrackParNew;
1183 // Add vertex as a hit
1184 TMatrixD pointWeight(kSize,kSize);
1185 TMatrixD point(kSize,1);
1186 TMatrixD trackParTmp = point;
1187 point(0,0) = 0; // vertex coordinate - should be taken somewhere
1188 point(1,0) = 0; // vertex coordinate - should be taken somewhere
1189 pointWeight(0,0) = 1/1.e-3/1.e-3; // 10 um error
1190 pointWeight(1,1) = 1/1.e-3/1.e-3; // 10 um error
1191 TryPoint(point,pointWeight,trackParTmp,dChi2);
1192 *fTrackPar = trackParTmp;
1193 *fWeight += pointWeight;
1194 fChi2 += dChi2; // Chi2
1195 cout << pOld << " " << 1/(*fTrackPar)(4,0) << " " << dChi2 << " " << fChi2 << " " << fNTrackHits << endl;
1196 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1197 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
1198 printf ("%4d", hit->GetChamberNumber());
1199 //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetChamberNumber() << " ";
1202 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1203 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
1204 //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetHitNumber() << " ";
1205 //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetZ() << " ";
1206 printf ("%4d", fgHitForRec->IndexOf(hit));
1207 //cout << fgHitForRec->IndexOf(((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))) << " ";
1210 if (fgEventReconstructor->GetRecGeantHits()) {
1212 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1213 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
1214 cout << hit->GetTHTrack() + hit->GetGeantSignal()*10000 << " ";
1217 // from raw clusters
1218 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1219 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
1220 rawclusters = fgMUON->RawClustAddress(hit->GetChamberNumber());
1221 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
1222 printf ("%4d", clus->fTracks[1] - 1);
1223 //cout << clus->fTracks[1] - 1 << " ";
1226 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1227 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
1228 rawclusters = fgMUON->RawClustAddress(hit->GetChamberNumber());
1229 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
1230 if (clus->fTracks[2] != 0) printf ("%4d", clus->fTracks[2] - 1);
1231 else printf ("%4s", " ");
1232 //if (clus->fTracks[2] != 0) cout << clus->fTracks[2] - 1 << " ";
1236 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1237 //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetHitNumber() << " ";
1238 cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetZ() << " ";
1239 //cout << fgHitForRec->IndexOf(((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))) << " ";
1242 cout << "---------------------------------------------------" << endl;
1244 // Get covariance matrix
1245 *fCovariance = *fWeight;
1246 if (fCovariance->Determinant() != 0) {
1247 // fCovariance->Invert();
1250 mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
1252 cout << " ***** Warning in GoToVertex: Determinant fCovariance=0:" << endl;
1256 //__________________________________________________________________________
1257 void AliMUONTrackK::MSLine(Double_t dZ, Double_t X0)
1259 // Adds multiple scattering in a thick layer for linear propagation
1261 Double_t cosAlph = TMath::Cos((*fTrackPar)(2,0));
1262 Double_t tanAlph = TMath::Tan((*fTrackPar)(2,0));
1263 Double_t cosBeta = TMath::Cos((*fTrackPar)(3,0));
1265 sinBeta = TMath::Sin((*fTrackPar)(3,0));
1266 Double_t tanBeta = TMath::Tan((*fTrackPar)(3,0));
1267 Double_t momentum = 1/(*fTrackPar)(4,0);
1268 Double_t velo = 1; // relativistic velocity
1269 Double_t step = TMath::Abs(dZ)/cosAlph/cosBeta; // step length
1271 // Projected scattering angle
1272 Double_t theta0 = 0.0136/velo/momentum/TMath::Sqrt(X0)*(1+0.038*TMath::Log(step/X0));
1273 Double_t theta02 = theta0*theta0;
1274 Double_t dl2 = step*step/2*theta02;
1275 Double_t dl3 = dl2*step*2/3;
1278 Double_t dYdT = 1/cosAlph;
1279 Double_t dYdB = 0; //(*fTrackPar)(2,0)*sinBeta/cosAlph;
1280 Double_t dXdT = tanAlph*tanBeta;
1281 //Double_t dXdB = (1+(*fTrackPar)(2,0)*tanAlph*sinBeta*sinBeta)/cosBeta;
1282 Double_t dXdB = 1/cosBeta;
1283 Double_t dAdT = 1/cosBeta;
1284 Double_t dAdB = 0; //(*fTrackPar)(2,0)*tanBeta;
1286 // Get covariance matrix
1287 *fCovariance = *fWeight;
1288 if (fCovariance->Determinant() != 0) {
1289 // fCovariance->Invert();
1292 mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
1294 cout << " ***** Warning in MSLine: Determinant fCovariance=0:" << endl;
1297 (*fCovariance)(0,0) += dl3*(dYdT*dYdT+dYdB*dYdB); // <yy>
1298 (*fCovariance)(1,1) += dl3*(dXdT*dXdT+dXdB*dXdB); // <xx>
1299 (*fCovariance)(2,2) += theta02*step*(dAdT*dAdT+dAdB*dAdB); // <aa>
1300 (*fCovariance)(3,3) += theta02*step; // <bb>
1302 (*fCovariance)(0,1) += dl3*(dYdT*dXdT+dYdB*dXdB); // <yx>
1303 (*fCovariance)(1,0) = (*fCovariance)(0,1);
1305 (*fCovariance)(0,2) += dl2*(dYdT*dAdT+dYdB*dAdB); // <ya>
1306 (*fCovariance)(2,0) = (*fCovariance)(0,2);
1308 (*fCovariance)(0,3) += dl2*dYdB; // <yb>
1309 (*fCovariance)(3,0) = (*fCovariance)(0,3);
1311 (*fCovariance)(1,2) += dl2*(dXdT*dAdT+dXdB*dAdB); // <xa>
1312 (*fCovariance)(2,1) = (*fCovariance)(1,2);
1314 (*fCovariance)(1,3) += dl2*dXdB; // <xb>
1315 (*fCovariance)(3,1) = (*fCovariance)(1,3);
1317 (*fCovariance)(2,3) += theta02*step*dAdB; // <ab>
1318 (*fCovariance)(3,2) = (*fCovariance)(2,3);
1320 // Get weight matrix
1321 *fWeight = *fCovariance;
1322 if (fWeight->Determinant() != 0) {
1323 // fWeight->Invert();
1326 mnvertLocalK(&((*fWeight)(0,0)), kSize,kSize,kSize,ifailWeight);
1328 cout << " ***** Warning in MSLine: Determinant fWeight=0:" << endl;
1332 //__________________________________________________________________________
1333 void AliMUONTrackK::Recover(void)
1335 // Adds new failed track(s) which can be tried to be recovered
1336 Int_t nRecTracks, ichamb;
1337 TClonesArray *trackPtr;
1338 AliMUONTrackK *trackK;
1340 //cout << " ******** Enter Recover " << endl;
1342 trackPtr = fgEventReconstructor->GetRecTracksPtr();
1344 // The last hit will be removed
1345 nRecTracks = fgEventReconstructor->GetNRecTracks();
1347 // Check if the track candidate doesn't exist yet
1348 for (Int_t i=0; i<nRecTracks; i++) {
1349 trackK = (AliMUONTrackK*) ((*trackPtr)[i]);
1350 if (trackK->fNTrackHits == 2 && trackK->GetRecover() == 0) continue;
1351 if (trackK == this) continue;
1352 //if (trackK->GetRecover() != 1) continue;
1353 if (trackK->fNTrackHits >= fNTrackHits-1) {
1355 for (Int_t j=0; j<fNTrackHits-1; j++) {
1356 if ((*trackK->fTrackHitsPtr)[j] != ((*fTrackHitsPtr)[j])) break;
1358 } // for (Int_t j=0;
1360 if ((*trackK->fTrackHitsPtr)[0] == ((*fTrackHitsPtr)[0])) return;
1362 } // for (Int_t i=0;
1364 cout << " ******** Enter Recover " << endl;
1365 trackK = new ((*trackPtr)[nRecTracks]) AliMUONTrackK(fStartSegment);
1366 fgEventReconstructor->SetNRecTracks(nRecTracks+1);
1367 trackK->fRecover = 1;
1368 trackK->fSkipHit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[fNTrackHits-1]);
1369 trackK->fNTrackHits = fNTrackHits;
1370 delete trackK->fTrackHitsPtr; // not efficient ?
1371 trackK->fTrackHitsPtr = new TObjArray(*fTrackHitsPtr);
1372 cout << nRecTracks << " " << trackK->fRecover << endl;
1374 // The hit before missing chamber will be removed
1375 Int_t ichamBeg = ((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetChamberNumber();
1376 Int_t indxSkip = -1;
1377 if (ichamBeg == 9) {
1378 // segment in the last station
1379 // look for the missing chamber
1380 for (Int_t i=1; i<fNTrackHits; i++) {
1381 ichamb = ((AliMUONHitForRec*)((*fTrackHitsPtr)[i]))->GetChamberNumber();
1382 if (TMath::Abs(ichamBeg-ichamb)>1 && i>2) {
1387 } // for (Int_t i=1;
1389 // in the last but one station
1390 for (Int_t i=1; i<fNTrackHits; i++) {
1391 ichamb = ((AliMUONHitForRec*)((*fTrackHitsPtr)[i]))->GetChamberNumber();
1392 if (TMath::Abs(ichamBeg-ichamb)>1 && ichamb<4) {
1397 } // for (Int_t i=1;
1399 if (indxSkip < 0) return;
1401 // Check if the track candidate doesn't exist yet
1402 for (Int_t i=0; i<nRecTracks; i++) {
1403 trackK = (AliMUONTrackK*) ((*trackPtr)[i]);
1404 if (trackK->fNTrackHits == 2 && trackK->GetRecover() == 0) continue;
1405 if (trackK == this) continue;
1406 //if (trackK->GetRecover() != 1) continue;
1407 if (trackK->fNTrackHits >= indxSkip-1) {
1409 for (Int_t j=0; j<indxSkip-1; j++) {
1410 if ((*trackK->fTrackHitsPtr)[j] != ((*fTrackHitsPtr)[j])) break;
1412 } // for (Int_t j=0;
1414 if ((*trackK->fTrackHitsPtr)[0] == ((*fTrackHitsPtr)[0])) return;
1416 } // for (Int_t i=0;
1418 nRecTracks = fgEventReconstructor->GetNRecTracks();
1419 trackK = new ((*trackPtr)[nRecTracks]) AliMUONTrackK(fStartSegment);
1420 fgEventReconstructor->SetNRecTracks(nRecTracks+1);
1421 trackK->fRecover = 2;
1422 trackK->fSkipHit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[indxSkip-1]);
1423 trackK->fNTrackHits = fNTrackHits;
1424 delete trackK->fTrackHitsPtr; // not efficient ?
1425 trackK->fTrackHitsPtr = new TObjArray(*fTrackHitsPtr);
1426 cout << nRecTracks << " " << trackK->fRecover << endl;
1429 //______________________________________________________________________________
1430 void mnvertLocalK(Double_t *a, Int_t l, Int_t, Int_t n, Int_t &ifail)
1432 //*-*-*-*-*-*-*-*-*-*-*-*Inverts a symmetric matrix*-*-*-*-*-*-*-*-*-*-*-*-*
1433 //*-* ==========================
1434 //*-* inverts a symmetric matrix. matrix is first scaled to
1435 //*-* have all ones on the diagonal (equivalent to change of units)
1436 //*-* but no pivoting is done since matrix is positive-definite.
1437 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1439 // taken from TMinuit package of Root (l>=n)
1440 // fVERTs, fVERTq and fVERTpp changed to localVERTs, localVERTq and localVERTpp
1441 // Double_t localVERTs[n], localVERTq[n], localVERTpp[n];
1442 Double_t * localVERTs = new Double_t[n];
1443 Double_t * localVERTq = new Double_t[n];
1444 Double_t * localVERTpp = new Double_t[n];
1445 // fMaxint changed to localMaxint
1446 Int_t localMaxint = n;
1448 /* System generated locals */
1451 /* Local variables */
1453 Int_t i, j, k, kp1, km1;
1455 /* Parameter adjustments */
1461 if (n < 1) goto L100;
1462 if (n > localMaxint) goto L100;
1463 //*-*- scale matrix by sqrt of diag elements
1464 for (i = 1; i <= n; ++i) {
1466 if (si <= 0) goto L100;
1467 localVERTs[i-1] = 1 / TMath::Sqrt(si);
1469 for (i = 1; i <= n; ++i) {
1470 for (j = 1; j <= n; ++j) {
1471 a[i + j*l] = a[i + j*l]*localVERTs[i-1]*localVERTs[j-1];
1474 //*-*- . . . start main loop . . . .
1475 for (i = 1; i <= n; ++i) {
1477 //*-*- preparation for elimination step1
1478 if (a[k + k*l] != 0) localVERTq[k-1] = 1 / a[k + k*l];
1480 localVERTpp[k-1] = 1;
1484 if (km1 < 0) goto L100;
1485 else if (km1 == 0) goto L50;
1488 for (j = 1; j <= km1; ++j) {
1489 localVERTpp[j-1] = a[j + k*l];
1490 localVERTq[j-1] = a[j + k*l]*localVERTq[k-1];
1494 if (k - n < 0) goto L51;
1495 else if (k - n == 0) goto L60;
1498 for (j = kp1; j <= n; ++j) {
1499 localVERTpp[j-1] = a[k + j*l];
1500 localVERTq[j-1] = -a[k + j*l]*localVERTq[k-1];
1503 //*-*- elimination proper
1505 for (j = 1; j <= n; ++j) {
1506 for (k = j; k <= n; ++k) { a[j + k*l] += localVERTpp[j-1]*localVERTq[k-1]; }
1509 //*-*- elements of left diagonal and unscaling
1510 for (j = 1; j <= n; ++j) {
1511 for (k = 1; k <= j; ++k) {
1512 a[k + j*l] = a[k + j*l]*localVERTs[k-1]*localVERTs[j-1];
1513 a[j + k*l] = a[k + j*l];
1520 //*-*- failure return