]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrack.cxx
Adaption to new fluka common blocks (E. Futo)
[u/mrichter/AliRoot.git] / MUON / AliMUONTrack.cxx
CommitLineData
a9e2aefa 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
16/*
17$Log$
70479d0e 18Revision 1.14 2001/08/30 09:52:12 hristov
19The operator[] is replaced by At() or AddAt() in case of TObjArray.
20
2682e810 21Revision 1.13 2001/05/03 08:11:31 hristov
22stdlib.h included to define exit()
23
82a4bc7b 24Revision 1.12 2001/04/25 14:50:42 gosset
25Corrections to violations of coding conventions
26
3831f268 27Revision 1.11 2001/04/23 12:33:17 hristov
28Arrays with variable size created by new and deleted at the end
29
e804eb46 30Revision 1.10 2001/04/09 12:25:09 gosset
31Inversion of covariance matrices with local copy of TMinuit::mnvert,
32for symmetric positive definite matrices, instead of TMatrixD::Invert
33
44f59652 34Revision 1.9 2001/01/17 20:59:24 hristov
35chPrev initialised
36
bbe35c23 37Revision 1.8 2001/01/08 11:01:02 gosset
38Modifications used for addendum to Dimuon TDR (JP Cussonneau):
39*. MaxBendingMomentum to make both a segment and a track (default 500)
40*. MaxChi2 per degree of freedom to make a track (default 100)
41*. MinBendingMomentum used also to make a track
42 and not only a segment (default 3)
43*. wider roads for track search in stations 1 to 3
44*. extrapolation to actual Z instead of Z(chamber) in FollowTracks
45*. in track fit:
46 - limits on parameters X and Y (+/-500)
47 - covariance matrices in double precision
48 - normalization of covariance matrices before inversion
49 - suppression of Minuit printouts
50*. correction against memory leak (delete extrapHit) in FollowTracks
51*. RMax to 10 degrees with Z(chamber) instead of fixed values;
52 RMin and Rmax cuts suppressed in NewHitForRecFromGEANT,
53 because useless with realistic geometry
54
d0bfce8d 55Revision 1.7 2000/09/19 15:50:46 gosset
56TrackChi2MCS function: covariance matrix better calculated,
57taking into account missing planes...
58
eb9c9dab 59Revision 1.6 2000/07/20 12:45:27 gosset
60New "EventReconstructor..." structure,
61 hopefully more adapted to tree/streamer.
62"AliMUONEventReconstructor::RemoveDoubleTracks"
63 to keep only one track among similar ones.
64
8429a5e4 65Revision 1.5 2000/07/18 16:04:06 gosset
66AliMUONEventReconstructor package:
67* a few minor modifications and more comments
68* a few corrections
69 * right sign for Z of raw clusters
70 * right loop over chambers inside station
71 * symmetrized covariance matrix for measurements (TrackChi2MCS)
72 * right sign of charge in extrapolation (ExtrapToZ)
73 * right zEndAbsorber for Branson correction below 3 degrees
74* use of TVirtualFitter instead of TMinuit for AliMUONTrack::Fit
75* no parameter for AliMUONTrack::Fit() but more fit parameters in Track object
76
956019b6 77Revision 1.4 2000/06/30 10:15:48 gosset
78Changes to EventReconstructor...:
79precision fit with multiple Coulomb scattering;
80extrapolation to vertex with Branson correction in absorber (JPC)
81
04b5ea16 82Revision 1.3 2000/06/25 13:23:28 hristov
83stdlib.h needed for non-Linux compilation
84
f6e92cf4 85Revision 1.2 2000/06/15 07:58:48 morsch
86Code from MUON-dev joined
87
a9e2aefa 88Revision 1.1.2.3 2000/06/12 10:11:34 morsch
89Dummy copy constructor and assignment operator added
90
91Revision 1.1.2.2 2000/06/09 12:58:05 gosset
92Removed comment beginnings in Log sections of .cxx files
93Suppressed most violations of coding rules
94
95Revision 1.1.2.1 2000/06/07 14:44:53 gosset
96Addition of files for track reconstruction in C++
97*/
98
3831f268 99///////////////////////////////////////////////////
a9e2aefa 100//
3831f268 101// Reconstructed track
102// in
103// ALICE
104// dimuon
105// spectrometer
106//
107///////////////////////////////////////////////////
a9e2aefa 108
70479d0e 109#include <Riostream.h> // for cout
82a4bc7b 110#include <stdlib.h> // for exit()
a9e2aefa 111
112#include <TClonesArray.h>
04b5ea16 113#include <TMath.h>
d0bfce8d 114#include <TMatrixD.h>
8429a5e4 115#include <TObjArray.h>
956019b6 116#include <TVirtualFitter.h>
a9e2aefa 117
118#include "AliMUONEventReconstructor.h"
119#include "AliMUONHitForRec.h"
120#include "AliMUONSegment.h"
3831f268 121#include "AliMUONTrack.h"
a9e2aefa 122#include "AliMUONTrackHit.h"
123
04b5ea16 124// Functions to be minimized with Minuit
a9e2aefa 125void TrackChi2(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag);
04b5ea16 126void TrackChi2MCS(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag);
127
44f59652 128void mnvertLocal(Double_t* a, Int_t l, Int_t m, Int_t n, Int_t& ifail);
129
04b5ea16 130Double_t MultipleScatteringAngle2(AliMUONTrackHit *TrackHit);
a9e2aefa 131
132ClassImp(AliMUONTrack) // Class implementation in ROOT context
133
956019b6 134TVirtualFitter* AliMUONTrack::fgFitter = NULL;
135
a9e2aefa 136 //__________________________________________________________________________
137AliMUONTrack::AliMUONTrack(AliMUONSegment* BegSegment, AliMUONSegment* EndSegment, AliMUONEventReconstructor* EventReconstructor)
138{
139 // Constructor from two Segment's
140 fEventReconstructor = EventReconstructor; // link back to EventReconstructor
8429a5e4 141 // memory allocation for the TObjArray of pointers to reconstructed TrackHit's
142 fTrackHitsPtr = new TObjArray(10);
a9e2aefa 143 fNTrackHits = 0;
144 AddSegment(BegSegment); // add hits from BegSegment
145 AddSegment(EndSegment); // add hits from EndSegment
146 fTrackHitsPtr->Sort(); // sort TrackHits according to increasing Z
147 SetTrackParamAtVertex(); // set track parameters at vertex
8429a5e4 148 // set fit conditions...
04b5ea16 149 fFitMCS = 0;
956019b6 150 fFitNParam = 3;
151 fFitStart = 1;
8429a5e4 152 fFitFMin = -1.0;
a9e2aefa 153 return;
154}
155
156 //__________________________________________________________________________
157AliMUONTrack::AliMUONTrack(AliMUONSegment* Segment, AliMUONHitForRec* HitForRec, AliMUONEventReconstructor* EventReconstructor)
158{
159 // Constructor from one Segment and one HitForRec
160 fEventReconstructor = EventReconstructor; // link back to EventReconstructor
8429a5e4 161 // memory allocation for the TObjArray of pointers to reconstructed TrackHit's
162 fTrackHitsPtr = new TObjArray(10);
a9e2aefa 163 fNTrackHits = 0;
164 AddSegment(Segment); // add hits from Segment
165 AddHitForRec(HitForRec); // add HitForRec
166 fTrackHitsPtr->Sort(); // sort TrackHits according to increasing Z
167 SetTrackParamAtVertex(); // set track parameters at vertex
8429a5e4 168 // set fit conditions...
04b5ea16 169 fFitMCS = 0;
956019b6 170 fFitNParam = 3;
171 fFitStart = 1;
8429a5e4 172 fFitFMin = -1.0;
a9e2aefa 173 return;
174}
175
8429a5e4 176 //__________________________________________________________________________
177AliMUONTrack::~AliMUONTrack()
178{
179 // Destructor
180 if (fTrackHitsPtr) {
181 delete fTrackHitsPtr; // delete the TObjArray of pointers to TrackHit's
182 fTrackHitsPtr = NULL;
183 }
184}
185
956019b6 186 //__________________________________________________________________________
a9e2aefa 187AliMUONTrack::AliMUONTrack (const AliMUONTrack& MUONTrack)
188{
189// Dummy copy constructor
190}
191
956019b6 192 //__________________________________________________________________________
a9e2aefa 193AliMUONTrack & AliMUONTrack::operator=(const AliMUONTrack& MUONTrack)
194{
195// Dummy assignment operator
196 return *this;
197}
198
8429a5e4 199 //__________________________________________________________________________
200void AliMUONTrack::Remove()
201{
202 // Remove current track from array of tracks,
203 // and corresponding track hits from array of track hits.
204 // Compress the TClonesArray it belongs to.
205 AliMUONTrackHit *nextTrackHit;
206 AliMUONEventReconstructor *eventRec = this->fEventReconstructor;
207 TClonesArray *trackHitsPtr = eventRec->GetRecTrackHitsPtr();
208 // Loop over all track hits of track
209 AliMUONTrackHit *trackHit = (AliMUONTrackHit*) fTrackHitsPtr->First();
210 while (trackHit) {
211 nextTrackHit = (AliMUONTrackHit*) fTrackHitsPtr->After(trackHit);
212 // Remove TrackHit from event TClonesArray.
213 // Destructor is called,
214 // hence links between HitForRec's and TrackHit's are updated
215 trackHitsPtr->Remove(trackHit);
216 trackHit = nextTrackHit;
217 }
218 // Remove the track from event TClonesArray
219 // Destructor is called,
220 // hence space for TObjArray of pointers to TrackHit's is freed
221 eventRec->GetRecTracksPtr()->Remove(this);
222 // Number of tracks decreased by 1
223 eventRec->SetNRecTracks(eventRec->GetNRecTracks() - 1);
224 // Compress event TClonesArray of Track's:
225 // this is essential to retrieve the TClonesArray afterwards
226 eventRec->GetRecTracksPtr()->Compress();
227 // Compress event TClonesArray of TrackHit's:
228 // this is probably also essential to retrieve the TClonesArray afterwards
229 trackHitsPtr->Compress();
230}
231
04b5ea16 232 //__________________________________________________________________________
233void AliMUONTrack::SetFitMCS(Int_t FitMCS)
234{
956019b6 235 // Set multiple Coulomb scattering option for track fit "fFitMCS"
04b5ea16 236 // from "FitMCS" argument: 0 without, 1 with
956019b6 237 if ((FitMCS == 0) || (FitMCS == 1)) fFitMCS = FitMCS;
04b5ea16 238 // better implementation with enum(with, without) ????
956019b6 239 else {
240 cout << "ERROR in AliMUONTrack::SetFitMCS(FitMCS)" << endl;
241 cout << "FitMCS = " << FitMCS << " is neither 0 nor 1" << endl;
242 exit(0);
243 }
244 return;
245}
246
247 //__________________________________________________________________________
248void AliMUONTrack::SetFitNParam(Int_t FitNParam)
249{
250 // Set number of parameters for track fit "fFitNParam" from "FitNParam":
251 // 3 for momentum, 5 for momentum and position
252 if ((FitNParam == 3) || (FitNParam == 5)) fFitNParam = FitNParam;
253 else {
254 cout << "ERROR in AliMUONTrack::SetFitNParam(FitNParam)" << endl;
255 cout << "FitNParam = " << FitNParam << " is neither 3 nor 5" << endl;
256 exit(0);
257 }
258 return;
259}
260
261 //__________________________________________________________________________
262void AliMUONTrack::SetFitStart(Int_t FitStart)
263{
264 // Set multiple Coulomb scattering option for track fit "fFitStart"
265 // from "FitStart" argument: 0 without, 1 with
266 if ((FitStart == 0) || (FitStart == 1)) fFitStart = FitStart;
267 // better implementation with enum(vertex, firstHit) ????
268 else {
269 cout << "ERROR in AliMUONTrack::SetFitStart(FitStart)" << endl;
270 cout << "FitStart = " << FitStart << " is neither 0 nor 1" << endl;
271 exit(0);
272 }
04b5ea16 273 return;
274}
275
956019b6 276 //__________________________________________________________________________
3831f268 277AliMUONTrackParam* AliMUONTrack::GetTrackParamAtFirstHit(void) const {
a9e2aefa 278 // Get pointer to TrackParamAtFirstHit
279 return ((AliMUONTrackHit*) (fTrackHitsPtr->First()))->GetTrackParam();}
a9e2aefa 280
281 //__________________________________________________________________________
3831f268 282void AliMUONTrack::RecursiveDump(void) const
a9e2aefa 283{
284 // Recursive dump of AliMUONTrack, i.e. with dump of TrackHit's and HitForRec's
285 AliMUONTrackHit *trackHit;
286 AliMUONHitForRec *hitForRec;
287 cout << "Recursive dump of Track: " << this << endl;
288 // Track
289 this->Dump();
290 for (Int_t trackHitIndex = 0; trackHitIndex < fNTrackHits; trackHitIndex++) {
291 trackHit = (AliMUONTrackHit*) ((*fTrackHitsPtr)[trackHitIndex]);
292 // TrackHit
293 cout << "TrackHit: " << trackHit << " (index: " << trackHitIndex << ")" << endl;
294 trackHit->Dump();
295 hitForRec = trackHit->GetHitForRecPtr();
296 // HitForRec
297 cout << "HitForRec: " << hitForRec << endl;
298 hitForRec->Dump();
299 }
300 return;
301}
302
8429a5e4 303 //__________________________________________________________________________
304Int_t AliMUONTrack::HitsInCommon(AliMUONTrack* Track)
305{
306 // Returns the number of hits in common
307 // between the current track ("this")
308 // and the track pointed to by "Track".
309 Int_t hitsInCommon = 0;
310 AliMUONTrackHit *trackHit1, *trackHit2;
311 // Loop over hits of first track
312 trackHit1 = (AliMUONTrackHit*) this->GetTrackHitsPtr()->First();
313 while (trackHit1) {
314 // Loop over hits of second track
315 trackHit2 = (AliMUONTrackHit*) Track->GetTrackHitsPtr()->First();
316 while (trackHit2) {
317 // Increment "hitsInCommon" if both TrackHits point to the same HitForRec
318 if ( (trackHit1->GetHitForRecPtr()) ==
319 (trackHit2->GetHitForRecPtr()) ) hitsInCommon++;
320 trackHit2 = (AliMUONTrackHit*) Track->GetTrackHitsPtr()->After(trackHit2);
321 } // trackHit2
322 trackHit1 = (AliMUONTrackHit*) this->GetTrackHitsPtr()->After(trackHit1);
323 } // trackHit1
324 return hitsInCommon;
325}
326
a9e2aefa 327 //__________________________________________________________________________
956019b6 328void AliMUONTrack::Fit()
a9e2aefa 329{
330 // Fit the current track ("this"),
956019b6 331 // with or without multiple Coulomb scattering according to "fFitMCS",
332 // with the number of parameters given by "fFitNParam"
333 // (3 if one keeps X and Y fixed in "TrackParam", 5 if one lets them vary),
334 // starting, according to "fFitStart",
335 // with track parameters at vertex or at the first TrackHit.
336 // "fFitMCS", "fFitNParam" and "fFitStart" have to be set before
337 // by calling the corresponding Set methods.
a9e2aefa 338 Double_t arg[1], benC, errorParam, invBenP, lower, nonBenC, upper, x, y;
956019b6 339 char parName[50];
340 AliMUONTrackParam *trackParam;
341 // Check if Minuit is initialized...
342 fgFitter = TVirtualFitter::Fitter(this); // add 3 or 5 for the maximum number of parameters ???
343 fgFitter->Clear(); // necessary ???? probably yes
344 // how to reset the printout number at every fit ????
345 // is there any risk to leave it like that ????
a9e2aefa 346 // how to go faster ???? choice of Minuit parameters like EDM ????
04b5ea16 347 // choice of function to be minimized according to fFitMCS
956019b6 348 if (fFitMCS == 0) fgFitter->SetFCN(TrackChi2);
349 else fgFitter->SetFCN(TrackChi2MCS);
d0bfce8d 350 arg[0] = -1;
956019b6 351 fgFitter->ExecuteCommand("SET PRINT", arg, 1); // More printing !!!!
352 // Parameters according to "fFitStart"
353 // (should be a function to be used at every place where needed ????)
354 if (fFitStart == 0) trackParam = &fTrackParamAtVertex;
355 else trackParam = this->GetTrackParamAtFirstHit();
356 // set first 3 Minuit parameters
04b5ea16 357 // could be tried with no limits for the search (min=max=0) ????
956019b6 358 fgFitter->SetParameter(0, "InvBenP",
359 trackParam->GetInverseBendingMomentum(),
360 0.003, -0.4, 0.4);
361 fgFitter->SetParameter(1, "BenS",
362 trackParam->GetBendingSlope(),
363 0.001, -0.5, 0.5);
364 fgFitter->SetParameter(2, "NonBenS",
365 trackParam->GetNonBendingSlope(),
366 0.001, -0.5, 0.5);
367 if (fFitNParam == 5) {
d0bfce8d 368 // set last 2 Minuit parameters
369 // mandatory limits in Bending to avoid NaN values of parameters
956019b6 370 fgFitter->SetParameter(3, "X",
371 trackParam->GetNonBendingCoor(),
d0bfce8d 372 0.03, -500.0, 500.0);
373 // mandatory limits in non Bending to avoid NaN values of parameters
956019b6 374 fgFitter->SetParameter(4, "Y",
375 trackParam->GetBendingCoor(),
d0bfce8d 376 0.10, -500.0, 500.0);
a9e2aefa 377 }
378 // search without gradient calculation in the function
956019b6 379 fgFitter->ExecuteCommand("SET NOGRADIENT", arg, 0);
a9e2aefa 380 // minimization
956019b6 381 fgFitter->ExecuteCommand("MINIMIZE", arg, 0);
a9e2aefa 382 // exit from Minuit
956019b6 383 fgFitter->ExecuteCommand("EXIT", arg, 0); // necessary ????
384 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
385 fgFitter->GetParameter(0, parName, invBenP, errorParam, lower, upper);
386 fgFitter->GetParameter(1, parName, benC, errorParam, lower, upper);
387 fgFitter->GetParameter(2, parName, nonBenC, errorParam, lower, upper);
388 if (fFitNParam == 5) {
389 fgFitter->GetParameter(3, parName, x, errorParam, lower, upper);
390 fgFitter->GetParameter(4, parName, y, errorParam, lower, upper);
a9e2aefa 391 }
392 // result of the fit into track parameters
956019b6 393 trackParam->SetInverseBendingMomentum(invBenP);
394 trackParam->SetBendingSlope(benC);
395 trackParam->SetNonBendingSlope(nonBenC);
396 if (fFitNParam == 5) {
397 trackParam->SetNonBendingCoor(x);
398 trackParam->SetBendingCoor(y);
a9e2aefa 399 }
8429a5e4 400 // global result of the fit
401 Double_t fedm, errdef;
402 Int_t npari, nparx;
403 fgFitter->GetStats(fFitFMin, fedm, errdef, npari, nparx);
a9e2aefa 404}
405
406 //__________________________________________________________________________
407void AliMUONTrack::AddSegment(AliMUONSegment* Segment)
408{
8429a5e4 409 // Add Segment to the track
a9e2aefa 410 AddHitForRec(Segment->GetHitForRec1()); // 1st hit
411 AddHitForRec(Segment->GetHitForRec2()); // 2nd hit
412}
413
414 //__________________________________________________________________________
415void AliMUONTrack::AddHitForRec(AliMUONHitForRec* HitForRec)
416{
8429a5e4 417 // Add HitForRec to the track:
418 // actual TrackHit into TClonesArray of TrackHit's for the event;
419 // pointer to actual TrackHit in TObjArray of pointers to TrackHit's for the track
420 TClonesArray *recTrackHitsPtr = this->fEventReconstructor->GetRecTrackHitsPtr();
421 Int_t eventTrackHits = this->fEventReconstructor->GetNRecTrackHits();
422 // event
423 AliMUONTrackHit* trackHit =
424 new ((*recTrackHitsPtr)[eventTrackHits]) AliMUONTrackHit(HitForRec);
425 this->fEventReconstructor->SetNRecTrackHits(eventTrackHits + 1);
426 // track
427 fTrackHitsPtr->Add(trackHit);
a9e2aefa 428 fNTrackHits++;
429}
430
431 //__________________________________________________________________________
3831f268 432void AliMUONTrack::SetTrackParamAtHit(Int_t indexHit, AliMUONTrackParam *TrackParam) const
a9e2aefa 433{
434 // Set track parameters at TrackHit with index "indexHit"
435 // from the track parameters pointed to by "TrackParam".
2682e810 436 //PH AliMUONTrackHit* trackHit = (AliMUONTrackHit*) ((*fTrackHitsPtr)[indexHit]);
437 AliMUONTrackHit* trackHit = (AliMUONTrackHit*) (fTrackHitsPtr->At(indexHit));
a9e2aefa 438 trackHit->SetTrackParam(TrackParam);
439}
440
441 //__________________________________________________________________________
442void AliMUONTrack::SetTrackParamAtVertex()
443{
444 // Set track parameters at vertex.
445 // TrackHit's are assumed to be only in stations(1..) 4 and 5,
446 // and sorted according to increasing Z..
447 // Parameters are calculated from information in HitForRec's
448 // of first and last TrackHit's.
449 AliMUONTrackParam *trackParam =
450 &fTrackParamAtVertex; // pointer to track parameters
451 // Pointer to HitForRec of first TrackHit
452 AliMUONHitForRec *firstHit =
453 ((AliMUONTrackHit*) (fTrackHitsPtr->First()))->GetHitForRecPtr();
454 // Pointer to HitForRec of last TrackHit
455 AliMUONHitForRec *lastHit =
456 ((AliMUONTrackHit*) (fTrackHitsPtr->Last()))->GetHitForRecPtr();
457 // Z difference between first and last hits
458 Double_t deltaZ = firstHit->GetZ() - lastHit->GetZ();
459 // bending slope in stations(1..) 4 and 5
460 Double_t bendingSlope =
461 (firstHit->GetBendingCoor() - lastHit->GetBendingCoor()) / deltaZ;
462 trackParam->SetBendingSlope(bendingSlope);
463 // impact parameter
464 Double_t impactParam =
465 firstHit->GetBendingCoor() - bendingSlope * firstHit->GetZ(); // same if from firstHit and lastHit ????
466 // signed bending momentum
467 Double_t signedBendingMomentum =
468 fEventReconstructor->GetBendingMomentumFromImpactParam(impactParam);
469 trackParam->SetInverseBendingMomentum(1.0 / signedBendingMomentum);
470 // bending slope at vertex
471 trackParam->
472 SetBendingSlope(bendingSlope +
473 impactParam / fEventReconstructor->GetSimpleBPosition());
474 // non bending slope
475 Double_t nonBendingSlope =
476 (firstHit->GetNonBendingCoor() - lastHit->GetNonBendingCoor()) / deltaZ;
477 trackParam->SetNonBendingSlope(nonBendingSlope);
478 // vertex coordinates at (0,0,0)
479 trackParam->SetZ(0.0);
480 trackParam->SetBendingCoor(0.0);
481 trackParam->SetNonBendingCoor(0.0);
482}
483
484 //__________________________________________________________________________
485void TrackChi2(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag)
486{
487 // Return the "Chi2" to be minimized with Minuit for track fitting,
488 // with "NParam" parameters
489 // and their current values in array pointed to by "Param".
490 // Assumes that the track hits are sorted according to increasing Z.
491 // Track parameters at each TrackHit are updated accordingly.
04b5ea16 492 // Multiple Coulomb scattering is not taken into account
956019b6 493 AliMUONTrack *trackBeingFitted;
a9e2aefa 494 AliMUONTrackHit* hit;
495 AliMUONTrackParam param1;
496 Int_t hitNumber;
497 Double_t zHit;
498 Chi2 = 0.0; // initialize Chi2
499 // copy of track parameters to be fitted
956019b6 500 trackBeingFitted = (AliMUONTrack*) AliMUONTrack::Fitter()->GetObjectFit();
501 if (trackBeingFitted->GetFitStart() == 0)
502 param1 = *(trackBeingFitted->GetTrackParamAtVertex());
503 else param1 = *(trackBeingFitted->GetTrackParamAtFirstHit());
a9e2aefa 504 // Minuit parameters to be fitted into this copy
505 param1.SetInverseBendingMomentum(Param[0]);
506 param1.SetBendingSlope(Param[1]);
507 param1.SetNonBendingSlope(Param[2]);
508 if (NParam == 5) {
509 param1.SetNonBendingCoor(Param[3]);
510 param1.SetBendingCoor(Param[4]);
511 }
512 // Follow track through all planes of track hits
513 for (hitNumber = 0; hitNumber < trackBeingFitted->GetNTrackHits(); hitNumber++) {
514 hit = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber];
515 zHit = hit->GetHitForRecPtr()->GetZ();
516 // do something special if 2 hits with same Z ????
517 // security against infinite loop ????
518 (&param1)->ExtrapToZ(zHit); // extrapolation
519 hit->SetTrackParam(&param1);
520 // Increment Chi2
521 // done hit per hit, with hit resolution,
522 // and not with point and angle like in "reco_muon.F" !!!!
523 // Needs to add multiple scattering contribution ????
524 Double_t dX =
525 hit->GetHitForRecPtr()->GetNonBendingCoor() - (&param1)->GetNonBendingCoor();
526 Double_t dY =
527 hit->GetHitForRecPtr()->GetBendingCoor() - (&param1)->GetBendingCoor();
528 Chi2 =
529 Chi2 +
530 dX * dX / hit->GetHitForRecPtr()->GetNonBendingReso2() +
531 dY * dY / hit->GetHitForRecPtr()->GetBendingReso2();
532 }
533}
04b5ea16 534
535 //__________________________________________________________________________
536void TrackChi2MCS(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag)
537{
538 // Return the "Chi2" to be minimized with Minuit for track fitting,
539 // with "NParam" parameters
540 // and their current values in array pointed to by "Param".
541 // Assumes that the track hits are sorted according to increasing Z.
542 // Track parameters at each TrackHit are updated accordingly.
543 // Multiple Coulomb scattering is taken into account with covariance matrix.
956019b6 544 AliMUONTrack *trackBeingFitted;
04b5ea16 545 AliMUONTrackParam param1;
546 Chi2 = 0.0; // initialize Chi2
547 // copy of track parameters to be fitted
956019b6 548 trackBeingFitted = (AliMUONTrack*) AliMUONTrack::Fitter()->GetObjectFit();
549 if (trackBeingFitted->GetFitStart() == 0)
550 param1 = *(trackBeingFitted->GetTrackParamAtVertex());
551 else param1 = *(trackBeingFitted->GetTrackParamAtFirstHit());
04b5ea16 552 // Minuit parameters to be fitted into this copy
553 param1.SetInverseBendingMomentum(Param[0]);
554 param1.SetBendingSlope(Param[1]);
555 param1.SetNonBendingSlope(Param[2]);
556 if (NParam == 5) {
557 param1.SetNonBendingCoor(Param[3]);
558 param1.SetBendingCoor(Param[4]);
559 }
560
956019b6 561 AliMUONTrackHit *hit;
bbe35c23 562 Int_t chCurrent, chPrev = 0, hitNumber, hitNumber1, hitNumber2, hitNumber3;
eb9c9dab 563 Double_t z, z1, z2, z3;
564 AliMUONTrackHit *hit1, *hit2, *hit3;
565 Double_t hbc1, hbc2, pbc1, pbc2;
566 Double_t hnbc1, hnbc2, pnbc1, pnbc2;
567 Int_t numberOfHit = trackBeingFitted->GetNTrackHits();
d0bfce8d 568 TMatrixD *covBending = new TMatrixD(numberOfHit, numberOfHit);
569 TMatrixD *covNonBending = new TMatrixD(numberOfHit, numberOfHit);
eb9c9dab 570 Double_t *msa2 = new Double_t[numberOfHit];
04b5ea16 571
572 // Predicted coordinates and multiple scattering angles are first calculated
573 for (hitNumber = 0; hitNumber < numberOfHit; hitNumber++) {
574 hit = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber];
eb9c9dab 575 z = hit->GetHitForRecPtr()->GetZ();
04b5ea16 576 // do something special if 2 hits with same Z ????
577 // security against infinite loop ????
eb9c9dab 578 (&param1)->ExtrapToZ(z); // extrapolation
04b5ea16 579 hit->SetTrackParam(&param1);
eb9c9dab 580 // square of multiple scattering angle at current hit, with one chamber
581 msa2[hitNumber] = MultipleScatteringAngle2(hit);
582 // correction for eventual missing hits or multiple hits in a chamber,
583 // according to the number of chambers
584 // between the current hit and the previous one
585 chCurrent = hit->GetHitForRecPtr()->GetChamberNumber();
586 if (hitNumber > 0) msa2[hitNumber] = msa2[hitNumber] * (chCurrent - chPrev);
587 chPrev = chCurrent;
04b5ea16 588 }
589
590 // Calculates the covariance matrix
eb9c9dab 591 for (hitNumber1 = 0; hitNumber1 < numberOfHit; hitNumber1++) {
592 hit1 = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber1];
593 z1 = hit1->GetHitForRecPtr()->GetZ();
04b5ea16 594 for (hitNumber2 = hitNumber1; hitNumber2 < numberOfHit; hitNumber2++) {
eb9c9dab 595 hit2 = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber2];
596 z2 = hit2->GetHitForRecPtr()->GetZ();
956019b6 597 // initialization to 0 (diagonal plus upper triangular part)
598 (*covBending)(hitNumber2, hitNumber1) = 0.0;
599 // contribution from multiple scattering in bending plane:
600 // loop over upstream hits
601 for (hitNumber3 = 0; hitNumber3 < hitNumber1; hitNumber3++) {
eb9c9dab 602 hit3 = (AliMUONTrackHit*)
603 (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber3];
604 z3 = hit3->GetHitForRecPtr()->GetZ();
04b5ea16 605 (*covBending)(hitNumber2, hitNumber1) =
606 (*covBending)(hitNumber2, hitNumber1) +
eb9c9dab 607 ((z1 - z3) * (z2 - z3) * msa2[hitNumber3]);
956019b6 608 }
609 // equal contribution from multiple scattering in non bending plane
04b5ea16 610 (*covNonBending)(hitNumber2, hitNumber1) =
611 (*covBending)(hitNumber2, hitNumber1);
956019b6 612 if (hitNumber1 == hitNumber2) {
613 // Diagonal elements: add contribution from position measurements
614 // in bending plane
615 (*covBending)(hitNumber2, hitNumber1) =
eb9c9dab 616 (*covBending)(hitNumber2, hitNumber1) +
617 hit1->GetHitForRecPtr()->GetBendingReso2();
956019b6 618 // and in non bending plane
04b5ea16 619 (*covNonBending)(hitNumber2, hitNumber1) =
eb9c9dab 620 (*covNonBending)(hitNumber2, hitNumber1) +
621 hit1->GetHitForRecPtr()->GetNonBendingReso2();
956019b6 622 }
623 else {
624 // Non diagonal elements: symmetrization
625 // for bending plane
626 (*covBending)(hitNumber1, hitNumber2) =
627 (*covBending)(hitNumber2, hitNumber1);
628 // and non bending plane
629 (*covNonBending)(hitNumber1, hitNumber2) =
630 (*covNonBending)(hitNumber2, hitNumber1);
631 }
632 } // for (hitNumber2 = hitNumber1;...
633 } // for (hitNumber1 = 0;...
d0bfce8d 634
44f59652 635 // Inversion of covariance matrices
636 // with "mnvertLocal", local "mnvert" function of Minuit.
637 // One cannot use directly "mnvert" since "TVirtualFitter" does not know it.
638 // One will have to replace this local function by the right inversion function
639 // from a specialized Root package for symmetric positive definite matrices,
640 // when available!!!!
641 Int_t ifailBending;
642 mnvertLocal(&((*covBending)(0,0)), numberOfHit, numberOfHit, numberOfHit,
643 ifailBending);
644 Int_t ifailNonBending;
645 mnvertLocal(&((*covNonBending)(0,0)), numberOfHit, numberOfHit, numberOfHit,
646 ifailNonBending);
956019b6 647
648 // It would be worth trying to calculate the inverse of the covariance matrix
649 // only once per fit, since it cannot change much in principle,
650 // and it would save a lot of computing time !!!!
04b5ea16 651
652 // Calculates Chi2
44f59652 653 if ((ifailBending == 0) && (ifailNonBending == 0)) {
eb9c9dab 654 // with Multiple Scattering if inversion correct
655 for (hitNumber1 = 0; hitNumber1 < numberOfHit ; hitNumber1++) {
656 hit1 = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber1];
657 hbc1 = hit1->GetHitForRecPtr()->GetBendingCoor();
658 pbc1 = hit1->GetTrackParam()->GetBendingCoor();
659 hnbc1 = hit1->GetHitForRecPtr()->GetNonBendingCoor();
660 pnbc1 = hit1->GetTrackParam()->GetNonBendingCoor();
661 for (hitNumber2 = 0; hitNumber2 < numberOfHit; hitNumber2++) {
662 hit2 = (AliMUONTrackHit*)
663 (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber2];
664 hbc2 = hit2->GetHitForRecPtr()->GetBendingCoor();
665 pbc2 = hit2->GetTrackParam()->GetBendingCoor();
666 hnbc2 = hit2->GetHitForRecPtr()->GetNonBendingCoor();
667 pnbc2 = hit2->GetTrackParam()->GetNonBendingCoor();
04b5ea16 668 Chi2 = Chi2 +
eb9c9dab 669 ((*covBending)(hitNumber2, hitNumber1) *
670 (hbc1 - pbc1) * (hbc2 - pbc2)) +
04b5ea16 671 ((*covNonBending)(hitNumber2, hitNumber1) *
eb9c9dab 672 (hnbc1 - pnbc1) * (hnbc2 - pnbc2));
04b5ea16 673 }
674 }
eb9c9dab 675 } else {
676 // without Multiple Scattering if inversion impossible
677 for (hitNumber1 = 0; hitNumber1 < numberOfHit ; hitNumber1++) {
678 hit1 = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber1];
679 hbc1 = hit1->GetHitForRecPtr()->GetBendingCoor();
680 pbc1 = hit1->GetTrackParam()->GetBendingCoor();
681 hnbc1 = hit1->GetHitForRecPtr()->GetNonBendingCoor();
682 pnbc1 = hit1->GetTrackParam()->GetNonBendingCoor();
683 Chi2 = Chi2 +
684 ((hbc1 - pbc1) * (hbc1 - pbc1) /
685 hit1->GetHitForRecPtr()->GetBendingReso2()) +
686 ((hnbc1 - pnbc1) * (hnbc1 - pnbc1) /
687 hit1->GetHitForRecPtr()->GetNonBendingReso2());
04b5ea16 688 }
689 }
690
691 delete covBending;
692 delete covNonBending;
eb9c9dab 693 delete [] msa2;
04b5ea16 694}
695
696Double_t MultipleScatteringAngle2(AliMUONTrackHit *TrackHit)
697{
698 // Returns square of multiple Coulomb scattering angle
699 // at TrackHit pointed to by "TrackHit"
700 Double_t slopeBending, slopeNonBending, radiationLength, inverseBendingMomentum2, inverseTotalMomentum2;
701 Double_t varMultipleScatteringAngle;
956019b6 702 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) AliMUONTrack::Fitter()->GetObjectFit();
04b5ea16 703 AliMUONTrackParam *param = TrackHit->GetTrackParam();
956019b6 704 // Better implementation in AliMUONTrack class ????
04b5ea16 705 slopeBending = param->GetBendingSlope();
706 slopeNonBending = param->GetNonBendingSlope();
707 // thickness in radiation length for the current track,
708 // taking local angle into account
709 radiationLength =
710 trackBeingFitted->GetEventReconstructor()->GetChamberThicknessInX0() *
711 TMath::Sqrt(1.0 +
712 slopeBending * slopeBending + slopeNonBending * slopeNonBending);
713 inverseBendingMomentum2 =
714 param->GetInverseBendingMomentum() * param->GetInverseBendingMomentum();
715 inverseTotalMomentum2 =
956019b6 716 inverseBendingMomentum2 * (1.0 + slopeBending * slopeBending) /
04b5ea16 717 (1.0 + slopeBending *slopeBending + slopeNonBending * slopeNonBending);
718 varMultipleScatteringAngle = 0.0136 * (1.0 + 0.038 * TMath::Log(radiationLength));
956019b6 719 // The velocity is assumed to be 1 !!!!
04b5ea16 720 varMultipleScatteringAngle = inverseTotalMomentum2 * radiationLength *
721 varMultipleScatteringAngle * varMultipleScatteringAngle;
722 return varMultipleScatteringAngle;
723}
44f59652 724
725//______________________________________________________________________________
726 void mnvertLocal(Double_t *a, Int_t l, Int_t, Int_t n, Int_t &ifail)
727{
728//*-*-*-*-*-*-*-*-*-*-*-*Inverts a symmetric matrix*-*-*-*-*-*-*-*-*-*-*-*-*
729//*-* ==========================
730//*-* inverts a symmetric matrix. matrix is first scaled to
731//*-* have all ones on the diagonal (equivalent to change of units)
732//*-* but no pivoting is done since matrix is positive-definite.
733//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
734
735 // taken from TMinuit package of Root (l>=n)
736 // fVERTs, fVERTq and fVERTpp changed to localVERTs, localVERTq and localVERTpp
e804eb46 737 // Double_t localVERTs[n], localVERTq[n], localVERTpp[n];
738 Double_t * localVERTs = new Double_t[n];
739 Double_t * localVERTq = new Double_t[n];
740 Double_t * localVERTpp = new Double_t[n];
44f59652 741 // fMaxint changed to localMaxint
742 Int_t localMaxint = n;
743
744 /* System generated locals */
3831f268 745 Int_t aOffset;
44f59652 746
747 /* Local variables */
748 Double_t si;
749 Int_t i, j, k, kp1, km1;
750
751 /* Parameter adjustments */
3831f268 752 aOffset = l + 1;
753 a -= aOffset;
44f59652 754
755 /* Function Body */
756 ifail = 0;
757 if (n < 1) goto L100;
758 if (n > localMaxint) goto L100;
759//*-*- scale matrix by sqrt of diag elements
760 for (i = 1; i <= n; ++i) {
761 si = a[i + i*l];
762 if (si <= 0) goto L100;
763 localVERTs[i-1] = 1 / TMath::Sqrt(si);
764 }
765 for (i = 1; i <= n; ++i) {
766 for (j = 1; j <= n; ++j) {
767 a[i + j*l] = a[i + j*l]*localVERTs[i-1]*localVERTs[j-1];
768 }
769 }
770//*-*- . . . start main loop . . . .
771 for (i = 1; i <= n; ++i) {
772 k = i;
773//*-*- preparation for elimination step1
774 if (a[k + k*l] != 0) localVERTq[k-1] = 1 / a[k + k*l];
775 else goto L100;
776 localVERTpp[k-1] = 1;
777 a[k + k*l] = 0;
778 kp1 = k + 1;
779 km1 = k - 1;
780 if (km1 < 0) goto L100;
781 else if (km1 == 0) goto L50;
782 else goto L40;
783L40:
784 for (j = 1; j <= km1; ++j) {
785 localVERTpp[j-1] = a[j + k*l];
786 localVERTq[j-1] = a[j + k*l]*localVERTq[k-1];
787 a[j + k*l] = 0;
788 }
789L50:
790 if (k - n < 0) goto L51;
791 else if (k - n == 0) goto L60;
792 else goto L100;
793L51:
794 for (j = kp1; j <= n; ++j) {
795 localVERTpp[j-1] = a[k + j*l];
796 localVERTq[j-1] = -a[k + j*l]*localVERTq[k-1];
797 a[k + j*l] = 0;
798 }
799//*-*- elimination proper
800L60:
801 for (j = 1; j <= n; ++j) {
802 for (k = j; k <= n; ++k) { a[j + k*l] += localVERTpp[j-1]*localVERTq[k-1]; }
803 }
804 }
805//*-*- elements of left diagonal and unscaling
806 for (j = 1; j <= n; ++j) {
807 for (k = 1; k <= j; ++k) {
808 a[k + j*l] = a[k + j*l]*localVERTs[k-1]*localVERTs[j-1];
809 a[j + k*l] = a[k + j*l];
810 }
811 }
e804eb46 812 delete localVERTs;
813 delete localVERTq;
814 delete localVERTpp;
44f59652 815 return;
816//*-*- failure return
817L100:
e804eb46 818 delete localVERTs;
819 delete localVERTq;
820 delete localVERTpp;
44f59652 821 ifail = 1;
822} /* mnvertLocal */
823