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