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