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