1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 #include "AliMUONRefitter.h"
20 #include "AliMUONGeometryTransformer.h"
21 #include "AliMUONClusterFinderCOG.h"
22 #include "AliMUONClusterFinderMLEM.h"
23 #include "AliMUONClusterFinderSimpleFit.h"
24 #include "AliMUONPreClusterFinder.h"
25 #include "AliMUONPreClusterFinderV2.h"
26 #include "AliMUONPreClusterFinderV3.h"
27 #include "AliMUONSimpleClusterServer.h"
28 #include "AliMUONTrackReconstructor.h"
29 #include "AliMUONTrackReconstructorK.h"
30 #include "AliMUONRecoParam.h"
31 #include "AliMUONESDInterface.h"
32 #include "AliMUONVClusterStore.h"
33 #include "AliMUONVTrackStore.h"
34 #include "AliMUONTrack.h"
35 #include "AliMUONTracker.h"
38 //-----------------------------------------------------------------------------
39 /// \class AliMUONRefitter
41 /// create new MUON object from ESD objects given as input (through the ESDInterface):
43 /// - re-clusterize the ESD clusters using the attached ESD pads
44 /// (several new clusters can be reconstructed per ESD cluster)
45 /// - re-fit the ESD tracks using the attached ESD clusters
46 /// - reconstruct the ESD tracks from ESD pads (i.e. re-clusterized the attached clusters)
49 /// - connexion between an ESD cluster and corresponding MUON clusters from re-clustering
50 /// can be made through the detection element ID
51 /// - connexion between an ESD track and the corresponding refitted MUON track
52 /// can be made through their unique ID
54 /// \author Philippe Pillot
55 //-----------------------------------------------------------------------------
58 ClassImp(AliMUONRefitter)
61 //_____________________________________________________________________________
62 AliMUONRefitter::AliMUONRefitter()
64 fGeometryTransformer(0x0),
69 /// Default constructor
70 CreateGeometryTransformer();
71 CreateClusterServer(*fGeometryTransformer);
72 if (fClusterServer) fTracker = AliMUONTracker::CreateTrackReconstructor(AliMUONReconstructor::GetRecoParam()->GetTrackingMode(),fClusterServer);
73 if (!fClusterServer || !fTracker) {
74 AliFatal("refitter initialization failed");
79 //_____________________________________________________________________________
80 AliMUONRefitter::~AliMUONRefitter()
83 delete fGeometryTransformer;
84 delete fClusterServer;
88 //_____________________________________________________________________________
89 AliMUONVTrackStore* AliMUONRefitter::ReconstructFromDigits()
91 /// re-reconstruct all tracks and attached clusters from the digits
92 /// it is the responsability of the user to delete the returned store
95 AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct");
99 // prepare new track(s)
100 AliMUONVTrackStore* newTrackStore = AliMUONESDInterface::NewTrackStore();
101 if (!newTrackStore) return 0x0;
103 // loop over tracks and refit them (create new tracks)
105 TIter next(fESDInterface->CreateTrackIterator());
106 while ((track = static_cast<AliMUONTrack*>(next()))) {
107 AliMUONTrack *newTrack = RetrackFromDigits(*track);
108 newTrackStore->Add(newTrack);
112 return newTrackStore;
115 //_____________________________________________________________________________
116 AliMUONVTrackStore* AliMUONRefitter::ReconstructFromClusters()
118 /// refit all tracks from the attached clusters
119 /// it is the responsability of the user to delete the returned store
121 if (!fESDInterface) {
122 AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct");
126 // prepare new track(s)
127 AliMUONVTrackStore* newTrackStore = AliMUONESDInterface::NewTrackStore();
128 if (!newTrackStore) return 0x0;
130 // loop over tracks and refit them (create new tracks)
132 TIter next(fESDInterface->CreateTrackIterator());
133 while ((track = static_cast<AliMUONTrack*>(next()))) {
134 AliMUONTrack* newTrack = newTrackStore->Add(*track);
135 if (!fTracker->RefitTrack(*newTrack)) newTrackStore->Remove(*newTrack);
138 return newTrackStore;
141 //_____________________________________________________________________________
142 AliMUONTrack* AliMUONRefitter::RetrackFromDigits(UInt_t trackId)
144 /// refit track "trackId" from the digits (i.e. re-clusterized the attached clusters)
145 /// it is the responsability of the user to delete the returned track
147 if (!fESDInterface) {
148 AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct");
152 // get the track to refit
153 AliMUONTrack* track = fESDInterface->FindTrack(trackId);
155 return track ? RetrackFromDigits(*track) : 0x0;
158 //_____________________________________________________________________________
159 AliMUONTrack* AliMUONRefitter::RetrackFromClusters(UInt_t trackId)
161 /// refit track "trackId" form the clusters (i.e. do not re-clusterize)
162 /// it is the responsability of the user to delete the returned track
164 if (!fESDInterface) {
165 AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct");
169 // get the track to refit
170 AliMUONTrack* track = fESDInterface->FindTrack(trackId);
171 if (!track) return 0x0;
173 // refit the track (create a new one)
174 AliMUONTrack* newTrack = new AliMUONTrack(*track);
175 if (!fTracker->RefitTrack(*newTrack)) {
183 //_____________________________________________________________________________
184 AliMUONVClusterStore* AliMUONRefitter::ReClusterize(UInt_t trackId, UInt_t clusterId)
186 /// re-clusterize cluster numbered "clusterId" in track "trackId"
187 /// several new clusters may be reconstructed
188 /// it is the responsability of the user to delete the returned store
190 if (!fESDInterface) {
191 AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct");
195 // get the cluster to re-clusterize
196 AliMUONVCluster* cluster = fESDInterface->FindCluster(trackId,clusterId);
197 if (!cluster) return 0x0;
199 // check if digits exist
200 if (cluster->GetNDigits() == 0) {
201 AliError(Form("no digit attached to cluster #%d in track %d",clusterId,trackId));
205 // create the cluster store
206 AliMUONVClusterStore* clusterStore = AliMUONESDInterface::NewClusterStore();
207 if (!clusterStore) return 0x0;
210 TIter next(fESDInterface->CreateDigitIterator(trackId, clusterId));
211 fClusterServer->UseDigits(next);
212 fClusterServer->Clusterize(cluster->GetChamberId(),*clusterStore,AliMpArea());
217 //_____________________________________________________________________________
218 AliMUONVClusterStore* AliMUONRefitter::ReClusterize(UInt_t clusterId)
220 /// re-clusterize cluster "clusterId"
221 /// several new clusters may be reconstructed
222 /// it is the responsability of the user to delete the returned store
224 if (!fESDInterface) {
225 AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct");
229 // get the cluster to re-clusterize
230 AliMUONVCluster* cluster = fESDInterface->FindCluster(clusterId);
231 if (!cluster) return 0x0;
233 // check if digits exist
234 if (cluster->GetNDigits() == 0) {
235 AliError(Form("no digit attached to cluster %d",clusterId));
239 // create the cluster store
240 AliMUONVClusterStore* clusterStore = AliMUONESDInterface::NewClusterStore();
241 if (!clusterStore) return 0x0;
244 TIter next(fESDInterface->CreateDigitIteratorInCluster(clusterId));
245 fClusterServer->UseDigits(next);
246 fClusterServer->Clusterize(cluster->GetChamberId(),*clusterStore,AliMpArea());
251 //_____________________________________________________________________________
252 void AliMUONRefitter::CreateGeometryTransformer()
254 /// Create geometry transformer (local<->global)
255 /// and load geometry data
256 fGeometryTransformer = new AliMUONGeometryTransformer();
257 fGeometryTransformer->LoadGeometryData();
260 //_____________________________________________________________________________
261 void AliMUONRefitter::CreateClusterServer(AliMUONGeometryTransformer& transformer)
263 /// Create cluster server
264 AliMUONVClusterFinder* clusterFinder = AliMUONReconstructor::CreateClusterFinder(AliMUONReconstructor::GetRecoParam()->GetClusteringMode());
265 fClusterServer = clusterFinder ? new AliMUONSimpleClusterServer(clusterFinder,transformer) : 0x0;
268 //_____________________________________________________________________________
269 AliMUONTrack* AliMUONRefitter::RetrackFromDigits(const AliMUONTrack& track)
271 /// refit the given track from the digits (i.e. re-clusterized the attached clusters):
272 /// several new clusters may be reconstructed per initial ESD cluster:
273 /// -> all the combinations of clusters are considered to build the new tracks
274 /// -> return the best track (largest number of clusters or best chi2 in case of equality)
276 // check if digits exist
277 UInt_t trackId = track.GetUniqueID();
278 if (fESDInterface->GetNDigits(trackId) == 0) {
279 AliError(Form("no digit attached to track #%d",trackId));
283 // prepare new track(s)
284 AliMUONVTrackStore* newTrackStore = AliMUONESDInterface::NewTrackStore();
285 if (!newTrackStore) return 0x0;
286 newTrackStore->Add(track)->Clear("C");
288 // prepare new cluster store
289 AliMUONVClusterStore* newClusterStore = AliMUONESDInterface::NewClusterStore();
290 if (!newClusterStore) {
291 delete newTrackStore;
295 // loop over clusters, re-clusterize and build new tracks
296 AliMUONVCluster* cluster;
297 TIter nextCluster(fESDInterface->CreateClusterIterator(trackId));
298 while ((cluster = static_cast<AliMUONVCluster*>(nextCluster()))) {
300 // reset the new cluster store
301 newClusterStore->Clear();
303 // re-clusterize current cluster
304 TIter nextDigit(fESDInterface->CreateDigitIterator(trackId, cluster->GetUniqueID()));
305 fClusterServer->UseDigits(nextDigit);
306 Int_t nNewClusters = fClusterServer->Clusterize(cluster->GetChamberId(),*newClusterStore,AliMpArea());
308 // check that re-clusterizing succeeded
309 if (nNewClusters == 0) {
310 AliWarning(Form("refit gave no cluster (chamber %d)",cluster->GetChamberId()));
311 AliInfo("initial ESD cluster:");
312 cluster->Print("FULL");
316 // add the new cluster(s) to the tracks
317 AddClusterToTracks(*newClusterStore, *newTrackStore);
321 // refit the tracks and pick up the best one
322 AliMUONTrack *currentTrack, *bestTrack = 0x0;
323 Double_t currentChi2, bestChi2 = 1.e10;
324 Int_t currentNCluster, bestNClusters = 0;
325 TIter next(newTrackStore->CreateIterator());
326 while ((currentTrack = static_cast<AliMUONTrack*>(next()))) {
328 // set the track parameters at first cluster if any (used as seed in original tracking)
329 AliMUONTrackParam* param = (AliMUONTrackParam*) currentTrack->GetTrackParamAtCluster()->First();
330 if (param) *param = *((AliMUONTrackParam*) track.GetTrackParamAtCluster()->First());
333 if (!fTracker->RefitTrack(*currentTrack)) break;
335 // find best track (the one with the higher number of cluster or the best chi2 in case of equality)
336 currentNCluster = currentTrack->GetNClusters();
337 currentChi2 = currentTrack->GetGlobalChi2();
338 if (currentNCluster > bestNClusters || (currentNCluster == bestNClusters && currentChi2 < bestChi2)) {
339 bestTrack = currentTrack;
340 bestNClusters = currentNCluster;
341 bestChi2 = currentChi2;
346 // copy best track and free memory
347 AliMUONTrack* newTrack = bestTrack ? new AliMUONTrack(*bestTrack) : 0x0;
348 delete newClusterStore;
349 delete newTrackStore;
354 //_____________________________________________________________________________
355 void AliMUONRefitter::AddClusterToTracks(const AliMUONVClusterStore &clusterStore, AliMUONVTrackStore &trackStore)
357 /// add clusters to each of the given tracks
358 /// duplicate the tracks if there are several clusters and add one cluster per copy
360 // create new track store if there are more than 1 cluster to add per track
361 Int_t nClusters = clusterStore.GetSize();
362 if (nClusters < 1) return;
364 AliMUONTrackParam dummyParam;
365 AliMUONTrack *currentTrack, *track;
366 AliMUONVCluster *newCluster;
367 Int_t nTracks = trackStore.GetSize();
371 // loop over existing tracks to add the cluster(s)
372 TIter nextTrack(trackStore.CreateIterator());
373 while ((currentTrack = static_cast<AliMUONTrack*>(nextTrack())) && (iTrack < nTracks)) {
377 // add the new cluster(s) to the tracks
378 // duplicate the tracks if there are several clusters
379 // the loop after loading the last cluster which is added to the current track
381 TIter nextCluster(clusterStore.CreateIterator());
382 while ((newCluster = static_cast<AliMUONVCluster*>(nextCluster())) && (iCluster < nClusters - 1)) {
386 // add a copy of the current track to the store
387 track = trackStore.Add(AliMUONTrack(*currentTrack));
389 // only set Z parameter to avoid error in AddTrackParamAtCluster()
390 // the rest will be recomputed during refit
391 dummyParam.SetZ(newCluster->GetZ());
393 // add new cluster to the new track
394 track->AddTrackParamAtCluster(dummyParam, *newCluster, kTRUE);
398 // only set Z parameter to avoid error in AddTrackParamAtCluster()
399 // the rest will be recomputed during refit
400 dummyParam.SetZ(newCluster->GetZ());
402 // add new cluster to the current track
403 currentTrack->AddTrackParamAtCluster(dummyParam, *newCluster, kTRUE);