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