]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliReconstruction.cxx
Mixing template.
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
CommitLineData
596a855f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class for running the reconstruction //
21// //
22// Clusters and tracks are created for all detectors and all events by //
23// typing: //
24// //
25// AliReconstruction rec; //
26// rec.Run(); //
27// //
28// The Run method returns kTRUE in case of successful execution. //
c71de921 29// //
30// If the input to the reconstruction are not simulated digits but raw data, //
31// this can be specified by an argument of the Run method or by the method //
32// //
33// rec.SetInput("..."); //
34// //
35// The input formats and the corresponding argument are: //
36// - DDL raw data files: directory name, ends with "/" //
37// - raw data root file: root file name, extension ".root" //
38// - raw data DATE file: DATE file name, any other non-empty string //
39// - MC root files : empty string, default //
40// //
b26c3770 41// By default all events are reconstructed. The reconstruction can be //
42// limited to a range of events by giving the index of the first and the //
43// last event as an argument to the Run method or by calling //
44// //
45// rec.SetEventRange(..., ...); //
46// //
47// The index -1 (default) can be used for the last event to indicate no //
48// upper limit of the event range. //
49// //
973388c2 50// In case of raw-data reconstruction the user can modify the default //
51// number of events per digits/clusters/tracks file. In case the option //
52// is not used the number is set 1. In case the user provides 0, than //
53// the number of events is equal to the number of events inside the //
54// raw-data file (i.e. one digits/clusters/tracks file): //
55// //
56// rec.SetNumberOfEventsPerFile(...); //
57// //
58// //
596a855f 59// The name of the galice file can be changed from the default //
e583c30d 60// "galice.root" by passing it as argument to the AliReconstruction //
61// constructor or by //
596a855f 62// //
63// rec.SetGAliceFile("..."); //
64// //
59697224 65// The local reconstruction can be switched on or off for individual //
66// detectors by //
596a855f 67// //
59697224 68// rec.SetRunLocalReconstruction("..."); //
596a855f 69// //
70// The argument is a (case sensitive) string with the names of the //
71// detectors separated by a space. The special string "ALL" selects all //
72// available detectors. This is the default. //
73// //
c71de921 74// The reconstruction of the primary vertex position can be switched off by //
75// //
76// rec.SetRunVertexFinder(kFALSE); //
77// //
b8cd5251 78// The tracking and the creation of ESD tracks can be switched on for //
79// selected detectors by //
596a855f 80// //
b8cd5251 81// rec.SetRunTracking("..."); //
596a855f 82// //
c84a5e9e 83// Uniform/nonuniform field tracking switches (default: uniform field) //
84// //
1d99986f 85// rec.SetUniformFieldTracking(); ( rec.SetUniformFieldTracking(kFALSE); ) //
c84a5e9e 86// //
596a855f 87// The filling of additional ESD information can be steered by //
88// //
89// rec.SetFillESD("..."); //
90// //
b8cd5251 91// Again, for both methods the string specifies the list of detectors. //
92// The default is "ALL". //
93// //
94// The call of the shortcut method //
95// //
96// rec.SetRunReconstruction("..."); //
97// //
98// is equivalent to calling SetRunLocalReconstruction, SetRunTracking and //
99// SetFillESD with the same detector selecting string as argument. //
596a855f 100// //
c71de921 101// The reconstruction requires digits or raw data as input. For the creation //
102// of digits and raw data have a look at the class AliSimulation. //
596a855f 103// //
cd0b062e 104// The input data of a detector can be replaced by the corresponding HLT //
105// data by calling (usual detector string) //
106// SetUseHLTData("..."); //
107// //
24f7a148 108// For debug purposes the method SetCheckPointLevel can be used. If the //
109// argument is greater than 0, files with ESD events will be written after //
110// selected steps of the reconstruction for each event: //
111// level 1: after tracking and after filling of ESD (final) //
112// level 2: in addition after each tracking step //
113// level 3: in addition after the filling of ESD for each detector //
114// If a final check point file exists for an event, this event will be //
115// skipped in the reconstruction. The tracking and the filling of ESD for //
116// a detector will be skipped as well, if the corresponding check point //
117// file exists. The ESD event will then be loaded from the file instead. //
118// //
596a855f 119///////////////////////////////////////////////////////////////////////////////
120
024a7e64 121#include <TArrayF.h>
122#include <TFile.h>
444753c6 123#include <TList.h>
024a7e64 124#include <TSystem.h>
125#include <TROOT.h>
126#include <TPluginManager.h>
3103d196 127#include <TGeoManager.h>
2bdb9d38 128#include <TLorentzVector.h>
3dd9f9e3 129#include <TArrayS.h>
130#include <TArrayD.h>
3c3709c4 131#include <TObjArray.h>
596a855f 132
133#include "AliReconstruction.h"
87932dab 134#include "AliCodeTimer.h"
b8cd5251 135#include "AliReconstructor.h"
815c2b38 136#include "AliLog.h"
596a855f 137#include "AliRunLoader.h"
138#include "AliRun.h"
b649205a 139#include "AliRawReaderFile.h"
140#include "AliRawReaderDate.h"
141#include "AliRawReaderRoot.h"
001397cd 142#include "AliRawEventHeaderBase.h"
af885e0f 143#include "AliESDEvent.h"
faffd83e 144#include "AliESDMuonTrack.h"
1d99986f 145#include "AliESDfriend.h"
2257f27e 146#include "AliESDVertex.h"
faffd83e 147#include "AliESDcascade.h"
148#include "AliESDkink.h"
149#include "AliESDtrack.h"
150#include "AliESDCaloCluster.h"
e649177a 151#include "AliESDCaloCells.h"
32e449be 152#include "AliMultiplicity.h"
c84a5e9e 153#include "AliTracker.h"
2257f27e 154#include "AliVertexer.h"
c5e3e5d1 155#include "AliVertexerTracks.h"
5e4ff34d 156#include "AliV0vertexer.h"
157#include "AliCascadeVertexer.h"
596a855f 158#include "AliHeader.h"
159#include "AliGenEventHeader.h"
b26c3770 160#include "AliPID.h"
596a855f 161#include "AliESDpid.h"
ff8bb5ae 162#include "AliESDtrack.h"
3dd9f9e3 163#include "AliESDPmdTrack.h"
f3a97c86 164
08e1a23e 165#include "AliESDTagCreator.h"
a1069ee1 166#include "AliAODTagCreator.h"
f3a97c86 167
25be1e5c 168#include "AliGeomManager.h"
98937d93 169#include "AliTrackPointArray.h"
b0314964 170#include "AliCDBManager.h"
795e4a22 171#include "AliCDBStorage.h"
6bae477a 172#include "AliCDBEntry.h"
173#include "AliAlignObj.h"
f3a97c86 174
b647652d 175#include "AliCentralTrigger.h"
b024fd7f 176#include "AliTriggerConfiguration.h"
177#include "AliTriggerClass.h"
b647652d 178#include "AliCTPRawStream.h"
179
04236e67 180#include "AliQADataMakerRec.h"
aa3c69a9 181#include "AliGlobalQADataMaker.h"
c65c502a 182#include "AliQA.h"
183#include "AliQADataMakerSteer.h"
f29f1726 184
7167ae53 185#include "AliPlaneEff.h"
186
0f88822a 187#include "AliSysInfo.h" // memory snapshots
cd0b062e 188#include "AliRawHLTManager.h"
0f88822a 189
6efecea1 190
596a855f 191ClassImp(AliReconstruction)
192
193
c757bafd 194//_____________________________________________________________________________
b384f8a4 195const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
c757bafd 196
596a855f 197//_____________________________________________________________________________
795e4a22 198AliReconstruction::AliReconstruction(const char* gAliceFilename,
e583c30d 199 const char* name, const char* title) :
200 TNamed(name, title),
201
f8b507e0 202 fUniformField(kFALSE),
2257f27e 203 fRunVertexFinder(kTRUE),
a84e2607 204 fRunVertexFinderTracks(kTRUE),
1f46a9ae 205 fRunHLTTracking(kFALSE),
e66fbafb 206 fRunMuonTracking(kFALSE),
d1683eef 207 fRunV0Finder(kTRUE),
208 fRunCascadeFinder(kTRUE),
1d99986f 209 fStopOnError(kFALSE),
210 fWriteAlignmentData(kFALSE),
211 fWriteESDfriend(kFALSE),
a7807689 212 fWriteAOD(kFALSE),
b647652d 213 fFillTriggerESD(kTRUE),
1d99986f 214
7f68891d 215 fCleanESD(kTRUE),
a023d8d8 216 fV0DCAmax(3.),
217 fV0CsPmin(0.),
7f68891d 218 fDmax(50.),
219 fZmax(50.),
220
1d99986f 221 fRunLocalReconstruction("ALL"),
b8cd5251 222 fRunTracking("ALL"),
e583c30d 223 fFillESD("ALL"),
48ce48d1 224 fUseTrackingErrorsForAlignment(""),
e583c30d 225 fGAliceFileName(gAliceFilename),
b649205a 226 fInput(""),
35042093 227 fEquipIdMap(""),
b26c3770 228 fFirstEvent(0),
229 fLastEvent(-1),
973388c2 230 fNumberOfEventsPerFile(1),
24f7a148 231 fCheckPointLevel(0),
b8cd5251 232 fOptions(),
6bae477a 233 fLoadAlignFromCDB(kTRUE),
234 fLoadAlignData("ALL"),
46698ae4 235 fESDPar(""),
cd0b062e 236 fUseHLTData(),
e583c30d 237
238 fRunLoader(NULL),
b649205a 239 fRawReader(NULL),
cd0b062e 240 fParentRawReader(NULL),
b8cd5251 241
98937d93 242 fVertexer(NULL),
9178838a 243 fDiamondProfile(NULL),
43c9dae1 244 fDiamondProfileTPC(NULL),
87317a47 245 fMeanVertexConstraint(kTRUE),
98937d93 246
6b6e4472 247 fGRPData(NULL),
444753c6 248
6bae477a 249 fAlignObjArray(NULL),
795e4a22 250 fCDBUri(),
759c1df1 251 fSpecCDBUri(),
795e4a22 252 fInitCDBCalled(kFALSE),
253 fSetRunNumberFromDataCalled(kFALSE),
7e963665 254 fRunQA(kTRUE),
6b150027 255 fRunGlobalQA(kTRUE),
7167ae53 256 fInLoopQA(kFALSE),
e4a998ed 257 fSameQACycle(kFALSE),
7167ae53 258
21a3aa09 259 fRunPlaneEff(kFALSE),
260
261 fesd(NULL),
262 fhltesd(NULL),
263 fesdf(NULL),
264 ffile(NULL),
265 ftree(NULL),
266 fhlttree(NULL),
267 ffileOld(NULL),
268 ftreeOld(NULL),
269 fhlttreeOld(NULL),
270 ftVertexer(NULL),
14dd053c 271 fIsNewRunLoader(kFALSE),
272 fRunAliEVE(kFALSE)
596a855f 273{
274// create reconstruction object with default parameters
b8cd5251 275
276 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
277 fReconstructor[iDet] = NULL;
278 fLoader[iDet] = NULL;
279 fTracker[iDet] = NULL;
7e963665 280 fQADataMaker[iDet] = NULL;
281 fQACycles[iDet] = 999999;
b8cd5251 282 }
aa3c69a9 283 fQADataMaker[fgkNDetectors]=NULL; //Global QA
e47c4c2e 284 AliPID pid;
596a855f 285}
286
287//_____________________________________________________________________________
288AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
e583c30d 289 TNamed(rec),
290
c84a5e9e 291 fUniformField(rec.fUniformField),
2257f27e 292 fRunVertexFinder(rec.fRunVertexFinder),
a84e2607 293 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
1f46a9ae 294 fRunHLTTracking(rec.fRunHLTTracking),
e66fbafb 295 fRunMuonTracking(rec.fRunMuonTracking),
d1683eef 296 fRunV0Finder(rec.fRunV0Finder),
297 fRunCascadeFinder(rec.fRunCascadeFinder),
1d99986f 298 fStopOnError(rec.fStopOnError),
299 fWriteAlignmentData(rec.fWriteAlignmentData),
300 fWriteESDfriend(rec.fWriteESDfriend),
a7807689 301 fWriteAOD(rec.fWriteAOD),
b647652d 302 fFillTriggerESD(rec.fFillTriggerESD),
1d99986f 303
7f68891d 304 fCleanESD(rec.fCleanESD),
a023d8d8 305 fV0DCAmax(rec.fV0DCAmax),
5e5c1aa9 306 fV0CsPmin(rec.fV0CsPmin),
7f68891d 307 fDmax(rec.fDmax),
308 fZmax(rec.fZmax),
309
1d99986f 310 fRunLocalReconstruction(rec.fRunLocalReconstruction),
e583c30d 311 fRunTracking(rec.fRunTracking),
312 fFillESD(rec.fFillESD),
48ce48d1 313 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
e583c30d 314 fGAliceFileName(rec.fGAliceFileName),
b649205a 315 fInput(rec.fInput),
35042093 316 fEquipIdMap(rec.fEquipIdMap),
b26c3770 317 fFirstEvent(rec.fFirstEvent),
318 fLastEvent(rec.fLastEvent),
973388c2 319 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
24f7a148 320 fCheckPointLevel(0),
b8cd5251 321 fOptions(),
6bae477a 322 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
323 fLoadAlignData(rec.fLoadAlignData),
46698ae4 324 fESDPar(rec.fESDPar),
2972d4eb 325 fUseHLTData(rec.fUseHLTData),
e583c30d 326
327 fRunLoader(NULL),
b649205a 328 fRawReader(NULL),
2972d4eb 329 fParentRawReader(NULL),
b8cd5251 330
98937d93 331 fVertexer(NULL),
9178838a 332 fDiamondProfile(NULL),
43c9dae1 333 fDiamondProfileTPC(NULL),
87317a47 334 fMeanVertexConstraint(rec.fMeanVertexConstraint),
98937d93 335
6b6e4472 336 fGRPData(NULL),
444753c6 337
6bae477a 338 fAlignObjArray(rec.fAlignObjArray),
ec92bee0 339 fCDBUri(rec.fCDBUri),
7e963665 340 fSpecCDBUri(),
795e4a22 341 fInitCDBCalled(rec.fInitCDBCalled),
342 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
aa3c69a9 343 fRunQA(rec.fRunQA),
344 fRunGlobalQA(rec.fRunGlobalQA),
7167ae53 345 fInLoopQA(rec.fInLoopQA),
e4a998ed 346 fSameQACycle(rec.fSameQACycle),
21a3aa09 347 fRunPlaneEff(rec.fRunPlaneEff),
348
349 fesd(NULL),
350 fhltesd(NULL),
351 fesdf(NULL),
352 ffile(NULL),
353 ftree(NULL),
354 fhlttree(NULL),
355 ffileOld(NULL),
356 ftreeOld(NULL),
357 fhlttreeOld(NULL),
358 ftVertexer(NULL),
14dd053c 359 fIsNewRunLoader(rec.fIsNewRunLoader),
360 fRunAliEVE(kFALSE)
596a855f 361{
362// copy constructor
363
ec92bee0 364 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
efd2085e 365 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
366 }
b8cd5251 367 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
368 fReconstructor[iDet] = NULL;
369 fLoader[iDet] = NULL;
370 fTracker[iDet] = NULL;
7e963665 371 fQADataMaker[iDet] = NULL;
372 fQACycles[iDet] = rec.fQACycles[iDet];
b8cd5251 373 }
aa3c69a9 374 fQADataMaker[fgkNDetectors]=NULL; //Global QA
ec92bee0 375 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
376 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
377 }
596a855f 378}
379
380//_____________________________________________________________________________
381AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
382{
383// assignment operator
384
385 this->~AliReconstruction();
386 new(this) AliReconstruction(rec);
387 return *this;
388}
389
390//_____________________________________________________________________________
391AliReconstruction::~AliReconstruction()
392{
393// clean up
394
e583c30d 395 CleanUp();
efd2085e 396 fOptions.Delete();
ec92bee0 397 fSpecCDBUri.Delete();
87932dab 398
399 AliCodeTimer::Instance()->Print();
596a855f 400}
401
024cf675 402//_____________________________________________________________________________
795e4a22 403void AliReconstruction::InitCDB()
024cf675 404{
405// activate a default CDB storage
406// First check if we have any CDB storage set, because it is used
407// to retrieve the calibration and alignment constants
408
795e4a22 409 if (fInitCDBCalled) return;
410 fInitCDBCalled = kTRUE;
411
024cf675 412 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 413 if (man->IsDefaultStorageSet())
024cf675 414 {
415 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 416 AliWarning("Default CDB storage has been already set !");
417 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
024cf675 418 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 419 fCDBUri = man->GetDefaultStorage()->GetURI();
ec92bee0 420 }
421 else {
795e4a22 422 if (fCDBUri.Length() > 0)
423 {
424 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
425 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
426 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
427 } else {
428 fCDBUri="local://$ALICE_ROOT";
429 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
430 AliWarning("Default CDB storage not yet set !!!!");
431 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
432 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
433
434 }
ec92bee0 435 man->SetDefaultStorage(fCDBUri);
436 }
437
438 // Now activate the detector specific CDB storage locations
c3a7b59a 439 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
440 TObject* obj = fSpecCDBUri[i];
441 if (!obj) continue;
b8ec52f6 442 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
443 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
444 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 445 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 446 }
795e4a22 447
024cf675 448}
449
450//_____________________________________________________________________________
451void AliReconstruction::SetDefaultStorage(const char* uri) {
ec92bee0 452// Store the desired default CDB storage location
453// Activate it later within the Run() method
024cf675 454
ec92bee0 455 fCDBUri = uri;
024cf675 456
457}
458
00aa02d5 459//_____________________________________________________________________________
c3a7b59a 460void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 461// Store a detector-specific CDB storage location
462// Activate it later within the Run() method
024cf675 463
c3a7b59a 464 AliCDBPath aPath(calibType);
465 if(!aPath.IsValid()){
466 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
467 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
468 if(!strcmp(calibType, fgkDetectorName[iDet])) {
469 aPath.SetPath(Form("%s/*", calibType));
470 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
471 break;
472 }
473 }
474 if(!aPath.IsValid()){
475 AliError(Form("Not a valid path or detector: %s", calibType));
476 return;
477 }
478 }
479
53dd3c3d 480// // check that calibType refers to a "valid" detector name
481// Bool_t isDetector = kFALSE;
482// for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
483// TString detName = fgkDetectorName[iDet];
484// if(aPath.GetLevel0() == detName) {
485// isDetector = kTRUE;
486// break;
487// }
488// }
489//
490// if(!isDetector) {
491// AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
492// return;
493// }
c3a7b59a 494
495 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
ec92bee0 496 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 497 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
024cf675 498
499}
500
6bae477a 501//_____________________________________________________________________________
795e4a22 502Bool_t AliReconstruction::SetRunNumberFromData()
6bae477a 503{
504 // The method is called in Run() in order
505 // to set a correct run number.
506 // In case of raw data reconstruction the
507 // run number is taken from the raw data header
508
795e4a22 509 if (fSetRunNumberFromDataCalled) return kTRUE;
510 fSetRunNumberFromDataCalled = kTRUE;
511
512 AliCDBManager* man = AliCDBManager::Instance();
513
514 if(man->GetRun() > 0) {
21a3aa09 515 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
795e4a22 516 }
517
518 if (!fRunLoader) {
6bae477a 519 AliError("No run loader is found !");
520 return kFALSE;
521 }
522 // read run number from gAlice
ec92bee0 523 if(fRunLoader->GetAliRun())
f2ee4290 524 AliCDBManager::Instance()->SetRun(fRunLoader->GetHeader()->GetRun());
ec92bee0 525 else {
526 if(fRawReader) {
527 if(fRawReader->NextEvent()) {
528 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
529 fRawReader->RewindEvents();
530 }
531 else {
21a3aa09 532 if(man->GetRun() > 0) {
533 AliWarning("No raw events is found ! Using settings in AliCDBManager !");
534 man->Print();
535 return kTRUE;
536 }
537 else {
538 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
539 return kFALSE;
540 }
ec92bee0 541 }
542 }
543 else {
544 AliError("Neither gAlice nor RawReader objects are found !");
545 return kFALSE;
546 }
6bae477a 547 }
795e4a22 548
549 man->Print();
550
6bae477a 551 return kTRUE;
552}
553
795e4a22 554//_____________________________________________________________________________
555void AliReconstruction::SetCDBLock() {
556 // Set CDB lock: from now on it is forbidden to reset the run number
557 // or the default storage or to activate any further storage!
558
559 AliCDBManager::Instance()->SetLock(1);
560}
561
6bae477a 562//_____________________________________________________________________________
563Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
564{
565 // Read the alignment objects from CDB.
566 // Each detector is supposed to have the
567 // alignment objects in DET/Align/Data CDB path.
568 // All the detector objects are then collected,
569 // sorted by geometry level (starting from ALIC) and
570 // then applied to the TGeo geometry.
571 // Finally an overlaps check is performed.
572
573 // Load alignment data from CDB and fill fAlignObjArray
574 if(fLoadAlignFromCDB){
6bae477a 575
25be1e5c 576 TString detStr = detectors;
577 TString loadAlObjsListOfDets = "";
578
579 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
580 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
581 loadAlObjsListOfDets += fgkDetectorName[iDet];
582 loadAlObjsListOfDets += " ";
583 } // end loop over detectors
53dd3c3d 584 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
98e303d9 585 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
25be1e5c 586 }else{
587 // Check if the array with alignment objects was
588 // provided by the user. If yes, apply the objects
589 // to the present TGeo geometry
590 if (fAlignObjArray) {
591 if (gGeoManager && gGeoManager->IsClosed()) {
98e303d9 592 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
25be1e5c 593 AliError("The misalignment of one or more volumes failed!"
594 "Compare the list of simulated detectors and the list of detector alignment data!");
595 return kFALSE;
596 }
597 }
598 else {
599 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
6bae477a 600 return kFALSE;
601 }
602 }
6bae477a 603 }
25be1e5c 604
8e245d15 605 delete fAlignObjArray; fAlignObjArray=0;
a03b0371 606
6bae477a 607 return kTRUE;
608}
596a855f 609
610//_____________________________________________________________________________
611void AliReconstruction::SetGAliceFile(const char* fileName)
612{
613// set the name of the galice file
614
615 fGAliceFileName = fileName;
616}
617
21a3aa09 618//_____________________________________________________________________________
b58710ef 619void AliReconstruction::SetInput(const char* input)
21a3aa09 620{
b58710ef 621 // In case the input string starts with 'mem://', we run in an online mode
622 // and AliRawReaderDateOnline object is created. In all other cases a raw-data
623 // file is assumed. One can give as an input:
624 // mem://: - events taken from DAQ monitoring libs online
625 // or
626 // mem://<filename> - emulation of the above mode (via DATE monitoring libs)
627 fInput = input;
21a3aa09 628}
629
efd2085e 630//_____________________________________________________________________________
631void AliReconstruction::SetOption(const char* detector, const char* option)
632{
633// set options for the reconstruction of a detector
634
635 TObject* obj = fOptions.FindObject(detector);
636 if (obj) fOptions.Remove(obj);
637 fOptions.Add(new TNamed(detector, option));
638}
639
596a855f 640//_____________________________________________________________________________
21a3aa09 641Bool_t AliReconstruction::Run(const char* input)
596a855f 642{
21a3aa09 643 // Run Run Run
644 AliCodeTimerAuto("");
596a855f 645
21a3aa09 646 if (!InitRun(input)) return kFALSE;
319f3084 647
21a3aa09 648 //******* The loop over events
649 Int_t iEvent = 0;
650 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
651 (fRawReader && fRawReader->NextEvent())) {
652 if (!RunEvent(iEvent)) return kFALSE;
653 iEvent++;
654 }
655
656 if (!FinishRun()) return kFALSE;
657
658 return kTRUE;
659}
660
661//_____________________________________________________________________________
b58710ef 662Bool_t AliReconstruction::InitRun(const char* input)
21a3aa09 663{
664 // Initialize all the stuff before
665 // going into the event loop
666 // If the second argument is given, the first one is ignored and
667 // the reconstruction works in an online mode
668 AliCodeTimerAuto("");
669
b58710ef 670 // Overwrite the previous setting
21a3aa09 671 if (input) fInput = input;
672
673 // set the input in case of raw data
b58710ef 674 fRawReader = AliRawReader::Create(fInput.Data());
675 if (!fRawReader)
21a3aa09 676 AliInfo("Reconstruction will run over digits");
e0027792 677
35042093 678 if (!fEquipIdMap.IsNull() && fRawReader)
679 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
680
cd0b062e 681 if (!fUseHLTData.IsNull()) {
682 // create the RawReaderHLT which performs redirection of HLT input data for
683 // the specified detectors
684 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
685 if (pRawReader) {
686 fParentRawReader=fRawReader;
687 fRawReader=pRawReader;
688 } else {
689 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
690 }
691 }
692
0f88822a 693 AliSysInfo::AddStamp("Start");
f08fc9f5 694 // get the run loader
695 if (!InitRunLoader()) return kFALSE;
0f88822a 696 AliSysInfo::AddStamp("LoadLoader");
596a855f 697
ec92bee0 698 // Initialize the CDB storage
795e4a22 699 InitCDB();
700
701 AliSysInfo::AddStamp("LoadCDB");
ec92bee0 702
6bae477a 703 // Set run number in CDBManager (if it is not already set by the user)
795e4a22 704 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
705
706 // Set CDB lock: from now on it is forbidden to reset the run number
707 // or the default storage or to activate any further storage!
708 SetCDBLock();
709
6bae477a 710 // Import ideal TGeo geometry and apply misalignment
711 if (!gGeoManager) {
712 TString geom(gSystem->DirName(fGAliceFileName));
713 geom += "/geometry.root";
98e303d9 714 AliGeomManager::LoadGeometry(geom.Data());
6bae477a 715 if (!gGeoManager) if (fStopOnError) return kFALSE;
716 }
8e245d15 717
6bae477a 718 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
0f88822a 719 AliSysInfo::AddStamp("LoadGeom");
6bae477a 720
f6806ad3 721 //QA
722 AliQADataMakerSteer qas ;
723 if (fRunQA && fRawReader) {
724 qas.Run(fRunLocalReconstruction, fRawReader) ;
725 fSameQACycle = kTRUE ;
726 }
727 // checking the QA of previous steps
728 //CheckQA() ;
729
aa3c69a9 730 /*
596a855f 731 // local reconstruction
59697224 732 if (!fRunLocalReconstruction.IsNull()) {
733 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
e583c30d 734 if (fStopOnError) {CleanUp(); return kFALSE;}
596a855f 735 }
736 }
aa3c69a9 737 */
2257f27e 738
739 // get vertexer
740 if (fRunVertexFinder && !CreateVertexer()) {
741 if (fStopOnError) {
742 CleanUp();
743 return kFALSE;
744 }
745 }
0f88822a 746 AliSysInfo::AddStamp("Vertexer");
596a855f 747
f08fc9f5 748 // get trackers
b8cd5251 749 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
24f7a148 750 if (fStopOnError) {
751 CleanUp();
752 return kFALSE;
753 }
596a855f 754 }
0f88822a 755 AliSysInfo::AddStamp("LoadTrackers");
24f7a148 756
b26c3770 757 // get the possibly already existing ESD file and tree
21a3aa09 758 fesd = new AliESDEvent(); fhltesd = new AliESDEvent();
b26c3770 759 if (!gSystem->AccessPathName("AliESDs.root")){
760 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
21a3aa09 761 ffileOld = TFile::Open("AliESDs.old.root");
762 if (ffileOld && ffileOld->IsOpen()) {
763 ftreeOld = (TTree*) ffileOld->Get("esdTree");
764 if (ftreeOld)fesd->ReadFromTree(ftreeOld);
765 fhlttreeOld = (TTree*) ffileOld->Get("HLTesdTree");
766 if (fhlttreeOld) fhltesd->ReadFromTree(fhlttreeOld);
b26c3770 767 }
768 }
769
36711aa4 770 // create the ESD output file and tree
21a3aa09 771 ffile = TFile::Open("AliESDs.root", "RECREATE");
772 ffile->SetCompressionLevel(2);
773 if (!ffile->IsOpen()) {
815c2b38 774 AliError("opening AliESDs.root failed");
21a3aa09 775 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
596a855f 776 }
46698ae4 777
21a3aa09 778 ftree = new TTree("esdTree", "Tree with ESD objects");
779 fesd = new AliESDEvent();
780 fesd->CreateStdContent();
781 fesd->WriteToTree(ftree);
46698ae4 782
21a3aa09 783 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
784 fhltesd = new AliESDEvent();
785 fhltesd->CreateStdContent();
786 fhltesd->WriteToTree(fhlttree);
46698ae4 787
788 /* CKB Why?
1f46a9ae 789 delete esd; delete hltesd;
790 esd = NULL; hltesd = NULL;
46698ae4 791 */
500d54ab 792 // create the branch with ESD additions
5728d3d5 793
794
795
1d99986f 796 if (fWriteESDfriend) {
21a3aa09 797 fesdf = new AliESDfriend();
798 TBranch *br=ftree->Branch("ESDfriend.","AliESDfriend", &fesdf);
46698ae4 799 br->SetFile("AliESDfriends.root");
21a3aa09 800 fesd->AddObject(fesdf);
1d99986f 801 }
5728d3d5 802
444753c6 803 // Get the GRP CDB entry
804 AliCDBEntry* entryGRP = AliCDBManager::Instance()->Get("GRP/GRP/Data");
805
6b6e4472 806 if (entryGRP)
807 fGRPData = dynamic_cast<TMap*> (entryGRP->GetObject());
808
809 if (!fGRPData)
444753c6 810 AliError("No GRP entry found in OCDB!");
444753c6 811
17c86e90 812 // Get the diamond profile from OCDB
813 AliCDBEntry* entry = AliCDBManager::Instance()
814 ->Get("GRP/Calib/MeanVertex");
815
816 if(entry) {
817 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
818 } else {
819 AliError("No diamond profile found in OCDB!");
820 }
821
43c9dae1 822 entry = 0;
823 entry = AliCDBManager::Instance()
824 ->Get("GRP/Calib/MeanVertexTPC");
825
826 if(entry) {
827 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
828 } else {
829 AliError("No diamond profile found in OCDB!");
830 }
831
21a3aa09 832 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
833 if(fDiamondProfile && fMeanVertexConstraint) ftVertexer->SetVtxStart(fDiamondProfile);
c5e3e5d1 834
b649205a 835 if (fRawReader) fRawReader->RewindEvents();
a5fa6165 836
95cee32f 837 ProcInfo_t ProcInfo;
838 gSystem->GetProcInfo(&ProcInfo);
839 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
8661738e 840
aa3c69a9 841
842 //Initialize the QA and start of cycle for out-of-cycle QA
f6806ad3 843 if (fRunQA) {
844 TString detStr(fFillESD);
845 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
846 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
847 AliQADataMakerRec *qadm = GetQADataMaker(iDet);
848 if (!qadm) continue;
849 AliInfo(Form("Initializing the QA data maker for %s",
850 fgkDetectorName[iDet]));
851 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
852 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
853 if (!fInLoopQA) {
854 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
855 qadm->StartOfCycle(AliQA::kESDS,"same");
856 }
857 }
e4a998ed 858 if (fRunGlobalQA) {
859 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
860 AliInfo(Form("Initializing the global QA data maker"));
861 TObjArray *arr=
862 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
863 AliTracker::SetResidualsArray(arr);
864 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
865 if (!fInLoopQA) {
866 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
867 qadm->StartOfCycle(AliQA::kESDS, "same");
868 }
869 }
870 if (!fInLoopQA)
871 fSameQACycle = kTRUE;
aa3c69a9 872 }
873
7167ae53 874 //Initialize the Plane Efficiency framework
875 if (fRunPlaneEff && !InitPlaneEff()) {
21a3aa09 876 if(fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
7167ae53 877 }
aa3c69a9 878
14dd053c 879 if (strcmp(gProgName,"alieve") == 0)
880 fRunAliEVE = InitAliEVE();
881
21a3aa09 882 return kTRUE;
883}
884
885//_____________________________________________________________________________
886Bool_t AliReconstruction::RunEvent(Int_t iEvent)
887{
888 // run the reconstruction over a single event
889 // The event loop is steered in Run method
890
891 AliCodeTimerAuto("");
892
893 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
894 fRunLoader->SetEventNumber(iEvent);
895 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
896 iEvent, iEvent);
897 //?? fRunLoader->MakeTree("H");
898 fRunLoader->TreeE()->Fill();
899 }
900
901 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
902 // copy old ESD to the new one
903 if (ftreeOld) {
904 fesd->ReadFromTree(ftreeOld);
905 ftreeOld->GetEntry(iEvent);
906 ftree->Fill();
b26c3770 907 }
21a3aa09 908 if (fhlttreeOld) {
f6806ad3 909 fhltesd->ReadFromTree(fhlttreeOld);
21a3aa09 910 fhlttreeOld->GetEntry(iEvent);
911 fhlttree->Fill();
912 }
913 return kTRUE;
914 }
915
916 AliInfo(Form("processing event %d", iEvent));
aa3c69a9 917
918 //Start of cycle for the in-loop QA
3b378a42 919 if (fInLoopQA) {
920 if (fRunQA) {
921 TString detStr(fFillESD);
922 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
e4a998ed 923 if (!IsSelected(fgkDetectorName[iDet], detStr))
924 continue;
3b378a42 925 AliQADataMakerRec *qadm = GetQADataMaker(iDet);
e4a998ed 926 if (!qadm)
927 continue;
928 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
3b378a42 929 qadm->StartOfCycle(AliQA::kESDS, "same") ;
930 }
e4a998ed 931 if (fRunGlobalQA) {
932 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
933 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
934 qadm->StartOfCycle(AliQA::kESDS, "same");
935 }
936 }
aa3c69a9 937 }
938
596a855f 939 fRunLoader->GetEvent(iEvent);
24f7a148 940
bb0901a4 941 char aFileName[256];
942 sprintf(aFileName, "ESD_%d.%d_final.root",
f08fc9f5 943 fRunLoader->GetHeader()->GetRun(),
944 fRunLoader->GetHeader()->GetEventNrInRun());
21a3aa09 945 if (!gSystem->AccessPathName(aFileName)) return kTRUE;
24f7a148 946
d506c543 947 // local single event reconstruction
b26c3770 948 if (!fRunLocalReconstruction.IsNull()) {
d506c543 949 TString detectors=fRunLocalReconstruction;
a441bf51 950 // run HLT event reconstruction first
d506c543 951 // ;-( IsSelected changes the string
952 if (IsSelected("HLT", detectors) &&
953 !RunLocalEventReconstruction("HLT")) {
a441bf51 954 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
955 }
956 detectors=fRunLocalReconstruction;
957 detectors.ReplaceAll("HLT", "");
958 if (!RunLocalEventReconstruction(detectors)) {
21a3aa09 959 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
b26c3770 960 }
961 }
962
21a3aa09 963 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
964 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
965 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
966 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
46698ae4 967
d6ee376f 968 // Set magnetic field from the tracker
21a3aa09 969 fesd->SetMagneticField(AliTracker::GetBz());
970 fhltesd->SetMagneticField(AliTracker::GetBz());
596a855f 971
46698ae4 972
973
2e3550da 974 // Fill raw-data error log into the ESD
21a3aa09 975 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 976
2257f27e 977 // vertex finder
978 if (fRunVertexFinder) {
21a3aa09 979 if (!ReadESD(fesd, "vertex")) {
980 if (!RunVertexFinder(fesd)) {
981 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
2257f27e 982 }
21a3aa09 983 if (fCheckPointLevel > 0) WriteESD(fesd, "vertex");
2257f27e 984 }
985 }
986
e66fbafb 987 // Muon tracking
b8cd5251 988 if (!fRunTracking.IsNull()) {
e66fbafb 989 if (fRunMuonTracking) {
21a3aa09 990 if (!RunMuonTracking(fesd)) {
991 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
24f7a148 992 }
596a855f 993 }
994 }
995
e66fbafb 996 // barrel tracking
997 if (!fRunTracking.IsNull()) {
21a3aa09 998 if (!ReadESD(fesd, "tracking")) {
999 if (!RunTracking(fesd)) {
1000 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
e66fbafb 1001 }
21a3aa09 1002 if (fCheckPointLevel > 0) WriteESD(fesd, "tracking");
e66fbafb 1003 }
1004 }
21c573b7 1005
596a855f 1006 // fill ESD
1007 if (!fFillESD.IsNull()) {
d506c543 1008 TString detectors=fFillESD;
f6806ad3 1009 // run HLT first and on hltesd
d506c543 1010 // ;-( IsSelected changes the string
1011 if (IsSelected("HLT", detectors) &&
1012 !FillESD(fhltesd, "HLT")) {
f6806ad3 1013 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1014 }
1015 detectors=fFillESD;
1016 detectors.ReplaceAll("HLT", "");
1017 if (!FillESD(fesd, detectors)) {
21a3aa09 1018 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
596a855f 1019 }
1020 }
a5fa6165 1021
001397cd 1022 // fill Event header information from the RawEventHeader
21a3aa09 1023 if (fRawReader){FillRawEventHeaderESD(fesd);}
596a855f 1024
1025 // combined PID
21a3aa09 1026 AliESDpid::MakePID(fesd);
1027 if (fCheckPointLevel > 1) WriteESD(fesd, "PID");
596a855f 1028
b647652d 1029 if (fFillTriggerESD) {
21a3aa09 1030 if (!ReadESD(fesd, "trigger")) {
1031 if (!FillTriggerESD(fesd)) {
1032 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
b647652d 1033 }
21a3aa09 1034 if (fCheckPointLevel > 1) WriteESD(fesd, "trigger");
b647652d 1035 }
1036 }
1037
21a3aa09 1038 ffile->cd();
a6ee503a 1039
3c3709c4 1040 //
67be5c77 1041 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 1042 //
21a3aa09 1043 const Int_t ntracks = fesd->GetNumberOfTracks();
1044 const Double_t kBz = fesd->GetMagneticField();
3c3709c4 1045 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1046
1047 TObjArray trkArray;
1048 UShort_t *selectedIdx=new UShort_t[ntracks];
1049
1050 for (Int_t itrack=0; itrack<ntracks; itrack++){
1051 const Double_t kMaxStep = 5; //max step over the material
1052 Bool_t ok;
1053
21a3aa09 1054 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 1055 if (!track) continue;
1056
1057 AliExternalTrackParam *tpcTrack =
1058 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 1059 ok = kFALSE;
1060 if (tpcTrack)
1061 ok = AliTracker::
1062 PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
43c9dae1 1063
1064
1065
3c3709c4 1066 if (ok) {
1067 Int_t n=trkArray.GetEntriesFast();
1068 selectedIdx[n]=track->GetID();
1069 trkArray.AddLast(tpcTrack);
1070 }
1071
f6806ad3 1072 if (track->GetX() < kRadius) continue;
3c3709c4 1073
f6806ad3 1074 ok = AliTracker::
3c3709c4 1075 PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
f6806ad3 1076 if (ok) {
1077 track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kRadius);
1078 }
3c3709c4 1079 }
1080
1081 //
1082 // Improve the reconstructed primary vertex position using the tracks
1083 //
1084 TObject *obj = fOptions.FindObject("ITS");
c060d7fe 1085 if (obj) {
1086 TString optITS = obj->GetTitle();
1087 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
a84e2607 1088 fRunVertexFinderTracks=kFALSE;
c060d7fe 1089 }
3c3709c4 1090 if (fRunVertexFinderTracks) {
1091 // TPC + ITS primary vertex
21a3aa09 1092 ftVertexer->SetITSrefitRequired();
43c9dae1 1093 if(fDiamondProfile && fMeanVertexConstraint) {
21a3aa09 1094 ftVertexer->SetVtxStart(fDiamondProfile);
43c9dae1 1095 } else {
21a3aa09 1096 ftVertexer->SetConstraintOff();
43c9dae1 1097 }
21a3aa09 1098 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 1099 if (pvtx) {
1100 if (pvtx->GetStatus()) {
21a3aa09 1101 fesd->SetPrimaryVertex(pvtx);
3c3709c4 1102 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 1103 AliESDtrack *t = fesd->GetTrack(i);
f6806ad3 1104 t->RelateToVertex(pvtx, kBz, kRadius);
3c3709c4 1105 }
1106 }
1107 }
1108
1109 // TPC-only primary vertex
21a3aa09 1110 ftVertexer->SetITSrefitNotRequired();
43c9dae1 1111 if(fDiamondProfileTPC && fMeanVertexConstraint) {
21a3aa09 1112 ftVertexer->SetVtxStart(fDiamondProfileTPC);
43c9dae1 1113 } else {
21a3aa09 1114 ftVertexer->SetConstraintOff();
43c9dae1 1115 }
21a3aa09 1116 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 1117 if (pvtx) {
1118 if (pvtx->GetStatus()) {
21a3aa09 1119 fesd->SetPrimaryVertexTPC(pvtx);
3c3709c4 1120 Int_t nsel=trkArray.GetEntriesFast();
1121 for (Int_t i=0; i<nsel; i++) {
1122 AliExternalTrackParam *t =
1123 (AliExternalTrackParam *)trkArray.UncheckedAt(i);
1124 t->PropagateToDCA(pvtx, kBz, kRadius);
1125 }
1126 }
1127 }
1128
1129 }
1130 delete[] selectedIdx;
1131
21a3aa09 1132 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
17c86e90 1133
c5e3e5d1 1134
d1683eef 1135 if (fRunV0Finder) {
1136 // V0 finding
1137 AliV0vertexer vtxer;
21a3aa09 1138 vtxer.Tracks2V0vertices(fesd);
5e4ff34d 1139
d1683eef 1140 if (fRunCascadeFinder) {
1141 // Cascade finding
1142 AliCascadeVertexer cvtxer;
21a3aa09 1143 cvtxer.V0sTracks2CascadeVertices(fesd);
d1683eef 1144 }
5e4ff34d 1145 }
1146
596a855f 1147 // write ESD
21a3aa09 1148 if (fCleanESD) CleanESD(fesd);
854c6476 1149
79740dfc 1150 if (fRunQA) {
1151 if (fRunGlobalQA) {
1152 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1153 if (qadm) qadm->Exec(AliQA::kESDS, fesd);
1154 }
1155 }
854c6476 1156
1d99986f 1157 if (fWriteESDfriend) {
21a3aa09 1158 fesdf->~AliESDfriend();
1159 new (fesdf) AliESDfriend(); // Reset...
1160 fesd->GetESDfriend(fesdf);
1d99986f 1161 }
21a3aa09 1162 ftree->Fill();
500d54ab 1163
1164 // write HLT ESD
21a3aa09 1165 fhlttree->Fill();
1d99986f 1166
14dd053c 1167 // call AliEVE
1168 if (fRunAliEVE) RunAliEVE();
1169
21a3aa09 1170 if (fCheckPointLevel > 0) WriteESD(fesd, "final");
1171 fesd->Reset();
1172 fhltesd->Reset();
5728d3d5 1173 if (fWriteESDfriend) {
21a3aa09 1174 fesdf->~AliESDfriend();
1175 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 1176 }
a5fa6165 1177
21a3aa09 1178 ProcInfo_t ProcInfo;
95cee32f 1179 gSystem->GetProcInfo(&ProcInfo);
1180 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
a5fa6165 1181
7e963665 1182
aa3c69a9 1183 // End of cycle for the in-loop QA
3b378a42 1184 if (fInLoopQA) {
1185 if (fRunQA) {
21a3aa09 1186 RunQA(fFillESD.Data(), fesd);
3b378a42 1187 TString detStr(fFillESD);
1188 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
7c002d48 1189 if (!IsSelected(fgkDetectorName[iDet], detStr))
1190 continue;
1191 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
1192 if (!qadm)
1193 continue;
1194 qadm->EndOfCycle(AliQA::kRECPOINTS);
1195 qadm->EndOfCycle(AliQA::kESDS);
1196 qadm->Finish();
1197 }
aa3c69a9 1198 }
1199 if (fRunGlobalQA) {
7c002d48 1200 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
aa3c69a9 1201 if (qadm) {
1202 qadm->EndOfCycle(AliQA::kRECPOINTS);
d7259b2e 1203 qadm->EndOfCycle(AliQA::kESDS);
aa3c69a9 1204 qadm->Finish();
1205 }
1206 }
1207 }
aa3c69a9 1208
21a3aa09 1209 return kTRUE;
1210}
1211
21a3aa09 1212//_____________________________________________________________________________
1213Bool_t AliReconstruction::FinishRun()
1214{
1215 // Finalize the run
1216 // Called after the exit
1217 // from the event loop
1218 AliCodeTimerAuto("");
1219
1220 if (fIsNewRunLoader) { // galice.root didn't exist
1221 fRunLoader->WriteHeader("OVERWRITE");
1222 fRunLoader->CdGAFile();
1223 fRunLoader->Write(0, TObject::kOverwrite);
1224 }
1225
1226 ftree->GetUserInfo()->Add(fesd);
1227 fhlttree->GetUserInfo()->Add(fhltesd);
f747912b 1228
1229 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1230 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1231
1232 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1233 cdbMapCopy->SetOwner(1);
1234 cdbMapCopy->SetName("cdbMap");
1235 TIter iter(cdbMap->GetTable());
1236
1237 TPair* pair = 0;
1238 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1239 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1240 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1241 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1242 }
1243
1244 TList *cdbListCopy = new TList();
1245 cdbListCopy->SetOwner(1);
1246 cdbListCopy->SetName("cdbList");
1247
1248 TIter iter2(cdbList);
1249
1250 AliCDBId* id=0;
1251 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 1252 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 1253 }
1254
21a3aa09 1255 ftree->GetUserInfo()->Add(cdbMapCopy);
1256 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 1257
46698ae4 1258
1259 if(fESDPar.Contains("ESD.par")){
1260 AliInfo("Attaching ESD.par to Tree");
1261 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
21a3aa09 1262 ftree->GetUserInfo()->Add(fn);
596a855f 1263 }
1264
46698ae4 1265
21a3aa09 1266 ffile->cd();
aa3c69a9 1267
a9c0e6db 1268 if (fWriteESDfriend)
21a3aa09 1269 ftree->SetBranchStatus("ESDfriend*",0);
562dd0b4 1270 // we want to have only one tree version number
21a3aa09 1271 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1272 fhlttree->Write();
f3a97c86 1273
a7a1e1c7 1274// Finish with Plane Efficiency evaluation: before of CleanUp !!!
1275 if (fRunPlaneEff && !FinishPlaneEff()) {
1276 AliWarning("Finish PlaneEff evaluation failed");
1277 }
1278
eae191bc 1279 gROOT->cd();
21a3aa09 1280 CleanUp(ffile, ffileOld);
eae191bc 1281
a7807689 1282 if (fWriteAOD) {
7a3b2050 1283 AliWarning("AOD creation not supported anymore during reconstruction. See ANALYSIS/AliAnalysisTaskESDfilter.cxx instead.");
a7807689 1284 }
1285
f3a97c86 1286 // Create tags for the events in the ESD tree (the ESD tree is always present)
1287 // In case of empty events the tags will contain dummy values
08e1a23e 1288 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
6b6e4472 1289 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData);
a1069ee1 1290 if (fWriteAOD) {
7a3b2050 1291 AliWarning("AOD tag creation not supported anymore during reconstruction.");
a1069ee1 1292 }
596a855f 1293
aa3c69a9 1294 //Finish QA and end of cycle for out-of-loop QA
3b378a42 1295 if (!fInLoopQA) {
79740dfc 1296 if (fRunQA) {
1297 AliQADataMakerSteer qas;
1298 qas.Run(fRunLocalReconstruction.Data(), AliQA::kRECPOINTS, fSameQACycle);
1299 //qas.Reset() ;
f6806ad3 1300 qas.Run(fRunTracking.Data(), AliQA::kESDS, fSameQACycle);
79740dfc 1301 if (fRunGlobalQA) {
1302 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1303 if (qadm) {
1304 qadm->EndOfCycle(AliQA::kRECPOINTS);
1305 qadm->EndOfCycle(AliQA::kESDS);
1306 qadm->Finish();
1307 }
1308 }
1309 }
759c1df1 1310 }
795e4a22 1311
1312 // Cleanup of CDB manager: cache and active storages!
1313 AliCDBManager::Instance()->ClearCache();
1314
596a855f 1315 return kTRUE;
1316}
1317
1318
1319//_____________________________________________________________________________
c4aa7a4c 1320Bool_t AliReconstruction::RunLocalReconstruction(const TString& /*detectors*/)
596a855f 1321{
59697224 1322// run the local reconstruction
0f88822a 1323 static Int_t eventNr=0;
87932dab 1324 AliCodeTimerAuto("")
030b532d 1325
d76c31f4 1326 // AliCDBManager* man = AliCDBManager::Instance();
1327// Bool_t origCache = man->GetCacheFlag();
8e245d15 1328
d76c31f4 1329// TString detStr = detectors;
1330// for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1331// if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1332// AliReconstructor* reconstructor = GetReconstructor(iDet);
1333// if (!reconstructor) continue;
1334// if (reconstructor->HasLocalReconstruction()) continue;
b8cd5251 1335
d76c31f4 1336// AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1337// AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
87932dab 1338
d76c31f4 1339// AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1340// AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
8e245d15 1341
d76c31f4 1342// man->SetCacheFlag(kTRUE);
1343// TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
1344// man->GetAll(calibPath); // entries are cached!
8e245d15 1345
d76c31f4 1346// AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
87932dab 1347
d76c31f4 1348// if (fRawReader) {
1349// fRawReader->RewindEvents();
1350// reconstructor->Reconstruct(fRunLoader, fRawReader);
1351// } else {
1352// reconstructor->Reconstruct(fRunLoader);
1353// }
87932dab 1354
d76c31f4 1355// AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
0f88822a 1356 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
8e245d15 1357
d76c31f4 1358// // unload calibration data
1359// man->UnloadFromCache(calibPath);
1360// //man->ClearCache();
1361// }
596a855f 1362
d76c31f4 1363// man->SetCacheFlag(origCache);
8e245d15 1364
d76c31f4 1365// if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1366// AliError(Form("the following detectors were not found: %s",
1367// detStr.Data()));
1368// if (fStopOnError) return kFALSE;
1369// }
596a855f 1370
0f88822a 1371 eventNr++;
596a855f 1372 return kTRUE;
1373}
1374
b26c3770 1375//_____________________________________________________________________________
1376Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1377{
1378// run the local reconstruction
aa3c69a9 1379
0f88822a 1380 static Int_t eventNr=0;
87932dab 1381 AliCodeTimerAuto("")
b26c3770 1382
1383 TString detStr = detectors;
1384 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1385 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1386 AliReconstructor* reconstructor = GetReconstructor(iDet);
1387 if (!reconstructor) continue;
1388 AliLoader* loader = fLoader[iDet];
f6806ad3 1389 // Matthias April 2008: temporary fix to run HLT reconstruction
1390 // although the HLT loader is missing
1391 if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
1392 if (fRawReader) {
1393 reconstructor->Reconstruct(fRawReader, NULL);
1394 } else {
1395 TTree* dummy=NULL;
1396 reconstructor->Reconstruct(dummy, NULL);
1397 }
1398 continue;
1399 }
d76c31f4 1400 if (!loader) {
1401 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1402 continue;
1403 }
b26c3770 1404 // conversion of digits
1405 if (fRawReader && reconstructor->HasDigitConversion()) {
1406 AliInfo(Form("converting raw data digits into root objects for %s",
1407 fgkDetectorName[iDet]));
87932dab 1408 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1409 fgkDetectorName[iDet]));
b26c3770 1410 loader->LoadDigits("update");
1411 loader->CleanDigits();
1412 loader->MakeDigitsContainer();
1413 TTree* digitsTree = loader->TreeD();
1414 reconstructor->ConvertDigits(fRawReader, digitsTree);
1415 loader->WriteDigits("OVERWRITE");
1416 loader->UnloadDigits();
b26c3770 1417 }
b26c3770 1418 // local reconstruction
b26c3770 1419 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
87932dab 1420 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
b26c3770 1421 loader->LoadRecPoints("update");
1422 loader->CleanRecPoints();
1423 loader->MakeRecPointsContainer();
1424 TTree* clustersTree = loader->TreeR();
1425 if (fRawReader && !reconstructor->HasDigitConversion()) {
1426 reconstructor->Reconstruct(fRawReader, clustersTree);
1427 } else {
1428 loader->LoadDigits("read");
1429 TTree* digitsTree = loader->TreeD();
1430 if (!digitsTree) {
1431 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1432 if (fStopOnError) return kFALSE;
1433 } else {
1434 reconstructor->Reconstruct(digitsTree, clustersTree);
1435 }
1436 loader->UnloadDigits();
1437 }
d76c31f4 1438
aa3c69a9 1439 // In-loop QA for local reconstrucion
1440 if (fRunQA && fInLoopQA) {
04236e67 1441 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
aa3c69a9 1442 if (qadm) {
1443 //AliCodeTimerStart
1444 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1445 //AliInfo
1446 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1447
1448 qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
1449
1450 //AliCodeTimerStop
1451 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1452 }
1453 }
d76c31f4 1454
aa3c69a9 1455 loader->WriteRecPoints("OVERWRITE");
b26c3770 1456 loader->UnloadRecPoints();
6efecea1 1457 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
b26c3770 1458 }
1459
1460 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1461 AliError(Form("the following detectors were not found: %s",
1462 detStr.Data()));
1463 if (fStopOnError) return kFALSE;
1464 }
0f88822a 1465 eventNr++;
b26c3770 1466 return kTRUE;
1467}
1468
596a855f 1469//_____________________________________________________________________________
af885e0f 1470Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 1471{
1472// run the barrel tracking
1473
87932dab 1474 AliCodeTimerAuto("")
030b532d 1475
2257f27e 1476 AliESDVertex* vertex = NULL;
1477 Double_t vtxPos[3] = {0, 0, 0};
1478 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1479 TArrayF mcVertex(3);
a6b0b91b 1480 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1481 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1482 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1483 }
2257f27e 1484
b8cd5251 1485 if (fVertexer) {
17c86e90 1486 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
815c2b38 1487 AliInfo("running the ITS vertex finder");
b26c3770 1488 if (fLoader[0]) fLoader[0]->LoadRecPoints();
b8cd5251 1489 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
b26c3770 1490 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
2257f27e 1491 if(!vertex){
815c2b38 1492 AliWarning("Vertex not found");
c710f220 1493 vertex = new AliESDVertex();
d1a50cb5 1494 vertex->SetName("default");
2257f27e 1495 }
1496 else {
d1a50cb5 1497 vertex->SetName("reconstructed");
2257f27e 1498 }
1499
1500 } else {
815c2b38 1501 AliInfo("getting the primary vertex from MC");
2257f27e 1502 vertex = new AliESDVertex(vtxPos, vtxErr);
1503 }
1504
1505 if (vertex) {
1506 vertex->GetXYZ(vtxPos);
1507 vertex->GetSigmaXYZ(vtxErr);
1508 } else {
815c2b38 1509 AliWarning("no vertex reconstructed");
2257f27e 1510 vertex = new AliESDVertex(vtxPos, vtxErr);
1511 }
06cc9d95 1512 esd->SetPrimaryVertexSPD(vertex);
32e449be 1513 // if SPD multiplicity has been determined, it is stored in the ESD
25be1e5c 1514 AliMultiplicity *mult = fVertexer->GetMultiplicity();
32e449be 1515 if(mult)esd->SetMultiplicity(mult);
1516
b8cd5251 1517 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1518 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1519 }
2257f27e 1520 delete vertex;
1521
2257f27e 1522 return kTRUE;
1523}
1524
1f46a9ae 1525//_____________________________________________________________________________
af885e0f 1526Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 1527{
1528// run the HLT barrel tracking
1529
87932dab 1530 AliCodeTimerAuto("")
1f46a9ae 1531
1532 if (!fRunLoader) {
1533 AliError("Missing runLoader!");
1534 return kFALSE;
1535 }
1536
1537 AliInfo("running HLT tracking");
1538
1539 // Get a pointer to the HLT reconstructor
1540 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1541 if (!reconstructor) return kFALSE;
1542
1543 // TPC + ITS
1544 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1545 TString detName = fgkDetectorName[iDet];
1546 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1547 reconstructor->SetOption(detName.Data());
d76c31f4 1548 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 1549 if (!tracker) {
1550 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1551 if (fStopOnError) return kFALSE;
9dcc06e1 1552 continue;
1f46a9ae 1553 }
1554 Double_t vtxPos[3];
1555 Double_t vtxErr[3]={0.005,0.005,0.010};
1556 const AliESDVertex *vertex = esd->GetVertex();
1557 vertex->GetXYZ(vtxPos);
1558 tracker->SetVertex(vtxPos,vtxErr);
1559 if(iDet != 1) {
1560 fLoader[iDet]->LoadRecPoints("read");
1561 TTree* tree = fLoader[iDet]->TreeR();
1562 if (!tree) {
1563 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1564 return kFALSE;
1565 }
1566 tracker->LoadClusters(tree);
1567 }
1568 if (tracker->Clusters2Tracks(esd) != 0) {
1569 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1570 return kFALSE;
1571 }
1572 if(iDet != 1) {
1573 tracker->UnloadClusters();
1574 }
1575 delete tracker;
1576 }
1577
1f46a9ae 1578 return kTRUE;
1579}
1580
e66fbafb 1581//_____________________________________________________________________________
af885e0f 1582Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 1583{
1584// run the muon spectrometer tracking
1585
87932dab 1586 AliCodeTimerAuto("")
e66fbafb 1587
1588 if (!fRunLoader) {
1589 AliError("Missing runLoader!");
1590 return kFALSE;
1591 }
1592 Int_t iDet = 7; // for MUON
1593
1594 AliInfo("is running...");
1595
1596 // Get a pointer to the MUON reconstructor
1597 AliReconstructor *reconstructor = GetReconstructor(iDet);
1598 if (!reconstructor) return kFALSE;
1599
1600
1601 TString detName = fgkDetectorName[iDet];
1602 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 1603 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 1604 if (!tracker) {
1605 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1606 return kFALSE;
1607 }
1608
e66fbafb 1609 // read RecPoints
761350a6 1610 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 1611
761350a6 1612 tracker->LoadClusters(fLoader[iDet]->TreeR());
1613
1614 Int_t rv = tracker->Clusters2Tracks(esd);
1615
761350a6 1616 if ( rv )
1617 {
e66fbafb 1618 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1619 return kFALSE;
1620 }
761350a6 1621
e66fbafb 1622 fLoader[iDet]->UnloadRecPoints();
1623
c1954ee5 1624 tracker->UnloadClusters();
1625
e66fbafb 1626 delete tracker;
1627
e66fbafb 1628 return kTRUE;
1629}
1630
1631
2257f27e 1632//_____________________________________________________________________________
af885e0f 1633Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
2257f27e 1634{
1635// run the barrel tracking
0f88822a 1636 static Int_t eventNr=0;
87932dab 1637 AliCodeTimerAuto("")
24f7a148 1638
815c2b38 1639 AliInfo("running tracking");
596a855f 1640
91b876d1 1641 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 1642 if (fReconstructor[11] && fLoader[11]) {
1643 fLoader[11]->LoadRecPoints("READ");
1644 TTree *treeR = fLoader[11]->TreeR();
1645 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1646 }
91b876d1 1647
b8cd5251 1648 // pass 1: TPC + ITS inwards
1649 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1650 if (!fTracker[iDet]) continue;
1651 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 1652
b8cd5251 1653 // load clusters
1654 fLoader[iDet]->LoadRecPoints("read");
6efecea1 1655 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 1656 TTree* tree = fLoader[iDet]->TreeR();
1657 if (!tree) {
1658 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 1659 return kFALSE;
1660 }
b8cd5251 1661 fTracker[iDet]->LoadClusters(tree);
6efecea1 1662 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 1663 // run tracking
1664 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1665 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 1666 return kFALSE;
1667 }
b8cd5251 1668 if (fCheckPointLevel > 1) {
1669 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1670 }
878e1fe1 1671 // preliminary PID in TPC needed by the ITS tracker
1672 if (iDet == 1) {
b26c3770 1673 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
878e1fe1 1674 AliESDpid::MakePID(esd);
0f88822a 1675 }
6efecea1 1676 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 1677 }
596a855f 1678
b8cd5251 1679 // pass 2: ALL backwards
aa3c69a9 1680
b8cd5251 1681 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1682 if (!fTracker[iDet]) continue;
1683 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1684
1685 // load clusters
1686 if (iDet > 1) { // all except ITS, TPC
1687 TTree* tree = NULL;
7b61cd9c 1688 fLoader[iDet]->LoadRecPoints("read");
6efecea1 1689 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 1690 tree = fLoader[iDet]->TreeR();
b8cd5251 1691 if (!tree) {
1692 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 1693 return kFALSE;
1694 }
0f88822a 1695 fTracker[iDet]->LoadClusters(tree);
6efecea1 1696 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 1697 }
24f7a148 1698
b8cd5251 1699 // run tracking
283f39c6 1700 if (iDet>1) // start filling residuals for the "outer" detectors
1701 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1702
b8cd5251 1703 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1704 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 1705 // return kFALSE;
b8cd5251 1706 }
1707 if (fCheckPointLevel > 1) {
1708 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1709 }
24f7a148 1710
b8cd5251 1711 // unload clusters
1712 if (iDet > 2) { // all except ITS, TPC, TRD
1713 fTracker[iDet]->UnloadClusters();
7b61cd9c 1714 fLoader[iDet]->UnloadRecPoints();
b8cd5251 1715 }
8f37df88 1716 // updated PID in TPC needed by the ITS tracker -MI
1717 if (iDet == 1) {
8f37df88 1718 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1719 AliESDpid::MakePID(esd);
1720 }
6efecea1 1721 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 1722 }
283f39c6 1723 //stop filling residuals for the "outer" detectors
1724 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
596a855f 1725
98937d93 1726 // write space-points to the ESD in case alignment data output
1727 // is switched on
1728 if (fWriteAlignmentData)
1729 WriteAlignmentData(esd);
1730
b8cd5251 1731 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 1732
b8cd5251 1733 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1734 if (!fTracker[iDet]) continue;
1735 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 1736
b8cd5251 1737 // run tracking
283f39c6 1738 if (iDet<2) // start filling residuals for TPC and ITS
1739 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1740
b8cd5251 1741 if (fTracker[iDet]->RefitInward(esd) != 0) {
1742 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 1743 // return kFALSE;
b8cd5251 1744 }
db2368d0 1745 // run postprocessing
1746 if (fTracker[iDet]->PostProcess(esd) != 0) {
1747 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
1748 // return kFALSE;
1749 }
b8cd5251 1750 if (fCheckPointLevel > 1) {
1751 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1752 }
6efecea1 1753 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 1754 // unload clusters
1755 fTracker[iDet]->UnloadClusters();
6efecea1 1756 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 1757 fLoader[iDet]->UnloadRecPoints();
6efecea1 1758 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 1759 }
283f39c6 1760 // stop filling residuals for TPC and ITS
3b378a42 1761 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
854c6476 1762
0f88822a 1763 eventNr++;
596a855f 1764 return kTRUE;
1765}
1766
d64bd07d 1767//_____________________________________________________________________________
1768Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1769 //
1770 // Remove the data which are not needed for the physics analysis.
1771 //
1772
d64bd07d 1773 Int_t nTracks=esd->GetNumberOfTracks();
18571674 1774 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 1775 AliInfo
1776 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 1777
18571674 1778 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 1779 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 1780
7f68891d 1781 nTracks=esd->GetNumberOfTracks();
18571674 1782 nV0s=esd->GetNumberOfV0s();
cf37fd88 1783 AliInfo
ae5d5566 1784 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 1785
7f68891d 1786 return rc;
d64bd07d 1787}
1788
596a855f 1789//_____________________________________________________________________________
af885e0f 1790Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 1791{
1792// fill the event summary data
1793
87932dab 1794 AliCodeTimerAuto("")
0f88822a 1795 static Int_t eventNr=0;
596a855f 1796 TString detStr = detectors;
abe0c04e 1797
b8cd5251 1798 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
abe0c04e 1799 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 1800 AliReconstructor* reconstructor = GetReconstructor(iDet);
1801 if (!reconstructor) continue;
b8cd5251 1802 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1803 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
b26c3770 1804 TTree* clustersTree = NULL;
d76c31f4 1805 if (fLoader[iDet]) {
b26c3770 1806 fLoader[iDet]->LoadRecPoints("read");
1807 clustersTree = fLoader[iDet]->TreeR();
1808 if (!clustersTree) {
1809 AliError(Form("Can't get the %s clusters tree",
1810 fgkDetectorName[iDet]));
1811 if (fStopOnError) return kFALSE;
1812 }
1813 }
1814 if (fRawReader && !reconstructor->HasDigitConversion()) {
1815 reconstructor->FillESD(fRawReader, clustersTree, esd);
1816 } else {
1817 TTree* digitsTree = NULL;
1818 if (fLoader[iDet]) {
1819 fLoader[iDet]->LoadDigits("read");
1820 digitsTree = fLoader[iDet]->TreeD();
1821 if (!digitsTree) {
1822 AliError(Form("Can't get the %s digits tree",
1823 fgkDetectorName[iDet]));
1824 if (fStopOnError) return kFALSE;
1825 }
1826 }
1827 reconstructor->FillESD(digitsTree, clustersTree, esd);
1828 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1829 }
d76c31f4 1830 if (fLoader[iDet]) {
b26c3770 1831 fLoader[iDet]->UnloadRecPoints();
1832 }
1833
b8cd5251 1834 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
596a855f 1835 }
1836 }
1837
1838 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 1839 AliError(Form("the following detectors were not found: %s",
1840 detStr.Data()));
596a855f 1841 if (fStopOnError) return kFALSE;
1842 }
6efecea1 1843 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
0f88822a 1844 eventNr++;
596a855f 1845 return kTRUE;
1846}
1847
b647652d 1848//_____________________________________________________________________________
af885e0f 1849Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 1850{
1851 // Reads the trigger decision which is
1852 // stored in Trigger.root file and fills
1853 // the corresponding esd entries
1854
87932dab 1855 AliCodeTimerAuto("")
1856
b647652d 1857 AliInfo("Filling trigger information into the ESD");
1858
b024fd7f 1859 AliCentralTrigger *aCTP = NULL;
1860
b647652d 1861 if (fRawReader) {
1862 AliCTPRawStream input(fRawReader);
1863 if (!input.Next()) {
1864 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1865 return kFALSE;
1866 }
1867 esd->SetTriggerMask(input.GetClassMask());
1868 esd->SetTriggerCluster(input.GetClusterMask());
b024fd7f 1869
1870 aCTP = new AliCentralTrigger();
1871 TString configstr("");
1872 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
1873 AliError("No trigger configuration found in OCDB! The trigger classes information will no be stored in ESD!");
259e35c9 1874 delete aCTP;
b024fd7f 1875 return kFALSE;
1876 }
b647652d 1877 }
1878 else {
1879 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1880 if (runloader) {
1881 if (!runloader->LoadTrigger()) {
1ea86aa2 1882 aCTP = runloader->GetTrigger();
b647652d 1883 esd->SetTriggerMask(aCTP->GetClassMask());
1884 esd->SetTriggerCluster(aCTP->GetClusterMask());
1885 }
1886 else {
1887 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1888 return kFALSE;
1889 }
1890 }
1891 else {
1892 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1893 return kFALSE;
1894 }
1895 }
1896
b024fd7f 1897 // Now fill the trigger class names into AliESDRun object
1898 AliTriggerConfiguration *config = aCTP->GetConfiguration();
1899 if (!config) {
1900 AliError("No trigger configuration has been found! The trigger classes information will no be stored in ESD!");
d74294be 1901 if (fRawReader) delete aCTP;
b024fd7f 1902 return kFALSE;
1903 }
1904
1905 const TObjArray& classesArray = config->GetClasses();
1906 Int_t nclasses = classesArray.GetEntriesFast();
1907 for( Int_t j=0; j<nclasses; j++ ) {
1908 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
1909 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
1910 esd->SetTriggerClass(trclass->GetName(),trindex);
1911 }
1912
d74294be 1913 if (fRawReader) delete aCTP;
b647652d 1914 return kTRUE;
1915}
596a855f 1916
001397cd 1917
1918
1919
1920
1921//_____________________________________________________________________________
af885e0f 1922Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 1923{
1924 //
1925 // Filling information from RawReader Header
1926 //
1927
1928 AliInfo("Filling information from RawReader Header");
31fd97b2 1929 esd->SetBunchCrossNumber(0);
1930 esd->SetOrbitNumber(0);
9bcc1e45 1931 esd->SetPeriodNumber(0);
001397cd 1932 esd->SetTimeStamp(0);
1933 esd->SetEventType(0);
1934 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1935 if (eventHeader){
9bcc1e45 1936
1937 const UInt_t *id = eventHeader->GetP("Id");
1938 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1939 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1940 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1941
001397cd 1942 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
31fd97b2 1943 esd->SetEventType((eventHeader->Get("Type")));
001397cd 1944 }
1945
1946 return kTRUE;
1947}
1948
1949
596a855f 1950//_____________________________________________________________________________
1951Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1952{
1953// check whether detName is contained in detectors
1954// if yes, it is removed from detectors
1955
1956 // check if all detectors are selected
1957 if ((detectors.CompareTo("ALL") == 0) ||
1958 detectors.BeginsWith("ALL ") ||
1959 detectors.EndsWith(" ALL") ||
1960 detectors.Contains(" ALL ")) {
1961 detectors = "ALL";
1962 return kTRUE;
1963 }
1964
1965 // search for the given detector
1966 Bool_t result = kFALSE;
1967 if ((detectors.CompareTo(detName) == 0) ||
1968 detectors.BeginsWith(detName+" ") ||
1969 detectors.EndsWith(" "+detName) ||
1970 detectors.Contains(" "+detName+" ")) {
1971 detectors.ReplaceAll(detName, "");
1972 result = kTRUE;
1973 }
1974
1975 // clean up the detectors string
1976 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1977 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1978 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1979
1980 return result;
1981}
e583c30d 1982
f08fc9f5 1983//_____________________________________________________________________________
1984Bool_t AliReconstruction::InitRunLoader()
1985{
1986// get or create the run loader
1987
1988 if (gAlice) delete gAlice;
1989 gAlice = NULL;
1990
b26c3770 1991 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1992 // load all base libraries to get the loader classes
1993 TString libs = gSystem->GetLibraries();
1994 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1995 TString detName = fgkDetectorName[iDet];
1996 if (detName == "HLT") continue;
1997 if (libs.Contains("lib" + detName + "base.so")) continue;
1998 gSystem->Load("lib" + detName + "base.so");
1999 }
f08fc9f5 2000 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2001 if (!fRunLoader) {
2002 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2003 CleanUp();
2004 return kFALSE;
2005 }
b26c3770 2006 fRunLoader->CdGAFile();
2007 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
2008 if (fRunLoader->LoadgAlice() == 0) {
2009 gAlice = fRunLoader->GetAliRun();
c84a5e9e 2010 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
b26c3770 2011 }
f08fc9f5 2012 }
2013 if (!gAlice && !fRawReader) {
2014 AliError(Form("no gAlice object found in file %s",
2015 fGAliceFileName.Data()));
2016 CleanUp();
2017 return kFALSE;
2018 }
2019
6cae184e 2020 //PH This is a temporary fix to give access to the kinematics
2021 //PH that is needed for the labels of ITS clusters
f2ee4290 2022 fRunLoader->LoadHeader();
6cae184e 2023 fRunLoader->LoadKinematics();
2024
f08fc9f5 2025 } else { // galice.root does not exist
2026 if (!fRawReader) {
2027 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
2028 CleanUp();
2029 return kFALSE;
2030 }
2031 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2032 AliConfig::GetDefaultEventFolderName(),
2033 "recreate");
2034 if (!fRunLoader) {
2035 AliError(Form("could not create run loader in file %s",
2036 fGAliceFileName.Data()));
2037 CleanUp();
2038 return kFALSE;
2039 }
21a3aa09 2040 fIsNewRunLoader = kTRUE;
f08fc9f5 2041 fRunLoader->MakeTree("E");
21a3aa09 2042
973388c2 2043 if (fNumberOfEventsPerFile > 0)
2044 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2045 else
21a3aa09 2046 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 2047 }
2048
2049 return kTRUE;
2050}
2051
c757bafd 2052//_____________________________________________________________________________
b8cd5251 2053AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 2054{
f08fc9f5 2055// get the reconstructor object and the loader for a detector
c757bafd 2056
b8cd5251 2057 if (fReconstructor[iDet]) return fReconstructor[iDet];
2058
2059 // load the reconstructor object
2060 TPluginManager* pluginManager = gROOT->GetPluginManager();
2061 TString detName = fgkDetectorName[iDet];
2062 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 2063
2064 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 2065
b8cd5251 2066 AliReconstructor* reconstructor = NULL;
2067 // first check if a plugin is defined for the reconstructor
2068 TPluginHandler* pluginHandler =
2069 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 2070 // if not, add a plugin for it
2071 if (!pluginHandler) {
b8cd5251 2072 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 2073 TString libs = gSystem->GetLibraries();
2074 if (libs.Contains("lib" + detName + "base.so") ||
2075 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 2076 pluginManager->AddHandler("AliReconstructor", detName,
2077 recName, detName + "rec", recName + "()");
2078 } else {
2079 pluginManager->AddHandler("AliReconstructor", detName,
2080 recName, detName, recName + "()");
c757bafd 2081 }
b8cd5251 2082 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2083 }
2084 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2085 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 2086 }
b8cd5251 2087 if (reconstructor) {
2088 TObject* obj = fOptions.FindObject(detName.Data());
2089 if (obj) reconstructor->SetOption(obj->GetTitle());
d76c31f4 2090 reconstructor->Init();
b8cd5251 2091 fReconstructor[iDet] = reconstructor;
2092 }
2093
f08fc9f5 2094 // get or create the loader
2095 if (detName != "HLT") {
2096 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2097 if (!fLoader[iDet]) {
2098 AliConfig::Instance()
2099 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2100 detName, detName);
2101 // first check if a plugin is defined for the loader
bb0901a4 2102 pluginHandler =
f08fc9f5 2103 pluginManager->FindHandler("AliLoader", detName);
2104 // if not, add a plugin for it
2105 if (!pluginHandler) {
2106 TString loaderName = "Ali" + detName + "Loader";
2107 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2108 pluginManager->AddHandler("AliLoader", detName,
2109 loaderName, detName + "base",
2110 loaderName + "(const char*, TFolder*)");
2111 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2112 }
2113 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2114 fLoader[iDet] =
2115 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2116 fRunLoader->GetEventFolder());
2117 }
2118 if (!fLoader[iDet]) { // use default loader
2119 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2120 }
2121 if (!fLoader[iDet]) {
2122 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 2123 if (fStopOnError) return NULL;
f08fc9f5 2124 } else {
2125 fRunLoader->AddLoader(fLoader[iDet]);
2126 fRunLoader->CdGAFile();
2127 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2128 fRunLoader->Write(0, TObject::kOverwrite);
2129 }
2130 }
2131 }
2132
b8cd5251 2133 return reconstructor;
c757bafd 2134}
2135
2257f27e 2136//_____________________________________________________________________________
2137Bool_t AliReconstruction::CreateVertexer()
2138{
2139// create the vertexer
2140
b8cd5251 2141 fVertexer = NULL;
2142 AliReconstructor* itsReconstructor = GetReconstructor(0);
59697224 2143 if (itsReconstructor) {
d76c31f4 2144 fVertexer = itsReconstructor->CreateVertexer();
2257f27e 2145 }
b8cd5251 2146 if (!fVertexer) {
815c2b38 2147 AliWarning("couldn't create a vertexer for ITS");
2257f27e 2148 if (fStopOnError) return kFALSE;
2149 }
2150
2151 return kTRUE;
2152}
2153
24f7a148 2154//_____________________________________________________________________________
b8cd5251 2155Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 2156{
f08fc9f5 2157// create the trackers
24f7a148 2158
b8cd5251 2159 TString detStr = detectors;
2160 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2161 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2162 AliReconstructor* reconstructor = GetReconstructor(iDet);
2163 if (!reconstructor) continue;
2164 TString detName = fgkDetectorName[iDet];
1f46a9ae 2165 if (detName == "HLT") {
2166 fRunHLTTracking = kTRUE;
2167 continue;
2168 }
e66fbafb 2169 if (detName == "MUON") {
2170 fRunMuonTracking = kTRUE;
2171 continue;
2172 }
2173
f08fc9f5 2174
d76c31f4 2175 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 2176 if (!fTracker[iDet] && (iDet < 7)) {
2177 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 2178 if (fStopOnError) return kFALSE;
2179 }
6efecea1 2180 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 2181 }
2182
24f7a148 2183 return kTRUE;
2184}
2185
e583c30d 2186//_____________________________________________________________________________
b26c3770 2187void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
e583c30d 2188{
2189// delete trackers and the run loader and close and delete the file
2190
b8cd5251 2191 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2192 delete fReconstructor[iDet];
2193 fReconstructor[iDet] = NULL;
2194 fLoader[iDet] = NULL;
2195 delete fTracker[iDet];
2196 fTracker[iDet] = NULL;
c65c502a 2197// delete fQADataMaker[iDet];
2198// fQADataMaker[iDet] = NULL;
b8cd5251 2199 }
2200 delete fVertexer;
2201 fVertexer = NULL;
21a3aa09 2202
2203 if (ftVertexer) delete ftVertexer;
2204 ftVertexer = NULL;
795e4a22 2205
2206 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
2207 delete fDiamondProfile;
2208 fDiamondProfile = NULL;
43c9dae1 2209 delete fDiamondProfileTPC;
2210 fDiamondProfileTPC = NULL;
6b6e4472 2211 delete fGRPData;
2212 fGRPData = NULL;
795e4a22 2213 }
e583c30d 2214
444753c6 2215
e583c30d 2216 delete fRunLoader;
2217 fRunLoader = NULL;
b649205a 2218 delete fRawReader;
2219 fRawReader = NULL;
cd0b062e 2220 if (fParentRawReader) delete fParentRawReader;
2221 fParentRawReader=NULL;
e583c30d 2222
2223 if (file) {
2224 file->Close();
2225 delete file;
2226 }
b26c3770 2227
2228 if (fileOld) {
2229 fileOld->Close();
2230 delete fileOld;
2231 gSystem->Unlink("AliESDs.old.root");
2232 }
21a3aa09 2233
e583c30d 2234}
24f7a148 2235
24f7a148 2236//_____________________________________________________________________________
af885e0f 2237
2238Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
24f7a148 2239{
2240// read the ESD event from a file
2241
2242 if (!esd) return kFALSE;
2243 char fileName[256];
2244 sprintf(fileName, "ESD_%d.%d_%s.root",
31fd97b2 2245 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
24f7a148 2246 if (gSystem->AccessPathName(fileName)) return kFALSE;
2247
f3a97c86 2248 AliInfo(Form("reading ESD from file %s", fileName));
815c2b38 2249 AliDebug(1, Form("reading ESD from file %s", fileName));
24f7a148 2250 TFile* file = TFile::Open(fileName);
2251 if (!file || !file->IsOpen()) {
815c2b38 2252 AliError(Form("opening %s failed", fileName));
24f7a148 2253 delete file;
2254 return kFALSE;
2255 }
2256
2257 gROOT->cd();
2258 delete esd;
af885e0f 2259 esd = (AliESDEvent*) file->Get("ESD");
24f7a148 2260 file->Close();
2261 delete file;
2262 return kTRUE;
af885e0f 2263
24f7a148 2264}
2265
af885e0f 2266
2267
24f7a148 2268//_____________________________________________________________________________
af885e0f 2269void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
24f7a148 2270{
2271// write the ESD event to a file
2272
2273 if (!esd) return;
2274 char fileName[256];
2275 sprintf(fileName, "ESD_%d.%d_%s.root",
31fd97b2 2276 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
24f7a148 2277
815c2b38 2278 AliDebug(1, Form("writing ESD to file %s", fileName));
24f7a148 2279 TFile* file = TFile::Open(fileName, "recreate");
2280 if (!file || !file->IsOpen()) {
815c2b38 2281 AliError(Form("opening %s failed", fileName));
24f7a148 2282 } else {
2283 esd->Write("ESD");
2284 file->Close();
2285 }
2286 delete file;
2287}
f3a97c86 2288
2289
af885e0f 2290void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 2291{
2292 // Write space-points which are then used in the alignment procedures
2293 // For the moment only ITS, TRD and TPC
2294
2295 // Load TOF clusters
d528ee75 2296 if (fTracker[3]){
2297 fLoader[3]->LoadRecPoints("read");
2298 TTree* tree = fLoader[3]->TreeR();
2299 if (!tree) {
2300 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2301 return;
2302 }
2303 fTracker[3]->LoadClusters(tree);
98937d93 2304 }
98937d93 2305 Int_t ntracks = esd->GetNumberOfTracks();
2306 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2307 {
2308 AliESDtrack *track = esd->GetTrack(itrack);
2309 Int_t nsp = 0;
ef7253ac 2310 Int_t idx[200];
98937d93 2311 for (Int_t iDet = 3; iDet >= 0; iDet--)
2312 nsp += track->GetNcls(iDet);
2313 if (nsp) {
2314 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2315 track->SetTrackPointArray(sp);
2316 Int_t isptrack = 0;
2317 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2318 AliTracker *tracker = fTracker[iDet];
2319 if (!tracker) continue;
2320 Int_t nspdet = track->GetNcls(iDet);
98937d93 2321 if (nspdet <= 0) continue;
2322 track->GetClusters(iDet,idx);
2323 AliTrackPoint p;
2324 Int_t isp = 0;
2325 Int_t isp2 = 0;
4ed6fb1c 2326 while (isp2 < nspdet) {
48ce48d1 2327 Bool_t isvalid;
c12b6e44 2328 TString dets = fgkDetectorName[iDet];
2329 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2330 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2331 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2332 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
2333 isvalid = tracker->GetTrackPointTrackingError(idx[isp2],p,track);
48ce48d1 2334 } else {
2335 isvalid = tracker->GetTrackPoint(idx[isp2],p);
2336 }
2337 isp2++;
160db090 2338 const Int_t kNTPCmax = 159;
2339 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
98937d93 2340 if (!isvalid) continue;
2341 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2342 }
98937d93 2343 }
2344 }
2345 }
d528ee75 2346 if (fTracker[3]){
2347 fTracker[3]->UnloadClusters();
2348 fLoader[3]->UnloadRecPoints();
2349 }
98937d93 2350}
2e3550da 2351
2352//_____________________________________________________________________________
af885e0f 2353void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 2354{
2355 // The method reads the raw-data error log
2356 // accumulated within the rawReader.
2357 // It extracts the raw-data errors related to
2358 // the current event and stores them into
2359 // a TClonesArray inside the esd object.
2360
2361 if (!fRawReader) return;
2362
2363 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2364
2365 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2366 if (!log) continue;
2367 if (iEvent != log->GetEventNumber()) continue;
2368
2369 esd->AddRawDataErrorLog(log);
2370 }
2371
2372}
46698ae4 2373
605cb8bb 2374TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString pName){
b545009a 2375 // Dump a file content into a char in TNamed
46698ae4 2376 ifstream in;
2377 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2378 Int_t kBytes = (Int_t)in.tellg();
2379 printf("Size: %d \n",kBytes);
2380 TNamed *fn = 0;
2381 if(in.good()){
2382 char* memblock = new char [kBytes];
2383 in.seekg (0, ios::beg);
2384 in.read (memblock, kBytes);
2385 in.close();
2386 TString fData(memblock,kBytes);
605cb8bb 2387 fn = new TNamed(pName,fData);
46698ae4 2388 printf("fData Size: %d \n",fData.Sizeof());
605cb8bb 2389 printf("pName Size: %d \n",pName.Sizeof());
46698ae4 2390 printf("fn Size: %d \n",fn->Sizeof());
2391 delete[] memblock;
2392 }
2393 else{
2394 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2395 }
2396
2397 return fn;
2398}
2399
605cb8bb 2400void AliReconstruction::TNamedToFile(TTree* fTree, TString pName){
46698ae4 2401 // This is not really needed in AliReconstruction at the moment
2402 // but can serve as a template
2403
2404 TList *fList = fTree->GetUserInfo();
605cb8bb 2405 TNamed *fn = (TNamed*)fList->FindObject(pName.Data());
46698ae4 2406 printf("fn Size: %d \n",fn->Sizeof());
2407
605cb8bb 2408 TString fTmp(fn->GetName()); // to be 100% sure in principle pName also works
46698ae4 2409 const char* cdata = fn->GetTitle();
2410 printf("fTmp Size %d\n",fTmp.Sizeof());
2411
2412 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2413 printf("calculated size %d\n",size);
605cb8bb 2414 ofstream out(pName.Data(),ios::out | ios::binary);
46698ae4 2415 out.write(cdata,size);
2416 out.close();
2417
2418}
6efecea1 2419
7e963665 2420//_____________________________________________________________________________
04236e67 2421AliQADataMakerRec * AliReconstruction::GetQADataMaker(Int_t iDet)
7e963665 2422{
2423 // get the quality assurance data maker object and the loader for a detector
6efecea1 2424
7e963665 2425 if (fQADataMaker[iDet])
2426 return fQADataMaker[iDet];
2427
04236e67 2428 AliQADataMakerRec * qadm = NULL;
2429 if (iDet == fgkNDetectors) { //Global QA
2430 qadm = new AliGlobalQADataMaker();
aa3c69a9 2431 fQADataMaker[iDet] = qadm;
2432 return qadm;
2433 }
2434
7e963665 2435 // load the QA data maker object
2436 TPluginManager* pluginManager = gROOT->GetPluginManager();
2437 TString detName = fgkDetectorName[iDet];
04236e67 2438 TString qadmName = "Ali" + detName + "QADataMakerRec";
f0999a9a 2439 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT"))
7e963665 2440 return NULL;
2441
7e963665 2442 // first check if a plugin is defined for the quality assurance data maker
04236e67 2443 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
7e963665 2444 // if not, add a plugin for it
2445 if (!pluginHandler) {
2446 AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
2447 TString libs = gSystem->GetLibraries();
2448 if (libs.Contains("lib" + detName + "base.so") ||
2449 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
04236e67 2450 pluginManager->AddHandler("AliQADataMakerRec", detName,
7e963665 2451 qadmName, detName + "qadm", qadmName + "()");
2452 } else {
04236e67 2453 pluginManager->AddHandler("AliQADataMakerRec", detName,
7e963665 2454 qadmName, detName, qadmName + "()");
2455 }
04236e67 2456 pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
7e963665 2457 }
2458 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
04236e67 2459 qadm = (AliQADataMakerRec *) pluginHandler->ExecPlugin(0);
7e963665 2460 }
aa3c69a9 2461
2462 fQADataMaker[iDet] = qadm;
7e963665 2463
2464 return qadm;
2465}
46698ae4 2466
a5fa6165 2467//_____________________________________________________________________________
7e963665 2468Bool_t AliReconstruction::RunQA(const char* detectors, AliESDEvent *& esd)
2469{
2470 // run the Quality Assurance data producer
2471
2472 AliCodeTimerAuto("")
2473 TString detStr = detectors;
2474 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2475 if (!IsSelected(fgkDetectorName[iDet], detStr))
2476 continue;
04236e67 2477 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
7e963665 2478 if (!qadm)
2479 continue;
2480 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2481 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2482
2483 qadm->Exec(AliQA::kESDS, esd) ;
2484 qadm->Increment() ;
2485
2486 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2487 }
2488 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2489 AliError(Form("the following detectors were not found: %s",
2490 detStr.Data()));
2491 if (fStopOnError)
2492 return kFALSE;
2493 }
2494
2495 return kTRUE;
2496
2497}
8661738e 2498
2499//_____________________________________________________________________________
2500void AliReconstruction::CheckQA()
2501{
2502// check the QA of SIM for this run and remove the detectors
2503// with status Fatal
2504
abe0c04e 2505 TString newRunLocalReconstruction ;
2506 TString newRunTracking ;
2507 TString newFillESD ;
2508
8661738e 2509 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2510 TString detName(AliQA::GetDetName(iDet)) ;
96d67a8d 2511 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2512 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
8661738e 2513 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
abe0c04e 2514 } else {
2515 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2516 fRunLocalReconstruction.Contains("ALL") ) {
2517 newRunLocalReconstruction += detName ;
2518 newRunLocalReconstruction += " " ;
2519 }
2520 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2521 fRunTracking.Contains("ALL") ) {
2522 newRunTracking += detName ;
2523 newRunTracking += " " ;
2524 }
2525 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2526 fFillESD.Contains("ALL") ) {
2527 newFillESD += detName ;
2528 newFillESD += " " ;
8661738e 2529 }
2530 }
2531 }
abe0c04e 2532 fRunLocalReconstruction = newRunLocalReconstruction ;
2533 fRunTracking = newRunTracking ;
2534 fFillESD = newFillESD ;
a5fa6165 2535}
5b188f2f 2536
2537//_____________________________________________________________________________
2538Int_t AliReconstruction::GetDetIndex(const char* detector)
2539{
2540 // return the detector index corresponding to detector
2541 Int_t index = -1 ;
2542 for (index = 0; index < fgkNDetectors ; index++) {
2543 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2544 break ;
2545 }
2546 return index ;
2547}
7167ae53 2548//_____________________________________________________________________________
2549Bool_t AliReconstruction::FinishPlaneEff() {
2550 //
2551 // Here execute all the necessary operationis, at the end of the tracking phase,
2552 // in case that evaluation of PlaneEfficiencies was required for some detector.
2553 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
2554 //
2555 // This Preliminary version works only FOR ITS !!!!!
2556 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2557 //
2558 // Input: none
2559 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2560 //
2561 Bool_t ret=kFALSE;
2562 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2563 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
2564 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
5fbd4fd6 2565 if(fTracker[iDet]) {
2566 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2567 ret=planeeff->WriteIntoCDB();
2568 if(planeeff->GetCreateHistos()) {
2569 TString name="PlaneEffHisto";
2570 name+=fgkDetectorName[iDet];
2571 name+=".root";
2572 ret*=planeeff->WriteHistosToFile(name,"RECREATE");
2573 }
2574 }
7167ae53 2575 }
2576 return ret;
2577}
2578//_____________________________________________________________________________
2579Bool_t AliReconstruction::InitPlaneEff() {
2580//
2581 // Here execute all the necessary operations, before of the tracking phase,
2582 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2583 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2584 // which should be updated/recalculated.
2585 //
2586 // This Preliminary version will work only FOR ITS !!!!!
2587 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2588 //
2589 // Input: none
2590 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2591 //
2592 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));
2593 return kTRUE;
7520312d 2594}
14dd053c 2595
2596//_____________________________________________________________________________
2597Bool_t AliReconstruction::InitAliEVE()
2598{
2599 // This method should be called only in case
2600 // AliReconstruction is run
2601 // within the alieve environment.
2602 // It will initialize AliEVE in a way
2603 // so that it can visualize event processed
2604 // by AliReconstruction.
2605 // The return flag shows whenever the
2606 // AliEVE initialization was successful or not.
2607
2608 TString macroStr;
2609 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
2610 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
2611 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
2612
2613 gROOT->ProcessLine("if (!gAliEveEvent) {gAliEveEvent = new AliEveEventManager();gAliEveEvent->SetAutoLoad(kTRUE);gAliEveEvent->AddNewEventCommand(\"alieve_online()\");gEve->AddEvent(gAliEveEvent);};");
2614
2615 return kTRUE;
2616}
2617
2618//_____________________________________________________________________________
2619void AliReconstruction::RunAliEVE()
2620{
2621 // Runs AliEVE visualisation of
2622 // the current event.
2623 // Should be executed only after
2624 // successful initialization of AliEVE.
2625
2626 AliInfo("Running AliEVE...");
2627 gROOT->ProcessLine(Form("gAliEveEvent->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p);",fRunLoader,fRawReader,fesd));
2628 gROOT->ProcessLine("gAliEveEvent->StartStopAutoLoadTimer();");
2629 gSystem->Run();
2630}