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 "AliMUONTriggerUtilities.h"
58 #include <Riostream.h>
64 ClassImp(AliMUONTracker)
68 //_____________________________________________________________________________
69 AliMUONTracker::AliMUONTracker(const AliMUONRecoParam* recoParam,
70 AliMUONVClusterServer* clusterServer,
71 AliMUONVDigitStore& digitStore,
72 const AliMUONGeometryTransformer* transformer,
73 const AliMUONTriggerCircuit* triggerCircuit,
74 const AliMUONTriggerUtilities* triggerUtilities)
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),
88 fInternalTrackStore(0x0)
93 fTrackHitPatternMaker = new AliMUONTrackHitPattern(recoParam,*fkTransformer,fkDigitStore,triggerUtilities);
97 AliDebug(1,"No cluster server given. Will use AliMUONLegacyClusterServer");
98 fIsOwnerOfClusterServer = kTRUE;
102 TIter next(fkDigitStore.CreateIterator());
103 fClusterServer->UseDigits(next,&digitStore);
105 SetupClusterServer(*fClusterServer);
109 //_____________________________________________________________________________
110 AliMUONTracker::~AliMUONTracker()
115 delete fTrackHitPatternMaker;
116 delete fClusterStore;
117 delete fTriggerStore;
118 if ( fIsOwnerOfClusterServer ) delete fClusterServer;
119 delete fInputClusterStore;
120 delete fTriggerTrackStore;
121 delete fInternalTrackStore;
124 //_____________________________________________________________________________
125 AliMUONVClusterStore*
126 AliMUONTracker::ClusterStore() const
128 /// Return (and create if necessary) the cluster container
131 fClusterStore = new AliMUONClusterStoreV2;
133 return fClusterStore;
136 //_____________________________________________________________________________
137 AliMUONVTriggerTrackStore*
138 AliMUONTracker::TriggerTrackStore() const
140 /// Return (and create if necessary) the trigger track container
141 if (!fTriggerTrackStore)
143 fTriggerTrackStore = new AliMUONTriggerTrackStoreV1;
145 return fTriggerTrackStore;
148 //_____________________________________________________________________________
149 Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
151 /// Load triggerStore from clustersTree
153 if ( ! clustersTree ) {
154 AliFatal("No clustersTree");
158 if ( !fTriggerStore )
160 fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
165 AliError("Could not get triggerStore");
169 if (!fInputClusterStore)
171 fInputClusterStore = AliMUONVClusterStore::Create(*clustersTree);
172 if (!fInputClusterStore)
174 AliError("Could not get clusterStore");
177 AliDebug(1,Form("Created %s from cluster tree",fInputClusterStore->ClassName()));
180 if ( !fClusterServer && fIsOwnerOfClusterServer )
182 if ( !fClusterServer )
184 fClusterServer = new AliMUONLegacyClusterServer(*fkTransformer,fInputClusterStore,
185 GetRecoParam()->BypassSt4(),
186 GetRecoParam()->BypassSt5());
187 SetupClusterServer(*fClusterServer);
192 fInputClusterStore->Clear();
193 fInputClusterStore->Connect(*clustersTree,kFALSE);
194 fTriggerStore->Clear();
195 fTriggerStore->Connect(*clustersTree,kFALSE);
197 clustersTree->GetEvent(0);
202 //_____________________________________________________________________________
203 Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
205 /// Performs the tracking and store the resulting tracks in the ESD
207 /// note that we're dealing with two cluster stores here : fInputClusterStore
208 /// and ClusterStore().
209 /// The first one is read from the TreeR and may be used by the cluster server
210 /// (that's the case for the legacy cluster server) to fill the other one.
211 /// The second one is more dynamic and might be created on the fly by the cluster
212 /// server (used by the combined tracking, in which case the first one is not used
215 AliCodeTimerAuto("",0)
219 fTrackReco = CreateTrackReconstructor(GetRecoParam(),fClusterServer);
220 fInternalTrackStore = new AliMUONTrackStoreV1;
223 // if the required tracking mode does not exist
224 if (!fTrackReco) return 1;
226 if ( ! ClusterStore() )
228 AliError("ClusterStore is NULL");
232 if (!fTriggerStore) {
233 AliError("TriggerStore is NULL");
237 // Make trigger tracks
238 if ( fkTriggerCircuit )
240 TriggerTrackStore()->Clear();
241 fTrackReco->EventReconstructTrigger(*fkTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
244 if ( TriggerTrackStore()->GetSize() > GetRecoParam()->GetMaxTriggerTracks() )
246 // cut to reject shower events
248 AliCodeTimerAuto("MUON Shower events",1);
250 AliWarning(Form("Probably got a shower event (%d trigger tracks). Will not reconstruct tracks.",
251 TriggerTrackStore()->GetSize()));
256 fTrackReco->EventReconstruct(*(ClusterStore()),*fInternalTrackStore);
258 // Match tracker/trigger tracks
259 if ( fTrackHitPatternMaker )
261 fTrackReco->ValidateTracksWithTrigger(*fInternalTrackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
265 FillESD(*fInternalTrackStore,esd);
267 fInternalTrackStore->Clear();
268 ClusterStore()->Clear();
273 //_____________________________________________________________________________
274 void AliMUONTracker::FillESD(const AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
276 /// Fill the ESD from the trackStore
278 AliCodeTimerAuto("",0)
281 Double_t vertex[3] = {0., 0., 0.};
282 const AliESDVertex* esdVert = esd->GetVertex();
283 if (esdVert->GetNContributors() > 0 || !strcmp(esdVert->GetTitle(),"vertexer: smearMC")) {
284 esdVert->GetXYZ(vertex);
285 AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
288 // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
290 AliMUONLocalTrigger* locTrg;
291 AliESDMuonTrack esdTrack;
292 TIter next(trackStore.CreateIterator());
293 if (GetRecoParam()->SaveFullClusterInESD() &&
294 gRandom->Uniform(100.) <= GetRecoParam()->GetPercentOfFullClusterInESD()) {
296 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
298 if (track->GetMatchTrigger() > 0) {
299 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
300 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore, locTrg);
301 } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore);
303 esd->AddMuonTrack(&esdTrack);
308 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
310 if (track->GetMatchTrigger() > 0) {
311 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
312 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, 0x0, locTrg);
313 } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
315 esd->AddMuonTrack(&esdTrack);
320 // fill the local trigger decisions not matched with tracks (associate them to "ghost" tracks)
321 UInt_t ghostId = 0xFFFFFFFF - 1;
322 Bool_t matched = kFALSE;
323 AliMUONTriggerTrack *triggerTrack;
324 TIter itTriggerTrack(fTriggerTrackStore->CreateIterator());
325 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack()) ) ) {
327 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(triggerTrack->GetLoTrgNum()));
329 // check if this local trigger has already been matched
330 TIter itTrack(trackStore.CreateIterator());
331 while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) ) {
332 matched = (track->LoCircuit() == locTrg->LoCircuit());
335 if (matched) continue;
337 AliMUONESDInterface::MUONToESD(*locTrg, esdTrack, ghostId, triggerTrack);
339 esd->AddMuonTrack(&esdTrack);
345 //_____________________________________________________________________________
346 AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
348 /// Create track reconstructor, depending on tracking mode set in RecoParam
350 AliMUONVTrackReconstructor* trackReco(0x0);
352 TString opt(recoParam->GetTrackingMode());
355 if (strstr(opt,"ORIGINAL"))
357 trackReco = new AliMUONTrackReconstructor(recoParam,clusterServer);
359 else if (strstr(opt,"KALMAN"))
361 trackReco = new AliMUONTrackReconstructorK(recoParam,clusterServer);
365 AliErrorClass(Form("tracking mode \"%s\" does not exist",opt.Data()));
369 AliDebugClass(1,Form("Will use %s for tracking",trackReco->ClassName()));
374 //_____________________________________________________________________________
375 void AliMUONTracker::UnloadClusters()
377 /// Clear internal clusterStore
379 fInputClusterStore->Clear();
383 //_____________________________________________________________________________
385 AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
387 /// Setup the cluster server
389 if ( GetRecoParam()->BypassSt4() ||
390 GetRecoParam()->BypassSt5() )
392 Bool_t ok = clusterServer.UseTriggerTrackStore(TriggerTrackStore());
397 if ( GetRecoParam()->BypassSt45() )
399 msg1 = "STATIONS 4 AND 5";
400 msg2 = "THOSE TWO STATIONS";
402 else if ( GetRecoParam()->BypassSt4() )
405 msg2 = "THAT STATION";
407 else if ( GetRecoParam()->BypassSt5() )
410 msg2 = "THAT STATION";
415 AliWarning(Form("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN %s, "
416 "THUS BYPASSING REAL CLUSTERS IN %s!!!",msg1.Data(),msg2.Data()));
420 AliWarning("BYPASSING OF ST4 AND/OR 5 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");