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