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