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