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