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