Replacing some cout << by AliWarning and AliError to reduce output; small bug fix...
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackK.cxx
CommitLineData
83dbc640 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
b035a148 16/* $Id$ */
83dbc640 17
b035a148 18#include <stdlib.h> // for exit()
83dbc640 19#include <Riostream.h>
20#include <TClonesArray.h>
b035a148 21#include <TArrayD.h>
83dbc640 22#include <TMatrixD.h>
83dbc640 23
30178c30 24#include "AliMUONTrackK.h"
83dbc640 25#include "AliMUON.h"
cc87ebcd 26
29f1b13a 27#include "AliMUONTrackReconstructor.h"
ef3eee8c 28#include "AliMagF.h"
83dbc640 29#include "AliMUONSegment.h"
30#include "AliMUONHitForRec.h"
31#include "AliMUONRawCluster.h"
32#include "AliMUONTrackParam.h"
cc87ebcd 33#include "AliMUONEventRecoCombi.h"
34#include "AliMUONDetElement.h"
83dbc640 35#include "AliRun.h"
8c343c7c 36#include "AliLog.h"
83dbc640 37
343146bf 38const Int_t AliMUONTrackK::fgkSize = 5;
b21aa6eb 39const Int_t AliMUONTrackK::fgkNSigma = 12;
40const Double_t AliMUONTrackK::fgkChi2max = 100;
343146bf 41const Int_t AliMUONTrackK::fgkTriesMax = 10000;
42const Double_t AliMUONTrackK::fgkEpsilon = 0.002;
43
b21aa6eb 44void mnvertLocal(Double_t* a, Int_t l, Int_t m, Int_t n, Int_t& ifail); // from AliMUONTrack
83dbc640 45
46ClassImp(AliMUONTrackK) // Class implementation in ROOT context
47
cc87ebcd 48 Int_t AliMUONTrackK::fgDebug = -1; //-1;
83dbc640 49Int_t AliMUONTrackK::fgNOfPoints = 0;
29f1b13a 50AliMUONTrackReconstructor* AliMUONTrackK::fgTrackReconstructor = NULL;
83dbc640 51TClonesArray* AliMUONTrackK::fgHitForRec = NULL;
cc87ebcd 52AliMUONEventRecoCombi *AliMUONTrackK::fgCombi = NULL;
b035a148 53//FILE *lun1 = fopen("window.dat","w");
83dbc640 54
55 //__________________________________________________________________________
56AliMUONTrackK::AliMUONTrackK()
b035a148 57 //AZ: TObject()
58 : AliMUONTrack()
83dbc640 59{
60 // Default constructor
61
b21aa6eb 62 fgTrackReconstructor = NULL; // pointer to event reconstructor
83dbc640 63 fgHitForRec = NULL; // pointer to points
64 fgNOfPoints = 0; // number of points
65
66 fStartSegment = NULL;
67 fTrackHitsPtr = NULL;
68 fNTrackHits = 0;
b035a148 69 fTrackPar = fTrackParNew = NULL;
70 fCovariance = fWeight = NULL;
83dbc640 71 fSkipHit = NULL;
b035a148 72 fParExtrap = fParFilter = fParSmooth = NULL;
73 fCovExtrap = fCovFilter = NULL;
74 fJacob = NULL;
75 fSteps = NULL; fNSteps = 0;
76 fChi2Array = NULL;
77 fChi2Smooth = NULL;
83dbc640 78
79 return;
80}
81
82 //__________________________________________________________________________
29f1b13a 83AliMUONTrackK::AliMUONTrackK(AliMUONTrackReconstructor *TrackReconstructor, TClonesArray *hitForRec)
b035a148 84 : AliMUONTrack()
83dbc640 85{
86 // Constructor
87
29f1b13a 88 if (!TrackReconstructor) return;
b21aa6eb 89 fgTrackReconstructor = TrackReconstructor; // pointer to event reconstructor
83dbc640 90 fgHitForRec = hitForRec; // pointer to points
91 fgNOfPoints = fgHitForRec->GetEntriesFast(); // number of points
cc87ebcd 92 fgCombi = NULL;
93 if (fgTrackReconstructor->GetTrackMethod() == 3) fgCombi = AliMUONEventRecoCombi::Instance();
83dbc640 94
95 fStartSegment = NULL;
96 fTrackHitsPtr = NULL;
97 fNTrackHits = 0;
98 fChi2 = 0;
b035a148 99 fTrackPar = fTrackParNew = NULL;
100 fCovariance = fWeight = NULL;
83dbc640 101 fSkipHit = NULL;
b035a148 102 fParExtrap = fParFilter = fParSmooth = NULL;
103 fCovExtrap = fCovFilter = NULL;
104 fJacob = NULL;
105 fSteps = NULL; fNSteps = 0;
106 fChi2Array = NULL;
107 fChi2Smooth = NULL;
83dbc640 108}
109
110 //__________________________________________________________________________
111AliMUONTrackK::AliMUONTrackK(AliMUONSegment *segment)
29f1b13a 112 : AliMUONTrack(segment, segment, fgTrackReconstructor)
83dbc640 113{
114 // Constructor from a segment
115 Double_t dX, dY, dZ;
116 AliMUONHitForRec *hit1, *hit2;
117 AliMUONRawCluster *clus;
118 TClonesArray *rawclusters;
119
120 fStartSegment = segment;
121 fRecover = 0;
b035a148 122 fSkipHit = NULL;
83dbc640 123 // Pointers to hits from the segment
124 hit1 = segment->GetHitForRec1();
125 hit2 = segment->GetHitForRec2();
126 hit1->SetNTrackHits(hit1->GetNTrackHits()+1); // mark hit as being on track
127 hit2->SetNTrackHits(hit2->GetNTrackHits()+1); // mark hit as being on track
128 // check sorting in Z
b035a148 129 if (TMath::Abs(hit1->GetZ()) > TMath::Abs(hit2->GetZ())) {
83dbc640 130 hit1 = hit2;
131 hit2 = segment->GetHitForRec1();
132 }
133 // memory allocation for the TObjArray of pointers to reconstructed TrackHit's
b035a148 134 fTrackHitsPtr = new TObjArray(13);
83dbc640 135 fNTrackHits = 2;
136 fChi2 = 0;
137 fBPFlag = kFALSE;
343146bf 138 fTrackPar = new TMatrixD(fgkSize,1); // track parameters
139 fTrackParNew = new TMatrixD(fgkSize,1); // track parameters
140 fCovariance = new TMatrixD(fgkSize,fgkSize); // covariance matrix
141 fWeight = new TMatrixD(fgkSize,fgkSize); // weight matrix (inverse of covariance)
83dbc640 142
143 // Fill array of track parameters
144 if (hit1->GetChamberNumber() > 7) {
145 // last tracking station
146 (*fTrackPar)(0,0) = hit1->GetBendingCoor(); // y
147 (*fTrackPar)(1,0) = hit1->GetNonBendingCoor(); // x
148 fPosition = hit1->GetZ(); // z
b035a148 149 fTrackHitsPtr->Add(hit2); // add hit 2
150 fTrackHitsPtr->Add(hit1); // add hit 1
151 //AZ(Z->-Z) fTrackDir = -1;
152 fTrackDir = 1;
83dbc640 153 } else {
154 // last but one tracking station
155 (*fTrackPar)(0,0) = hit2->GetBendingCoor(); // y
156 (*fTrackPar)(1,0) = hit2->GetNonBendingCoor(); // x
157 fPosition = hit2->GetZ(); // z
b035a148 158 fTrackHitsPtr->Add(hit1); // add hit 1
159 fTrackHitsPtr->Add(hit2); // add hit 2
160 //AZ(Z->-Z) fTrackDir = 1;
161 fTrackDir = -1;
83dbc640 162 }
163 dZ = hit2->GetZ() - hit1->GetZ();
164 dY = hit2->GetBendingCoor() - hit1->GetBendingCoor();
165 dX = hit2->GetNonBendingCoor() - hit1->GetNonBendingCoor();
166 (*fTrackPar)(2,0) = TMath::ATan2(dY,dZ); // alpha
b21aa6eb 167 if ((*fTrackPar)(2,0) < 0.) (*fTrackPar)(2,0) += 2*TMath::Pi(); // from 0 to 2*pi
168 (*fTrackPar)(3,0) = TMath::ATan2(-dX,dZ/TMath::Cos((*fTrackPar)(2,0))); // beta
169 (*fTrackPar)(2,0) -= TMath::Pi();
29f1b13a 170 (*fTrackPar)(4,0) = 1/fgTrackReconstructor->GetBendingMomentumFromImpactParam(segment->GetBendingImpact()); // 1/Pt
83dbc640 171 (*fTrackPar)(4,0) *= TMath::Cos((*fTrackPar)(3,0)); // 1/p
b035a148 172 // Evaluate covariance (and weight) matrix
173 EvalCovariance(dZ);
174
175 // For smoother
176 fParExtrap = new TObjArray(15);
177 fParFilter = new TObjArray(15);
178 fCovExtrap = new TObjArray(15);
179 fCovFilter = new TObjArray(15);
180 fJacob = new TObjArray(15);
181 fSteps = new TArrayD(15);
182 fNSteps = 0;
183 fChi2Array = new TArrayD(13);
184 fChi2Smooth = NULL;
185 fParSmooth = NULL;
186
187 if (fgDebug < 0 ) return;
cc87ebcd 188 cout << fgTrackReconstructor->GetNRecTracks()-1 << " " << fgTrackReconstructor->GetBendingMomentumFromImpactParam(segment->GetBendingImpact()) << " " << 1/(*fTrackPar)(4,0) << " ";
29f1b13a 189 if (fgTrackReconstructor->GetRecTrackRefHits()) {
29fc2c86 190 // from track ref. hits
191 cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetTTRTrack() << "<-->" << ((AliMUONHitForRec*)((*fTrackHitsPtr)[1]))->GetTTRTrack() << " @ " << fStartSegment->GetHitForRec1()->GetChamberNumber() << endl;
83dbc640 192 } else {
193 // from raw clusters
194 for (Int_t i=0; i<2; i++) {
195 hit1 = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
29f1b13a 196 rawclusters = fgTrackReconstructor->GetMUONData()->RawClusters(hit1->GetChamberNumber());
83dbc640 197 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit1->GetHitNumber());
b21aa6eb 198 cout << clus->GetTrack(1);
199 if (clus->GetTrack(2) != -1) cout << " " << clus->GetTrack(2);
83dbc640 200 if (i == 0) cout << " <--> ";
201 }
b035a148 202 cout << " @ " << fStartSegment->GetHitForRec1()->GetChamberNumber() << endl;
83dbc640 203 }
83dbc640 204}
205
206 //__________________________________________________________________________
207AliMUONTrackK::~AliMUONTrackK()
208{
209 // Destructor
210
211 if (fTrackHitsPtr) {
212 delete fTrackHitsPtr; // delete the TObjArray of pointers to TrackHit's
213 fTrackHitsPtr = NULL;
214 }
b035a148 215 if (fTrackPar) {
216 delete fTrackPar; delete fTrackParNew; delete fCovariance;
217 delete fWeight;
218 }
219
220 if (fSteps) delete fSteps;
221 if (fChi2Array) delete fChi2Array;
222 if (fChi2Smooth) delete fChi2Smooth;
223 if (fParSmooth) {fParSmooth->Delete(); delete fParSmooth; }
224 // Delete only matrices not shared by several tracks
225 if (!fParExtrap) return;
226
227 Int_t id = 0;
228 for (Int_t i=0; i<fNSteps; i++) {
229 //if (fParExtrap->UncheckedAt(i)->GetUniqueID() > 1)
230 // fParExtrap->UncheckedAt(i)->SetUniqueID(fParExtrap->RemoveAt(i)->GetUniqueID()-1);
231 id = fParExtrap->UncheckedAt(i)->GetUniqueID();
232 if (id > 1) {
233 fParExtrap->UncheckedAt(i)->SetUniqueID(id-1);
234 fParExtrap->RemoveAt(i);
235 }
236 //if (fParFilter->UncheckedAt(i)->GetUniqueID() > 1)
237 // fParFilter->UncheckedAt(i)->SetUniqueID(fParFilter->RemoveAt(i)->GetUniqueID()-1);
238 id = fParFilter->UncheckedAt(i)->GetUniqueID();
239 if (id > 1) {
240 fParFilter->UncheckedAt(i)->SetUniqueID(id-1);
241 fParFilter->RemoveAt(i);
242 }
243 //if (fCovExtrap->UncheckedAt(i)->GetUniqueID() > 1)
244 // fCovExtrap->UncheckedAt(i)->SetUniqueID(fCovExtrap->RemoveAt(i)->GetUniqueID()-1);
245 id = fCovExtrap->UncheckedAt(i)->GetUniqueID();
246 if (id > 1) {
247 fCovExtrap->UncheckedAt(i)->SetUniqueID(id-1);
248 fCovExtrap->RemoveAt(i);
249 }
250
251 //if (fCovFilter->UncheckedAt(i)->GetUniqueID() > 1)
252 // fCovFilter->UncheckedAt(i)->SetUniqueID(fCovFilter->RemoveAt(i)->GetUniqueID()-1);
253 id = fCovFilter->UncheckedAt(i)->GetUniqueID();
254 if (id > 1) {
255 fCovFilter->UncheckedAt(i)->SetUniqueID(id-1);
256 fCovFilter->RemoveAt(i);
257 }
258 //if (fJacob->UncheckedAt(i)->GetUniqueID() > 1)
259 // fJacob->UncheckedAt(i)->SetUniqueID(fJacob->RemoveAt(i)->GetUniqueID()-1);
260 id = fJacob->UncheckedAt(i)->GetUniqueID();
261 if (id > 1) {
262 fJacob->UncheckedAt(i)->SetUniqueID(id-1);
263 fJacob->RemoveAt(i);
264 }
265 }
266 /*
267 for (Int_t i=0; i<fNSteps; i++) {
268 if (fParExtrap->UncheckedAt(i)) ((TMatrixD*)fParExtrap->UncheckedAt(i))->Delete();
269 if (fParFilter->UncheckedAt(i)) ((TMatrixD*)fParFilter->UncheckedAt(i))->Delete();
270 if (fCovExtrap->UncheckedAt(i)) ((TMatrixD*)fCovExtrap->UncheckedAt(i))->Delete();
271 cout << fCovFilter->UncheckedAt(i) << " " << (*fSteps)[i] << endl;
272 if (fCovFilter->UncheckedAt(i)) ((TMatrixD*)fCovFilter->UncheckedAt(i))->Delete();
273 if (fJacob->UncheckedAt(i)) ((TMatrixD*)fJacob->UncheckedAt(i))->Delete();
274 }
275 */
276 fParExtrap->Delete(); fParFilter->Delete();
277 fCovExtrap->Delete(); fCovFilter->Delete();
278 fJacob->Delete();
279 delete fParExtrap; delete fParFilter;
280 delete fCovExtrap; delete fCovFilter;
281 delete fJacob;
83dbc640 282}
283
284 //__________________________________________________________________________
30178c30 285AliMUONTrackK::AliMUONTrackK (const AliMUONTrackK& source)
b035a148 286 : AliMUONTrack(source)
83dbc640 287{
30178c30 288// Protected copy constructor
8c343c7c 289 AliFatal("Not implemented.");
83dbc640 290}
291
292 //__________________________________________________________________________
293AliMUONTrackK & AliMUONTrackK::operator=(const AliMUONTrackK& source)
294{
295 // Assignment operator
296 // Members
297 if(&source == this) return *this;
30178c30 298
299 // base class assignement
b035a148 300 //AZ TObject::operator=(source);
301 AliMUONTrack::operator=(source);
30178c30 302
83dbc640 303 fStartSegment = source.fStartSegment;
304 fNTrackHits = source.fNTrackHits;
305 fChi2 = source.fChi2;
306 fPosition = source.fPosition;
307 fPositionNew = source.fPositionNew;
308 fTrackDir = source.fTrackDir;
309 fBPFlag = source.fBPFlag;
310 fRecover = source.fRecover;
311 fSkipHit = source.fSkipHit;
312
313 // Pointers
314 fTrackHitsPtr = new TObjArray(*source.fTrackHitsPtr);
315 //source.fTrackHitsPtr->Dump();
316 //fTrackHitsPtr->Dump();
317
318 fTrackPar = new TMatrixD(*source.fTrackPar); // track parameters
319 fTrackParNew = new TMatrixD(*source.fTrackParNew); // track parameters
320 fCovariance = new TMatrixD(*source.fCovariance); // covariance matrix
321 fWeight = new TMatrixD(*source.fWeight); // weight matrix (inverse of covariance)
322
b035a148 323 // For smoother
324 fParExtrap = new TObjArray(*source.fParExtrap);
325 fParFilter = new TObjArray(*source.fParFilter);
326 fCovExtrap = new TObjArray(*source.fCovExtrap);
327 fCovFilter = new TObjArray(*source.fCovFilter);
328 fJacob = new TObjArray(*source.fJacob);
329 fSteps = new TArrayD(*source.fSteps);
330 fNSteps = source.fNSteps;
331 fChi2Array = NULL;
332 if (source.fChi2Array) fChi2Array = new TArrayD(*source.fChi2Array);
333 fChi2Smooth = NULL;
334 fParSmooth = NULL;
335
336 for (Int_t i=0; i<fParExtrap->GetEntriesFast(); i++) {
337 fParExtrap->UncheckedAt(i)->SetUniqueID(fParExtrap->UncheckedAt(i)->GetUniqueID()+1);
338 fParFilter->UncheckedAt(i)->SetUniqueID(fParFilter->UncheckedAt(i)->GetUniqueID()+1);
339 fCovExtrap->UncheckedAt(i)->SetUniqueID(fCovExtrap->UncheckedAt(i)->GetUniqueID()+1);
340 fCovFilter->UncheckedAt(i)->SetUniqueID(fCovFilter->UncheckedAt(i)->GetUniqueID()+1);
341 fJacob->UncheckedAt(i)->SetUniqueID(fJacob->UncheckedAt(i)->GetUniqueID()+1);
342 }
83dbc640 343 return *this;
344}
345
346 //__________________________________________________________________________
347void AliMUONTrackK::EvalCovariance(Double_t dZ)
348{
349 // Evaluate covariance (and weight) matrix for track candidate
350 Double_t sigmaB, sigmaNonB, tanA, tanB, dAdY, rad, dBdX, dBdY;
351
b21aa6eb 352 dZ = -dZ;
29f1b13a 353 sigmaB = fgTrackReconstructor->GetBendingResolution(); // bending resolution
354 sigmaNonB = fgTrackReconstructor->GetNonBendingResolution(); // non-bending resolution
83dbc640 355
356 (*fWeight)(0,0) = sigmaB*sigmaB; // <yy>
357
358 (*fWeight)(1,1) = sigmaNonB*sigmaNonB; // <xx>
359
360 tanA = TMath::Tan((*fTrackPar)(2,0));
361 dAdY = 1/(1+tanA*tanA)/dZ;
362 (*fWeight)(2,2) = dAdY*dAdY*(*fWeight)(0,0)*2; // <aa>
363 (*fWeight)(0,2) = dAdY*(*fWeight)(0,0); // <ya>
364 (*fWeight)(2,0) = (*fWeight)(0,2);
365
366 rad = dZ/TMath::Cos((*fTrackPar)(2,0));
367 tanB = TMath::Tan((*fTrackPar)(3,0));
368 dBdX = 1/(1+tanB*tanB)/rad;
369 dBdY = 0; // neglect
370 (*fWeight)(3,3) = dBdX*dBdX*(*fWeight)(1,1)*2; // <bb>
371 (*fWeight)(1,3) = dBdX*(*fWeight)(1,1); // <xb>
372 (*fWeight)(3,1) = (*fWeight)(1,3);
373
83dbc640 374 (*fWeight)(4,4) = ((*fTrackPar)(4,0)*0.5)*((*fTrackPar)(4,0)*0.5); // error 50%
375
376 // check whether the Invert method returns flag if matrix cannot be inverted,
377 // and do not calculate the Determinant in that case !!!!
378 if (fWeight->Determinant() != 0) {
83dbc640 379 // fWeight->Invert();
b21aa6eb 380 Int_t ifail;
b21aa6eb 381 mnvertLocal(&((*fWeight)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 382 } else {
8c343c7c 383 AliWarning(" Determinant fWeight=0:");
83dbc640 384 }
385 return;
386}
387
388 //__________________________________________________________________________
389Bool_t AliMUONTrackK::KalmanFilter(Int_t ichamBeg, Int_t ichamEnd, Bool_t Back, Double_t zDipole1, Double_t zDipole2)
390{
391 // Follows track through detector stations
392 Bool_t miss, success;
b035a148 393 Int_t ichamb, iFB, iMin, iMax, dChamb, ichambOK;
cc87ebcd 394 Int_t ihit, firstIndx = -1, lastIndx = -1, currIndx = -1, iz0 = -1, iz = -1;
83dbc640 395 Double_t zEnd, dChi2;
cc87ebcd 396 AliMUONHitForRec *hitAdd, *firstHit = NULL, *lastHit = NULL, *hit;
83dbc640 397 AliMUONRawCluster *clus;
398 TClonesArray *rawclusters;
399 hit = 0; clus = 0; rawclusters = 0;
400
b035a148 401 miss = success = kTRUE;
83dbc640 402 Int_t endOfProp = 0;
ef4d63ce 403 //iFB = (ichamEnd == ichamBeg) ? fTrackDir : TMath::Sign(1,ichamEnd-ichamBeg);
404 iFB = (ichamEnd == ichamBeg) ? -fTrackDir : TMath::Sign(1,ichamEnd-ichamBeg);
83dbc640 405 iMin = TMath::Min(ichamEnd,ichamBeg);
406 iMax = TMath::Max(ichamEnd,ichamBeg);
407 ichamb = ichamBeg;
408 ichambOK = ichamb;
409
83dbc640 410 if (Back) {
411 // backpropagation
b035a148 412 currIndx = 1;
413 if (((AliMUONHitForRec*)fTrackHitsPtr->First())->GetChamberNumber() != ichamb) currIndx = 0;
414 } else if (fRecover) {
415 hit = GetHitLastOk();
416 currIndx = fTrackHitsPtr->IndexOf(hit);
417 if (currIndx < 0) hit = fStartSegment->GetHitForRec1(); // for station 3
418 Back = kTRUE;
419 ichamb = hit->GetChamberNumber();
420 if (hit == fSkipHit || fRecover == 2 && currIndx >= 0) {
421 // start from the last point or outlier
422 // remove the skipped hit
423 fTrackHitsPtr->Remove(fSkipHit); // remove hit
424 fNTrackHits --;
425 fSkipHit->SetNTrackHits(fSkipHit->GetNTrackHits()-1); // unmark hit
426 if (fRecover == 1) {
427 // recovery
428 Back = kFALSE;
429 fRecover = 0;
430 ichambOK = ((AliMUONHitForRec*)((*fTrackHitsPtr)[fNTrackHits-1]))->GetChamberNumber();
431 //if (ichambOK >= 8 && ((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetChamberNumber() == 6) ichambOK = 6;
cc87ebcd 432 if (fgTrackReconstructor->GetTrackMethod() == 3 &&
433 fSkipHit->GetHitNumber() < 0) {
434 iz0 = fgCombi->IZfromHit(fSkipHit);
435 currIndx = -1;
436 }
437 else currIndx = fgHitForRec->IndexOf(fSkipHit);
b035a148 438 } else {
439 // outlier
440 fTrackHitsPtr->Compress();
441 }
442 } // if (hit == fSkipHit)
443 else if (currIndx < 0) currIndx = fTrackHitsPtr->IndexOf(hit);
444 } // else if (fRecover)
445 else {
446 // Get indices of the 1'st and last hits on the track candidate
447 firstHit = (AliMUONHitForRec*) fTrackHitsPtr->First();
448 lastHit = (AliMUONHitForRec*) fTrackHitsPtr->Last();
cc87ebcd 449 if (fgTrackReconstructor->GetTrackMethod() == 3 &&
450 lastHit->GetHitNumber() < 0) iz0 = fgCombi->IZfromHit(lastHit);
451 else {
452 firstIndx = fgHitForRec->IndexOf(firstHit);
453 lastIndx = fgHitForRec->IndexOf(lastHit);
454 currIndx = TMath::Abs (TMath::Max(firstIndx*iFB,lastIndx*iFB));
455 }
83dbc640 456 }
457
cc87ebcd 458 if (iz0 < 0) iz0 = iFB;
459 while (ichamb >= iMin && ichamb <= iMax) {
83dbc640 460 // Find the closest hit in Z, not belonging to the current plane
461 if (Back) {
462 // backpropagation
b035a148 463 if (currIndx < fNTrackHits) {
464 hitAdd = (AliMUONHitForRec*) fTrackHitsPtr->UncheckedAt(currIndx);
465 zEnd = hitAdd->GetZ();
466 //AZ(z->-z) } else zEnd = -9999;
467 } else zEnd = 9999;
83dbc640 468 } else {
b035a148 469 //AZ(Z->-Z) zEnd = -9999;
470 zEnd = 9999;
83dbc640 471 for (ihit=currIndx+iFB; ihit>=0 && ihit<fgNOfPoints; ihit+=iFB) {
472 hitAdd = (AliMUONHitForRec*) ((*fgHitForRec)[ihit]);
473 //if (TMath::Abs(hitAdd->GetZ()-fPosition) > 0.1) {
474 if (TMath::Abs(hitAdd->GetZ()-fPosition) > 0.5) {
475 zEnd = hitAdd->GetZ();
476 currIndx = ihit;
477 break;
478 }
479 }
cc87ebcd 480
481 // Combined cluster / track finder
482 if (zEnd > 999 && iFB < 0 && fgTrackReconstructor->GetTrackMethod() == 3) {
483 currIndx = -2;
484 AliMUONHitForRec hitTmp;
485 for (iz = iz0 - iFB; iz < fgCombi->Nz(); iz++) {
486 if (TMath::Abs(fgCombi->Z(iz)-fPosition) < 0.5) continue;
487 Int_t *pDEatZ = fgCombi->DEatZ(iz);
488 //cout << iz << " " << fgCombi->Z(iz) << endl;
489 zEnd = fgCombi->Z(iz);
490 iz0 = iz;
491 AliMUONDetElement *detElem = fgCombi->DetElem(pDEatZ[0]);
492 hitAdd = &hitTmp;
493 hitAdd->SetChamberNumber(detElem->Chamber());
494 //hitAdd = (AliMUONHitForRec*) detElem->HitsForRec()->First();
495 if (hitAdd) break;
496 }
497 }
83dbc640 498 }
b035a148 499 if (zEnd>999 && ichamb==ichamEnd) endOfProp = 1; // end-of-propagation
83dbc640 500 else {
b035a148 501 // Check if there is a chamber without hits
502 if (zEnd>999 || TMath::Abs(hitAdd->GetChamberNumber()-ichamb) > 1) {
503 if (!Back && zEnd<999) currIndx -= iFB;
83dbc640 504 ichamb += iFB;
f93b9bd8 505 zEnd = AliMUONConstants::DefaultChamberZ(ichamb);
83dbc640 506 miss = kTRUE;
507 } else {
508 ichamb = hitAdd->GetChamberNumber();
509 miss = kFALSE;
510 }
511 }
512 if (ichamb<iMin || ichamb>iMax) break;
513 // Check for missing station
514 if (!Back) {
515 dChamb = TMath::Abs(ichamb-ichambOK);
b035a148 516 //cout << dChamb << " " << ichambOK << " " << fgNOfPoints << endl;
517 Int_t dStatMiss = TMath::Abs (ichamb/2 - ichambOK/2);
518 if (zEnd > 999) dStatMiss++;
519 if (dStatMiss > 1) {
520 // missing station - abandon track
521 //cout << dChamb << " " << ichambOK << " " << fgNOfPoints << " " << 1/(*fTrackPar)(4,0) << endl;
522 if (fgDebug >= 10) {
83dbc640 523 for (Int_t i1=0; i1<fgNOfPoints; i1++) {
524 cout << " Hit #" << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetChamberNumber() << " ";
525 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetBendingCoor() << " ";
526 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetNonBendingCoor() << " ";
527 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetZ() << " " << " ";
29fc2c86 528 cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetTTRTrack() << endl;
83dbc640 529 }
b035a148 530 cout << endl;
83dbc640 531 cout << fNTrackHits << endl;
532 for (Int_t i1=0; i1<fNTrackHits; i1++) {
533 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
534 printf(" * %d %10.4f %10.4f %10.4f",
b035a148 535 hit->GetChamberNumber(), hit->GetBendingCoor(),
83dbc640 536 hit->GetNonBendingCoor(), hit->GetZ());
29f1b13a 537 if (fgTrackReconstructor->GetRecTrackRefHits()) {
29fc2c86 538 // from track ref. hits
539 printf(" %3d %3d \n", hit->GetTrackRefSignal(), hit->GetTTRTrack());
83dbc640 540 } else {
541 // from raw clusters
29f1b13a 542 rawclusters = fgTrackReconstructor->GetMUONData()->RawClusters(hit->GetChamberNumber());
83dbc640 543 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
b035a148 544 printf("%3d", clus->GetTrack(1)-1);
545 if (clus->GetTrack(2) != 0) printf("%3d \n", clus->GetTrack(2)-1);
83dbc640 546 else printf("\n");
547 }
548 }
b035a148 549 } // if (fgDebug >= 10)
550 if (fNTrackHits>2 && fRecover==0) Recover(); // try to recover track later
551 return kFALSE;
552 } // if (dStatMiss > 1)
553 } // if (!Back)
83dbc640 554 if (endOfProp != 0) break;
555
556 // propagate to the found Z
557
558 // Check if track steps into dipole
b035a148 559 //AZ(z->-z) if (fPosition>zDipole2 && zEnd<zDipole2) {
560 if (fPosition<zDipole2 && zEnd>zDipole2) {
83dbc640 561 //LinearPropagation(zDipole2-zBeg);
562 ParPropagation(zDipole2);
563 MSThin(1); // multiple scattering in the chamber
b035a148 564 WeightPropagation(zDipole2, kTRUE); // propagate weight matrix
83dbc640 565 fPosition = fPositionNew;
566 *fTrackPar = *fTrackParNew;
567 //MagnetPropagation(zEnd);
568 ParPropagation(zEnd);
b035a148 569 WeightPropagation(zEnd, kTRUE);
83dbc640 570 fPosition = fPositionNew;
571 }
572 // Check if track steps out of dipole
b035a148 573 //AZ(z->-z) else if (fPosition>zDipole1 && zEnd<zDipole1) {
574 else if (fPosition<zDipole1 && zEnd>zDipole1) {
83dbc640 575 //MagnetPropagation(zDipole1-zBeg);
576 ParPropagation(zDipole1);
577 MSThin(1); // multiple scattering in the chamber
b035a148 578 WeightPropagation(zDipole1, kTRUE);
83dbc640 579 fPosition = fPositionNew;
580 *fTrackPar = *fTrackParNew;
581 //LinearPropagation(zEnd-zDipole1);
582 ParPropagation(zEnd);
b035a148 583 WeightPropagation(zEnd, kTRUE);
83dbc640 584 fPosition = fPositionNew;
585 } else {
586 ParPropagation(zEnd);
587 //MSThin(1); // multiple scattering in the chamber
588 if (TMath::Abs(zEnd-fPosition) > 5) MSThin(1); // multiple scattering in the chamber
b035a148 589 WeightPropagation(zEnd, kTRUE);
83dbc640 590 fPosition = fPositionNew;
591 }
592
593 // Add measurement
594 if (fRecover != 0 && hitAdd == fSkipHit && !miss) {
595 // recovered track - remove the hit
596 miss = kTRUE;
b035a148 597 ichamb = fSkipHit->GetChamberNumber();
598 // remove the skipped hit
599 fTrackHitsPtr->Remove(fSkipHit);
600 fNTrackHits --;
601 fSkipHit->SetNTrackHits(fSkipHit->GetNTrackHits()-1); // unmark hit
83dbc640 602 Back = kFALSE;
b035a148 603 fRecover =0;
83dbc640 604 ichambOK = ((AliMUONHitForRec*)((*fTrackHitsPtr)[fNTrackHits-1]))->GetChamberNumber();
cc87ebcd 605 //? if (fgTrackReconstructor->GetTrackMethod() != 3) currIndx = fgHitForRec->IndexOf(fSkipHit);
83dbc640 606 currIndx = fgHitForRec->IndexOf(fSkipHit);
607 }
608
609 if (Back && !miss) {
610 // backward propagator
b035a148 611 if (currIndx) {
612 TMatrixD pointWeight(fgkSize,fgkSize);
613 TMatrixD point(fgkSize,1);
614 TMatrixD trackParTmp = point;
615 point(0,0) = hitAdd->GetBendingCoor();
616 point(1,0) = hitAdd->GetNonBendingCoor();
617 pointWeight(0,0) = 1/hitAdd->GetBendingReso2();
618 pointWeight(1,1) = 1/hitAdd->GetNonBendingReso2();
619 TryPoint(point,pointWeight,trackParTmp,dChi2);
620 *fTrackPar = trackParTmp;
621 *fWeight += pointWeight;
b035a148 622 if (fTrackDir > 0) AddMatrices (this, dChi2, hitAdd);
623 fChi2 += dChi2; // Chi2
624 } else *fTrackPar = *fTrackParNew; // adjust end point to the last hit
83dbc640 625 if (ichamb==ichamEnd) break;
b035a148 626 currIndx ++;
83dbc640 627 } else {
628 // forward propagator
cc87ebcd 629 if (miss || !FindPoint(ichamb, zEnd, currIndx, iFB, hitAdd, iz)) {
83dbc640 630 // missing point
631 *fTrackPar = *fTrackParNew;
632 } else {
633 //add point
b035a148 634 fTrackHitsPtr->Add(hitAdd); // add hit
83dbc640 635 fNTrackHits ++;
636 hitAdd->SetNTrackHits(hitAdd->GetNTrackHits()+1); // mark hit as being on track
637 ichambOK = ichamb;
638 currIndx = fgHitForRec->IndexOf(hitAdd); // Check
639 }
640 }
641 } // while
b035a148 642 if (fgDebug > 0) cout << fNTrackHits << " " << fChi2 << " " << 1/(*fTrackPar)(4,0) << " " << fPosition << endl;
29f1b13a 643 if (1/TMath::Abs((*fTrackPar)(4,0)) < fgTrackReconstructor->GetMinBendingMomentum()) success = kFALSE; // p < p_min
83dbc640 644 return success;
645}
646
647 //__________________________________________________________________________
648void AliMUONTrackK::ParPropagation(Double_t zEnd)
649{
650 // Propagation of track parameters to zEnd
651 Int_t iFB, nTries;
652 Double_t dZ, step, distance, charge;
653 Double_t vGeant3[7], vGeant3New[7];
b21aa6eb 654 AliMUONTrackParam trackParam;
655
83dbc640 656 nTries = 0;
657 // First step using linear extrapolation
658 dZ = zEnd - fPosition;
83dbc640 659 fPositionNew = fPosition;
660 *fTrackParNew = *fTrackPar;
b035a148 661 if (dZ == 0) return; //AZ ???
662 iFB = (Int_t)TMath::Sign(Double_t(1.0),dZ);
663 step = dZ/TMath::Cos((*fTrackPar)(2,0))/TMath::Cos((*fTrackPar)(3,0)); // linear estimate
664 //AZ(z->-z) charge = iFB*TMath::Sign(Double_t(1.0),(*fTrackPar)(4,0));
665 charge = -iFB*TMath::Sign(Double_t(1.0),(*fTrackPar)(4,0));
83dbc640 666 SetGeantParam(vGeant3,iFB);
b21aa6eb 667 //fTrackParNew->Print();
83dbc640 668
669 // Check if overstep
670 do {
671 step = TMath::Abs(step);
672 // Propagate parameters
b21aa6eb 673 trackParam.ExtrapOneStepRungekutta(charge,step,vGeant3,vGeant3New);
674 //extrap_onestep_rungekutta(charge,step,vGeant3,vGeant3New);
83dbc640 675 distance = zEnd - vGeant3New[2];
676 step *= dZ/(vGeant3New[2]-fPositionNew);
677 nTries ++;
343146bf 678 } while (distance*iFB < 0 && TMath::Abs(distance) > fgkEpsilon);
83dbc640 679
680 GetFromGeantParam(vGeant3New,iFB);
b21aa6eb 681 //fTrackParNew->Print();
83dbc640 682
b035a148 683 // Position adjustment (until within tolerance)
343146bf 684 while (TMath::Abs(distance) > fgkEpsilon) {
83dbc640 685 dZ = zEnd - fPositionNew;
686 iFB = (Int_t)TMath::Sign(Double_t(1.0),dZ);
687 step = dZ/TMath::Cos((*fTrackParNew)(2,0))/TMath::Cos((*fTrackParNew)(3,0));
688 step = TMath::Abs(step);
689 SetGeantParam(vGeant3,iFB);
690 do {
691 // binary search
692 // Propagate parameters
b21aa6eb 693 trackParam.ExtrapOneStepRungekutta(charge,step,vGeant3,vGeant3New);
694 //extrap_onestep_rungekutta(charge,step,vGeant3,vGeant3New);
83dbc640 695 distance = zEnd - vGeant3New[2];
696 step /= 2;
697 nTries ++;
94eb555e 698 if (nTries > fgkTriesMax) AliError(Form(" Too many tries: %d", nTries));
83dbc640 699 } while (distance*iFB < 0);
700
701 GetFromGeantParam(vGeant3New,iFB);
702 }
703 //cout << nTries << endl;
b21aa6eb 704 //fTrackParNew->Print();
83dbc640 705 return;
706}
83dbc640 707
83dbc640 708 //__________________________________________________________________________
b035a148 709void AliMUONTrackK::WeightPropagation(Double_t zEnd, Bool_t smooth)
83dbc640 710{
711 // Propagation of the weight matrix
712 // W = DtWD, where D is Jacobian
713 Int_t i, j;
714 Double_t dPar;
715
30178c30 716 TMatrixD jacob(fgkSize,fgkSize);
717 jacob = 0;
83dbc640 718
719 // Save initial and propagated parameters
720 TMatrixD trackPar0 = *fTrackPar;
721 TMatrixD trackParNew0 = *fTrackParNew;
83dbc640 722
723 // Get covariance matrix
724 *fCovariance = *fWeight;
725 // check whether the Invert method returns flag if matrix cannot be inverted,
726 // and do not calculate the Determinant in that case !!!!
727 if (fCovariance->Determinant() != 0) {
b21aa6eb 728 Int_t ifail;
729 mnvertLocal(&((*fCovariance)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
730 //fCovariance->Print();
83dbc640 731 } else {
8c343c7c 732 AliWarning(" Determinant fCovariance=0:");
83dbc640 733 }
734
b21aa6eb 735 // Loop over parameters to find change of the propagated vs initial ones
343146bf 736 for (i=0; i<fgkSize; i++) {
83dbc640 737 dPar = TMath::Sqrt((*fCovariance)(i,i));
b21aa6eb 738 *fTrackPar = trackPar0;
739 if (i == 4) dPar *= TMath::Sign(1.,-trackPar0(4,0)); // 1/p
83dbc640 740 (*fTrackPar)(i,0) += dPar;
741 ParPropagation(zEnd);
343146bf 742 for (j=0; j<fgkSize; j++) {
b21aa6eb 743 jacob(j,i) = ((*fTrackParNew)(j,0)-trackParNew0(j,0))/dPar;
83dbc640 744 }
745 }
746
83dbc640 747 //trackParNew0.Print();
30178c30 748 //TMatrixD par1(jacob,TMatrixD::kMult,trackPar0); //
83dbc640 749 //par1.Print();
b21aa6eb 750 TMatrixD jacob0 = jacob;
30178c30 751 if (jacob.Determinant() != 0) {
b21aa6eb 752 jacob.Invert();
83dbc640 753 } else {
b21aa6eb 754 AliWarning(" Determinant jacob=0:");
83dbc640 755 }
30178c30 756 TMatrixD weight1(*fWeight,TMatrixD::kMult,jacob); // WD
757 *fWeight = TMatrixD(jacob,TMatrixD::kTransposeMult,weight1); // DtWD
83dbc640 758
759 // Restore initial and propagated parameters
760 *fTrackPar = trackPar0;
761 *fTrackParNew = trackParNew0;
b035a148 762
763 // Save for smoother
764 if (!smooth) return; // do not use smoother
b035a148 765 if (fTrackDir < 0) return; // only for propagation towards int. point
766 TMatrixD *tmp = new TMatrixD(*fTrackParNew); // extrapolated parameters
767 fParExtrap->Add(tmp);
768 tmp->SetUniqueID(1);
769 tmp = new TMatrixD(*fTrackParNew); // filtered parameters (if no measurement will be found)
770 fParFilter->Add(tmp);
771 tmp->SetUniqueID(1);
772 *fCovariance = *fWeight;
773 if (fCovariance->Determinant() != 0) {
b21aa6eb 774 Int_t ifail;
775 mnvertLocal(&((*fCovariance)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
b035a148 776 } else {
777 AliWarning(" Determinant fCovariance=0:");
778 }
779 tmp = new TMatrixD(*fCovariance); // extrapolated covariance
780 fCovExtrap->Add(tmp);
781 tmp->SetUniqueID(1);
782 tmp = new TMatrixD(*fCovariance); // filtered covariance (if no measurement will be found)
783 fCovFilter->Add(tmp);
784 tmp->SetUniqueID(1);
b21aa6eb 785 tmp = new TMatrixD(jacob0); // Jacobian
b035a148 786 fJacob->Add(tmp);
787 tmp->SetUniqueID(1);
788 if (fSteps->fN <= fNSteps) fSteps->Set(fSteps->fN+10);
789 fSteps->AddAt(fPositionNew,fNSteps++);
790 if (fgDebug > 0) cout << " WeightPropagation " << fNSteps << " " << fPositionNew << endl;
83dbc640 791 return;
792}
793
794 //__________________________________________________________________________
cc87ebcd 795Bool_t AliMUONTrackK::FindPoint(Int_t ichamb, Double_t zEnd, Int_t currIndx, Int_t iFB, AliMUONHitForRec *&hitAdd, Int_t iz)
83dbc640 796{
797 // Picks up point within a window for the chamber No ichamb
798 // Split the track if there are more than 1 hit
799 Int_t ihit, nRecTracks;
30178c30 800 Double_t windowB, windowNonB, dChi2Tmp=0, dChi2, y, x, savePosition=0;
83dbc640 801 TClonesArray *trackPtr;
802 AliMUONHitForRec *hit, *hitLoop;
803 AliMUONTrackK *trackK;
cc87ebcd 804 AliMUONDetElement *detElem = NULL;
83dbc640 805
30178c30 806 Bool_t ok = kFALSE;
cc87ebcd 807
808 if (fgTrackReconstructor->GetTrackMethod() == 3 && iz >= 0) {
809 // Combined cluster / track finder
810 // Check if extrapolated track passes thru det. elems. at iz
811 Int_t *pDEatZ = fgCombi->DEatZ(iz);
812 Int_t nDetElem = pDEatZ[-1];
813 //cout << fgCombi->Z(iz) << " " << nDetElem << endl;
814 for (Int_t i = 0; i < nDetElem; i++) {
815 detElem = fgCombi->DetElem(pDEatZ[i]);
816 if (detElem->Inside((*fTrackParNew)(1,0), (*fTrackParNew)(0,0), fPosition)) {
817 detElem->ClusterReco((*fTrackParNew)(1,0), (*fTrackParNew)(0,0));
818 hitAdd = (AliMUONHitForRec*) detElem->HitsForRec()->First();
819 ok = kTRUE;
820 break;
821 }
822 }
823 if (!ok) return ok; // outside det. elem.
824 ok = kFALSE;
825 }
826
29f1b13a 827 //sigmaB = fgTrackReconstructor->GetBendingResolution(); // bending resolution
828 //sigmaNonB = fgTrackReconstructor->GetNonBendingResolution(); // non-bending resolution
83dbc640 829 *fCovariance = *fWeight;
830 // check whether the Invert method returns flag if matrix cannot be inverted,
831 // and do not calculate the Determinant in that case !!!!
832 if (fCovariance->Determinant() != 0) {
b21aa6eb 833 Int_t ifail;
834 mnvertLocal(&((*fCovariance)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 835 } else {
b21aa6eb 836 AliWarning(" Determinant fCovariance=0:");
83dbc640 837 }
30178c30 838 //windowB = fgkNSigma*TMath::Sqrt((*fCovariance)(0,0)+sigmaB*sigmaB);
839 //windowNonB = fgkNSigma*TMath::Sqrt((*fCovariance)(1,1)+sigmaNonB*sigmaNonB);
83dbc640 840 // Loop over all hits and take hits from the chamber
343146bf 841 TMatrixD pointWeight(fgkSize,fgkSize);
83dbc640 842 TMatrixD saveWeight = pointWeight;
843 TMatrixD pointWeightTmp = pointWeight;
343146bf 844 TMatrixD point(fgkSize,1);
83dbc640 845 TMatrixD trackPar = point;
846 TMatrixD trackParTmp = point;
cc87ebcd 847 Int_t nHitsOK = 0, ihitB = currIndx, ihitE = fgNOfPoints, iDhit = iFB;
b035a148 848 Double_t zLast;
849 zLast = ((AliMUONHitForRec*)fTrackHitsPtr->Last())->GetZ();
cc87ebcd 850 if (fgTrackReconstructor->GetTrackMethod() == 3 && detElem) {
851 ihitB = 0;
852 ihitE = detElem->NHitsForRec();
853 iDhit = 1;
854 }
855
83dbc640 856
cc87ebcd 857 for (ihit = ihitB; ihit >= 0 && ihit < ihitE; ihit+=iDhit) {
858 if (fgTrackReconstructor->GetTrackMethod() != 3 || !detElem)
859 hit = (AliMUONHitForRec*) ((*fgHitForRec)[ihit]);
860 else hit = (AliMUONHitForRec*) detElem->HitsForRec()->UncheckedAt(ihit);
83dbc640 861 if (hit->GetChamberNumber() == ichamb) {
862 //if (TMath::Abs(hit->GetZ()-zEnd) < 0.1) {
863 if (TMath::Abs(hit->GetZ()-zEnd) < 0.5) {
b21aa6eb 864 //if (TMath::Abs(hit->GetZ()-zEnd) > 0.1) {
865 if (TMath::Abs(hit->GetZ()-zEnd) > 0.05) {
83dbc640 866 // adjust position: for multiple hits in the chamber
867 // (mostly (only?) for GEANT hits)
94eb555e 868 AliWarning(Form(" *** adjust %f %f ", zEnd, hit->GetZ()));
83dbc640 869 zEnd = hit->GetZ();
870 *fTrackPar = *fTrackParNew;
871 ParPropagation(zEnd);
b035a148 872 WeightPropagation(zEnd, kTRUE);
83dbc640 873 fPosition = fPositionNew;
874 *fTrackPar = *fTrackParNew;
875 // Get covariance
876 *fCovariance = *fWeight;
877 if (fCovariance->Determinant() != 0) {
b21aa6eb 878 Int_t ifail;
879 mnvertLocal(&((*fCovariance)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 880 } else {
b21aa6eb 881 AliWarning(" Determinant fCovariance=0:" );
83dbc640 882 }
883 }
884 y = hit->GetBendingCoor();
885 x = hit->GetNonBendingCoor();
cc87ebcd 886 if (hit->GetBendingReso2() < 0) {
887 // Combined cluster / track finder
888 hit->SetBendingReso2(fgTrackReconstructor->GetBendingResolution()*
889 fgTrackReconstructor->GetBendingResolution());
890 hit->SetNonBendingReso2(fgTrackReconstructor->GetNonBendingResolution()*
891 fgTrackReconstructor->GetNonBendingResolution());
892 }
30178c30 893 windowB = fgkNSigma*TMath::Sqrt((*fCovariance)(0,0)+hit->GetBendingReso2());
894 windowNonB = fgkNSigma*TMath::Sqrt((*fCovariance)(1,1)+hit->GetNonBendingReso2());
b035a148 895
b21aa6eb 896 // windowB = TMath::Min (windowB,5.);
897 if (fgkNSigma > 6) windowB = TMath::Min (windowB,5.);
b035a148 898 /*
899 if (TMath::Abs(hit->GetZ()-zLast) < 50) {
900 windowB = TMath::Min (windowB,0.5);
901 windowNonB = TMath::Min (windowNonB,3.);
902 } else if (TMath::Abs(hit->GetZ()-zLast) < 200) {
903 windowB = TMath::Min (windowB,1.5);
904 windowNonB = TMath::Min (windowNonB,3.);
905 } else if (TMath::Abs(hit->GetZ()-zLast) < 350) {
906 windowB = TMath::Min (windowB,4.);
907 windowNonB = TMath::Min (windowNonB,6.);
908 }
909 */
910
911 // Test
912 /*
913 if (TMath::Abs(hit->GetZ()-zLast) < 50) {
914 windowB = 5*TMath::Sqrt((*fCovariance)(0,0)+hit->GetBendingReso2());
915 windowNonB = 5*TMath::Sqrt((*fCovariance)(1,1)+hit->GetNonBendingReso2());
916 } else {
917 windowB = fgkNSigma*TMath::Sqrt((*fCovariance)(0,0)+hit->GetBendingReso2());
918 windowNonB = fgkNSigma*TMath::Sqrt((*fCovariance)(1,1)+hit->GetNonBendingReso2());
919 }
920 */
921
922 //cout << TMath::Abs((*fTrackParNew)(0,0)-y) << " " << windowB << " " << TMath::Abs((*fTrackParNew)(1,0)-x) << " " << windowNonB << " " << zEnd << endl;
30178c30 923 if (TMath::Abs((*fTrackParNew)(0,0)-y) <= windowB &&
924 TMath::Abs((*fTrackParNew)(1,0)-x) <= windowNonB) {
b035a148 925 //if (TMath::Abs((*fTrackParNew)(0,0)-y) <= windowB &&
926 // TMath::Abs((*fTrackParNew)(1,0)-x) <= windowNonB &&
29fc2c86 927 // hit->GetTrackRefSignal() == 1) { // just for test
83dbc640 928 // Vector of measurements and covariance matrix
b21aa6eb 929 //fprintf(lun1,"%3d %3d %10.4f %10.4f \n", gAlice->GetEvNumber(), ichamb, x, y);
83dbc640 930 point.Zero();
931 point(0,0) = y;
932 point(1,0) = x;
933 pointWeight(0,0) = 1/hit->GetBendingReso2();
934 pointWeight(1,1) = 1/hit->GetNonBendingReso2();
935 TryPoint(point,pointWeight,trackPar,dChi2);
29f1b13a 936 if (TMath::Abs(1./(trackPar)(4,0)) < fgTrackReconstructor->GetMinBendingMomentum()) continue; // p < p_min - next hit
cc87ebcd 937 // if (TMath::Sign(1.,(trackPar)(4,0)*(*fTrackPar)(4,0)) < 0) continue; // change of sign
30178c30 938 ok = kTRUE;
83dbc640 939 nHitsOK++;
940 //if (nHitsOK > -1) {
941 if (nHitsOK == 1) {
942 // Save current members
943 saveWeight = *fWeight;
944 savePosition = fPosition;
945 // temporary storage for the current track
946 dChi2Tmp = dChi2;
947 trackParTmp = trackPar;
948 pointWeightTmp = pointWeight;
949 hitAdd = hit;
dc9a75bb 950 if (fgDebug > 0) cout << " Added point: " << x << " " << y << " " << dChi2 << endl;
83dbc640 951 } else {
952 // branching: create a new track
29f1b13a 953 trackPtr = fgTrackReconstructor->GetRecTracksPtr();
954 nRecTracks = fgTrackReconstructor->GetNRecTracks();
b035a148 955 trackK = new ((*trackPtr)[nRecTracks]) AliMUONTrackK(NULL, NULL);
83dbc640 956 *trackK = *this;
29f1b13a 957 fgTrackReconstructor->SetNRecTracks(nRecTracks+1);
29fc2c86 958 if (fgDebug > 0) cout << " ******** New track: " << ichamb << " " << hit->GetTTRTrack() << " " << 1/(trackPar)(4,0) << " " << hit->GetBendingCoor() << " " << hit->GetNonBendingCoor() << " " << fNTrackHits << " " << nRecTracks << endl;
83dbc640 959 trackK->fRecover = 0;
960 *(trackK->fTrackPar) = trackPar;
961 *(trackK->fWeight) += pointWeight;
962 trackK->fChi2 += dChi2;
b035a148 963 // Check
964 /*
965 *(trackK->fCovariance) = *(trackK->fWeight);
966 if (trackK->fCovariance->Determinant() != 0) {
b21aa6eb 967 Int_t ifail;
968 mnvertLocal(&((*(trackK->fCovariance))(0,0)), fgkSize,fgkSize,fgkSize,ifail);
b035a148 969 }
970 cout << (*(trackK->fCovariance))(0,0) << " " << (*(trackK->fCovariance))(1,1) << " " << (*fCovariance)(0,0) << " " << (*fCovariance)(1,1) << endl;
971 */
972 // Add filtered matrices for the smoother
b035a148 973 if (fTrackDir > 0) {
974 if (nHitsOK > 2) { // check for position adjustment
975 for (Int_t i=trackK->fNSteps-1; i>=0; i--) {
976 if (TMath::Abs(hit->GetZ()-(*trackK->fSteps)[i]) > 0.1) {
977 //if (TMath::Abs(hit->GetZ()-(trackK->fSteps)[i]) > 0.1) {
978 RemoveMatrices(trackK);
94eb555e 979 AliError(Form(" *** Position adjustment 1: %f %f", hit->GetZ(), (*trackK->fSteps)[i]));
b035a148 980 }
981 else break;
982 }
983 }
984 AddMatrices (trackK, dChi2, hit);
985 }
83dbc640 986 // Mark hits as being on 2 tracks
987 for (Int_t i=0; i<fNTrackHits; i++) {
988 hitLoop = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
989 hitLoop->SetNTrackHits(hitLoop->GetNTrackHits()+1);
b035a148 990 if (fgDebug >=10) {
991 cout << " ** ";
992 cout << hitLoop->GetChamberNumber() << " ";
993 cout << hitLoop->GetBendingCoor() << " ";
994 cout << hitLoop->GetNonBendingCoor() << " ";
995 cout << hitLoop->GetZ() << " " << " ";
29fc2c86 996 cout << hitLoop->GetTrackRefSignal() << " " << " ";
997 cout << hitLoop->GetTTRTrack() << endl;
b035a148 998 printf(" ** %d %10.4f %10.4f %10.4f %d %d \n",
999 hitLoop->GetChamberNumber(), hitLoop->GetBendingCoor(),
1000 hitLoop->GetNonBendingCoor(), hitLoop->GetZ(),
29fc2c86 1001 hitLoop->GetTrackRefSignal(), hitLoop->GetTTRTrack());
b035a148 1002 }
83dbc640 1003 }
1004 //add point
b035a148 1005 trackK->fTrackHitsPtr->Add(hit); // add hit
83dbc640 1006 trackK->fNTrackHits ++;
1007 hit->SetNTrackHits(hit->GetNTrackHits()+1); // mark hit as being on track
1008 if (ichamb == 9) {
1009 // the last chamber
b035a148 1010 trackK->fTrackDir = 1;
83dbc640 1011 trackK->fBPFlag = kTRUE;
1012 }
1013 }
1014 }
1015 }
1016 } else break; // different chamber
1017 } // for (ihit=currIndx;
30178c30 1018 if (ok) {
b035a148 1019 // Restore members
83dbc640 1020 *fTrackPar = trackParTmp;
1021 *fWeight = saveWeight;
1022 *fWeight += pointWeightTmp;
1023 fChi2 += dChi2Tmp; // Chi2
83dbc640 1024 fPosition = savePosition;
b035a148 1025 // Add filtered matrices for the smoother
b035a148 1026 if (fTrackDir > 0) {
1027 for (Int_t i=fNSteps-1; i>=0; i--) {
1028 if (TMath::Abs(fPosition-(*fSteps)[i]) > 0.1) {
1029 //if (TMath::Abs(fPosition-fSteps[i]) > 0.1) {
1030 RemoveMatrices(this);
b21aa6eb 1031 if (fgDebug > 0) cout << " *** Position adjustment 2 " << fPosition << " " << (*fSteps)[i] << endl;
b035a148 1032 }
1033 else break;
1034 } // for (Int_t i=fNSteps-1;
1035 AddMatrices (this, dChi2Tmp, hitAdd);
1036 /*
1037 if (nHitsOK > 1) {
1038 for (Int_t i=0; i<fNSteps; i++) cout << (*fSteps)[i] << " "; cout << endl;
1039 for (Int_t i=0; i<trackK->fNSteps; i++) cout << (*trackK->fSteps)[i] << " "; cout << endl;
1040 }
1041 */
1042 } // if (fTrackDir > 0)
83dbc640 1043 }
30178c30 1044 return ok;
83dbc640 1045}
1046
1047 //__________________________________________________________________________
1048void AliMUONTrackK::TryPoint(TMatrixD &point, const TMatrixD &pointWeight, TMatrixD &trackParTmp, Double_t &dChi2)
1049{
1050 // Adds a measurement point (modifies track parameters and computes
1051 // change of Chi2)
1052
1053 // Solving linear system (W+U)p' = U(m-p) + (W+U)p
1054 TMatrixD wu = *fWeight;
1055 wu += pointWeight; // W+U
1056 trackParTmp = point;
1057 trackParTmp -= *fTrackParNew; // m-p
1058 TMatrixD right(pointWeight,TMatrixD::kMult,trackParTmp); // U(m-p)
1059 TMatrixD right1(wu,TMatrixD::kMult,*fTrackParNew); // (W+U)p
1060 right += right1; // U(m-p) + (W+U)p
1061
1062 // check whether the Invert method returns flag if matrix cannot be inverted,
1063 // and do not calculate the Determinant in that case !!!!
1064 if (wu.Determinant() != 0) {
cc87ebcd 1065 Int_t ifail;
1066 mnvertLocal(&((wu)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 1067 } else {
b21aa6eb 1068 AliWarning(" Determinant wu=0:");
83dbc640 1069 }
1070 trackParTmp = TMatrixD(wu,TMatrixD::kMult,right);
1071
1072 right1 = trackParTmp;
1073 right1 -= point; // p'-m
1074 point = trackParTmp;
1075 point -= *fTrackParNew; // p'-p
1076 right = TMatrixD(*fWeight,TMatrixD::kMult,point); // W(p'-p)
1077 TMatrixD value(point,TMatrixD::kTransposeMult,right); // (p'-p)'W(p'-p)
1078 dChi2 = value(0,0);
1079 right = TMatrixD(pointWeight,TMatrixD::kMult,right1); // U(p'-m)
1080 value = TMatrixD(right1,TMatrixD::kTransposeMult,right); // (p'-m)'U(p'-m)
1081 dChi2 += value(0,0);
1082 return;
1083}
1084
1085 //__________________________________________________________________________
1086void AliMUONTrackK::MSThin(Int_t sign)
1087{
1088 // Adds multiple scattering in a thin layer (only angles are affected)
1089 Double_t cosAlph, cosBeta, momentum, velo, path, theta0;
1090
1091 // check whether the Invert method returns flag if matrix cannot be inverted,
1092 // and do not calculate the Determinant in that case !!!!
1093 if (fWeight->Determinant() != 0) {
b21aa6eb 1094 Int_t ifail;
1095 mnvertLocal(&((*fWeight)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 1096 } else {
b21aa6eb 1097 AliWarning(" Determinant fWeight=0:");
83dbc640 1098 }
1099
1100 cosAlph = TMath::Cos((*fTrackParNew)(2,0));
1101 cosBeta = TMath::Cos((*fTrackParNew)(3,0));
1102 momentum = 1/(*fTrackParNew)(4,0); // particle momentum
1103 //velo = momentum/TMath::Sqrt(momentum*momentum+muonMass*muonMass); // velocity/c for muon hypothesis
1104 velo = 1; // relativistic
29f1b13a 1105 path = TMath::Abs(fgTrackReconstructor->GetChamberThicknessInX0()/cosAlph/cosBeta); // path length
83dbc640 1106 theta0 = 0.0136/velo/momentum*TMath::Sqrt(path)*(1+0.038*TMath::Log(path)); // projected scattering angle
1107
1108 (*fWeight)(2,2) += sign*theta0/cosBeta*theta0/cosBeta; // alpha
1109 (*fWeight)(3,3) += sign*theta0*theta0; // beta
b21aa6eb 1110 Int_t ifail;
1111 mnvertLocal(&((*fWeight)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 1112 return;
1113}
b035a148 1114
83dbc640 1115 //__________________________________________________________________________
1116void AliMUONTrackK::StartBack(void)
1117{
1118 // Starts backpropagator
1119
1120 fBPFlag = kTRUE;
1121 fChi2 = 0;
343146bf 1122 for (Int_t i=0; i<fgkSize; i++) {
1123 for (Int_t j=0; j<fgkSize; j++) {
83dbc640 1124 if (j==i) (*fWeight)(i,i) /= 100;
1125 //if (j==i) (*fWeight)(i,i) /= fNTrackHits*fNTrackHits;
1126 else (*fWeight)(j,i) = 0;
1127 }
1128 }
b035a148 1129 // Sort hits on track in descending order in abs(z)
1130 SortHits(0, fTrackHitsPtr);
1131}
1132
1133 //__________________________________________________________________________
1134void AliMUONTrackK::SortHits(Int_t iflag, TObjArray *array)
1135{
1136 // Sort hits in Z if the seed segment in the last but one station
1137 // (if iflag==0 in descending order in abs(z), if !=0 - unsort)
1138
1139 if (iflag && ((AliMUONHitForRec*)(array->UncheckedAt(0)))->GetChamberNumber() == 6) return;
1140 Double_t z = 0, zmax = TMath::Abs(((AliMUONHitForRec*)(array->UncheckedAt(0)))->GetZ());
1141 Int_t i = 1, entries = array->GetEntriesFast();
1142 for ( ; i<entries; i++) {
1143 if (iflag) {
1144 if (((AliMUONHitForRec*)(array->UncheckedAt(i)))->GetChamberNumber() == 6) break;
1145 } else {
1146 z = TMath::Abs(((AliMUONHitForRec*)(array->UncheckedAt(i)))->GetZ());
1147 if (z < zmax) break;
1148 zmax = z;
1149 if (fgDebug >= 10) cout << " " << zmax << " " << z << " " << i << endl;
1150 }
1151 }
1152 if (!iflag) i--;
1153 for (Int_t j=0; j<=(i-1)/2; j++) {
1154 TObject *hit = array->UncheckedAt(j);
1155 array->AddAt(array->UncheckedAt(i-j),j);
1156 array->AddAt(hit,i-j);
1157 }
1158 if (fgDebug >= 10) {
1159 for (i=0; i<entries; i++)
1160 cout << ((AliMUONHitForRec*)(array->UncheckedAt(i)))->GetZ() << " ";
1161 cout << " - Sort" << endl;
1162 }
83dbc640 1163}
1164
1165 //__________________________________________________________________________
1166void AliMUONTrackK::SetGeantParam(Double_t *VGeant3, Int_t iFB)
1167{
1168 // Set vector of Geant3 parameters pointed to by "VGeant3"
1169 // from track parameters
1170
1171 VGeant3[0] = (*fTrackParNew)(1,0); // X
1172 VGeant3[1] = (*fTrackParNew)(0,0); // Y
1173 VGeant3[2] = fPositionNew; // Z
b21aa6eb 1174 VGeant3[3] = iFB*TMath::Sin((*fTrackParNew)(3,0)); // Px/Ptot
1175 VGeant3[4] = iFB*TMath::Cos((*fTrackParNew)(3,0))*TMath::Sin((*fTrackParNew)(2,0)); // Py/Ptot
83dbc640 1176 VGeant3[5] = iFB*TMath::Sqrt(1.0-VGeant3[3]*VGeant3[3]-VGeant3[4]*VGeant3[4]); // Pz/Ptot
1177 VGeant3[6] = 1/TMath::Abs((*fTrackParNew)(4,0)); // Ptot
1178}
1179
1180 //__________________________________________________________________________
1181void AliMUONTrackK::GetFromGeantParam(Double_t *VGeant3, Int_t iFB)
1182{
1183 // Get track parameters from vector of Geant3 parameters pointed
1184 // to by "VGeant3"
1185
1186 fPositionNew = VGeant3[2]; // Z
1187 (*fTrackParNew)(0,0) = VGeant3[1]; // Y
1188 (*fTrackParNew)(1,0) = VGeant3[0]; // X
b21aa6eb 1189 (*fTrackParNew)(3,0) = TMath::ASin(iFB*VGeant3[3]); // beta
1190 (*fTrackParNew)(2,0) = TMath::ASin(iFB*VGeant3[4]/TMath::Cos((*fTrackParNew)(3,0))); // alpha
83dbc640 1191 (*fTrackParNew)(4,0) = 1/VGeant3[6]*TMath::Sign(Double_t(1.0),(*fTrackPar)(4,0)); // 1/Ptot
1192}
1193
1194 //__________________________________________________________________________
1195void AliMUONTrackK::SetTrackQuality(Int_t iChi2)
1196{
1197 // Computes "track quality" from Chi2 (if iChi2==0) or vice versa
1198
b035a148 1199 if (fChi2 > 500) {
94eb555e 1200 AliWarning(Form(" *** Too high Chi2: %f ", fChi2));
b035a148 1201 fChi2 = 500;
83dbc640 1202 }
b035a148 1203 if (iChi2 == 0) fChi2 = fNTrackHits + (500.-fChi2)/501;
1204 else fChi2 = 500 - (fChi2-fNTrackHits)*501;
83dbc640 1205}
1206
1207 //__________________________________________________________________________
1208Int_t AliMUONTrackK::Compare(const TObject* trackK) const
1209{
1210 // "Compare" function to sort with decreasing "track quality".
1211 // Returns +1 (0, -1) if quality of current track
1212 // is smaller than (equal to, larger than) quality of trackK
1213
1214 if (fChi2 < ((AliMUONTrackK*)trackK)->fChi2) return(+1);
1215 else if (fChi2 == ((AliMUONTrackK*)trackK)->fChi2) return(0);
1216 else return(-1);
1217}
1218
1219 //__________________________________________________________________________
30178c30 1220Bool_t AliMUONTrackK::KeepTrack(AliMUONTrackK* track0) const
83dbc640 1221{
1222 // Check whether or not to keep current track
1223 // (keep, if it has less than half of common hits with track0)
1224 Int_t hitsInCommon, nHits0, i, j, nTrackHits2;
1225 AliMUONHitForRec *hit0, *hit1;
1226
1227 hitsInCommon = 0;
1228 nHits0 = track0->fNTrackHits;
1229 nTrackHits2 = fNTrackHits/2;
1230
1231 for (i=0; i<nHits0; i++) {
1232 // Check if hit belongs to several tracks
1233 hit0 = (AliMUONHitForRec*) (*track0->fTrackHitsPtr)[i];
1234 if (hit0->GetNTrackHits() == 1) continue;
1235 for (j=0; j<fNTrackHits; j++) {
1236 hit1 = (AliMUONHitForRec*) (*fTrackHitsPtr)[j];
1237 if (hit1->GetNTrackHits() == 1) continue;
1238 if (hit0 == hit1) {
1239 hitsInCommon++;
1240 if (hitsInCommon >= nTrackHits2) return kFALSE;
1241 break;
1242 }
1243 } // for (j=0;
1244 } // for (i=0;
1245 return kTRUE;
1246}
1247
1248 //__________________________________________________________________________
1249void AliMUONTrackK::Kill(void)
1250{
1251 // Kill track candidate
1252 Int_t i;
1253 AliMUONHitForRec *hit;
1254
1255 if (fTrackHitsPtr) {
1256 // Remove track mark from hits
1257 for (i=0; i<fNTrackHits; i++) {
1258 hit = (AliMUONHitForRec*) (*fTrackHitsPtr)[i];
1259 hit->SetNTrackHits(hit->GetNTrackHits()-1);
1260 }
1261 }
29f1b13a 1262 fgTrackReconstructor->GetRecTracksPtr()->Remove(this);
83dbc640 1263}
1264
b035a148 1265 //__________________________________________________________________________
1266void AliMUONTrackK::FillMUONTrack(void)
1267{
1268 // Compute track parameters at hit positions (as for AliMUONTrack)
1269
1270 // Set number of hits per track
1271 ((AliMUONTrack*)this)->SetNTrackHits(fNTrackHits);
1272
1273 // Set track parameters at vertex
1274 AliMUONTrackParam trackParam;
1275 SetTrackParam(&trackParam, fTrackPar, fPosition);
1276 ((AliMUONTrack*)this)->SetTrackParamAtVertex(&trackParam);
1277
1278 // Set track parameters at hits
1279 for (Int_t i = fNTrackHits-1; i>=0; i--) {
1280 if ((*fChi2Smooth)[i] < 0) {
1281 // Propagate through last chambers
1282 trackParam.ExtrapToZ(((AliMUONHitForRec*)((*fTrackHitsPtr)[i]))->GetZ());
1283 } else {
1284 // Take saved info
1285 SetTrackParam(&trackParam, (TMatrixD*)fParSmooth->UncheckedAt(i), ((AliMUONHitForRec*)((*fTrackHitsPtr)[i]))->GetZ());
1286 }
1287 ((AliMUONTrack*)this)->AddTrackParamAtHit(&trackParam);
b21aa6eb 1288 // Fill array of HitForRec's
1289 ((AliMUONTrack*)this)->AddHitForRecAtHit((AliMUONHitForRec*)fTrackHitsPtr->UncheckedAt(i));
b035a148 1290 }
1291}
1292
1293 //__________________________________________________________________________
1294void AliMUONTrackK::SetTrackParam(AliMUONTrackParam *trackParam, TMatrixD *par, Double_t z)
1295{
1296 // Fill AliMUONTrackParam object
1297
1298 trackParam->SetBendingCoor((*par)(0,0));
1299 trackParam->SetNonBendingCoor((*par)(1,0));
1300 trackParam->SetBendingSlope(TMath::Tan((*par)(2,0)));
1301 trackParam->SetNonBendingSlope(TMath::Tan((*par)(3,0))/TMath::Cos((*par)(2,0)));
1302 trackParam->SetInverseBendingMomentum((*par)(4,0)/TMath::Cos((*par)(3,0)));
1303 trackParam->SetZ(z);
1304}
1305
83dbc640 1306 //__________________________________________________________________________
1307void AliMUONTrackK::Branson(void)
1308{
1309 // Propagates track to the vertex thru absorber using Branson correction
1310 // (makes use of the AliMUONTrackParam class)
1311
b21aa6eb 1312 //AliMUONTrackParam *trackParam = new AliMUONTrackParam();
1313 AliMUONTrackParam trackParam = AliMUONTrackParam();
b035a148 1314 /*
83dbc640 1315 trackParam->SetBendingCoor((*fTrackPar)(0,0));
1316 trackParam->SetNonBendingCoor((*fTrackPar)(1,0));
1317 trackParam->SetBendingSlope(TMath::Tan((*fTrackPar)(2,0)));
1318 trackParam->SetNonBendingSlope(TMath::Tan((*fTrackPar)(3,0))/TMath::Cos((*fTrackPar)(2,0)));
1319 trackParam->SetInverseBendingMomentum((*fTrackPar)(4,0)/TMath::Cos((*fTrackPar)(3,0)));
1320 trackParam->SetZ(fPosition);
b035a148 1321 */
b21aa6eb 1322 SetTrackParam(&trackParam, fTrackPar, fPosition);
83dbc640 1323
b21aa6eb 1324 trackParam.ExtrapToVertex(Double_t(0.), Double_t(0.), Double_t(0.));
1325 //trackParam.ExtrapToVertex();
83dbc640 1326
b21aa6eb 1327 (*fTrackPar)(0,0) = trackParam.GetBendingCoor();
1328 (*fTrackPar)(1,0) = trackParam.GetNonBendingCoor();
1329 (*fTrackPar)(2,0) = TMath::ATan(trackParam.GetBendingSlope());
1330 (*fTrackPar)(3,0) = TMath::ATan(TMath::Cos((*fTrackPar)(2,0))*trackParam.GetNonBendingSlope());
1331 (*fTrackPar)(4,0) = TMath::Cos((*fTrackPar)(3,0))*trackParam.GetInverseBendingMomentum();
1332 fPosition = trackParam.GetZ();
1333 //delete trackParam;
94eb555e 1334 if (fgDebug > 0) cout << 1/(*fTrackPar)(4,0) << " " << fPosition << " " << (*fTrackPar)(0,0) << endl;
83dbc640 1335
1336 // Get covariance matrix
1337 *fCovariance = *fWeight;
1338 if (fCovariance->Determinant() != 0) {
cc87ebcd 1339 Int_t ifail;
1340 mnvertLocal(&((*fCovariance)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 1341 } else {
b21aa6eb 1342 AliWarning(" Determinant fCovariance=0:");
83dbc640 1343 }
1344}
1345
1346 //__________________________________________________________________________
1347void AliMUONTrackK::GoToZ(Double_t zEnd)
1348{
1349 // Propagates track to given Z
1350
1351 ParPropagation(zEnd);
1352 MSThin(1); // multiple scattering in the chamber
b035a148 1353 WeightPropagation(zEnd, kFALSE);
83dbc640 1354 fPosition = fPositionNew;
1355 *fTrackPar = *fTrackParNew;
1356}
1357
1358 //__________________________________________________________________________
b035a148 1359void AliMUONTrackK::GoToVertex(Int_t iflag)
83dbc640 1360{
1361 // Version 3.08
1362 // Propagates track to the vertex
1363 // All material constants are taken from AliRoot
1364
1365 static Double_t x01[5] = { 24.282, // C
1366 24.282, // C
1367 11.274, // Concrete
1368 1.758, // Fe
1369 1.758}; // Fe (cm)
1370 // inner part theta < 3 degrees
1371 static Double_t x02[5] = { 30413, // Air
1372 24.282, // C
1373 11.274, // Concrete
1374 1.758, // Fe
1375 0.369}; // W (cm)
1376 // z positions of the materials inside the absober outer part theta > 3 degres
b035a148 1377 static Double_t zPos[10] = {-90, -105, -315, -443, -468};
83dbc640 1378
30178c30 1379 Double_t dZ, r0Norm, x0, deltaP, dChi2, pTotal, pOld;
83dbc640 1380 AliMUONHitForRec *hit;
1381 AliMUONRawCluster *clus;
1382 TClonesArray *rawclusters;
1383
1384 // First step to the rear end of the absorber
b035a148 1385 //AZ(z->-z) Double_t zRear = 503;
1386 Double_t zRear = -503;
83dbc640 1387 GoToZ(zRear);
1388 Double_t tan3 = TMath::Tan(3./180*TMath::Pi());
1389
1390 // Go through absorber
1391 pOld = 1/(*fTrackPar)(4,0);
1392 Double_t r0Rear = (*fTrackPar)(0,0)*(*fTrackPar)(0,0) +
1393 (*fTrackPar)(1,0)*(*fTrackPar)(1,0);
b035a148 1394 r0Rear = TMath::Sqrt(r0Rear)/TMath::Abs(fPosition)/tan3;
83dbc640 1395 r0Norm = r0Rear;
b035a148 1396 Double_t p0, cos25, cos60;
1397 if (!iflag) goto vertex;
1398
83dbc640 1399 for (Int_t i=4; i>=0; i--) {
1400 ParPropagation(zPos[i]);
b035a148 1401 WeightPropagation(zPos[i], kFALSE);
83dbc640 1402 dZ = TMath::Abs (fPositionNew-fPosition);
30178c30 1403 if (r0Norm > 1) x0 = x01[i];
1404 else x0 = x02[i];
1405 MSLine(dZ,x0); // multiple scattering in the medium (linear approximation)
83dbc640 1406 fPosition = fPositionNew;
1407 *fTrackPar = *fTrackParNew;
1408 r0Norm = (*fTrackPar)(0,0)*(*fTrackPar)(0,0) +
1409 (*fTrackPar)(1,0)*(*fTrackPar)(1,0);
b035a148 1410 r0Norm = TMath::Sqrt(r0Norm)/TMath::Abs(fPosition)/tan3;
83dbc640 1411 }
1412 // Correct momentum for energy losses
1413 pTotal = 1/TMath::Abs((*fTrackPar)(4,0));
b035a148 1414 p0 = pTotal;
1415 cos25 = TMath::Cos(2.5/180*TMath::Pi());
1416 cos60 = TMath::Cos(6.0/180*TMath::Pi());
1417 for (Int_t j=0; j<1; j++) {
83dbc640 1418 /*
1419 if (r0Rear > 1) {
1420 if (p0 < 20) {
1421 deltaP = 2.164 + 0.145e-1*p0 - 0.417e-3*p0*p0;
1422 } else {
1423 deltaP = 2.275 + 0.102e-2*p0 - 0.674e-6*p0*p0;
1424 }
1425 } else {
1426 if (p0 < 20) {
1427 deltaP = 2.581 + 0.188e-1*p0 - 0.398e-3*p0*p0;
1428 } else {
1429 deltaP = 2.727 + 0.356e-2*p0 + 0.242e-5*p0*p0;
1430 }
1431 }
1432 */
b035a148 1433 /*
83dbc640 1434 if (r0Rear < 1) {
1435 //W
1436 if (p0<15) {
1437 deltaP = 2.737 + 0.0494*p0 - 0.001123*p0*p0;
1438 } else {
1439 deltaP = 3.0643 + 0.01346*p0;
1440 }
b035a148 1441 deltaP *= 0.95;
83dbc640 1442 } else {
1443 //Pb
1444 if (p0<15) {
1445 deltaP = 2.1380 + 0.0351*p0 - 0.000853*p0*p0;
1446 } else {
1447 deltaP = 2.407 + 0.00702*p0;
1448 }
b035a148 1449 deltaP *= 0.95;
1450 }
1451 */
1452 /*
1453 if (r0Rear < 1) {
1454 //W
1455 if (p0<18) {
1456 deltaP = 2.439 + 0.806e-1*p0 - 0.500e-2*p0*p0 + 0.106e-3*p0*p0*p0;
1457 } else {
1458 deltaP = 2.767 + 0.742e-2*p0 - 0.196e-4*p0*p0 + 0.403e-7*p0*p0*p0;
1459 }
1460 //deltaP += 0.2;
1461 deltaP *= cos25;
1462 } else {
1463 //Pb
1464 if (p0<18) {
1465 deltaP = 2.209 + 0.800e-2*p0;
1466 } else {
1467 deltaP = 2.285 + 0.141e-2*p0 - 0.446e-6*p0*p0;
1468 }
1469 //deltaP += 0.2;
1470 deltaP *= cos60;
1471 }
1472 deltaP *= 1.1;
1473 */
1474 //*
1475 if (r0Rear < 1) {
1476 if (p0 < 20) {
1477 deltaP = 2.5938 + 0.0570 * p0 - 0.001151 * p0 * p0;
1478 } else {
1479 deltaP = 3.0714 + 0.011767 * p0;
1480 }
1481 } else {
1482 if (p0 < 20) {
1483 deltaP = 2.1207 + 0.05478 * p0 - 0.00145079 * p0 * p0;
1484 } else {
1485 deltaP = 2.6069 + 0.0051705 * p0;
1486 }
83dbc640 1487 }
b035a148 1488 deltaP *= 0.9;
1489 //*/
83dbc640 1490
b035a148 1491 p0 = pTotal + deltaP/TMath::Abs(TMath::Cos((*fTrackPar)(2,0))/TMath::Cos((*fTrackPar)(3,0)));
83dbc640 1492 }
1493 (*fTrackPar)(4,0) = 1/p0*TMath::Sign((Double_t)1.,(*fTrackPar)(4,0));
1494
1495 // Go to the vertex
b035a148 1496vertex:
83dbc640 1497 ParPropagation((Double_t)0.);
b035a148 1498 WeightPropagation((Double_t)0., kFALSE);
83dbc640 1499 fPosition = fPositionNew;
1500 //*fTrackPar = *fTrackParNew;
1501 // Add vertex as a hit
343146bf 1502 TMatrixD pointWeight(fgkSize,fgkSize);
1503 TMatrixD point(fgkSize,1);
83dbc640 1504 TMatrixD trackParTmp = point;
1505 point(0,0) = 0; // vertex coordinate - should be taken somewhere
1506 point(1,0) = 0; // vertex coordinate - should be taken somewhere
1507 pointWeight(0,0) = 1/1.e-3/1.e-3; // 10 um error
1508 pointWeight(1,1) = 1/1.e-3/1.e-3; // 10 um error
1509 TryPoint(point,pointWeight,trackParTmp,dChi2);
1510 *fTrackPar = trackParTmp;
1511 *fWeight += pointWeight;
1512 fChi2 += dChi2; // Chi2
b035a148 1513 if (fgDebug < 0) return; // no output
1514
83dbc640 1515 cout << pOld << " " << 1/(*fTrackPar)(4,0) << " " << dChi2 << " " << fChi2 << " " << fNTrackHits << endl;
1516 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1517 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
1518 printf ("%4d", hit->GetChamberNumber());
83dbc640 1519 }
1520 cout << endl;
b035a148 1521 if (fgDebug > 0) {
1522 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1523 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
1524 //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetHitNumber() << " ";
1525 //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetZ() << " ";
1526 printf ("%4d", fgHitForRec->IndexOf(hit));
1527 }
1528 cout << endl;
83dbc640 1529 }
29f1b13a 1530 if (fgTrackReconstructor->GetRecTrackRefHits()) {
29fc2c86 1531 // from track ref. hits
83dbc640 1532 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1533 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
29fc2c86 1534 cout << hit->GetTTRTrack() + hit->GetTrackRefSignal()*10000 << " ";
83dbc640 1535 }
1536 } else {
1537 // from raw clusters
1538 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1539 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
cc87ebcd 1540 if (hit->GetHitNumber() < 0) { // combined cluster / track finder
1541 Int_t index = -hit->GetHitNumber() / 100000;
1542 Int_t iPos = -hit->GetHitNumber() - index * 100000;
1543 clus = (AliMUONRawCluster*) fgCombi->DetElem(index-1)->RawClusters()->UncheckedAt(iPos);
1544 } else {
1545 rawclusters = fgTrackReconstructor->GetMUONData()->RawClusters(hit->GetChamberNumber());
1546 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
1547 }
b21aa6eb 1548 printf ("%4d", clus->GetTrack(1));
83dbc640 1549 }
1550 cout << endl;
1551 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1552 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
cc87ebcd 1553 if (hit->GetHitNumber() < 0) { // combined cluster / track finder
1554 Int_t index = -hit->GetHitNumber() / 100000;
1555 Int_t iPos = -hit->GetHitNumber() - index * 100000;
1556 clus = (AliMUONRawCluster*) fgCombi->DetElem(index-1)->RawClusters()->UncheckedAt(iPos);
1557 } else {
1558 rawclusters = fgTrackReconstructor->GetMUONData()->RawClusters(hit->GetChamberNumber());
1559 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
1560 }
b21aa6eb 1561 if (clus->GetTrack(2) != -1) printf ("%4d", clus->GetTrack(2));
83dbc640 1562 else printf ("%4s", " ");
83dbc640 1563 }
1564 }
1565 cout << endl;
1566 for (Int_t i1=0; i1<fNTrackHits; i1++) {
1567 //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetHitNumber() << " ";
1568 cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetZ() << " ";
1569 //cout << fgHitForRec->IndexOf(((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))) << " ";
1570 }
1571 cout << endl;
b035a148 1572 for (Int_t i1=0; i1<fNTrackHits; i1++) printf("%8.4f", (*fChi2Smooth)[i1]);
1573 cout << endl;
83dbc640 1574 cout << "---------------------------------------------------" << endl;
1575
1576 // Get covariance matrix
b035a148 1577 /* Not needed - covariance matrix is not interesting to anybody
83dbc640 1578 *fCovariance = *fWeight;
1579 if (fCovariance->Determinant() != 0) {
b21aa6eb 1580 Int_t ifail;
1581 mnvertLocal(&((*fCovariance)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 1582 } else {
b21aa6eb 1583 AliWarning(" Determinant fCovariance=0:" );
83dbc640 1584 }
b035a148 1585 */
83dbc640 1586}
1587
1588 //__________________________________________________________________________
30178c30 1589void AliMUONTrackK::MSLine(Double_t dZ, Double_t x0)
83dbc640 1590{
1591 // Adds multiple scattering in a thick layer for linear propagation
1592
1593 Double_t cosAlph = TMath::Cos((*fTrackPar)(2,0));
1594 Double_t tanAlph = TMath::Tan((*fTrackPar)(2,0));
1595 Double_t cosBeta = TMath::Cos((*fTrackPar)(3,0));
1596 Double_t sinBeta;
1597 sinBeta = TMath::Sin((*fTrackPar)(3,0));
1598 Double_t tanBeta = TMath::Tan((*fTrackPar)(3,0));
1599 Double_t momentum = 1/(*fTrackPar)(4,0);
1600 Double_t velo = 1; // relativistic velocity
b035a148 1601 Double_t step = TMath::Abs(dZ/cosAlph/cosBeta); // step length
83dbc640 1602
1603 // Projected scattering angle
30178c30 1604 Double_t theta0 = 0.0136/velo/momentum/TMath::Sqrt(x0)*(1+0.038*TMath::Log(step/x0));
83dbc640 1605 Double_t theta02 = theta0*theta0;
1606 Double_t dl2 = step*step/2*theta02;
1607 Double_t dl3 = dl2*step*2/3;
1608
1609 //Derivatives
1610 Double_t dYdT = 1/cosAlph;
1611 Double_t dYdB = 0; //(*fTrackPar)(2,0)*sinBeta/cosAlph;
1612 Double_t dXdT = tanAlph*tanBeta;
1613 //Double_t dXdB = (1+(*fTrackPar)(2,0)*tanAlph*sinBeta*sinBeta)/cosBeta;
1614 Double_t dXdB = 1/cosBeta;
1615 Double_t dAdT = 1/cosBeta;
1616 Double_t dAdB = 0; //(*fTrackPar)(2,0)*tanBeta;
1617
1618 // Get covariance matrix
1619 *fCovariance = *fWeight;
1620 if (fCovariance->Determinant() != 0) {
1621 // fCovariance->Invert();
b21aa6eb 1622 Int_t ifail;
1623 mnvertLocal(&((*fCovariance)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 1624 } else {
b21aa6eb 1625 AliWarning(" Determinant fCovariance=0:" );
83dbc640 1626 }
1627
1628 (*fCovariance)(0,0) += dl3*(dYdT*dYdT+dYdB*dYdB); // <yy>
1629 (*fCovariance)(1,1) += dl3*(dXdT*dXdT+dXdB*dXdB); // <xx>
1630 (*fCovariance)(2,2) += theta02*step*(dAdT*dAdT+dAdB*dAdB); // <aa>
1631 (*fCovariance)(3,3) += theta02*step; // <bb>
1632
1633 (*fCovariance)(0,1) += dl3*(dYdT*dXdT+dYdB*dXdB); // <yx>
1634 (*fCovariance)(1,0) = (*fCovariance)(0,1);
1635
1636 (*fCovariance)(0,2) += dl2*(dYdT*dAdT+dYdB*dAdB); // <ya>
1637 (*fCovariance)(2,0) = (*fCovariance)(0,2);
1638
1639 (*fCovariance)(0,3) += dl2*dYdB; // <yb>
1640 (*fCovariance)(3,0) = (*fCovariance)(0,3);
1641
b21aa6eb 1642 (*fCovariance)(1,2) += dl2*(-dXdT*dAdT+dXdB*dAdB); // <xa>
83dbc640 1643 (*fCovariance)(2,1) = (*fCovariance)(1,2);
1644
1645 (*fCovariance)(1,3) += dl2*dXdB; // <xb>
1646 (*fCovariance)(3,1) = (*fCovariance)(1,3);
1647
1648 (*fCovariance)(2,3) += theta02*step*dAdB; // <ab>
1649 (*fCovariance)(3,2) = (*fCovariance)(2,3);
1650
1651 // Get weight matrix
1652 *fWeight = *fCovariance;
1653 if (fWeight->Determinant() != 0) {
b21aa6eb 1654 Int_t ifail;
1655 mnvertLocal(&((*fWeight)(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 1656 } else {
b21aa6eb 1657 AliWarning(" Determinant fWeight=0:");
83dbc640 1658 }
1659}
1660
1661 //__________________________________________________________________________
b035a148 1662Bool_t AliMUONTrackK::Recover(void)
83dbc640 1663{
1664 // Adds new failed track(s) which can be tried to be recovered
b035a148 1665 Int_t nRecTracks;
83dbc640 1666 TClonesArray *trackPtr;
1667 AliMUONTrackK *trackK;
1668
b035a148 1669 if (fgDebug > 0) cout << " ******** Enter Recover " << endl;
29f1b13a 1670 trackPtr = fgTrackReconstructor->GetRecTracksPtr();
83dbc640 1671
b035a148 1672 // Remove hit with the highest chi2
1673 Double_t chi2 = 0;
1674 if (fgDebug > 0) {
1675 for (Int_t i=0; i<fNTrackHits; i++) {
1676 chi2 = fChi2Smooth ? (*fChi2Smooth)[i] : (*fChi2Array)[i];
1677 printf("%10.4f", chi2);
1678 }
1679 printf("\n");
1680 for (Int_t i=0; i<fNTrackHits; i++) {
1681 printf("%10d", ((AliMUONHitForRec*)fTrackHitsPtr->UncheckedAt(i))->GetChamberNumber());
1682 }
1683 printf("\n");
1684 }
f29ba3e1 1685 Double_t chi2max = 0;
b035a148 1686 Int_t imax = 0;
1687 for (Int_t i=0; i<fNTrackHits; i++) {
1688 chi2 = fChi2Smooth ? (*fChi2Smooth)[i] : (*fChi2Array)[i];
f29ba3e1 1689 if (chi2 < chi2max) continue;
1690 chi2max = chi2;
b035a148 1691 imax = i;
1692 }
f29ba3e1 1693 //if (chi2max < 10) return kFALSE; // !!!
1694 //if (chi2max < 25) imax = fNTrackHits - 1;
1695 if (chi2max < 15) imax = fNTrackHits - 1; // discard the last point
b035a148 1696 // Check if the outlier is not from the seed segment
1697 AliMUONHitForRec *skipHit = (AliMUONHitForRec*) fTrackHitsPtr->UncheckedAt(imax);
1698 if (skipHit == fStartSegment->GetHitForRec1() || skipHit == fStartSegment->GetHitForRec2()) {
1699 //DropBranches(fStartSegment); // drop all tracks with the same seed segment
1700 return kFALSE; // to be changed probably
1701 }
1702
1703 // Make a copy of track hit collection
1704 TObjArray *hits = new TObjArray(*fTrackHitsPtr);
1705 Int_t imax0;
1706 imax0 = imax;
1707
1708 // Hits after the found one will be removed
dc9a75bb 1709 if (GetStation0() == 3 && skipHit->GetChamberNumber() >= 7) {
b035a148 1710 SortHits(1, fTrackHitsPtr); // unsort hits
1711 imax = fTrackHitsPtr->IndexOf(skipHit);
1712 }
1713 Int_t nTrackHits = fNTrackHits;
1714 for (Int_t i=imax+1; i<nTrackHits; i++) {
1715 AliMUONHitForRec *hit = (AliMUONHitForRec*) fTrackHitsPtr->UncheckedAt(i);
1716 fTrackHitsPtr->Remove(hit);
1717 hit->SetNTrackHits(hit->GetNTrackHits()-1); // unmark hit
1718 fNTrackHits--;
1719 }
83dbc640 1720
1721 // Check if the track candidate doesn't exist yet
b035a148 1722 if (ExistDouble()) { delete hits; return kFALSE; }
1723
1724 //DropBranches(imax0, hits); // drop branches downstream the discarded hit
1725 delete hits;
83dbc640 1726
29f1b13a 1727 nRecTracks = fgTrackReconstructor->GetNRecTracks();
b035a148 1728 skipHit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[fNTrackHits-1]);
1729 // Remove all saved steps and smoother matrices after the skipped hit
1730 RemoveMatrices(skipHit->GetZ());
1731
1732 //AZ(z->-z) if (skipHit->GetZ() > fStartSegment->GetHitForRec2()->GetZ() || !fNSteps) {
1733 if (TMath::Abs(skipHit->GetZ()) > TMath::Abs(fStartSegment->GetHitForRec2()->GetZ()) || !fNSteps) {
1734 // Propagation toward high Z or skipped hit next to segment -
1735 // start track from segment
1736 trackK = new ((*trackPtr)[nRecTracks]) AliMUONTrackK(fStartSegment);
29f1b13a 1737 fgTrackReconstructor->SetNRecTracks(nRecTracks+1);
b035a148 1738 trackK->fRecover = 1;
1739 trackK->fSkipHit = skipHit;
1740 trackK->fNTrackHits = fNTrackHits;
1741 delete trackK->fTrackHitsPtr; // not efficient ?
1742 trackK->fTrackHitsPtr = new TObjArray(*fTrackHitsPtr);
1743 if (fgDebug > 0) cout << nRecTracks << " " << trackK->fRecover << endl;
1744 return kTRUE;
1745 }
1746
1747 trackK = new ((*trackPtr)[nRecTracks]) AliMUONTrackK(NULL, NULL);
1748 *trackK = *this;
29f1b13a 1749 fgTrackReconstructor->SetNRecTracks(nRecTracks+1);
b035a148 1750 //AZ(z->-z) trackK->fTrackDir = -1;
1751 trackK->fTrackDir = 1;
83dbc640 1752 trackK->fRecover = 1;
b035a148 1753 trackK->fSkipHit = skipHit;
1754 Int_t iD = trackK->fParFilter->Last()->GetUniqueID();
1755 if (iD > 1) {
1756 trackK->fParFilter->Last()->SetUniqueID(iD-1);
1757 CreateMatrix(trackK->fParFilter);
1758 iD = 1;
1759 trackK->fParFilter->Last()->SetUniqueID(iD);
1760 }
1761 *((TMatrixD*)trackK->fParFilter->Last()) = *((TMatrixD*)fParExtrap->Last());
1762 *(trackK->fTrackPar) = *((TMatrixD*)trackK->fParFilter->Last());
1763 iD = trackK->fCovFilter->Last()->GetUniqueID();
1764 if (iD > 1) {
1765 trackK->fCovFilter->Last()->SetUniqueID(iD-1);
1766 CreateMatrix(trackK->fCovFilter);
1767 iD = 1;
1768 trackK->fCovFilter->Last()->SetUniqueID(iD);
1769 }
1770 *((TMatrixD*)trackK->fCovFilter->Last()) = *((TMatrixD*)fCovExtrap->Last());
1771 *(trackK->fWeight) = *((TMatrixD*)trackK->fCovFilter->Last());
1772 if (trackK->fWeight->Determinant() != 0) {
b21aa6eb 1773 Int_t ifail;
1774 mnvertLocal(&((*(trackK->fWeight))(0,0)), fgkSize,fgkSize,fgkSize,ifail);
83dbc640 1775 } else {
b21aa6eb 1776 AliWarning(" Determinant fWeight=0:");
83dbc640 1777 }
b035a148 1778 trackK->fPosition = trackK->fPositionNew = (*fSteps)[fNSteps-1];
1779 trackK->fChi2 = 0;
1780 for (Int_t i=0; i<fNTrackHits-1; i++) trackK->fChi2 += (*fChi2Array)[i];
1781 if (fgDebug > 0) cout << nRecTracks << " " << trackK->fRecover << endl;
1782 return kTRUE;
1783}
83dbc640 1784
b035a148 1785 //__________________________________________________________________________
1786void AliMUONTrackK::AddMatrices(AliMUONTrackK *trackK, Double_t dChi2, AliMUONHitForRec *hitAdd)
1787{
1788 // Adds matrices for the smoother and keep Chi2 for the point
1789 // Track parameters
1790 //trackK->fParFilter->Last()->Print();
1791 Int_t iD = trackK->fParFilter->Last()->GetUniqueID();
1792 if (iD > 1) {
1793 trackK->fParFilter->Last()->SetUniqueID(iD-1);
1794 CreateMatrix(trackK->fParFilter);
1795 iD = 1;
1796 }
1797 *((TMatrixD*)(trackK->fParFilter->Last())) = *(trackK->fTrackPar);
1798 trackK->fParFilter->Last()->SetUniqueID(iD);
1799 if (fgDebug > 1) {
1800 cout << " Add matrices" << " " << fPosition << " " << dChi2 << " " << fgHitForRec->IndexOf(hitAdd) << endl;
1801 //trackK->fTrackPar->Print();
1802 //trackK->fTrackParNew->Print();
1803 trackK->fParFilter->Last()->Print();
1804 cout << " Add matrices" << endl;
1805 }
1806 // Covariance
1807 *(trackK->fCovariance) = *(trackK->fWeight);
1808 if (trackK->fCovariance->Determinant() != 0) {
b21aa6eb 1809 Int_t ifail;
1810 mnvertLocal(&((*(trackK->fCovariance))(0,0)), fgkSize,fgkSize,fgkSize,ifail);
b035a148 1811 } else {
b21aa6eb 1812 AliWarning(" Determinant fCovariance=0:");
b035a148 1813 }
1814 iD = trackK->fCovFilter->Last()->GetUniqueID();
1815 if (iD > 1) {
1816 trackK->fCovFilter->Last()->SetUniqueID(iD-1);
1817 CreateMatrix(trackK->fCovFilter);
1818 iD = 1;
1819 }
1820 *((TMatrixD*)(trackK->fCovFilter->Last())) = *(trackK->fCovariance);
1821 trackK->fCovFilter->Last()->SetUniqueID(iD);
1822
1823 // Save Chi2-increment for point
1824 Int_t indx = trackK->fTrackHitsPtr->IndexOf(hitAdd);
1825 if (indx < 0) indx = fNTrackHits;
1826 if (trackK->fChi2Array->fN <= indx) trackK->fChi2Array->Set(indx+10);
1827 trackK->fChi2Array->AddAt(dChi2,indx);
1828}
1829
1830 //__________________________________________________________________________
1831void AliMUONTrackK::CreateMatrix(TObjArray *objArray)
1832{
1833 // Create new matrix and add it to TObjArray
1834
1835 TMatrixD *matrix = (TMatrixD*) objArray->First();
1836 TMatrixD *tmp = new TMatrixD(*matrix);
b21aa6eb 1837 objArray->AddAtAndExpand(tmp,objArray->GetLast());
b035a148 1838 //cout << " !!! " << tmp << " " << tmp->GetUniqueID() << " " << tmp->GetNoElements() << endl;
1839}
1840
1841 //__________________________________________________________________________
1842void AliMUONTrackK::RemoveMatrices(Double_t zEnd)
1843{
1844 // Remove matrices (and saved steps) in the smoother part with abs(z) < abs(zEnd)
1845
1846 for (Int_t i=fNSteps-1; i>=0; i--) {
1847 if (fgDebug > 1) printf("%10.4f %10.4f \n", (*fSteps)[i], zEnd);
1848 if (TMath::Abs((*fSteps)[i]) > TMath::Abs(zEnd) - 0.01) break;
1849 RemoveMatrices(this);
1850 } // for (Int_t i=fNSteps-1;
83dbc640 1851}
1852
b035a148 1853 //__________________________________________________________________________
1854void AliMUONTrackK::RemoveMatrices(AliMUONTrackK* trackK)
1855{
1856 // Remove last saved matrices and steps in the smoother part
1857
1858 trackK->fNSteps--;
1859 Int_t i = trackK->fNSteps;
1860
1861 Int_t id = 0;
1862 // Delete only matrices not shared by several tracks
1863 id = trackK->fParExtrap->Last()->GetUniqueID();
1864 if (id > 1) {
1865 trackK->fParExtrap->Last()->SetUniqueID(id-1);
1866 trackK->fParExtrap->RemoveAt(i);
1867 }
1868 else ((TMatrixD*)(trackK->fParExtrap->RemoveAt(i)))->Delete();
1869 id = fParFilter->Last()->GetUniqueID();
1870 if (id > 1) {
1871 trackK->fParFilter->Last()->SetUniqueID(id-1);
1872 trackK->fParFilter->RemoveAt(i);
1873 }
1874 else ((TMatrixD*)(trackK->fParFilter->RemoveAt(i)))->Delete();
1875 id = trackK->fCovExtrap->Last()->GetUniqueID();
1876 if (id > 1) {
1877 trackK->fCovExtrap->Last()->SetUniqueID(id-1);
1878 trackK->fCovExtrap->RemoveAt(i);
1879 }
1880 else ((TMatrixD*)(trackK->fCovExtrap->RemoveAt(i)))->Delete();
1881 id = trackK->fCovFilter->Last()->GetUniqueID();
1882 if (id > 1) {
1883 trackK->fCovFilter->Last()->SetUniqueID(id-1);
1884 trackK->fCovFilter->RemoveAt(i);
1885 }
1886 else ((TMatrixD*)(trackK->fCovFilter->RemoveAt(i)))->Delete();
1887 id = trackK->fJacob->Last()->GetUniqueID();
1888 if (id > 1) {
1889 trackK->fJacob->Last()->SetUniqueID(id-1);
1890 trackK->fJacob->RemoveAt(i);
1891 }
1892 else ((TMatrixD*)(trackK->fJacob->RemoveAt(i)))->Delete();
1893}
1894
b035a148 1895 //__________________________________________________________________________
1896Bool_t AliMUONTrackK::Smooth(void)
1897{
1898 // Apply smoother
1899 Int_t ihit = fNTrackHits - 1;
1900 AliMUONHitForRec *hit = (AliMUONHitForRec*) (*fTrackHitsPtr)[ihit];
1901 fChi2Smooth = new TArrayD(fNTrackHits);
1902 fChi2Smooth->Reset(-1);
1903 fChi2 = 0;
1904 fParSmooth = new TObjArray(15);
1905 fParSmooth->Clear();
1906
1907 if (fgDebug > 0) {
1908 cout << " ******** Enter Smooth " << endl;
1909 cout << (*fSteps)[fNSteps-1] << " " << fPosition << " " << fPositionNew << endl;
1910 /*
1911 for (Int_t i=fNSteps-1; i>=0; i--) cout << (*fSteps)[i] << " ";
1912 cout << endl;
b21aa6eb 1913 for (Int_t i=fNSteps-1; i>=0; i--) {cout << i << " " << (*fSteps)[i]; ((TMatrixD*)fParFilter->UncheckedAt(i))->Print(); ((TMatrixD*)fParExtrap->UncheckedAt(i))->Print(); ((TMatrixD*)fJacob->UncheckedAt(i))->Print();}
b035a148 1914 */
1915 for (Int_t i=ihit; i>=0; i--) cout << ((AliMUONHitForRec*)(*fTrackHitsPtr)[i])->GetZ() << " ";
1916 cout << endl;
1917 }
1918
1919 // Find last point corresponding to the last hit
1920 Int_t iLast = fNSteps - 1;
1921 for ( ; iLast>=0; iLast--) {
1922 //AZ(z->-z) if ((*fSteps)[iLast] + 0.01 > ((AliMUONHitForRec*)(*fTrackHitsPtr)[fNTrackHits-1])->GetZ()) break;
1923 if (TMath::Abs((*fSteps)[iLast]) + 0.01 > TMath::Abs(((AliMUONHitForRec*)(*fTrackHitsPtr)[fNTrackHits-1])->GetZ())) break;
1924 }
1925
1926 TMatrixD parSmooth = *((TMatrixD*)(fParFilter->UncheckedAt(iLast))); // last filtered = first smoothed
1927 //parSmooth.Dump();
1928 TMatrixD covSmooth = *((TMatrixD*)(fCovFilter->UncheckedAt(iLast))); // last filtered = first smoothed
1929 TMatrixD tmp=covSmooth, weight=covSmooth, gain = covSmooth;
1930 TMatrixD tmpPar = *fTrackPar;
1931 //parSmooth.Print(); ((TMatrixD*)(fParExtrap->Last()))->Print();
1932
1933 Bool_t found;
f29ba3e1 1934 Double_t chi2max = 0;
b035a148 1935 for (Int_t i=iLast+1; i>0; i--) {
1936 if (i == iLast + 1) goto L33; // temporary fix
1937
1938 // Smoother gain matrix
1939 weight = *((TMatrixD*)(fCovExtrap->UncheckedAt(i)));
1940 if (weight.Determinant() != 0) {
b21aa6eb 1941 Int_t ifail;
1942 mnvertLocal(&(weight(0,0)), fgkSize,fgkSize,fgkSize,ifail);
b035a148 1943 } else {
b21aa6eb 1944 AliWarning(" Determinant weight=0:");
b035a148 1945 }
1946 // Fk'Wkk+1
1947 tmp = TMatrixD(*((TMatrixD*)(fJacob->UncheckedAt(i))),TMatrixD::kTransposeMult,weight);
1948 gain = TMatrixD(*((TMatrixD*)(fCovFilter->UncheckedAt(i-1))),TMatrixD::kMult,tmp);
1949 //cout << (*fSteps)[i-1] << " " << (*fSteps)[i] << endl; gain.Print();
1950
1951 // Smoothed parameter vector
1952 //((TMatrixD*)(fParExtrap->UncheckedAt(i)))->Dump();
1953 parSmooth -= *((TMatrixD*)(fParExtrap->UncheckedAt(i)));
1954 tmpPar = *((TMatrixD*)(fParFilter->UncheckedAt(i-1)));
1955 tmpPar += TMatrixD(gain,TMatrixD::kMult,parSmooth);
1956 parSmooth = tmpPar;
1957
1958 // Smoothed covariance
1959 covSmooth -= *((TMatrixD*)(fCovExtrap->UncheckedAt(i)));
1960 weight = TMatrixD(TMatrixD::kTransposed,gain);
1961 tmp = TMatrixD(covSmooth,TMatrixD::kMult,weight);
1962 covSmooth = *((TMatrixD*)(fCovFilter->UncheckedAt(i-1)));
1963 covSmooth += TMatrixD(gain,TMatrixD::kMult,tmp);
1964
1965 // Check if there was a measurement at given z
1966 found = kFALSE;
1967 for ( ; ihit>=0; ihit--) {
1968 hit = (AliMUONHitForRec*) (*fTrackHitsPtr)[ihit];
1969 if (TMath::Abs(hit->GetZ()-(*fSteps)[i-1]) < 0.1) { found = kTRUE; break; }
1970 //AZ(z->-z) else if (ihit < fNTrackHits-1 && hit->GetZ() > (*fSteps)[i-1]) { ihit++; break; }
1971 else if (ihit < fNTrackHits-1 && TMath::Abs(hit->GetZ()) > TMath::Abs((*fSteps)[i-1])) { ihit++; break; }
1972 }
1973 if (!found) continue; // no measurement - skip the rest
1974 else if (fgDebug > 1) cout << i << " " << ihit << " " << hit->GetZ() << endl;
1975 if (ihit == 0) continue; // the first hit - skip the rest
1976
1977L33:
1978 // Smoothed residuals
1979 tmpPar = 0;
1980 tmpPar(0,0) = hit->GetBendingCoor() - parSmooth(0,0); // bending coordinate
1981 tmpPar(1,0) = hit->GetNonBendingCoor() - parSmooth(1,0); // non-bending coordinate
1982 if (fgDebug > 1) {
1983 cout << hit->GetBendingCoor() << " " << parSmooth(0,0) << " " << tmpPar(0,0) << endl;
1984 cout << hit->GetNonBendingCoor() << " " << parSmooth(1,0) << " " << tmpPar(1,0) << endl;
1985 }
1986 // Cov. matrix of smoothed residuals
1987 tmp = 0;
1988 tmp(0,0) = hit->GetBendingReso2() - covSmooth(0,0);
1989 tmp(1,1) = hit->GetNonBendingReso2() - covSmooth(1,1);
1990 tmp(0,1) = tmp(1,0) = -covSmooth(0,1);
1991 tmp(2,2) = tmp(3,3) = tmp(4,4) = 1;
1992
1993 // Calculate Chi2 of smoothed residuals
1994 if (tmp.Determinant() != 0) {
b21aa6eb 1995 Int_t ifail;
1996 mnvertLocal(&(tmp(0,0)), fgkSize,fgkSize,fgkSize,ifail);
b035a148 1997 } else {
b21aa6eb 1998 AliWarning(" Determinant tmp=0:");
b035a148 1999 }
2000 TMatrixD vector(tmp,TMatrixD::kMult,tmpPar);
2001 TMatrixD chi2(tmpPar,TMatrixD::kTransposeMult,vector);
2002 if (fgDebug > 1) chi2.Print();
2003 (*fChi2Smooth)[ihit] = chi2(0,0);
f29ba3e1 2004 if (chi2(0,0) > chi2max) chi2max = chi2(0,0);
b035a148 2005 fChi2 += chi2(0,0);
2006 if (chi2(0,0) < 0) {
94eb555e 2007 //chi2.Print();
2008 AliError(Form(" *** chi2 < 0: %d %d ", i, iLast));
b035a148 2009 }
2010 // Save smoothed parameters
2011 TMatrixD *par = new TMatrixD(parSmooth);
b21aa6eb 2012 fParSmooth->AddAtAndExpand(par, ihit);
b035a148 2013
2014 } // for (Int_t i=iLast+1;
2015
f29ba3e1 2016 //if (chi2max > 16) {
2017 //if (chi2max > 25) {
2018 //if (chi2max > 50) {
2019 //if (chi2max > 100) {
2020 if (chi2max > fgkChi2max) {
b035a148 2021 //if (Recover()) DropBranches();
2022 //Recover();
2023 Outlier();
2024 return kFALSE;
2025 }
2026 return kTRUE;
2027}
2028
2029 //__________________________________________________________________________
2030void AliMUONTrackK::Outlier()
2031{
2032 // Adds new track with removed hit having the highest chi2
2033
2034 if (fgDebug > 0) {
2035 cout << " ******** Enter Outlier " << endl;
2036 for (Int_t i=0; i<fNTrackHits; i++) printf("%10.4f", (*fChi2Smooth)[i]);
2037 printf("\n");
2038 for (Int_t i=0; i<fNTrackHits; i++) {
2039 printf("%10d", ((AliMUONHitForRec*)fTrackHitsPtr->UncheckedAt(i))->GetChamberNumber());
2040 }
2041 printf("\n");
2042 }
2043
f29ba3e1 2044 Double_t chi2max = 0;
b035a148 2045 Int_t imax = 0;
2046 for (Int_t i=0; i<fNTrackHits; i++) {
f29ba3e1 2047 if ((*fChi2Smooth)[i] < chi2max) continue;
2048 chi2max = (*fChi2Smooth)[i];
b035a148 2049 imax = i;
2050 }
2051 // Check if the outlier is not from the seed segment
2052 AliMUONHitForRec *hit = (AliMUONHitForRec*) fTrackHitsPtr->UncheckedAt(imax);
2053 if (hit == fStartSegment->GetHitForRec1() || hit == fStartSegment->GetHitForRec2()) return; // to be changed probably
2054
2055 // Check for missing station
2056 Int_t ok = 1;
2057 if (imax == 0) {
2058 if (((AliMUONHitForRec*)fTrackHitsPtr->UncheckedAt(1))->GetChamberNumber() < 8) ok--;
2059 } else if (imax == fNTrackHits-1) {
2060 if (((AliMUONHitForRec*)fTrackHitsPtr->UncheckedAt(fNTrackHits-2))->GetChamberNumber() > 1) ok--;
2061 }
2062 else if (((AliMUONHitForRec*)fTrackHitsPtr->UncheckedAt(imax-1))->GetChamberNumber()/2 - ((AliMUONHitForRec*)fTrackHitsPtr->UncheckedAt(imax+1))->GetChamberNumber()/2 > 1) ok--;
2063 if (!ok) { Recover(); return; } // try to recover track
2064 //AZ if (!ok) { if (fgDebug >= 0) cout << imax << endl; DropBranches(imax, 0); return; }
2065
2066 // Remove saved steps and smoother matrices after the outlier
2067 RemoveMatrices(hit->GetZ());
2068
2069 // Check for possible double track candidates
2070 //if (ExistDouble(hit)) return;
2071
29f1b13a 2072 TClonesArray *trackPtr = fgTrackReconstructor->GetRecTracksPtr();
2073 Int_t nRecTracks = fgTrackReconstructor->GetNRecTracks();
b035a148 2074
2075 AliMUONTrackK *trackK = 0;
2076 if (!fNSteps || GetStation0() == 3 && hit->GetChamberNumber() > 7) {
2077 // start track from segment
2078 trackK = new ((*trackPtr)[nRecTracks]) AliMUONTrackK(fStartSegment);
29f1b13a 2079 fgTrackReconstructor->SetNRecTracks(nRecTracks+1);
b035a148 2080 trackK->fRecover = 2;
2081 trackK->fSkipHit = hit;
2082 trackK->fNTrackHits = fNTrackHits;
2083 delete trackK->fTrackHitsPtr; // not efficient ?
2084 trackK->fTrackHitsPtr = new TObjArray(*fTrackHitsPtr);
2085 if (GetStation0() == 3) trackK->SortHits(1, trackK->fTrackHitsPtr);
2086 if (fgDebug > 0) cout << nRecTracks << " Outlier" << endl;
2087 return;
2088 }
2089 trackK = new ((*trackPtr)[nRecTracks]) AliMUONTrackK(NULL, NULL);
2090 *trackK = *this;
29f1b13a 2091 fgTrackReconstructor->SetNRecTracks(nRecTracks+1);
b035a148 2092 trackK->fTrackDir = 1;
2093 trackK->fRecover = 2;
2094 trackK->fSkipHit = hit;
2095 Int_t iD = trackK->fParFilter->Last()->GetUniqueID();
2096 if (iD > 1) {
2097 trackK->fParFilter->Last()->SetUniqueID(iD-1);
2098 CreateMatrix(trackK->fParFilter);
2099 iD = 1;
2100 trackK->fParFilter->Last()->SetUniqueID(iD);
2101 }
2102 *((TMatrixD*)trackK->fParFilter->Last()) = *((TMatrixD*)fParExtrap->Last());
2103 *(trackK->fTrackPar) = *((TMatrixD*)trackK->fParFilter->Last());
2104 iD = trackK->fCovFilter->Last()->GetUniqueID();
2105 if (iD > 1) {
2106 trackK->fCovFilter->Last()->SetUniqueID(iD-1);
2107 CreateMatrix(trackK->fCovFilter);
2108 iD = 1;
2109 trackK->fCovFilter->Last()->SetUniqueID(iD);
2110 }
2111 *((TMatrixD*)trackK->fCovFilter->Last()) = *((TMatrixD*)fCovExtrap->Last());
2112 *(trackK->fWeight) = *((TMatrixD*)trackK->fCovFilter->Last());
2113 if (trackK->fWeight->Determinant() != 0) {
b21aa6eb 2114 Int_t ifail;
2115 mnvertLocal(&((*(trackK->fWeight))(0,0)), fgkSize,fgkSize,fgkSize,ifail);
b035a148 2116 } else {
b21aa6eb 2117 AliWarning(" Determinant fWeight=0:");
b035a148 2118 }
2119 trackK->fPosition = trackK->fPositionNew = (*fSteps)[fNSteps-1];
2120 trackK->fChi2 = 0;
2121 for (Int_t i=0; i<fNTrackHits-1; i++) trackK->fChi2 += (*fChi2Array)[i];
2122 if (fgDebug > 0) cout << nRecTracks << " Outlier " << trackK->fChi2 << endl;
2123}
2124
2125 //__________________________________________________________________________
2126Double_t AliMUONTrackK::GetChi2PerPoint(Int_t iPoint) const
2127{
2128 // Return Chi2 at point
2129 return fChi2Smooth ? (*fChi2Smooth)[iPoint] : (*fChi2Array)[iPoint];
2130 //return 0.;
2131}
2132
2133 //__________________________________________________________________________
2134void AliMUONTrackK::Print(FILE *lun) const
2135{
2136 // Print out track information
2137
2138 Int_t flag = 1;
2139 AliMUONHitForRec *hit = 0;
29f1b13a 2140 if (fgTrackReconstructor->GetRecTrackRefHits()) {
29fc2c86 2141 // from track ref. hits
b035a148 2142 for (Int_t j=0; j<fNTrackHits; j++) {
2143 hit = (AliMUONHitForRec*) fTrackHitsPtr->UncheckedAt(j);
29fc2c86 2144 if (hit->GetTTRTrack() > 1) { flag = 0; break; }
b035a148 2145 }
2146 for (Int_t j=0; j<fNTrackHits; j++) {
2147 printf("%10.4f", GetChi2PerPoint(j));
2148 if (GetChi2PerPoint(j) > -0.1) {
2149 hit = (AliMUONHitForRec*) fTrackHitsPtr->UncheckedAt(j);
2150 fprintf(lun,"%3d %3d %10.4f", gAlice->GetEvNumber(), hit->GetChamberNumber(), GetChi2PerPoint(j));
29fc2c86 2151 fprintf(lun, "%3d %3d %3d \n", hit->GetTrackRefSignal(), hit->GetTTRTrack(), flag);
b035a148 2152 }
2153 }
2154 printf("\n");
2155 } else {
2156 // from raw clusters
2157 AliMUONRawCluster *clus = 0;
2158 TClonesArray *rawclusters = 0;
2159 for (Int_t i1=0; i1<fNTrackHits; i1++) {
2160 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
29f1b13a 2161 rawclusters = fgTrackReconstructor->GetMUONData()->RawClusters(hit->GetChamberNumber());
b035a148 2162 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
2163 if (TMath::Abs(clus->GetTrack(1)-1) < 2) {
2164 if (clus->GetTrack(2)) flag = 2;
2165 continue;
2166 }
2167 if (clus->GetTrack(2) && TMath::Abs(clus->GetTrack(2)-1) < 2) {
2168 flag = 3;
2169 continue;
2170 }
2171 flag = 0;
2172 break;
2173 }
2174 Int_t sig[2]={1,1}, tid[2]={0};
2175 for (Int_t i1=0; i1<fNTrackHits; i1++) {
2176 if (GetChi2PerPoint(i1) < -0.1) continue;
2177 hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
29f1b13a 2178 rawclusters = fgTrackReconstructor->GetMUONData()->RawClusters(hit->GetChamberNumber());
b035a148 2179 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
2180 for (Int_t j=0; j<2; j++) {
2181 tid[j] = clus->GetTrack(j+1) - 1;
2182 if (clus->GetTrack(j+1) < 0) { sig[j] = 0; tid[j] = 999; }
2183 }
2184 fprintf(lun,"%3d %3d %10.4f", gAlice->GetEvNumber(), hit->GetChamberNumber(), GetChi2PerPoint(i1));
2185 if (!(clus->GetTrack(2))) fprintf(lun, "%3d %3d", sig[0], tid[0]); // simple cluster
2186 else { // track overlap
2187 fprintf(lun, "%3d %3d", TMath::Max(sig[0],sig[1]), TMath::Min(tid[0],tid[1]));
2188 //if (tid[0] < 2) flag *= 2;
2189 //else if (tid[1] < 2) flag *= 3;
2190 }
2191 fprintf (lun, "%3d \n", flag);
2192 }
2193 }
2194}
2195
2196 //__________________________________________________________________________
2197void AliMUONTrackK::DropBranches(Int_t imax, TObjArray *hits)
2198{
2199 // Drop branches downstream of the skipped hit
2200 Int_t nRecTracks;
2201 TClonesArray *trackPtr;
2202 AliMUONTrackK *trackK;
2203
29f1b13a 2204 trackPtr = fgTrackReconstructor->GetRecTracksPtr();
2205 nRecTracks = fgTrackReconstructor->GetNRecTracks();
b035a148 2206 Int_t icand = trackPtr->IndexOf(this);
2207 if (!hits) hits = fTrackHitsPtr;
2208
2209 // Check if the track candidate doesn't exist yet
2210 for (Int_t i=icand+1; i<nRecTracks; i++) {
2211 trackK = (AliMUONTrackK*) ((*trackPtr)[i]);
2212 if (trackK->fNTrackHits == 2 && trackK->GetRecover() == 0) continue;
2213 if (trackK->GetRecover() < 0) continue;
2214
2215 if (trackK->fNTrackHits >= imax + 1) {
2216 for (Int_t j=0; j<=imax; j++) {
2217 //if (j != fNTrackHits-1 && (*trackK->fTrackHitsPtr)[j] != (*fTrackHitsPtr)[j]) break;
2218 if ((*trackK->fTrackHitsPtr)[j] != (*hits)[j]) break;
2219 if (j == imax) {
2220 if (hits != fTrackHitsPtr) {
2221 // Drop all branches downstream the hit (for Recover)
2222 trackK->SetRecover(-1);
2223 if (fgDebug >= 0 )cout << " Recover " << i << endl;
2224 continue;
2225 }
2226 // Check if the removal of the hit breaks the track
2227 Int_t ok = 1;
2228 if (imax == 0) {
2229 if (((AliMUONHitForRec*)trackK->fTrackHitsPtr->UncheckedAt(1))->GetChamberNumber() < 8) ok--; }
2230 else if (imax == trackK->fNTrackHits-1) continue;
2231 // else if (imax == trackK->fNTrackHits-1) {
2232 //if (((AliMUONHitForRec*)trackK->fTrackHitsPtr->UncheckedAt(trackK->fNTrackHits-2))->GetChamberNumber() > 1) ok--;
2233 //}
2234 else if (((AliMUONHitForRec*)trackK->fTrackHitsPtr->UncheckedAt(imax-1))->GetChamberNumber()/2 - ((AliMUONHitForRec*)trackK->fTrackHitsPtr->UncheckedAt(imax+1))->GetChamberNumber()/2 > 1) ok--;
2235 if (!ok) trackK->SetRecover(-1);
2236 }
2237 } // for (Int_t j=0;
2238 }
2239 } // for (Int_t i=0;
2240}
2241
2242 //__________________________________________________________________________
2243void AliMUONTrackK::DropBranches(AliMUONSegment *segment)
2244{
2245 // Drop all candidates with the same seed segment
2246 Int_t nRecTracks;
2247 TClonesArray *trackPtr;
2248 AliMUONTrackK *trackK;
2249
29f1b13a 2250 trackPtr = fgTrackReconstructor->GetRecTracksPtr();
2251 nRecTracks = fgTrackReconstructor->GetNRecTracks();
b035a148 2252 Int_t icand = trackPtr->IndexOf(this);
2253
2254 for (Int_t i=icand+1; i<nRecTracks; i++) {
2255 trackK = (AliMUONTrackK*) ((*trackPtr)[i]);
2256 if (trackK->fNTrackHits == 2 && trackK->GetRecover() == 0) continue;
2257 if (trackK->GetRecover() < 0) continue;
2258 if (trackK->fStartSegment == segment) trackK->SetRecover(-1);
2259 }
2260 if (fgDebug >= 0) cout << " Drop segment " << endl;
2261}
2262
2263 //__________________________________________________________________________
2264AliMUONHitForRec* AliMUONTrackK::GetHitLastOk(void)
2265{
2266 // Return the hit where track stopped
2267
2268 if (!fNSteps) return (AliMUONHitForRec*)((*fTrackHitsPtr)[1]);
2269 return fSkipHit;
2270}
2271
2272 //__________________________________________________________________________
2273Int_t AliMUONTrackK::GetStation0(void)
2274{
2275 // Return seed station number
2276 return fStartSegment->GetHitForRec1()->GetChamberNumber() / 2;
2277}
2278
2279 //__________________________________________________________________________
2280Bool_t AliMUONTrackK::ExistDouble(AliMUONHitForRec *hit)
2281{
2282 // Check if the track will make a double after outlier removal
2283
29f1b13a 2284 TClonesArray *trackPtr = fgTrackReconstructor->GetRecTracksPtr();
2285 Int_t nRecTracks = fgTrackReconstructor->GetNRecTracks();
b035a148 2286 TObjArray *hitArray = new TObjArray(*fTrackHitsPtr);
2287 TObjArray *hitArray1 = new TObjArray(*hitArray);
2288 hitArray1->Remove(hit);
2289 hitArray1->Compress();
2290
2291 Bool_t same = kFALSE;
2292 for (Int_t i=0; i<nRecTracks; i++) {
2293 AliMUONTrackK *trackK = (AliMUONTrackK*) ((*trackPtr)[i]);
2294 if (trackK->fNTrackHits == 2 && trackK->GetRecover() == 0) continue;
2295 if (trackK == this) continue;
2296 if (trackK->fNTrackHits == fNTrackHits || trackK->fNTrackHits == fNTrackHits-1) {
2297 TObjArray *hits = new TObjArray(*trackK->fTrackHitsPtr);
2298 same = kTRUE;
2299 if (trackK->fNTrackHits == fNTrackHits) {
2300 for (Int_t j=0; j<fNTrackHits; j++) {
2301 if (hits->UncheckedAt(j) != hitArray->UncheckedAt(j)) { same = kFALSE; break; }
2302 }
2303 if (same) { delete hits; break; }
2304 if (trackK->fSkipHit) {
2305 TObjArray *hits1 = new TObjArray(*hits);
2306 if (hits1->Remove(trackK->fSkipHit) > 0) {
2307 hits1->Compress();
2308 same = kTRUE;
2309 for (Int_t j=0; j<fNTrackHits-1; j++) {
2310 if (hits1->UncheckedAt(j) != hitArray1->UncheckedAt(j)) { same = kFALSE; break; }
2311 }
2312 if (same) { delete hits1; break; }
2313 }
2314 delete hits1;
2315 }
2316 } else {
2317 // Check with removed outlier
2318 same = kTRUE;
2319 for (Int_t j=0; j<fNTrackHits-1; j++) {
2320 if (hits->UncheckedAt(j) != hitArray1->UncheckedAt(j)) { same = kFALSE; break; }
2321 }
2322 if (same) { delete hits; break; }
2323 }
2324 delete hits;
2325 }
2326 } // for (Int_t i=0; i<nRecTracks;
2327 delete hitArray; delete hitArray1;
2328 if (same && fgDebug >= 0) cout << " Same" << endl;
2329 return same;
2330}
2331
2332 //__________________________________________________________________________
2333Bool_t AliMUONTrackK::ExistDouble(void)
2334{
2335 // Check if the track will make a double after recovery
2336
29f1b13a 2337 TClonesArray *trackPtr = fgTrackReconstructor->GetRecTracksPtr();
2338 Int_t nRecTracks = fgTrackReconstructor->GetNRecTracks();
b035a148 2339
2340 TObjArray *hitArray = new TObjArray(*fTrackHitsPtr);
2341 if (GetStation0() == 3) SortHits(0, hitArray); // sort
2342 //if (GetStation0() == 3) SortHits(1, hitArray); // unsort
2343
2344 Bool_t same = kFALSE;
2345 for (Int_t i=0; i<nRecTracks; i++) {
2346 AliMUONTrackK *trackK = (AliMUONTrackK*) ((*trackPtr)[i]);
2347 if (trackK->fNTrackHits == 2 && trackK->GetRecover() == 0) continue;
2348 if (trackK == this) continue;
2349 //AZ if (trackK->GetRecover() < 0) continue; //
2350 if (trackK->fNTrackHits >= fNTrackHits) {
2351 TObjArray *hits = new TObjArray(*trackK->fTrackHitsPtr);
2352 if (trackK->GetStation0() == 3) SortHits(0, hits); // sort
2353 //if (trackK->GetStation0() == 3) SortHits(1, hits); // unsort
2354 for (Int_t j=0; j<fNTrackHits; j++) {
2355 //cout << fNTrackHits << " " << i << " " << j << " " << (*hitArray)[j] << " " << (*hits)[j] << " " << trackK->fSkipHit << endl;
2356 if (j != fNTrackHits-1 && (*hitArray)[j] != (*hits)[j]) break;
2357 if (j == fNTrackHits-1) {
2358 if (trackK->fSkipHit && TMath::Abs(((AliMUONHitForRec*)((*hitArray)[j]))->GetZ()-trackK->fSkipHit->GetZ()) < 0.5) same = kTRUE;
2359 //if (trackK->fNTrackHits > fNTrackHits &&
2360 //if (trackK->fSkipHit) cout << ((AliMUONHitForRec*)((*hitArray)[j]))->GetZ() << " " << trackK->fSkipHit->GetZ() << endl;
2361 }
2362 } // for (Int_t j=0;
2363 delete hits;
2364 if (same) break;
2365 }
2366 } // for (Int_t i=0;
2367 delete hitArray;
2368 return same;
2369}