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