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