]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTracker.cxx
Re-establishing creation of RecPoints in TreeR (Laurent)
[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 "AliMUONVCluster.h"
55 #include "AliMUONVClusterServer.h"
56 #include "AliMUONVDigitStore.h"
57 #include "AliMUONVTriggerStore.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(AliMUONVClusterServer* clusterServer,
69                                const AliMUONVDigitStore& digitStore,
70                                const AliMUONDigitMaker* digitMaker,
71                                const AliMUONGeometryTransformer* transformer,
72                                const AliMUONTriggerCircuit* triggerCircuit)
73 : AliTracker(),
74   fDigitMaker(digitMaker), // not owner
75   fTransformer(transformer), // not owner
76   fTriggerCircuit(triggerCircuit), // not owner
77   fTrackHitPatternMaker(0x0),
78   fTrackReco(0x0),
79   fClusterStore(0x0),
80   fTriggerStore(0x0),
81   fClusterServer(clusterServer), 
82   fIsOwnerOfClusterServer(kFALSE),
83   fDigitStore(digitStore), // not owner
84   fInputClusterStore(0x0),
85   fTriggerTrackStore(0x0)
86 {
87   /// constructor
88   if (fTransformer && fDigitMaker)
89     fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
90   
91   if (!fClusterServer)
92   {
93     AliInfo("No cluster server given. Will use AliMUONLegacyClusterServer");
94     fIsOwnerOfClusterServer = kTRUE;
95   }
96   else
97   {
98     TIter next(fDigitStore.CreateIterator());
99     fClusterServer->UseDigits(next);
100     
101     SetupClusterServer(*fClusterServer);
102   }
103 }
104
105 //_____________________________________________________________________________
106 AliMUONTracker::~AliMUONTracker()
107 {
108   /// dtor
109   delete fTrackReco;
110   delete fTrackHitPatternMaker;
111   delete fClusterStore;
112   delete fTriggerStore;
113   if ( fIsOwnerOfClusterServer ) delete fClusterServer;
114   delete fInputClusterStore;
115   delete fTriggerTrackStore;
116 }
117
118 //_____________________________________________________________________________
119 AliMUONVClusterStore*
120 AliMUONTracker::ClusterStore() const
121 {
122   /// Return (and create if necessary) the cluster container
123   if (!fClusterStore) 
124   {
125     fClusterStore = new AliMUONClusterStoreV2;
126   }
127   return fClusterStore;
128 }
129
130 //_____________________________________________________________________________
131 AliMUONVTriggerTrackStore*
132 AliMUONTracker::TriggerTrackStore() const
133 {
134   /// Return (and create if necessary) the trigger track container
135   if (!fTriggerTrackStore) 
136   {
137     fTriggerTrackStore = new AliMUONTriggerTrackStoreV1;
138   }
139   return fTriggerTrackStore;
140 }
141
142 //_____________________________________________________________________________
143 Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
144 {
145   /// Load triggerStore from clustersTree
146
147   delete fTriggerStore;
148   delete fInputClusterStore;
149   fInputClusterStore=0x0;
150
151   if ( ! clustersTree ) {
152     AliFatal("No clustersTree");
153     return 1;
154   }
155
156   fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
157   
158   if (!fTriggerStore)
159   {
160     AliError("Could not get triggerStore");
161     return 2;
162   }
163   
164   if ( fIsOwnerOfClusterServer )
165   {
166     fInputClusterStore = AliMUONVClusterStore::Create(*clustersTree);
167     if ( fInputClusterStore ) 
168     {
169       AliInfo(Form("Created %s from cluster tree",fInputClusterStore->ClassName()));
170       fInputClusterStore->Clear();
171       fInputClusterStore->Connect(*clustersTree,kFALSE);
172     }
173     delete fClusterServer;
174     fClusterServer = new AliMUONLegacyClusterServer(*fTransformer,fInputClusterStore);
175     SetupClusterServer(*fClusterServer);
176   }
177   
178   fTriggerStore->Connect(*clustersTree,kFALSE);
179   
180   clustersTree->GetEvent(0);
181
182   return 0;
183 }
184
185 //_____________________________________________________________________________
186 Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
187 {
188   /// Performs the tracking and store the resulting tracks in the ESD
189   AliDebug(1,"");
190   AliCodeTimerAuto("")
191   
192   if (!fTrackReco) 
193   {
194     fTrackReco = CreateTrackReconstructor(AliMUONReconstructor::GetRecoParam()->GetTrackingMode(),fClusterServer);
195   }
196   
197   // if the required tracking mode does not exist
198   if  (!fTrackReco) return 1;
199   
200   if ( ! ClusterStore() ) 
201   {
202     AliError("ClusterStore is NULL");
203     return 2;
204   }
205   
206   if (!fTriggerStore) {
207     AliError("TriggerStore is NULL");
208     return 3;
209   }
210
211   // Make trigger tracks
212   if ( fTriggerCircuit ) 
213   {
214     TriggerTrackStore()->Clear();
215     fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*(TriggerTrackStore()));
216   }
217   
218   // Make tracker tracks
219   AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
220   fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
221   
222   // Match tracker/trigger tracks
223   if ( fTrackHitPatternMaker ) 
224   {
225     fTrackReco->ValidateTracksWithTrigger(*trackStore,*(TriggerTrackStore()),*fTriggerStore,*fTrackHitPatternMaker);
226   }
227   
228   // Fill ESD
229   FillESD(*trackStore,esd);
230   
231   // cleanup
232   delete trackStore;
233   
234   return 0;
235 }
236
237 //_____________________________________________________________________________
238 void AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
239 {
240   /// Fill the ESD from the trackStore
241   AliDebug(1,"");
242   AliCodeTimerAuto("")
243   
244   AliMUONTrack* track;
245   AliESDMuonTrack esdTrack;
246   Double_t vertex[3] = {0., 0., 0.};
247   TIter next(trackStore.CreateIterator());
248   
249   // get ITS vertex
250   const AliESDVertex* esdVert = esd->GetVertex(); 
251   if (esdVert->GetNContributors()) {
252     esdVert->GetXYZ(vertex);
253     AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
254   }
255   
256   // fill ESD event including all info in ESD cluster if required and only for the given fraction of events
257   if (AliMUONReconstructor::GetRecoParam()->SaveFullClusterInESD() && 
258       gRandom->Uniform(100.) <= AliMUONReconstructor::GetRecoParam()->GetPercentOfFullClusterInESD()) {
259     
260     while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
261       AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex, &fDigitStore);
262       esd->AddMuonTrack(&esdTrack);
263     }
264     
265   } else {
266     
267     while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
268       AliMUONESDInterface::MUONToESD(*track, esdTrack, vertex);
269       esd->AddMuonTrack(&esdTrack);
270     }
271     
272   }
273   
274 }
275
276 //_____________________________________________________________________________
277 AliMUONVTrackReconstructor* AliMUONTracker::CreateTrackReconstructor(const char* trackingMode, AliMUONVClusterServer* clusterServer)
278 {
279   /// Create track reconstructor, depending on tracking mode set in RecoParam
280   
281   AliMUONVTrackReconstructor* trackReco(0x0);
282   
283   TString opt(trackingMode);
284   opt.ToUpper();
285   
286   if (strstr(opt,"ORIGINAL"))
287   {
288     trackReco = new AliMUONTrackReconstructor(*clusterServer);
289   }
290   else if (strstr(opt,"KALMAN"))
291   {
292     trackReco = new AliMUONTrackReconstructorK(*clusterServer);
293   }
294   else
295   {
296     AliErrorClass(Form("tracking mode \"%s\" does not exist",opt.Data()));
297     return 0x0;
298   }
299   
300   AliInfoClass(Form("Will use %s for tracking",trackReco->ClassName()));
301   
302   return trackReco;
303 }
304
305 //_____________________________________________________________________________
306 void AliMUONTracker::UnloadClusters()
307 {
308   /// Clear internal clusterStore
309   
310   delete fInputClusterStore;
311   fInputClusterStore = 0x0;
312 }
313
314
315 //_____________________________________________________________________________
316 void
317 AliMUONTracker::SetupClusterServer(AliMUONVClusterServer& clusterServer)
318 {
319   /// Setup the cluster server
320   
321   if ( AliMUONReconstructor::GetRecoParam()->BypassSt45() )
322   {
323     Bool_t ok = clusterServer.UseTriggerTrackStore(TriggerTrackStore());
324   
325     if ( ok ) 
326     
327     {
328       AliWarning("WILL USE TRIGGER TRACKS TO GENERATE CLUSTERS IN STATIONS 4 AND 5, THUS BYPASSING REAL CLUSTERS IN THOSE TWO STATIONS !!!");    
329     }
330     else
331     {
332       AliWarning("BYPASSING OF ST45 REQUESTED, BUT CLUSTERSERVER DOES NOT SEEM TO SUPPORT IT !!!");    
333     }
334   }
335 }
336
337