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