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