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 TString detStr = detectors;
281 TObjArray* detArray = gAlice->Detectors();
282 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
283 AliModule* det = (AliModule*) detArray->At(iDet);
284 if (!det || !det->IsActive()) continue;
285 if (IsSelected(det->GetName(), detStr)) {
286 Info("RunReconstruction", "running reconstruction for %s",
292 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
293 Error("RunReconstruction", "the following detectors were not found: %s",
295 if (fStopOnError) return kFALSE;
301 //_____________________________________________________________________________
302 Bool_t AliReconstruction::RunTracking(AliESD* esd)
304 // run the barrel tracking
306 // get the primary vertex (from MC for the moment)
308 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(vertex);
309 Double_t vtxPos[3] = {vertex[0], vertex[1], vertex[2]};
310 Double_t vtxCov[6] = {
315 Double_t vtxErr[3] = {vtxCov[0], vtxCov[2], vtxCov[5]}; // diag. elements
316 esd->SetVertex(vtxPos, vtxCov);
317 fITSTracker->SetVertex(vtxPos, vtxErr);
318 fTPCTracker->SetVertex(vtxPos, vtxErr);
319 fTRDTracker->SetVertex(vtxPos, vtxErr);
322 Info("RunTracking", "TPC inward fit");
323 fTPCLoader->LoadRecPoints("read");
324 TTree* tpcTree = fTPCLoader->TreeR();
326 Error("RunTracking", "Can't get the TPC cluster tree");
329 fTPCTracker->LoadClusters(tpcTree);
330 if (fTPCTracker->Clusters2Tracks(esd) != 0) {
331 Error("RunTracking", "TPC inward track fit failed");
336 Info("RunTracking", "ITS inward fit");
337 fITSLoader->LoadRecPoints("read");
338 TTree* itsTree = fITSLoader->TreeR();
340 Error("RunTracking", "Can't get the ITS cluster tree");
343 fITSTracker->LoadClusters(itsTree);
344 if (fITSTracker->Clusters2Tracks(esd) != 0) {
345 Error("RunTracking", "ITS inward track fit failed");
349 // ITS back propagation
350 Info("RunTracking", "ITS back propagation");
351 if (fITSTracker->PropagateBack(esd) != 0) {
352 Error("RunTracking", "ITS backward propagation failed");
356 // TPC back propagation
357 Info("RunTracking", "TPC back propagation");
358 if (fTPCTracker->PropagateBack(esd) != 0) {
359 Error("RunTracking", "TPC backward propagation failed");
363 // TRD back propagation
364 Info("RunTracking", "TRD back propagation");
365 fTRDLoader->LoadRecPoints("read");
366 TTree* trdTree = fTRDLoader->TreeR();
368 Error("RunTracking", "Can't get the TRD cluster tree");
371 fTRDTracker->LoadClusters(trdTree);
372 if (fTRDTracker->PropagateBack(esd) != 0) {
373 Error("RunTracking", "TRD backward propagation failed");
377 // TOF back propagation
378 Info("RunTracking", "TOF back propagation");
379 fTOFLoader->LoadDigits("read");
380 TTree* tofTree = fTOFLoader->TreeD();
382 Error("RunTracking", "Can't get the TOF digits tree");
385 fTOFTracker->LoadClusters(tofTree);
386 if (fTOFTracker->PropagateBack(esd) != 0) {
387 Error("RunTracking", "TOF backward propagation failed");
390 fTOFTracker->UnloadClusters();
391 fTOFLoader->UnloadDigits();
394 Info("RunTracking", "TRD inward refit");
395 if (fTRDTracker->RefitInward(esd) != 0) {
396 Error("RunTracking", "TRD inward refit failed");
399 fTRDTracker->UnloadClusters();
400 fTRDLoader->UnloadRecPoints();
403 Info("RunTracking", "TPC inward refit");
404 if (fTPCTracker->RefitInward(esd) != 0) {
405 Error("RunTracking", "TPC inward refit failed");
408 fTPCTracker->UnloadClusters();
409 fTPCLoader->UnloadRecPoints();
412 Info("RunTracking", "ITS inward refit");
413 if (fITSTracker->RefitInward(esd) != 0) {
414 Error("RunTracking", "ITS inward refit failed");
417 fITSTracker->UnloadClusters();
418 fITSLoader->UnloadRecPoints();
423 //_____________________________________________________________________________
424 Bool_t AliReconstruction::FillESD(AliESD* esd, const TString& detectors)
426 // fill the event summary data
428 TString detStr = detectors;
429 TObjArray* detArray = gAlice->Detectors();
430 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
431 AliModule* det = (AliModule*) detArray->At(iDet);
432 if (!det || !det->IsActive()) continue;
433 if (IsSelected(det->GetName(), detStr)) {
434 Info("FillESD", "filling ESD for %s",
440 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
441 Error("FillESD", "the following detectors were not found: %s",
443 if (fStopOnError) return kFALSE;
450 //_____________________________________________________________________________
451 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
453 // check whether detName is contained in detectors
454 // if yes, it is removed from detectors
456 // check if all detectors are selected
457 if ((detectors.CompareTo("ALL") == 0) ||
458 detectors.BeginsWith("ALL ") ||
459 detectors.EndsWith(" ALL") ||
460 detectors.Contains(" ALL ")) {
465 // search for the given detector
466 Bool_t result = kFALSE;
467 if ((detectors.CompareTo(detName) == 0) ||
468 detectors.BeginsWith(detName+" ") ||
469 detectors.EndsWith(" "+detName) ||
470 detectors.Contains(" "+detName+" ")) {
471 detectors.ReplaceAll(detName, "");
475 // clean up the detectors string
476 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
477 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
478 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);