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