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