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 #include "AliMUONESDInterface.h"
19 #include "AliMUONTrack.h"
20 #include "AliMUONVTrackStore.h"
21 #include "AliMUONVCluster.h"
22 #include "AliMUONVClusterStore.h"
23 #include "AliMUONVDigit.h"
24 #include "AliMUONVDigitStore.h"
25 #include "AliMUONLocalTrigger.h"
26 #include "AliMUONTriggerTrack.h"
27 #include "AliMUONVTriggerStore.h"
28 #include "AliMUONVTriggerTrackStore.h"
29 #include "AliMUON2DMapIterator.h"
30 #include "AliMUONTrackParam.h"
31 #include "AliMUONTrackExtrap.h"
32 #include "AliMUONConstants.h"
33 #include "AliMUONTracker.h"
34 #include "AliMUONRecoParam.h"
35 #include "AliMUONVTrackReconstructor.h"
37 #include "AliMpExMapIterator.h"
38 #include "AliMpVSegmentation.h"
39 #include "AliMpSegmentation.h"
42 #include "AliESDEvent.h"
43 #include "AliESDMuonTrack.h"
44 #include "AliESDMuonCluster.h"
45 #include "AliESDMuonPad.h"
49 #include <TIterator.h>
52 #include <Riostream.h>
53 #include <TGeoGlobalMagField.h>
54 #include <TVirtualMagField.h>
56 //-----------------------------------------------------------------------------
57 /// \class AliMUONESDInterface
59 /// There are 2 way of using thid converter between MUON track/cluster/digit
60 /// and ESDMuon track/cluster/pad:
62 /// 1) using the static methods converting the objects one by one
64 /// 2) loading a whole ESDEvent and using the finders and/or the iterators
65 /// to access the corresponding MUON objects
67 /// note: You can set the recoParam used to refit the MUON track with ResetTracker(...);
68 /// By default we use Kalman filter + Smoother
70 /// \author Philippe Pillot
71 //-----------------------------------------------------------------------------
74 ClassImp(AliMUONESDInterface)
77 AliMUONRecoParam* AliMUONESDInterface::fgRecoParam = 0x0;
78 AliMUONVTrackReconstructor* AliMUONESDInterface::fgTracker = 0x0;
80 TString AliMUONESDInterface::fgTrackStoreName = "AliMUONTrackStoreV1";
81 TString AliMUONESDInterface::fgClusterStoreName = "AliMUONClusterStoreV2";
82 TString AliMUONESDInterface::fgDigitStoreName = "AliMUONDigitStoreV2R";
83 TString AliMUONESDInterface::fgTriggerStoreName = "AliMUONTriggerStoreV1";
84 TString AliMUONESDInterface::fgTriggerTrackStoreName = "AliMUONTriggerTrackStoreV1";
86 //_____________________________________________________________________________
87 AliMUONESDInterface::AliMUONESDInterface()
95 /// Default constructor
98 //_____________________________________________________________________________
99 AliMUONESDInterface::~AliMUONESDInterface()
109 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
110 // methods to play with internal objects //
111 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
113 //_____________________________________________________________________________
114 void AliMUONESDInterface::Clear(Option_t*)
117 delete fTracks; fTracks = 0x0;
118 delete fDigits; fDigits = 0x0;
119 delete fTriggers; fTriggers = 0x0;
120 delete fClusterMap; fClusterMap = 0x0;
121 delete fDigitMap; fDigitMap = 0x0;
124 //_____________________________________________________________________________
125 void AliMUONESDInterface::Reset()
127 /// reset stores and maps
129 if (fTracks) fTracks->Clear("C");
130 else fTracks = NewTrackStore();
132 if (fDigits) fDigits->Clear("C");
133 else fDigits = NewDigitStore();
135 if (fTriggers) fTriggers->Clear("C");
136 else fTriggers = NewTriggerStore();
138 if (fClusterMap) fClusterMap->Clear();
139 else fClusterMap = new AliMpExMap;
140 fClusterMap->SetOwner(kTRUE);
142 if (fDigitMap) fDigitMap->Clear();
143 else fDigitMap = new AliMpExMap;
144 fDigitMap->SetOwner(kTRUE);
147 //_____________________________________________________________________________
148 void AliMUONESDInterface::LoadEvent(AliESDEvent& esdEvent, Bool_t refit)
150 /// Extract MUON data from the given ESD event
152 // reset data members
155 // loop over ESD tracks and fill the stores
156 Int_t nTracks = (Int_t) esdEvent.GetNumberOfMuonTracks();
157 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
160 AliESDMuonTrack* esdTrack = esdEvent.GetMuonTrack(iTrack);
162 // fill trigger store if related info are availables
163 if (esdTrack->ContainTriggerData()) Add(*esdTrack, *fTriggers);
165 // fill tracker data if availables
166 if (!esdTrack->ContainTrackerData()) continue;
168 // add it to track store
169 AliMUONTrack* track = Add(*esdTrack, *fTracks, refit);
171 // prepare cluster map
172 AliMpExMap* cMap = new AliMpExMap;
173 cMap->SetOwner(kFALSE);
174 fClusterMap->Add(esdTrack->GetUniqueID(), cMap);
176 // prepare digit maps
177 AliMpExMap* dMaps = new AliMpExMap;
178 dMaps->SetOwner(kTRUE);
179 fDigitMap->Add(esdTrack->GetUniqueID(), dMaps);
181 // loop over ESD clusters
182 Int_t nClusters = esdTrack->GetNClusters();
183 for (Int_t iCluster = 0; iCluster < nClusters; iCluster++) {
186 AliESDMuonCluster *esdCluster = (AliESDMuonCluster*) esdTrack->GetClusters().UncheckedAt(iCluster);
188 // get the corresponding MUON cluster
189 AliMUONVCluster* cluster = FindClusterInTrack(*track, esdCluster->GetUniqueID());
192 cMap->Add(cluster->GetUniqueID(), cluster);
195 AliMpExMap* dMap =new AliMpExMap;
196 dMap->SetOwner(kFALSE);
197 dMaps->Add(esdCluster->GetUniqueID(), dMap);
199 // loop over ESD pads
200 Int_t nPads = esdCluster->GetNPads();
201 for (Int_t iPad = 0; iPad < nPads; iPad++) {
204 AliESDMuonPad *esdPad = (AliESDMuonPad*) esdCluster->GetPads().UncheckedAt(iPad);
206 // add it to digit store
207 AliMUONVDigit* digit = Add(*esdPad, *fDigits);
210 if (digit) dMap->Add(esdPad->GetUniqueID(), digit);
211 else dMap->Add(esdPad->GetUniqueID(), fDigits->FindObject(esdPad->GetUniqueID()));
213 } // end of loop over pads
215 } // end of loop over clusters
217 } // end of loop over tracks
221 //___________________________________________________________________________
222 Int_t AliMUONESDInterface::GetNTracks() const
224 /// return the number of tracks
225 return fTracks ? fTracks->GetSize() : 0;
228 //___________________________________________________________________________
229 Int_t AliMUONESDInterface::GetNClusters() const
231 /// return the number of clusters
234 TIter next(CreateTrackIterator());
235 while ((track = static_cast<AliMUONTrack*>(next()))) nClusters += track->GetNClusters();
239 //___________________________________________________________________________
240 Int_t AliMUONESDInterface::GetNClusters(UInt_t trackId) const
242 /// return the number of clusters in track "trackId"
243 AliMUONTrack* track = FindTrack(trackId);
244 return track ? track->GetNClusters() : 0;
247 //___________________________________________________________________________
248 Int_t AliMUONESDInterface::GetNDigits() const
250 /// return the number of digits
251 return fDigits ? fDigits->GetSize() : 0;
254 //___________________________________________________________________________
255 Int_t AliMUONESDInterface::GetNDigits(UInt_t trackId) const
257 /// return the number of digits in all clusters of track "trackId"
259 AliMUONVCluster *cluster;
260 TIter next(CreateClusterIterator(trackId));
261 while ((cluster = static_cast<AliMUONVCluster*>(next()))) nDigits += cluster->GetNDigits();
265 //___________________________________________________________________________
266 Int_t AliMUONESDInterface::GetNDigits(UInt_t trackId, UInt_t clusterId) const
268 /// return the number of digits in cluster numbered "iCluster" of track "iTrack"
269 AliMUONVCluster* cluster = FindCluster(trackId, clusterId);
270 return cluster ? cluster->GetNDigits() : 0;
273 //___________________________________________________________________________
274 Int_t AliMUONESDInterface::GetNDigitsInCluster(UInt_t clusterId) const
276 /// return the number of digits in cluster "clusterId"
277 AliMUONVCluster* cluster = FindCluster(clusterId);
278 return cluster ? cluster->GetNDigits() : 0;
281 //___________________________________________________________________________
282 Int_t AliMUONESDInterface::GetNTriggers() const
284 /// return the number of triggers
285 return fTriggers ? fTriggers->GetSize() : 0;
288 //___________________________________________________________________________
289 AliMUONTrack* AliMUONESDInterface::FindTrack(UInt_t trackId) const
291 /// return track "trackId" (0x0 if not found)
292 AliMUONTrack *track = fTracks ? static_cast<AliMUONTrack*>(fTracks->FindObject(trackId)) : 0x0;
293 if (!track) AliWarning(Form("track %d does not exist",trackId));
297 //___________________________________________________________________________
298 AliMUONVCluster* AliMUONESDInterface::FindCluster(UInt_t clusterId) const
300 /// loop over tracks and return the first cluster "clusterId" found (0x0 if not found)
302 AliMUONVCluster* cluster = 0x0;
306 TIter next(fClusterMap->CreateIterator());
307 while ((cMap = static_cast<AliMpExMap*>(next()))) {
309 cluster = static_cast<AliMUONVCluster*>(cMap->GetValue(clusterId));
310 if (cluster) return cluster;
316 if (!cluster) AliWarning(Form("cluster %d does not exist",clusterId));
320 //___________________________________________________________________________
321 AliMUONVCluster* AliMUONESDInterface::FindCluster(UInt_t trackId, UInt_t clusterId) const
323 /// return cluster "clusterId" in track "trackId" (0x0 if not found)
324 AliMpExMap *cMap = fClusterMap ? static_cast<AliMpExMap*>(fClusterMap->GetValue(trackId)) : 0x0;
325 AliMUONVCluster* cluster = cMap ? static_cast<AliMUONVCluster*>(cMap->GetValue(clusterId)) : 0x0;
326 if (!cluster) AliWarning(Form("cluster %d does not exist in track %d", clusterId, trackId));
330 //___________________________________________________________________________
331 AliMUONVDigit* AliMUONESDInterface::FindDigit(UInt_t digitId) const
333 /// return digit "digitId" (0x0 if not found)
334 AliMUONVDigit *digit = fDigits ? fDigits->FindObject(digitId) : 0x0;
335 if (!digit) AliWarning(Form("digit %d does not exist",digitId));
339 //___________________________________________________________________________
340 AliMUONLocalTrigger* AliMUONESDInterface::FindLocalTrigger(Int_t boardNumber) const
342 /// return MUON local trigger "boardNumber"
343 return (fTriggers) ? fTriggers->FindLocal(boardNumber) : 0x0;
346 //___________________________________________________________________________
347 TIterator* AliMUONESDInterface::CreateTrackIterator() const
349 /// return iterator over all tracks
350 return fTracks ? fTracks->CreateIterator() : 0x0;
353 //___________________________________________________________________________
354 TIterator* AliMUONESDInterface::CreateClusterIterator() const
356 /// return iterator over all clusters
357 return fClusterMap ? new AliMUON2DMapIterator(*fClusterMap) : 0x0;
360 //___________________________________________________________________________
361 TIterator* AliMUONESDInterface::CreateClusterIterator(UInt_t trackId) const
363 /// return iterator over clusters of track "trackId"
364 AliMpExMap *cMap = fClusterMap ? static_cast<AliMpExMap*>(fClusterMap->GetValue(trackId)) : 0x0;
365 return cMap ? cMap->CreateIterator() : 0x0;
368 //___________________________________________________________________________
369 TIterator* AliMUONESDInterface::CreateDigitIterator() const
371 /// return iterator over all digits
372 return fDigits ? fDigits->CreateIterator() : 0x0;
375 //___________________________________________________________________________
376 TIterator* AliMUONESDInterface::CreateDigitIterator(UInt_t trackId) const
378 /// return iterator over all digits of track "trackId"
379 AliMpExMap* dMaps = fDigitMap ? static_cast<AliMpExMap*>(fDigitMap->GetValue(trackId)) : 0x0;
380 return dMaps ? new AliMUON2DMapIterator(*dMaps) : 0x0;
383 //___________________________________________________________________________
384 TIterator* AliMUONESDInterface::CreateDigitIterator(UInt_t trackId, UInt_t clusterId) const
386 /// return iterator over digits of cluster "clusterId" in track "trackId"
387 AliMpExMap* dMaps = fDigitMap ? static_cast<AliMpExMap*>(fDigitMap->GetValue(trackId)) : 0x0;
388 AliMpExMap* dMap = dMaps ? static_cast<AliMpExMap*>(dMaps->GetValue(clusterId)) : 0x0;
389 return dMap ? dMap->CreateIterator() : 0x0;
392 //___________________________________________________________________________
393 TIterator* AliMUONESDInterface::CreateDigitIteratorInCluster(UInt_t clusterId) const
395 /// return iterator over digits of the first cluster "clusterId" found by looping over all tracks
397 AliMpExMap* dMap = 0x0;
401 TIter next(fDigitMap->CreateIterator());
402 while ((dMaps = static_cast<AliMpExMap*>(next()))) {
404 dMap = static_cast<AliMpExMap*>(dMaps->GetValue(clusterId));
405 if (dMap) return dMap->CreateIterator();
414 //___________________________________________________________________________
415 TIterator* AliMUONESDInterface::CreateLocalTriggerIterator() const
417 /// return iterator over all local trigger
418 return fTriggers ? fTriggers->CreateLocalIterator() : 0x0;
421 //___________________________________________________________________________
422 AliMUONVCluster* AliMUONESDInterface::FindClusterInTrack(const AliMUONTrack& track, UInt_t clusterId) const
424 /// find the cluster with the given Id into the track
426 Int_t nClusters = track.GetNClusters();
427 for (Int_t iCluster = 0; iCluster < nClusters; iCluster++) {
429 AliMUONVCluster* cluster = ((AliMUONTrackParam*) track.GetTrackParamAtCluster()->UncheckedAt(iCluster))->GetClusterPtr();
430 if (cluster->GetUniqueID() == clusterId) return cluster;
437 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
439 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
441 //_____________________________________________________________________________
442 void AliMUONESDInterface::ResetTracker(const AliMUONRecoParam* recoParam, Bool_t info)
444 /// Reset the MUON tracker using "recoParam" if provided.
445 /// If not provided, will use Kalman filter + Smoother
452 fgRecoParam = new AliMUONRecoParam(*recoParam);
454 if (info) cout<<"I-AliMUONESDInterface::ResetTracker: will refit tracks with provided RecoParam:"<<endl;
458 fgRecoParam = AliMUONRecoParam::GetLowFluxParam();
460 cout<<"W-AliMUONESDInterface::ResetTracker: RecoParam not provided. Will use default LowFlux parametrization:"<<endl;
464 // print useful parameters for refitting
466 cout<<" --> Tracking mode = "<<fgRecoParam->GetTrackingMode()<<endl;
467 if (fgRecoParam->UseSmoother()) cout<<" --> Use Smoother"<<endl;
468 else cout<<" --> Do not use smoother"<<endl;
469 cout<<" --> Vertex dispersion in bending direction = "
470 <<fgRecoParam->GetBendingVertexDispersion()<<" cm"<<endl;
473 if (!TGeoGlobalMagField::Instance()->GetField())
474 cout<<"W-AliMUONESDInterface::ResetTracker: Magnetic field has not been set --> assume field is OFF"<<endl;
476 fgTracker = AliMUONTracker::CreateTrackReconstructor(fgRecoParam,0x0);
480 //_____________________________________________________________________________
481 AliMUONVTrackStore* AliMUONESDInterface::NewTrackStore()
483 /// Create an empty track store of type fgTrackStoreName
484 TClass* classPtr = TClass::GetClass(fgTrackStoreName);
485 if (!classPtr || !classPtr->InheritsFrom("AliMUONVTrackStore")) {
486 cout<<"E-AliMUONESDInterface::NewTrackStore: Unable to create store of type "<<fgTrackStoreName.Data()<<endl;
489 return reinterpret_cast<AliMUONVTrackStore*>(classPtr->New());
492 //_____________________________________________________________________________
493 AliMUONVClusterStore* AliMUONESDInterface::NewClusterStore()
495 /// Create an empty cluster store of type fgClusterStoreName
496 TClass* classPtr = TClass::GetClass(fgClusterStoreName);
497 if (!classPtr || !classPtr->InheritsFrom("AliMUONVClusterStore")) {
498 cout<<"E-AliMUONESDInterface::NewClusterStore: Unable to create store of type "<<fgClusterStoreName.Data()<<endl;
501 return reinterpret_cast<AliMUONVClusterStore*>(classPtr->New());
504 //_____________________________________________________________________________
505 AliMUONVDigitStore* AliMUONESDInterface::NewDigitStore()
507 /// Create an empty digit store of type fgDigitStoreName
508 TClass* classPtr = TClass::GetClass(fgDigitStoreName);
509 if (!classPtr || !classPtr->InheritsFrom("AliMUONVDigitStore")) {
510 cout<<"E-AliMUONESDInterface::NewDigitStore: Unable to create store of type "<<fgDigitStoreName.Data()<<endl;
513 return reinterpret_cast<AliMUONVDigitStore*>(classPtr->New());
516 //_____________________________________________________________________________
517 AliMUONVTriggerStore* AliMUONESDInterface::NewTriggerStore()
519 /// Create an empty trigger store of type fgTriggerStoreName
520 TClass* classPtr = TClass::GetClass(fgTriggerStoreName);
521 if (!classPtr || !classPtr->InheritsFrom("AliMUONVTriggerStore")) {
522 cout<<"E-AliMUONESDInterface::NewTriggerStore: Unable to create store of type "<<fgTriggerStoreName.Data()<<endl;
525 return reinterpret_cast<AliMUONVTriggerStore*>(classPtr->New());
528 //_____________________________________________________________________________
529 AliMUONVTriggerTrackStore* AliMUONESDInterface::NewTriggerTrackStore()
531 /// Create an empty trigger track store of type fgTriggerTrackStoreName
532 TClass* classPtr = TClass::GetClass(fgTriggerTrackStoreName);
533 if (!classPtr || !classPtr->InheritsFrom("AliMUONVTriggerTrackStore")) {
534 cout<<"E-AliMUONESDInterface::NewTriggerTrackStore: Unable to create store of type "<<fgTriggerTrackStoreName.Data()<<endl;
537 return reinterpret_cast<AliMUONVTriggerTrackStore*>(classPtr->New());
540 //_________________________________________________________________________
541 void AliMUONESDInterface::GetParamAtVertex(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
543 /// Get parameters at vertex from ESDMuon track
544 trackParam.SetZ(esdTrack.GetZ());
545 trackParam.SetNonBendingCoor(esdTrack.GetNonBendingCoor());
546 trackParam.SetNonBendingSlope(TMath::Tan(esdTrack.GetThetaX()));
547 trackParam.SetBendingCoor(esdTrack.GetBendingCoor());
548 trackParam.SetBendingSlope(TMath::Tan(esdTrack.GetThetaY()));
549 trackParam.SetInverseBendingMomentum(esdTrack.GetInverseBendingMomentum());
552 //_________________________________________________________________________
553 void AliMUONESDInterface::GetParamAtDCA(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
555 /// Get parameters at DCA from ESDMuon track
556 trackParam.SetZ(esdTrack.GetZ());
557 trackParam.SetNonBendingCoor(esdTrack.GetNonBendingCoorAtDCA());
558 trackParam.SetNonBendingSlope(TMath::Tan(esdTrack.GetThetaXAtDCA()));
559 trackParam.SetBendingCoor(esdTrack.GetBendingCoorAtDCA());
560 trackParam.SetBendingSlope(TMath::Tan(esdTrack.GetThetaYAtDCA()));
561 trackParam.SetInverseBendingMomentum(esdTrack.GetInverseBendingMomentumAtDCA());
564 //_________________________________________________________________________
565 void AliMUONESDInterface::GetParamAtFirstCluster(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
567 /// Get parameters at first cluster from ESDMuon track
568 trackParam.SetZ(esdTrack.GetZUncorrected());
569 trackParam.SetNonBendingCoor(esdTrack.GetNonBendingCoorUncorrected());
570 trackParam.SetNonBendingSlope(TMath::Tan(esdTrack.GetThetaXUncorrected()));
571 trackParam.SetBendingCoor(esdTrack.GetBendingCoorUncorrected());
572 trackParam.SetBendingSlope(TMath::Tan(esdTrack.GetThetaYUncorrected()));
573 trackParam.SetInverseBendingMomentum(esdTrack.GetInverseBendingMomentumUncorrected());
576 //_________________________________________________________________________
577 void AliMUONESDInterface::GetParamCov(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
579 /// Get parameters covariances from ESD track
581 // get ESD covariance matrix
582 TMatrixD covariances(5,5);
583 esdTrack.GetCovariances(covariances);
585 // compute Jacobian to change the coordinate system
586 // from (X,thetaX,Y,thetaY,c/pYZ) to (X,slopeX,Y,slopeY,c/pYZ)
587 Double_t cosThetaX = TMath::Cos(esdTrack.GetThetaXUncorrected());
588 Double_t cosThetaY = TMath::Cos(esdTrack.GetThetaYUncorrected());
592 jacob(1,1) = 1. / cosThetaX / cosThetaX;
594 jacob(3,3) = 1. / cosThetaY / cosThetaY;
597 // compute covariance matrix in ESD coordinate system
598 TMatrixD tmp(covariances,TMatrixD::kMultTranspose,jacob);
599 trackParam.SetCovariances(TMatrixD(jacob,TMatrixD::kMult,tmp));
603 //_________________________________________________________________________
604 void AliMUONESDInterface::SetParamAtVertex(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
606 /// Set parameters in ESD track
607 esdTrack.SetZ(trackParam.GetZ());
608 esdTrack.SetNonBendingCoor(trackParam.GetNonBendingCoor());
609 esdTrack.SetThetaX(TMath::ATan(trackParam.GetNonBendingSlope()));
610 esdTrack.SetBendingCoor(trackParam.GetBendingCoor());
611 esdTrack.SetThetaY(TMath::ATan(trackParam.GetBendingSlope()));
612 esdTrack.SetInverseBendingMomentum(trackParam.GetInverseBendingMomentum());
615 //_________________________________________________________________________
616 void AliMUONESDInterface::SetParamAtDCA(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
618 /// Set parameters in ESD track
619 esdTrack.SetNonBendingCoorAtDCA(trackParam.GetNonBendingCoor());
620 esdTrack.SetThetaXAtDCA(TMath::ATan(trackParam.GetNonBendingSlope()));
621 esdTrack.SetBendingCoorAtDCA(trackParam.GetBendingCoor());
622 esdTrack.SetThetaYAtDCA(TMath::ATan(trackParam.GetBendingSlope()));
623 esdTrack.SetInverseBendingMomentumAtDCA(trackParam.GetInverseBendingMomentum());
626 //_________________________________________________________________________
627 void AliMUONESDInterface::SetParamAtFirstCluster(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
629 /// Set parameters in ESD track
630 esdTrack.SetZUncorrected(trackParam.GetZ());
631 esdTrack.SetNonBendingCoorUncorrected(trackParam.GetNonBendingCoor());
632 esdTrack.SetThetaXUncorrected(TMath::ATan(trackParam.GetNonBendingSlope()));
633 esdTrack.SetBendingCoorUncorrected(trackParam.GetBendingCoor());
634 esdTrack.SetThetaYUncorrected(TMath::ATan(trackParam.GetBendingSlope()));
635 esdTrack.SetInverseBendingMomentumUncorrected(trackParam.GetInverseBendingMomentum());
638 //_________________________________________________________________________
639 void AliMUONESDInterface::SetParamCov(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
641 /// Set parameters covariances in ESD track
643 // set null matrix if covariances does not exist
644 if (!trackParam.CovariancesExist()) {
647 esdTrack.SetCovariances(tmp);
651 // compute Jacobian to change the coordinate system
652 // from (X,slopeX,Y,slopeY,c/pYZ) to (X,thetaX,Y,thetaY,c/pYZ)
653 Double_t cosThetaX = TMath::Cos(TMath::ATan(trackParam.GetNonBendingSlope()));
654 Double_t cosThetaY = TMath::Cos(TMath::ATan(trackParam.GetBendingSlope()));
658 jacob(1,1) = cosThetaX * cosThetaX;
660 jacob(3,3) = cosThetaY * cosThetaY;
663 // compute covariance matrix in ESD coordinate system
664 TMatrixD tmp(trackParam.GetCovariances(),TMatrixD::kMultTranspose,jacob);
665 esdTrack.SetCovariances(TMatrixD(jacob,TMatrixD::kMult,tmp));
669 //_____________________________________________________________________________
670 void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONTrack& track, Bool_t refit)
672 /// Transfert data from ESDMuon track to MUON track.
673 /// If refit = kTRUE, the track parameters at each cluster are obtained by refitting the track
674 /// or by extrapolating the parameters at the first one if the refit failed.
675 /// If refit = kFALSE, only the track parameters at first cluster are valid.
676 /// note: You can set the recoParam used to refit the MUON track with ResetTracker(...);
677 /// By default we use Kalman filter + Smoother
679 // if the ESDMuon track is a ghost then return an empty MUON track
680 if (!esdTrack.ContainTrackerData()) {
682 track.SetUniqueID(esdTrack.GetUniqueID());
689 track.SetUniqueID(esdTrack.GetUniqueID());
690 track.FitWithVertex(kFALSE);
691 track.FitWithMCS(kFALSE);
692 track.SetImproved(kFALSE);
693 track.SetVertexErrXY2(0.,0.);
694 track.SetGlobalChi2(esdTrack.GetChi2());
695 track.SetMatchTrigger(esdTrack.GetMatchTrigger());
696 track.SetChi2MatchTrigger(esdTrack.GetChi2MatchTrigger());
697 track.SetHitsPatternInTrigCh(esdTrack.GetHitsPatternInTrigCh());
698 track.SetLocalTrigger(esdTrack.LoCircuit(), esdTrack.LoStripX(), esdTrack.LoStripY(),
699 esdTrack.LoDev(), esdTrack.LoLpt(), esdTrack.LoHpt(),
700 esdTrack.GetTriggerWithoutChamber());
701 track.Connected(esdTrack.IsConnected());
703 // track parameters at vertex
704 AliMUONTrackParam paramAtVertex;
705 GetParamAtVertex(esdTrack, paramAtVertex);
706 track.SetTrackParamAtVertex(¶mAtVertex);
708 // track parameters at first cluster
709 AliMUONTrackParam param;
710 GetParamAtFirstCluster(esdTrack, param);
711 GetParamCov(esdTrack, param);
713 // create empty cluster
714 AliMUONVClusterStore* cStore = NewClusterStore();
716 AliMUONVCluster* cluster = cStore->CreateCluster(0,0,0);
718 // fill TrackParamAtCluster with track parameters at each cluster if available
719 // or with only track parameters at first (fake) cluster if not
720 if(esdTrack.ClustersStored()) {
722 // loop over ESD clusters
723 AliESDMuonCluster *esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().First();
726 // copy cluster information
727 ESDToMUON(*esdCluster, *cluster);
729 // only set the Z parameter to avoid error in the AddTrackParamAtCluster(...) method
730 param.SetZ(cluster->GetZ());
732 // add common track parameters at current cluster
733 track.AddTrackParamAtCluster(param, *cluster, kTRUE);
735 esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().After(esdCluster);
738 // refit the track to get better parameters and covariances at each cluster (temporary disable track improvement)
741 AliMUONTrackParam *firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
742 AliMUONTrackParam paramSave(*firstTrackParam);
744 if (!fgTracker) ResetTracker();
746 if (!fgTracker->RefitTrack(track, kFALSE) && track.GetGlobalChi2() < AliMUONTrack::MaxChi2()) {
747 *firstTrackParam = paramSave;
748 track.UpdateCovTrackParamAtCluster();
755 // get number of the first hit chamber according to the MUONClusterMap
757 while (firstCh < 10 && !esdTrack.IsInMuonClusterMap(firstCh)) firstCh++;
759 // produce fake cluster at this chamber
760 cluster->SetUniqueID(AliMUONVCluster::BuildUniqueID(firstCh, 0, 0));
761 cluster->SetXYZ(param.GetNonBendingCoor(), param.GetBendingCoor(), param.GetZ());
762 cluster->SetErrXY(0., 0.);
764 // add track parameters at first (fake) cluster
765 track.AddTrackParamAtCluster(param, *cluster, kTRUE);
769 // set the MC label from ESD track
770 track.SetMCLabel(esdTrack.GetLabel());
777 //_____________________________________________________________________________
778 void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONLocalTrigger& locTrg)
780 /// Transfert trigger data from ESDMuon track to the MUONLocalTtrigger object
782 // if the ESDMuon track is a ghost then return an empty MUON track
783 if (!esdTrack.ContainTriggerData()) {
784 AliMUONLocalTrigger emptyLocTrg;
785 locTrg = emptyLocTrg;
789 locTrg.SetUniqueID(esdTrack.GetUniqueID());
790 locTrg.SetLoCircuit(esdTrack.LoCircuit());
791 locTrg.SetLoStripX(esdTrack.LoStripX());
792 locTrg.SetLoStripY(esdTrack.LoStripY());
793 locTrg.SetDeviation(esdTrack.LoDev());
794 locTrg.SetLoLpt(esdTrack.LoLpt());
795 locTrg.SetLoHpt(esdTrack.LoHpt());
796 locTrg.SetTriggerWithoutChamber(esdTrack.GetTriggerWithoutChamber());
797 locTrg.SetLoTrigY(1);
798 locTrg.SetX1Pattern(esdTrack.GetTriggerX1Pattern());
799 locTrg.SetX2Pattern(esdTrack.GetTriggerX2Pattern());
800 locTrg.SetX3Pattern(esdTrack.GetTriggerX3Pattern());
801 locTrg.SetX4Pattern(esdTrack.GetTriggerX4Pattern());
802 locTrg.SetY1Pattern(esdTrack.GetTriggerY1Pattern());
803 locTrg.SetY2Pattern(esdTrack.GetTriggerY2Pattern());
804 locTrg.SetY3Pattern(esdTrack.GetTriggerY3Pattern());
805 locTrg.SetY4Pattern(esdTrack.GetTriggerY4Pattern());
809 //_____________________________________________________________________________
810 void AliMUONESDInterface::ESDToMUON(const AliESDMuonCluster& esdCluster, AliMUONVCluster& cluster)
812 /// Transfert data from ESDMuon cluster to MUON cluster
816 cluster.SetUniqueID(esdCluster.GetUniqueID());
817 cluster.SetXYZ(esdCluster.GetX(), esdCluster.GetY(), esdCluster.GetZ());
818 cluster.SetErrXY(esdCluster.GetErrX(),esdCluster.GetErrY());
819 cluster.SetCharge(esdCluster.GetCharge());
820 cluster.SetChi2(esdCluster.GetChi2());
821 cluster.SetMCLabel(esdCluster.GetLabel());
823 if (esdCluster.PadsStored()) {
824 Int_t nPads = esdCluster.GetNPads();
825 for (Int_t iPad = 0; iPad < nPads; iPad++)
826 cluster.AddDigitId(((AliESDMuonPad*)esdCluster.GetPads().UncheckedAt(iPad))->GetUniqueID());
831 //___________________________________________________________________________
832 void AliMUONESDInterface::ESDToMUON(const AliESDMuonPad& esdPad, AliMUONVDigit& digit)
834 /// Transfert data from ESDMuon pad to MUON digit
836 if (!AliMpSegmentation::Instance(kFALSE)) {
837 cout<<"E-AliMUONESDInterface::ESDToMUON: need mapping segmentation to convert ESD pad to MUON digit"<<endl;
841 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(esdPad.GetDetElemId(), esdPad.GetManuId());
842 AliMpPad pad = seg->PadByLocation(esdPad.GetManuId(), esdPad.GetManuChannel(), kFALSE);
844 digit.Saturated(esdPad.IsSaturated());
846 digit.Calibrated(esdPad.IsCalibrated());
847 digit.SetUniqueID(esdPad.GetUniqueID());
848 digit.SetCharge(esdPad.GetCharge());
849 digit.SetADC(esdPad.GetADC());
850 digit.SetPadXY(pad.GetIx(), pad.GetIy());
854 //_____________________________________________________________________________
855 void AliMUONESDInterface::MUONToESD(const AliMUONTrack& track, AliESDMuonTrack& esdTrack, const Double_t vertex[3],
856 const AliMUONVDigitStore* digits, const AliMUONLocalTrigger* locTrg)
858 /// Transfert data from MUON track to ESDMuon track
859 /// Incorporate the ESDPads if the digits are provided
860 /// Add trigger info if the MUON track is matched with a trigger track
862 // empty MUON track -> produce a ghost ESDMuon track if trigger info are available otherwise produce an empty track
863 if (track.GetNClusters() == 0) {
864 if (locTrg) MUONToESD(*locTrg, esdTrack, track.GetUniqueID());
866 cout<<"W-AliMUONESDInterface::MUONToESD: will produce an empty ESDMuon track"<<endl;
868 esdTrack.SetUniqueID(0xFFFFFFFF);
876 esdTrack.SetUniqueID(track.GetUniqueID());
877 esdTrack.SetChi2(track.GetGlobalChi2());
878 esdTrack.SetNHit(track.GetNClusters());
879 esdTrack.SetLabel(track.GetMCLabel());
881 // set param at first cluster
882 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track.GetTrackParamAtCluster())->First());
883 SetParamAtFirstCluster(*trackParam, esdTrack);
884 SetParamCov(*trackParam, esdTrack);
886 // set transverse position at the end of the absorber
887 AliMUONTrackParam trackParamAtAbsEnd(*trackParam);
888 AliMUONTrackExtrap::ExtrapToZ(&trackParamAtAbsEnd, AliMUONConstants::AbsZEnd());
889 Double_t xAbs = trackParamAtAbsEnd.GetNonBendingCoor();
890 Double_t yAbs = trackParamAtAbsEnd.GetBendingCoor();
891 esdTrack.SetRAtAbsorberEnd(TMath::Sqrt(xAbs*xAbs + yAbs*yAbs));
893 // set param at vertex
894 AliMUONTrackParam trackParamAtVtx(*trackParam);
895 AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0], vertex[1], vertex[2], 0., 0.);
896 SetParamAtVertex(trackParamAtVtx, esdTrack);
898 // set param at Distance of Closest Approach
899 AliMUONTrackParam trackParamAtDCA(*trackParam);
900 AliMUONTrackExtrap::ExtrapToVertexWithoutBranson(&trackParamAtDCA, vertex[2]);
901 SetParamAtDCA(trackParamAtDCA, esdTrack);
903 // set muon cluster info
904 AliESDMuonCluster esdCluster;
905 esdTrack.SetMuonClusterMap(0);
907 MUONToESD(*(trackParam->GetClusterPtr()), esdCluster, digits);
908 esdTrack.AddCluster(esdCluster);
909 esdTrack.AddInMuonClusterMap(esdCluster.GetChamberId());
910 trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
913 // set connected flag
914 esdTrack.Connected(track.IsConnected());
917 esdTrack.SetLocalTrigger(track.GetLocalTrigger());
918 esdTrack.SetChi2MatchTrigger(track.GetChi2MatchTrigger());
919 esdTrack.SetHitsPatternInTrigCh(track.GetHitsPatternInTrigCh());
921 esdTrack.SetTriggerX1Pattern(locTrg->GetX1Pattern());
922 esdTrack.SetTriggerY1Pattern(locTrg->GetY1Pattern());
923 esdTrack.SetTriggerX2Pattern(locTrg->GetX2Pattern());
924 esdTrack.SetTriggerY2Pattern(locTrg->GetY2Pattern());
925 esdTrack.SetTriggerX3Pattern(locTrg->GetX3Pattern());
926 esdTrack.SetTriggerY3Pattern(locTrg->GetY3Pattern());
927 esdTrack.SetTriggerX4Pattern(locTrg->GetX4Pattern());
928 esdTrack.SetTriggerY4Pattern(locTrg->GetY4Pattern());
930 esdTrack.SetTriggerX1Pattern(0);
931 esdTrack.SetTriggerY1Pattern(0);
932 esdTrack.SetTriggerX2Pattern(0);
933 esdTrack.SetTriggerY2Pattern(0);
934 esdTrack.SetTriggerX3Pattern(0);
935 esdTrack.SetTriggerY3Pattern(0);
936 esdTrack.SetTriggerX4Pattern(0);
937 esdTrack.SetTriggerY4Pattern(0);
942 //_____________________________________________________________________________
943 void AliMUONESDInterface::MUONToESD(const AliMUONLocalTrigger& locTrg, AliESDMuonTrack& esdTrack,
944 UInt_t trackId, const AliMUONTriggerTrack* triggerTrack)
946 /// Build ghost ESDMuon track containing only informations about trigger track
949 esdTrack.SetUniqueID(trackId);
952 AliMUONTrack muonTrack;
953 muonTrack.SetLocalTrigger(locTrg.LoCircuit(),
956 locTrg.GetDeviation(),
959 locTrg.GetTriggerWithoutChamber());
960 esdTrack.SetLocalTrigger(muonTrack.GetLocalTrigger());
961 esdTrack.SetChi2MatchTrigger(0.);
962 esdTrack.SetTriggerX1Pattern(locTrg.GetX1Pattern());
963 esdTrack.SetTriggerY1Pattern(locTrg.GetY1Pattern());
964 esdTrack.SetTriggerX2Pattern(locTrg.GetX2Pattern());
965 esdTrack.SetTriggerY2Pattern(locTrg.GetY2Pattern());
966 esdTrack.SetTriggerX3Pattern(locTrg.GetX3Pattern());
967 esdTrack.SetTriggerY3Pattern(locTrg.GetY3Pattern());
968 esdTrack.SetTriggerX4Pattern(locTrg.GetX4Pattern());
969 esdTrack.SetTriggerY4Pattern(locTrg.GetY4Pattern());
970 UShort_t hitPattern = 0;
972 hitPattern = triggerTrack->GetHitsPatternInTrigCh();
973 esdTrack.SetHitsPatternInTrigCh(hitPattern);
974 esdTrack.SetThetaXUncorrected(triggerTrack->GetThetax());
975 esdTrack.SetThetaYUncorrected(triggerTrack->GetThetay());
976 esdTrack.SetNonBendingCoorUncorrected(triggerTrack->GetX11());
977 esdTrack.SetBendingCoorUncorrected(triggerTrack->GetY11());
978 esdTrack.SetZUncorrected(triggerTrack->GetZ11());
982 //_____________________________________________________________________________
983 void AliMUONESDInterface::MUONToESD(const AliMUONVCluster& cluster, AliESDMuonCluster& esdCluster, const AliMUONVDigitStore* digits)
985 /// Transfert data from MUON cluster to ESDMuon cluster
986 /// Incorporate the ESDPads if the digits are provided
988 esdCluster.Clear("C");
990 esdCluster.SetUniqueID(cluster.GetUniqueID());
991 esdCluster.SetXYZ(cluster.GetX(), cluster.GetY(), cluster.GetZ());
992 esdCluster.SetErrXY(cluster.GetErrX(), cluster.GetErrY());
993 esdCluster.SetCharge(cluster.GetCharge());
994 esdCluster.SetChi2(cluster.GetChi2());
995 esdCluster.SetLabel(cluster.GetMCLabel());
997 if (digits) { // transfert all data if required
999 AliESDMuonPad esdPad;
1000 for (Int_t i=0; i<cluster.GetNDigits(); i++) {
1001 AliMUONVDigit* digit = digits->FindObject(cluster.GetDigitId(i));
1003 cout<<"E-AliMUONESDInterface::MUONToESD: digit "<<cluster.GetDigitId(i)<<" not found"<<endl;
1006 MUONToESD(*digit, esdPad);
1007 esdCluster.AddPad(esdPad);
1014 //_____________________________________________________________________________
1015 void AliMUONESDInterface::MUONToESD(const AliMUONVDigit& digit, AliESDMuonPad& esdPad)
1017 /// Transfert data from MUON digit to ESDMuon pad
1018 esdPad.SetUniqueID(digit.GetUniqueID());
1019 esdPad.SetADC(digit.ADC());
1020 esdPad.SetCharge(digit.Charge());
1021 esdPad.SetCalibrated(digit.IsCalibrated());
1022 esdPad.SetSaturated(digit.IsSaturated());
1025 //___________________________________________________________________________
1026 AliMUONTrack* AliMUONESDInterface::Add(const AliESDMuonTrack& esdTrack, AliMUONVTrackStore& trackStore, Bool_t refit)
1028 /// Create MUON track from ESDMuon track and add it to the store
1029 /// Track parameters at each clusters are recomputed or not depending on the flag "refit"
1030 /// return a pointer to the track into the store (0x0 if the track already exist)
1031 if(trackStore.FindObject(esdTrack.GetUniqueID())) return 0x0;
1032 AliMUONTrack* track = trackStore.Add(AliMUONTrack());
1033 ESDToMUON(esdTrack, *track, refit);
1037 //___________________________________________________________________________
1038 void AliMUONESDInterface::Add(const AliESDMuonTrack& esdTrack, AliMUONVTriggerStore& triggerStore)
1040 /// Create MUON local trigger from ESDMuon track and add it to the store if not already there
1041 if (!triggerStore.FindLocal(esdTrack.LoCircuit())->IsNull()) return;
1042 AliMUONLocalTrigger locTrg;
1043 ESDToMUON(esdTrack, locTrg);
1044 triggerStore.Add(locTrg);
1047 //___________________________________________________________________________
1048 AliMUONVCluster* AliMUONESDInterface::Add(const AliESDMuonCluster& esdCluster, AliMUONVClusterStore& clusterStore)
1050 /// Create MUON cluster from ESDMuon cluster and add it to the store
1051 /// return a pointer to the cluster into the store (0x0 if the cluster already exist)
1052 AliMUONVCluster* cluster = clusterStore.Add(esdCluster.GetChamberId(), esdCluster.GetDetElemId(), esdCluster.GetClusterIndex());
1053 if (cluster) ESDToMUON(esdCluster, *cluster);
1057 //___________________________________________________________________________
1058 AliMUONVDigit* AliMUONESDInterface::Add(const AliESDMuonPad& esdPad, AliMUONVDigitStore& digitStore)
1060 /// Create MUON digit from ESDMuon digit and add it to the store
1061 /// return a pointer to the digit into the store (0x0 if the digit already exist)
1062 AliMUONVDigit* digit = digitStore.Add(esdPad.GetDetElemId(), esdPad.GetManuId(), esdPad.GetManuChannel(), esdPad.GetCathode(), AliMUONVDigitStore::kDeny);
1063 if (digit) ESDToMUON(esdPad, *digit);