]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrack.cxx
Switches for each station individually for debug and lego.
[u/mrichter/AliRoot.git] / MUON / AliMUONTrack.cxx
CommitLineData
a9e2aefa 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17$Log$
eb9c9dab 18Revision 1.6 2000/07/20 12:45:27 gosset
19New "EventReconstructor..." structure,
20 hopefully more adapted to tree/streamer.
21"AliMUONEventReconstructor::RemoveDoubleTracks"
22 to keep only one track among similar ones.
23
8429a5e4 24Revision 1.5 2000/07/18 16:04:06 gosset
25AliMUONEventReconstructor package:
26* a few minor modifications and more comments
27* a few corrections
28 * right sign for Z of raw clusters
29 * right loop over chambers inside station
30 * symmetrized covariance matrix for measurements (TrackChi2MCS)
31 * right sign of charge in extrapolation (ExtrapToZ)
32 * right zEndAbsorber for Branson correction below 3 degrees
33* use of TVirtualFitter instead of TMinuit for AliMUONTrack::Fit
34* no parameter for AliMUONTrack::Fit() but more fit parameters in Track object
35
956019b6 36Revision 1.4 2000/06/30 10:15:48 gosset
37Changes to EventReconstructor...:
38precision fit with multiple Coulomb scattering;
39extrapolation to vertex with Branson correction in absorber (JPC)
40
04b5ea16 41Revision 1.3 2000/06/25 13:23:28 hristov
42stdlib.h needed for non-Linux compilation
43
f6e92cf4 44Revision 1.2 2000/06/15 07:58:48 morsch
45Code from MUON-dev joined
46
a9e2aefa 47Revision 1.1.2.3 2000/06/12 10:11:34 morsch
48Dummy copy constructor and assignment operator added
49
50Revision 1.1.2.2 2000/06/09 12:58:05 gosset
51Removed comment beginnings in Log sections of .cxx files
52Suppressed most violations of coding rules
53
54Revision 1.1.2.1 2000/06/07 14:44:53 gosset
55Addition of files for track reconstruction in C++
56*/
57
58//__________________________________________________________________________
59//
60// Reconstructed track in ALICE dimuon spectrometer
61//__________________________________________________________________________
62
63#include "AliMUONTrack.h"
64
65#include <iostream.h>
66
67#include <TClonesArray.h>
04b5ea16 68#include <TMath.h>
69#include <TMatrix.h>
8429a5e4 70#include <TObjArray.h>
956019b6 71#include <TVirtualFitter.h>
a9e2aefa 72
73#include "AliMUONEventReconstructor.h"
74#include "AliMUONHitForRec.h"
75#include "AliMUONSegment.h"
76#include "AliMUONTrackHit.h"
77
f6e92cf4 78#include <stdlib.h>
79
04b5ea16 80// Functions to be minimized with Minuit
a9e2aefa 81void TrackChi2(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag);
04b5ea16 82void TrackChi2MCS(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag);
83
84Double_t MultipleScatteringAngle2(AliMUONTrackHit *TrackHit);
a9e2aefa 85
86ClassImp(AliMUONTrack) // Class implementation in ROOT context
87
956019b6 88TVirtualFitter* AliMUONTrack::fgFitter = NULL;
89
a9e2aefa 90 //__________________________________________________________________________
91AliMUONTrack::AliMUONTrack(AliMUONSegment* BegSegment, AliMUONSegment* EndSegment, AliMUONEventReconstructor* EventReconstructor)
92{
93 // Constructor from two Segment's
94 fEventReconstructor = EventReconstructor; // link back to EventReconstructor
8429a5e4 95 // memory allocation for the TObjArray of pointers to reconstructed TrackHit's
96 fTrackHitsPtr = new TObjArray(10);
a9e2aefa 97 fNTrackHits = 0;
98 AddSegment(BegSegment); // add hits from BegSegment
99 AddSegment(EndSegment); // add hits from EndSegment
100 fTrackHitsPtr->Sort(); // sort TrackHits according to increasing Z
101 SetTrackParamAtVertex(); // set track parameters at vertex
8429a5e4 102 // set fit conditions...
04b5ea16 103 fFitMCS = 0;
956019b6 104 fFitNParam = 3;
105 fFitStart = 1;
8429a5e4 106 fFitFMin = -1.0;
a9e2aefa 107 return;
108}
109
110 //__________________________________________________________________________
111AliMUONTrack::AliMUONTrack(AliMUONSegment* Segment, AliMUONHitForRec* HitForRec, AliMUONEventReconstructor* EventReconstructor)
112{
113 // Constructor from one Segment and one HitForRec
114 fEventReconstructor = EventReconstructor; // link back to EventReconstructor
8429a5e4 115 // memory allocation for the TObjArray of pointers to reconstructed TrackHit's
116 fTrackHitsPtr = new TObjArray(10);
a9e2aefa 117 fNTrackHits = 0;
118 AddSegment(Segment); // add hits from Segment
119 AddHitForRec(HitForRec); // add HitForRec
120 fTrackHitsPtr->Sort(); // sort TrackHits according to increasing Z
121 SetTrackParamAtVertex(); // set track parameters at vertex
8429a5e4 122 // set fit conditions...
04b5ea16 123 fFitMCS = 0;
956019b6 124 fFitNParam = 3;
125 fFitStart = 1;
8429a5e4 126 fFitFMin = -1.0;
a9e2aefa 127 return;
128}
129
8429a5e4 130 //__________________________________________________________________________
131AliMUONTrack::~AliMUONTrack()
132{
133 // Destructor
134 if (fTrackHitsPtr) {
135 delete fTrackHitsPtr; // delete the TObjArray of pointers to TrackHit's
136 fTrackHitsPtr = NULL;
137 }
138}
139
956019b6 140 //__________________________________________________________________________
a9e2aefa 141AliMUONTrack::AliMUONTrack (const AliMUONTrack& MUONTrack)
142{
143// Dummy copy constructor
144}
145
956019b6 146 //__________________________________________________________________________
a9e2aefa 147AliMUONTrack & AliMUONTrack::operator=(const AliMUONTrack& MUONTrack)
148{
149// Dummy assignment operator
150 return *this;
151}
152
8429a5e4 153 //__________________________________________________________________________
154void AliMUONTrack::Remove()
155{
156 // Remove current track from array of tracks,
157 // and corresponding track hits from array of track hits.
158 // Compress the TClonesArray it belongs to.
159 AliMUONTrackHit *nextTrackHit;
160 AliMUONEventReconstructor *eventRec = this->fEventReconstructor;
161 TClonesArray *trackHitsPtr = eventRec->GetRecTrackHitsPtr();
162 // Loop over all track hits of track
163 AliMUONTrackHit *trackHit = (AliMUONTrackHit*) fTrackHitsPtr->First();
164 while (trackHit) {
165 nextTrackHit = (AliMUONTrackHit*) fTrackHitsPtr->After(trackHit);
166 // Remove TrackHit from event TClonesArray.
167 // Destructor is called,
168 // hence links between HitForRec's and TrackHit's are updated
169 trackHitsPtr->Remove(trackHit);
170 trackHit = nextTrackHit;
171 }
172 // Remove the track from event TClonesArray
173 // Destructor is called,
174 // hence space for TObjArray of pointers to TrackHit's is freed
175 eventRec->GetRecTracksPtr()->Remove(this);
176 // Number of tracks decreased by 1
177 eventRec->SetNRecTracks(eventRec->GetNRecTracks() - 1);
178 // Compress event TClonesArray of Track's:
179 // this is essential to retrieve the TClonesArray afterwards
180 eventRec->GetRecTracksPtr()->Compress();
181 // Compress event TClonesArray of TrackHit's:
182 // this is probably also essential to retrieve the TClonesArray afterwards
183 trackHitsPtr->Compress();
184}
185
04b5ea16 186 //__________________________________________________________________________
187void AliMUONTrack::SetFitMCS(Int_t FitMCS)
188{
956019b6 189 // Set multiple Coulomb scattering option for track fit "fFitMCS"
04b5ea16 190 // from "FitMCS" argument: 0 without, 1 with
956019b6 191 if ((FitMCS == 0) || (FitMCS == 1)) fFitMCS = FitMCS;
04b5ea16 192 // better implementation with enum(with, without) ????
956019b6 193 else {
194 cout << "ERROR in AliMUONTrack::SetFitMCS(FitMCS)" << endl;
195 cout << "FitMCS = " << FitMCS << " is neither 0 nor 1" << endl;
196 exit(0);
197 }
198 return;
199}
200
201 //__________________________________________________________________________
202void AliMUONTrack::SetFitNParam(Int_t FitNParam)
203{
204 // Set number of parameters for track fit "fFitNParam" from "FitNParam":
205 // 3 for momentum, 5 for momentum and position
206 if ((FitNParam == 3) || (FitNParam == 5)) fFitNParam = FitNParam;
207 else {
208 cout << "ERROR in AliMUONTrack::SetFitNParam(FitNParam)" << endl;
209 cout << "FitNParam = " << FitNParam << " is neither 3 nor 5" << endl;
210 exit(0);
211 }
212 return;
213}
214
215 //__________________________________________________________________________
216void AliMUONTrack::SetFitStart(Int_t FitStart)
217{
218 // Set multiple Coulomb scattering option for track fit "fFitStart"
219 // from "FitStart" argument: 0 without, 1 with
220 if ((FitStart == 0) || (FitStart == 1)) fFitStart = FitStart;
221 // better implementation with enum(vertex, firstHit) ????
222 else {
223 cout << "ERROR in AliMUONTrack::SetFitStart(FitStart)" << endl;
224 cout << "FitStart = " << FitStart << " is neither 0 nor 1" << endl;
225 exit(0);
226 }
04b5ea16 227 return;
228}
229
956019b6 230 //__________________________________________________________________________
a9e2aefa 231AliMUONTrackParam* AliMUONTrack::GetTrackParamAtFirstHit(void) {
232 // Get pointer to TrackParamAtFirstHit
233 return ((AliMUONTrackHit*) (fTrackHitsPtr->First()))->GetTrackParam();}
a9e2aefa 234
235 //__________________________________________________________________________
236void AliMUONTrack::RecursiveDump(void)
237{
238 // Recursive dump of AliMUONTrack, i.e. with dump of TrackHit's and HitForRec's
239 AliMUONTrackHit *trackHit;
240 AliMUONHitForRec *hitForRec;
241 cout << "Recursive dump of Track: " << this << endl;
242 // Track
243 this->Dump();
244 for (Int_t trackHitIndex = 0; trackHitIndex < fNTrackHits; trackHitIndex++) {
245 trackHit = (AliMUONTrackHit*) ((*fTrackHitsPtr)[trackHitIndex]);
246 // TrackHit
247 cout << "TrackHit: " << trackHit << " (index: " << trackHitIndex << ")" << endl;
248 trackHit->Dump();
249 hitForRec = trackHit->GetHitForRecPtr();
250 // HitForRec
251 cout << "HitForRec: " << hitForRec << endl;
252 hitForRec->Dump();
253 }
254 return;
255}
256
8429a5e4 257 //__________________________________________________________________________
258Int_t AliMUONTrack::HitsInCommon(AliMUONTrack* Track)
259{
260 // Returns the number of hits in common
261 // between the current track ("this")
262 // and the track pointed to by "Track".
263 Int_t hitsInCommon = 0;
264 AliMUONTrackHit *trackHit1, *trackHit2;
265 // Loop over hits of first track
266 trackHit1 = (AliMUONTrackHit*) this->GetTrackHitsPtr()->First();
267 while (trackHit1) {
268 // Loop over hits of second track
269 trackHit2 = (AliMUONTrackHit*) Track->GetTrackHitsPtr()->First();
270 while (trackHit2) {
271 // Increment "hitsInCommon" if both TrackHits point to the same HitForRec
272 if ( (trackHit1->GetHitForRecPtr()) ==
273 (trackHit2->GetHitForRecPtr()) ) hitsInCommon++;
274 trackHit2 = (AliMUONTrackHit*) Track->GetTrackHitsPtr()->After(trackHit2);
275 } // trackHit2
276 trackHit1 = (AliMUONTrackHit*) this->GetTrackHitsPtr()->After(trackHit1);
277 } // trackHit1
278 return hitsInCommon;
279}
280
a9e2aefa 281 //__________________________________________________________________________
956019b6 282void AliMUONTrack::Fit()
a9e2aefa 283{
284 // Fit the current track ("this"),
956019b6 285 // with or without multiple Coulomb scattering according to "fFitMCS",
286 // with the number of parameters given by "fFitNParam"
287 // (3 if one keeps X and Y fixed in "TrackParam", 5 if one lets them vary),
288 // starting, according to "fFitStart",
289 // with track parameters at vertex or at the first TrackHit.
290 // "fFitMCS", "fFitNParam" and "fFitStart" have to be set before
291 // by calling the corresponding Set methods.
a9e2aefa 292 Double_t arg[1], benC, errorParam, invBenP, lower, nonBenC, upper, x, y;
956019b6 293 char parName[50];
294 AliMUONTrackParam *trackParam;
295 // Check if Minuit is initialized...
296 fgFitter = TVirtualFitter::Fitter(this); // add 3 or 5 for the maximum number of parameters ???
297 fgFitter->Clear(); // necessary ???? probably yes
298 // how to reset the printout number at every fit ????
299 // is there any risk to leave it like that ????
a9e2aefa 300 // how to go faster ???? choice of Minuit parameters like EDM ????
04b5ea16 301 // choice of function to be minimized according to fFitMCS
956019b6 302 if (fFitMCS == 0) fgFitter->SetFCN(TrackChi2);
303 else fgFitter->SetFCN(TrackChi2MCS);
304 arg[0] = 1;
305 fgFitter->ExecuteCommand("SET PRINT", arg, 1); // More printing !!!!
306 // Parameters according to "fFitStart"
307 // (should be a function to be used at every place where needed ????)
308 if (fFitStart == 0) trackParam = &fTrackParamAtVertex;
309 else trackParam = this->GetTrackParamAtFirstHit();
310 // set first 3 Minuit parameters
04b5ea16 311 // could be tried with no limits for the search (min=max=0) ????
956019b6 312 fgFitter->SetParameter(0, "InvBenP",
313 trackParam->GetInverseBendingMomentum(),
314 0.003, -0.4, 0.4);
315 fgFitter->SetParameter(1, "BenS",
316 trackParam->GetBendingSlope(),
317 0.001, -0.5, 0.5);
318 fgFitter->SetParameter(2, "NonBenS",
319 trackParam->GetNonBendingSlope(),
320 0.001, -0.5, 0.5);
321 if (fFitNParam == 5) {
322 // set last 2 Minuit parameters (no limits for the search: min=max=0)
323 fgFitter->SetParameter(3, "X",
324 trackParam->GetNonBendingCoor(),
325 0.03, 0.0, 0.0);
326 fgFitter->SetParameter(4, "Y",
327 trackParam->GetBendingCoor(),
328 0.10, 0.0, 0.0);
a9e2aefa 329 }
330 // search without gradient calculation in the function
956019b6 331 fgFitter->ExecuteCommand("SET NOGRADIENT", arg, 0);
a9e2aefa 332 // minimization
956019b6 333 fgFitter->ExecuteCommand("MINIMIZE", arg, 0);
a9e2aefa 334 // exit from Minuit
956019b6 335 fgFitter->ExecuteCommand("EXIT", arg, 0); // necessary ????
336 // get results into "invBenP", "benC", "nonBenC" ("x", "y")
337 fgFitter->GetParameter(0, parName, invBenP, errorParam, lower, upper);
338 fgFitter->GetParameter(1, parName, benC, errorParam, lower, upper);
339 fgFitter->GetParameter(2, parName, nonBenC, errorParam, lower, upper);
340 if (fFitNParam == 5) {
341 fgFitter->GetParameter(3, parName, x, errorParam, lower, upper);
342 fgFitter->GetParameter(4, parName, y, errorParam, lower, upper);
a9e2aefa 343 }
344 // result of the fit into track parameters
956019b6 345 trackParam->SetInverseBendingMomentum(invBenP);
346 trackParam->SetBendingSlope(benC);
347 trackParam->SetNonBendingSlope(nonBenC);
348 if (fFitNParam == 5) {
349 trackParam->SetNonBendingCoor(x);
350 trackParam->SetBendingCoor(y);
a9e2aefa 351 }
8429a5e4 352 // global result of the fit
353 Double_t fedm, errdef;
354 Int_t npari, nparx;
355 fgFitter->GetStats(fFitFMin, fedm, errdef, npari, nparx);
a9e2aefa 356}
357
358 //__________________________________________________________________________
359void AliMUONTrack::AddSegment(AliMUONSegment* Segment)
360{
8429a5e4 361 // Add Segment to the track
a9e2aefa 362 AddHitForRec(Segment->GetHitForRec1()); // 1st hit
363 AddHitForRec(Segment->GetHitForRec2()); // 2nd hit
364}
365
366 //__________________________________________________________________________
367void AliMUONTrack::AddHitForRec(AliMUONHitForRec* HitForRec)
368{
8429a5e4 369 // Add HitForRec to the track:
370 // actual TrackHit into TClonesArray of TrackHit's for the event;
371 // pointer to actual TrackHit in TObjArray of pointers to TrackHit's for the track
372 TClonesArray *recTrackHitsPtr = this->fEventReconstructor->GetRecTrackHitsPtr();
373 Int_t eventTrackHits = this->fEventReconstructor->GetNRecTrackHits();
374 // event
375 AliMUONTrackHit* trackHit =
376 new ((*recTrackHitsPtr)[eventTrackHits]) AliMUONTrackHit(HitForRec);
377 this->fEventReconstructor->SetNRecTrackHits(eventTrackHits + 1);
378 // track
379 fTrackHitsPtr->Add(trackHit);
a9e2aefa 380 fNTrackHits++;
381}
382
383 //__________________________________________________________________________
384void AliMUONTrack::SetTrackParamAtHit(Int_t indexHit, AliMUONTrackParam *TrackParam)
385{
386 // Set track parameters at TrackHit with index "indexHit"
387 // from the track parameters pointed to by "TrackParam".
388 AliMUONTrackHit* trackHit = (AliMUONTrackHit*) ((*fTrackHitsPtr)[indexHit]);
389 trackHit->SetTrackParam(TrackParam);
390}
391
392 //__________________________________________________________________________
393void AliMUONTrack::SetTrackParamAtVertex()
394{
395 // Set track parameters at vertex.
396 // TrackHit's are assumed to be only in stations(1..) 4 and 5,
397 // and sorted according to increasing Z..
398 // Parameters are calculated from information in HitForRec's
399 // of first and last TrackHit's.
400 AliMUONTrackParam *trackParam =
401 &fTrackParamAtVertex; // pointer to track parameters
402 // Pointer to HitForRec of first TrackHit
403 AliMUONHitForRec *firstHit =
404 ((AliMUONTrackHit*) (fTrackHitsPtr->First()))->GetHitForRecPtr();
405 // Pointer to HitForRec of last TrackHit
406 AliMUONHitForRec *lastHit =
407 ((AliMUONTrackHit*) (fTrackHitsPtr->Last()))->GetHitForRecPtr();
408 // Z difference between first and last hits
409 Double_t deltaZ = firstHit->GetZ() - lastHit->GetZ();
410 // bending slope in stations(1..) 4 and 5
411 Double_t bendingSlope =
412 (firstHit->GetBendingCoor() - lastHit->GetBendingCoor()) / deltaZ;
413 trackParam->SetBendingSlope(bendingSlope);
414 // impact parameter
415 Double_t impactParam =
416 firstHit->GetBendingCoor() - bendingSlope * firstHit->GetZ(); // same if from firstHit and lastHit ????
417 // signed bending momentum
418 Double_t signedBendingMomentum =
419 fEventReconstructor->GetBendingMomentumFromImpactParam(impactParam);
420 trackParam->SetInverseBendingMomentum(1.0 / signedBendingMomentum);
421 // bending slope at vertex
422 trackParam->
423 SetBendingSlope(bendingSlope +
424 impactParam / fEventReconstructor->GetSimpleBPosition());
425 // non bending slope
426 Double_t nonBendingSlope =
427 (firstHit->GetNonBendingCoor() - lastHit->GetNonBendingCoor()) / deltaZ;
428 trackParam->SetNonBendingSlope(nonBendingSlope);
429 // vertex coordinates at (0,0,0)
430 trackParam->SetZ(0.0);
431 trackParam->SetBendingCoor(0.0);
432 trackParam->SetNonBendingCoor(0.0);
433}
434
435 //__________________________________________________________________________
436void TrackChi2(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag)
437{
438 // Return the "Chi2" to be minimized with Minuit for track fitting,
439 // with "NParam" parameters
440 // and their current values in array pointed to by "Param".
441 // Assumes that the track hits are sorted according to increasing Z.
442 // Track parameters at each TrackHit are updated accordingly.
04b5ea16 443 // Multiple Coulomb scattering is not taken into account
956019b6 444 AliMUONTrack *trackBeingFitted;
a9e2aefa 445 AliMUONTrackHit* hit;
446 AliMUONTrackParam param1;
447 Int_t hitNumber;
448 Double_t zHit;
449 Chi2 = 0.0; // initialize Chi2
450 // copy of track parameters to be fitted
956019b6 451 trackBeingFitted = (AliMUONTrack*) AliMUONTrack::Fitter()->GetObjectFit();
452 if (trackBeingFitted->GetFitStart() == 0)
453 param1 = *(trackBeingFitted->GetTrackParamAtVertex());
454 else param1 = *(trackBeingFitted->GetTrackParamAtFirstHit());
a9e2aefa 455 // Minuit parameters to be fitted into this copy
456 param1.SetInverseBendingMomentum(Param[0]);
457 param1.SetBendingSlope(Param[1]);
458 param1.SetNonBendingSlope(Param[2]);
459 if (NParam == 5) {
460 param1.SetNonBendingCoor(Param[3]);
461 param1.SetBendingCoor(Param[4]);
462 }
463 // Follow track through all planes of track hits
464 for (hitNumber = 0; hitNumber < trackBeingFitted->GetNTrackHits(); hitNumber++) {
465 hit = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber];
466 zHit = hit->GetHitForRecPtr()->GetZ();
467 // do something special if 2 hits with same Z ????
468 // security against infinite loop ????
469 (&param1)->ExtrapToZ(zHit); // extrapolation
470 hit->SetTrackParam(&param1);
471 // Increment Chi2
472 // done hit per hit, with hit resolution,
473 // and not with point and angle like in "reco_muon.F" !!!!
474 // Needs to add multiple scattering contribution ????
475 Double_t dX =
476 hit->GetHitForRecPtr()->GetNonBendingCoor() - (&param1)->GetNonBendingCoor();
477 Double_t dY =
478 hit->GetHitForRecPtr()->GetBendingCoor() - (&param1)->GetBendingCoor();
479 Chi2 =
480 Chi2 +
481 dX * dX / hit->GetHitForRecPtr()->GetNonBendingReso2() +
482 dY * dY / hit->GetHitForRecPtr()->GetBendingReso2();
483 }
484}
04b5ea16 485
486 //__________________________________________________________________________
487void TrackChi2MCS(Int_t &NParam, Double_t *Gradient, Double_t &Chi2, Double_t *Param, Int_t Flag)
488{
489 // Return the "Chi2" to be minimized with Minuit for track fitting,
490 // with "NParam" parameters
491 // and their current values in array pointed to by "Param".
492 // Assumes that the track hits are sorted according to increasing Z.
493 // Track parameters at each TrackHit are updated accordingly.
494 // Multiple Coulomb scattering is taken into account with covariance matrix.
956019b6 495 AliMUONTrack *trackBeingFitted;
04b5ea16 496 AliMUONTrackParam param1;
497 Chi2 = 0.0; // initialize Chi2
498 // copy of track parameters to be fitted
956019b6 499 trackBeingFitted = (AliMUONTrack*) AliMUONTrack::Fitter()->GetObjectFit();
500 if (trackBeingFitted->GetFitStart() == 0)
501 param1 = *(trackBeingFitted->GetTrackParamAtVertex());
502 else param1 = *(trackBeingFitted->GetTrackParamAtFirstHit());
04b5ea16 503 // Minuit parameters to be fitted into this copy
504 param1.SetInverseBendingMomentum(Param[0]);
505 param1.SetBendingSlope(Param[1]);
506 param1.SetNonBendingSlope(Param[2]);
507 if (NParam == 5) {
508 param1.SetNonBendingCoor(Param[3]);
509 param1.SetBendingCoor(Param[4]);
510 }
511
956019b6 512 AliMUONTrackHit *hit;
513 Bool_t goodDeterminant;
eb9c9dab 514 Int_t chCurrent, chPrev, hitNumber, hitNumber1, hitNumber2, hitNumber3;
515 Double_t z, z1, z2, z3;
516 AliMUONTrackHit *hit1, *hit2, *hit3;
517 Double_t hbc1, hbc2, pbc1, pbc2;
518 Double_t hnbc1, hnbc2, pnbc1, pnbc2;
519 Int_t numberOfHit = trackBeingFitted->GetNTrackHits();
04b5ea16 520 TMatrix *covBending = new TMatrix(numberOfHit, numberOfHit);
521 TMatrix *covNonBending = new TMatrix(numberOfHit, numberOfHit);
eb9c9dab 522 Double_t *msa2 = new Double_t[numberOfHit];
04b5ea16 523
524 // Predicted coordinates and multiple scattering angles are first calculated
525 for (hitNumber = 0; hitNumber < numberOfHit; hitNumber++) {
526 hit = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber];
eb9c9dab 527 z = hit->GetHitForRecPtr()->GetZ();
04b5ea16 528 // do something special if 2 hits with same Z ????
529 // security against infinite loop ????
eb9c9dab 530 (&param1)->ExtrapToZ(z); // extrapolation
04b5ea16 531 hit->SetTrackParam(&param1);
eb9c9dab 532 // square of multiple scattering angle at current hit, with one chamber
533 msa2[hitNumber] = MultipleScatteringAngle2(hit);
534 // correction for eventual missing hits or multiple hits in a chamber,
535 // according to the number of chambers
536 // between the current hit and the previous one
537 chCurrent = hit->GetHitForRecPtr()->GetChamberNumber();
538 if (hitNumber > 0) msa2[hitNumber] = msa2[hitNumber] * (chCurrent - chPrev);
539 chPrev = chCurrent;
04b5ea16 540 }
541
542 // Calculates the covariance matrix
eb9c9dab 543 for (hitNumber1 = 0; hitNumber1 < numberOfHit; hitNumber1++) {
544 hit1 = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber1];
545 z1 = hit1->GetHitForRecPtr()->GetZ();
04b5ea16 546 for (hitNumber2 = hitNumber1; hitNumber2 < numberOfHit; hitNumber2++) {
eb9c9dab 547 hit2 = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber2];
548 z2 = hit2->GetHitForRecPtr()->GetZ();
956019b6 549 // initialization to 0 (diagonal plus upper triangular part)
550 (*covBending)(hitNumber2, hitNumber1) = 0.0;
551 // contribution from multiple scattering in bending plane:
552 // loop over upstream hits
553 for (hitNumber3 = 0; hitNumber3 < hitNumber1; hitNumber3++) {
eb9c9dab 554 hit3 = (AliMUONTrackHit*)
555 (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber3];
556 z3 = hit3->GetHitForRecPtr()->GetZ();
04b5ea16 557 (*covBending)(hitNumber2, hitNumber1) =
558 (*covBending)(hitNumber2, hitNumber1) +
eb9c9dab 559 ((z1 - z3) * (z2 - z3) * msa2[hitNumber3]);
956019b6 560 }
561 // equal contribution from multiple scattering in non bending plane
04b5ea16 562 (*covNonBending)(hitNumber2, hitNumber1) =
563 (*covBending)(hitNumber2, hitNumber1);
956019b6 564 if (hitNumber1 == hitNumber2) {
565 // Diagonal elements: add contribution from position measurements
566 // in bending plane
567 (*covBending)(hitNumber2, hitNumber1) =
eb9c9dab 568 (*covBending)(hitNumber2, hitNumber1) +
569 hit1->GetHitForRecPtr()->GetBendingReso2();
956019b6 570 // and in non bending plane
04b5ea16 571 (*covNonBending)(hitNumber2, hitNumber1) =
eb9c9dab 572 (*covNonBending)(hitNumber2, hitNumber1) +
573 hit1->GetHitForRecPtr()->GetNonBendingReso2();
956019b6 574 }
575 else {
576 // Non diagonal elements: symmetrization
577 // for bending plane
578 (*covBending)(hitNumber1, hitNumber2) =
579 (*covBending)(hitNumber2, hitNumber1);
580 // and non bending plane
581 (*covNonBending)(hitNumber1, hitNumber2) =
582 (*covNonBending)(hitNumber2, hitNumber1);
583 }
584 } // for (hitNumber2 = hitNumber1;...
585 } // for (hitNumber1 = 0;...
04b5ea16 586
587 // Inverts covariance matrix
956019b6 588 goodDeterminant = kTRUE;
589 // check whether the Invert method returns flag if matrix cannot be inverted,
590 // and do not calculate the Determinant in that case !!!!
04b5ea16 591 if (covBending->Determinant() != 0) {
592 covBending->Invert();
593 } else {
956019b6 594 goodDeterminant = kFALSE;
04b5ea16 595 cout << "Warning in ChiMCS Determinant Bending=0: " << endl;
596 }
956019b6 597 if (covNonBending->Determinant() != 0) {
04b5ea16 598 covNonBending->Invert();
599 } else {
956019b6 600 goodDeterminant = kFALSE;
04b5ea16 601 cout << "Warning in ChiMCS Determinant non Bending=0: " << endl;
602 }
956019b6 603
604 // It would be worth trying to calculate the inverse of the covariance matrix
605 // only once per fit, since it cannot change much in principle,
606 // and it would save a lot of computing time !!!!
04b5ea16 607
608 // Calculates Chi2
eb9c9dab 609 if (goodDeterminant) {
610 // with Multiple Scattering if inversion correct
611 for (hitNumber1 = 0; hitNumber1 < numberOfHit ; hitNumber1++) {
612 hit1 = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber1];
613 hbc1 = hit1->GetHitForRecPtr()->GetBendingCoor();
614 pbc1 = hit1->GetTrackParam()->GetBendingCoor();
615 hnbc1 = hit1->GetHitForRecPtr()->GetNonBendingCoor();
616 pnbc1 = hit1->GetTrackParam()->GetNonBendingCoor();
617 for (hitNumber2 = 0; hitNumber2 < numberOfHit; hitNumber2++) {
618 hit2 = (AliMUONTrackHit*)
619 (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber2];
620 hbc2 = hit2->GetHitForRecPtr()->GetBendingCoor();
621 pbc2 = hit2->GetTrackParam()->GetBendingCoor();
622 hnbc2 = hit2->GetHitForRecPtr()->GetNonBendingCoor();
623 pnbc2 = hit2->GetTrackParam()->GetNonBendingCoor();
04b5ea16 624 Chi2 = Chi2 +
eb9c9dab 625 ((*covBending)(hitNumber2, hitNumber1) *
626 (hbc1 - pbc1) * (hbc2 - pbc2)) +
04b5ea16 627 ((*covNonBending)(hitNumber2, hitNumber1) *
eb9c9dab 628 (hnbc1 - pnbc1) * (hnbc2 - pnbc2));
04b5ea16 629 }
630 }
eb9c9dab 631 } else {
632 // without Multiple Scattering if inversion impossible
633 for (hitNumber1 = 0; hitNumber1 < numberOfHit ; hitNumber1++) {
634 hit1 = (AliMUONTrackHit*) (*(trackBeingFitted->GetTrackHitsPtr()))[hitNumber1];
635 hbc1 = hit1->GetHitForRecPtr()->GetBendingCoor();
636 pbc1 = hit1->GetTrackParam()->GetBendingCoor();
637 hnbc1 = hit1->GetHitForRecPtr()->GetNonBendingCoor();
638 pnbc1 = hit1->GetTrackParam()->GetNonBendingCoor();
639 Chi2 = Chi2 +
640 ((hbc1 - pbc1) * (hbc1 - pbc1) /
641 hit1->GetHitForRecPtr()->GetBendingReso2()) +
642 ((hnbc1 - pnbc1) * (hnbc1 - pnbc1) /
643 hit1->GetHitForRecPtr()->GetNonBendingReso2());
04b5ea16 644 }
645 }
646
647 delete covBending;
648 delete covNonBending;
eb9c9dab 649 delete [] msa2;
04b5ea16 650}
651
652Double_t MultipleScatteringAngle2(AliMUONTrackHit *TrackHit)
653{
654 // Returns square of multiple Coulomb scattering angle
655 // at TrackHit pointed to by "TrackHit"
656 Double_t slopeBending, slopeNonBending, radiationLength, inverseBendingMomentum2, inverseTotalMomentum2;
657 Double_t varMultipleScatteringAngle;
956019b6 658 AliMUONTrack *trackBeingFitted = (AliMUONTrack*) AliMUONTrack::Fitter()->GetObjectFit();
04b5ea16 659 AliMUONTrackParam *param = TrackHit->GetTrackParam();
956019b6 660 // Better implementation in AliMUONTrack class ????
04b5ea16 661 slopeBending = param->GetBendingSlope();
662 slopeNonBending = param->GetNonBendingSlope();
663 // thickness in radiation length for the current track,
664 // taking local angle into account
665 radiationLength =
666 trackBeingFitted->GetEventReconstructor()->GetChamberThicknessInX0() *
667 TMath::Sqrt(1.0 +
668 slopeBending * slopeBending + slopeNonBending * slopeNonBending);
669 inverseBendingMomentum2 =
670 param->GetInverseBendingMomentum() * param->GetInverseBendingMomentum();
671 inverseTotalMomentum2 =
956019b6 672 inverseBendingMomentum2 * (1.0 + slopeBending * slopeBending) /
04b5ea16 673 (1.0 + slopeBending *slopeBending + slopeNonBending * slopeNonBending);
674 varMultipleScatteringAngle = 0.0136 * (1.0 + 0.038 * TMath::Log(radiationLength));
956019b6 675 // The velocity is assumed to be 1 !!!!
04b5ea16 676 varMultipleScatteringAngle = inverseTotalMomentum2 * radiationLength *
677 varMultipleScatteringAngle * varMultipleScatteringAngle;
678 return varMultipleScatteringAngle;
679}