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