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