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. //
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 //
33 // rec.SetInput("..."); //
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 //
41 // By default all events are reconstructed. The reconstruction can be //
42 // limited to a range of events by giving the index of the first and the //
43 // last event as an argument to the Run method or by calling //
45 // rec.SetEventRange(..., ...); //
47 // The index -1 (default) can be used for the last event to indicate no //
48 // upper limit of the event range. //
50 // The name of the galice file can be changed from the default //
51 // "galice.root" by passing it as argument to the AliReconstruction //
52 // constructor or by //
54 // rec.SetGAliceFile("..."); //
56 // The local reconstruction can be switched on or off for individual //
59 // rec.SetRunLocalReconstruction("..."); //
61 // The argument is a (case sensitive) string with the names of the //
62 // detectors separated by a space. The special string "ALL" selects all //
63 // available detectors. This is the default. //
65 // The reconstruction of the primary vertex position can be switched off by //
67 // rec.SetRunVertexFinder(kFALSE); //
69 // The tracking and the creation of ESD tracks can be switched on for //
70 // selected detectors by //
72 // rec.SetRunTracking("..."); //
74 // Uniform/nonuniform field tracking switches (default: uniform field) //
76 // rec.SetUniformFieldTracking(); ( rec.SetNonuniformFieldTracking(); ) //
78 // The filling of additional ESD information can be steered by //
80 // rec.SetFillESD("..."); //
82 // Again, for both methods the string specifies the list of detectors. //
83 // The default is "ALL". //
85 // The call of the shortcut method //
87 // rec.SetRunReconstruction("..."); //
89 // is equivalent to calling SetRunLocalReconstruction, SetRunTracking and //
90 // SetFillESD with the same detector selecting string as argument. //
92 // The reconstruction requires digits or raw data as input. For the creation //
93 // of digits and raw data have a look at the class AliSimulation. //
95 // For debug purposes the method SetCheckPointLevel can be used. If the //
96 // argument is greater than 0, files with ESD events will be written after //
97 // selected steps of the reconstruction for each event: //
98 // level 1: after tracking and after filling of ESD (final) //
99 // level 2: in addition after each tracking step //
100 // level 3: in addition after the filling of ESD for each detector //
101 // If a final check point file exists for an event, this event will be //
102 // skipped in the reconstruction. The tracking and the filling of ESD for //
103 // a detector will be skipped as well, if the corresponding check point //
104 // file exists. The ESD event will then be loaded from the file instead. //
106 ///////////////////////////////////////////////////////////////////////////////
112 #include <TPluginManager.h>
113 #include <TStopwatch.h>
115 #include "AliReconstruction.h"
116 #include "AliReconstructor.h"
118 #include "AliRunLoader.h"
120 #include "AliRawReaderFile.h"
121 #include "AliRawReaderDate.h"
122 #include "AliRawReaderRoot.h"
124 #include "AliESDVertex.h"
125 #include "AliTracker.h"
126 #include "AliVertexer.h"
127 #include "AliHeader.h"
128 #include "AliGenEventHeader.h"
130 #include "AliESDpid.h"
133 ClassImp(AliReconstruction)
136 //_____________________________________________________________________________
137 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "RICH", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "START", "VZERO", "CRT", "HLT"};
139 //_____________________________________________________________________________
140 AliReconstruction::AliReconstruction(const char* gAliceFilename,
141 const char* name, const char* title) :
144 fRunLocalReconstruction("ALL"),
145 fUniformField(kTRUE),
146 fRunVertexFinder(kTRUE),
147 fRunHLTTracking(kFALSE),
150 fGAliceFileName(gAliceFilename),
154 fStopOnError(kFALSE),
163 // create reconstruction object with default parameters
165 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
166 fReconstructor[iDet] = NULL;
167 fLoader[iDet] = NULL;
168 fTracker[iDet] = NULL;
173 //_____________________________________________________________________________
174 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
177 fRunLocalReconstruction(rec.fRunLocalReconstruction),
178 fUniformField(rec.fUniformField),
179 fRunVertexFinder(rec.fRunVertexFinder),
180 fRunHLTTracking(rec.fRunHLTTracking),
181 fRunTracking(rec.fRunTracking),
182 fFillESD(rec.fFillESD),
183 fGAliceFileName(rec.fGAliceFileName),
185 fFirstEvent(rec.fFirstEvent),
186 fLastEvent(rec.fLastEvent),
187 fStopOnError(rec.fStopOnError),
198 for (Int_t i = 0; i < fOptions.GetEntriesFast(); i++) {
199 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
201 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
202 fReconstructor[iDet] = NULL;
203 fLoader[iDet] = NULL;
204 fTracker[iDet] = NULL;
208 //_____________________________________________________________________________
209 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
211 // assignment operator
213 this->~AliReconstruction();
214 new(this) AliReconstruction(rec);
218 //_____________________________________________________________________________
219 AliReconstruction::~AliReconstruction()
228 //_____________________________________________________________________________
229 void AliReconstruction::SetGAliceFile(const char* fileName)
231 // set the name of the galice file
233 fGAliceFileName = fileName;
236 //_____________________________________________________________________________
237 void AliReconstruction::SetOption(const char* detector, const char* option)
239 // set options for the reconstruction of a detector
241 TObject* obj = fOptions.FindObject(detector);
242 if (obj) fOptions.Remove(obj);
243 fOptions.Add(new TNamed(detector, option));
247 //_____________________________________________________________________________
248 Bool_t AliReconstruction::Run(const char* input,
249 Int_t firstEvent, Int_t lastEvent)
251 // run the reconstruction
254 if (!input) input = fInput.Data();
255 TString fileName(input);
256 if (fileName.EndsWith("/")) {
257 fRawReader = new AliRawReaderFile(fileName);
258 } else if (fileName.EndsWith(".root")) {
259 fRawReader = new AliRawReaderRoot(fileName);
260 } else if (!fileName.IsNull()) {
261 fRawReader = new AliRawReaderDate(fileName);
262 fRawReader->SelectEvents(7);
265 // get the run loader
266 if (!InitRunLoader()) return kFALSE;
268 // local reconstruction
269 if (!fRunLocalReconstruction.IsNull()) {
270 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
271 if (fStopOnError) {CleanUp(); return kFALSE;}
274 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
275 // fFillESD.IsNull()) return kTRUE;
278 if (fRunVertexFinder && !CreateVertexer()) {
286 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
293 // get the possibly already existing ESD file and tree
294 AliESD* esd = new AliESD; AliESD* hltesd = new AliESD;
295 TFile* fileOld = NULL;
296 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
297 if (!gSystem->AccessPathName("AliESDs.root")){
298 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
299 fileOld = TFile::Open("AliESDs.old.root");
300 if (fileOld && fileOld->IsOpen()) {
301 treeOld = (TTree*) fileOld->Get("esdTree");
302 if (treeOld) treeOld->SetBranchAddress("ESD", &esd);
303 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
304 if (hlttreeOld) hlttreeOld->SetBranchAddress("ESD", &hltesd);
308 // create the ESD output file and tree
309 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
310 if (!file->IsOpen()) {
311 AliError("opening AliESDs.root failed");
312 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
314 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
315 tree->Branch("ESD", "AliESD", &esd);
316 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
317 hlttree->Branch("ESD", "AliESD", &hltesd);
318 delete esd; delete hltesd;
319 esd = NULL; hltesd = NULL;
323 if (fRawReader) fRawReader->RewindEvents();
325 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
326 if (fRawReader) fRawReader->NextEvent();
327 if ((iEvent < firstEvent) || ((lastEvent >= 0) && (iEvent > lastEvent))) {
328 // copy old ESD to the new one
330 treeOld->SetBranchAddress("ESD", &esd);
331 treeOld->GetEntry(iEvent);
335 hlttreeOld->SetBranchAddress("ESD", &hltesd);
336 hlttreeOld->GetEntry(iEvent);
342 AliInfo(Form("processing event %d", iEvent));
343 fRunLoader->GetEvent(iEvent);
346 sprintf(fileName, "ESD_%d.%d_final.root",
347 fRunLoader->GetHeader()->GetRun(),
348 fRunLoader->GetHeader()->GetEventNrInRun());
349 if (!gSystem->AccessPathName(fileName)) continue;
351 // local reconstruction
352 if (!fRunLocalReconstruction.IsNull()) {
353 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
354 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
358 esd = new AliESD; hltesd = new AliESD;
359 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
360 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
361 esd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
362 hltesd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
364 esd->SetMagneticField(gAlice->Field()->SolenoidField());
365 hltesd->SetMagneticField(gAlice->Field()->SolenoidField());
371 if (fRunVertexFinder) {
372 if (!ReadESD(esd, "vertex")) {
373 if (!RunVertexFinder(esd)) {
374 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
376 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
381 if (!fRunTracking.IsNull()) {
382 if (fRunHLTTracking) {
383 hltesd->SetVertex(esd->GetVertex());
384 if (!RunHLTTracking(hltesd)) {
385 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
391 if (!fRunTracking.IsNull()) {
392 if (!ReadESD(esd, "tracking")) {
393 if (!RunTracking(esd)) {
394 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
396 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
401 if (!fFillESD.IsNull()) {
402 if (!FillESD(esd, fFillESD)) {
403 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
408 AliESDpid::MakePID(esd);
409 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
416 if (fCheckPointLevel > 0) WriteESD(esd, "final");
417 delete esd; delete hltesd;
418 esd = NULL; hltesd = NULL;
424 CleanUp(file, fileOld);
430 //_____________________________________________________________________________
431 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
433 // run the local reconstruction
435 TStopwatch stopwatch;
438 TString detStr = detectors;
439 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
440 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
441 AliReconstructor* reconstructor = GetReconstructor(iDet);
442 if (!reconstructor) continue;
443 if (reconstructor->HasLocalReconstruction()) continue;
445 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
446 TStopwatch stopwatchDet;
447 stopwatchDet.Start();
449 fRawReader->RewindEvents();
450 reconstructor->Reconstruct(fRunLoader, fRawReader);
452 reconstructor->Reconstruct(fRunLoader);
454 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
455 fgkDetectorName[iDet],
456 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
459 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
460 AliError(Form("the following detectors were not found: %s",
462 if (fStopOnError) return kFALSE;
465 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
466 stopwatch.RealTime(),stopwatch.CpuTime()));
471 //_____________________________________________________________________________
472 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
474 // run the local reconstruction
476 TStopwatch stopwatch;
479 TString detStr = detectors;
480 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
481 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
482 AliReconstructor* reconstructor = GetReconstructor(iDet);
483 if (!reconstructor) continue;
484 AliLoader* loader = fLoader[iDet];
486 // conversion of digits
487 if (fRawReader && reconstructor->HasDigitConversion()) {
488 AliInfo(Form("converting raw data digits into root objects for %s",
489 fgkDetectorName[iDet]));
490 TStopwatch stopwatchDet;
491 stopwatchDet.Start();
492 loader->LoadDigits("update");
493 loader->CleanDigits();
494 loader->MakeDigitsContainer();
495 TTree* digitsTree = loader->TreeD();
496 reconstructor->ConvertDigits(fRawReader, digitsTree);
497 loader->WriteDigits("OVERWRITE");
498 loader->UnloadDigits();
499 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
500 fgkDetectorName[iDet],
501 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
504 // local reconstruction
505 if (!reconstructor->HasLocalReconstruction()) continue;
506 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
507 TStopwatch stopwatchDet;
508 stopwatchDet.Start();
509 loader->LoadRecPoints("update");
510 loader->CleanRecPoints();
511 loader->MakeRecPointsContainer();
512 TTree* clustersTree = loader->TreeR();
513 if (fRawReader && !reconstructor->HasDigitConversion()) {
514 reconstructor->Reconstruct(fRawReader, clustersTree);
516 loader->LoadDigits("read");
517 TTree* digitsTree = loader->TreeD();
519 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
520 if (fStopOnError) return kFALSE;
522 reconstructor->Reconstruct(digitsTree, clustersTree);
524 loader->UnloadDigits();
526 loader->WriteRecPoints("OVERWRITE");
527 loader->UnloadRecPoints();
528 AliDebug(1,Form("Execution time for %s: R:%.2fs C:%.2fs",
529 fgkDetectorName[iDet],
530 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
533 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
534 AliError(Form("the following detectors were not found: %s",
536 if (fStopOnError) return kFALSE;
539 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
540 stopwatch.RealTime(),stopwatch.CpuTime()));
545 //_____________________________________________________________________________
546 Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
548 // run the barrel tracking
550 TStopwatch stopwatch;
553 AliESDVertex* vertex = NULL;
554 Double_t vtxPos[3] = {0, 0, 0};
555 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
557 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
558 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
559 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
563 AliInfo("running the ITS vertex finder");
564 if (fLoader[0]) fLoader[0]->LoadRecPoints();
565 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
566 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
568 AliWarning("Vertex not found");
569 vertex = new AliESDVertex();
572 vertex->SetTruePos(vtxPos); // store also the vertex from MC
576 AliInfo("getting the primary vertex from MC");
577 vertex = new AliESDVertex(vtxPos, vtxErr);
581 vertex->GetXYZ(vtxPos);
582 vertex->GetSigmaXYZ(vtxErr);
584 AliWarning("no vertex reconstructed");
585 vertex = new AliESDVertex(vtxPos, vtxErr);
587 esd->SetVertex(vertex);
588 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
589 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
593 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
594 stopwatch.RealTime(),stopwatch.CpuTime()));
599 //_____________________________________________________________________________
600 Bool_t AliReconstruction::RunHLTTracking(AliESD*& esd)
602 // run the HLT barrel tracking
604 TStopwatch stopwatch;
608 AliError("Missing runLoader!");
612 AliInfo("running HLT tracking");
614 // Get a pointer to the HLT reconstructor
615 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
616 if (!reconstructor) return kFALSE;
619 for (Int_t iDet = 1; iDet >= 0; iDet--) {
620 TString detName = fgkDetectorName[iDet];
621 AliDebug(1, Form("%s HLT tracking", detName.Data()));
622 reconstructor->SetOption(detName.Data());
623 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
625 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
626 if (fStopOnError) return kFALSE;
630 Double_t vtxErr[3]={0.005,0.005,0.010};
631 const AliESDVertex *vertex = esd->GetVertex();
632 vertex->GetXYZ(vtxPos);
633 tracker->SetVertex(vtxPos,vtxErr);
635 fLoader[iDet]->LoadRecPoints("read");
636 TTree* tree = fLoader[iDet]->TreeR();
638 AliError(Form("Can't get the %s cluster tree", detName.Data()));
641 tracker->LoadClusters(tree);
643 if (tracker->Clusters2Tracks(esd) != 0) {
644 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
648 tracker->UnloadClusters();
653 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
654 stopwatch.RealTime(),stopwatch.CpuTime()));
659 //_____________________________________________________________________________
660 Bool_t AliReconstruction::RunTracking(AliESD*& esd)
662 // run the barrel tracking
664 TStopwatch stopwatch;
667 AliInfo("running tracking");
669 // pass 1: TPC + ITS inwards
670 for (Int_t iDet = 1; iDet >= 0; iDet--) {
671 if (!fTracker[iDet]) continue;
672 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
675 fLoader[iDet]->LoadRecPoints("read");
676 TTree* tree = fLoader[iDet]->TreeR();
678 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
681 fTracker[iDet]->LoadClusters(tree);
684 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
685 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
688 if (fCheckPointLevel > 1) {
689 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
691 // preliminary PID in TPC needed by the ITS tracker
693 GetReconstructor(1)->FillESD(fRunLoader, esd);
694 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
695 AliESDpid::MakePID(esd);
699 // pass 2: ALL backwards
700 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
701 if (!fTracker[iDet]) continue;
702 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
705 if (iDet > 1) { // all except ITS, TPC
707 if (iDet == 3) { // TOF
708 fLoader[iDet]->LoadDigits("read");
709 tree = fLoader[iDet]->TreeD();
711 fLoader[iDet]->LoadRecPoints("read");
712 tree = fLoader[iDet]->TreeR();
715 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
718 fTracker[iDet]->LoadClusters(tree);
722 if (fTracker[iDet]->PropagateBack(esd) != 0) {
723 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
726 if (fCheckPointLevel > 1) {
727 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
731 if (iDet > 2) { // all except ITS, TPC, TRD
732 fTracker[iDet]->UnloadClusters();
733 if (iDet == 3) { // TOF
734 fLoader[iDet]->UnloadDigits();
736 fLoader[iDet]->UnloadRecPoints();
741 // pass 3: TRD + TPC + ITS refit inwards
742 for (Int_t iDet = 2; iDet >= 0; iDet--) {
743 if (!fTracker[iDet]) continue;
744 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
747 if (fTracker[iDet]->RefitInward(esd) != 0) {
748 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
751 if (fCheckPointLevel > 1) {
752 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
756 fTracker[iDet]->UnloadClusters();
757 fLoader[iDet]->UnloadRecPoints();
760 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
761 stopwatch.RealTime(),stopwatch.CpuTime()));
766 //_____________________________________________________________________________
767 Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
769 // fill the event summary data
771 TStopwatch stopwatch;
773 AliInfo("filling ESD");
775 TString detStr = detectors;
776 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
777 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
778 AliReconstructor* reconstructor = GetReconstructor(iDet);
779 if (!reconstructor) continue;
781 if (!ReadESD(esd, fgkDetectorName[iDet])) {
782 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
783 TTree* clustersTree = NULL;
784 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
785 fLoader[iDet]->LoadRecPoints("read");
786 clustersTree = fLoader[iDet]->TreeR();
788 AliError(Form("Can't get the %s clusters tree",
789 fgkDetectorName[iDet]));
790 if (fStopOnError) return kFALSE;
793 if (fRawReader && !reconstructor->HasDigitConversion()) {
794 reconstructor->FillESD(fRawReader, clustersTree, esd);
796 TTree* digitsTree = NULL;
798 fLoader[iDet]->LoadDigits("read");
799 digitsTree = fLoader[iDet]->TreeD();
801 AliError(Form("Can't get the %s digits tree",
802 fgkDetectorName[iDet]));
803 if (fStopOnError) return kFALSE;
806 reconstructor->FillESD(digitsTree, clustersTree, esd);
807 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
809 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
810 fLoader[iDet]->UnloadRecPoints();
814 reconstructor->FillESD(fRunLoader, fRawReader, esd);
816 reconstructor->FillESD(fRunLoader, esd);
818 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
822 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
823 AliError(Form("the following detectors were not found: %s",
825 if (fStopOnError) return kFALSE;
828 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
829 stopwatch.RealTime(),stopwatch.CpuTime()));
835 //_____________________________________________________________________________
836 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
838 // check whether detName is contained in detectors
839 // if yes, it is removed from detectors
841 // check if all detectors are selected
842 if ((detectors.CompareTo("ALL") == 0) ||
843 detectors.BeginsWith("ALL ") ||
844 detectors.EndsWith(" ALL") ||
845 detectors.Contains(" ALL ")) {
850 // search for the given detector
851 Bool_t result = kFALSE;
852 if ((detectors.CompareTo(detName) == 0) ||
853 detectors.BeginsWith(detName+" ") ||
854 detectors.EndsWith(" "+detName) ||
855 detectors.Contains(" "+detName+" ")) {
856 detectors.ReplaceAll(detName, "");
860 // clean up the detectors string
861 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
862 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
863 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
868 //_____________________________________________________________________________
869 Bool_t AliReconstruction::InitRunLoader()
871 // get or create the run loader
873 if (gAlice) delete gAlice;
876 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
877 // load all base libraries to get the loader classes
878 TString libs = gSystem->GetLibraries();
879 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
880 TString detName = fgkDetectorName[iDet];
881 if (detName == "HLT") continue;
882 if (libs.Contains("lib" + detName + "base.so")) continue;
883 gSystem->Load("lib" + detName + "base.so");
885 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
887 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
891 fRunLoader->CdGAFile();
892 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
893 if (fRunLoader->LoadgAlice() == 0) {
894 gAlice = fRunLoader->GetAliRun();
895 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
898 if (!gAlice && !fRawReader) {
899 AliError(Form("no gAlice object found in file %s",
900 fGAliceFileName.Data()));
905 } else { // galice.root does not exist
907 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
911 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
912 AliConfig::GetDefaultEventFolderName(),
915 AliError(Form("could not create run loader in file %s",
916 fGAliceFileName.Data()));
920 fRunLoader->MakeTree("E");
922 while (fRawReader->NextEvent()) {
923 fRunLoader->SetEventNumber(iEvent);
924 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
926 fRunLoader->MakeTree("H");
927 fRunLoader->TreeE()->Fill();
930 fRawReader->RewindEvents();
931 fRunLoader->WriteHeader("OVERWRITE");
932 fRunLoader->CdGAFile();
933 fRunLoader->Write(0, TObject::kOverwrite);
934 // AliTracker::SetFieldMap(???);
940 //_____________________________________________________________________________
941 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
943 // get the reconstructor object and the loader for a detector
945 if (fReconstructor[iDet]) return fReconstructor[iDet];
947 // load the reconstructor object
948 TPluginManager* pluginManager = gROOT->GetPluginManager();
949 TString detName = fgkDetectorName[iDet];
950 TString recName = "Ali" + detName + "Reconstructor";
951 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
953 if (detName == "HLT") {
954 if (!gROOT->GetClass("AliLevel3")) {
955 gSystem->Load("libAliL3Src.so");
956 gSystem->Load("libAliL3Misc.so");
957 gSystem->Load("libAliL3Hough.so");
958 gSystem->Load("libAliL3Comp.so");
962 AliReconstructor* reconstructor = NULL;
963 // first check if a plugin is defined for the reconstructor
964 TPluginHandler* pluginHandler =
965 pluginManager->FindHandler("AliReconstructor", detName);
966 // if not, add a plugin for it
967 if (!pluginHandler) {
968 AliDebug(1, Form("defining plugin for %s", recName.Data()));
969 TString libs = gSystem->GetLibraries();
970 if (libs.Contains("lib" + detName + "base.so") ||
971 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
972 pluginManager->AddHandler("AliReconstructor", detName,
973 recName, detName + "rec", recName + "()");
975 pluginManager->AddHandler("AliReconstructor", detName,
976 recName, detName, recName + "()");
978 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
980 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
981 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
984 TObject* obj = fOptions.FindObject(detName.Data());
985 if (obj) reconstructor->SetOption(obj->GetTitle());
986 reconstructor->Init(fRunLoader);
987 fReconstructor[iDet] = reconstructor;
990 // get or create the loader
991 if (detName != "HLT") {
992 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
993 if (!fLoader[iDet]) {
994 AliConfig::Instance()
995 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
997 // first check if a plugin is defined for the loader
998 TPluginHandler* pluginHandler =
999 pluginManager->FindHandler("AliLoader", detName);
1000 // if not, add a plugin for it
1001 if (!pluginHandler) {
1002 TString loaderName = "Ali" + detName + "Loader";
1003 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1004 pluginManager->AddHandler("AliLoader", detName,
1005 loaderName, detName + "base",
1006 loaderName + "(const char*, TFolder*)");
1007 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1009 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1011 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1012 fRunLoader->GetEventFolder());
1014 if (!fLoader[iDet]) { // use default loader
1015 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1017 if (!fLoader[iDet]) {
1018 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1019 if (fStopOnError) return NULL;
1021 fRunLoader->AddLoader(fLoader[iDet]);
1022 fRunLoader->CdGAFile();
1023 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1024 fRunLoader->Write(0, TObject::kOverwrite);
1029 return reconstructor;
1032 //_____________________________________________________________________________
1033 Bool_t AliReconstruction::CreateVertexer()
1035 // create the vertexer
1038 AliReconstructor* itsReconstructor = GetReconstructor(0);
1039 if (itsReconstructor) {
1040 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
1043 AliWarning("couldn't create a vertexer for ITS");
1044 if (fStopOnError) return kFALSE;
1050 //_____________________________________________________________________________
1051 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1053 // create the trackers
1055 TString detStr = detectors;
1056 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1057 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1058 AliReconstructor* reconstructor = GetReconstructor(iDet);
1059 if (!reconstructor) continue;
1060 TString detName = fgkDetectorName[iDet];
1061 if (detName == "HLT") {
1062 fRunHLTTracking = kTRUE;
1066 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1067 if (!fTracker[iDet] && (iDet < 7)) {
1068 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1069 if (fStopOnError) return kFALSE;
1076 //_____________________________________________________________________________
1077 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1079 // delete trackers and the run loader and close and delete the file
1081 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1082 delete fReconstructor[iDet];
1083 fReconstructor[iDet] = NULL;
1084 fLoader[iDet] = NULL;
1085 delete fTracker[iDet];
1086 fTracker[iDet] = NULL;
1104 gSystem->Unlink("AliESDs.old.root");
1109 //_____________________________________________________________________________
1110 Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
1112 // read the ESD event from a file
1114 if (!esd) return kFALSE;
1116 sprintf(fileName, "ESD_%d.%d_%s.root",
1117 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
1118 if (gSystem->AccessPathName(fileName)) return kFALSE;
1120 AliDebug(1, Form("reading ESD from file %s", fileName));
1121 TFile* file = TFile::Open(fileName);
1122 if (!file || !file->IsOpen()) {
1123 AliError(Form("opening %s failed", fileName));
1130 esd = (AliESD*) file->Get("ESD");
1136 //_____________________________________________________________________________
1137 void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
1139 // write the ESD event to a file
1143 sprintf(fileName, "ESD_%d.%d_%s.root",
1144 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
1146 AliDebug(1, Form("writing ESD to file %s", fileName));
1147 TFile* file = TFile::Open(fileName, "recreate");
1148 if (!file || !file->IsOpen()) {
1149 AliError(Form("opening %s failed", fileName));