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),
123 // create reconstruction object with default parameters
127 //_____________________________________________________________________________
128 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
131 fRunLocalReconstruction(rec.fRunLocalReconstruction),
132 fRunVertexFinder(rec.fRunVertexFinder),
133 fRunTracking(rec.fRunTracking),
134 fFillESD(rec.fFillESD),
135 fGAliceFileName(rec.fGAliceFileName),
136 fStopOnError(rec.fStopOnError),
155 for (Int_t i = 0; i < fOptions.GetEntriesFast(); i++) {
156 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
160 //_____________________________________________________________________________
161 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
163 // assignment operator
165 this->~AliReconstruction();
166 new(this) AliReconstruction(rec);
170 //_____________________________________________________________________________
171 AliReconstruction::~AliReconstruction()
180 //_____________________________________________________________________________
181 void AliReconstruction::SetGAliceFile(const char* fileName)
183 // set the name of the galice file
185 fGAliceFileName = fileName;
188 //_____________________________________________________________________________
189 void AliReconstruction::SetOption(const char* detector, const char* option)
191 // set options for the reconstruction of a detector
193 TObject* obj = fOptions.FindObject(detector);
194 if (obj) fOptions.Remove(obj);
195 fOptions.Add(new TNamed(detector, option));
199 //_____________________________________________________________________________
200 Bool_t AliReconstruction::Run()
202 // run the reconstruction
204 // open the run loader
205 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
207 Error("Run", "no run loader found in file %s",
208 fGAliceFileName.Data());
212 fRunLoader->LoadgAlice();
213 AliRun* aliRun = fRunLoader->GetAliRun();
215 Error("Run", "no gAlice object found in file %s",
216 fGAliceFileName.Data());
222 // load the reconstructor objects
223 TPluginManager* pluginManager = gROOT->GetPluginManager();
224 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
225 TString detName = fgkDetectorName[iDet];
226 TString recName = "Ali" + detName + "Reconstructor";
227 if (!gAlice->GetDetector(detName) && detName != "HLT") continue;
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");
238 AliReconstructor* reconstructor = NULL;
239 // first check if a plugin is defined for the reconstructor
240 TPluginHandler* pluginHandler =
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);
249 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
250 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
252 // if there is no reconstructor class for the detector use the dummy one
253 if (!reconstructor && gAlice->GetDetector(detName)) {
254 Info("Run", "using dummy reconstructor for %s", detName.Data());
255 reconstructor = new AliDummyReconstructor(gAlice->GetDetector(detName));
258 TObject* obj = fOptions.FindObject(detName.Data());
259 if (obj) reconstructor->SetOption(obj->GetTitle());
260 fReconstructors.Add(reconstructor);
264 // local reconstruction
265 if (!fRunLocalReconstruction.IsNull()) {
266 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
267 if (fStopOnError) {CleanUp(); return kFALSE;}
270 if (!fRunVertexFinder && !fRunTracking && fFillESD.IsNull()) return kTRUE;
273 if (fRunVertexFinder && !CreateVertexer()) {
280 // get loaders and trackers
281 if (fRunTracking && !CreateTrackers()) {
288 // create the ESD output file and tree
289 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
290 if (!file->IsOpen()) {
291 Error("Run", "opening AliESDs.root failed");
292 if (fStopOnError) {CleanUp(file); return kFALSE;}
294 AliESD* esd = new AliESD;
295 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
296 tree->Branch("ESD", "AliESD", &esd);
301 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
302 Info("Run", "processing event %d", iEvent);
303 fRunLoader->GetEvent(iEvent);
306 sprintf(fileName, "ESD_%d.%d_final.root",
307 aliRun->GetRunNumber(), aliRun->GetEvNumber());
308 if (!gSystem->AccessPathName(fileName)) continue;
311 esd->SetRunNumber(aliRun->GetRunNumber());
312 esd->SetEventNumber(aliRun->GetEvNumber());
313 esd->SetMagneticField(aliRun->Field()->SolenoidField());
316 if (fRunVertexFinder) {
317 if (!ReadESD(esd, "vertex")) {
318 if (!RunVertexFinder(esd)) {
319 if (fStopOnError) {CleanUp(file); return kFALSE;}
321 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
327 if (!ReadESD(esd, "tracking")) {
328 if (!RunTracking(esd)) {
329 if (fStopOnError) {CleanUp(file); return kFALSE;}
331 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
336 if (!fFillESD.IsNull()) {
337 if (!FillESD(esd, fFillESD)) {
338 if (fStopOnError) {CleanUp(file); return kFALSE;}
343 AliESDpid::MakePID(esd);
344 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
349 if (fCheckPointLevel > 0) WriteESD(esd, "final");
361 //_____________________________________________________________________________
362 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
364 // run the local reconstruction
366 TStopwatch stopwatch;
369 TString detStr = detectors;
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)) {
375 Info("RunReconstruction", "running reconstruction for %s",
377 TStopwatch stopwatchDet;
378 stopwatchDet.Start();
379 reconstructor->Reconstruct(fRunLoader);
380 Info("RunReconstruction", "execution time for %s:", detName.Data());
381 stopwatchDet.Print();
385 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
386 Error("RunReconstruction", "the following detectors were not found: %s",
388 if (fStopOnError) return kFALSE;
391 Info("RunReconstruction", "execution time:");
397 //_____________________________________________________________________________
398 Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
400 // run the barrel tracking
402 TStopwatch stopwatch;
405 AliESDVertex* vertex = NULL;
406 Double_t vtxPos[3] = {0, 0, 0};
407 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
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];
415 Info("RunVertexFinder", "running the ITS vertex finder");
416 fITSVertexer->SetDebug(1);
417 vertex = fITSVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
419 Warning("RunVertexFinder","Vertex not found \n");
420 vertex = new AliESDVertex();
423 vertex->SetTruePos(vtxPos); // store also the vertex from MC
427 Info("RunVertexFinder", "getting the primary vertex from MC");
428 vertex = new AliESDVertex(vtxPos, vtxErr);
432 vertex->GetXYZ(vtxPos);
433 vertex->GetSigmaXYZ(vtxErr);
435 Warning("RunVertexFinder", "no vertex reconstructed");
436 vertex = new AliESDVertex(vtxPos, vtxErr);
438 esd->SetVertex(vertex);
439 if (fITSTracker) fITSTracker->SetVertex(vtxPos, vtxErr);
440 if (fTPCTracker) fTPCTracker->SetVertex(vtxPos, vtxErr);
441 if (fTRDTracker) fTRDTracker->SetVertex(vtxPos, vtxErr);
444 Info("RunVertexFinder", "execution time:");
450 //_____________________________________________________________________________
451 Bool_t AliReconstruction::RunTracking(AliESD*& esd)
453 // run the barrel tracking
455 TStopwatch stopwatch;
459 Error("RunTracking", "no TPC tracker");
464 Info("RunTracking", "TPC tracking");
465 fTPCLoader->LoadRecPoints("read");
466 TTree* tpcTree = fTPCLoader->TreeR();
468 Error("RunTracking", "Can't get the TPC cluster tree");
471 fTPCTracker->LoadClusters(tpcTree);
472 if (fTPCTracker->Clusters2Tracks(esd) != 0) {
473 Error("RunTracking", "TPC Clusters2Tracks failed");
476 if (fCheckPointLevel > 1) WriteESD(esd, "TPC.tracking");
479 Warning("RunTracking", "no ITS tracker");
482 GetReconstructor("TPC")->FillESD(fRunLoader, esd); // preliminary
483 AliESDpid::MakePID(esd); // PID for the ITS tracker
486 Info("RunTracking", "ITS tracking");
487 fITSLoader->LoadRecPoints("read");
488 TTree* itsTree = fITSLoader->TreeR();
490 Error("RunTracking", "Can't get the ITS cluster tree");
493 fITSTracker->LoadClusters(itsTree);
494 if (fITSTracker->Clusters2Tracks(esd) != 0) {
495 Error("RunTracking", "ITS Clusters2Tracks failed");
498 if (fCheckPointLevel > 1) WriteESD(esd, "ITS.tracking");
501 Warning("RunTracking", "no TRD tracker");
503 // ITS back propagation
504 Info("RunTracking", "ITS back propagation");
505 if (fITSTracker->PropagateBack(esd) != 0) {
506 Error("RunTracking", "ITS backward propagation failed");
509 if (fCheckPointLevel > 1) WriteESD(esd, "ITS.back");
511 // TPC back propagation
512 Info("RunTracking", "TPC back propagation");
513 if (fTPCTracker->PropagateBack(esd) != 0) {
514 Error("RunTracking", "TPC backward propagation failed");
517 if (fCheckPointLevel > 1) WriteESD(esd, "TPC.back");
519 // TRD back propagation
520 Info("RunTracking", "TRD back propagation");
521 fTRDLoader->LoadRecPoints("read");
522 TTree* trdTree = fTRDLoader->TreeR();
524 Error("RunTracking", "Can't get the TRD cluster tree");
527 fTRDTracker->LoadClusters(trdTree);
528 if (fTRDTracker->PropagateBack(esd) != 0) {
529 Error("RunTracking", "TRD backward propagation failed");
532 if (fCheckPointLevel > 1) WriteESD(esd, "TRD.back");
535 Warning("RunTracking", "no TOF tracker");
537 // TOF back propagation
538 Info("RunTracking", "TOF back propagation");
539 fTOFLoader->LoadDigits("read");
540 TTree* tofTree = fTOFLoader->TreeD();
542 Error("RunTracking", "Can't get the TOF digits tree");
545 fTOFTracker->LoadClusters(tofTree);
546 if (fTOFTracker->PropagateBack(esd) != 0) {
547 Error("RunTracking", "TOF backward propagation failed");
550 if (fCheckPointLevel > 1) WriteESD(esd, "TOF.back");
551 fTOFTracker->UnloadClusters();
552 fTOFLoader->UnloadDigits();
556 Info("RunTracking", "TRD inward refit");
557 if (fTRDTracker->RefitInward(esd) != 0) {
558 Error("RunTracking", "TRD inward refit failed");
561 if (fCheckPointLevel > 1) WriteESD(esd, "TRD.refit");
562 fTRDTracker->UnloadClusters();
563 fTRDLoader->UnloadRecPoints();
566 Info("RunTracking", "TPC inward refit");
567 if (fTPCTracker->RefitInward(esd) != 0) {
568 Error("RunTracking", "TPC inward refit failed");
571 if (fCheckPointLevel > 1) WriteESD(esd, "TPC.refit");
574 Info("RunTracking", "ITS inward refit");
575 if (fITSTracker->RefitInward(esd) != 0) {
576 Error("RunTracking", "ITS inward refit failed");
579 if (fCheckPointLevel > 1) WriteESD(esd, "ITS.refit");
582 fITSTracker->UnloadClusters();
583 fITSLoader->UnloadRecPoints();
586 fTPCTracker->UnloadClusters();
587 fTPCLoader->UnloadRecPoints();
589 Info("RunTracking", "execution time:");
595 //_____________________________________________________________________________
596 Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
598 // fill the event summary data
600 TStopwatch stopwatch;
603 TString detStr = detectors;
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());
617 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
618 Error("FillESD", "the following detectors were not found: %s",
620 if (fStopOnError) return kFALSE;
623 Info("FillESD", "execution time:");
630 //_____________________________________________________________________________
631 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
633 // check whether detName is contained in detectors
634 // if yes, it is removed from detectors
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 ")) {
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, "");
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);
663 //_____________________________________________________________________________
664 AliReconstructor* AliReconstruction::GetReconstructor(const char* detName) const
666 // get the reconstructor object for a detector
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;
678 //_____________________________________________________________________________
679 Bool_t AliReconstruction::CreateVertexer()
681 // create the vertexer
684 AliReconstructor* itsReconstructor = GetReconstructor("ITS");
685 if (itsReconstructor) {
686 fITSVertexer = itsReconstructor->CreateVertexer(fRunLoader);
689 Warning("CreateVertexer", "couldn't create a vertexer for ITS");
690 if (fStopOnError) return kFALSE;
696 //_____________________________________________________________________________
697 Bool_t AliReconstruction::CreateTrackers()
699 // get the loaders and create the trackers
702 fITSLoader = fRunLoader->GetLoader("ITSLoader");
704 Warning("CreateTrackers", "no ITS loader found");
705 if (fStopOnError) return kFALSE;
707 AliReconstructor* itsReconstructor = GetReconstructor("ITS");
708 if (itsReconstructor) {
709 fITSTracker = itsReconstructor->CreateTracker(fRunLoader);
712 Warning("CreateTrackers", "couldn't create a tracker for ITS");
713 if (fStopOnError) return kFALSE;
718 fTPCLoader = fRunLoader->GetLoader("TPCLoader");
720 Error("CreateTrackers", "no TPC loader found");
721 if (fStopOnError) return kFALSE;
723 AliReconstructor* tpcReconstructor = GetReconstructor("TPC");
724 if (tpcReconstructor) {
725 fTPCTracker = tpcReconstructor->CreateTracker(fRunLoader);
728 Error("CreateTrackers", "couldn't create a tracker for TPC");
729 if (fStopOnError) return kFALSE;
734 fTRDLoader = fRunLoader->GetLoader("TRDLoader");
736 Warning("CreateTrackers", "no TRD loader found");
737 if (fStopOnError) return kFALSE;
739 AliReconstructor* trdReconstructor = GetReconstructor("TRD");
740 if (trdReconstructor) {
741 fTRDTracker = trdReconstructor->CreateTracker(fRunLoader);
744 Warning("CreateTrackers", "couldn't create a tracker for TRD");
745 if (fStopOnError) return kFALSE;
750 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
752 Warning("CreateTrackers", "no TOF loader found");
753 if (fStopOnError) return kFALSE;
755 AliReconstructor* tofReconstructor = GetReconstructor("TOF");
756 if (tofReconstructor) {
757 fTOFTracker = tofReconstructor->CreateTracker(fRunLoader);
760 Warning("CreateTrackers", "couldn't create a tracker for TOF");
761 if (fStopOnError) return kFALSE;
768 //_____________________________________________________________________________
769 void AliReconstruction::CleanUp(TFile* file)
771 // delete trackers and the run loader and close and delete the file
773 fReconstructors.Delete();
796 //_____________________________________________________________________________
797 Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
799 // read the ESD event from a file
801 if (!esd) return kFALSE;
803 sprintf(fileName, "ESD_%d.%d_%s.root",
804 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
805 if (gSystem->AccessPathName(fileName)) return kFALSE;
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);
817 esd = (AliESD*) file->Get("ESD");
823 //_____________________________________________________________________________
824 void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
826 // write the ESD event to a file
830 sprintf(fileName, "ESD_%d.%d_%s.root",
831 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
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);