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