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