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