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