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