Implemented a new version of cluster (with its store and iterator):
[u/mrichter/AliRoot.git] / MUON / AliMUONTracker.cxx
CommitLineData
196471e9 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
ea94c18b 16/* $Id$ */
17
ee8a8d65 18//-----------------------------------------------------------------------------
27bf410b 19/// \class AliMUONTracker
e64fdf8a 20///
21/// Steering class for use in global tracking framework;
27bf410b 22/// reconstruct tracks from recpoints
23///
e64fdf8a 24/// Actual tracking is performed by some AliMUONVTrackReconstructor children
25///
26/// \author Christian Finck and Laurent Aphecetche, SUBATECH Nantes
ee8a8d65 27//-----------------------------------------------------------------------------
196471e9 28
29#include "AliMUONTracker.h"
e64fdf8a 30
e64fdf8a 31#include "AliMUONTrack.h"
32#include "AliMUONTrackExtrap.h"
33#include "AliMUONTrackHitPattern.h"
34#include "AliMUONTrackParam.h"
60765b06 35#include "AliMUONHitForRec.h"
196471e9 36#include "AliMUONTrackReconstructor.h"
e64fdf8a 37#include "AliMUONTrackReconstructorK.h"
38#include "AliMUONTrackStoreV1.h"
8c0b5e70 39#include "AliMUONTriggerChamberEff.h"
e64fdf8a 40#include "AliMUONTriggerTrackStoreV1.h"
41#include "AliMUONVClusterStore.h"
42#include "AliMUONVTriggerStore.h"
ea94c18b 43
af885e0f 44#include "AliESDEvent.h"
ea94c18b 45#include "AliESDMuonTrack.h"
46#include "AliESDVertex.h"
ea94c18b 47#include "AliLog.h"
48
e64fdf8a 49#include <Riostream.h>
50#include <TTree.h>
196471e9 51
ee8a8d65 52/// \cond CLASSIMP
53ClassImp(AliMUONTracker)
54/// \endcond
55
56
196471e9 57//_____________________________________________________________________________
d76c31f4 58AliMUONTracker::AliMUONTracker(const AliMUONDigitMaker* digitMaker,
e64fdf8a 59 const AliMUONGeometryTransformer* transformer,
8c0b5e70 60 const AliMUONTriggerCircuit* triggerCircuit,
61 AliMUONTriggerChamberEff* chamberEff)
e64fdf8a 62: AliTracker(),
e64fdf8a 63 fDigitMaker(digitMaker), // not owner
64 fTransformer(transformer), // not owner
65 fTriggerCircuit(triggerCircuit), // not owner
8c0b5e70 66 fTrigChamberEff(chamberEff), // not owner
e64fdf8a 67 fTrackHitPatternMaker(0x0),
68 fTrackReco(0x0),
69 fClusterStore(0x0),
70 fTriggerStore(0x0)
196471e9 71{
72 /// constructor
e64fdf8a 73 if (fTransformer && fDigitMaker)
74 {
75 fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
76 }
196471e9 77}
e64fdf8a 78
196471e9 79//_____________________________________________________________________________
80AliMUONTracker::~AliMUONTracker()
81{
e64fdf8a 82 /// dtor
196471e9 83 delete fTrackReco;
e64fdf8a 84 delete fTrackHitPatternMaker;
85 delete fClusterStore;
86 delete fTriggerStore;
196471e9 87}
88
89//_____________________________________________________________________________
e64fdf8a 90Int_t
91AliMUONTracker::LoadClusters(TTree* clustersTree)
196471e9 92{
e64fdf8a 93 /// Load clusterStore and triggerStore from clustersTree
94 delete fClusterStore;
95 delete fTriggerStore;
196471e9 96
e64fdf8a 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);
196471e9 115
e64fdf8a 116 return 0;
117}
196471e9 118
e64fdf8a 119//_____________________________________________________________________________
120Int_t
af885e0f 121AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
e64fdf8a 122{
123 /// Performs the tracking and store the resulting tracks in both
124 /// the TreeT and the ESD
125
126 Int_t rv(0);
d76c31f4 127
128 TTree *tracksTree = new TTree;
129
e64fdf8a 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}
196471e9 146
e64fdf8a 147//_____________________________________________________________________________
af885e0f 148Int_t AliMUONTracker::Clusters2Tracks(TTree& tracksTree, AliESDEvent* esd)
e64fdf8a 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
8c0b5e70 183 if( trackStore && triggerTrackStore && fTriggerStore && fTrigChamberEff){
184 fTrigChamberEff->EventChamberEff(*fTriggerStore,*triggerTrackStore,*trackStore);
8c0b5e70 185 }
186
e64fdf8a 187 FillESD(*trackStore,esd);
188
189 // cleanup
190 delete trackStore;
191 delete triggerTrackStore;
192
193 return 0;
194}
196471e9 195
e64fdf8a 196//_____________________________________________________________________________
197void
af885e0f 198AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
e64fdf8a 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
60765b06 230 trackParam->SetParamForUncorrected(esdTrack);
231 trackParam->SetCovFor(esdTrack);
e64fdf8a 232 // at vertex
60765b06 233 trackParamAtVtx.SetParamFor(esdTrack);
e64fdf8a 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());
60765b06 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 }
e64fdf8a 246
247 // storing ESD MUON Track into ESD Event
248 esd->AddMuonTrack(&esdTrack);
249 } // end of loop on tracks
196471e9 250}
251
252//_____________________________________________________________________________
e64fdf8a 253void AliMUONTracker::SetOption(Option_t* option)
196471e9 254{
e64fdf8a 255 /// set reconstructor class
256
257 if (strstr(option,"Original"))
258 {
259 fTrackReco = new AliMUONTrackReconstructor;
260 }
e64fdf8a 261 else
262 {
ea94c18b 263 fTrackReco = new AliMUONTrackReconstructorK();
e64fdf8a 264 }
265}
196471e9 266
e64fdf8a 267//_____________________________________________________________________________
268void
269AliMUONTracker::UnloadClusters()
270{
271 /// Delete internal clusterStore
272 delete fClusterStore;
273 fClusterStore = 0x0;
196471e9 274}
e64fdf8a 275