]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTracker.cxx
Fill ESD MUON clusters with additional informations (including pads)
[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 "AliMUONVClusterServer.h"
44 #include "AliMUONVDigitStore.h"
45 #include "AliMUONTrackReconstructor.h"
46 #include "AliMUONTrackReconstructorK.h"
47 #include "AliMUONTrackStoreV1.h"
48 #include "AliMUONTriggerTrackStoreV1.h"
49 #include "AliMUONClusterStoreV2.h"
50 #include "AliMUONVTriggerStore.h"
51
52 #include "AliESDEvent.h"
53 #include "AliESDMuonTrack.h"
54 #include "AliESDMuonCluster.h"
55 #include "AliESDMuonPad.h"
56 #include "AliESDVertex.h"
57 #include "AliLog.h"
58 #include "AliCodeTimer.h"
59
60 #include <Riostream.h>
61 #include <TTree.h>
62 #include <TRandom.h>
63
64 /// \cond CLASSIMP
65 ClassImp(AliMUONTracker)
66 /// \endcond
67
68
69 //_____________________________________________________________________________
70 AliMUONTracker::AliMUONTracker(AliMUONVClusterServer& clusterServer,
71                                const AliMUONVDigitStore& digitStore,
72                                const AliMUONDigitMaker* digitMaker,
73                                const AliMUONGeometryTransformer* transformer,
74                                const AliMUONTriggerCircuit* triggerCircuit)
75 : AliTracker(),
76   fDigitMaker(digitMaker), // not owner
77   fTransformer(transformer), // not owner
78   fTriggerCircuit(triggerCircuit), // not owner
79   fTrackHitPatternMaker(0x0),
80   fTrackReco(0x0),
81   fClusterStore(0x0),
82   fTriggerStore(0x0),
83   fClusterServer(clusterServer), // not owner
84   fDigitStore(digitStore) // not owner
85 {
86   /// constructor
87   if (fTransformer && fDigitMaker)
88     fTrackHitPatternMaker = new AliMUONTrackHitPattern(*fTransformer,*fDigitMaker);
89   
90   fClusterServer.UseDigitStore(fDigitStore);
91 }
92
93 //_____________________________________________________________________________
94 AliMUONTracker::~AliMUONTracker()
95 {
96   /// dtor
97   delete fTrackReco;
98   delete fTrackHitPatternMaker;
99   delete fClusterStore;
100   delete fTriggerStore;
101 }
102
103 //_____________________________________________________________________________
104 AliMUONVClusterStore*
105 AliMUONTracker::ClusterStore() const
106 {
107   /// Return (and create if necessary) the cluster container
108   if (!fClusterStore) 
109   {
110     fClusterStore = new AliMUONClusterStoreV2;
111   }
112   return fClusterStore;
113 }
114
115 //_____________________________________________________________________________
116 Int_t AliMUONTracker::LoadClusters(TTree* clustersTree)
117 {
118   /// Load triggerStore from clustersTree
119
120   ClusterStore()->Clear();
121   
122   delete fTriggerStore;
123
124   if ( ! clustersTree ) {
125     AliFatal("No clustersTree");
126     return 1;
127   }
128
129   fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
130   
131   if (!fTriggerStore)
132   {
133     AliError("Could not get triggerStore");
134     return 2;
135   }
136   
137   ClusterStore()->Connect(*clustersTree,kFALSE);
138   fTriggerStore->Connect(*clustersTree,kFALSE);
139   
140   clustersTree->GetEvent(0);
141
142   return 0;
143 }
144
145 //_____________________________________________________________________________
146 Int_t AliMUONTracker::Clusters2Tracks(AliESDEvent* esd)
147 {
148   /// Performs the tracking and store the resulting tracks in the ESD
149   AliDebug(1,"");
150   AliCodeTimerAuto("")
151   
152   if (!fTrackReco) CreateTrackReconstructor();
153   
154   // if the required tracking mode does not exist
155   if  (!fTrackReco) return 1;
156   
157   if ( ! ClusterStore() ) 
158   {
159     AliError("ClusterStore is NULL");
160     return 2;
161   }
162   
163   if (!fTriggerStore) {
164     AliError("TriggerStore is NULL");
165     return 3;
166   }
167
168   // Make tracker tracks
169   AliMUONVTrackStore* trackStore = new AliMUONTrackStoreV1;
170   fTrackReco->EventReconstruct(*(ClusterStore()),*trackStore);
171   
172   // Make trigger tracks
173   AliMUONVTriggerTrackStore* triggerTrackStore(0x0);
174   if ( fTriggerCircuit ) {
175     triggerTrackStore = new AliMUONTriggerTrackStoreV1;
176     fTrackReco->EventReconstructTrigger(*fTriggerCircuit,*fTriggerStore,*triggerTrackStore);
177   }
178
179   // Match tracker/trigger tracks
180   if ( triggerTrackStore && fTrackHitPatternMaker ) {
181     fTrackReco->ValidateTracksWithTrigger(*trackStore,*triggerTrackStore,*fTriggerStore,*fTrackHitPatternMaker);
182   }
183   
184   // Fill ESD
185   FillESD(*trackStore,esd);
186   
187   // cleanup
188   delete trackStore;
189   delete triggerTrackStore;
190   
191   return 0;
192 }
193
194 //_____________________________________________________________________________
195 void AliMUONTracker::FillESD(AliMUONVTrackStore& trackStore, AliESDEvent* esd) const
196 {
197   /// Fill the ESD from the trackStore
198   AliDebug(1,"");
199   AliCodeTimerAuto("")
200   
201   // Random number to decide whether to save additional cluster info or not for the current event
202   Double_t rand = 0.;
203   if (AliMUONReconstructor::GetRecoParam()->SaveFullClusterInESD()) rand = gRandom->Uniform(0.,100.);
204   
205   // Get vertex 
206   Double_t vertex[3] = {0};
207   Double_t errXVtx = 0., errYVtx = 0.;
208   const AliESDVertex* esdVert = esd->GetVertex(); 
209   if (esdVert->GetNContributors()) 
210   {
211     esdVert->GetXYZ(vertex);
212     errXVtx = esdVert->GetXRes();
213     errYVtx = esdVert->GetYRes();
214     AliDebug(1,Form("found vertex (%e,%e,%e)",vertex[0],vertex[1],vertex[2]));
215   }
216   
217   AliMUONTrack* track;
218   AliMUONVCluster* cluster;
219   AliMUONVDigit* digit;
220   TIter next(trackStore.CreateIterator());
221   
222   while ( ( track = static_cast<AliMUONTrack*>(next()) ) )
223   {
224     AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>((track->GetTrackParamAtCluster())->First());
225     
226     // new ESD muon track
227     AliESDMuonTrack esdTrack;
228     
229     /// Extrapolate to vertex (which is set to (0,0,0) if not available, see above)
230     AliMUONTrackParam trackParamAtVtx(*trackParam);
231     AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0], vertex[1], vertex[2], errXVtx, errYVtx);
232     
233     /// Extrapolate to vertex plan (which is set to z=0 if not available, see above)
234     AliMUONTrackParam trackParamAtDCA(*trackParam);
235     AliMUONTrackExtrap::ExtrapToVertexWithoutBranson(&trackParamAtDCA, vertex[2]);
236     
237     // at first station
238     trackParam->SetParamForUncorrected(esdTrack);
239     trackParam->SetCovFor(esdTrack);
240     
241     // at vertex
242     trackParamAtVtx.SetParamFor(esdTrack);
243     
244     // at Distance of Closest Approach
245     trackParamAtDCA.SetParamForDCA(esdTrack);
246     
247     // global info
248     esdTrack.SetChi2(track->GetGlobalChi2());
249     esdTrack.SetNHit(track->GetNClusters());
250     esdTrack.SetLocalTrigger(track->GetLocalTrigger());
251     esdTrack.SetChi2MatchTrigger(track->GetChi2MatchTrigger());
252     esdTrack.SetHitsPatternInTrigCh(track->GetHitsPatternInTrigCh());
253     
254     // muon cluster info
255     while (trackParam) {
256       cluster = trackParam->GetClusterPtr();
257       
258       // new ESD muon cluster
259       AliESDMuonCluster esdCluster;
260       
261       // fill minimum info in ESD cluster
262       esdCluster.SetUniqueID(cluster->GetUniqueID());
263       esdCluster.SetXYZ(cluster->GetX(), cluster->GetY(), cluster->GetZ());
264       esdCluster.SetErrXY(cluster->GetErrX(), cluster->GetErrY());
265       
266       // fill additional info in ESD cluster if required and only for a fraction of events
267       if (AliMUONReconstructor::GetRecoParam()->SaveFullClusterInESD() && 
268           rand <= AliMUONReconstructor::GetRecoParam()->GetPercentOfFullClusterInESD()) {
269         
270         esdCluster.SetCharge(cluster->GetCharge());
271         esdCluster.SetChi2(cluster->GetChi2());
272         
273         // fill ESD pad with digit info
274         for (Int_t i=0; i<cluster->GetNDigits(); i++) {
275           digit = fDigitStore.FindObject(cluster->GetDigitId(i));
276           
277           // new ESD muon pad
278           AliESDMuonPad esdPad;
279           
280           esdPad.SetUniqueID(digit->GetUniqueID());
281           esdPad.SetADC(digit->ADC());
282           esdPad.SetCharge(digit->Charge());
283           
284           // add pad info in ESD cluster
285           esdCluster.AddPad(esdPad);
286         }
287         
288       }
289       
290       // add cluster info in ESD track
291       esdTrack.AddCluster(esdCluster);
292       esdTrack.AddInMuonClusterMap(cluster->GetChamberId());
293       
294       trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
295     }
296     
297     // storing ESD MUON Track into ESD Event 
298     esd->AddMuonTrack(&esdTrack);
299   } // end of loop on tracks
300 }
301
302 //_____________________________________________________________________________
303 void AliMUONTracker::CreateTrackReconstructor()
304 {
305   /// Create track reconstructor, depending on tracking mode set in RecoParam
306   
307   TString opt(AliMUONReconstructor::GetRecoParam()->GetTrackingMode());
308   opt.ToUpper();
309   
310   if (strstr(opt,"ORIGINAL"))
311   {
312     fTrackReco = new AliMUONTrackReconstructor(fClusterServer);
313   }
314   else if (strstr(opt,"KALMAN"))
315   {
316     fTrackReco = new AliMUONTrackReconstructorK(fClusterServer);
317   }
318   else
319   {
320     AliError(Form("tracking mode \"%s\" does not exist",opt.Data()));
321     return;
322   }
323   
324   AliInfo(Form("Will use %s for tracking",fTrackReco->ClassName()));
325 }
326
327 //_____________________________________________________________________________
328 void AliMUONTracker::UnloadClusters()
329 {
330   /// Clear internal clusterStore
331   
332   ClusterStore()->Clear();
333 }