1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONTracker
21 /// Steering class for use in global tracking framework;
22 /// reconstruct tracks from recpoints
24 /// Actual tracking is performed by some AliMUONVTrackReconstructor children
25 /// Tracking modes (ORIGINAL, KALMAN) and associated options and parameters can be changed
26 /// through the AliMUONRecoParam object set in the reconstruction macro or read from the CDB
27 /// (see methods in AliMUONRecoParam.h file for details)
29 /// \author Christian Finck and Laurent Aphecetche, SUBATECH Nantes
30 //-----------------------------------------------------------------------------
32 #include "AliMUONTracker.h"
34 #include "AliCodeTimer.h"
35 #include "AliESDEvent.h"
36 #include "AliESDMuonTrack.h"
37 #include "AliESDVertex.h"
39 #include "AliMUONClusterStoreV2.h"
40 #include "AliMUONESDInterface.h"
41 #include "AliMUONLegacyClusterServer.h"
42 #include "AliMUONRecoParam.h"
43 #include "AliMUONReconstructor.h"
44 #include "AliMUONTrack.h"
45 #include "AliMUONTrackExtrap.h"
46 #include "AliMUONTrackHitPattern.h"
47 #include "AliMUONTrackParam.h"
48 #include "AliMUONTrackReconstructor.h"
49 #include "AliMUONTrackReconstructorK.h"
50 #include "AliMUONTrackStoreV1.h"
51 #include "AliMUONTriggerTrackStoreV1.h"
52 #include "AliMUONTriggerTrack.h"
53 #include "AliMUONLocalTrigger.h"
54 #include "AliMUONVClusterServer.h"
55 #include "AliMUONVDigitStore.h"
56 #include "AliMUONVTriggerStore.h"
57 #include "AliMUONDigitMaker.h"
58 #include <Riostream.h>
63 ClassImp(AliMUONTracker)
67 //_____________________________________________________________________________
68 AliMUONTracker::AliMUONTracker(const AliMUONRecoParam* recoParam,
69 AliMUONVClusterServer* clusterServer,
70 AliMUONVDigitStore& digitStore,
71 const AliMUONDigitMaker* digitMaker,
72 const AliMUONGeometryTransformer* transformer,
73 const AliMUONTriggerCircuit* triggerCircuit)
75 fkDigitMaker(digitMaker), // not owner
76 fkTransformer(transformer), // not owner
77 fkTriggerCircuit(triggerCircuit), // not owner
78 fTrackHitPatternMaker(0x0),
82 fClusterServer(clusterServer),
83 fIsOwnerOfClusterServer(kFALSE),
84 fkDigitStore(digitStore), // not owner
85 fInputClusterStore(0x0),
86 fTriggerTrackStore(0x0),
87 fkRecoParam(recoParam)
90 if (fkTransformer && fkDigitMaker)
91 fTrackHitPatternMaker = new AliMUONTrackHitPattern(recoParam,*fkTransformer,*fkDigitMaker);
95 AliDebug(1,"No cluster server given. Will use AliMUONLegacyClusterServer");
96 fIsOwnerOfClusterServer = kTRUE;
100 TIter next(fkDigitStore.CreateIterator());
101 fClusterServer->UseDigits(next,&digitStore);
103 SetupClusterServer(*fClusterServer);
107 //_____________________________________________________________________________
108 AliMUONTracker::~AliMUONTracker()
112 delete fTrackHitPatternMaker;
113 delete fClusterStore;
114 delete fTriggerStore;
115 if ( fIsOwnerOfClusterServer ) delete fClusterServer;
116 delete fInputClusterStore;
117 delete fTriggerTrackStore;
120 //_____________________________________________________________________________
121 AliMUONVClusterStore*
122 AliMUONTracker::ClusterStore() const
124 /// Return (and create if necessary) the cluster container
127 fClusterStore = new AliMUONClusterStoreV2;
129 return fClusterStore;
132 //_____________________________________________________________________________
133 AliMUONVTriggerTrackStore*
134 AliMUONTracker::TriggerTrackStore() const
136 /// Return (and create if necessary) the trigger track container
137 if (!fTriggerTrackStore)
139 fTriggerTrackStore = new AliMUONTriggerTrackStoreV1;
141 return fTriggerTrackStore;
144 //_____________________________________________________________________________
145 Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
147 /// Load triggerStore from clustersTree
149 delete fTriggerStore;
150 delete fInputClusterStore;
151 fInputClusterStore=0x0;
153 if ( ! clustersTree ) {
154 AliFatal("No clustersTree");
158 fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
162 AliError("Could not get triggerStore");
166 if ( fIsOwnerOfClusterServer )
168 fInputClusterStore = AliMUONVClusterStore::Create(*clustersTree);
169 if ( fInputClusterStore )
171 AliDebug(1,Form("Created %s from cluster tree",fInputClusterStore->ClassName()));
172 fInputClusterStore->Clear();
173 fInputClusterStore->Connect(*clustersTree,kFALSE);
175 delete fClusterServer;
176 fClusterServer = new AliMUONLegacyClusterServer(*fkTransformer,fInputClusterStore,
177 GetRecoParam()->BypassSt4(),
178 GetRecoParam()->BypassSt5());
179 SetupClusterServer(*fClusterServer);
182 fTriggerStore->Connect(*clustersTree,kFALSE);
184 clustersTree->GetEvent(0);
189 //_____________________________________________________________________________
190 Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
192 /// Performs the tracking and store the resulting tracks in the ESD
194 AliCodeTimerAuto("",0)
198 fTrackReco = CreateTrackReconstructor(GetRecoParam(),fClusterServer);
201 // if the required tracking mode does not exist
202 if (!fTrackReco) return 1;
204 if ( ! ClusterStore() )
206 AliError("ClusterStore is NULL");
210 if (!fTriggerStore) {
211 AliError("TriggerStore is NULL");
215 // Make trigger tracks
216 if ( fkTriggerCircuit )
218 TriggerTrackStore()->Clear();
219 fTrackReco->EventReconstructTrigger(*fkTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
222 if ( TriggerTrackStore()->GetSize() > GetRecoParam()->GetMaxTriggerTracks() )
224 // cut to reject shower events
226 AliCodeTimerAuto("MUON Shower events",1);
228 AliWarning(Form("Probably got a shower event (%d trigger tracks). Will not reconstruct tracks.",
229 TriggerTrackStore()->GetSize()));
234 // Make tracker tracks
235 AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
236 fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
238 // Match tracker/trigger tracks
239 if ( fTrackHitPatternMaker )
241 fTrackReco->ValidateTracksWithTrigger(*trackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
245 FillESD(*trackStore,esd);
253 //_____________________________________________________________________________
254 void AliMUONTracker::FillESD(const AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
256 /// Fill the ESD from the trackStore
258 AliCodeTimerAuto("",0)
261 Double_t vertex[3] = {0., 0., 0.};
262 const AliESDVertex* esdVert = esd->GetVertex();
263 if (esdVert->GetNContributors()) {
264 esdVert->GetXYZ(vertex);
265 AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
268 // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
270 AliMUONLocalTrigger* locTrg;
271 AliESDMuonTrack esdTrack;
272 TIter next(trackStore.CreateIterator());
273 if (GetRecoParam()->SaveFullClusterInESD() &&
274 gRandom->Uniform(100.) <= GetRecoParam()->GetPercentOfFullClusterInESD()) {
276 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
278 if (track->GetMatchTrigger() > 0) {
279 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
280 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore, locTrg);
281 } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore);
283 esd->AddMuonTrack(&esdTrack);
288 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
290 if (track->GetMatchTrigger() > 0) {
291 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
292 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, 0x0, locTrg);
293 } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
295 esd->AddMuonTrack(&esdTrack);
300 // fill the local trigger decisions not matched with tracks (associate them to "ghost" tracks)
301 UInt_t ghostId = 0xFFFFFFFF - 1;
302 Bool_t matched = kFALSE;
303 AliMUONTriggerTrack *triggerTrack;
304 TIter itTriggerTrack(fTriggerTrackStore->CreateIterator());
305 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack()) ) ) {
307 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(triggerTrack->GetLoTrgNum()));
309 // check if this local trigger has already been matched
310 TIter itTrack(trackStore.CreateIterator());
311 while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) ) {
312 matched = (track->LoCircuit() == locTrg->LoCircuit());
315 if (matched) continue;
317 AliMUONESDInterface::MUONToESD(*locTrg, esdTrack, ghostId, triggerTrack);
319 esd->AddMuonTrack(&esdTrack);
325 //_____________________________________________________________________________
326 AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
328 /// Create track reconstructor, depending on tracking mode set in RecoParam
330 AliMUONVTrackReconstructor* trackReco(0x0);
332 TString opt(recoParam->GetTrackingMode());
335 if (strstr(opt,"ORIGINAL"))
337 trackReco = new AliMUONTrackReconstructor(recoParam,clusterServer);
339 else if (strstr(opt,"KALMAN"))
341 trackReco = new AliMUONTrackReconstructorK(recoParam,clusterServer);
345 AliErrorClass(Form("tracking mode \"%s\" does not exist",opt.Data()));
349 AliDebugClass(1,Form("Will use %s for tracking",trackReco->ClassName()));
354 //_____________________________________________________________________________
355 void AliMUONTracker::UnloadClusters()
357 /// Clear internal clusterStore
359 delete fInputClusterStore;
360 fInputClusterStore = 0x0;
364 //_____________________________________________________________________________
366 AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
368 /// Setup the cluster server
370 if ( GetRecoParam()->BypassSt4() ||
371 GetRecoParam()->BypassSt5() )
373 Bool_t ok = clusterServer.UseTriggerTrackStore(TriggerTrackStore());
378 if ( GetRecoParam()->BypassSt45() )
380 msg1 = "STATIONS 4 AND 5";
381 msg2 = "THOSE TWO STATIONS";
383 else if ( GetRecoParam()->BypassSt4() )
386 msg2 = "THAT STATION";
388 else if ( GetRecoParam()->BypassSt5() )
391 msg2 = "THAT STATION";
396 AliWarning(Form("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN %s, "
397 "THUS BYPASSING REAL CLUSTERS IN %s!!!",msg1.Data(),msg2.Data()));
401 AliWarning("BYPASSING OF ST4 AND/OR 5 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");