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 reconstruction can be switched on or off for individual detectors by //
37 // rec.SetRunReconstruction("..."); //
39 // The argument is a (case sensitive) string with the names of the //
40 // detectors separated by a space. The special string "ALL" selects all //
41 // available detectors. This is the default. //
43 // The tracking in ITS, TPC and TRD and the creation of ESD tracks can be //
46 // rec.SetRunTracking(kFALSE); //
48 // The filling of additional ESD information can be steered by //
50 // rec.SetFillESD("..."); //
52 // Again, the string specifies the list of detectors. The default is "ALL". //
54 // The reconstruction requires digits as input. For the creation of digits //
55 // have a look at the class AliSimulation. //
57 ///////////////////////////////////////////////////////////////////////////////
60 #include "AliReconstruction.h"
61 #include "AliRunLoader.h"
63 #include "AliModule.h"
64 #include "AliDetector.h"
65 #include "AliTracker.h"
67 #include "AliHeader.h"
68 #include "AliGenEventHeader.h"
69 #include "AliESDpid.h"
74 ClassImp(AliReconstruction)
77 //_____________________________________________________________________________
78 AliReconstruction::AliReconstruction(const char* gAliceFilename,
79 const char* name, const char* title) :
82 fRunReconstruction("ALL"),
85 fGAliceFileName(gAliceFilename),
98 // create reconstruction object with default parameters
102 //_____________________________________________________________________________
103 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
106 fRunReconstruction(rec.fRunReconstruction),
107 fRunTracking(rec.fRunTracking),
108 fFillESD(rec.fFillESD),
109 fGAliceFileName(rec.fGAliceFileName),
110 fStopOnError(rec.fStopOnError),
126 //_____________________________________________________________________________
127 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
129 // assignment operator
131 this->~AliReconstruction();
132 new(this) AliReconstruction(rec);
136 //_____________________________________________________________________________
137 AliReconstruction::~AliReconstruction()
145 //_____________________________________________________________________________
146 void AliReconstruction::SetGAliceFile(const char* fileName)
148 // set the name of the galice file
150 fGAliceFileName = fileName;
154 //_____________________________________________________________________________
155 Bool_t AliReconstruction::Run()
157 // run the reconstruction
159 // open the run loader
160 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
162 Error("Run", "no run loader found in file %s",
163 fGAliceFileName.Data());
167 fRunLoader->LoadgAlice();
168 AliRun* aliRun = fRunLoader->GetAliRun();
170 Error("Run", "no gAlice object found in file %s",
171 fGAliceFileName.Data());
177 // local reconstruction
178 if (!fRunReconstruction.IsNull()) {
179 if (!RunReconstruction(fRunReconstruction)) {
180 if (fStopOnError) {CleanUp(); return kFALSE;}
183 if (!fRunTracking && fFillESD.IsNull()) return kTRUE;
185 // get loaders and trackers
186 fITSLoader = fRunLoader->GetLoader("ITSLoader");
188 Error("Run", "no ITS loader found");
189 if (fStopOnError) {CleanUp(); return kFALSE;}
192 if (aliRun->GetDetector("ITS")) {
193 fITSTracker = aliRun->GetDetector("ITS")->CreateTracker();
196 Error("Run", "couldn't create a tracker for ITS");
197 if (fStopOnError) {CleanUp(); return kFALSE;}
200 fTPCLoader = fRunLoader->GetLoader("TPCLoader");
202 Error("Run", "no TPC loader found");
203 if (fStopOnError) {CleanUp(); return kFALSE;}
206 if (aliRun->GetDetector("TPC")) {
207 fTPCTracker = aliRun->GetDetector("TPC")->CreateTracker();
210 Error("Run", "couldn't create a tracker for TPC");
211 if (fStopOnError) {CleanUp(); return kFALSE;}
214 fTRDLoader = fRunLoader->GetLoader("TRDLoader");
216 Error("Run", "no TRD loader found");
217 if (fStopOnError) {CleanUp(); return kFALSE;}
220 if (aliRun->GetDetector("TRD")) {
221 fTRDTracker = aliRun->GetDetector("TRD")->CreateTracker();
224 Error("Run", "couldn't create a tracker for TRD");
225 if (fStopOnError) {CleanUp(); return kFALSE;}
228 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
230 Error("Run", "no TOF loader found");
231 if (fStopOnError) {CleanUp(); return kFALSE;}
234 if (aliRun->GetDetector("TOF")) {
235 fTOFTracker = aliRun->GetDetector("TOF")->CreateTracker();
238 Error("Run", "couldn't create a tracker for TOF");
239 if (fStopOnError) {CleanUp(); return kFALSE;}
242 // create the ESD output file
243 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
244 if (!file->IsOpen()) {
245 Error("Run", "opening AliESDs.root failed");
246 if (fStopOnError) {CleanUp(file); return kFALSE;}
250 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
251 Info("Run", "processing event %d", iEvent);
252 AliESD* esd = new AliESD;
253 fRunLoader->GetEvent(iEvent);
254 esd->SetRunNumber(aliRun->GetRunNumber());
255 esd->SetEventNumber(aliRun->GetEvNumber());
256 esd->SetMagneticField(aliRun->Field()->SolenoidField());
260 if (!RunTracking(esd)) {
261 if (fStopOnError) {CleanUp(file); return kFALSE;}
266 if (!fFillESD.IsNull()) {
267 if (!FillESD(esd, fFillESD)) {
268 if (fStopOnError) {CleanUp(file); return kFALSE;}
273 AliESDpid::MakePID(esd);
277 sprintf(name, "ESD%d", iEvent);
279 if (!esd->Write(name)) {
280 Error("Run", "writing ESD failed");
281 if (fStopOnError) {CleanUp(file); return kFALSE;}
291 //_____________________________________________________________________________
292 Bool_t AliReconstruction::RunReconstruction(const TString& detectors)
294 // run the reconstruction
296 TStopwatch stopwatch;
299 TString detStr = detectors;
300 TObjArray* detArray = fRunLoader->GetAliRun()->Detectors();
301 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
302 AliModule* det = (AliModule*) detArray->At(iDet);
303 if (!det || !det->IsActive()) continue;
304 if (IsSelected(det->GetName(), detStr)) {
305 Info("RunReconstruction", "running reconstruction for %s",
307 TStopwatch stopwatchDet;
308 stopwatchDet.Start();
310 Info("RunReconstruction", "execution time for %s:", det->GetName());
311 stopwatchDet.Print();
315 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
316 Error("RunReconstruction", "the following detectors were not found: %s",
318 if (fStopOnError) return kFALSE;
321 Info("RunReconstruction", "execution time:");
327 //_____________________________________________________________________________
328 Bool_t AliReconstruction::RunTracking(AliESD* esd)
330 // run the barrel tracking
332 TStopwatch stopwatch;
335 // get the primary vertex (from MC for the moment)
337 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(vertex);
338 Double_t vtxPos[3] = {vertex[0], vertex[1], vertex[2]};
339 Double_t vtxCov[6] = {
344 Double_t vtxErr[3] = {vtxCov[0], vtxCov[2], vtxCov[5]}; // diag. elements
345 esd->SetVertex(vtxPos, vtxCov);
346 fITSTracker->SetVertex(vtxPos, vtxErr);
347 fTPCTracker->SetVertex(vtxPos, vtxErr);
348 fTRDTracker->SetVertex(vtxPos, vtxErr);
351 Info("RunTracking", "TPC tracking");
352 fTPCLoader->LoadRecPoints("read");
353 TTree* tpcTree = fTPCLoader->TreeR();
355 Error("RunTracking", "Can't get the TPC cluster tree");
358 fTPCTracker->LoadClusters(tpcTree);
359 if (fTPCTracker->Clusters2Tracks(esd) != 0) {
360 Error("RunTracking", "TPC Clusters2Tracks failed");
364 fRunLoader->GetAliRun()->GetDetector("TPC")->FillESD(esd); // preliminary PID
365 AliESDpid::MakePID(esd); // for the ITS tracker
368 Info("RunTracking", "ITS tracking");
369 fITSLoader->LoadRecPoints("read");
370 TTree* itsTree = fITSLoader->TreeR();
372 Error("RunTracking", "Can't get the ITS cluster tree");
375 fITSTracker->LoadClusters(itsTree);
376 if (fITSTracker->Clusters2Tracks(esd) != 0) {
377 Error("RunTracking", "ITS Clusters2Tracks failed");
381 // ITS back propagation
382 Info("RunTracking", "ITS back propagation");
383 if (fITSTracker->PropagateBack(esd) != 0) {
384 Error("RunTracking", "ITS backward propagation failed");
388 // TPC back propagation
389 Info("RunTracking", "TPC back propagation");
390 if (fTPCTracker->PropagateBack(esd) != 0) {
391 Error("RunTracking", "TPC backward propagation failed");
395 // TRD back propagation
396 Info("RunTracking", "TRD back propagation");
397 fTRDLoader->LoadRecPoints("read");
398 TTree* trdTree = fTRDLoader->TreeR();
400 Error("RunTracking", "Can't get the TRD cluster tree");
403 fTRDTracker->LoadClusters(trdTree);
404 if (fTRDTracker->PropagateBack(esd) != 0) {
405 Error("RunTracking", "TRD backward propagation failed");
409 // TOF back propagation
410 Info("RunTracking", "TOF back propagation");
411 fTOFLoader->LoadDigits("read");
412 TTree* tofTree = fTOFLoader->TreeD();
414 Error("RunTracking", "Can't get the TOF digits tree");
417 fTOFTracker->LoadClusters(tofTree);
418 if (fTOFTracker->PropagateBack(esd) != 0) {
419 Error("RunTracking", "TOF backward propagation failed");
422 fTOFTracker->UnloadClusters();
423 fTOFLoader->UnloadDigits();
426 Info("RunTracking", "TRD inward refit");
427 if (fTRDTracker->RefitInward(esd) != 0) {
428 Error("RunTracking", "TRD inward refit failed");
431 fTRDTracker->UnloadClusters();
432 fTRDLoader->UnloadRecPoints();
435 Info("RunTracking", "TPC inward refit");
436 if (fTPCTracker->RefitInward(esd) != 0) {
437 Error("RunTracking", "TPC inward refit failed");
440 fTPCTracker->UnloadClusters();
441 fTPCLoader->UnloadRecPoints();
444 Info("RunTracking", "ITS inward refit");
445 if (fITSTracker->RefitInward(esd) != 0) {
446 Error("RunTracking", "ITS inward refit failed");
449 fITSTracker->UnloadClusters();
450 fITSLoader->UnloadRecPoints();
452 Info("RunTracking", "execution time:");
458 //_____________________________________________________________________________
459 Bool_t AliReconstruction::FillESD(AliESD* esd, const TString& detectors)
461 // fill the event summary data
463 TStopwatch stopwatch;
466 TString detStr = detectors;
467 TObjArray* detArray = fRunLoader->GetAliRun()->Detectors();
468 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
469 AliModule* det = (AliModule*) detArray->At(iDet);
470 if (!det || !det->IsActive()) continue;
471 if (IsSelected(det->GetName(), detStr)) {
472 Info("FillESD", "filling ESD for %s",
478 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
479 Error("FillESD", "the following detectors were not found: %s",
481 if (fStopOnError) return kFALSE;
484 Info("FillESD", "execution time:");
491 //_____________________________________________________________________________
492 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
494 // check whether detName is contained in detectors
495 // if yes, it is removed from detectors
497 // check if all detectors are selected
498 if ((detectors.CompareTo("ALL") == 0) ||
499 detectors.BeginsWith("ALL ") ||
500 detectors.EndsWith(" ALL") ||
501 detectors.Contains(" ALL ")) {
506 // search for the given detector
507 Bool_t result = kFALSE;
508 if ((detectors.CompareTo(detName) == 0) ||
509 detectors.BeginsWith(detName+" ") ||
510 detectors.EndsWith(" "+detName) ||
511 detectors.Contains(" "+detName+" ")) {
512 detectors.ReplaceAll(detName, "");
516 // clean up the detectors string
517 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
518 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
519 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
524 //_____________________________________________________________________________
525 void AliReconstruction::CleanUp(TFile* file)
527 // delete trackers and the run loader and close and delete the file