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