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