]>
Commit | Line | Data |
---|---|---|
596a855f | 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 | // // | |
20 | // class for running the reconstruction // | |
21 | // // | |
22 | // Clusters and tracks are created for all detectors and all events by // | |
23 | // typing: // | |
24 | // // | |
25 | // AliReconstruction rec; // | |
26 | // rec.Run(); // | |
27 | // // | |
28 | // The Run method returns kTRUE in case of successful execution. // | |
29 | // The name of the galice file can be changed from the default // | |
e583c30d | 30 | // "galice.root" by passing it as argument to the AliReconstruction // |
31 | // constructor or by // | |
596a855f | 32 | // // |
33 | // rec.SetGAliceFile("..."); // | |
34 | // // | |
59697224 | 35 | // The local reconstruction can be switched on or off for individual // |
36 | // detectors by // | |
596a855f | 37 | // // |
59697224 | 38 | // rec.SetRunLocalReconstruction("..."); // |
596a855f | 39 | // // |
40 | // The argument is a (case sensitive) string with the names of the // | |
41 | // detectors separated by a space. The special string "ALL" selects all // | |
42 | // available detectors. This is the default. // | |
43 | // // | |
44 | // The tracking in ITS, TPC and TRD and the creation of ESD tracks can be // | |
45 | // switched off by // | |
46 | // // | |
47 | // rec.SetRunTracking(kFALSE); // | |
48 | // // | |
49 | // The filling of additional ESD information can be steered by // | |
50 | // // | |
51 | // rec.SetFillESD("..."); // | |
52 | // // | |
53 | // Again, the string specifies the list of detectors. The default is "ALL". // | |
54 | // // | |
55 | // The reconstruction requires digits as input. For the creation of digits // | |
56 | // have a look at the class AliSimulation. // | |
57 | // // | |
24f7a148 | 58 | // For debug purposes the method SetCheckPointLevel can be used. If the // |
59 | // argument is greater than 0, files with ESD events will be written after // | |
60 | // selected steps of the reconstruction for each event: // | |
61 | // level 1: after tracking and after filling of ESD (final) // | |
62 | // level 2: in addition after each tracking step // | |
63 | // level 3: in addition after the filling of ESD for each detector // | |
64 | // If a final check point file exists for an event, this event will be // | |
65 | // skipped in the reconstruction. The tracking and the filling of ESD for // | |
66 | // a detector will be skipped as well, if the corresponding check point // | |
67 | // file exists. The ESD event will then be loaded from the file instead. // | |
68 | // // | |
596a855f | 69 | /////////////////////////////////////////////////////////////////////////////// |
70 | ||
024a7e64 | 71 | #include <TArrayF.h> |
72 | #include <TFile.h> | |
73 | #include <TSystem.h> | |
74 | #include <TROOT.h> | |
75 | #include <TPluginManager.h> | |
fd46e2d2 | 76 | #include <TStopwatch.h> |
596a855f | 77 | |
78 | #include "AliReconstruction.h" | |
79 | #include "AliRunLoader.h" | |
80 | #include "AliRun.h" | |
596a855f | 81 | #include "AliTracker.h" |
82 | #include "AliESD.h" | |
2257f27e | 83 | #include "AliESDVertex.h" |
84 | #include "AliVertexer.h" | |
596a855f | 85 | #include "AliHeader.h" |
86 | #include "AliGenEventHeader.h" | |
87 | #include "AliESDpid.h" | |
a866ac60 | 88 | #include "AliMagF.h" |
596a855f | 89 | |
90 | ClassImp(AliReconstruction) | |
91 | ||
92 | ||
c757bafd | 93 | //_____________________________________________________________________________ |
94 | const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "RICH", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "START", "VZERO", "CRT"}; | |
95 | ||
596a855f | 96 | //_____________________________________________________________________________ |
e583c30d | 97 | AliReconstruction::AliReconstruction(const char* gAliceFilename, |
98 | const char* name, const char* title) : | |
99 | TNamed(name, title), | |
100 | ||
59697224 | 101 | fRunLocalReconstruction("ALL"), |
2257f27e | 102 | fRunVertexFinder(kTRUE), |
e583c30d | 103 | fRunTracking(kTRUE), |
104 | fFillESD("ALL"), | |
105 | fGAliceFileName(gAliceFilename), | |
106 | fStopOnError(kFALSE), | |
24f7a148 | 107 | fCheckPointLevel(0), |
e583c30d | 108 | |
109 | fRunLoader(NULL), | |
110 | fITSLoader(NULL), | |
2257f27e | 111 | fITSVertexer(NULL), |
e583c30d | 112 | fITSTracker(NULL), |
113 | fTPCLoader(NULL), | |
114 | fTPCTracker(NULL), | |
115 | fTRDLoader(NULL), | |
116 | fTRDTracker(NULL), | |
117 | fTOFLoader(NULL), | |
118 | fTOFTracker(NULL) | |
596a855f | 119 | { |
120 | // create reconstruction object with default parameters | |
121 | ||
596a855f | 122 | } |
123 | ||
124 | //_____________________________________________________________________________ | |
125 | AliReconstruction::AliReconstruction(const AliReconstruction& rec) : | |
e583c30d | 126 | TNamed(rec), |
127 | ||
59697224 | 128 | fRunLocalReconstruction(rec.fRunLocalReconstruction), |
2257f27e | 129 | fRunVertexFinder(rec.fRunVertexFinder), |
e583c30d | 130 | fRunTracking(rec.fRunTracking), |
131 | fFillESD(rec.fFillESD), | |
132 | fGAliceFileName(rec.fGAliceFileName), | |
133 | fStopOnError(rec.fStopOnError), | |
24f7a148 | 134 | fCheckPointLevel(0), |
e583c30d | 135 | |
136 | fRunLoader(NULL), | |
137 | fITSLoader(NULL), | |
2257f27e | 138 | fITSVertexer(NULL), |
e583c30d | 139 | fITSTracker(NULL), |
140 | fTPCLoader(NULL), | |
141 | fTPCTracker(NULL), | |
142 | fTRDLoader(NULL), | |
143 | fTRDTracker(NULL), | |
144 | fTOFLoader(NULL), | |
145 | fTOFTracker(NULL) | |
596a855f | 146 | { |
147 | // copy constructor | |
148 | ||
596a855f | 149 | } |
150 | ||
151 | //_____________________________________________________________________________ | |
152 | AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec) | |
153 | { | |
154 | // assignment operator | |
155 | ||
156 | this->~AliReconstruction(); | |
157 | new(this) AliReconstruction(rec); | |
158 | return *this; | |
159 | } | |
160 | ||
161 | //_____________________________________________________________________________ | |
162 | AliReconstruction::~AliReconstruction() | |
163 | { | |
164 | // clean up | |
165 | ||
e583c30d | 166 | CleanUp(); |
596a855f | 167 | } |
168 | ||
169 | ||
170 | //_____________________________________________________________________________ | |
171 | void AliReconstruction::SetGAliceFile(const char* fileName) | |
172 | { | |
173 | // set the name of the galice file | |
174 | ||
175 | fGAliceFileName = fileName; | |
176 | } | |
177 | ||
178 | ||
179 | //_____________________________________________________________________________ | |
180 | Bool_t AliReconstruction::Run() | |
181 | { | |
182 | // run the reconstruction | |
183 | ||
184 | // open the run loader | |
596a855f | 185 | fRunLoader = AliRunLoader::Open(fGAliceFileName.Data()); |
186 | if (!fRunLoader) { | |
187 | Error("Run", "no run loader found in file %s", | |
188 | fGAliceFileName.Data()); | |
e583c30d | 189 | CleanUp(); |
596a855f | 190 | return kFALSE; |
191 | } | |
192 | fRunLoader->LoadgAlice(); | |
e583c30d | 193 | AliRun* aliRun = fRunLoader->GetAliRun(); |
194 | if (!aliRun) { | |
596a855f | 195 | Error("Run", "no gAlice object found in file %s", |
196 | fGAliceFileName.Data()); | |
e583c30d | 197 | CleanUp(); |
596a855f | 198 | return kFALSE; |
199 | } | |
e583c30d | 200 | gAlice = aliRun; |
596a855f | 201 | |
59697224 | 202 | // load the reconstructor objects |
203 | TPluginManager* pluginManager = gROOT->GetPluginManager(); | |
c757bafd | 204 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { |
205 | TString detName = fgkDetectorName[iDet]; | |
206 | TString recName = "Ali" + detName + "Reconstructor"; | |
207 | if (!gAlice->GetDetector(detName)) continue; | |
208 | ||
209 | AliReconstructor* reconstructor = NULL; | |
210 | // first check if a plugin is defined for the reconstructor | |
59697224 | 211 | TPluginHandler* pluginHandler = |
c757bafd | 212 | pluginManager->FindHandler("AliReconstructor", detName); |
213 | // if not, but the reconstructor class is implemented, add a plugin for it | |
214 | if (!pluginHandler && gROOT->GetClass(recName.Data())) { | |
215 | Info("Run", "defining plugin for %s", recName.Data()); | |
216 | pluginManager->AddHandler("AliReconstructor", detName, | |
217 | recName, detName, recName + "()"); | |
218 | pluginHandler = pluginManager->FindHandler("AliReconstructor", detName); | |
219 | } | |
220 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
221 | reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0); | |
222 | } | |
223 | // if there is no reconstructor class for the detector use the dummy one | |
224 | if (!reconstructor) { | |
225 | Info("Run", "using dummy reconstructor for %s", detName.Data()); | |
226 | reconstructor = new AliDummyReconstructor(gAlice->GetDetector(detName)); | |
227 | } | |
59697224 | 228 | if (reconstructor) fReconstructors.Add(reconstructor); |
229 | } | |
230 | ||
596a855f | 231 | // local reconstruction |
59697224 | 232 | if (!fRunLocalReconstruction.IsNull()) { |
233 | if (!RunLocalReconstruction(fRunLocalReconstruction)) { | |
e583c30d | 234 | if (fStopOnError) {CleanUp(); return kFALSE;} |
596a855f | 235 | } |
236 | } | |
2257f27e | 237 | if (!fRunVertexFinder && !fRunTracking && fFillESD.IsNull()) return kTRUE; |
238 | ||
239 | // get vertexer | |
240 | if (fRunVertexFinder && !CreateVertexer()) { | |
241 | if (fStopOnError) { | |
242 | CleanUp(); | |
243 | return kFALSE; | |
244 | } | |
245 | } | |
596a855f | 246 | |
24f7a148 | 247 | // get loaders and trackers |
248 | if (fRunTracking && !CreateTrackers()) { | |
249 | if (fStopOnError) { | |
250 | CleanUp(); | |
251 | return kFALSE; | |
252 | } | |
596a855f | 253 | } |
24f7a148 | 254 | |
596a855f | 255 | // create the ESD output file |
256 | TFile* file = TFile::Open("AliESDs.root", "RECREATE"); | |
257 | if (!file->IsOpen()) { | |
258 | Error("Run", "opening AliESDs.root failed"); | |
e583c30d | 259 | if (fStopOnError) {CleanUp(file); return kFALSE;} |
596a855f | 260 | } |
261 | ||
262 | // loop over events | |
263 | for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) { | |
264 | Info("Run", "processing event %d", iEvent); | |
596a855f | 265 | fRunLoader->GetEvent(iEvent); |
24f7a148 | 266 | |
267 | char fileName[256]; | |
268 | sprintf(fileName, "ESD_%d.%d_final.root", | |
269 | aliRun->GetRunNumber(), aliRun->GetEvNumber()); | |
270 | if (!gSystem->AccessPathName(fileName)) continue; | |
271 | ||
272 | AliESD* esd = new AliESD; | |
e583c30d | 273 | esd->SetRunNumber(aliRun->GetRunNumber()); |
274 | esd->SetEventNumber(aliRun->GetEvNumber()); | |
275 | esd->SetMagneticField(aliRun->Field()->SolenoidField()); | |
596a855f | 276 | |
2257f27e | 277 | // vertex finder |
278 | if (fRunVertexFinder) { | |
279 | if (!ReadESD(esd, "vertex")) { | |
280 | if (!RunVertexFinder(esd)) { | |
281 | if (fStopOnError) {CleanUp(file); return kFALSE;} | |
282 | } | |
283 | if (fCheckPointLevel > 0) WriteESD(esd, "vertex"); | |
284 | } | |
285 | } | |
286 | ||
596a855f | 287 | // barrel tracking |
288 | if (fRunTracking) { | |
24f7a148 | 289 | if (!ReadESD(esd, "tracking")) { |
290 | if (!RunTracking(esd)) { | |
291 | if (fStopOnError) {CleanUp(file); return kFALSE;} | |
292 | } | |
293 | if (fCheckPointLevel > 0) WriteESD(esd, "tracking"); | |
596a855f | 294 | } |
295 | } | |
296 | ||
297 | // fill ESD | |
298 | if (!fFillESD.IsNull()) { | |
299 | if (!FillESD(esd, fFillESD)) { | |
e583c30d | 300 | if (fStopOnError) {CleanUp(file); return kFALSE;} |
596a855f | 301 | } |
302 | } | |
303 | ||
304 | // combined PID | |
305 | AliESDpid::MakePID(esd); | |
24f7a148 | 306 | if (fCheckPointLevel > 1) WriteESD(esd, "PID"); |
596a855f | 307 | |
308 | // write ESD | |
309 | char name[100]; | |
310 | sprintf(name, "ESD%d", iEvent); | |
311 | file->cd(); | |
312 | if (!esd->Write(name)) { | |
313 | Error("Run", "writing ESD failed"); | |
e583c30d | 314 | if (fStopOnError) {CleanUp(file); return kFALSE;} |
596a855f | 315 | } |
24f7a148 | 316 | file->Flush(); |
317 | ||
318 | if (fCheckPointLevel > 0) WriteESD(esd, "final"); | |
d9b8978b | 319 | delete esd; |
596a855f | 320 | } |
321 | ||
e583c30d | 322 | CleanUp(file); |
596a855f | 323 | |
324 | return kTRUE; | |
325 | } | |
326 | ||
327 | ||
328 | //_____________________________________________________________________________ | |
59697224 | 329 | Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors) |
596a855f | 330 | { |
59697224 | 331 | // run the local reconstruction |
596a855f | 332 | |
030b532d | 333 | TStopwatch stopwatch; |
334 | stopwatch.Start(); | |
335 | ||
596a855f | 336 | TString detStr = detectors; |
c757bafd | 337 | for (Int_t iDet = 0; iDet < fReconstructors.GetEntriesFast(); iDet++) { |
338 | AliReconstructor* reconstructor = | |
339 | (AliReconstructor*) fReconstructors[iDet]; | |
340 | TString detName = reconstructor->GetDetectorName(); | |
341 | if (IsSelected(detName, detStr)) { | |
596a855f | 342 | Info("RunReconstruction", "running reconstruction for %s", |
c757bafd | 343 | detName.Data()); |
030b532d | 344 | TStopwatch stopwatchDet; |
345 | stopwatchDet.Start(); | |
c757bafd | 346 | reconstructor->Reconstruct(fRunLoader); |
347 | Info("RunReconstruction", "execution time for %s:", detName.Data()); | |
030b532d | 348 | stopwatchDet.Print(); |
596a855f | 349 | } |
350 | } | |
351 | ||
352 | if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) { | |
353 | Error("RunReconstruction", "the following detectors were not found: %s", | |
354 | detStr.Data()); | |
355 | if (fStopOnError) return kFALSE; | |
356 | } | |
357 | ||
030b532d | 358 | Info("RunReconstruction", "execution time:"); |
359 | stopwatch.Print(); | |
360 | ||
596a855f | 361 | return kTRUE; |
362 | } | |
363 | ||
364 | //_____________________________________________________________________________ | |
2257f27e | 365 | Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd) |
596a855f | 366 | { |
367 | // run the barrel tracking | |
368 | ||
030b532d | 369 | TStopwatch stopwatch; |
370 | stopwatch.Start(); | |
371 | ||
2257f27e | 372 | AliESDVertex* vertex = NULL; |
373 | Double_t vtxPos[3] = {0, 0, 0}; | |
374 | Double_t vtxErr[3] = {0.07, 0.07, 0.1}; | |
375 | TArrayF mcVertex(3); | |
a6b0b91b | 376 | if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) { |
377 | fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex); | |
378 | for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i]; | |
379 | } | |
2257f27e | 380 | |
381 | if (fITSVertexer) { | |
382 | Info("RunVertexFinder", "running the ITS vertex finder"); | |
383 | fITSVertexer->SetDebug(1); | |
384 | vertex = fITSVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber()); | |
385 | if(!vertex){ | |
386 | Warning("RunVertexFinder","Vertex not found \n"); | |
c710f220 | 387 | vertex = new AliESDVertex(); |
2257f27e | 388 | } |
389 | else { | |
390 | vertex->SetTruePos(vtxPos); // store also the vertex from MC | |
391 | } | |
392 | ||
393 | } else { | |
394 | Info("RunVertexFinder", "getting the primary vertex from MC"); | |
395 | vertex = new AliESDVertex(vtxPos, vtxErr); | |
396 | } | |
397 | ||
398 | if (vertex) { | |
399 | vertex->GetXYZ(vtxPos); | |
400 | vertex->GetSigmaXYZ(vtxErr); | |
401 | } else { | |
402 | Warning("RunVertexFinder", "no vertex reconstructed"); | |
403 | vertex = new AliESDVertex(vtxPos, vtxErr); | |
404 | } | |
405 | esd->SetVertex(vertex); | |
24f7a148 | 406 | if (fITSTracker) fITSTracker->SetVertex(vtxPos, vtxErr); |
407 | if (fTPCTracker) fTPCTracker->SetVertex(vtxPos, vtxErr); | |
408 | if (fTRDTracker) fTRDTracker->SetVertex(vtxPos, vtxErr); | |
2257f27e | 409 | delete vertex; |
410 | ||
411 | Info("RunVertexFinder", "execution time:"); | |
412 | stopwatch.Print(); | |
413 | ||
414 | return kTRUE; | |
415 | } | |
416 | ||
417 | //_____________________________________________________________________________ | |
418 | Bool_t AliReconstruction::RunTracking(AliESD*& esd) | |
419 | { | |
420 | // run the barrel tracking | |
421 | ||
422 | TStopwatch stopwatch; | |
423 | stopwatch.Start(); | |
24f7a148 | 424 | |
425 | if (!fTPCTracker) { | |
426 | Error("RunTracking", "no TPC tracker"); | |
427 | return kFALSE; | |
428 | } | |
596a855f | 429 | |
85555ca8 | 430 | // TPC tracking |
431 | Info("RunTracking", "TPC tracking"); | |
596a855f | 432 | fTPCLoader->LoadRecPoints("read"); |
433 | TTree* tpcTree = fTPCLoader->TreeR(); | |
434 | if (!tpcTree) { | |
435 | Error("RunTracking", "Can't get the TPC cluster tree"); | |
436 | return kFALSE; | |
24f7a148 | 437 | } |
596a855f | 438 | fTPCTracker->LoadClusters(tpcTree); |
439 | if (fTPCTracker->Clusters2Tracks(esd) != 0) { | |
85555ca8 | 440 | Error("RunTracking", "TPC Clusters2Tracks failed"); |
596a855f | 441 | return kFALSE; |
442 | } | |
24f7a148 | 443 | if (fCheckPointLevel > 1) WriteESD(esd, "TPC.tracking"); |
444 | ||
445 | if (!fITSTracker) { | |
446 | Warning("RunTracking", "no ITS tracker"); | |
447 | } else { | |
448 | ||
449 | fRunLoader->GetAliRun()->GetDetector("TPC")->FillESD(esd); // preliminary | |
450 | AliESDpid::MakePID(esd); // PID for the ITS tracker | |
451 | ||
452 | // ITS tracking | |
453 | Info("RunTracking", "ITS tracking"); | |
454 | fITSLoader->LoadRecPoints("read"); | |
455 | TTree* itsTree = fITSLoader->TreeR(); | |
456 | if (!itsTree) { | |
457 | Error("RunTracking", "Can't get the ITS cluster tree"); | |
458 | return kFALSE; | |
459 | } | |
460 | fITSTracker->LoadClusters(itsTree); | |
461 | if (fITSTracker->Clusters2Tracks(esd) != 0) { | |
462 | Error("RunTracking", "ITS Clusters2Tracks failed"); | |
463 | return kFALSE; | |
464 | } | |
465 | if (fCheckPointLevel > 1) WriteESD(esd, "ITS.tracking"); | |
596a855f | 466 | |
24f7a148 | 467 | if (!fTRDTracker) { |
468 | Warning("RunTracking", "no TRD tracker"); | |
469 | } else { | |
470 | // ITS back propagation | |
471 | Info("RunTracking", "ITS back propagation"); | |
472 | if (fITSTracker->PropagateBack(esd) != 0) { | |
473 | Error("RunTracking", "ITS backward propagation failed"); | |
474 | return kFALSE; | |
475 | } | |
476 | if (fCheckPointLevel > 1) WriteESD(esd, "ITS.back"); | |
596a855f | 477 | |
24f7a148 | 478 | // TPC back propagation |
479 | Info("RunTracking", "TPC back propagation"); | |
480 | if (fTPCTracker->PropagateBack(esd) != 0) { | |
481 | Error("RunTracking", "TPC backward propagation failed"); | |
482 | return kFALSE; | |
483 | } | |
484 | if (fCheckPointLevel > 1) WriteESD(esd, "TPC.back"); | |
485 | ||
486 | // TRD back propagation | |
487 | Info("RunTracking", "TRD back propagation"); | |
488 | fTRDLoader->LoadRecPoints("read"); | |
489 | TTree* trdTree = fTRDLoader->TreeR(); | |
490 | if (!trdTree) { | |
491 | Error("RunTracking", "Can't get the TRD cluster tree"); | |
492 | return kFALSE; | |
493 | } | |
494 | fTRDTracker->LoadClusters(trdTree); | |
495 | if (fTRDTracker->PropagateBack(esd) != 0) { | |
496 | Error("RunTracking", "TRD backward propagation failed"); | |
497 | return kFALSE; | |
498 | } | |
499 | if (fCheckPointLevel > 1) WriteESD(esd, "TRD.back"); | |
500 | ||
501 | if (!fTOFTracker) { | |
502 | Warning("RunTracking", "no TOF tracker"); | |
503 | } else { | |
504 | // TOF back propagation | |
505 | Info("RunTracking", "TOF back propagation"); | |
506 | fTOFLoader->LoadDigits("read"); | |
507 | TTree* tofTree = fTOFLoader->TreeD(); | |
508 | if (!tofTree) { | |
509 | Error("RunTracking", "Can't get the TOF digits tree"); | |
510 | return kFALSE; | |
511 | } | |
512 | fTOFTracker->LoadClusters(tofTree); | |
513 | if (fTOFTracker->PropagateBack(esd) != 0) { | |
514 | Error("RunTracking", "TOF backward propagation failed"); | |
515 | return kFALSE; | |
516 | } | |
517 | if (fCheckPointLevel > 1) WriteESD(esd, "TOF.back"); | |
518 | fTOFTracker->UnloadClusters(); | |
519 | fTOFLoader->UnloadDigits(); | |
520 | } | |
596a855f | 521 | |
24f7a148 | 522 | // TRD inward refit |
523 | Info("RunTracking", "TRD inward refit"); | |
524 | if (fTRDTracker->RefitInward(esd) != 0) { | |
525 | Error("RunTracking", "TRD inward refit failed"); | |
526 | return kFALSE; | |
527 | } | |
528 | if (fCheckPointLevel > 1) WriteESD(esd, "TRD.refit"); | |
529 | fTRDTracker->UnloadClusters(); | |
530 | fTRDLoader->UnloadRecPoints(); | |
531 | ||
532 | // TPC inward refit | |
533 | Info("RunTracking", "TPC inward refit"); | |
534 | if (fTPCTracker->RefitInward(esd) != 0) { | |
535 | Error("RunTracking", "TPC inward refit failed"); | |
536 | return kFALSE; | |
537 | } | |
538 | if (fCheckPointLevel > 1) WriteESD(esd, "TPC.refit"); | |
539 | ||
540 | // ITS inward refit | |
541 | Info("RunTracking", "ITS inward refit"); | |
542 | if (fITSTracker->RefitInward(esd) != 0) { | |
543 | Error("RunTracking", "ITS inward refit failed"); | |
544 | return kFALSE; | |
545 | } | |
546 | if (fCheckPointLevel > 1) WriteESD(esd, "ITS.refit"); | |
596a855f | 547 | |
24f7a148 | 548 | } // if TRD tracker |
549 | fITSTracker->UnloadClusters(); | |
550 | fITSLoader->UnloadRecPoints(); | |
596a855f | 551 | |
24f7a148 | 552 | } // if ITS tracker |
596a855f | 553 | fTPCTracker->UnloadClusters(); |
554 | fTPCLoader->UnloadRecPoints(); | |
596a855f | 555 | |
030b532d | 556 | Info("RunTracking", "execution time:"); |
557 | stopwatch.Print(); | |
558 | ||
596a855f | 559 | return kTRUE; |
560 | } | |
561 | ||
562 | //_____________________________________________________________________________ | |
24f7a148 | 563 | Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors) |
596a855f | 564 | { |
565 | // fill the event summary data | |
566 | ||
030b532d | 567 | TStopwatch stopwatch; |
568 | stopwatch.Start(); | |
569 | ||
596a855f | 570 | TString detStr = detectors; |
c757bafd | 571 | for (Int_t iDet = 0; iDet < fReconstructors.GetEntriesFast(); iDet++) { |
572 | AliReconstructor* reconstructor = | |
573 | (AliReconstructor*) fReconstructors[iDet]; | |
574 | TString detName = reconstructor->GetDetectorName(); | |
575 | if (IsSelected(detName, detStr)) { | |
576 | if (!ReadESD(esd, detName.Data())) { | |
577 | Info("FillESD", "filling ESD for %s", detName.Data()); | |
578 | reconstructor->FillESD(fRunLoader, esd); | |
579 | if (fCheckPointLevel > 2) WriteESD(esd, detName.Data()); | |
24f7a148 | 580 | } |
596a855f | 581 | } |
582 | } | |
583 | ||
584 | if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) { | |
585 | Error("FillESD", "the following detectors were not found: %s", | |
586 | detStr.Data()); | |
587 | if (fStopOnError) return kFALSE; | |
588 | } | |
589 | ||
030b532d | 590 | Info("FillESD", "execution time:"); |
591 | stopwatch.Print(); | |
592 | ||
596a855f | 593 | return kTRUE; |
594 | } | |
595 | ||
596 | ||
597 | //_____________________________________________________________________________ | |
598 | Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const | |
599 | { | |
600 | // check whether detName is contained in detectors | |
601 | // if yes, it is removed from detectors | |
602 | ||
603 | // check if all detectors are selected | |
604 | if ((detectors.CompareTo("ALL") == 0) || | |
605 | detectors.BeginsWith("ALL ") || | |
606 | detectors.EndsWith(" ALL") || | |
607 | detectors.Contains(" ALL ")) { | |
608 | detectors = "ALL"; | |
609 | return kTRUE; | |
610 | } | |
611 | ||
612 | // search for the given detector | |
613 | Bool_t result = kFALSE; | |
614 | if ((detectors.CompareTo(detName) == 0) || | |
615 | detectors.BeginsWith(detName+" ") || | |
616 | detectors.EndsWith(" "+detName) || | |
617 | detectors.Contains(" "+detName+" ")) { | |
618 | detectors.ReplaceAll(detName, ""); | |
619 | result = kTRUE; | |
620 | } | |
621 | ||
622 | // clean up the detectors string | |
623 | while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " "); | |
624 | while (detectors.BeginsWith(" ")) detectors.Remove(0, 1); | |
625 | while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1); | |
626 | ||
627 | return result; | |
628 | } | |
e583c30d | 629 | |
c757bafd | 630 | //_____________________________________________________________________________ |
631 | AliReconstructor* AliReconstruction::GetReconstructor(const char* detName) const | |
632 | { | |
633 | // get the reconstructor object for a detector | |
634 | ||
635 | for (Int_t iDet = 0; iDet < fReconstructors.GetEntriesFast(); iDet++) { | |
636 | AliReconstructor* reconstructor = | |
637 | (AliReconstructor*) fReconstructors[iDet]; | |
638 | if (strcmp(reconstructor->GetDetectorName(), detName) == 0) { | |
639 | return reconstructor; | |
640 | } | |
641 | } | |
642 | return NULL; | |
643 | } | |
644 | ||
2257f27e | 645 | //_____________________________________________________________________________ |
646 | Bool_t AliReconstruction::CreateVertexer() | |
647 | { | |
648 | // create the vertexer | |
649 | ||
650 | fITSVertexer = NULL; | |
c757bafd | 651 | AliReconstructor* itsReconstructor = GetReconstructor("ITS"); |
59697224 | 652 | if (itsReconstructor) { |
653 | fITSVertexer = itsReconstructor->CreateVertexer(fRunLoader); | |
2257f27e | 654 | } |
655 | if (!fITSVertexer) { | |
656 | Warning("CreateVertexer", "couldn't create a vertexer for ITS"); | |
657 | if (fStopOnError) return kFALSE; | |
658 | } | |
659 | ||
660 | return kTRUE; | |
661 | } | |
662 | ||
24f7a148 | 663 | //_____________________________________________________________________________ |
664 | Bool_t AliReconstruction::CreateTrackers() | |
665 | { | |
666 | // get the loaders and create the trackers | |
667 | ||
24f7a148 | 668 | fITSTracker = NULL; |
669 | fITSLoader = fRunLoader->GetLoader("ITSLoader"); | |
670 | if (!fITSLoader) { | |
671 | Warning("CreateTrackers", "no ITS loader found"); | |
672 | if (fStopOnError) return kFALSE; | |
673 | } else { | |
c757bafd | 674 | AliReconstructor* itsReconstructor = GetReconstructor("ITS"); |
59697224 | 675 | if (itsReconstructor) { |
676 | fITSTracker = itsReconstructor->CreateTracker(fRunLoader); | |
24f7a148 | 677 | } |
678 | if (!fITSTracker) { | |
679 | Warning("CreateTrackers", "couldn't create a tracker for ITS"); | |
680 | if (fStopOnError) return kFALSE; | |
681 | } | |
682 | } | |
683 | ||
684 | fTPCTracker = NULL; | |
685 | fTPCLoader = fRunLoader->GetLoader("TPCLoader"); | |
686 | if (!fTPCLoader) { | |
687 | Error("CreateTrackers", "no TPC loader found"); | |
688 | if (fStopOnError) return kFALSE; | |
689 | } else { | |
c757bafd | 690 | AliReconstructor* tpcReconstructor = GetReconstructor("TPC"); |
59697224 | 691 | if (tpcReconstructor) { |
692 | fTPCTracker = tpcReconstructor->CreateTracker(fRunLoader); | |
24f7a148 | 693 | } |
694 | if (!fTPCTracker) { | |
695 | Error("CreateTrackers", "couldn't create a tracker for TPC"); | |
696 | if (fStopOnError) return kFALSE; | |
697 | } | |
698 | } | |
699 | ||
700 | fTRDTracker = NULL; | |
701 | fTRDLoader = fRunLoader->GetLoader("TRDLoader"); | |
702 | if (!fTRDLoader) { | |
703 | Warning("CreateTrackers", "no TRD loader found"); | |
704 | if (fStopOnError) return kFALSE; | |
705 | } else { | |
c757bafd | 706 | AliReconstructor* trdReconstructor = GetReconstructor("TRD"); |
59697224 | 707 | if (trdReconstructor) { |
708 | fTRDTracker = trdReconstructor->CreateTracker(fRunLoader); | |
24f7a148 | 709 | } |
710 | if (!fTRDTracker) { | |
711 | Warning("CreateTrackers", "couldn't create a tracker for TRD"); | |
712 | if (fStopOnError) return kFALSE; | |
713 | } | |
714 | } | |
715 | ||
716 | fTOFTracker = NULL; | |
717 | fTOFLoader = fRunLoader->GetLoader("TOFLoader"); | |
718 | if (!fTOFLoader) { | |
719 | Warning("CreateTrackers", "no TOF loader found"); | |
720 | if (fStopOnError) return kFALSE; | |
721 | } else { | |
c757bafd | 722 | AliReconstructor* tofReconstructor = GetReconstructor("TOF"); |
59697224 | 723 | if (tofReconstructor) { |
724 | fTOFTracker = tofReconstructor->CreateTracker(fRunLoader); | |
24f7a148 | 725 | } |
726 | if (!fTOFTracker) { | |
727 | Warning("CreateTrackers", "couldn't create a tracker for TOF"); | |
728 | if (fStopOnError) return kFALSE; | |
729 | } | |
730 | } | |
731 | ||
732 | return kTRUE; | |
733 | } | |
734 | ||
e583c30d | 735 | //_____________________________________________________________________________ |
736 | void AliReconstruction::CleanUp(TFile* file) | |
737 | { | |
738 | // delete trackers and the run loader and close and delete the file | |
739 | ||
59697224 | 740 | fReconstructors.Delete(); |
741 | ||
2257f27e | 742 | delete fITSVertexer; |
743 | fITSVertexer = NULL; | |
e583c30d | 744 | delete fITSTracker; |
745 | fITSTracker = NULL; | |
746 | delete fTPCTracker; | |
747 | fTPCTracker = NULL; | |
748 | delete fTRDTracker; | |
749 | fTRDTracker = NULL; | |
750 | delete fTOFTracker; | |
751 | fTOFTracker = NULL; | |
752 | ||
753 | delete fRunLoader; | |
754 | fRunLoader = NULL; | |
755 | ||
756 | if (file) { | |
757 | file->Close(); | |
758 | delete file; | |
759 | } | |
760 | } | |
24f7a148 | 761 | |
762 | ||
763 | //_____________________________________________________________________________ | |
764 | Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const | |
765 | { | |
766 | // read the ESD event from a file | |
767 | ||
768 | if (!esd) return kFALSE; | |
769 | char fileName[256]; | |
770 | sprintf(fileName, "ESD_%d.%d_%s.root", | |
771 | esd->GetRunNumber(), esd->GetEventNumber(), recStep); | |
772 | if (gSystem->AccessPathName(fileName)) return kFALSE; | |
773 | ||
774 | Info("ReadESD", "reading ESD from file %s", fileName); | |
775 | TFile* file = TFile::Open(fileName); | |
776 | if (!file || !file->IsOpen()) { | |
777 | Error("ReadESD", "opening %s failed", fileName); | |
778 | delete file; | |
779 | return kFALSE; | |
780 | } | |
781 | ||
782 | gROOT->cd(); | |
783 | delete esd; | |
784 | esd = (AliESD*) file->Get("ESD"); | |
785 | file->Close(); | |
786 | delete file; | |
787 | return kTRUE; | |
788 | } | |
789 | ||
790 | //_____________________________________________________________________________ | |
791 | void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const | |
792 | { | |
793 | // write the ESD event to a file | |
794 | ||
795 | if (!esd) return; | |
796 | char fileName[256]; | |
797 | sprintf(fileName, "ESD_%d.%d_%s.root", | |
798 | esd->GetRunNumber(), esd->GetEventNumber(), recStep); | |
799 | ||
800 | Info("WriteESD", "writing ESD to file %s", fileName); | |
801 | TFile* file = TFile::Open(fileName, "recreate"); | |
802 | if (!file || !file->IsOpen()) { | |
803 | Error("WriteESD", "opening %s failed", fileName); | |
804 | } else { | |
805 | esd->Write("ESD"); | |
806 | file->Close(); | |
807 | } | |
808 | delete file; | |
809 | } |