]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliReconstruction.cxx
error in comment
[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
c757bafd 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
596a855f 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 }
30bbd491 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),
30bbd491 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;
30bbd491 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;
30bbd491 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
00aa02d5 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
795e4a22 578//_____________________________________________________________________________
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
6bae477a 586//_____________________________________________________________________________
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
21a3aa09 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
efd2085e 654//_____________________________________________________________________________
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
7e88424f 664//_____________________________________________________________________________
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
61807e09 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
596a855f 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]));
1066 if (fQATasks.Contains(Form("%d", AliQA::kRAWS))) ;
1067 qadm->Init(AliQA::kRAWS, AliCDBManager::Instance()->GetRun());
1068 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1069 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
1070 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1071 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
1072 if (!fInLoopQA) {
1073 if (fQATasks.Contains(Form("%d", AliQA::kRAWS))) {
1074 qadm->StartOfCycle(AliQA::kRAWS, fSameQACycle);
1075 fSameQACycle = kTRUE;
1076 }
1077 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1078 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
1079 fSameQACycle = kTRUE;
1080 }
1081 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
1082 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
1083 fSameQACycle = kTRUE;
1084 }
ce43afbe 1085 }
ca13fb87 1086 }
1087 if (fRunGlobalQA) {
1088 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1089 AliInfo(Form("Initializing the global QA data maker"));
1090 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1091 TObjArray *arr=
1092 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
1093 AliTracker::SetResidualsArray(arr);
1094 }
1095 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
1096 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
1097 }
1098 if (!fInLoopQA) {
1099 fSameQACycle = kFALSE;
1100 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1101 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
1102 fSameQACycle = kTRUE;
1103 }
1104 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
1105 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
1106 fSameQACycle = kTRUE;
1107 }
1108 }
1109 }
aa3c69a9 1110 }
1111
7167ae53 1112 //Initialize the Plane Efficiency framework
1113 if (fRunPlaneEff && !InitPlaneEff()) {
21a3aa09 1114 if(fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
7167ae53 1115 }
aa3c69a9 1116
14dd053c 1117 if (strcmp(gProgName,"alieve") == 0)
1118 fRunAliEVE = InitAliEVE();
1119
21a3aa09 1120 return kTRUE;
1121}
1122
1123//_____________________________________________________________________________
1124Bool_t AliReconstruction::RunEvent(Int_t iEvent)
1125{
1126 // run the reconstruction over a single event
1127 // The event loop is steered in Run method
1128
1129 AliCodeTimerAuto("");
1130
1131 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
1132 fRunLoader->SetEventNumber(iEvent);
1133 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1134 iEvent, iEvent);
1135 //?? fRunLoader->MakeTree("H");
1136 fRunLoader->TreeE()->Fill();
1137 }
1138
1139 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
1140 // copy old ESD to the new one
1141 if (ftreeOld) {
1142 fesd->ReadFromTree(ftreeOld);
1143 ftreeOld->GetEntry(iEvent);
1144 ftree->Fill();
b26c3770 1145 }
21a3aa09 1146 if (fhlttreeOld) {
f6806ad3 1147 fhltesd->ReadFromTree(fhlttreeOld);
21a3aa09 1148 fhlttreeOld->GetEntry(iEvent);
1149 fhlttree->Fill();
1150 }
1151 return kTRUE;
1152 }
1153
1154 AliInfo(Form("processing event %d", iEvent));
aa3c69a9 1155
7e88424f 1156 // Fill Event-info object
1157 GetEventInfo();
1158 fRecoParam.SetEventSpecie(fRunInfo,fEventInfo);
1159
ca13fb87 1160 //Start of cycle for the in-loop QA
1161 if (fInLoopQA && fRunQA) {
1162 TString detStr(fQADetectors);
1163 fSameQACycle = kFALSE ;
1164 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1165 if (!IsSelected(fgkDetectorName[iDet], detStr))
1166 continue;
1167 AliQADataMaker *qadm = fQASteer->GetQADataMaker(iDet);
1168 if (!qadm)
1169 continue;
1170 if (fQATasks.Contains(Form("%d", AliQA::kRAWS))) {
1171 qadm->StartOfCycle(AliQA::kRAWS, fSameQACycle);
1172 fSameQACycle = kTRUE;
1173 }
1174 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1175 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
1176 fSameQACycle = kTRUE;
1177 }
1178 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
1179 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle) ;
1180 fSameQACycle = kTRUE;
1181 }
aa3c69a9 1182 }
ca13fb87 1183 if (fRunGlobalQA) {
1184 fSameQACycle = kFALSE;
1185 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1186 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1187 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
1188 fSameQACycle = kTRUE;
1189 }
1190 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
1191 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
1192 fSameQACycle = kTRUE;
1193 }
1194 }
1195 }
aa3c69a9 1196
596a855f 1197 fRunLoader->GetEvent(iEvent);
24f7a148 1198
bb0901a4 1199 char aFileName[256];
1200 sprintf(aFileName, "ESD_%d.%d_final.root",
f08fc9f5 1201 fRunLoader->GetHeader()->GetRun(),
1202 fRunLoader->GetHeader()->GetEventNrInRun());
21a3aa09 1203 if (!gSystem->AccessPathName(aFileName)) return kTRUE;
24f7a148 1204
ca13fb87 1205 // QA on single raw
1206 if (fInLoopQA && fRunQA) {
1207 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1208 TString detStr(fQADetectors);
1209 if (!IsSelected(fgkDetectorName[iDet], detStr))
1210 continue;
1211 AliQADataMaker *qadm = fQASteer->GetQADataMaker(iDet);
1212 if (!qadm)
1213 continue;
1214 if (fQATasks.Contains(Form("%d", AliQA::kRAWS)))
1215 qadm->Exec(AliQA::kRAWS, fRawReader) ;
1216 }
1217 }
1218
d506c543 1219 // local single event reconstruction
b26c3770 1220 if (!fRunLocalReconstruction.IsNull()) {
d506c543 1221 TString detectors=fRunLocalReconstruction;
a441bf51 1222 // run HLT event reconstruction first
d506c543 1223 // ;-( IsSelected changes the string
1224 if (IsSelected("HLT", detectors) &&
1225 !RunLocalEventReconstruction("HLT")) {
a441bf51 1226 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1227 }
1228 detectors=fRunLocalReconstruction;
1229 detectors.ReplaceAll("HLT", "");
1230 if (!RunLocalEventReconstruction(detectors)) {
21a3aa09 1231 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
b26c3770 1232 }
1233 }
1234
21a3aa09 1235 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1236 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1237 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1238 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
46698ae4 1239
d6ee376f 1240 // Set magnetic field from the tracker
21a3aa09 1241 fesd->SetMagneticField(AliTracker::GetBz());
1242 fhltesd->SetMagneticField(AliTracker::GetBz());
596a855f 1243
46698ae4 1244
1245
2e3550da 1246 // Fill raw-data error log into the ESD
21a3aa09 1247 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 1248
2257f27e 1249 // vertex finder
1250 if (fRunVertexFinder) {
21a3aa09 1251 if (!ReadESD(fesd, "vertex")) {
1252 if (!RunVertexFinder(fesd)) {
1253 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
2257f27e 1254 }
21a3aa09 1255 if (fCheckPointLevel > 0) WriteESD(fesd, "vertex");
2257f27e 1256 }
1257 }
1258
e66fbafb 1259 // Muon tracking
b8cd5251 1260 if (!fRunTracking.IsNull()) {
e66fbafb 1261 if (fRunMuonTracking) {
21a3aa09 1262 if (!RunMuonTracking(fesd)) {
1263 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
24f7a148 1264 }
596a855f 1265 }
1266 }
1267
e66fbafb 1268 // barrel tracking
1269 if (!fRunTracking.IsNull()) {
21a3aa09 1270 if (!ReadESD(fesd, "tracking")) {
1271 if (!RunTracking(fesd)) {
1272 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
e66fbafb 1273 }
21a3aa09 1274 if (fCheckPointLevel > 0) WriteESD(fesd, "tracking");
e66fbafb 1275 }
1276 }
21c573b7 1277
596a855f 1278 // fill ESD
1279 if (!fFillESD.IsNull()) {
d506c543 1280 TString detectors=fFillESD;
f6806ad3 1281 // run HLT first and on hltesd
d506c543 1282 // ;-( IsSelected changes the string
1283 if (IsSelected("HLT", detectors) &&
1284 !FillESD(fhltesd, "HLT")) {
f6806ad3 1285 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1286 }
1287 detectors=fFillESD;
d5105682 1288 // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
1289 if (detectors.Contains("ALL")) {
1290 detectors="";
1291 for (Int_t idet=0; idet<fgkNDetectors; ++idet){
1292 detectors += fgkDetectorName[idet];
1293 detectors += " ";
1294 }
1295 }
f6806ad3 1296 detectors.ReplaceAll("HLT", "");
1297 if (!FillESD(fesd, detectors)) {
21a3aa09 1298 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
596a855f 1299 }
1300 }
a5fa6165 1301
001397cd 1302 // fill Event header information from the RawEventHeader
21a3aa09 1303 if (fRawReader){FillRawEventHeaderESD(fesd);}
596a855f 1304
1305 // combined PID
21a3aa09 1306 AliESDpid::MakePID(fesd);
1307 if (fCheckPointLevel > 1) WriteESD(fesd, "PID");
596a855f 1308
b647652d 1309 if (fFillTriggerESD) {
21a3aa09 1310 if (!ReadESD(fesd, "trigger")) {
1311 if (!FillTriggerESD(fesd)) {
1312 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
b647652d 1313 }
21a3aa09 1314 if (fCheckPointLevel > 1) WriteESD(fesd, "trigger");
b647652d 1315 }
1316 }
1317
21a3aa09 1318 ffile->cd();
a6ee503a 1319
3c3709c4 1320 //
67be5c77 1321 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 1322 //
21a3aa09 1323 const Int_t ntracks = fesd->GetNumberOfTracks();
1324 const Double_t kBz = fesd->GetMagneticField();
3c3709c4 1325 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1326
1327 TObjArray trkArray;
1328 UShort_t *selectedIdx=new UShort_t[ntracks];
1329
1330 for (Int_t itrack=0; itrack<ntracks; itrack++){
1331 const Double_t kMaxStep = 5; //max step over the material
1332 Bool_t ok;
1333
21a3aa09 1334 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 1335 if (!track) continue;
1336
1337 AliExternalTrackParam *tpcTrack =
1338 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 1339 ok = kFALSE;
1340 if (tpcTrack)
1341 ok = AliTracker::
1342 PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
43c9dae1 1343
3c3709c4 1344 if (ok) {
1345 Int_t n=trkArray.GetEntriesFast();
1346 selectedIdx[n]=track->GetID();
1347 trkArray.AddLast(tpcTrack);
1348 }
1349
3d65e645 1350 //Tracks refitted by ITS should already be at the SPD vertex
1351 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1352
1353 AliTracker::
1354 PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1355 track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kVeryBig);
3c3709c4 1356
3c3709c4 1357 }
1358
1359 //
1360 // Improve the reconstructed primary vertex position using the tracks
1361 //
1362 TObject *obj = fOptions.FindObject("ITS");
c060d7fe 1363 if (obj) {
1364 TString optITS = obj->GetTitle();
1365 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
a84e2607 1366 fRunVertexFinderTracks=kFALSE;
c060d7fe 1367 }
3c3709c4 1368 if (fRunVertexFinderTracks) {
1369 // TPC + ITS primary vertex
21a3aa09 1370 ftVertexer->SetITSrefitRequired();
43c9dae1 1371 if(fDiamondProfile && fMeanVertexConstraint) {
21a3aa09 1372 ftVertexer->SetVtxStart(fDiamondProfile);
43c9dae1 1373 } else {
21a3aa09 1374 ftVertexer->SetConstraintOff();
43c9dae1 1375 }
21a3aa09 1376 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 1377 if (pvtx) {
1378 if (pvtx->GetStatus()) {
21a3aa09 1379 fesd->SetPrimaryVertex(pvtx);
3c3709c4 1380 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 1381 AliESDtrack *t = fesd->GetTrack(i);
3d65e645 1382 t->RelateToVertex(pvtx, kBz, kVeryBig);
3c3709c4 1383 }
1384 }
1385 }
1386
1387 // TPC-only primary vertex
21a3aa09 1388 ftVertexer->SetITSrefitNotRequired();
43c9dae1 1389 if(fDiamondProfileTPC && fMeanVertexConstraint) {
21a3aa09 1390 ftVertexer->SetVtxStart(fDiamondProfileTPC);
43c9dae1 1391 } else {
21a3aa09 1392 ftVertexer->SetConstraintOff();
43c9dae1 1393 }
21a3aa09 1394 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 1395 if (pvtx) {
1396 if (pvtx->GetStatus()) {
21a3aa09 1397 fesd->SetPrimaryVertexTPC(pvtx);
3d65e645 1398 for (Int_t i=0; i<ntracks; i++) {
1399 AliESDtrack *t = fesd->GetTrack(i);
1400 t->RelateToVertexTPC(pvtx, kBz, kVeryBig);
3c3709c4 1401 }
1402 }
1403 }
1404
1405 }
1406 delete[] selectedIdx;
1407
21a3aa09 1408 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
17c86e90 1409
c5e3e5d1 1410
d1683eef 1411 if (fRunV0Finder) {
1412 // V0 finding
1413 AliV0vertexer vtxer;
21a3aa09 1414 vtxer.Tracks2V0vertices(fesd);
5e4ff34d 1415
d1683eef 1416 if (fRunCascadeFinder) {
1417 // Cascade finding
1418 AliCascadeVertexer cvtxer;
21a3aa09 1419 cvtxer.V0sTracks2CascadeVertices(fesd);
d1683eef 1420 }
5e4ff34d 1421 }
1422
596a855f 1423 // write ESD
21a3aa09 1424 if (fCleanESD) CleanESD(fesd);
854c6476 1425
79740dfc 1426 if (fRunQA) {
1427 if (fRunGlobalQA) {
30bbd491 1428 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
ce43afbe 1429 if (qadm && fQATasks.Contains(Form("%d", AliQA::kESDS)))
1430 qadm->Exec(AliQA::kESDS, fesd);
79740dfc 1431 }
1432 }
854c6476 1433
1d99986f 1434 if (fWriteESDfriend) {
21a3aa09 1435 fesdf->~AliESDfriend();
1436 new (fesdf) AliESDfriend(); // Reset...
1437 fesd->GetESDfriend(fesdf);
1d99986f 1438 }
21a3aa09 1439 ftree->Fill();
500d54ab 1440
2d91a353 1441 // Auto-save the ESD tree in case of prompt reco @P2
1442 if (fRawReader && fRawReader->UseAutoSaveESD())
1443 ftree->AutoSave("SaveSelf");
1444
500d54ab 1445 // write HLT ESD
21a3aa09 1446 fhlttree->Fill();
1d99986f 1447
14dd053c 1448 // call AliEVE
1449 if (fRunAliEVE) RunAliEVE();
1450
21a3aa09 1451 if (fCheckPointLevel > 0) WriteESD(fesd, "final");
1452 fesd->Reset();
1453 fhltesd->Reset();
5728d3d5 1454 if (fWriteESDfriend) {
21a3aa09 1455 fesdf->~AliESDfriend();
1456 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 1457 }
a5fa6165 1458
21a3aa09 1459 ProcInfo_t ProcInfo;
95cee32f 1460 gSystem->GetProcInfo(&ProcInfo);
1461 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
a5fa6165 1462
7e963665 1463
ce43afbe 1464 // End of cycle for the in-loop
ca13fb87 1465 if (fInLoopQA && fRunQA) {
1466 RunQA(fesd);
1467 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1468 if (!IsSelected(fgkDetectorName[iDet], fQADetectors))
1469 continue;
1470 AliQADataMaker * qadm = fQASteer->GetQADataMaker(iDet);
1471 if (!qadm)
1472 continue;
1473 if (fQATasks.Contains(Form("%d", AliQA::kRAWS)))
1474 qadm->EndOfCycle(AliQA::kRAWS);
1475 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1476 qadm->EndOfCycle(AliQA::kRECPOINTS);
1477 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1478 qadm->EndOfCycle(AliQA::kESDS);
1479 qadm->Finish();
1480 }
1481 }
1482 if (fRunGlobalQA) {
1483 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1484 if (qadm) {
1485 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1486 qadm->EndOfCycle(AliQA::kRECPOINTS);
1487 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1488 qadm->EndOfCycle(AliQA::kESDS);
1489 qadm->Finish();
1490 }
1491 }
7e88424f 1492
ca13fb87 1493 fEventInfo.Reset();
1494 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1495 if (fReconstructor[iDet])
1496 fReconstructor[iDet]->SetRecoParam(NULL);
1497 }
1498
1499 return kTRUE;
21a3aa09 1500}
1501
21a3aa09 1502//_____________________________________________________________________________
1503Bool_t AliReconstruction::FinishRun()
1504{
1505 // Finalize the run
1506 // Called after the exit
1507 // from the event loop
1508 AliCodeTimerAuto("");
1509
1510 if (fIsNewRunLoader) { // galice.root didn't exist
1511 fRunLoader->WriteHeader("OVERWRITE");
1512 fRunLoader->CdGAFile();
1513 fRunLoader->Write(0, TObject::kOverwrite);
1514 }
1515
1516 ftree->GetUserInfo()->Add(fesd);
1517 fhlttree->GetUserInfo()->Add(fhltesd);
f747912b 1518
1519 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1520 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1521
1522 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1523 cdbMapCopy->SetOwner(1);
1524 cdbMapCopy->SetName("cdbMap");
1525 TIter iter(cdbMap->GetTable());
1526
1527 TPair* pair = 0;
1528 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1529 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1530 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1531 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1532 }
1533
1534 TList *cdbListCopy = new TList();
1535 cdbListCopy->SetOwner(1);
1536 cdbListCopy->SetName("cdbList");
1537
1538 TIter iter2(cdbList);
1539
1540 AliCDBId* id=0;
1541 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 1542 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 1543 }
1544
21a3aa09 1545 ftree->GetUserInfo()->Add(cdbMapCopy);
1546 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 1547
46698ae4 1548
1549 if(fESDPar.Contains("ESD.par")){
1550 AliInfo("Attaching ESD.par to Tree");
1551 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
21a3aa09 1552 ftree->GetUserInfo()->Add(fn);
596a855f 1553 }
1554
46698ae4 1555
21a3aa09 1556 ffile->cd();
aa3c69a9 1557
a9c0e6db 1558 if (fWriteESDfriend)
21a3aa09 1559 ftree->SetBranchStatus("ESDfriend*",0);
562dd0b4 1560 // we want to have only one tree version number
21a3aa09 1561 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1562 fhlttree->Write();
f3a97c86 1563
a7a1e1c7 1564// Finish with Plane Efficiency evaluation: before of CleanUp !!!
1565 if (fRunPlaneEff && !FinishPlaneEff()) {
1566 AliWarning("Finish PlaneEff evaluation failed");
1567 }
1568
eae191bc 1569 gROOT->cd();
21a3aa09 1570 CleanUp(ffile, ffileOld);
eae191bc 1571
a7807689 1572 if (fWriteAOD) {
7a3b2050 1573 AliWarning("AOD creation not supported anymore during reconstruction. See ANALYSIS/AliAnalysisTaskESDfilter.cxx instead.");
a7807689 1574 }
1575
f3a97c86 1576 // Create tags for the events in the ESD tree (the ESD tree is always present)
1577 // In case of empty events the tags will contain dummy values
08e1a23e 1578 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
6b6e4472 1579 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData);
a1069ee1 1580 if (fWriteAOD) {
7a3b2050 1581 AliWarning("AOD tag creation not supported anymore during reconstruction.");
a1069ee1 1582 }
596a855f 1583
aa3c69a9 1584 //Finish QA and end of cycle for out-of-loop QA
3b378a42 1585 if (!fInLoopQA) {
79740dfc 1586 if (fRunQA) {
ce43afbe 1587 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
30bbd491 1588 fQASteer->Run(fRunLocalReconstruction.Data(), AliQA::kRECPOINTS, fSameQACycle);
1589 //fQASteer->Reset() ;
ce43afbe 1590 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
30bbd491 1591 fQASteer->Run(fRunLocalReconstruction.Data(), AliQA::kESDS, fSameQACycle);
79740dfc 1592 if (fRunGlobalQA) {
30bbd491 1593 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
79740dfc 1594 if (qadm) {
ce43afbe 1595 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1596 qadm->EndOfCycle(AliQA::kRECPOINTS);
1597 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1598 qadm->EndOfCycle(AliQA::kESDS);
79740dfc 1599 qadm->Finish();
1600 }
1601 }
1602 }
759c1df1 1603 }
795e4a22 1604
1605 // Cleanup of CDB manager: cache and active storages!
1606 AliCDBManager::Instance()->ClearCache();
1607
596a855f 1608 return kTRUE;
1609}
1610
1611
1612//_____________________________________________________________________________
c4aa7a4c 1613Bool_t AliReconstruction::RunLocalReconstruction(const TString& /*detectors*/)
596a855f 1614{
59697224 1615// run the local reconstruction
0f88822a 1616 static Int_t eventNr=0;
87932dab 1617 AliCodeTimerAuto("")
030b532d 1618
d76c31f4 1619 // AliCDBManager* man = AliCDBManager::Instance();
1620// Bool_t origCache = man->GetCacheFlag();
8e245d15 1621
d76c31f4 1622// TString detStr = detectors;
1623// for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1624// if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1625// AliReconstructor* reconstructor = GetReconstructor(iDet);
1626// if (!reconstructor) continue;
1627// if (reconstructor->HasLocalReconstruction()) continue;
b8cd5251 1628
d76c31f4 1629// AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1630// AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
87932dab 1631
d76c31f4 1632// AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1633// AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
8e245d15 1634
d76c31f4 1635// man->SetCacheFlag(kTRUE);
1636// TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
1637// man->GetAll(calibPath); // entries are cached!
8e245d15 1638
d76c31f4 1639// AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
87932dab 1640
d76c31f4 1641// if (fRawReader) {
1642// fRawReader->RewindEvents();
1643// reconstructor->Reconstruct(fRunLoader, fRawReader);
1644// } else {
1645// reconstructor->Reconstruct(fRunLoader);
1646// }
87932dab 1647
d76c31f4 1648// AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
0f88822a 1649 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
8e245d15 1650
d76c31f4 1651// // unload calibration data
1652// man->UnloadFromCache(calibPath);
1653// //man->ClearCache();
1654// }
596a855f 1655
d76c31f4 1656// man->SetCacheFlag(origCache);
8e245d15 1657
d76c31f4 1658// if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1659// AliError(Form("the following detectors were not found: %s",
1660// detStr.Data()));
1661// if (fStopOnError) return kFALSE;
1662// }
596a855f 1663
0f88822a 1664 eventNr++;
596a855f 1665 return kTRUE;
1666}
1667
b26c3770 1668//_____________________________________________________________________________
1669Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1670{
1671// run the local reconstruction
aa3c69a9 1672
0f88822a 1673 static Int_t eventNr=0;
87932dab 1674 AliCodeTimerAuto("")
b26c3770 1675
1676 TString detStr = detectors;
1677 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1678 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1679 AliReconstructor* reconstructor = GetReconstructor(iDet);
1680 if (!reconstructor) continue;
1681 AliLoader* loader = fLoader[iDet];
f6806ad3 1682 // Matthias April 2008: temporary fix to run HLT reconstruction
1683 // although the HLT loader is missing
1684 if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
1685 if (fRawReader) {
1686 reconstructor->Reconstruct(fRawReader, NULL);
1687 } else {
1688 TTree* dummy=NULL;
1689 reconstructor->Reconstruct(dummy, NULL);
1690 }
1691 continue;
1692 }
d76c31f4 1693 if (!loader) {
1694 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1695 continue;
1696 }
b26c3770 1697 // conversion of digits
1698 if (fRawReader && reconstructor->HasDigitConversion()) {
1699 AliInfo(Form("converting raw data digits into root objects for %s",
1700 fgkDetectorName[iDet]));
30bbd491 1701// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1702// fgkDetectorName[iDet]));
b26c3770 1703 loader->LoadDigits("update");
1704 loader->CleanDigits();
1705 loader->MakeDigitsContainer();
1706 TTree* digitsTree = loader->TreeD();
1707 reconstructor->ConvertDigits(fRawReader, digitsTree);
1708 loader->WriteDigits("OVERWRITE");
1709 loader->UnloadDigits();
b26c3770 1710 }
b26c3770 1711 // local reconstruction
b26c3770 1712 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
30bbd491 1713 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
b26c3770 1714 loader->LoadRecPoints("update");
1715 loader->CleanRecPoints();
1716 loader->MakeRecPointsContainer();
1717 TTree* clustersTree = loader->TreeR();
1718 if (fRawReader && !reconstructor->HasDigitConversion()) {
1719 reconstructor->Reconstruct(fRawReader, clustersTree);
1720 } else {
1721 loader->LoadDigits("read");
1722 TTree* digitsTree = loader->TreeD();
1723 if (!digitsTree) {
1724 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1725 if (fStopOnError) return kFALSE;
1726 } else {
1727 reconstructor->Reconstruct(digitsTree, clustersTree);
1728 }
1729 loader->UnloadDigits();
1730 }
d76c31f4 1731
aa3c69a9 1732 // In-loop QA for local reconstrucion
30bbd491 1733 TString detQAStr(fQADetectors) ;
ae7222f3 1734 if (fRunQA && fInLoopQA && IsSelected(fgkDetectorName[iDet], detQAStr) ) {
30bbd491 1735 AliQADataMaker * qadm = fQASteer->GetQADataMaker(iDet);
aa3c69a9 1736 if (qadm) {
1737 //AliCodeTimerStart
1738 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1739 //AliInfo
1740 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1741
ce43afbe 1742 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1743 qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
aa3c69a9 1744 //AliCodeTimerStop
1745 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1746 }
1747 }
d76c31f4 1748
aa3c69a9 1749 loader->WriteRecPoints("OVERWRITE");
b26c3770 1750 loader->UnloadRecPoints();
6efecea1 1751 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
b26c3770 1752 }
1753
1754 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1755 AliError(Form("the following detectors were not found: %s",
1756 detStr.Data()));
1757 if (fStopOnError) return kFALSE;
1758 }
0f88822a 1759 eventNr++;
b26c3770 1760 return kTRUE;
1761}
1762
596a855f 1763//_____________________________________________________________________________
af885e0f 1764Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 1765{
1766// run the barrel tracking
1767
87932dab 1768 AliCodeTimerAuto("")
030b532d 1769
2257f27e 1770 AliESDVertex* vertex = NULL;
1771 Double_t vtxPos[3] = {0, 0, 0};
1772 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1773 TArrayF mcVertex(3);
a6b0b91b 1774 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1775 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1776 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1777 }
2257f27e 1778
b8cd5251 1779 if (fVertexer) {
815c2b38 1780 AliInfo("running the ITS vertex finder");
308c2f7c 1781 if (fLoader[0]) {
1782 fLoader[0]->LoadRecPoints();
1783 TTree* cltree = fLoader[0]->TreeR();
1784 if (cltree) {
1785 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1786 vertex = fVertexer->FindVertexForCurrentEvent(cltree);
1787 }
1788 else {
1789 AliError("Can't get the ITS cluster tree");
1790 }
1791 fLoader[0]->UnloadRecPoints();
1792 }
1793 else {
1794 AliError("Can't get the ITS loader");
1795 }
2257f27e 1796 if(!vertex){
815c2b38 1797 AliWarning("Vertex not found");
c710f220 1798 vertex = new AliESDVertex();
d1a50cb5 1799 vertex->SetName("default");
2257f27e 1800 }
1801 else {
d1a50cb5 1802 vertex->SetName("reconstructed");
2257f27e 1803 }
1804
1805 } else {
815c2b38 1806 AliInfo("getting the primary vertex from MC");
2257f27e 1807 vertex = new AliESDVertex(vtxPos, vtxErr);
1808 }
1809
1810 if (vertex) {
1811 vertex->GetXYZ(vtxPos);
1812 vertex->GetSigmaXYZ(vtxErr);
1813 } else {
815c2b38 1814 AliWarning("no vertex reconstructed");
2257f27e 1815 vertex = new AliESDVertex(vtxPos, vtxErr);
1816 }
06cc9d95 1817 esd->SetPrimaryVertexSPD(vertex);
32e449be 1818 // if SPD multiplicity has been determined, it is stored in the ESD
25be1e5c 1819 AliMultiplicity *mult = fVertexer->GetMultiplicity();
32e449be 1820 if(mult)esd->SetMultiplicity(mult);
1821
b8cd5251 1822 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1823 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1824 }
2257f27e 1825 delete vertex;
1826
2257f27e 1827 return kTRUE;
1828}
1829
1f46a9ae 1830//_____________________________________________________________________________
af885e0f 1831Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 1832{
1833// run the HLT barrel tracking
1834
87932dab 1835 AliCodeTimerAuto("")
1f46a9ae 1836
1837 if (!fRunLoader) {
1838 AliError("Missing runLoader!");
1839 return kFALSE;
1840 }
1841
1842 AliInfo("running HLT tracking");
1843
1844 // Get a pointer to the HLT reconstructor
1845 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1846 if (!reconstructor) return kFALSE;
1847
1848 // TPC + ITS
1849 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1850 TString detName = fgkDetectorName[iDet];
1851 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1852 reconstructor->SetOption(detName.Data());
d76c31f4 1853 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 1854 if (!tracker) {
1855 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1856 if (fStopOnError) return kFALSE;
9dcc06e1 1857 continue;
1f46a9ae 1858 }
1859 Double_t vtxPos[3];
1860 Double_t vtxErr[3]={0.005,0.005,0.010};
1861 const AliESDVertex *vertex = esd->GetVertex();
1862 vertex->GetXYZ(vtxPos);
1863 tracker->SetVertex(vtxPos,vtxErr);
1864 if(iDet != 1) {
1865 fLoader[iDet]->LoadRecPoints("read");
1866 TTree* tree = fLoader[iDet]->TreeR();
1867 if (!tree) {
1868 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1869 return kFALSE;
1870 }
1871 tracker->LoadClusters(tree);
1872 }
1873 if (tracker->Clusters2Tracks(esd) != 0) {
1874 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1875 return kFALSE;
1876 }
1877 if(iDet != 1) {
1878 tracker->UnloadClusters();
1879 }
1880 delete tracker;
1881 }
1882
1f46a9ae 1883 return kTRUE;
1884}
1885
e66fbafb 1886//_____________________________________________________________________________
af885e0f 1887Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 1888{
1889// run the muon spectrometer tracking
1890
87932dab 1891 AliCodeTimerAuto("")
e66fbafb 1892
1893 if (!fRunLoader) {
1894 AliError("Missing runLoader!");
1895 return kFALSE;
1896 }
1897 Int_t iDet = 7; // for MUON
1898
1899 AliInfo("is running...");
1900
1901 // Get a pointer to the MUON reconstructor
1902 AliReconstructor *reconstructor = GetReconstructor(iDet);
1903 if (!reconstructor) return kFALSE;
1904
1905
1906 TString detName = fgkDetectorName[iDet];
1907 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 1908 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 1909 if (!tracker) {
1910 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1911 return kFALSE;
1912 }
1913
e66fbafb 1914 // read RecPoints
761350a6 1915 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 1916
761350a6 1917 tracker->LoadClusters(fLoader[iDet]->TreeR());
1918
1919 Int_t rv = tracker->Clusters2Tracks(esd);
1920
761350a6 1921 if ( rv )
1922 {
e66fbafb 1923 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1924 return kFALSE;
1925 }
761350a6 1926
e66fbafb 1927 fLoader[iDet]->UnloadRecPoints();
1928
c1954ee5 1929 tracker->UnloadClusters();
1930
e66fbafb 1931 delete tracker;
1932
e66fbafb 1933 return kTRUE;
1934}
1935
1936
2257f27e 1937//_____________________________________________________________________________
af885e0f 1938Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
2257f27e 1939{
1940// run the barrel tracking
0f88822a 1941 static Int_t eventNr=0;
87932dab 1942 AliCodeTimerAuto("")
24f7a148 1943
815c2b38 1944 AliInfo("running tracking");
596a855f 1945
91b876d1 1946 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 1947 if (fReconstructor[11] && fLoader[11]) {
1948 fLoader[11]->LoadRecPoints("READ");
1949 TTree *treeR = fLoader[11]->TreeR();
1950 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1951 }
91b876d1 1952
b8cd5251 1953 // pass 1: TPC + ITS inwards
1954 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1955 if (!fTracker[iDet]) continue;
1956 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 1957
b8cd5251 1958 // load clusters
1959 fLoader[iDet]->LoadRecPoints("read");
6efecea1 1960 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 1961 TTree* tree = fLoader[iDet]->TreeR();
1962 if (!tree) {
1963 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 1964 return kFALSE;
1965 }
b8cd5251 1966 fTracker[iDet]->LoadClusters(tree);
6efecea1 1967 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 1968 // run tracking
1969 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1970 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 1971 return kFALSE;
1972 }
b8cd5251 1973 if (fCheckPointLevel > 1) {
1974 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1975 }
878e1fe1 1976 // preliminary PID in TPC needed by the ITS tracker
1977 if (iDet == 1) {
b26c3770 1978 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
878e1fe1 1979 AliESDpid::MakePID(esd);
0f88822a 1980 }
6efecea1 1981 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 1982 }
596a855f 1983
b8cd5251 1984 // pass 2: ALL backwards
aa3c69a9 1985
b8cd5251 1986 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1987 if (!fTracker[iDet]) continue;
1988 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1989
1990 // load clusters
1991 if (iDet > 1) { // all except ITS, TPC
1992 TTree* tree = NULL;
7b61cd9c 1993 fLoader[iDet]->LoadRecPoints("read");
6efecea1 1994 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 1995 tree = fLoader[iDet]->TreeR();
b8cd5251 1996 if (!tree) {
1997 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 1998 return kFALSE;
1999 }
0f88822a 2000 fTracker[iDet]->LoadClusters(tree);
6efecea1 2001 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2002 }
24f7a148 2003
b8cd5251 2004 // run tracking
283f39c6 2005 if (iDet>1) // start filling residuals for the "outer" detectors
2006 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
2007
b8cd5251 2008 if (fTracker[iDet]->PropagateBack(esd) != 0) {
2009 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 2010 // return kFALSE;
b8cd5251 2011 }
2012 if (fCheckPointLevel > 1) {
2013 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
2014 }
24f7a148 2015
b8cd5251 2016 // unload clusters
6e65648b 2017 if (iDet > 3) { // all except ITS, TPC, TRD and TOF
b8cd5251 2018 fTracker[iDet]->UnloadClusters();
7b61cd9c 2019 fLoader[iDet]->UnloadRecPoints();
b8cd5251 2020 }
8f37df88 2021 // updated PID in TPC needed by the ITS tracker -MI
2022 if (iDet == 1) {
8f37df88 2023 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
2024 AliESDpid::MakePID(esd);
2025 }
6efecea1 2026 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 2027 }
283f39c6 2028 //stop filling residuals for the "outer" detectors
2029 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
596a855f 2030
b8cd5251 2031 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 2032
b8cd5251 2033 for (Int_t iDet = 2; iDet >= 0; iDet--) {
2034 if (!fTracker[iDet]) continue;
2035 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 2036
b8cd5251 2037 // run tracking
283f39c6 2038 if (iDet<2) // start filling residuals for TPC and ITS
2039 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
2040
b8cd5251 2041 if (fTracker[iDet]->RefitInward(esd) != 0) {
2042 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 2043 // return kFALSE;
b8cd5251 2044 }
db2368d0 2045 // run postprocessing
2046 if (fTracker[iDet]->PostProcess(esd) != 0) {
2047 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
2048 // return kFALSE;
2049 }
b8cd5251 2050 if (fCheckPointLevel > 1) {
2051 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
2052 }
6efecea1 2053 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
6e65648b 2054 }
2055
2056 // write space-points to the ESD in case alignment data output
2057 // is switched on
2058 if (fWriteAlignmentData)
2059 WriteAlignmentData(esd);
2060
2061 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2062 if (!fTracker[iDet]) continue;
b8cd5251 2063 // unload clusters
2064 fTracker[iDet]->UnloadClusters();
6efecea1 2065 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 2066 fLoader[iDet]->UnloadRecPoints();
6efecea1 2067 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 2068 }
283f39c6 2069 // stop filling residuals for TPC and ITS
3b378a42 2070 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
854c6476 2071
0f88822a 2072 eventNr++;
596a855f 2073 return kTRUE;
2074}
2075
d64bd07d 2076//_____________________________________________________________________________
2077Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
2078 //
2079 // Remove the data which are not needed for the physics analysis.
2080 //
2081
d64bd07d 2082 Int_t nTracks=esd->GetNumberOfTracks();
18571674 2083 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 2084 AliInfo
2085 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 2086
18571674 2087 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 2088 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 2089
7f68891d 2090 nTracks=esd->GetNumberOfTracks();
18571674 2091 nV0s=esd->GetNumberOfV0s();
cf37fd88 2092 AliInfo
ae5d5566 2093 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 2094
7f68891d 2095 return rc;
d64bd07d 2096}
2097
596a855f 2098//_____________________________________________________________________________
af885e0f 2099Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 2100{
2101// fill the event summary data
2102
87932dab 2103 AliCodeTimerAuto("")
0f88822a 2104 static Int_t eventNr=0;
596a855f 2105 TString detStr = detectors;
abe0c04e 2106
b8cd5251 2107 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
abe0c04e 2108 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 2109 AliReconstructor* reconstructor = GetReconstructor(iDet);
2110 if (!reconstructor) continue;
b8cd5251 2111 if (!ReadESD(esd, fgkDetectorName[iDet])) {
2112 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
b26c3770 2113 TTree* clustersTree = NULL;
d76c31f4 2114 if (fLoader[iDet]) {
b26c3770 2115 fLoader[iDet]->LoadRecPoints("read");
2116 clustersTree = fLoader[iDet]->TreeR();
2117 if (!clustersTree) {
2118 AliError(Form("Can't get the %s clusters tree",
2119 fgkDetectorName[iDet]));
2120 if (fStopOnError) return kFALSE;
2121 }
2122 }
2123 if (fRawReader && !reconstructor->HasDigitConversion()) {
2124 reconstructor->FillESD(fRawReader, clustersTree, esd);
2125 } else {
2126 TTree* digitsTree = NULL;
2127 if (fLoader[iDet]) {
2128 fLoader[iDet]->LoadDigits("read");
2129 digitsTree = fLoader[iDet]->TreeD();
2130 if (!digitsTree) {
2131 AliError(Form("Can't get the %s digits tree",
2132 fgkDetectorName[iDet]));
2133 if (fStopOnError) return kFALSE;
2134 }
2135 }
2136 reconstructor->FillESD(digitsTree, clustersTree, esd);
2137 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
2138 }
d76c31f4 2139 if (fLoader[iDet]) {
b26c3770 2140 fLoader[iDet]->UnloadRecPoints();
2141 }
2142
b8cd5251 2143 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
596a855f 2144 }
2145 }
2146
2147 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 2148 AliError(Form("the following detectors were not found: %s",
2149 detStr.Data()));
596a855f 2150 if (fStopOnError) return kFALSE;
2151 }
6efecea1 2152 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
0f88822a 2153 eventNr++;
596a855f 2154 return kTRUE;
2155}
2156
b647652d 2157//_____________________________________________________________________________
af885e0f 2158Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 2159{
2160 // Reads the trigger decision which is
2161 // stored in Trigger.root file and fills
2162 // the corresponding esd entries
2163
87932dab 2164 AliCodeTimerAuto("")
2165
b647652d 2166 AliInfo("Filling trigger information into the ESD");
2167
2168 if (fRawReader) {
2169 AliCTPRawStream input(fRawReader);
2170 if (!input.Next()) {
7e88424f 2171 AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
b647652d 2172 }
2173 else {
7e88424f 2174 if (esd->GetTriggerMask() != input.GetClassMask())
2175 AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
2176 input.GetClassMask(),esd->GetTriggerMask()));
2177 if (esd->GetOrbitNumber() != input.GetOrbitID())
2178 AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
2179 input.GetOrbitID(),esd->GetOrbitNumber()));
2180 if (esd->GetBunchCrossNumber() != input.GetBCID())
2181 AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
2182 input.GetBCID(),esd->GetBunchCrossNumber()));
b647652d 2183 }
b024fd7f 2184
7e88424f 2185 // Here one has to add the filling of trigger inputs and
2186 // interaction records
2187 // ...
b024fd7f 2188 }
b647652d 2189 return kTRUE;
2190}
596a855f 2191
001397cd 2192
2193
2194
2195
2196//_____________________________________________________________________________
af885e0f 2197Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 2198{
2199 //
2200 // Filling information from RawReader Header
2201 //
2202
151bea4e 2203 if (!fRawReader) return kFALSE;
2204
001397cd 2205 AliInfo("Filling information from RawReader Header");
151bea4e 2206
2207 esd->SetBunchCrossNumber(fRawReader->GetBCID());
2208 esd->SetOrbitNumber(fRawReader->GetOrbitID());
2209 esd->SetPeriodNumber(fRawReader->GetPeriod());
2210
2211 esd->SetTimeStamp(fRawReader->GetTimestamp());
2212 esd->SetEventType(fRawReader->GetType());
001397cd 2213
2214 return kTRUE;
2215}
2216
2217
596a855f 2218//_____________________________________________________________________________
2219Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
2220{
2221// check whether detName is contained in detectors
2222// if yes, it is removed from detectors
2223
2224 // check if all detectors are selected
2225 if ((detectors.CompareTo("ALL") == 0) ||
2226 detectors.BeginsWith("ALL ") ||
2227 detectors.EndsWith(" ALL") ||
2228 detectors.Contains(" ALL ")) {
2229 detectors = "ALL";
2230 return kTRUE;
2231 }
2232
2233 // search for the given detector
2234 Bool_t result = kFALSE;
2235 if ((detectors.CompareTo(detName) == 0) ||
2236 detectors.BeginsWith(detName+" ") ||
2237 detectors.EndsWith(" "+detName) ||
2238 detectors.Contains(" "+detName+" ")) {
2239 detectors.ReplaceAll(detName, "");
2240 result = kTRUE;
2241 }
2242
2243 // clean up the detectors string
2244 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2245 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2246 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2247
2248 return result;
2249}
e583c30d 2250
f08fc9f5 2251//_____________________________________________________________________________
2252Bool_t AliReconstruction::InitRunLoader()
2253{
2254// get or create the run loader
2255
2256 if (gAlice) delete gAlice;
2257 gAlice = NULL;
2258
b26c3770 2259 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2260 // load all base libraries to get the loader classes
2261 TString libs = gSystem->GetLibraries();
2262 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2263 TString detName = fgkDetectorName[iDet];
2264 if (detName == "HLT") continue;
2265 if (libs.Contains("lib" + detName + "base.so")) continue;
2266 gSystem->Load("lib" + detName + "base.so");
2267 }
f08fc9f5 2268 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2269 if (!fRunLoader) {
2270 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2271 CleanUp();
2272 return kFALSE;
2273 }
325aa76f 2274
b26c3770 2275 fRunLoader->CdGAFile();
325aa76f 2276 fRunLoader->LoadgAlice();
f08fc9f5 2277
6cae184e 2278 //PH This is a temporary fix to give access to the kinematics
2279 //PH that is needed for the labels of ITS clusters
f2ee4290 2280 fRunLoader->LoadHeader();
6cae184e 2281 fRunLoader->LoadKinematics();
2282
f08fc9f5 2283 } else { // galice.root does not exist
2284 if (!fRawReader) {
2285 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
2286 CleanUp();
2287 return kFALSE;
2288 }
2289 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2290 AliConfig::GetDefaultEventFolderName(),
2291 "recreate");
2292 if (!fRunLoader) {
2293 AliError(Form("could not create run loader in file %s",
2294 fGAliceFileName.Data()));
2295 CleanUp();
2296 return kFALSE;
2297 }
21a3aa09 2298 fIsNewRunLoader = kTRUE;
f08fc9f5 2299 fRunLoader->MakeTree("E");
21a3aa09 2300
973388c2 2301 if (fNumberOfEventsPerFile > 0)
2302 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2303 else
21a3aa09 2304 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 2305 }
2306
2307 return kTRUE;
2308}
2309
c757bafd 2310//_____________________________________________________________________________
b8cd5251 2311AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 2312{
f08fc9f5 2313// get the reconstructor object and the loader for a detector
c757bafd 2314
7e88424f 2315 if (fReconstructor[iDet]) {
2316 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2317 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2318 fReconstructor[iDet]->SetRecoParam(par);
2319 }
2320 return fReconstructor[iDet];
2321 }
b8cd5251 2322
2323 // load the reconstructor object
2324 TPluginManager* pluginManager = gROOT->GetPluginManager();
2325 TString detName = fgkDetectorName[iDet];
2326 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 2327
2328 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 2329
b8cd5251 2330 AliReconstructor* reconstructor = NULL;
2331 // first check if a plugin is defined for the reconstructor
2332 TPluginHandler* pluginHandler =
2333 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 2334 // if not, add a plugin for it
2335 if (!pluginHandler) {
b8cd5251 2336 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 2337 TString libs = gSystem->GetLibraries();
2338 if (libs.Contains("lib" + detName + "base.so") ||
2339 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 2340 pluginManager->AddHandler("AliReconstructor", detName,
2341 recName, detName + "rec", recName + "()");
2342 } else {
2343 pluginManager->AddHandler("AliReconstructor", detName,
2344 recName, detName, recName + "()");
c757bafd 2345 }
b8cd5251 2346 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2347 }
2348 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2349 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 2350 }
b8cd5251 2351 if (reconstructor) {
2352 TObject* obj = fOptions.FindObject(detName.Data());
2353 if (obj) reconstructor->SetOption(obj->GetTitle());
d76c31f4 2354 reconstructor->Init();
b8cd5251 2355 fReconstructor[iDet] = reconstructor;
2356 }
2357
f08fc9f5 2358 // get or create the loader
2359 if (detName != "HLT") {
2360 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2361 if (!fLoader[iDet]) {
2362 AliConfig::Instance()
2363 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2364 detName, detName);
2365 // first check if a plugin is defined for the loader
bb0901a4 2366 pluginHandler =
f08fc9f5 2367 pluginManager->FindHandler("AliLoader", detName);
2368 // if not, add a plugin for it
2369 if (!pluginHandler) {
2370 TString loaderName = "Ali" + detName + "Loader";
2371 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2372 pluginManager->AddHandler("AliLoader", detName,
2373 loaderName, detName + "base",
2374 loaderName + "(const char*, TFolder*)");
2375 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2376 }
2377 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2378 fLoader[iDet] =
2379 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2380 fRunLoader->GetEventFolder());
2381 }
2382 if (!fLoader[iDet]) { // use default loader
2383 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2384 }
2385 if (!fLoader[iDet]) {
2386 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 2387 if (fStopOnError) return NULL;
f08fc9f5 2388 } else {
2389 fRunLoader->AddLoader(fLoader[iDet]);
2390 fRunLoader->CdGAFile();
2391 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2392 fRunLoader->Write(0, TObject::kOverwrite);
2393 }
2394 }
2395 }
2396
7e88424f 2397 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2398 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2399 reconstructor->SetRecoParam(par);
2400 }
b8cd5251 2401 return reconstructor;
c757bafd 2402}
2403
2257f27e 2404//_____________________________________________________________________________
2405Bool_t AliReconstruction::CreateVertexer()
2406{
2407// create the vertexer
2408
b8cd5251 2409 fVertexer = NULL;
2410 AliReconstructor* itsReconstructor = GetReconstructor(0);
59697224 2411 if (itsReconstructor) {
d76c31f4 2412 fVertexer = itsReconstructor->CreateVertexer();
2257f27e 2413 }
b8cd5251 2414 if (!fVertexer) {
815c2b38 2415 AliWarning("couldn't create a vertexer for ITS");
2257f27e 2416 if (fStopOnError) return kFALSE;
2417 }
2418
2419 return kTRUE;
2420}
2421
24f7a148 2422//_____________________________________________________________________________
b8cd5251 2423Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 2424{
f08fc9f5 2425// create the trackers
24f7a148 2426
b8cd5251 2427 TString detStr = detectors;
2428 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2429 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2430 AliReconstructor* reconstructor = GetReconstructor(iDet);
2431 if (!reconstructor) continue;
2432 TString detName = fgkDetectorName[iDet];
1f46a9ae 2433 if (detName == "HLT") {
2434 fRunHLTTracking = kTRUE;
2435 continue;
2436 }
e66fbafb 2437 if (detName == "MUON") {
2438 fRunMuonTracking = kTRUE;
2439 continue;
2440 }
2441
f08fc9f5 2442
d76c31f4 2443 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 2444 if (!fTracker[iDet] && (iDet < 7)) {
2445 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 2446 if (fStopOnError) return kFALSE;
2447 }
6efecea1 2448 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 2449 }
2450
24f7a148 2451 return kTRUE;
2452}
2453
e583c30d 2454//_____________________________________________________________________________
b26c3770 2455void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
e583c30d 2456{
2457// delete trackers and the run loader and close and delete the file
2458
b8cd5251 2459 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2460 delete fReconstructor[iDet];
2461 fReconstructor[iDet] = NULL;
2462 fLoader[iDet] = NULL;
2463 delete fTracker[iDet];
2464 fTracker[iDet] = NULL;
2465 }
7e88424f 2466 if (fRunInfo) delete fRunInfo;
2467 fRunInfo = NULL;
2468
b8cd5251 2469 delete fVertexer;
2470 fVertexer = NULL;
21a3aa09 2471
2472 if (ftVertexer) delete ftVertexer;
2473 ftVertexer = NULL;
795e4a22 2474
2475 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
2476 delete fDiamondProfile;
2477 fDiamondProfile = NULL;
43c9dae1 2478 delete fDiamondProfileTPC;
2479 fDiamondProfileTPC = NULL;
6b6e4472 2480 delete fGRPData;
2481 fGRPData = NULL;
795e4a22 2482 }
e583c30d 2483
444753c6 2484
e583c30d 2485 delete fRunLoader;
2486 fRunLoader = NULL;
b649205a 2487 delete fRawReader;
2488 fRawReader = NULL;
cd0b062e 2489 if (fParentRawReader) delete fParentRawReader;
2490 fParentRawReader=NULL;
e583c30d 2491
2492 if (file) {
2493 file->Close();
2494 delete file;
2495 }
b26c3770 2496
2497 if (fileOld) {
2498 fileOld->Close();
2499 delete fileOld;
2500 gSystem->Unlink("AliESDs.old.root");
2501 }
21a3aa09 2502
e583c30d 2503}
24f7a148 2504
24f7a148 2505//_____________________________________________________________________________
af885e0f 2506
2507Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
24f7a148 2508{
2509// read the ESD event from a file
2510
2511 if (!esd) return kFALSE;
2512 char fileName[256];
2513 sprintf(fileName, "ESD_%d.%d_%s.root",
31fd97b2 2514 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
24f7a148 2515 if (gSystem->AccessPathName(fileName)) return kFALSE;
2516
f3a97c86 2517 AliInfo(Form("reading ESD from file %s", fileName));
815c2b38 2518 AliDebug(1, Form("reading ESD from file %s", fileName));
24f7a148 2519 TFile* file = TFile::Open(fileName);
2520 if (!file || !file->IsOpen()) {
815c2b38 2521 AliError(Form("opening %s failed", fileName));
24f7a148 2522 delete file;
2523 return kFALSE;
2524 }
2525
2526 gROOT->cd();
2527 delete esd;
af885e0f 2528 esd = (AliESDEvent*) file->Get("ESD");
24f7a148 2529 file->Close();
2530 delete file;
2531 return kTRUE;
af885e0f 2532
24f7a148 2533}
2534
af885e0f 2535
2536
24f7a148 2537//_____________________________________________________________________________
af885e0f 2538void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
24f7a148 2539{
2540// write the ESD event to a file
2541
2542 if (!esd) return;
2543 char fileName[256];
2544 sprintf(fileName, "ESD_%d.%d_%s.root",
31fd97b2 2545 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
24f7a148 2546
815c2b38 2547 AliDebug(1, Form("writing ESD to file %s", fileName));
24f7a148 2548 TFile* file = TFile::Open(fileName, "recreate");
2549 if (!file || !file->IsOpen()) {
815c2b38 2550 AliError(Form("opening %s failed", fileName));
24f7a148 2551 } else {
2552 esd->Write("ESD");
2553 file->Close();
2554 }
2555 delete file;
2556}
f3a97c86 2557
2558
af885e0f 2559void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 2560{
2561 // Write space-points which are then used in the alignment procedures
6e65648b 2562 // For the moment only ITS, TPC, TRD and TOF
98937d93 2563
98937d93 2564 Int_t ntracks = esd->GetNumberOfTracks();
2565 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2566 {
2567 AliESDtrack *track = esd->GetTrack(itrack);
2568 Int_t nsp = 0;
ef7253ac 2569 Int_t idx[200];
6e65648b 2570 for (Int_t iDet = 3; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
2571 nsp += track->GetNcls(iDet);
2572
2573 if (iDet==0) { // ITS "extra" clusters
2574 track->GetClusters(iDet,idx);
2575 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
2576 }
2577 }
2578
98937d93 2579 if (nsp) {
2580 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2581 track->SetTrackPointArray(sp);
2582 Int_t isptrack = 0;
2583 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2584 AliTracker *tracker = fTracker[iDet];
2585 if (!tracker) continue;
6e65648b 2586 Int_t nspdet = track->GetClusters(iDet,idx);
2587
2588 if (iDet==0) // ITS "extra" clusters
2589 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
2590
98937d93 2591 if (nspdet <= 0) continue;
98937d93 2592 AliTrackPoint p;
2593 Int_t isp = 0;
2594 Int_t isp2 = 0;
4ed6fb1c 2595 while (isp2 < nspdet) {
f3c6e4c9 2596 Bool_t isvalid=kTRUE;
2597
2598 Int_t index=idx[isp++];
2599 if (index < 0) continue;
2600
c12b6e44 2601 TString dets = fgkDetectorName[iDet];
2602 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2603 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2604 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2605 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
f3c6e4c9 2606 isvalid = tracker->GetTrackPointTrackingError(index,p,track);
48ce48d1 2607 } else {
f3c6e4c9 2608 isvalid = tracker->GetTrackPoint(index,p);
48ce48d1 2609 }
2610 isp2++;
98937d93 2611 if (!isvalid) continue;
f3c6e4c9 2612 sp->AddPoint(isptrack,&p); isptrack++;
98937d93 2613 }
98937d93 2614 }
2615 }
2616 }
98937d93 2617}
2e3550da 2618
2619//_____________________________________________________________________________
af885e0f 2620void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 2621{
2622 // The method reads the raw-data error log
2623 // accumulated within the rawReader.
2624 // It extracts the raw-data errors related to
2625 // the current event and stores them into
2626 // a TClonesArray inside the esd object.
2627
2628 if (!fRawReader) return;
2629
2630 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2631
2632 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2633 if (!log) continue;
2634 if (iEvent != log->GetEventNumber()) continue;
2635
2636 esd->AddRawDataErrorLog(log);
2637 }
2638
2639}
46698ae4 2640
605cb8bb 2641TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString pName){
b545009a 2642 // Dump a file content into a char in TNamed
46698ae4 2643 ifstream in;
2644 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2645 Int_t kBytes = (Int_t)in.tellg();
2646 printf("Size: %d \n",kBytes);
2647 TNamed *fn = 0;
2648 if(in.good()){
2649 char* memblock = new char [kBytes];
2650 in.seekg (0, ios::beg);
2651 in.read (memblock, kBytes);
2652 in.close();
2653 TString fData(memblock,kBytes);
605cb8bb 2654 fn = new TNamed(pName,fData);
46698ae4 2655 printf("fData Size: %d \n",fData.Sizeof());
605cb8bb 2656 printf("pName Size: %d \n",pName.Sizeof());
46698ae4 2657 printf("fn Size: %d \n",fn->Sizeof());
2658 delete[] memblock;
2659 }
2660 else{
2661 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2662 }
2663
2664 return fn;
2665}
2666
605cb8bb 2667void AliReconstruction::TNamedToFile(TTree* fTree, TString pName){
46698ae4 2668 // This is not really needed in AliReconstruction at the moment
2669 // but can serve as a template
2670
2671 TList *fList = fTree->GetUserInfo();
605cb8bb 2672 TNamed *fn = (TNamed*)fList->FindObject(pName.Data());
46698ae4 2673 printf("fn Size: %d \n",fn->Sizeof());
2674
605cb8bb 2675 TString fTmp(fn->GetName()); // to be 100% sure in principle pName also works
46698ae4 2676 const char* cdata = fn->GetTitle();
2677 printf("fTmp Size %d\n",fTmp.Sizeof());
2678
2679 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2680 printf("calculated size %d\n",size);
605cb8bb 2681 ofstream out(pName.Data(),ios::out | ios::binary);
46698ae4 2682 out.write(cdata,size);
2683 out.close();
2684
2685}
6efecea1 2686
a5fa6165 2687//_____________________________________________________________________________
ce43afbe 2688Bool_t AliReconstruction::RunQA(AliESDEvent *& esd)
7e963665 2689{
2690 // run the Quality Assurance data producer
2691
2692 AliCodeTimerAuto("")
ce43afbe 2693 TString detStr = fQADetectors ;
7e963665 2694 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2695 if (!IsSelected(fgkDetectorName[iDet], detStr))
2696 continue;
30bbd491 2697 AliQADataMaker * qadm = fQASteer->GetQADataMaker(iDet);
7e963665 2698 if (!qadm)
2699 continue;
2700 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2701 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2702
ce43afbe 2703 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
2704 qadm->Exec(AliQA::kESDS, esd) ;
2705 qadm->Increment() ;
2706 }
7e963665 2707 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2708 }
2709 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2710 AliError(Form("the following detectors were not found: %s",
2711 detStr.Data()));
2712 if (fStopOnError)
2713 return kFALSE;
2714 }
2715
2716 return kTRUE;
2717
2718}
8661738e 2719
2720//_____________________________________________________________________________
2721void AliReconstruction::CheckQA()
2722{
2723// check the QA of SIM for this run and remove the detectors
2724// with status Fatal
2725
abe0c04e 2726 TString newRunLocalReconstruction ;
2727 TString newRunTracking ;
2728 TString newFillESD ;
2729
8661738e 2730 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2731 TString detName(AliQA::GetDetName(iDet)) ;
96d67a8d 2732 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2733 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
8661738e 2734 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
abe0c04e 2735 } else {
2736 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2737 fRunLocalReconstruction.Contains("ALL") ) {
2738 newRunLocalReconstruction += detName ;
2739 newRunLocalReconstruction += " " ;
2740 }
2741 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2742 fRunTracking.Contains("ALL") ) {
2743 newRunTracking += detName ;
2744 newRunTracking += " " ;
2745 }
2746 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2747 fFillESD.Contains("ALL") ) {
2748 newFillESD += detName ;
2749 newFillESD += " " ;
8661738e 2750 }
2751 }
2752 }
abe0c04e 2753 fRunLocalReconstruction = newRunLocalReconstruction ;
2754 fRunTracking = newRunTracking ;
2755 fFillESD = newFillESD ;
a5fa6165 2756}
5b188f2f 2757
2758//_____________________________________________________________________________
2759Int_t AliReconstruction::GetDetIndex(const char* detector)
2760{
2761 // return the detector index corresponding to detector
2762 Int_t index = -1 ;
2763 for (index = 0; index < fgkNDetectors ; index++) {
2764 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2765 break ;
2766 }
2767 return index ;
2768}
7167ae53 2769//_____________________________________________________________________________
2770Bool_t AliReconstruction::FinishPlaneEff() {
2771 //
2772 // Here execute all the necessary operationis, at the end of the tracking phase,
d7f8fd68 2773 // in case that evaluation of PlaneEfficiencies was required for some detector.
2774 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
7167ae53 2775 //
2776 // This Preliminary version works only FOR ITS !!!!!
2777 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2778 //
2779 // Input: none
d7f8fd68 2780 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
7167ae53 2781 //
2782 Bool_t ret=kFALSE;
2783 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
d7f8fd68 2784 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
7167ae53 2785 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
5fbd4fd6 2786 if(fTracker[iDet]) {
d7f8fd68 2787 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2788 TString name=planeeff->GetName();
2789 name+=".root";
2790 TFile* pefile = TFile::Open(name, "RECREATE");
2791 ret=(Bool_t)planeeff->Write();
2792 pefile->Close();
5fbd4fd6 2793 if(planeeff->GetCreateHistos()) {
d7f8fd68 2794 TString hname=planeeff->GetName();
2795 hname+="Histo.root";
2796 ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
5fbd4fd6 2797 }
2798 }
7167ae53 2799 }
2800 return ret;
2801}
2802//_____________________________________________________________________________
2803Bool_t AliReconstruction::InitPlaneEff() {
2804//
2805 // Here execute all the necessary operations, before of the tracking phase,
2806 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2807 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2808 // which should be updated/recalculated.
2809 //
2810 // This Preliminary version will work only FOR ITS !!!!!
2811 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2812 //
2813 // Input: none
2814 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2815 //
2816 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));
2817 return kTRUE;
7520312d 2818}
14dd053c 2819
2820//_____________________________________________________________________________
2821Bool_t AliReconstruction::InitAliEVE()
2822{
2823 // This method should be called only in case
2824 // AliReconstruction is run
2825 // within the alieve environment.
2826 // It will initialize AliEVE in a way
2827 // so that it can visualize event processed
2828 // by AliReconstruction.
2829 // The return flag shows whenever the
2830 // AliEVE initialization was successful or not.
2831
2832 TString macroStr;
2833 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
2834 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
2835 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
2836
de33999e 2837 gROOT->ProcessLine("if (!gAliEveEvent) {gAliEveEvent = new AliEveEventManager();gAliEveEvent->SetAutoLoad(kTRUE);gAliEveEvent->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(gAliEveEvent);};");
2838 gROOT->ProcessLine("alieve_online_init()");
14dd053c 2839
2840 return kTRUE;
2841}
2842
2843//_____________________________________________________________________________
2844void AliReconstruction::RunAliEVE()
2845{
2846 // Runs AliEVE visualisation of
2847 // the current event.
2848 // Should be executed only after
2849 // successful initialization of AliEVE.
2850
2851 AliInfo("Running AliEVE...");
2852 gROOT->ProcessLine(Form("gAliEveEvent->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p);",fRunLoader,fRawReader,fesd));
2853 gROOT->ProcessLine("gAliEveEvent->StartStopAutoLoadTimer();");
2854 gSystem->Run();
2855}
ce43afbe 2856
2857//_____________________________________________________________________________
2858Bool_t AliReconstruction::SetRunQA(TString detAndAction)
2859{
2860 // Allows to run QA for a selected set of detectors
2861 // and a selected set of tasks among RAWS, RECPOINTS and ESDS
2862 // all selected detectors run the same selected tasks
2863
2864 if (!detAndAction.Contains(":")) {
2865 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
2866 fRunQA = kFALSE ;
2867 return kFALSE ;
2868 }
2869 Int_t colon = detAndAction.Index(":") ;
2870 fQADetectors = detAndAction(0, colon) ;
2871 if (fQADetectors.Contains("ALL") )
2872 fQADetectors = fFillESD ;
2873 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
2874 if (fQATasks.Contains("ALL") ) {
2875 fQATasks = Form("%d %d %d", AliQA::kRAWS, AliQA::kRECPOINTS, AliQA::kESDS) ;
2876 } else {
2877 fQATasks.ToUpper() ;
2878 TString tempo("") ;
2879 if ( fQATasks.Contains("RAW") )
2880 tempo = Form("%d ", AliQA::kRAWS) ;
2881 if ( fQATasks.Contains("RECPOINT") )
2882 tempo += Form("%d ", AliQA::kRECPOINTS) ;
2883 if ( fQATasks.Contains("ESD") )
2884 tempo += Form("%d ", AliQA::kESDS) ;
2885 fQATasks = tempo ;
2886 if (fQATasks.IsNull()) {
2887 AliInfo("No QA requested\n") ;
2888 fRunQA = kFALSE ;
2889 return kTRUE ;
2890 }
2891 }
2892 TString tempo(fQATasks) ;
2893 tempo.ReplaceAll(Form("%d", AliQA::kRAWS), AliQA::GetTaskName(AliQA::kRAWS)) ;
2894 tempo.ReplaceAll(Form("%d", AliQA::kRECPOINTS), AliQA::GetTaskName(AliQA::kRECPOINTS)) ;
2895 tempo.ReplaceAll(Form("%d", AliQA::kESDS), AliQA::GetTaskName(AliQA::kESDS)) ;
2896 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
2897 fRunQA = kTRUE ;
2898 return kTRUE;
2899}
2900
7e88424f 2901//_____________________________________________________________________________
2902Bool_t AliReconstruction::InitRecoParams()
2903{
2904 // The method accesses OCDB and retrieves all
2905 // the available reco-param objects from there.
2906
2907 Bool_t isOK = kTRUE;
2908
2909 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2910
2911 if (fRecoParam.GetDetRecoParamArray(iDet)) {
2912 AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
2913 continue;
2914 }
2915
2916 AliDebug(1, Form("Loading RecoParam objects for detector: %s",fgkDetectorName[iDet]));
2917
2918 AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
2919 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
2920 if(!entry){
2921 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
2922 isOK = kFALSE;
2923 }
2924 else {
2925 TObject *recoParamObj = entry->GetObject();
2926 if (dynamic_cast<TObjArray*>(recoParamObj)) {
2927 // The detector has a normal TobjArray of AliDetectorRecoParam objects
2928 // Registering them in AliRecoParam
2929 fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
2930 }
2931 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
2932 // The detector has only onse set of reco parameters
2933 // Registering it in AliRecoParam
2934 AliInfo(Form("Single set of reco parameters found for detector %s",fgkDetectorName[iDet]));
2935 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
2936 fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
2937 }
2938 else {
2939 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
2940 isOK = kFALSE;
2941 }
2942 entry->SetOwner(0);
2943 }
2944 }
2945
2946 return isOK;
2947}
2948
2949//_____________________________________________________________________________
2950Bool_t AliReconstruction::GetEventInfo()
2951{
2952 // Fill the event info object
2953 // ...
2954 AliCodeTimerAuto("")
2955
2956 AliCentralTrigger *aCTP = NULL;
2957 if (fRawReader) {
2958 fEventInfo.SetEventType(fRawReader->GetType());
2959
2960 ULong64_t mask = fRawReader->GetClassMask();
2961 fEventInfo.SetTriggerMask(mask);
2962 UInt_t clmask = fRawReader->GetDetectorPattern()[0];
2963 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
2964
2965 aCTP = new AliCentralTrigger();
2966 TString configstr("");
2967 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
2968 AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
2969 delete aCTP;
2970 return kFALSE;
2971 }
2972 aCTP->SetClassMask(mask);
2973 aCTP->SetClusterMask(clmask);
2974 }
2975 else {
2976 fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
2977
2978 if (fRunLoader && (!fRunLoader->LoadTrigger())) {
2979 aCTP = fRunLoader->GetTrigger();
2980 fEventInfo.SetTriggerMask(aCTP->GetClassMask());
2981 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
2982 }
2983 else {
2984 AliWarning("No trigger can be loaded! The trigger information will not be used!");
2985 return kFALSE;
2986 }
2987 }
2988
2989 AliTriggerConfiguration *config = aCTP->GetConfiguration();
2990 if (!config) {
2991 AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
2992 if (fRawReader) delete aCTP;
2993 return kFALSE;
2994 }
2995
2996 TString trclasses;
2997 ULong64_t trmask = fEventInfo.GetTriggerMask();
2998 const TObjArray& classesArray = config->GetClasses();
2999 Int_t nclasses = classesArray.GetEntriesFast();
3000 for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
3001 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
3002 if (trclass) {
3003 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
3004 fesd->SetTriggerClass(trclass->GetName(),trindex);
3005 if (trmask & (1 << trindex)) {
3006 trclasses += " ";
3007 trclasses += trclass->GetName();
3008 trclasses += " ";
3009 }
3010 }
3011 }
3012 fEventInfo.SetTriggerClasses(trclasses);
3013
3014 if (!aCTP->CheckTriggeredDetectors()) {
3015 if (fRawReader) delete aCTP;
3016 return kFALSE;
3017 }
3018
3019 if (fRawReader) delete aCTP;
3020
3021 // We have to fill also the HLT decision here!!
3022 // ...
3023
3024 return kTRUE;
3025}
3026
3027const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
3028{
3029 // Match the detector list found in the rec.C or the default 'ALL'
3030 // to the list found in the GRP (stored there by the shuttle PP which
3031 // gets the information from ECS)
3032 static TString resultList;
3033 TString detList = detectorList;
3034
3035 resultList = "";
3036
3037 for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
3038 if ((detectorMask >> iDet) & 0x1) {
3039 TString det = AliDAQ::OfflineModuleName(iDet);
3040 if ((detList.CompareTo("ALL") == 0) ||
3041 detList.BeginsWith("ALL ") ||
3042 detList.EndsWith(" ALL") ||
3043 detList.Contains(" ALL ") ||
3044 (detList.CompareTo(det) == 0) ||
3045 detList.BeginsWith(det) ||
3046 detList.EndsWith(det) ||
3047 detList.Contains( " "+det+" " )) {
3048 if (!resultList.EndsWith(det + " ")) {
3049 resultList += det;
3050 resultList += " ";
3051 }
3052 }
3053 }
3054 }
3055
3056 // HLT
3057 if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
3058 TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
3059 if ((detList.CompareTo("ALL") == 0) ||
3060 detList.BeginsWith("ALL ") ||
3061 detList.EndsWith(" ALL") ||
3062 detList.Contains(" ALL ") ||
3063 (detList.CompareTo(hltDet) == 0) ||
3064 detList.BeginsWith(hltDet) ||
3065 detList.EndsWith(hltDet) ||
3066 detList.Contains( " "+hltDet+" " )) {
3067 resultList += hltDet;
3068 }
3069 }
3070
3071 return resultList.Data();
3072
3073}