]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliReconstruction.cxx
Cleaning the ESD: first step
[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// //
24f7a148 104// For debug purposes the method SetCheckPointLevel can be used. If the //
105// argument is greater than 0, files with ESD events will be written after //
106// selected steps of the reconstruction for each event: //
107// level 1: after tracking and after filling of ESD (final) //
108// level 2: in addition after each tracking step //
109// level 3: in addition after the filling of ESD for each detector //
110// If a final check point file exists for an event, this event will be //
111// skipped in the reconstruction. The tracking and the filling of ESD for //
112// a detector will be skipped as well, if the corresponding check point //
113// file exists. The ESD event will then be loaded from the file instead. //
114// //
596a855f 115///////////////////////////////////////////////////////////////////////////////
116
024a7e64 117#include <TArrayF.h>
118#include <TFile.h>
119#include <TSystem.h>
120#include <TROOT.h>
121#include <TPluginManager.h>
3103d196 122#include <TGeoManager.h>
2bdb9d38 123#include <TLorentzVector.h>
596a855f 124
125#include "AliReconstruction.h"
87932dab 126#include "AliCodeTimer.h"
b8cd5251 127#include "AliReconstructor.h"
815c2b38 128#include "AliLog.h"
596a855f 129#include "AliRunLoader.h"
130#include "AliRun.h"
b649205a 131#include "AliRawReaderFile.h"
132#include "AliRawReaderDate.h"
133#include "AliRawReaderRoot.h"
001397cd 134#include "AliRawEventHeaderBase.h"
af885e0f 135#include "AliESDEvent.h"
faffd83e 136#include "AliESDMuonTrack.h"
1d99986f 137#include "AliESDfriend.h"
2257f27e 138#include "AliESDVertex.h"
faffd83e 139#include "AliESDcascade.h"
140#include "AliESDkink.h"
141#include "AliESDtrack.h"
142#include "AliESDCaloCluster.h"
32e449be 143#include "AliMultiplicity.h"
c84a5e9e 144#include "AliTracker.h"
2257f27e 145#include "AliVertexer.h"
c5e3e5d1 146#include "AliVertexerTracks.h"
5e4ff34d 147#include "AliV0vertexer.h"
148#include "AliCascadeVertexer.h"
596a855f 149#include "AliHeader.h"
150#include "AliGenEventHeader.h"
b26c3770 151#include "AliPID.h"
596a855f 152#include "AliESDpid.h"
ff8bb5ae 153#include "AliESDtrack.h"
f3a97c86 154
08e1a23e 155#include "AliESDTagCreator.h"
f3a97c86 156
25be1e5c 157#include "AliGeomManager.h"
98937d93 158#include "AliTrackPointArray.h"
b0314964 159#include "AliCDBManager.h"
6bae477a 160#include "AliCDBEntry.h"
161#include "AliAlignObj.h"
f3a97c86 162
b647652d 163#include "AliCentralTrigger.h"
164#include "AliCTPRawStream.h"
165
f29f1726 166#include "AliAODEvent.h"
167#include "AliAODHeader.h"
168#include "AliAODTrack.h"
169#include "AliAODVertex.h"
170#include "AliAODCluster.h"
171
172
596a855f 173ClassImp(AliReconstruction)
174
175
c757bafd 176//_____________________________________________________________________________
b384f8a4 177const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
c757bafd 178
596a855f 179//_____________________________________________________________________________
024cf675 180AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
e583c30d 181 const char* name, const char* title) :
182 TNamed(name, title),
183
c84a5e9e 184 fUniformField(kTRUE),
2257f27e 185 fRunVertexFinder(kTRUE),
1f46a9ae 186 fRunHLTTracking(kFALSE),
e66fbafb 187 fRunMuonTracking(kFALSE),
1d99986f 188 fStopOnError(kFALSE),
189 fWriteAlignmentData(kFALSE),
d64bd07d 190 fCleanESD(kTRUE),
1d99986f 191 fWriteESDfriend(kFALSE),
a7807689 192 fWriteAOD(kFALSE),
b647652d 193 fFillTriggerESD(kTRUE),
1d99986f 194
195 fRunLocalReconstruction("ALL"),
b8cd5251 196 fRunTracking("ALL"),
e583c30d 197 fFillESD("ALL"),
198 fGAliceFileName(gAliceFilename),
b649205a 199 fInput(""),
35042093 200 fEquipIdMap(""),
b26c3770 201 fFirstEvent(0),
202 fLastEvent(-1),
973388c2 203 fNumberOfEventsPerFile(1),
24f7a148 204 fCheckPointLevel(0),
b8cd5251 205 fOptions(),
6bae477a 206 fLoadAlignFromCDB(kTRUE),
207 fLoadAlignData("ALL"),
46698ae4 208 fESDPar(""),
e583c30d 209
210 fRunLoader(NULL),
b649205a 211 fRawReader(NULL),
b8cd5251 212
98937d93 213 fVertexer(NULL),
9178838a 214 fDiamondProfile(NULL),
98937d93 215
6bae477a 216 fAlignObjArray(NULL),
ec92bee0 217 fCDBUri(cdbUri),
218 fSpecCDBUri()
596a855f 219{
220// create reconstruction object with default parameters
b8cd5251 221
222 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
223 fReconstructor[iDet] = NULL;
224 fLoader[iDet] = NULL;
225 fTracker[iDet] = NULL;
226 }
e47c4c2e 227 AliPID pid;
596a855f 228}
229
230//_____________________________________________________________________________
231AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
e583c30d 232 TNamed(rec),
233
c84a5e9e 234 fUniformField(rec.fUniformField),
2257f27e 235 fRunVertexFinder(rec.fRunVertexFinder),
1f46a9ae 236 fRunHLTTracking(rec.fRunHLTTracking),
e66fbafb 237 fRunMuonTracking(rec.fRunMuonTracking),
1d99986f 238 fStopOnError(rec.fStopOnError),
239 fWriteAlignmentData(rec.fWriteAlignmentData),
d64bd07d 240 fCleanESD(rec.fCleanESD),
1d99986f 241 fWriteESDfriend(rec.fWriteESDfriend),
a7807689 242 fWriteAOD(rec.fWriteAOD),
b647652d 243 fFillTriggerESD(rec.fFillTriggerESD),
1d99986f 244
245 fRunLocalReconstruction(rec.fRunLocalReconstruction),
e583c30d 246 fRunTracking(rec.fRunTracking),
247 fFillESD(rec.fFillESD),
248 fGAliceFileName(rec.fGAliceFileName),
b649205a 249 fInput(rec.fInput),
35042093 250 fEquipIdMap(rec.fEquipIdMap),
b26c3770 251 fFirstEvent(rec.fFirstEvent),
252 fLastEvent(rec.fLastEvent),
973388c2 253 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
24f7a148 254 fCheckPointLevel(0),
b8cd5251 255 fOptions(),
6bae477a 256 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
257 fLoadAlignData(rec.fLoadAlignData),
46698ae4 258 fESDPar(rec.fESDPar),
e583c30d 259
260 fRunLoader(NULL),
b649205a 261 fRawReader(NULL),
b8cd5251 262
98937d93 263 fVertexer(NULL),
9178838a 264 fDiamondProfile(NULL),
98937d93 265
6bae477a 266 fAlignObjArray(rec.fAlignObjArray),
ec92bee0 267 fCDBUri(rec.fCDBUri),
268 fSpecCDBUri()
596a855f 269{
270// copy constructor
271
ec92bee0 272 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
efd2085e 273 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
274 }
b8cd5251 275 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
276 fReconstructor[iDet] = NULL;
277 fLoader[iDet] = NULL;
278 fTracker[iDet] = NULL;
279 }
ec92bee0 280 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
281 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
282 }
596a855f 283}
284
285//_____________________________________________________________________________
286AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
287{
288// assignment operator
289
290 this->~AliReconstruction();
291 new(this) AliReconstruction(rec);
292 return *this;
293}
294
295//_____________________________________________________________________________
296AliReconstruction::~AliReconstruction()
297{
298// clean up
299
e583c30d 300 CleanUp();
efd2085e 301 fOptions.Delete();
ec92bee0 302 fSpecCDBUri.Delete();
87932dab 303
304 AliCodeTimer::Instance()->Print();
596a855f 305}
306
024cf675 307//_____________________________________________________________________________
308void AliReconstruction::InitCDBStorage()
309{
310// activate a default CDB storage
311// First check if we have any CDB storage set, because it is used
312// to retrieve the calibration and alignment constants
313
314 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 315 if (man->IsDefaultStorageSet())
024cf675 316 {
317 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 318 AliWarning("Default CDB storage has been already set !");
319 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
024cf675 320 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 321 fCDBUri = "";
322 }
323 else {
b8ec52f6 324 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
325 AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
326 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 327 man->SetDefaultStorage(fCDBUri);
328 }
329
330 // Now activate the detector specific CDB storage locations
c3a7b59a 331 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
332 TObject* obj = fSpecCDBUri[i];
333 if (!obj) continue;
b8ec52f6 334 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
335 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
336 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 337 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 338 }
727d0766 339 man->Print();
024cf675 340}
341
342//_____________________________________________________________________________
343void AliReconstruction::SetDefaultStorage(const char* uri) {
ec92bee0 344// Store the desired default CDB storage location
345// Activate it later within the Run() method
024cf675 346
ec92bee0 347 fCDBUri = uri;
024cf675 348
349}
350
351//_____________________________________________________________________________
c3a7b59a 352void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 353// Store a detector-specific CDB storage location
354// Activate it later within the Run() method
024cf675 355
c3a7b59a 356 AliCDBPath aPath(calibType);
357 if(!aPath.IsValid()){
358 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
359 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
360 if(!strcmp(calibType, fgkDetectorName[iDet])) {
361 aPath.SetPath(Form("%s/*", calibType));
362 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
363 break;
364 }
365 }
366 if(!aPath.IsValid()){
367 AliError(Form("Not a valid path or detector: %s", calibType));
368 return;
369 }
370 }
371
372 // check that calibType refers to a "valid" detector name
373 Bool_t isDetector = kFALSE;
374 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
375 TString detName = fgkDetectorName[iDet];
376 if(aPath.GetLevel0() == detName) {
377 isDetector = kTRUE;
378 break;
379 }
380 }
381
382 if(!isDetector) {
383 AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
384 return;
385 }
386
387 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
ec92bee0 388 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 389 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
024cf675 390
391}
392
46698ae4 393
394
395
6bae477a 396//_____________________________________________________________________________
397Bool_t AliReconstruction::SetRunNumber()
398{
399 // The method is called in Run() in order
400 // to set a correct run number.
401 // In case of raw data reconstruction the
402 // run number is taken from the raw data header
403
404 if(AliCDBManager::Instance()->GetRun() < 0) {
405 if (!fRunLoader) {
406 AliError("No run loader is found !");
407 return kFALSE;
408 }
409 // read run number from gAlice
ec92bee0 410 if(fRunLoader->GetAliRun())
411 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
412 else {
413 if(fRawReader) {
414 if(fRawReader->NextEvent()) {
415 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
416 fRawReader->RewindEvents();
417 }
418 else {
419 AliError("No raw-data events found !");
420 return kFALSE;
421 }
422 }
423 else {
424 AliError("Neither gAlice nor RawReader objects are found !");
425 return kFALSE;
426 }
427 }
428 AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
6bae477a 429 }
430 return kTRUE;
431}
432
6bae477a 433//_____________________________________________________________________________
434Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
435{
436 // Read the alignment objects from CDB.
437 // Each detector is supposed to have the
438 // alignment objects in DET/Align/Data CDB path.
439 // All the detector objects are then collected,
440 // sorted by geometry level (starting from ALIC) and
441 // then applied to the TGeo geometry.
442 // Finally an overlaps check is performed.
443
444 // Load alignment data from CDB and fill fAlignObjArray
445 if(fLoadAlignFromCDB){
6bae477a 446
25be1e5c 447 TString detStr = detectors;
448 TString loadAlObjsListOfDets = "";
449
450 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
451 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
452 loadAlObjsListOfDets += fgkDetectorName[iDet];
453 loadAlObjsListOfDets += " ";
454 } // end loop over detectors
98e303d9 455 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
25be1e5c 456 }else{
457 // Check if the array with alignment objects was
458 // provided by the user. If yes, apply the objects
459 // to the present TGeo geometry
460 if (fAlignObjArray) {
461 if (gGeoManager && gGeoManager->IsClosed()) {
98e303d9 462 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
25be1e5c 463 AliError("The misalignment of one or more volumes failed!"
464 "Compare the list of simulated detectors and the list of detector alignment data!");
465 return kFALSE;
466 }
467 }
468 else {
469 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
6bae477a 470 return kFALSE;
471 }
472 }
6bae477a 473 }
25be1e5c 474
8e245d15 475 delete fAlignObjArray; fAlignObjArray=0;
a03b0371 476
6bae477a 477 return kTRUE;
478}
596a855f 479
480//_____________________________________________________________________________
481void AliReconstruction::SetGAliceFile(const char* fileName)
482{
483// set the name of the galice file
484
485 fGAliceFileName = fileName;
486}
487
efd2085e 488//_____________________________________________________________________________
489void AliReconstruction::SetOption(const char* detector, const char* option)
490{
491// set options for the reconstruction of a detector
492
493 TObject* obj = fOptions.FindObject(detector);
494 if (obj) fOptions.Remove(obj);
495 fOptions.Add(new TNamed(detector, option));
496}
497
596a855f 498
499//_____________________________________________________________________________
4a33489c 500Bool_t AliReconstruction::Run(const char* input)
596a855f 501{
502// run the reconstruction
503
87932dab 504 AliCodeTimerAuto("")
505
b649205a 506 // set the input
507 if (!input) input = fInput.Data();
508 TString fileName(input);
509 if (fileName.EndsWith("/")) {
510 fRawReader = new AliRawReaderFile(fileName);
511 } else if (fileName.EndsWith(".root")) {
512 fRawReader = new AliRawReaderRoot(fileName);
513 } else if (!fileName.IsNull()) {
514 fRawReader = new AliRawReaderDate(fileName);
515 fRawReader->SelectEvents(7);
516 }
35042093 517 if (!fEquipIdMap.IsNull() && fRawReader)
518 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
519
b649205a 520
f08fc9f5 521 // get the run loader
522 if (!InitRunLoader()) return kFALSE;
596a855f 523
ec92bee0 524 // Initialize the CDB storage
525 InitCDBStorage();
526
6bae477a 527 // Set run number in CDBManager (if it is not already set by the user)
528 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
529
530 // Import ideal TGeo geometry and apply misalignment
531 if (!gGeoManager) {
532 TString geom(gSystem->DirName(fGAliceFileName));
533 geom += "/geometry.root";
98e303d9 534 AliGeomManager::LoadGeometry(geom.Data());
6bae477a 535 if (!gGeoManager) if (fStopOnError) return kFALSE;
536 }
8e245d15 537
538 AliCDBManager* man = AliCDBManager::Instance();
6bae477a 539 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
540
596a855f 541 // local reconstruction
59697224 542 if (!fRunLocalReconstruction.IsNull()) {
543 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
e583c30d 544 if (fStopOnError) {CleanUp(); return kFALSE;}
596a855f 545 }
546 }
b26c3770 547// if (!fRunVertexFinder && fRunTracking.IsNull() &&
548// fFillESD.IsNull()) return kTRUE;
2257f27e 549
550 // get vertexer
551 if (fRunVertexFinder && !CreateVertexer()) {
552 if (fStopOnError) {
553 CleanUp();
554 return kFALSE;
555 }
556 }
596a855f 557
f08fc9f5 558 // get trackers
b8cd5251 559 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
24f7a148 560 if (fStopOnError) {
561 CleanUp();
562 return kFALSE;
563 }
596a855f 564 }
24f7a148 565
b26c3770 566 // get the possibly already existing ESD file and tree
af885e0f 567 AliESDEvent* esd = new AliESDEvent(); AliESDEvent* hltesd = new AliESDEvent();
b26c3770 568 TFile* fileOld = NULL;
1f46a9ae 569 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
b26c3770 570 if (!gSystem->AccessPathName("AliESDs.root")){
571 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
572 fileOld = TFile::Open("AliESDs.old.root");
573 if (fileOld && fileOld->IsOpen()) {
574 treeOld = (TTree*) fileOld->Get("esdTree");
46698ae4 575 if (treeOld)esd->ReadFromTree(treeOld);
1f46a9ae 576 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
46698ae4 577 if (hlttreeOld) hltesd->ReadFromTree(hlttreeOld);
b26c3770 578 }
579 }
580
36711aa4 581 // create the ESD output file and tree
596a855f 582 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
46698ae4 583 file->SetCompressionLevel(2);
596a855f 584 if (!file->IsOpen()) {
815c2b38 585 AliError("opening AliESDs.root failed");
b26c3770 586 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
596a855f 587 }
46698ae4 588
36711aa4 589 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
af885e0f 590 esd = new AliESDEvent();
46698ae4 591 esd->CreateStdContent();
592 esd->WriteToTree(tree);
593
1f46a9ae 594 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
af885e0f 595 hltesd = new AliESDEvent();
46698ae4 596 hltesd->CreateStdContent();
597 hltesd->WriteToTree(hlttree);
598
599 /* CKB Why?
1f46a9ae 600 delete esd; delete hltesd;
601 esd = NULL; hltesd = NULL;
46698ae4 602 */
500d54ab 603 // create the branch with ESD additions
5728d3d5 604
605
606
46698ae4 607 AliESDfriend *esdf = 0;
1d99986f 608 if (fWriteESDfriend) {
46698ae4 609 esdf = new AliESDfriend();
610 TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf);
611 br->SetFile("AliESDfriends.root");
612 esd->AddObject(esdf);
1d99986f 613 }
5728d3d5 614
46698ae4 615
17c86e90 616 // Get the diamond profile from OCDB
617 AliCDBEntry* entry = AliCDBManager::Instance()
618 ->Get("GRP/Calib/MeanVertex");
619
620 if(entry) {
621 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
622 } else {
623 AliError("No diamond profile found in OCDB!");
624 }
625
20e5681c 626 AliVertexerTracks tVertexer(AliTracker::GetBz());
9178838a 627 if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
c5e3e5d1 628
596a855f 629 // loop over events
b649205a 630 if (fRawReader) fRawReader->RewindEvents();
f08fc9f5 631
596a855f 632 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
b26c3770 633 if (fRawReader) fRawReader->NextEvent();
4a33489c 634 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
b26c3770 635 // copy old ESD to the new one
636 if (treeOld) {
46698ae4 637 esd->ReadFromTree(treeOld);
b26c3770 638 treeOld->GetEntry(iEvent);
639 }
640 tree->Fill();
1f46a9ae 641 if (hlttreeOld) {
46698ae4 642 esd->ReadFromTree(hlttreeOld);
1f46a9ae 643 hlttreeOld->GetEntry(iEvent);
644 }
645 hlttree->Fill();
b26c3770 646 continue;
647 }
46698ae4 648
815c2b38 649 AliInfo(Form("processing event %d", iEvent));
596a855f 650 fRunLoader->GetEvent(iEvent);
24f7a148 651
bb0901a4 652 char aFileName[256];
653 sprintf(aFileName, "ESD_%d.%d_final.root",
f08fc9f5 654 fRunLoader->GetHeader()->GetRun(),
655 fRunLoader->GetHeader()->GetEventNrInRun());
bb0901a4 656 if (!gSystem->AccessPathName(aFileName)) continue;
24f7a148 657
b26c3770 658 // local reconstruction
659 if (!fRunLocalReconstruction.IsNull()) {
660 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
661 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
662 }
663 }
664
46698ae4 665
f08fc9f5 666 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1f46a9ae 667 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
31fd97b2 668 esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
669 hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
46698ae4 670
d6ee376f 671 // Set magnetic field from the tracker
672 esd->SetMagneticField(AliTracker::GetBz());
673 hltesd->SetMagneticField(AliTracker::GetBz());
596a855f 674
46698ae4 675
676
2e3550da 677 // Fill raw-data error log into the ESD
678 if (fRawReader) FillRawDataErrorLog(iEvent,esd);
679
2257f27e 680 // vertex finder
681 if (fRunVertexFinder) {
682 if (!ReadESD(esd, "vertex")) {
683 if (!RunVertexFinder(esd)) {
b26c3770 684 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
2257f27e 685 }
686 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
687 }
688 }
689
1f46a9ae 690 // HLT tracking
691 if (!fRunTracking.IsNull()) {
692 if (fRunHLTTracking) {
693 hltesd->SetVertex(esd->GetVertex());
694 if (!RunHLTTracking(hltesd)) {
695 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
696 }
697 }
698 }
699
e66fbafb 700 // Muon tracking
b8cd5251 701 if (!fRunTracking.IsNull()) {
e66fbafb 702 if (fRunMuonTracking) {
761350a6 703 if (!RunMuonTracking(esd)) {
b26c3770 704 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
24f7a148 705 }
596a855f 706 }
707 }
708
e66fbafb 709 // barrel tracking
710 if (!fRunTracking.IsNull()) {
21c573b7 711 if (!ReadESD(esd, "tracking")) {
712 if (!RunTracking(esd)) {
713 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
e66fbafb 714 }
21c573b7 715 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
e66fbafb 716 }
717 }
21c573b7 718
596a855f 719 // fill ESD
720 if (!fFillESD.IsNull()) {
721 if (!FillESD(esd, fFillESD)) {
b26c3770 722 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
596a855f 723 }
724 }
001397cd 725 // fill Event header information from the RawEventHeader
726 if (fRawReader){FillRawEventHeaderESD(esd);}
596a855f 727
728 // combined PID
729 AliESDpid::MakePID(esd);
24f7a148 730 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
596a855f 731
b647652d 732 if (fFillTriggerESD) {
733 if (!ReadESD(esd, "trigger")) {
734 if (!FillTriggerESD(esd)) {
735 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
736 }
737 if (fCheckPointLevel > 1) WriteESD(esd, "trigger");
738 }
739 }
740
a03cd2e0 741 //Try to improve the reconstructed primary vertex position using the tracks
c060d7fe 742 AliESDVertex *pvtx=0;
743 Bool_t dovertex=kTRUE;
744 TObject* obj = fOptions.FindObject("ITS");
745 if (obj) {
746 TString optITS = obj->GetTitle();
747 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
748 dovertex=kFALSE;
749 }
750 if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
17c86e90 751 if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
752
a03cd2e0 753 if (pvtx)
754 if (pvtx->GetStatus()) {
755 // Store the improved primary vertex
756 esd->SetPrimaryVertex(pvtx);
757 // Propagate the tracks to the DCA to the improved primary vertex
758 Double_t somethingbig = 777.;
759 Double_t bz = esd->GetMagneticField();
760 Int_t nt=esd->GetNumberOfTracks();
761 while (nt--) {
762 AliESDtrack *t = esd->GetTrack(nt);
763 t->RelateToVertex(pvtx, bz, somethingbig);
764 }
765 }
c5e3e5d1 766
5e4ff34d 767 {
768 // V0 finding
769 AliV0vertexer vtxer;
770 vtxer.Tracks2V0vertices(esd);
771
772 // Cascade finding
773 AliCascadeVertexer cvtxer;
774 cvtxer.V0sTracks2CascadeVertices(esd);
775 }
776
596a855f 777 // write ESD
d64bd07d 778 if (fCleanESD) CleanESD(esd);
1d99986f 779 if (fWriteESDfriend) {
46698ae4 780 new (esdf) AliESDfriend(); // Reset...
781 esd->GetESDfriend(esdf);
1d99986f 782 }
500d54ab 783 tree->Fill();
784
785 // write HLT ESD
786 hlttree->Fill();
1d99986f 787
f3a97c86 788 if (fCheckPointLevel > 0) WriteESD(esd, "final");
46698ae4 789 esd->Reset();
790 hltesd->Reset();
5728d3d5 791 if (fWriteESDfriend) {
792 new (esdf) AliESDfriend(); // Reset...
793 }
46698ae4 794 // esdf->Reset();
795 // delete esdf; esdf = 0;
796 }
797
798
5728d3d5 799
800
46698ae4 801 tree->GetUserInfo()->Add(esd);
802 hlttree->GetUserInfo()->Add(hltesd);
803
804
805
806 if(fESDPar.Contains("ESD.par")){
807 AliInfo("Attaching ESD.par to Tree");
808 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
809 tree->GetUserInfo()->Add(fn);
596a855f 810 }
811
46698ae4 812
36711aa4 813 file->cd();
a9c0e6db 814 if (fWriteESDfriend)
815 tree->SetBranchStatus("ESDfriend*",0);
36711aa4 816 tree->Write();
1f46a9ae 817 hlttree->Write();
f3a97c86 818
a7807689 819 if (fWriteAOD) {
f29f1726 820 TFile *aodFile = TFile::Open("AliAOD.root", "RECREATE");
821 ESDFile2AODFile(file, aodFile);
822 aodFile->Close();
a7807689 823 }
824
46698ae4 825 gROOT->cd();
151e0c96 826 CleanUp(file, fileOld);
827
f3a97c86 828 // Create tags for the events in the ESD tree (the ESD tree is always present)
829 // In case of empty events the tags will contain dummy values
08e1a23e 830 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
831 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent);
f575f960 832 //if (fWriteAOD) tagCreator->CreateAODTags(fFirstEvent,fLastEvent);
596a855f 833
834 return kTRUE;
835}
836
837
838//_____________________________________________________________________________
59697224 839Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
596a855f 840{
59697224 841// run the local reconstruction
596a855f 842
87932dab 843 AliCodeTimerAuto("")
030b532d 844
8e245d15 845 AliCDBManager* man = AliCDBManager::Instance();
846 Bool_t origCache = man->GetCacheFlag();
847
596a855f 848 TString detStr = detectors;
b8cd5251 849 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
850 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
851 AliReconstructor* reconstructor = GetReconstructor(iDet);
852 if (!reconstructor) continue;
b26c3770 853 if (reconstructor->HasLocalReconstruction()) continue;
b8cd5251 854
87932dab 855 AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
b8cd5251 856 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
87932dab 857
858 AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
8e245d15 859 AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
860
861 man->SetCacheFlag(kTRUE);
862 TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
863 man->GetAll(calibPath); // entries are cached!
864
87932dab 865 AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
866
b8cd5251 867 if (fRawReader) {
868 fRawReader->RewindEvents();
869 reconstructor->Reconstruct(fRunLoader, fRawReader);
870 } else {
871 reconstructor->Reconstruct(fRunLoader);
596a855f 872 }
87932dab 873
874 AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
8e245d15 875
876 // unload calibration data
98e303d9 877 man->UnloadFromCache(calibPath);
878 //man->ClearCache();
596a855f 879 }
880
8e245d15 881 man->SetCacheFlag(origCache);
882
596a855f 883 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 884 AliError(Form("the following detectors were not found: %s",
885 detStr.Data()));
596a855f 886 if (fStopOnError) return kFALSE;
887 }
888
889 return kTRUE;
890}
891
b26c3770 892//_____________________________________________________________________________
893Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
894{
895// run the local reconstruction
896
87932dab 897 AliCodeTimerAuto("")
b26c3770 898
899 TString detStr = detectors;
900 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
901 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
902 AliReconstructor* reconstructor = GetReconstructor(iDet);
903 if (!reconstructor) continue;
904 AliLoader* loader = fLoader[iDet];
905
906 // conversion of digits
907 if (fRawReader && reconstructor->HasDigitConversion()) {
908 AliInfo(Form("converting raw data digits into root objects for %s",
909 fgkDetectorName[iDet]));
87932dab 910 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
911 fgkDetectorName[iDet]));
b26c3770 912 loader->LoadDigits("update");
913 loader->CleanDigits();
914 loader->MakeDigitsContainer();
915 TTree* digitsTree = loader->TreeD();
916 reconstructor->ConvertDigits(fRawReader, digitsTree);
917 loader->WriteDigits("OVERWRITE");
918 loader->UnloadDigits();
b26c3770 919 }
920
921 // local reconstruction
922 if (!reconstructor->HasLocalReconstruction()) continue;
923 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
87932dab 924 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
b26c3770 925 loader->LoadRecPoints("update");
926 loader->CleanRecPoints();
927 loader->MakeRecPointsContainer();
928 TTree* clustersTree = loader->TreeR();
929 if (fRawReader && !reconstructor->HasDigitConversion()) {
930 reconstructor->Reconstruct(fRawReader, clustersTree);
931 } else {
932 loader->LoadDigits("read");
933 TTree* digitsTree = loader->TreeD();
934 if (!digitsTree) {
935 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
936 if (fStopOnError) return kFALSE;
937 } else {
938 reconstructor->Reconstruct(digitsTree, clustersTree);
939 }
940 loader->UnloadDigits();
941 }
942 loader->WriteRecPoints("OVERWRITE");
943 loader->UnloadRecPoints();
b26c3770 944 }
945
946 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
947 AliError(Form("the following detectors were not found: %s",
948 detStr.Data()));
949 if (fStopOnError) return kFALSE;
950 }
5f8272e1 951
b26c3770 952 return kTRUE;
953}
954
596a855f 955//_____________________________________________________________________________
af885e0f 956Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 957{
958// run the barrel tracking
959
87932dab 960 AliCodeTimerAuto("")
030b532d 961
2257f27e 962 AliESDVertex* vertex = NULL;
963 Double_t vtxPos[3] = {0, 0, 0};
964 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
965 TArrayF mcVertex(3);
a6b0b91b 966 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
967 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
968 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
969 }
2257f27e 970
b8cd5251 971 if (fVertexer) {
17c86e90 972 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
815c2b38 973 AliInfo("running the ITS vertex finder");
b26c3770 974 if (fLoader[0]) fLoader[0]->LoadRecPoints();
b8cd5251 975 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
b26c3770 976 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
2257f27e 977 if(!vertex){
815c2b38 978 AliWarning("Vertex not found");
c710f220 979 vertex = new AliESDVertex();
d1a50cb5 980 vertex->SetName("default");
2257f27e 981 }
982 else {
d1a50cb5 983 vertex->SetName("reconstructed");
2257f27e 984 }
985
986 } else {
815c2b38 987 AliInfo("getting the primary vertex from MC");
2257f27e 988 vertex = new AliESDVertex(vtxPos, vtxErr);
989 }
990
991 if (vertex) {
992 vertex->GetXYZ(vtxPos);
993 vertex->GetSigmaXYZ(vtxErr);
994 } else {
815c2b38 995 AliWarning("no vertex reconstructed");
2257f27e 996 vertex = new AliESDVertex(vtxPos, vtxErr);
997 }
998 esd->SetVertex(vertex);
32e449be 999 // if SPD multiplicity has been determined, it is stored in the ESD
25be1e5c 1000 AliMultiplicity *mult = fVertexer->GetMultiplicity();
32e449be 1001 if(mult)esd->SetMultiplicity(mult);
1002
b8cd5251 1003 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1004 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1005 }
2257f27e 1006 delete vertex;
1007
2257f27e 1008 return kTRUE;
1009}
1010
1f46a9ae 1011//_____________________________________________________________________________
af885e0f 1012Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 1013{
1014// run the HLT barrel tracking
1015
87932dab 1016 AliCodeTimerAuto("")
1f46a9ae 1017
1018 if (!fRunLoader) {
1019 AliError("Missing runLoader!");
1020 return kFALSE;
1021 }
1022
1023 AliInfo("running HLT tracking");
1024
1025 // Get a pointer to the HLT reconstructor
1026 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1027 if (!reconstructor) return kFALSE;
1028
1029 // TPC + ITS
1030 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1031 TString detName = fgkDetectorName[iDet];
1032 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1033 reconstructor->SetOption(detName.Data());
1034 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1035 if (!tracker) {
1036 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1037 if (fStopOnError) return kFALSE;
9dcc06e1 1038 continue;
1f46a9ae 1039 }
1040 Double_t vtxPos[3];
1041 Double_t vtxErr[3]={0.005,0.005,0.010};
1042 const AliESDVertex *vertex = esd->GetVertex();
1043 vertex->GetXYZ(vtxPos);
1044 tracker->SetVertex(vtxPos,vtxErr);
1045 if(iDet != 1) {
1046 fLoader[iDet]->LoadRecPoints("read");
1047 TTree* tree = fLoader[iDet]->TreeR();
1048 if (!tree) {
1049 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1050 return kFALSE;
1051 }
1052 tracker->LoadClusters(tree);
1053 }
1054 if (tracker->Clusters2Tracks(esd) != 0) {
1055 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1056 return kFALSE;
1057 }
1058 if(iDet != 1) {
1059 tracker->UnloadClusters();
1060 }
1061 delete tracker;
1062 }
1063
1f46a9ae 1064 return kTRUE;
1065}
1066
e66fbafb 1067//_____________________________________________________________________________
af885e0f 1068Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 1069{
1070// run the muon spectrometer tracking
1071
87932dab 1072 AliCodeTimerAuto("")
e66fbafb 1073
1074 if (!fRunLoader) {
1075 AliError("Missing runLoader!");
1076 return kFALSE;
1077 }
1078 Int_t iDet = 7; // for MUON
1079
1080 AliInfo("is running...");
1081
1082 // Get a pointer to the MUON reconstructor
1083 AliReconstructor *reconstructor = GetReconstructor(iDet);
1084 if (!reconstructor) return kFALSE;
1085
1086
1087 TString detName = fgkDetectorName[iDet];
1088 AliDebug(1, Form("%s tracking", detName.Data()));
1089 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1090 if (!tracker) {
1091 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1092 return kFALSE;
1093 }
1094
1095 // create Tracks
1096 fLoader[iDet]->LoadTracks("update");
1097 fLoader[iDet]->CleanTracks();
1098 fLoader[iDet]->MakeTracksContainer();
1099
1100 // read RecPoints
761350a6 1101 fLoader[iDet]->LoadRecPoints("read");
1102 tracker->LoadClusters(fLoader[iDet]->TreeR());
1103
1104 Int_t rv = tracker->Clusters2Tracks(esd);
1105
1106 fLoader[iDet]->UnloadRecPoints();
1107
1108 if ( rv )
1109 {
e66fbafb 1110 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1111 return kFALSE;
1112 }
761350a6 1113
1114 tracker->UnloadClusters();
1115
e66fbafb 1116 fLoader[iDet]->UnloadRecPoints();
1117
1118 fLoader[iDet]->WriteTracks("OVERWRITE");
1119 fLoader[iDet]->UnloadTracks();
1120
1121 delete tracker;
1122
e66fbafb 1123 return kTRUE;
1124}
1125
1126
2257f27e 1127//_____________________________________________________________________________
af885e0f 1128Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
2257f27e 1129{
1130// run the barrel tracking
1131
87932dab 1132 AliCodeTimerAuto("")
24f7a148 1133
815c2b38 1134 AliInfo("running tracking");
596a855f 1135
91b876d1 1136 //Fill the ESD with the T0 info (will be used by the TOF)
1f4331b3 1137 if (fReconstructor[11])
1138 GetReconstructor(11)->FillESD(fRunLoader, esd);
91b876d1 1139
b8cd5251 1140 // pass 1: TPC + ITS inwards
1141 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1142 if (!fTracker[iDet]) continue;
1143 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 1144
b8cd5251 1145 // load clusters
1146 fLoader[iDet]->LoadRecPoints("read");
1147 TTree* tree = fLoader[iDet]->TreeR();
1148 if (!tree) {
1149 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 1150 return kFALSE;
1151 }
b8cd5251 1152 fTracker[iDet]->LoadClusters(tree);
1153
1154 // run tracking
1155 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1156 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 1157 return kFALSE;
1158 }
b8cd5251 1159 if (fCheckPointLevel > 1) {
1160 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1161 }
878e1fe1 1162 // preliminary PID in TPC needed by the ITS tracker
1163 if (iDet == 1) {
1164 GetReconstructor(1)->FillESD(fRunLoader, esd);
b26c3770 1165 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
878e1fe1 1166 AliESDpid::MakePID(esd);
1167 }
b8cd5251 1168 }
596a855f 1169
b8cd5251 1170 // pass 2: ALL backwards
1171 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1172 if (!fTracker[iDet]) continue;
1173 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1174
1175 // load clusters
1176 if (iDet > 1) { // all except ITS, TPC
1177 TTree* tree = NULL;
7b61cd9c 1178 fLoader[iDet]->LoadRecPoints("read");
1179 tree = fLoader[iDet]->TreeR();
b8cd5251 1180 if (!tree) {
1181 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 1182 return kFALSE;
1183 }
b8cd5251 1184 fTracker[iDet]->LoadClusters(tree);
1185 }
24f7a148 1186
b8cd5251 1187 // run tracking
1188 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1189 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 1190 // return kFALSE;
b8cd5251 1191 }
1192 if (fCheckPointLevel > 1) {
1193 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1194 }
24f7a148 1195
b8cd5251 1196 // unload clusters
1197 if (iDet > 2) { // all except ITS, TPC, TRD
1198 fTracker[iDet]->UnloadClusters();
7b61cd9c 1199 fLoader[iDet]->UnloadRecPoints();
b8cd5251 1200 }
8f37df88 1201 // updated PID in TPC needed by the ITS tracker -MI
1202 if (iDet == 1) {
1203 GetReconstructor(1)->FillESD(fRunLoader, esd);
1204 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1205 AliESDpid::MakePID(esd);
1206 }
b8cd5251 1207 }
596a855f 1208
98937d93 1209 // write space-points to the ESD in case alignment data output
1210 // is switched on
1211 if (fWriteAlignmentData)
1212 WriteAlignmentData(esd);
1213
b8cd5251 1214 // pass 3: TRD + TPC + ITS refit inwards
1215 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1216 if (!fTracker[iDet]) continue;
1217 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 1218
b8cd5251 1219 // run tracking
1220 if (fTracker[iDet]->RefitInward(esd) != 0) {
1221 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 1222 // return kFALSE;
b8cd5251 1223 }
1224 if (fCheckPointLevel > 1) {
1225 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1226 }
596a855f 1227
b8cd5251 1228 // unload clusters
1229 fTracker[iDet]->UnloadClusters();
1230 fLoader[iDet]->UnloadRecPoints();
1231 }
ff8bb5ae 1232 //
1233 // Propagate track to the vertex - if not done by ITS
1234 //
1235 Int_t ntracks = esd->GetNumberOfTracks();
1236 for (Int_t itrack=0; itrack<ntracks; itrack++){
1237 const Double_t kRadius = 3; // beam pipe radius
1238 const Double_t kMaxStep = 5; // max step
1239 const Double_t kMaxD = 123456; // max distance to prim vertex
1240 Double_t fieldZ = AliTracker::GetBz(); //
1241 AliESDtrack * track = esd->GetTrack(itrack);
1242 if (!track) continue;
1243 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
a28195f7 1244 track->PropagateTo(kRadius, fieldZ, track->GetMass(),kMaxStep,kTRUE);
ff8bb5ae 1245 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1246 }
1247
596a855f 1248 return kTRUE;
1249}
1250
d64bd07d 1251//_____________________________________________________________________________
1252Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1253 //
1254 // Remove the data which are not needed for the physics analysis.
1255 //
1256
1257 AliInfo("Cleaning the ESD...");
1258
1259 const AliESDVertex *vertex=esd->GetVertex();
1260 Double_t vz=vertex->GetZv();
1261
1262 Int_t nTracks=esd->GetNumberOfTracks();
1263 for (Int_t i=0; i<nTracks; i++) {
1264 AliESDtrack *track=esd->GetTrack(i);
1265
1266 Float_t xy,z; track->GetImpactParameters(xy,z);
1267 if (TMath::Abs(xy) < 50.) continue;
1268 if (vertex->GetStatus())
1269 if (TMath::Abs(vz-z) < 5.) continue;
1270
1271 esd->RemoveTrack(i);
1272 }
1273
1274 return kTRUE;
1275}
1276
596a855f 1277//_____________________________________________________________________________
af885e0f 1278Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 1279{
1280// fill the event summary data
1281
87932dab 1282 AliCodeTimerAuto("")
030b532d 1283
596a855f 1284 TString detStr = detectors;
b8cd5251 1285 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1286 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1287 AliReconstructor* reconstructor = GetReconstructor(iDet);
1288 if (!reconstructor) continue;
1289
1290 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1291 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
b26c3770 1292 TTree* clustersTree = NULL;
1293 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1294 fLoader[iDet]->LoadRecPoints("read");
1295 clustersTree = fLoader[iDet]->TreeR();
1296 if (!clustersTree) {
1297 AliError(Form("Can't get the %s clusters tree",
1298 fgkDetectorName[iDet]));
1299 if (fStopOnError) return kFALSE;
1300 }
1301 }
1302 if (fRawReader && !reconstructor->HasDigitConversion()) {
1303 reconstructor->FillESD(fRawReader, clustersTree, esd);
1304 } else {
1305 TTree* digitsTree = NULL;
1306 if (fLoader[iDet]) {
1307 fLoader[iDet]->LoadDigits("read");
1308 digitsTree = fLoader[iDet]->TreeD();
1309 if (!digitsTree) {
1310 AliError(Form("Can't get the %s digits tree",
1311 fgkDetectorName[iDet]));
1312 if (fStopOnError) return kFALSE;
1313 }
1314 }
1315 reconstructor->FillESD(digitsTree, clustersTree, esd);
1316 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1317 }
1318 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1319 fLoader[iDet]->UnloadRecPoints();
1320 }
1321
b8cd5251 1322 if (fRawReader) {
1323 reconstructor->FillESD(fRunLoader, fRawReader, esd);
1324 } else {
1325 reconstructor->FillESD(fRunLoader, esd);
24f7a148 1326 }
b8cd5251 1327 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
596a855f 1328 }
1329 }
1330
1331 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 1332 AliError(Form("the following detectors were not found: %s",
1333 detStr.Data()));
596a855f 1334 if (fStopOnError) return kFALSE;
1335 }
1336
1337 return kTRUE;
1338}
1339
b647652d 1340//_____________________________________________________________________________
af885e0f 1341Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 1342{
1343 // Reads the trigger decision which is
1344 // stored in Trigger.root file and fills
1345 // the corresponding esd entries
1346
87932dab 1347 AliCodeTimerAuto("")
1348
b647652d 1349 AliInfo("Filling trigger information into the ESD");
1350
1351 if (fRawReader) {
1352 AliCTPRawStream input(fRawReader);
1353 if (!input.Next()) {
1354 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1355 return kFALSE;
1356 }
1357 esd->SetTriggerMask(input.GetClassMask());
1358 esd->SetTriggerCluster(input.GetClusterMask());
1359 }
1360 else {
1361 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1362 if (runloader) {
1363 if (!runloader->LoadTrigger()) {
1364 AliCentralTrigger *aCTP = runloader->GetTrigger();
1365 esd->SetTriggerMask(aCTP->GetClassMask());
1366 esd->SetTriggerCluster(aCTP->GetClusterMask());
1367 }
1368 else {
1369 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1370 return kFALSE;
1371 }
1372 }
1373 else {
1374 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1375 return kFALSE;
1376 }
1377 }
1378
1379 return kTRUE;
1380}
596a855f 1381
001397cd 1382
1383
1384
1385
1386//_____________________________________________________________________________
af885e0f 1387Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 1388{
1389 //
1390 // Filling information from RawReader Header
1391 //
1392
1393 AliInfo("Filling information from RawReader Header");
31fd97b2 1394 esd->SetBunchCrossNumber(0);
1395 esd->SetOrbitNumber(0);
9bcc1e45 1396 esd->SetPeriodNumber(0);
001397cd 1397 esd->SetTimeStamp(0);
1398 esd->SetEventType(0);
1399 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1400 if (eventHeader){
9bcc1e45 1401
1402 const UInt_t *id = eventHeader->GetP("Id");
1403 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1404 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1405 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1406
001397cd 1407 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
31fd97b2 1408 esd->SetEventType((eventHeader->Get("Type")));
001397cd 1409 }
1410
1411 return kTRUE;
1412}
1413
1414
596a855f 1415//_____________________________________________________________________________
1416Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1417{
1418// check whether detName is contained in detectors
1419// if yes, it is removed from detectors
1420
1421 // check if all detectors are selected
1422 if ((detectors.CompareTo("ALL") == 0) ||
1423 detectors.BeginsWith("ALL ") ||
1424 detectors.EndsWith(" ALL") ||
1425 detectors.Contains(" ALL ")) {
1426 detectors = "ALL";
1427 return kTRUE;
1428 }
1429
1430 // search for the given detector
1431 Bool_t result = kFALSE;
1432 if ((detectors.CompareTo(detName) == 0) ||
1433 detectors.BeginsWith(detName+" ") ||
1434 detectors.EndsWith(" "+detName) ||
1435 detectors.Contains(" "+detName+" ")) {
1436 detectors.ReplaceAll(detName, "");
1437 result = kTRUE;
1438 }
1439
1440 // clean up the detectors string
1441 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1442 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1443 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1444
1445 return result;
1446}
e583c30d 1447
f08fc9f5 1448//_____________________________________________________________________________
1449Bool_t AliReconstruction::InitRunLoader()
1450{
1451// get or create the run loader
1452
1453 if (gAlice) delete gAlice;
1454 gAlice = NULL;
1455
b26c3770 1456 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1457 // load all base libraries to get the loader classes
1458 TString libs = gSystem->GetLibraries();
1459 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1460 TString detName = fgkDetectorName[iDet];
1461 if (detName == "HLT") continue;
1462 if (libs.Contains("lib" + detName + "base.so")) continue;
1463 gSystem->Load("lib" + detName + "base.so");
1464 }
f08fc9f5 1465 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1466 if (!fRunLoader) {
1467 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1468 CleanUp();
1469 return kFALSE;
1470 }
b26c3770 1471 fRunLoader->CdGAFile();
1472 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1473 if (fRunLoader->LoadgAlice() == 0) {
1474 gAlice = fRunLoader->GetAliRun();
c84a5e9e 1475 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
b26c3770 1476 }
f08fc9f5 1477 }
1478 if (!gAlice && !fRawReader) {
1479 AliError(Form("no gAlice object found in file %s",
1480 fGAliceFileName.Data()));
1481 CleanUp();
1482 return kFALSE;
1483 }
1484
1485 } else { // galice.root does not exist
1486 if (!fRawReader) {
1487 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1488 CleanUp();
1489 return kFALSE;
1490 }
1491 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1492 AliConfig::GetDefaultEventFolderName(),
1493 "recreate");
1494 if (!fRunLoader) {
1495 AliError(Form("could not create run loader in file %s",
1496 fGAliceFileName.Data()));
1497 CleanUp();
1498 return kFALSE;
1499 }
1500 fRunLoader->MakeTree("E");
1501 Int_t iEvent = 0;
1502 while (fRawReader->NextEvent()) {
1503 fRunLoader->SetEventNumber(iEvent);
1504 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1505 iEvent, iEvent);
1506 fRunLoader->MakeTree("H");
1507 fRunLoader->TreeE()->Fill();
1508 iEvent++;
1509 }
1510 fRawReader->RewindEvents();
973388c2 1511 if (fNumberOfEventsPerFile > 0)
1512 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
1513 else
1514 fRunLoader->SetNumberOfEventsPerFile(iEvent);
f08fc9f5 1515 fRunLoader->WriteHeader("OVERWRITE");
1516 fRunLoader->CdGAFile();
1517 fRunLoader->Write(0, TObject::kOverwrite);
1518// AliTracker::SetFieldMap(???);
1519 }
1520
1521 return kTRUE;
1522}
1523
c757bafd 1524//_____________________________________________________________________________
b8cd5251 1525AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 1526{
f08fc9f5 1527// get the reconstructor object and the loader for a detector
c757bafd 1528
b8cd5251 1529 if (fReconstructor[iDet]) return fReconstructor[iDet];
1530
1531 // load the reconstructor object
1532 TPluginManager* pluginManager = gROOT->GetPluginManager();
1533 TString detName = fgkDetectorName[iDet];
1534 TString recName = "Ali" + detName + "Reconstructor";
f08fc9f5 1535 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
b8cd5251 1536
1537 if (detName == "HLT") {
1538 if (!gROOT->GetClass("AliLevel3")) {
4aa41877 1539 gSystem->Load("libAliHLTSrc.so");
1540 gSystem->Load("libAliHLTMisc.so");
1541 gSystem->Load("libAliHLTHough.so");
1542 gSystem->Load("libAliHLTComp.so");
b8cd5251 1543 }
1544 }
1545
1546 AliReconstructor* reconstructor = NULL;
1547 // first check if a plugin is defined for the reconstructor
1548 TPluginHandler* pluginHandler =
1549 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 1550 // if not, add a plugin for it
1551 if (!pluginHandler) {
b8cd5251 1552 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 1553 TString libs = gSystem->GetLibraries();
1554 if (libs.Contains("lib" + detName + "base.so") ||
1555 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 1556 pluginManager->AddHandler("AliReconstructor", detName,
1557 recName, detName + "rec", recName + "()");
1558 } else {
1559 pluginManager->AddHandler("AliReconstructor", detName,
1560 recName, detName, recName + "()");
c757bafd 1561 }
b8cd5251 1562 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1563 }
1564 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1565 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 1566 }
b8cd5251 1567 if (reconstructor) {
1568 TObject* obj = fOptions.FindObject(detName.Data());
1569 if (obj) reconstructor->SetOption(obj->GetTitle());
b26c3770 1570 reconstructor->Init(fRunLoader);
b8cd5251 1571 fReconstructor[iDet] = reconstructor;
1572 }
1573
f08fc9f5 1574 // get or create the loader
1575 if (detName != "HLT") {
1576 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1577 if (!fLoader[iDet]) {
1578 AliConfig::Instance()
1579 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1580 detName, detName);
1581 // first check if a plugin is defined for the loader
bb0901a4 1582 pluginHandler =
f08fc9f5 1583 pluginManager->FindHandler("AliLoader", detName);
1584 // if not, add a plugin for it
1585 if (!pluginHandler) {
1586 TString loaderName = "Ali" + detName + "Loader";
1587 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1588 pluginManager->AddHandler("AliLoader", detName,
1589 loaderName, detName + "base",
1590 loaderName + "(const char*, TFolder*)");
1591 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1592 }
1593 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1594 fLoader[iDet] =
1595 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1596 fRunLoader->GetEventFolder());
1597 }
1598 if (!fLoader[iDet]) { // use default loader
1599 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1600 }
1601 if (!fLoader[iDet]) {
1602 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 1603 if (fStopOnError) return NULL;
f08fc9f5 1604 } else {
1605 fRunLoader->AddLoader(fLoader[iDet]);
1606 fRunLoader->CdGAFile();
1607 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1608 fRunLoader->Write(0, TObject::kOverwrite);
1609 }
1610 }
1611 }
1612
b8cd5251 1613 return reconstructor;
c757bafd 1614}
1615
2257f27e 1616//_____________________________________________________________________________
1617Bool_t AliReconstruction::CreateVertexer()
1618{
1619// create the vertexer
1620
b8cd5251 1621 fVertexer = NULL;
1622 AliReconstructor* itsReconstructor = GetReconstructor(0);
59697224 1623 if (itsReconstructor) {
b8cd5251 1624 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
2257f27e 1625 }
b8cd5251 1626 if (!fVertexer) {
815c2b38 1627 AliWarning("couldn't create a vertexer for ITS");
2257f27e 1628 if (fStopOnError) return kFALSE;
1629 }
1630
1631 return kTRUE;
1632}
1633
24f7a148 1634//_____________________________________________________________________________
b8cd5251 1635Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 1636{
f08fc9f5 1637// create the trackers
24f7a148 1638
b8cd5251 1639 TString detStr = detectors;
1640 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1641 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1642 AliReconstructor* reconstructor = GetReconstructor(iDet);
1643 if (!reconstructor) continue;
1644 TString detName = fgkDetectorName[iDet];
1f46a9ae 1645 if (detName == "HLT") {
1646 fRunHLTTracking = kTRUE;
1647 continue;
1648 }
e66fbafb 1649 if (detName == "MUON") {
1650 fRunMuonTracking = kTRUE;
1651 continue;
1652 }
1653
f08fc9f5 1654
1655 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1656 if (!fTracker[iDet] && (iDet < 7)) {
1657 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 1658 if (fStopOnError) return kFALSE;
1659 }
1660 }
1661
24f7a148 1662 return kTRUE;
1663}
1664
e583c30d 1665//_____________________________________________________________________________
b26c3770 1666void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
e583c30d 1667{
1668// delete trackers and the run loader and close and delete the file
1669
b8cd5251 1670 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1671 delete fReconstructor[iDet];
1672 fReconstructor[iDet] = NULL;
1673 fLoader[iDet] = NULL;
1674 delete fTracker[iDet];
1675 fTracker[iDet] = NULL;
1676 }
1677 delete fVertexer;
1678 fVertexer = NULL;
9178838a 1679 delete fDiamondProfile;
1680 fDiamondProfile = NULL;
e583c30d 1681
1682 delete fRunLoader;
1683 fRunLoader = NULL;
b649205a 1684 delete fRawReader;
1685 fRawReader = NULL;
e583c30d 1686
1687 if (file) {
1688 file->Close();
1689 delete file;
1690 }
b26c3770 1691
1692 if (fileOld) {
1693 fileOld->Close();
1694 delete fileOld;
1695 gSystem->Unlink("AliESDs.old.root");
1696 }
e583c30d 1697}
24f7a148 1698
1699
1700//_____________________________________________________________________________
af885e0f 1701
1702Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
24f7a148 1703{
1704// read the ESD event from a file
1705
1706 if (!esd) return kFALSE;
1707 char fileName[256];
1708 sprintf(fileName, "ESD_%d.%d_%s.root",
31fd97b2 1709 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
24f7a148 1710 if (gSystem->AccessPathName(fileName)) return kFALSE;
1711
f3a97c86 1712 AliInfo(Form("reading ESD from file %s", fileName));
815c2b38 1713 AliDebug(1, Form("reading ESD from file %s", fileName));
24f7a148 1714 TFile* file = TFile::Open(fileName);
1715 if (!file || !file->IsOpen()) {
815c2b38 1716 AliError(Form("opening %s failed", fileName));
24f7a148 1717 delete file;
1718 return kFALSE;
1719 }
1720
1721 gROOT->cd();
1722 delete esd;
af885e0f 1723 esd = (AliESDEvent*) file->Get("ESD");
24f7a148 1724 file->Close();
1725 delete file;
1726 return kTRUE;
af885e0f 1727
24f7a148 1728}
1729
af885e0f 1730
1731
24f7a148 1732//_____________________________________________________________________________
af885e0f 1733void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
24f7a148 1734{
1735// write the ESD event to a file
1736
1737 if (!esd) return;
1738 char fileName[256];
1739 sprintf(fileName, "ESD_%d.%d_%s.root",
31fd97b2 1740 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
24f7a148 1741
815c2b38 1742 AliDebug(1, Form("writing ESD to file %s", fileName));
24f7a148 1743 TFile* file = TFile::Open(fileName, "recreate");
1744 if (!file || !file->IsOpen()) {
815c2b38 1745 AliError(Form("opening %s failed", fileName));
24f7a148 1746 } else {
1747 esd->Write("ESD");
1748 file->Close();
1749 }
1750 delete file;
1751}
f3a97c86 1752
1753
1754
1755
f3a97c86 1756
a7807689 1757//_____________________________________________________________________________
f29f1726 1758void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
a7807689 1759{
f29f1726 1760 // write all files from the given esd file to an aod file
1761
1762 // create an AliAOD object
1763 AliAODEvent *aod = new AliAODEvent();
1764 aod->CreateStdContent();
1765
1766 // go to the file
1767 aodFile->cd();
1768
1769 // create the tree
1770 TTree *aodTree = new TTree("AOD", "AliAOD tree");
1771 aodTree->Branch(aod->GetList());
1772
1773 // connect to ESD
1774 TTree *t = (TTree*) esdFile->Get("esdTree");
af885e0f 1775 AliESDEvent *esd = new AliESDEvent();
53ec9628 1776 esd->ReadFromTree(t);
f29f1726 1777
53ec9628 1778 Int_t nEvents = t->GetEntries();
f29f1726 1779
1780 // set arrays and pointers
1781 Float_t posF[3];
1782 Double_t pos[3];
1783 Double_t p[3];
1784 Double_t covVtx[6];
1785 Double_t covTr[21];
1786 Double_t pid[10];
1787
1788 // loop over events and fill them
1789 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
53ec9628 1790 t->GetEntry(iEvent);
f29f1726 1791
1792 // Multiplicity information needed by the header (to be revised!)
1793 Int_t nTracks = esd->GetNumberOfTracks();
1794 Int_t nPosTracks = 0;
1795 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack)
1796 if (esd->GetTrack(iTrack)->GetSign()> 0) nPosTracks++;
1797
a1d4139d 1798 // Update the header
1799 AliAODHeader* header = aod->GetHeader();
1800
ade23daf 1801 header->SetRunNumber (esd->GetRunNumber() );
1802 header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
1803 header->SetOrbitNumber (esd->GetOrbitNumber() );
1804 header->SetPeriodNumber (esd->GetPeriodNumber() );
1805 header->SetTriggerMask (esd->GetTriggerMask() );
1806 header->SetTriggerCluster (esd->GetTriggerCluster() );
1807 header->SetEventType (esd->GetEventType() );
1808 header->SetMagneticField (esd->GetMagneticField() );
1809 header->SetZDCN1Energy (esd->GetZDCN1Energy() );
1810 header->SetZDCP1Energy (esd->GetZDCP1Energy() );
1811 header->SetZDCN2Energy (esd->GetZDCN2Energy() );
1812 header->SetZDCP2Energy (esd->GetZDCP2Energy() );
1813 header->SetZDCEMEnergy (esd->GetZDCEMEnergy() );
a1d4139d 1814 header->SetRefMultiplicity (nTracks);
1815 header->SetRefMultiplicityPos(nPosTracks);
1816 header->SetRefMultiplicityNeg(nTracks - nPosTracks);
1817 header->SetMuonMagFieldScale(-999.); // FIXME
1818 header->SetCentrality(-999.); // FIXME
1819//
1820//
f29f1726 1821
1822 Int_t nV0s = esd->GetNumberOfV0s();
1823 Int_t nCascades = esd->GetNumberOfCascades();
1824 Int_t nKinks = esd->GetNumberOfKinks();
1825 Int_t nVertices = nV0s + nCascades + nKinks;
1826
1827 aod->ResetStd(nTracks, nVertices);
1828 AliAODTrack *aodTrack;
1829
1830
1831 // Array to take into account the tracks already added to the AOD
1832 Bool_t * usedTrack = NULL;
1833 if (nTracks>0) {
1834 usedTrack = new Bool_t[nTracks];
1835 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;
1836 }
1837 // Array to take into account the V0s already added to the AOD
1838 Bool_t * usedV0 = NULL;
1839 if (nV0s>0) {
1840 usedV0 = new Bool_t[nV0s];
1841 for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;
1842 }
1843 // Array to take into account the kinks already added to the AOD
1844 Bool_t * usedKink = NULL;
1845 if (nKinks>0) {
1846 usedKink = new Bool_t[nKinks];
1847 for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;
1848 }
1849
1850 // Access to the AOD container of vertices
1851 TClonesArray &vertices = *(aod->GetVertices());
1852 Int_t jVertices=0;
1853
1854 // Access to the AOD container of tracks
1855 TClonesArray &tracks = *(aod->GetTracks());
1856 Int_t jTracks=0;
1857
1858 // Add primary vertex. The primary tracks will be defined
1859 // after the loops on the composite objects (V0, cascades, kinks)
1860 const AliESDVertex *vtx = esd->GetPrimaryVertex();
1861
1862 vtx->GetXYZ(pos); // position
1863 vtx->GetCovMatrix(covVtx); //covariance matrix
1864
1865 AliAODVertex * primary = new(vertices[jVertices++])
1866 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, AliAODVertex::kPrimary);
1867
1868 // Create vertices starting from the most complex objects
1869
1870 // Cascades
1871 for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {
1872 AliESDcascade *cascade = esd->GetCascade(nCascade);
1873
1874 cascade->GetXYZ(pos[0], pos[1], pos[2]);
1875 cascade->GetPosCovXi(covVtx);
1876
1877 // Add the cascade vertex
1878 AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos,
1879 covVtx,
1880 cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
1881 primary,
1882 AliAODVertex::kCascade);
1883
1884 primary->AddDaughter(vcascade);
1885
1886 // Add the V0 from the cascade. The ESD class have to be optimized...
1887 // Now we have to search for the corresponding Vo in the list of V0s
1888 // using the indeces of the positive and negative tracks
1889
1890 Int_t posFromV0 = cascade->GetPindex();
1891 Int_t negFromV0 = cascade->GetNindex();
1892
1893
1894 AliESDv0 * v0 = 0x0;
1895 Int_t indV0 = -1;
1896
1897 for (Int_t iV0=0; iV0<nV0s; ++iV0) {
1898
1899 v0 = esd->GetV0(iV0);
1900 Int_t posV0 = v0->GetPindex();
1901 Int_t negV0 = v0->GetNindex();
1902
1903 if (posV0==posFromV0 && negV0==negFromV0) {
1904 indV0 = iV0;
1905 break;
1906 }
1907 }
1908
1909 AliAODVertex * vV0FromCascade = 0x0;
1910
1911 if (indV0>-1 && !usedV0[indV0] ) {
1912
1913 // the V0 exists in the array of V0s and is not used
1914
1915 usedV0[indV0] = kTRUE;
1916
1917 v0->GetXYZ(pos[0], pos[1], pos[2]);
1918 v0->GetPosCov(covVtx);
1919
1920 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
1921 covVtx,
1922 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
1923 vcascade,
1924 AliAODVertex::kV0);
1925 } else {
1926
1927 // the V0 doesn't exist in the array of V0s or was used
1928 cerr << "Error: event " << iEvent << " cascade " << nCascade
1929 << " The V0 " << indV0
1930 << " doesn't exist in the array of V0s or was used!" << endl;
1931
1932 cascade->GetXYZ(pos[0], pos[1], pos[2]);
1933 cascade->GetPosCov(covVtx);
1934
1935 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
1936 covVtx,
1937 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
1938 vcascade,
1939 AliAODVertex::kV0);
1940 vcascade->AddDaughter(vV0FromCascade);
1941 }
1942
1943 // Add the positive tracks from the V0
1944
1945 if (! usedTrack[posFromV0]) {
1946
1947 usedTrack[posFromV0] = kTRUE;
1948
1949 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
1950 esdTrack->GetPxPyPz(p);
1951 esdTrack->GetXYZ(pos);
1952 esdTrack->GetCovarianceXYZPxPyPz(covTr);
1953 esdTrack->GetESDpid(pid);
1954
1955 vV0FromCascade->AddDaughter(aodTrack =
1956 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
1957 esdTrack->GetLabel(),
1958 p,
1959 kTRUE,
1960 pos,
1961 kFALSE,
1962 covTr,
1963 (Short_t)esdTrack->GetSign(),
1964 esdTrack->GetITSClusterMap(),
1965 pid,
1966 vV0FromCascade,
1967 kTRUE, // check if this is right
1968 kFALSE, // check if this is right
1969 AliAODTrack::kSecondary)
1970 );
1971 aodTrack->ConvertAliPIDtoAODPID();
1972 }
1973 else {
1974 cerr << "Error: event " << iEvent << " cascade " << nCascade
1975 << " track " << posFromV0 << " has already been used!" << endl;
1976 }
1977
1978 // Add the negative tracks from the V0
1979
1980 if (!usedTrack[negFromV0]) {
1981
1982 usedTrack[negFromV0] = kTRUE;
1983
1984 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
1985 esdTrack->GetPxPyPz(p);
1986 esdTrack->GetXYZ(pos);
1987 esdTrack->GetCovarianceXYZPxPyPz(covTr);
1988 esdTrack->GetESDpid(pid);
1989
1990 vV0FromCascade->AddDaughter(aodTrack =
1991 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
1992 esdTrack->GetLabel(),
1993 p,
1994 kTRUE,
1995 pos,
1996 kFALSE,
1997 covTr,
1998 (Short_t)esdTrack->GetSign(),
1999 esdTrack->GetITSClusterMap(),
2000 pid,
2001 vV0FromCascade,
2002 kTRUE, // check if this is right
2003 kFALSE, // check if this is right
2004 AliAODTrack::kSecondary)
2005 );
2006 aodTrack->ConvertAliPIDtoAODPID();
2007 }
2008 else {
2009 cerr << "Error: event " << iEvent << " cascade " << nCascade
2010 << " track " << negFromV0 << " has already been used!" << endl;
2011 }
2012
2013 // Add the bachelor track from the cascade
2014
2015 Int_t bachelor = cascade->GetBindex();
2016
2017 if(!usedTrack[bachelor]) {
2018
2019 usedTrack[bachelor] = kTRUE;
2020
2021 AliESDtrack *esdTrack = esd->GetTrack(bachelor);
2022 esdTrack->GetPxPyPz(p);
2023 esdTrack->GetXYZ(pos);
2024 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2025 esdTrack->GetESDpid(pid);
2026
2027 vcascade->AddDaughter(aodTrack =
2028 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2029 esdTrack->GetLabel(),
2030 p,
2031 kTRUE,
2032 pos,
2033 kFALSE,
2034 covTr,
2035 (Short_t)esdTrack->GetSign(),
2036 esdTrack->GetITSClusterMap(),
2037 pid,
2038 vcascade,
2039 kTRUE, // check if this is right
2040 kFALSE, // check if this is right
2041 AliAODTrack::kSecondary)
2042 );
2043 aodTrack->ConvertAliPIDtoAODPID();
2044 }
2045 else {
2046 cerr << "Error: event " << iEvent << " cascade " << nCascade
2047 << " track " << bachelor << " has already been used!" << endl;
2048 }
2049
2050 // Add the primary track of the cascade (if any)
2051
2052 } // end of the loop on cascades
2053
2054 // V0s
2055
2056 for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {
2057
2058 if (usedV0[nV0]) continue; // skip if aready added to the AOD
2059
2060 AliESDv0 *v0 = esd->GetV0(nV0);
2061
2062 v0->GetXYZ(pos[0], pos[1], pos[2]);
2063 v0->GetPosCov(covVtx);
2064
2065 AliAODVertex * vV0 =
2066 new(vertices[jVertices++]) AliAODVertex(pos,
2067 covVtx,
2068 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2069 primary,
2070 AliAODVertex::kV0);
2071 primary->AddDaughter(vV0);
2072
2073 Int_t posFromV0 = v0->GetPindex();
2074 Int_t negFromV0 = v0->GetNindex();
2075
2076 // Add the positive tracks from the V0
2077
2078 if (!usedTrack[posFromV0]) {
2079
2080 usedTrack[posFromV0] = kTRUE;
2081
2082 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2083 esdTrack->GetPxPyPz(p);
2084 esdTrack->GetXYZ(pos);
2085 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2086 esdTrack->GetESDpid(pid);
2087
2088 vV0->AddDaughter(aodTrack =
2089 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2090 esdTrack->GetLabel(),
2091 p,
2092 kTRUE,
2093 pos,
2094 kFALSE,
2095 covTr,
2096 (Short_t)esdTrack->GetSign(),
2097 esdTrack->GetITSClusterMap(),
2098 pid,
2099 vV0,
2100 kTRUE, // check if this is right
2101 kFALSE, // check if this is right
2102 AliAODTrack::kSecondary)
2103 );
2104 aodTrack->ConvertAliPIDtoAODPID();
2105 }
2106 else {
2107 cerr << "Error: event " << iEvent << " V0 " << nV0
2108 << " track " << posFromV0 << " has already been used!" << endl;
2109 }
a7807689 2110
f29f1726 2111 // Add the negative tracks from the V0
2112
2113 if (!usedTrack[negFromV0]) {
2114
2115 usedTrack[negFromV0] = kTRUE;
2116
2117 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2118 esdTrack->GetPxPyPz(p);
2119 esdTrack->GetXYZ(pos);
2120 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2121 esdTrack->GetESDpid(pid);
2122
2123 vV0->AddDaughter(aodTrack =
2124 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2125 esdTrack->GetLabel(),
2126 p,
2127 kTRUE,
2128 pos,
2129 kFALSE,
2130 covTr,
2131 (Short_t)esdTrack->GetSign(),
2132 esdTrack->GetITSClusterMap(),
2133 pid,
2134 vV0,
2135 kTRUE, // check if this is right
2136 kFALSE, // check if this is right
2137 AliAODTrack::kSecondary)
2138 );
2139 aodTrack->ConvertAliPIDtoAODPID();
2140 }
2141 else {
2142 cerr << "Error: event " << iEvent << " V0 " << nV0
2143 << " track " << negFromV0 << " has already been used!" << endl;
2144 }
2145
2146 } // end of the loop on V0s
2147
2148 // Kinks: it is a big mess the access to the information in the kinks
2149 // The loop is on the tracks in order to find the mother and daugther of each kink
2150
2151
2152 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
2153
2154
2155 AliESDtrack * esdTrack = esd->GetTrack(iTrack);
2156
2157 Int_t ikink = esdTrack->GetKinkIndex(0);
2158
2159 if (ikink) {
2160 // Negative kink index: mother, positive: daughter
2161
2162 // Search for the second track of the kink
2163
2164 for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {
2165
2166 AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);
2167
2168 Int_t jkink = esdTrack1->GetKinkIndex(0);
2169
2170 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
2171
2172 // The two tracks are from the same kink
2173
2174 if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
2175
2176 Int_t imother = -1;
2177 Int_t idaughter = -1;
2178
2179 if (ikink<0 && jkink>0) {
2180
2181 imother = iTrack;
2182 idaughter = jTrack;
2183 }
2184 else if (ikink>0 && jkink<0) {
2185
2186 imother = jTrack;
2187 idaughter = iTrack;
2188 }
2189 else {
2190 cerr << "Error: Wrong combination of kink indexes: "
2191 << ikink << " " << jkink << endl;
2192 continue;
2193 }
2194
2195 // Add the mother track
2196
2197 AliAODTrack * mother = NULL;
2198
2199 if (!usedTrack[imother]) {
2200
2201 usedTrack[imother] = kTRUE;
2202
2203 AliESDtrack *esdTrack = esd->GetTrack(imother);
2204 esdTrack->GetPxPyPz(p);
2205 esdTrack->GetXYZ(pos);
2206 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2207 esdTrack->GetESDpid(pid);
2208
2209 mother =
2210 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2211 esdTrack->GetLabel(),
2212 p,
2213 kTRUE,
2214 pos,
2215 kFALSE,
2216 covTr,
2217 (Short_t)esdTrack->GetSign(),
2218 esdTrack->GetITSClusterMap(),
2219 pid,
2220 primary,
2221 kTRUE, // check if this is right
2222 kTRUE, // check if this is right
2223 AliAODTrack::kPrimary);
2224 primary->AddDaughter(mother);
2225 mother->ConvertAliPIDtoAODPID();
2226 }
2227 else {
2228 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2229 << " track " << imother << " has already been used!" << endl;
2230 }
2231
2232 // Add the kink vertex
2233 AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);
2234
2235 AliAODVertex * vkink =
2236 new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),
2237 NULL,
2238 0.,
2239 mother,
2240 AliAODVertex::kKink);
2241 // Add the daughter track
2242
2243 AliAODTrack * daughter = NULL;
2244
2245 if (!usedTrack[idaughter]) {
2246
2247 usedTrack[idaughter] = kTRUE;
2248
2249 AliESDtrack *esdTrack = esd->GetTrack(idaughter);
2250 esdTrack->GetPxPyPz(p);
2251 esdTrack->GetXYZ(pos);
2252 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2253 esdTrack->GetESDpid(pid);
2254
2255 daughter =
2256 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2257 esdTrack->GetLabel(),
2258 p,
2259 kTRUE,
2260 pos,
2261 kFALSE,
2262 covTr,
2263 (Short_t)esdTrack->GetSign(),
2264 esdTrack->GetITSClusterMap(),
2265 pid,
2266 vkink,
2267 kTRUE, // check if this is right
2268 kTRUE, // check if this is right
2269 AliAODTrack::kPrimary);
2270 vkink->AddDaughter(daughter);
2271 daughter->ConvertAliPIDtoAODPID();
2272 }
2273 else {
2274 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2275 << " track " << idaughter << " has already been used!" << endl;
2276 }
2277
2278
2279 }
2280 }
2281
2282 }
2283
2284 }
2285
2286
2287 // Tracks (primary and orphan)
2288
2289 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
2290
2291
2292 if (usedTrack[nTrack]) continue;
2293
2294 AliESDtrack *esdTrack = esd->GetTrack(nTrack);
2295 esdTrack->GetPxPyPz(p);
2296 esdTrack->GetXYZ(pos);
2297 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2298 esdTrack->GetESDpid(pid);
2299
2300 Float_t impactXY, impactZ;
2301
2302 esdTrack->GetImpactParameters(impactXY,impactZ);
2303
2304 if (impactXY<3) {
2305 // track inside the beam pipe
2306
2307 primary->AddDaughter(aodTrack =
2308 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2309 esdTrack->GetLabel(),
2310 p,
2311 kTRUE,
2312 pos,
2313 kFALSE,
2314 covTr,
2315 (Short_t)esdTrack->GetSign(),
2316 esdTrack->GetITSClusterMap(),
2317 pid,
2318 primary,
2319 kTRUE, // check if this is right
2320 kTRUE, // check if this is right
2321 AliAODTrack::kPrimary)
2322 );
2323 aodTrack->ConvertAliPIDtoAODPID();
2324 }
2325 else {
2326 // outside the beam pipe: orphan track
2327 aodTrack =
2328 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2329 esdTrack->GetLabel(),
2330 p,
2331 kTRUE,
2332 pos,
2333 kFALSE,
2334 covTr,
2335 (Short_t)esdTrack->GetSign(),
2336 esdTrack->GetITSClusterMap(),
2337 pid,
2338 NULL,
2339 kFALSE, // check if this is right
2340 kFALSE, // check if this is right
2341 AliAODTrack::kOrphan);
2342 aodTrack->ConvertAliPIDtoAODPID();
2343 }
2344 } // end of loop on tracks
2345
2346 // muon tracks
2347 Int_t nMuTracks = esd->GetNumberOfMuonTracks();
2348 for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
2349
2350 AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack);
2351 p[0] = esdMuTrack->Px();
2352 p[1] = esdMuTrack->Py();
2353 p[2] = esdMuTrack->Pz();
2354 pos[0] = primary->GetX();
2355 pos[1] = primary->GetY();
2356 pos[2] = primary->GetZ();
2357
2358 // has to be changed once the muon pid is provided by the ESD
2359 for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
2360
2361 primary->AddDaughter(
2362 new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
2363 0, // no label provided
2364 p,
2365 kTRUE,
2366 pos,
2367 kFALSE,
2368 NULL, // no covariance matrix provided
2369 (Short_t)-99, // no charge provided
2370 0, // no ITSClusterMap
2371 pid,
2372 primary,
7eb019e8 2373 kFALSE, // muon tracks are not used to fit the primary vtx
2374 kFALSE, // not used for vertex fit
f29f1726 2375 AliAODTrack::kPrimary)
2376 );
2377 }
2378
2379 // Access to the AOD container of clusters
2380 TClonesArray &clusters = *(aod->GetClusters());
2381 Int_t jClusters=0;
2382
2383 // Calo Clusters
2384 Int_t nClusters = esd->GetNumberOfCaloClusters();
2385
2386 for (Int_t iClust=0; iClust<nClusters; ++iClust) {
2387
2388 AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
2389
2390 Int_t id = cluster->GetID();
2391 Int_t label = -1;
53ec9628 2392 Float_t energy = cluster->E();
2393 cluster->GetPosition(posF);
f29f1726 2394 AliAODVertex *prodVertex = primary;
2395 AliAODTrack *primTrack = NULL;
2396 Char_t ttype=AliAODCluster::kUndef;
2397
2398 if (cluster->IsPHOS()) ttype=AliAODCluster::kPHOSNeutral;
2399 else if (cluster->IsEMCAL()) {
2400
2401 if (cluster->GetClusterType() == AliESDCaloCluster::kPseudoCluster)
2402 ttype = AliAODCluster::kEMCALPseudoCluster;
2403 else
2404 ttype = AliAODCluster::kEMCALClusterv1;
2405
2406 }
2407
2408 new(clusters[jClusters++]) AliAODCluster(id,
2409 label,
2410 energy,
2411 pos,
2412 NULL, // no covariance matrix provided
2413 NULL, // no pid for clusters provided
2414 prodVertex,
2415 primTrack,
2416 ttype);
2417
2418 } // end of loop on calo clusters
2419
2420 delete [] usedTrack;
2421 delete [] usedV0;
2422 delete [] usedKink;
2423
2424 // fill the tree for this event
2425 aodTree->Fill();
2426 } // end of event loop
2427
2428 aodTree->GetUserInfo()->Add(aod);
2429
2430 // close ESD file
2431 esdFile->Close();
2432
2433 // write the tree to the specified file
2434 aodFile = aodTree->GetCurrentFile();
2435 aodFile->cd();
2436 aodTree->Write();
2437
a7807689 2438 return;
2439}
2440
af885e0f 2441void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 2442{
2443 // Write space-points which are then used in the alignment procedures
2444 // For the moment only ITS, TRD and TPC
2445
2446 // Load TOF clusters
d528ee75 2447 if (fTracker[3]){
2448 fLoader[3]->LoadRecPoints("read");
2449 TTree* tree = fLoader[3]->TreeR();
2450 if (!tree) {
2451 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2452 return;
2453 }
2454 fTracker[3]->LoadClusters(tree);
98937d93 2455 }
98937d93 2456 Int_t ntracks = esd->GetNumberOfTracks();
2457 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2458 {
2459 AliESDtrack *track = esd->GetTrack(itrack);
2460 Int_t nsp = 0;
ef7253ac 2461 Int_t idx[200];
98937d93 2462 for (Int_t iDet = 3; iDet >= 0; iDet--)
2463 nsp += track->GetNcls(iDet);
2464 if (nsp) {
2465 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2466 track->SetTrackPointArray(sp);
2467 Int_t isptrack = 0;
2468 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2469 AliTracker *tracker = fTracker[iDet];
2470 if (!tracker) continue;
2471 Int_t nspdet = track->GetNcls(iDet);
98937d93 2472 if (nspdet <= 0) continue;
2473 track->GetClusters(iDet,idx);
2474 AliTrackPoint p;
2475 Int_t isp = 0;
2476 Int_t isp2 = 0;
2477 while (isp < nspdet) {
2478 Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++;
160db090 2479 const Int_t kNTPCmax = 159;
2480 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
98937d93 2481 if (!isvalid) continue;
2482 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2483 }
98937d93 2484 }
2485 }
2486 }
d528ee75 2487 if (fTracker[3]){
2488 fTracker[3]->UnloadClusters();
2489 fLoader[3]->UnloadRecPoints();
2490 }
98937d93 2491}
2e3550da 2492
2493//_____________________________________________________________________________
af885e0f 2494void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 2495{
2496 // The method reads the raw-data error log
2497 // accumulated within the rawReader.
2498 // It extracts the raw-data errors related to
2499 // the current event and stores them into
2500 // a TClonesArray inside the esd object.
2501
2502 if (!fRawReader) return;
2503
2504 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2505
2506 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2507 if (!log) continue;
2508 if (iEvent != log->GetEventNumber()) continue;
2509
2510 esd->AddRawDataErrorLog(log);
2511 }
2512
2513}
46698ae4 2514
2515TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
b545009a 2516 // Dump a file content into a char in TNamed
46698ae4 2517 ifstream in;
2518 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2519 Int_t kBytes = (Int_t)in.tellg();
2520 printf("Size: %d \n",kBytes);
2521 TNamed *fn = 0;
2522 if(in.good()){
2523 char* memblock = new char [kBytes];
2524 in.seekg (0, ios::beg);
2525 in.read (memblock, kBytes);
2526 in.close();
2527 TString fData(memblock,kBytes);
2528 fn = new TNamed(fName,fData);
2529 printf("fData Size: %d \n",fData.Sizeof());
2530 printf("fName Size: %d \n",fName.Sizeof());
2531 printf("fn Size: %d \n",fn->Sizeof());
2532 delete[] memblock;
2533 }
2534 else{
2535 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2536 }
2537
2538 return fn;
2539}
2540
2541void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
46698ae4 2542 // This is not really needed in AliReconstruction at the moment
2543 // but can serve as a template
2544
2545 TList *fList = fTree->GetUserInfo();
2546 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2547 printf("fn Size: %d \n",fn->Sizeof());
2548
2549 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2550 const char* cdata = fn->GetTitle();
2551 printf("fTmp Size %d\n",fTmp.Sizeof());
2552
2553 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2554 printf("calculated size %d\n",size);
2555 ofstream out(fName.Data(),ios::out | ios::binary);
2556 out.write(cdata,size);
2557 out.close();
2558
2559}
2560