]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTracker.cxx
Main changes:
[u/mrichter/AliRoot.git] / MUON / AliMUONTracker.cxx
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
63 ClassImp(AliMUONTracker)
64 /// \endcond
65
66
67 //_____________________________________________________________________________
68 AliMUONTracker::AliMUONTracker(const AliMUONRecoParam* recoParam,
69                                AliMUONVClusterServer* clusterServer,
70                                AliMUONVDigitStore& digitStore,
71                                const AliMUONDigitMaker* digitMaker,
72                                const AliMUONGeometryTransformer* transformer,
73                                const AliMUONTriggerCircuit* triggerCircuit)
74 : AliTracker(),
75 fkDigitMaker(digitMaker), // not owner
76 fkTransformer(transformer), // not owner
77 fkTriggerCircuit(triggerCircuit), // not owner
78 fTrackHitPatternMaker(0x0),
79 fTrackReco(0x0),
80 fClusterStore(0x0),
81 fTriggerStore(0x0),
82 fClusterServer(clusterServer), 
83 fIsOwnerOfClusterServer(kFALSE),
84 fkDigitStore(digitStore), // not owner
85 fInputClusterStore(0x0),
86 fTriggerTrackStore(0x0),
87 fkRecoParam(recoParam)
88 {
89   /// constructor
90   if (fkTransformer && fkDigitMaker)
91     fTrackHitPatternMaker = new AliMUONTrackHitPattern(recoParam,*fkTransformer,*fkDigitMaker);
92   
93   if (!fClusterServer)
94   {
95     AliInfo("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 //_____________________________________________________________________________
108 AliMUONTracker::~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 //_____________________________________________________________________________
121 AliMUONVClusterStore*
122 AliMUONTracker::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 //_____________________________________________________________________________
133 AliMUONVTriggerTrackStore*
134 AliMUONTracker::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 //_____________________________________________________________________________
145 Int_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       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(*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 //_____________________________________________________________________________
190 Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
191 {
192   /// Performs the tracking and store the resulting tracks in the ESD
193   AliDebug(1,"");
194   AliCodeTimerAuto("")
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 ( ( GetRecoParam()->BypassSt4() || 
223                                  GetRecoParam()->BypassSt5() ) && 
224                         TriggerTrackStore()->GetSize() > 5 ) 
225   {
226     // Hard cut to reject shower events
227     
228     AliCodeTimerAuto("MUON Shower events");
229
230     AliWarning(Form("Probably got a shower event (%d trigger tracks). Will not reconstruct tracks.",
231                     TriggerTrackStore()->GetSize()));
232     
233     return 0;
234   }
235        
236   // Make tracker tracks
237   AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
238   fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
239   
240   // Match tracker/trigger tracks
241   if ( fTrackHitPatternMaker ) 
242   {
243     fTrackReco->ValidateTracksWithTrigger(*trackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
244   }
245   
246   // Fill ESD
247   FillESD(*trackStore,esd);
248   
249   // cleanup
250   delete trackStore;
251   
252   return 0;
253 }
254
255 //_____________________________________________________________________________
256 void AliMUONTracker::FillESD(const AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
257 {
258   /// Fill the ESD from the trackStore
259   AliDebug(1,"");
260   AliCodeTimerAuto("")
261   
262   // get ITS vertex
263   Double_t vertex[3] = {0., 0., 0.};
264   const AliESDVertex* esdVert = esd->GetVertex(); 
265   if (esdVert->GetNContributors()) {
266     esdVert->GetXYZ(vertex);
267     AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
268   }
269   
270   // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
271   AliMUONTrack* track;
272   AliMUONLocalTrigger* locTrg;
273   AliESDMuonTrack esdTrack;
274   TIter next(trackStore.CreateIterator());
275   if (GetRecoParam()->SaveFullClusterInESD() && 
276       gRandom->Uniform(100.) <= GetRecoParam()->GetPercentOfFullClusterInESD()) {
277     
278     while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
279       
280       if (track->GetMatchTrigger() > 0) {
281         locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
282         AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore, locTrg);
283       } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fkDigitStore);
284       
285       esd->AddMuonTrack(&esdTrack);
286     }
287     
288   } else {
289     
290     while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
291       
292       if (track->GetMatchTrigger() > 0) {
293         locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(track->LoCircuit()));
294         AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, 0x0, locTrg);
295       } else AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
296       
297       esd->AddMuonTrack(&esdTrack);
298     }
299     
300   }
301   
302   // fill the local trigger decisions not matched with tracks (associate them to "ghost" tracks)
303   UInt_t ghostId = 0xFFFFFFFF - 1;
304   Bool_t matched = kFALSE;
305   AliMUONTriggerTrack *triggerTrack;
306   TIter itTriggerTrack(fTriggerTrackStore->CreateIterator());
307   while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack()) ) ) {
308     
309     locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(triggerTrack->GetLoTrgNum()));
310     
311     // check if this local trigger has already been matched
312     TIter itTrack(trackStore.CreateIterator());
313     while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) ) {
314       matched = (track->LoCircuit() == locTrg->LoCircuit());
315       if (matched) break;
316     }
317     if (matched) continue;
318
319     AliMUONESDInterface::MUONToESD(*locTrg, esdTrack, ghostId, triggerTrack);
320     
321     esd->AddMuonTrack(&esdTrack);
322     ghostId -= 1;
323   }
324   
325 }
326
327 //_____________________________________________________________________________
328 AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const AliMUONRecoParam* recoParam, AliMUONVClusterServer* clusterServer)
329 {
330   /// Create track reconstructor, depending on tracking mode set in RecoParam
331   
332   AliMUONVTrackReconstructor* trackReco(0x0);
333   
334   TString opt(recoParam->GetTrackingMode());
335   opt.ToUpper();
336   
337   if (strstr(opt,"ORIGINAL"))
338   {
339     trackReco = new AliMUONTrackReconstructor(recoParam,clusterServer);
340   }
341   else if (strstr(opt,"KALMAN"))
342   {
343     trackReco = new AliMUONTrackReconstructorK(recoParam,clusterServer);
344   }
345   else
346   {
347     AliErrorClass(Form("tracking mode \"%s\" does not exist",opt.Data()));
348     return 0x0;
349   }
350   
351   AliInfoClass(Form("Will use %s for tracking",trackReco->ClassName()));
352   
353   return trackReco;
354 }
355
356 //_____________________________________________________________________________
357 void AliMUONTracker::UnloadClusters()
358 {
359   /// Clear internal clusterStore
360   
361   delete fInputClusterStore;
362   fInputClusterStore = 0x0;
363 }
364
365
366 //_____________________________________________________________________________
367 void
368 AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
369 {
370   /// Setup the cluster server
371   
372   if ( GetRecoParam()->BypassSt4() ||
373                          GetRecoParam()->BypassSt5() )
374   {
375     Bool_t ok = clusterServer.UseTriggerTrackStore(TriggerTrackStore());
376   
377                 TString msg1;
378                 TString msg2;
379                 
380                 if ( GetRecoParam()->BypassSt45() )
381                 {
382                         msg1 = "STATIONS 4 AND 5";
383                         msg2 = "THOSE TWO STATIONS";
384                 }
385                 else if ( GetRecoParam()->BypassSt4() )
386                 {
387                         msg1 = "STATION 4";
388                         msg2 = "THAT STATION";
389                 }
390                 else if ( GetRecoParam()->BypassSt5() )
391                 {
392                         msg1 = "STATION 5";
393                         msg2 = "THAT STATION";
394                 }
395                 
396     if ( ok ) 
397     {
398       AliWarning(Form("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN %s, "
399                                                                                         "THUS BYPASSING REAL CLUSTERS IN %s!!!",msg1.Data(),msg2.Data()));    
400     }
401     else
402     {
403       AliWarning("BYPASSING OF ST4 AND/OR 5 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");    
404     }
405   }
406 }
407
408