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