]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONEventReconstructor.cxx
Code revision:
[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
88cb7938 16/* $Id$ */
a9e2aefa 17
3831f268 18////////////////////////////////////
a9e2aefa 19//
20// MUON event reconstructor in ALICE
21//
22// This class contains as data:
23// * the parameters for the event reconstruction
24// * a pointer to the array of hits to be reconstructed (the event)
25// * a pointer to the array of segments made with these hits inside each station
26// * a pointer to the array of reconstructed tracks
27//
28// It contains as methods, among others:
29// * MakeEventToBeReconstructed to build the array of hits to be reconstructed
30// * MakeSegments to build the segments
31// * MakeTracks to build the tracks
3831f268 32//
33////////////////////////////////////
a9e2aefa 34
30178c30 35#include <Riostream.h>
36#include <TDirectory.h>
37#include <TFile.h>
38#include <TMatrixD.h> //AZ
a9e2aefa 39
3831f268 40#include "AliMUONEventReconstructor.h"
30178c30 41#include "AliMUON.h"
42#include "AliMUONHit.h"
a9e2aefa 43#include "AliMUONHitForRec.h"
276c44b7 44#include "AliMUONTriggerTrack.h"
276c44b7 45#include "AliMUONTriggerCircuit.h"
a9e2aefa 46#include "AliMUONRawCluster.h"
276c44b7 47#include "AliMUONLocalTrigger.h"
52c9bc11 48#include "AliMUONGlobalTrigger.h"
3831f268 49#include "AliMUONRecoEvent.h"
50#include "AliMUONSegment.h"
a9e2aefa 51#include "AliMUONTrack.h"
a9e2aefa 52#include "AliMUONTrackHit.h"
94de3818 53#include "AliMagF.h"
3831f268 54#include "AliRun.h" // for gAlice
88cb7938 55#include "AliRunLoader.h"
56#include "AliLoader.h"
83dbc640 57#include "AliMUONTrackK.h" //AZ
5d12ce38 58#include "AliMC.h"
a9e2aefa 59
a9e2aefa 60//************* Defaults parameters for reconstruction
343146bf 61const Double_t AliMUONEventReconstructor::fgkDefaultMinBendingMomentum = 3.0;
62const Double_t AliMUONEventReconstructor::fgkDefaultMaxBendingMomentum = 500.0;
63const Double_t AliMUONEventReconstructor::fgkDefaultMaxChi2 = 100.0;
64const Double_t AliMUONEventReconstructor::fgkDefaultMaxSigma2Distance = 16.0;
65const Double_t AliMUONEventReconstructor::fgkDefaultBendingResolution = 0.01;
66const Double_t AliMUONEventReconstructor::fgkDefaultNonBendingResolution = 0.144;
67const Double_t AliMUONEventReconstructor::fgkDefaultChamberThicknessInX0 = 0.03;
a9e2aefa 68// Simple magnetic field:
69// Value taken from macro MUONtracking.C: 0.7 T, hence 7 kG
70// Length and Position from reco_muon.F, with opposite sign:
71// Length = ZMAGEND-ZCOIL
72// Position = (ZMAGEND+ZCOIL)/2
73// to be ajusted differently from real magnetic field ????
343146bf 74const Double_t AliMUONEventReconstructor::fgkDefaultSimpleBValue = 7.0;
75const Double_t AliMUONEventReconstructor::fgkDefaultSimpleBLength = 428.0;
76const Double_t AliMUONEventReconstructor::fgkDefaultSimpleBPosition = 1019.0;
77const Int_t AliMUONEventReconstructor::fgkDefaultRecGeantHits = 0;
78const Double_t AliMUONEventReconstructor::fgkDefaultEfficiency = 0.95;
a9e2aefa 79
343146bf 80const Int_t AliMUONEventReconstructor::fgkDefaultPrintLevel = -1;
a9e2aefa 81
82ClassImp(AliMUONEventReconstructor) // Class implementation in ROOT context
83
84 //__________________________________________________________________________
52c9bc11 85AliMUONEventReconstructor::AliMUONEventReconstructor(AliLoader* loader)
30178c30 86 : TObject()
a9e2aefa 87{
88 // Constructor for class AliMUONEventReconstructor
89 SetReconstructionParametersToDefaults();
83dbc640 90 fTrackMethod = 1; //AZ - tracking method (1-default, 2-Kalman)
a9e2aefa 91 // Memory allocation for the TClonesArray of hits for reconstruction
92 // Is 10000 the right size ????
93 fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
94 fNHitsForRec = 0; // really needed or GetEntriesFast sufficient ????
95 // Memory allocation for the TClonesArray's of segments in stations
96 // Is 2000 the right size ????
30178c30 97 for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++) {
a9e2aefa 98 fSegmentsPtr[st] = new TClonesArray("AliMUONSegment", 2000);
99 fNSegments[st] = 0; // really needed or GetEntriesFast sufficient ????
100 }
101 // Memory allocation for the TClonesArray of reconstructed tracks
102 // Is 10 the right size ????
103 fRecTracksPtr = new TClonesArray("AliMUONTrack", 10);
104 fNRecTracks = 0; // really needed or GetEntriesFast sufficient ????
276c44b7 105// trigger tracks
106 fRecTriggerTracksPtr = new TClonesArray("AliMUONTriggerTrack", 10);
107 fNRecTriggerTracks = 0; // really needed or GetEntriesFast sufficient ????
8429a5e4 108 // Memory allocation for the TClonesArray of hits on reconstructed tracks
109 // Is 100 the right size ????
110 fRecTrackHitsPtr = new TClonesArray("AliMUONTrack", 100);
111 fNRecTrackHits = 0; // really needed or GetEntriesFast sufficient ????
a9e2aefa 112
5b64e914 113 // Sign of fSimpleBValue according to sign of Bx value at (50,50,-950).
a6f03ddb 114 Float_t b[3], x[3];
5b64e914 115 x[0] = 50.; x[1] = 50.; x[2] = -950.;
a6f03ddb 116 gAlice->Field()->Field(x, b);
065bd0e1 117 fSimpleBValue = TMath::Sign(fSimpleBValue,(Double_t) b[0]);
5b64e914 118 fSimpleBPosition = TMath::Sign(fSimpleBPosition,(Double_t) x[2]);
a6f03ddb 119 // See how to get fSimple(BValue, BLength, BPosition)
120 // automatically calculated from the actual magnetic field ????
a9e2aefa 121
122 if (fPrintLevel >= 0) {
a6f03ddb 123 cout << "AliMUONEventReconstructor constructed with defaults" << endl; Dump();
124 cout << endl << "Magnetic field from root file:" << endl;
125 gAlice->Field()->Dump();
126 cout << endl;
127 }
c7ba256d 128
47a6b602 129 // Initializions for GEANT background events
130 fBkgGeantFile = 0;
131 fBkgGeantTK = 0;
132 fBkgGeantParticles = 0;
133 fBkgGeantTH = 0;
134 fBkgGeantHits = 0;
135 fBkgGeantEventNumber = -1;
136
c7ba256d 137 // Initialize to 0 pointers to RecoEvent, tree and tree file
138 fRecoEvent = 0;
139 fEventTree = 0;
140 fTreeFile = 0;
52c9bc11 141
142 // initialize loader's
143 fLoader = loader;
144
145 // initialize container
146 fMUONData = new AliMUONData(fLoader,"MUON","MUON");
147
148 // Loading AliRun master
149 AliRunLoader* runloader = fLoader->GetRunLoader();
150 if (runloader->GetAliRun() == 0x0) runloader->LoadgAlice();
151 gAlice = runloader->GetAliRun();
152
a9e2aefa 153 return;
154}
52c9bc11 155 //__________________________________________________________________________
30178c30 156AliMUONEventReconstructor::AliMUONEventReconstructor (const AliMUONEventReconstructor& rhs)
157 : TObject(rhs)
9cbdf048 158{
30178c30 159// Protected copy constructor
160
161 Fatal("AliMUONEventReconstructor", "Not implemented.");
9cbdf048 162}
163
30178c30 164AliMUONEventReconstructor &
165AliMUONEventReconstructor::operator=(const AliMUONEventReconstructor& rhs)
9cbdf048 166{
30178c30 167// Protected assignement operator
168
169 if (this == &rhs) return *this;
170
171 Fatal("operator=", "Not implemented.");
172
173 return *this;
9cbdf048 174}
175
a9e2aefa 176 //__________________________________________________________________________
177AliMUONEventReconstructor::~AliMUONEventReconstructor(void)
178{
179 // Destructor for class AliMUONEventReconstructor
c7ba256d 180 if (fTreeFile) {
181 fTreeFile->Close();
182 delete fTreeFile;
183 }
184// if (fEventTree) delete fEventTree;
185 if (fRecoEvent) delete fRecoEvent;
a9e2aefa 186 delete fHitsForRecPtr; // Correct destruction of everything ???? or delete [] ????
30178c30 187 for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++)
a9e2aefa 188 delete fSegmentsPtr[st]; // Correct destruction of everything ????
189 return;
190}
191
192 //__________________________________________________________________________
193void AliMUONEventReconstructor::SetReconstructionParametersToDefaults(void)
194{
195 // Set reconstruction parameters to default values
196 // Would be much more convenient with a structure (or class) ????
343146bf 197 fMinBendingMomentum = fgkDefaultMinBendingMomentum;
198 fMaxBendingMomentum = fgkDefaultMaxBendingMomentum;
199 fMaxChi2 = fgkDefaultMaxChi2;
200 fMaxSigma2Distance = fgkDefaultMaxSigma2Distance;
a9e2aefa 201
9cbdf048 202 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON");
a9e2aefa 203 // ******** Parameters for making HitsForRec
204 // minimum radius,
205 // like in TRACKF_STAT:
206 // 2 degrees for stations 1 and 2, or ch(0...) from 0 to 3;
207 // 30 cm for stations 3 to 5, or ch(0...) from 4 to 9
343146bf 208 for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
9cbdf048 209 if (ch < 4) fRMin[ch] = TMath::Abs((&(pMUON->Chamber(ch)))->Z()) *
a9e2aefa 210 2.0 * TMath::Pi() / 180.0;
211 else fRMin[ch] = 30.0;
d0bfce8d 212 // maximum radius at 10 degrees and Z of chamber
213 fRMax[ch] = TMath::Abs((&(pMUON->Chamber(ch)))->Z()) *
214 10.0 * TMath::Pi() / 180.0;
a9e2aefa 215 }
a9e2aefa 216
217 // ******** Parameters for making segments
218 // should be parametrized ????
219 // according to interval between chambers in a station ????
220 // Maximum distance in non bending plane
221 // 5 * 0.22 just to remember the way it was made in TRACKF_STAT
222 // SIGCUT*DYMAX(IZ)
30178c30 223 for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++)
a9e2aefa 224 fSegmentMaxDistNonBending[st] = 5. * 0.22;
860cef81 225 // Maximum distance in bending plane:
226 // values from TRACKF_STAT, corresponding to (J psi 20cm),
227 // scaled to the real distance between chambers in a station
ef21c79e 228 fSegmentMaxDistBending[0] = TMath::Abs( 1.5 *
229 ((&(pMUON->Chamber(1)))->Z() - (&(pMUON->Chamber(0)))->Z()) / 20.0);
230 fSegmentMaxDistBending[1] = TMath::Abs( 1.5 *
231 ((&(pMUON->Chamber(3)))->Z() - (&(pMUON->Chamber(2)))->Z()) / 20.0);
232 fSegmentMaxDistBending[2] = TMath::Abs( 3.0 *
233 ((&(pMUON->Chamber(5)))->Z() - (&(pMUON->Chamber(4)))->Z()) / 20.0);
234 fSegmentMaxDistBending[3] = TMath::Abs( 6.0 *
235 ((&(pMUON->Chamber(7)))->Z() - (&(pMUON->Chamber(6)))->Z()) / 20.0);
236 fSegmentMaxDistBending[4] = TMath::Abs( 6.0 *
237 ((&(pMUON->Chamber(9)))->Z() - (&(pMUON->Chamber(8)))->Z()) / 20.0);
a9e2aefa 238
343146bf 239 fBendingResolution = fgkDefaultBendingResolution;
240 fNonBendingResolution = fgkDefaultNonBendingResolution;
241 fChamberThicknessInX0 = fgkDefaultChamberThicknessInX0;
242 fSimpleBValue = fgkDefaultSimpleBValue;
243 fSimpleBLength = fgkDefaultSimpleBLength;
244 fSimpleBPosition = fgkDefaultSimpleBPosition;
245 fRecGeantHits = fgkDefaultRecGeantHits;
246 fEfficiency = fgkDefaultEfficiency;
247 fPrintLevel = fgkDefaultPrintLevel;
a9e2aefa 248 return;
249}
250
251//__________________________________________________________________________
3831f268 252Double_t AliMUONEventReconstructor::GetImpactParamFromBendingMomentum(Double_t BendingMomentum) const
a9e2aefa 253{
254 // Returns impact parameter at vertex in bending plane (cm),
255 // from the signed bending momentum "BendingMomentum" in bending plane (GeV/c),
256 // using simple values for dipole magnetic field.
065bd0e1 257 // The sign of "BendingMomentum" is the sign of the charge.
a9e2aefa 258 return (-0.0003 * fSimpleBValue * fSimpleBLength * fSimpleBPosition /
259 BendingMomentum);
260}
261
262//__________________________________________________________________________
3831f268 263Double_t AliMUONEventReconstructor::GetBendingMomentumFromImpactParam(Double_t ImpactParam) const
a9e2aefa 264{
265 // Returns signed bending momentum in bending plane (GeV/c),
065bd0e1 266 // the sign being the sign of the charge for particles moving forward in Z,
a9e2aefa 267 // from the impact parameter "ImpactParam" at vertex in bending plane (cm),
268 // using simple values for dipole magnetic field.
a9e2aefa 269 return (-0.0003 * fSimpleBValue * fSimpleBLength * fSimpleBPosition /
270 ImpactParam);
271}
272
273//__________________________________________________________________________
274void AliMUONEventReconstructor::SetBkgGeantFile(Text_t *BkgGeantFileName)
275{
276 // Set background file ... for GEANT hits
277 // Must be called after having loaded the firts signal event
278 if (fPrintLevel >= 0) {
279 cout << "Enter SetBkgGeantFile with BkgGeantFileName ``"
280 << BkgGeantFileName << "''" << endl;}
281 if (strlen(BkgGeantFileName)) {
282 // BkgGeantFileName not empty: try to open the file
283 if (fPrintLevel >= 2) {cout << "Before File(Bkg)" << endl; gDirectory->Dump();}
284 fBkgGeantFile = new TFile(BkgGeantFileName);
285 if (fPrintLevel >= 2) {cout << "After File(Bkg)" << endl; gDirectory->Dump();}
286 if (fBkgGeantFile-> IsOpen()) {
287 if (fPrintLevel >= 0) {
288 cout << "Background for GEANT hits in file: ``" << BkgGeantFileName
289 << "'' successfully opened" << endl;}
290 }
291 else {
292 cout << "Background for GEANT hits in file: " << BkgGeantFileName << endl;
293 cout << "NOT FOUND: EXIT" << endl;
294 exit(0); // right instruction for exit ????
295 }
296 // Arrays for "particles" and "hits"
297 fBkgGeantParticles = new TClonesArray("TParticle", 200);
298 fBkgGeantHits = new TClonesArray("AliMUONHit", 2000);
299 // Event number to -1 for initialization
300 fBkgGeantEventNumber = -1;
301 // Back to the signal file:
302 // first signal event must have been loaded previously,
303 // otherwise, Segmentation violation at the next instruction
304 // How is it possible to do smething better ????
305 ((gAlice->TreeK())->GetCurrentFile())->cd();
306 if (fPrintLevel >= 2) {cout << "After cd(gAlice)" << endl; gDirectory->Dump();}
307 }
308 return;
309}
310
311//__________________________________________________________________________
312void AliMUONEventReconstructor::NextBkgGeantEvent(void)
313{
314 // Get next event in background file for GEANT hits
315 // Goes back to event number 0 when end of file is reached
316 char treeName[20];
317 TBranch *branch;
318 if (fPrintLevel >= 0) {
319 cout << "Enter NextBkgGeantEvent" << endl;}
320 // Clean previous event
321 if(fBkgGeantTK) delete fBkgGeantTK;
322 fBkgGeantTK = NULL;
323 if(fBkgGeantParticles) fBkgGeantParticles->Clear();
324 if(fBkgGeantTH) delete fBkgGeantTH;
325 fBkgGeantTH = NULL;
326 if(fBkgGeantHits) fBkgGeantHits->Clear();
327 // Increment event number
328 fBkgGeantEventNumber++;
329 // Get access to Particles and Hits for event from background file
330 if (fPrintLevel >= 2) {cout << "Before cd(Bkg)" << endl; gDirectory->Dump();}
331 fBkgGeantFile->cd();
332 if (fPrintLevel >= 2) {cout << "After cd(Bkg)" << endl; gDirectory->Dump();}
333 // Particles: TreeK for event and branch "Particles"
334 sprintf(treeName, "TreeK%d", fBkgGeantEventNumber);
335 fBkgGeantTK = (TTree*)gDirectory->Get(treeName);
336 if (!fBkgGeantTK) {
337 if (fPrintLevel >= 0) {
338 cout << "Cannot find Kine Tree for background event: " <<
339 fBkgGeantEventNumber << endl;
340 cout << "Goes back to event 0" << endl;
341 }
342 fBkgGeantEventNumber = 0;
343 sprintf(treeName, "TreeK%d", fBkgGeantEventNumber);
344 fBkgGeantTK = (TTree*)gDirectory->Get(treeName);
345 if (!fBkgGeantTK) {
346 cout << "ERROR: cannot find Kine Tree for background event: " <<
347 fBkgGeantEventNumber << endl;
348 exit(0);
349 }
350 }
351 if (fBkgGeantTK)
352 fBkgGeantTK->SetBranchAddress("Particles", &fBkgGeantParticles);
353 fBkgGeantTK->GetEvent(0); // why event 0 ???? necessary ????
354 // Hits: TreeH for event and branch "MUON"
355 sprintf(treeName, "TreeH%d", fBkgGeantEventNumber);
356 fBkgGeantTH = (TTree*)gDirectory->Get(treeName);
357 if (!fBkgGeantTH) {
358 cout << "ERROR: cannot find Hits Tree for background event: " <<
359 fBkgGeantEventNumber << endl;
360 exit(0);
361 }
362 if (fBkgGeantTH && fBkgGeantHits) {
363 branch = fBkgGeantTH->GetBranch("MUON");
364 if (branch) branch->SetAddress(&fBkgGeantHits);
365 }
366 fBkgGeantTH->GetEntries(); // necessary ????
367 // Back to the signal file
368 ((gAlice->TreeK())->GetCurrentFile())->cd();
369 if (fPrintLevel >= 2) {cout << "After cd(gAlice)" << endl; gDirectory->Dump();}
370 return;
371}
372
373//__________________________________________________________________________
374void AliMUONEventReconstructor::EventReconstruct(void)
375{
376 // To reconstruct one event
377 if (fPrintLevel >= 1) cout << "enter EventReconstruct" << endl;
378 MakeEventToBeReconstructed();
379 MakeSegments();
380 MakeTracks();
d837040f 381 if (fMUONData->IsTriggerTrackBranchesInTree())
382 ValidateTracksWithTrigger();
383
384 // Add tracks to MUON data container
385 for(Int_t i=0; i<GetNRecTracks(); i++) {
386 AliMUONTrack * track = (AliMUONTrack*) GetRecTracksPtr()->At(i);
387 fMUONData->AddRecTrack(*track);
388 }
389
a9e2aefa 390 return;
391}
392
276c44b7 393//__________________________________________________________________________
394void AliMUONEventReconstructor::EventReconstructTrigger(void)
395{
396 // To reconstruct one event
397 if (fPrintLevel >= 1) cout << "enter EventReconstructTrigger" << endl;
398 MakeTriggerTracks();
399 return;
400}
401
a9e2aefa 402 //__________________________________________________________________________
403void AliMUONEventReconstructor::ResetHitsForRec(void)
404{
405 // To reset the array and the number of HitsForRec,
406 // and also the number of HitsForRec
407 // and the index of the first HitForRec per chamber
408 if (fHitsForRecPtr) fHitsForRecPtr->Clear();
409 fNHitsForRec = 0;
343146bf 410 for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++)
a9e2aefa 411 fNHitsForRecPerChamber[ch] = fIndexOfFirstHitForRecPerChamber[ch] = 0;
412 return;
413}
414
415 //__________________________________________________________________________
416void AliMUONEventReconstructor::ResetSegments(void)
417{
418 // To reset the TClonesArray of segments and the number of Segments
419 // for all stations
30178c30 420 for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++) {
a9e2aefa 421 if (fSegmentsPtr[st]) fSegmentsPtr[st]->Clear();
422 fNSegments[st] = 0;
423 }
424 return;
425}
426
427 //__________________________________________________________________________
428void AliMUONEventReconstructor::ResetTracks(void)
429{
430 // To reset the TClonesArray of reconstructed tracks
8429a5e4 431 if (fRecTracksPtr) fRecTracksPtr->Delete();
432 // Delete in order that the Track destructors are called,
433 // hence the space for the TClonesArray of pointers to TrackHit's is freed
a9e2aefa 434 fNRecTracks = 0;
435 return;
436}
437
276c44b7 438 //__________________________________________________________________________
439void AliMUONEventReconstructor::ResetTriggerTracks(void)
440{
441 // To reset the TClonesArray of reconstructed trigger tracks
442 if (fRecTriggerTracksPtr) fRecTriggerTracksPtr->Delete();
443 // Delete in order that the Track destructors are called,
444 // hence the space for the TClonesArray of pointers to TrackHit's is freed
445 fNRecTriggerTracks = 0;
446 return;
447}
448
8429a5e4 449 //__________________________________________________________________________
450void AliMUONEventReconstructor::ResetTrackHits(void)
451{
452 // To reset the TClonesArray of hits on reconstructed tracks
453 if (fRecTrackHitsPtr) fRecTrackHitsPtr->Clear();
454 fNRecTrackHits = 0;
455 return;
456}
457
a9e2aefa 458 //__________________________________________________________________________
459void AliMUONEventReconstructor::MakeEventToBeReconstructed(void)
460{
461 // To make the list of hits to be reconstructed,
462 // either from the GEANT hits or from the raw clusters
463 // according to the parameter set for the reconstructor
e191bb57 464// TString evfoldname = AliConfig::GetDefaultEventFolderName();//to be interfaced properly
88cb7938 465
52c9bc11 466// AliRunLoader* rl = AliRunLoader::GetRunLoader(evfoldname);
467// if (rl == 0x0)
468// {
469// Error("MakeEventToBeReconstructed",
470// "Can not find Run Loader in Event Folder named %s.",
471// evfoldname.Data());
472// return;
473// }
474// AliLoader* gime = rl->GetLoader("MUONLoader");
475// if (gime == 0x0)
476// {
477// Error("MakeEventToBeReconstructed","Can not get MUON Loader from Run Loader.");
478// return;
479// }
88cb7938 480
a9e2aefa 481 if (fPrintLevel >= 1) cout << "enter MakeEventToBeReconstructed" << endl;
482 ResetHitsForRec();
483 if (fRecGeantHits == 1) {
484 // Reconstruction from GEANT hits
485 // Back to the signal file
52c9bc11 486 TTree* treeH = fLoader->TreeH();
88cb7938 487 if (treeH == 0x0)
488 {
52c9bc11 489 Int_t retval = fLoader->LoadHits();
88cb7938 490 if ( retval)
491 {
492 Error("MakeEventToBeReconstructed","Error occured while loading hits.");
493 return;
494 }
52c9bc11 495 treeH = fLoader->TreeH();
88cb7938 496 if (treeH == 0x0)
497 {
498 Error("MakeEventToBeReconstructed","Can not get TreeH");
499 return;
500 }
501 }
52c9bc11 502 fMUONData->SetTreeAddress("H");
503 AddHitsForRecFromGEANT(treeH);
88cb7938 504
a9e2aefa 505 // Background hits
506 AddHitsForRecFromBkgGEANT(fBkgGeantTH, fBkgGeantHits);
507 // Sort HitsForRec in increasing order with respect to chamber number
508 SortHitsForRecWithIncreasingChamber();
509 }
510 else {
511 // Reconstruction from raw clusters
512 // AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
513 // Security on MUON ????
514 // TreeR assumed to be be "prepared" in calling function
515 // by "MUON->GetTreeR(nev)" ????
52c9bc11 516 TTree *treeR = fLoader->TreeR();
517 fMUONData->SetTreeAddress("RC");
9cbdf048 518 AddHitsForRecFromRawClusters(treeR);
a9e2aefa 519 // No sorting: it is done automatically in the previous function
520 }
521 if (fPrintLevel >= 10) {
522 cout << "end of MakeEventToBeReconstructed" << endl;
523 cout << "NHitsForRec: " << fNHitsForRec << endl;
343146bf 524 for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
a9e2aefa 525 cout << "chamber(0...): " << ch
526 << " NHitsForRec: " << fNHitsForRecPerChamber[ch]
527 << " index(first HitForRec): " << fIndexOfFirstHitForRecPerChamber[ch]
528 << endl;
529 for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
530 hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
531 hit++) {
532 cout << "HitForRec index(0...): " << hit << endl;
533 ((*fHitsForRecPtr)[hit])->Dump();
534 }
535 }
536 }
537 return;
538}
539
540 //__________________________________________________________________________
541void AliMUONEventReconstructor::AddHitsForRecFromGEANT(TTree *TH)
542{
543 // To add to the list of hits for reconstruction
544 // the GEANT signal hits from a hit tree TH.
83dbc640 545 Int_t hitBits, chamBits; //AZ
a9e2aefa 546 if (fPrintLevel >= 2)
547 cout << "enter AddHitsForRecFromGEANT with TH: " << TH << endl;
548 if (TH == NULL) return;
52c9bc11 549 // AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
550 //AliMUONData * muondata = pMUON->GetMUONData();
a9e2aefa 551 // Security on MUON ????
552 // See whether it could be the same for signal and background ????
553 // Loop over tracks in tree
554 Int_t ntracks = (Int_t) TH->GetEntries();
555 if (fPrintLevel >= 2)
556 cout << "ntracks: " << ntracks << endl;
83dbc640 557 fMuons = 0; //AZ
a9e2aefa 558 for (Int_t track = 0; track < ntracks; track++) {
52c9bc11 559 fMUONData->ResetHits();
a9e2aefa 560 TH->GetEvent(track);
561 // Loop over hits
562 Int_t hit = 0;
83dbc640 563 hitBits = 0; // AZ
564 chamBits = 0; // AZ
565 Int_t itrack = track; //AZ
38302c61 566
567 Int_t ihit, nhits=0;
52c9bc11 568 nhits = (Int_t) fMUONData->Hits()->GetEntriesFast();
38302c61 569 AliMUONHit* mHit=0x0;
1391e633 570
38302c61 571 for(ihit=0; ihit<nhits; ihit++) {
52c9bc11 572 mHit = static_cast<AliMUONHit*>(fMUONData->Hits()->At(ihit));
38302c61 573 Int_t ipart = TMath::Abs ((Int_t) mHit->Particle()); //AZ
574 if (NewHitForRecFromGEANT(mHit,track, hit, 1) && ipart == 13
575 //if (NewHitForRecFromGEANT(mHit,itrack-1, hit, 1) && ipart == 13
1391e633 576 && itrack <= 2 && !BIT(mHit->Chamber()-1) ) chamBits |= BIT(mHit->Chamber()-1); //AZ - set bit
38302c61 577 }
1391e633 578
83dbc640 579 if (chamBits&3 && chamBits>>2&3 && chamBits>>4&3 && chamBits>>6&3 &&
580 chamBits>>8&3 && ((chamBits>>6&3)==3 || (chamBits>>8&3)==3))
581 fMuons += 1; //AZ
582 //if (chamBits&3 && chamBits>>2&3 && chamBits>>4&3 && chamBits>>6&3 &&
583 // chamBits>>8&3 && ((chamBits>>6&3)==3 || (chamBits>>8&3)==3) &&
584 // ((chamBits&3)==3 || (chamBits>>2&3)==3)) fMuons += 1;
a9e2aefa 585 } // end of track loop
586 return;
587}
588
589 //__________________________________________________________________________
590void AliMUONEventReconstructor::AddHitsForRecFromBkgGEANT(TTree *TH, TClonesArray *Hits)
591{
592 // To add to the list of hits for reconstruction
593 // the GEANT background hits from a hit tree TH and a pointer Hits to a hit list.
594 // How to have only one function "AddHitsForRecFromGEANT" ????
595 if (fPrintLevel >= 2)
596 cout << "enter AddHitsForRecFromBkgGEANT with TH: " << TH << endl;
597 if (TH == NULL) return;
598 // Loop over tracks in tree
599 Int_t ntracks = (Int_t) TH->GetEntries();
600 if (fPrintLevel >= 2)
601 cout << "ntracks: " << ntracks << endl;
602 for (Int_t track = 0; track < ntracks; track++) {
603 if (Hits) Hits->Clear();
604 TH->GetEvent(track);
605 // Loop over hits
606 for (Int_t hit = 0; hit < Hits->GetEntriesFast(); hit++) {
607 NewHitForRecFromGEANT((AliMUONHit*) (*Hits)[hit], track, hit, 0);
608 } // end of hit loop
609 } // end of track loop
610 return;
611}
612
613 //__________________________________________________________________________
614AliMUONHitForRec* AliMUONEventReconstructor::NewHitForRecFromGEANT(AliMUONHit* Hit, Int_t TrackNumber, Int_t HitNumber, Int_t Signal)
615{
616 // To make a new hit for reconstruction from a GEANT hit pointed to by "Hit",
617 // with hit number "HitNumber" in the track numbered "TrackNumber",
618 // either from signal ("Signal" = 1) or background ("Signal" = 0) event.
619 // Selects hits in tracking (not trigger) chambers.
620 // Takes into account the efficiency (fEfficiency)
621 // and the smearing from resolution (fBendingResolution and fNonBendingResolution).
622 // Adds a condition on the radius between RMin and RMax
623 // to better simulate the real chambers.
624 // Returns the pointer to the new hit for reconstruction,
625 // or NULL in case of inefficiency or non tracking chamber or bad radius.
626 // No condition on at most 20 cm from a muon from a resonance
627 // like in Fortran TRACKF_STAT.
628 AliMUONHitForRec* hitForRec;
629 Double_t bendCoor, nonBendCoor, radius;
0a5f36d9 630 Int_t chamber = Hit->Chamber() - 1; // chamber(0...)
a9e2aefa 631 // only in tracking chambers (fChamber starts at 1)
343146bf 632 if (chamber >= fgkMaxMuonTrackingChambers) return NULL;
a9e2aefa 633 // only if hit is efficient (keep track for checking ????)
634 if (gRandom->Rndm() > fEfficiency) return NULL;
635 // only if radius between RMin and RMax
94de3818 636 bendCoor = Hit->Y();
637 nonBendCoor = Hit->X();
a9e2aefa 638 radius = TMath::Sqrt((bendCoor * bendCoor) + (nonBendCoor * nonBendCoor));
d0bfce8d 639 // This cut is not needed with a realistic chamber geometry !!!!
640// if ((radius < fRMin[chamber]) || (radius > fRMax[chamber])) return NULL;
a9e2aefa 641 // new AliMUONHitForRec from GEANT hit and increment number of AliMUONHitForRec's
642 hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(Hit);
643 fNHitsForRec++;
644 // add smearing from resolution
645 hitForRec->SetBendingCoor(bendCoor + gRandom->Gaus(0., fBendingResolution));
646 hitForRec->SetNonBendingCoor(nonBendCoor
647 + gRandom->Gaus(0., fNonBendingResolution));
d0bfce8d 648// // !!!! without smearing
649// hitForRec->SetBendingCoor(bendCoor);
650// hitForRec->SetNonBendingCoor(nonBendCoor);
a9e2aefa 651 // more information into HitForRec
652 // resolution: angular effect to be added here ????
653 hitForRec->SetBendingReso2(fBendingResolution * fBendingResolution);
654 hitForRec->SetNonBendingReso2(fNonBendingResolution * fNonBendingResolution);
655 // GEANT track info
656 hitForRec->SetHitNumber(HitNumber);
657 hitForRec->SetTHTrack(TrackNumber);
658 hitForRec->SetGeantSignal(Signal);
659 if (fPrintLevel >= 10) {
660 cout << "track: " << TrackNumber << " hit: " << HitNumber << endl;
661 Hit->Dump();
662 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
663 hitForRec->Dump();}
664 return hitForRec;
665}
666
667 //__________________________________________________________________________
668void AliMUONEventReconstructor::SortHitsForRecWithIncreasingChamber()
669{
670 // Sort HitsForRec's in increasing order with respect to chamber number.
671 // Uses the function "Compare".
672 // Update the information for HitsForRec per chamber too.
673 Int_t ch, nhits, prevch;
674 fHitsForRecPtr->Sort();
343146bf 675 for (ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
a9e2aefa 676 fNHitsForRecPerChamber[ch] = 0;
677 fIndexOfFirstHitForRecPerChamber[ch] = 0;
678 }
679 prevch = 0; // previous chamber
680 nhits = 0; // number of hits in current chamber
681 // Loop over HitsForRec
682 for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
683 // chamber number (0...)
684 ch = ((AliMUONHitForRec*) ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
685 // increment number of hits in current chamber
686 (fNHitsForRecPerChamber[ch])++;
687 // update index of first HitForRec in current chamber
688 // if chamber number different from previous one
689 if (ch != prevch) {
690 fIndexOfFirstHitForRecPerChamber[ch] = hit;
691 prevch = ch;
692 }
693 }
694 return;
695}
696
697// //__________________________________________________________________________
698// void AliMUONEventReconstructor::AddHitsForRecFromCathodeCorrelations(TTree* TC)
699// {
700// // OLD VERSION WHEN ONE ONE WAS USING SO CALLED CATHODE CORRELATIONS
701// // To add to the list of hits for reconstruction
702// // the (cathode correlated) raw clusters
703// // No condition added, like in Fortran TRACKF_STAT,
704// // on the radius between RMin and RMax.
705// AliMUONHitForRec *hitForRec;
706// if (fPrintLevel >= 1) cout << "enter AddHitsForRecFromCathodeCorrelations" << endl;
707// AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
708// // Security on MUON ????
709// // Loop over tracking chambers
343146bf 710// for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
a9e2aefa 711// // number of HitsForRec to 0 for the chamber
712// fNHitsForRecPerChamber[ch] = 0;
713// // index of first HitForRec for the chamber
714// if (ch == 0) fIndexOfFirstHitForRecPerChamber[ch] = 0;
715// else fIndexOfFirstHitForRecPerChamber[ch] = fNHitsForRec;
716// TClonesArray *reconst_hits = MUON->ReconstHitsAddress(ch);
717// MUON->ResetReconstHits();
718// TC->GetEvent();
719// Int_t ncor = (Int_t)reconst_hits->GetEntries();
720// // Loop over (cathode correlated) raw clusters
721// for (Int_t cor = 0; cor < ncor; cor++) {
722// AliMUONReconstHit * mCor =
723// (AliMUONReconstHit*) reconst_hits->UncheckedAt(cor);
724// // new AliMUONHitForRec from (cathode correlated) raw cluster
725// // and increment number of AliMUONHitForRec's (total and in chamber)
726// hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(mCor);
727// fNHitsForRec++;
728// (fNHitsForRecPerChamber[ch])++;
729// // more information into HitForRec
730// hitForRec->SetChamberNumber(ch);
731// hitForRec->SetHitNumber(cor);
732// // Z coordinate of the chamber (cm) with sign opposite to GEANT sign
733// // could (should) be more exact from chamber geometry ????
734// hitForRec->SetZ(-(&(MUON->Chamber(ch)))->Z());
735// if (fPrintLevel >= 10) {
736// cout << "chamber (0...): " << ch <<
737// " cathcorrel (0...): " << cor << endl;
738// mCor->Dump();
739// cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
740// hitForRec->Dump();}
741// } // end of cluster loop
742// } // end of chamber loop
743// return;
744// }
745
746 //__________________________________________________________________________
747void AliMUONEventReconstructor::AddHitsForRecFromRawClusters(TTree* TR)
748{
749 // To add to the list of hits for reconstruction all the raw clusters
750 // No condition added, like in Fortran TRACKF_STAT,
751 // on the radius between RMin and RMax.
752 AliMUONHitForRec *hitForRec;
753 AliMUONRawCluster *clus;
f69d51b5 754 Int_t iclus, nclus, nTRentries;
a9e2aefa 755 TClonesArray *rawclusters;
756 if (fPrintLevel >= 1) cout << "enter AddHitsForRecFromRawClusters" << endl;
88cb7938 757
e191bb57 758// TString evfoldname = AliConfig::GetDefaultEventFolderName();//to be interfaced properly
52c9bc11 759// AliRunLoader* rl = AliRunLoader::GetRunLoader(evfoldname);
760// if (rl == 0x0)
761// {
762// Error("MakeEventToBeReconstructed",
763// "Can not find Run Loader in Event Folder named %s.",
764// evfoldname.Data());
765// return;
766// }
767// AliLoader* gime = rl->GetLoader("MUONLoader");
768// if (gime == 0x0)
769// {
770// Error("MakeEventToBeReconstructed","Can not get MUON Loader from Run Loader.");
771// return;
772// }
773// // Loading AliRun master
774// rl->LoadgAlice();
775// gAlice = rl->GetAliRun();
88cb7938 776
777 // Loading MUON subsystem
52c9bc11 778 // AliMUON * pMUON = (AliMUON *) gAlice->GetDetector("MUON");
88cb7938 779
f69d51b5 780 nTRentries = Int_t(TR->GetEntries());
781 if (nTRentries != 1) {
782 cout << "Error in AliMUONEventReconstructor::AddHitsForRecFromRawClusters"
783 << endl;
784 cout << "nTRentries = " << nTRentries << " not equal to 1" << endl;
785 exit(0);
786 }
52c9bc11 787 fLoader->TreeR()->GetEvent(0); // only one entry
788
a9e2aefa 789 // Loop over tracking chambers
343146bf 790 for (Int_t ch = 0; ch < fgkMaxMuonTrackingChambers; ch++) {
a9e2aefa 791 // number of HitsForRec to 0 for the chamber
792 fNHitsForRecPerChamber[ch] = 0;
793 // index of first HitForRec for the chamber
794 if (ch == 0) fIndexOfFirstHitForRecPerChamber[ch] = 0;
795 else fIndexOfFirstHitForRecPerChamber[ch] = fNHitsForRec;
52c9bc11 796 rawclusters =fMUONData->RawClusters(ch);
f69d51b5 797// pMUON->ResetRawClusters();
798// TR->GetEvent((Int_t) (TR->GetEntries()) - 1); // to be checked ????
a9e2aefa 799 nclus = (Int_t) (rawclusters->GetEntries());
800 // Loop over (cathode correlated) raw clusters
801 for (iclus = 0; iclus < nclus; iclus++) {
802 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(iclus);
803 // new AliMUONHitForRec from raw cluster
804 // and increment number of AliMUONHitForRec's (total and in chamber)
805 hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
806 fNHitsForRec++;
807 (fNHitsForRecPerChamber[ch])++;
808 // more information into HitForRec
809 // resolution: info should be already in raw cluster and taken from it ????
810 hitForRec->SetBendingReso2(fBendingResolution * fBendingResolution);
811 hitForRec->SetNonBendingReso2(fNonBendingResolution * fNonBendingResolution);
812 // original raw cluster
813 hitForRec->SetChamberNumber(ch);
814 hitForRec->SetHitNumber(iclus);
ba5b68db 815 // Z coordinate of the raw cluster (cm)
ba12c242 816 hitForRec->SetZ(clus->GetZ(0));
a9e2aefa 817 if (fPrintLevel >= 10) {
818 cout << "chamber (0...): " << ch <<
819 " raw cluster (0...): " << iclus << endl;
820 clus->Dump();
821 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
822 hitForRec->Dump();}
823 } // end of cluster loop
824 } // end of chamber loop
83dbc640 825 SortHitsForRecWithIncreasingChamber(); //AZ
a9e2aefa 826 return;
827}
828
829 //__________________________________________________________________________
830void AliMUONEventReconstructor::MakeSegments(void)
831{
832 // To make the list of segments in all stations,
833 // from the list of hits to be reconstructed
834 if (fPrintLevel >= 1) cout << "enter MakeSegments" << endl;
835 ResetSegments();
836 // Loop over stations
83dbc640 837 Int_t nb = (fTrackMethod == 2) ? 3 : 0; //AZ
30178c30 838 //AZ for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++)
839 for (Int_t st = nb; st < fgkMaxMuonTrackingStations; st++) //AZ
a9e2aefa 840 MakeSegmentsPerStation(st);
841 if (fPrintLevel >= 10) {
842 cout << "end of MakeSegments" << endl;
30178c30 843 for (Int_t st = 0; st < fgkMaxMuonTrackingStations; st++) {
a9e2aefa 844 cout << "station(0...): " << st
845 << " Segments: " << fNSegments[st]
846 << endl;
847 for (Int_t seg = 0;
848 seg < fNSegments[st];
849 seg++) {
850 cout << "Segment index(0...): " << seg << endl;
851 ((*fSegmentsPtr[st])[seg])->Dump();
852 }
853 }
854 }
855 return;
856}
857
858 //__________________________________________________________________________
859void AliMUONEventReconstructor::MakeSegmentsPerStation(Int_t Station)
860{
861 // To make the list of segments in station number "Station" (0...)
862 // from the list of hits to be reconstructed.
863 // Updates "fNSegments"[Station].
864 // Segments in stations 4 and 5 are sorted
865 // according to increasing absolute value of "impact parameter"
866 AliMUONHitForRec *hit1Ptr, *hit2Ptr;
867 AliMUONSegment *segment;
868 Bool_t last2st;
869 Double_t bendingSlope, distBend, distNonBend, extBendCoor, extNonBendCoor,
d0bfce8d 870 impactParam = 0., maxImpactParam = 0., minImpactParam = 0.; // =0 to avoid compilation warnings.
9cbdf048 871 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
a9e2aefa 872 if (fPrintLevel >= 1)
873 cout << "enter MakeSegmentsPerStation (0...) " << Station << endl;
874 // first and second chambers (0...) in the station
875 Int_t ch1 = 2 * Station;
876 Int_t ch2 = ch1 + 1;
877 // variable true for stations downstream of the dipole:
878 // Station(0..4) equal to 3 or 4
879 if ((Station == 3) || (Station == 4)) {
880 last2st = kTRUE;
881 // maximum impact parameter (cm) according to fMinBendingMomentum...
882 maxImpactParam =
883 TMath::Abs(GetImpactParamFromBendingMomentum(fMinBendingMomentum));
d0bfce8d 884 // minimum impact parameter (cm) according to fMaxBendingMomentum...
885 minImpactParam =
886 TMath::Abs(GetImpactParamFromBendingMomentum(fMaxBendingMomentum));
a9e2aefa 887 }
888 else last2st = kFALSE;
889 // extrapolation factor from Z of first chamber to Z of second chamber
890 // dZ to be changed to take into account fine structure of chambers ????
891 Double_t extrapFact =
9cbdf048 892 (&(pMUON->Chamber(ch2)))->Z() / (&(pMUON->Chamber(ch1)))->Z();
a9e2aefa 893 // index for current segment
894 Int_t segmentIndex = 0;
895 // Loop over HitsForRec in the first chamber of the station
896 for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
897 hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
898 hit1++) {
899 // pointer to the HitForRec
900 hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
901 // extrapolation,
902 // on the straight line joining the HitForRec to the vertex (0,0,0),
903 // to the Z of the second chamber of the station
904 extBendCoor = extrapFact * hit1Ptr->GetBendingCoor();
905 extNonBendCoor = extrapFact * hit1Ptr->GetNonBendingCoor();
906 // Loop over HitsForRec in the second chamber of the station
907 for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
908 hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
909 hit2++) {
910 // pointer to the HitForRec
911 hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
912 // absolute values of distances, in bending and non bending planes,
913 // between the HitForRec in the second chamber
914 // and the previous extrapolation
915 distBend = TMath::Abs(hit2Ptr->GetBendingCoor() - extBendCoor);
916 distNonBend = TMath::Abs(hit2Ptr->GetNonBendingCoor() - extNonBendCoor);
917 if (last2st) {
918 // bending slope
919 bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) /
920 (hit1Ptr->GetZ() - hit2Ptr->GetZ());
921 // absolute value of impact parameter
922 impactParam =
31817925 923 TMath::Abs(hit1Ptr->GetBendingCoor() - hit1Ptr->GetZ() * bendingSlope);
a9e2aefa 924 }
925 // check for distances not too large,
926 // and impact parameter not too big if stations downstream of the dipole.
927 // Conditions "distBend" and "impactParam" correlated for these stations ????
928 if ((distBend < fSegmentMaxDistBending[Station]) &&
929 (distNonBend < fSegmentMaxDistNonBending[Station]) &&
d0bfce8d 930 (!last2st || (impactParam < maxImpactParam)) &&
931 (!last2st || (impactParam > minImpactParam))) {
a9e2aefa 932 // make new segment
933 segment = new ((*fSegmentsPtr[Station])[segmentIndex])
934 AliMUONSegment(hit1Ptr, hit2Ptr);
935 // update "link" to this segment from the hit in the first chamber
936 if (hit1Ptr->GetNSegments() == 0)
937 hit1Ptr->SetIndexOfFirstSegment(segmentIndex);
938 hit1Ptr->SetNSegments(hit1Ptr->GetNSegments() + 1);
939 if (fPrintLevel >= 10) {
940 cout << "segmentIndex(0...): " << segmentIndex
941 << " distBend: " << distBend
942 << " distNonBend: " << distNonBend
943 << endl;
944 segment->Dump();
945 cout << "HitForRec in first chamber" << endl;
946 hit1Ptr->Dump();
947 cout << "HitForRec in second chamber" << endl;
948 hit2Ptr->Dump();
949 };
950 // increment index for current segment
951 segmentIndex++;
952 }
953 } //for (Int_t hit2
954 } // for (Int_t hit1...
955 fNSegments[Station] = segmentIndex;
956 // Sorting according to "impact parameter" if station(1..5) 4 or 5,
957 // i.e. Station(0..4) 3 or 4, using the function "Compare".
958 // After this sorting, it is impossible to use
959 // the "fNSegments" and "fIndexOfFirstSegment"
960 // of the HitForRec in the first chamber to explore all segments formed with it.
961 // Is this sorting really needed ????
962 if ((Station == 3) || (Station == 4)) (fSegmentsPtr[Station])->Sort();
963 if (fPrintLevel >= 1) cout << "Station: " << Station << " NSegments: "
964 << fNSegments[Station] << endl;
965 return;
966}
967
968 //__________________________________________________________________________
969void AliMUONEventReconstructor::MakeTracks(void)
970{
971 // To make the tracks,
972 // from the list of segments and points in all stations
973 if (fPrintLevel >= 1) cout << "enter MakeTracks" << endl;
8429a5e4 974 // The order may be important for the following Reset's
a9e2aefa 975 ResetTracks();
8429a5e4 976 ResetTrackHits();
83dbc640 977 if (fTrackMethod == 2) { //AZ - Kalman filter
978 MakeTrackCandidatesK();
979 // Follow tracks in stations(1..) 3, 2 and 1
980 FollowTracksK();
981 // Remove double tracks
982 RemoveDoubleTracksK();
983 // Propagate tracks to the vertex thru absorber
984 GoToVertex();
d837040f 985 } else {
83dbc640 986 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
987 MakeTrackCandidates();
988 // Follow tracks in stations(1..) 3, 2 and 1
989 FollowTracks();
990 // Remove double tracks
991 RemoveDoubleTracks();
d837040f 992 UpdateTrackParamAtHit();
52c9bc11 993 }
a9e2aefa 994 return;
995}
996
276c44b7 997 //__________________________________________________________________________
d837040f 998void AliMUONEventReconstructor::ValidateTracksWithTrigger(void)
999{
1000 AliMUONTrack *track;
24ab3324 1001 TClonesArray *recTriggerTracks;
1002
1003 fMUONData->ResetRecTriggerTracks();
1004 fMUONData->SetTreeAddress("RL");
1005 fMUONData->GetRecTriggerTracks();
1006 recTriggerTracks = fMUONData->RecTriggerTracks();
e8765288 1007
d837040f 1008 track = (AliMUONTrack*) fRecTracksPtr->First();
1009 while (track) {
1010 track->MatchTriggerTrack(recTriggerTracks);
1011 track = (AliMUONTrack*) fRecTracksPtr->After(track);
e8765288 1012 }
24ab3324 1013
d837040f 1014}
1015
1016 //__________________________________________________________________________
1017Bool_t AliMUONEventReconstructor::MakeTriggerTracks(void)
276c44b7 1018{
1019 // To make the trigger tracks from Local Trigger
1020 if (fPrintLevel >= 1) cout << "enter MakeTriggerTracks" << endl;
52c9bc11 1021 // ResetTriggerTracks();
276c44b7 1022
1023 Int_t nTRentries;
52c9bc11 1024 Long_t gloTrigPat;
276c44b7 1025 TClonesArray *localTrigger;
9131b4fe 1026 TClonesArray *globalTrigger;
276c44b7 1027 AliMUONLocalTrigger *locTrg;
9131b4fe 1028 AliMUONGlobalTrigger *gloTrg;
276c44b7 1029 AliMUONTriggerCircuit *circuit;
52c9bc11 1030 AliMUONTriggerTrack *recTriggerTrack = 0;
d837040f 1031
30178c30 1032 TTree* treeR = fLoader->TreeR();
276c44b7 1033
276c44b7 1034 // Loading MUON subsystem
1035 AliMUON * pMUON = (AliMUON *) gAlice->GetDetector("MUON");
1036
30178c30 1037 nTRentries = Int_t(treeR->GetEntries());
d837040f 1038
30178c30 1039 treeR->GetEvent(0); // only one entry
d837040f 1040
1041 if (!(fMUONData->IsTriggerBranchesInTree())) {
1042 cout << "Warning in AliMUONEventReconstructor::MakeTriggerTracks"
52c9bc11 1043 << endl;
d837040f 1044 cout << "Trigger information is not avalaible, nTRentries = " << nTRentries << " not equal to 1" << endl;
1045 return kFALSE;
276c44b7 1046 }
276c44b7 1047
52c9bc11 1048 fMUONData->SetTreeAddress("GLT");
1049 fMUONData->GetTrigger();
9131b4fe 1050
52c9bc11 1051 // global trigger for trigger pattern
9131b4fe 1052 gloTrigPat = 0;
52c9bc11 1053 globalTrigger = fMUONData->GlobalTrigger();
9131b4fe 1054 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
1055 if (gloTrg->SinglePlusLpt()) gloTrigPat|= 0x1;
1056 if (gloTrg->SinglePlusHpt()) gloTrigPat|= 0x2;
1057 if (gloTrg->SinglePlusApt()) gloTrigPat|= 0x4;
1058
1059 if (gloTrg->SingleMinusLpt()) gloTrigPat|= 0x8;
1060 if (gloTrg->SingleMinusHpt()) gloTrigPat|= 0x10;
1061 if (gloTrg->SingleMinusApt()) gloTrigPat|= 0x20;
1062
1063 if (gloTrg->SingleUndefLpt()) gloTrigPat|= 0x40;
1064 if (gloTrg->SingleUndefHpt()) gloTrigPat|= 0x80;
1065 if (gloTrg->SingleUndefApt()) gloTrigPat|= 0x100;
1066
1067 if (gloTrg->PairUnlikeLpt()) gloTrigPat|= 0x200;
1068 if (gloTrg->PairUnlikeHpt()) gloTrigPat|= 0x400;
1069 if (gloTrg->PairUnlikeApt()) gloTrigPat|= 0x800;
1070
1071 if (gloTrg->PairLikeLpt()) gloTrigPat|= 0x1000;
1072 if (gloTrg->PairLikeHpt()) gloTrigPat|= 0x2000;
1073 if (gloTrg->PairLikeApt()) gloTrigPat|= 0x4000;
1074
52c9bc11 1075
1076
1077 // local trigger for tracking
1078 localTrigger = fMUONData->LocalTrigger();
276c44b7 1079 Int_t nlocals = (Int_t) (localTrigger->GetEntries());
1080 Float_t z11 = ( &(pMUON->Chamber(10)) )->Z();
1081 Float_t z21 = ( &(pMUON->Chamber(12)) )->Z();
1082
1083 for (Int_t i=0; i<nlocals; i++) { // loop on Local Trigger
52c9bc11 1084 locTrg = (AliMUONLocalTrigger*)localTrigger->UncheckedAt(i);
1085 circuit = &(pMUON->TriggerCircuit(locTrg->LoCircuit()));
1086 Float_t y11 = circuit->GetY11Pos(locTrg->LoStripX());
aeb4f510 1087 Int_t stripX21 = locTrg->LoStripX()+locTrg->LoDev()+1;
1088 Float_t y21 = circuit->GetY21Pos(stripX21);
52c9bc11 1089 Float_t x11 = circuit->GetX11Pos(locTrg->LoStripY());
1090 Float_t thetax = TMath::ATan2( x11 , z11 );
1091 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
1092
1093 recTriggerTrack = new AliMUONTriggerTrack(x11,y11,thetax,thetay,gloTrigPat,this);
1094 // since static statement does not work, set gloTrigPat for each track
1095
1096 // fNRecTriggerTracks++;
1097 fMUONData->AddRecTriggerTrack(*recTriggerTrack);
276c44b7 1098 } // end of loop on Local Trigger
d837040f 1099 return kTRUE;
276c44b7 1100}
1101
a9e2aefa 1102 //__________________________________________________________________________
1103Int_t AliMUONEventReconstructor::MakeTrackCandidatesWithTwoSegments(AliMUONSegment *BegSegment)
1104{
1105 // To make track candidates with two segments in stations(1..) 4 and 5,
1106 // the first segment being pointed to by "BegSegment".
1107 // Returns the number of such track candidates.
1108 Int_t endStation, iEndSegment, nbCan2Seg;
1109 AliMUONSegment *endSegment, *extrapSegment;
1110 AliMUONTrack *recTrack;
1111 Double_t mcsFactor;
1112 if (fPrintLevel >= 1) cout << "enter MakeTrackCandidatesWithTwoSegments" << endl;
1113 // Station for the end segment
1114 endStation = 7 - (BegSegment->GetHitForRec1())->GetChamberNumber() / 2;
1115 // multiple scattering factor corresponding to one chamber
1116 mcsFactor = 0.0136 /
1117 GetBendingMomentumFromImpactParam(BegSegment->GetBendingImpact());
1118 mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
1119 // linear extrapolation to end station
1120 extrapSegment =
1121 BegSegment->CreateSegmentFromLinearExtrapToStation(endStation, mcsFactor);
1122 // number of candidates with 2 segments to 0
1123 nbCan2Seg = 0;
1124 // Loop over segments in the end station
1125 for (iEndSegment = 0; iEndSegment < fNSegments[endStation]; iEndSegment++) {
1126 // pointer to segment
1127 endSegment = (AliMUONSegment*) ((*fSegmentsPtr[endStation])[iEndSegment]);
1128 // test compatibility between current segment and "extrapSegment"
04b5ea16 1129 // 4 because 4 quantities in chi2
a9e2aefa 1130 if ((endSegment->
1131 NormalizedChi2WithSegment(extrapSegment,
1132 fMaxSigma2Distance)) <= 4.0) {
1133 // both segments compatible:
1134 // make track candidate from "begSegment" and "endSegment"
1135 if (fPrintLevel >= 2)
1136 cout << "TrackCandidate with Segment " << iEndSegment <<
1137 " in Station(0..) " << endStation << endl;
1138 // flag for both segments in one track:
1139 // to be done in track constructor ????
1140 BegSegment->SetInTrack(kTRUE);
1141 endSegment->SetInTrack(kTRUE);
1142 recTrack = new ((*fRecTracksPtr)[fNRecTracks])
1143 AliMUONTrack(BegSegment, endSegment, this);
1144 fNRecTracks++;
1145 if (fPrintLevel >= 10) recTrack->RecursiveDump();
1146 // increment number of track candidates with 2 segments
1147 nbCan2Seg++;
1148 }
1149 } // for (iEndSegment = 0;...
1150 delete extrapSegment; // should not delete HitForRec's it points to !!!!
1151 return nbCan2Seg;
1152}
1153
1154 //__________________________________________________________________________
1155Int_t AliMUONEventReconstructor::MakeTrackCandidatesWithOneSegmentAndOnePoint(AliMUONSegment *BegSegment)
1156{
1157 // To make track candidates with one segment and one point
1158 // in stations(1..) 4 and 5,
1159 // the segment being pointed to by "BegSegment".
1160 Int_t ch, ch1, ch2, endStation, iHit, iHitMax, iHitMin, nbCan1Seg1Hit;
1161 AliMUONHitForRec *extrapHitForRec, *hit;
1162 AliMUONTrack *recTrack;
1163 Double_t mcsFactor;
1164 if (fPrintLevel >= 1)
1165 cout << "enter MakeTrackCandidatesWithOneSegmentAndOnePoint" << endl;
1166 // station for the end point
1167 endStation = 7 - (BegSegment->GetHitForRec1())->GetChamberNumber() / 2;
1168 // multiple scattering factor corresponding to one chamber
1169 mcsFactor = 0.0136 /
1170 GetBendingMomentumFromImpactParam(BegSegment->GetBendingImpact());
1171 mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
1172 // first and second chambers(0..) in the end station
1173 ch1 = 2 * endStation;
1174 ch2 = ch1 + 1;
1175 // number of candidates to 0
1176 nbCan1Seg1Hit = 0;
1177 // Loop over chambers of the end station
1178 for (ch = ch2; ch >= ch1; ch--) {
1179 // linear extrapolation to chamber
1180 extrapHitForRec =
1181 BegSegment->CreateHitForRecFromLinearExtrapToChamber(ch, mcsFactor);
1182 // limits for the hit index in the loop
1183 iHitMin = fIndexOfFirstHitForRecPerChamber[ch];
1184 iHitMax = iHitMin + fNHitsForRecPerChamber[ch];
1185 // Loop over HitForRec's in the chamber
1186 for (iHit = iHitMin; iHit < iHitMax; iHit++) {
1187 // pointer to HitForRec
1188 hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[iHit]);
1189 // test compatibility between current HitForRec and "extrapHitForRec"
04b5ea16 1190 // 2 because 2 quantities in chi2
a9e2aefa 1191 if ((hit->
1192 NormalizedChi2WithHitForRec(extrapHitForRec,
1193 fMaxSigma2Distance)) <= 2.0) {
1194 // both HitForRec's compatible:
1195 // make track candidate from begSegment and current HitForRec
1196 if (fPrintLevel >= 2)
1197 cout << "TrackCandidate with HitForRec " << iHit <<
1198 " in Chamber(0..) " << ch << endl;
1199 // flag for beginning segments in one track:
1200 // to be done in track constructor ????
1201 BegSegment->SetInTrack(kTRUE);
1202 recTrack = new ((*fRecTracksPtr)[fNRecTracks])
1203 AliMUONTrack(BegSegment, hit, this);
1204 // the right place to eliminate "double counting" ???? how ????
1205 fNRecTracks++;
1206 if (fPrintLevel >= 10) recTrack->RecursiveDump();
1207 // increment number of track candidates
1208 nbCan1Seg1Hit++;
1209 }
1210 } // for (iHit = iHitMin;...
1211 delete extrapHitForRec;
1212 } // for (ch = ch2;...
1213 return nbCan1Seg1Hit;
1214}
1215
1216 //__________________________________________________________________________
1217void AliMUONEventReconstructor::MakeTrackCandidates(void)
1218{
1219 // To make track candidates
1220 // with at least 3 aligned points in stations(1..) 4 and 5
1221 // (two Segment's or one Segment and one HitForRec)
1222 Int_t begStation, iBegSegment, nbCan1Seg1Hit, nbCan2Seg;
1223 AliMUONSegment *begSegment;
1224 if (fPrintLevel >= 1) cout << "enter MakeTrackCandidates" << endl;
1225 // Loop over stations(1..) 5 and 4 for the beginning segment
1226 for (begStation = 4; begStation > 2; begStation--) {
1227 // Loop over segments in the beginning station
1228 for (iBegSegment = 0; iBegSegment < fNSegments[begStation]; iBegSegment++) {
1229 // pointer to segment
1230 begSegment = (AliMUONSegment*) ((*fSegmentsPtr[begStation])[iBegSegment]);
1231 if (fPrintLevel >= 2)
1232 cout << "look for TrackCandidate's with Segment " << iBegSegment <<
1233 " in Station(0..) " << begStation << endl;
1234 // Look for track candidates with two segments,
1235 // "begSegment" and all compatible segments in other station.
1236 // Only for beginning station(1..) 5
1237 // because candidates with 2 segments have to looked for only once.
1238 if (begStation == 4)
1239 nbCan2Seg = MakeTrackCandidatesWithTwoSegments(begSegment);
956019b6 1240 // Look for track candidates with one segment and one point,
a9e2aefa 1241 // "begSegment" and all compatible HitForRec's in other station.
1242 // Only if "begSegment" does not belong already to a track candidate.
1243 // Is that a too strong condition ????
1244 if (!(begSegment->GetInTrack()))
1245 nbCan1Seg1Hit = MakeTrackCandidatesWithOneSegmentAndOnePoint(begSegment);
1246 } // for (iBegSegment = 0;...
1247 } // for (begStation = 4;...
1248 return;
1249}
1250
1251 //__________________________________________________________________________
1252void AliMUONEventReconstructor::FollowTracks(void)
1253{
1254 // Follow tracks in stations(1..) 3, 2 and 1
04b5ea16 1255 // too long: should be made more modular !!!!
d0bfce8d 1256 AliMUONHitForRec *bestHit, *extrapHit, *extrapCorrHit, *hit;
1257 AliMUONSegment *bestSegment, *extrapSegment, *extrapCorrSegment, *segment;
04b5ea16 1258 AliMUONTrack *track, *nextTrack;
1259 AliMUONTrackParam *trackParam1, trackParam[2], trackParamVertex;
ecfa008b 1260 // -1 to avoid compilation warnings
1261 Int_t ch = -1, chInStation, chBestHit = -1, iHit, iSegment, station, trackIndex;
04b5ea16 1262 Double_t bestChi2, chi2, dZ1, dZ2, dZ3, maxSigma2Distance, mcsFactor;
d0bfce8d 1263 Double_t bendingMomentum, chi2Norm = 0.;
9cbdf048 1264 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
04b5ea16 1265 // local maxSigma2Distance, for easy increase in testing
1266 maxSigma2Distance = fMaxSigma2Distance;
a9e2aefa 1267 if (fPrintLevel >= 2)
1268 cout << "enter FollowTracks" << endl;
1269 // Loop over track candidates
04b5ea16 1270 track = (AliMUONTrack*) fRecTracksPtr->First();
1271 trackIndex = -1;
1272 while (track) {
1273 // Follow function for each track candidate ????
1274 trackIndex++;
1275 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
a9e2aefa 1276 if (fPrintLevel >= 2)
1277 cout << "FollowTracks: track candidate(0..): " << trackIndex << endl;
956019b6 1278 // Fit track candidate
1279 track->SetFitMCS(0); // without multiple Coulomb scattering
1280 track->SetFitNParam(3); // with 3 parameters (X = Y = 0)
1281 track->SetFitStart(0); // from parameters at vertex
1282 track->Fit();
a9e2aefa 1283 if (fPrintLevel >= 10) {
1284 cout << "FollowTracks: track candidate(0..): " << trackIndex
956019b6 1285 << " after fit in stations(0..) 3 and 4" << endl;
a9e2aefa 1286 track->RecursiveDump();
1287 }
1288 // Loop over stations(1..) 3, 2 and 1
04b5ea16 1289 // something SPECIAL for stations 2 and 1 for majority 3 coincidence ????
1290 // otherwise: majority coincidence 2 !!!!
a9e2aefa 1291 for (station = 2; station >= 0; station--) {
1292 // Track parameters at first track hit (smallest Z)
1293 trackParam1 = ((AliMUONTrackHit*)
1294 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
1295 // extrapolation to station
1296 trackParam1->ExtrapToStation(station, trackParam);
79e1e601 1297 extrapSegment = new AliMUONSegment(); // empty segment
d0bfce8d 1298 extrapCorrSegment = new AliMUONSegment(); // empty corrected segment
a9e2aefa 1299 // multiple scattering factor corresponding to one chamber
1300 // and momentum in bending plane (not total)
1301 mcsFactor = 0.0136 * trackParam1->GetInverseBendingMomentum();
1302 mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
1303 // Z difference from previous station
9cbdf048 1304 dZ1 = (&(pMUON->Chamber(2 * station)))->Z() -
1305 (&(pMUON->Chamber(2 * station + 2)))->Z();
a9e2aefa 1306 // Z difference between the two previous stations
9cbdf048 1307 dZ2 = (&(pMUON->Chamber(2 * station + 2)))->Z() -
1308 (&(pMUON->Chamber(2 * station + 4)))->Z();
04b5ea16 1309 // Z difference between the two chambers in the previous station
1310 dZ3 = (&(pMUON->Chamber(2 * station)))->Z() -
1311 (&(pMUON->Chamber(2 * station + 1)))->Z();
1312 extrapSegment->SetBendingCoorReso2(fBendingResolution * fBendingResolution);
1313 extrapSegment->
1314 SetNonBendingCoorReso2(fNonBendingResolution * fNonBendingResolution);
1315 extrapSegment->UpdateFromStationTrackParam
1316 (trackParam, mcsFactor, dZ1, dZ2, dZ3, station,
1317 trackParam1->GetInverseBendingMomentum());
d0bfce8d 1318 // same thing for corrected segment
1319 // better to use copy constructor, after checking that it works properly !!!!
1320 extrapCorrSegment->SetBendingCoorReso2(fBendingResolution * fBendingResolution);
1321 extrapCorrSegment->
1322 SetNonBendingCoorReso2(fNonBendingResolution * fNonBendingResolution);
1323 extrapCorrSegment->UpdateFromStationTrackParam
1324 (trackParam, mcsFactor, dZ1, dZ2, dZ3, station,
1325 trackParam1->GetInverseBendingMomentum());
a9e2aefa 1326 bestChi2 = 5.0;
1327 bestSegment = NULL;
1328 if (fPrintLevel >= 10) {
1329 cout << "FollowTracks: track candidate(0..): " << trackIndex
1330 << " Look for segment in station(0..): " << station << endl;
1331 }
1332 // Loop over segments in station
1333 for (iSegment = 0; iSegment < fNSegments[station]; iSegment++) {
1334 // Look for best compatible Segment in station
1335 // should consider all possibilities ????
1336 // multiple scattering ????
1337 // separation in 2 functions: Segment and HitForRec ????
1338 segment = (AliMUONSegment*) ((*fSegmentsPtr[station])[iSegment]);
d0bfce8d 1339 // correction of corrected segment (fBendingCoor and fNonBendingCoor)
1340 // according to real Z value of "segment" and slopes of "extrapSegment"
1341 extrapCorrSegment->
1342 SetBendingCoor(extrapSegment->GetBendingCoor() +
1343 extrapSegment->GetBendingSlope() *
1344 (segment->GetHitForRec1()->GetZ() -
1345 (&(pMUON->Chamber(2 * station)))->Z()));
1346 extrapCorrSegment->
1347 SetNonBendingCoor(extrapSegment->GetNonBendingCoor() +
1348 extrapSegment->GetNonBendingSlope() *
1349 (segment->GetHitForRec1()->GetZ() -
1350 (&(pMUON->Chamber(2 * station)))->Z()));
1351 chi2 = segment->
1352 NormalizedChi2WithSegment(extrapCorrSegment, maxSigma2Distance);
a9e2aefa 1353 if (chi2 < bestChi2) {
1354 // update best Chi2 and Segment if better found
1355 bestSegment = segment;
1356 bestChi2 = chi2;
1357 }
1358 }
1359 if (bestSegment) {
1360 // best segment found: add it to track candidate
1361 track->AddSegment(bestSegment);
1362 // set track parameters at these two TrakHit's
1363 track->SetTrackParamAtHit(track->GetNTrackHits() - 2, &(trackParam[0]));
1364 track->SetTrackParamAtHit(track->GetNTrackHits() - 1, &(trackParam[1]));
1365 if (fPrintLevel >= 10) {
1366 cout << "FollowTracks: track candidate(0..): " << trackIndex
1367 << " Added segment in station(0..): " << station << endl;
1368 track->RecursiveDump();
1369 }
1370 }
1371 else {
1372 // No best segment found:
1373 // Look for best compatible HitForRec in station:
1374 // should consider all possibilities ????
1375 // multiple scattering ???? do about like for extrapSegment !!!!
79e1e601 1376 extrapHit = new AliMUONHitForRec(); // empty hit
d0bfce8d 1377 extrapCorrHit = new AliMUONHitForRec(); // empty corrected hit
a9e2aefa 1378 bestChi2 = 3.0;
1379 bestHit = NULL;
1380 if (fPrintLevel >= 10) {
1381 cout << "FollowTracks: track candidate(0..): " << trackIndex
1382 << " Segment not found, look for hit in station(0..): " << station
1383 << endl;
1384 }
1385 // Loop over chambers of the station
d82671a0 1386 for (chInStation = 0; chInStation < 2; chInStation++) {
a9e2aefa 1387 // coordinates of extrapolated hit
d82671a0 1388 extrapHit->
1389 SetBendingCoor((&(trackParam[chInStation]))->GetBendingCoor());
1390 extrapHit->
1391 SetNonBendingCoor((&(trackParam[chInStation]))->GetNonBendingCoor());
a9e2aefa 1392 // resolutions from "extrapSegment"
1393 extrapHit->SetBendingReso2(extrapSegment->GetBendingCoorReso2());
1394 extrapHit->SetNonBendingReso2(extrapSegment->GetNonBendingCoorReso2());
d0bfce8d 1395 // same things for corrected hit
1396 // better to use copy constructor, after checking that it works properly !!!!
1397 extrapCorrHit->
1398 SetBendingCoor((&(trackParam[chInStation]))->GetBendingCoor());
1399 extrapCorrHit->
1400 SetNonBendingCoor((&(trackParam[chInStation]))->GetNonBendingCoor());
1401 extrapHit->SetBendingReso2(extrapSegment->GetBendingCoorReso2());
1402 extrapHit->SetNonBendingReso2(extrapSegment->GetNonBendingCoorReso2());
a9e2aefa 1403 // Loop over hits in the chamber
956019b6 1404 ch = 2 * station + chInStation;
a9e2aefa 1405 for (iHit = fIndexOfFirstHitForRecPerChamber[ch];
1406 iHit < fIndexOfFirstHitForRecPerChamber[ch] +
1407 fNHitsForRecPerChamber[ch];
1408 iHit++) {
1409 hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[iHit]);
d0bfce8d 1410 // correction of corrected hit (fBendingCoor and fNonBendingCoor)
1411 // according to real Z value of "hit" and slopes of right "trackParam"
1412 extrapCorrHit->
1413 SetBendingCoor((&(trackParam[chInStation]))->GetBendingCoor() +
1414 (&(trackParam[chInStation]))->GetBendingSlope() *
1415 (hit->GetZ() -
1416 (&(trackParam[chInStation]))->GetZ()));
1417 extrapCorrHit->
1418 SetNonBendingCoor((&(trackParam[chInStation]))->GetNonBendingCoor() +
1419 (&(trackParam[chInStation]))->GetNonBendingSlope() *
1420 (hit->GetZ() -
1421 (&(trackParam[chInStation]))->GetZ()));
a9e2aefa 1422 // condition for hit not already in segment ????
1423 chi2 = hit->NormalizedChi2WithHitForRec(extrapHit, maxSigma2Distance);
1424 if (chi2 < bestChi2) {
1425 // update best Chi2 and HitForRec if better found
1426 bestHit = hit;
1427 bestChi2 = chi2;
d82671a0 1428 chBestHit = chInStation;
a9e2aefa 1429 }
1430 }
1431 }
1432 if (bestHit) {
1433 // best hit found: add it to track candidate
1434 track->AddHitForRec(bestHit);
956019b6 1435 // set track parameters at this TrackHit
a9e2aefa 1436 track->SetTrackParamAtHit(track->GetNTrackHits() - 1,
1437 &(trackParam[chBestHit]));
1438 if (fPrintLevel >= 10) {
1439 cout << "FollowTracks: track candidate(0..): " << trackIndex
1440 << " Added hit in station(0..): " << station << endl;
1441 track->RecursiveDump();
1442 }
1443 }
1444 else {
8429a5e4 1445 // Remove current track candidate
1446 // and corresponding TrackHit's, ...
1447 track->Remove();
04b5ea16 1448 delete extrapSegment;
d0bfce8d 1449 delete extrapCorrSegment;
1450 delete extrapHit;
1451 delete extrapCorrHit;
a9e2aefa 1452 break; // stop the search for this candidate:
1453 // exit from the loop over station
1454 }
d0bfce8d 1455 delete extrapHit;
1456 delete extrapCorrHit;
a9e2aefa 1457 }
04b5ea16 1458 delete extrapSegment;
d0bfce8d 1459 delete extrapCorrSegment;
a9e2aefa 1460 // Sort track hits according to increasing Z
1461 track->GetTrackHitsPtr()->Sort();
1462 // Update track parameters at first track hit (smallest Z)
1463 trackParam1 = ((AliMUONTrackHit*)
1464 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
d0bfce8d 1465 bendingMomentum = 0.;
1466 if (TMath::Abs(trackParam1->GetInverseBendingMomentum()) > 0.)
1467 bendingMomentum = TMath::Abs(1/(trackParam1->GetInverseBendingMomentum()));
1468 // Track removed if bendingMomentum not in window [min, max]
1469 if ((bendingMomentum < fMinBendingMomentum) || (bendingMomentum > fMaxBendingMomentum)) {
1470 track->Remove();
1471 break; // stop the search for this candidate:
1472 // exit from the loop over station
1473 }
956019b6 1474 // Track fit
04b5ea16 1475 // with multiple Coulomb scattering if all stations
1476 if (station == 0) track->SetFitMCS(1);
956019b6 1477 // without multiple Coulomb scattering if not all stations
04b5ea16 1478 else track->SetFitMCS(0);
956019b6 1479 track->SetFitNParam(5); // with 5 parameters (momentum and position)
1480 track->SetFitStart(1); // from parameters at first hit
1481 track->Fit();
d0bfce8d 1482 Double_t numberOfDegFree = (2.0 * track->GetNTrackHits() - 5);
1483 if (numberOfDegFree > 0) {
1484 chi2Norm = track->GetFitFMin() / numberOfDegFree;
1485 } else {
1486 chi2Norm = 1.e10;
1487 }
1488 // Track removed if normalized chi2 too high
1489 if (chi2Norm > fMaxChi2) {
1490 track->Remove();
1491 break; // stop the search for this candidate:
1492 // exit from the loop over station
1493 }
a9e2aefa 1494 if (fPrintLevel >= 10) {
1495 cout << "FollowTracks: track candidate(0..): " << trackIndex
1496 << " after fit from station(0..): " << station << " to 4" << endl;
1497 track->RecursiveDump();
1498 }
04b5ea16 1499 // Track extrapolation to the vertex through the absorber (Branson)
956019b6 1500 // after going through the first station
04b5ea16 1501 if (station == 0) {
1502 trackParamVertex = *trackParam1;
1503 (&trackParamVertex)->ExtrapToVertex();
1504 track->SetTrackParamAtVertex(&trackParamVertex);
6ae236ee 1505 if (fPrintLevel >= 1) {
1506 cout << "FollowTracks: track candidate(0..): " << trackIndex
1507 << " after extrapolation to vertex" << endl;
1508 track->RecursiveDump();
1509 }
04b5ea16 1510 }
a9e2aefa 1511 } // for (station = 2;...
04b5ea16 1512 // go really to next track
1513 track = nextTrack;
1514 } // while (track)
1515 // Compression of track array (necessary after Remove ????)
1516 fRecTracksPtr->Compress();
1517 return;
1518}
1519
1520 //__________________________________________________________________________
8429a5e4 1521void AliMUONEventReconstructor::RemoveDoubleTracks(void)
1522{
1523 // To remove double tracks.
1524 // Tracks are considered identical
1525 // if they have at least half of their hits in common.
1526 // Among two identical tracks, one keeps the track with the larger number of hits
1527 // or, if these numbers are equal, the track with the minimum Chi2.
1528 AliMUONTrack *track1, *track2, *trackToRemove;
1529 Bool_t identicalTracks;
1530 Int_t hitsInCommon, nHits1, nHits2;
1531 identicalTracks = kTRUE;
1532 while (identicalTracks) {
1533 identicalTracks = kFALSE;
1534 // Loop over first track of the pair
1535 track1 = (AliMUONTrack*) fRecTracksPtr->First();
1536 while (track1 && (!identicalTracks)) {
1537 nHits1 = track1->GetNTrackHits();
1538 // Loop over second track of the pair
1539 track2 = (AliMUONTrack*) fRecTracksPtr->After(track1);
1540 while (track2 && (!identicalTracks)) {
1541 nHits2 = track2->GetNTrackHits();
1542 // number of hits in common between two tracks
1543 hitsInCommon = track1->HitsInCommon(track2);
1544 // check for identical tracks
1545 if ((4 * hitsInCommon) >= (nHits1 + nHits2)) {
1546 identicalTracks = kTRUE;
1547 // decide which track to remove
1548 if (nHits1 > nHits2) trackToRemove = track2;
1549 else if (nHits1 < nHits2) trackToRemove = track1;
1550 else if ((track1->GetFitFMin()) < (track2->GetFitFMin()))
1551 trackToRemove = track2;
1552 else trackToRemove = track1;
1553 // remove it
1554 trackToRemove->Remove();
1555 }
1556 track2 = (AliMUONTrack*) fRecTracksPtr->After(track2);
1557 } // track2
1558 track1 = (AliMUONTrack*) fRecTracksPtr->After(track1);
1559 } // track1
1560 }
1561 return;
1562}
1563
d837040f 1564 //__________________________________________________________________________
1565void AliMUONEventReconstructor::UpdateTrackParamAtHit()
1566{
1567 // Set track parameters after track fitting. Fill fTrackParamAtHit of AliMUONTrack's
1568 AliMUONTrack *track;
1569 AliMUONTrackHit *trackHit;
1570 AliMUONTrackParam *trackParam;
1571 track = (AliMUONTrack*) fRecTracksPtr->First();
1572 while (track) {
1573 trackHit = (AliMUONTrackHit*) (track->GetTrackHitsPtr())->First();
1574 while (trackHit) {
1575 trackParam = trackHit->GetTrackParam();
1576 track->AddTrackParamAtHit(trackParam);
1577 trackHit = (AliMUONTrackHit*) (track->GetTrackHitsPtr())->After(trackHit);
1578 } // trackHit
1579 track = (AliMUONTrack*) fRecTracksPtr->After(track);
1580 } // track
1581 return;
1582}
1583
8429a5e4 1584 //__________________________________________________________________________
04b5ea16 1585void AliMUONEventReconstructor::EventDump(void)
1586{
1587 // Dump reconstructed event (track parameters at vertex and at first hit),
1588 // and the particle parameters
1589
1590 AliMUONTrack *track;
1591 AliMUONTrackParam *trackParam, *trackParam1;
04b5ea16 1592 Double_t bendingSlope, nonBendingSlope, pYZ;
1593 Double_t pX, pY, pZ, x, y, z, c;
1594 Int_t np, trackIndex, nTrackHits;
1595
1596 if (fPrintLevel >= 1) cout << "****** enter EventDump ******" << endl;
1597 if (fPrintLevel >= 1) {
1598 cout << " Number of Reconstructed tracks :" << fNRecTracks << endl;
1599 }
1600 fRecTracksPtr->Compress(); // for simple loop without "Next" since no hole
1601 // Loop over reconstructed tracks
1602 for (trackIndex = 0; trackIndex < fNRecTracks; trackIndex++) {
83dbc640 1603 if (fTrackMethod != 1) continue; //AZ - skip the rest for now
04b5ea16 1604 if (fPrintLevel >= 1)
1605 cout << " track number: " << trackIndex << endl;
1606 // function for each track for modularity ????
1607 track = (AliMUONTrack*) ((*fRecTracksPtr)[trackIndex]);
1608 nTrackHits = track->GetNTrackHits();
1609 if (fPrintLevel >= 1)
1610 cout << " number of track hits: " << nTrackHits << endl;
1611 // track parameters at Vertex
1612 trackParam = track->GetTrackParamAtVertex();
1613 x = trackParam->GetNonBendingCoor();
1614 y = trackParam->GetBendingCoor();
1615 z = trackParam->GetZ();
1616 bendingSlope = trackParam->GetBendingSlope();
1617 nonBendingSlope = trackParam->GetNonBendingSlope();
1618 pYZ = 1/TMath::Abs(trackParam->GetInverseBendingMomentum());
1619 pZ = pYZ/TMath::Sqrt(1+bendingSlope*bendingSlope);
1620 pX = pZ * nonBendingSlope;
1621 pY = pZ * bendingSlope;
1622 c = TMath::Sign(1.0, trackParam->GetInverseBendingMomentum());
1623 if (fPrintLevel >= 1)
1624 printf(" track parameters at Vertex z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
1625 z, x, y, pX, pY, pZ, c);
1626
1627 // track parameters at first hit
1628 trackParam1 = ((AliMUONTrackHit*)
1629 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
1630 x = trackParam1->GetNonBendingCoor();
1631 y = trackParam1->GetBendingCoor();
1632 z = trackParam1->GetZ();
1633 bendingSlope = trackParam1->GetBendingSlope();
1634 nonBendingSlope = trackParam1->GetNonBendingSlope();
1635 pYZ = 1/TMath::Abs(trackParam1->GetInverseBendingMomentum());
1636 pZ = pYZ/TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
1637 pX = pZ * nonBendingSlope;
1638 pY = pZ * bendingSlope;
1639 c = TMath::Sign(1.0, trackParam1->GetInverseBendingMomentum());
1640 if (fPrintLevel >= 1)
1641 printf(" track parameters at z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
1642 z, x, y, pX, pY, pZ, c);
1643 }
1644 // informations about generated particles
5d12ce38 1645 np = gAlice->GetMCApp()->GetNtrack();
04b5ea16 1646 printf(" **** number of generated particles: %d \n", np);
1647
88cb7938 1648// for (Int_t iPart = 0; iPart < np; iPart++) {
1649// p = gAlice->Particle(iPart);
1650// printf(" particle %d: type= %d px= %f py= %f pz= %f pdg= %d\n",
1651// iPart, p->GetPdgCode(), p->Px(), p->Py(), p->Pz(), p->GetPdgCode());
1652// }
a9e2aefa 1653 return;
1654}
1655
276c44b7 1656
1657//__________________________________________________________________________
1658void AliMUONEventReconstructor::EventDumpTrigger(void)
1659{
1660 // Dump reconstructed trigger event
1661 // and the particle parameters
1662
52c9bc11 1663 AliMUONTriggerTrack *triggertrack ;
1664 Int_t nTriggerTracks = fMUONData->RecTriggerTracks()->GetEntriesFast();
276c44b7 1665
276c44b7 1666 if (fPrintLevel >= 1) {
52c9bc11 1667 cout << "****** enter EventDumpTrigger ******" << endl;
1668 cout << " Number of Reconstructed tracks :" << nTriggerTracks << endl;
276c44b7 1669 }
1670 // Loop over reconstructed tracks
52c9bc11 1671 for (Int_t trackIndex = 0; trackIndex < nTriggerTracks; trackIndex++) {
1672 triggertrack = (AliMUONTriggerTrack*)fMUONData->RecTriggerTracks()->At(trackIndex);
276c44b7 1673 printf(" trigger track number %i x11=%f y11=%f thetax=%f thetay=%f \n",
1674 trackIndex,
1675 triggertrack->GetX11(),triggertrack->GetY11(),
1676 triggertrack->GetThetax(),triggertrack->GetThetay());
1677 }
1678}
1679
1680//__________________________________________________________________________
c7ba256d 1681void AliMUONEventReconstructor::FillEvent()
1682{
1683// Create a new AliMUONRecoEvent, fill its track list, then add it as a
1684// leaf in the Event branch of TreeRecoEvent tree
1685 cout << "Enter FillEvent() ...\n";
1686
1687 if (!fRecoEvent) {
1688 fRecoEvent = new AliMUONRecoEvent();
1689 } else {
1690 fRecoEvent->Clear();
1691 }
1692 //save current directory
1693 TDirectory *current = gDirectory;
1694 if (!fTreeFile) fTreeFile = new TFile("tree_reco.root", "RECREATE");
1695 if (!fEventTree) fEventTree = new TTree("TreeRecoEvent", "MUON reconstructed events");
83dbc640 1696 //AZif (fRecoEvent->MakeDumpTracks(fRecTracksPtr)) {
1697 if (fRecoEvent->MakeDumpTracks(fMuons, fRecTracksPtr, this)) { //AZ
c7ba256d 1698 if (fPrintLevel > 1) fRecoEvent->EventInfo();
1699 TBranch *branch = fEventTree->GetBranch("Event");
d0f40f23 1700 if (!branch) branch = fEventTree->Branch("Event", "AliMUONRecoEvent", &fRecoEvent, 64000);
c7ba256d 1701 branch->SetAutoDelete();
1702 fTreeFile->cd();
1703 fEventTree->Fill();
1704 fTreeFile->Write();
1705 }
1706 // restore directory
1707 current->cd();
1708}
83dbc640 1709
1710//__________________________________________________________________________
1711void AliMUONEventReconstructor::MakeTrackCandidatesK(void)
1712{
1713 // To make initial tracks for Kalman filter from the list of segments
1714 Int_t istat, iseg;
1715 AliMUONSegment *segment;
1716 AliMUONTrackK *trackK;
1717
1718 if (fPrintLevel >= 1) cout << "enter MakeTrackCandidatesK" << endl;
1719 // Reset the TClonesArray of reconstructed tracks
1720 if (fRecTracksPtr) fRecTracksPtr->Delete();
1721 // Delete in order that the Track destructors are called,
1722 // hence the space for the TClonesArray of pointers to TrackHit's is freed
1723 fNRecTracks = 0;
1724
1725 AliMUONTrackK a(this, fHitsForRecPtr); // bad idea ???
1726 // Loop over stations(1...) 5 and 4
1727 for (istat=4; istat>=3; istat--) {
1728 // Loop over segments in the station
1729 for (iseg=0; iseg<fNSegments[istat]; iseg++) {
1730 // Transform segments to tracks and evaluate covariance matrix
1731 segment = (AliMUONSegment*) ((*fSegmentsPtr[istat])[iseg]);
1732 trackK = new ((*fRecTracksPtr)[fNRecTracks]) AliMUONTrackK(segment);
1733 fNRecTracks++;
1734 } // for (iseg=0;...)
1735 } // for (istat=4;...)
1736 return;
1737}
1738
1739//__________________________________________________________________________
1740void AliMUONEventReconstructor::FollowTracksK(void)
1741{
1742 // Follow tracks using Kalman filter
30178c30 1743 Bool_t ok;
83dbc640 1744 Int_t icand, ichamBeg, ichamEnd, chamBits;
1745 Double_t zDipole1, zDipole2;
1746 AliMUONTrackK *trackK;
1747 AliMUONHitForRec *hit;
1748 AliMUONRawCluster *clus;
1749 TClonesArray *rawclusters;
1750 AliMUON *pMUON;
1751 clus = 0; rawclusters = 0;
1752
1753 zDipole1 = GetSimpleBPosition() - GetSimpleBLength()/2;
1754 zDipole2 = zDipole1 + GetSimpleBLength();
1755
1756 // Print hits
1757 pMUON = (AliMUON*) gAlice->GetModule("MUON");
1758 for (Int_t i1=0; i1<fNHitsForRec; i1++) {
1759 hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[i1]);
1760 //if (hit->GetTHTrack() > 1 || hit->GetGeantSignal() == 0) continue;
1761 /*
1762 cout << " Hit #" << hit->GetChamberNumber() << " ";
1763 cout << hit->GetBendingCoor() << " ";
1764 cout << hit->GetNonBendingCoor() << " ";
1765 cout << hit->GetZ() << " ";
1766 cout << hit->GetGeantSignal() << " ";
1767 cout << hit->GetTHTrack() << endl;
1768 */
1769 /*
1770 printf(" Hit # %d %10.4f %10.4f %10.4f",
1771 hit->GetChamberNumber(), hit->GetBendingCoor(),
1772 hit->GetNonBendingCoor(), hit->GetZ());
1773 if (fRecGeantHits) {
1774 // from GEANT hits
1775 printf(" %3d %3d \n", hit->GetGeantSignal(), hit->GetTHTrack());
1776 } else {
1777 // from raw clusters
1778 rawclusters = pMUON->RawClustAddress(hit->GetChamberNumber());
1779 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->
1780 GetHitNumber());
1781 printf("%3d", clus->fTracks[1]-1);
1782 if (clus->fTracks[2] != 0) printf("%3d \n", clus->fTracks[2]-1);
1783 else printf("\n");
1784 }
1785 */
1786 }
1787
1788 icand = -1;
1789 Int_t nSeeds = fNRecTracks; // starting number of seeds
1790 // Loop over track candidates
1791 while (icand < fNRecTracks-1) {
1792 icand ++;
1793 trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[icand]);
1794
1795 // Discard candidate which will produce the double track
1796 if (icand > 0) {
30178c30 1797 ok = CheckCandidateK(icand,nSeeds);
1798 if (!ok) {
83dbc640 1799 //trackK->SetRecover(-1); // mark candidate to be removed
1800 //continue;
1801 }
1802 }
1803
30178c30 1804 ok = kTRUE;
83dbc640 1805 if (trackK->GetRecover() == 0) hit = (AliMUONHitForRec*)
1806 trackK->GetHitOnTrack()->Last(); // last hit
1807 else hit = (AliMUONHitForRec*) (*trackK->GetHitOnTrack())[1]; // 2'nd hit
1808 ichamBeg = hit->GetChamberNumber();
1809 ichamEnd = 0;
1810 // Check propagation direction
1811 if (trackK->GetTrackDir() > 0) {
1812 ichamEnd = 9; // forward propagation
30178c30 1813 ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kFALSE,zDipole1,zDipole2);
1814 if (ok) {
83dbc640 1815 ichamBeg = ichamEnd;
1816 ichamEnd = 6; // backward propagation
1817 // Change weight matrix and zero fChi2 for backpropagation
1818 trackK->StartBack();
30178c30 1819 ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kTRUE,zDipole1,zDipole2);
83dbc640 1820 ichamBeg = ichamEnd;
1821 ichamEnd = 0;
1822 }
1823 } else {
1824 if (trackK->GetBPFlag()) {
1825 // backpropagation
1826 ichamEnd = 6; // backward propagation
1827 // Change weight matrix and zero fChi2 for backpropagation
1828 trackK->StartBack();
30178c30 1829 ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kTRUE,zDipole1,zDipole2);
83dbc640 1830 ichamBeg = ichamEnd;
1831 ichamEnd = 0;
1832 }
1833 }
1834
30178c30 1835 if (ok) {
83dbc640 1836 trackK->SetTrackDir(-1);
1837 trackK->SetBPFlag(kFALSE);
30178c30 1838 ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kFALSE,zDipole1,zDipole2);
83dbc640 1839 }
30178c30 1840 if (ok) trackK->SetTrackQuality(0); // compute "track quality"
83dbc640 1841 else trackK->SetRecover(-1); // mark candidate to be removed
1842
1843 // Majority 3 of 4 in first 2 stations
1844 chamBits = 0;
1845 for (Int_t i=0; i<trackK->GetNTrackHits(); i++) {
1846 hit = (AliMUONHitForRec*) (*trackK->GetHitOnTrack())[i];
1847 chamBits |= BIT(hit->GetChamberNumber()-1);
1848 }
1849 //if (!((chamBits&3)==3 || (chamBits>>2&3)==3)) trackK->SetRecover(-1);
1850 //mark candidate to be removed
1851 } // while
1852
1853 for (Int_t i=0; i<fNRecTracks; i++) {
1854 trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[i]);
1855 if (trackK->GetRecover() < 0) fRecTracksPtr->RemoveAt(i);
1856 }
1857
1858 // Compress TClonesArray
1859 fRecTracksPtr->Compress();
1860 fNRecTracks = fRecTracksPtr->GetEntriesFast();
1861 return;
1862}
1863
1864//__________________________________________________________________________
30178c30 1865Bool_t AliMUONEventReconstructor::CheckCandidateK(Int_t icand, Int_t nSeeds) const
83dbc640 1866{
1867 // Discards track candidate if it will produce the double track (having
1868 // the same seed segment hits as hits of a good track found before)
1869 AliMUONTrackK *track1, *track2;
1870 AliMUONHitForRec *hit1, *hit2, *hit;
1871
1872 track1 = (AliMUONTrackK*) ((*fRecTracksPtr)[icand]);
1873 hit1 = (AliMUONHitForRec*) (*track1->GetHitOnTrack())[0]; // 1'st hit
1874 hit2 = (AliMUONHitForRec*) (*track1->GetHitOnTrack())[1]; // 2'nd hit
1875
1876 for (Int_t i=0; i<icand; i++) {
1877 track2 = (AliMUONTrackK*) ((*fRecTracksPtr)[i]);
1878 //if (track2->GetRecover() < 0) continue;
1879 if (track2->GetRecover() < 0 && icand >= nSeeds) continue;
1880
1881 if (track1->GetStartSegment() == track2->GetStartSegment()) {
1882 return kFALSE;
1883 } else {
1884 Int_t nSame = 0;
1885 for (Int_t j=0; j<track2->GetNTrackHits(); j++) {
1886 hit = (AliMUONHitForRec*) (*track2->GetHitOnTrack())[j];
1887 if (hit == hit1 || hit == hit2) {
1888 nSame++;
1889 if (nSame == 2) return kFALSE;
1890 }
1891 } // for (Int_t j=0;
1892 }
1893 } // for (Int_t i=0;
1894 return kTRUE;
1895}
1896
1897//__________________________________________________________________________
1898void AliMUONEventReconstructor::RemoveDoubleTracksK(void)
1899{
1900 // Removes double tracks (sharing more than half of their hits). Keeps
1901 // the track with higher quality
1902 AliMUONTrackK *track1, *track2, *trackToKill;
1903
1904 // Sort tracks according to their quality
1905 fRecTracksPtr->Sort();
1906
1907 // Loop over first track of the pair
1908 track1 = (AliMUONTrackK*) fRecTracksPtr->First();
1909 while (track1) {
1910 // Loop over second track of the pair
1911 track2 = (AliMUONTrackK*) fRecTracksPtr->After(track1);
1912 while (track2) {
1913 // Check whether or not to keep track2
1914 if (!track2->KeepTrack(track1)) {
1915 cout << " Killed track: " << 1/(*track2->GetTrackParameters())(4,0) <<
1916 " " << track2->GetTrackQuality() << endl;
1917 trackToKill = track2;
1918 track2 = (AliMUONTrackK*) fRecTracksPtr->After(track2);
1919 trackToKill->Kill();
1920 fRecTracksPtr->Compress();
1921 } else track2 = (AliMUONTrackK*) fRecTracksPtr->After(track2);
1922 } // track2
1923 track1 = (AliMUONTrackK*) fRecTracksPtr->After(track1);
1924 } // track1
1925
1926 fNRecTracks = fRecTracksPtr->GetEntriesFast();
1927 cout << " Number of Kalman tracks: " << fNRecTracks << endl;
1928}
1929
1930//__________________________________________________________________________
1931void AliMUONEventReconstructor::GoToVertex(void)
1932{
1933 // Propagates track to the vertex thru absorber
1934 // (using Branson correction for now)
1935
1936 Double_t zVertex;
1937 zVertex = 0;
1938 for (Int_t i=0; i<fNRecTracks; i++) {
1939 //((AliMUONTrackK*)(*fRecTracksPtr)[i])->Branson();
1940 //((AliMUONTrackK*)(*fRecTracksPtr)[i])->GoToZ(zVertex); // w/out absorber
1941 ((AliMUONTrackK*)(*fRecTracksPtr)[i])->SetTrackQuality(1); // compute Chi2
1942 ((AliMUONTrackK*)(*fRecTracksPtr)[i])->GoToVertex(); // with absorber
1943 }
1944}