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