New versions of the DA executables to comply with DAQ DA file naming conventions
[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"
103e6575 25#include "AliMUON2DMapIterator.h"
26#include "AliMUONTrackParam.h"
27#include "AliMUONTrackExtrap.h"
28#include "AliMUONConstants.h"
29
630711ed 30#include "AliMpExMapIterator.h"
103e6575 31#include "AliMpVSegmentation.h"
32#include "AliMpSegmentation.h"
33#include "AliMpIntPair.h"
34#include "AliMpPad.h"
35
36#include "AliESDEvent.h"
37#include "AliESDMuonTrack.h"
38#include "AliESDMuonCluster.h"
39#include "AliESDMuonPad.h"
40#include "AliLog.h"
41
42#include <TClass.h>
43#include <TIterator.h>
44#include <TMath.h>
45#include <TMatrixD.h>
46#include <Riostream.h>
47
48//-----------------------------------------------------------------------------
49/// \class AliMUONESDInterface
50///
51/// There are 2 way of using thid converter between MUON track/cluster/digit
52/// and ESDMuon track/cluster/pad:
53///
54/// 1) using the static methods converting the objects one by one
55///
56/// 2) loading a whole ESDEvent and using the getters and/or the iterators
57/// to access the corresponding MUON objects
58///
59/// \author Philippe Pillot
60//-----------------------------------------------------------------------------
61
62/// \cond CLASSIMP
63ClassImp(AliMUONESDInterface)
64/// \endcond
65
66TString AliMUONESDInterface::fgTrackStoreName = "AliMUONTrackStoreV1";
67TString AliMUONESDInterface::fgClusterStoreName = "AliMUONClusterStoreV2";
68TString AliMUONESDInterface::fgDigitStoreName = "AliMUONDigitStoreV2R";
69
70//_____________________________________________________________________________
71AliMUONESDInterface::AliMUONESDInterface()
72: TObject(),
73 fTracks(0x0),
74 fDigits(0x0),
103e6575 75 fClusterMap(0x0),
76 fDigitMap(0x0)
77{
78 /// Default constructor
79}
80
81//_____________________________________________________________________________
82AliMUONESDInterface::~AliMUONESDInterface()
83{
84 /// Destructor
85 delete fTracks;
86 delete fDigits;
103e6575 87 delete fClusterMap;
88 delete fDigitMap;
89}
90
91//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
92// methods to play with internal objects //
93//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
94
95//_____________________________________________________________________________
96void AliMUONESDInterface::Clear(Option_t*)
97{
98 /// clear memory
99 delete fTracks; fTracks = 0x0;
100 delete fDigits; fDigits = 0x0;
103e6575 101 delete fClusterMap; fClusterMap = 0x0;
102 delete fDigitMap; fDigitMap = 0x0;
103}
104
105//_____________________________________________________________________________
106void AliMUONESDInterface::Reset()
107{
108 /// reset stores and maps
109
110 if (fTracks) fTracks->Clear("C");
111 else fTracks = NewTrackStore();
112
113 if (fDigits) fDigits->Clear("C");
114 else fDigits = NewDigitStore();
115
103e6575 116 if (fClusterMap) fClusterMap->Clear();
630711ed 117 else fClusterMap = new AliMpExMap;
103e6575 118 fClusterMap->SetOwner(kTRUE);
119
630711ed 120 if (fDigitMap) fDigitMap->Clear();
121 else fDigitMap = new AliMpExMap;
122 fDigitMap->SetOwner(kTRUE);
103e6575 123}
124
125//_____________________________________________________________________________
126void AliMUONESDInterface::LoadEvent(AliESDEvent& esdEvent)
127{
128 /// Extract MUON data from the given ESD event
129
130 // reset data members
131 Reset();
132
133 // loop over ESD tracks and fill the stores
134 Int_t nTracks = (Int_t) esdEvent.GetNumberOfMuonTracks();
135 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
136
137 // get ESD track
138 AliESDMuonTrack* esdTrack = esdEvent.GetMuonTrack(iTrack);
139
140 // add it to track store
141 AliMUONTrack* track = Add(*esdTrack, *fTracks);
142
103e6575 143 // prepare cluster map
630711ed 144 AliMpExMap* cMap = new AliMpExMap;
103e6575 145 cMap->SetOwner(kFALSE);
630711ed 146 fClusterMap->Add(esdTrack->GetUniqueID(), cMap);
103e6575 147
148 // prepare digit maps
630711ed 149 AliMpExMap* dMaps = new AliMpExMap;
103e6575 150 dMaps->SetOwner(kTRUE);
630711ed 151 fDigitMap->Add(esdTrack->GetUniqueID(), dMaps);
103e6575 152
153 // loop over ESD clusters
154 Int_t nClusters = esdTrack->GetNClusters();
155 for (Int_t iCluster = 0; iCluster < nClusters; iCluster++) {
156
157 // get ESD cluster
158 AliESDMuonCluster *esdCluster = (AliESDMuonCluster*) esdTrack->GetClusters().UncheckedAt(iCluster);
159
160 // get the corresponding MUON cluster
161 AliMUONVCluster* cluster = FindClusterInTrack(*track, esdCluster->GetUniqueID());
162
163 // fill cluster map
164 cMap->Add(cluster->GetUniqueID(), cluster);
165
166 // prepare digit map
630711ed 167 AliMpExMap* dMap =new AliMpExMap;
103e6575 168 dMap->SetOwner(kFALSE);
630711ed 169 dMaps->Add(esdCluster->GetUniqueID(), dMap);
103e6575 170
171 // loop over ESD pads
172 Int_t nPads = esdCluster->GetNPads();
173 for (Int_t iPad = 0; iPad < nPads; iPad++) {
174
175 // get ESD pad
176 AliESDMuonPad *esdPad = (AliESDMuonPad*) esdCluster->GetPads().UncheckedAt(iPad);
177
178 // add it to digit store
179 AliMUONVDigit* digit = Add(*esdPad, *fDigits);
180
181 // fill digit map
182 if (digit) dMap->Add(esdPad->GetUniqueID(), digit);
183 else dMap->Add(esdPad->GetUniqueID(), fDigits->FindObject(esdPad->GetUniqueID()));
184
185 } // end of loop over pads
186
187 } // end of loop over clusters
188
189 } // end of loop over tracks
190
191}
192
193//___________________________________________________________________________
194Int_t AliMUONESDInterface::GetNTracks() const
195{
196 /// return the number of tracks
630711ed 197 return fTracks ? fTracks->GetSize() : 0;
103e6575 198}
199
200//___________________________________________________________________________
201Int_t AliMUONESDInterface::GetNClusters() const
202{
203 /// return the number of clusters
204 Int_t nClusters = 0;
630711ed 205 AliMUONTrack *track;
206 TIter next(CreateTrackIterator());
207 while ((track = static_cast<AliMUONTrack*>(next()))) nClusters += track->GetNClusters();
103e6575 208 return nClusters;
209}
210
211//___________________________________________________________________________
630711ed 212Int_t AliMUONESDInterface::GetNClusters(UInt_t trackId) const
103e6575 213{
630711ed 214 /// return the number of clusters in track "trackId"
215 AliMUONTrack* track = FindTrack(trackId);
103e6575 216 return track ? track->GetNClusters() : 0;
217}
218
219//___________________________________________________________________________
220Int_t AliMUONESDInterface::GetNDigits() const
221{
222 /// return the number of digits
223 return fDigits ? fDigits->GetSize() : 0;
224}
225
226//___________________________________________________________________________
630711ed 227Int_t AliMUONESDInterface::GetNDigits(UInt_t trackId) const
103e6575 228{
630711ed 229 /// return the number of digits in all clusters of track "trackId"
103e6575 230 Int_t nDigits = 0;
630711ed 231 AliMUONVCluster *cluster;
232 TIter next(CreateClusterIterator(trackId));
233 while ((cluster = static_cast<AliMUONVCluster*>(next()))) nDigits += cluster->GetNDigits();
103e6575 234 return nDigits;
235}
236
237//___________________________________________________________________________
630711ed 238Int_t AliMUONESDInterface::GetNDigits(UInt_t trackId, UInt_t clusterId) const
103e6575 239{
240 /// return the number of digits in cluster numbered "iCluster" of track "iTrack"
630711ed 241 AliMUONVCluster* cluster = FindCluster(trackId, clusterId);
103e6575 242 return cluster ? cluster->GetNDigits() : 0;
243}
244
245//___________________________________________________________________________
246Int_t AliMUONESDInterface::GetNDigitsInCluster(UInt_t clusterId) const
247{
248 /// return the number of digits in cluster "clusterId"
249 AliMUONVCluster* cluster = FindCluster(clusterId);
250 return cluster ? cluster->GetNDigits() : 0;
251}
252
253//___________________________________________________________________________
630711ed 254AliMUONTrack* AliMUONESDInterface::FindTrack(UInt_t trackId) const
103e6575 255{
630711ed 256 /// return track "trackId" (0x0 if not found)
257 AliMUONTrack *track = fTracks ? static_cast<AliMUONTrack*>(fTracks->FindObject(trackId)) : 0x0;
258 if (!track) AliWarning(Form("track %d does not exist",trackId));
103e6575 259 return track;
260}
261
262//___________________________________________________________________________
103e6575 263AliMUONVCluster* AliMUONESDInterface::FindCluster(UInt_t clusterId) const
264{
630711ed 265 /// loop over tracks and return the first cluster "clusterId" found (0x0 if not found)
266 AliMpExMap *cMap;
103e6575 267 AliMUONVCluster* cluster = 0x0;
268
630711ed 269 if (fClusterMap) {
103e6575 270
630711ed 271 TIter next(fClusterMap->CreateIterator());
272 while ((cMap = static_cast<AliMpExMap*>(next()))) {
273
274 cluster = static_cast<AliMUONVCluster*>(cMap->GetValue(clusterId));
275 if (cluster) return cluster;
276
277 }
103e6575 278
279 }
280
281 if (!cluster) AliWarning(Form("cluster %d does not exist",clusterId));
630711ed 282 return 0x0;
283}
284
285//___________________________________________________________________________
286AliMUONVCluster* AliMUONESDInterface::FindCluster(UInt_t trackId, UInt_t clusterId) const
287{
288 /// return cluster "clusterId" in track "trackId" (0x0 if not found)
289 AliMpExMap *cMap = fClusterMap ? static_cast<AliMpExMap*>(fClusterMap->GetValue(trackId)) : 0x0;
290 AliMUONVCluster* cluster = cMap ? static_cast<AliMUONVCluster*>(cMap->GetValue(clusterId)) : 0x0;
291 if (!cluster) AliWarning(Form("cluster %d does not exist in track %d", clusterId, trackId));
103e6575 292 return cluster;
293}
294
295//___________________________________________________________________________
296AliMUONVDigit* AliMUONESDInterface::FindDigit(UInt_t digitId) const
297{
298 /// return digit "digitId" (0x0 if not found)
299 AliMUONVDigit *digit = fDigits ? fDigits->FindObject(digitId) : 0x0;
300 if (!digit) AliWarning(Form("digit %d does not exist",digitId));
301 return digit;
302}
303
304//___________________________________________________________________________
305TIterator* AliMUONESDInterface::CreateTrackIterator() const
306{
307 /// return iterator over all tracks
308 return fTracks ? fTracks->CreateIterator() : 0x0;
309}
310
311//___________________________________________________________________________
312TIterator* AliMUONESDInterface::CreateClusterIterator() const
313{
314 /// return iterator over all clusters
315 return fClusterMap ? new AliMUON2DMapIterator(*fClusterMap) : 0x0;
316}
317
318//___________________________________________________________________________
630711ed 319TIterator* AliMUONESDInterface::CreateClusterIterator(UInt_t trackId) const
103e6575 320{
630711ed 321 /// return iterator over clusters of track "trackId"
322 AliMpExMap *cMap = fClusterMap ? static_cast<AliMpExMap*>(fClusterMap->GetValue(trackId)) : 0x0;
323 return cMap ? cMap->CreateIterator() : 0x0;
103e6575 324}
325
326//___________________________________________________________________________
327TIterator* AliMUONESDInterface::CreateDigitIterator() const
328{
329 /// return iterator over all digits
330 return fDigits ? fDigits->CreateIterator() : 0x0;
331}
332
333//___________________________________________________________________________
630711ed 334TIterator* AliMUONESDInterface::CreateDigitIterator(UInt_t trackId) const
103e6575 335{
630711ed 336 /// return iterator over all digits of track "trackId"
337 AliMpExMap* dMaps = fDigitMap ? static_cast<AliMpExMap*>(fDigitMap->GetValue(trackId)) : 0x0;
103e6575 338 return dMaps ? new AliMUON2DMapIterator(*dMaps) : 0x0;
339}
340
341//___________________________________________________________________________
630711ed 342TIterator* AliMUONESDInterface::CreateDigitIterator(UInt_t trackId, UInt_t clusterId) const
103e6575 343{
630711ed 344 /// return iterator over digits of cluster "clusterId" in track "trackId"
345 AliMpExMap* dMaps = fDigitMap ? static_cast<AliMpExMap*>(fDigitMap->GetValue(trackId)) : 0x0;
346 AliMpExMap* dMap = dMaps ? static_cast<AliMpExMap*>(dMaps->GetValue(clusterId)) : 0x0;
347 return dMap ? dMap->CreateIterator() : 0x0;
103e6575 348}
349
350//___________________________________________________________________________
351TIterator* AliMUONESDInterface::CreateDigitIteratorInCluster(UInt_t clusterId) const
352{
630711ed 353 /// return iterator over digits of the first cluster "clusterId" found by looping over all tracks
354 AliMpExMap *dMaps;
103e6575 355 AliMpExMap* dMap = 0x0;
356
630711ed 357 if (fDigitMap) {
103e6575 358
630711ed 359 TIter next(fDigitMap->CreateIterator());
360 while ((dMaps = static_cast<AliMpExMap*>(next()))) {
361
362 dMap = static_cast<AliMpExMap*>(dMaps->GetValue(clusterId));
363 if (dMap) return dMap->CreateIterator();
364
365 }
103e6575 366
367 }
368
630711ed 369 return 0x0;
103e6575 370}
371
372//___________________________________________________________________________
373AliMUONVCluster* AliMUONESDInterface::FindClusterInTrack(const AliMUONTrack& track, UInt_t clusterId) const
374{
375 /// find the cluster with the given Id into the track
376
377 Int_t nClusters = track.GetNClusters();
378 for (Int_t iCluster = 0; iCluster < nClusters; iCluster++) {
379
380 AliMUONVCluster* cluster = ((AliMUONTrackParam*) track.GetTrackParamAtCluster()->UncheckedAt(iCluster))->GetClusterPtr();
381 if (cluster->GetUniqueID() == clusterId) return cluster;
382
383 }
384
385 return 0x0;
386}
387
388//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
389// static methods //
390//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
391
392//_____________________________________________________________________________
393AliMUONVTrackStore* AliMUONESDInterface::NewTrackStore()
394{
395 /// Create an empty track store of type fgTrackStoreName
396 TClass* classPtr = TClass::GetClass(fgTrackStoreName);
397 if (!classPtr || !classPtr->InheritsFrom("AliMUONVTrackStore")) {
398 cout<<"E-AliMUONESDInterface::NewTrackStore: Unable to create store of type "<<fgTrackStoreName.Data()<<endl;
399 return 0x0;
400 }
401 return reinterpret_cast<AliMUONVTrackStore*>(classPtr->New());
402}
403
404//_____________________________________________________________________________
405AliMUONVClusterStore* AliMUONESDInterface::NewClusterStore()
406{
407 /// Create an empty cluster store of type fgClusterStoreName
408 TClass* classPtr = TClass::GetClass(fgClusterStoreName);
409 if (!classPtr || !classPtr->InheritsFrom("AliMUONVClusterStore")) {
410 cout<<"E-AliMUONESDInterface::NewClusterStore: Unable to create store of type "<<fgClusterStoreName.Data()<<endl;
411 return 0x0;
412 }
413 return reinterpret_cast<AliMUONVClusterStore*>(classPtr->New());
414}
415
416//_____________________________________________________________________________
417AliMUONVDigitStore* AliMUONESDInterface::NewDigitStore()
418{
419 /// Create an empty digit store of type fgDigitStoreName
420 TClass* classPtr = TClass::GetClass(fgDigitStoreName);
421 if (!classPtr || !classPtr->InheritsFrom("AliMUONVDigitStore")) {
422 cout<<"E-AliMUONESDInterface::NewDigitStore: Unable to create store of type "<<fgDigitStoreName.Data()<<endl;
423 return 0x0;
424 }
425 return reinterpret_cast<AliMUONVDigitStore*>(classPtr->New());
426}
427
428//_________________________________________________________________________
429void AliMUONESDInterface::GetParamAtVertex(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
430{
431 /// Get parameters at vertex from ESDMuon track
432 trackParam.SetZ(esdTrack.GetZ());
433 trackParam.SetNonBendingCoor(esdTrack.GetNonBendingCoor());
434 trackParam.SetNonBendingSlope(TMath::Tan(esdTrack.GetThetaX()));
435 trackParam.SetBendingCoor(esdTrack.GetBendingCoor());
436 trackParam.SetBendingSlope(TMath::Tan(esdTrack.GetThetaY()));
437 trackParam.SetInverseBendingMomentum(esdTrack.GetInverseBendingMomentum());
438}
439
440//_________________________________________________________________________
441void AliMUONESDInterface::GetParamAtDCA(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
442{
443 /// Get parameters at DCA from ESDMuon track
444 trackParam.SetZ(esdTrack.GetZ());
445 trackParam.SetNonBendingCoor(esdTrack.GetNonBendingCoorAtDCA());
446 trackParam.SetNonBendingSlope(TMath::Tan(esdTrack.GetThetaXAtDCA()));
447 trackParam.SetBendingCoor(esdTrack.GetBendingCoorAtDCA());
448 trackParam.SetBendingSlope(TMath::Tan(esdTrack.GetThetaYAtDCA()));
449 trackParam.SetInverseBendingMomentum(esdTrack.GetInverseBendingMomentumAtDCA());
450}
451
452//_________________________________________________________________________
453void AliMUONESDInterface::GetParamAtFirstCluster(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
454{
455 /// Get parameters at first cluster from ESDMuon track
456 trackParam.SetZ(esdTrack.GetZUncorrected());
457 trackParam.SetNonBendingCoor(esdTrack.GetNonBendingCoorUncorrected());
458 trackParam.SetNonBendingSlope(TMath::Tan(esdTrack.GetThetaXUncorrected()));
459 trackParam.SetBendingCoor(esdTrack.GetBendingCoorUncorrected());
460 trackParam.SetBendingSlope(TMath::Tan(esdTrack.GetThetaYUncorrected()));
461 trackParam.SetInverseBendingMomentum(esdTrack.GetInverseBendingMomentumUncorrected());
462}
463
464//_________________________________________________________________________
465void AliMUONESDInterface::GetParamCov(const AliESDMuonTrack& esdTrack, AliMUONTrackParam& trackParam)
466{
467 /// Get parameters covariances from ESD track
468
469 // get ESD covariance matrix
470 TMatrixD covariances(5,5);
471 esdTrack.GetCovariances(covariances);
472
473 // compute Jacobian to change the coordinate system
474 // from (X,thetaX,Y,thetaY,c/pYZ) to (X,slopeX,Y,slopeY,c/pYZ)
475 Double_t cosThetaX = TMath::Cos(esdTrack.GetThetaXUncorrected());
476 Double_t cosThetaY = TMath::Cos(esdTrack.GetThetaYUncorrected());
477 TMatrixD jacob(5,5);
478 jacob.Zero();
479 jacob(0,0) = 1.;
480 jacob(1,1) = 1. / cosThetaX / cosThetaX;
481 jacob(2,2) = 1.;
482 jacob(3,3) = 1. / cosThetaY / cosThetaY;
483 jacob(4,4) = 1.;
484
485 // compute covariance matrix in ESD coordinate system
486 TMatrixD tmp(covariances,TMatrixD::kMultTranspose,jacob);
487 trackParam.SetCovariances(TMatrixD(jacob,TMatrixD::kMult,tmp));
488
489}
490
491//_________________________________________________________________________
492void AliMUONESDInterface::SetParamAtVertex(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
493{
494 /// Set parameters in ESD track
495 esdTrack.SetZ(trackParam.GetZ());
496 esdTrack.SetNonBendingCoor(trackParam.GetNonBendingCoor());
497 esdTrack.SetThetaX(TMath::ATan(trackParam.GetNonBendingSlope()));
498 esdTrack.SetBendingCoor(trackParam.GetBendingCoor());
499 esdTrack.SetThetaY(TMath::ATan(trackParam.GetBendingSlope()));
500 esdTrack.SetInverseBendingMomentum(trackParam.GetInverseBendingMomentum());
501}
502
503//_________________________________________________________________________
504void AliMUONESDInterface::SetParamAtDCA(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
505{
506 /// Set parameters in ESD track
507 esdTrack.SetNonBendingCoorAtDCA(trackParam.GetNonBendingCoor());
508 esdTrack.SetThetaXAtDCA(TMath::ATan(trackParam.GetNonBendingSlope()));
509 esdTrack.SetBendingCoorAtDCA(trackParam.GetBendingCoor());
510 esdTrack.SetThetaYAtDCA(TMath::ATan(trackParam.GetBendingSlope()));
511 esdTrack.SetInverseBendingMomentumAtDCA(trackParam.GetInverseBendingMomentum());
512}
513
514//_________________________________________________________________________
515void AliMUONESDInterface::SetParamAtFirstCluster(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
516{
517 /// Set parameters in ESD track
518 esdTrack.SetZUncorrected(trackParam.GetZ());
519 esdTrack.SetNonBendingCoorUncorrected(trackParam.GetNonBendingCoor());
520 esdTrack.SetThetaXUncorrected(TMath::ATan(trackParam.GetNonBendingSlope()));
521 esdTrack.SetBendingCoorUncorrected(trackParam.GetBendingCoor());
522 esdTrack.SetThetaYUncorrected(TMath::ATan(trackParam.GetBendingSlope()));
523 esdTrack.SetInverseBendingMomentumUncorrected(trackParam.GetInverseBendingMomentum());
524}
525
526//_________________________________________________________________________
527void AliMUONESDInterface::SetParamCov(const AliMUONTrackParam& trackParam, AliESDMuonTrack& esdTrack)
528{
529 /// Set parameters covariances in ESD track
530
531 // set null matrix if covariances does not exist
532 if (!trackParam.CovariancesExist()) {
533 TMatrixD tmp(5,5);
534 tmp.Zero();
535 esdTrack.SetCovariances(tmp);
536 return;
537 }
538
539 // compute Jacobian to change the coordinate system
540 // from (X,slopeX,Y,slopeY,c/pYZ) to (X,thetaX,Y,thetaY,c/pYZ)
541 Double_t cosThetaX = TMath::Cos(TMath::ATan(trackParam.GetNonBendingSlope()));
542 Double_t cosThetaY = TMath::Cos(TMath::ATan(trackParam.GetBendingSlope()));
543 TMatrixD jacob(5,5);
544 jacob.Zero();
545 jacob(0,0) = 1.;
546 jacob(1,1) = cosThetaX * cosThetaX;
547 jacob(2,2) = 1.;
548 jacob(3,3) = cosThetaY * cosThetaY;
549 jacob(4,4) = 1.;
550
551 // compute covariance matrix in ESD coordinate system
552 TMatrixD tmp(trackParam.GetCovariances(),TMatrixD::kMultTranspose,jacob);
553 esdTrack.SetCovariances(TMatrixD(jacob,TMatrixD::kMult,tmp));
554
555}
556
557//_____________________________________________________________________________
558void AliMUONESDInterface::ESDToMUON(const AliESDMuonTrack& esdTrack, AliMUONTrack& track)
559{
560 /// Transfert data from ESDMuon track to MUON track
561
562 track.Clear("C");
563
564 // global info
565 track.SetUniqueID(esdTrack.GetUniqueID());
566 track.FitWithVertex(kFALSE);
567 track.FitWithMCS(kFALSE);
568 track.SetImproved(kFALSE);
569 track.SetVertexErrXY2(0.,0.);
570 track.SetGlobalChi2(esdTrack.GetChi2());
571 track.SetMatchTrigger(esdTrack.GetMatchTrigger());
572 track.SetLoTrgNum(-1);
573 track.SetChi2MatchTrigger(esdTrack.GetChi2MatchTrigger());
574 track.SetTrackID(0);
575 track.SetHitsPatternInTrigCh(esdTrack.GetHitsPatternInTrigCh());
576 track.SetLocalTrigger(esdTrack.LoCircuit(), esdTrack.LoStripX(), esdTrack.LoStripY(),
577 esdTrack.LoDev(), esdTrack.LoLpt(), esdTrack.LoHpt());
578
579 // track parameters at vertex
580 AliMUONTrackParam paramAtVertex;
581 GetParamAtVertex(esdTrack, paramAtVertex);
582 track.SetTrackParamAtVertex(&paramAtVertex);
583
584 // track parameters at first cluster
585 AliMUONTrackParam param;
586 GetParamAtFirstCluster(esdTrack, param);
587 GetParamCov(esdTrack, param);
588
589 // create empty cluster
590 AliMUONVClusterStore* cStore = NewClusterStore();
591 if (!cStore) return;
592 AliMUONVCluster* cluster = cStore->CreateCluster(0,0,0);
593
594 // fill TrackParamAtCluster with track parameters at each cluster if available
595 // or with only track parameters at first (fake) cluster if not
596 if(esdTrack.ClustersStored()) {
597
598 // loop over ESD clusters
599 AliESDMuonCluster *esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().First();
600 while (esdCluster) {
601
602 // copy cluster information
603 ESDToMUON(*esdCluster, *cluster);
604
605 // only set the Z parameter to avoid error in the AddTrackParamAtCluster(...) method
606 param.SetZ(cluster->GetZ());
607
608 // add common track parameters at current cluster
609 track.AddTrackParamAtCluster(param, *cluster, kTRUE);
610
611 esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().After(esdCluster);
612 }
613
614 // recompute parameters at first cluster in case of those stored
615 // in ESD are not related to the most upstream cluster
616 AliMUONTrackParam *firstTrackParam = (AliMUONTrackParam*) track.GetTrackParamAtCluster()->First();
617 firstTrackParam->SetZ(esdTrack.GetZUncorrected()); // reset the z to the one stored in ESD
618 AliMUONTrackExtrap::ExtrapToZCov(firstTrackParam,firstTrackParam->GetClusterPtr()->GetZ());
619
620 // Compute track parameters and covariances at each cluster from those at the first one
621 track.UpdateCovTrackParamAtCluster();
622
623 } else {
624
625 // get number of the first hit chamber (according to the MUONClusterMap if not empty)
626 Int_t firstCh = 0;
627 if (esdTrack.GetMuonClusterMap() != 0) while (!esdTrack.IsInMuonClusterMap(firstCh)) firstCh++;
628 else firstCh = AliMUONConstants::ChamberNumber(param.GetZ());
629
630 // produce fake cluster at this chamber
631 cluster->SetUniqueID(AliMUONVCluster::BuildUniqueID(firstCh, 0, 0));
632 cluster->SetXYZ(param.GetNonBendingCoor(), param.GetBendingCoor(), param.GetZ());
633 cluster->SetErrXY(0., 0.);
634
635 // add track parameters at first (fake) cluster
636 track.AddTrackParamAtCluster(param, *cluster, kTRUE);
637
638 }
639
640 delete cluster;
641 delete cStore;
642
643}
644
645//_____________________________________________________________________________
646void AliMUONESDInterface::ESDToMUON(const AliESDMuonCluster& esdCluster, AliMUONVCluster& cluster)
647{
648 /// Transfert data from ESDMuon cluster to MUON cluster
649
650 cluster.Clear("C");
651
652 cluster.SetUniqueID(esdCluster.GetUniqueID());
653 cluster.SetXYZ(esdCluster.GetX(), esdCluster.GetY(), esdCluster.GetZ());
654 cluster.SetErrXY(esdCluster.GetErrX(),esdCluster.GetErrY());
655 cluster.SetCharge(esdCluster.GetCharge());
656 cluster.SetChi2(esdCluster.GetChi2());
657
658 if (esdCluster.PadsStored()) {
659 Int_t nPads = esdCluster.GetNPads();
660 for (Int_t iPad = 0; iPad < nPads; iPad++)
661 cluster.AddDigitId(((AliESDMuonPad*)esdCluster.GetPads().UncheckedAt(iPad))->GetUniqueID());
662 }
663
664}
665
666//___________________________________________________________________________
667void AliMUONESDInterface::ESDToMUON(const AliESDMuonPad& esdPad, AliMUONVDigit& digit)
668{
669 /// Transfert data from ESDMuon pad to MUON digit
670
671 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(esdPad.GetDetElemId(), esdPad.GetManuId());
672 AliMpPad pad = seg->PadByLocation(AliMpIntPair(esdPad.GetManuId(), esdPad.GetManuChannel()), kFALSE);
673
674 digit.Saturated(kFALSE);
675 digit.Used(kFALSE);
676 digit.Calibrated(kTRUE);
677 digit.SetUniqueID(esdPad.GetUniqueID());
678 digit.SetCharge(esdPad.GetCharge());
679 digit.SetADC(esdPad.GetADC());
680 digit.SetPadXY(pad.GetIndices().GetFirst(), pad.GetIndices().GetSecond());
681
682}
683
684//_____________________________________________________________________________
685void AliMUONESDInterface::MUONToESD(const AliMUONTrack& track, AliESDMuonTrack& esdTrack, const Double_t vertex[3], const AliMUONVDigitStore* digits)
686{
687 /// Transfert data from MUON track to ESDMuon track
688 /// Incorporate the ESDPads if the digits are provided
689
690 esdTrack.Clear("C");
691
692 // set param at first cluster
693 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track.GetTrackParamAtCluster())->First());
694 SetParamAtFirstCluster(*trackParam, esdTrack);
695 SetParamCov(*trackParam, esdTrack);
696
697 // set param at vertex
698 AliMUONTrackParam trackParamAtVtx(*trackParam);
699 AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0], vertex[1], vertex[2], 0., 0.);
700 SetParamAtVertex(trackParamAtVtx, esdTrack);
701
702 // set param at Distance of Closest Approach
703 AliMUONTrackParam trackParamAtDCA(*trackParam);
704 AliMUONTrackExtrap::ExtrapToVertexWithoutBranson(&trackParamAtDCA, vertex[2]);
705 SetParamAtDCA(trackParamAtDCA, esdTrack);
706
707 // set global info
708 esdTrack.SetUniqueID(track.GetUniqueID());
709 esdTrack.SetChi2(track.GetGlobalChi2());
710 esdTrack.SetNHit(track.GetNClusters());
711 esdTrack.SetLocalTrigger(track.GetLocalTrigger());
712 esdTrack.SetChi2MatchTrigger(track.GetChi2MatchTrigger());
713 esdTrack.SetHitsPatternInTrigCh(track.GetHitsPatternInTrigCh());
714
715 // set muon cluster info
716 AliESDMuonCluster esdCluster;
717 esdTrack.SetMuonClusterMap(0);
718 while (trackParam) {
719 MUONToESD(*(trackParam->GetClusterPtr()), esdCluster, digits);
720 esdTrack.AddCluster(esdCluster);
721 esdTrack.AddInMuonClusterMap(esdCluster.GetChamberId());
722 trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
723 }
724
725}
726
727//_____________________________________________________________________________
728void AliMUONESDInterface::MUONToESD(const AliMUONVCluster& cluster, AliESDMuonCluster& esdCluster, const AliMUONVDigitStore* digits)
729{
730 /// Transfert data from MUON cluster to ESDMuon cluster
731 /// Incorporate the ESDPads if the digits are provided
732
733 esdCluster.Clear("C");
734
735 esdCluster.SetUniqueID(cluster.GetUniqueID());
736 esdCluster.SetXYZ(cluster.GetX(), cluster.GetY(), cluster.GetZ());
737 esdCluster.SetErrXY(cluster.GetErrX(), cluster.GetErrY());
630711ed 738 esdCluster.SetCharge(cluster.GetCharge());
739 esdCluster.SetChi2(cluster.GetChi2());
103e6575 740
630711ed 741 if (digits) { // transfert all data if required
103e6575 742
103e6575 743 AliESDMuonPad esdPad;
744 for (Int_t i=0; i<cluster.GetNDigits(); i++) {
745 AliMUONVDigit* digit = digits->FindObject(cluster.GetDigitId(i));
746 if (!digit) {
747 cout<<"E-AliMUONESDInterface::MUONToESD: digit "<<cluster.GetDigitId(i)<<" not found"<<endl;
748 continue;
749 }
750 MUONToESD(*digit, esdPad);
751 esdCluster.AddPad(esdPad);
752 }
753
103e6575 754 }
755
756}
757
758//_____________________________________________________________________________
759void AliMUONESDInterface::MUONToESD(const AliMUONVDigit& digit, AliESDMuonPad& esdPad)
760{
761 /// Transfert data from MUON digit to ESDMuon pad
762 esdPad.SetUniqueID(digit.GetUniqueID());
763 esdPad.SetADC(digit.ADC());
764 esdPad.SetCharge(digit.Charge());
765}
766
767//___________________________________________________________________________
768AliMUONTrack* AliMUONESDInterface::Add(const AliESDMuonTrack& esdTrack, AliMUONVTrackStore& trackStore)
769{
770 /// Create MUON track from ESDMuon track and add it to the store
771 /// return a pointer to the track into the store
772 AliMUONTrack* track = trackStore.Add(AliMUONTrack());
773 ESDToMUON(esdTrack, *track);
774 return track;
775}
776
777//___________________________________________________________________________
778AliMUONVCluster* AliMUONESDInterface::Add(const AliESDMuonCluster& esdCluster, AliMUONVClusterStore& clusterStore)
779{
780 /// Create MUON cluster from ESDMuon cluster and add it to the store
781 /// return a pointer to the cluster into the store (0x0 if the cluster already exist)
782 AliMUONVCluster* cluster = clusterStore.Add(esdCluster.GetChamberId(), esdCluster.GetDetElemId(), esdCluster.GetClusterIndex());
783 if (cluster) ESDToMUON(esdCluster, *cluster);
784 return cluster;
785}
786
787//___________________________________________________________________________
788AliMUONVDigit* AliMUONESDInterface::Add(const AliESDMuonPad& esdPad, AliMUONVDigitStore& digitStore)
789{
790 /// Create MUON digit from ESDMuon digit and add it to the store
791 /// return a pointer to the digit into the store (0x0 if the digit already exist)
792 AliMUONVDigit* digit = digitStore.Add(esdPad.GetDetElemId(), esdPad.GetManuId(), esdPad.GetManuChannel(), esdPad.GetCathode(), AliMUONVDigitStore::kDeny);
793 if (digit) ESDToMUON(esdPad, *digit);
794 return digit;
795}
796