]>
Commit | Line | Data |
---|---|---|
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 | #include <cstdlib> | |
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 "AliMUONReconstructor.h" | |
29 | #include "AliMUONTrackReconstructor.h" | |
30 | #include "AliMUONTrackReconstructorK.h" | |
31 | #include "AliMUONRecoParam.h" | |
32 | #include "AliMUONESDInterface.h" | |
33 | #include "AliMUONVClusterStore.h" | |
34 | #include "AliMUONVTrackStore.h" | |
35 | #include "AliMUONTrack.h" | |
36 | #include "AliMUONTracker.h" | |
37 | #include "AliMUONTrackParam.h" | |
38 | #include "AliLog.h" | |
39 | ||
40 | //----------------------------------------------------------------------------- | |
41 | /// \class AliMUONRefitter | |
42 | /// | |
43 | /// This class has been developped to simplify the re-reconstruction of the MUON tracks | |
44 | /// stored into ESD with different recoParams and/or after having re-calibrated the digits. | |
45 | /// It creates new MUON object from ESD objects given as input (through the ESDInterface) then: | |
46 | /// | |
47 | /// - re-clusterize the ESD clusters using the attached ESD pads | |
48 | /// (several new clusters can be reconstructed per ESD cluster) | |
49 | /// - re-fit the ESD tracks using the attached ESD clusters | |
50 | /// - reconstruct the ESD tracks from ESD pads (i.e. re-clusterized the attached clusters) | |
51 | /// | |
52 | /// note: | |
53 | /// - connexion between an ESD cluster and corresponding MUON clusters from re-clustering | |
54 | /// can be made through the detection element ID | |
55 | /// - connexion between an ESD track and the corresponding refitted MUON track | |
56 | /// can be made through their unique ID | |
57 | /// | |
58 | /// \author Philippe Pillot | |
59 | //----------------------------------------------------------------------------- | |
60 | ||
61 | /// \cond CLASSIMP | |
62 | ClassImp(AliMUONRefitter) | |
63 | /// \endcond | |
64 | ||
65 | //_____________________________________________________________________________ | |
66 | AliMUONRefitter::AliMUONRefitter(const AliMUONRecoParam* recoParam) | |
67 | : TObject(), | |
68 | fkRecoParam(recoParam), | |
69 | fkESDInterface(0x0), | |
70 | fGeometryTransformer(0x0), | |
71 | fClusterServer(0x0), | |
72 | fTracker(0x0) | |
73 | { | |
74 | /// Default constructor | |
75 | CreateGeometryTransformer(); | |
76 | CreateClusterServer(*fGeometryTransformer); | |
77 | if (fClusterServer) fTracker = AliMUONTracker::CreateTrackReconstructor(recoParam,fClusterServer); | |
78 | if (!fClusterServer || !fTracker) { | |
79 | AliFatal("refitter initialization failed"); | |
80 | exit(-1); | |
81 | } | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | AliMUONRefitter::~AliMUONRefitter() | |
86 | { | |
87 | /// Destructor | |
88 | delete fGeometryTransformer; | |
89 | delete fClusterServer; | |
90 | delete fTracker; | |
91 | } | |
92 | ||
93 | //_____________________________________________________________________________ | |
94 | AliMUONVTrackStore* AliMUONRefitter::ReconstructFromDigits() | |
95 | { | |
96 | /// re-reconstruct all tracks and attached clusters from the digits | |
97 | /// it is the responsability of the user to delete the returned store | |
98 | ||
99 | if (!fkESDInterface) { | |
100 | AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct"); | |
101 | return 0x0; | |
102 | } | |
103 | ||
104 | // prepare new track(s) | |
105 | AliMUONVTrackStore* newTrackStore = AliMUONESDInterface::NewTrackStore(); | |
106 | if (!newTrackStore) return 0x0; | |
107 | ||
108 | // loop over tracks and refit them (create new tracks) | |
109 | AliMUONTrack *track; | |
110 | TIter next(fkESDInterface->CreateTrackIterator()); | |
111 | while ((track = static_cast<AliMUONTrack*>(next()))) { | |
112 | AliMUONTrack *newTrack = RetrackFromDigits(*track); | |
113 | newTrackStore->Add(newTrack); | |
114 | delete newTrack; | |
115 | } | |
116 | ||
117 | return newTrackStore; | |
118 | } | |
119 | ||
120 | //_____________________________________________________________________________ | |
121 | AliMUONVTrackStore* AliMUONRefitter::ReconstructFromClusters() | |
122 | { | |
123 | /// refit all tracks from the attached clusters | |
124 | /// it is the responsability of the user to delete the returned store | |
125 | ||
126 | if (!fkESDInterface) { | |
127 | AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct"); | |
128 | return 0x0; | |
129 | } | |
130 | ||
131 | // prepare new track(s) | |
132 | AliMUONVTrackStore* newTrackStore = AliMUONESDInterface::NewTrackStore(); | |
133 | if (!newTrackStore) return 0x0; | |
134 | ||
135 | // loop over tracks and refit them (create new tracks) | |
136 | AliMUONTrack *track; | |
137 | TIter next(fkESDInterface->CreateTrackIterator()); | |
138 | while ((track = static_cast<AliMUONTrack*>(next()))) { | |
139 | AliMUONTrack* newTrack = newTrackStore->Add(*track); | |
140 | if (!fTracker->RefitTrack(*newTrack)) newTrackStore->Remove(*newTrack); | |
141 | } | |
142 | ||
143 | return newTrackStore; | |
144 | } | |
145 | ||
146 | //_____________________________________________________________________________ | |
147 | AliMUONTrack* AliMUONRefitter::RetrackFromDigits(UInt_t trackId) | |
148 | { | |
149 | /// refit track "trackId" from the digits (i.e. re-clusterized the attached clusters) | |
150 | /// it is the responsability of the user to delete the returned track | |
151 | ||
152 | if (!fkESDInterface) { | |
153 | AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct"); | |
154 | return 0x0; | |
155 | } | |
156 | ||
157 | // get the track to refit | |
158 | AliMUONTrack* track = fkESDInterface->FindTrack(trackId); | |
159 | ||
160 | return track ? RetrackFromDigits(*track) : 0x0; | |
161 | } | |
162 | ||
163 | //_____________________________________________________________________________ | |
164 | AliMUONTrack* AliMUONRefitter::RetrackFromClusters(UInt_t trackId) | |
165 | { | |
166 | /// refit track "trackId" form the clusters (i.e. do not re-clusterize) | |
167 | /// it is the responsability of the user to delete the returned track | |
168 | ||
169 | if (!fkESDInterface) { | |
170 | AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct"); | |
171 | return 0x0; | |
172 | } | |
173 | ||
174 | // get the track to refit | |
175 | AliMUONTrack* track = fkESDInterface->FindTrack(trackId); | |
176 | if (!track) return 0x0; | |
177 | ||
178 | // refit the track (create a new one) | |
179 | AliMUONTrack* newTrack = new AliMUONTrack(*track); | |
180 | if (!fTracker->RefitTrack(*newTrack)) { | |
181 | delete newTrack; | |
182 | return 0x0; | |
183 | } | |
184 | ||
185 | return newTrack; | |
186 | } | |
187 | ||
188 | //_____________________________________________________________________________ | |
189 | AliMUONVClusterStore* AliMUONRefitter::ReClusterize(UInt_t trackId, UInt_t clusterId) | |
190 | { | |
191 | /// re-clusterize cluster numbered "clusterId" in track "trackId" | |
192 | /// several new clusters may be reconstructed | |
193 | /// it is the responsability of the user to delete the returned store | |
194 | ||
195 | if (!fkESDInterface) { | |
196 | AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct"); | |
197 | return 0x0; | |
198 | } | |
199 | ||
200 | // get the cluster to re-clusterize | |
201 | AliMUONVCluster* cluster = fkESDInterface->FindCluster(trackId,clusterId); | |
202 | if (!cluster) return 0x0; | |
203 | ||
204 | // check if digits exist | |
205 | if (cluster->GetNDigits() == 0) { | |
206 | AliError(Form("no digit attached to cluster #%d in track %d",clusterId,trackId)); | |
207 | return 0x0; | |
208 | } | |
209 | ||
210 | // create the cluster store | |
211 | AliMUONVClusterStore* clusterStore = AliMUONESDInterface::NewClusterStore(); | |
212 | if (!clusterStore) return 0x0; | |
213 | ||
214 | // re-clusterize | |
215 | TIter next(fkESDInterface->CreateDigitIterator(trackId, clusterId)); | |
216 | fClusterServer->UseDigits(next); | |
217 | fClusterServer->Clusterize(cluster->GetChamberId(),*clusterStore,AliMpArea(),fkRecoParam); | |
218 | ||
219 | return clusterStore; | |
220 | } | |
221 | ||
222 | //_____________________________________________________________________________ | |
223 | AliMUONVClusterStore* AliMUONRefitter::ReClusterize(UInt_t clusterId) | |
224 | { | |
225 | /// re-clusterize cluster "clusterId" | |
226 | /// several new clusters may be reconstructed | |
227 | /// it is the responsability of the user to delete the returned store | |
228 | ||
229 | if (!fkESDInterface) { | |
230 | AliError("the refitter must be connected to an ESDInterface containing the ESD event to reconstruct"); | |
231 | return 0x0; | |
232 | } | |
233 | ||
234 | // get the cluster to re-clusterize | |
235 | AliMUONVCluster* cluster = fkESDInterface->FindCluster(clusterId); | |
236 | if (!cluster) return 0x0; | |
237 | ||
238 | // check if digits exist | |
239 | if (cluster->GetNDigits() == 0) { | |
240 | AliError(Form("no digit attached to cluster %d",clusterId)); | |
241 | return 0x0; | |
242 | } | |
243 | ||
244 | // create the cluster store | |
245 | AliMUONVClusterStore* clusterStore = AliMUONESDInterface::NewClusterStore(); | |
246 | if (!clusterStore) return 0x0; | |
247 | ||
248 | // re-clusterize | |
249 | TIter next(fkESDInterface->CreateDigitIteratorInCluster(clusterId)); | |
250 | fClusterServer->UseDigits(next); | |
251 | fClusterServer->Clusterize(cluster->GetChamberId(),*clusterStore,AliMpArea(),fkRecoParam); | |
252 | ||
253 | return clusterStore; | |
254 | } | |
255 | ||
256 | //_____________________________________________________________________________ | |
257 | void AliMUONRefitter::CreateGeometryTransformer() | |
258 | { | |
259 | /// Create geometry transformer (local<->global) | |
260 | /// and load geometry data | |
261 | fGeometryTransformer = new AliMUONGeometryTransformer(); | |
262 | fGeometryTransformer->LoadGeometryData(); | |
263 | } | |
264 | ||
265 | //_____________________________________________________________________________ | |
266 | void AliMUONRefitter::CreateClusterServer(AliMUONGeometryTransformer& transformer) | |
267 | { | |
268 | /// Create cluster server | |
269 | AliMUONVClusterFinder* clusterFinder = AliMUONReconstructor::CreateClusterFinder(fkRecoParam->GetClusteringMode()); | |
270 | fClusterServer = clusterFinder ? new AliMUONSimpleClusterServer(clusterFinder,transformer) : 0x0; | |
271 | } | |
272 | ||
273 | //_____________________________________________________________________________ | |
274 | AliMUONTrack* AliMUONRefitter::RetrackFromDigits(const AliMUONTrack& track) | |
275 | { | |
276 | /// refit the given track from the digits (i.e. re-clusterized the attached clusters): | |
277 | /// several new clusters may be reconstructed per initial ESD cluster: | |
278 | /// -> all the combinations of clusters are considered to build the new tracks | |
279 | /// -> return the best track (largest number of clusters or best chi2 in case of equality) | |
280 | ||
281 | // check if digits exist | |
282 | UInt_t trackId = track.GetUniqueID(); | |
283 | if (fkESDInterface->GetNDigits(trackId) == 0) { | |
284 | AliError(Form("no digit attached to track #%d",trackId)); | |
285 | return 0x0; | |
286 | } | |
287 | ||
288 | // prepare new track(s) | |
289 | AliMUONVTrackStore* newTrackStore = AliMUONESDInterface::NewTrackStore(); | |
290 | if (!newTrackStore) return 0x0; | |
291 | newTrackStore->Add(track)->Clear("C"); | |
292 | ||
293 | // prepare new cluster store | |
294 | AliMUONVClusterStore* newClusterStore = AliMUONESDInterface::NewClusterStore(); | |
295 | if (!newClusterStore) { | |
296 | delete newTrackStore; | |
297 | return 0x0; | |
298 | } | |
299 | ||
300 | // loop over clusters, re-clusterize and build new tracks | |
301 | AliMUONVCluster* cluster; | |
302 | TIter nextCluster(fkESDInterface->CreateClusterIterator(trackId)); | |
303 | while ((cluster = static_cast<AliMUONVCluster*>(nextCluster()))) { | |
304 | ||
305 | // reset the new cluster store | |
306 | newClusterStore->Clear(); | |
307 | ||
308 | // re-clusterize current cluster | |
309 | TIter nextDigit(fkESDInterface->CreateDigitIterator(trackId, cluster->GetUniqueID())); | |
310 | fClusterServer->UseDigits(nextDigit); | |
311 | Int_t nNewClusters = fClusterServer->Clusterize(cluster->GetChamberId(),*newClusterStore,AliMpArea(),fkRecoParam); | |
312 | ||
313 | // check that re-clusterizing succeeded | |
314 | if (nNewClusters == 0) { | |
315 | AliWarning(Form("refit gave no cluster (chamber %d)",cluster->GetChamberId())); | |
316 | AliInfo("initial ESD cluster:"); | |
317 | cluster->Print("FULL"); | |
318 | continue; | |
319 | } | |
320 | ||
321 | // add the new cluster(s) to the tracks | |
322 | AddClusterToTracks(*newClusterStore, *newTrackStore); | |
323 | ||
324 | } | |
325 | ||
326 | // refit the tracks and pick up the best one | |
327 | AliMUONTrack *currentTrack, *bestTrack = 0x0; | |
328 | Double_t currentChi2, bestChi2 = 1.e10; | |
329 | Int_t currentNCluster, bestNClusters = 0; | |
330 | TIter next(newTrackStore->CreateIterator()); | |
331 | while ((currentTrack = static_cast<AliMUONTrack*>(next()))) { | |
332 | ||
333 | // set the track parameters at first cluster if any (used as seed in original tracking) | |
334 | AliMUONTrackParam* param = (AliMUONTrackParam*) currentTrack->GetTrackParamAtCluster()->First(); | |
335 | if (param) *param = *((AliMUONTrackParam*) track.GetTrackParamAtCluster()->First()); | |
336 | ||
337 | // refit the track | |
338 | if (!fTracker->RefitTrack(*currentTrack)) break; | |
339 | ||
340 | // find best track (the one with the higher number of cluster or the best chi2 in case of equality) | |
341 | currentNCluster = currentTrack->GetNClusters(); | |
342 | currentChi2 = currentTrack->GetGlobalChi2(); | |
343 | if (currentNCluster > bestNClusters || (currentNCluster == bestNClusters && currentChi2 < bestChi2)) { | |
344 | bestTrack = currentTrack; | |
345 | bestNClusters = currentNCluster; | |
346 | bestChi2 = currentChi2; | |
347 | } | |
348 | ||
349 | } | |
350 | ||
351 | // copy best track and free memory | |
352 | AliMUONTrack* newTrack = bestTrack ? new AliMUONTrack(*bestTrack) : 0x0; | |
353 | delete newClusterStore; | |
354 | delete newTrackStore; | |
355 | ||
356 | return newTrack; | |
357 | } | |
358 | ||
359 | //_____________________________________________________________________________ | |
360 | void AliMUONRefitter::AddClusterToTracks(const AliMUONVClusterStore &clusterStore, AliMUONVTrackStore &trackStore) | |
361 | { | |
362 | /// add clusters to each of the given tracks | |
363 | /// duplicate the tracks if there are several clusters and add one cluster per copy | |
364 | ||
365 | // create new track store if there are more than 1 cluster to add per track | |
366 | Int_t nClusters = clusterStore.GetSize(); | |
367 | if (nClusters < 1) return; | |
368 | ||
369 | AliMUONTrackParam dummyParam; | |
370 | AliMUONTrack *currentTrack, *track; | |
371 | AliMUONVCluster *newCluster; | |
372 | Int_t nTracks = trackStore.GetSize(); | |
373 | Int_t iTrack = 0; | |
374 | Int_t iCluster = 0; | |
375 | ||
376 | // loop over existing tracks to add the cluster(s) | |
377 | TIter nextTrack(trackStore.CreateIterator()); | |
378 | while ((currentTrack = static_cast<AliMUONTrack*>(nextTrack())) && (iTrack < nTracks)) { | |
379 | ||
380 | iTrack++; | |
381 | ||
382 | // add the new cluster(s) to the tracks | |
383 | // duplicate the tracks if there are several clusters | |
384 | // the loop after loading the last cluster which is added to the current track | |
385 | iCluster = 0; | |
386 | TIter nextCluster(clusterStore.CreateIterator()); | |
387 | while ((newCluster = static_cast<AliMUONVCluster*>(nextCluster())) && (iCluster < nClusters - 1)) { | |
388 | ||
389 | iCluster++; | |
390 | ||
391 | // add a copy of the current track to the store | |
392 | track = trackStore.Add(AliMUONTrack(*currentTrack)); | |
393 | ||
394 | // only set Z parameter to avoid error in AddTrackParamAtCluster() | |
395 | // the rest will be recomputed during refit | |
396 | dummyParam.SetZ(newCluster->GetZ()); | |
397 | ||
398 | // add new cluster to the new track | |
399 | track->AddTrackParamAtCluster(dummyParam, *newCluster, kTRUE); | |
400 | ||
401 | } | |
402 | ||
403 | // only set Z parameter to avoid error in AddTrackParamAtCluster() | |
404 | // the rest will be recomputed during refit | |
405 | dummyParam.SetZ(newCluster->GetZ()); | |
406 | ||
407 | // add new cluster to the current track | |
408 | currentTrack->AddTrackParamAtCluster(dummyParam, *newCluster, kTRUE); | |
409 | ||
410 | } | |
411 | ||
412 | } | |
413 |