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