Adding a new TrackletVertexFinder method accepting an array of AliStrLine pointers...
[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
ad3c6eda 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)
e64fdf8a 28///
29/// \author Christian Finck and Laurent Aphecetche, SUBATECH Nantes
ee8a8d65 30//-----------------------------------------------------------------------------
196471e9 31
32#include "AliMUONTracker.h"
e64fdf8a 33
9bf6860b 34#include "AliCodeTimer.h"
35#include "AliESDEvent.h"
36#include "AliESDMuonTrack.h"
37#include "AliESDVertex.h"
38#include "AliLog.h"
39#include "AliMUONClusterStoreV2.h"
40#include "AliMUONESDInterface.h"
41#include "AliMUONLegacyClusterServer.h"
3304fa09 42#include "AliMUONRecoParam.h"
9bf6860b 43#include "AliMUONReconstructor.h"
e64fdf8a 44#include "AliMUONTrack.h"
45#include "AliMUONTrackExtrap.h"
46#include "AliMUONTrackHitPattern.h"
47#include "AliMUONTrackParam.h"
196471e9 48#include "AliMUONTrackReconstructor.h"
e64fdf8a 49#include "AliMUONTrackReconstructorK.h"
50#include "AliMUONTrackStoreV1.h"
51#include "AliMUONTriggerTrackStoreV1.h"
94e2086e 52#include "AliMUONTriggerTrack.h"
53#include "AliMUONLocalTrigger.h"
9bf6860b 54#include "AliMUONVClusterServer.h"
55#include "AliMUONVDigitStore.h"
54355f2c 56#include "AliMUONDigitStoreV1.h"
e64fdf8a 57#include "AliMUONVTriggerStore.h"
54355f2c 58#include "AliMUONDigitMaker.h"
e64fdf8a 59#include <Riostream.h>
89b4e052 60#include <TRandom.h>
9bf6860b 61#include <TTree.h>
196471e9 62
ee8a8d65 63/// \cond CLASSIMP
64ClassImp(AliMUONTracker)
65/// \endcond
66
67
196471e9 68//_____________________________________________________________________________
a0dc65b4 69AliMUONTracker::AliMUONTracker(const AliMUONRecoParam* recoParam,
70 AliMUONVClusterServer* clusterServer,
2e2d0c44 71 AliMUONVDigitStore& digitStore,
1fef78c8 72 const AliMUONDigitMaker* digitMaker,
e64fdf8a 73 const AliMUONGeometryTransformer* transformer,
683cb6c5 74 const AliMUONTriggerCircuit* triggerCircuit)
e64fdf8a 75: AliTracker(),
72dae9ff 76fkDigitMaker(digitMaker), // not owner
77fkTransformer(transformer), // not owner
78fkTriggerCircuit(triggerCircuit), // not owner
a0dc65b4 79fTrackHitPatternMaker(0x0),
80fTrackReco(0x0),
81fClusterStore(0x0),
82fTriggerStore(0x0),
83fClusterServer(clusterServer),
84fIsOwnerOfClusterServer(kFALSE),
72dae9ff 85fkDigitStore(digitStore), // not owner
a0dc65b4 86fInputClusterStore(0x0),
87fTriggerTrackStore(0x0),
72dae9ff 88fkRecoParam(recoParam)
196471e9 89{
90 /// constructor
72dae9ff 91 if (fkTransformer && fkDigitMaker)
92 fTrackHitPatternMaker = new AliMUONTrackHitPattern(recoParam,*fkTransformer,*fkDigitMaker);
89b4e052 93
9bf6860b 94 if (!fClusterServer)
95 {
96 AliInfo("No cluster server given. Will use AliMUONLegacyClusterServer");
97 fIsOwnerOfClusterServer = kTRUE;
98 }
99 else
100 {
72dae9ff 101 TIter next(fkDigitStore.CreateIterator());
2e2d0c44 102 fClusterServer->UseDigits(next,&digitStore);
9bf6860b 103
104 SetupClusterServer(*fClusterServer);
105 }
196471e9 106}
e64fdf8a 107
196471e9 108//_____________________________________________________________________________
109AliMUONTracker::~AliMUONTracker()
110{
e64fdf8a 111 /// dtor
196471e9 112 delete fTrackReco;
e64fdf8a 113 delete fTrackHitPatternMaker;
114 delete fClusterStore;
115 delete fTriggerStore;
9bf6860b 116 if ( fIsOwnerOfClusterServer ) delete fClusterServer;
117 delete fInputClusterStore;
118 delete fTriggerTrackStore;
196471e9 119}
120
121//_____________________________________________________________________________
1fef78c8 122AliMUONVClusterStore*
123AliMUONTracker::ClusterStore() const
124{
125 /// Return (and create if necessary) the cluster container
126 if (!fClusterStore)
127 {
128 fClusterStore = new AliMUONClusterStoreV2;
129 }
130 return fClusterStore;
131}
132
133//_____________________________________________________________________________
9bf6860b 134AliMUONVTriggerTrackStore*
135AliMUONTracker::TriggerTrackStore() const
136{
137 /// Return (and create if necessary) the trigger track container
138 if (!fTriggerTrackStore)
139 {
140 fTriggerTrackStore = new AliMUONTriggerTrackStoreV1;
141 }
142 return fTriggerTrackStore;
143}
144
145//_____________________________________________________________________________
3304fa09 146Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
196471e9 147{
1fef78c8 148 /// Load triggerStore from clustersTree
149
e64fdf8a 150 delete fTriggerStore;
9bf6860b 151 delete fInputClusterStore;
152 fInputClusterStore=0x0;
196471e9 153
6cfc11c3 154 if ( ! clustersTree ) {
155 AliFatal("No clustersTree");
156 return 1;
157 }
158
e64fdf8a 159 fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
160
e64fdf8a 161 if (!fTriggerStore)
162 {
163 AliError("Could not get triggerStore");
164 return 2;
165 }
166
9bf6860b 167 if ( fIsOwnerOfClusterServer )
168 {
169 fInputClusterStore = AliMUONVClusterStore::Create(*clustersTree);
170 if ( fInputClusterStore )
171 {
172 AliInfo(Form("Created %s from cluster tree",fInputClusterStore->ClassName()));
173 fInputClusterStore->Clear();
174 fInputClusterStore->Connect(*clustersTree,kFALSE);
175 }
176 delete fClusterServer;
72dae9ff 177 fClusterServer = new AliMUONLegacyClusterServer(*fkTransformer,fInputClusterStore,
a0dc65b4 178 GetRecoParam()->BypassSt4(),
179 GetRecoParam()->BypassSt5());
9bf6860b 180 SetupClusterServer(*fClusterServer);
181 }
182
e64fdf8a 183 fTriggerStore->Connect(*clustersTree,kFALSE);
184
185 clustersTree->GetEvent(0);
196471e9 186
e64fdf8a 187 return 0;
188}
196471e9 189
e64fdf8a 190//_____________________________________________________________________________
3304fa09 191Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
e64fdf8a 192{
3304fa09 193 /// Performs the tracking and store the resulting tracks in the ESD
194 AliDebug(1,"");
195 AliCodeTimerAuto("")
e64fdf8a 196
9bf6860b 197 if (!fTrackReco)
198 {
a0dc65b4 199 fTrackReco = CreateTrackReconstructor(GetRecoParam(),fClusterServer);
9bf6860b 200 }
3304fa09 201
202 // if the required tracking mode does not exist
203 if (!fTrackReco) return 1;
204
1fef78c8 205 if ( ! ClusterStore() )
206 {
e64fdf8a 207 AliError("ClusterStore is NULL");
6cfc11c3 208 return 2;
e64fdf8a 209 }
6cfc11c3 210
3304fa09 211 if (!fTriggerStore) {
e64fdf8a 212 AliError("TriggerStore is NULL");
6cfc11c3 213 return 3;
e64fdf8a 214 }
1fef78c8 215
9bf6860b 216 // Make trigger tracks
72dae9ff 217 if ( fkTriggerCircuit )
9bf6860b 218 {
219 TriggerTrackStore()->Clear();
72dae9ff 220 fTrackReco->EventReconstructTrigger(*fkTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
9bf6860b 221 }
222
a0dc65b4 223 if ( ( GetRecoParam()->BypassSt4() ||
224 GetRecoParam()->BypassSt5() ) &&
de487b6e 225 TriggerTrackStore()->GetSize() > 5 )
d7820279 226 {
227 // Hard cut to reject shower events
228
229 AliCodeTimerAuto("MUON Shower events");
230
231 AliWarning(Form("Probably got a shower event (%d trigger tracks). Will not reconstruct tracks.",
232 TriggerTrackStore()->GetSize()));
233
234 return 0;
235 }
236
e64fdf8a 237 // Make tracker tracks
3304fa09 238 AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
1fef78c8 239 fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
e64fdf8a 240
3304fa09 241 // Match tracker/trigger tracks
9bf6860b 242 if ( fTrackHitPatternMaker )
243 {
244 fTrackReco->ValidateTracksWithTrigger(*trackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
e64fdf8a 245 }
246
3304fa09 247 // Fill ESD
e64fdf8a 248 FillESD(*trackStore,esd);
249
250 // cleanup
251 delete trackStore;
e64fdf8a 252
253 return 0;
254}
196471e9 255
e64fdf8a 256//_____________________________________________________________________________
72dae9ff 257void AliMUONTracker::FillESD(const AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
e64fdf8a 258{
259 /// Fill the ESD from the trackStore
e64fdf8a 260 AliDebug(1,"");
2060b217 261 AliCodeTimerAuto("")
e64fdf8a 262
103e6575 263 // get ITS vertex
b1fea02e 264 Double_t vertex[3] = {0., 0., 0.};
e64fdf8a 265 const AliESDVertex* esdVert = esd->GetVertex();
103e6575 266 if (esdVert->GetNContributors()) {
e64fdf8a 267 esdVert->GetXYZ(vertex);
268 AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
269 }
270
103e6575 271 // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
b1fea02e 272 AliMUONTrack* track;
273 AliMUONLocalTrigger* locTrg;
274 AliESDMuonTrack esdTrack;
275 TIter next(trackStore.CreateIterator());
a0dc65b4 276 if (GetRecoParam()->SaveFullClusterInESD() &&
277 gRandom->Uniform(100.) <= GetRecoParam()->GetPercentOfFullClusterInESD()) {
e64fdf8a 278
103e6575 279 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
b1fea02e 280
281 if (track->GetMatchTrigger() > 0) {
282 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
72dae9ff 283 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore, locTrg);
284 } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore);
b1fea02e 285
103e6575 286 esd->AddMuonTrack(&esdTrack);
287 }
89b4e052 288
103e6575 289 } else {
89b4e052 290
103e6575 291 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
b1fea02e 292
293 if (track->GetMatchTrigger() > 0) {
294 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
295 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, 0x0, locTrg);
296 } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
297
103e6575 298 esd->AddMuonTrack(&esdTrack);
60765b06 299 }
e64fdf8a 300
103e6575 301 }
b1fea02e 302
303 // fill the local trigger decisions not matched with tracks (associate them to "ghost" tracks)
304 UInt_t ghostId = 0xFFFFFFFF - 1;
94e2086e 305 Bool_t matched = kFALSE;
94e2086e 306 AliMUONTriggerTrack *triggerTrack;
54355f2c 307
308 // Needed to calculate the hit pattern for ghosts
309 AliMUONDigitStoreV1 digitStore;
310 fkDigitMaker->TriggerToDigitsStore(*fTriggerStore,digitStore);
311
94e2086e 312 TIter itTriggerTrack(fTriggerTrackStore->CreateIterator());
b1fea02e 313 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack()) ) ) {
314
315 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(triggerTrack->GetLoTrgNum()));
316
317 // check if this local trigger has already been matched
318 TIter itTrack(trackStore.CreateIterator());
319 while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) ) {
320 matched = (track->LoCircuit() == locTrg->LoCircuit());
321 if (matched) break;
94e2086e 322 }
b1fea02e 323 if (matched) continue;
324
54355f2c 325 UShort_t pattern = fTrackHitPatternMaker->GetHitPattern(triggerTrack, digitStore);
326
327 AliMUONESDInterface::MUONToESD(*locTrg, esdTrack, ghostId, pattern);
b1fea02e 328
329 esd->AddMuonTrack(&esdTrack);
330 ghostId -= 1;
331 }
103e6575 332
196471e9 333}
334
335//_____________________________________________________________________________
a0dc65b4 336AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
196471e9 337{
3304fa09 338 /// Create track reconstructor, depending on tracking mode set in RecoParam
339
9bf6860b 340 AliMUONVTrackReconstructor* trackReco(0x0);
341
a0dc65b4 342 TString opt(recoParam->GetTrackingMode());
3304fa09 343 opt.ToUpper();
e64fdf8a 344
3304fa09 345 if (strstr(opt,"ORIGINAL"))
e64fdf8a 346 {
a0dc65b4 347 trackReco = new AliMUONTrackReconstructor(recoParam,clusterServer);
e64fdf8a 348 }
3304fa09 349 else if (strstr(opt,"KALMAN"))
e64fdf8a 350 {
a0dc65b4 351 trackReco = new AliMUONTrackReconstructorK(recoParam,clusterServer);
e64fdf8a 352 }
3304fa09 353 else
354 {
9bf6860b 355 AliErrorClass(Form("tracking mode \"%s\" does not exist",opt.Data()));
356 return 0x0;
3304fa09 357 }
358
9bf6860b 359 AliInfoClass(Form("Will use %s for tracking",trackReco->ClassName()));
360
361 return trackReco;
e64fdf8a 362}
196471e9 363
e64fdf8a 364//_____________________________________________________________________________
3304fa09 365void AliMUONTracker::UnloadClusters()
e64fdf8a 366{
1fef78c8 367 /// Clear internal clusterStore
368
9bf6860b 369 delete fInputClusterStore;
370 fInputClusterStore = 0x0;
196471e9 371}
9bf6860b 372
373
374//_____________________________________________________________________________
375void
376AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
377{
378 /// Setup the cluster server
379
a0dc65b4 380 if ( GetRecoParam()->BypassSt4() ||
381 GetRecoParam()->BypassSt5() )
9bf6860b 382 {
383 Bool_t ok = clusterServer.UseTriggerTrackStore(TriggerTrackStore());
384
de487b6e 385 TString msg1;
386 TString msg2;
387
a0dc65b4 388 if ( GetRecoParam()->BypassSt45() )
de487b6e 389 {
390 msg1 = "STATIONS 4 AND 5";
391 msg2 = "THOSE TWO STATIONS";
392 }
a0dc65b4 393 else if ( GetRecoParam()->BypassSt4() )
de487b6e 394 {
395 msg1 = "STATION 4";
396 msg2 = "THAT STATION";
397 }
a0dc65b4 398 else if ( GetRecoParam()->BypassSt5() )
de487b6e 399 {
400 msg1 = "STATION 5";
401 msg2 = "THAT STATION";
402 }
403
9bf6860b 404 if ( ok )
9bf6860b 405 {
de487b6e 406 AliWarning(Form("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN %s, "
407 "THUS BYPASSING REAL CLUSTERS IN %s!!!",msg1.Data(),msg2.Data()));
9bf6860b 408 }
409 else
410 {
de487b6e 411 AliWarning("BYPASSING OF ST4 AND/OR 5 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");
9bf6860b 412 }
413 }
414}
415
416