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