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