Bug in DQM agent resetting solved
[u/mrichter/AliRoot.git] / MUON / AliMUONTracker.cxx
... / ...
CommitLineData
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
16/* $Id$ */
17
18//-----------------------------------------------------------------------------
19/// \class AliMUONTracker
20///
21/// Steering class for use in global tracking framework;
22/// reconstruct tracks from recpoints
23///
24/// Actual tracking is performed by some AliMUONVTrackReconstructor children
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)
28///
29/// \author Christian Finck and Laurent Aphecetche, SUBATECH Nantes
30//-----------------------------------------------------------------------------
31
32#include "AliMUONTracker.h"
33
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"
42#include "AliMUONRecoParam.h"
43#include "AliMUONReconstructor.h"
44#include "AliMUONTrack.h"
45#include "AliMUONTrackExtrap.h"
46#include "AliMUONTrackHitPattern.h"
47#include "AliMUONTrackParam.h"
48#include "AliMUONTrackReconstructor.h"
49#include "AliMUONTrackReconstructorK.h"
50#include "AliMUONTrackStoreV1.h"
51#include "AliMUONTriggerTrackStoreV1.h"
52#include "AliMUONTriggerTrack.h"
53#include "AliMUONLocalTrigger.h"
54#include "AliMUONVClusterServer.h"
55#include "AliMUONVDigitStore.h"
56#include "AliMUONVTriggerStore.h"
57#include "AliMUONDigitMaker.h"
58#include <Riostream.h>
59#include <TRandom.h>
60#include <TTree.h>
61
62/// \cond CLASSIMP
63ClassImp(AliMUONTracker)
64/// \endcond
65
66
67//_____________________________________________________________________________
68AliMUONTracker::AliMUONTracker(const AliMUONRecoParam* recoParam,
69 AliMUONVClusterServer* clusterServer,
70 AliMUONVDigitStore& digitStore,
71 const AliMUONDigitMaker* digitMaker,
72 const AliMUONGeometryTransformer* transformer,
73 const AliMUONTriggerCircuit* triggerCircuit)
74: AliTracker(),
75fkDigitMaker(digitMaker), // not owner
76fkTransformer(transformer), // not owner
77fkTriggerCircuit(triggerCircuit), // not owner
78fTrackHitPatternMaker(0x0),
79fTrackReco(0x0),
80fClusterStore(0x0),
81fTriggerStore(0x0),
82fClusterServer(clusterServer),
83fIsOwnerOfClusterServer(kFALSE),
84fkDigitStore(digitStore), // not owner
85fInputClusterStore(0x0),
86fTriggerTrackStore(0x0),
87fkRecoParam(recoParam)
88{
89 /// constructor
90 if (fkTransformer && fkDigitMaker)
91 fTrackHitPatternMaker = new AliMUONTrackHitPattern(recoParam,*fkTransformer,*fkDigitMaker);
92
93 if (!fClusterServer)
94 {
95 AliDebug(1,"No cluster server given. Will use AliMUONLegacyClusterServer");
96 fIsOwnerOfClusterServer = kTRUE;
97 }
98 else
99 {
100 TIter next(fkDigitStore.CreateIterator());
101 fClusterServer->UseDigits(next,&digitStore);
102
103 SetupClusterServer(*fClusterServer);
104 }
105}
106
107//_____________________________________________________________________________
108AliMUONTracker::~AliMUONTracker()
109{
110 /// dtor
111 delete fTrackReco;
112 delete fTrackHitPatternMaker;
113 delete fClusterStore;
114 delete fTriggerStore;
115 if ( fIsOwnerOfClusterServer ) delete fClusterServer;
116 delete fInputClusterStore;
117 delete fTriggerTrackStore;
118}
119
120//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
145Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
146{
147 /// Load triggerStore from clustersTree
148
149 delete fTriggerStore;
150 delete fInputClusterStore;
151 fInputClusterStore=0x0;
152
153 if ( ! clustersTree ) {
154 AliFatal("No clustersTree");
155 return 1;
156 }
157
158 fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
159
160 if (!fTriggerStore)
161 {
162 AliError("Could not get triggerStore");
163 return 2;
164 }
165
166 if ( fIsOwnerOfClusterServer )
167 {
168 fInputClusterStore = AliMUONVClusterStore::Create(*clustersTree);
169 if ( fInputClusterStore )
170 {
171 AliDebug(1,Form("Created %s from cluster tree",fInputClusterStore->ClassName()));
172 fInputClusterStore->Clear();
173 fInputClusterStore->Connect(*clustersTree,kFALSE);
174 }
175 delete fClusterServer;
176 fClusterServer = new AliMUONLegacyClusterServer(*fkTransformer,fInputClusterStore,
177 GetRecoParam()->BypassSt4(),
178 GetRecoParam()->BypassSt5());
179 SetupClusterServer(*fClusterServer);
180 }
181
182 fTriggerStore->Connect(*clustersTree,kFALSE);
183
184 clustersTree->GetEvent(0);
185
186 return 0;
187}
188
189//_____________________________________________________________________________
190Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
191{
192 /// Performs the tracking and store the resulting tracks in the ESD
193 AliDebug(1,"");
194 AliCodeTimerAuto("",0)
195
196 if (!fTrackReco)
197 {
198 fTrackReco = CreateTrackReconstructor(GetRecoParam(),fClusterServer);
199 }
200
201 // if the required tracking mode does not exist
202 if (!fTrackReco) return 1;
203
204 if ( ! ClusterStore() )
205 {
206 AliError("ClusterStore is NULL");
207 return 2;
208 }
209
210 if (!fTriggerStore) {
211 AliError("TriggerStore is NULL");
212 return 3;
213 }
214
215 // Make trigger tracks
216 if ( fkTriggerCircuit )
217 {
218 TriggerTrackStore()->Clear();
219 fTrackReco->EventReconstructTrigger(*fkTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
220 }
221
222 if ( TriggerTrackStore()->GetSize() > GetRecoParam()->GetMaxTriggerTracks() )
223 {
224 // cut to reject shower events
225
226 AliCodeTimerAuto("MUON Shower events",1);
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
234 // Make tracker tracks
235 AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
236 fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
237
238 // Match tracker/trigger tracks
239 if ( fTrackHitPatternMaker )
240 {
241 fTrackReco->ValidateTracksWithTrigger(*trackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
242 }
243
244 // Fill ESD
245 FillESD(*trackStore,esd);
246
247 // cleanup
248 delete trackStore;
249
250 return 0;
251}
252
253//_____________________________________________________________________________
254void AliMUONTracker::FillESD(const AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
255{
256 /// Fill the ESD from the trackStore
257 AliDebug(1,"");
258 AliCodeTimerAuto("",0)
259
260 // get ITS vertex
261 Double_t vertex[3] = {0., 0., 0.};
262 const AliESDVertex* esdVert = esd->GetVertex();
263 if (esdVert->GetNContributors()) {
264 esdVert->GetXYZ(vertex);
265 AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
266 }
267
268 // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
269 AliMUONTrack* track;
270 AliMUONLocalTrigger* locTrg;
271 AliESDMuonTrack esdTrack;
272 TIter next(trackStore.CreateIterator());
273 if (GetRecoParam()->SaveFullClusterInESD() &&
274 gRandom->Uniform(100.) <= GetRecoParam()->GetPercentOfFullClusterInESD()) {
275
276 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
277
278 if (track->GetMatchTrigger() > 0) {
279 locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
280 AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore, locTrg);
281 } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore);
282
283 esd->AddMuonTrack(&esdTrack);
284 }
285
286 } else {
287
288 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
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
295 esd->AddMuonTrack(&esdTrack);
296 }
297
298 }
299
300 // fill the local trigger decisions not matched with tracks (associate them to "ghost" tracks)
301 UInt_t ghostId = 0xFFFFFFFF - 1;
302 Bool_t matched = kFALSE;
303 AliMUONTriggerTrack *triggerTrack;
304 TIter itTriggerTrack(fTriggerTrackStore->CreateIterator());
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;
314 }
315 if (matched) continue;
316
317 AliMUONESDInterface::MUONToESD(*locTrg, esdTrack, ghostId, triggerTrack);
318
319 esd->AddMuonTrack(&esdTrack);
320 ghostId -= 1;
321 }
322
323}
324
325//_____________________________________________________________________________
326AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
327{
328 /// Create track reconstructor, depending on tracking mode set in RecoParam
329
330 AliMUONVTrackReconstructor* trackReco(0x0);
331
332 TString opt(recoParam->GetTrackingMode());
333 opt.ToUpper();
334
335 if (strstr(opt,"ORIGINAL"))
336 {
337 trackReco = new AliMUONTrackReconstructor(recoParam,clusterServer);
338 }
339 else if (strstr(opt,"KALMAN"))
340 {
341 trackReco = new AliMUONTrackReconstructorK(recoParam,clusterServer);
342 }
343 else
344 {
345 AliErrorClass(Form("tracking mode \"%s\" does not exist",opt.Data()));
346 return 0x0;
347 }
348
349 AliDebugClass(1,Form("Will use %s for tracking",trackReco->ClassName()));
350
351 return trackReco;
352}
353
354//_____________________________________________________________________________
355void AliMUONTracker::UnloadClusters()
356{
357 /// Clear internal clusterStore
358
359 delete fInputClusterStore;
360 fInputClusterStore = 0x0;
361}
362
363
364//_____________________________________________________________________________
365void
366AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
367{
368 /// Setup the cluster server
369
370 if ( GetRecoParam()->BypassSt4() ||
371 GetRecoParam()->BypassSt5() )
372 {
373 Bool_t ok = clusterServer.UseTriggerTrackStore(TriggerTrackStore());
374
375 TString msg1;
376 TString msg2;
377
378 if ( GetRecoParam()->BypassSt45() )
379 {
380 msg1 = "STATIONS 4 AND 5";
381 msg2 = "THOSE TWO STATIONS";
382 }
383 else if ( GetRecoParam()->BypassSt4() )
384 {
385 msg1 = "STATION 4";
386 msg2 = "THAT STATION";
387 }
388 else if ( GetRecoParam()->BypassSt5() )
389 {
390 msg1 = "STATION 5";
391 msg2 = "THAT STATION";
392 }
393
394 if ( ok )
395 {
396 AliWarning(Form("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN %s, "
397 "THUS BYPASSING REAL CLUSTERS IN %s!!!",msg1.Data(),msg2.Data()));
398 }
399 else
400 {
401 AliWarning("BYPASSING OF ST4 AND/OR 5 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");
402 }
403 }
404}
405
406