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