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