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