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