]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTracker.cxx
adfc1cafaa5517905226cd7f5f960c4d86c0ed8c
[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 "AliMUONReconstructor.h"
37 #include "AliMUONRecoParam.h"
38 #include "AliMUONTrack.h"
39 #include "AliMUONTrackExtrap.h"
40 #include "AliMUONTrackHitPattern.h"
41 #include "AliMUONTrackParam.h"
42 #include "AliMUONVCluster.h"
43 #include "AliMUONVClusterServer.h"
44 #include "AliMUONTrackReconstructor.h"
45 #include "AliMUONTrackReconstructorK.h"
46 #include "AliMUONTrackStoreV1.h"
47 #include "AliMUONTriggerChamberEff.h"
48 #include "AliMUONTriggerTrackStoreV1.h"
49 #include "AliMUONClusterStoreV2.h"
50 #include "AliMUONVTriggerStore.h"
51
52 #include "AliESDEvent.h"
53 #include "AliESDMuonTrack.h"
54 #include "AliESDMuonCluster.h"
55 #include "AliESDVertex.h"
56 #include "AliLog.h"
57 #include "AliCodeTimer.h"
58
59 #include <Riostream.h>
60 #include <TTree.h>
61
62 /// \cond CLASSIMP
63 ClassImp(AliMUONTracker)
64 /// \endcond
65
66
67 //_____________________________________________________________________________
68 AliMUONTracker::AliMUONTracker(AliMUONVClusterServer& clusterServer,
69                                const AliMUONDigitMaker* digitMaker,
70                                const AliMUONGeometryTransformer* transformer,
71                                const AliMUONTriggerCircuit* triggerCircuit,
72                                AliMUONTriggerChamberEff* chamberEff)
73 : AliTracker(),
74   fDigitMaker(digitMaker), // not owner
75   fTransformer(transformer), // not owner
76   fTriggerCircuit(triggerCircuit), // not owner
77   fTrigChamberEff(chamberEff), // not owner
78   fTrackHitPatternMaker(0x0),
79   fTrackReco(0x0),
80   fClusterStore(0x0),
81   fTriggerStore(0x0),
82   fClusterServer(clusterServer)
83 {
84   /// constructor
85   if (fTransformer && fDigitMaker)
86     fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
87 }
88
89 //_____________________________________________________________________________
90 AliMUONTracker::~AliMUONTracker()
91 {
92   /// dtor
93   delete fTrackReco;
94   delete fTrackHitPatternMaker;
95   delete fClusterStore;
96   delete fTriggerStore;
97 }
98
99 //_____________________________________________________________________________
100 AliMUONVClusterStore*
101 AliMUONTracker::ClusterStore() const
102 {
103   /// Return (and create if necessary) the cluster container
104   if (!fClusterStore) 
105   {
106     fClusterStore = new AliMUONClusterStoreV2;
107   }
108   return fClusterStore;
109 }
110
111 //_____________________________________________________________________________
112 Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
113 {
114   /// Load triggerStore from clustersTree
115
116   ClusterStore()->Clear();
117   
118   delete fTriggerStore;
119
120   if ( ! clustersTree ) {
121     AliFatal("No clustersTree");
122     return 1;
123   }
124
125   fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
126   
127   if (!fTriggerStore)
128   {
129     AliError("Could not get triggerStore");
130     return 2;
131   }
132   
133   ClusterStore()->Connect(*clustersTree,kFALSE);
134   fTriggerStore->Connect(*clustersTree,kFALSE);
135   
136   clustersTree->GetEvent(0);
137
138   return 0;
139 }
140
141 //_____________________________________________________________________________
142 Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
143 {
144   /// Performs the tracking and store the resulting tracks in the ESD
145   AliDebug(1,"");
146   AliCodeTimerAuto("")
147   
148   if (!fTrackReco) CreateTrackReconstructor();
149   
150   // if the required tracking mode does not exist
151   if  (!fTrackReco) return 1;
152   
153   if ( ! ClusterStore() ) 
154   {
155     AliError("ClusterStore is NULL");
156     return 2;
157   }
158   
159   if (!fTriggerStore) {
160     AliError("TriggerStore is NULL");
161     return 3;
162   }
163
164   // Make tracker tracks
165   AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
166   fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
167   
168   // Make trigger tracks
169   AliMUONVTriggerTrackStore* triggerTrackStore(0x0);
170   if ( fTriggerCircuit ) {
171     triggerTrackStore = new AliMUONTriggerTrackStoreV1;
172     fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*triggerTrackStore);
173   }
174
175   // Match tracker/trigger tracks
176   if ( triggerTrackStore && fTrackHitPatternMaker ) {
177     fTrackReco->ValidateTracksWithTrigger(*trackStore,*triggerTrackStore,*fTriggerStore,*fTrackHitPatternMaker);
178   }
179   
180   // Compute trigger chamber efficiency
181   if( triggerTrackStore && fTrigChamberEff){
182       AliCodeTimerStart("EventChamberEff");
183       fTrigChamberEff->EventChamberEff(*fTriggerStore,*triggerTrackStore,*trackStore);
184       AliCodeTimerStop("EventChamberEff");
185   }
186   
187   // Fill ESD
188   FillESD(*trackStore,esd);
189   
190   // cleanup
191   delete trackStore;
192   delete triggerTrackStore;
193   
194   return 0;
195 }
196
197 //_____________________________________________________________________________
198 void AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
199 {
200   /// Fill the ESD from the trackStore
201   AliDebug(1,"");
202   AliCodeTimerAuto("")
203   
204   // Get vertex 
205   Double_t vertex[3] = {0};
206   Double_t errXVtx = 0., errYVtx = 0.;
207   const AliESDVertex* esdVert = esd->GetVertex(); 
208   if (esdVert->GetNContributors()) 
209   {
210     esdVert->GetXYZ(vertex);
211     errXVtx = esdVert->GetXRes();
212     errYVtx = esdVert->GetYRes();
213     AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
214   }
215   
216   // setting ESD MUON class
217   AliESDMuonTrack esdTrack;
218   AliESDMuonCluster esdCluster;
219   
220   AliMUONTrack* track;
221   AliMUONVCluster* cluster;
222   TIter next(trackStore.CreateIterator());
223   
224   while ( ( track = static_cast<AliMUONTrack*>(next()) ) )
225   {
226     AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track->GetTrackParamAtCluster())->First());
227     
228     /// Extrapolate to vertex (which is set to (0,0,0) if not available, see above)
229     AliMUONTrackParam trackParamAtVtx(*trackParam);
230     AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0], vertex[1], vertex[2], errXVtx, errYVtx);
231     
232     /// Extrapolate to vertex plan (which is set to z=0 if not available, see above)
233     AliMUONTrackParam trackParamAtDCA(*trackParam);
234     AliMUONTrackExtrap::ExtrapToVertexWithoutBranson(&trackParamAtDCA, vertex[2]);
235     
236     // setting data member of ESD MUON
237     esdTrack.Clear("C");           // remove already attached clusters
238     esdTrack.SetMuonClusterMap(0); // important to use the Add..() methods
239     
240     // at first station
241     trackParam->SetParamForUncorrected(esdTrack);
242     trackParam->SetCovFor(esdTrack);
243     // at vertex
244     trackParamAtVtx.SetParamFor(esdTrack);
245     // at Distance of Closest Approach
246     trackParamAtDCA.SetParamForDCA(esdTrack);
247     // global info
248     esdTrack.SetChi2(track->GetGlobalChi2());
249     esdTrack.SetNHit(track->GetNClusters());
250     esdTrack.SetLocalTrigger(track->GetLocalTrigger());
251     esdTrack.SetChi2MatchTrigger(track->GetChi2MatchTrigger());
252     esdTrack.SetHitsPatternInTrigCh(track->GetHitsPatternInTrigCh());
253     // muon cluster info
254     while (trackParam) {
255       cluster = trackParam->GetClusterPtr();
256       esdCluster.SetUniqueID(cluster->GetUniqueID());
257       esdCluster.SetXYZ(cluster->GetX(), cluster->GetY(), cluster->GetZ());
258       esdCluster.SetErrXY(cluster->GetErrX(), cluster->GetErrY());
259       esdTrack.AddCluster(esdCluster);
260       esdTrack.AddInMuonClusterMap(cluster->GetChamberId());
261       trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
262     }
263     
264     // storing ESD MUON Track into ESD Event 
265     esd->AddMuonTrack(&esdTrack);
266   } // end of loop on tracks
267 }
268
269 //_____________________________________________________________________________
270 void AliMUONTracker::CreateTrackReconstructor()
271 {
272   /// Create track reconstructor, depending on tracking mode set in RecoParam
273   
274   TString opt(AliMUONReconstructor::GetRecoParam()->GetTrackingMode());
275   opt.ToUpper();
276   
277   if (strstr(opt,"ORIGINAL"))
278   {
279     fTrackReco = new AliMUONTrackReconstructor(fClusterServer);
280   }
281   else if (strstr(opt,"KALMAN"))
282   {
283     fTrackReco = new AliMUONTrackReconstructorK(fClusterServer);
284   }
285   else
286   {
287     AliError(Form("tracking mode \"%s\" does not exist",opt.Data()));
288     return;
289   }
290   
291   AliInfo(Form("Will use %s for tracking",fTrackReco->ClassName()));
292 }
293
294 //_____________________________________________________________________________
295 void AliMUONTracker::UnloadClusters()
296 {
297   /// Clear internal clusterStore
298   
299   ClusterStore()->Clear();
300 }