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"
131 //#include "AliMagF.h"
135 #include "AliRunTag.h"
136 //#include "AliLHCTag.h"
137 #include "AliDetectorTag.h"
138 #include "AliEventTag.h"
142 ClassImp(AliReconstruction)
145 //_____________________________________________________________________________
146 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "RICH", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "START", "VZERO", "CRT", "HLT"};
148 //_____________________________________________________________________________
149 AliReconstruction::AliReconstruction(const char* gAliceFilename,
150 const char* name, const char* title) :
153 fRunLocalReconstruction("ALL"),
154 fUniformField(kTRUE),
155 fRunVertexFinder(kTRUE),
156 fRunHLTTracking(kFALSE),
159 fGAliceFileName(gAliceFilename),
163 fStopOnError(kFALSE),
172 // create reconstruction object with default parameters
174 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
175 fReconstructor[iDet] = NULL;
176 fLoader[iDet] = NULL;
177 fTracker[iDet] = NULL;
182 //_____________________________________________________________________________
183 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
186 fRunLocalReconstruction(rec.fRunLocalReconstruction),
187 fUniformField(rec.fUniformField),
188 fRunVertexFinder(rec.fRunVertexFinder),
189 fRunHLTTracking(rec.fRunHLTTracking),
190 fRunTracking(rec.fRunTracking),
191 fFillESD(rec.fFillESD),
192 fGAliceFileName(rec.fGAliceFileName),
194 fFirstEvent(rec.fFirstEvent),
195 fLastEvent(rec.fLastEvent),
196 fStopOnError(rec.fStopOnError),
207 for (Int_t i = 0; i < fOptions.GetEntriesFast(); i++) {
208 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
210 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
211 fReconstructor[iDet] = NULL;
212 fLoader[iDet] = NULL;
213 fTracker[iDet] = NULL;
217 //_____________________________________________________________________________
218 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
220 // assignment operator
222 this->~AliReconstruction();
223 new(this) AliReconstruction(rec);
227 //_____________________________________________________________________________
228 AliReconstruction::~AliReconstruction()
237 //_____________________________________________________________________________
238 void AliReconstruction::SetGAliceFile(const char* fileName)
240 // set the name of the galice file
242 fGAliceFileName = fileName;
245 //_____________________________________________________________________________
246 void AliReconstruction::SetOption(const char* detector, const char* option)
248 // set options for the reconstruction of a detector
250 TObject* obj = fOptions.FindObject(detector);
251 if (obj) fOptions.Remove(obj);
252 fOptions.Add(new TNamed(detector, option));
256 //_____________________________________________________________________________
257 Bool_t AliReconstruction::Run(const char* input,
258 Int_t firstEvent, Int_t lastEvent)
260 // run the reconstruction
263 if (!input) input = fInput.Data();
264 TString fileName(input);
265 if (fileName.EndsWith("/")) {
266 fRawReader = new AliRawReaderFile(fileName);
267 } else if (fileName.EndsWith(".root")) {
268 fRawReader = new AliRawReaderRoot(fileName);
269 } else if (!fileName.IsNull()) {
270 fRawReader = new AliRawReaderDate(fileName);
271 fRawReader->SelectEvents(7);
274 // get the run loader
275 if (!InitRunLoader()) return kFALSE;
277 // local reconstruction
278 if (!fRunLocalReconstruction.IsNull()) {
279 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
280 if (fStopOnError) {CleanUp(); return kFALSE;}
283 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
284 // fFillESD.IsNull()) return kTRUE;
287 if (fRunVertexFinder && !CreateVertexer()) {
295 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
303 TStopwatch stopwatch;
306 // get the possibly already existing ESD file and tree
307 AliESD* esd = new AliESD; AliESD* hltesd = new AliESD;
308 TFile* fileOld = NULL;
309 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
310 if (!gSystem->AccessPathName("AliESDs.root")){
311 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
312 fileOld = TFile::Open("AliESDs.old.root");
313 if (fileOld && fileOld->IsOpen()) {
314 treeOld = (TTree*) fileOld->Get("esdTree");
315 if (treeOld) treeOld->SetBranchAddress("ESD", &esd);
316 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
317 if (hlttreeOld) hlttreeOld->SetBranchAddress("ESD", &hltesd);
321 // create the ESD output file and tree
322 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
323 if (!file->IsOpen()) {
324 AliError("opening AliESDs.root failed");
325 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
327 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
328 tree->Branch("ESD", "AliESD", &esd);
329 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
330 hlttree->Branch("ESD", "AliESD", &hltesd);
331 delete esd; delete hltesd;
332 esd = NULL; hltesd = NULL;
336 if (fRawReader) fRawReader->RewindEvents();
338 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
339 if (fRawReader) fRawReader->NextEvent();
340 if ((iEvent < firstEvent) || ((lastEvent >= 0) && (iEvent > lastEvent))) {
341 // copy old ESD to the new one
343 treeOld->SetBranchAddress("ESD", &esd);
344 treeOld->GetEntry(iEvent);
348 hlttreeOld->SetBranchAddress("ESD", &hltesd);
349 hlttreeOld->GetEntry(iEvent);
355 AliInfo(Form("processing event %d", iEvent));
356 fRunLoader->GetEvent(iEvent);
359 sprintf(fileName, "ESD_%d.%d_final.root",
360 fRunLoader->GetHeader()->GetRun(),
361 fRunLoader->GetHeader()->GetEventNrInRun());
362 if (!gSystem->AccessPathName(fileName)) continue;
364 // local reconstruction
365 if (!fRunLocalReconstruction.IsNull()) {
366 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
367 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
371 esd = new AliESD; hltesd = new AliESD;
372 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
373 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
374 esd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
375 hltesd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
377 esd->SetMagneticField(gAlice->Field()->SolenoidField());
378 hltesd->SetMagneticField(gAlice->Field()->SolenoidField());
384 if (fRunVertexFinder) {
385 if (!ReadESD(esd, "vertex")) {
386 if (!RunVertexFinder(esd)) {
387 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
389 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
394 if (!fRunTracking.IsNull()) {
395 if (fRunHLTTracking) {
396 hltesd->SetVertex(esd->GetVertex());
397 if (!RunHLTTracking(hltesd)) {
398 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
404 if (!fRunTracking.IsNull()) {
405 if (!ReadESD(esd, "tracking")) {
406 if (!RunTracking(esd)) {
407 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
409 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
414 if (!fFillESD.IsNull()) {
415 if (!FillESD(esd, fFillESD)) {
416 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
421 AliESDpid::MakePID(esd);
422 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
429 if (fCheckPointLevel > 0) WriteESD(esd, "final");
431 delete esd; delete hltesd;
432 esd = NULL; hltesd = NULL;
435 AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
436 stopwatch.RealTime(),stopwatch.CpuTime()));
442 // Create tags for the events in the ESD tree (the ESD tree is always present)
443 // In case of empty events the tags will contain dummy values
445 CleanUp(file, fileOld);
451 //_____________________________________________________________________________
452 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
454 // run the local reconstruction
456 TStopwatch stopwatch;
459 TString detStr = detectors;
460 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
461 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
462 AliReconstructor* reconstructor = GetReconstructor(iDet);
463 if (!reconstructor) continue;
464 if (reconstructor->HasLocalReconstruction()) continue;
466 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
467 TStopwatch stopwatchDet;
468 stopwatchDet.Start();
470 fRawReader->RewindEvents();
471 reconstructor->Reconstruct(fRunLoader, fRawReader);
473 reconstructor->Reconstruct(fRunLoader);
475 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
476 fgkDetectorName[iDet],
477 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
480 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
481 AliError(Form("the following detectors were not found: %s",
483 if (fStopOnError) return kFALSE;
486 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
487 stopwatch.RealTime(),stopwatch.CpuTime()));
492 //_____________________________________________________________________________
493 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
495 // run the local reconstruction
497 TStopwatch stopwatch;
500 TString detStr = detectors;
501 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
502 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
503 AliReconstructor* reconstructor = GetReconstructor(iDet);
504 if (!reconstructor) continue;
505 AliLoader* loader = fLoader[iDet];
507 // conversion of digits
508 if (fRawReader && reconstructor->HasDigitConversion()) {
509 AliInfo(Form("converting raw data digits into root objects for %s",
510 fgkDetectorName[iDet]));
511 TStopwatch stopwatchDet;
512 stopwatchDet.Start();
513 loader->LoadDigits("update");
514 loader->CleanDigits();
515 loader->MakeDigitsContainer();
516 TTree* digitsTree = loader->TreeD();
517 reconstructor->ConvertDigits(fRawReader, digitsTree);
518 loader->WriteDigits("OVERWRITE");
519 loader->UnloadDigits();
520 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
521 fgkDetectorName[iDet],
522 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
525 // local reconstruction
526 if (!reconstructor->HasLocalReconstruction()) continue;
527 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
528 TStopwatch stopwatchDet;
529 stopwatchDet.Start();
530 loader->LoadRecPoints("update");
531 loader->CleanRecPoints();
532 loader->MakeRecPointsContainer();
533 TTree* clustersTree = loader->TreeR();
534 if (fRawReader && !reconstructor->HasDigitConversion()) {
535 reconstructor->Reconstruct(fRawReader, clustersTree);
537 loader->LoadDigits("read");
538 TTree* digitsTree = loader->TreeD();
540 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
541 if (fStopOnError) return kFALSE;
543 reconstructor->Reconstruct(digitsTree, clustersTree);
545 loader->UnloadDigits();
547 loader->WriteRecPoints("OVERWRITE");
548 loader->UnloadRecPoints();
549 AliDebug(1,Form("Execution time for %s: R:%.2fs C:%.2fs",
550 fgkDetectorName[iDet],
551 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
554 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
555 AliError(Form("the following detectors were not found: %s",
557 if (fStopOnError) return kFALSE;
560 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
561 stopwatch.RealTime(),stopwatch.CpuTime()));
566 //_____________________________________________________________________________
567 Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
569 // run the barrel tracking
571 TStopwatch stopwatch;
574 AliESDVertex* vertex = NULL;
575 Double_t vtxPos[3] = {0, 0, 0};
576 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
578 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
579 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
580 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
584 AliInfo("running the ITS vertex finder");
585 if (fLoader[0]) fLoader[0]->LoadRecPoints();
586 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
587 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
589 AliWarning("Vertex not found");
590 vertex = new AliESDVertex();
593 vertex->SetTruePos(vtxPos); // store also the vertex from MC
597 AliInfo("getting the primary vertex from MC");
598 vertex = new AliESDVertex(vtxPos, vtxErr);
602 vertex->GetXYZ(vtxPos);
603 vertex->GetSigmaXYZ(vtxErr);
605 AliWarning("no vertex reconstructed");
606 vertex = new AliESDVertex(vtxPos, vtxErr);
608 esd->SetVertex(vertex);
609 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
610 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
614 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
615 stopwatch.RealTime(),stopwatch.CpuTime()));
620 //_____________________________________________________________________________
621 Bool_t AliReconstruction::RunHLTTracking(AliESD*& esd)
623 // run the HLT barrel tracking
625 TStopwatch stopwatch;
629 AliError("Missing runLoader!");
633 AliInfo("running HLT tracking");
635 // Get a pointer to the HLT reconstructor
636 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
637 if (!reconstructor) return kFALSE;
640 for (Int_t iDet = 1; iDet >= 0; iDet--) {
641 TString detName = fgkDetectorName[iDet];
642 AliDebug(1, Form("%s HLT tracking", detName.Data()));
643 reconstructor->SetOption(detName.Data());
644 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
646 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
647 if (fStopOnError) return kFALSE;
651 Double_t vtxErr[3]={0.005,0.005,0.010};
652 const AliESDVertex *vertex = esd->GetVertex();
653 vertex->GetXYZ(vtxPos);
654 tracker->SetVertex(vtxPos,vtxErr);
656 fLoader[iDet]->LoadRecPoints("read");
657 TTree* tree = fLoader[iDet]->TreeR();
659 AliError(Form("Can't get the %s cluster tree", detName.Data()));
662 tracker->LoadClusters(tree);
664 if (tracker->Clusters2Tracks(esd) != 0) {
665 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
669 tracker->UnloadClusters();
674 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
675 stopwatch.RealTime(),stopwatch.CpuTime()));
680 //_____________________________________________________________________________
681 Bool_t AliReconstruction::RunTracking(AliESD*& esd)
683 // run the barrel tracking
685 TStopwatch stopwatch;
688 AliInfo("running tracking");
690 // pass 1: TPC + ITS inwards
691 for (Int_t iDet = 1; iDet >= 0; iDet--) {
692 if (!fTracker[iDet]) continue;
693 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
696 fLoader[iDet]->LoadRecPoints("read");
697 TTree* tree = fLoader[iDet]->TreeR();
699 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
702 fTracker[iDet]->LoadClusters(tree);
705 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
706 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
709 if (fCheckPointLevel > 1) {
710 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
712 // preliminary PID in TPC needed by the ITS tracker
714 GetReconstructor(1)->FillESD(fRunLoader, esd);
715 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
716 AliESDpid::MakePID(esd);
720 // pass 2: ALL backwards
721 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
722 if (!fTracker[iDet]) continue;
723 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
726 if (iDet > 1) { // all except ITS, TPC
728 fLoader[iDet]->LoadRecPoints("read");
729 tree = fLoader[iDet]->TreeR();
731 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
734 fTracker[iDet]->LoadClusters(tree);
738 if (fTracker[iDet]->PropagateBack(esd) != 0) {
739 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
742 if (fCheckPointLevel > 1) {
743 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
747 if (iDet > 2) { // all except ITS, TPC, TRD
748 fTracker[iDet]->UnloadClusters();
749 fLoader[iDet]->UnloadRecPoints();
753 // pass 3: TRD + TPC + ITS refit inwards
754 for (Int_t iDet = 2; iDet >= 0; iDet--) {
755 if (!fTracker[iDet]) continue;
756 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
759 if (fTracker[iDet]->RefitInward(esd) != 0) {
760 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
763 if (fCheckPointLevel > 1) {
764 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
768 fTracker[iDet]->UnloadClusters();
769 fLoader[iDet]->UnloadRecPoints();
772 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
773 stopwatch.RealTime(),stopwatch.CpuTime()));
778 //_____________________________________________________________________________
779 Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
781 // fill the event summary data
783 TStopwatch stopwatch;
785 AliInfo("filling ESD");
787 TString detStr = detectors;
788 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
789 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
790 AliReconstructor* reconstructor = GetReconstructor(iDet);
791 if (!reconstructor) continue;
793 if (!ReadESD(esd, fgkDetectorName[iDet])) {
794 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
795 TTree* clustersTree = NULL;
796 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
797 fLoader[iDet]->LoadRecPoints("read");
798 clustersTree = fLoader[iDet]->TreeR();
800 AliError(Form("Can't get the %s clusters tree",
801 fgkDetectorName[iDet]));
802 if (fStopOnError) return kFALSE;
805 if (fRawReader && !reconstructor->HasDigitConversion()) {
806 reconstructor->FillESD(fRawReader, clustersTree, esd);
808 TTree* digitsTree = NULL;
810 fLoader[iDet]->LoadDigits("read");
811 digitsTree = fLoader[iDet]->TreeD();
813 AliError(Form("Can't get the %s digits tree",
814 fgkDetectorName[iDet]));
815 if (fStopOnError) return kFALSE;
818 reconstructor->FillESD(digitsTree, clustersTree, esd);
819 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
821 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
822 fLoader[iDet]->UnloadRecPoints();
826 reconstructor->FillESD(fRunLoader, fRawReader, esd);
828 reconstructor->FillESD(fRunLoader, esd);
830 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
834 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
835 AliError(Form("the following detectors were not found: %s",
837 if (fStopOnError) return kFALSE;
840 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
841 stopwatch.RealTime(),stopwatch.CpuTime()));
847 //_____________________________________________________________________________
848 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
850 // check whether detName is contained in detectors
851 // if yes, it is removed from detectors
853 // check if all detectors are selected
854 if ((detectors.CompareTo("ALL") == 0) ||
855 detectors.BeginsWith("ALL ") ||
856 detectors.EndsWith(" ALL") ||
857 detectors.Contains(" ALL ")) {
862 // search for the given detector
863 Bool_t result = kFALSE;
864 if ((detectors.CompareTo(detName) == 0) ||
865 detectors.BeginsWith(detName+" ") ||
866 detectors.EndsWith(" "+detName) ||
867 detectors.Contains(" "+detName+" ")) {
868 detectors.ReplaceAll(detName, "");
872 // clean up the detectors string
873 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
874 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
875 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
880 //_____________________________________________________________________________
881 Bool_t AliReconstruction::InitRunLoader()
883 // get or create the run loader
885 if (gAlice) delete gAlice;
888 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
889 // load all base libraries to get the loader classes
890 TString libs = gSystem->GetLibraries();
891 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
892 TString detName = fgkDetectorName[iDet];
893 if (detName == "HLT") continue;
894 if (libs.Contains("lib" + detName + "base.so")) continue;
895 gSystem->Load("lib" + detName + "base.so");
897 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
899 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
903 fRunLoader->CdGAFile();
904 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
905 if (fRunLoader->LoadgAlice() == 0) {
906 gAlice = fRunLoader->GetAliRun();
907 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
908 AliExternalTrackParam::SetFieldMap(gAlice->Field());
910 AliExternalTrackParam::SetUniformFieldTracking();
912 AliExternalTrackParam::SetNonuniformFieldTracking();
915 if (!gAlice && !fRawReader) {
916 AliError(Form("no gAlice object found in file %s",
917 fGAliceFileName.Data()));
922 } else { // galice.root does not exist
924 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
928 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
929 AliConfig::GetDefaultEventFolderName(),
932 AliError(Form("could not create run loader in file %s",
933 fGAliceFileName.Data()));
937 fRunLoader->MakeTree("E");
939 while (fRawReader->NextEvent()) {
940 fRunLoader->SetEventNumber(iEvent);
941 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
943 fRunLoader->MakeTree("H");
944 fRunLoader->TreeE()->Fill();
947 fRawReader->RewindEvents();
948 fRunLoader->WriteHeader("OVERWRITE");
949 fRunLoader->CdGAFile();
950 fRunLoader->Write(0, TObject::kOverwrite);
951 // AliTracker::SetFieldMap(???);
957 //_____________________________________________________________________________
958 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
960 // get the reconstructor object and the loader for a detector
962 if (fReconstructor[iDet]) return fReconstructor[iDet];
964 // load the reconstructor object
965 TPluginManager* pluginManager = gROOT->GetPluginManager();
966 TString detName = fgkDetectorName[iDet];
967 TString recName = "Ali" + detName + "Reconstructor";
968 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
970 if (detName == "HLT") {
971 if (!gROOT->GetClass("AliLevel3")) {
972 gSystem->Load("libAliL3Src.so");
973 gSystem->Load("libAliL3Misc.so");
974 gSystem->Load("libAliL3Hough.so");
975 gSystem->Load("libAliL3Comp.so");
979 AliReconstructor* reconstructor = NULL;
980 // first check if a plugin is defined for the reconstructor
981 TPluginHandler* pluginHandler =
982 pluginManager->FindHandler("AliReconstructor", detName);
983 // if not, add a plugin for it
984 if (!pluginHandler) {
985 AliDebug(1, Form("defining plugin for %s", recName.Data()));
986 TString libs = gSystem->GetLibraries();
987 if (libs.Contains("lib" + detName + "base.so") ||
988 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
989 pluginManager->AddHandler("AliReconstructor", detName,
990 recName, detName + "rec", recName + "()");
992 pluginManager->AddHandler("AliReconstructor", detName,
993 recName, detName, recName + "()");
995 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
997 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
998 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1000 if (reconstructor) {
1001 TObject* obj = fOptions.FindObject(detName.Data());
1002 if (obj) reconstructor->SetOption(obj->GetTitle());
1003 reconstructor->Init(fRunLoader);
1004 fReconstructor[iDet] = reconstructor;
1007 // get or create the loader
1008 if (detName != "HLT") {
1009 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1010 if (!fLoader[iDet]) {
1011 AliConfig::Instance()
1012 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1014 // first check if a plugin is defined for the loader
1015 TPluginHandler* pluginHandler =
1016 pluginManager->FindHandler("AliLoader", detName);
1017 // if not, add a plugin for it
1018 if (!pluginHandler) {
1019 TString loaderName = "Ali" + detName + "Loader";
1020 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1021 pluginManager->AddHandler("AliLoader", detName,
1022 loaderName, detName + "base",
1023 loaderName + "(const char*, TFolder*)");
1024 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1026 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1028 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1029 fRunLoader->GetEventFolder());
1031 if (!fLoader[iDet]) { // use default loader
1032 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1034 if (!fLoader[iDet]) {
1035 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1036 if (fStopOnError) return NULL;
1038 fRunLoader->AddLoader(fLoader[iDet]);
1039 fRunLoader->CdGAFile();
1040 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1041 fRunLoader->Write(0, TObject::kOverwrite);
1046 return reconstructor;
1049 //_____________________________________________________________________________
1050 Bool_t AliReconstruction::CreateVertexer()
1052 // create the vertexer
1055 AliReconstructor* itsReconstructor = GetReconstructor(0);
1056 if (itsReconstructor) {
1057 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
1060 AliWarning("couldn't create a vertexer for ITS");
1061 if (fStopOnError) return kFALSE;
1067 //_____________________________________________________________________________
1068 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1070 // create the trackers
1072 TString detStr = detectors;
1073 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1074 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1075 AliReconstructor* reconstructor = GetReconstructor(iDet);
1076 if (!reconstructor) continue;
1077 TString detName = fgkDetectorName[iDet];
1078 if (detName == "HLT") {
1079 fRunHLTTracking = kTRUE;
1083 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1084 if (!fTracker[iDet] && (iDet < 7)) {
1085 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1086 if (fStopOnError) return kFALSE;
1093 //_____________________________________________________________________________
1094 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1096 // delete trackers and the run loader and close and delete the file
1098 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1099 delete fReconstructor[iDet];
1100 fReconstructor[iDet] = NULL;
1101 fLoader[iDet] = NULL;
1102 delete fTracker[iDet];
1103 fTracker[iDet] = NULL;
1121 gSystem->Unlink("AliESDs.old.root");
1126 //_____________________________________________________________________________
1127 Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
1129 // read the ESD event from a file
1131 if (!esd) return kFALSE;
1133 sprintf(fileName, "ESD_%d.%d_%s.root",
1134 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
1135 if (gSystem->AccessPathName(fileName)) return kFALSE;
1137 AliInfo(Form("reading ESD from file %s", fileName));
1138 AliDebug(1, Form("reading ESD from file %s", fileName));
1139 TFile* file = TFile::Open(fileName);
1140 if (!file || !file->IsOpen()) {
1141 AliError(Form("opening %s failed", fileName));
1148 esd = (AliESD*) file->Get("ESD");
1154 //_____________________________________________________________________________
1155 void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
1157 // write the ESD event to a file
1161 sprintf(fileName, "ESD_%d.%d_%s.root",
1162 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
1164 AliDebug(1, Form("writing ESD to file %s", fileName));
1165 TFile* file = TFile::Open(fileName, "recreate");
1166 if (!file || !file->IsOpen()) {
1167 AliError(Form("opening %s failed", fileName));
1178 //_____________________________________________________________________________
1179 void AliReconstruction::CreateTag(TFile* file)
1181 // Creates the tags for all the events in a given ESD file
1183 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
1184 Int_t nPos, nNeg, nNeutr;
1185 Int_t nK0s, nNeutrons, nPi0s, nGamas;
1186 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
1187 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
1188 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
1189 Float_t maxPt = .0, meanPt = .0, totalP = .0;
1191 AliRunTag *tag = new AliRunTag();
1192 AliDetectorTag *detTag = new AliDetectorTag();
1193 AliEventTag *evTag = new AliEventTag();
1194 TTree ttag("T","A Tree with event tags");
1195 TBranch * btag = ttag.Branch("AliTAG", "AliRunTag", &tag);
1196 btag->SetCompressionLevel(9);
1198 AliInfo(Form("Creating the tags......."));
1200 if (!file || !file->IsOpen()) {
1201 AliError(Form("opening failed"));
1206 TTree *t = (TTree*) file->Get("esdTree");
1207 TBranch * b = t->GetBranch("ESD");
1209 b->SetAddress(&esd);
1211 tag->SetRunId(esd->GetRunNumber());
1213 Int_t firstEvent = 0,lastEvent = 0;
1214 Int_t iNumberOfEvents = b->GetEntries();
1215 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++)
1243 b->GetEntry(iEventNumber);
1244 const AliESDVertex * vertexIn = esd->GetVertex();
1246 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++)
1248 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
1249 UInt_t status = esdTrack->GetStatus();
1251 //select only tracks with ITS refit
1252 if ((status&AliESDtrack::kITSrefit)==0) continue;
1254 //select only tracks with TPC refit-->remove extremely high Pt tracks
1255 if ((status&AliESDtrack::kTPCrefit)==0) continue;
1257 //select only tracks with the "combined PID"
1258 if ((status&AliESDtrack::kESDpid)==0) continue;
1260 esdTrack->GetPxPyPz(p);
1261 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
1262 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
1268 if(esdTrack->GetSign() > 0)
1278 if(esdTrack->GetSign() < 0)
1288 if(esdTrack->GetSign() == 0)
1293 esdTrack->GetESDpid(prob);
1296 if ((prob[8]>prob[7])&&(prob[8]>prob[6])&&(prob[8]>prob[5])&&(prob[8]>prob[4])&&(prob[8]>prob[3])&&(prob[8]>prob[2])&&(prob[8]>prob[1])&&(prob[8]>prob[0]))
1299 if ((prob[7]>prob[8])&&(prob[7]>prob[6])&&(prob[7]>prob[5])&&(prob[7]>prob[4])&&(prob[7]>prob[3])&&(prob[7]>prob[2])&&(prob[7]>prob[1])&&(prob[7]>prob[0]))
1302 if ((prob[6]>prob[8])&&(prob[6]>prob[7])&&(prob[6]>prob[5])&&(prob[6]>prob[4])&&(prob[6]>prob[3])&&(prob[6]>prob[2])&&(prob[6]>prob[1])&&(prob[6]>prob[0]))
1305 if ((prob[5]>prob[8])&&(prob[5]>prob[7])&&(prob[5]>prob[6])&&(prob[5]>prob[4])&&(prob[5]>prob[3])&&(prob[5]>prob[2])&&(prob[5]>prob[1])&&(prob[5]>prob[0]))
1308 if ((prob[4]>prob[8])&&(prob[4]>prob[7])&&(prob[4]>prob[6])&&(prob[4]>prob[5])&&(prob[4]>prob[3])&&(prob[4]>prob[2])&&(prob[4]>prob[1])&&(prob[4]>prob[0]))
1311 if ((prob[3]>prob[8])&&(prob[3]>prob[7])&&(prob[3]>prob[6])&&(prob[3]>prob[5])&&(prob[3]>prob[4])&&(prob[3]>prob[2])&&(prob[3]>prob[1])&&(prob[3]>prob[0]))
1314 if ((prob[2]>prob[8])&&(prob[2]>prob[7])&&(prob[2]>prob[6])&&(prob[2]>prob[5])&&(prob[2]>prob[4])&&(prob[2]>prob[3])&&(prob[2]>prob[1])&&(prob[2]>prob[0]))
1317 if ((prob[1]>prob[8])&&(prob[1]>prob[7])&&(prob[1]>prob[6])&&(prob[1]>prob[5])&&(prob[1]>prob[4])&&(prob[1]>prob[3])&&(prob[1]>prob[2])&&(prob[1]>prob[0]))
1328 if ((prob[0]>prob[8])&&(prob[0]>prob[7])&&(prob[0]>prob[6])&&(prob[0]>prob[5])&&(prob[0]>prob[4])&&(prob[0]>prob[3])&&(prob[0]>prob[2])&&(prob[0]>prob[1]))
1343 // Fill the event tags
1345 meanPt = meanPt/ntrack;
1347 evTag->SetEventId(iEventNumber+1);
1348 evTag->SetVertexX(vertexIn->GetXv());
1349 evTag->SetVertexY(vertexIn->GetYv());
1350 evTag->SetVertexZ(vertexIn->GetZv());
1352 evTag->SetT0VertexZ(esd->GetT0zVertex());
1354 evTag->SetTrigger(esd->GetTrigger());
1356 evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
1357 evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
1358 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
1359 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
1362 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
1363 evTag->SetNumOfPosTracks(nPos);
1364 evTag->SetNumOfNegTracks(nNeg);
1365 evTag->SetNumOfNeutrTracks(nNeutr);
1367 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
1368 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
1369 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
1370 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
1372 evTag->SetNumOfProtons(nProtons);
1373 evTag->SetNumOfKaons(nKaons);
1374 evTag->SetNumOfPions(nPions);
1375 evTag->SetNumOfMuons(nMuons);
1376 evTag->SetNumOfElectrons(nElectrons);
1377 evTag->SetNumOfPhotons(nGamas);
1378 evTag->SetNumOfPi0s(nPi0s);
1379 evTag->SetNumOfNeutrons(nNeutrons);
1380 evTag->SetNumOfKaon0s(nK0s);
1382 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
1383 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
1384 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
1385 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
1386 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
1387 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
1388 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
1389 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
1390 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
1392 evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
1393 evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
1395 evTag->SetTotalMomentum(totalP);
1396 evTag->SetMeanPt(meanPt);
1397 evTag->SetMaxPt(maxPt);
1399 tag->AddEventTag(*evTag);
1401 lastEvent = iNumberOfEvents;
1407 sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root",
1408 tag->GetRunId(),firstEvent,lastEvent );
1409 AliInfo(Form("writing tags to file %s", fileName));
1410 AliDebug(1, Form("writing tags to file %s", fileName));
1412 TFile* ftag = TFile::Open(fileName, "recreate");