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