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