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