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;
186 // get loaders and trackers
187 fITSLoader = fRunLoader->GetLoader("ITSLoader");
189 Error("Run", "no ITS loader found");
190 if (fStopOnError) {CleanUp(); return kFALSE;}
193 if (aliRun->GetDetector("ITS")) {
194 fITSTracker = aliRun->GetDetector("ITS")->CreateTracker();
197 Error("Run", "couldn't create a tracker for ITS");
198 if (fStopOnError) {CleanUp(); return kFALSE;}
201 fTPCLoader = fRunLoader->GetLoader("TPCLoader");
203 Error("Run", "no TPC loader found");
204 if (fStopOnError) {CleanUp(); return kFALSE;}
207 if (aliRun->GetDetector("TPC")) {
208 fTPCTracker = aliRun->GetDetector("TPC")->CreateTracker();
211 Error("Run", "couldn't create a tracker for TPC");
212 if (fStopOnError) {CleanUp(); return kFALSE;}
215 fTRDLoader = fRunLoader->GetLoader("TRDLoader");
217 Error("Run", "no TRD loader found");
218 if (fStopOnError) {CleanUp(); return kFALSE;}
221 if (aliRun->GetDetector("TRD")) {
222 fTRDTracker = aliRun->GetDetector("TRD")->CreateTracker();
225 Error("Run", "couldn't create a tracker for TRD");
226 if (fStopOnError) {CleanUp(); return kFALSE;}
229 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
231 Error("Run", "no TOF loader found");
232 if (fStopOnError) {CleanUp(); return kFALSE;}
235 if (aliRun->GetDetector("TOF")) {
236 fTOFTracker = aliRun->GetDetector("TOF")->CreateTracker();
239 Error("Run", "couldn't create a tracker for TOF");
240 if (fStopOnError) {CleanUp(); return kFALSE;}
243 // create the ESD output file
244 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
245 if (!file->IsOpen()) {
246 Error("Run", "opening AliESDs.root failed");
247 if (fStopOnError) {CleanUp(file); return kFALSE;}
251 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
252 Info("Run", "processing event %d", iEvent);
253 AliESD* esd = new AliESD;
254 fRunLoader->GetEvent(iEvent);
255 esd->SetRunNumber(aliRun->GetRunNumber());
256 esd->SetEventNumber(aliRun->GetEvNumber());
257 esd->SetMagneticField(aliRun->Field()->SolenoidField());
261 if (!RunTracking(esd)) {
262 if (fStopOnError) {CleanUp(file); return kFALSE;}
267 if (!fFillESD.IsNull()) {
268 if (!FillESD(esd, fFillESD)) {
269 if (fStopOnError) {CleanUp(file); return kFALSE;}
274 AliESDpid::MakePID(esd);
278 sprintf(name, "ESD%d", iEvent);
280 if (!esd->Write(name)) {
281 Error("Run", "writing ESD failed");
282 if (fStopOnError) {CleanUp(file); return kFALSE;}
293 //_____________________________________________________________________________
294 Bool_t AliReconstruction::RunReconstruction(const TString& detectors)
296 // run the reconstruction
298 TStopwatch stopwatch;
301 TString detStr = detectors;
302 TObjArray* detArray = fRunLoader->GetAliRun()->Detectors();
303 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
304 AliModule* det = (AliModule*) detArray->At(iDet);
305 if (!det || !det->IsActive()) continue;
306 if (IsSelected(det->GetName(), detStr)) {
307 Info("RunReconstruction", "running reconstruction for %s",
309 TStopwatch stopwatchDet;
310 stopwatchDet.Start();
312 Info("RunReconstruction", "execution time for %s:", det->GetName());
313 stopwatchDet.Print();
317 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
318 Error("RunReconstruction", "the following detectors were not found: %s",
320 if (fStopOnError) return kFALSE;
323 Info("RunReconstruction", "execution time:");
329 //_____________________________________________________________________________
330 Bool_t AliReconstruction::RunTracking(AliESD* esd)
332 // run the barrel tracking
334 TStopwatch stopwatch;
337 // get the primary vertex (from MC for the moment)
339 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(vertex);
340 Double_t vtxPos[3] = {vertex[0], vertex[1], vertex[2]};
341 Double_t vtxCov[6] = {
346 Double_t vtxErr[3] = {vtxCov[0], vtxCov[2], vtxCov[5]}; // diag. elements
347 esd->SetVertex(vtxPos, vtxCov);
348 fITSTracker->SetVertex(vtxPos, vtxErr);
349 fTPCTracker->SetVertex(vtxPos, vtxErr);
350 fTRDTracker->SetVertex(vtxPos, vtxErr);
353 Info("RunTracking", "TPC tracking");
354 fTPCLoader->LoadRecPoints("read");
355 TTree* tpcTree = fTPCLoader->TreeR();
357 Error("RunTracking", "Can't get the TPC cluster tree");
360 fTPCTracker->LoadClusters(tpcTree);
361 if (fTPCTracker->Clusters2Tracks(esd) != 0) {
362 Error("RunTracking", "TPC Clusters2Tracks failed");
366 fRunLoader->GetAliRun()->GetDetector("TPC")->FillESD(esd); // preliminary PID
367 AliESDpid::MakePID(esd); // for the ITS tracker
370 Info("RunTracking", "ITS tracking");
371 fITSLoader->LoadRecPoints("read");
372 TTree* itsTree = fITSLoader->TreeR();
374 Error("RunTracking", "Can't get the ITS cluster tree");
377 fITSTracker->LoadClusters(itsTree);
378 if (fITSTracker->Clusters2Tracks(esd) != 0) {
379 Error("RunTracking", "ITS Clusters2Tracks failed");
383 // ITS back propagation
384 Info("RunTracking", "ITS back propagation");
385 if (fITSTracker->PropagateBack(esd) != 0) {
386 Error("RunTracking", "ITS backward propagation failed");
390 // TPC back propagation
391 Info("RunTracking", "TPC back propagation");
392 if (fTPCTracker->PropagateBack(esd) != 0) {
393 Error("RunTracking", "TPC backward propagation failed");
397 // TRD back propagation
398 Info("RunTracking", "TRD back propagation");
399 fTRDLoader->LoadRecPoints("read");
400 TTree* trdTree = fTRDLoader->TreeR();
402 Error("RunTracking", "Can't get the TRD cluster tree");
405 fTRDTracker->LoadClusters(trdTree);
406 if (fTRDTracker->PropagateBack(esd) != 0) {
407 Error("RunTracking", "TRD backward propagation failed");
411 // TOF back propagation
412 Info("RunTracking", "TOF back propagation");
413 fTOFLoader->LoadDigits("read");
414 TTree* tofTree = fTOFLoader->TreeD();
416 Error("RunTracking", "Can't get the TOF digits tree");
419 fTOFTracker->LoadClusters(tofTree);
420 if (fTOFTracker->PropagateBack(esd) != 0) {
421 Error("RunTracking", "TOF backward propagation failed");
424 fTOFTracker->UnloadClusters();
425 fTOFLoader->UnloadDigits();
428 Info("RunTracking", "TRD inward refit");
429 if (fTRDTracker->RefitInward(esd) != 0) {
430 Error("RunTracking", "TRD inward refit failed");
433 fTRDTracker->UnloadClusters();
434 fTRDLoader->UnloadRecPoints();
437 Info("RunTracking", "TPC inward refit");
438 if (fTPCTracker->RefitInward(esd) != 0) {
439 Error("RunTracking", "TPC inward refit failed");
442 fTPCTracker->UnloadClusters();
443 fTPCLoader->UnloadRecPoints();
446 Info("RunTracking", "ITS inward refit");
447 if (fITSTracker->RefitInward(esd) != 0) {
448 Error("RunTracking", "ITS inward refit failed");
451 fITSTracker->UnloadClusters();
452 fITSLoader->UnloadRecPoints();
454 Info("RunTracking", "execution time:");
460 //_____________________________________________________________________________
461 Bool_t AliReconstruction::FillESD(AliESD* esd, const TString& detectors)
463 // fill the event summary data
465 TStopwatch stopwatch;
468 TString detStr = detectors;
469 TObjArray* detArray = fRunLoader->GetAliRun()->Detectors();
470 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
471 AliModule* det = (AliModule*) detArray->At(iDet);
472 if (!det || !det->IsActive()) continue;
473 if (IsSelected(det->GetName(), detStr)) {
474 Info("FillESD", "filling ESD for %s",
480 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
481 Error("FillESD", "the following detectors were not found: %s",
483 if (fStopOnError) return kFALSE;
486 Info("FillESD", "execution time:");
493 //_____________________________________________________________________________
494 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
496 // check whether detName is contained in detectors
497 // if yes, it is removed from detectors
499 // check if all detectors are selected
500 if ((detectors.CompareTo("ALL") == 0) ||
501 detectors.BeginsWith("ALL ") ||
502 detectors.EndsWith(" ALL") ||
503 detectors.Contains(" ALL ")) {
508 // search for the given detector
509 Bool_t result = kFALSE;
510 if ((detectors.CompareTo(detName) == 0) ||
511 detectors.BeginsWith(detName+" ") ||
512 detectors.EndsWith(" "+detName) ||
513 detectors.Contains(" "+detName+" ")) {
514 detectors.ReplaceAll(detName, "");
518 // clean up the detectors string
519 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
520 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
521 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
526 //_____________________________________________________________________________
527 void AliReconstruction::CleanUp(TFile* file)
529 // delete trackers and the run loader and close and delete the file