Bug in DQM agent resetting solved
[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"
54355f2c 57#include "AliMUONDigitMaker.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,
1fef78c8 71 const AliMUONDigitMaker* digitMaker,
e64fdf8a 72 const AliMUONGeometryTransformer* transformer,
683cb6c5 73 const AliMUONTriggerCircuit* triggerCircuit)
e64fdf8a 74: AliTracker(),
72dae9ff 75fkDigitMaker(digitMaker), // not owner
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),
72dae9ff 87fkRecoParam(recoParam)
196471e9 88{
89 /// constructor
72dae9ff 90 if (fkTransformer && fkDigitMaker)
91 fTrackHitPatternMaker = new AliMUONTrackHitPattern(recoParam,*fkTransformer,*fkDigitMaker);
89b4e052 92
9bf6860b 93 if (!fClusterServer)
94 {
da448a15 95 AliDebug(1,"No cluster server given. Will use AliMUONLegacyClusterServer");
9bf6860b 96 fIsOwnerOfClusterServer = kTRUE;
97 }
98 else
99 {
72dae9ff 100 TIter next(fkDigitStore.CreateIterator());
2e2d0c44 101 fClusterServer->UseDigits(next,&digitStore);
9bf6860b 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 {
da448a15 171 AliDebug(1,Form("Created %s from cluster tree",fInputClusterStore->ClassName()));
9bf6860b 172 fInputClusterStore->Clear();
173 fInputClusterStore->Connect(*clustersTree,kFALSE);
174 }
175 delete fClusterServer;
72dae9ff 176 fClusterServer = new AliMUONLegacyClusterServer(*fkTransformer,fInputClusterStore,
a0dc65b4 177 GetRecoParam()->BypassSt4(),
178 GetRecoParam()->BypassSt5());
9bf6860b 179 SetupClusterServer(*fClusterServer);
180 }
181
e64fdf8a 182 fTriggerStore->Connect(*clustersTree,kFALSE);
183
184 clustersTree->GetEvent(0);
196471e9 185
e64fdf8a 186 return 0;
187}
196471e9 188
e64fdf8a 189//_____________________________________________________________________________
3304fa09 190Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
e64fdf8a 191{
3304fa09 192 /// Performs the tracking and store the resulting tracks in the ESD
193 AliDebug(1,"");
99c136e1 194 AliCodeTimerAuto("",0)
e64fdf8a 195
9bf6860b 196 if (!fTrackReco)
197 {
a0dc65b4 198 fTrackReco = CreateTrackReconstructor(GetRecoParam(),fClusterServer);
9bf6860b 199 }
3304fa09 200
201 // if the required tracking mode does not exist
202 if (!fTrackReco) return 1;
203
1fef78c8 204 if ( ! ClusterStore() )
205 {
e64fdf8a 206 AliError("ClusterStore is NULL");
6cfc11c3 207 return 2;
e64fdf8a 208 }
6cfc11c3 209
3304fa09 210 if (!fTriggerStore) {
e64fdf8a 211 AliError("TriggerStore is NULL");
6cfc11c3 212 return 3;
e64fdf8a 213 }
1fef78c8 214
9bf6860b 215 // Make trigger tracks
72dae9ff 216 if ( fkTriggerCircuit )
9bf6860b 217 {
218 TriggerTrackStore()->Clear();
72dae9ff 219 fTrackReco->EventReconstructTrigger(*fkTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
9bf6860b 220 }
221
89c8d66d 222 if ( TriggerTrackStore()->GetSize() > GetRecoParam()->GetMaxTriggerTracks() )
d7820279 223 {
89c8d66d 224 // cut to reject shower events
d7820279 225
dd0be8a7 226 AliCodeTimerAuto("MUON Shower events",1);
d7820279 227
228 AliWarning(Form("Probably got a shower event (%d trigger tracks). Will not reconstruct tracks.",
229 TriggerTrackStore()->GetSize()));
230
231 return 0;
232 }
233
e64fdf8a 234 // Make tracker tracks
3304fa09 235 AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
1fef78c8 236 fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
e64fdf8a 237
3304fa09 238 // Match tracker/trigger tracks
9bf6860b 239 if ( fTrackHitPatternMaker )
240 {
241 fTrackReco->ValidateTracksWithTrigger(*trackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
e64fdf8a 242 }
243
3304fa09 244 // Fill ESD
e64fdf8a 245 FillESD(*trackStore,esd);
246
247 // cleanup
248 delete trackStore;
e64fdf8a 249
250 return 0;
251}
196471e9 252
e64fdf8a 253//_____________________________________________________________________________
72dae9ff 254void AliMUONTracker::FillESD(const AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
e64fdf8a 255{
256 /// Fill the ESD from the trackStore
e64fdf8a 257 AliDebug(1,"");
99c136e1 258 AliCodeTimerAuto("",0)
e64fdf8a 259
103e6575 260 // get ITS vertex
b1fea02e 261 Double_t vertex[3] = {0., 0., 0.};
e64fdf8a 262 const AliESDVertex* esdVert = esd->GetVertex();
103e6575 263 if (esdVert->GetNContributors()) {
e64fdf8a 264 esdVert->GetXYZ(vertex);
265 AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
266 }
267
103e6575 268 // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
b1fea02e 269 AliMUONTrack* track;
270 AliMUONLocalTrigger* locTrg;
271 AliESDMuonTrack esdTrack;
272 TIter next(trackStore.CreateIterator());
a0dc65b4 273 if (GetRecoParam()->SaveFullClusterInESD() &&
274 gRandom->Uniform(100.) <= GetRecoParam()->GetPercentOfFullClusterInESD()) {
e64fdf8a 275
103e6575 276 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
b1fea02e 277
278 if (track->GetMatchTrigger() > 0) {
279 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
72dae9ff 280 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore, locTrg);
281 } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore);
b1fea02e 282
103e6575 283 esd->AddMuonTrack(&esdTrack);
284 }
89b4e052 285
103e6575 286 } else {
89b4e052 287
103e6575 288 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
b1fea02e 289
290 if (track->GetMatchTrigger() > 0) {
291 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
292 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, 0x0, locTrg);
293 } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
294
103e6575 295 esd->AddMuonTrack(&esdTrack);
60765b06 296 }
e64fdf8a 297
103e6575 298 }
b1fea02e 299
300 // fill the local trigger decisions not matched with tracks (associate them to "ghost" tracks)
301 UInt_t ghostId = 0xFFFFFFFF - 1;
94e2086e 302 Bool_t matched = kFALSE;
94e2086e 303 AliMUONTriggerTrack *triggerTrack;
94e2086e 304 TIter itTriggerTrack(fTriggerTrackStore->CreateIterator());
b1fea02e 305 while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack()) ) ) {
306
307 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(triggerTrack->GetLoTrgNum()));
308
309 // check if this local trigger has already been matched
310 TIter itTrack(trackStore.CreateIterator());
311 while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) ) {
312 matched = (track->LoCircuit() == locTrg->LoCircuit());
313 if (matched) break;
94e2086e 314 }
b1fea02e 315 if (matched) continue;
54355f2c 316
67c201be 317 AliMUONESDInterface::MUONToESD(*locTrg, esdTrack, ghostId, triggerTrack);
b1fea02e 318
319 esd->AddMuonTrack(&esdTrack);
320 ghostId -= 1;
321 }
103e6575 322
196471e9 323}
324
325//_____________________________________________________________________________
a0dc65b4 326AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
196471e9 327{
3304fa09 328 /// Create track reconstructor, depending on tracking mode set in RecoParam
329
9bf6860b 330 AliMUONVTrackReconstructor* trackReco(0x0);
331
a0dc65b4 332 TString opt(recoParam->GetTrackingMode());
3304fa09 333 opt.ToUpper();
e64fdf8a 334
3304fa09 335 if (strstr(opt,"ORIGINAL"))
e64fdf8a 336 {
a0dc65b4 337 trackReco = new AliMUONTrackReconstructor(recoParam,clusterServer);
e64fdf8a 338 }
3304fa09 339 else if (strstr(opt,"KALMAN"))
e64fdf8a 340 {
a0dc65b4 341 trackReco = new AliMUONTrackReconstructorK(recoParam,clusterServer);
e64fdf8a 342 }
3304fa09 343 else
344 {
9bf6860b 345 AliErrorClass(Form("tracking mode \"%s\" does not exist",opt.Data()));
346 return 0x0;
3304fa09 347 }
348
da448a15 349 AliDebugClass(1,Form("Will use %s for tracking",trackReco->ClassName()));
9bf6860b 350
351 return trackReco;
e64fdf8a 352}
196471e9 353
e64fdf8a 354//_____________________________________________________________________________
3304fa09 355void AliMUONTracker::UnloadClusters()
e64fdf8a 356{
1fef78c8 357 /// Clear internal clusterStore
358
9bf6860b 359 delete fInputClusterStore;
360 fInputClusterStore = 0x0;
196471e9 361}
9bf6860b 362
363
364//_____________________________________________________________________________
365void
366AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
367{
368 /// Setup the cluster server
369
a0dc65b4 370 if ( GetRecoParam()->BypassSt4() ||
371 GetRecoParam()->BypassSt5() )
9bf6860b 372 {
373 Bool_t ok = clusterServer.UseTriggerTrackStore(TriggerTrackStore());
374
de487b6e 375 TString msg1;
376 TString msg2;
377
a0dc65b4 378 if ( GetRecoParam()->BypassSt45() )
de487b6e 379 {
380 msg1 = "STATIONS 4 AND 5";
381 msg2 = "THOSE TWO STATIONS";
382 }
a0dc65b4 383 else if ( GetRecoParam()->BypassSt4() )
de487b6e 384 {
385 msg1 = "STATION 4";
386 msg2 = "THAT STATION";
387 }
a0dc65b4 388 else if ( GetRecoParam()->BypassSt5() )
de487b6e 389 {
390 msg1 = "STATION 5";
391 msg2 = "THAT STATION";
392 }
393
9bf6860b 394 if ( ok )
9bf6860b 395 {
de487b6e 396 AliWarning(Form("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN %s, "
397 "THUS BYPASSING REAL CLUSTERS IN %s!!!",msg1.Data(),msg2.Data()));
9bf6860b 398 }
399 else
400 {
de487b6e 401 AliWarning("BYPASSING OF ST4 AND/OR 5 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");
9bf6860b 402 }
403 }
404}
405
406