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