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