]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONEventReconstructor.cxx
AliHitMap and AliSegmentation added
[u/mrichter/AliRoot.git] / MUON / AliMUONEventReconstructor.cxx
CommitLineData
a9e2aefa 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17$Log$
d82671a0 18Revision 1.5 2000/06/30 10:15:48 gosset
19Changes to EventReconstructor...:
20precision fit with multiple Coulomb scattering;
21extrapolation to vertex with Branson correction in absorber (JPC)
22
04b5ea16 23Revision 1.4 2000/06/27 14:11:36 gosset
24Corrections against violations of coding conventions
25
9cbdf048 26Revision 1.3 2000/06/16 07:27:08 gosset
27To remove problem in running RuleChecker, like in MUON-dev
28
79e1e601 29Revision 1.1.2.5 2000/06/16 07:00:26 gosset
30To remove problem in running RuleChecker
31
a9e2aefa 32Revision 1.1.2.4 2000/06/12 08:00:07 morsch
33Dummy streamer to solve CINT compilation problem (to be investigated !)
34
35Revision 1.1.2.3 2000/06/09 20:59:57 morsch
36Make includes consistent with new file structure.
37
38Revision 1.1.2.2 2000/06/09 12:58:05 gosset
39Removed comment beginnings in Log sections of .cxx files
40Suppressed most violations of coding rules
41
42Revision 1.1.2.1 2000/06/07 14:44:53 gosset
43Addition of files for track reconstruction in C++
44*/
45
46//__________________________________________________________________________
47//
48// MUON event reconstructor in ALICE
49//
50// This class contains as data:
51// * the parameters for the event reconstruction
52// * a pointer to the array of hits to be reconstructed (the event)
53// * a pointer to the array of segments made with these hits inside each station
54// * a pointer to the array of reconstructed tracks
55//
56// It contains as methods, among others:
57// * MakeEventToBeReconstructed to build the array of hits to be reconstructed
58// * MakeSegments to build the segments
59// * MakeTracks to build the tracks
60//__________________________________________________________________________
61
62#include <iostream.h>
63
64#include <TRandom.h>
65#include <TFile.h>
66
67#include "AliCallf77.h"
68#include "AliMUONEventReconstructor.h"
69#include "AliMUON.h"
70#include "AliMUONHitForRec.h"
71#include "AliMUONSegment.h"
72#include "AliMUONHit.h"
73#include "AliMUONRawCluster.h"
74#include "AliMUONTrack.h"
75#include "AliMUONChamber.h"
76#include "AliMUONTrackHit.h"
77#include "AliRun.h"
04b5ea16 78#include "TParticle.h"
a9e2aefa 79
80#ifndef WIN32
81# define initfield initfield_
82# define reco_gufld reco_gufld_
83#else
84# define initfield INITFIELD
85# define reco_gufld RECO_GUFLD
86#endif
87
88extern "C"
89{
90void type_of_call initfield();
91void type_of_call reco_gufld(Double_t *Coor, Double_t *Field);
92}
93
94//************* Defaults parameters for reconstruction
9cbdf048 95static const Double_t kDefaultMinBendingMomentum = 3.0;
96static const Double_t kDefaultMaxSigma2Distance = 16.0;
97static const Double_t kDefaultBendingResolution = 0.01;
98static const Double_t kDefaultNonBendingResolution = 0.144;
99static const Double_t kDefaultChamberThicknessInX0 = 0.03;
a9e2aefa 100// Simple magnetic field:
101// Value taken from macro MUONtracking.C: 0.7 T, hence 7 kG
102// Length and Position from reco_muon.F, with opposite sign:
103// Length = ZMAGEND-ZCOIL
104// Position = (ZMAGEND+ZCOIL)/2
105// to be ajusted differently from real magnetic field ????
9cbdf048 106static const Double_t kDefaultSimpleBValue = 7.0;
107static const Double_t kDefaultSimpleBLength = 428.0;
108static const Double_t kDefaultSimpleBPosition = 1019.0;
109static const Int_t kDefaultRecGeantHits = 0;
110static const Double_t kDefaultEfficiency = 0.95;
a9e2aefa 111
9cbdf048 112static const Int_t kDefaultPrintLevel = 0;
a9e2aefa 113
114ClassImp(AliMUONEventReconstructor) // Class implementation in ROOT context
115
116 //__________________________________________________________________________
117AliMUONEventReconstructor::AliMUONEventReconstructor(void)
118{
119 // Constructor for class AliMUONEventReconstructor
120 SetReconstructionParametersToDefaults();
121 // Memory allocation for the TClonesArray of hits for reconstruction
122 // Is 10000 the right size ????
123 fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
124 fNHitsForRec = 0; // really needed or GetEntriesFast sufficient ????
125 // Memory allocation for the TClonesArray's of segments in stations
126 // Is 2000 the right size ????
9cbdf048 127 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++) {
a9e2aefa 128 fSegmentsPtr[st] = new TClonesArray("AliMUONSegment", 2000);
129 fNSegments[st] = 0; // really needed or GetEntriesFast sufficient ????
130 }
131 // Memory allocation for the TClonesArray of reconstructed tracks
132 // Is 10 the right size ????
133 fRecTracksPtr = new TClonesArray("AliMUONTrack", 10);
134 fNRecTracks = 0; // really needed or GetEntriesFast sufficient ????
135
136 // Initialize magnetic field
137 // using Fortran subroutine INITFIELD in "reco_muon.F".
138 // Should rather use AliMagF ???? and remove prototyping ...
139 initfield();
140 // Impression de quelques valeurs
141 Double_t coor[3], field[3];
142 coor[0] = 50.0;
143 coor[1] = 50.0;
144 coor[2] = 950.0;
145 reco_gufld(coor, field);
146 cout << "coor: " << coor[0] << ", " << coor[1] << ", " << coor[2] << endl;
147 cout << "field: " << field[0] << ", " << field[1] << ", " << field[2] << endl;
148 coor[2] = -950.0;
149 reco_gufld(coor, field);
150 cout << "coor: " << coor[0] << ", " << coor[1] << ", " << coor[2] << endl;
151 cout << "field: " << field[0] << ", " << field[1] << ", " << field[2] << endl;
152 coor[2] = -950.0;
153
154 if (fPrintLevel >= 0) {
155 cout << "AliMUONEventReconstructor constructed with defaults" << endl; Dump();}
156 return;
157}
158
9cbdf048 159AliMUONEventReconstructor::AliMUONEventReconstructor (const AliMUONEventReconstructor& Reconstructor)
160{
161 // Dummy copy constructor
162}
163
164AliMUONEventReconstructor & AliMUONEventReconstructor::operator=(const AliMUONEventReconstructor& Reconstructor)
165{
166 // Dummy assignment operator
167 return *this;
168}
169
a9e2aefa 170 //__________________________________________________________________________
171AliMUONEventReconstructor::~AliMUONEventReconstructor(void)
172{
173 // Destructor for class AliMUONEventReconstructor
174 delete fHitsForRecPtr; // Correct destruction of everything ???? or delete [] ????
9cbdf048 175 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++)
a9e2aefa 176 delete fSegmentsPtr[st]; // Correct destruction of everything ????
177 return;
178}
179
180 //__________________________________________________________________________
181void AliMUONEventReconstructor::SetReconstructionParametersToDefaults(void)
182{
183 // Set reconstruction parameters to default values
184 // Would be much more convenient with a structure (or class) ????
9cbdf048 185 fMinBendingMomentum = kDefaultMinBendingMomentum;
186 fMaxSigma2Distance = kDefaultMaxSigma2Distance;
a9e2aefa 187
9cbdf048 188 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON");
a9e2aefa 189 // ******** Parameters for making HitsForRec
190 // minimum radius,
191 // like in TRACKF_STAT:
192 // 2 degrees for stations 1 and 2, or ch(0...) from 0 to 3;
193 // 30 cm for stations 3 to 5, or ch(0...) from 4 to 9
9cbdf048 194 for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
195 if (ch < 4) fRMin[ch] = TMath::Abs((&(pMUON->Chamber(ch)))->Z()) *
a9e2aefa 196 2.0 * TMath::Pi() / 180.0;
197 else fRMin[ch] = 30.0;
198 }
199 // maximum radius
200 // like in TRACKF_STAT (10 degrees ????)
201 fRMax[0] = fRMax[1] = 91.5;
202 fRMax[2] = fRMax[3] = 122.5;
203 fRMax[4] = fRMax[5] = 158.3;
204 fRMax[6] = fRMax[7] = 260.0;
205 fRMax[8] = fRMax[9] = 260.0;
206
207 // ******** Parameters for making segments
208 // should be parametrized ????
209 // according to interval between chambers in a station ????
210 // Maximum distance in non bending plane
211 // 5 * 0.22 just to remember the way it was made in TRACKF_STAT
212 // SIGCUT*DYMAX(IZ)
9cbdf048 213 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++)
a9e2aefa 214 fSegmentMaxDistNonBending[st] = 5. * 0.22;
215 // Maximum distance in bending plane
216 // values from TRACKF_STAT corresponding to (J psi 20cm)
217 fSegmentMaxDistBending[0] = 1.5;
218 fSegmentMaxDistBending[1] = 1.5;
219 fSegmentMaxDistBending[2] = 3.0;
220 fSegmentMaxDistBending[3] = 6.0;
221 fSegmentMaxDistBending[4] = 6.0;
222
9cbdf048 223 fBendingResolution = kDefaultBendingResolution;
224 fNonBendingResolution = kDefaultNonBendingResolution;
225 fChamberThicknessInX0 = kDefaultChamberThicknessInX0;
226 fSimpleBValue = kDefaultSimpleBValue;
227 fSimpleBLength = kDefaultSimpleBLength;
228 fSimpleBPosition = kDefaultSimpleBPosition;
229 fRecGeantHits = kDefaultRecGeantHits;
230 fEfficiency = kDefaultEfficiency;
231 fPrintLevel = kDefaultPrintLevel;
a9e2aefa 232 return;
233}
234
235//__________________________________________________________________________
236Double_t AliMUONEventReconstructor::GetImpactParamFromBendingMomentum(Double_t BendingMomentum)
237{
238 // Returns impact parameter at vertex in bending plane (cm),
239 // from the signed bending momentum "BendingMomentum" in bending plane (GeV/c),
240 // using simple values for dipole magnetic field.
241 // The sign is the sign of the charge.
242 return (-0.0003 * fSimpleBValue * fSimpleBLength * fSimpleBPosition /
243 BendingMomentum);
244}
245
246//__________________________________________________________________________
247Double_t AliMUONEventReconstructor::GetBendingMomentumFromImpactParam(Double_t ImpactParam)
248{
249 // Returns signed bending momentum in bending plane (GeV/c),
250 // from the impact parameter "ImpactParam" at vertex in bending plane (cm),
251 // using simple values for dipole magnetic field.
252 // The sign is the sign of the charge.
253 return (-0.0003 * fSimpleBValue * fSimpleBLength * fSimpleBPosition /
254 ImpactParam);
255}
256
257//__________________________________________________________________________
258void AliMUONEventReconstructor::SetBkgGeantFile(Text_t *BkgGeantFileName)
259{
260 // Set background file ... for GEANT hits
261 // Must be called after having loaded the firts signal event
262 if (fPrintLevel >= 0) {
263 cout << "Enter SetBkgGeantFile with BkgGeantFileName ``"
264 << BkgGeantFileName << "''" << endl;}
265 if (strlen(BkgGeantFileName)) {
266 // BkgGeantFileName not empty: try to open the file
267 if (fPrintLevel >= 2) {cout << "Before File(Bkg)" << endl; gDirectory->Dump();}
268 fBkgGeantFile = new TFile(BkgGeantFileName);
269 if (fPrintLevel >= 2) {cout << "After File(Bkg)" << endl; gDirectory->Dump();}
270 if (fBkgGeantFile-> IsOpen()) {
271 if (fPrintLevel >= 0) {
272 cout << "Background for GEANT hits in file: ``" << BkgGeantFileName
273 << "'' successfully opened" << endl;}
274 }
275 else {
276 cout << "Background for GEANT hits in file: " << BkgGeantFileName << endl;
277 cout << "NOT FOUND: EXIT" << endl;
278 exit(0); // right instruction for exit ????
279 }
280 // Arrays for "particles" and "hits"
281 fBkgGeantParticles = new TClonesArray("TParticle", 200);
282 fBkgGeantHits = new TClonesArray("AliMUONHit", 2000);
283 // Event number to -1 for initialization
284 fBkgGeantEventNumber = -1;
285 // Back to the signal file:
286 // first signal event must have been loaded previously,
287 // otherwise, Segmentation violation at the next instruction
288 // How is it possible to do smething better ????
289 ((gAlice->TreeK())->GetCurrentFile())->cd();
290 if (fPrintLevel >= 2) {cout << "After cd(gAlice)" << endl; gDirectory->Dump();}
291 }
292 return;
293}
294
295//__________________________________________________________________________
296void AliMUONEventReconstructor::NextBkgGeantEvent(void)
297{
298 // Get next event in background file for GEANT hits
299 // Goes back to event number 0 when end of file is reached
300 char treeName[20];
301 TBranch *branch;
302 if (fPrintLevel >= 0) {
303 cout << "Enter NextBkgGeantEvent" << endl;}
304 // Clean previous event
305 if(fBkgGeantTK) delete fBkgGeantTK;
306 fBkgGeantTK = NULL;
307 if(fBkgGeantParticles) fBkgGeantParticles->Clear();
308 if(fBkgGeantTH) delete fBkgGeantTH;
309 fBkgGeantTH = NULL;
310 if(fBkgGeantHits) fBkgGeantHits->Clear();
311 // Increment event number
312 fBkgGeantEventNumber++;
313 // Get access to Particles and Hits for event from background file
314 if (fPrintLevel >= 2) {cout << "Before cd(Bkg)" << endl; gDirectory->Dump();}
315 fBkgGeantFile->cd();
316 if (fPrintLevel >= 2) {cout << "After cd(Bkg)" << endl; gDirectory->Dump();}
317 // Particles: TreeK for event and branch "Particles"
318 sprintf(treeName, "TreeK%d", fBkgGeantEventNumber);
319 fBkgGeantTK = (TTree*)gDirectory->Get(treeName);
320 if (!fBkgGeantTK) {
321 if (fPrintLevel >= 0) {
322 cout << "Cannot find Kine Tree for background event: " <<
323 fBkgGeantEventNumber << endl;
324 cout << "Goes back to event 0" << endl;
325 }
326 fBkgGeantEventNumber = 0;
327 sprintf(treeName, "TreeK%d", fBkgGeantEventNumber);
328 fBkgGeantTK = (TTree*)gDirectory->Get(treeName);
329 if (!fBkgGeantTK) {
330 cout << "ERROR: cannot find Kine Tree for background event: " <<
331 fBkgGeantEventNumber << endl;
332 exit(0);
333 }
334 }
335 if (fBkgGeantTK)
336 fBkgGeantTK->SetBranchAddress("Particles", &fBkgGeantParticles);
337 fBkgGeantTK->GetEvent(0); // why event 0 ???? necessary ????
338 // Hits: TreeH for event and branch "MUON"
339 sprintf(treeName, "TreeH%d", fBkgGeantEventNumber);
340 fBkgGeantTH = (TTree*)gDirectory->Get(treeName);
341 if (!fBkgGeantTH) {
342 cout << "ERROR: cannot find Hits Tree for background event: " <<
343 fBkgGeantEventNumber << endl;
344 exit(0);
345 }
346 if (fBkgGeantTH && fBkgGeantHits) {
347 branch = fBkgGeantTH->GetBranch("MUON");
348 if (branch) branch->SetAddress(&fBkgGeantHits);
349 }
350 fBkgGeantTH->GetEntries(); // necessary ????
351 // Back to the signal file
352 ((gAlice->TreeK())->GetCurrentFile())->cd();
353 if (fPrintLevel >= 2) {cout << "After cd(gAlice)" << endl; gDirectory->Dump();}
354 return;
355}
356
357//__________________________________________________________________________
358void AliMUONEventReconstructor::EventReconstruct(void)
359{
360 // To reconstruct one event
361 if (fPrintLevel >= 1) cout << "enter EventReconstruct" << endl;
362 MakeEventToBeReconstructed();
363 MakeSegments();
364 MakeTracks();
365 return;
366}
367
368 //__________________________________________________________________________
369void AliMUONEventReconstructor::ResetHitsForRec(void)
370{
371 // To reset the array and the number of HitsForRec,
372 // and also the number of HitsForRec
373 // and the index of the first HitForRec per chamber
374 if (fHitsForRecPtr) fHitsForRecPtr->Clear();
375 fNHitsForRec = 0;
9cbdf048 376 for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++)
a9e2aefa 377 fNHitsForRecPerChamber[ch] = fIndexOfFirstHitForRecPerChamber[ch] = 0;
378 return;
379}
380
381 //__________________________________________________________________________
382void AliMUONEventReconstructor::ResetSegments(void)
383{
384 // To reset the TClonesArray of segments and the number of Segments
385 // for all stations
9cbdf048 386 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++) {
a9e2aefa 387 if (fSegmentsPtr[st]) fSegmentsPtr[st]->Clear();
388 fNSegments[st] = 0;
389 }
390 return;
391}
392
393 //__________________________________________________________________________
394void AliMUONEventReconstructor::ResetTracks(void)
395{
396 // To reset the TClonesArray of reconstructed tracks
397 if (fRecTracksPtr) fRecTracksPtr->Clear();
398 fNRecTracks = 0;
399 return;
400}
401
402 //__________________________________________________________________________
403void AliMUONEventReconstructor::MakeEventToBeReconstructed(void)
404{
405 // To make the list of hits to be reconstructed,
406 // either from the GEANT hits or from the raw clusters
407 // according to the parameter set for the reconstructor
408 if (fPrintLevel >= 1) cout << "enter MakeEventToBeReconstructed" << endl;
409 ResetHitsForRec();
410 if (fRecGeantHits == 1) {
411 // Reconstruction from GEANT hits
412 // Back to the signal file
413 ((gAlice->TreeK())->GetCurrentFile())->cd();
414 // Signal hits
415 // AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
416 // Security on MUON ????
417 AddHitsForRecFromGEANT(gAlice->TreeH());
418 // Background hits
419 AddHitsForRecFromBkgGEANT(fBkgGeantTH, fBkgGeantHits);
420 // Sort HitsForRec in increasing order with respect to chamber number
421 SortHitsForRecWithIncreasingChamber();
422 }
423 else {
424 // Reconstruction from raw clusters
425 // AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
426 // Security on MUON ????
427 // TreeR assumed to be be "prepared" in calling function
428 // by "MUON->GetTreeR(nev)" ????
9cbdf048 429 TTree *treeR = gAlice->TreeR();
430 AddHitsForRecFromRawClusters(treeR);
a9e2aefa 431 // No sorting: it is done automatically in the previous function
432 }
433 if (fPrintLevel >= 10) {
434 cout << "end of MakeEventToBeReconstructed" << endl;
435 cout << "NHitsForRec: " << fNHitsForRec << endl;
9cbdf048 436 for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
a9e2aefa 437 cout << "chamber(0...): " << ch
438 << " NHitsForRec: " << fNHitsForRecPerChamber[ch]
439 << " index(first HitForRec): " << fIndexOfFirstHitForRecPerChamber[ch]
440 << endl;
441 for (Int_t hit = fIndexOfFirstHitForRecPerChamber[ch];
442 hit < fIndexOfFirstHitForRecPerChamber[ch] + fNHitsForRecPerChamber[ch];
443 hit++) {
444 cout << "HitForRec index(0...): " << hit << endl;
445 ((*fHitsForRecPtr)[hit])->Dump();
446 }
447 }
448 }
449 return;
450}
451
452 //__________________________________________________________________________
453void AliMUONEventReconstructor::AddHitsForRecFromGEANT(TTree *TH)
454{
455 // To add to the list of hits for reconstruction
456 // the GEANT signal hits from a hit tree TH.
457 if (fPrintLevel >= 2)
458 cout << "enter AddHitsForRecFromGEANT with TH: " << TH << endl;
459 if (TH == NULL) return;
9cbdf048 460 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
a9e2aefa 461 // Security on MUON ????
462 // See whether it could be the same for signal and background ????
463 // Loop over tracks in tree
464 Int_t ntracks = (Int_t) TH->GetEntries();
465 if (fPrintLevel >= 2)
466 cout << "ntracks: " << ntracks << endl;
467 for (Int_t track = 0; track < ntracks; track++) {
468 gAlice->ResetHits();
469 TH->GetEvent(track);
470 // Loop over hits
471 Int_t hit = 0;
9cbdf048 472 for (AliMUONHit* mHit = (AliMUONHit*) pMUON->FirstHit(-1);
a9e2aefa 473 mHit;
9cbdf048 474 mHit = (AliMUONHit*) pMUON->NextHit(), hit++) {
a9e2aefa 475 NewHitForRecFromGEANT(mHit,track, hit, 1);
476 } // end of hit loop
477 } // end of track loop
478 return;
479}
480
481 //__________________________________________________________________________
482void AliMUONEventReconstructor::AddHitsForRecFromBkgGEANT(TTree *TH, TClonesArray *Hits)
483{
484 // To add to the list of hits for reconstruction
485 // the GEANT background hits from a hit tree TH and a pointer Hits to a hit list.
486 // How to have only one function "AddHitsForRecFromGEANT" ????
487 if (fPrintLevel >= 2)
488 cout << "enter AddHitsForRecFromBkgGEANT with TH: " << TH << endl;
489 if (TH == NULL) return;
490 // Loop over tracks in tree
491 Int_t ntracks = (Int_t) TH->GetEntries();
492 if (fPrintLevel >= 2)
493 cout << "ntracks: " << ntracks << endl;
494 for (Int_t track = 0; track < ntracks; track++) {
495 if (Hits) Hits->Clear();
496 TH->GetEvent(track);
497 // Loop over hits
498 for (Int_t hit = 0; hit < Hits->GetEntriesFast(); hit++) {
499 NewHitForRecFromGEANT((AliMUONHit*) (*Hits)[hit], track, hit, 0);
500 } // end of hit loop
501 } // end of track loop
502 return;
503}
504
505 //__________________________________________________________________________
506AliMUONHitForRec* AliMUONEventReconstructor::NewHitForRecFromGEANT(AliMUONHit* Hit, Int_t TrackNumber, Int_t HitNumber, Int_t Signal)
507{
508 // To make a new hit for reconstruction from a GEANT hit pointed to by "Hit",
509 // with hit number "HitNumber" in the track numbered "TrackNumber",
510 // either from signal ("Signal" = 1) or background ("Signal" = 0) event.
511 // Selects hits in tracking (not trigger) chambers.
512 // Takes into account the efficiency (fEfficiency)
513 // and the smearing from resolution (fBendingResolution and fNonBendingResolution).
514 // Adds a condition on the radius between RMin and RMax
515 // to better simulate the real chambers.
516 // Returns the pointer to the new hit for reconstruction,
517 // or NULL in case of inefficiency or non tracking chamber or bad radius.
518 // No condition on at most 20 cm from a muon from a resonance
519 // like in Fortran TRACKF_STAT.
520 AliMUONHitForRec* hitForRec;
521 Double_t bendCoor, nonBendCoor, radius;
522 Int_t chamber = Hit->fChamber - 1; // chamber(0...)
523 // only in tracking chambers (fChamber starts at 1)
9cbdf048 524 if (chamber >= kMaxMuonTrackingChambers) return NULL;
a9e2aefa 525 // only if hit is efficient (keep track for checking ????)
526 if (gRandom->Rndm() > fEfficiency) return NULL;
527 // only if radius between RMin and RMax
528 bendCoor = Hit->fY;
529 nonBendCoor = Hit->fX;
530 radius = TMath::Sqrt((bendCoor * bendCoor) + (nonBendCoor * nonBendCoor));
531 if ((radius < fRMin[chamber]) || (radius > fRMax[chamber])) return NULL;
532 // new AliMUONHitForRec from GEANT hit and increment number of AliMUONHitForRec's
533 hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(Hit);
534 fNHitsForRec++;
535 // add smearing from resolution
536 hitForRec->SetBendingCoor(bendCoor + gRandom->Gaus(0., fBendingResolution));
537 hitForRec->SetNonBendingCoor(nonBendCoor
538 + gRandom->Gaus(0., fNonBendingResolution));
539 // more information into HitForRec
540 // resolution: angular effect to be added here ????
541 hitForRec->SetBendingReso2(fBendingResolution * fBendingResolution);
542 hitForRec->SetNonBendingReso2(fNonBendingResolution * fNonBendingResolution);
543 // GEANT track info
544 hitForRec->SetHitNumber(HitNumber);
545 hitForRec->SetTHTrack(TrackNumber);
546 hitForRec->SetGeantSignal(Signal);
547 if (fPrintLevel >= 10) {
548 cout << "track: " << TrackNumber << " hit: " << HitNumber << endl;
549 Hit->Dump();
550 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
551 hitForRec->Dump();}
552 return hitForRec;
553}
554
555 //__________________________________________________________________________
556void AliMUONEventReconstructor::SortHitsForRecWithIncreasingChamber()
557{
558 // Sort HitsForRec's in increasing order with respect to chamber number.
559 // Uses the function "Compare".
560 // Update the information for HitsForRec per chamber too.
561 Int_t ch, nhits, prevch;
562 fHitsForRecPtr->Sort();
9cbdf048 563 for (ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
a9e2aefa 564 fNHitsForRecPerChamber[ch] = 0;
565 fIndexOfFirstHitForRecPerChamber[ch] = 0;
566 }
567 prevch = 0; // previous chamber
568 nhits = 0; // number of hits in current chamber
569 // Loop over HitsForRec
570 for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
571 // chamber number (0...)
572 ch = ((AliMUONHitForRec*) ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
573 // increment number of hits in current chamber
574 (fNHitsForRecPerChamber[ch])++;
575 // update index of first HitForRec in current chamber
576 // if chamber number different from previous one
577 if (ch != prevch) {
578 fIndexOfFirstHitForRecPerChamber[ch] = hit;
579 prevch = ch;
580 }
581 }
582 return;
583}
584
585// //__________________________________________________________________________
586// void AliMUONEventReconstructor::AddHitsForRecFromCathodeCorrelations(TTree* TC)
587// {
588// // OLD VERSION WHEN ONE ONE WAS USING SO CALLED CATHODE CORRELATIONS
589// // To add to the list of hits for reconstruction
590// // the (cathode correlated) raw clusters
591// // No condition added, like in Fortran TRACKF_STAT,
592// // on the radius between RMin and RMax.
593// AliMUONHitForRec *hitForRec;
594// if (fPrintLevel >= 1) cout << "enter AddHitsForRecFromCathodeCorrelations" << endl;
595// AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
596// // Security on MUON ????
597// // Loop over tracking chambers
9cbdf048 598// for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
a9e2aefa 599// // number of HitsForRec to 0 for the chamber
600// fNHitsForRecPerChamber[ch] = 0;
601// // index of first HitForRec for the chamber
602// if (ch == 0) fIndexOfFirstHitForRecPerChamber[ch] = 0;
603// else fIndexOfFirstHitForRecPerChamber[ch] = fNHitsForRec;
604// TClonesArray *reconst_hits = MUON->ReconstHitsAddress(ch);
605// MUON->ResetReconstHits();
606// TC->GetEvent();
607// Int_t ncor = (Int_t)reconst_hits->GetEntries();
608// // Loop over (cathode correlated) raw clusters
609// for (Int_t cor = 0; cor < ncor; cor++) {
610// AliMUONReconstHit * mCor =
611// (AliMUONReconstHit*) reconst_hits->UncheckedAt(cor);
612// // new AliMUONHitForRec from (cathode correlated) raw cluster
613// // and increment number of AliMUONHitForRec's (total and in chamber)
614// hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(mCor);
615// fNHitsForRec++;
616// (fNHitsForRecPerChamber[ch])++;
617// // more information into HitForRec
618// hitForRec->SetChamberNumber(ch);
619// hitForRec->SetHitNumber(cor);
620// // Z coordinate of the chamber (cm) with sign opposite to GEANT sign
621// // could (should) be more exact from chamber geometry ????
622// hitForRec->SetZ(-(&(MUON->Chamber(ch)))->Z());
623// if (fPrintLevel >= 10) {
624// cout << "chamber (0...): " << ch <<
625// " cathcorrel (0...): " << cor << endl;
626// mCor->Dump();
627// cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
628// hitForRec->Dump();}
629// } // end of cluster loop
630// } // end of chamber loop
631// return;
632// }
633
634 //__________________________________________________________________________
635void AliMUONEventReconstructor::AddHitsForRecFromRawClusters(TTree* TR)
636{
637 // To add to the list of hits for reconstruction all the raw clusters
638 // No condition added, like in Fortran TRACKF_STAT,
639 // on the radius between RMin and RMax.
640 AliMUONHitForRec *hitForRec;
641 AliMUONRawCluster *clus;
642 Int_t iclus, nclus;
643 TClonesArray *rawclusters;
644 if (fPrintLevel >= 1) cout << "enter AddHitsForRecFromRawClusters" << endl;
9cbdf048 645 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
a9e2aefa 646 // Security on MUON ????
647 // Loop over tracking chambers
9cbdf048 648 for (Int_t ch = 0; ch < kMaxMuonTrackingChambers; ch++) {
a9e2aefa 649 // number of HitsForRec to 0 for the chamber
650 fNHitsForRecPerChamber[ch] = 0;
651 // index of first HitForRec for the chamber
652 if (ch == 0) fIndexOfFirstHitForRecPerChamber[ch] = 0;
653 else fIndexOfFirstHitForRecPerChamber[ch] = fNHitsForRec;
9cbdf048 654 rawclusters = pMUON->RawClustAddress(ch);
655 pMUON->ResetRawClusters();
a9e2aefa 656 TR->GetEvent((Int_t) (TR->GetEntries()) - 1); // to be checked ????
657 nclus = (Int_t) (rawclusters->GetEntries());
658 // Loop over (cathode correlated) raw clusters
659 for (iclus = 0; iclus < nclus; iclus++) {
660 clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(iclus);
661 // new AliMUONHitForRec from raw cluster
662 // and increment number of AliMUONHitForRec's (total and in chamber)
663 hitForRec = new ((*fHitsForRecPtr)[fNHitsForRec]) AliMUONHitForRec(clus);
664 fNHitsForRec++;
665 (fNHitsForRecPerChamber[ch])++;
666 // more information into HitForRec
667 // resolution: info should be already in raw cluster and taken from it ????
668 hitForRec->SetBendingReso2(fBendingResolution * fBendingResolution);
669 hitForRec->SetNonBendingReso2(fNonBendingResolution * fNonBendingResolution);
670 // original raw cluster
671 hitForRec->SetChamberNumber(ch);
672 hitForRec->SetHitNumber(iclus);
673 // Z coordinate of the chamber (cm) with sign opposite to GEANT sign
674 // could (should) be more exact from chamber geometry ????
9cbdf048 675 hitForRec->SetZ(-(&(pMUON->Chamber(ch)))->Z());
a9e2aefa 676 if (fPrintLevel >= 10) {
677 cout << "chamber (0...): " << ch <<
678 " raw cluster (0...): " << iclus << endl;
679 clus->Dump();
680 cout << "AliMUONHitForRec number (1...): " << fNHitsForRec << endl;
681 hitForRec->Dump();}
682 } // end of cluster loop
683 } // end of chamber loop
684 return;
685}
686
687 //__________________________________________________________________________
688void AliMUONEventReconstructor::MakeSegments(void)
689{
690 // To make the list of segments in all stations,
691 // from the list of hits to be reconstructed
692 if (fPrintLevel >= 1) cout << "enter MakeSegments" << endl;
693 ResetSegments();
694 // Loop over stations
9cbdf048 695 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++)
a9e2aefa 696 MakeSegmentsPerStation(st);
697 if (fPrintLevel >= 10) {
698 cout << "end of MakeSegments" << endl;
9cbdf048 699 for (Int_t st = 0; st < kMaxMuonTrackingStations; st++) {
a9e2aefa 700 cout << "station(0...): " << st
701 << " Segments: " << fNSegments[st]
702 << endl;
703 for (Int_t seg = 0;
704 seg < fNSegments[st];
705 seg++) {
706 cout << "Segment index(0...): " << seg << endl;
707 ((*fSegmentsPtr[st])[seg])->Dump();
708 }
709 }
710 }
711 return;
712}
713
714 //__________________________________________________________________________
715void AliMUONEventReconstructor::MakeSegmentsPerStation(Int_t Station)
716{
717 // To make the list of segments in station number "Station" (0...)
718 // from the list of hits to be reconstructed.
719 // Updates "fNSegments"[Station].
720 // Segments in stations 4 and 5 are sorted
721 // according to increasing absolute value of "impact parameter"
722 AliMUONHitForRec *hit1Ptr, *hit2Ptr;
723 AliMUONSegment *segment;
724 Bool_t last2st;
725 Double_t bendingSlope, distBend, distNonBend, extBendCoor, extNonBendCoor,
726 impactParam, maxImpactParam;
9cbdf048 727 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
a9e2aefa 728 if (fPrintLevel >= 1)
729 cout << "enter MakeSegmentsPerStation (0...) " << Station << endl;
730 // first and second chambers (0...) in the station
731 Int_t ch1 = 2 * Station;
732 Int_t ch2 = ch1 + 1;
733 // variable true for stations downstream of the dipole:
734 // Station(0..4) equal to 3 or 4
735 if ((Station == 3) || (Station == 4)) {
736 last2st = kTRUE;
737 // maximum impact parameter (cm) according to fMinBendingMomentum...
738 maxImpactParam =
739 TMath::Abs(GetImpactParamFromBendingMomentum(fMinBendingMomentum));
740 }
741 else last2st = kFALSE;
742 // extrapolation factor from Z of first chamber to Z of second chamber
743 // dZ to be changed to take into account fine structure of chambers ????
744 Double_t extrapFact =
9cbdf048 745 (&(pMUON->Chamber(ch2)))->Z() / (&(pMUON->Chamber(ch1)))->Z();
a9e2aefa 746 // index for current segment
747 Int_t segmentIndex = 0;
748 // Loop over HitsForRec in the first chamber of the station
749 for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
750 hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
751 hit1++) {
752 // pointer to the HitForRec
753 hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
754 // extrapolation,
755 // on the straight line joining the HitForRec to the vertex (0,0,0),
756 // to the Z of the second chamber of the station
757 extBendCoor = extrapFact * hit1Ptr->GetBendingCoor();
758 extNonBendCoor = extrapFact * hit1Ptr->GetNonBendingCoor();
759 // Loop over HitsForRec in the second chamber of the station
760 for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
761 hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
762 hit2++) {
763 // pointer to the HitForRec
764 hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
765 // absolute values of distances, in bending and non bending planes,
766 // between the HitForRec in the second chamber
767 // and the previous extrapolation
768 distBend = TMath::Abs(hit2Ptr->GetBendingCoor() - extBendCoor);
769 distNonBend = TMath::Abs(hit2Ptr->GetNonBendingCoor() - extNonBendCoor);
770 if (last2st) {
771 // bending slope
772 bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) /
773 (hit1Ptr->GetZ() - hit2Ptr->GetZ());
774 // absolute value of impact parameter
775 impactParam =
776 TMath::Abs(hit1Ptr->GetBendingCoor() - hit2Ptr->GetZ() * bendingSlope);
777 }
778 // check for distances not too large,
779 // and impact parameter not too big if stations downstream of the dipole.
780 // Conditions "distBend" and "impactParam" correlated for these stations ????
781 if ((distBend < fSegmentMaxDistBending[Station]) &&
782 (distNonBend < fSegmentMaxDistNonBending[Station]) &&
783 (!last2st || (impactParam < maxImpactParam))) {
784 // make new segment
785 segment = new ((*fSegmentsPtr[Station])[segmentIndex])
786 AliMUONSegment(hit1Ptr, hit2Ptr);
787 // update "link" to this segment from the hit in the first chamber
788 if (hit1Ptr->GetNSegments() == 0)
789 hit1Ptr->SetIndexOfFirstSegment(segmentIndex);
790 hit1Ptr->SetNSegments(hit1Ptr->GetNSegments() + 1);
791 if (fPrintLevel >= 10) {
792 cout << "segmentIndex(0...): " << segmentIndex
793 << " distBend: " << distBend
794 << " distNonBend: " << distNonBend
795 << endl;
796 segment->Dump();
797 cout << "HitForRec in first chamber" << endl;
798 hit1Ptr->Dump();
799 cout << "HitForRec in second chamber" << endl;
800 hit2Ptr->Dump();
801 };
802 // increment index for current segment
803 segmentIndex++;
804 }
805 } //for (Int_t hit2
806 } // for (Int_t hit1...
807 fNSegments[Station] = segmentIndex;
808 // Sorting according to "impact parameter" if station(1..5) 4 or 5,
809 // i.e. Station(0..4) 3 or 4, using the function "Compare".
810 // After this sorting, it is impossible to use
811 // the "fNSegments" and "fIndexOfFirstSegment"
812 // of the HitForRec in the first chamber to explore all segments formed with it.
813 // Is this sorting really needed ????
814 if ((Station == 3) || (Station == 4)) (fSegmentsPtr[Station])->Sort();
815 if (fPrintLevel >= 1) cout << "Station: " << Station << " NSegments: "
816 << fNSegments[Station] << endl;
817 return;
818}
819
820 //__________________________________________________________________________
821void AliMUONEventReconstructor::MakeTracks(void)
822{
823 // To make the tracks,
824 // from the list of segments and points in all stations
825 if (fPrintLevel >= 1) cout << "enter MakeTracks" << endl;
826 ResetTracks();
827 // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
828 MakeTrackCandidates();
829 // Follow tracks in stations(1..) 3, 2 and 1
830 FollowTracks();
831 return;
832}
833
834 //__________________________________________________________________________
835Int_t AliMUONEventReconstructor::MakeTrackCandidatesWithTwoSegments(AliMUONSegment *BegSegment)
836{
837 // To make track candidates with two segments in stations(1..) 4 and 5,
838 // the first segment being pointed to by "BegSegment".
839 // Returns the number of such track candidates.
840 Int_t endStation, iEndSegment, nbCan2Seg;
841 AliMUONSegment *endSegment, *extrapSegment;
842 AliMUONTrack *recTrack;
843 Double_t mcsFactor;
844 if (fPrintLevel >= 1) cout << "enter MakeTrackCandidatesWithTwoSegments" << endl;
845 // Station for the end segment
846 endStation = 7 - (BegSegment->GetHitForRec1())->GetChamberNumber() / 2;
847 // multiple scattering factor corresponding to one chamber
848 mcsFactor = 0.0136 /
849 GetBendingMomentumFromImpactParam(BegSegment->GetBendingImpact());
850 mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
851 // linear extrapolation to end station
852 extrapSegment =
853 BegSegment->CreateSegmentFromLinearExtrapToStation(endStation, mcsFactor);
854 // number of candidates with 2 segments to 0
855 nbCan2Seg = 0;
856 // Loop over segments in the end station
857 for (iEndSegment = 0; iEndSegment < fNSegments[endStation]; iEndSegment++) {
858 // pointer to segment
859 endSegment = (AliMUONSegment*) ((*fSegmentsPtr[endStation])[iEndSegment]);
860 // test compatibility between current segment and "extrapSegment"
04b5ea16 861 // 4 because 4 quantities in chi2
a9e2aefa 862 if ((endSegment->
863 NormalizedChi2WithSegment(extrapSegment,
864 fMaxSigma2Distance)) <= 4.0) {
865 // both segments compatible:
866 // make track candidate from "begSegment" and "endSegment"
867 if (fPrintLevel >= 2)
868 cout << "TrackCandidate with Segment " << iEndSegment <<
869 " in Station(0..) " << endStation << endl;
870 // flag for both segments in one track:
871 // to be done in track constructor ????
872 BegSegment->SetInTrack(kTRUE);
873 endSegment->SetInTrack(kTRUE);
874 recTrack = new ((*fRecTracksPtr)[fNRecTracks])
875 AliMUONTrack(BegSegment, endSegment, this);
876 fNRecTracks++;
877 if (fPrintLevel >= 10) recTrack->RecursiveDump();
878 // increment number of track candidates with 2 segments
879 nbCan2Seg++;
880 }
881 } // for (iEndSegment = 0;...
882 delete extrapSegment; // should not delete HitForRec's it points to !!!!
883 return nbCan2Seg;
884}
885
886 //__________________________________________________________________________
887Int_t AliMUONEventReconstructor::MakeTrackCandidatesWithOneSegmentAndOnePoint(AliMUONSegment *BegSegment)
888{
889 // To make track candidates with one segment and one point
890 // in stations(1..) 4 and 5,
891 // the segment being pointed to by "BegSegment".
892 Int_t ch, ch1, ch2, endStation, iHit, iHitMax, iHitMin, nbCan1Seg1Hit;
893 AliMUONHitForRec *extrapHitForRec, *hit;
894 AliMUONTrack *recTrack;
895 Double_t mcsFactor;
896 if (fPrintLevel >= 1)
897 cout << "enter MakeTrackCandidatesWithOneSegmentAndOnePoint" << endl;
898 // station for the end point
899 endStation = 7 - (BegSegment->GetHitForRec1())->GetChamberNumber() / 2;
900 // multiple scattering factor corresponding to one chamber
901 mcsFactor = 0.0136 /
902 GetBendingMomentumFromImpactParam(BegSegment->GetBendingImpact());
903 mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
904 // first and second chambers(0..) in the end station
905 ch1 = 2 * endStation;
906 ch2 = ch1 + 1;
907 // number of candidates to 0
908 nbCan1Seg1Hit = 0;
909 // Loop over chambers of the end station
910 for (ch = ch2; ch >= ch1; ch--) {
911 // linear extrapolation to chamber
912 extrapHitForRec =
913 BegSegment->CreateHitForRecFromLinearExtrapToChamber(ch, mcsFactor);
914 // limits for the hit index in the loop
915 iHitMin = fIndexOfFirstHitForRecPerChamber[ch];
916 iHitMax = iHitMin + fNHitsForRecPerChamber[ch];
917 // Loop over HitForRec's in the chamber
918 for (iHit = iHitMin; iHit < iHitMax; iHit++) {
919 // pointer to HitForRec
920 hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[iHit]);
921 // test compatibility between current HitForRec and "extrapHitForRec"
04b5ea16 922 // 2 because 2 quantities in chi2
a9e2aefa 923 if ((hit->
924 NormalizedChi2WithHitForRec(extrapHitForRec,
925 fMaxSigma2Distance)) <= 2.0) {
926 // both HitForRec's compatible:
927 // make track candidate from begSegment and current HitForRec
928 if (fPrintLevel >= 2)
929 cout << "TrackCandidate with HitForRec " << iHit <<
930 " in Chamber(0..) " << ch << endl;
931 // flag for beginning segments in one track:
932 // to be done in track constructor ????
933 BegSegment->SetInTrack(kTRUE);
934 recTrack = new ((*fRecTracksPtr)[fNRecTracks])
935 AliMUONTrack(BegSegment, hit, this);
936 // the right place to eliminate "double counting" ???? how ????
937 fNRecTracks++;
938 if (fPrintLevel >= 10) recTrack->RecursiveDump();
939 // increment number of track candidates
940 nbCan1Seg1Hit++;
941 }
942 } // for (iHit = iHitMin;...
943 delete extrapHitForRec;
944 } // for (ch = ch2;...
945 return nbCan1Seg1Hit;
946}
947
948 //__________________________________________________________________________
949void AliMUONEventReconstructor::MakeTrackCandidates(void)
950{
951 // To make track candidates
952 // with at least 3 aligned points in stations(1..) 4 and 5
953 // (two Segment's or one Segment and one HitForRec)
954 Int_t begStation, iBegSegment, nbCan1Seg1Hit, nbCan2Seg;
955 AliMUONSegment *begSegment;
956 if (fPrintLevel >= 1) cout << "enter MakeTrackCandidates" << endl;
957 // Loop over stations(1..) 5 and 4 for the beginning segment
958 for (begStation = 4; begStation > 2; begStation--) {
959 // Loop over segments in the beginning station
960 for (iBegSegment = 0; iBegSegment < fNSegments[begStation]; iBegSegment++) {
961 // pointer to segment
962 begSegment = (AliMUONSegment*) ((*fSegmentsPtr[begStation])[iBegSegment]);
963 if (fPrintLevel >= 2)
964 cout << "look for TrackCandidate's with Segment " << iBegSegment <<
965 " in Station(0..) " << begStation << endl;
966 // Look for track candidates with two segments,
967 // "begSegment" and all compatible segments in other station.
968 // Only for beginning station(1..) 5
969 // because candidates with 2 segments have to looked for only once.
970 if (begStation == 4)
971 nbCan2Seg = MakeTrackCandidatesWithTwoSegments(begSegment);
972 // Look for track candidates with one segments and one point,
973 // "begSegment" and all compatible HitForRec's in other station.
974 // Only if "begSegment" does not belong already to a track candidate.
975 // Is that a too strong condition ????
976 if (!(begSegment->GetInTrack()))
977 nbCan1Seg1Hit = MakeTrackCandidatesWithOneSegmentAndOnePoint(begSegment);
978 } // for (iBegSegment = 0;...
979 } // for (begStation = 4;...
980 return;
981}
982
983 //__________________________________________________________________________
984void AliMUONEventReconstructor::FollowTracks(void)
985{
986 // Follow tracks in stations(1..) 3, 2 and 1
04b5ea16 987 // too long: should be made more modular !!!!
a9e2aefa 988 AliMUONHitForRec *bestHit, *extrapHit, *hit;
989 AliMUONSegment *bestSegment, *extrapSegment, *segment;
04b5ea16 990 AliMUONTrack *track, *nextTrack;
991 AliMUONTrackParam *trackParam1, trackParam[2], trackParamVertex;
d82671a0 992 Int_t ch, chInStation, chBestHit, iHit, iSegment, station, trackIndex;
04b5ea16 993 Double_t bestChi2, chi2, dZ1, dZ2, dZ3, maxSigma2Distance, mcsFactor;
9cbdf048 994 AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
04b5ea16 995 // local maxSigma2Distance, for easy increase in testing
996 maxSigma2Distance = fMaxSigma2Distance;
a9e2aefa 997 if (fPrintLevel >= 2)
998 cout << "enter FollowTracks" << endl;
999 // Loop over track candidates
04b5ea16 1000 track = (AliMUONTrack*) fRecTracksPtr->First();
1001 trackIndex = -1;
1002 while (track) {
1003 // Follow function for each track candidate ????
1004 trackIndex++;
1005 nextTrack = (AliMUONTrack*) fRecTracksPtr->After(track); // prepare next track
a9e2aefa 1006 if (fPrintLevel >= 2)
1007 cout << "FollowTracks: track candidate(0..): " << trackIndex << endl;
a9e2aefa 1008 // Fit track candidate from vertex at X = Y = 0
04b5ea16 1009 track->SetFitMCS(0); // fit without Multiple Scattering
a9e2aefa 1010 track->Fit(track->GetTrackParamAtVertex(), 3);
1011 if (fPrintLevel >= 10) {
1012 cout << "FollowTracks: track candidate(0..): " << trackIndex
1013 << " after fit in stations(1..) 4 and 5" << endl;
1014 track->RecursiveDump();
1015 }
1016 // Loop over stations(1..) 3, 2 and 1
04b5ea16 1017 // something SPECIAL for stations 2 and 1 for majority 3 coincidence ????
1018 // otherwise: majority coincidence 2 !!!!
a9e2aefa 1019 for (station = 2; station >= 0; station--) {
1020 // Track parameters at first track hit (smallest Z)
1021 trackParam1 = ((AliMUONTrackHit*)
1022 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
1023 // extrapolation to station
1024 trackParam1->ExtrapToStation(station, trackParam);
79e1e601 1025 extrapSegment = new AliMUONSegment(); // empty segment
a9e2aefa 1026 // multiple scattering factor corresponding to one chamber
1027 // and momentum in bending plane (not total)
1028 mcsFactor = 0.0136 * trackParam1->GetInverseBendingMomentum();
1029 mcsFactor = fChamberThicknessInX0 * mcsFactor * mcsFactor;
1030 // Z difference from previous station
9cbdf048 1031 dZ1 = (&(pMUON->Chamber(2 * station)))->Z() -
1032 (&(pMUON->Chamber(2 * station + 2)))->Z();
a9e2aefa 1033 // Z difference between the two previous stations
9cbdf048 1034 dZ2 = (&(pMUON->Chamber(2 * station + 2)))->Z() -
1035 (&(pMUON->Chamber(2 * station + 4)))->Z();
04b5ea16 1036 // Z difference between the two chambers in the previous station
1037 dZ3 = (&(pMUON->Chamber(2 * station)))->Z() -
1038 (&(pMUON->Chamber(2 * station + 1)))->Z();
1039 extrapSegment->SetBendingCoorReso2(fBendingResolution * fBendingResolution);
1040 extrapSegment->
1041 SetNonBendingCoorReso2(fNonBendingResolution * fNonBendingResolution);
1042 extrapSegment->UpdateFromStationTrackParam
1043 (trackParam, mcsFactor, dZ1, dZ2, dZ3, station,
1044 trackParam1->GetInverseBendingMomentum());
a9e2aefa 1045 bestChi2 = 5.0;
1046 bestSegment = NULL;
1047 if (fPrintLevel >= 10) {
1048 cout << "FollowTracks: track candidate(0..): " << trackIndex
1049 << " Look for segment in station(0..): " << station << endl;
1050 }
1051 // Loop over segments in station
1052 for (iSegment = 0; iSegment < fNSegments[station]; iSegment++) {
1053 // Look for best compatible Segment in station
1054 // should consider all possibilities ????
1055 // multiple scattering ????
1056 // separation in 2 functions: Segment and HitForRec ????
1057 segment = (AliMUONSegment*) ((*fSegmentsPtr[station])[iSegment]);
1058 chi2 = segment->NormalizedChi2WithSegment(extrapSegment, maxSigma2Distance);
1059 if (chi2 < bestChi2) {
1060 // update best Chi2 and Segment if better found
1061 bestSegment = segment;
1062 bestChi2 = chi2;
1063 }
1064 }
1065 if (bestSegment) {
1066 // best segment found: add it to track candidate
1067 track->AddSegment(bestSegment);
1068 // set track parameters at these two TrakHit's
1069 track->SetTrackParamAtHit(track->GetNTrackHits() - 2, &(trackParam[0]));
1070 track->SetTrackParamAtHit(track->GetNTrackHits() - 1, &(trackParam[1]));
1071 if (fPrintLevel >= 10) {
1072 cout << "FollowTracks: track candidate(0..): " << trackIndex
1073 << " Added segment in station(0..): " << station << endl;
1074 track->RecursiveDump();
1075 }
1076 }
1077 else {
1078 // No best segment found:
1079 // Look for best compatible HitForRec in station:
1080 // should consider all possibilities ????
1081 // multiple scattering ???? do about like for extrapSegment !!!!
79e1e601 1082 extrapHit = new AliMUONHitForRec(); // empty hit
a9e2aefa 1083 bestChi2 = 3.0;
1084 bestHit = NULL;
1085 if (fPrintLevel >= 10) {
1086 cout << "FollowTracks: track candidate(0..): " << trackIndex
1087 << " Segment not found, look for hit in station(0..): " << station
1088 << endl;
1089 }
1090 // Loop over chambers of the station
d82671a0 1091 for (chInStation = 0; chInStation < 2; chInStation++) {
a9e2aefa 1092 // coordinates of extrapolated hit
d82671a0 1093 extrapHit->
1094 SetBendingCoor((&(trackParam[chInStation]))->GetBendingCoor());
1095 extrapHit->
1096 SetNonBendingCoor((&(trackParam[chInStation]))->GetNonBendingCoor());
a9e2aefa 1097 // resolutions from "extrapSegment"
1098 extrapHit->SetBendingReso2(extrapSegment->GetBendingCoorReso2());
1099 extrapHit->SetNonBendingReso2(extrapSegment->GetNonBendingCoorReso2());
1100 // Loop over hits in the chamber
d82671a0 1101 ch = 2 * station + ch;
a9e2aefa 1102 for (iHit = fIndexOfFirstHitForRecPerChamber[ch];
1103 iHit < fIndexOfFirstHitForRecPerChamber[ch] +
1104 fNHitsForRecPerChamber[ch];
1105 iHit++) {
1106 hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[iHit]);
1107 // condition for hit not already in segment ????
1108 chi2 = hit->NormalizedChi2WithHitForRec(extrapHit, maxSigma2Distance);
1109 if (chi2 < bestChi2) {
1110 // update best Chi2 and HitForRec if better found
1111 bestHit = hit;
1112 bestChi2 = chi2;
d82671a0 1113 chBestHit = chInStation;
a9e2aefa 1114 }
1115 }
1116 }
1117 if (bestHit) {
1118 // best hit found: add it to track candidate
1119 track->AddHitForRec(bestHit);
d82671a0 1120 // set track parameters at these two TrackHit's
a9e2aefa 1121 track->SetTrackParamAtHit(track->GetNTrackHits() - 1,
1122 &(trackParam[chBestHit]));
1123 if (fPrintLevel >= 10) {
1124 cout << "FollowTracks: track candidate(0..): " << trackIndex
1125 << " Added hit in station(0..): " << station << endl;
1126 track->RecursiveDump();
1127 }
1128 }
1129 else {
04b5ea16 1130 // Remove current track candidate and update fNRecTracks
1131 // To be checked: recursive delete of TrackHit's !!!!
1132 // For cleaner implementation: call track->Remove()
1133 // to be coded, with all cleanings,
1134 // including links between HitForRec's and TrackHit's !!!!
1135 fRecTracksPtr->Remove(track);
1136 fNRecTracks--;
1137 delete extrapSegment;
a9e2aefa 1138 break; // stop the search for this candidate:
1139 // exit from the loop over station
1140 }
1141 }
04b5ea16 1142 delete extrapSegment;
a9e2aefa 1143 // Sort track hits according to increasing Z
1144 track->GetTrackHitsPtr()->Sort();
1145 // Update track parameters at first track hit (smallest Z)
1146 trackParam1 = ((AliMUONTrackHit*)
1147 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
04b5ea16 1148 // Track fit from first track hit varying X and Y,
1149 // with multiple Coulomb scattering if all stations
1150 if (station == 0) track->SetFitMCS(1);
1151 else track->SetFitMCS(0);
a9e2aefa 1152 track->Fit(trackParam1, 5);
1153 if (fPrintLevel >= 10) {
1154 cout << "FollowTracks: track candidate(0..): " << trackIndex
1155 << " after fit from station(0..): " << station << " to 4" << endl;
1156 track->RecursiveDump();
1157 }
04b5ea16 1158 // Track extrapolation to the vertex through the absorber (Branson)
1159 if (station == 0) {
1160 trackParamVertex = *trackParam1;
1161 (&trackParamVertex)->ExtrapToVertex();
1162 track->SetTrackParamAtVertex(&trackParamVertex);
1163 }
1164 if (fPrintLevel >= 1) {
1165 cout << "FollowTracks: track candidate(0..): " << trackIndex
d82671a0 1166 << " after extrapolation to vertex" << endl;
1167 track->RecursiveDump();
04b5ea16 1168 }
a9e2aefa 1169 } // for (station = 2;...
04b5ea16 1170 // go really to next track
1171 track = nextTrack;
1172 } // while (track)
1173 // Compression of track array (necessary after Remove ????)
1174 fRecTracksPtr->Compress();
1175 return;
1176}
1177
1178 //__________________________________________________________________________
1179void AliMUONEventReconstructor::EventDump(void)
1180{
1181 // Dump reconstructed event (track parameters at vertex and at first hit),
1182 // and the particle parameters
1183
1184 AliMUONTrack *track;
1185 AliMUONTrackParam *trackParam, *trackParam1;
1186 TClonesArray *particles; // pointer to the particle list
1187 TParticle *p;
1188 Double_t bendingSlope, nonBendingSlope, pYZ;
1189 Double_t pX, pY, pZ, x, y, z, c;
1190 Int_t np, trackIndex, nTrackHits;
1191
1192 if (fPrintLevel >= 1) cout << "****** enter EventDump ******" << endl;
1193 if (fPrintLevel >= 1) {
1194 cout << " Number of Reconstructed tracks :" << fNRecTracks << endl;
1195 }
1196 fRecTracksPtr->Compress(); // for simple loop without "Next" since no hole
1197 // Loop over reconstructed tracks
1198 for (trackIndex = 0; trackIndex < fNRecTracks; trackIndex++) {
1199 if (fPrintLevel >= 1)
1200 cout << " track number: " << trackIndex << endl;
1201 // function for each track for modularity ????
1202 track = (AliMUONTrack*) ((*fRecTracksPtr)[trackIndex]);
1203 nTrackHits = track->GetNTrackHits();
1204 if (fPrintLevel >= 1)
1205 cout << " number of track hits: " << nTrackHits << endl;
1206 // track parameters at Vertex
1207 trackParam = track->GetTrackParamAtVertex();
1208 x = trackParam->GetNonBendingCoor();
1209 y = trackParam->GetBendingCoor();
1210 z = trackParam->GetZ();
1211 bendingSlope = trackParam->GetBendingSlope();
1212 nonBendingSlope = trackParam->GetNonBendingSlope();
1213 pYZ = 1/TMath::Abs(trackParam->GetInverseBendingMomentum());
1214 pZ = pYZ/TMath::Sqrt(1+bendingSlope*bendingSlope);
1215 pX = pZ * nonBendingSlope;
1216 pY = pZ * bendingSlope;
1217 c = TMath::Sign(1.0, trackParam->GetInverseBendingMomentum());
1218 if (fPrintLevel >= 1)
1219 printf(" track parameters at Vertex z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
1220 z, x, y, pX, pY, pZ, c);
1221
1222 // track parameters at first hit
1223 trackParam1 = ((AliMUONTrackHit*)
1224 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
1225 x = trackParam1->GetNonBendingCoor();
1226 y = trackParam1->GetBendingCoor();
1227 z = trackParam1->GetZ();
1228 bendingSlope = trackParam1->GetBendingSlope();
1229 nonBendingSlope = trackParam1->GetNonBendingSlope();
1230 pYZ = 1/TMath::Abs(trackParam1->GetInverseBendingMomentum());
1231 pZ = pYZ/TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
1232 pX = pZ * nonBendingSlope;
1233 pY = pZ * bendingSlope;
1234 c = TMath::Sign(1.0, trackParam1->GetInverseBendingMomentum());
1235 if (fPrintLevel >= 1)
1236 printf(" track parameters at z= %f: X= %f Y= %f pX= %f pY= %f pZ= %f c= %f\n",
1237 z, x, y, pX, pY, pZ, c);
1238 }
1239 // informations about generated particles
1240 particles = gAlice->Particles();
1241 np = particles->GetEntriesFast();
1242 printf(" **** number of generated particles: %d \n", np);
1243
1244 for (Int_t iPart = 0; iPart < np; iPart++) {
1245 p = (TParticle*) particles->UncheckedAt(iPart);
1246 printf(" particle %d: type= %d px= %f py= %f pz= %f pdg= %d\n",
1247 iPart, p->GetPdgCode(), p->Px(), p->Py(), p->Pz(), p->GetPdgCode());
1248 }
a9e2aefa 1249 return;
1250}
1251
1252void AliMUONEventReconstructor::Streamer(TBuffer &R__b)
1253{
1254 ;
1255}