]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTracker.cxx
reducing macro to minimum AliReconstruction functionality, disable QA and TriggerESD...
[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(AliMUONVClusterServer* clusterServer,
71                                const AliMUONVDigitStore& digitStore,
72                                const AliMUONDigitMaker* digitMaker,
73                                const AliMUONGeometryTransformer* transformer,
74                                const AliMUONTriggerCircuit* triggerCircuit)
75 : AliTracker(),
76   fDigitMaker(digitMaker), // not owner
77   fTransformer(transformer), // not owner
78   fTriggerCircuit(triggerCircuit), // not owner
79   fTrackHitPatternMaker(0x0),
80   fTrackReco(0x0),
81   fClusterStore(0x0),
82   fTriggerStore(0x0),
83   fClusterServer(clusterServer), 
84   fIsOwnerOfClusterServer(kFALSE),
85   fDigitStore(digitStore), // not owner
86   fInputClusterStore(0x0),
87   fTriggerTrackStore(0x0)
88 {
89   /// constructor
90   if (fTransformer && fDigitMaker)
91     fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
92   
93   if (!fClusterServer)
94   {
95     AliInfo("No cluster server given. Will use AliMUONLegacyClusterServer");
96     fIsOwnerOfClusterServer = kTRUE;
97   }
98   else
99   {
100     TIter next(fDigitStore.CreateIterator());
101     fClusterServer->UseDigits(next);
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(*fTransformer,fInputClusterStore);
177     SetupClusterServer(*fClusterServer);
178   }
179   
180   fTriggerStore->Connect(*clustersTree,kFALSE);
181   
182   clustersTree->GetEvent(0);
183
184   return 0;
185 }
186
187 //_____________________________________________________________________________
188 Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
189 {
190   /// Performs the tracking and store the resulting tracks in the ESD
191   AliDebug(1,"");
192   AliCodeTimerAuto("")
193   
194   if (!fTrackReco) 
195   {
196     fTrackReco = CreateTrackReconstructor(AliMUONReconstructor::GetRecoParam()->GetTrackingMode(),fClusterServer);
197   }
198   
199   // if the required tracking mode does not exist
200   if  (!fTrackReco) return 1;
201   
202   if ( ! ClusterStore() ) 
203   {
204     AliError("ClusterStore is NULL");
205     return 2;
206   }
207   
208   if (!fTriggerStore) {
209     AliError("TriggerStore is NULL");
210     return 3;
211   }
212
213   // Make trigger tracks
214   if ( fTriggerCircuit ) 
215   {
216     TriggerTrackStore()->Clear();
217     fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
218   }
219   
220   if ( AliMUONReconstructor::GetRecoParam()->BypassSt45() && TriggerTrackStore()->GetSize() > 5 ) 
221   {
222     // Hard cut to reject shower events
223     
224     AliCodeTimerAuto("MUON Shower events");
225
226     AliWarning(Form("Probably got a shower event (%d trigger tracks). Will not reconstruct tracks.",
227                     TriggerTrackStore()->GetSize()));
228     
229     return 0;
230   }
231        
232   // Make tracker tracks
233   AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
234   fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
235   
236   // Match tracker/trigger tracks
237   if ( fTrackHitPatternMaker ) 
238   {
239     fTrackReco->ValidateTracksWithTrigger(*trackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
240   }
241   
242   // Fill ESD
243   FillESD(*trackStore,esd);
244   
245   // cleanup
246   delete trackStore;
247   
248   return 0;
249 }
250
251 //_____________________________________________________________________________
252 void AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
253 {
254   /// Fill the ESD from the trackStore
255   AliDebug(1,"");
256   AliCodeTimerAuto("")
257   
258   AliMUONTrack* track;
259   AliESDMuonTrack esdTrack;
260   Double_t vertex[3] = {0., 0., 0.};
261   TIter next(trackStore.CreateIterator());
262   
263   // get ITS vertex
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   if (AliMUONReconstructor::GetRecoParam()->SaveFullClusterInESD() && 
272       gRandom->Uniform(100.) <= AliMUONReconstructor::GetRecoParam()->GetPercentOfFullClusterInESD()) {
273     
274     while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
275       AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fDigitStore);
276       // set the trigger x/y strips pattern
277       if (esdTrack.GetMatchTrigger()) {
278         AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(esdTrack.LoCircuit()));
279         esdTrack.SetTriggerX1Pattern(locTrg->GetX1Pattern());
280         esdTrack.SetTriggerY1Pattern(locTrg->GetY1Pattern());
281         esdTrack.SetTriggerX2Pattern(locTrg->GetX2Pattern());
282         esdTrack.SetTriggerY2Pattern(locTrg->GetY2Pattern());
283         esdTrack.SetTriggerX3Pattern(locTrg->GetX3Pattern());
284         esdTrack.SetTriggerY3Pattern(locTrg->GetY3Pattern());
285         esdTrack.SetTriggerX4Pattern(locTrg->GetX4Pattern());
286         esdTrack.SetTriggerY4Pattern(locTrg->GetY4Pattern());
287       }
288       esd->AddMuonTrack(&esdTrack);
289     }
290     
291   } else {
292     
293     while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
294       AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
295       // set the trigger x/y strips pattern
296       if (esdTrack.GetMatchTrigger()) {
297         AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(esdTrack.LoCircuit()));
298         esdTrack.SetTriggerX1Pattern(locTrg->GetX1Pattern());
299         esdTrack.SetTriggerY1Pattern(locTrg->GetY1Pattern());
300         esdTrack.SetTriggerX2Pattern(locTrg->GetX2Pattern());
301         esdTrack.SetTriggerY2Pattern(locTrg->GetY2Pattern());
302         esdTrack.SetTriggerX3Pattern(locTrg->GetX3Pattern());
303         esdTrack.SetTriggerY3Pattern(locTrg->GetY3Pattern());
304         esdTrack.SetTriggerX4Pattern(locTrg->GetX4Pattern());
305         esdTrack.SetTriggerY4Pattern(locTrg->GetY4Pattern());
306       }
307       esd->AddMuonTrack(&esdTrack);
308     }
309     
310   }
311
312   // fill the local trigger decisions not matched with tracks 
313   // associate them to "ghost" tracks
314
315   Int_t loTrgNum(-1);
316   Bool_t matched = kFALSE;
317
318   AliMUONTriggerTrack *triggerTrack;
319   AliMUONTrack muonTrack;
320   AliESDMuonTrack esdGhostTrack;
321   TIter itTriggerTrack(fTriggerTrackStore->CreateIterator());
322   while ( ( triggerTrack = static_cast<AliMUONTriggerTrack*>(itTriggerTrack() )
323 ) )
324     {
325       loTrgNum = triggerTrack->GetLoTrgNum();
326       AliMUONLocalTrigger* locTrg = static_cast<AliMUONLocalTrigger*>(fTriggerStore->FindLocal(loTrgNum));
327
328       /* verify if this local trigger has been already matched */
329       TIter itTrack(trackStore.CreateIterator());
330       while ( ( track = static_cast<AliMUONTrack*>(itTrack()) ) )
331         {
332           if (matched = (track->LoCircuit() == locTrg->LoCircuit())) break;
333         }
334       if (matched) continue;
335
336       muonTrack.SetLocalTrigger(locTrg->LoCircuit(),
337                                 locTrg->LoStripX(),
338                                 locTrg->LoStripY(),
339                                 locTrg->LoDev(),
340                                 locTrg->LoLpt(),
341                                 locTrg->LoHpt());
342
343       /* make the AliESDMuonTrack from the "track" object */
344
345       esdGhostTrack.SetLocalTrigger(muonTrack.GetLocalTrigger());
346       // set the transverse momentum of this track to "zero"
347       esdGhostTrack.SetInverseBendingMomentum(1.E+10);
348       esdGhostTrack.SetInverseBendingMomentumAtDCA(1.E+10);
349       esdGhostTrack.SetInverseBendingMomentumUncorrected(1.E+10);
350       // set the trigger x/y strips pattern
351       esdGhostTrack.SetTriggerX1Pattern(locTrg->GetX1Pattern());
352       esdGhostTrack.SetTriggerY1Pattern(locTrg->GetY1Pattern());
353       esdGhostTrack.SetTriggerX2Pattern(locTrg->GetX2Pattern());
354       esdGhostTrack.SetTriggerY2Pattern(locTrg->GetY2Pattern());
355       esdGhostTrack.SetTriggerX3Pattern(locTrg->GetX3Pattern());
356       esdGhostTrack.SetTriggerY3Pattern(locTrg->GetY3Pattern());
357       esdGhostTrack.SetTriggerX4Pattern(locTrg->GetX4Pattern());
358       esdGhostTrack.SetTriggerY4Pattern(locTrg->GetY4Pattern());
359       esd->AddMuonTrack(&esdGhostTrack);
360
361     }
362   
363 }
364
365 //_____________________________________________________________________________
366 AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const char* trackingMode, AliMUONVClusterServer* clusterServer)
367 {
368   /// Create track reconstructor, depending on tracking mode set in RecoParam
369   
370   AliMUONVTrackReconstructor* trackReco(0x0);
371   
372   TString opt(trackingMode);
373   opt.ToUpper();
374   
375   if (strstr(opt,"ORIGINAL"))
376   {
377     trackReco = new AliMUONTrackReconstructor(*clusterServer);
378   }
379   else if (strstr(opt,"KALMAN"))
380   {
381     trackReco = new AliMUONTrackReconstructorK(*clusterServer);
382   }
383   else
384   {
385     AliErrorClass(Form("tracking mode \"%s\" does not exist",opt.Data()));
386     return 0x0;
387   }
388   
389   AliInfoClass(Form("Will use %s for tracking",trackReco->ClassName()));
390   
391   return trackReco;
392 }
393
394 //_____________________________________________________________________________
395 void AliMUONTracker::UnloadClusters()
396 {
397   /// Clear internal clusterStore
398   
399   delete fInputClusterStore;
400   fInputClusterStore = 0x0;
401 }
402
403
404 //_____________________________________________________________________________
405 void
406 AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
407 {
408   /// Setup the cluster server
409   
410   if ( AliMUONReconstructor::GetRecoParam()->BypassSt45() )
411   {
412     Bool_t ok = clusterServer.UseTriggerTrackStore(TriggerTrackStore());
413   
414     if ( ok ) 
415     
416     {
417       AliWarning("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN STATIONS 4 AND 5, THUS BYPASSING REAL CLUSTERS IN THOSE TWO STATIONS !!!");    
418     }
419     else
420     {
421       AliWarning("BYPASSING OF ST45 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");    
422     }
423   }
424 }
425
426