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