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 //
32 // rec.SetGAliceFile("..."); //
34 // The reconstruction can be switched on or off for individual detectors by //
36 // rec.SetRunReconstruction("..."); //
38 // The argument is a (case sensitive) string with the names of the //
39 // detectors separated by a space. The special string "ALL" selects all //
40 // available detectors. This is the default. //
42 // The tracking in ITS, TPC and TRD and the creation of ESD tracks can be //
45 // rec.SetRunTracking(kFALSE); //
47 // The filling of additional ESD information can be steered by //
49 // rec.SetFillESD("..."); //
51 // Again, the string specifies the list of detectors. The default is "ALL". //
53 // The reconstruction requires digits as input. For the creation of digits //
54 // have a look at the class AliSimulation. //
56 ///////////////////////////////////////////////////////////////////////////////
59 #include "AliReconstruction.h"
60 #include "AliRunLoader.h"
62 #include "AliModule.h"
63 #include "AliDetector.h"
64 #include "AliTracker.h"
66 #include "AliHeader.h"
67 #include "AliGenEventHeader.h"
68 #include "AliESDpid.h"
72 ClassImp(AliReconstruction)
75 //_____________________________________________________________________________
76 AliReconstruction::AliReconstruction(const char* name, const char* title) :
79 // create reconstruction object with default parameters
84 //_____________________________________________________________________________
85 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
90 fRunReconstruction = rec.fRunReconstruction;
91 fRunTracking = rec.fRunTracking;
92 fStopOnError = rec.fStopOnError;
94 fGAliceFileName = rec.fGAliceFileName;
99 //_____________________________________________________________________________
100 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
102 // assignment operator
104 this->~AliReconstruction();
105 new(this) AliReconstruction(rec);
109 //_____________________________________________________________________________
110 AliReconstruction::~AliReconstruction()
116 //_____________________________________________________________________________
117 void AliReconstruction::Init()
119 // set default parameters
121 fRunReconstruction = "ALL";
122 fRunTracking = kTRUE;
124 fStopOnError = kFALSE;
126 fGAliceFileName = "galice.root";
132 //_____________________________________________________________________________
133 void AliReconstruction::SetGAliceFile(const char* fileName)
135 // set the name of the galice file
137 fGAliceFileName = fileName;
141 //_____________________________________________________________________________
142 Bool_t AliReconstruction::Run()
144 // run the reconstruction
146 // open the run loader
147 if (fRunLoader) delete fRunLoader;
148 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
150 Error("Run", "no run loader found in file %s",
151 fGAliceFileName.Data());
154 fRunLoader->LoadgAlice();
155 gAlice = fRunLoader->GetAliRun();
157 Error("Run", "no gAlice object found in file %s",
158 fGAliceFileName.Data());
162 // local reconstruction
163 if (!fRunReconstruction.IsNull()) {
164 if (!RunReconstruction(fRunReconstruction)) {
165 if (fStopOnError) return kFALSE;
168 if (!fRunTracking && fFillESD.IsNull()) return kTRUE;
170 // get loaders and trackers
171 fITSLoader = fRunLoader->GetLoader("ITSLoader");
173 Error("Run", "no ITS loader found");
174 if (fStopOnError) return kFALSE;
177 if (gAlice->GetDetector("ITS")) {
178 fITSTracker = gAlice->GetDetector("ITS")->CreateTracker();
181 Error("Run", "couldn't create a tracker for ITS");
182 if (fStopOnError) return kFALSE;
185 fTPCLoader = fRunLoader->GetLoader("TPCLoader");
187 Error("Run", "no TPC loader found");
188 if (fStopOnError) return kFALSE;
191 if (gAlice->GetDetector("TPC")) {
192 fTPCTracker = gAlice->GetDetector("TPC")->CreateTracker();
195 Error("Run", "couldn't create a tracker for TPC");
196 if (fStopOnError) return kFALSE;
199 fTRDLoader = fRunLoader->GetLoader("TRDLoader");
201 Error("Run", "no TRD loader found");
202 if (fStopOnError) return kFALSE;
205 if (gAlice->GetDetector("TRD")) {
206 fTRDTracker = gAlice->GetDetector("TRD")->CreateTracker();
209 Error("Run", "couldn't create a tracker for TRD");
210 if (fStopOnError) return kFALSE;
213 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
215 Error("Run", "no TOF loader found");
216 if (fStopOnError) return kFALSE;
219 if (gAlice->GetDetector("TOF")) {
220 fTOFTracker = gAlice->GetDetector("TOF")->CreateTracker();
223 Error("Run", "couldn't create a tracker for TOF");
224 if (fStopOnError) return kFALSE;
227 // create the ESD output file
228 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
229 if (!file->IsOpen()) {
230 Error("Run", "opening AliESDs.root failed");
231 if (fStopOnError) return kFALSE;
235 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
236 Info("Run", "processing event %d", iEvent);
237 AliESD* esd = new AliESD;
238 fRunLoader->GetEvent(iEvent);
239 esd->SetRunNumber(gAlice->GetRunNumber());
240 esd->SetEventNumber(gAlice->GetEvNumber());
244 if (!RunTracking(esd)) {
245 if (fStopOnError) return kFALSE;
250 if (!fFillESD.IsNull()) {
251 if (!FillESD(esd, fFillESD)) {
252 if (fStopOnError) return kFALSE;
257 AliESDpid::MakePID(esd);
261 sprintf(name, "ESD%d", iEvent);
263 if (!esd->Write(name)) {
264 Error("Run", "writing ESD failed");
265 if (fStopOnError) return kFALSE;
275 //_____________________________________________________________________________
276 Bool_t AliReconstruction::RunReconstruction(const TString& detectors)
278 // run the reconstruction
280 TStopwatch stopwatch;
283 TString detStr = detectors;
284 TObjArray* detArray = gAlice->Detectors();
285 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
286 AliModule* det = (AliModule*) detArray->At(iDet);
287 if (!det || !det->IsActive()) continue;
288 if (IsSelected(det->GetName(), detStr)) {
289 Info("RunReconstruction", "running reconstruction for %s",
291 TStopwatch stopwatchDet;
292 stopwatchDet.Start();
294 Info("RunReconstruction", "execution time for %s:", det->GetName());
295 stopwatchDet.Print();
299 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
300 Error("RunReconstruction", "the following detectors were not found: %s",
302 if (fStopOnError) return kFALSE;
305 Info("RunReconstruction", "execution time:");
311 //_____________________________________________________________________________
312 Bool_t AliReconstruction::RunTracking(AliESD* esd)
314 // run the barrel tracking
316 TStopwatch stopwatch;
319 // get the primary vertex (from MC for the moment)
321 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(vertex);
322 Double_t vtxPos[3] = {vertex[0], vertex[1], vertex[2]};
323 Double_t vtxCov[6] = {
328 Double_t vtxErr[3] = {vtxCov[0], vtxCov[2], vtxCov[5]}; // diag. elements
329 esd->SetVertex(vtxPos, vtxCov);
330 fITSTracker->SetVertex(vtxPos, vtxErr);
331 fTPCTracker->SetVertex(vtxPos, vtxErr);
332 fTRDTracker->SetVertex(vtxPos, vtxErr);
335 Info("RunTracking", "TPC tracking");
336 fTPCLoader->LoadRecPoints("read");
337 TTree* tpcTree = fTPCLoader->TreeR();
339 Error("RunTracking", "Can't get the TPC cluster tree");
342 fTPCTracker->LoadClusters(tpcTree);
343 if (fTPCTracker->Clusters2Tracks(esd) != 0) {
344 Error("RunTracking", "TPC Clusters2Tracks failed");
348 gAlice->GetDetector("TPC")->FillESD(esd); // preliminary PID
349 AliESDpid::MakePID(esd); // for the ITS tracker
352 Info("RunTracking", "ITS tracking");
353 fITSLoader->LoadRecPoints("read");
354 TTree* itsTree = fITSLoader->TreeR();
356 Error("RunTracking", "Can't get the ITS cluster tree");
359 fITSTracker->LoadClusters(itsTree);
360 if (fITSTracker->Clusters2Tracks(esd) != 0) {
361 Error("RunTracking", "ITS Clusters2Tracks failed");
365 // ITS back propagation
366 Info("RunTracking", "ITS back propagation");
367 if (fITSTracker->PropagateBack(esd) != 0) {
368 Error("RunTracking", "ITS backward propagation failed");
372 // TPC back propagation
373 Info("RunTracking", "TPC back propagation");
374 if (fTPCTracker->PropagateBack(esd) != 0) {
375 Error("RunTracking", "TPC backward propagation failed");
379 // TRD back propagation
380 Info("RunTracking", "TRD back propagation");
381 fTRDLoader->LoadRecPoints("read");
382 TTree* trdTree = fTRDLoader->TreeR();
384 Error("RunTracking", "Can't get the TRD cluster tree");
387 fTRDTracker->LoadClusters(trdTree);
388 if (fTRDTracker->PropagateBack(esd) != 0) {
389 Error("RunTracking", "TRD backward propagation failed");
393 // TOF back propagation
394 Info("RunTracking", "TOF back propagation");
395 fTOFLoader->LoadDigits("read");
396 TTree* tofTree = fTOFLoader->TreeD();
398 Error("RunTracking", "Can't get the TOF digits tree");
401 fTOFTracker->LoadClusters(tofTree);
402 if (fTOFTracker->PropagateBack(esd) != 0) {
403 Error("RunTracking", "TOF backward propagation failed");
406 fTOFTracker->UnloadClusters();
407 fTOFLoader->UnloadDigits();
410 Info("RunTracking", "TRD inward refit");
411 if (fTRDTracker->RefitInward(esd) != 0) {
412 Error("RunTracking", "TRD inward refit failed");
415 fTRDTracker->UnloadClusters();
416 fTRDLoader->UnloadRecPoints();
419 Info("RunTracking", "TPC inward refit");
420 if (fTPCTracker->RefitInward(esd) != 0) {
421 Error("RunTracking", "TPC inward refit failed");
424 fTPCTracker->UnloadClusters();
425 fTPCLoader->UnloadRecPoints();
428 Info("RunTracking", "ITS inward refit");
429 if (fITSTracker->RefitInward(esd) != 0) {
430 Error("RunTracking", "ITS inward refit failed");
433 fITSTracker->UnloadClusters();
434 fITSLoader->UnloadRecPoints();
436 Info("RunTracking", "execution time:");
442 //_____________________________________________________________________________
443 Bool_t AliReconstruction::FillESD(AliESD* esd, const TString& detectors)
445 // fill the event summary data
447 TStopwatch stopwatch;
450 TString detStr = detectors;
451 TObjArray* detArray = gAlice->Detectors();
452 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
453 AliModule* det = (AliModule*) detArray->At(iDet);
454 if (!det || !det->IsActive()) continue;
455 if (IsSelected(det->GetName(), detStr)) {
456 Info("FillESD", "filling ESD for %s",
462 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
463 Error("FillESD", "the following detectors were not found: %s",
465 if (fStopOnError) return kFALSE;
468 Info("FillESD", "execution time:");
475 //_____________________________________________________________________________
476 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
478 // check whether detName is contained in detectors
479 // if yes, it is removed from detectors
481 // check if all detectors are selected
482 if ((detectors.CompareTo("ALL") == 0) ||
483 detectors.BeginsWith("ALL ") ||
484 detectors.EndsWith(" ALL") ||
485 detectors.Contains(" ALL ")) {
490 // search for the given detector
491 Bool_t result = kFALSE;
492 if ((detectors.CompareTo(detName) == 0) ||
493 detectors.BeginsWith(detName+" ") ||
494 detectors.EndsWith(" "+detName) ||
495 detectors.Contains(" "+detName+" ")) {
496 detectors.ReplaceAll(detName, "");
500 // clean up the detectors string
501 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
502 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
503 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);