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