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