1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONRecoCheck
20 /// Utility class to check reconstruction
21 /// Reconstructed tracks are compared to reference tracks.
22 /// The reference tracks are built from AliTrackReference for the
23 /// hit in chamber (0..9) and from kinematics for the vertex parameters.
24 //-----------------------------------------------------------------------------
27 // Added a method to create a list of reconstructed AliMUONTrack objects from
28 // ESD data. This is necessary since the track objects that are actually created
29 // during offline reconstruction are no longer stored to disk.
30 // - Artur Szostak <artursz@iafrica.com>
32 // Use the new ESDInterface to create MUON objects from ESD data
36 #include "AliMUONRecoCheck.h"
37 #include "AliMUONTrack.h"
38 #include "AliMUONVTrackStore.h"
39 #include "AliMUONVCluster.h"
40 #include "AliMUONVClusterStore.h"
41 #include "AliMUONConstants.h"
42 #include "AliMUONESDInterface.h"
43 #include "AliMUONTrackParam.h"
44 #include "AliMUONTriggerTrack.h"
45 #include "AliMUONVTriggerTrackStore.h"
46 #include "AliMUONTriggerStoreV1.h"
47 #include "AliMUONLocalTrigger.h"
48 #include "AliMCEventHandler.h"
49 #include "AliMCEvent.h"
51 #include "AliTrackReference.h"
53 #include "AliESDEvent.h"
54 #include "AliESDMuonTrack.h"
55 #include "AliMUONDigitStoreV2S.h"
56 #include "AliMUONVDigit.h"
57 #include "AliMpVSegmentation.h"
58 #include "AliMpSegmentation.h"
61 #include "AliGeomManager.h"
62 #include "AliCDBManager.h"
64 #include "AliMpDDLStore.h"
65 #include "AliMUONCDB.h"
66 #include "AliMUONGeometryTransformer.h"
67 #include "AliMUONTriggerCircuit.h"
68 #include "AliMUONVTrackReconstructor.h"
69 #include "AliMUONVTriggerStore.h"
70 #include "AliMUONCalibrationData.h"
71 #include "AliMUONTriggerElectronics.h"
74 #include "TGeoManager.h"
78 #include <TParticle.h>
79 #include <TParticlePDG.h>
80 #include <Riostream.h>
82 #include "AliMUONRecoCheck.h"
85 ClassImp(AliMUONRecoCheck)
88 //_____________________________________________________________________________
89 AliMUONRecoCheck::AliMUONRecoCheck(const Char_t *esdFileName, const Char_t *pathSim)
91 fMCEventHandler(new AliMCEventHandler()),
92 fESDEvent(new AliESDEvent()),
97 fRecoTrackRefStore(0x0),
98 fRecoTriggerRefStore(0x0),
100 fRecoTriggerTrackStore(0x0),
101 fGeometryTransformer(0x0),
102 fTriggerCircuit(0x0),
103 fCalibrationData(0x0),
104 fTriggerElectronics(0x0),
105 fESDEventOwner(kTRUE)
109 // TrackRefs and Particules
110 fMCEventHandler->SetInputPath(pathSim);
111 fMCEventHandler->InitIO("");
114 fESDFile = TFile::Open(esdFileName); // open the file
115 if (!fESDFile || !fESDFile->IsOpen()) {
116 AliError(Form("opening ESD file %s failed", esdFileName));
120 fESDTree = (TTree*) fESDFile->Get("esdTree"); // get the tree
122 AliError("no ESD tree found");
127 fESDEvent->ReadFromTree(fESDTree); // link fESDEvent to the tree
130 //_____________________________________________________________________________
131 AliMUONRecoCheck::AliMUONRecoCheck(AliESDEvent *esdEvent, AliMCEventHandler *mcEventHandler)
139 fRecoTrackRefStore(0x0),
140 fRecoTriggerRefStore(0x0),
141 fRecoTrackStore(0x0),
142 fRecoTriggerTrackStore(0x0),
143 fGeometryTransformer(0x0),
144 fTriggerCircuit(0x0),
145 fCalibrationData(0x0),
146 fTriggerElectronics(0x0),
147 fESDEventOwner(kFALSE)
151 // TrackRefs and Particules
152 fMCEventHandler = mcEventHandler;
155 fESDEvent = esdEvent;
158 //_____________________________________________________________________________
159 AliMUONRecoCheck::~AliMUONRecoCheck()
162 if (fESDEventOwner) {
163 delete fMCEventHandler;
165 if (fESDFile) fESDFile->Close();
168 delete fGeometryTransformer;
169 delete fTriggerCircuit;
170 delete fTriggerElectronics;
171 delete fCalibrationData;
174 //_____________________________________________________________________________
175 void AliMUONRecoCheck::ResetStores()
177 /// Deletes all the store objects that have been created and resets the pointers to 0x0
178 delete fTrackRefStore; fTrackRefStore = 0x0;
179 delete fRecoTrackRefStore; fRecoTrackRefStore = 0x0;
180 delete fRecoTriggerRefStore; fRecoTriggerRefStore = 0x0;
181 delete fRecoTrackStore; fRecoTrackStore = 0x0;
182 delete fRecoTriggerTrackStore; fRecoTriggerTrackStore = 0x0;
185 //_____________________________________________________________________________
186 Bool_t AliMUONRecoCheck::InitCircuit()
189 if ( fTriggerCircuit ) return kTRUE;
191 if ( ! InitGeometryTransformer() ) return kFALSE;
193 // reset tracker for local trigger to trigger track conversion
194 if ( ! AliMUONESDInterface::GetTracker() ) AliMUONESDInterface::ResetTracker();
196 fTriggerCircuit = new AliMUONTriggerCircuit(fGeometryTransformer);
202 //_____________________________________________________________________________
203 Int_t AliMUONRecoCheck::GetRunNumber()
205 /// Return the run number of the current ESD event
207 if (fESDEventOwner && fRecoTrackStore == 0x0 && fRecoTriggerTrackStore == 0x0) {
208 if (!fESDTree || fESDTree->GetEvent(fCurrentEvent) <= 0) {
209 AliError(Form("fails to read ESD object for event %d: cannot get the run number",fCurrentEvent));
214 return fESDEvent->GetRunNumber();
217 //_____________________________________________________________________________
218 Int_t AliMUONRecoCheck::NumberOfEvents() const
220 /// Return the number of events
221 if (fESDEventOwner && fESDTree) return fESDTree->GetEntries();
225 //_____________________________________________________________________________
226 AliMUONVTrackStore* AliMUONRecoCheck::ReconstructedTracks(Int_t event, Bool_t refit)
228 /// Return a track store containing the reconstructed tracks (converted into
229 /// MUONTrack objects) for a given event.
230 /// Track parameters at each clusters are computed or not depending on the flag "refit".
231 /// If not, only the track parameters at first cluster are valid.
233 if (!fESDEventOwner) {
234 if (fRecoTrackStore == 0x0) MakeReconstructedTracks(refit);
235 return fRecoTrackStore;
238 if (event != fCurrentEvent) {
240 fCurrentEvent = event;
243 if (fRecoTrackStore != 0x0) return fRecoTrackStore;
245 if (!fESDTree) return 0x0;
246 if (fESDTree->GetEvent(event) <= 0) {
247 AliError(Form("fails to read ESD object for event %d", event));
250 MakeReconstructedTracks(refit);
251 return fRecoTrackStore;
256 //_____________________________________________________________________________
257 AliMUONVTriggerTrackStore* AliMUONRecoCheck::TriggeredTracks(Int_t event)
259 /// Return a track store containing the reconstructed trigger tracks (converted into
260 /// MUONTriggerTrack objects) for a given event.
262 if (!fESDEventOwner) {
263 if (fRecoTriggerTrackStore == 0x0) MakeTriggeredTracks();
264 return fRecoTriggerTrackStore;
267 if (event != fCurrentEvent) {
269 fCurrentEvent = event;
272 if (fRecoTriggerTrackStore != 0x0) return fRecoTriggerTrackStore;
274 if (!fESDTree) return 0x0;
275 if (fESDTree->GetEvent(event) <= 0) {
276 AliError(Form("fails to read ESD object for event %d", event));
279 MakeTriggeredTracks();
280 return fRecoTriggerTrackStore;
285 //_____________________________________________________________________________
286 AliMUONVTrackStore* AliMUONRecoCheck::TrackRefs(Int_t event)
288 /// Return a track store containing the track references (converted into
289 /// MUONTrack objects) for a given event
291 if (!fESDEventOwner) {
292 if (fTrackRefStore == 0x0) MakeTrackRefs();
293 return fTrackRefStore;
296 if (event != fCurrentEvent) {
298 fCurrentEvent = event;
301 if (fTrackRefStore != 0x0) return fTrackRefStore;
303 if (!fMCEventHandler->BeginEvent(event)) {
304 AliError(Form("fails to read MC objects for event %d", event));
308 fMCEventHandler->FinishEvent();
309 return fTrackRefStore;
313 //_____________________________________________________________________________
314 AliMUONVTriggerTrackStore* AliMUONRecoCheck::TriggerableTracks(Int_t event)
316 /// Return a trigger track store containing the triggerable track references (converted into
317 /// AliMUONTriggerTrack objects) for a given event
319 if (!fESDEventOwner) {
320 if (fRecoTriggerRefStore == 0x0) MakeTriggerableTracks();
321 return fRecoTriggerRefStore;
324 if (event != fCurrentEvent) {
326 fCurrentEvent = event;
329 if (fRecoTriggerRefStore != 0x0) return fRecoTriggerRefStore;
331 if (!fMCEventHandler->BeginEvent(event)) {
332 AliError(Form("fails to read MC objects for event %d", event));
335 MakeTriggerableTracks();
336 fMCEventHandler->FinishEvent();
337 return fRecoTriggerRefStore;
342 //_____________________________________________________________________________
343 AliMUONVTrackStore* AliMUONRecoCheck::ReconstructibleTracks(Int_t event, UInt_t requestedStationMask,
344 Bool_t request2ChInSameSt45, Bool_t hitInFrontOfPad)
346 /// Return a track store containing the reconstructible tracks for a given event,
347 /// according to the mask of requested stations and the minimum number of chambers hit in stations 4 & 5.
349 if (!fESDEventOwner) {
350 if (fRecoTrackRefStore == 0x0) {
351 if (TrackRefs(event) == 0x0) return 0x0;
352 MakeReconstructibleTracks(requestedStationMask, request2ChInSameSt45, hitInFrontOfPad);
354 return fRecoTrackRefStore;
357 if (event != fCurrentEvent) {
359 fCurrentEvent = event;
362 if (fRecoTrackRefStore != 0x0) return fRecoTrackRefStore;
364 if (TrackRefs(event) == 0x0) return 0x0;
365 MakeReconstructibleTracks(requestedStationMask, request2ChInSameSt45, hitInFrontOfPad);
366 return fRecoTrackRefStore;
371 //_____________________________________________________________________________
372 void AliMUONRecoCheck::MakeReconstructedTracks(Bool_t refit)
374 /// Make reconstructed tracks
375 if (!(fRecoTrackStore = AliMUONESDInterface::NewTrackStore())) return;
377 // loop over all reconstructed tracks and add them to the store (skip ghosts)
378 Int_t nTracks = (Int_t) fESDEvent->GetNumberOfMuonTracks();
379 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
380 AliESDMuonTrack* esdTrack = fESDEvent->GetMuonTrack(iTrack);
381 if (esdTrack->ContainTrackerData()) AliMUONESDInterface::Add(*esdTrack, *fRecoTrackStore, refit);
387 //_____________________________________________________________________________
388 void AliMUONRecoCheck::MakeTriggeredTracks()
390 /// Make reconstructed trigger tracks
391 if (!(fRecoTriggerTrackStore = AliMUONESDInterface::NewTriggerTrackStore())) return;
393 AliMUONVTriggerStore* tmpTriggerStore = AliMUONESDInterface::NewTriggerStore();
394 if ( ! tmpTriggerStore ) return;
396 // loop over all reconstructed tracks and add them to the store (include ghosts)
397 Int_t nTracks = (Int_t) fESDEvent->GetNumberOfMuonTracks();
398 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
399 AliESDMuonTrack* esdTrack = fESDEvent->GetMuonTrack(iTrack);
400 if (esdTrack->ContainTriggerData()) AliMUONESDInterface::Add(*esdTrack, *tmpTriggerStore);
403 if ( InitCircuit() ) {
405 AliMUONVTrackReconstructor* tracker = AliMUONESDInterface::GetTracker();
406 tracker->EventReconstructTrigger(*fTriggerCircuit, *tmpTriggerStore, *fRecoTriggerTrackStore);
409 delete tmpTriggerStore;
412 //_____________________________________________________________________________
413 Bool_t AliMUONRecoCheck::TriggerToTrack(const AliMUONLocalTrigger& locTrg, AliMUONTriggerTrack& triggerTrack)
415 /// Make trigger track from local trigger info
416 if ( ! InitCircuit() ) return kFALSE;
417 AliMUONVTrackReconstructor* tracker = AliMUONESDInterface::GetTracker();
418 return tracker->TriggerToTrack(*fTriggerCircuit, locTrg, triggerTrack);
422 //_____________________________________________________________________________
423 void AliMUONRecoCheck::MakeTrackRefs()
425 /// Make reconstructible tracks
426 AliMUONVTrackStore *tmpTrackRefStore = AliMUONESDInterface::NewTrackStore();
427 if (!tmpTrackRefStore) return;
429 Double_t x, y, z, pX, pY, pZ, bendingSlope, nonBendingSlope, inverseBendingMomentum;
431 TClonesArray* trackRefs;
432 Int_t nTrackRef = fMCEventHandler->MCEvent()->GetNumberOfTracks();
433 AliMUONVCluster* hit = AliMUONESDInterface::NewCluster();
435 // loop over simulated tracks
436 for (Int_t iTrackRef = 0; iTrackRef < nTrackRef; ++iTrackRef) {
437 Int_t nHits = fMCEventHandler->GetParticleAndTR(iTrackRef, particle, trackRefs);
439 // skip empty trackRefs
440 if (nHits < 1) continue;
442 // get the particle charge for further calculation
443 TParticlePDG* ppdg = particle->GetPDG();
444 Int_t charge = ppdg != NULL ? (Int_t)(ppdg->Charge()/3.0) : 0;
448 // loop over simulated track hits
449 for (Int_t iHit = 0; iHit < nHits; ++iHit) {
450 AliTrackReference* trackReference = static_cast<AliTrackReference*>(trackRefs->UncheckedAt(iHit));
452 // skip trackRefs not in MUON
453 if (trackReference->DetectorId() != AliTrackReference::kMUON) continue;
455 // Get track parameters of current hit
456 x = trackReference->X();
457 y = trackReference->Y();
458 z = trackReference->Z();
459 pX = trackReference->Px();
460 pY = trackReference->Py();
461 pZ = trackReference->Pz();
463 // check chamberId of current trackReference
464 Int_t detElemId = trackReference->UserId();
465 Int_t chamberId = detElemId / 100 - 1;
466 if (chamberId < 0 || chamberId >= AliMUONConstants::NTrackingCh()) continue;
468 // set hit parameters
469 hit->SetUniqueID(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, iHit));
471 hit->SetErrXY(0.,0.);
473 // compute track parameters at hit
476 inverseBendingMomentum = 0;
477 if (TMath::Abs(pZ) > 0) {
478 bendingSlope = pY/pZ;
479 nonBendingSlope = pX/pZ;
481 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
482 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
483 inverseBendingMomentum *= charge;
485 // set track parameters at hit
486 AliMUONTrackParam trackParam;
487 trackParam.SetNonBendingCoor(x);
488 trackParam.SetBendingCoor(y);
490 trackParam.SetBendingSlope(bendingSlope);
491 trackParam.SetNonBendingSlope(nonBendingSlope);
492 trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
494 // add track parameters at current hit to the track
495 track.AddTrackParamAtCluster(trackParam, *hit, kTRUE);
498 // if none of the track hits was in MUON, goto the next track
499 if (track.GetNClusters() < 1) continue;
501 // get track parameters at particle's vertex
509 // compute rest of track parameters at particle's vertex
512 inverseBendingMomentum = 0;
513 if (TMath::Abs(pZ) > 0) {
514 bendingSlope = pY/pZ;
515 nonBendingSlope = pX/pZ;
517 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
518 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
519 inverseBendingMomentum *= charge;
521 // set track parameters at particle's vertex
522 AliMUONTrackParam trackParamAtVertex;
523 trackParamAtVertex.SetNonBendingCoor(x);
524 trackParamAtVertex.SetBendingCoor(y);
525 trackParamAtVertex.SetZ(z);
526 trackParamAtVertex.SetBendingSlope(bendingSlope);
527 trackParamAtVertex.SetNonBendingSlope(nonBendingSlope);
528 trackParamAtVertex.SetInverseBendingMomentum(inverseBendingMomentum);
530 // add track parameters at vertex
531 track.SetTrackParamAtVertex(&trackParamAtVertex);
534 track.SetUniqueID(iTrackRef);
535 tmpTrackRefStore->Add(track);
538 CleanMuonTrackRef(tmpTrackRefStore);
541 delete tmpTrackRefStore;
544 //_____________________________________________________________________________
545 void AliMUONRecoCheck::MakeTriggerableTracks()
547 /// Make triggerable tracks
548 if (!(fRecoTriggerRefStore = AliMUONESDInterface::NewTriggerTrackStore()))
551 Double_t x, y, z, slopeX, slopeY, pZ, xLoc, yLoc, zLoc;
553 TClonesArray* trackRefs;
554 Int_t nTrackRef = fMCEventHandler->MCEvent()->GetNumberOfTracks();
556 // loop over simulated tracks
557 for (Int_t iTrackRef = 0; iTrackRef < nTrackRef; ++iTrackRef) {
558 Int_t nHits = fMCEventHandler->GetParticleAndTR(iTrackRef, particle, trackRefs);
560 // skip empty trackRefs
561 if (nHits < 1) continue;
563 AliMUONTriggerTrack track;
564 AliMUONDigitStoreV2S digitStore;
565 Int_t hitsOnTrigger = 0;
568 // loop over simulated track hits
569 for (Int_t iHit = 0; iHit < nHits; ++iHit) {
570 AliTrackReference* trackReference = static_cast<AliTrackReference*>(trackRefs->UncheckedAt(iHit));
572 // skip trackRefs not in MUON
573 if (trackReference->DetectorId() != AliTrackReference::kMUON) continue;
575 // check chamberId of current trackReference
576 Int_t detElemId = trackReference->UserId();
577 Int_t chamberId = detElemId / 100 - 1;
578 if (chamberId < AliMUONConstants::NTrackingCh() || chamberId >= AliMUONConstants::NCh() ) continue;
580 // Get track parameters of current hit
581 x = trackReference->X();
582 y = trackReference->Y();
583 z = trackReference->Z();
585 if ( InitTriggerResponse() ) {
586 fGeometryTransformer->Global2Local(detElemId, x, y, z, xLoc, yLoc, zLoc);
589 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
591 const AliMpVSegmentation* seg
592 = AliMpSegmentation::Instance()
593 ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
595 AliMpPad pad = seg->PadByPosition(xLoc,yLoc,kFALSE);
596 Int_t ix = pad.GetIx();
597 Int_t iy = pad.GetIy();
599 if ( !pad.IsValid() ) continue;
601 if ( cath == AliMp::kCath0 ) nboard = pad.GetLocalBoardId(0);
603 AliMUONVDigit* digit = digitStore.Add(detElemId, nboard, pad.GetLocalBoardChannel(0),
604 cath, AliMUONVDigitStore::kDeny);
606 digit->SetPadXY(ix,iy);
607 digit->SetCharge(1.);
612 if ( hitsOnTrigger == 0 ) {
613 pZ = trackReference->Pz();
614 slopeX = ( pZ == 0. ) ? 99999. : trackReference->Px() / pZ;
615 slopeY = ( pZ == 0. ) ? 99999. : trackReference->Py() / pZ;
620 track.SetSlopeX(slopeX);
621 track.SetSlopeY(slopeY);
624 if ( currCh != chamberId ) {
631 if ( hitsOnTrigger < 3 ) continue;
633 // Check if the track passes the trigger algorithm
634 if ( InitTriggerResponse() ) {
635 AliMUONTriggerStoreV1 triggerStore;
636 fTriggerElectronics->Digits2Trigger(digitStore,triggerStore);
638 TIter next(triggerStore.CreateIterator());
639 AliMUONLocalTrigger* locTrg(0x0);
641 Int_t ptCutLevel = 0;
643 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
645 if ( locTrg->IsTrigX() && locTrg->IsTrigY() )
647 ptCutLevel = TMath::Max(ptCutLevel, 1);
648 if ( locTrg->LoHpt() ) ptCutLevel = TMath::Max(ptCutLevel, 3);
649 else if ( locTrg->LoLpt() ) ptCutLevel = TMath::Max(ptCutLevel, 2);
651 } // end of loop on Local Trigger
652 track.SetPtCutLevel(ptCutLevel);
654 track.SetUniqueID(iTrackRef);
655 fRecoTriggerRefStore->Add(track);
660 //_____________________________________________________________________________
661 void AliMUONRecoCheck::CleanMuonTrackRef(const AliMUONVTrackStore *tmpTrackRefStore)
663 /// Re-calculate hits parameters because two AliTrackReferences are recorded for
664 /// each chamber (one when particle is entering + one when particle is leaving
665 /// the sensitive volume)
666 if (!(fTrackRefStore = AliMUONESDInterface::NewTrackStore())) return;
668 Double_t maxGasGap = 1.; // cm
669 Double_t x, y, z, pX, pY, pZ, x1, y1, z1, pX1, pY1, pZ1, z2;
670 Double_t bendingSlope,nonBendingSlope,inverseBendingMomentum;
671 AliMUONVCluster* hit = AliMUONESDInterface::NewCluster();
674 TIter next(tmpTrackRefStore->CreateIterator());
676 // loop over tmpTrackRef
678 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
680 AliMUONTrack newTrack;
682 // loop over tmpTrackRef's hits
684 Int_t nTrackHits = track->GetNClusters();
685 while (iHit1 < nTrackHits) {
686 AliMUONTrackParam *trackParam1 = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit1);
688 // get track parameters at hit1
689 x1 = trackParam1->GetNonBendingCoor();
690 y1 = trackParam1->GetBendingCoor();
691 z1 = trackParam1->GetZ();
692 pX1 = trackParam1->Px();
693 pY1 = trackParam1->Py();
694 pZ1 = trackParam1->Pz();
696 // prepare new track parameters
704 // loop over next tmpTrackRef's hits
705 Int_t nCombinedHits = 1;
706 for (Int_t iHit2 = iHit1+1; iHit2 < nTrackHits; iHit2++) {
707 AliMUONTrackParam *trackParam2 = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit2);
709 // get z position of hit2
710 z2 = trackParam2->GetZ();
712 // complete new track parameters if hit2 is on the same detection element
713 if ( TMath::Abs(z2-z1) < maxGasGap ) {
714 x += trackParam2->GetNonBendingCoor();
715 y += trackParam2->GetBendingCoor();
717 pX += trackParam2->Px();
718 pY += trackParam2->Py();
719 pZ += trackParam2->Pz();
726 // finalize new track parameters
727 x /= (Double_t)nCombinedHits;
728 y /= (Double_t)nCombinedHits;
729 z /= (Double_t)nCombinedHits;
730 pX /= (Double_t)nCombinedHits;
731 pY /= (Double_t)nCombinedHits;
732 pZ /= (Double_t)nCombinedHits;
735 inverseBendingMomentum = 0;
736 if (TMath::Abs(pZ) > 0) {
737 bendingSlope = pY/pZ;
738 nonBendingSlope = pX/pZ;
740 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
741 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
742 inverseBendingMomentum *= trackParam1->GetCharge();
744 // set hit parameters
745 hit->SetUniqueID(trackParam1->GetClusterPtr()->GetUniqueID());
747 hit->SetErrXY(0.,0.);
749 // set new track parameters at new hit
750 AliMUONTrackParam trackParam;
751 trackParam.SetNonBendingCoor(x);
752 trackParam.SetBendingCoor(y);
754 trackParam.SetBendingSlope(bendingSlope);
755 trackParam.SetNonBendingSlope(nonBendingSlope);
756 trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
758 // add track parameters at current hit to the track
759 newTrack.AddTrackParamAtCluster(trackParam, *hit, kTRUE);
764 newTrack.SetUniqueID(track->GetUniqueID());
765 newTrack.SetTrackParamAtVertex(track->GetTrackParamAtVertex());
766 fTrackRefStore->Add(newTrack);
773 //_____________________________________________________________________________
774 void AliMUONRecoCheck::MakeReconstructibleTracks(UInt_t requestedStationMask, Bool_t request2ChInSameSt45,
775 Bool_t hitInFrontOfPad)
777 /// Isolate the reconstructible tracks
778 if (!(fRecoTrackRefStore = AliMUONESDInterface::NewTrackStore())) return;
780 // need geometry transformer and segmentation to check if trackrefs are located in front of pad(s)
781 if (hitInFrontOfPad) {
782 if (!InitGeometryTransformer()) return;
783 if (!AliMpSegmentation::Instance(kFALSE) && !AliMUONCDB::LoadMapping(kTRUE)) return;
786 // create iterator on trackRef
787 TIter next(fTrackRefStore->CreateIterator());
789 // loop over trackRef and add reconstructible tracks to fRecoTrackRefStore
791 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
793 // check if the track is valid as it is
794 if (track->IsValid(requestedStationMask, request2ChInSameSt45)) {
796 if (hitInFrontOfPad) {
798 AliMUONTrack trackTmp(*track);
800 // loop over clusters and remove those which are not in front of pad(s)
801 AliMUONTrackParam *param = static_cast<AliMUONTrackParam*>(trackTmp.GetTrackParamAtCluster()->First());
803 AliMUONTrackParam *nextParam = static_cast<AliMUONTrackParam*>(trackTmp.GetTrackParamAtCluster()->After(param));
804 if (!IsHitInFrontOfPad(param)) trackTmp.RemoveTrackParamAtCluster(param);
808 // add the track if it is still valid
809 if (trackTmp.IsValid(requestedStationMask, request2ChInSameSt45)) fRecoTrackRefStore->Add(trackTmp);
814 fRecoTrackRefStore->Add(*track);
824 //_____________________________________________________________________________
825 AliMUONTrack* AliMUONRecoCheck::FindCompatibleTrack(AliMUONTrack &track, AliMUONVTrackStore &trackStore,
826 Int_t &nMatchClusters, Bool_t useLabel, Double_t sigmaCut)
828 /// Return the track from the store matched with the given track (or 0x0) and the number of matched clusters.
829 /// Matching is done by using the MC label of by comparing cluster/TrackRef positions according to the flag "useLabel".
830 /// WARNING: Who match who matters since the matching algorithm uses the *fraction* of matched clusters of the given track
832 AliMUONTrack *matchedTrack = 0x0;
835 if (useLabel) { // by using the MC label
837 // get the corresponding simulated track if any
838 Int_t label = track.GetMCLabel();
839 matchedTrack = (AliMUONTrack*) trackStore.FindObject(label);
841 // get the fraction of matched clusters
843 Int_t nClusters = track.GetNClusters();
844 for (Int_t iCl = 0; iCl < nClusters; iCl++)
845 if (((AliMUONTrackParam*) track.GetTrackParamAtCluster()->UncheckedAt(iCl))->GetClusterPtr()->GetMCLabel() == label)
849 } else { // by comparing cluster/TrackRef positions
851 // look for the corresponding simulated track if any
852 TIter next(trackStore.CreateIterator());
853 AliMUONTrack* track2;
854 while ( ( track2 = static_cast<AliMUONTrack*>(next()) ) ) {
856 // check compatibility
858 if (track.Match(*track2, sigmaCut, n)) {
859 matchedTrack = track2;
873 //_____________________________________________________________________________
874 AliMUONTriggerTrack* AliMUONRecoCheck::FindCompatibleTrack(AliMUONTriggerTrack &track, const AliMUONVTriggerTrackStore &triggerTrackStore,
877 /// Return the trigger track from the store matched with the given track (or 0x0).
878 /// Matching is done by comparing cluster/TrackRef positions.
880 AliMUONTriggerTrack *matchedTrack = 0x0;
882 // look for the corresponding simulated track if any
883 TIter next(triggerTrackStore.CreateIterator());
884 AliMUONTriggerTrack* track2;
885 while ( ( track2 = static_cast<AliMUONTriggerTrack*>(next()) ) ) {
886 // check compatibility
887 if (track.Match(*track2, sigmaCut)) {
888 matchedTrack = track2;
898 //____________________________________________________________________________
899 Bool_t AliMUONRecoCheck::InitTriggerResponse()
901 /// Initialize trigger electronics
902 /// for building of triggerable tracks from MC
904 if ( fTriggerElectronics ) return kTRUE;
906 if ( ! InitGeometryTransformer() ) return kFALSE;
908 if ( ! AliMpDDLStore::Instance(false) && ! AliMpCDB::LoadDDLStore()) return kFALSE;
910 if ( ! InitCalibrationData() ) return kFALSE;
912 fTriggerElectronics = new AliMUONTriggerElectronics(fCalibrationData);
918 //____________________________________________________________________________
919 Bool_t AliMUONRecoCheck::InitCalibrationData()
921 /// Initialize calibration data
922 if ( ! fCalibrationData ) {
923 if ( !AliMUONCDB::CheckOCDB() ) return kFALSE;
924 fCalibrationData = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
930 //____________________________________________________________________________
931 Bool_t AliMUONRecoCheck::InitGeometryTransformer()
933 /// Return geometry transformer
934 /// (create it if necessary)
935 if ( ! fGeometryTransformer ) {
937 if ( !AliMUONCDB::CheckOCDB() ) return kFALSE;
939 if (!AliGeomManager::GetGeometry()) {
940 AliGeomManager::LoadGeometry();
941 if (!AliGeomManager::GetGeometry()) return kFALSE;
942 if (!AliGeomManager::ApplyAlignObjsFromCDB("MUON")) return kFALSE;
945 fGeometryTransformer = new AliMUONGeometryTransformer();
946 fGeometryTransformer->LoadGeometryData();
952 //________________________________________________________________________
953 Bool_t AliMUONRecoCheck::IsHitInFrontOfPad(AliMUONTrackParam *param) const
955 /// Return kTRUE if the hit is located in front of at least 1 pad
957 Int_t deId = param->GetClusterPtr()->GetDetElemId();
960 fGeometryTransformer->Global2Local(deId, param->GetNonBendingCoor(), param->GetBendingCoor(), param->GetZ(), xL, yL, zL);
962 const AliMpVSegmentation* seg1 = AliMpSegmentation::Instance()->GetMpSegmentation(deId, AliMp::kCath0);
963 const AliMpVSegmentation* seg2 = AliMpSegmentation::Instance()->GetMpSegmentation(deId, AliMp::kCath1);
964 if (!seg1 || !seg2) return kFALSE;
966 AliMpPad pad1 = seg1->PadByPosition(xL, yL, kFALSE);
967 AliMpPad pad2 = seg2->PadByPosition(xL, yL, kFALSE);
969 return (pad1.IsValid() || pad2.IsValid());