]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONEventReconstructor.cxx
Bugfix in AliPoints2Memory
[u/mrichter/AliRoot.git] / MUON / AliMUONEventReconstructor.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$
31817925 18Revision 1.28 2001/08/31 06:50:11 gosset
19Different handling of TreeR for track reconstruction from raw clusters
20
f69d51b5 21Revision 1.27 2001/07/27 13:03:12 hristov
22Default Branch split level set to 99
23
d0f40f23 24Revision 1.26 2001/05/03 08:11:31 hristov
25stdlib.h included to define exit()
26
82a4bc7b 27Revision 1.25 2001/04/25 14:50:42 gosset
28Corrections to violations of coding conventions
29
3831f268 30Revision 1.24 2001/03/30 09:37:58 gosset
31Initialisations of pointers... for GEANT background events in the constructor
32
47a6b602 33Revision 1.23 2001/01/26 21:44:45 morsch
34Use access functions to AliMUONDigit, ... member data.
35
0a5f36d9 36Revision 1.22 2001/01/26 20:00:53 hristov
37Major upgrade of AliRoot code
3f5cf0b3 38Revision 1.20 2001/01/08 11:01:02 gosset
39Modifications used for addendum to Dimuon TDR (JP Cussonneau):
40*. MaxBendingMomentum to make both a segment and a track (default 500)
41*. MaxChi2 per degree of freedom to make a track (default 100)
42*. MinBendingMomentum used also to make a track
43 and not only a segment (default 3)
44*. wider roads for track search in stations 1 to 3
45*. extrapolation to actual Z instead of Z(chamber) in FollowTracks
46*. in track fit:
47 - limits on parameters X and Y (+/-500)
48 - covariance matrices in double precision
49 - normalization of covariance matrices before inversion
50 - suppression of Minuit printouts
51*. correction against memory leak (delete extrapHit) in FollowTracks
52*. RMax to 10 degrees with Z(chamber) instead of fixed values;
53 RMin and Rmax cuts suppressed in NewHitForRecFromGEANT,
54 because useless with realistic geometry
55
d0bfce8d 56Revision 1.19 2000/11/20 11:24:10 gosset
57New package for reconstructed tracks (A. Gheata):
58* tree output in the file "tree_reco.root"
59* display events and make histograms from this file
60
c7ba256d 61Revision 1.18 2000/10/26 12:47:03 gosset
62Real distance between chambers of each station taken into account
63for the reconstruction parameters "fSegmentMaxDistBending[5]"
64
860cef81 65Revision 1.17 2000/10/24 09:26:20 gosset
66Comments updated
67
ba5b68db 68Revision 1.16 2000/10/24 09:22:35 gosset
69Method AddHitsForRecFromRawClusters: real Z of raw cluster and not Z of chamber
70
cfe0107f 71Revision 1.15 2000/10/12 15:17:30 gosset
72Sign of fSimpleBValue corrected: sign ox Bx and not Bz (thanks to Galina)
73
065bd0e1 74Revision 1.14 2000/10/04 18:21:26 morsch
75Include stdlib.h
76
e7d455d5 77Revision 1.13 2000/10/02 21:28:09 fca
78Removal of useless dependecies via forward declarations
79
94de3818 80Revision 1.12 2000/10/02 16:58:29 egangler
81Cleaning of the code :
82-> coding conventions
83-> void Streamers
84-> some useless includes removed or replaced by "class" statement
85
ecfa008b 86Revision 1.11 2000/09/22 09:16:33 hristov
87Casting needed on DEC
88
8832c7b4 89Revision 1.10 2000/09/19 09:49:50 gosset
90AliMUONEventReconstructor package
91* track extrapolation independent from reco_muon.F, use of AliMagF...
92* possibility to use new magnetic field (automatic from generated root file)
93
a6f03ddb 94Revision 1.9 2000/07/20 12:45:27 gosset
95New "EventReconstructor..." structure,
96 hopefully more adapted to tree/streamer.
97"AliMUONEventReconstructor::RemoveDoubleTracks"
98 to keep only one track among similar ones.
99
8429a5e4 100Revision 1.8 2000/07/18 16:04:06 gosset
101AliMUONEventReconstructor package:
102* a few minor modifications and more comments
103* a few corrections
104 * right sign for Z of raw clusters
105 * right loop over chambers inside station
106 * symmetrized covariance matrix for measurements (TrackChi2MCS)
107 * right sign of charge in extrapolation (ExtrapToZ)
108 * right zEndAbsorber for Branson correction below 3 degrees
109* use of TVirtualFitter instead of TMinuit for AliMUONTrack::Fit
110* no parameter for AliMUONTrack::Fit() but more fit parameters in Track object
111
956019b6 112Revision 1.7 2000/07/03 12:28:06 gosset
113Printout at the right place after extrapolation to vertex
114
6ae236ee 115Revision 1.6 2000/06/30 12:01:06 gosset
116Correction for hit search in the right chamber (JPC)
117
d82671a0 118Revision 1.5 2000/06/30 10:15:48 gosset
119Changes to EventReconstructor...:
120precision fit with multiple Coulomb scattering;
121extrapolation to vertex with Branson correction in absorber (JPC)
122
04b5ea16 123Revision 1.4 2000/06/27 14:11:36 gosset
124Corrections against violations of coding conventions
125
9cbdf048 126Revision 1.3 2000/06/16 07:27:08 gosset
127To remove problem in running RuleChecker, like in MUON-dev
128
79e1e601 129Revision 1.1.2.5 2000/06/16 07:00:26 gosset
130To remove problem in running RuleChecker
131
a9e2aefa 132Revision 1.1.2.4 2000/06/12 08:00:07 morsch
133Dummy streamer to solve CINT compilation problem (to be investigated !)
134
135Revision 1.1.2.3 2000/06/09 20:59:57 morsch
136Make includes consistent with new file structure.
137
138Revision 1.1.2.2 2000/06/09 12:58:05 gosset
139Removed comment beginnings in Log sections of .cxx files
140Suppressed most violations of coding rules
141
142Revision 1.1.2.1 2000/06/07 14:44:53 gosset
143Addition of files for track reconstruction in C++
144*/
145
3831f268 146////////////////////////////////////
a9e2aefa 147//
148// MUON event reconstructor in ALICE
149//
150// This class contains as data:
151// * the parameters for the event reconstruction
152// * a pointer to the array of hits to be reconstructed (the event)
153// * a pointer to the array of segments made with these hits inside each station
154// * a pointer to the array of reconstructed tracks
155//
156// It contains as methods, among others:
157// * MakeEventToBeReconstructed to build the array of hits to be reconstructed
158// * MakeSegments to build the segments
159// * MakeTracks to build the tracks
3831f268 160//
161////////////////////////////////////
a9e2aefa 162
3831f268 163#include <iostream.h> // for cout
82a4bc7b 164#include <stdlib.h> // for exit()
a9e2aefa 165
94de3818 166#include <TTree.h>
a9e2aefa 167
a9e2aefa 168#include "AliMUON.h"
3831f268 169#include "AliMUONChamber.h"
170#include "AliMUONEventReconstructor.h"
a9e2aefa 171#include "AliMUONHitForRec.h"
a9e2aefa 172#include "AliMUONRawCluster.h"
3831f268 173#include "AliMUONRecoEvent.h"
174#include "AliMUONSegment.h"
a9e2aefa 175#include "AliMUONTrack.h"
a9e2aefa 176#include "AliMUONTrackHit.h"
94de3818 177#include "AliMagF.h"
3831f268 178#include "AliRun.h" // for gAlice
a9e2aefa 179
a9e2aefa 180//************* Defaults parameters for reconstruction
9cbdf048 181static const Double_t kDefaultMinBendingMomentum = 3.0;
d0bfce8d 182static const Double_t kDefaultMaxBendingMomentum = 500.0;
183static const Double_t kDefaultMaxChi2 = 100.0;
9cbdf048 184static const Double_t kDefaultMaxSigma2Distance = 16.0;
185static const Double_t kDefaultBendingResolution = 0.01;
186static const Double_t kDefaultNonBendingResolution = 0.144;
187static const Double_t kDefaultChamberThicknessInX0 = 0.03;
a9e2aefa 188// Simple magnetic field:
189// Value taken from macro MUONtracking.C: 0.7 T, hence 7 kG
190// Length and Position from reco_muon.F, with opposite sign:
191// Length = ZMAGEND-ZCOIL
192// Position = (ZMAGEND+ZCOIL)/2
193// to be ajusted differently from real magnetic field ????
9cbdf048 194static const Double_t kDefaultSimpleBValue = 7.0;
195static const Double_t kDefaultSimpleBLength = 428.0;
196static const Double_t kDefaultSimpleBPosition = 1019.0;
197static const Int_t kDefaultRecGeantHits = 0;
198static const Double_t kDefaultEfficiency = 0.95;
a9e2aefa 199
9cbdf048 200static const Int_t kDefaultPrintLevel = 0;
a9e2aefa 201
202ClassImp(AliMUONEventReconstructor) // Class implementation in ROOT context
203
204 //__________________________________________________________________________
205AliMUONEventReconstructor::AliMUONEventReconstructor(void)
206{
207 // Constructor for class AliMUONEventReconstructor
208 SetReconstructionParametersToDefaults();
209 // Memory allocation for the TClonesArray of hits for reconstruction
210 // Is 10000 the right size ????
211 fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
212 fNHitsForRec = 0; // really needed or GetEntriesFast sufficient ????
213 // Memory allocation for the TClonesArray's of segments in stations
214 // Is 2000 the right size ????
9cbdf048 215 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++) {
a9e2aefa 216 fSegmentsPtr[st] = new TClonesArray("AliMUONSegment", 2000);
217 fNSegments[st] = 0; // really needed or GetEntriesFast sufficient ????
218 }
219 // Memory allocation for the TClonesArray of reconstructed tracks
220 // Is 10 the right size ????
221 fRecTracksPtr = new TClonesArray("AliMUONTrack", 10);
222 fNRecTracks = 0; // really needed or GetEntriesFast sufficient ????
8429a5e4 223 // Memory allocation for the TClonesArray of hits on reconstructed tracks
224 // Is 100 the right size ????
225 fRecTrackHitsPtr = new TClonesArray("AliMUONTrack", 100);
226 fNRecTrackHits = 0; // really needed or GetEntriesFast sufficient ????
a9e2aefa 227
065bd0e1 228 // Sign of fSimpleBValue according to sign of Bx value at (50,50,950).
a6f03ddb 229 Float_t b[3], x[3];
230 x[0] = 50.; x[1] = 50.; x[2] = 950.;
231 gAlice->Field()->Field(x, b);
065bd0e1 232 fSimpleBValue = TMath::Sign(fSimpleBValue,(Double_t) b[0]);
a6f03ddb 233 // See how to get fSimple(BValue, BLength, BPosition)
234 // automatically calculated from the actual magnetic field ????
a9e2aefa 235
236 if (fPrintLevel >= 0) {
a6f03ddb 237 cout << "AliMUONEventReconstructor constructed with defaults" << endl; Dump();
238 cout << endl << "Magnetic field from root file:" << endl;
239 gAlice->Field()->Dump();
240 cout << endl;
241 }
c7ba256d 242
47a6b602 243 // Initializions for GEANT background events
244 fBkgGeantFile = 0;
245 fBkgGeantTK = 0;
246 fBkgGeantParticles = 0;
247 fBkgGeantTH = 0;
248 fBkgGeantHits = 0;
249 fBkgGeantEventNumber = -1;
250
c7ba256d 251 // Initialize to 0 pointers to RecoEvent, tree and tree file
252 fRecoEvent = 0;
253 fEventTree = 0;
254 fTreeFile = 0;
255
a9e2aefa 256 return;
257}
258
9cbdf048 259AliMUONEventReconstructor::AliMUONEventReconstructor (const AliMUONEventReconstructor& Reconstructor)
260{
261 // Dummy copy constructor
262}
263
264AliMUONEventReconstructor & AliMUONEventReconstructor::operator=(const AliMUONEventReconstructor& Reconstructor)
265{
266 // Dummy assignment operator
267 return *this;
268}
269
a9e2aefa 270 //__________________________________________________________________________
271AliMUONEventReconstructor::~AliMUONEventReconstructor(void)
272{
273 // Destructor for class AliMUONEventReconstructor
c7ba256d 274 if (fTreeFile) {
275 fTreeFile->Close();
276 delete fTreeFile;
277 }
278// if (fEventTree) delete fEventTree;
279 if (fRecoEvent) delete fRecoEvent;
a9e2aefa 280 delete fHitsForRecPtr; // Correct destruction of everything ???? or delete [] ????
9cbdf048 281 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++)
a9e2aefa 282 delete fSegmentsPtr[st]; // Correct destruction of everything ????
283 return;
284}
285
286 //__________________________________________________________________________
287void AliMUONEventReconstructor::SetReconstructionParametersToDefaults(void)
288{
289 // Set reconstruction parameters to default values
290 // Would be much more convenient with a structure (or class) ????
9cbdf048 291 fMinBendingMomentum = kDefaultMinBendingMomentum;
d0bfce8d 292 fMaxBendingMomentum = kDefaultMaxBendingMomentum;
293 fMaxChi2 = kDefaultMaxChi2;
9cbdf048 294 fMaxSigma2Distance = kDefaultMaxSigma2Distance;
a9e2aefa 295
9cbdf048 296 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON");
a9e2aefa 297 // ******** Parameters for making HitsForRec
298 // minimum radius,
299 // like in TRACKF_STAT:
300 // 2 degrees for stations 1 and 2, or ch(0...) from 0 to 3;
301 // 30 cm for stations 3 to 5, or ch(0...) from 4 to 9
9cbdf048 302 for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
303 if (ch < 4) fRMin[ch] = TMath::Abs((&(pMUON->Chamber(ch)))->Z()) *
a9e2aefa 304 2.0 * TMath::Pi() / 180.0;
305 else fRMin[ch] = 30.0;
d0bfce8d 306 // maximum radius at 10 degrees and Z of chamber
307 fRMax[ch] = TMath::Abs((&(pMUON->Chamber(ch)))->Z()) *
308 10.0 * TMath::Pi() / 180.0;
a9e2aefa 309 }
a9e2aefa 310
311 // ******** Parameters for making segments
312 // should be parametrized ????
313 // according to interval between chambers in a station ????
314 // Maximum distance in non bending plane
315 // 5 * 0.22 just to remember the way it was made in TRACKF_STAT
316 // SIGCUT*DYMAX(IZ)
9cbdf048 317 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++)
a9e2aefa 318 fSegmentMaxDistNonBending[st] = 5. * 0.22;
860cef81 319 // Maximum distance in bending plane:
320 // values from TRACKF_STAT, corresponding to (J psi 20cm),
321 // scaled to the real distance between chambers in a station
322 fSegmentMaxDistBending[0] = 1.5 *
323 ((&(pMUON->Chamber(1)))->Z() - (&(pMUON->Chamber(0)))->Z()) / 20.0;
324 fSegmentMaxDistBending[1] = 1.5 *
325 ((&(pMUON->Chamber(3)))->Z() - (&(pMUON->Chamber(2)))->Z()) / 20.0;
326 fSegmentMaxDistBending[2] = 3.0 *
327 ((&(pMUON->Chamber(5)))->Z() - (&(pMUON->Chamber(4)))->Z()) / 20.0;
328 fSegmentMaxDistBending[3] = 6.0 *
329 ((&(pMUON->Chamber(7)))->Z() - (&(pMUON->Chamber(6)))->Z()) / 20.0;
330 fSegmentMaxDistBending[4] = 6.0 *
331 ((&(pMUON->Chamber(9)))->Z() - (&(pMUON->Chamber(8)))->Z()) / 20.0;
a9e2aefa 332
9cbdf048 333 fBendingResolution = kDefaultBendingResolution;
334 fNonBendingResolution = kDefaultNonBendingResolution;
335 fChamberThicknessInX0 = kDefaultChamberThicknessInX0;
336 fSimpleBValue = kDefaultSimpleBValue;
337 fSimpleBLength = kDefaultSimpleBLength;
338 fSimpleBPosition = kDefaultSimpleBPosition;
339 fRecGeantHits = kDefaultRecGeantHits;
340 fEfficiency = kDefaultEfficiency;
341 fPrintLevel = kDefaultPrintLevel;
a9e2aefa 342 return;
343}
344
345//__________________________________________________________________________
3831f268 346Double_t AliMUONEventReconstructor::GetImpactParamFromBendingMomentum(Double_t BendingMomentum) const
a9e2aefa 347{
348 // Returns impact parameter at vertex in bending plane (cm),
349 // from the signed bending momentum "BendingMomentum" in bending plane (GeV/c),
350 // using simple values for dipole magnetic field.
065bd0e1 351 // The sign of "BendingMomentum" is the sign of the charge.
a9e2aefa 352 return (-0.0003 * fSimpleBValue * fSimpleBLength * fSimpleBPosition /
353 BendingMomentum);
354}
355
356//__________________________________________________________________________
3831f268 357Double_t AliMUONEventReconstructor::GetBendingMomentumFromImpactParam(Double_t ImpactParam) const
a9e2aefa 358{
359 // Returns signed bending momentum in bending plane (GeV/c),
065bd0e1 360 // the sign being the sign of the charge for particles moving forward in Z,
a9e2aefa 361 // from the impact parameter "ImpactParam" at vertex in bending plane (cm),
362 // using simple values for dipole magnetic field.
a9e2aefa 363 return (-0.0003 * fSimpleBValue * fSimpleBLength * fSimpleBPosition /
364 ImpactParam);
365}
366
367//__________________________________________________________________________
368void AliMUONEventReconstructor::SetBkgGeantFile(Text_t *BkgGeantFileName)
369{
370 // Set background file ... for GEANT hits
371 // Must be called after having loaded the firts signal event
372 if (fPrintLevel >= 0) {
373 cout << "Enter SetBkgGeantFile with BkgGeantFileName ``"
374 << BkgGeantFileName << "''" << endl;}
375 if (strlen(BkgGeantFileName)) {
376 // BkgGeantFileName not empty: try to open the file
377 if (fPrintLevel >= 2) {cout << "Before File(Bkg)" << endl; gDirectory->Dump();}
378 fBkgGeantFile = new TFile(BkgGeantFileName);
379 if (fPrintLevel >= 2) {cout << "After File(Bkg)" << endl; gDirectory->Dump();}
380 if (fBkgGeantFile-> IsOpen()) {
381 if (fPrintLevel >= 0) {
382 cout << "Background for GEANT hits in file: ``" << BkgGeantFileName
383 << "'' successfully opened" << endl;}
384 }
385 else {
386 cout << "Background for GEANT hits in file: " << BkgGeantFileName << endl;
387 cout << "NOT FOUND: EXIT" << endl;
388 exit(0); // right instruction for exit ????
389 }
390 // Arrays for "particles" and "hits"
391 fBkgGeantParticles = new TClonesArray("TParticle", 200);
392 fBkgGeantHits = new TClonesArray("AliMUONHit", 2000);
393 // Event number to -1 for initialization
394 fBkgGeantEventNumber = -1;
395 // Back to the signal file:
396 // first signal event must have been loaded previously,
397 // otherwise, Segmentation violation at the next instruction
398 // How is it possible to do smething better ????
399 ((gAlice->TreeK())->GetCurrentFile())->cd();
400 if (fPrintLevel >= 2) {cout << "After cd(gAlice)" << endl; gDirectory->Dump();}
401 }
402 return;
403}
404
405//__________________________________________________________________________
406void AliMUONEventReconstructor::NextBkgGeantEvent(void)
407{
408 // Get next event in background file for GEANT hits
409 // Goes back to event number 0 when end of file is reached
410 char treeName[20];
411 TBranch *branch;
412 if (fPrintLevel >= 0) {
413 cout << "Enter NextBkgGeantEvent" << endl;}
414 // Clean previous event
415 if(fBkgGeantTK) delete fBkgGeantTK;
416 fBkgGeantTK = NULL;
417 if(fBkgGeantParticles) fBkgGeantParticles->Clear();
418 if(fBkgGeantTH) delete fBkgGeantTH;
419 fBkgGeantTH = NULL;
420 if(fBkgGeantHits) fBkgGeantHits->Clear();
421 // Increment event number
422 fBkgGeantEventNumber++;
423 // Get access to Particles and Hits for event from background file
424 if (fPrintLevel >= 2) {cout << "Before cd(Bkg)" << endl; gDirectory->Dump();}
425 fBkgGeantFile->cd();
426 if (fPrintLevel >= 2) {cout << "After cd(Bkg)" << endl; gDirectory->Dump();}
427 // Particles: TreeK for event and branch "Particles"
428 sprintf(treeName, "TreeK%d", fBkgGeantEventNumber);
429 fBkgGeantTK = (TTree*)gDirectory->Get(treeName);
430 if (!fBkgGeantTK) {
431 if (fPrintLevel >= 0) {
432 cout << "Cannot find Kine Tree for background event: " <<
433 fBkgGeantEventNumber << endl;
434 cout << "Goes back to event 0" << endl;
435 }
436 fBkgGeantEventNumber = 0;
437 sprintf(treeName, "TreeK%d", fBkgGeantEventNumber);
438 fBkgGeantTK = (TTree*)gDirectory->Get(treeName);
439 if (!fBkgGeantTK) {
440 cout << "ERROR: cannot find Kine Tree for background event: " <<
441 fBkgGeantEventNumber << endl;
442 exit(0);
443 }
444 }
445 if (fBkgGeantTK)
446 fBkgGeantTK->SetBranchAddress("Particles", &fBkgGeantParticles);
447 fBkgGeantTK->GetEvent(0); // why event 0 ???? necessary ????
448 // Hits: TreeH for event and branch "MUON"
449 sprintf(treeName, "TreeH%d", fBkgGeantEventNumber);
450 fBkgGeantTH = (TTree*)gDirectory->Get(treeName);
451 if (!fBkgGeantTH) {
452 cout << "ERROR: cannot find Hits Tree for background event: " <<
453 fBkgGeantEventNumber << endl;
454 exit(0);
455 }
456 if (fBkgGeantTH && fBkgGeantHits) {
457 branch = fBkgGeantTH->GetBranch("MUON");
458 if (branch) branch->SetAddress(&fBkgGeantHits);
459 }
460 fBkgGeantTH->GetEntries(); // necessary ????
461 // Back to the signal file
462 ((gAlice->TreeK())->GetCurrentFile())->cd();
463 if (fPrintLevel >= 2) {cout << "After cd(gAlice)" << endl; gDirectory->Dump();}
464 return;
465}
466
467//__________________________________________________________________________
468void AliMUONEventReconstructor::EventReconstruct(void)
469{
470 // To reconstruct one event
471 if (fPrintLevel >= 1) cout << "enter EventReconstruct" << endl;
472 MakeEventToBeReconstructed();
473 MakeSegments();
474 MakeTracks();
475 return;
476}
477
478 //__________________________________________________________________________
479void AliMUONEventReconstructor::ResetHitsForRec(void)
480{
481 // To reset the array and the number of HitsForRec,
482 // and also the number of HitsForRec
483 // and the index of the first HitForRec per chamber
484 if (fHitsForRecPtr) fHitsForRecPtr->Clear();
485 fNHitsForRec = 0;
9cbdf048 486 for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++)
a9e2aefa 487 fNHitsForRecPerChamber[ch] = fIndexOfFirstHitForRecPerChamber[ch] = 0;
488 return;
489}
490
491 //__________________________________________________________________________
492void AliMUONEventReconstructor::ResetSegments(void)
493{
494 // To reset the TClonesArray of segments and the number of Segments
495 // for all stations
9cbdf048 496 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++) {
a9e2aefa 497 if (fSegmentsPtr[st]) fSegmentsPtr[st]->Clear();
498 fNSegments[st] = 0;
499 }
500 return;
501}
502
503 //__________________________________________________________________________
504void AliMUONEventReconstructor::ResetTracks(void)
505{
506 // To reset the TClonesArray of reconstructed tracks
8429a5e4 507 if (fRecTracksPtr) fRecTracksPtr->Delete();
508 // Delete in order that the Track destructors are called,
509 // hence the space for the TClonesArray of pointers to TrackHit's is freed
a9e2aefa 510 fNRecTracks = 0;
511 return;
512}
513
8429a5e4 514 //__________________________________________________________________________
515void AliMUONEventReconstructor::ResetTrackHits(void)
516{
517 // To reset the TClonesArray of hits on reconstructed tracks
518 if (fRecTrackHitsPtr) fRecTrackHitsPtr->Clear();
519 fNRecTrackHits = 0;
520 return;
521}
522
a9e2aefa 523 //__________________________________________________________________________
524void AliMUONEventReconstructor::MakeEventToBeReconstructed(void)
525{
526 // To make the list of hits to be reconstructed,
527 // either from the GEANT hits or from the raw clusters
528 // according to the parameter set for the reconstructor
529 if (fPrintLevel >= 1) cout << "enter MakeEventToBeReconstructed" << endl;
530 ResetHitsForRec();
531 if (fRecGeantHits == 1) {
532 // Reconstruction from GEANT hits
533 // Back to the signal file
534 ((gAlice->TreeK())->GetCurrentFile())->cd();
535 // Signal hits
536 // AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
537 // Security on MUON ????
538 AddHitsForRecFromGEANT(gAlice->TreeH());
539 // Background hits
540 AddHitsForRecFromBkgGEANT(fBkgGeantTH, fBkgGeantHits);
541 // Sort HitsForRec in increasing order with respect to chamber number
542 SortHitsForRecWithIncreasingChamber();
543 }
544 else {
545 // Reconstruction from raw clusters
546 // AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
547 // Security on MUON ????
548 // TreeR assumed to be be "prepared" in calling function
549 // by "MUON->GetTreeR(nev)" ????
9cbdf048 550 TTree *treeR = gAlice->TreeR();
551 AddHitsForRecFromRawClusters(treeR);
a9e2aefa 552 // No sorting: it is done automatically in the previous function
553 }
554 if (fPrintLevel >= 10) {
555 cout << "end of MakeEventToBeReconstructed" << endl;
556 cout << "NHitsForRec: " << fNHitsForRec << endl;
9cbdf048 557 for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
a9e2aefa 558 cout << "chamber(0...): " << ch
559 << " NHitsForRec: " << fNHitsForRecPerChamber[ch]
560 << " index(first HitForRec): " << fIndexOfFirstHitForRecPerChamber[ch]
561 << endl;
562 for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
563 hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
564 hit++) {
565 cout << "HitForRec index(0...): " << hit << endl;
566 ((*fHitsForRecPtr)[hit])->Dump();
567 }
568 }
569 }
570 return;
571}
572
573 //__________________________________________________________________________
574void AliMUONEventReconstructor::AddHitsForRecFromGEANT(TTree *TH)
575{
576 // To add to the list of hits for reconstruction
577 // the GEANT signal hits from a hit tree TH.
578 if (fPrintLevel >= 2)
579 cout << "enter AddHitsForRecFromGEANT with TH: " << TH << endl;
580 if (TH == NULL) return;
9cbdf048 581 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
a9e2aefa 582 // Security on MUON ????
583 // See whether it could be the same for signal and background ????
584 // Loop over tracks in tree
585 Int_t ntracks = (Int_t) TH->GetEntries();
586 if (fPrintLevel >= 2)
587 cout << "ntracks: " << ntracks << endl;
588 for (Int_t track = 0; track < ntracks; track++) {
589 gAlice->ResetHits();
590 TH->GetEvent(track);
591 // Loop over hits
592 Int_t hit = 0;
9cbdf048 593 for (AliMUONHit* mHit = (AliMUONHit*) pMUON->FirstHit(-1);
a9e2aefa 594 mHit;
9cbdf048 595 mHit = (AliMUONHit*) pMUON->NextHit(), hit++) {
a9e2aefa 596 NewHitForRecFromGEANT(mHit,track, hit, 1);
597 } // end of hit loop
598 } // end of track loop
599 return;
600}
601
602 //__________________________________________________________________________
603void AliMUONEventReconstructor::AddHitsForRecFromBkgGEANT(TTree *TH, TClonesArray *Hits)
604{
605 // To add to the list of hits for reconstruction
606 // the GEANT background hits from a hit tree TH and a pointer Hits to a hit list.
607 // How to have only one function "AddHitsForRecFromGEANT" ????
608 if (fPrintLevel >= 2)
609 cout << "enter AddHitsForRecFromBkgGEANT with TH: " << TH << endl;
610 if (TH == NULL) return;
611 // Loop over tracks in tree
612 Int_t ntracks = (Int_t) TH->GetEntries();
613 if (fPrintLevel >= 2)
614 cout << "ntracks: " << ntracks << endl;
615 for (Int_t track = 0; track < ntracks; track++) {
616 if (Hits) Hits->Clear();
617 TH->GetEvent(track);
618 // Loop over hits
619 for (Int_t hit = 0; hit < Hits->GetEntriesFast(); hit++) {
620 NewHitForRecFromGEANT((AliMUONHit*) (*Hits)[hit], track, hit, 0);
621 } // end of hit loop
622 } // end of track loop
623 return;
624}
625
626 //__________________________________________________________________________
627AliMUONHitForRec* AliMUONEventReconstructor::NewHitForRecFromGEANT(AliMUONHit* Hit, Int_t TrackNumber, Int_t HitNumber, Int_t Signal)
628{
629 // To make a new hit for reconstruction from a GEANT hit pointed to by "Hit",
630 // with hit number "HitNumber" in the track numbered "TrackNumber",
631 // either from signal ("Signal" = 1) or background ("Signal" = 0) event.
632 // Selects hits in tracking (not trigger) chambers.
633 // Takes into account the efficiency (fEfficiency)
634 // and the smearing from resolution (fBendingResolution and fNonBendingResolution).
635 // Adds a condition on the radius between RMin and RMax
636 // to better simulate the real chambers.
637 // Returns the pointer to the new hit for reconstruction,
638 // or NULL in case of inefficiency or non tracking chamber or bad radius.
639 // No condition on at most 20 cm from a muon from a resonance
640 // like in Fortran TRACKF_STAT.
641 AliMUONHitForRec* hitForRec;
642 Double_t bendCoor, nonBendCoor, radius;
0a5f36d9 643 Int_t chamber = Hit->Chamber() - 1; // chamber(0...)
a9e2aefa 644 // only in tracking chambers (fChamber starts at 1)
9cbdf048 645 if (chamber >= kMaxMuonTrackingChambers) return NULL;
a9e2aefa 646 // only if hit is efficient (keep track for checking ????)
647 if (gRandom->Rndm() > fEfficiency) return NULL;
648 // only if radius between RMin and RMax
94de3818 649 bendCoor = Hit->Y();
650 nonBendCoor = Hit->X();
a9e2aefa 651 radius = TMath::Sqrt((bendCoor * bendCoor) + (nonBendCoor * nonBendCoor));
d0bfce8d 652 // This cut is not needed with a realistic chamber geometry !!!!
653// if ((radius < fRMin[chamber]) || (radius > fRMax[chamber])) return NULL;
a9e2aefa 654 // new AliMUONHitForRec from GEANT hit and increment number of AliMUONHitForRec's
655 hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(Hit);
656 fNHitsForRec++;
657 // add smearing from resolution
658 hitForRec->SetBendingCoor(bendCoor + gRandom->Gaus(0., fBendingResolution));
659 hitForRec->SetNonBendingCoor(nonBendCoor
660 + gRandom->Gaus(0., fNonBendingResolution));
d0bfce8d 661// // !!!! without smearing
662// hitForRec->SetBendingCoor(bendCoor);
663// hitForRec->SetNonBendingCoor(nonBendCoor);
a9e2aefa 664 // more information into HitForRec
665 // resolution: angular effect to be added here ????
666 hitForRec->SetBendingReso2(fBendingResolution * fBendingResolution);
667 hitForRec->SetNonBendingReso2(fNonBendingResolution * fNonBendingResolution);
668 // GEANT track info
669 hitForRec->SetHitNumber(HitNumber);
670 hitForRec->SetTHTrack(TrackNumber);
671 hitForRec->SetGeantSignal(Signal);
672 if (fPrintLevel >= 10) {
673 cout << "track: " << TrackNumber << " hit: " << HitNumber << endl;
674 Hit->Dump();
675 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
676 hitForRec->Dump();}
677 return hitForRec;
678}
679
680 //__________________________________________________________________________
681void AliMUONEventReconstructor::SortHitsForRecWithIncreasingChamber()
682{
683 // Sort HitsForRec's in increasing order with respect to chamber number.
684 // Uses the function "Compare".
685 // Update the information for HitsForRec per chamber too.
686 Int_t ch, nhits, prevch;
687 fHitsForRecPtr->Sort();
9cbdf048 688 for (ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
a9e2aefa 689 fNHitsForRecPerChamber[ch] = 0;
690 fIndexOfFirstHitForRecPerChamber[ch] = 0;
691 }
692 prevch = 0; // previous chamber
693 nhits = 0; // number of hits in current chamber
694 // Loop over HitsForRec
695 for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
696 // chamber number (0...)
697 ch = ((AliMUONHitForRec*) ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
698 // increment number of hits in current chamber
699 (fNHitsForRecPerChamber[ch])++;
700 // update index of first HitForRec in current chamber
701 // if chamber number different from previous one
702 if (ch != prevch) {
703 fIndexOfFirstHitForRecPerChamber[ch] = hit;
704 prevch = ch;
705 }
706 }
707 return;
708}
709
710// //__________________________________________________________________________
711// void AliMUONEventReconstructor::AddHitsForRecFromCathodeCorrelations(TTree* TC)
712// {
713// // OLD VERSION WHEN ONE ONE WAS USING SO CALLED CATHODE CORRELATIONS
714// // To add to the list of hits for reconstruction
715// // the (cathode correlated) raw clusters
716// // No condition added, like in Fortran TRACKF_STAT,
717// // on the radius between RMin and RMax.
718// AliMUONHitForRec *hitForRec;
719// if (fPrintLevel >= 1) cout << "enter AddHitsForRecFromCathodeCorrelations" << endl;
720// AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
721// // Security on MUON ????
722// // Loop over tracking chambers
9cbdf048 723// for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
a9e2aefa 724// // number of HitsForRec to 0 for the chamber
725// fNHitsForRecPerChamber[ch] = 0;
726// // index of first HitForRec for the chamber
727// if (ch == 0) fIndexOfFirstHitForRecPerChamber[ch] = 0;
728// else fIndexOfFirstHitForRecPerChamber[ch] = fNHitsForRec;
729// TClonesArray *reconst_hits = MUON->ReconstHitsAddress(ch);
730// MUON->ResetReconstHits();
731// TC->GetEvent();
732// Int_t ncor = (Int_t)reconst_hits->GetEntries();
733// // Loop over (cathode correlated) raw clusters
734// for (Int_t cor = 0; cor < ncor; cor++) {
735// AliMUONReconstHit * mCor =
736// (AliMUONReconstHit*) reconst_hits->UncheckedAt(cor);
737// // new AliMUONHitForRec from (cathode correlated) raw cluster
738// // and increment number of AliMUONHitForRec's (total and in chamber)
739// hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(mCor);
740// fNHitsForRec++;
741// (fNHitsForRecPerChamber[ch])++;
742// // more information into HitForRec
743// hitForRec->SetChamberNumber(ch);
744// hitForRec->SetHitNumber(cor);
745// // Z coordinate of the chamber (cm) with sign opposite to GEANT sign
746// // could (should) be more exact from chamber geometry ????
747// hitForRec->SetZ(-(&(MUON->Chamber(ch)))->Z());
748// if (fPrintLevel >= 10) {
749// cout << "chamber (0...): " << ch <<
750// " cathcorrel (0...): " << cor << endl;
751// mCor->Dump();
752// cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
753// hitForRec->Dump();}
754// } // end of cluster loop
755// } // end of chamber loop
756// return;
757// }
758
759 //__________________________________________________________________________
760void AliMUONEventReconstructor::AddHitsForRecFromRawClusters(TTree* TR)
761{
762 // To add to the list of hits for reconstruction all the raw clusters
763 // No condition added, like in Fortran TRACKF_STAT,
764 // on the radius between RMin and RMax.
765 AliMUONHitForRec *hitForRec;
766 AliMUONRawCluster *clus;
f69d51b5 767 Int_t iclus, nclus, nTRentries;
a9e2aefa 768 TClonesArray *rawclusters;
769 if (fPrintLevel >= 1) cout << "enter AddHitsForRecFromRawClusters" << endl;
9cbdf048 770 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
a9e2aefa 771 // Security on MUON ????
f69d51b5 772 pMUON->ResetRawClusters();
773 nTRentries = Int_t(TR->GetEntries());
774 if (nTRentries != 1) {
775 cout << "Error in AliMUONEventReconstructor::AddHitsForRecFromRawClusters"
776 << endl;
777 cout << "nTRentries = " << nTRentries << " not equal to 1" << endl;
778 exit(0);
779 }
780 TR->GetEvent(0); // only one entry
a9e2aefa 781 // Loop over tracking chambers
9cbdf048 782 for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
a9e2aefa 783 // number of HitsForRec to 0 for the chamber
784 fNHitsForRecPerChamber[ch] = 0;
785 // index of first HitForRec for the chamber
786 if (ch == 0) fIndexOfFirstHitForRecPerChamber[ch] = 0;
787 else fIndexOfFirstHitForRecPerChamber[ch] = fNHitsForRec;
9cbdf048 788 rawclusters = pMUON->RawClustAddress(ch);
f69d51b5 789// pMUON->ResetRawClusters();
790// TR->GetEvent((Int_t) (TR->GetEntries()) - 1); // to be checked ????
a9e2aefa 791 nclus = (Int_t) (rawclusters->GetEntries());
792 // Loop over (cathode correlated) raw clusters
793 for (iclus = 0; iclus < nclus; iclus++) {
794 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(iclus);
795 // new AliMUONHitForRec from raw cluster
796 // and increment number of AliMUONHitForRec's (total and in chamber)
797 hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
798 fNHitsForRec++;
799 (fNHitsForRecPerChamber[ch])++;
800 // more information into HitForRec
801 // resolution: info should be already in raw cluster and taken from it ????
802 hitForRec->SetBendingReso2(fBendingResolution * fBendingResolution);
803 hitForRec->SetNonBendingReso2(fNonBendingResolution * fNonBendingResolution);
804 // original raw cluster
805 hitForRec->SetChamberNumber(ch);
806 hitForRec->SetHitNumber(iclus);
ba5b68db 807 // Z coordinate of the raw cluster (cm)
cfe0107f 808 hitForRec->SetZ(clus->fZ[0]);
a9e2aefa 809 if (fPrintLevel >= 10) {
810 cout << "chamber (0...): " << ch <<
811 " raw cluster (0...): " << iclus << endl;
812 clus->Dump();
813 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
814 hitForRec->Dump();}
815 } // end of cluster loop
816 } // end of chamber loop
817 return;
818}
819
820 //__________________________________________________________________________
821void AliMUONEventReconstructor::MakeSegments(void)
822{
823 // To make the list of segments in all stations,
824 // from the list of hits to be reconstructed
825 if (fPrintLevel >= 1) cout << "enter MakeSegments" << endl;
826 ResetSegments();
827 // Loop over stations
9cbdf048 828 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++)
a9e2aefa 829 MakeSegmentsPerStation(st);
830 if (fPrintLevel >= 10) {
831 cout << "end of MakeSegments" << endl;
9cbdf048 832 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++) {
a9e2aefa 833 cout << "station(0...): " << st
834 << " Segments: " << fNSegments[st]
835 << endl;
836 for (Int_t seg = 0;
837 seg < fNSegments[st];
838 seg++) {
839 cout << "Segment index(0...): " << seg << endl;
840 ((*fSegmentsPtr[st])[seg])->Dump();
841 }
842 }
843 }
844 return;
845}
846
847 //__________________________________________________________________________
848void AliMUONEventReconstructor::MakeSegmentsPerStation(Int_t Station)
849{
850 // To make the list of segments in station number "Station" (0...)
851 // from the list of hits to be reconstructed.
852 // Updates "fNSegments"[Station].
853 // Segments in stations 4 and 5 are sorted
854 // according to increasing absolute value of "impact parameter"
855 AliMUONHitForRec *hit1Ptr, *hit2Ptr;
856 AliMUONSegment *segment;
857 Bool_t last2st;
858 Double_t bendingSlope, distBend, distNonBend, extBendCoor, extNonBendCoor,
d0bfce8d 859 impactParam = 0., maxImpactParam = 0., minImpactParam = 0.; // =0 to avoid compilation warnings.
9cbdf048 860 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
a9e2aefa 861 if (fPrintLevel >= 1)
862 cout << "enter MakeSegmentsPerStation (0...) " << Station << endl;
863 // first and second chambers (0...) in the station
864 Int_t ch1 = 2 * Station;
865 Int_t ch2 = ch1 + 1;
866 // variable true for stations downstream of the dipole:
867 // Station(0..4) equal to 3 or 4
868 if ((Station == 3) || (Station == 4)) {
869 last2st = kTRUE;
870 // maximum impact parameter (cm) according to fMinBendingMomentum...
871 maxImpactParam =
872 TMath::Abs(GetImpactParamFromBendingMomentum(fMinBendingMomentum));
d0bfce8d 873 // minimum impact parameter (cm) according to fMaxBendingMomentum...
874 minImpactParam =
875 TMath::Abs(GetImpactParamFromBendingMomentum(fMaxBendingMomentum));
a9e2aefa 876 }
877 else last2st = kFALSE;
878 // extrapolation factor from Z of first chamber to Z of second chamber
879 // dZ to be changed to take into account fine structure of chambers ????
880 Double_t extrapFact =
9cbdf048 881 (&(pMUON->Chamber(ch2)))->Z() / (&(pMUON->Chamber(ch1)))->Z();
a9e2aefa 882 // index for current segment
883 Int_t segmentIndex = 0;
884 // Loop over HitsForRec in the first chamber of the station
885 for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
886 hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
887 hit1++) {
888 // pointer to the HitForRec
889 hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
890 // extrapolation,
891 // on the straight line joining the HitForRec to the vertex (0,0,0),
892 // to the Z of the second chamber of the station
893 extBendCoor = extrapFact * hit1Ptr->GetBendingCoor();
894 extNonBendCoor = extrapFact * hit1Ptr->GetNonBendingCoor();
895 // Loop over HitsForRec in the second chamber of the station
896 for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
897 hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
898 hit2++) {
899 // pointer to the HitForRec
900 hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
901 // absolute values of distances, in bending and non bending planes,
902 // between the HitForRec in the second chamber
903 // and the previous extrapolation
904 distBend = TMath::Abs(hit2Ptr->GetBendingCoor() - extBendCoor);
905 distNonBend = TMath::Abs(hit2Ptr->GetNonBendingCoor() - extNonBendCoor);
906 if (last2st) {
907 // bending slope
908 bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) /
909 (hit1Ptr->GetZ() - hit2Ptr->GetZ());
910 // absolute value of impact parameter
911 impactParam =
31817925 912 TMath::Abs(hit1Ptr->GetBendingCoor() - hit1Ptr->GetZ() * bendingSlope);
a9e2aefa 913 }
914 // check for distances not too large,
915 // and impact parameter not too big if stations downstream of the dipole.
916 // Conditions "distBend" and "impactParam" correlated for these stations ????
917 if ((distBend < fSegmentMaxDistBending[Station]) &&
918 (distNonBend < fSegmentMaxDistNonBending[Station]) &&
d0bfce8d 919 (!last2st || (impactParam < maxImpactParam)) &&
920 (!last2st || (impactParam > minImpactParam))) {
a9e2aefa 921 // make new segment
922 segment = new ((*fSegmentsPtr[Station])[segmentIndex])
923 AliMUONSegment(hit1Ptr, hit2Ptr);
924 // update "link" to this segment from the hit in the first chamber
925 if (hit1Ptr->GetNSegments() == 0)
926 hit1Ptr->SetIndexOfFirstSegment(segmentIndex);
927 hit1Ptr->SetNSegments(hit1Ptr->GetNSegments() + 1);
928 if (fPrintLevel >= 10) {
929 cout << "segmentIndex(0...): " << segmentIndex
930 << " distBend: " << distBend
931 << " distNonBend: " << distNonBend
932 << endl;
933 segment->Dump();
934 cout << "HitForRec in first chamber" << endl;
935 hit1Ptr->Dump();
936 cout << "HitForRec in second chamber" << endl;
937 hit2Ptr->Dump();
938 };
939 // increment index for current segment
940 segmentIndex++;
941 }
942 } //for (Int_t hit2
943 } // for (Int_t hit1...
944 fNSegments[Station] = segmentIndex;
945 // Sorting according to "impact parameter" if station(1..5) 4 or 5,
946 // i.e. Station(0..4) 3 or 4, using the function "Compare".
947 // After this sorting, it is impossible to use
948 // the "fNSegments" and "fIndexOfFirstSegment"
949 // of the HitForRec in the first chamber to explore all segments formed with it.
950 // Is this sorting really needed ????
951 if ((Station == 3) || (Station == 4)) (fSegmentsPtr[Station])->Sort();
952 if (fPrintLevel >= 1) cout << "Station: " << Station << " NSegments: "
953 << fNSegments[Station] << endl;
954 return;
955}
956
957 //__________________________________________________________________________
958void AliMUONEventReconstructor::MakeTracks(void)
959{
960 // To make the tracks,
961 // from the list of segments and points in all stations
962 if (fPrintLevel >= 1) cout << "enter MakeTracks" << endl;
8429a5e4 963 // The order may be important for the following Reset's
a9e2aefa 964 ResetTracks();
8429a5e4 965 ResetTrackHits();
a9e2aefa 966 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
967 MakeTrackCandidates();
968 // Follow tracks in stations(1..) 3, 2 and 1
969 FollowTracks();
8429a5e4 970 // Remove double tracks
971 RemoveDoubleTracks();
a9e2aefa 972 return;
973}
974
975 //__________________________________________________________________________
976Int_t AliMUONEventReconstructor::MakeTrackCandidatesWithTwoSegments(AliMUONSegment *BegSegment)
977{
978 // To make track candidates with two segments in stations(1..) 4 and 5,
979 // the first segment being pointed to by "BegSegment".
980 // Returns the number of such track candidates.
981 Int_t endStation, iEndSegment, nbCan2Seg;
982 AliMUONSegment *endSegment, *extrapSegment;
983 AliMUONTrack *recTrack;
984 Double_t mcsFactor;
985 if (fPrintLevel >= 1) cout << "enter MakeTrackCandidatesWithTwoSegments" << endl;
986 // Station for the end segment
987 endStation = 7 - (BegSegment->GetHitForRec1())->GetChamberNumber() / 2;
988 // multiple scattering factor corresponding to one chamber
989 mcsFactor = 0.0136 /
990 GetBendingMomentumFromImpactParam(BegSegment->GetBendingImpact());
991 mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
992 // linear extrapolation to end station
993 extrapSegment =
994 BegSegment->CreateSegmentFromLinearExtrapToStation(endStation, mcsFactor);
995 // number of candidates with 2 segments to 0
996 nbCan2Seg = 0;
997 // Loop over segments in the end station
998 for (iEndSegment = 0; iEndSegment < fNSegments[endStation]; iEndSegment++) {
999 // pointer to segment
1000 endSegment = (AliMUONSegment*) ((*fSegmentsPtr[endStation])[iEndSegment]);
1001 // test compatibility between current segment and "extrapSegment"
04b5ea16 1002 // 4 because 4 quantities in chi2
a9e2aefa 1003 if ((endSegment->
1004 NormalizedChi2WithSegment(extrapSegment,
1005 fMaxSigma2Distance)) <= 4.0) {
1006 // both segments compatible:
1007 // make track candidate from "begSegment" and "endSegment"
1008 if (fPrintLevel >= 2)
1009 cout << "TrackCandidate with Segment " << iEndSegment <<
1010 " in Station(0..) " << endStation << endl;
1011 // flag for both segments in one track:
1012 // to be done in track constructor ????
1013 BegSegment->SetInTrack(kTRUE);
1014 endSegment->SetInTrack(kTRUE);
1015 recTrack = new ((*fRecTracksPtr)[fNRecTracks])
1016 AliMUONTrack(BegSegment, endSegment, this);
1017 fNRecTracks++;
1018 if (fPrintLevel >= 10) recTrack->RecursiveDump();
1019 // increment number of track candidates with 2 segments
1020 nbCan2Seg++;
1021 }
1022 } // for (iEndSegment = 0;...
1023 delete extrapSegment; // should not delete HitForRec's it points to !!!!
1024 return nbCan2Seg;
1025}
1026
1027 //__________________________________________________________________________
1028Int_t AliMUONEventReconstructor::MakeTrackCandidatesWithOneSegmentAndOnePoint(AliMUONSegment *BegSegment)
1029{
1030 // To make track candidates with one segment and one point
1031 // in stations(1..) 4 and 5,
1032 // the segment being pointed to by "BegSegment".
1033 Int_t ch, ch1, ch2, endStation, iHit, iHitMax, iHitMin, nbCan1Seg1Hit;
1034 AliMUONHitForRec *extrapHitForRec, *hit;
1035 AliMUONTrack *recTrack;
1036 Double_t mcsFactor;
1037 if (fPrintLevel >= 1)
1038 cout << "enter MakeTrackCandidatesWithOneSegmentAndOnePoint" << endl;
1039 // station for the end point
1040 endStation = 7 - (BegSegment->GetHitForRec1())->GetChamberNumber() / 2;
1041 // multiple scattering factor corresponding to one chamber
1042 mcsFactor = 0.0136 /
1043 GetBendingMomentumFromImpactParam(BegSegment->GetBendingImpact());
1044 mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
1045 // first and second chambers(0..) in the end station
1046 ch1 = 2 * endStation;
1047 ch2 = ch1 + 1;
1048 // number of candidates to 0
1049 nbCan1Seg1Hit = 0;
1050 // Loop over chambers of the end station
1051 for (ch = ch2; ch >= ch1; ch--) {
1052 // linear extrapolation to chamber
1053 extrapHitForRec =
1054 BegSegment->CreateHitForRecFromLinearExtrapToChamber(ch, mcsFactor);
1055 // limits for the hit index in the loop
1056 iHitMin = fIndexOfFirstHitForRecPerChamber[ch];
1057 iHitMax = iHitMin + fNHitsForRecPerChamber[ch];
1058 // Loop over HitForRec's in the chamber
1059 for (iHit = iHitMin; iHit < iHitMax; iHit++) {
1060 // pointer to HitForRec
1061 hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[iHit]);
1062 // test compatibility between current HitForRec and "extrapHitForRec"
04b5ea16 1063 // 2 because 2 quantities in chi2
a9e2aefa 1064 if ((hit->
1065 NormalizedChi2WithHitForRec(extrapHitForRec,
1066 fMaxSigma2Distance)) <= 2.0) {
1067 // both HitForRec's compatible:
1068 // make track candidate from begSegment and current HitForRec
1069 if (fPrintLevel >= 2)
1070 cout << "TrackCandidate with HitForRec " << iHit <<
1071 " in Chamber(0..) " << ch << endl;
1072 // flag for beginning segments in one track:
1073 // to be done in track constructor ????
1074 BegSegment->SetInTrack(kTRUE);
1075 recTrack = new ((*fRecTracksPtr)[fNRecTracks])
1076 AliMUONTrack(BegSegment, hit, this);
1077 // the right place to eliminate "double counting" ???? how ????
1078 fNRecTracks++;
1079 if (fPrintLevel >= 10) recTrack->RecursiveDump();
1080 // increment number of track candidates
1081 nbCan1Seg1Hit++;
1082 }
1083 } // for (iHit = iHitMin;...
1084 delete extrapHitForRec;
1085 } // for (ch = ch2;...
1086 return nbCan1Seg1Hit;
1087}
1088
1089 //__________________________________________________________________________
1090void AliMUONEventReconstructor::MakeTrackCandidates(void)
1091{
1092 // To make track candidates
1093 // with at least 3 aligned points in stations(1..) 4 and 5
1094 // (two Segment's or one Segment and one HitForRec)
1095 Int_t begStation, iBegSegment, nbCan1Seg1Hit, nbCan2Seg;
1096 AliMUONSegment *begSegment;
1097 if (fPrintLevel >= 1) cout << "enter MakeTrackCandidates" << endl;
1098 // Loop over stations(1..) 5 and 4 for the beginning segment
1099 for (begStation = 4; begStation > 2; begStation--) {
1100 // Loop over segments in the beginning station
1101 for (iBegSegment = 0; iBegSegment < fNSegments[begStation]; iBegSegment++) {
1102 // pointer to segment
1103 begSegment = (AliMUONSegment*) ((*fSegmentsPtr[begStation])[iBegSegment]);
1104 if (fPrintLevel >= 2)
1105 cout << "look for TrackCandidate's with Segment " << iBegSegment <<
1106 " in Station(0..) " << begStation << endl;
1107 // Look for track candidates with two segments,
1108 // "begSegment" and all compatible segments in other station.
1109 // Only for beginning station(1..) 5
1110 // because candidates with 2 segments have to looked for only once.
1111 if (begStation == 4)
1112 nbCan2Seg = MakeTrackCandidatesWithTwoSegments(begSegment);
956019b6 1113 // Look for track candidates with one segment and one point,
a9e2aefa 1114 // "begSegment" and all compatible HitForRec's in other station.
1115 // Only if "begSegment" does not belong already to a track candidate.
1116 // Is that a too strong condition ????
1117 if (!(begSegment->GetInTrack()))
1118 nbCan1Seg1Hit = MakeTrackCandidatesWithOneSegmentAndOnePoint(begSegment);
1119 } // for (iBegSegment = 0;...
1120 } // for (begStation = 4;...
1121 return;
1122}
1123
1124 //__________________________________________________________________________
1125void AliMUONEventReconstructor::FollowTracks(void)
1126{
1127 // Follow tracks in stations(1..) 3, 2 and 1
04b5ea16 1128 // too long: should be made more modular !!!!
d0bfce8d 1129 AliMUONHitForRec *bestHit, *extrapHit, *extrapCorrHit, *hit;
1130 AliMUONSegment *bestSegment, *extrapSegment, *extrapCorrSegment, *segment;
04b5ea16 1131 AliMUONTrack *track, *nextTrack;
1132 AliMUONTrackParam *trackParam1, trackParam[2], trackParamVertex;
ecfa008b 1133 // -1 to avoid compilation warnings
1134 Int_t ch = -1, chInStation, chBestHit = -1, iHit, iSegment, station, trackIndex;
04b5ea16 1135 Double_t bestChi2, chi2, dZ1, dZ2, dZ3, maxSigma2Distance, mcsFactor;
d0bfce8d 1136 Double_t bendingMomentum, chi2Norm = 0.;
9cbdf048 1137 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
04b5ea16 1138 // local maxSigma2Distance, for easy increase in testing
1139 maxSigma2Distance = fMaxSigma2Distance;
a9e2aefa 1140 if (fPrintLevel >= 2)
1141 cout << "enter FollowTracks" << endl;
1142 // Loop over track candidates
04b5ea16 1143 track = (AliMUONTrack*) fRecTracksPtr->First();
1144 trackIndex = -1;
1145 while (track) {
1146 // Follow function for each track candidate ????
1147 trackIndex++;
1148 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
a9e2aefa 1149 if (fPrintLevel >= 2)
1150 cout << "FollowTracks: track candidate(0..): " << trackIndex << endl;
956019b6 1151 // Fit track candidate
1152 track->SetFitMCS(0); // without multiple Coulomb scattering
1153 track->SetFitNParam(3); // with 3 parameters (X = Y = 0)
1154 track->SetFitStart(0); // from parameters at vertex
1155 track->Fit();
a9e2aefa 1156 if (fPrintLevel >= 10) {
1157 cout << "FollowTracks: track candidate(0..): " << trackIndex
956019b6 1158 << " after fit in stations(0..) 3 and 4" << endl;
a9e2aefa 1159 track->RecursiveDump();
1160 }
1161 // Loop over stations(1..) 3, 2 and 1
04b5ea16 1162 // something SPECIAL for stations 2 and 1 for majority 3 coincidence ????
1163 // otherwise: majority coincidence 2 !!!!
a9e2aefa 1164 for (station = 2; station >= 0; station--) {
1165 // Track parameters at first track hit (smallest Z)
1166 trackParam1 = ((AliMUONTrackHit*)
1167 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
1168 // extrapolation to station
1169 trackParam1->ExtrapToStation(station, trackParam);
79e1e601 1170 extrapSegment = new AliMUONSegment(); // empty segment
d0bfce8d 1171 extrapCorrSegment = new AliMUONSegment(); // empty corrected segment
a9e2aefa 1172 // multiple scattering factor corresponding to one chamber
1173 // and momentum in bending plane (not total)
1174 mcsFactor = 0.0136 * trackParam1->GetInverseBendingMomentum();
1175 mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
1176 // Z difference from previous station
9cbdf048 1177 dZ1 = (&(pMUON->Chamber(2 * station)))->Z() -
1178 (&(pMUON->Chamber(2 * station + 2)))->Z();
a9e2aefa 1179 // Z difference between the two previous stations
9cbdf048 1180 dZ2 = (&(pMUON->Chamber(2 * station + 2)))->Z() -
1181 (&(pMUON->Chamber(2 * station + 4)))->Z();
04b5ea16 1182 // Z difference between the two chambers in the previous station
1183 dZ3 = (&(pMUON->Chamber(2 * station)))->Z() -
1184 (&(pMUON->Chamber(2 * station + 1)))->Z();
1185 extrapSegment->SetBendingCoorReso2(fBendingResolution * fBendingResolution);
1186 extrapSegment->
1187 SetNonBendingCoorReso2(fNonBendingResolution * fNonBendingResolution);
1188 extrapSegment->UpdateFromStationTrackParam
1189 (trackParam, mcsFactor, dZ1, dZ2, dZ3, station,
1190 trackParam1->GetInverseBendingMomentum());
d0bfce8d 1191 // same thing for corrected segment
1192 // better to use copy constructor, after checking that it works properly !!!!
1193 extrapCorrSegment->SetBendingCoorReso2(fBendingResolution * fBendingResolution);
1194 extrapCorrSegment->
1195 SetNonBendingCoorReso2(fNonBendingResolution * fNonBendingResolution);
1196 extrapCorrSegment->UpdateFromStationTrackParam
1197 (trackParam, mcsFactor, dZ1, dZ2, dZ3, station,
1198 trackParam1->GetInverseBendingMomentum());
a9e2aefa 1199 bestChi2 = 5.0;
1200 bestSegment = NULL;
1201 if (fPrintLevel >= 10) {
1202 cout << "FollowTracks: track candidate(0..): " << trackIndex
1203 << " Look for segment in station(0..): " << station << endl;
1204 }
1205 // Loop over segments in station
1206 for (iSegment = 0; iSegment < fNSegments[station]; iSegment++) {
1207 // Look for best compatible Segment in station
1208 // should consider all possibilities ????
1209 // multiple scattering ????
1210 // separation in 2 functions: Segment and HitForRec ????
1211 segment = (AliMUONSegment*) ((*fSegmentsPtr[station])[iSegment]);
d0bfce8d 1212 // correction of corrected segment (fBendingCoor and fNonBendingCoor)
1213 // according to real Z value of "segment" and slopes of "extrapSegment"
1214 extrapCorrSegment->
1215 SetBendingCoor(extrapSegment->GetBendingCoor() +
1216 extrapSegment->GetBendingSlope() *
1217 (segment->GetHitForRec1()->GetZ() -
1218 (&(pMUON->Chamber(2 * station)))->Z()));
1219 extrapCorrSegment->
1220 SetNonBendingCoor(extrapSegment->GetNonBendingCoor() +
1221 extrapSegment->GetNonBendingSlope() *
1222 (segment->GetHitForRec1()->GetZ() -
1223 (&(pMUON->Chamber(2 * station)))->Z()));
1224 chi2 = segment->
1225 NormalizedChi2WithSegment(extrapCorrSegment, maxSigma2Distance);
a9e2aefa 1226 if (chi2 < bestChi2) {
1227 // update best Chi2 and Segment if better found
1228 bestSegment = segment;
1229 bestChi2 = chi2;
1230 }
1231 }
1232 if (bestSegment) {
1233 // best segment found: add it to track candidate
1234 track->AddSegment(bestSegment);
1235 // set track parameters at these two TrakHit's
1236 track->SetTrackParamAtHit(track->GetNTrackHits() - 2, &(trackParam[0]));
1237 track->SetTrackParamAtHit(track->GetNTrackHits() - 1, &(trackParam[1]));
1238 if (fPrintLevel >= 10) {
1239 cout << "FollowTracks: track candidate(0..): " << trackIndex
1240 << " Added segment in station(0..): " << station << endl;
1241 track->RecursiveDump();
1242 }
1243 }
1244 else {
1245 // No best segment found:
1246 // Look for best compatible HitForRec in station:
1247 // should consider all possibilities ????
1248 // multiple scattering ???? do about like for extrapSegment !!!!
79e1e601 1249 extrapHit = new AliMUONHitForRec(); // empty hit
d0bfce8d 1250 extrapCorrHit = new AliMUONHitForRec(); // empty corrected hit
a9e2aefa 1251 bestChi2 = 3.0;
1252 bestHit = NULL;
1253 if (fPrintLevel >= 10) {
1254 cout << "FollowTracks: track candidate(0..): " << trackIndex
1255 << " Segment not found, look for hit in station(0..): " << station
1256 << endl;
1257 }
1258 // Loop over chambers of the station
d82671a0 1259 for (chInStation = 0; chInStation < 2; chInStation++) {
a9e2aefa 1260 // coordinates of extrapolated hit
d82671a0 1261 extrapHit->
1262 SetBendingCoor((&(trackParam[chInStation]))->GetBendingCoor());
1263 extrapHit->
1264 SetNonBendingCoor((&(trackParam[chInStation]))->GetNonBendingCoor());
a9e2aefa 1265 // resolutions from "extrapSegment"
1266 extrapHit->SetBendingReso2(extrapSegment->GetBendingCoorReso2());
1267 extrapHit->SetNonBendingReso2(extrapSegment->GetNonBendingCoorReso2());
d0bfce8d 1268 // same things for corrected hit
1269 // better to use copy constructor, after checking that it works properly !!!!
1270 extrapCorrHit->
1271 SetBendingCoor((&(trackParam[chInStation]))->GetBendingCoor());
1272 extrapCorrHit->
1273 SetNonBendingCoor((&(trackParam[chInStation]))->GetNonBendingCoor());
1274 extrapHit->SetBendingReso2(extrapSegment->GetBendingCoorReso2());
1275 extrapHit->SetNonBendingReso2(extrapSegment->GetNonBendingCoorReso2());
a9e2aefa 1276 // Loop over hits in the chamber
956019b6 1277 ch = 2 * station + chInStation;
a9e2aefa 1278 for (iHit = fIndexOfFirstHitForRecPerChamber[ch];
1279 iHit < fIndexOfFirstHitForRecPerChamber[ch] +
1280 fNHitsForRecPerChamber[ch];
1281 iHit++) {
1282 hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[iHit]);
d0bfce8d 1283 // correction of corrected hit (fBendingCoor and fNonBendingCoor)
1284 // according to real Z value of "hit" and slopes of right "trackParam"
1285 extrapCorrHit->
1286 SetBendingCoor((&(trackParam[chInStation]))->GetBendingCoor() +
1287 (&(trackParam[chInStation]))->GetBendingSlope() *
1288 (hit->GetZ() -
1289 (&(trackParam[chInStation]))->GetZ()));
1290 extrapCorrHit->
1291 SetNonBendingCoor((&(trackParam[chInStation]))->GetNonBendingCoor() +
1292 (&(trackParam[chInStation]))->GetNonBendingSlope() *
1293 (hit->GetZ() -
1294 (&(trackParam[chInStation]))->GetZ()));
a9e2aefa 1295 // condition for hit not already in segment ????
1296 chi2 = hit->NormalizedChi2WithHitForRec(extrapHit, maxSigma2Distance);
1297 if (chi2 < bestChi2) {
1298 // update best Chi2 and HitForRec if better found
1299 bestHit = hit;
1300 bestChi2 = chi2;
d82671a0 1301 chBestHit = chInStation;
a9e2aefa 1302 }
1303 }
1304 }
1305 if (bestHit) {
1306 // best hit found: add it to track candidate
1307 track->AddHitForRec(bestHit);
956019b6 1308 // set track parameters at this TrackHit
a9e2aefa 1309 track->SetTrackParamAtHit(track->GetNTrackHits() - 1,
1310 &(trackParam[chBestHit]));
1311 if (fPrintLevel >= 10) {
1312 cout << "FollowTracks: track candidate(0..): " << trackIndex
1313 << " Added hit in station(0..): " << station << endl;
1314 track->RecursiveDump();
1315 }
1316 }
1317 else {
8429a5e4 1318 // Remove current track candidate
1319 // and corresponding TrackHit's, ...
1320 track->Remove();
04b5ea16 1321 delete extrapSegment;
d0bfce8d 1322 delete extrapCorrSegment;
1323 delete extrapHit;
1324 delete extrapCorrHit;
a9e2aefa 1325 break; // stop the search for this candidate:
1326 // exit from the loop over station
1327 }
d0bfce8d 1328 delete extrapHit;
1329 delete extrapCorrHit;
a9e2aefa 1330 }
04b5ea16 1331 delete extrapSegment;
d0bfce8d 1332 delete extrapCorrSegment;
a9e2aefa 1333 // Sort track hits according to increasing Z
1334 track->GetTrackHitsPtr()->Sort();
1335 // Update track parameters at first track hit (smallest Z)
1336 trackParam1 = ((AliMUONTrackHit*)
1337 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
d0bfce8d 1338 bendingMomentum = 0.;
1339 if (TMath::Abs(trackParam1->GetInverseBendingMomentum()) > 0.)
1340 bendingMomentum = TMath::Abs(1/(trackParam1->GetInverseBendingMomentum()));
1341 // Track removed if bendingMomentum not in window [min, max]
1342 if ((bendingMomentum < fMinBendingMomentum) || (bendingMomentum > fMaxBendingMomentum)) {
1343 track->Remove();
1344 break; // stop the search for this candidate:
1345 // exit from the loop over station
1346 }
956019b6 1347 // Track fit
04b5ea16 1348 // with multiple Coulomb scattering if all stations
1349 if (station == 0) track->SetFitMCS(1);
956019b6 1350 // without multiple Coulomb scattering if not all stations
04b5ea16 1351 else track->SetFitMCS(0);
956019b6 1352 track->SetFitNParam(5); // with 5 parameters (momentum and position)
1353 track->SetFitStart(1); // from parameters at first hit
1354 track->Fit();
d0bfce8d 1355 Double_t numberOfDegFree = (2.0 * track->GetNTrackHits() - 5);
1356 if (numberOfDegFree > 0) {
1357 chi2Norm = track->GetFitFMin() / numberOfDegFree;
1358 } else {
1359 chi2Norm = 1.e10;
1360 }
1361 // Track removed if normalized chi2 too high
1362 if (chi2Norm > fMaxChi2) {
1363 track->Remove();
1364 break; // stop the search for this candidate:
1365 // exit from the loop over station
1366 }
a9e2aefa 1367 if (fPrintLevel >= 10) {
1368 cout << "FollowTracks: track candidate(0..): " << trackIndex
1369 << " after fit from station(0..): " << station << " to 4" << endl;
1370 track->RecursiveDump();
1371 }
04b5ea16 1372 // Track extrapolation to the vertex through the absorber (Branson)
956019b6 1373 // after going through the first station
04b5ea16 1374 if (station == 0) {
1375 trackParamVertex = *trackParam1;
1376 (&trackParamVertex)->ExtrapToVertex();
1377 track->SetTrackParamAtVertex(&trackParamVertex);
6ae236ee 1378 if (fPrintLevel >= 1) {
1379 cout << "FollowTracks: track candidate(0..): " << trackIndex
1380 << " after extrapolation to vertex" << endl;
1381 track->RecursiveDump();
1382 }
04b5ea16 1383 }
a9e2aefa 1384 } // for (station = 2;...
04b5ea16 1385 // go really to next track
1386 track = nextTrack;
1387 } // while (track)
1388 // Compression of track array (necessary after Remove ????)
1389 fRecTracksPtr->Compress();
1390 return;
1391}
1392
1393 //__________________________________________________________________________
8429a5e4 1394void AliMUONEventReconstructor::RemoveDoubleTracks(void)
1395{
1396 // To remove double tracks.
1397 // Tracks are considered identical
1398 // if they have at least half of their hits in common.
1399 // Among two identical tracks, one keeps the track with the larger number of hits
1400 // or, if these numbers are equal, the track with the minimum Chi2.
1401 AliMUONTrack *track1, *track2, *trackToRemove;
1402 Bool_t identicalTracks;
1403 Int_t hitsInCommon, nHits1, nHits2;
1404 identicalTracks = kTRUE;
1405 while (identicalTracks) {
1406 identicalTracks = kFALSE;
1407 // Loop over first track of the pair
1408 track1 = (AliMUONTrack*) fRecTracksPtr->First();
1409 while (track1 && (!identicalTracks)) {
1410 nHits1 = track1->GetNTrackHits();
1411 // Loop over second track of the pair
1412 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
1413 while (track2 && (!identicalTracks)) {
1414 nHits2 = track2->GetNTrackHits();
1415 // number of hits in common between two tracks
1416 hitsInCommon = track1->HitsInCommon(track2);
1417 // check for identical tracks
1418 if ((4 * hitsInCommon) >= (nHits1 + nHits2)) {
1419 identicalTracks = kTRUE;
1420 // decide which track to remove
1421 if (nHits1 > nHits2) trackToRemove = track2;
1422 else if (nHits1 < nHits2) trackToRemove = track1;
1423 else if ((track1->GetFitFMin()) < (track2->GetFitFMin()))
1424 trackToRemove = track2;
1425 else trackToRemove = track1;
1426 // remove it
1427 trackToRemove->Remove();
1428 }
1429 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
1430 } // track2
1431 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
1432 } // track1
1433 }
1434 return;
1435}
1436
1437 //__________________________________________________________________________
04b5ea16 1438void AliMUONEventReconstructor::EventDump(void)
1439{
1440 // Dump reconstructed event (track parameters at vertex and at first hit),
1441 // and the particle parameters
1442
1443 AliMUONTrack *track;
1444 AliMUONTrackParam *trackParam, *trackParam1;
04b5ea16 1445 TParticle *p;
1446 Double_t bendingSlope, nonBendingSlope, pYZ;
1447 Double_t pX, pY, pZ, x, y, z, c;
1448 Int_t np, trackIndex, nTrackHits;
1449
1450 if (fPrintLevel >= 1) cout << "****** enter EventDump ******" << endl;
1451 if (fPrintLevel >= 1) {
1452 cout << " Number of Reconstructed tracks :" << fNRecTracks << endl;
1453 }
1454 fRecTracksPtr->Compress(); // for simple loop without "Next" since no hole
1455 // Loop over reconstructed tracks
1456 for (trackIndex = 0; trackIndex < fNRecTracks; trackIndex++) {
1457 if (fPrintLevel >= 1)
1458 cout << " track number: " << trackIndex << endl;
1459 // function for each track for modularity ????
1460 track = (AliMUONTrack*) ((*fRecTracksPtr)[trackIndex]);
1461 nTrackHits = track->GetNTrackHits();
1462 if (fPrintLevel >= 1)
1463 cout << " number of track hits: " << nTrackHits << endl;
1464 // track parameters at Vertex
1465 trackParam = track->GetTrackParamAtVertex();
1466 x = trackParam->GetNonBendingCoor();
1467 y = trackParam->GetBendingCoor();
1468 z = trackParam->GetZ();
1469 bendingSlope = trackParam->GetBendingSlope();
1470 nonBendingSlope = trackParam->GetNonBendingSlope();
1471 pYZ = 1/TMath::Abs(trackParam->GetInverseBendingMomentum());
1472 pZ = pYZ/TMath::Sqrt(1+bendingSlope*bendingSlope);
1473 pX = pZ * nonBendingSlope;
1474 pY = pZ * bendingSlope;
1475 c = TMath::Sign(1.0, trackParam->GetInverseBendingMomentum());
1476 if (fPrintLevel >= 1)
1477 printf(" track parameters at Vertex z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
1478 z, x, y, pX, pY, pZ, c);
1479
1480 // track parameters at first hit
1481 trackParam1 = ((AliMUONTrackHit*)
1482 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
1483 x = trackParam1->GetNonBendingCoor();
1484 y = trackParam1->GetBendingCoor();
1485 z = trackParam1->GetZ();
1486 bendingSlope = trackParam1->GetBendingSlope();
1487 nonBendingSlope = trackParam1->GetNonBendingSlope();
1488 pYZ = 1/TMath::Abs(trackParam1->GetInverseBendingMomentum());
1489 pZ = pYZ/TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
1490 pX = pZ * nonBendingSlope;
1491 pY = pZ * bendingSlope;
1492 c = TMath::Sign(1.0, trackParam1->GetInverseBendingMomentum());
1493 if (fPrintLevel >= 1)
1494 printf(" track parameters at z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
1495 z, x, y, pX, pY, pZ, c);
1496 }
1497 // informations about generated particles
2ab0c725 1498 np = gAlice->GetNtrack();
04b5ea16 1499 printf(" **** number of generated particles: %d \n", np);
1500
1501 for (Int_t iPart = 0; iPart < np; iPart++) {
2ab0c725 1502 p = gAlice->Particle(iPart);
04b5ea16 1503 printf(" particle %d: type= %d px= %f py= %f pz= %f pdg= %d\n",
1504 iPart, p->GetPdgCode(), p->Px(), p->Py(), p->Pz(), p->GetPdgCode());
1505 }
a9e2aefa 1506 return;
1507}
1508
c7ba256d 1509void AliMUONEventReconstructor::FillEvent()
1510{
1511// Create a new AliMUONRecoEvent, fill its track list, then add it as a
1512// leaf in the Event branch of TreeRecoEvent tree
1513 cout << "Enter FillEvent() ...\n";
1514
1515 if (!fRecoEvent) {
1516 fRecoEvent = new AliMUONRecoEvent();
1517 } else {
1518 fRecoEvent->Clear();
1519 }
1520 //save current directory
1521 TDirectory *current = gDirectory;
1522 if (!fTreeFile) fTreeFile = new TFile("tree_reco.root", "RECREATE");
1523 if (!fEventTree) fEventTree = new TTree("TreeRecoEvent", "MUON reconstructed events");
1524 if (fRecoEvent->MakeDumpTracks(fRecTracksPtr)) {
1525 if (fPrintLevel > 1) fRecoEvent->EventInfo();
1526 TBranch *branch = fEventTree->GetBranch("Event");
d0f40f23 1527 if (!branch) branch = fEventTree->Branch("Event", "AliMUONRecoEvent", &fRecoEvent, 64000);
c7ba256d 1528 branch->SetAutoDelete();
1529 fTreeFile->cd();
1530 fEventTree->Fill();
1531 fTreeFile->Write();
1532 }
1533 // restore directory
1534 current->cd();
1535}