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