]>
Commit | Line | Data |
---|---|---|
d0cf54cd | 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 | ||
27de2dfb | 16 | /* $Id$ */ |
17 | ||
d0cf54cd | 18 | // ROOT includes |
19 | #include <TString.h> | |
fe0324de | 20 | #include <TList.h> |
d0cf54cd | 21 | #include <TGeoManager.h> |
22 | ||
23 | // STEER includes | |
24 | #include "AliESDEvent.h" | |
25 | #include "AliESDMuonTrack.h" | |
26 | #include "AliCDBManager.h" | |
27 | #include "AliCDBStorage.h" | |
28 | #include "AliGeomManager.h" | |
29 | ||
30 | // ANALYSIS includes | |
31 | #include "AliAnalysisManager.h" | |
32 | #include "AliInputEventHandler.h" | |
33 | #include "AliAnalysisTaskMuonRefit.h" | |
34 | ||
35 | // MUON includes | |
36 | #include "AliMUONCDB.h" | |
09c18f72 | 37 | #include "AliMUONConstants.h" |
d0cf54cd | 38 | #include "AliMUONRecoParam.h" |
39 | #include "AliMUONESDInterface.h" | |
40 | #include "AliMUONRefitter.h" | |
41 | #include "AliMUONTrack.h" | |
fe0324de | 42 | #include "AliMUONTrackParam.h" |
d0cf54cd | 43 | #include "AliMUONVCluster.h" |
44 | #include "AliMUONVTrackStore.h" | |
fe0324de | 45 | #include "AliMUONLocalTrigger.h" |
d0cf54cd | 46 | #include "AliMUONGeometryTransformer.h" |
47 | ||
48 | #ifndef SafeDelete | |
49 | #define SafeDelete(x) if (x != NULL) { delete x; x = NULL; } | |
50 | #endif | |
51 | ||
52 | ClassImp(AliAnalysisTaskMuonRefit) | |
53 | ||
54 | //________________________________________________________________________ | |
55 | AliAnalysisTaskMuonRefit::AliAnalysisTaskMuonRefit() : | |
56 | AliAnalysisTaskSE(), | |
57 | fDefaultStorage(""), | |
58 | fImproveTracks(kFALSE), | |
59 | fSigmaCut(-1.), | |
60 | fSigmaCutForTrigger(-1.), | |
61 | fReAlign(kFALSE), | |
62 | fOldAlignStorage(""), | |
63 | fNewAlignStorage(""), | |
64 | fOldGeoTransformer(NULL), | |
65 | fNewGeoTransformer(NULL), | |
66 | fESDInterface(NULL), | |
67 | fRefitter(NULL) | |
68 | { | |
69 | /// Default constructor | |
09c18f72 | 70 | for (Int_t i = 0; i < 10; i++) ResetClusterResolution(i, -1., -1.); |
d0cf54cd | 71 | } |
72 | ||
73 | //________________________________________________________________________ | |
74 | AliAnalysisTaskMuonRefit::AliAnalysisTaskMuonRefit(const char *name) : | |
75 | AliAnalysisTaskSE(name), | |
76 | fDefaultStorage("raw://"), | |
77 | fImproveTracks(kFALSE), | |
78 | fSigmaCut(-1.), | |
79 | fSigmaCutForTrigger(-1.), | |
80 | fReAlign(kFALSE), | |
81 | fOldAlignStorage(""), | |
82 | fNewAlignStorage(""), | |
83 | fOldGeoTransformer(NULL), | |
84 | fNewGeoTransformer(NULL), | |
85 | fESDInterface(NULL), | |
86 | fRefitter(NULL) | |
87 | { | |
88 | /// Constructor | |
09c18f72 | 89 | for (Int_t i = 0; i < 10; i++) ResetClusterResolution(i, -1., -1.); |
d0cf54cd | 90 | } |
91 | ||
92 | //________________________________________________________________________ | |
93 | AliAnalysisTaskMuonRefit::~AliAnalysisTaskMuonRefit() | |
94 | { | |
95 | /// Destructor | |
96 | SafeDelete(fOldGeoTransformer); | |
97 | SafeDelete(fNewGeoTransformer); | |
98 | SafeDelete(fESDInterface); | |
99 | SafeDelete(fRefitter); | |
100 | } | |
101 | ||
102 | //___________________________________________________________________________ | |
103 | void AliAnalysisTaskMuonRefit::UserCreateOutputObjects() | |
104 | { | |
105 | } | |
106 | ||
107 | //________________________________________________________________________ | |
108 | void AliAnalysisTaskMuonRefit::UserExec(Option_t *) | |
109 | { | |
110 | /// Main event loop | |
111 | ||
112 | // check if refitter properly created | |
113 | if (!fRefitter) return; | |
114 | ||
115 | AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent()); | |
116 | if (!esd) return; | |
117 | ||
118 | Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks(); | |
119 | if (nTracks < 1) return; | |
120 | ||
fe0324de | 121 | TList newGhosts; |
122 | newGhosts.SetOwner(kFALSE); | |
123 | UInt_t firstGhostId = 0xFFFFFFFF - 1; | |
124 | ||
17d7055c | 125 | TList esdTracksToRemove; |
126 | esdTracksToRemove.SetOwner(kFALSE); | |
127 | ||
d0cf54cd | 128 | // load the current event |
129 | fESDInterface->LoadEvent(*esd, kFALSE); | |
130 | ||
fe0324de | 131 | // remove clusters from ESD (keep digits as they will not change, just eventually not used anymore) |
132 | esd->FindListObject("MuonClusters")->Clear("C"); | |
133 | ||
d0cf54cd | 134 | // modify clusters |
135 | AliMUONVCluster* cluster = 0x0; | |
136 | TIter nextCluster(fESDInterface->CreateClusterIterator()); | |
137 | while ((cluster = static_cast<AliMUONVCluster*>(nextCluster()))) ModifyCluster(*cluster); | |
138 | ||
139 | // refit the tracks from clusters | |
140 | AliMUONVTrackStore* newTrackStore = fRefitter->ReconstructFromClusters(); | |
141 | ||
142 | // loop over the list of ESD tracks | |
143 | TClonesArray *esdTracks = (TClonesArray*) esd->FindListObject("MuonTracks"); | |
144 | for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) { | |
145 | ||
146 | // get the ESD track | |
147 | AliESDMuonTrack* esdTrack = (AliESDMuonTrack*) esdTracks->UncheckedAt(iTrack); | |
148 | ||
149 | // skip ghost tracks (leave them unchanged) | |
fe0324de | 150 | if (!esdTrack->ContainTrackerData()) { |
151 | if (esdTrack->GetUniqueID() <= firstGhostId) firstGhostId = esdTrack->GetUniqueID()-1; | |
152 | continue; | |
153 | } | |
d0cf54cd | 154 | |
155 | // Find the corresponding re-fitted MUON track | |
156 | AliMUONTrack* newTrack = (AliMUONTrack*) newTrackStore->FindObject(esdTrack->GetUniqueID()); | |
157 | ||
fe0324de | 158 | // Find the corresponding locaTrigger if any |
159 | AliMUONLocalTrigger *locTrg = (esdTrack->ContainTriggerData()) ? fESDInterface->FindLocalTrigger(esdTrack->LoCircuit()) : 0x0; | |
160 | if (locTrg && locTrg->IsNull()) locTrg = 0x0; | |
161 | ||
d0cf54cd | 162 | // replace the content of the current ESD track or remove it |
163 | if (newTrack && (!fImproveTracks || newTrack->IsImproved())) { | |
d0cf54cd | 164 | |
165 | // eventually remove the trigger part if matching chi2 do not pass the new cut | |
fe0324de | 166 | if (locTrg && newTrack->GetChi2MatchTrigger() > fSigmaCutForTrigger*fSigmaCutForTrigger) { |
167 | newTrack->SetMatchTrigger(0); | |
168 | newTrack->SetLocalTrigger(0,0,0,0,0,0,0); | |
169 | newTrack->SetChi2MatchTrigger(0.); | |
170 | newTrack->SetHitsPatternInTrigCh(0); | |
171 | newGhosts.AddLast(locTrg); | |
172 | locTrg = 0x0; | |
173 | } | |
174 | ||
175 | // fill the track info | |
176 | Double_t vertex[3] = {esdTrack->GetNonBendingCoor(), esdTrack->GetBendingCoor(), esdTrack->GetZ()}; | |
177 | AliMUONESDInterface::MUONToESD(*newTrack, *esdTrack, vertex, locTrg); | |
178 | ||
179 | // add the clusters if not already there | |
180 | for (Int_t i = 0; i < newTrack->GetNClusters(); i++) { | |
181 | AliMUONVCluster *cl = static_cast<AliMUONTrackParam*>(newTrack->GetTrackParamAtCluster()->UncheckedAt(i))->GetClusterPtr(); | |
182 | if (esd->FindMuonCluster(cl->GetUniqueID())) continue; | |
183 | AliESDMuonCluster *esdCl = esd->NewMuonCluster(); | |
184 | AliMUONESDInterface::MUONToESD(*cl, *esdCl, kTRUE); | |
d0cf54cd | 185 | } |
186 | ||
187 | } else { | |
fe0324de | 188 | |
189 | // keep the trigger part if any | |
190 | if (locTrg) newGhosts.AddLast(locTrg); | |
191 | ||
17d7055c | 192 | // remember to remove that track (cannot remove it now as it will create an hole which |
193 | // will eventually produce a crash in parallel track loop (AliESDEvent::MoveMuonObjects())) | |
194 | esdTracksToRemove.AddLast(esdTrack); | |
fe0324de | 195 | |
d0cf54cd | 196 | } |
197 | ||
198 | } | |
199 | ||
200 | // free memory | |
201 | delete newTrackStore; | |
202 | ||
17d7055c | 203 | // remove tracks to remove and compress the array of ESD tracks |
204 | TIter nextTrackToRemove(&esdTracksToRemove); | |
205 | AliESDMuonTrack* esdTrack = 0x0; | |
206 | while ((esdTrack = static_cast<AliESDMuonTrack*>(nextTrackToRemove()))) esdTracks->Remove(esdTrack); | |
d0cf54cd | 207 | esdTracks->Compress(); |
208 | ||
fe0324de | 209 | // add new ghosts if not already there |
210 | TIter nextGhost(&newGhosts); | |
211 | AliMUONLocalTrigger *locTrg = 0x0; | |
212 | while ((locTrg = static_cast<AliMUONLocalTrigger*>(nextGhost()))) { | |
213 | Bool_t alreadyThere = kFALSE; | |
214 | for (Int_t iTrack = 0; iTrack < esdTracks->GetEntriesFast(); iTrack++) { | |
17d7055c | 215 | esdTrack = (AliESDMuonTrack*) esdTracks->UncheckedAt(iTrack); |
fe0324de | 216 | alreadyThere = (esdTrack->LoCircuit() == locTrg->LoCircuit()); |
217 | if (alreadyThere) break; | |
218 | } | |
219 | if (!alreadyThere) AliMUONESDInterface::MUONToESD(*locTrg, *esd, firstGhostId--); | |
220 | } | |
221 | ||
d0cf54cd | 222 | } |
223 | ||
224 | //________________________________________________________________________ | |
225 | void AliAnalysisTaskMuonRefit::NotifyRun() | |
226 | { | |
227 | /// load necessary data from OCDB and create the refitter | |
228 | ||
229 | AliCDBManager* cdbm = AliCDBManager::Instance(); | |
230 | cdbm->SetDefaultStorage(fDefaultStorage.Data()); | |
231 | cdbm->SetRun(fCurrentRunNumber); | |
232 | ||
233 | if (!AliMUONCDB::LoadField()) return; | |
234 | ||
235 | if (!AliMUONCDB::LoadMapping(kTRUE)) return; | |
236 | ||
237 | AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam(); | |
238 | if (!recoParam) return; | |
239 | ||
240 | if (fImproveTracks) { | |
241 | if (fSigmaCut > 0.) recoParam->ImproveTracks(kTRUE, fSigmaCut); | |
242 | else recoParam->ImproveTracks(kTRUE); | |
243 | } else recoParam->ImproveTracks(kFALSE); | |
244 | ||
245 | if (fSigmaCutForTrigger > 0.) recoParam->SetSigmaCutForTrigger(fSigmaCutForTrigger); | |
246 | else fSigmaCutForTrigger = recoParam->GetSigmaCutForTrigger(); | |
247 | ||
248 | for (Int_t i = 0; i < AliMUONConstants::NTrackingCh(); i++) { | |
249 | if (fClusterResNB[i] < 0.) fClusterResNB[i] = recoParam->GetDefaultNonBendingReso(i); | |
250 | if (fClusterResB[i] < 0.) fClusterResB[i] = recoParam->GetDefaultBendingReso(i); | |
251 | } | |
252 | ||
253 | if (fReAlign) { | |
254 | ||
255 | // recover default storage full name (raw:// cannot be used to set specific storage) | |
256 | TString defaultStorage(cdbm->GetDefaultStorage()->GetType()); | |
257 | if (defaultStorage == "alien") defaultStorage += Form("://folder=%s", cdbm->GetDefaultStorage()->GetBaseFolder().Data()); | |
258 | else defaultStorage += Form("://%s", cdbm->GetDefaultStorage()->GetBaseFolder().Data()); | |
259 | ||
260 | // reset existing geometry/alignment if any | |
261 | if (cdbm->GetEntryCache()->Contains("GRP/Geometry/Data")) cdbm->UnloadFromCache("GRP/Geometry/Data"); | |
262 | if (cdbm->GetEntryCache()->Contains("MUON/Align/Data")) cdbm->UnloadFromCache("MUON/Align/Data"); | |
263 | if (AliGeomManager::GetGeometry()) AliGeomManager::GetGeometry()->UnlockGeometry(); | |
264 | ||
265 | // get original geometry transformer | |
266 | AliGeomManager::LoadGeometry(); | |
267 | if (!AliGeomManager::GetGeometry()) return; | |
268 | if (fOldAlignStorage != "none") { | |
269 | if (!fOldAlignStorage.IsNull()) cdbm->SetSpecificStorage("MUON/Align/Data",fOldAlignStorage.Data()); | |
270 | else cdbm->SetSpecificStorage("MUON/Align/Data",defaultStorage.Data()); | |
271 | AliGeomManager::ApplyAlignObjsFromCDB("MUON"); | |
272 | } | |
273 | fOldGeoTransformer = new AliMUONGeometryTransformer(); | |
274 | fOldGeoTransformer->LoadGeometryData(); | |
275 | ||
276 | // get new geometry transformer | |
277 | cdbm->UnloadFromCache("GRP/Geometry/Data"); | |
278 | if (fOldAlignStorage != "none") cdbm->UnloadFromCache("MUON/Align/Data"); | |
279 | AliGeomManager::GetGeometry()->UnlockGeometry(); | |
280 | AliGeomManager::LoadGeometry(); | |
281 | if (!AliGeomManager::GetGeometry()) return; | |
282 | if (!fNewAlignStorage.IsNull()) cdbm->SetSpecificStorage("MUON/Align/Data",fNewAlignStorage.Data()); | |
283 | else cdbm->SetSpecificStorage("MUON/Align/Data",defaultStorage.Data()); | |
284 | AliGeomManager::ApplyAlignObjsFromCDB("MUON"); | |
285 | fNewGeoTransformer = new AliMUONGeometryTransformer(); | |
286 | fNewGeoTransformer->LoadGeometryData(); | |
287 | ||
288 | } else { | |
289 | ||
290 | // load geometry for track extrapolation to vertex | |
291 | if (cdbm->GetEntryCache()->Contains("GRP/Geometry/Data")) cdbm->UnloadFromCache("GRP/Geometry/Data"); | |
292 | if (AliGeomManager::GetGeometry()) AliGeomManager::GetGeometry()->UnlockGeometry(); | |
293 | AliGeomManager::LoadGeometry(); | |
294 | if (!AliGeomManager::GetGeometry()) return; | |
295 | ||
296 | } | |
297 | ||
298 | fESDInterface = new AliMUONESDInterface(); | |
299 | fRefitter = new AliMUONRefitter(recoParam); | |
300 | fRefitter->Connect(fESDInterface); | |
301 | } | |
302 | ||
303 | //________________________________________________________________________ | |
304 | void AliAnalysisTaskMuonRefit::Terminate(Option_t *) | |
305 | { | |
306 | } | |
307 | ||
308 | //________________________________________________________________________ | |
309 | void AliAnalysisTaskMuonRefit::ModifyCluster(AliMUONVCluster& cl) | |
310 | { | |
311 | /// Reset the cluster resolution to the one given to the task and change | |
312 | /// the cluster position according to the new alignment parameters if required | |
313 | ||
314 | Double_t gX,gY,gZ,lX,lY,lZ; | |
315 | ||
316 | // change their resolution | |
317 | cl.SetErrXY(fClusterResNB[cl.GetChamberId()], fClusterResB[cl.GetChamberId()]); | |
318 | ||
319 | // change their position | |
320 | if (fReAlign) { | |
321 | gX = cl.GetX(); | |
322 | gY = cl.GetY(); | |
323 | gZ = cl.GetZ(); | |
324 | fOldGeoTransformer->Global2Local(cl.GetDetElemId(),gX,gY,gZ,lX,lY,lZ); | |
325 | fNewGeoTransformer->Local2Global(cl.GetDetElemId(),lX,lY,lZ,gX,gY,gZ); | |
326 | cl.SetXYZ(gX,gY,gZ); | |
327 | } | |
328 | ||
329 | } | |
330 |