Updeted files for Doxygen:
[u/mrichter/AliRoot.git] / MUON / AliMUONESDInterface.cxx
CommitLineData
103e6575 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
16// $Id$
17
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"
b1fea02e 25#include "AliMUONLocalTrigger.h"
26#include "AliMUONVTriggerStore.h"
103e6575 27#include "AliMUON2DMapIterator.h"
28#include "AliMUONTrackParam.h"
29#include "AliMUONTrackExtrap.h"
30#include "AliMUONConstants.h"
b1fea02e 31#include "AliMUONTracker.h"
32#include "AliMUONRecoParam.h"
33#include "AliMUONVTrackReconstructor.h"
103e6575 34
630711ed 35#include "AliMpExMapIterator.h"
103e6575 36#include "AliMpVSegmentation.h"
37#include "AliMpSegmentation.h"
38#include "AliMpIntPair.h"
39#include "AliMpPad.h"
40
41#include "AliESDEvent.h"
42#include "AliESDMuonTrack.h"
43#include "AliESDMuonCluster.h"
44#include "AliESDMuonPad.h"
45#include "AliLog.h"
46
47#include <TClass.h>
48#include <TIterator.h>
49#include <TMath.h>
50#include <TMatrixD.h>
51#include <Riostream.h>
52
53//-----------------------------------------------------------------------------
54/// \class AliMUONESDInterface
55///
56/// There are 2 way of using thid converter between MUON track/cluster/digit
57/// and ESDMuon track/cluster/pad:
58///
59/// 1) using the static methods converting the objects one by one
60///
b1fea02e 61/// 2) loading a whole ESDEvent and using the finders and/or the iterators
103e6575 62/// to access the corresponding MUON objects
63///
ad3c6eda 64/// note: You can set the recoParam used to refit the MUON track with ResetTracker(...);
65/// By default we use Kalman filter + Smoother
66///
103e6575 67/// \author Philippe Pillot
68//-----------------------------------------------------------------------------
69
70/// \cond CLASSIMP
71ClassImp(AliMUONESDInterface)
72/// \endcond
73
ad3c6eda 74AliMUONRecoParam* AliMUONESDInterface::fgRecoParam = 0x0;
b1fea02e 75AliMUONVTrackReconstructor* AliMUONESDInterface::fgTracker = 0x0;
76
103e6575 77TString AliMUONESDInterface::fgTrackStoreName = "AliMUONTrackStoreV1";
78TString AliMUONESDInterface::fgClusterStoreName = "AliMUONClusterStoreV2";
79TString AliMUONESDInterface::fgDigitStoreName = "AliMUONDigitStoreV2R";
b1fea02e 80TString AliMUONESDInterface::fgTriggerStoreName = "AliMUONTriggerStoreV1";
103e6575 81
82//_____________________________________________________________________________
ad3c6eda 83AliMUONESDInterface::AliMUONESDInterface()
103e6575 84: TObject(),
a0dc65b4 85fTracks(0x0),
86fDigits(0x0),
87fTriggers(0x0),
88fClusterMap(0x0),
89fDigitMap(0x0)
103e6575 90{
91 /// Default constructor
92}
93
94//_____________________________________________________________________________
95AliMUONESDInterface::~AliMUONESDInterface()
96{
97 /// Destructor
98 delete fTracks;
99 delete fDigits;
b1fea02e 100 delete fTriggers;
103e6575 101 delete fClusterMap;
102 delete fDigitMap;
103}
104
105//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
106// methods to play with internal objects //
107//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
108
109//_____________________________________________________________________________
110void AliMUONESDInterface::Clear(Option_t*)
111{
112 /// clear memory
113 delete fTracks; fTracks = 0x0;
114 delete fDigits; fDigits = 0x0;
b1fea02e 115 delete fTriggers; fTriggers = 0x0;
103e6575 116 delete fClusterMap; fClusterMap = 0x0;
117 delete fDigitMap; fDigitMap = 0x0;
118}
119
120//_____________________________________________________________________________
121void AliMUONESDInterface::Reset()
122{
123 /// reset stores and maps
124
125 if (fTracks) fTracks->Clear("C");
126 else fTracks = NewTrackStore();
127
128 if (fDigits) fDigits->Clear("C");
129 else fDigits = NewDigitStore();
130
b1fea02e 131 if (fTriggers) fTriggers->Clear("C");
132 else fTriggers = NewTriggerStore();
133
103e6575 134 if (fClusterMap) fClusterMap->Clear();
630711ed 135 else fClusterMap = new AliMpExMap;
103e6575 136 fClusterMap->SetOwner(kTRUE);
137
630711ed 138 if (fDigitMap) fDigitMap->Clear();
139 else fDigitMap = new AliMpExMap;
140 fDigitMap->SetOwner(kTRUE);
103e6575 141}
142
143//_____________________________________________________________________________
144void AliMUONESDInterface::LoadEvent(AliESDEvent& esdEvent)
145{
146 /// Extract MUON data from the given ESD event
147
148 // reset data members
149 Reset();
150
151 // loop over ESD tracks and fill the stores
152 Int_t nTracks = (Int_t) esdEvent.GetNumberOfMuonTracks();
153 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
154
155 // get ESD track
156 AliESDMuonTrack* esdTrack = esdEvent.GetMuonTrack(iTrack);
157
b1fea02e 158 // fill trigger store if related info are availables
159 if (esdTrack->ContainTriggerData()) Add(*esdTrack, *fTriggers);
160
161 // fill tracker data if availables
162 if (!esdTrack->ContainTrackerData()) continue;
163
103e6575 164 // add it to track store
ad3c6eda 165 AliMUONTrack* track = Add(*esdTrack, *fTracks);
103e6575 166
103e6575 167 // prepare cluster map
630711ed 168 AliMpExMap* cMap = new AliMpExMap;
103e6575 169 cMap->SetOwner(kFALSE);
630711ed 170 fClusterMap->Add(esdTrack->GetUniqueID(), cMap);
103e6575 171
172 // prepare digit maps
630711ed 173 AliMpExMap* dMaps = new AliMpExMap;
103e6575 174 dMaps->SetOwner(kTRUE);
630711ed 175 fDigitMap->Add(esdTrack->GetUniqueID(), dMaps);
103e6575 176
177 // loop over ESD clusters
178 Int_t nClusters = esdTrack->GetNClusters();
179 for (Int_t iCluster = 0; iCluster < nClusters; iCluster++) {
180
181 // get ESD cluster
182 AliESDMuonCluster *esdCluster = (AliESDMuonCluster*) esdTrack->GetClusters().UncheckedAt(iCluster);
183
184 // get the corresponding MUON cluster
185 AliMUONVCluster* cluster = FindClusterInTrack(*track, esdCluster->GetUniqueID());
186
187 // fill cluster map
188 cMap->Add(cluster->GetUniqueID(), cluster);
189
190 // prepare digit map
630711ed 191 AliMpExMap* dMap =new AliMpExMap;
103e6575 192 dMap->SetOwner(kFALSE);
630711ed 193 dMaps->Add(esdCluster->GetUniqueID(), dMap);
103e6575 194
195 // loop over ESD pads
196 Int_t nPads = esdCluster->GetNPads();
b1fea02e 197 for (Int_t iPad = 0; iPad < nPads; iPad++) {
103e6575 198
199 // get ESD pad
200 AliESDMuonPad *esdPad = (AliESDMuonPad*) esdCluster->GetPads().UncheckedAt(iPad);
201
202 // add it to digit store
203 AliMUONVDigit* digit = Add(*esdPad, *fDigits);
204
205 // fill digit map
206 if (digit) dMap->Add(esdPad->GetUniqueID(), digit);
207 else dMap->Add(esdPad->GetUniqueID(), fDigits->FindObject(esdPad->GetUniqueID()));
208
209 } // end of loop over pads
210
211 } // end of loop over clusters
212
213 } // end of loop over tracks
214
215}
216
217//___________________________________________________________________________
218Int_t AliMUONESDInterface::GetNTracks() const
219{
220 /// return the number of tracks
630711ed 221 return fTracks ? fTracks->GetSize() : 0;
103e6575 222}
223
224//___________________________________________________________________________
225Int_t AliMUONESDInterface::GetNClusters() const
226{
227 /// return the number of clusters
228 Int_t nClusters = 0;
630711ed 229 AliMUONTrack *track;
230 TIter next(CreateTrackIterator());
231 while ((track = static_cast<AliMUONTrack*>(next()))) nClusters += track->GetNClusters();
103e6575 232 return nClusters;
233}
234
235//___________________________________________________________________________
630711ed 236Int_t AliMUONESDInterface::GetNClusters(UInt_t trackId) const
103e6575 237{
630711ed 238 /// return the number of clusters in track "trackId"
239 AliMUONTrack* track = FindTrack(trackId);
103e6575 240 return track ? track->GetNClusters() : 0;
241}
242
243//___________________________________________________________________________
244Int_t AliMUONESDInterface::GetNDigits() const
245{
246 /// return the number of digits
247 return fDigits ? fDigits->GetSize() : 0;
248}
249
250//___________________________________________________________________________
630711ed 251Int_t AliMUONESDInterface::GetNDigits(UInt_t trackId) const
103e6575 252{
630711ed 253 /// return the number of digits in all clusters of track "trackId"
103e6575 254 Int_t nDigits = 0;
630711ed 255 AliMUONVCluster *cluster;
256 TIter next(CreateClusterIterator(trackId));
257 while ((cluster = static_cast<AliMUONVCluster*>(next()))) nDigits += cluster->GetNDigits();
103e6575 258 return nDigits;
259}
260
261//___________________________________________________________________________
630711ed 262Int_t AliMUONESDInterface::GetNDigits(UInt_t trackId, UInt_t clusterId) const
103e6575 263{
264 /// return the number of digits in cluster numbered "iCluster" of track "iTrack"
630711ed 265 AliMUONVCluster* cluster = FindCluster(trackId, clusterId);
103e6575 266 return cluster ? cluster->GetNDigits() : 0;
267}
268
269//___________________________________________________________________________
270Int_t AliMUONESDInterface::GetNDigitsInCluster(UInt_t clusterId) const
271{
272 /// return the number of digits in cluster "clusterId"
273 AliMUONVCluster* cluster = FindCluster(clusterId);
274 return cluster ? cluster->GetNDigits() : 0;
275}
276
277//___________________________________________________________________________
b1fea02e 278Int_t AliMUONESDInterface::GetNTriggers() const
279{
280 /// return the number of triggers
281 return fTriggers ? fTriggers->GetSize() : 0;
282}
283
284//___________________________________________________________________________
630711ed 285AliMUONTrack* AliMUONESDInterface::FindTrack(UInt_t trackId) const
103e6575 286{
630711ed 287 /// return track "trackId" (0x0 if not found)
288 AliMUONTrack *track = fTracks ? static_cast<AliMUONTrack*>(fTracks->FindObject(trackId)) : 0x0;
289 if (!track) AliWarning(Form("track %d does not exist",trackId));
103e6575 290 return track;
291}
292
293//___________________________________________________________________________
103e6575 294AliMUONVCluster* AliMUONESDInterface::FindCluster(UInt_t clusterId) const
295{
630711ed 296 /// loop over tracks and return the first cluster "clusterId" found (0x0 if not found)
297 AliMpExMap *cMap;
103e6575 298 AliMUONVCluster* cluster = 0x0;
299
630711ed 300 if (fClusterMap) {
103e6575 301
630711ed 302 TIter next(fClusterMap->CreateIterator());
303 while ((cMap = static_cast<AliMpExMap*>(next()))) {
304
305 cluster = static_cast<AliMUONVCluster*>(cMap->GetValue(clusterId));
306 if (cluster) return cluster;
307
308 }
103e6575 309
310 }
311
312 if (!cluster) AliWarning(Form("cluster %d does not exist",clusterId));
630711ed 313 return 0x0;
314}
315
316//___________________________________________________________________________
317AliMUONVCluster* AliMUONESDInterface::FindCluster(UInt_t trackId, UInt_t clusterId) const
318{
319 /// return cluster "clusterId" in track "trackId" (0x0 if not found)
320 AliMpExMap *cMap = fClusterMap ? static_cast<AliMpExMap*>(fClusterMap->GetValue(trackId)) : 0x0;
321 AliMUONVCluster* cluster = cMap ? static_cast<AliMUONVCluster*>(cMap->GetValue(clusterId)) : 0x0;
322 if (!cluster) AliWarning(Form("cluster %d does not exist in track %d", clusterId, trackId));
103e6575 323 return cluster;
324}
325
326//___________________________________________________________________________
327AliMUONVDigit* AliMUONESDInterface::FindDigit(UInt_t digitId) const
328{
329 /// return digit "digitId" (0x0 if not found)
330 AliMUONVDigit *digit = fDigits ? fDigits->FindObject(digitId) : 0x0;
331 if (!digit) AliWarning(Form("digit %d does not exist",digitId));
332 return digit;
333}
334
335//___________________________________________________________________________
b1fea02e 336AliMUONLocalTrigger* AliMUONESDInterface::FindLocalTrigger(Int_t boardNumber) const
337{
338 /// return MUON local trigger "boardNumber"
339 return (fTriggers) ? fTriggers->FindLocal(boardNumber) : 0x0;
340}
341
342//___________________________________________________________________________
103e6575 343TIterator* AliMUONESDInterface::CreateTrackIterator() const
344{
345 /// return iterator over all tracks
346 return fTracks ? fTracks->CreateIterator() : 0x0;
347}
348
349//___________________________________________________________________________
350TIterator* AliMUONESDInterface::CreateClusterIterator() const
351{
352 /// return iterator over all clusters
353 return fClusterMap ? new AliMUON2DMapIterator(*fClusterMap) : 0x0;
354}
355
356//___________________________________________________________________________
630711ed 357TIterator* AliMUONESDInterface::CreateClusterIterator(UInt_t trackId) const
103e6575 358{
630711ed 359 /// return iterator over clusters of track "trackId"
360 AliMpExMap *cMap = fClusterMap ? static_cast<AliMpExMap*>(fClusterMap->GetValue(trackId)) : 0x0;
361 return cMap ? cMap->CreateIterator() : 0x0;
103e6575 362}
363
364//___________________________________________________________________________
365TIterator* AliMUONESDInterface::CreateDigitIterator() const
366{
367 /// return iterator over all digits
368 return fDigits ? fDigits->CreateIterator() : 0x0;
369}
370
371//___________________________________________________________________________
630711ed 372TIterator* AliMUONESDInterface::CreateDigitIterator(UInt_t trackId) const
103e6575 373{
630711ed 374 /// return iterator over all digits of track "trackId"
375 AliMpExMap* dMaps = fDigitMap ? static_cast<AliMpExMap*>(fDigitMap->GetValue(trackId)) : 0x0;
103e6575 376 return dMaps ? new AliMUON2DMapIterator(*dMaps) : 0x0;
377}
378
379//___________________________________________________________________________
630711ed 380TIterator* AliMUONESDInterface::CreateDigitIterator(UInt_t trackId, UInt_t clusterId) const
103e6575 381{
630711ed 382 /// return iterator over digits of cluster "clusterId" in track "trackId"
383 AliMpExMap* dMaps = fDigitMap ? static_cast<AliMpExMap*>(fDigitMap->GetValue(trackId)) : 0x0;
384 AliMpExMap* dMap = dMaps ? static_cast<AliMpExMap*>(dMaps->GetValue(clusterId)) : 0x0;
385 return dMap ? dMap->CreateIterator() : 0x0;
103e6575 386}
387
388//___________________________________________________________________________
389TIterator* AliMUONESDInterface::CreateDigitIteratorInCluster(UInt_t clusterId) const
390{
630711ed 391 /// return iterator over digits of the first cluster "clusterId" found by looping over all tracks
392 AliMpExMap *dMaps;
103e6575 393 AliMpExMap* dMap = 0x0;
394
630711ed 395 if (fDigitMap) {
103e6575 396
630711ed 397 TIter next(fDigitMap->CreateIterator());
398 while ((dMaps = static_cast<AliMpExMap*>(next()))) {
399
400 dMap = static_cast<AliMpExMap*>(dMaps->GetValue(clusterId));
401 if (dMap) return dMap->CreateIterator();
402
403 }
103e6575 404
405 }
406
630711ed 407 return 0x0;
103e6575 408}
409
410//___________________________________________________________________________
b1fea02e 411TIterator* AliMUONESDInterface::CreateLocalTriggerIterator() const
412{
413 /// return iterator over all local trigger
414 return fTriggers ? fTriggers->CreateLocalIterator() : 0x0;
415}
416
417//___________________________________________________________________________
103e6575 418AliMUONVCluster* AliMUONESDInterface::FindClusterInTrack(const AliMUONTrack& track, UInt_t clusterId) const
419{
420 /// find the cluster with the given Id into the track
421
422 Int_t nClusters = track.GetNClusters();
423 for (Int_t iCluster = 0; iCluster < nClusters; iCluster++) {
424
425 AliMUONVCluster* cluster = ((AliMUONTrackParam*) track.GetTrackParamAtCluster()->UncheckedAt(iCluster))->GetClusterPtr();
426 if (cluster->GetUniqueID() == clusterId) return cluster;
427
428 }
429
430 return 0x0;
431}
432
433//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
434// static methods //
435//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
436
437//_____________________________________________________________________________
ad3c6eda 438void AliMUONESDInterface::ResetTracker(const AliMUONRecoParam* recoParam)
439{
440 /// Reset the MUON tracker using "recoParam" if provided.
441 /// If not provided, will use Kalman filter + Smoother
442
443 delete fgTracker;
444 delete fgRecoParam;
445
446 if (recoParam) {
447
448 fgRecoParam = new AliMUONRecoParam(*recoParam);
449
450 }else {
451
452 fgRecoParam = AliMUONRecoParam::GetLowFluxParam();
453 fgRecoParam->SetTrackingMode("KALMAN");
454 fgRecoParam->UseSmoother(kTRUE);
455 fgRecoParam->SetBendingVertexDispersion(10.);
456
457 }
458
459 fgTracker = AliMUONTracker::CreateTrackReconstructor(fgRecoParam,0x0);
460
461}
462
463//_____________________________________________________________________________
103e6575 464AliMUONVTrackStore* AliMUONESDInterface::NewTrackStore()
465{
466 /// Create an empty track store of type fgTrackStoreName
467 TClass* classPtr = TClass::GetClass(fgTrackStoreName);
468 if (!classPtr || !classPtr->InheritsFrom("AliMUONVTrackStore")) {
469 cout<<"E-AliMUONESDInterface::NewTrackStore: Unable to create store of type "<<fgTrackStoreName.Data()<<endl;
470 return 0x0;
471 }
472 return reinterpret_cast<AliMUONVTrackStore*>(classPtr->New());
473}
474
475//_____________________________________________________________________________
476AliMUONVClusterStore* AliMUONESDInterface::NewClusterStore()
477{
478 /// Create an empty cluster store of type fgClusterStoreName
479 TClass* classPtr = TClass::GetClass(fgClusterStoreName);
480 if (!classPtr || !classPtr->InheritsFrom("AliMUONVClusterStore")) {
481 cout<<"E-AliMUONESDInterface::NewClusterStore: Unable to create store of type "<<fgClusterStoreName.Data()<<endl;
482 return 0x0;
483 }
484 return reinterpret_cast<AliMUONVClusterStore*>(classPtr->New());
485}
486
487//_____________________________________________________________________________
488AliMUONVDigitStore* AliMUONESDInterface::NewDigitStore()
489{
490 /// Create an empty digit store of type fgDigitStoreName
491 TClass* classPtr = TClass::GetClass(fgDigitStoreName);
492 if (!classPtr || !classPtr->InheritsFrom("AliMUONVDigitStore")) {
493 cout<<"E-AliMUONESDInterface::NewDigitStore: Unable to create store of type "<<fgDigitStoreName.Data()<<endl;
494 return 0x0;
495 }
496 return reinterpret_cast<AliMUONVDigitStore*>(classPtr->New());
497}
498
b1fea02e 499//_____________________________________________________________________________
500AliMUONVTriggerStore* AliMUONESDInterface::NewTriggerStore()
501{
502 /// Create an empty trigger store of type fgTriggerStoreName
503 TClass* classPtr = TClass::GetClass(fgTriggerStoreName);
504 if (!classPtr || !classPtr->InheritsFrom("AliMUONVTriggerStore")) {
505 cout<<"E-AliMUONESDInterface::NewTriggerStore: Unable to create store of type "<<fgTriggerStoreName.Data()<<endl;
506 return 0x0;
507 }
508 return reinterpret_cast<AliMUONVTriggerStore*>(classPtr->New());
509}
510
103e6575 511//_________________________________________________________________________
512void AliMUONESDInterface::GetParamAtVertex(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
513{
514 /// Get parameters at vertex from ESDMuon track
515 trackParam.SetZ(esdTrack.GetZ());
516 trackParam.SetNonBendingCoor(esdTrack.GetNonBendingCoor());
517 trackParam.SetNonBendingSlope(TMath::Tan(esdTrack.GetThetaX()));
518 trackParam.SetBendingCoor(esdTrack.GetBendingCoor());
519 trackParam.SetBendingSlope(TMath::Tan(esdTrack.GetThetaY()));
520 trackParam.SetInverseBendingMomentum(esdTrack.GetInverseBendingMomentum());
521}
522
523//_________________________________________________________________________
524void AliMUONESDInterface::GetParamAtDCA(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
525{
526 /// Get parameters at DCA from ESDMuon track
527 trackParam.SetZ(esdTrack.GetZ());
528 trackParam.SetNonBendingCoor(esdTrack.GetNonBendingCoorAtDCA());
529 trackParam.SetNonBendingSlope(TMath::Tan(esdTrack.GetThetaXAtDCA()));
530 trackParam.SetBendingCoor(esdTrack.GetBendingCoorAtDCA());
531 trackParam.SetBendingSlope(TMath::Tan(esdTrack.GetThetaYAtDCA()));
532 trackParam.SetInverseBendingMomentum(esdTrack.GetInverseBendingMomentumAtDCA());
533}
534
535//_________________________________________________________________________
536void AliMUONESDInterface::GetParamAtFirstCluster(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
537{
538 /// Get parameters at first cluster from ESDMuon track
539 trackParam.SetZ(esdTrack.GetZUncorrected());
540 trackParam.SetNonBendingCoor(esdTrack.GetNonBendingCoorUncorrected());
541 trackParam.SetNonBendingSlope(TMath::Tan(esdTrack.GetThetaXUncorrected()));
542 trackParam.SetBendingCoor(esdTrack.GetBendingCoorUncorrected());
543 trackParam.SetBendingSlope(TMath::Tan(esdTrack.GetThetaYUncorrected()));
544 trackParam.SetInverseBendingMomentum(esdTrack.GetInverseBendingMomentumUncorrected());
545}
546
547//_________________________________________________________________________
548void AliMUONESDInterface::GetParamCov(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
549{
550 /// Get parameters covariances from ESD track
551
552 // get ESD covariance matrix
553 TMatrixD covariances(5,5);
554 esdTrack.GetCovariances(covariances);
555
556 // compute Jacobian to change the coordinate system
557 // from (X,thetaX,Y,thetaY,c/pYZ) to (X,slopeX,Y,slopeY,c/pYZ)
558 Double_t cosThetaX = TMath::Cos(esdTrack.GetThetaXUncorrected());
559 Double_t cosThetaY = TMath::Cos(esdTrack.GetThetaYUncorrected());
560 TMatrixD jacob(5,5);
561 jacob.Zero();
562 jacob(0,0) = 1.;
563 jacob(1,1) = 1. / cosThetaX / cosThetaX;
564 jacob(2,2) = 1.;
565 jacob(3,3) = 1. / cosThetaY / cosThetaY;
566 jacob(4,4) = 1.;
567
568 // compute covariance matrix in ESD coordinate system
569 TMatrixD tmp(covariances,TMatrixD::kMultTranspose,jacob);
570 trackParam.SetCovariances(TMatrixD(jacob,TMatrixD::kMult,tmp));
571
572}
573
574//_________________________________________________________________________
575void AliMUONESDInterface::SetParamAtVertex(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
576{
577 /// Set parameters in ESD track
578 esdTrack.SetZ(trackParam.GetZ());
579 esdTrack.SetNonBendingCoor(trackParam.GetNonBendingCoor());
580 esdTrack.SetThetaX(TMath::ATan(trackParam.GetNonBendingSlope()));
581 esdTrack.SetBendingCoor(trackParam.GetBendingCoor());
582 esdTrack.SetThetaY(TMath::ATan(trackParam.GetBendingSlope()));
583 esdTrack.SetInverseBendingMomentum(trackParam.GetInverseBendingMomentum());
584}
585
586//_________________________________________________________________________
587void AliMUONESDInterface::SetParamAtDCA(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
588{
589 /// Set parameters in ESD track
590 esdTrack.SetNonBendingCoorAtDCA(trackParam.GetNonBendingCoor());
591 esdTrack.SetThetaXAtDCA(TMath::ATan(trackParam.GetNonBendingSlope()));
592 esdTrack.SetBendingCoorAtDCA(trackParam.GetBendingCoor());
593 esdTrack.SetThetaYAtDCA(TMath::ATan(trackParam.GetBendingSlope()));
594 esdTrack.SetInverseBendingMomentumAtDCA(trackParam.GetInverseBendingMomentum());
595}
596
597//_________________________________________________________________________
598void AliMUONESDInterface::SetParamAtFirstCluster(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
599{
600 /// Set parameters in ESD track
601 esdTrack.SetZUncorrected(trackParam.GetZ());
602 esdTrack.SetNonBendingCoorUncorrected(trackParam.GetNonBendingCoor());
603 esdTrack.SetThetaXUncorrected(TMath::ATan(trackParam.GetNonBendingSlope()));
604 esdTrack.SetBendingCoorUncorrected(trackParam.GetBendingCoor());
605 esdTrack.SetThetaYUncorrected(TMath::ATan(trackParam.GetBendingSlope()));
606 esdTrack.SetInverseBendingMomentumUncorrected(trackParam.GetInverseBendingMomentum());
607}
608
609//_________________________________________________________________________
610void AliMUONESDInterface::SetParamCov(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
611{
612 /// Set parameters covariances in ESD track
613
614 // set null matrix if covariances does not exist
615 if (!trackParam.CovariancesExist()) {
616 TMatrixD tmp(5,5);
617 tmp.Zero();
618 esdTrack.SetCovariances(tmp);
619 return;
620 }
621
622 // compute Jacobian to change the coordinate system
623 // from (X,slopeX,Y,slopeY,c/pYZ) to (X,thetaX,Y,thetaY,c/pYZ)
624 Double_t cosThetaX = TMath::Cos(TMath::ATan(trackParam.GetNonBendingSlope()));
625 Double_t cosThetaY = TMath::Cos(TMath::ATan(trackParam.GetBendingSlope()));
626 TMatrixD jacob(5,5);
627 jacob.Zero();
628 jacob(0,0) = 1.;
629 jacob(1,1) = cosThetaX * cosThetaX;
630 jacob(2,2) = 1.;
631 jacob(3,3) = cosThetaY * cosThetaY;
632 jacob(4,4) = 1.;
633
634 // compute covariance matrix in ESD coordinate system
635 TMatrixD tmp(trackParam.GetCovariances(),TMatrixD::kMultTranspose,jacob);
636 esdTrack.SetCovariances(TMatrixD(jacob,TMatrixD::kMult,tmp));
637
638}
639
640//_____________________________________________________________________________
ad3c6eda 641void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONTrack& track)
103e6575 642{
c59f70b9 643 /// Transfert data from ESDMuon track to MUON track.
644 /// The track parameters at each cluster are obtained by refitting the track
645 /// or by extrapolating the parameters at the first one if the refit failed.
646 /// note: You can set the recoParam used to refit the MUON track with ResetTracker(...);
647 /// By default we use Kalman filter + Smoother
103e6575 648
b1fea02e 649 // if the ESDMuon track is a ghost then return an empty MUON track
650 if (!esdTrack.ContainTrackerData()) {
651 track.Reset();
652 track.SetUniqueID(esdTrack.GetUniqueID());
653 return;
654 }
655
103e6575 656 track.Clear("C");
657
658 // global info
659 track.SetUniqueID(esdTrack.GetUniqueID());
660 track.FitWithVertex(kFALSE);
661 track.FitWithMCS(kFALSE);
662 track.SetImproved(kFALSE);
663 track.SetVertexErrXY2(0.,0.);
664 track.SetGlobalChi2(esdTrack.GetChi2());
665 track.SetMatchTrigger(esdTrack.GetMatchTrigger());
666 track.SetLoTrgNum(-1);
667 track.SetChi2MatchTrigger(esdTrack.GetChi2MatchTrigger());
668 track.SetTrackID(0);
669 track.SetHitsPatternInTrigCh(esdTrack.GetHitsPatternInTrigCh());
670 track.SetLocalTrigger(esdTrack.LoCircuit(), esdTrack.LoStripX(), esdTrack.LoStripY(),
671 esdTrack.LoDev(), esdTrack.LoLpt(), esdTrack.LoHpt());
672
673 // track parameters at vertex
674 AliMUONTrackParam paramAtVertex;
675 GetParamAtVertex(esdTrack, paramAtVertex);
676 track.SetTrackParamAtVertex(&paramAtVertex);
677
678 // track parameters at first cluster
679 AliMUONTrackParam param;
680 GetParamAtFirstCluster(esdTrack, param);
681 GetParamCov(esdTrack, param);
682
683 // create empty cluster
684 AliMUONVClusterStore* cStore = NewClusterStore();
685 if (!cStore) return;
686 AliMUONVCluster* cluster = cStore->CreateCluster(0,0,0);
687
688 // fill TrackParamAtCluster with track parameters at each cluster if available
689 // or with only track parameters at first (fake) cluster if not
690 if(esdTrack.ClustersStored()) {
691
692 // loop over ESD clusters
693 AliESDMuonCluster *esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().First();
694 while (esdCluster) {
695
696 // copy cluster information
697 ESDToMUON(*esdCluster, *cluster);
698
699 // only set the Z parameter to avoid error in the AddTrackParamAtCluster(...) method
700 param.SetZ(cluster->GetZ());
701
702 // add common track parameters at current cluster
703 track.AddTrackParamAtCluster(param, *cluster, kTRUE);
704
705 esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().After(esdCluster);
706 }
707
708 // recompute parameters at first cluster in case of those stored
709 // in ESD are not related to the most upstream cluster
710 AliMUONTrackParam *firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
711 firstTrackParam->SetZ(esdTrack.GetZUncorrected()); // reset the z to the one stored in ESD
712 AliMUONTrackExtrap::ExtrapToZCov(firstTrackParam,firstTrackParam->GetClusterPtr()->GetZ());
713
b1fea02e 714 // refit the track to get better parameters and covariances at each cluster (temporary disable track improvement)
ad3c6eda 715 if (!fgTracker) ResetTracker();
b1fea02e 716 if (!fgTracker->RefitTrack(track, kFALSE)) track.UpdateCovTrackParamAtCluster();
103e6575 717
718 } else {
719
c59f70b9 720 // get number of the first hit chamber according to the MUONClusterMap
103e6575 721 Int_t firstCh = 0;
c59f70b9 722 while (firstCh < 10 && !esdTrack.IsInMuonClusterMap(firstCh)) firstCh++;
103e6575 723
724 // produce fake cluster at this chamber
725 cluster->SetUniqueID(AliMUONVCluster::BuildUniqueID(firstCh, 0, 0));
726 cluster->SetXYZ(param.GetNonBendingCoor(), param.GetBendingCoor(), param.GetZ());
727 cluster->SetErrXY(0., 0.);
728
729 // add track parameters at first (fake) cluster
730 track.AddTrackParamAtCluster(param, *cluster, kTRUE);
731
732 }
733
734 delete cluster;
735 delete cStore;
736
737}
738
739//_____________________________________________________________________________
b1fea02e 740void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONLocalTrigger& locTrg)
741{
742 /// Transfert trigger data from ESDMuon track to the MUONLocalTtrigger object
743
744 // if the ESDMuon track is a ghost then return an empty MUON track
745 if (!esdTrack.ContainTriggerData()) {
746 AliMUONLocalTrigger emptyLocTrg;
747 locTrg = emptyLocTrg;
748 return;
749 }
750
751 locTrg.SetLoCircuit(esdTrack.LoCircuit());
752 locTrg.SetLoStripX(esdTrack.LoStripX());
753 locTrg.SetLoStripY(esdTrack.LoStripY());
754 locTrg.SetLoDev(esdTrack.LoDev());
755 locTrg.SetLoLpt(esdTrack.LoLpt());
756 locTrg.SetLoHpt(esdTrack.LoHpt());
757 locTrg.SetLoSdev(1);
758 locTrg.SetLoTrigY(1);
759 locTrg.SetX1Pattern(esdTrack.GetTriggerX1Pattern());
760 locTrg.SetX2Pattern(esdTrack.GetTriggerX2Pattern());
761 locTrg.SetX3Pattern(esdTrack.GetTriggerX3Pattern());
762 locTrg.SetX4Pattern(esdTrack.GetTriggerX4Pattern());
763 locTrg.SetY1Pattern(esdTrack.GetTriggerY1Pattern());
764 locTrg.SetY2Pattern(esdTrack.GetTriggerY2Pattern());
765 locTrg.SetY3Pattern(esdTrack.GetTriggerY3Pattern());
766 locTrg.SetY4Pattern(esdTrack.GetTriggerY4Pattern());
767
768}
769
770//_____________________________________________________________________________
103e6575 771void AliMUONESDInterface::ESDToMUON(const AliESDMuonCluster& esdCluster, AliMUONVCluster& cluster)
772{
773 /// Transfert data from ESDMuon cluster to MUON cluster
774
775 cluster.Clear("C");
776
777 cluster.SetUniqueID(esdCluster.GetUniqueID());
778 cluster.SetXYZ(esdCluster.GetX(), esdCluster.GetY(), esdCluster.GetZ());
779 cluster.SetErrXY(esdCluster.GetErrX(),esdCluster.GetErrY());
780 cluster.SetCharge(esdCluster.GetCharge());
781 cluster.SetChi2(esdCluster.GetChi2());
782
783 if (esdCluster.PadsStored()) {
784 Int_t nPads = esdCluster.GetNPads();
785 for (Int_t iPad = 0; iPad < nPads; iPad++)
786 cluster.AddDigitId(((AliESDMuonPad*)esdCluster.GetPads().UncheckedAt(iPad))->GetUniqueID());
787 }
788
789}
790
791//___________________________________________________________________________
792void AliMUONESDInterface::ESDToMUON(const AliESDMuonPad& esdPad, AliMUONVDigit& digit)
793{
794 /// Transfert data from ESDMuon pad to MUON digit
795
796 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(esdPad.GetDetElemId(), esdPad.GetManuId());
797 AliMpPad pad = seg->PadByLocation(AliMpIntPair(esdPad.GetManuId(), esdPad.GetManuChannel()), kFALSE);
798
b1fea02e 799 digit.Saturated(esdPad.IsSaturated());
103e6575 800 digit.Used(kFALSE);
b1fea02e 801 digit.Calibrated(esdPad.IsCalibrated());
103e6575 802 digit.SetUniqueID(esdPad.GetUniqueID());
803 digit.SetCharge(esdPad.GetCharge());
804 digit.SetADC(esdPad.GetADC());
805 digit.SetPadXY(pad.GetIndices().GetFirst(), pad.GetIndices().GetSecond());
806
807}
808
809//_____________________________________________________________________________
b1fea02e 810void AliMUONESDInterface::MUONToESD(const AliMUONTrack& track, AliESDMuonTrack& esdTrack, const Double_t vertex[3],
811 const AliMUONVDigitStore* digits, const AliMUONLocalTrigger* locTrg)
103e6575 812{
813 /// Transfert data from MUON track to ESDMuon track
814 /// Incorporate the ESDPads if the digits are provided
b1fea02e 815 /// Add trigger info if the MUON track is matched with a trigger track
816
817 // empty MUON track -> produce a ghost ESDMuon track if trigger info are available otherwise produce an empty track
818 if (track.GetNClusters() == 0) {
819 if (locTrg) MUONToESD(*locTrg, esdTrack, track.GetUniqueID());
820 else {
821 cout<<"W-AliMUONESDInterface::MUONToESD: will produce an empty ESDMuon track"<<endl;
822 esdTrack.Reset();
823 esdTrack.SetUniqueID(0xFFFFFFFF);
824 }
825 return;
826 }
103e6575 827
828 esdTrack.Clear("C");
829
b1fea02e 830 // set global info
831 esdTrack.SetUniqueID(track.GetUniqueID());
832 esdTrack.SetChi2(track.GetGlobalChi2());
833 esdTrack.SetNHit(track.GetNClusters());
834
103e6575 835 // set param at first cluster
836 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track.GetTrackParamAtCluster())->First());
837 SetParamAtFirstCluster(*trackParam, esdTrack);
838 SetParamCov(*trackParam, esdTrack);
839
840 // set param at vertex
841 AliMUONTrackParam trackParamAtVtx(*trackParam);
842 AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0], vertex[1], vertex[2], 0., 0.);
843 SetParamAtVertex(trackParamAtVtx, esdTrack);
844
845 // set param at Distance of Closest Approach
846 AliMUONTrackParam trackParamAtDCA(*trackParam);
847 AliMUONTrackExtrap::ExtrapToVertexWithoutBranson(&trackParamAtDCA, vertex[2]);
848 SetParamAtDCA(trackParamAtDCA, esdTrack);
849
103e6575 850 // set muon cluster info
851 AliESDMuonCluster esdCluster;
852 esdTrack.SetMuonClusterMap(0);
853 while (trackParam) {
854 MUONToESD(*(trackParam->GetClusterPtr()), esdCluster, digits);
855 esdTrack.AddCluster(esdCluster);
856 esdTrack.AddInMuonClusterMap(esdCluster.GetChamberId());
857 trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
858 }
859
b1fea02e 860 // set trigger info
861 esdTrack.SetLocalTrigger(track.GetLocalTrigger());
862 esdTrack.SetChi2MatchTrigger(track.GetChi2MatchTrigger());
863 esdTrack.SetHitsPatternInTrigCh(track.GetHitsPatternInTrigCh());
864 if (locTrg) {
865 esdTrack.SetTriggerX1Pattern(locTrg->GetX1Pattern());
866 esdTrack.SetTriggerY1Pattern(locTrg->GetY1Pattern());
867 esdTrack.SetTriggerX2Pattern(locTrg->GetX2Pattern());
868 esdTrack.SetTriggerY2Pattern(locTrg->GetY2Pattern());
869 esdTrack.SetTriggerX3Pattern(locTrg->GetX3Pattern());
870 esdTrack.SetTriggerY3Pattern(locTrg->GetY3Pattern());
871 esdTrack.SetTriggerX4Pattern(locTrg->GetX4Pattern());
872 esdTrack.SetTriggerY4Pattern(locTrg->GetY4Pattern());
873 } else {
874 esdTrack.SetTriggerX1Pattern(0);
875 esdTrack.SetTriggerY1Pattern(0);
876 esdTrack.SetTriggerX2Pattern(0);
877 esdTrack.SetTriggerY2Pattern(0);
878 esdTrack.SetTriggerX3Pattern(0);
879 esdTrack.SetTriggerY3Pattern(0);
880 esdTrack.SetTriggerX4Pattern(0);
881 esdTrack.SetTriggerY4Pattern(0);
882 }
883
884}
885
886//_____________________________________________________________________________
887void AliMUONESDInterface::MUONToESD(const AliMUONLocalTrigger& locTrg, AliESDMuonTrack& esdTrack, UInt_t trackId)
888{
889 /// Build ghost ESDMuon track containing only informations about trigger track
890
891 esdTrack.Reset();
892 esdTrack.SetUniqueID(trackId);
893
894 // set trigger info
895 AliMUONTrack muonTrack;
896 muonTrack.SetLocalTrigger(locTrg.LoCircuit(),
897 locTrg.LoStripX(),
898 locTrg.LoStripY(),
98606cfc 899 locTrg.GetDeviation(),
b1fea02e 900 locTrg.LoLpt(),
901 locTrg.LoHpt());
902 esdTrack.SetLocalTrigger(muonTrack.GetLocalTrigger());
903 esdTrack.SetChi2MatchTrigger(0.);
904 esdTrack.SetHitsPatternInTrigCh(0);
905 esdTrack.SetTriggerX1Pattern(locTrg.GetX1Pattern());
906 esdTrack.SetTriggerY1Pattern(locTrg.GetY1Pattern());
907 esdTrack.SetTriggerX2Pattern(locTrg.GetX2Pattern());
908 esdTrack.SetTriggerY2Pattern(locTrg.GetY2Pattern());
909 esdTrack.SetTriggerX3Pattern(locTrg.GetX3Pattern());
910 esdTrack.SetTriggerY3Pattern(locTrg.GetY3Pattern());
911 esdTrack.SetTriggerX4Pattern(locTrg.GetX4Pattern());
912 esdTrack.SetTriggerY4Pattern(locTrg.GetY4Pattern());
913
103e6575 914}
915
916//_____________________________________________________________________________
917void AliMUONESDInterface::MUONToESD(const AliMUONVCluster& cluster, AliESDMuonCluster& esdCluster, const AliMUONVDigitStore* digits)
918{
919 /// Transfert data from MUON cluster to ESDMuon cluster
920 /// Incorporate the ESDPads if the digits are provided
921
922 esdCluster.Clear("C");
923
924 esdCluster.SetUniqueID(cluster.GetUniqueID());
925 esdCluster.SetXYZ(cluster.GetX(), cluster.GetY(), cluster.GetZ());
926 esdCluster.SetErrXY(cluster.GetErrX(), cluster.GetErrY());
630711ed 927 esdCluster.SetCharge(cluster.GetCharge());
928 esdCluster.SetChi2(cluster.GetChi2());
103e6575 929
630711ed 930 if (digits) { // transfert all data if required
103e6575 931
103e6575 932 AliESDMuonPad esdPad;
933 for (Int_t i=0; i<cluster.GetNDigits(); i++) {
934 AliMUONVDigit* digit = digits->FindObject(cluster.GetDigitId(i));
935 if (!digit) {
936 cout<<"E-AliMUONESDInterface::MUONToESD: digit "<<cluster.GetDigitId(i)<<" not found"<<endl;
937 continue;
938 }
939 MUONToESD(*digit, esdPad);
940 esdCluster.AddPad(esdPad);
941 }
942
103e6575 943 }
944
945}
946
947//_____________________________________________________________________________
948void AliMUONESDInterface::MUONToESD(const AliMUONVDigit& digit, AliESDMuonPad& esdPad)
949{
950 /// Transfert data from MUON digit to ESDMuon pad
951 esdPad.SetUniqueID(digit.GetUniqueID());
952 esdPad.SetADC(digit.ADC());
953 esdPad.SetCharge(digit.Charge());
b1fea02e 954 esdPad.SetCalibrated(digit.IsCalibrated());
955 esdPad.SetSaturated(digit.IsSaturated());
103e6575 956}
957
958//___________________________________________________________________________
ad3c6eda 959AliMUONTrack* AliMUONESDInterface::Add(const AliESDMuonTrack& esdTrack, AliMUONVTrackStore& trackStore)
103e6575 960{
961 /// Create MUON track from ESDMuon track and add it to the store
b1fea02e 962 /// return a pointer to the track into the store (0x0 if the track already exist)
963 if(trackStore.FindObject(esdTrack.GetUniqueID())) return 0x0;
103e6575 964 AliMUONTrack* track = trackStore.Add(AliMUONTrack());
ad3c6eda 965 ESDToMUON(esdTrack, *track);
103e6575 966 return track;
967}
968
969//___________________________________________________________________________
b1fea02e 970void AliMUONESDInterface::Add(const AliESDMuonTrack& esdTrack, AliMUONVTriggerStore& triggerStore)
971{
972 /// Create MUON local trigger from ESDMuon track and add it to the store if not already there
973 if (triggerStore.FindLocal(esdTrack.LoCircuit())) return;
974 AliMUONLocalTrigger locTrg;
975 ESDToMUON(esdTrack, locTrg);
976 triggerStore.Add(locTrg);
977}
978
979//___________________________________________________________________________
103e6575 980AliMUONVCluster* AliMUONESDInterface::Add(const AliESDMuonCluster& esdCluster, AliMUONVClusterStore& clusterStore)
981{
982 /// Create MUON cluster from ESDMuon cluster and add it to the store
983 /// return a pointer to the cluster into the store (0x0 if the cluster already exist)
984 AliMUONVCluster* cluster = clusterStore.Add(esdCluster.GetChamberId(), esdCluster.GetDetElemId(), esdCluster.GetClusterIndex());
985 if (cluster) ESDToMUON(esdCluster, *cluster);
986 return cluster;
987}
988
989//___________________________________________________________________________
990AliMUONVDigit* AliMUONESDInterface::Add(const AliESDMuonPad& esdPad, AliMUONVDigitStore& digitStore)
991{
992 /// Create MUON digit from ESDMuon digit and add it to the store
993 /// return a pointer to the digit into the store (0x0 if the digit already exist)
994 AliMUONVDigit* digit = digitStore.Add(esdPad.GetDetElemId(), esdPad.GetManuId(), esdPad.GetManuChannel(), esdPad.GetCathode(), AliMUONVDigitStore::kDeny);
995 if (digit) ESDToMUON(esdPad, *digit);
996 return digit;
997}
998