1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for running the reconstruction //
22 // Clusters and tracks are created for all detectors and all events by //
25 // AliReconstruction rec; //
28 // The Run method returns kTRUE in case of successful execution. //
29 // The name of the galice file can be changed from the default //
30 // "galice.root" by passing it as argument to the AliReconstruction //
31 // constructor or by //
33 // rec.SetGAliceFile("..."); //
35 // The local reconstruction can be switched on or off for individual //
38 // rec.SetRunLocalReconstruction("..."); //
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. //
44 // The tracking in ITS, TPC and TRD and the creation of ESD tracks can be //
47 // rec.SetRunTracking(kFALSE); //
49 // The filling of additional ESD information can be steered by //
51 // rec.SetFillESD("..."); //
53 // Again, the string specifies the list of detectors. The default is "ALL". //
55 // The reconstruction requires digits as input. For the creation of digits //
56 // have a look at the class AliSimulation. //
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. //
69 ///////////////////////////////////////////////////////////////////////////////
75 #include <TPluginManager.h>
76 #include <TStopwatch.h>
78 #include "AliReconstruction.h"
79 #include "AliRunLoader.h"
81 #include "AliTracker.h"
83 #include "AliESDVertex.h"
84 #include "AliVertexer.h"
85 #include "AliHeader.h"
86 #include "AliGenEventHeader.h"
87 #include "AliESDpid.h"
90 ClassImp(AliReconstruction)
93 //_____________________________________________________________________________
94 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "RICH", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "START", "VZERO", "CRT", "HLT"};
96 //_____________________________________________________________________________
97 AliReconstruction::AliReconstruction(const char* gAliceFilename,
98 const char* name, const char* title) :
101 fRunLocalReconstruction("ALL"),
102 fRunVertexFinder(kTRUE),
105 fGAliceFileName(gAliceFilename),
106 fStopOnError(kFALSE),
120 // create reconstruction object with default parameters
124 //_____________________________________________________________________________
125 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
128 fRunLocalReconstruction(rec.fRunLocalReconstruction),
129 fRunVertexFinder(rec.fRunVertexFinder),
130 fRunTracking(rec.fRunTracking),
131 fFillESD(rec.fFillESD),
132 fGAliceFileName(rec.fGAliceFileName),
133 fStopOnError(rec.fStopOnError),
151 //_____________________________________________________________________________
152 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
154 // assignment operator
156 this->~AliReconstruction();
157 new(this) AliReconstruction(rec);
161 //_____________________________________________________________________________
162 AliReconstruction::~AliReconstruction()
170 //_____________________________________________________________________________
171 void AliReconstruction::SetGAliceFile(const char* fileName)
173 // set the name of the galice file
175 fGAliceFileName = fileName;
179 //_____________________________________________________________________________
180 Bool_t AliReconstruction::Run()
182 // run the reconstruction
184 // open the run loader
185 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
187 Error("Run", "no run loader found in file %s",
188 fGAliceFileName.Data());
192 fRunLoader->LoadgAlice();
193 AliRun* aliRun = fRunLoader->GetAliRun();
195 Error("Run", "no gAlice object found in file %s",
196 fGAliceFileName.Data());
202 // load the reconstructor objects
203 TPluginManager* pluginManager = gROOT->GetPluginManager();
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) && detName != "HLT") continue;
209 if(detName == "HLT") {
210 if (!gROOT->GetClass("AliLevel3")) {
211 gSystem->Load("libAliL3Src.so");
212 gSystem->Load("libAliL3Misc.so");
213 gSystem->Load("libAliL3Hough.so");
214 gSystem->Load("libAliL3Comp.so");
218 AliReconstructor* reconstructor = NULL;
219 // first check if a plugin is defined for the reconstructor
220 TPluginHandler* pluginHandler =
221 pluginManager->FindHandler("AliReconstructor", detName);
222 // if not, but the reconstructor class is implemented, add a plugin for it
223 if (!pluginHandler && gROOT->GetClass(recName.Data())) {
224 Info("Run", "defining plugin for %s", recName.Data());
225 pluginManager->AddHandler("AliReconstructor", detName,
226 recName, detName, recName + "()");
227 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
229 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
230 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
232 // if there is no reconstructor class for the detector use the dummy one
233 if (!reconstructor && gAlice->GetDetector(detName)) {
234 Info("Run", "using dummy reconstructor for %s", detName.Data());
235 reconstructor = new AliDummyReconstructor(gAlice->GetDetector(detName));
237 if (reconstructor) fReconstructors.Add(reconstructor);
240 // local reconstruction
241 if (!fRunLocalReconstruction.IsNull()) {
242 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
243 if (fStopOnError) {CleanUp(); return kFALSE;}
246 if (!fRunVertexFinder && !fRunTracking && fFillESD.IsNull()) return kTRUE;
249 if (fRunVertexFinder && !CreateVertexer()) {
256 // get loaders and trackers
257 if (fRunTracking && !CreateTrackers()) {
264 // create the ESD output file and tree
265 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
266 if (!file->IsOpen()) {
267 Error("Run", "opening AliESDs.root failed");
268 if (fStopOnError) {CleanUp(file); return kFALSE;}
270 AliESD* esd = new AliESD;
271 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
272 tree->Branch("ESD", "AliESD", &esd);
277 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
278 Info("Run", "processing event %d", iEvent);
279 fRunLoader->GetEvent(iEvent);
282 sprintf(fileName, "ESD_%d.%d_final.root",
283 aliRun->GetRunNumber(), aliRun->GetEvNumber());
284 if (!gSystem->AccessPathName(fileName)) continue;
287 esd->SetRunNumber(aliRun->GetRunNumber());
288 esd->SetEventNumber(aliRun->GetEvNumber());
289 esd->SetMagneticField(aliRun->Field()->SolenoidField());
292 if (fRunVertexFinder) {
293 if (!ReadESD(esd, "vertex")) {
294 if (!RunVertexFinder(esd)) {
295 if (fStopOnError) {CleanUp(file); return kFALSE;}
297 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
303 if (!ReadESD(esd, "tracking")) {
304 if (!RunTracking(esd)) {
305 if (fStopOnError) {CleanUp(file); return kFALSE;}
307 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
312 if (!fFillESD.IsNull()) {
313 if (!FillESD(esd, fFillESD)) {
314 if (fStopOnError) {CleanUp(file); return kFALSE;}
319 AliESDpid::MakePID(esd);
320 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
325 if (fCheckPointLevel > 0) WriteESD(esd, "final");
337 //_____________________________________________________________________________
338 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
340 // run the local reconstruction
342 TStopwatch stopwatch;
345 TString detStr = detectors;
346 for (Int_t iDet = 0; iDet < fReconstructors.GetEntriesFast(); iDet++) {
347 AliReconstructor* reconstructor =
348 (AliReconstructor*) fReconstructors[iDet];
349 TString detName = reconstructor->GetDetectorName();
350 if (IsSelected(detName, detStr)) {
351 Info("RunReconstruction", "running reconstruction for %s",
353 TStopwatch stopwatchDet;
354 stopwatchDet.Start();
355 reconstructor->Reconstruct(fRunLoader);
356 Info("RunReconstruction", "execution time for %s:", detName.Data());
357 stopwatchDet.Print();
361 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
362 Error("RunReconstruction", "the following detectors were not found: %s",
364 if (fStopOnError) return kFALSE;
367 Info("RunReconstruction", "execution time:");
373 //_____________________________________________________________________________
374 Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
376 // run the barrel tracking
378 TStopwatch stopwatch;
381 AliESDVertex* vertex = NULL;
382 Double_t vtxPos[3] = {0, 0, 0};
383 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
385 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
386 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
387 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
391 Info("RunVertexFinder", "running the ITS vertex finder");
392 fITSVertexer->SetDebug(1);
393 vertex = fITSVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
395 Warning("RunVertexFinder","Vertex not found \n");
396 vertex = new AliESDVertex();
399 vertex->SetTruePos(vtxPos); // store also the vertex from MC
403 Info("RunVertexFinder", "getting the primary vertex from MC");
404 vertex = new AliESDVertex(vtxPos, vtxErr);
408 vertex->GetXYZ(vtxPos);
409 vertex->GetSigmaXYZ(vtxErr);
411 Warning("RunVertexFinder", "no vertex reconstructed");
412 vertex = new AliESDVertex(vtxPos, vtxErr);
414 esd->SetVertex(vertex);
415 if (fITSTracker) fITSTracker->SetVertex(vtxPos, vtxErr);
416 if (fTPCTracker) fTPCTracker->SetVertex(vtxPos, vtxErr);
417 if (fTRDTracker) fTRDTracker->SetVertex(vtxPos, vtxErr);
420 Info("RunVertexFinder", "execution time:");
426 //_____________________________________________________________________________
427 Bool_t AliReconstruction::RunTracking(AliESD*& esd)
429 // run the barrel tracking
431 TStopwatch stopwatch;
435 Error("RunTracking", "no TPC tracker");
440 Info("RunTracking", "TPC tracking");
441 fTPCLoader->LoadRecPoints("read");
442 TTree* tpcTree = fTPCLoader->TreeR();
444 Error("RunTracking", "Can't get the TPC cluster tree");
447 fTPCTracker->LoadClusters(tpcTree);
448 if (fTPCTracker->Clusters2Tracks(esd) != 0) {
449 Error("RunTracking", "TPC Clusters2Tracks failed");
452 if (fCheckPointLevel > 1) WriteESD(esd, "TPC.tracking");
455 Warning("RunTracking", "no ITS tracker");
458 fRunLoader->GetAliRun()->GetDetector("TPC")->FillESD(esd); // preliminary
459 AliESDpid::MakePID(esd); // PID for the ITS tracker
462 Info("RunTracking", "ITS tracking");
463 fITSLoader->LoadRecPoints("read");
464 TTree* itsTree = fITSLoader->TreeR();
466 Error("RunTracking", "Can't get the ITS cluster tree");
469 fITSTracker->LoadClusters(itsTree);
470 if (fITSTracker->Clusters2Tracks(esd) != 0) {
471 Error("RunTracking", "ITS Clusters2Tracks failed");
474 if (fCheckPointLevel > 1) WriteESD(esd, "ITS.tracking");
477 Warning("RunTracking", "no TRD tracker");
479 // ITS back propagation
480 Info("RunTracking", "ITS back propagation");
481 if (fITSTracker->PropagateBack(esd) != 0) {
482 Error("RunTracking", "ITS backward propagation failed");
485 if (fCheckPointLevel > 1) WriteESD(esd, "ITS.back");
487 // TPC back propagation
488 Info("RunTracking", "TPC back propagation");
489 if (fTPCTracker->PropagateBack(esd) != 0) {
490 Error("RunTracking", "TPC backward propagation failed");
493 if (fCheckPointLevel > 1) WriteESD(esd, "TPC.back");
495 // TRD back propagation
496 Info("RunTracking", "TRD back propagation");
497 fTRDLoader->LoadRecPoints("read");
498 TTree* trdTree = fTRDLoader->TreeR();
500 Error("RunTracking", "Can't get the TRD cluster tree");
503 fTRDTracker->LoadClusters(trdTree);
504 if (fTRDTracker->PropagateBack(esd) != 0) {
505 Error("RunTracking", "TRD backward propagation failed");
508 if (fCheckPointLevel > 1) WriteESD(esd, "TRD.back");
511 Warning("RunTracking", "no TOF tracker");
513 // TOF back propagation
514 Info("RunTracking", "TOF back propagation");
515 fTOFLoader->LoadDigits("read");
516 TTree* tofTree = fTOFLoader->TreeD();
518 Error("RunTracking", "Can't get the TOF digits tree");
521 fTOFTracker->LoadClusters(tofTree);
522 if (fTOFTracker->PropagateBack(esd) != 0) {
523 Error("RunTracking", "TOF backward propagation failed");
526 if (fCheckPointLevel > 1) WriteESD(esd, "TOF.back");
527 fTOFTracker->UnloadClusters();
528 fTOFLoader->UnloadDigits();
532 Info("RunTracking", "TRD inward refit");
533 if (fTRDTracker->RefitInward(esd) != 0) {
534 Error("RunTracking", "TRD inward refit failed");
537 if (fCheckPointLevel > 1) WriteESD(esd, "TRD.refit");
538 fTRDTracker->UnloadClusters();
539 fTRDLoader->UnloadRecPoints();
542 Info("RunTracking", "TPC inward refit");
543 if (fTPCTracker->RefitInward(esd) != 0) {
544 Error("RunTracking", "TPC inward refit failed");
547 if (fCheckPointLevel > 1) WriteESD(esd, "TPC.refit");
550 Info("RunTracking", "ITS inward refit");
551 if (fITSTracker->RefitInward(esd) != 0) {
552 Error("RunTracking", "ITS inward refit failed");
555 if (fCheckPointLevel > 1) WriteESD(esd, "ITS.refit");
558 fITSTracker->UnloadClusters();
559 fITSLoader->UnloadRecPoints();
562 fTPCTracker->UnloadClusters();
563 fTPCLoader->UnloadRecPoints();
565 Info("RunTracking", "execution time:");
571 //_____________________________________________________________________________
572 Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
574 // fill the event summary data
576 TStopwatch stopwatch;
579 TString detStr = detectors;
580 for (Int_t iDet = 0; iDet < fReconstructors.GetEntriesFast(); iDet++) {
581 AliReconstructor* reconstructor =
582 (AliReconstructor*) fReconstructors[iDet];
583 TString detName = reconstructor->GetDetectorName();
584 if (IsSelected(detName, detStr)) {
585 if (!ReadESD(esd, detName.Data())) {
586 Info("FillESD", "filling ESD for %s", detName.Data());
587 reconstructor->FillESD(fRunLoader, esd);
588 if (fCheckPointLevel > 2) WriteESD(esd, detName.Data());
593 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
594 Error("FillESD", "the following detectors were not found: %s",
596 if (fStopOnError) return kFALSE;
599 Info("FillESD", "execution time:");
606 //_____________________________________________________________________________
607 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
609 // check whether detName is contained in detectors
610 // if yes, it is removed from detectors
612 // check if all detectors are selected
613 if ((detectors.CompareTo("ALL") == 0) ||
614 detectors.BeginsWith("ALL ") ||
615 detectors.EndsWith(" ALL") ||
616 detectors.Contains(" ALL ")) {
621 // search for the given detector
622 Bool_t result = kFALSE;
623 if ((detectors.CompareTo(detName) == 0) ||
624 detectors.BeginsWith(detName+" ") ||
625 detectors.EndsWith(" "+detName) ||
626 detectors.Contains(" "+detName+" ")) {
627 detectors.ReplaceAll(detName, "");
631 // clean up the detectors string
632 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
633 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
634 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
639 //_____________________________________________________________________________
640 AliReconstructor* AliReconstruction::GetReconstructor(const char* detName) const
642 // get the reconstructor object for a detector
644 for (Int_t iDet = 0; iDet < fReconstructors.GetEntriesFast(); iDet++) {
645 AliReconstructor* reconstructor =
646 (AliReconstructor*) fReconstructors[iDet];
647 if (strcmp(reconstructor->GetDetectorName(), detName) == 0) {
648 return reconstructor;
654 //_____________________________________________________________________________
655 Bool_t AliReconstruction::CreateVertexer()
657 // create the vertexer
660 AliReconstructor* itsReconstructor = GetReconstructor("ITS");
661 if (itsReconstructor) {
662 fITSVertexer = itsReconstructor->CreateVertexer(fRunLoader);
665 Warning("CreateVertexer", "couldn't create a vertexer for ITS");
666 if (fStopOnError) return kFALSE;
672 //_____________________________________________________________________________
673 Bool_t AliReconstruction::CreateTrackers()
675 // get the loaders and create the trackers
678 fITSLoader = fRunLoader->GetLoader("ITSLoader");
680 Warning("CreateTrackers", "no ITS loader found");
681 if (fStopOnError) return kFALSE;
683 AliReconstructor* itsReconstructor = GetReconstructor("ITS");
684 if (itsReconstructor) {
685 fITSTracker = itsReconstructor->CreateTracker(fRunLoader);
688 Warning("CreateTrackers", "couldn't create a tracker for ITS");
689 if (fStopOnError) return kFALSE;
694 fTPCLoader = fRunLoader->GetLoader("TPCLoader");
696 Error("CreateTrackers", "no TPC loader found");
697 if (fStopOnError) return kFALSE;
699 AliReconstructor* tpcReconstructor = GetReconstructor("TPC");
700 if (tpcReconstructor) {
701 fTPCTracker = tpcReconstructor->CreateTracker(fRunLoader);
704 Error("CreateTrackers", "couldn't create a tracker for TPC");
705 if (fStopOnError) return kFALSE;
710 fTRDLoader = fRunLoader->GetLoader("TRDLoader");
712 Warning("CreateTrackers", "no TRD loader found");
713 if (fStopOnError) return kFALSE;
715 AliReconstructor* trdReconstructor = GetReconstructor("TRD");
716 if (trdReconstructor) {
717 fTRDTracker = trdReconstructor->CreateTracker(fRunLoader);
720 Warning("CreateTrackers", "couldn't create a tracker for TRD");
721 if (fStopOnError) return kFALSE;
726 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
728 Warning("CreateTrackers", "no TOF loader found");
729 if (fStopOnError) return kFALSE;
731 AliReconstructor* tofReconstructor = GetReconstructor("TOF");
732 if (tofReconstructor) {
733 fTOFTracker = tofReconstructor->CreateTracker(fRunLoader);
736 Warning("CreateTrackers", "couldn't create a tracker for TOF");
737 if (fStopOnError) return kFALSE;
744 //_____________________________________________________________________________
745 void AliReconstruction::CleanUp(TFile* file)
747 // delete trackers and the run loader and close and delete the file
749 fReconstructors.Delete();
772 //_____________________________________________________________________________
773 Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
775 // read the ESD event from a file
777 if (!esd) return kFALSE;
779 sprintf(fileName, "ESD_%d.%d_%s.root",
780 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
781 if (gSystem->AccessPathName(fileName)) return kFALSE;
783 Info("ReadESD", "reading ESD from file %s", fileName);
784 TFile* file = TFile::Open(fileName);
785 if (!file || !file->IsOpen()) {
786 Error("ReadESD", "opening %s failed", fileName);
793 esd = (AliESD*) file->Get("ESD");
799 //_____________________________________________________________________________
800 void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
802 // write the ESD event to a file
806 sprintf(fileName, "ESD_%d.%d_%s.root",
807 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
809 Info("WriteESD", "writing ESD to file %s", fileName);
810 TFile* file = TFile::Open(fileName, "recreate");
811 if (!file || !file->IsOpen()) {
812 Error("WriteESD", "opening %s failed", fileName);