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