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