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