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