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