Implementation of trigger response re-calculation with a 4/4 coincidence or after...
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackHitPattern.cxx
CommitLineData
7771752e 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
ea94c18b 16/* $Id$ */
17
18
3d1463c8 19//-----------------------------------------------------------------------------
7771752e 20/// \class AliMUONTrackHitPattern
21///
22/// This class propagates tracks to trigger chambers
683cb6c5 23/// searching for matching trigger tracks and fired strips.
7771752e 24///
25/// To each track, a hit pattern for trigger chambers is set.
67c201be 26///
7771752e 27/// The main method is:
683cb6c5 28/// * ExecuteValidation
7771752e 29///
30/// \author Diego Stocco
3d1463c8 31//-----------------------------------------------------------------------------
7771752e 32
33
34#include "AliMUONTrackHitPattern.h"
7ec3b9cf 35
7771752e 36#include "AliMUONConstants.h"
7ec3b9cf 37#include "AliMUONVDigit.h"
38#include "AliMUONDigitMaker.h"
39#include "AliMUONDigitStoreV1.h"
7771752e 40#include "AliMUONGeometryTransformer.h"
7771752e 41#include "AliMUONLocalTrigger.h"
7771752e 42#include "AliMUONLocalTriggerBoard.h"
a0dc65b4 43#include "AliMUONRecoParam.h"
7ec3b9cf 44#include "AliMUONTrack.h"
45#include "AliMUONTrackExtrap.h"
46#include "AliMUONTrackParam.h"
47#include "AliMUONVTrackStore.h"
48#include "AliMUONVTriggerStore.h"
7771752e 49#include "AliMpPad.h"
7771752e 50#include "AliMpSegmentation.h"
7ec3b9cf 51#include "AliMpVSegmentation.h"
fda59e58 52#include "AliMpDEManager.h"
53#include "AliMUONReconstructor.h"
683cb6c5 54#include "AliMUONTriggerTrack.h"
55#include "AliMUONVTriggerTrackStore.h"
56
57#include "AliMpConstants.h"
ea94c18b 58
ea94c18b 59#include "AliLog.h"
7771752e 60#include "AliTracker.h"
67c201be 61#include "AliESDMuonTrack.h"
ea94c18b 62
7771752e 63#include <Riostream.h>
7ec3b9cf 64#include <TArrayS.h>
7771752e 65#include <TClonesArray.h>
66#include <TMath.h>
67#include <TMatrixD.h>
683cb6c5 68#include <TROOT.h>
69#include <TDirectory.h>
70#include <TFile.h>
71#include <TSystem.h>
6e97fbb8 72#include <TVector2.h>
683cb6c5 73
74#include <cassert>
7771752e 75
76/// \cond CLASSIMP
77ClassImp(AliMUONTrackHitPattern) // Class implementation in ROOT context
78/// \endcond
79
80
81//______________________________________________________________________________
a0dc65b4 82AliMUONTrackHitPattern::AliMUONTrackHitPattern(const AliMUONRecoParam* recoParam,
83 const AliMUONGeometryTransformer& transformer,
7ec3b9cf 84 const AliMUONDigitMaker& digitMaker)
a0dc65b4 85: TObject(),
9b1e069f 86fkRecoParam(recoParam),
87fkTransformer(transformer),
88fkDigitMaker(digitMaker),
a0dc65b4 89fDeltaZ(0.0),
90fTrigCovariance(0x0),
91fkMaxDistance(99999.)
7771752e 92{
93 /// Default constructor
683cb6c5 94 InitMembers();
f7a1cc68 95 AliMUONTrackExtrap::SetField();
7771752e 96}
97
98
99//______________________________________________________________________________
100AliMUONTrackHitPattern::~AliMUONTrackHitPattern(void)
101{
7ec3b9cf 102 /// Destructor
683cb6c5 103 delete fTrigCovariance;
7771752e 104}
105
106
107//______________________________________________________________________________
683cb6c5 108void AliMUONTrackHitPattern::InitMembers()
7771752e 109{
683cb6c5 110 //
111 /// Initialize data members
112 //
37a615ac 113 fDeltaZ = AliMUONConstants::DefaultChamberZ(10) - AliMUONConstants::DefaultChamberZ(12);
683cb6c5 114
115 const Double_t kTrigNonBendReso = AliMUONConstants::TriggerNonBendingReso();
116 const Double_t kTrigBendReso = AliMUONConstants::TriggerBendingReso();
683cb6c5 117
118 // Covariance matrix 3x3 (X,Y,slopeY) for trigger tracks
119 fTrigCovariance = new TMatrixD(3,3);
120 fTrigCovariance->Zero();
121 (*fTrigCovariance)(0,0) = kTrigNonBendReso * kTrigNonBendReso;
122 (*fTrigCovariance)(1,1) = kTrigBendReso * kTrigBendReso;
37a615ac 123 (*fTrigCovariance)(2,2) = 2. * (*fTrigCovariance)(1,1) / fDeltaZ / fDeltaZ;
124 (*fTrigCovariance)(1,2) = (*fTrigCovariance)(2,1) = (*fTrigCovariance)(1,1) / fDeltaZ;
683cb6c5 125}
fda59e58 126
7ec3b9cf 127
683cb6c5 128//_____________________________________________________________________________
129void AliMUONTrackHitPattern::CheckConstants() const
130{
131/// Check consistence of redefined constants
132
133 assert(fgkNcathodes == AliMpConstants::NofCathodes());
134 assert(fgkNchambers == AliMpConstants::NofTriggerChambers());
135 assert(fgkNplanes == AliMpConstants::NofTriggerChambers() * fgkNcathodes);
136}
137
138
139//______________________________________________________________________________
9b1e069f 140void AliMUONTrackHitPattern::ExecuteValidation(const AliMUONVTrackStore& trackStore,
683cb6c5 141 const AliMUONVTriggerTrackStore& triggerTrackStore,
142 const AliMUONVTriggerStore& triggerStore) const
143{
144 //
145 /// Main method:
146 /// Loops on reco tracks, extrapolates them to trigger chambers
147 /// and searches for matching trigger tracks and digits
148 //
149
150 AliMUONDigitStoreV1 digitStore;
54355f2c 151 fkDigitMaker.TriggerToDigitsStore(triggerStore,digitStore);
683cb6c5 152
67c201be 153 // Get the hit pattern for all trigger tracks
154 AliMUONTriggerTrack* triggerTrack;
155 TIter itTriggerTrack(triggerTrackStore.CreateIterator());
156 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack() ) ) ){
157 UShort_t pattern = GetHitPattern(triggerTrack, digitStore);
158 triggerTrack->SetHitsPatternInTrigCh(pattern);
159 AliDebug(1, Form("Hit pattern: hits 0x%x slat %2i board %3i effFlag %i",
160 pattern & 0xFF, AliESDMuonTrack::GetSlatOrInfo(pattern),
161 triggerTrack->GetLoTrgNum(), AliESDMuonTrack::GetEffFlag(pattern)));
162 }
683cb6c5 163
67c201be 164 // Match tracker tracks with trigger tracks.
683cb6c5 165 TIter itTrack(trackStore.CreateIterator());
166 AliMUONTrack* track;
167
168 const Int_t kFirstTrigCh = AliMUONConstants::NTrackingCh();
169
170 while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) )
171 {
172 AliMUONTrackParam trackParam(*((AliMUONTrackParam*) (track->GetTrackParamAtCluster()->Last())));
173
174 ApplyMCSCorrections(trackParam);
175 AliMUONTrackExtrap::ExtrapToZCov(&trackParam, AliMUONConstants::DefaultChamberZ(kFirstTrigCh)); // extrap to 1st trigger chamber
176
177 AliMUONTriggerTrack *matchedTriggerTrack = MatchTriggerTrack(track, trackParam, triggerTrackStore, triggerStore);
178
67c201be 179 // Copy trigger tracks hit pattern if there is matching,
180 // otherwise calculate the hit pattern directly from tracker track:
181 // the obtained pattern is good for check, but not good for efficiency determination.
182 UShort_t pattern = matchedTriggerTrack ?
183 matchedTriggerTrack->GetHitsPatternInTrigCh() :
184 GetHitPattern(&trackParam, digitStore);
185
683cb6c5 186 track->SetHitsPatternInTrigCh(pattern);
187 }
188}
189
190
191//______________________________________________________________________________
192AliMUONTriggerTrack *
193AliMUONTrackHitPattern::MatchTriggerTrack(AliMUONTrack* track,
194 AliMUONTrackParam& trackParam,
195 const AliMUONVTriggerTrackStore& triggerTrackStore,
196 const AliMUONVTriggerStore& triggerStore) const
197{
198 //
199 /// Match track with trigger track
200 //
201
202 Int_t matchTrigger = 0;
203 Int_t loTrgNum(-1);
204 Double_t distTriggerTrack[3], sigma2[3];
205 Double_t chi2;
206 Double_t chi2MatchTrigger = 0., minChi2MatchTrigger = 999.;
207 Int_t doubleMatch = -1; // Check if track matches 2 trigger tracks
208 Double_t doubleChi2 = -1.;
209 AliMUONTriggerTrack* doubleTriggerTrack = 0x0;
210 AliMUONTriggerTrack* matchedTriggerTrack = 0x0;
7ec3b9cf 211
683cb6c5 212 const TMatrixD& kParamCov = trackParam.GetCovariances();
7ec3b9cf 213
683cb6c5 214 Double_t xTrack = trackParam.GetNonBendingCoor();
215 Double_t yTrack = trackParam.GetBendingCoor();
216 Double_t ySlopeTrack = trackParam.GetBendingSlope();
217
218 // Covariance matrix 3x3 (X,Y,slopeY) for tracker tracks
219 TMatrixD trackCov(3,3);
220 trackCov.Zero();
221 trackCov(0,0) = kParamCov(0,0);
222 trackCov(1,1) = kParamCov(2,2);
223 trackCov(2,2) = kParamCov(3,3);
224 trackCov(1,2) = kParamCov(2,3);
225 trackCov(2,1) = kParamCov(3,2);
226
227 TMatrixD sumCov(trackCov,TMatrixD::kPlus,*fTrigCovariance);
228
229 Bool_t isCovOK = kTRUE;
230
231 if (sumCov.Determinant() != 0) {
232 sumCov.Invert();
233 } else {
234 AliWarning(" Determinant = 0");
235 isCovOK = kFALSE;
236 sigma2[0] = kParamCov(0,0);
237 sigma2[1] = kParamCov(2,2);
238 sigma2[2] = kParamCov(3,3);
239 // sigma of distributions (trigger-track) X,Y,slopeY
240 const Double_t kDistSigma[3]={AliMUONConstants::TriggerNonBendingReso(),
241 AliMUONConstants::TriggerBendingReso(),
242 1.414 * AliMUONConstants::TriggerBendingReso()/fDeltaZ};
243 for (Int_t iVar = 0; iVar < 3; iVar++) sigma2[iVar] += kDistSigma[iVar] * kDistSigma[iVar];
244 }
fda59e58 245
683cb6c5 246 AliMUONTriggerTrack *triggerTrack;
247 TIter itTriggerTrack(triggerTrackStore.CreateIterator());
248 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack() ) ) )
249 {
250 distTriggerTrack[0] = triggerTrack->GetX11() - xTrack;
251 distTriggerTrack[1] = triggerTrack->GetY11() - yTrack;
252 distTriggerTrack[2] = TMath::Tan(triggerTrack->GetThetay()) - ySlopeTrack;
253
254 if(isCovOK){
255 TMatrixD paramDiff(3,1);
256 for(Int_t iVar = 0; iVar < 3; iVar++)
257 paramDiff(iVar,0) = distTriggerTrack[iVar];
258
259 TMatrixD tmp(sumCov,TMatrixD::kMult,paramDiff);
260 TMatrixD chi2M(paramDiff,TMatrixD::kTransposeMult,tmp);
261 chi2 = chi2M(0,0);
262 }
263 else {
264 chi2 = 0.;
265 for (Int_t iVar = 0; iVar < 3; iVar++) chi2 += distTriggerTrack[iVar]*distTriggerTrack[iVar]/sigma2[iVar];
266 }
fda59e58 267
683cb6c5 268 chi2 /= 3.; // Normalized Chi2: 3 degrees of freedom (X,Y,slopeY)
a0dc65b4 269 if (chi2 < GetRecoParam()->GetMaxNormChi2MatchTrigger())
7ec3b9cf 270 {
683cb6c5 271 Bool_t isDoubleTrack = (TMath::Abs(chi2 - minChi2MatchTrigger)<1.);
a0dc65b4 272 if (chi2 < minChi2MatchTrigger && chi2 < GetRecoParam()->GetMaxNormChi2MatchTrigger())
7ec3b9cf 273 {
683cb6c5 274 if(isDoubleTrack)
275 {
276 doubleMatch = loTrgNum;
277 doubleChi2 = chi2MatchTrigger;
278 doubleTriggerTrack = matchedTriggerTrack;
fda59e58 279 }
683cb6c5 280 minChi2MatchTrigger = chi2;
281 chi2MatchTrigger = chi2;
282 loTrgNum = triggerTrack->GetLoTrgNum();
283 matchedTriggerTrack = triggerTrack;
284 AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(loTrgNum);
285 matchTrigger = 1;
286 if(locTrg->LoLpt()>0) matchTrigger = 2;
287 if(locTrg->LoHpt()>0) matchTrigger = 3;
288 }
289 else if(isDoubleTrack)
290 {
291 doubleMatch = triggerTrack->GetLoTrgNum();
292 doubleChi2 = chi2;
7ec3b9cf 293 }
7771752e 294 }
683cb6c5 295 }
296 if(doubleMatch>=0)
297 { // If two trigger tracks match, select the one passing more trigger cuts
298 AliDebug(1, Form("Two candidates found: %i and %i",loTrgNum,doubleMatch));
299 AliMUONLocalTrigger* locTrg1 = triggerStore.FindLocal(doubleMatch);
300 if((locTrg1->LoLpt()>0 && matchTrigger<2) || (locTrg1->LoHpt() && matchTrigger<3))
301 {
302 if(locTrg1->LoHpt()>0) matchTrigger=3;
303 else matchTrigger = 2;
304 loTrgNum = doubleMatch;
305 chi2MatchTrigger = doubleChi2;
306 matchedTriggerTrack = doubleTriggerTrack;
307 }
308 }
309
310 track->SetMatchTrigger(matchTrigger);
311 track->SetLoTrgNum(loTrgNum);
312 track->SetChi2MatchTrigger(chi2MatchTrigger);
313
314 AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(triggerStore.FindLocal(loTrgNum));
315
316 if (locTrg)
317 {
d72d7b9e 318 Int_t deviation = locTrg->GetDeviation();
683cb6c5 319 track->SetLocalTrigger(locTrg->LoCircuit(),
320 locTrg->LoStripX(),
321 locTrg->LoStripY(),
c79ae710 322 deviation,
683cb6c5 323 locTrg->LoLpt(),
324 locTrg->LoHpt());
325 }
326
327 return matchedTriggerTrack;
328}
329
330
331//______________________________________________________________________________
54355f2c 332UShort_t AliMUONTrackHitPattern::GetHitPattern(AliMUONTriggerTrack* matchedTriggerTrack,
67c201be 333 AliMUONVDigitStore& digitStore) const
683cb6c5 334{
335 //
67c201be 336 /// Get hit pattern on trigger chambers for the current trigger track
683cb6c5 337 //
338 UShort_t pattern = 0;
67c201be 339 PerformTrigTrackMatch(pattern, matchedTriggerTrack, digitStore);
340 return pattern;
341}
683cb6c5 342
54355f2c 343
67c201be 344//______________________________________________________________________________
345UShort_t AliMUONTrackHitPattern::GetHitPattern(AliMUONTrackParam* trackParam,
346 AliMUONVDigitStore& digitStore) const
347{
348 //
349 /// Get hit pattern on trigger chambers for the current tracker track
350 //
351 UShort_t pattern = 0;
352 Bool_t isMatch[2];
353 const Int_t kNTrackingCh = AliMUONConstants::NTrackingCh();
683cb6c5 354
355 for(Int_t ch=0; ch<4; ++ch)
356 {
357 Int_t iChamber = kNTrackingCh+ch;
54355f2c 358 AliMUONTrackExtrap::ExtrapToZCov(trackParam, AliMUONConstants::DefaultChamberZ(iChamber));
359 FindPadMatchingTrack(digitStore, *trackParam, isMatch, iChamber);
683cb6c5 360 for(Int_t cath=0; cath<2; ++cath)
361 {
67c201be 362 if(isMatch[cath]) AliESDMuonTrack::SetFiredChamber(pattern, cath, ch);
683cb6c5 363 }
364 }
683cb6c5 365
67c201be 366 // pattern obtained by propagation of tracker track
367 // when it does not match the trigger.
368 AliESDMuonTrack::AddEffInfo(pattern, AliESDMuonTrack::kTrackerTrackPattern);
683cb6c5 369
67c201be 370 return pattern;
683cb6c5 371}
372
683cb6c5 373//______________________________________________________________________________
374void
375AliMUONTrackHitPattern::ApplyMCSCorrections(AliMUONTrackParam& trackParam) const
376{
377 //
378 /// Returns uncertainties on extrapolated position.
379 /// Takes into account Branson plane corrections in the iron wall.
380 //
381
382 const Float_t kZFilterOut = AliMUONConstants::MuonFilterZEnd();
37a615ac 383 const Float_t kFilterThickness = kZFilterOut-AliMUONConstants::MuonFilterZBeg(); // cm
683cb6c5 384
385 AliMUONTrackExtrap::ExtrapToZCov(&trackParam, kZFilterOut); // Extrap to muon filter end
386 AliMUONTrackExtrap::AddMCSEffect(&trackParam, kFilterThickness, AliMUONConstants::MuonFilterX0()); // Add MCS effects
387 return;
388}
389
390
391//______________________________________________________________________________
7ec3b9cf 392void
9b1e069f 393AliMUONTrackHitPattern::FindPadMatchingTrack(const AliMUONVDigitStore& digitStore,
7ec3b9cf 394 const AliMUONTrackParam& trackParam,
fda59e58 395 Bool_t isMatch[2], Int_t iChamber) const
7771752e 396{
397 //
683cb6c5 398 /// Given the tracker track position, searches for matching digits.
7771752e 399 //
400
401 Float_t minMatchDist[2];
402
7ec3b9cf 403 for(Int_t cath=0; cath<2; ++cath)
404 {
405 isMatch[cath]=kFALSE;
683cb6c5 406 minMatchDist[cath]=fkMaxDistance/10.;
7771752e 407 }
408
7ec3b9cf 409 TIter next(digitStore.CreateIterator());
410 AliMUONVDigit* mDigit;
fda59e58 411
7ec3b9cf 412 while ( ( mDigit = static_cast<AliMUONVDigit*>(next()) ) )
413 {
414 Int_t currDetElemId = mDigit->DetElemId();
fda59e58 415 Int_t currCh = AliMpDEManager::GetChamberId(currDetElemId);
416 if(currCh!=iChamber) continue;
7ec3b9cf 417 Int_t cathode = mDigit->Cathode();
418 Int_t ix = mDigit->PadX();
419 Int_t iy = mDigit->PadY();
420 Float_t xpad, ypad, zpad;
421 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()
422 ->GetMpSegmentation(currDetElemId,AliMp::GetCathodType(cathode));
423
168e9c4d 424 AliMpPad pad = seg->PadByIndices(ix,iy,kTRUE);
6e97fbb8 425 Float_t xlocal1 = pad.GetPositionX();
426 Float_t ylocal1 = pad.GetPositionY();
427 Float_t dpx = pad.GetDimensionX();
428 Float_t dpy = pad.GetDimensionY();
429
9b1e069f 430 fkTransformer.Local2Global(currDetElemId, xlocal1, ylocal1, 0, xpad, ypad, zpad);
7ec3b9cf 431 Float_t matchDist = MinDistanceFromPad(xpad, ypad, zpad, dpx, dpy, trackParam);
432 if(matchDist>minMatchDist[cathode])continue;
433 isMatch[cathode] = kTRUE;
fda59e58 434 if(isMatch[0] && isMatch[1]) break;
7ec3b9cf 435 minMatchDist[cathode] = matchDist;
7771752e 436 }
7771752e 437}
438
439
440//______________________________________________________________________________
7ec3b9cf 441Float_t
442AliMUONTrackHitPattern::MinDistanceFromPad(Float_t xPad, Float_t yPad, Float_t zPad,
443 Float_t dpx, Float_t dpy,
444 const AliMUONTrackParam& trackParam) const
7771752e 445{
446 //
683cb6c5 447 /// Decides if the digit belongs to the tracker track.
7771752e 448 //
7771752e 449
fda59e58 450 AliMUONTrackParam trackParamAtPadZ(trackParam);
451 AliMUONTrackExtrap::ExtrapToZCov(&trackParamAtPadZ, zPad);
452
453 Float_t xTrackAtPad = trackParamAtPadZ.GetNonBendingCoor();
454 Float_t yTrackAtPad = trackParamAtPadZ.GetBendingCoor();
7771752e 455
a0dc65b4 456 const Float_t kNSigma = GetRecoParam()->GetSigmaCutForTrigger();
fda59e58 457
458 const TMatrixD& kCovParam = trackParamAtPadZ.GetCovariances();
459
460 Float_t sigmaX = TMath::Sqrt(kCovParam(0,0));
461 Float_t sigmaY = TMath::Sqrt(kCovParam(2,2));
462
463 Float_t maxDistX = kNSigma * sigmaX; // in cm
464 Float_t maxDistY = kNSigma * sigmaY; // in cm
7771752e 465
466 Float_t deltaX = TMath::Abs(xPad-xTrackAtPad)-dpx;
467 Float_t deltaY = TMath::Abs(yPad-yTrackAtPad)-dpy;
468
683cb6c5 469 Float_t matchDist = fkMaxDistance;
7771752e 470 if(deltaX<=maxDistX && deltaY<=maxDistY) matchDist = TMath::Max(deltaX, deltaY);
fda59e58 471
7771752e 472 return matchDist;
473}
474
475
683cb6c5 476//_____________________________________________________________________________
9b1e069f 477Int_t AliMUONTrackHitPattern::FindPadMatchingTrig(const AliMUONVDigitStore& digitStore, Int_t &detElemId,
683cb6c5 478 Float_t coor[2], Bool_t isMatch[2],
479 TArrayI nboard[2], TArrayF &zRealMatch, Float_t y11) const
480{
481 //
482 /// Check slat and board number of digit matching trigger track
483 //
484
485 enum {kBending, kNonBending};
486
487 Float_t minMatchDist[fgkNcathodes];
488 Int_t padsInCheckArea[fgkNcathodes];
489
490 for(Int_t cath=0; cath<fgkNcathodes; cath++){
491 isMatch[cath] = kFALSE;
492 minMatchDist[cath] = fkMaxDistance/10.;
493 padsInCheckArea[cath] = 0;
494 }
495 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
496 Int_t ch = iChamber-10;
497 Float_t oldDeltaZ = AliMUONConstants::DefaultChamberZ(iChamber) - AliMUONConstants::DefaultChamberZ(10);
498 Float_t y = coor[1];
499 Int_t iSlat = detElemId%100;
500 Int_t trigDigitBendPlane = -1;
501 Int_t foundDetElemId = detElemId;
502 Float_t foundZmatch=999.;
503 Float_t yCoorAtPadZ=999.;
504
505 TIter next(digitStore.CreateIterator());
506 AliMUONVDigit* mDigit;
507 Int_t idigit=0;
508
509 while ( ( mDigit = static_cast<AliMUONVDigit*>(next()) ) )
510 {
511 idigit++;
512 Int_t currDetElemId = mDigit->DetElemId();
513 Int_t currCh = AliMpDEManager::GetChamberId(currDetElemId);
514 if(currCh!=iChamber) continue;
515 Int_t currSlat = currDetElemId%100;
516 Int_t slatDiff = TMath::Abs(currSlat-iSlat);
517 if(slatDiff>1 && slatDiff<17) continue; // Check neighbour slats
518 Int_t cathode = mDigit->Cathode();
519 Int_t ix = mDigit->PadX();
520 Int_t iy = mDigit->PadY();
521 Float_t xpad, ypad, zpad;
522 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()
523 ->GetMpSegmentation(currDetElemId,AliMp::GetCathodType(cathode));
524
168e9c4d 525 AliMpPad pad = seg->PadByIndices(ix,iy,kTRUE);
6e97fbb8 526 Float_t xlocal1 = pad.GetPositionX();
527 Float_t ylocal1 = pad.GetPositionY();
528 Float_t dpx = pad.GetDimensionX();
529 Float_t dpy = pad.GetDimensionY();
530
9b1e069f 531 fkTransformer.Local2Global(currDetElemId, xlocal1, ylocal1, 0, xpad, ypad, zpad);
b5270f21 532 AliDebug(2, Form("\nDetElemId = %i Cathode = %i Pad = (%i,%i) = (%.2f,%.2f) Dim = (%.2f,%.2f) Track = (%.2f,%.2f)\n",currDetElemId,cathode,ix,iy,xpad,ypad,dpx,dpy,coor[0],coor[1]));
683cb6c5 533 // searching track intersection with chambers (second approximation)
534 if(ch%2==1){
535 //if(iChamber%2==1){
536 Float_t deltaZ = zpad - zRealMatch[0];
537 y = (coor[1]-y11)*deltaZ/oldDeltaZ + y11;
538 if(TMath::Abs(y-coor[1])>0.1) AliDebug(3, Form("oldDeltaZ = %7.2f newDeltaZ = %7.2f\toldY = %7.2f new y = %7.2f\n",oldDeltaZ,deltaZ,coor[1],y));
539 }
540 Float_t matchDist = PadMatchTrack(xpad, ypad, dpx, dpy, coor[0], y);
541 if(matchDist<fkMaxDistance/2.) padsInCheckArea[cathode]++;
542 if(matchDist>minMatchDist[cathode])continue;
543 isMatch[cathode] = kTRUE;
544 minMatchDist[cathode] = matchDist;
545 foundDetElemId = currDetElemId;
546 foundZmatch=zpad;
547 yCoorAtPadZ=y;
548 if(cathode==kBending) trigDigitBendPlane = idigit;
549 for (Int_t loc=0; loc<pad.GetNofLocations(); loc++){
168e9c4d 550 nboard[cathode][loc] = pad.GetLocalBoardId(loc);
683cb6c5 551 }
552 for(Int_t loc=pad.GetNofLocations(); loc<fgkNlocations; loc++){
553 nboard[cathode][loc]=-1;
554 }
683cb6c5 555 }
556
683cb6c5 557 if(isMatch[kBending] || isMatch[kNonBending]){
558 detElemId = foundDetElemId;
559 zRealMatch[ch] = foundZmatch;
560 coor[1] = yCoorAtPadZ;
561 }
67c201be 562
563 // If track matches many pads, it is not good for effciency determination.
564 // However we still want to calculate the hit pattern.
565 for(Int_t cath=0; cath<fgkNcathodes; cath++){
566 if(padsInCheckArea[cath]>2) {
567 AliDebug(1, Form("padsInCheckArea[%i] = %i\n",cath,padsInCheckArea[cath]));
568 return -500;
569 }
570 }
571
683cb6c5 572 return trigDigitBendPlane;
573}
574
575//_____________________________________________________________________________
576Float_t AliMUONTrackHitPattern::PadMatchTrack(Float_t xPad, Float_t yPad,
577 Float_t dpx, Float_t dpy,
578 Float_t xTrackAtPad, Float_t yTrackAtPad) const
579{
580 //
581 /// Decides if the digit belongs to the trigger track.
582 //
583
a0dc65b4 584 Float_t maxDist = GetRecoParam()->GetStripCutForTrigger() * 2. * TMath::Min(dpx,dpy); // cm
b5270f21 585 if(maxDist<2.) maxDist = 2.;
a0dc65b4 586 Float_t maxDistCheckArea = GetRecoParam()->GetMaxStripAreaForTrigger() * 2. * TMath::Min(dpx,dpy); // cm
683cb6c5 587
588 Float_t matchDist = fkMaxDistance;
589
590 Float_t deltaX = TMath::Abs(xPad-xTrackAtPad)-dpx;
591 Float_t deltaY = TMath::Abs(yPad-yTrackAtPad)-dpy;
592 Float_t maxDistX = maxDist;
593 Float_t maxDistY = maxDist;
594
595 if(deltaX<=maxDistX && deltaY<=maxDistY) matchDist = TMath::Max(deltaX, deltaY);
596 else if(deltaX<=maxDistCheckArea && deltaY<=maxDistCheckArea) matchDist = fkMaxDistance/5.;
597 return matchDist;
598}
599
600
601//_____________________________________________________________________________
602Int_t AliMUONTrackHitPattern::DetElemIdFromPos(Float_t x, Float_t y,
603 Int_t chamber, Int_t cathode) const
604{
605 //
606 /// Given the (x,y) position in the chamber,
607 /// it returns the corresponding slat
608 //
609
610 Int_t resultingDetElemId = -1;
611 AliMpDEIterator it;
612 Float_t minDist = 999.;
613 for ( it.First(chamber-1); ! it.IsDone(); it.Next() ){
614 Int_t detElemId = it.CurrentDEId();
615 Int_t ich = detElemId/100-10;
616 Float_t tolerance=0.2*((Float_t)ich);
617 Float_t currDist=9999.;
618
619 const AliMpVSegmentation* seg =
620 AliMpSegmentation::Instance()
621 ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
622 if (!seg) continue;
623
6e97fbb8 624 Float_t deltax = seg->GetDimensionX();
625 Float_t deltay = seg->GetDimensionY();
683cb6c5 626 Float_t xlocal1 = -deltax;
627 Float_t ylocal1 = -deltay;
628 Float_t xlocal2 = +deltax;
629 Float_t ylocal2 = +deltay;
630 Float_t xg01, yg01, zg1, xg02, yg02, zg2;
9b1e069f 631 fkTransformer.Local2Global(detElemId, xlocal1, ylocal1, 0, xg01, yg01, zg1);
632 fkTransformer.Local2Global(detElemId, xlocal2, ylocal2, 0, xg02, yg02, zg2);
683cb6c5 633
634 Float_t xg1 = xg01, xg2 = xg02, yg1 = yg01, yg2 = yg02;
635
636 if(xg01>xg02){
637 xg1 = xg02;
638 xg2 = xg01;
639 }
640 if(yg01>yg02){
641 yg1 = yg02;
642 yg2 = yg01;
643 }
644
645 if(x>=xg1-tolerance && x<=xg2+tolerance && y>=yg1-tolerance && y<=yg2+tolerance){ // takes into account errors in extrapolation
646 if(y<yg1) currDist = yg1-y;
647 else if(y>yg2) currDist = y-yg2;
648 if(currDist<minDist) {
649 resultingDetElemId = detElemId;
650 minDist=currDist;
651 continue;
652 }
653 resultingDetElemId = detElemId;
654 break;
655 }
656 } // loop on detElemId
657 return resultingDetElemId;
658}
659
660
661//_____________________________________________________________________________
662void AliMUONTrackHitPattern::LocalBoardFromPos(Float_t x, Float_t y,
663 Int_t detElemId, Int_t cathode,
664 Int_t localBoard[4]) const
665{
666 //
667 /// Given the (x,y) position in the chamber,
668 /// it returns the corresponding local board
669 //
670
671 for(Int_t loc=0; loc<fgkNlocations; loc++){
672 localBoard[loc]=-1;
673 }
674 Float_t xl, yl, zl;
9b1e069f 675 fkTransformer.Global2Local(detElemId, x, y, 0, xl, yl, zl);
683cb6c5 676 TVector2 pos(xl,yl);
677 const AliMpVSegmentation* seg =
678 AliMpSegmentation::Instance()
679 ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
680 if (seg){
6e97fbb8 681 AliMpPad pad = seg->PadByPosition(pos.X(),pos.Y(),kFALSE);
683cb6c5 682 for (Int_t loc=0; loc<pad.GetNofLocations(); loc++){
168e9c4d 683 localBoard[loc] = pad.GetLocalBoardId(loc);
683cb6c5 684 }
685 }
686}
687
688
689//_____________________________________________________________________________
690Bool_t AliMUONTrackHitPattern::PerformTrigTrackMatch(UShort_t &pattern,
9b1e069f 691 const AliMUONTriggerTrack* matchedTrigTrack,
683cb6c5 692 AliMUONVDigitStore& digitStore) const
7771752e 693{
fda59e58 694 //
683cb6c5 695 /// It searches for matching digits around the trigger track.
fda59e58 696 //
7771752e 697
683cb6c5 698 enum {kBending, kNonBending};
7771752e 699
683cb6c5 700 Int_t chOrder[fgkNchambers] = {0,2,1,3};
701
702 TArrayF zRealMatch(fgkNchambers);
703 TArrayF correctFactor(fgkNcathodes);
704
705 Bool_t isMatch[fgkNcathodes];
706 for(Int_t cath=0; cath<fgkNcathodes; cath++){
707 isMatch[cath] = kFALSE;
708 }
709
710 TArrayF zMeanChamber(fgkNchambers);
711 for(Int_t ch=0; ch<fgkNchambers; ch++){
712 zMeanChamber[ch] = AliMUONConstants::DefaultChamberZ(10+ch);
713 }
714
715 TArrayI digitPerTrack(fgkNcathodes);
716
717 Float_t trackIntersectCh[fgkNchambers][fgkNcathodes];
718
719 TArrayI triggeredDigits;
720 triggeredDigits.Set(fgkNchambers);
721 triggeredDigits.Reset(-1);
722
723 TArrayI trigScheme[fgkNcathodes];
724 TArrayI slatThatTriggered[fgkNcathodes];
725 for(Int_t cath=0; cath<fgkNcathodes; cath++){
726 trigScheme[cath].Set(fgkNchambers);
727 slatThatTriggered[cath].Set(fgkNchambers);
728 }
729
730 Int_t boardThatTriggered[fgkNchambers][fgkNcathodes][fgkNlocations];
731 TArrayI nboard[fgkNcathodes];
732 for(Int_t cath=0; cath<fgkNcathodes; cath++){
733 nboard[cath].Set(fgkNlocations);
734 }
735 Int_t ineffBoard[fgkNlocations];
736 for(Int_t loc=0; loc<fgkNlocations; loc++){
737 ineffBoard[loc] = -1;
738 }
739
740 digitPerTrack.Reset();
741 for(Int_t ch=0; ch<fgkNchambers; ch++){
742 zRealMatch[ch] = zMeanChamber[ch];
743 for(Int_t cath=0; cath<fgkNcathodes; cath++){
744 for(Int_t loc=0; loc<fgkNlocations; loc++){
745 boardThatTriggered[ch][cath][loc]=-1;
746 }
747 }
748 }
749
750 for(Int_t cath=0; cath<fgkNcathodes; cath++){
751 slatThatTriggered[cath].Reset(-1);
752 trigScheme[cath].Reset();
753 }
754
755 Bool_t isClearEvent = kTRUE;
756
757 //Float_t x11 = matchedTrigTrack->GetX11();// x position (info from non-bending plane)
758 Float_t y11 = matchedTrigTrack->GetY11();// y position (info from bending plane)
759 Float_t thetaX = matchedTrigTrack->GetThetax();
760 Float_t thetaY = matchedTrigTrack->GetThetay();
761
762 for(Int_t ch=0; ch<fgkNchambers; ch++) { // chamber loop
763 Int_t currCh = chOrder[ch];
b5270f21 764 AliDebug(3, Form("zMeanChamber[%i] = %.2f\tzRealMatch[0] = %.2f\n",currCh,zMeanChamber[currCh],zRealMatch[0]));
683cb6c5 765
766 for(Int_t cath=0; cath<fgkNcathodes; cath++){
767 correctFactor[cath]=1.;
768 }
769 // calculate corrections to trigger track theta
770 if(ch>=1) correctFactor[kNonBending] = zMeanChamber[0]/zRealMatch[0];// corrects x position
771 if(ch>=2) correctFactor[kBending] = (zMeanChamber[2] - zMeanChamber[0]) / (zRealMatch[2] - zRealMatch[0]);// corrects y position
772
773 // searching track intersection with chambers (first approximation)
774 Float_t deltaZ = zMeanChamber[currCh] - zMeanChamber[0];
775 trackIntersectCh[currCh][0] = zMeanChamber[currCh] * TMath::Tan(thetaX) * correctFactor[kNonBending];// x position (info from non-bending plane)
776 trackIntersectCh[currCh][1] = y11 + deltaZ * TMath::Tan(thetaY) * correctFactor[kBending];// y position (info from bending plane)
777 Int_t detElemIdFromTrack = DetElemIdFromPos(trackIntersectCh[currCh][0], trackIntersectCh[currCh][1], 11+currCh, 0);
778 if(detElemIdFromTrack<0) {
779 AliDebug(1, "Warning: trigger track outside trigger chamber\n");
67c201be 780 isClearEvent = kFALSE;
781
782 // track is rejected since the extrapolated track
783 // does not match a slat (border effects)
784 AliESDMuonTrack::AddEffInfo(pattern, AliESDMuonTrack::kTrackOutsideGeometry);
683cb6c5 785 continue;
786 }
787
788 triggeredDigits[currCh] = FindPadMatchingTrig(digitStore, detElemIdFromTrack, trackIntersectCh[currCh], isMatch, nboard, zRealMatch, y11);
789
790 // if FindPadMatchingTrig = -500 => too many digits matching pad =>
67c201be 791 // => Event not clear => Do not use for efficiency calculation
683cb6c5 792 if(triggeredDigits[currCh]<-100){
793 isClearEvent = kFALSE;
67c201be 794 // track is rejected since it matches many pads
795 AliESDMuonTrack::AddEffInfo(pattern, AliESDMuonTrack::kTrackMatchesManyPads);
683cb6c5 796 AliDebug(1, Form("Warning: track = %p (%i) matches many pads. Rejected!\n",(void *)matchedTrigTrack, detElemIdFromTrack));
683cb6c5 797 }
798
799 for(Int_t cath=0; cath<fgkNcathodes; cath++){
800 if(!isMatch[cath]) continue;
67c201be 801 AliESDMuonTrack::SetFiredChamber(pattern, cath, currCh);
683cb6c5 802 digitPerTrack[cath]++;
803 trigScheme[cath][currCh]++;
804 slatThatTriggered[cath][currCh] = detElemIdFromTrack;
805 for(Int_t loc=0; loc<fgkNlocations; loc++){
806 boardThatTriggered[currCh][cath][loc] = nboard[cath][loc];
807 }
808 }
809 } // end chamber loop
810
811 for(Int_t cath=0; cath<fgkNcathodes; cath++){
67c201be 812 if(digitPerTrack[cath]<3) {
813 isClearEvent = kFALSE;
814 // track is rejected since the number of associated
815 // digits found is less than 3.
816 AliESDMuonTrack::AddEffInfo(pattern, AliESDMuonTrack::kTrackMatchesFewPads);
817 AliDebug(1, Form("Warning: found %i digits for trigger track cathode %i.\nRejecting event\n", digitPerTrack[cath],cath));
818 }
683cb6c5 819 }
820
821 if(!isClearEvent) return kFALSE;
822
67c201be 823 AliESDMuonTrack::EAliTriggerChPatternFlag goodForEff = AliESDMuonTrack::kBoardEff;
683cb6c5 824
825 Int_t ineffSlat = -1;
826 Int_t ineffDetElId = -1;
827 Int_t firstSlat = slatThatTriggered[kBending][0]%100;
828 if(firstSlat<0) firstSlat = slatThatTriggered[kBending][1]%100;
829 Int_t firstBoard = boardThatTriggered[0][kBending][0];
830 if(firstBoard<0) firstBoard = boardThatTriggered[1][kBending][0];
831 for(Int_t ch=0; ch<fgkNchambers; ch++){
832 Bool_t isCurrChIneff = kFALSE;
833 Int_t currSlat = slatThatTriggered[kBending][ch]%100;
834 if(currSlat<0){
835 ineffDetElId = DetElemIdFromPos(trackIntersectCh[ch][0], trackIntersectCh[ch][1], 11+ch, kBending);
836 currSlat = ineffDetElId%100;
837 ineffSlat = currSlat;
838 isCurrChIneff = kTRUE;
839 }
840 if(currSlat!=firstSlat) {
67c201be 841 AliESDMuonTrack::AddEffInfo(pattern,
842 AliESDMuonTrack::kCrossDifferentSlats,
843 AliESDMuonTrack::kChEff); // track crosses different slats
683cb6c5 844 return kTRUE;
845 }
846 Bool_t atLeastOneLoc=kFALSE;
847 if(isCurrChIneff) LocalBoardFromPos(trackIntersectCh[ch][0], trackIntersectCh[ch][1], ineffDetElId, kBending, ineffBoard);
848 for(Int_t loc=0; loc<fgkNlocations; loc++){
849 Int_t currBoard = boardThatTriggered[ch][kBending][loc];
850 if(isCurrChIneff) currBoard = ineffBoard[loc];
851 if(currBoard==firstBoard){
852 atLeastOneLoc=kTRUE;
853 break;
854 }
855 }
67c201be 856 if(!atLeastOneLoc) goodForEff = AliESDMuonTrack::kSlatEff;
683cb6c5 857 } // end chamber loop
858
67c201be 859 AliESDMuonTrack::AddEffInfo(pattern, firstSlat, goodForEff);
683cb6c5 860 return kTRUE;
7771752e 861}