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