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