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