- Removing obsolete tags
[u/mrichter/AliRoot.git] / MUON / AliMUONVTrackReconstructor.cxx
CommitLineData
8d0843c6 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/* $Id$ */
17
06ca6d7b 18/// \class AliMUONVTrackReconstructor
8d0843c6 19////////////////////////////////////
06ca6d7b 20///
21/// Virtual MUON track reconstructor in ALICE (class renamed from AliMUONEventReconstructor)
22///
23/// This class contains as data:
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/// * EventReconstruct to build the muon tracks
30/// * EventReconstructTrigger to build the trigger tracks
31///
8d0843c6 32////////////////////////////////////
33
8d0843c6 34#include "AliMUONVTrackReconstructor.h"
35#include "AliMUONData.h"
36#include "AliMUONConstants.h"
37#include "AliMUONHitForRec.h"
208f139e 38#include "AliMUONObjectPair.h"
8d0843c6 39#include "AliMUONTriggerTrack.h"
e1a10d41 40#include "AliMUONTriggerCircuit.h"
8d0843c6 41#include "AliMUONLocalTrigger.h"
42#include "AliMUONGlobalTrigger.h"
8d0843c6 43#include "AliMUONTrack.h"
37827b29 44#include "AliMUONTrackParam.h"
45#include "AliMUONTrackExtrap.h"
4889d34c 46
8d0843c6 47#include "AliLog.h"
48#include "AliTracker.h"
49
4889d34c 50#include <Riostream.h>
51#include <TClonesArray.h>
52#include <TMath.h>
53
8d0843c6 54ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
55
56//************* Defaults parameters for reconstruction
57const Double_t AliMUONVTrackReconstructor::fgkDefaultMinBendingMomentum = 3.0;
58const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxBendingMomentum = 3000.0;
59const Double_t AliMUONVTrackReconstructor::fgkDefaultBendingResolution = 0.01;
60const Double_t AliMUONVTrackReconstructor::fgkDefaultNonBendingResolution = 0.144;
208f139e 61const Double_t AliMUONVTrackReconstructor::fgkDefaultBendingVertexDispersion = 10.;
62const Double_t AliMUONVTrackReconstructor::fgkDefaultNonBendingVertexDispersion = 10.;
63const Double_t AliMUONVTrackReconstructor::fgkDefaultMaxNormChi2MatchTrigger = 16.0;
8d0843c6 64
65//__________________________________________________________________________
66AliMUONVTrackReconstructor::AliMUONVTrackReconstructor(AliMUONData* data)
67 : TObject(),
68 fMinBendingMomentum(fgkDefaultMinBendingMomentum),
69 fMaxBendingMomentum(fgkDefaultMaxBendingMomentum),
70 fBendingResolution(fgkDefaultBendingResolution),
71 fNonBendingResolution(fgkDefaultNonBendingResolution),
208f139e 72 fBendingVertexDispersion(fgkDefaultBendingVertexDispersion),
73 fNonBendingVertexDispersion(fgkDefaultNonBendingVertexDispersion),
74 fMaxNormChi2MatchTrigger(fgkDefaultMaxNormChi2MatchTrigger),
8d0843c6 75 fSegmentMaxDistBending(0x0),
76 fSegmentMaxDistNonBending(0x0),
77 fHitsForRecPtr(0x0),
78 fNHitsForRec(0),
79 fNHitsForRecPerChamber(0x0),
80 fIndexOfFirstHitForRecPerChamber(0x0),
8d0843c6 81 fRecTracksPtr(0x0),
82 fNRecTracks(0),
83 fMUONData(data),
84 fTriggerTrack(new AliMUONTriggerTrack()),
85 fTriggerCircuit(0x0)
86{
87 /// Constructor for class AliMUONVTrackReconstructor
88 fSegmentMaxDistBending = new Double_t[AliMUONConstants::NTrackingSt()];
89 fSegmentMaxDistNonBending = new Double_t[AliMUONConstants::NTrackingSt()];
90 fNHitsForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
91 fIndexOfFirstHitForRecPerChamber = new Int_t[AliMUONConstants::NTrackingCh()];
92
93 SetReconstructionParametersToDefaults();
94
95 // Memory allocation for the TClonesArray of hits for reconstruction
96 // Is 10000 the right size ????
97 fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
98
208f139e 99 // set the magnetic field for track extrapolations
8d0843c6 100 const AliMagF* kField = AliTracker::GetFieldMap();
101 if (!kField) AliFatal("No field available");
37827b29 102 AliMUONTrackExtrap::SetField(kField);
8d0843c6 103}
104
105 //__________________________________________________________________________
106AliMUONVTrackReconstructor::~AliMUONVTrackReconstructor(void)
107{
108 /// Destructor for class AliMUONVTrackReconstructor
109 delete [] fSegmentMaxDistBending;
110 delete [] fSegmentMaxDistNonBending;
111 delete [] fNHitsForRecPerChamber;
112 delete [] fIndexOfFirstHitForRecPerChamber;
113 delete fTriggerTrack;
114 delete fHitsForRecPtr;
8d0843c6 115}
116
117 //__________________________________________________________________________
118void AliMUONVTrackReconstructor::SetReconstructionParametersToDefaults(void)
119{
120 /// Set reconstruction parameters for making segments to default values
121 // Would be much more convenient with a structure (or class) ????
122
123 // ******** Parameters for making segments
124 // should be parametrized ????
125 // according to interval between chambers in a station ????
126 // Maximum distance in non bending plane
127 // 5 * 0.22 just to remember the way it was made in TRACKF_STAT
128 // SIGCUT*DYMAX(IZ)
208f139e 129 for (Int_t st = 0; st < AliMUONConstants::NTrackingSt(); st++)
8d0843c6 130 fSegmentMaxDistNonBending[st] = 5. * 0.22;
131 // Maximum distance in bending plane:
132 // values from TRACKF_STAT, corresponding to (J psi 20cm),
133 // scaled to the real distance between chambers in a station
134 fSegmentMaxDistBending[0] = TMath::Abs( 1.5 *
135 (AliMUONConstants::DefaultChamberZ(1) - AliMUONConstants::DefaultChamberZ(0)) / 20.0);
136 fSegmentMaxDistBending[1] = TMath::Abs( 1.5 *
137 (AliMUONConstants::DefaultChamberZ(3) - AliMUONConstants::DefaultChamberZ(2)) / 20.0);
138 fSegmentMaxDistBending[2] = TMath::Abs( 3.0 *
139 (AliMUONConstants::DefaultChamberZ(5) - AliMUONConstants::DefaultChamberZ(4)) / 20.0);
140 fSegmentMaxDistBending[3] = TMath::Abs( 6.0 *
141 (AliMUONConstants::DefaultChamberZ(7) - AliMUONConstants::DefaultChamberZ(6)) / 20.0);
142 fSegmentMaxDistBending[4] = TMath::Abs( 6.0 *
143 (AliMUONConstants::DefaultChamberZ(9) - AliMUONConstants::DefaultChamberZ(8)) / 20.0);
144
145 return;
146}
147
148 //__________________________________________________________________________
149void AliMUONVTrackReconstructor::EventReconstruct(void)
150{
151 // To reconstruct one event
152 AliDebug(1,"Enter EventReconstruct");
153 ResetTracks(); //AZ
8d0843c6 154 ResetHitsForRec(); //AZ
155 AddHitsForRecFromRawClusters();
8d0843c6 156 MakeTracks();
157 if (fMUONData->IsTriggerTrackBranchesInTree())
158 ValidateTracksWithTrigger();
159
160 // Add tracks to MUON data container
161 for(Int_t i=0; i<fNRecTracks; i++) {
162 AliMUONTrack * track = (AliMUONTrack*) fRecTracksPtr->At(i);
163 fMUONData->AddRecTrack(*track);
164 }
165}
166
167 //__________________________________________________________________________
168void AliMUONVTrackReconstructor::ResetTracks(void)
169{
170 /// To reset the TClonesArray of reconstructed tracks
171 if (fRecTracksPtr) fRecTracksPtr->Delete();
172 // Delete in order that the Track destructors are called,
173 // hence the space for the TClonesArray of pointers to TrackHit's is freed
174 fNRecTracks = 0;
175 return;
176}
177
178 //__________________________________________________________________________
8d0843c6 179void AliMUONVTrackReconstructor::ResetHitsForRec(void)
180{
181 /// To reset the array and the number of HitsForRec,
182 /// and also the number of HitsForRec
183 /// and the index of the first HitForRec per chamber
184 if (fHitsForRecPtr) fHitsForRecPtr->Delete();
185 fNHitsForRec = 0;
186 for (Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++)
187 fNHitsForRecPerChamber[ch] = fIndexOfFirstHitForRecPerChamber[ch] = 0;
188 return;
189}
190
191 //__________________________________________________________________________
192void AliMUONVTrackReconstructor::SortHitsForRecWithIncreasingChamber()
193{
194 /// Sort HitsForRec's in increasing order with respect to chamber number.
195 /// Uses the function "Compare".
196 /// Update the information for HitsForRec per chamber too.
197 Int_t ch, nhits, prevch;
198 fHitsForRecPtr->Sort();
199 for (ch = 0; ch < AliMUONConstants::NTrackingCh(); ch++) {
200 fNHitsForRecPerChamber[ch] = 0;
201 fIndexOfFirstHitForRecPerChamber[ch] = 0;
202 }
203 prevch = 0; // previous chamber
204 nhits = 0; // number of hits in current chamber
205 // Loop over HitsForRec
206 for (Int_t hit = 0; hit < fNHitsForRec; hit++) {
207 // chamber number (0...)
208 ch = ((AliMUONHitForRec*) ((*fHitsForRecPtr)[hit]))->GetChamberNumber();
209 // increment number of hits in current chamber
210 (fNHitsForRecPerChamber[ch])++;
211 // update index of first HitForRec in current chamber
212 // if chamber number different from previous one
213 if (ch != prevch) {
214 fIndexOfFirstHitForRecPerChamber[ch] = hit;
215 prevch = ch;
216 }
217 }
218 return;
219}
220
221 //__________________________________________________________________________
208f139e 222TClonesArray* AliMUONVTrackReconstructor::MakeSegmentsInStation(Int_t station)
8d0843c6 223{
208f139e 224 /// To make the list of segments in station(0..) "Station" from the list of hits to be reconstructed.
225 /// Return a new TClonesArray of segments.
226 /// It is the responsibility of the user to delete it afterward.
227 AliDebug(1,Form("Enter MakeSegmentsPerStation (0...) %d",station));
228
8d0843c6 229 AliMUONHitForRec *hit1Ptr, *hit2Ptr;
208f139e 230 AliMUONObjectPair *segment;
231 Double_t bendingSlope, distBend, distNonBend, extBendCoor, extNonBendCoor, extrapFact;
232 Double_t impactParam = 0., bendingMomentum = 0.; // to avoid compilation warning
8d0843c6 233 // first and second chambers (0...) in the station
208f139e 234 Int_t ch1 = 2 * station;
8d0843c6 235 Int_t ch2 = ch1 + 1;
208f139e 236 // list of segments
237 TClonesArray *segments = new TClonesArray("AliMUONObjectPair", fNHitsForRecPerChamber[ch2]);
238 // Loop over HitForRec's in the first chamber of the station
8d0843c6 239 for (Int_t hit1 = fIndexOfFirstHitForRecPerChamber[ch1];
240 hit1 < fIndexOfFirstHitForRecPerChamber[ch1] + fNHitsForRecPerChamber[ch1];
241 hit1++) {
242 // pointer to the HitForRec
243 hit1Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit1]);
208f139e 244 // extrapolation, on the straight line joining the HitForRec to the vertex (0,0,0),
245 // to the Z of the HitForRec in the second chamber of the station
246 // Loop over HitsForRec's in the second chamber of the station
8d0843c6 247 for (Int_t hit2 = fIndexOfFirstHitForRecPerChamber[ch2];
248 hit2 < fIndexOfFirstHitForRecPerChamber[ch2] + fNHitsForRecPerChamber[ch2];
249 hit2++) {
250 // pointer to the HitForRec
251 hit2Ptr = (AliMUONHitForRec*) ((*fHitsForRecPtr)[hit2]);
252 // absolute values of distances, in bending and non bending planes,
253 // between the HitForRec in the second chamber
254 // and the previous extrapolation
255 extrapFact = hit2Ptr->GetZ()/ hit1Ptr->GetZ();
256 extBendCoor = extrapFact * hit1Ptr->GetBendingCoor();
257 extNonBendCoor = extrapFact * hit1Ptr->GetNonBendingCoor();
258 distBend = TMath::Abs(hit2Ptr->GetBendingCoor() - extBendCoor);
259 distNonBend = TMath::Abs(hit2Ptr->GetNonBendingCoor() - extNonBendCoor);
208f139e 260 // bending slope
261 if ( hit1Ptr->GetZ() - hit2Ptr->GetZ() != 0. ) {
262 bendingSlope = (hit1Ptr->GetBendingCoor() - hit2Ptr->GetBendingCoor()) / (hit1Ptr->GetZ() - hit2Ptr->GetZ());
263 // impact parameter
264 impactParam = hit1Ptr->GetBendingCoor() - hit1Ptr->GetZ() * bendingSlope;
265 // absolute value of bending momentum
266 bendingMomentum = TMath::Abs(AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(impactParam));
267 } else {
268 AliWarning("hit1Ptr->GetZ() = hit2Ptr->GetZ(): no segment created");
269 continue;
270 }
8d0843c6 271 // check for distances not too large,
272 // and impact parameter not too big if stations downstream of the dipole.
273 // Conditions "distBend" and "impactParam" correlated for these stations ????
208f139e 274 if ((distBend < fSegmentMaxDistBending[station]) && (distNonBend < fSegmentMaxDistNonBending[station]) &&
275 (bendingMomentum < fMaxBendingMomentum) && (bendingMomentum > fMinBendingMomentum)) {
8d0843c6 276 // make new segment
208f139e 277 segment = new ((*segments)[segments->GetLast()+1]) AliMUONObjectPair(hit1Ptr, hit2Ptr, kFALSE, kFALSE);
8d0843c6 278 if (AliLog::GetGlobalDebugLevel() > 1) {
208f139e 279 cout << "segmentIndex(0...): " << segments->GetLast()
8d0843c6 280 << " distBend: " << distBend
281 << " distNonBend: " << distNonBend
282 << endl;
283 segment->Dump();
284 cout << "HitForRec in first chamber" << endl;
285 hit1Ptr->Dump();
286 cout << "HitForRec in second chamber" << endl;
287 hit2Ptr->Dump();
208f139e 288 }
8d0843c6 289 }
290 } //for (Int_t hit2
291 } // for (Int_t hit1...
208f139e 292 AliDebug(1,Form("Station: %d NSegments: %d ", station, segments->GetEntriesFast()));
293 return segments;
8d0843c6 294}
295
296 //__________________________________________________________________________
297void AliMUONVTrackReconstructor::ValidateTracksWithTrigger(void)
298{
299 /// Try to match track from tracking system with trigger track
06ca6d7b 300 static const Double_t kDistSigma[3]={1,1,0.02}; // sigma of distributions (trigger-track) X,Y,slopeY
208f139e 301
8d0843c6 302 AliMUONTrack *track;
303 AliMUONTrackParam trackParam;
304 AliMUONTriggerTrack *triggerTrack;
305
306 fMUONData->SetTreeAddress("RL");
307 fMUONData->GetRecTriggerTracks();
308 TClonesArray *recTriggerTracks = fMUONData->RecTriggerTracks();
309
310 Bool_t matchTrigger;
c6ba19f7 311 Int_t loTrgNum;
8d0843c6 312 Double_t distTriggerTrack[3];
208f139e 313 Double_t xTrack, yTrack, ySlopeTrack, chi2MatchTrigger, minChi2MatchTrigger, chi2;
8d0843c6 314
315 track = (AliMUONTrack*) fRecTracksPtr->First();
316 while (track) {
317 matchTrigger = kFALSE;
318 chi2MatchTrigger = 0.;
c6ba19f7 319 loTrgNum = -1;
320
8d0843c6 321 trackParam = *((AliMUONTrackParam*) (track->GetTrackParamAtHit()->Last()));
37827b29 322 AliMUONTrackExtrap::ExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(10)); // extrap to 1st trigger chamber
8d0843c6 323
324 xTrack = trackParam.GetNonBendingCoor();
325 yTrack = trackParam.GetBendingCoor();
326 ySlopeTrack = trackParam.GetBendingSlope();
208f139e 327 minChi2MatchTrigger = 999.;
8d0843c6 328
329 triggerTrack = (AliMUONTriggerTrack*) recTriggerTracks->First();
330 while(triggerTrack){
06ca6d7b 331 distTriggerTrack[0] = (triggerTrack->GetX11()-xTrack)/kDistSigma[0];
332 distTriggerTrack[1] = (triggerTrack->GetY11()-yTrack)/kDistSigma[1];
333 distTriggerTrack[2] = (TMath::Tan(triggerTrack->GetThetay())-ySlopeTrack)/kDistSigma[2];
208f139e 334 chi2 = 0.;
335 for (Int_t iVar = 0; iVar < 3; iVar++) chi2 += distTriggerTrack[iVar]*distTriggerTrack[iVar];
336 chi2 /= 3.; // Normalized Chi2: 3 degrees of freedom (X,Y,slopeY)
337 if (chi2 < minChi2MatchTrigger && chi2 < fMaxNormChi2MatchTrigger) {
338 minChi2MatchTrigger = chi2;
8d0843c6 339 matchTrigger = kTRUE;
208f139e 340 chi2MatchTrigger = chi2;
42ef0c18 341 loTrgNum=triggerTrack->GetLoTrgNum();
8d0843c6 342 }
343 triggerTrack = (AliMUONTriggerTrack*) recTriggerTracks->After(triggerTrack);
344 }
345
346 track->SetMatchTrigger(matchTrigger);
c6ba19f7 347 track->SetLoTrgNum(loTrgNum);
8d0843c6 348 track->SetChi2MatchTrigger(chi2MatchTrigger);
8d0843c6 349 track = (AliMUONTrack*) fRecTracksPtr->After(track);
350 }
351
352 return;
353}
354
355//__________________________________________________________________________
356void AliMUONVTrackReconstructor::EventReconstructTrigger(void)
357{
358 /// To reconstruct trigger for one event
359 AliDebug(1,"Enter EventReconstructTrigger");
360 MakeTriggerTracks();
361 return;
362}
363
364 //__________________________________________________________________________
365Bool_t AliMUONVTrackReconstructor::MakeTriggerTracks(void)
366{
367 // To make the trigger tracks from Local Trigger
368 AliDebug(1, "Enter MakeTriggerTracks");
e6b25a6e 369
370 TTree* treeR;
e6b25a6e 371 UChar_t gloTrigPat;
372 TClonesArray *localTrigger;
373 TClonesArray *globalTrigger;
374 AliMUONLocalTrigger *locTrg;
375 AliMUONGlobalTrigger *gloTrg;
376
377 treeR = fMUONData->TreeR();
378 if (!treeR) {
379 AliWarning("TreeR is not loaded");
380 return kFALSE;
381 }
382
e6b25a6e 383 fMUONData->SetTreeAddress("TC");
384 fMUONData->GetTrigger();
8d0843c6 385
e6b25a6e 386 // global trigger for trigger pattern
387 gloTrigPat = 0;
388 globalTrigger = fMUONData->GlobalTrigger();
389 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
8d0843c6 390
e6b25a6e 391 if (gloTrg)
392 gloTrigPat = gloTrg->GetGlobalResponse();
393
394
395 // local trigger for tracking
396 localTrigger = fMUONData->LocalTrigger();
397 Int_t nlocals = (Int_t) (localTrigger->GetEntries());
8d0843c6 398
e6b25a6e 399 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
400 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
401
402 Float_t y11 = 0.;
403 Int_t stripX21 = 0;
404 Float_t y21 = 0.;
405 Float_t x11 = 0.;
406
407 for (Int_t i=0; i<nlocals; i++) { // loop on Local Trigger
408 locTrg = (AliMUONLocalTrigger*)localTrigger->UncheckedAt(i);
409
410 AliDebug(1, "AliMUONTrackReconstructor::MakeTriggerTrack using NEW trigger \n");
411 AliMUONTriggerCircuit* circuit =
412 (AliMUONTriggerCircuit*)fTriggerCircuit->At(locTrg->LoCircuit()-1); // -1 !!!
413
414 y11 = circuit->GetY11Pos(locTrg->LoStripX());
415 stripX21 = locTrg->LoStripX()+locTrg->LoDev()+1;
416 y21 = circuit->GetY21Pos(stripX21);
417 x11 = circuit->GetX11Pos(locTrg->LoStripY());
418
419 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %d %f %f %f \n",i,locTrg->LoCircuit(),
420 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
421
422 Float_t thetax = TMath::ATan2( x11 , z11 );
423 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
424
425 fTriggerTrack->SetX11(x11);
426 fTriggerTrack->SetY11(y11);
427 fTriggerTrack->SetThetax(thetax);
428 fTriggerTrack->SetThetay(thetay);
429 fTriggerTrack->SetGTPattern(gloTrigPat);
c6ba19f7 430 fTriggerTrack->SetLoTrgNum(i);
e6b25a6e 431
432 fMUONData->AddRecTriggerTrack(*fTriggerTrack);
433 } // end of loop on Local Trigger
434
435 return kTRUE;
8d0843c6 436}
437
438//__________________________________________________________________________
439void AliMUONVTrackReconstructor::EventDumpTrigger(void)
440{
441 /// Dump reconstructed trigger event
442 /// and the particle parameters
443 AliMUONTriggerTrack *triggertrack ;
444 Int_t nTriggerTracks = fMUONData->RecTriggerTracks()->GetEntriesFast();
445
446 AliDebug(1, "****** enter EventDumpTrigger ******");
447 AliDebug(1, Form("Number of Reconstructed tracks : %d ", nTriggerTracks));
448
449 // Loop over reconstructed tracks
450 for (Int_t trackIndex = 0; trackIndex < nTriggerTracks; trackIndex++) {
451 triggertrack = (AliMUONTriggerTrack*)fMUONData->RecTriggerTracks()->At(trackIndex);
452 printf(" trigger track number %i x11=%f y11=%f thetax=%f thetay=%f \n",
453 trackIndex,
454 triggertrack->GetX11(),triggertrack->GetY11(),
455 triggertrack->GetThetax(),triggertrack->GetThetay());
456 }
457}
458