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