Adding the DCS data points in the GRP preprocessor - Implementation of the process...
[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
34#include <stdlib.h>
35#include <Riostream.h>
208f139e 36#include <TClonesArray.h>
9edefa04 37#include <TMath.h>
38#include <TTree.h>
8d0843c6 39
40#include "AliMUONVTrackReconstructor.h"
41#include "AliMUONData.h"
42#include "AliMUONConstants.h"
43#include "AliMUONHitForRec.h"
208f139e 44#include "AliMUONObjectPair.h"
8d0843c6 45#include "AliMUONTriggerTrack.h"
e1a10d41 46#include "AliMUONTriggerCircuit.h"
8d0843c6 47#include "AliMUONLocalTrigger.h"
48#include "AliMUONGlobalTrigger.h"
8d0843c6 49#include "AliMUONTrack.h"
37827b29 50#include "AliMUONTrackParam.h"
51#include "AliMUONTrackExtrap.h"
8d0843c6 52#include "AliMagF.h"
53#include "AliLog.h"
54#include "AliTracker.h"
55
56ClassImp(AliMUONVTrackReconstructor) // Class implementation in ROOT context
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;
8d0843c6 313 Double_t distTriggerTrack[3];
208f139e 314 Double_t xTrack, yTrack, ySlopeTrack, chi2MatchTrigger, minChi2MatchTrigger, chi2;
8d0843c6 315
316 track = (AliMUONTrack*) fRecTracksPtr->First();
317 while (track) {
318 matchTrigger = kFALSE;
319 chi2MatchTrigger = 0.;
320
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;
8d0843c6 341 }
342 triggerTrack = (AliMUONTriggerTrack*) recTriggerTracks->After(triggerTrack);
343 }
344
345 track->SetMatchTrigger(matchTrigger);
346 track->SetChi2MatchTrigger(chi2MatchTrigger);
347
348 track = (AliMUONTrack*) fRecTracksPtr->After(track);
349 }
350
351 return;
352}
353
354//__________________________________________________________________________
355void AliMUONVTrackReconstructor::EventReconstructTrigger(void)
356{
357 /// To reconstruct trigger for one event
358 AliDebug(1,"Enter EventReconstructTrigger");
359 MakeTriggerTracks();
360 return;
361}
362
363 //__________________________________________________________________________
364Bool_t AliMUONVTrackReconstructor::MakeTriggerTracks(void)
365{
366 // To make the trigger tracks from Local Trigger
367 AliDebug(1, "Enter MakeTriggerTracks");
e6b25a6e 368
369 TTree* treeR;
e6b25a6e 370 UChar_t gloTrigPat;
371 TClonesArray *localTrigger;
372 TClonesArray *globalTrigger;
373 AliMUONLocalTrigger *locTrg;
374 AliMUONGlobalTrigger *gloTrg;
375
376 treeR = fMUONData->TreeR();
377 if (!treeR) {
378 AliWarning("TreeR is not loaded");
379 return kFALSE;
380 }
381
e6b25a6e 382 fMUONData->SetTreeAddress("TC");
383 fMUONData->GetTrigger();
8d0843c6 384
e6b25a6e 385 // global trigger for trigger pattern
386 gloTrigPat = 0;
387 globalTrigger = fMUONData->GlobalTrigger();
388 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
8d0843c6 389
e6b25a6e 390 if (gloTrg)
391 gloTrigPat = gloTrg->GetGlobalResponse();
392
393
394 // local trigger for tracking
395 localTrigger = fMUONData->LocalTrigger();
396 Int_t nlocals = (Int_t) (localTrigger->GetEntries());
8d0843c6 397
e6b25a6e 398 Float_t z11 = AliMUONConstants::DefaultChamberZ(10);
399 Float_t z21 = AliMUONConstants::DefaultChamberZ(12);
400
401 Float_t y11 = 0.;
402 Int_t stripX21 = 0;
403 Float_t y21 = 0.;
404 Float_t x11 = 0.;
405
406 for (Int_t i=0; i<nlocals; i++) { // loop on Local Trigger
407 locTrg = (AliMUONLocalTrigger*)localTrigger->UncheckedAt(i);
408
409 AliDebug(1, "AliMUONTrackReconstructor::MakeTriggerTrack using NEW trigger \n");
410 AliMUONTriggerCircuit* circuit =
411 (AliMUONTriggerCircuit*)fTriggerCircuit->At(locTrg->LoCircuit()-1); // -1 !!!
412
413 y11 = circuit->GetY11Pos(locTrg->LoStripX());
414 stripX21 = locTrg->LoStripX()+locTrg->LoDev()+1;
415 y21 = circuit->GetY21Pos(stripX21);
416 x11 = circuit->GetX11Pos(locTrg->LoStripY());
417
418 AliDebug(1, Form(" MakeTriggerTrack %d %d %d %d %d %f %f %f \n",i,locTrg->LoCircuit(),
419 locTrg->LoStripX(),locTrg->LoStripX()+locTrg->LoDev()+1,locTrg->LoStripY(),y11, y21, x11));
420
421 Float_t thetax = TMath::ATan2( x11 , z11 );
422 Float_t thetay = TMath::ATan2( (y21-y11) , (z21-z11) );
423
424 fTriggerTrack->SetX11(x11);
425 fTriggerTrack->SetY11(y11);
426 fTriggerTrack->SetThetax(thetax);
427 fTriggerTrack->SetThetay(thetay);
428 fTriggerTrack->SetGTPattern(gloTrigPat);
429
430 fMUONData->AddRecTriggerTrack(*fTriggerTrack);
431 } // end of loop on Local Trigger
432
433 return kTRUE;
8d0843c6 434}
435
436//__________________________________________________________________________
437void AliMUONVTrackReconstructor::EventDumpTrigger(void)
438{
439 /// Dump reconstructed trigger event
440 /// and the particle parameters
441 AliMUONTriggerTrack *triggertrack ;
442 Int_t nTriggerTracks = fMUONData->RecTriggerTracks()->GetEntriesFast();
443
444 AliDebug(1, "****** enter EventDumpTrigger ******");
445 AliDebug(1, Form("Number of Reconstructed tracks : %d ", nTriggerTracks));
446
447 // Loop over reconstructed tracks
448 for (Int_t trackIndex = 0; trackIndex < nTriggerTracks; trackIndex++) {
449 triggertrack = (AliMUONTriggerTrack*)fMUONData->RecTriggerTracks()->At(trackIndex);
450 printf(" trigger track number %i x11=%f y11=%f thetax=%f thetay=%f \n",
451 trackIndex,
452 triggertrack->GetX11(),triggertrack->GetY11(),
453 triggertrack->GetThetax(),triggertrack->GetThetay());
454 }
455}
456