]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTracker.cxx
Merging two methods, no longer needed to be separated after the death of TreeT
[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   if ( ! clustersTree ) {
99     AliFatal("No clustersTree");
100     return 1;
101   }
102
103   fClusterStore = AliMUONVClusterStore::Create(*clustersTree);
104   fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
105   
106   if (!fClusterStore)
107   {
108     AliError("Could not get clusterStore");
109     return 1;
110   }
111   if (!fTriggerStore)
112   {
113     AliError("Could not get triggerStore");
114     return 2;
115   }
116   
117   fClusterStore->Connect(*clustersTree,kFALSE);
118   fTriggerStore->Connect(*clustersTree,kFALSE);
119   
120   clustersTree->GetEvent(0);
121
122   return 0;
123 }
124
125 //_____________________________________________________________________________
126 Int_t
127 AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
128 {
129   /// Performs the tracking and store the resulting tracks in
130   /// the ESD
131   
132   if (!fClusterStore)
133   {
134     AliError("ClusterStore is NULL");
135     return 2;
136   }
137   
138   if (!fTriggerStore)
139   {
140     AliError("TriggerStore is NULL");
141     return 3;
142   }
143   
144   AliMUONVTrackStore* trackStore(0x0);
145   AliMUONVTriggerTrackStore* triggerTrackStore(0x0);
146   
147   // Make tracker tracks
148   if ( fClusterStore ) 
149   {
150     trackStore = new AliMUONTrackStoreV1;
151     Bool_t alone = ( ( fTriggerStore && fTriggerCircuit ) ? kFALSE : kTRUE );
152     fTrackReco->EventReconstruct(*fClusterStore,*trackStore);
153   }
154   
155   if ( fTriggerStore && fTriggerCircuit )
156   {
157     // Make trigger tracks
158     triggerTrackStore = new AliMUONTriggerTrackStoreV1;
159     Bool_t alone = ( fClusterStore ? kFALSE : kTRUE );
160     fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*triggerTrackStore);
161   }
162
163   if ( trackStore && triggerTrackStore && fTriggerStore && fTrackHitPatternMaker )
164   {
165     fTrackReco->ValidateTracksWithTrigger(*trackStore,*triggerTrackStore,*fTriggerStore,*fTrackHitPatternMaker);
166   }
167   
168   if( trackStore && triggerTrackStore && fTriggerStore && fTrigChamberEff){
169       AliCodeTimerStart("EventChamberEff");
170       fTrigChamberEff->EventChamberEff(*fTriggerStore,*triggerTrackStore,*trackStore);
171       AliCodeTimerStop("EventChamberEff");
172   }
173
174   FillESD(*trackStore,esd);
175   
176   // cleanup
177   delete trackStore;
178   delete triggerTrackStore;
179   
180   return 0;
181 }
182
183 //_____________________________________________________________________________
184 void 
185 AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
186 {
187   /// Fill the ESD from the trackStore
188   AliDebug(1,"");
189   AliCodeTimerAuto("")
190   
191   // Get vertex 
192   Double_t vertex[3] = {0};
193   const AliESDVertex* esdVert = esd->GetVertex(); 
194   if (esdVert->GetNContributors()) 
195   {
196     esdVert->GetXYZ(vertex);
197     AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
198   }
199   
200   // setting ESD MUON class
201   AliESDMuonTrack esdTrack;
202   
203   AliMUONTrack* track;
204   TIter next(trackStore.CreateIterator());
205   
206   while ( ( track = static_cast<AliMUONTrack*>(next()) ) )
207   {
208     AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track->GetTrackParamAtHit())->First());
209     AliMUONTrackParam trackParamAtVtx(*trackParam);
210     
211     /// Extrapolate to vertex (which is set to (0,0,0) if not available, see above)
212     AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0],vertex[1],vertex[2]);
213     
214     // setting data member of ESD MUON
215     
216     // at first station
217     trackParam->SetParamForUncorrected(esdTrack);
218     trackParam->SetCovFor(esdTrack);
219     // at vertex
220     trackParamAtVtx.SetParamFor(esdTrack);
221     // global info
222     esdTrack.SetChi2(track->GetFitFMin());
223     esdTrack.SetNHit(track->GetNTrackHits());
224     esdTrack.SetLocalTrigger(track->GetLocalTrigger());
225     esdTrack.SetChi2MatchTrigger(track->GetChi2MatchTrigger());
226     esdTrack.SetHitsPatternInTrigCh(track->GetHitsPatternInTrigCh());
227     // muon cluster map
228     AliMUONHitForRec* cluster = static_cast<AliMUONHitForRec*>((track->GetHitForRecAtHit())->First());
229     while (cluster) {
230       esdTrack.AddInMuonClusterMap(cluster->GetChamberNumber());
231       cluster = static_cast<AliMUONHitForRec*>((track->GetHitForRecAtHit())->After(cluster));
232     }
233     
234     // storing ESD MUON Track into ESD Event 
235     esd->AddMuonTrack(&esdTrack);
236   } // end of loop on tracks
237 }
238
239 //_____________________________________________________________________________
240 void AliMUONTracker::SetOption(Option_t* option)
241 {
242   /// set reconstructor class
243   
244   if (strstr(option,"Original")) 
245   {
246     fTrackReco = new AliMUONTrackReconstructor;
247   }
248   else 
249   {
250     fTrackReco = new AliMUONTrackReconstructorK();
251   }
252 }
253
254 //_____________________________________________________________________________
255 void 
256 AliMUONTracker::UnloadClusters()
257 {
258   /// Delete internal clusterStore
259   delete fClusterStore;
260   fClusterStore = 0x0;
261 }
262