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"
73 ClassImp(AliReconstruction)
76 //_____________________________________________________________________________
77 AliReconstruction::AliReconstruction(const char* name, const char* title) :
80 // create reconstruction object with default parameters
85 //_____________________________________________________________________________
86 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
91 fRunReconstruction = rec.fRunReconstruction;
92 fRunTracking = rec.fRunTracking;
93 fStopOnError = rec.fStopOnError;
95 fGAliceFileName = rec.fGAliceFileName;
100 //_____________________________________________________________________________
101 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
103 // assignment operator
105 this->~AliReconstruction();
106 new(this) AliReconstruction(rec);
110 //_____________________________________________________________________________
111 AliReconstruction::~AliReconstruction()
117 //_____________________________________________________________________________
118 void AliReconstruction::Init()
120 // set default parameters
122 fRunReconstruction = "ALL";
123 fRunTracking = kTRUE;
125 fStopOnError = kFALSE;
127 fGAliceFileName = "galice.root";
133 //_____________________________________________________________________________
134 void AliReconstruction::SetGAliceFile(const char* fileName)
136 // set the name of the galice file
138 fGAliceFileName = fileName;
142 //_____________________________________________________________________________
143 Bool_t AliReconstruction::Run()
145 // run the reconstruction
147 // open the run loader
148 if (fRunLoader) delete fRunLoader;
149 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
151 Error("Run", "no run loader found in file %s",
152 fGAliceFileName.Data());
155 fRunLoader->LoadgAlice();
156 gAlice = fRunLoader->GetAliRun();
158 Error("Run", "no gAlice object found in file %s",
159 fGAliceFileName.Data());
163 // local reconstruction
164 if (!fRunReconstruction.IsNull()) {
165 if (!RunReconstruction(fRunReconstruction)) {
166 if (fStopOnError) return kFALSE;
169 if (!fRunTracking && fFillESD.IsNull()) return kTRUE;
171 // get loaders and trackers
172 fITSLoader = fRunLoader->GetLoader("ITSLoader");
174 Error("Run", "no ITS loader found");
175 if (fStopOnError) return kFALSE;
178 if (gAlice->GetDetector("ITS")) {
179 fITSTracker = gAlice->GetDetector("ITS")->CreateTracker();
182 Error("Run", "couldn't create a tracker for ITS");
183 if (fStopOnError) return kFALSE;
186 fTPCLoader = fRunLoader->GetLoader("TPCLoader");
188 Error("Run", "no TPC loader found");
189 if (fStopOnError) return kFALSE;
192 if (gAlice->GetDetector("TPC")) {
193 fTPCTracker = gAlice->GetDetector("TPC")->CreateTracker();
196 Error("Run", "couldn't create a tracker for TPC");
197 if (fStopOnError) return kFALSE;
200 fTRDLoader = fRunLoader->GetLoader("TRDLoader");
202 Error("Run", "no TRD loader found");
203 if (fStopOnError) return kFALSE;
206 if (gAlice->GetDetector("TRD")) {
207 fTRDTracker = gAlice->GetDetector("TRD")->CreateTracker();
210 Error("Run", "couldn't create a tracker for TRD");
211 if (fStopOnError) return kFALSE;
214 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
216 Error("Run", "no TOF loader found");
217 if (fStopOnError) return kFALSE;
220 if (gAlice->GetDetector("TOF")) {
221 fTOFTracker = gAlice->GetDetector("TOF")->CreateTracker();
224 Error("Run", "couldn't create a tracker for TOF");
225 if (fStopOnError) return kFALSE;
228 // create the ESD output file
229 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
230 if (!file->IsOpen()) {
231 Error("Run", "opening AliESDs.root failed");
232 if (fStopOnError) return kFALSE;
236 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
237 Info("Run", "processing event %d", iEvent);
238 AliESD* esd = new AliESD;
239 fRunLoader->GetEvent(iEvent);
240 esd->SetRunNumber(gAlice->GetRunNumber());
241 esd->SetEventNumber(gAlice->GetEvNumber());
242 esd->SetMagneticField(fRunLoader->GetAliRun()->Field()->SolenoidField());
246 if (!RunTracking(esd)) {
247 if (fStopOnError) return kFALSE;
252 if (!fFillESD.IsNull()) {
253 if (!FillESD(esd, fFillESD)) {
254 if (fStopOnError) return kFALSE;
259 AliESDpid::MakePID(esd);
263 sprintf(name, "ESD%d", iEvent);
265 if (!esd->Write(name)) {
266 Error("Run", "writing ESD failed");
267 if (fStopOnError) return kFALSE;
277 //_____________________________________________________________________________
278 Bool_t AliReconstruction::RunReconstruction(const TString& detectors)
280 // run the reconstruction
282 TStopwatch stopwatch;
285 TString detStr = detectors;
286 TObjArray* detArray = gAlice->Detectors();
287 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
288 AliModule* det = (AliModule*) detArray->At(iDet);
289 if (!det || !det->IsActive()) continue;
290 if (IsSelected(det->GetName(), detStr)) {
291 Info("RunReconstruction", "running reconstruction for %s",
293 TStopwatch stopwatchDet;
294 stopwatchDet.Start();
296 Info("RunReconstruction", "execution time for %s:", det->GetName());
297 stopwatchDet.Print();
301 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
302 Error("RunReconstruction", "the following detectors were not found: %s",
304 if (fStopOnError) return kFALSE;
307 Info("RunReconstruction", "execution time:");
313 //_____________________________________________________________________________
314 Bool_t AliReconstruction::RunTracking(AliESD* esd)
316 // run the barrel tracking
318 TStopwatch stopwatch;
321 // get the primary vertex (from MC for the moment)
323 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(vertex);
324 Double_t vtxPos[3] = {vertex[0], vertex[1], vertex[2]};
325 Double_t vtxCov[6] = {
330 Double_t vtxErr[3] = {vtxCov[0], vtxCov[2], vtxCov[5]}; // diag. elements
331 esd->SetVertex(vtxPos, vtxCov);
332 fITSTracker->SetVertex(vtxPos, vtxErr);
333 fTPCTracker->SetVertex(vtxPos, vtxErr);
334 fTRDTracker->SetVertex(vtxPos, vtxErr);
337 Info("RunTracking", "TPC tracking");
338 fTPCLoader->LoadRecPoints("read");
339 TTree* tpcTree = fTPCLoader->TreeR();
341 Error("RunTracking", "Can't get the TPC cluster tree");
344 fTPCTracker->LoadClusters(tpcTree);
345 if (fTPCTracker->Clusters2Tracks(esd) != 0) {
346 Error("RunTracking", "TPC Clusters2Tracks failed");
350 gAlice->GetDetector("TPC")->FillESD(esd); // preliminary PID
351 AliESDpid::MakePID(esd); // for the ITS tracker
354 Info("RunTracking", "ITS tracking");
355 fITSLoader->LoadRecPoints("read");
356 TTree* itsTree = fITSLoader->TreeR();
358 Error("RunTracking", "Can't get the ITS cluster tree");
361 fITSTracker->LoadClusters(itsTree);
362 if (fITSTracker->Clusters2Tracks(esd) != 0) {
363 Error("RunTracking", "ITS Clusters2Tracks failed");
367 // ITS back propagation
368 Info("RunTracking", "ITS back propagation");
369 if (fITSTracker->PropagateBack(esd) != 0) {
370 Error("RunTracking", "ITS backward propagation failed");
374 // TPC back propagation
375 Info("RunTracking", "TPC back propagation");
376 if (fTPCTracker->PropagateBack(esd) != 0) {
377 Error("RunTracking", "TPC backward propagation failed");
381 // TRD back propagation
382 Info("RunTracking", "TRD back propagation");
383 fTRDLoader->LoadRecPoints("read");
384 TTree* trdTree = fTRDLoader->TreeR();
386 Error("RunTracking", "Can't get the TRD cluster tree");
389 fTRDTracker->LoadClusters(trdTree);
390 if (fTRDTracker->PropagateBack(esd) != 0) {
391 Error("RunTracking", "TRD backward propagation failed");
395 // TOF back propagation
396 Info("RunTracking", "TOF back propagation");
397 fTOFLoader->LoadDigits("read");
398 TTree* tofTree = fTOFLoader->TreeD();
400 Error("RunTracking", "Can't get the TOF digits tree");
403 fTOFTracker->LoadClusters(tofTree);
404 if (fTOFTracker->PropagateBack(esd) != 0) {
405 Error("RunTracking", "TOF backward propagation failed");
408 fTOFTracker->UnloadClusters();
409 fTOFLoader->UnloadDigits();
412 Info("RunTracking", "TRD inward refit");
413 if (fTRDTracker->RefitInward(esd) != 0) {
414 Error("RunTracking", "TRD inward refit failed");
417 fTRDTracker->UnloadClusters();
418 fTRDLoader->UnloadRecPoints();
421 Info("RunTracking", "TPC inward refit");
422 if (fTPCTracker->RefitInward(esd) != 0) {
423 Error("RunTracking", "TPC inward refit failed");
426 fTPCTracker->UnloadClusters();
427 fTPCLoader->UnloadRecPoints();
430 Info("RunTracking", "ITS inward refit");
431 if (fITSTracker->RefitInward(esd) != 0) {
432 Error("RunTracking", "ITS inward refit failed");
435 fITSTracker->UnloadClusters();
436 fITSLoader->UnloadRecPoints();
438 Info("RunTracking", "execution time:");
444 //_____________________________________________________________________________
445 Bool_t AliReconstruction::FillESD(AliESD* esd, const TString& detectors)
447 // fill the event summary data
449 TStopwatch stopwatch;
452 TString detStr = detectors;
453 TObjArray* detArray = gAlice->Detectors();
454 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
455 AliModule* det = (AliModule*) detArray->At(iDet);
456 if (!det || !det->IsActive()) continue;
457 if (IsSelected(det->GetName(), detStr)) {
458 Info("FillESD", "filling ESD for %s",
464 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
465 Error("FillESD", "the following detectors were not found: %s",
467 if (fStopOnError) return kFALSE;
470 Info("FillESD", "execution time:");
477 //_____________________________________________________________________________
478 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
480 // check whether detName is contained in detectors
481 // if yes, it is removed from detectors
483 // check if all detectors are selected
484 if ((detectors.CompareTo("ALL") == 0) ||
485 detectors.BeginsWith("ALL ") ||
486 detectors.EndsWith(" ALL") ||
487 detectors.Contains(" ALL ")) {
492 // search for the given detector
493 Bool_t result = kFALSE;
494 if ((detectors.CompareTo(detName) == 0) ||
495 detectors.BeginsWith(detName+" ") ||
496 detectors.EndsWith(" "+detName) ||
497 detectors.Contains(" "+detName+" ")) {
498 detectors.ReplaceAll(detName, "");
502 // clean up the detectors string
503 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
504 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
505 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);