Optional friend tree replaced by list of friends.
[u/mrichter/AliRoot.git] / MUON / AliMUONTracker.cxx
... / ...
CommitLineData
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//-----------------------------------------------------------------------------
19/// \class AliMUONTracker
20///
21/// Steering class for use in global tracking framework;
22/// reconstruct tracks from recpoints
23///
24/// Actual tracking is performed by some AliMUONVTrackReconstructor children
25/// Tracking modes (ORIGINAL, KALMAN) and associated options and parameters
26/// can be changed by using:
27/// AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLow(High)FluxParam();
28/// muonRecoParam->Set...(); // see methods in AliMUONRecoParam.h for details
29/// AliMUONReconstructor::SetRecoParam(muonRecoParam);
30///
31/// \author Christian Finck and Laurent Aphecetche, SUBATECH Nantes
32//-----------------------------------------------------------------------------
33
34#include "AliMUONTracker.h"
35
36#include "AliMUONReconstructor.h"
37#include "AliMUONRecoParam.h"
38#include "AliMUONTrack.h"
39#include "AliMUONTrackExtrap.h"
40#include "AliMUONTrackHitPattern.h"
41#include "AliMUONTrackParam.h"
42#include "AliMUONVCluster.h"
43#include "AliMUONVClusterServer.h"
44#include "AliMUONVDigitStore.h"
45#include "AliMUONTrackReconstructor.h"
46#include "AliMUONTrackReconstructorK.h"
47#include "AliMUONTrackStoreV1.h"
48#include "AliMUONTriggerTrackStoreV1.h"
49#include "AliMUONClusterStoreV2.h"
50#include "AliMUONVTriggerStore.h"
51#include "AliMUONESDInterface.h"
52
53#include "AliESDEvent.h"
54#include "AliESDVertex.h"
55#include "AliESDMuonTrack.h"
56#include "AliLog.h"
57#include "AliCodeTimer.h"
58
59#include <Riostream.h>
60#include <TTree.h>
61#include <TRandom.h>
62
63/// \cond CLASSIMP
64ClassImp(AliMUONTracker)
65/// \endcond
66
67
68//_____________________________________________________________________________
69AliMUONTracker::AliMUONTracker(AliMUONVClusterServer& clusterServer,
70 const AliMUONVDigitStore& digitStore,
71 const AliMUONDigitMaker* digitMaker,
72 const AliMUONGeometryTransformer* transformer,
73 const AliMUONTriggerCircuit* triggerCircuit)
74: AliTracker(),
75 fDigitMaker(digitMaker), // not owner
76 fTransformer(transformer), // not owner
77 fTriggerCircuit(triggerCircuit), // not owner
78 fTrackHitPatternMaker(0x0),
79 fTrackReco(0x0),
80 fClusterStore(0x0),
81 fTriggerStore(0x0),
82 fClusterServer(clusterServer), // not owner
83 fDigitStore(digitStore) // not owner
84{
85 /// constructor
86 if (fTransformer && fDigitMaker)
87 fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
88
89 TIter next(fDigitStore.CreateIterator());
90 fClusterServer.UseDigits(next);
91}
92
93//_____________________________________________________________________________
94AliMUONTracker::~AliMUONTracker()
95{
96 /// dtor
97 delete fTrackReco;
98 delete fTrackHitPatternMaker;
99 delete fClusterStore;
100 delete fTriggerStore;
101}
102
103//_____________________________________________________________________________
104AliMUONVClusterStore*
105AliMUONTracker::ClusterStore() const
106{
107 /// Return (and create if necessary) the cluster container
108 if (!fClusterStore)
109 {
110 fClusterStore = new AliMUONClusterStoreV2;
111 }
112 return fClusterStore;
113}
114
115//_____________________________________________________________________________
116Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
117{
118 /// Load triggerStore from clustersTree
119
120 ClusterStore()->Clear();
121
122 delete fTriggerStore;
123
124 if ( ! clustersTree ) {
125 AliFatal("No clustersTree");
126 return 1;
127 }
128
129 fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
130
131 if (!fTriggerStore)
132 {
133 AliError("Could not get triggerStore");
134 return 2;
135 }
136
137 ClusterStore()->Connect(*clustersTree,kFALSE);
138 fTriggerStore->Connect(*clustersTree,kFALSE);
139
140 clustersTree->GetEvent(0);
141
142 return 0;
143}
144
145//_____________________________________________________________________________
146Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
147{
148 /// Performs the tracking and store the resulting tracks in the ESD
149 AliDebug(1,"");
150 AliCodeTimerAuto("")
151
152 if (!fTrackReco) CreateTrackReconstructor();
153
154 // if the required tracking mode does not exist
155 if (!fTrackReco) return 1;
156
157 if ( ! ClusterStore() )
158 {
159 AliError("ClusterStore is NULL");
160 return 2;
161 }
162
163 if (!fTriggerStore) {
164 AliError("TriggerStore is NULL");
165 return 3;
166 }
167
168 // Make tracker tracks
169 AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
170 fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
171
172 // Make trigger tracks
173 AliMUONVTriggerTrackStore* triggerTrackStore(0x0);
174 if ( fTriggerCircuit ) {
175 triggerTrackStore = new AliMUONTriggerTrackStoreV1;
176 fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*triggerTrackStore);
177 }
178
179 // Match tracker/trigger tracks
180 if ( triggerTrackStore && fTrackHitPatternMaker ) {
181 fTrackReco->ValidateTracksWithTrigger(*trackStore,*triggerTrackStore,*fTriggerStore,*fTrackHitPatternMaker);
182 }
183
184 // Fill ESD
185 FillESD(*trackStore,esd);
186
187 // cleanup
188 delete trackStore;
189 delete triggerTrackStore;
190
191 return 0;
192}
193
194//_____________________________________________________________________________
195void AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
196{
197 /// Fill the ESD from the trackStore
198 AliDebug(1,"");
199 AliCodeTimerAuto("")
200
201 AliMUONTrack* track;
202 AliESDMuonTrack esdTrack;
203 Double_t vertex[3] = {0., 0., 0.};
204 TIter next(trackStore.CreateIterator());
205
206 // get ITS vertex
207 const AliESDVertex* esdVert = esd->GetVertex();
208 if (esdVert->GetNContributors()) {
209 esdVert->GetXYZ(vertex);
210 AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
211 }
212
213 // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
214 if (AliMUONReconstructor::GetRecoParam()->SaveFullClusterInESD() &&
215 gRandom->Uniform(100.) <= AliMUONReconstructor::GetRecoParam()->GetPercentOfFullClusterInESD()) {
216
217 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
218 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fDigitStore);
219 esd->AddMuonTrack(&esdTrack);
220 }
221
222 } else {
223
224 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
225 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
226 esd->AddMuonTrack(&esdTrack);
227 }
228
229 }
230
231}
232
233//_____________________________________________________________________________
234void AliMUONTracker::CreateTrackReconstructor()
235{
236 /// Create track reconstructor, depending on tracking mode set in RecoParam
237
238 TString opt(AliMUONReconstructor::GetRecoParam()->GetTrackingMode());
239 opt.ToUpper();
240
241 if (strstr(opt,"ORIGINAL"))
242 {
243 fTrackReco = new AliMUONTrackReconstructor(fClusterServer);
244 }
245 else if (strstr(opt,"KALMAN"))
246 {
247 fTrackReco = new AliMUONTrackReconstructorK(fClusterServer);
248 }
249 else
250 {
251 AliError(Form("tracking mode \"%s\" does not exist",opt.Data()));
252 return;
253 }
254
255 AliInfo(Form("Will use %s for tracking",fTrackReco->ClassName()));
256}
257
258//_____________________________________________________________________________
259void AliMUONTracker::UnloadClusters()
260{
261 /// Clear internal clusterStore
262
263 ClusterStore()->Clear();
264}