]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTracker.cxx
Adding a GetObjectFast method (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 ///
26 /// \author Christian Finck and Laurent Aphecetche, SUBATECH Nantes
27 //-----------------------------------------------------------------------------
28
29 #include "AliMUONTracker.h"
30
31 #include "AliMUONTrack.h"
32 #include "AliMUONTrackExtrap.h"
33 #include "AliMUONTrackHitPattern.h"
34 #include "AliMUONTrackParam.h"
35 #include "AliMUONHitForRec.h"
36 #include "AliMUONTrackReconstructor.h"
37 #include "AliMUONTrackReconstructorK.h"
38 #include "AliMUONTrackStoreV1.h"
39 #include "AliMUONTriggerChamberEff.h"
40 #include "AliMUONTriggerTrackStoreV1.h"
41 #include "AliMUONVClusterStore.h"
42 #include "AliMUONVTriggerStore.h"
43
44 #include "AliESDEvent.h"
45 #include "AliESDMuonTrack.h"
46 #include "AliESDVertex.h"
47 #include "AliLog.h"
48 #include "AliCodeTimer.h"
49
50 #include <Riostream.h>
51 #include <TTree.h>
52
53 /// \cond CLASSIMP
54 ClassImp(AliMUONTracker)
55 /// \endcond
56
57
58 //_____________________________________________________________________________
59 AliMUONTracker::AliMUONTracker(const AliMUONDigitMaker* digitMaker,
60                                const AliMUONGeometryTransformer* transformer,
61                                const AliMUONTriggerCircuit* triggerCircuit,
62                                AliMUONTriggerChamberEff* chamberEff)
63 : AliTracker(),
64   fDigitMaker(digitMaker), // not owner
65   fTransformer(transformer), // not owner
66   fTriggerCircuit(triggerCircuit), // not owner
67   fTrigChamberEff(chamberEff), // not owner
68   fTrackHitPatternMaker(0x0),
69   fTrackReco(0x0),
70   fClusterStore(0x0),
71   fTriggerStore(0x0)
72 {
73   /// constructor
74   if (fTransformer && fDigitMaker)
75   {
76     fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
77   }
78 }
79
80 //_____________________________________________________________________________
81 AliMUONTracker::~AliMUONTracker()
82 {
83   /// dtor
84   delete fTrackReco;
85   delete fTrackHitPatternMaker;
86   delete fClusterStore;
87   delete fTriggerStore;
88 }
89
90 //_____________________________________________________________________________
91 Int_t 
92 AliMUONTracker::LoadClusters(TTree* clustersTree)
93 {
94   /// Load clusterStore and triggerStore from clustersTree
95   delete fClusterStore;
96   delete fTriggerStore;
97
98   fClusterStore = AliMUONVClusterStore::Create(*clustersTree);
99   fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
100   
101   if (!fClusterStore)
102   {
103     AliError("Could not get clusterStore");
104     return 1;
105   }
106   if (!fTriggerStore)
107   {
108     AliError("Could not get triggerStore");
109     return 2;
110   }
111   
112   fClusterStore->Connect(*clustersTree,kFALSE);
113   fTriggerStore->Connect(*clustersTree,kFALSE);
114   
115   clustersTree->GetEvent(0);
116
117   return 0;
118 }
119
120 //_____________________________________________________________________________
121 Int_t
122 AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
123 {
124   /// Performs the tracking and store the resulting tracks in both
125   /// the TreeT and the ESD
126   
127   Int_t rv(0);
128  
129   TTree *tracksTree = new TTree;
130  
131   if (!fClusterStore)
132   {
133     AliError("ClusterStore is NULL");
134     rv=2;
135   }
136   if (!fTriggerStore)
137   {
138     AliError("TriggerStore is NULL");
139     rv=3;
140   }
141   if (!rv)
142   {
143     rv = Clusters2Tracks(*tracksTree,esd);
144   }
145   return rv;
146 }
147
148 //_____________________________________________________________________________
149 Int_t AliMUONTracker::Clusters2Tracks(TTree& tracksTree, AliESDEvent* esd)
150 {
151   /// Performs the tracking
152   AliDebug(1,"");
153   AliCodeTimerAuto("")
154   
155   AliMUONVTrackStore* trackStore(0x0);
156   AliMUONVTriggerTrackStore* triggerTrackStore(0x0);
157   
158   // Make tracker tracks
159   if ( fClusterStore ) 
160   {
161     trackStore = new AliMUONTrackStoreV1;
162     Bool_t alone = ( ( fTriggerStore && fTriggerCircuit ) ? kFALSE : kTRUE );
163     trackStore->Connect(tracksTree,alone);
164     fTrackReco->EventReconstruct(*fClusterStore,*trackStore);
165   }
166   
167   if ( fTriggerStore && fTriggerCircuit )
168   {
169     // Make trigger tracks
170     triggerTrackStore = new AliMUONTriggerTrackStoreV1;
171     Bool_t alone = ( fClusterStore ? kFALSE : kTRUE );
172     triggerTrackStore->Connect(tracksTree,alone);
173     fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*triggerTrackStore);
174   }
175
176   if ( trackStore && triggerTrackStore && fTriggerStore && fTrackHitPatternMaker )
177   {
178     fTrackReco->ValidateTracksWithTrigger(*trackStore,*triggerTrackStore,*fTriggerStore,*fTrackHitPatternMaker);
179   }
180   
181   // Fills output TreeT 
182   //tracksTree.Fill();
183
184   if( trackStore && triggerTrackStore && fTriggerStore && fTrigChamberEff){
185       AliCodeTimerStart("EventChamberEff");
186       fTrigChamberEff->EventChamberEff(*fTriggerStore,*triggerTrackStore,*trackStore);
187       AliCodeTimerStop("EventChamberEff");
188   }
189
190   FillESD(*trackStore,esd);
191   
192   // cleanup
193   delete trackStore;
194   delete triggerTrackStore;
195   
196   return 0;
197 }
198
199 //_____________________________________________________________________________
200 void 
201 AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
202 {
203   /// Fill the ESD from the trackStore
204   AliDebug(1,"");
205   AliCodeTimerAuto("")
206   
207   // Get vertex 
208   Double_t vertex[3] = {0};
209   const AliESDVertex* esdVert = esd->GetVertex(); 
210   if (esdVert->GetNContributors()) 
211   {
212     esdVert->GetXYZ(vertex);
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   
219   AliMUONTrack* track;
220   TIter next(trackStore.CreateIterator());
221   
222   while ( ( track = static_cast<AliMUONTrack*>(next()) ) )
223   {
224     AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track->GetTrackParamAtHit())->First());
225     AliMUONTrackParam trackParamAtVtx(*trackParam);
226     
227     /// Extrapolate to vertex (which is set to (0,0,0) if not available, see above)
228     AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0],vertex[1],vertex[2]);
229     
230     // setting data member of ESD MUON
231     
232     // at first station
233     trackParam->SetParamForUncorrected(esdTrack);
234     trackParam->SetCovFor(esdTrack);
235     // at vertex
236     trackParamAtVtx.SetParamFor(esdTrack);
237     // global info
238     esdTrack.SetChi2(track->GetFitFMin());
239     esdTrack.SetNHit(track->GetNTrackHits());
240     esdTrack.SetLocalTrigger(track->GetLocalTrigger());
241     esdTrack.SetChi2MatchTrigger(track->GetChi2MatchTrigger());
242     esdTrack.SetHitsPatternInTrigCh(track->GetHitsPatternInTrigCh());
243     // muon cluster map
244     AliMUONHitForRec* cluster = static_cast<AliMUONHitForRec*>((track->GetHitForRecAtHit())->First());
245     while (cluster) {
246       esdTrack.AddInMuonClusterMap(cluster->GetChamberNumber());
247       cluster = static_cast<AliMUONHitForRec*>((track->GetHitForRecAtHit())->After(cluster));
248     }
249     
250     // storing ESD MUON Track into ESD Event 
251     esd->AddMuonTrack(&esdTrack);
252   } // end of loop on tracks
253 }
254
255 //_____________________________________________________________________________
256 void AliMUONTracker::SetOption(Option_t* option)
257 {
258   /// set reconstructor class
259   
260   if (strstr(option,"Original")) 
261   {
262     fTrackReco = new AliMUONTrackReconstructor;
263   }
264   else 
265   {
266     fTrackReco = new AliMUONTrackReconstructorK();
267   }
268 }
269
270 //_____________________________________________________________________________
271 void 
272 AliMUONTracker::UnloadClusters()
273 {
274   /// Delete internal clusterStore
275   delete fClusterStore;
276   fClusterStore = 0x0;
277 }
278