]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliReconstruction.cxx
ooooooooooops
[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// //
cd0b062e 104// The input data of a detector can be replaced by the corresponding HLT //
105// data by calling (usual detector string) //
106// SetUseHLTData("..."); //
107// //
24f7a148 108// For debug purposes the method SetCheckPointLevel can be used. If the //
109// argument is greater than 0, files with ESD events will be written after //
110// selected steps of the reconstruction for each event: //
111// level 1: after tracking and after filling of ESD (final) //
112// level 2: in addition after each tracking step //
113// level 3: in addition after the filling of ESD for each detector //
114// If a final check point file exists for an event, this event will be //
115// skipped in the reconstruction. The tracking and the filling of ESD for //
116// a detector will be skipped as well, if the corresponding check point //
117// file exists. The ESD event will then be loaded from the file instead. //
118// //
596a855f 119///////////////////////////////////////////////////////////////////////////////
120
024a7e64 121#include <TArrayF.h>
122#include <TFile.h>
444753c6 123#include <TList.h>
024a7e64 124#include <TSystem.h>
125#include <TROOT.h>
126#include <TPluginManager.h>
3103d196 127#include <TGeoManager.h>
2bdb9d38 128#include <TLorentzVector.h>
3dd9f9e3 129#include <TArrayS.h>
130#include <TArrayD.h>
3c3709c4 131#include <TObjArray.h>
325aa76f 132#include <TMap.h>
596a855f 133
134#include "AliReconstruction.h"
87932dab 135#include "AliCodeTimer.h"
b8cd5251 136#include "AliReconstructor.h"
815c2b38 137#include "AliLog.h"
596a855f 138#include "AliRunLoader.h"
139#include "AliRun.h"
b649205a 140#include "AliRawReaderFile.h"
141#include "AliRawReaderDate.h"
142#include "AliRawReaderRoot.h"
001397cd 143#include "AliRawEventHeaderBase.h"
af885e0f 144#include "AliESDEvent.h"
faffd83e 145#include "AliESDMuonTrack.h"
1d99986f 146#include "AliESDfriend.h"
2257f27e 147#include "AliESDVertex.h"
faffd83e 148#include "AliESDcascade.h"
149#include "AliESDkink.h"
150#include "AliESDtrack.h"
151#include "AliESDCaloCluster.h"
e649177a 152#include "AliESDCaloCells.h"
32e449be 153#include "AliMultiplicity.h"
c84a5e9e 154#include "AliTracker.h"
2257f27e 155#include "AliVertexer.h"
c5e3e5d1 156#include "AliVertexerTracks.h"
5e4ff34d 157#include "AliV0vertexer.h"
158#include "AliCascadeVertexer.h"
596a855f 159#include "AliHeader.h"
160#include "AliGenEventHeader.h"
b26c3770 161#include "AliPID.h"
596a855f 162#include "AliESDpid.h"
ff8bb5ae 163#include "AliESDtrack.h"
3dd9f9e3 164#include "AliESDPmdTrack.h"
f3a97c86 165
08e1a23e 166#include "AliESDTagCreator.h"
a1069ee1 167#include "AliAODTagCreator.h"
f3a97c86 168
25be1e5c 169#include "AliGeomManager.h"
98937d93 170#include "AliTrackPointArray.h"
b0314964 171#include "AliCDBManager.h"
795e4a22 172#include "AliCDBStorage.h"
6bae477a 173#include "AliCDBEntry.h"
174#include "AliAlignObj.h"
f3a97c86 175
b647652d 176#include "AliCentralTrigger.h"
b024fd7f 177#include "AliTriggerConfiguration.h"
178#include "AliTriggerClass.h"
b647652d 179#include "AliCTPRawStream.h"
180
04236e67 181#include "AliQADataMakerRec.h"
aa3c69a9 182#include "AliGlobalQADataMaker.h"
c65c502a 183#include "AliQA.h"
184#include "AliQADataMakerSteer.h"
f29f1726 185
7167ae53 186#include "AliPlaneEff.h"
187
0f88822a 188#include "AliSysInfo.h" // memory snapshots
cd0b062e 189#include "AliRawHLTManager.h"
0f88822a 190
325aa76f 191#include "AliMagWrapCheb.h"
6efecea1 192
7e88424f 193#include "AliDetectorRecoParam.h"
194#include "AliRunInfo.h"
195#include "AliEventInfo.h"
196
197#include "AliDAQ.h"
198
596a855f 199ClassImp(AliReconstruction)
200
201
c757bafd 202//_____________________________________________________________________________
b384f8a4 203const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
c757bafd 204
596a855f 205//_____________________________________________________________________________
795e4a22 206AliReconstruction::AliReconstruction(const char* gAliceFilename,
e583c30d 207 const char* name, const char* title) :
208 TNamed(name, title),
209
f8b507e0 210 fUniformField(kFALSE),
61807e09 211 fForcedFieldMap(0x0),
2257f27e 212 fRunVertexFinder(kTRUE),
a84e2607 213 fRunVertexFinderTracks(kTRUE),
1f46a9ae 214 fRunHLTTracking(kFALSE),
e66fbafb 215 fRunMuonTracking(kFALSE),
d1683eef 216 fRunV0Finder(kTRUE),
217 fRunCascadeFinder(kTRUE),
1d99986f 218 fStopOnError(kFALSE),
219 fWriteAlignmentData(kFALSE),
220 fWriteESDfriend(kFALSE),
a7807689 221 fWriteAOD(kFALSE),
b647652d 222 fFillTriggerESD(kTRUE),
1d99986f 223
7f68891d 224 fCleanESD(kTRUE),
a023d8d8 225 fV0DCAmax(3.),
226 fV0CsPmin(0.),
7f68891d 227 fDmax(50.),
228 fZmax(50.),
229
1d99986f 230 fRunLocalReconstruction("ALL"),
b8cd5251 231 fRunTracking("ALL"),
e583c30d 232 fFillESD("ALL"),
48ce48d1 233 fUseTrackingErrorsForAlignment(""),
e583c30d 234 fGAliceFileName(gAliceFilename),
b649205a 235 fInput(""),
35042093 236 fEquipIdMap(""),
b26c3770 237 fFirstEvent(0),
238 fLastEvent(-1),
973388c2 239 fNumberOfEventsPerFile(1),
24f7a148 240 fCheckPointLevel(0),
b8cd5251 241 fOptions(),
6bae477a 242 fLoadAlignFromCDB(kTRUE),
243 fLoadAlignData("ALL"),
46698ae4 244 fESDPar(""),
cd0b062e 245 fUseHLTData(),
7e88424f 246 fRunInfo(NULL),
247 fEventInfo(),
e583c30d 248
249 fRunLoader(NULL),
b649205a 250 fRawReader(NULL),
cd0b062e 251 fParentRawReader(NULL),
b8cd5251 252
7e88424f 253 fRecoParam(),
254
98937d93 255 fVertexer(NULL),
9178838a 256 fDiamondProfile(NULL),
43c9dae1 257 fDiamondProfileTPC(NULL),
87317a47 258 fMeanVertexConstraint(kTRUE),
98937d93 259
6b6e4472 260 fGRPData(NULL),
444753c6 261
6bae477a 262 fAlignObjArray(NULL),
795e4a22 263 fCDBUri(),
759c1df1 264 fSpecCDBUri(),
795e4a22 265 fInitCDBCalled(kFALSE),
266 fSetRunNumberFromDataCalled(kFALSE),
ce43afbe 267 fQADetectors("ALL"),
30bbd491 268 fQASteer(NULL),
ce43afbe 269 fQATasks("ALL"),
7e963665 270 fRunQA(kTRUE),
6b150027 271 fRunGlobalQA(kTRUE),
7167ae53 272 fInLoopQA(kFALSE),
e4a998ed 273 fSameQACycle(kFALSE),
7167ae53 274
21a3aa09 275 fRunPlaneEff(kFALSE),
276
277 fesd(NULL),
278 fhltesd(NULL),
279 fesdf(NULL),
280 ffile(NULL),
281 ftree(NULL),
282 fhlttree(NULL),
283 ffileOld(NULL),
284 ftreeOld(NULL),
285 fhlttreeOld(NULL),
286 ftVertexer(NULL),
14dd053c 287 fIsNewRunLoader(kFALSE),
288 fRunAliEVE(kFALSE)
596a855f 289{
290// create reconstruction object with default parameters
b8cd5251 291
292 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
293 fReconstructor[iDet] = NULL;
294 fLoader[iDet] = NULL;
295 fTracker[iDet] = NULL;
30bbd491 296 fQACycles[iDet] = 999999;
b8cd5251 297 }
b8bd1ab8 298 fQASteer = new AliQADataMakerSteer("rec") ;
e84c88f5 299 fQASteer->SetActiveDetectors(fQADetectors) ;
300 fQASteer->SetTasks(fQATasks) ;
e47c4c2e 301 AliPID pid;
596a855f 302}
303
304//_____________________________________________________________________________
305AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
e583c30d 306 TNamed(rec),
307
c84a5e9e 308 fUniformField(rec.fUniformField),
61807e09 309 fForcedFieldMap(0x0),
2257f27e 310 fRunVertexFinder(rec.fRunVertexFinder),
a84e2607 311 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
1f46a9ae 312 fRunHLTTracking(rec.fRunHLTTracking),
e66fbafb 313 fRunMuonTracking(rec.fRunMuonTracking),
d1683eef 314 fRunV0Finder(rec.fRunV0Finder),
315 fRunCascadeFinder(rec.fRunCascadeFinder),
1d99986f 316 fStopOnError(rec.fStopOnError),
317 fWriteAlignmentData(rec.fWriteAlignmentData),
318 fWriteESDfriend(rec.fWriteESDfriend),
a7807689 319 fWriteAOD(rec.fWriteAOD),
b647652d 320 fFillTriggerESD(rec.fFillTriggerESD),
1d99986f 321
7f68891d 322 fCleanESD(rec.fCleanESD),
a023d8d8 323 fV0DCAmax(rec.fV0DCAmax),
5e5c1aa9 324 fV0CsPmin(rec.fV0CsPmin),
7f68891d 325 fDmax(rec.fDmax),
326 fZmax(rec.fZmax),
327
1d99986f 328 fRunLocalReconstruction(rec.fRunLocalReconstruction),
e583c30d 329 fRunTracking(rec.fRunTracking),
330 fFillESD(rec.fFillESD),
48ce48d1 331 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
e583c30d 332 fGAliceFileName(rec.fGAliceFileName),
b649205a 333 fInput(rec.fInput),
35042093 334 fEquipIdMap(rec.fEquipIdMap),
b26c3770 335 fFirstEvent(rec.fFirstEvent),
336 fLastEvent(rec.fLastEvent),
973388c2 337 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
24f7a148 338 fCheckPointLevel(0),
b8cd5251 339 fOptions(),
6bae477a 340 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
341 fLoadAlignData(rec.fLoadAlignData),
46698ae4 342 fESDPar(rec.fESDPar),
2972d4eb 343 fUseHLTData(rec.fUseHLTData),
7e88424f 344 fRunInfo(NULL),
345 fEventInfo(),
e583c30d 346
347 fRunLoader(NULL),
b649205a 348 fRawReader(NULL),
2972d4eb 349 fParentRawReader(NULL),
b8cd5251 350
7e88424f 351 fRecoParam(),
352
98937d93 353 fVertexer(NULL),
9178838a 354 fDiamondProfile(NULL),
43c9dae1 355 fDiamondProfileTPC(NULL),
87317a47 356 fMeanVertexConstraint(rec.fMeanVertexConstraint),
98937d93 357
6b6e4472 358 fGRPData(NULL),
444753c6 359
6bae477a 360 fAlignObjArray(rec.fAlignObjArray),
ec92bee0 361 fCDBUri(rec.fCDBUri),
7e963665 362 fSpecCDBUri(),
795e4a22 363 fInitCDBCalled(rec.fInitCDBCalled),
364 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
ce43afbe 365 fQADetectors(rec.fQADetectors),
b8bd1ab8 366 fQASteer(rec.fQASteer),
ce43afbe 367 fQATasks(rec.fQATasks),
aa3c69a9 368 fRunQA(rec.fRunQA),
369 fRunGlobalQA(rec.fRunGlobalQA),
7167ae53 370 fInLoopQA(rec.fInLoopQA),
e4a998ed 371 fSameQACycle(rec.fSameQACycle),
21a3aa09 372 fRunPlaneEff(rec.fRunPlaneEff),
373
374 fesd(NULL),
375 fhltesd(NULL),
376 fesdf(NULL),
377 ffile(NULL),
378 ftree(NULL),
379 fhlttree(NULL),
380 ffileOld(NULL),
381 ftreeOld(NULL),
382 fhlttreeOld(NULL),
383 ftVertexer(NULL),
14dd053c 384 fIsNewRunLoader(rec.fIsNewRunLoader),
385 fRunAliEVE(kFALSE)
596a855f 386{
387// copy constructor
388
ec92bee0 389 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
efd2085e 390 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
391 }
b8cd5251 392 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
393 fReconstructor[iDet] = NULL;
394 fLoader[iDet] = NULL;
395 fTracker[iDet] = NULL;
b8bd1ab8 396 fQACycles[iDet] = rec.fQACycles[iDet];
b8cd5251 397 }
ec92bee0 398 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
399 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
400 }
61807e09 401
402 fForcedFieldMap=new AliMagWrapCheb(*((AliMagWrapCheb*)rec.fForcedFieldMap));
596a855f 403}
404
405//_____________________________________________________________________________
406AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
407{
408// assignment operator
409
410 this->~AliReconstruction();
411 new(this) AliReconstruction(rec);
412 return *this;
413}
414
415//_____________________________________________________________________________
416AliReconstruction::~AliReconstruction()
417{
418// clean up
419
e583c30d 420 CleanUp();
efd2085e 421 fOptions.Delete();
ec92bee0 422 fSpecCDBUri.Delete();
61807e09 423 delete fForcedFieldMap;
b8bd1ab8 424 delete fQASteer ;
87932dab 425 AliCodeTimer::Instance()->Print();
596a855f 426}
427
024cf675 428//_____________________________________________________________________________
795e4a22 429void AliReconstruction::InitCDB()
024cf675 430{
431// activate a default CDB storage
432// First check if we have any CDB storage set, because it is used
433// to retrieve the calibration and alignment constants
434
795e4a22 435 if (fInitCDBCalled) return;
436 fInitCDBCalled = kTRUE;
437
024cf675 438 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 439 if (man->IsDefaultStorageSet())
024cf675 440 {
441 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 442 AliWarning("Default CDB storage has been already set !");
443 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
024cf675 444 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 445 fCDBUri = man->GetDefaultStorage()->GetURI();
ec92bee0 446 }
447 else {
795e4a22 448 if (fCDBUri.Length() > 0)
449 {
450 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
451 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
452 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
453 } else {
454 fCDBUri="local://$ALICE_ROOT";
455 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
456 AliWarning("Default CDB storage not yet set !!!!");
457 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
458 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
459
460 }
ec92bee0 461 man->SetDefaultStorage(fCDBUri);
462 }
463
464 // Now activate the detector specific CDB storage locations
c3a7b59a 465 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
466 TObject* obj = fSpecCDBUri[i];
467 if (!obj) continue;
b8ec52f6 468 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
469 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
470 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 471 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 472 }
795e4a22 473
024cf675 474}
475
476//_____________________________________________________________________________
477void AliReconstruction::SetDefaultStorage(const char* uri) {
ec92bee0 478// Store the desired default CDB storage location
479// Activate it later within the Run() method
024cf675 480
ec92bee0 481 fCDBUri = uri;
024cf675 482
483}
484
00aa02d5 485//_____________________________________________________________________________
c3a7b59a 486void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 487// Store a detector-specific CDB storage location
488// Activate it later within the Run() method
024cf675 489
c3a7b59a 490 AliCDBPath aPath(calibType);
491 if(!aPath.IsValid()){
492 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
493 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
494 if(!strcmp(calibType, fgkDetectorName[iDet])) {
495 aPath.SetPath(Form("%s/*", calibType));
496 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
497 break;
498 }
499 }
500 if(!aPath.IsValid()){
501 AliError(Form("Not a valid path or detector: %s", calibType));
502 return;
503 }
504 }
505
53dd3c3d 506// // check that calibType refers to a "valid" detector name
507// Bool_t isDetector = kFALSE;
508// for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
509// TString detName = fgkDetectorName[iDet];
510// if(aPath.GetLevel0() == detName) {
511// isDetector = kTRUE;
512// break;
513// }
514// }
515//
516// if(!isDetector) {
517// AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
518// return;
519// }
c3a7b59a 520
521 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
ec92bee0 522 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 523 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
024cf675 524
525}
526
6bae477a 527//_____________________________________________________________________________
795e4a22 528Bool_t AliReconstruction::SetRunNumberFromData()
6bae477a 529{
530 // The method is called in Run() in order
531 // to set a correct run number.
532 // In case of raw data reconstruction the
533 // run number is taken from the raw data header
534
795e4a22 535 if (fSetRunNumberFromDataCalled) return kTRUE;
536 fSetRunNumberFromDataCalled = kTRUE;
537
538 AliCDBManager* man = AliCDBManager::Instance();
539
540 if(man->GetRun() > 0) {
21a3aa09 541 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
795e4a22 542 }
543
544 if (!fRunLoader) {
6bae477a 545 AliError("No run loader is found !");
546 return kFALSE;
547 }
548 // read run number from gAlice
ec92bee0 549 if(fRunLoader->GetAliRun())
f2ee4290 550 AliCDBManager::Instance()->SetRun(fRunLoader->GetHeader()->GetRun());
ec92bee0 551 else {
552 if(fRawReader) {
553 if(fRawReader->NextEvent()) {
554 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
555 fRawReader->RewindEvents();
556 }
557 else {
21a3aa09 558 if(man->GetRun() > 0) {
559 AliWarning("No raw events is found ! Using settings in AliCDBManager !");
560 man->Print();
561 return kTRUE;
562 }
563 else {
564 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
565 return kFALSE;
566 }
ec92bee0 567 }
568 }
569 else {
570 AliError("Neither gAlice nor RawReader objects are found !");
571 return kFALSE;
572 }
6bae477a 573 }
795e4a22 574
575 man->Print();
576
6bae477a 577 return kTRUE;
578}
579
795e4a22 580//_____________________________________________________________________________
581void AliReconstruction::SetCDBLock() {
582 // Set CDB lock: from now on it is forbidden to reset the run number
583 // or the default storage or to activate any further storage!
584
585 AliCDBManager::Instance()->SetLock(1);
586}
587
6bae477a 588//_____________________________________________________________________________
589Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
590{
591 // Read the alignment objects from CDB.
592 // Each detector is supposed to have the
593 // alignment objects in DET/Align/Data CDB path.
594 // All the detector objects are then collected,
595 // sorted by geometry level (starting from ALIC) and
596 // then applied to the TGeo geometry.
597 // Finally an overlaps check is performed.
598
599 // Load alignment data from CDB and fill fAlignObjArray
600 if(fLoadAlignFromCDB){
6bae477a 601
25be1e5c 602 TString detStr = detectors;
603 TString loadAlObjsListOfDets = "";
604
605 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
606 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
607 loadAlObjsListOfDets += fgkDetectorName[iDet];
608 loadAlObjsListOfDets += " ";
609 } // end loop over detectors
53dd3c3d 610 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
98e303d9 611 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
25be1e5c 612 }else{
613 // Check if the array with alignment objects was
614 // provided by the user. If yes, apply the objects
615 // to the present TGeo geometry
616 if (fAlignObjArray) {
617 if (gGeoManager && gGeoManager->IsClosed()) {
98e303d9 618 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
25be1e5c 619 AliError("The misalignment of one or more volumes failed!"
620 "Compare the list of simulated detectors and the list of detector alignment data!");
621 return kFALSE;
622 }
623 }
624 else {
625 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
6bae477a 626 return kFALSE;
627 }
628 }
6bae477a 629 }
25be1e5c 630
8e245d15 631 delete fAlignObjArray; fAlignObjArray=0;
a03b0371 632
6bae477a 633 return kTRUE;
634}
596a855f 635
636//_____________________________________________________________________________
637void AliReconstruction::SetGAliceFile(const char* fileName)
638{
639// set the name of the galice file
640
641 fGAliceFileName = fileName;
642}
643
21a3aa09 644//_____________________________________________________________________________
b58710ef 645void AliReconstruction::SetInput(const char* input)
21a3aa09 646{
b58710ef 647 // In case the input string starts with 'mem://', we run in an online mode
648 // and AliRawReaderDateOnline object is created. In all other cases a raw-data
649 // file is assumed. One can give as an input:
650 // mem://: - events taken from DAQ monitoring libs online
651 // or
652 // mem://<filename> - emulation of the above mode (via DATE monitoring libs)
653 fInput = input;
21a3aa09 654}
655
efd2085e 656//_____________________________________________________________________________
657void AliReconstruction::SetOption(const char* detector, const char* option)
658{
659// set options for the reconstruction of a detector
660
661 TObject* obj = fOptions.FindObject(detector);
662 if (obj) fOptions.Remove(obj);
663 fOptions.Add(new TNamed(detector, option));
664}
665
7e88424f 666//_____________________________________________________________________________
667void AliReconstruction::SetRecoParam(const char* detector, AliDetectorRecoParam *par)
668{
669 // Set custom reconstruction parameters for a given detector
670 // Single set of parameters for all the events
671 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
672 if(!strcmp(detector, fgkDetectorName[iDet])) {
673 par->SetAsDefault();
674 fRecoParam.AddDetRecoParam(iDet,par);
675 break;
676 }
677 }
678
679}
680
61807e09 681//_____________________________________________________________________________
856024f0 682Bool_t AliReconstruction::SetFieldMap(Float_t l3Current, Float_t diCurrent, Float_t factor, const char *path) {
61807e09 683 //------------------------------------------------
684 // The magnetic field map, defined externally...
685 // L3 current 30000 A -> 0.5 T
686 // L3 current 12000 A -> 0.2 T
687 // dipole current 6000 A
688 // The polarities must be the same
689 //------------------------------------------------
690 const Float_t l3NominalCurrent1=30000.; // (A)
691 const Float_t l3NominalCurrent2=12000.; // (A)
692 const Float_t diNominalCurrent =6000. ; // (A)
693
694 const Float_t tolerance=0.03; // relative current tolerance
695 const Float_t zero=77.; // "zero" current (A)
696
697 Int_t map=0;
698 Bool_t dipoleON=kFALSE;
699
856024f0 700 TString s=(factor < 0) ? "L3: -" : "L3: +";
61807e09 701
bb91052d 702 l3Current = TMath::Abs(l3Current);
61807e09 703 if (TMath::Abs(l3Current-l3NominalCurrent1)/l3NominalCurrent1 < tolerance) {
704 map=AliMagWrapCheb::k5kG;
705 s+="0.5 T; ";
706 } else
707 if (TMath::Abs(l3Current-l3NominalCurrent2)/l3NominalCurrent2 < tolerance) {
708 map=AliMagWrapCheb::k2kG;
709 s+="0.2 T; ";
710 } else
bb91052d 711 if (l3Current < zero) {
61807e09 712 map=AliMagWrapCheb::k2kG;
713 s+="0.0 T; ";
714 factor=0.; // in fact, this is a global factor...
4d338614 715 fUniformField=kTRUE; // track with the uniform (zero) B field
61807e09 716 } else {
bb91052d 717 AliError(Form("Wrong L3 current (%f A)!",l3Current));
61807e09 718 return kFALSE;
719 }
720
bb91052d 721 diCurrent = TMath::Abs(diCurrent);
61807e09 722 if (TMath::Abs(diCurrent-diNominalCurrent)/diNominalCurrent < tolerance) {
723 // 3% current tolerance...
724 dipoleON=kTRUE;
725 s+="Dipole ON";
726 } else
bb91052d 727 if (diCurrent < zero) { // some small current..
61807e09 728 dipoleON=kFALSE;
729 s+="Dipole OFF";
730 } else {
bb91052d 731 AliError(Form("Wrong dipole current (%f A)!",diCurrent));
61807e09 732 return kFALSE;
733 }
734
735 delete fForcedFieldMap;
736 fForcedFieldMap=
737 new AliMagWrapCheb("B field map ",s,2,factor,10.,map,dipoleON,path);
738
739 fForcedFieldMap->Print();
740
741 AliTracker::SetFieldMap(fForcedFieldMap,fUniformField);
742
743 return kTRUE;
744}
745
746
747Bool_t AliReconstruction::InitGRP() {
748 //------------------------------------
749 // Initialization of the GRP entry
750 //------------------------------------
751 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
752
753 if (entry) fGRPData = dynamic_cast<TMap*>(entry->GetObject());
754
755 if (!fGRPData) {
756 AliError("No GRP entry found in OCDB!");
757 return kFALSE;
758 }
759
7e88424f 760 TObjString *lhcState=
761 dynamic_cast<TObjString*>(fGRPData->GetValue("fLHCState"));
762 if (!lhcState) {
763 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
764 }
765
766 TObjString *beamType=
767 dynamic_cast<TObjString*>(fGRPData->GetValue("fAliceBeamType"));
768 if (!beamType) {
769 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
770 }
771
772 TObjString *beamEnergyStr=
773 dynamic_cast<TObjString*>(fGRPData->GetValue("fAliceBeamEnergy"));
774 if (!beamEnergyStr) {
775 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
776 }
777
778 TObjString *runType=
779 dynamic_cast<TObjString*>(fGRPData->GetValue("fRunType"));
780 if (!runType) {
781 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
782 }
783
784 TObjString *activeDetectors=
785 dynamic_cast<TObjString*>(fGRPData->GetValue("fDetectorMask"));
786 if (!activeDetectors) {
787 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
788 }
789
790 fRunInfo = new AliRunInfo(lhcState ? lhcState->GetString().Data() : "UNKNOWN",
791 beamType ? beamType->GetString().Data() : "UNKNOWN",
792 beamEnergyStr ? beamEnergyStr->GetString().Atof() : 0,
793 runType ? runType->GetString().Data() : "UNKNOWN",
794 activeDetectors ? activeDetectors->GetString().Atoi() : 1074790399);
795
796 // Process the list of active detectors
797 if (activeDetectors && activeDetectors->GetString().IsDigit()) {
798 UInt_t detMask = activeDetectors->GetString().Atoi();
799 fRunLocalReconstruction = MatchDetectorList(fRunLocalReconstruction,detMask);
800 fRunTracking = MatchDetectorList(fRunTracking,detMask);
801 fFillESD = MatchDetectorList(fFillESD,detMask);
ca13fb87 802 fQADetectors = MatchDetectorList(fQADetectors,detMask);
e84c88f5 803 fQASteer->SetActiveDetectors(fQADetectors) ;
7e88424f 804 }
805
806 AliInfo("===================================================================================");
807 AliInfo(Form("Running local reconstruction for detectors: %s",fRunLocalReconstruction.Data()));
808 AliInfo(Form("Running tracking for detectors: %s",fRunTracking.Data()));
809 AliInfo(Form("Filling ESD for detectors: %s",fFillESD.Data()));
ca13fb87 810 AliInfo(Form("Quality assurance is active for detectors: %s",fQADetectors.Data()));
7e88424f 811 AliInfo("===================================================================================");
61807e09 812
813 //*** Dealing with the magnetic field map
814 if (AliTracker::GetFieldMap()) {
815 AliInfo("Running with the externally set B field !");
816 } else {
817 // Construct the field map out of the information retrieved from GRP.
818
856024f0 819 Bool_t ok = kTRUE;
820
61807e09 821 // L3
822 TObjString *l3Current=
823 dynamic_cast<TObjString*>(fGRPData->GetValue("fL3Current"));
824 if (!l3Current) {
825 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
856024f0 826 ok = kFALSE;
61807e09 827 }
828 TObjString *l3Polarity=
829 dynamic_cast<TObjString*>(fGRPData->GetValue("fL3Polarity"));
830 if (!l3Polarity) {
831 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
856024f0 832 ok = kFALSE;
61807e09 833 }
834
835 // Dipole
836 TObjString *diCurrent=
837 dynamic_cast<TObjString*>(fGRPData->GetValue("fDipoleCurrent"));
838 if (!diCurrent) {
839 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
856024f0 840 ok = kFALSE;
61807e09 841 }
842 TObjString *diPolarity=
843 dynamic_cast<TObjString*>(fGRPData->GetValue("fDipolePolarity"));
844 if (!diPolarity) {
845 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
856024f0 846 ok = kFALSE;
61807e09 847 }
848
856024f0 849 if (ok) {
850 Float_t l3Cur=TMath::Abs(atof(l3Current->GetName()));
851 Float_t diCur=TMath::Abs(atof(diCurrent->GetName()));
852 Float_t l3Pol=atof(l3Polarity->GetName());
853 Float_t factor=1.;
854 if (l3Pol != 0.) factor=-1.;
855
61807e09 856
856024f0 857 if (!SetFieldMap(l3Cur, diCur, factor)) {
858 AliFatal("Failed to creat a B field map ! Exiting...");
859 }
860 AliInfo("Running with the B field constructed out of GRP !");
861 }
862 else {
863 AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
61807e09 864 }
865
61807e09 866 }
867
868
869 //*** Get the diamond profile from OCDB
870 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
871 if (entry) {
872 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
873 } else {
874 AliError("No diamond profile found in OCDB!");
875 }
876
877 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexTPC");
878 if (entry) {
879 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
880 } else {
881 AliError("No diamond profile found in OCDB!");
882 }
883
884 return kTRUE;
885}
886
596a855f 887//_____________________________________________________________________________
21a3aa09 888Bool_t AliReconstruction::Run(const char* input)
596a855f 889{
21a3aa09 890 // Run Run Run
891 AliCodeTimerAuto("");
596a855f 892
21a3aa09 893 if (!InitRun(input)) return kFALSE;
21a3aa09 894 //******* The loop over events
895 Int_t iEvent = 0;
896 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
897 (fRawReader && fRawReader->NextEvent())) {
898 if (!RunEvent(iEvent)) return kFALSE;
899 iEvent++;
900 }
901
902 if (!FinishRun()) return kFALSE;
903
904 return kTRUE;
905}
906
907//_____________________________________________________________________________
b58710ef 908Bool_t AliReconstruction::InitRun(const char* input)
21a3aa09 909{
910 // Initialize all the stuff before
911 // going into the event loop
912 // If the second argument is given, the first one is ignored and
913 // the reconstruction works in an online mode
914 AliCodeTimerAuto("");
915
b58710ef 916 // Overwrite the previous setting
21a3aa09 917 if (input) fInput = input;
918
919 // set the input in case of raw data
b58710ef 920 fRawReader = AliRawReader::Create(fInput.Data());
921 if (!fRawReader)
21a3aa09 922 AliInfo("Reconstruction will run over digits");
e0027792 923
35042093 924 if (!fEquipIdMap.IsNull() && fRawReader)
925 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
926
cd0b062e 927 if (!fUseHLTData.IsNull()) {
928 // create the RawReaderHLT which performs redirection of HLT input data for
929 // the specified detectors
930 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
931 if (pRawReader) {
932 fParentRawReader=fRawReader;
933 fRawReader=pRawReader;
934 } else {
935 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
936 }
937 }
938
0f88822a 939 AliSysInfo::AddStamp("Start");
f08fc9f5 940 // get the run loader
941 if (!InitRunLoader()) return kFALSE;
0f88822a 942 AliSysInfo::AddStamp("LoadLoader");
596a855f 943
ec92bee0 944 // Initialize the CDB storage
795e4a22 945 InitCDB();
946
947 AliSysInfo::AddStamp("LoadCDB");
ec92bee0 948
6bae477a 949 // Set run number in CDBManager (if it is not already set by the user)
795e4a22 950 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
951
952 // Set CDB lock: from now on it is forbidden to reset the run number
953 // or the default storage or to activate any further storage!
954 SetCDBLock();
955
6bae477a 956 // Import ideal TGeo geometry and apply misalignment
957 if (!gGeoManager) {
958 TString geom(gSystem->DirName(fGAliceFileName));
959 geom += "/geometry.root";
98e303d9 960 AliGeomManager::LoadGeometry(geom.Data());
ff5970a3 961
962 TString detsToCheck=fRunLocalReconstruction;
963 if(!AliGeomManager::CheckSymNamesLUT(detsToCheck.Data()))
0bf7aade 964 AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
6bae477a 965 if (!gGeoManager) if (fStopOnError) return kFALSE;
966 }
8e245d15 967
6bae477a 968 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
0f88822a 969 AliSysInfo::AddStamp("LoadGeom");
6bae477a 970
325aa76f 971
61807e09 972 if (!InitGRP()) return kFALSE;
325aa76f 973
7e88424f 974 // Read the reconstruction parameters from OCDB
975 if (!InitRecoParams()) {
976 if (fStopOnError) {
977 CleanUp();
978 return kFALSE;
979 }
980 }
981 AliSysInfo::AddStamp("ReadRecoParam");
325aa76f 982
983 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
984 if(fDiamondProfile && fMeanVertexConstraint) ftVertexer->SetVtxStart(fDiamondProfile);
2257f27e 985
986 // get vertexer
987 if (fRunVertexFinder && !CreateVertexer()) {
988 if (fStopOnError) {
989 CleanUp();
990 return kFALSE;
991 }
992 }
0f88822a 993 AliSysInfo::AddStamp("Vertexer");
596a855f 994
f08fc9f5 995 // get trackers
b8cd5251 996 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
24f7a148 997 if (fStopOnError) {
998 CleanUp();
999 return kFALSE;
1000 }
596a855f 1001 }
0f88822a 1002 AliSysInfo::AddStamp("LoadTrackers");
24f7a148 1003
b26c3770 1004 // get the possibly already existing ESD file and tree
21a3aa09 1005 fesd = new AliESDEvent(); fhltesd = new AliESDEvent();
b26c3770 1006 if (!gSystem->AccessPathName("AliESDs.root")){
1007 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
21a3aa09 1008 ffileOld = TFile::Open("AliESDs.old.root");
1009 if (ffileOld && ffileOld->IsOpen()) {
1010 ftreeOld = (TTree*) ffileOld->Get("esdTree");
1011 if (ftreeOld)fesd->ReadFromTree(ftreeOld);
1012 fhlttreeOld = (TTree*) ffileOld->Get("HLTesdTree");
1013 if (fhlttreeOld) fhltesd->ReadFromTree(fhlttreeOld);
b26c3770 1014 }
1015 }
1016
36711aa4 1017 // create the ESD output file and tree
21a3aa09 1018 ffile = TFile::Open("AliESDs.root", "RECREATE");
1019 ffile->SetCompressionLevel(2);
1020 if (!ffile->IsOpen()) {
815c2b38 1021 AliError("opening AliESDs.root failed");
21a3aa09 1022 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
596a855f 1023 }
46698ae4 1024
21a3aa09 1025 ftree = new TTree("esdTree", "Tree with ESD objects");
1026 fesd = new AliESDEvent();
1027 fesd->CreateStdContent();
1028 fesd->WriteToTree(ftree);
46698ae4 1029
21a3aa09 1030 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
1031 fhltesd = new AliESDEvent();
1032 fhltesd->CreateStdContent();
1033 fhltesd->WriteToTree(fhlttree);
46698ae4 1034
5728d3d5 1035
1d99986f 1036 if (fWriteESDfriend) {
21a3aa09 1037 fesdf = new AliESDfriend();
1038 TBranch *br=ftree->Branch("ESDfriend.","AliESDfriend", &fesdf);
46698ae4 1039 br->SetFile("AliESDfriends.root");
21a3aa09 1040 fesd->AddObject(fesdf);
1d99986f 1041 }
5728d3d5 1042
444753c6 1043
c5e3e5d1 1044
b649205a 1045 if (fRawReader) fRawReader->RewindEvents();
a5fa6165 1046
95cee32f 1047 ProcInfo_t ProcInfo;
1048 gSystem->GetProcInfo(&ProcInfo);
1049 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
8661738e 1050
325aa76f 1051 //QA
ca13fb87 1052 if ( !fInLoopQA ) {
1053 if (fRunQA && fRawReader && fQATasks.Contains(Form("%d", AliQA::kRAWS))) {
1054 fQASteer->Run(fQADetectors, fRawReader) ;
1055 fSameQACycle = kTRUE ;
1056 }
325aa76f 1057 }
ca13fb87 1058
e84c88f5 1059 //Initialize the QA and start of cycle for out-of-loop QA
f6806ad3 1060 if (fRunQA) {
e84c88f5 1061 fQASteer->InitQADataMaker(AliCDBManager::Instance()->GetRun(), fRecoParam, fSameQACycle, !fInLoopQA) ;
ca13fb87 1062 }
e84c88f5 1063
1064 if (fRunGlobalQA) {
1065 fSameQACycle = kFALSE;
1066 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1067 AliInfo(Form("Initializing the global QA data maker"));
1068 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1069 TObjArray *arr=qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
1070 AliTracker::SetResidualsArray(arr);
1071 if (!fInLoopQA) {
1072 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
1073 fSameQACycle = kTRUE;
1074 }
1075 }
1076 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
1077 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
1078 if (!fInLoopQA) {
1079 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
1080 fSameQACycle = kTRUE;
1081 }
1082 }
ca13fb87 1083 }
aa3c69a9 1084
7167ae53 1085 //Initialize the Plane Efficiency framework
1086 if (fRunPlaneEff && !InitPlaneEff()) {
21a3aa09 1087 if(fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
7167ae53 1088 }
aa3c69a9 1089
14dd053c 1090 if (strcmp(gProgName,"alieve") == 0)
1091 fRunAliEVE = InitAliEVE();
1092
21a3aa09 1093 return kTRUE;
1094}
1095
1096//_____________________________________________________________________________
1097Bool_t AliReconstruction::RunEvent(Int_t iEvent)
1098{
1099 // run the reconstruction over a single event
1100 // The event loop is steered in Run method
1101
1102 AliCodeTimerAuto("");
1103
1104 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
1105 fRunLoader->SetEventNumber(iEvent);
1106 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1107 iEvent, iEvent);
1108 //?? fRunLoader->MakeTree("H");
1109 fRunLoader->TreeE()->Fill();
1110 }
1111
1112 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
1113 // copy old ESD to the new one
1114 if (ftreeOld) {
1115 fesd->ReadFromTree(ftreeOld);
1116 ftreeOld->GetEntry(iEvent);
1117 ftree->Fill();
b26c3770 1118 }
21a3aa09 1119 if (fhlttreeOld) {
f6806ad3 1120 fhltesd->ReadFromTree(fhlttreeOld);
21a3aa09 1121 fhlttreeOld->GetEntry(iEvent);
1122 fhlttree->Fill();
1123 }
1124 return kTRUE;
1125 }
1126
1127 AliInfo(Form("processing event %d", iEvent));
aa3c69a9 1128
7e88424f 1129 // Fill Event-info object
1130 GetEventInfo();
1131 fRecoParam.SetEventSpecie(fRunInfo,fEventInfo);
1132
ca13fb87 1133 //Start of cycle for the in-loop QA
1134 if (fInLoopQA && fRunQA) {
e84c88f5 1135 fQASteer->InitQADataMaker(AliCDBManager::Instance()->GetRun(), fRecoParam, fSameQACycle, fInLoopQA) ;
1136 }
1137 if (fInLoopQA && fRunGlobalQA) {
1138 fSameQACycle = kFALSE;
1139 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1140 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1141 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
1142 fSameQACycle = kTRUE;
1143 }
1144 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
1145 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
1146 fSameQACycle = kTRUE;
1147 }
1148 }
aa3c69a9 1149
e84c88f5 1150 fRunLoader->GetEvent(iEvent);
24f7a148 1151
bb0901a4 1152 char aFileName[256];
1153 sprintf(aFileName, "ESD_%d.%d_final.root",
f08fc9f5 1154 fRunLoader->GetHeader()->GetRun(),
1155 fRunLoader->GetHeader()->GetEventNrInRun());
21a3aa09 1156 if (!gSystem->AccessPathName(aFileName)) return kTRUE;
24f7a148 1157
ca13fb87 1158 // QA on single raw
e84c88f5 1159 if (fInLoopQA && fRunQA)
1160 fQASteer->RunOneEvent(fRawReader) ;
ca13fb87 1161
d506c543 1162 // local single event reconstruction
b26c3770 1163 if (!fRunLocalReconstruction.IsNull()) {
d506c543 1164 TString detectors=fRunLocalReconstruction;
a441bf51 1165 // run HLT event reconstruction first
d506c543 1166 // ;-( IsSelected changes the string
1167 if (IsSelected("HLT", detectors) &&
1168 !RunLocalEventReconstruction("HLT")) {
a441bf51 1169 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1170 }
1171 detectors=fRunLocalReconstruction;
1172 detectors.ReplaceAll("HLT", "");
1173 if (!RunLocalEventReconstruction(detectors)) {
21a3aa09 1174 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
b26c3770 1175 }
1176 }
1177
21a3aa09 1178 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1179 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1180 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1181 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
46698ae4 1182
d6ee376f 1183 // Set magnetic field from the tracker
21a3aa09 1184 fesd->SetMagneticField(AliTracker::GetBz());
1185 fhltesd->SetMagneticField(AliTracker::GetBz());
596a855f 1186
46698ae4 1187
1188
2e3550da 1189 // Fill raw-data error log into the ESD
21a3aa09 1190 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 1191
2257f27e 1192 // vertex finder
1193 if (fRunVertexFinder) {
21a3aa09 1194 if (!ReadESD(fesd, "vertex")) {
1195 if (!RunVertexFinder(fesd)) {
1196 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
2257f27e 1197 }
21a3aa09 1198 if (fCheckPointLevel > 0) WriteESD(fesd, "vertex");
2257f27e 1199 }
1200 }
1201
e66fbafb 1202 // Muon tracking
b8cd5251 1203 if (!fRunTracking.IsNull()) {
e66fbafb 1204 if (fRunMuonTracking) {
21a3aa09 1205 if (!RunMuonTracking(fesd)) {
1206 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
24f7a148 1207 }
596a855f 1208 }
1209 }
1210
e66fbafb 1211 // barrel tracking
1212 if (!fRunTracking.IsNull()) {
21a3aa09 1213 if (!ReadESD(fesd, "tracking")) {
1214 if (!RunTracking(fesd)) {
1215 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
e66fbafb 1216 }
21a3aa09 1217 if (fCheckPointLevel > 0) WriteESD(fesd, "tracking");
e66fbafb 1218 }
1219 }
21c573b7 1220
596a855f 1221 // fill ESD
1222 if (!fFillESD.IsNull()) {
d506c543 1223 TString detectors=fFillESD;
f6806ad3 1224 // run HLT first and on hltesd
d506c543 1225 // ;-( IsSelected changes the string
1226 if (IsSelected("HLT", detectors) &&
1227 !FillESD(fhltesd, "HLT")) {
f6806ad3 1228 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1229 }
1230 detectors=fFillESD;
d5105682 1231 // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
1232 if (detectors.Contains("ALL")) {
1233 detectors="";
1234 for (Int_t idet=0; idet<fgkNDetectors; ++idet){
1235 detectors += fgkDetectorName[idet];
1236 detectors += " ";
1237 }
1238 }
f6806ad3 1239 detectors.ReplaceAll("HLT", "");
1240 if (!FillESD(fesd, detectors)) {
21a3aa09 1241 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
596a855f 1242 }
1243 }
a5fa6165 1244
001397cd 1245 // fill Event header information from the RawEventHeader
21a3aa09 1246 if (fRawReader){FillRawEventHeaderESD(fesd);}
596a855f 1247
1248 // combined PID
21a3aa09 1249 AliESDpid::MakePID(fesd);
1250 if (fCheckPointLevel > 1) WriteESD(fesd, "PID");
596a855f 1251
b647652d 1252 if (fFillTriggerESD) {
21a3aa09 1253 if (!ReadESD(fesd, "trigger")) {
e84c88f5 1254 if (!FillTriggerESD(fesd)) {
1255 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1256 }
1257 if (fCheckPointLevel > 1) WriteESD(fesd, "trigger");
b647652d 1258 }
1259 }
1260
21a3aa09 1261 ffile->cd();
a6ee503a 1262
3c3709c4 1263 //
67be5c77 1264 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 1265 //
21a3aa09 1266 const Int_t ntracks = fesd->GetNumberOfTracks();
1267 const Double_t kBz = fesd->GetMagneticField();
3c3709c4 1268 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1269
1270 TObjArray trkArray;
1271 UShort_t *selectedIdx=new UShort_t[ntracks];
1272
1273 for (Int_t itrack=0; itrack<ntracks; itrack++){
1274 const Double_t kMaxStep = 5; //max step over the material
1275 Bool_t ok;
1276
21a3aa09 1277 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 1278 if (!track) continue;
1279
1280 AliExternalTrackParam *tpcTrack =
1281 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 1282 ok = kFALSE;
1283 if (tpcTrack)
1284 ok = AliTracker::
1285 PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
43c9dae1 1286
3c3709c4 1287 if (ok) {
1288 Int_t n=trkArray.GetEntriesFast();
1289 selectedIdx[n]=track->GetID();
1290 trkArray.AddLast(tpcTrack);
1291 }
1292
3d65e645 1293 //Tracks refitted by ITS should already be at the SPD vertex
1294 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1295
1296 AliTracker::
1297 PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1298 track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kVeryBig);
3c3709c4 1299
3c3709c4 1300 }
1301
1302 //
1303 // Improve the reconstructed primary vertex position using the tracks
1304 //
1305 TObject *obj = fOptions.FindObject("ITS");
c060d7fe 1306 if (obj) {
1307 TString optITS = obj->GetTitle();
1308 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
a84e2607 1309 fRunVertexFinderTracks=kFALSE;
c060d7fe 1310 }
3c3709c4 1311 if (fRunVertexFinderTracks) {
1312 // TPC + ITS primary vertex
21a3aa09 1313 ftVertexer->SetITSrefitRequired();
43c9dae1 1314 if(fDiamondProfile && fMeanVertexConstraint) {
21a3aa09 1315 ftVertexer->SetVtxStart(fDiamondProfile);
43c9dae1 1316 } else {
21a3aa09 1317 ftVertexer->SetConstraintOff();
43c9dae1 1318 }
21a3aa09 1319 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 1320 if (pvtx) {
1321 if (pvtx->GetStatus()) {
21a3aa09 1322 fesd->SetPrimaryVertex(pvtx);
3c3709c4 1323 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 1324 AliESDtrack *t = fesd->GetTrack(i);
3d65e645 1325 t->RelateToVertex(pvtx, kBz, kVeryBig);
3c3709c4 1326 }
1327 }
1328 }
1329
1330 // TPC-only primary vertex
21a3aa09 1331 ftVertexer->SetITSrefitNotRequired();
43c9dae1 1332 if(fDiamondProfileTPC && fMeanVertexConstraint) {
21a3aa09 1333 ftVertexer->SetVtxStart(fDiamondProfileTPC);
43c9dae1 1334 } else {
21a3aa09 1335 ftVertexer->SetConstraintOff();
43c9dae1 1336 }
21a3aa09 1337 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 1338 if (pvtx) {
1339 if (pvtx->GetStatus()) {
21a3aa09 1340 fesd->SetPrimaryVertexTPC(pvtx);
3d65e645 1341 for (Int_t i=0; i<ntracks; i++) {
1342 AliESDtrack *t = fesd->GetTrack(i);
1343 t->RelateToVertexTPC(pvtx, kBz, kVeryBig);
3c3709c4 1344 }
1345 }
1346 }
1347
1348 }
1349 delete[] selectedIdx;
1350
21a3aa09 1351 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
17c86e90 1352
c5e3e5d1 1353
d1683eef 1354 if (fRunV0Finder) {
1355 // V0 finding
1356 AliV0vertexer vtxer;
21a3aa09 1357 vtxer.Tracks2V0vertices(fesd);
5e4ff34d 1358
d1683eef 1359 if (fRunCascadeFinder) {
1360 // Cascade finding
1361 AliCascadeVertexer cvtxer;
21a3aa09 1362 cvtxer.V0sTracks2CascadeVertices(fesd);
d1683eef 1363 }
5e4ff34d 1364 }
1365
596a855f 1366 // write ESD
21a3aa09 1367 if (fCleanESD) CleanESD(fesd);
854c6476 1368
b8bd1ab8 1369 if (fRunQA) {
1370 if (fRunGlobalQA) {
1371 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1372 if (qadm && fQATasks.Contains(Form("%d", AliQA::kESDS)))
1373 qadm->Exec(AliQA::kESDS, fesd);
1374 }
1375 }
854c6476 1376
1d99986f 1377 if (fWriteESDfriend) {
21a3aa09 1378 fesdf->~AliESDfriend();
1379 new (fesdf) AliESDfriend(); // Reset...
1380 fesd->GetESDfriend(fesdf);
1d99986f 1381 }
21a3aa09 1382 ftree->Fill();
500d54ab 1383
2d91a353 1384 // Auto-save the ESD tree in case of prompt reco @P2
1385 if (fRawReader && fRawReader->UseAutoSaveESD())
1386 ftree->AutoSave("SaveSelf");
1387
500d54ab 1388 // write HLT ESD
21a3aa09 1389 fhlttree->Fill();
1d99986f 1390
14dd053c 1391 // call AliEVE
1392 if (fRunAliEVE) RunAliEVE();
1393
21a3aa09 1394 if (fCheckPointLevel > 0) WriteESD(fesd, "final");
1395 fesd->Reset();
1396 fhltesd->Reset();
5728d3d5 1397 if (fWriteESDfriend) {
21a3aa09 1398 fesdf->~AliESDfriend();
1399 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 1400 }
a5fa6165 1401
21a3aa09 1402 ProcInfo_t ProcInfo;
95cee32f 1403 gSystem->GetProcInfo(&ProcInfo);
1404 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
a5fa6165 1405
7e963665 1406
ce43afbe 1407 // End of cycle for the in-loop
ca13fb87 1408 if (fInLoopQA && fRunQA) {
e84c88f5 1409 fQASteer->RunOneEvent(fesd) ;
1410 fQASteer->EndOfCycle() ;
1411 }
ca13fb87 1412 if (fRunGlobalQA) {
1413 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1414 if (qadm) {
e84c88f5 1415 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1416 qadm->EndOfCycle(AliQA::kRECPOINTS);
1417 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1418 qadm->EndOfCycle(AliQA::kESDS);
1419 qadm->Finish();
ca13fb87 1420 }
1421 }
7e88424f 1422
ca13fb87 1423 fEventInfo.Reset();
1424 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1425 if (fReconstructor[iDet])
e84c88f5 1426 fReconstructor[iDet]->SetRecoParam(NULL);
ca13fb87 1427 }
1428
1429 return kTRUE;
21a3aa09 1430}
1431
21a3aa09 1432//_____________________________________________________________________________
1433Bool_t AliReconstruction::FinishRun()
1434{
1435 // Finalize the run
1436 // Called after the exit
1437 // from the event loop
1438 AliCodeTimerAuto("");
1439
1440 if (fIsNewRunLoader) { // galice.root didn't exist
1441 fRunLoader->WriteHeader("OVERWRITE");
1442 fRunLoader->CdGAFile();
1443 fRunLoader->Write(0, TObject::kOverwrite);
1444 }
1445
1446 ftree->GetUserInfo()->Add(fesd);
1447 fhlttree->GetUserInfo()->Add(fhltesd);
f747912b 1448
1449 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1450 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1451
1452 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1453 cdbMapCopy->SetOwner(1);
1454 cdbMapCopy->SetName("cdbMap");
1455 TIter iter(cdbMap->GetTable());
1456
1457 TPair* pair = 0;
1458 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1459 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1460 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1461 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1462 }
1463
1464 TList *cdbListCopy = new TList();
1465 cdbListCopy->SetOwner(1);
1466 cdbListCopy->SetName("cdbList");
1467
1468 TIter iter2(cdbList);
1469
b940cb9b 1470 AliCDBId* id=0;
e84c88f5 1471 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 1472 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 1473 }
1474
21a3aa09 1475 ftree->GetUserInfo()->Add(cdbMapCopy);
1476 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 1477
46698ae4 1478
1479 if(fESDPar.Contains("ESD.par")){
1480 AliInfo("Attaching ESD.par to Tree");
1481 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
21a3aa09 1482 ftree->GetUserInfo()->Add(fn);
596a855f 1483 }
1484
46698ae4 1485
21a3aa09 1486 ffile->cd();
aa3c69a9 1487
a9c0e6db 1488 if (fWriteESDfriend)
21a3aa09 1489 ftree->SetBranchStatus("ESDfriend*",0);
562dd0b4 1490 // we want to have only one tree version number
21a3aa09 1491 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1492 fhlttree->Write();
f3a97c86 1493
a7a1e1c7 1494// Finish with Plane Efficiency evaluation: before of CleanUp !!!
1495 if (fRunPlaneEff && !FinishPlaneEff()) {
1496 AliWarning("Finish PlaneEff evaluation failed");
1497 }
1498
eae191bc 1499 gROOT->cd();
21a3aa09 1500 CleanUp(ffile, ffileOld);
eae191bc 1501
a7807689 1502 if (fWriteAOD) {
7a3b2050 1503 AliWarning("AOD creation not supported anymore during reconstruction. See ANALYSIS/AliAnalysisTaskESDfilter.cxx instead.");
a7807689 1504 }
1505
f3a97c86 1506 // Create tags for the events in the ESD tree (the ESD tree is always present)
1507 // In case of empty events the tags will contain dummy values
08e1a23e 1508 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
6b6e4472 1509 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData);
a1069ee1 1510 if (fWriteAOD) {
7a3b2050 1511 AliWarning("AOD tag creation not supported anymore during reconstruction.");
a1069ee1 1512 }
596a855f 1513
aa3c69a9 1514 //Finish QA and end of cycle for out-of-loop QA
e84c88f5 1515 if (!fInLoopQA && fRunQA)
1516 fQASteer->Run(fRunLocalReconstruction.Data(), AliQA::kNULLTASKINDEX, fSameQACycle) ;
1517 if (!fInLoopQA && fRunGlobalQA) {
1518 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1519 if (qadm) {
1520 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1521 qadm->EndOfCycle(AliQA::kRECPOINTS);
1522 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1523 qadm->EndOfCycle(AliQA::kESDS);
1524 qadm->Finish();
1525 }
1526 }
1527
795e4a22 1528 // Cleanup of CDB manager: cache and active storages!
1529 AliCDBManager::Instance()->ClearCache();
1530
596a855f 1531 return kTRUE;
1532}
1533
1534
1535//_____________________________________________________________________________
c4aa7a4c 1536Bool_t AliReconstruction::RunLocalReconstruction(const TString& /*detectors*/)
596a855f 1537{
59697224 1538// run the local reconstruction
0f88822a 1539 static Int_t eventNr=0;
87932dab 1540 AliCodeTimerAuto("")
030b532d 1541
d76c31f4 1542 // AliCDBManager* man = AliCDBManager::Instance();
1543// Bool_t origCache = man->GetCacheFlag();
8e245d15 1544
d76c31f4 1545// TString detStr = detectors;
1546// for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1547// if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1548// AliReconstructor* reconstructor = GetReconstructor(iDet);
1549// if (!reconstructor) continue;
1550// if (reconstructor->HasLocalReconstruction()) continue;
b8cd5251 1551
d76c31f4 1552// AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1553// AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
87932dab 1554
d76c31f4 1555// AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1556// AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
8e245d15 1557
d76c31f4 1558// man->SetCacheFlag(kTRUE);
1559// TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
1560// man->GetAll(calibPath); // entries are cached!
8e245d15 1561
d76c31f4 1562// AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
87932dab 1563
d76c31f4 1564// if (fRawReader) {
1565// fRawReader->RewindEvents();
1566// reconstructor->Reconstruct(fRunLoader, fRawReader);
1567// } else {
1568// reconstructor->Reconstruct(fRunLoader);
1569// }
87932dab 1570
d76c31f4 1571// AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
0f88822a 1572 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
8e245d15 1573
d76c31f4 1574// // unload calibration data
1575// man->UnloadFromCache(calibPath);
1576// //man->ClearCache();
1577// }
596a855f 1578
d76c31f4 1579// man->SetCacheFlag(origCache);
8e245d15 1580
d76c31f4 1581// if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1582// AliError(Form("the following detectors were not found: %s",
1583// detStr.Data()));
1584// if (fStopOnError) return kFALSE;
1585// }
596a855f 1586
0f88822a 1587 eventNr++;
596a855f 1588 return kTRUE;
1589}
1590
b26c3770 1591//_____________________________________________________________________________
1592Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1593{
1594// run the local reconstruction
aa3c69a9 1595
0f88822a 1596 static Int_t eventNr=0;
87932dab 1597 AliCodeTimerAuto("")
b26c3770 1598
1599 TString detStr = detectors;
1600 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1601 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1602 AliReconstructor* reconstructor = GetReconstructor(iDet);
1603 if (!reconstructor) continue;
1604 AliLoader* loader = fLoader[iDet];
f6806ad3 1605 // Matthias April 2008: temporary fix to run HLT reconstruction
1606 // although the HLT loader is missing
1607 if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
1608 if (fRawReader) {
1609 reconstructor->Reconstruct(fRawReader, NULL);
1610 } else {
1611 TTree* dummy=NULL;
1612 reconstructor->Reconstruct(dummy, NULL);
1613 }
1614 continue;
1615 }
d76c31f4 1616 if (!loader) {
1617 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1618 continue;
1619 }
b26c3770 1620 // conversion of digits
1621 if (fRawReader && reconstructor->HasDigitConversion()) {
1622 AliInfo(Form("converting raw data digits into root objects for %s",
1623 fgkDetectorName[iDet]));
30bbd491 1624// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1625// fgkDetectorName[iDet]));
b26c3770 1626 loader->LoadDigits("update");
1627 loader->CleanDigits();
1628 loader->MakeDigitsContainer();
1629 TTree* digitsTree = loader->TreeD();
1630 reconstructor->ConvertDigits(fRawReader, digitsTree);
1631 loader->WriteDigits("OVERWRITE");
1632 loader->UnloadDigits();
b26c3770 1633 }
b26c3770 1634 // local reconstruction
b26c3770 1635 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
30bbd491 1636 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
b26c3770 1637 loader->LoadRecPoints("update");
1638 loader->CleanRecPoints();
1639 loader->MakeRecPointsContainer();
1640 TTree* clustersTree = loader->TreeR();
1641 if (fRawReader && !reconstructor->HasDigitConversion()) {
1642 reconstructor->Reconstruct(fRawReader, clustersTree);
1643 } else {
1644 loader->LoadDigits("read");
1645 TTree* digitsTree = loader->TreeD();
1646 if (!digitsTree) {
1647 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1648 if (fStopOnError) return kFALSE;
1649 } else {
1650 reconstructor->Reconstruct(digitsTree, clustersTree);
1651 }
1652 loader->UnloadDigits();
1653 }
d76c31f4 1654
aa3c69a9 1655 // In-loop QA for local reconstrucion
30bbd491 1656 TString detQAStr(fQADetectors) ;
e84c88f5 1657 if (fRunQA && fInLoopQA)
1658 fQASteer->RunOneEventInOneDetector(iDet, clustersTree) ;
1659
1660 loader->WriteRecPoints("OVERWRITE");
1661 loader->UnloadRecPoints();
1662 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
1663 }
1664 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
b26c3770 1665 AliError(Form("the following detectors were not found: %s",
1666 detStr.Data()));
1667 if (fStopOnError) return kFALSE;
1668 }
0f88822a 1669 eventNr++;
b26c3770 1670 return kTRUE;
1671}
1672
596a855f 1673//_____________________________________________________________________________
af885e0f 1674Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 1675{
1676// run the barrel tracking
1677
87932dab 1678 AliCodeTimerAuto("")
030b532d 1679
2257f27e 1680 AliESDVertex* vertex = NULL;
1681 Double_t vtxPos[3] = {0, 0, 0};
1682 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1683 TArrayF mcVertex(3);
a6b0b91b 1684 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1685 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1686 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1687 }
2257f27e 1688
b8cd5251 1689 if (fVertexer) {
815c2b38 1690 AliInfo("running the ITS vertex finder");
308c2f7c 1691 if (fLoader[0]) {
1692 fLoader[0]->LoadRecPoints();
1693 TTree* cltree = fLoader[0]->TreeR();
1694 if (cltree) {
1695 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1696 vertex = fVertexer->FindVertexForCurrentEvent(cltree);
1697 }
1698 else {
1699 AliError("Can't get the ITS cluster tree");
1700 }
1701 fLoader[0]->UnloadRecPoints();
1702 }
1703 else {
1704 AliError("Can't get the ITS loader");
1705 }
2257f27e 1706 if(!vertex){
815c2b38 1707 AliWarning("Vertex not found");
c710f220 1708 vertex = new AliESDVertex();
d1a50cb5 1709 vertex->SetName("default");
2257f27e 1710 }
1711 else {
d1a50cb5 1712 vertex->SetName("reconstructed");
2257f27e 1713 }
1714
1715 } else {
815c2b38 1716 AliInfo("getting the primary vertex from MC");
2257f27e 1717 vertex = new AliESDVertex(vtxPos, vtxErr);
1718 }
1719
1720 if (vertex) {
1721 vertex->GetXYZ(vtxPos);
1722 vertex->GetSigmaXYZ(vtxErr);
1723 } else {
815c2b38 1724 AliWarning("no vertex reconstructed");
2257f27e 1725 vertex = new AliESDVertex(vtxPos, vtxErr);
1726 }
06cc9d95 1727 esd->SetPrimaryVertexSPD(vertex);
32e449be 1728 // if SPD multiplicity has been determined, it is stored in the ESD
25be1e5c 1729 AliMultiplicity *mult = fVertexer->GetMultiplicity();
32e449be 1730 if(mult)esd->SetMultiplicity(mult);
1731
b8cd5251 1732 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1733 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1734 }
2257f27e 1735 delete vertex;
1736
2257f27e 1737 return kTRUE;
1738}
1739
1f46a9ae 1740//_____________________________________________________________________________
af885e0f 1741Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 1742{
1743// run the HLT barrel tracking
1744
87932dab 1745 AliCodeTimerAuto("")
1f46a9ae 1746
1747 if (!fRunLoader) {
1748 AliError("Missing runLoader!");
1749 return kFALSE;
1750 }
1751
1752 AliInfo("running HLT tracking");
1753
1754 // Get a pointer to the HLT reconstructor
1755 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1756 if (!reconstructor) return kFALSE;
1757
1758 // TPC + ITS
1759 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1760 TString detName = fgkDetectorName[iDet];
1761 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1762 reconstructor->SetOption(detName.Data());
d76c31f4 1763 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 1764 if (!tracker) {
1765 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1766 if (fStopOnError) return kFALSE;
9dcc06e1 1767 continue;
1f46a9ae 1768 }
1769 Double_t vtxPos[3];
1770 Double_t vtxErr[3]={0.005,0.005,0.010};
1771 const AliESDVertex *vertex = esd->GetVertex();
1772 vertex->GetXYZ(vtxPos);
1773 tracker->SetVertex(vtxPos,vtxErr);
1774 if(iDet != 1) {
1775 fLoader[iDet]->LoadRecPoints("read");
1776 TTree* tree = fLoader[iDet]->TreeR();
1777 if (!tree) {
1778 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1779 return kFALSE;
1780 }
1781 tracker->LoadClusters(tree);
1782 }
1783 if (tracker->Clusters2Tracks(esd) != 0) {
1784 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1785 return kFALSE;
1786 }
1787 if(iDet != 1) {
1788 tracker->UnloadClusters();
1789 }
1790 delete tracker;
1791 }
1792
1f46a9ae 1793 return kTRUE;
1794}
1795
e66fbafb 1796//_____________________________________________________________________________
af885e0f 1797Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 1798{
1799// run the muon spectrometer tracking
1800
87932dab 1801 AliCodeTimerAuto("")
e66fbafb 1802
1803 if (!fRunLoader) {
1804 AliError("Missing runLoader!");
1805 return kFALSE;
1806 }
1807 Int_t iDet = 7; // for MUON
1808
1809 AliInfo("is running...");
1810
1811 // Get a pointer to the MUON reconstructor
1812 AliReconstructor *reconstructor = GetReconstructor(iDet);
1813 if (!reconstructor) return kFALSE;
1814
1815
1816 TString detName = fgkDetectorName[iDet];
1817 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 1818 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 1819 if (!tracker) {
1820 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1821 return kFALSE;
1822 }
1823
e66fbafb 1824 // read RecPoints
761350a6 1825 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 1826
761350a6 1827 tracker->LoadClusters(fLoader[iDet]->TreeR());
1828
1829 Int_t rv = tracker->Clusters2Tracks(esd);
1830
761350a6 1831 if ( rv )
1832 {
e66fbafb 1833 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1834 return kFALSE;
1835 }
761350a6 1836
e66fbafb 1837 fLoader[iDet]->UnloadRecPoints();
1838
c1954ee5 1839 tracker->UnloadClusters();
1840
e66fbafb 1841 delete tracker;
1842
e66fbafb 1843 return kTRUE;
1844}
1845
1846
2257f27e 1847//_____________________________________________________________________________
af885e0f 1848Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
2257f27e 1849{
1850// run the barrel tracking
0f88822a 1851 static Int_t eventNr=0;
87932dab 1852 AliCodeTimerAuto("")
24f7a148 1853
815c2b38 1854 AliInfo("running tracking");
596a855f 1855
91b876d1 1856 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 1857 if (fReconstructor[11] && fLoader[11]) {
1858 fLoader[11]->LoadRecPoints("READ");
1859 TTree *treeR = fLoader[11]->TreeR();
1860 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1861 }
91b876d1 1862
b8cd5251 1863 // pass 1: TPC + ITS inwards
1864 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1865 if (!fTracker[iDet]) continue;
1866 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 1867
b8cd5251 1868 // load clusters
1869 fLoader[iDet]->LoadRecPoints("read");
6efecea1 1870 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 1871 TTree* tree = fLoader[iDet]->TreeR();
1872 if (!tree) {
1873 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 1874 return kFALSE;
1875 }
b8cd5251 1876 fTracker[iDet]->LoadClusters(tree);
6efecea1 1877 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 1878 // run tracking
1879 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1880 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 1881 return kFALSE;
1882 }
b8cd5251 1883 if (fCheckPointLevel > 1) {
1884 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1885 }
878e1fe1 1886 // preliminary PID in TPC needed by the ITS tracker
1887 if (iDet == 1) {
b26c3770 1888 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
878e1fe1 1889 AliESDpid::MakePID(esd);
0f88822a 1890 }
6efecea1 1891 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 1892 }
596a855f 1893
b8cd5251 1894 // pass 2: ALL backwards
aa3c69a9 1895
b8cd5251 1896 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1897 if (!fTracker[iDet]) continue;
1898 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1899
1900 // load clusters
1901 if (iDet > 1) { // all except ITS, TPC
1902 TTree* tree = NULL;
7b61cd9c 1903 fLoader[iDet]->LoadRecPoints("read");
6efecea1 1904 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 1905 tree = fLoader[iDet]->TreeR();
b8cd5251 1906 if (!tree) {
1907 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 1908 return kFALSE;
1909 }
0f88822a 1910 fTracker[iDet]->LoadClusters(tree);
6efecea1 1911 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 1912 }
24f7a148 1913
b8cd5251 1914 // run tracking
283f39c6 1915 if (iDet>1) // start filling residuals for the "outer" detectors
1916 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1917
b8cd5251 1918 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1919 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 1920 // return kFALSE;
b8cd5251 1921 }
1922 if (fCheckPointLevel > 1) {
1923 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1924 }
24f7a148 1925
b8cd5251 1926 // unload clusters
6e65648b 1927 if (iDet > 3) { // all except ITS, TPC, TRD and TOF
b8cd5251 1928 fTracker[iDet]->UnloadClusters();
7b61cd9c 1929 fLoader[iDet]->UnloadRecPoints();
b8cd5251 1930 }
8f37df88 1931 // updated PID in TPC needed by the ITS tracker -MI
1932 if (iDet == 1) {
8f37df88 1933 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1934 AliESDpid::MakePID(esd);
1935 }
6efecea1 1936 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 1937 }
283f39c6 1938 //stop filling residuals for the "outer" detectors
1939 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
596a855f 1940
b8cd5251 1941 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 1942
b8cd5251 1943 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1944 if (!fTracker[iDet]) continue;
1945 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 1946
b8cd5251 1947 // run tracking
283f39c6 1948 if (iDet<2) // start filling residuals for TPC and ITS
1949 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1950
b8cd5251 1951 if (fTracker[iDet]->RefitInward(esd) != 0) {
1952 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 1953 // return kFALSE;
b8cd5251 1954 }
db2368d0 1955 // run postprocessing
1956 if (fTracker[iDet]->PostProcess(esd) != 0) {
1957 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
1958 // return kFALSE;
1959 }
b8cd5251 1960 if (fCheckPointLevel > 1) {
1961 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1962 }
6efecea1 1963 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
6e65648b 1964 }
1965
1966 // write space-points to the ESD in case alignment data output
1967 // is switched on
1968 if (fWriteAlignmentData)
1969 WriteAlignmentData(esd);
1970
1971 for (Int_t iDet = 3; iDet >= 0; iDet--) {
1972 if (!fTracker[iDet]) continue;
b8cd5251 1973 // unload clusters
1974 fTracker[iDet]->UnloadClusters();
6efecea1 1975 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 1976 fLoader[iDet]->UnloadRecPoints();
6efecea1 1977 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 1978 }
283f39c6 1979 // stop filling residuals for TPC and ITS
3b378a42 1980 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
854c6476 1981
0f88822a 1982 eventNr++;
596a855f 1983 return kTRUE;
1984}
1985
d64bd07d 1986//_____________________________________________________________________________
1987Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1988 //
1989 // Remove the data which are not needed for the physics analysis.
1990 //
1991
d64bd07d 1992 Int_t nTracks=esd->GetNumberOfTracks();
18571674 1993 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 1994 AliInfo
1995 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 1996
18571674 1997 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 1998 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 1999
7f68891d 2000 nTracks=esd->GetNumberOfTracks();
18571674 2001 nV0s=esd->GetNumberOfV0s();
cf37fd88 2002 AliInfo
ae5d5566 2003 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 2004
7f68891d 2005 return rc;
d64bd07d 2006}
2007
596a855f 2008//_____________________________________________________________________________
af885e0f 2009Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 2010{
2011// fill the event summary data
2012
87932dab 2013 AliCodeTimerAuto("")
0f88822a 2014 static Int_t eventNr=0;
596a855f 2015 TString detStr = detectors;
abe0c04e 2016
b8cd5251 2017 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
abe0c04e 2018 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 2019 AliReconstructor* reconstructor = GetReconstructor(iDet);
2020 if (!reconstructor) continue;
b8cd5251 2021 if (!ReadESD(esd, fgkDetectorName[iDet])) {
2022 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
b26c3770 2023 TTree* clustersTree = NULL;
d76c31f4 2024 if (fLoader[iDet]) {
b26c3770 2025 fLoader[iDet]->LoadRecPoints("read");
2026 clustersTree = fLoader[iDet]->TreeR();
2027 if (!clustersTree) {
2028 AliError(Form("Can't get the %s clusters tree",
2029 fgkDetectorName[iDet]));
2030 if (fStopOnError) return kFALSE;
2031 }
2032 }
2033 if (fRawReader && !reconstructor->HasDigitConversion()) {
2034 reconstructor->FillESD(fRawReader, clustersTree, esd);
2035 } else {
2036 TTree* digitsTree = NULL;
2037 if (fLoader[iDet]) {
2038 fLoader[iDet]->LoadDigits("read");
2039 digitsTree = fLoader[iDet]->TreeD();
2040 if (!digitsTree) {
2041 AliError(Form("Can't get the %s digits tree",
2042 fgkDetectorName[iDet]));
2043 if (fStopOnError) return kFALSE;
2044 }
2045 }
2046 reconstructor->FillESD(digitsTree, clustersTree, esd);
2047 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
2048 }
d76c31f4 2049 if (fLoader[iDet]) {
b26c3770 2050 fLoader[iDet]->UnloadRecPoints();
2051 }
2052
b8cd5251 2053 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
596a855f 2054 }
2055 }
2056
2057 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 2058 AliError(Form("the following detectors were not found: %s",
2059 detStr.Data()));
596a855f 2060 if (fStopOnError) return kFALSE;
2061 }
6efecea1 2062 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
0f88822a 2063 eventNr++;
596a855f 2064 return kTRUE;
2065}
2066
b647652d 2067//_____________________________________________________________________________
af885e0f 2068Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 2069{
2070 // Reads the trigger decision which is
2071 // stored in Trigger.root file and fills
2072 // the corresponding esd entries
2073
87932dab 2074 AliCodeTimerAuto("")
2075
b647652d 2076 AliInfo("Filling trigger information into the ESD");
2077
2078 if (fRawReader) {
2079 AliCTPRawStream input(fRawReader);
2080 if (!input.Next()) {
7e88424f 2081 AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
b647652d 2082 }
2083 else {
7e88424f 2084 if (esd->GetTriggerMask() != input.GetClassMask())
2085 AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
2086 input.GetClassMask(),esd->GetTriggerMask()));
2087 if (esd->GetOrbitNumber() != input.GetOrbitID())
2088 AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
2089 input.GetOrbitID(),esd->GetOrbitNumber()));
2090 if (esd->GetBunchCrossNumber() != input.GetBCID())
2091 AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
2092 input.GetBCID(),esd->GetBunchCrossNumber()));
b647652d 2093 }
b024fd7f 2094
7e88424f 2095 // Here one has to add the filling of trigger inputs and
2096 // interaction records
2097 // ...
b024fd7f 2098 }
b647652d 2099 return kTRUE;
2100}
596a855f 2101
001397cd 2102
2103
2104
2105
2106//_____________________________________________________________________________
af885e0f 2107Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 2108{
2109 //
2110 // Filling information from RawReader Header
2111 //
2112
151bea4e 2113 if (!fRawReader) return kFALSE;
2114
001397cd 2115 AliInfo("Filling information from RawReader Header");
151bea4e 2116
2117 esd->SetBunchCrossNumber(fRawReader->GetBCID());
2118 esd->SetOrbitNumber(fRawReader->GetOrbitID());
2119 esd->SetPeriodNumber(fRawReader->GetPeriod());
2120
2121 esd->SetTimeStamp(fRawReader->GetTimestamp());
2122 esd->SetEventType(fRawReader->GetType());
001397cd 2123
2124 return kTRUE;
2125}
2126
2127
596a855f 2128//_____________________________________________________________________________
2129Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
2130{
2131// check whether detName is contained in detectors
2132// if yes, it is removed from detectors
2133
2134 // check if all detectors are selected
2135 if ((detectors.CompareTo("ALL") == 0) ||
2136 detectors.BeginsWith("ALL ") ||
2137 detectors.EndsWith(" ALL") ||
2138 detectors.Contains(" ALL ")) {
2139 detectors = "ALL";
2140 return kTRUE;
2141 }
2142
2143 // search for the given detector
2144 Bool_t result = kFALSE;
2145 if ((detectors.CompareTo(detName) == 0) ||
2146 detectors.BeginsWith(detName+" ") ||
2147 detectors.EndsWith(" "+detName) ||
2148 detectors.Contains(" "+detName+" ")) {
2149 detectors.ReplaceAll(detName, "");
2150 result = kTRUE;
2151 }
2152
2153 // clean up the detectors string
2154 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2155 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2156 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2157
2158 return result;
2159}
e583c30d 2160
f08fc9f5 2161//_____________________________________________________________________________
2162Bool_t AliReconstruction::InitRunLoader()
2163{
2164// get or create the run loader
2165
2166 if (gAlice) delete gAlice;
2167 gAlice = NULL;
2168
b26c3770 2169 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2170 // load all base libraries to get the loader classes
2171 TString libs = gSystem->GetLibraries();
2172 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2173 TString detName = fgkDetectorName[iDet];
2174 if (detName == "HLT") continue;
2175 if (libs.Contains("lib" + detName + "base.so")) continue;
2176 gSystem->Load("lib" + detName + "base.so");
2177 }
f08fc9f5 2178 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2179 if (!fRunLoader) {
2180 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2181 CleanUp();
2182 return kFALSE;
2183 }
325aa76f 2184
b26c3770 2185 fRunLoader->CdGAFile();
325aa76f 2186 fRunLoader->LoadgAlice();
f08fc9f5 2187
6cae184e 2188 //PH This is a temporary fix to give access to the kinematics
2189 //PH that is needed for the labels of ITS clusters
f2ee4290 2190 fRunLoader->LoadHeader();
6cae184e 2191 fRunLoader->LoadKinematics();
2192
f08fc9f5 2193 } else { // galice.root does not exist
2194 if (!fRawReader) {
2195 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
2196 CleanUp();
2197 return kFALSE;
2198 }
2199 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2200 AliConfig::GetDefaultEventFolderName(),
2201 "recreate");
2202 if (!fRunLoader) {
2203 AliError(Form("could not create run loader in file %s",
2204 fGAliceFileName.Data()));
2205 CleanUp();
2206 return kFALSE;
2207 }
21a3aa09 2208 fIsNewRunLoader = kTRUE;
f08fc9f5 2209 fRunLoader->MakeTree("E");
21a3aa09 2210
973388c2 2211 if (fNumberOfEventsPerFile > 0)
2212 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2213 else
21a3aa09 2214 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 2215 }
2216
2217 return kTRUE;
2218}
2219
c757bafd 2220//_____________________________________________________________________________
b8cd5251 2221AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 2222{
f08fc9f5 2223// get the reconstructor object and the loader for a detector
c757bafd 2224
7e88424f 2225 if (fReconstructor[iDet]) {
2226 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2227 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2228 fReconstructor[iDet]->SetRecoParam(par);
2229 }
2230 return fReconstructor[iDet];
2231 }
b8cd5251 2232
2233 // load the reconstructor object
2234 TPluginManager* pluginManager = gROOT->GetPluginManager();
2235 TString detName = fgkDetectorName[iDet];
2236 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 2237
2238 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 2239
b8cd5251 2240 AliReconstructor* reconstructor = NULL;
2241 // first check if a plugin is defined for the reconstructor
2242 TPluginHandler* pluginHandler =
2243 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 2244 // if not, add a plugin for it
2245 if (!pluginHandler) {
b8cd5251 2246 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 2247 TString libs = gSystem->GetLibraries();
2248 if (libs.Contains("lib" + detName + "base.so") ||
2249 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 2250 pluginManager->AddHandler("AliReconstructor", detName,
2251 recName, detName + "rec", recName + "()");
2252 } else {
2253 pluginManager->AddHandler("AliReconstructor", detName,
2254 recName, detName, recName + "()");
c757bafd 2255 }
b8cd5251 2256 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2257 }
2258 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2259 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 2260 }
b8cd5251 2261 if (reconstructor) {
2262 TObject* obj = fOptions.FindObject(detName.Data());
2263 if (obj) reconstructor->SetOption(obj->GetTitle());
d76c31f4 2264 reconstructor->Init();
b8cd5251 2265 fReconstructor[iDet] = reconstructor;
2266 }
2267
f08fc9f5 2268 // get or create the loader
2269 if (detName != "HLT") {
2270 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2271 if (!fLoader[iDet]) {
2272 AliConfig::Instance()
2273 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2274 detName, detName);
2275 // first check if a plugin is defined for the loader
bb0901a4 2276 pluginHandler =
f08fc9f5 2277 pluginManager->FindHandler("AliLoader", detName);
2278 // if not, add a plugin for it
2279 if (!pluginHandler) {
2280 TString loaderName = "Ali" + detName + "Loader";
2281 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2282 pluginManager->AddHandler("AliLoader", detName,
2283 loaderName, detName + "base",
2284 loaderName + "(const char*, TFolder*)");
2285 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2286 }
2287 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2288 fLoader[iDet] =
2289 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2290 fRunLoader->GetEventFolder());
2291 }
2292 if (!fLoader[iDet]) { // use default loader
2293 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2294 }
2295 if (!fLoader[iDet]) {
2296 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 2297 if (fStopOnError) return NULL;
f08fc9f5 2298 } else {
2299 fRunLoader->AddLoader(fLoader[iDet]);
2300 fRunLoader->CdGAFile();
2301 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2302 fRunLoader->Write(0, TObject::kOverwrite);
2303 }
2304 }
2305 }
2306
7e88424f 2307 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2308 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2309 reconstructor->SetRecoParam(par);
2310 }
b8cd5251 2311 return reconstructor;
c757bafd 2312}
2313
2257f27e 2314//_____________________________________________________________________________
2315Bool_t AliReconstruction::CreateVertexer()
2316{
2317// create the vertexer
2318
b8cd5251 2319 fVertexer = NULL;
2320 AliReconstructor* itsReconstructor = GetReconstructor(0);
59697224 2321 if (itsReconstructor) {
d76c31f4 2322 fVertexer = itsReconstructor->CreateVertexer();
2257f27e 2323 }
b8cd5251 2324 if (!fVertexer) {
815c2b38 2325 AliWarning("couldn't create a vertexer for ITS");
2257f27e 2326 if (fStopOnError) return kFALSE;
2327 }
2328
2329 return kTRUE;
2330}
2331
24f7a148 2332//_____________________________________________________________________________
b8cd5251 2333Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 2334{
f08fc9f5 2335// create the trackers
24f7a148 2336
b8cd5251 2337 TString detStr = detectors;
2338 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2339 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2340 AliReconstructor* reconstructor = GetReconstructor(iDet);
2341 if (!reconstructor) continue;
2342 TString detName = fgkDetectorName[iDet];
1f46a9ae 2343 if (detName == "HLT") {
2344 fRunHLTTracking = kTRUE;
2345 continue;
2346 }
e66fbafb 2347 if (detName == "MUON") {
2348 fRunMuonTracking = kTRUE;
2349 continue;
2350 }
2351
f08fc9f5 2352
d76c31f4 2353 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 2354 if (!fTracker[iDet] && (iDet < 7)) {
2355 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 2356 if (fStopOnError) return kFALSE;
2357 }
6efecea1 2358 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 2359 }
2360
24f7a148 2361 return kTRUE;
2362}
2363
e583c30d 2364//_____________________________________________________________________________
b26c3770 2365void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
e583c30d 2366{
2367// delete trackers and the run loader and close and delete the file
2368
b8cd5251 2369 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2370 delete fReconstructor[iDet];
2371 fReconstructor[iDet] = NULL;
2372 fLoader[iDet] = NULL;
2373 delete fTracker[iDet];
2374 fTracker[iDet] = NULL;
2375 }
7e88424f 2376 if (fRunInfo) delete fRunInfo;
2377 fRunInfo = NULL;
2378
b8cd5251 2379 delete fVertexer;
2380 fVertexer = NULL;
21a3aa09 2381
2382 if (ftVertexer) delete ftVertexer;
2383 ftVertexer = NULL;
795e4a22 2384
2385 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
2386 delete fDiamondProfile;
2387 fDiamondProfile = NULL;
43c9dae1 2388 delete fDiamondProfileTPC;
2389 fDiamondProfileTPC = NULL;
6b6e4472 2390 delete fGRPData;
2391 fGRPData = NULL;
795e4a22 2392 }
e583c30d 2393
444753c6 2394
e583c30d 2395 delete fRunLoader;
2396 fRunLoader = NULL;
b649205a 2397 delete fRawReader;
2398 fRawReader = NULL;
cd0b062e 2399 if (fParentRawReader) delete fParentRawReader;
2400 fParentRawReader=NULL;
e583c30d 2401
2402 if (file) {
2403 file->Close();
2404 delete file;
2405 }
b26c3770 2406
2407 if (fileOld) {
2408 fileOld->Close();
2409 delete fileOld;
2410 gSystem->Unlink("AliESDs.old.root");
2411 }
21a3aa09 2412
e583c30d 2413}
24f7a148 2414
24f7a148 2415//_____________________________________________________________________________
af885e0f 2416
2417Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
24f7a148 2418{
2419// read the ESD event from a file
2420
2421 if (!esd) return kFALSE;
2422 char fileName[256];
2423 sprintf(fileName, "ESD_%d.%d_%s.root",
31fd97b2 2424 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
24f7a148 2425 if (gSystem->AccessPathName(fileName)) return kFALSE;
2426
f3a97c86 2427 AliInfo(Form("reading ESD from file %s", fileName));
815c2b38 2428 AliDebug(1, Form("reading ESD from file %s", fileName));
24f7a148 2429 TFile* file = TFile::Open(fileName);
2430 if (!file || !file->IsOpen()) {
815c2b38 2431 AliError(Form("opening %s failed", fileName));
24f7a148 2432 delete file;
2433 return kFALSE;
2434 }
2435
2436 gROOT->cd();
2437 delete esd;
af885e0f 2438 esd = (AliESDEvent*) file->Get("ESD");
24f7a148 2439 file->Close();
2440 delete file;
2441 return kTRUE;
af885e0f 2442
24f7a148 2443}
2444
af885e0f 2445
2446
24f7a148 2447//_____________________________________________________________________________
af885e0f 2448void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
24f7a148 2449{
2450// write the ESD event to a file
2451
2452 if (!esd) return;
2453 char fileName[256];
2454 sprintf(fileName, "ESD_%d.%d_%s.root",
31fd97b2 2455 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
24f7a148 2456
815c2b38 2457 AliDebug(1, Form("writing ESD to file %s", fileName));
24f7a148 2458 TFile* file = TFile::Open(fileName, "recreate");
2459 if (!file || !file->IsOpen()) {
815c2b38 2460 AliError(Form("opening %s failed", fileName));
24f7a148 2461 } else {
2462 esd->Write("ESD");
2463 file->Close();
2464 }
2465 delete file;
2466}
f3a97c86 2467
2468
af885e0f 2469void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 2470{
2471 // Write space-points which are then used in the alignment procedures
6e65648b 2472 // For the moment only ITS, TPC, TRD and TOF
98937d93 2473
98937d93 2474 Int_t ntracks = esd->GetNumberOfTracks();
2475 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2476 {
2477 AliESDtrack *track = esd->GetTrack(itrack);
2478 Int_t nsp = 0;
ef7253ac 2479 Int_t idx[200];
6e65648b 2480 for (Int_t iDet = 3; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
2481 nsp += track->GetNcls(iDet);
2482
2483 if (iDet==0) { // ITS "extra" clusters
2484 track->GetClusters(iDet,idx);
2485 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
2486 }
2487 }
2488
98937d93 2489 if (nsp) {
2490 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2491 track->SetTrackPointArray(sp);
2492 Int_t isptrack = 0;
2493 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2494 AliTracker *tracker = fTracker[iDet];
2495 if (!tracker) continue;
6e65648b 2496 Int_t nspdet = track->GetClusters(iDet,idx);
2497
2498 if (iDet==0) // ITS "extra" clusters
2499 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
2500
98937d93 2501 if (nspdet <= 0) continue;
98937d93 2502 AliTrackPoint p;
2503 Int_t isp = 0;
2504 Int_t isp2 = 0;
4ed6fb1c 2505 while (isp2 < nspdet) {
f3c6e4c9 2506 Bool_t isvalid=kTRUE;
2507
2508 Int_t index=idx[isp++];
2509 if (index < 0) continue;
2510
c12b6e44 2511 TString dets = fgkDetectorName[iDet];
2512 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2513 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2514 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2515 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
f3c6e4c9 2516 isvalid = tracker->GetTrackPointTrackingError(index,p,track);
48ce48d1 2517 } else {
f3c6e4c9 2518 isvalid = tracker->GetTrackPoint(index,p);
48ce48d1 2519 }
2520 isp2++;
98937d93 2521 if (!isvalid) continue;
f3c6e4c9 2522 sp->AddPoint(isptrack,&p); isptrack++;
98937d93 2523 }
98937d93 2524 }
2525 }
2526 }
98937d93 2527}
2e3550da 2528
2529//_____________________________________________________________________________
af885e0f 2530void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 2531{
2532 // The method reads the raw-data error log
2533 // accumulated within the rawReader.
2534 // It extracts the raw-data errors related to
2535 // the current event and stores them into
2536 // a TClonesArray inside the esd object.
2537
2538 if (!fRawReader) return;
2539
2540 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2541
2542 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2543 if (!log) continue;
2544 if (iEvent != log->GetEventNumber()) continue;
2545
2546 esd->AddRawDataErrorLog(log);
2547 }
2548
2549}
46698ae4 2550
605cb8bb 2551TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString pName){
b545009a 2552 // Dump a file content into a char in TNamed
46698ae4 2553 ifstream in;
2554 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2555 Int_t kBytes = (Int_t)in.tellg();
2556 printf("Size: %d \n",kBytes);
2557 TNamed *fn = 0;
2558 if(in.good()){
2559 char* memblock = new char [kBytes];
2560 in.seekg (0, ios::beg);
2561 in.read (memblock, kBytes);
2562 in.close();
2563 TString fData(memblock,kBytes);
605cb8bb 2564 fn = new TNamed(pName,fData);
46698ae4 2565 printf("fData Size: %d \n",fData.Sizeof());
605cb8bb 2566 printf("pName Size: %d \n",pName.Sizeof());
46698ae4 2567 printf("fn Size: %d \n",fn->Sizeof());
2568 delete[] memblock;
2569 }
2570 else{
2571 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2572 }
2573
2574 return fn;
2575}
2576
605cb8bb 2577void AliReconstruction::TNamedToFile(TTree* fTree, TString pName){
46698ae4 2578 // This is not really needed in AliReconstruction at the moment
2579 // but can serve as a template
2580
2581 TList *fList = fTree->GetUserInfo();
605cb8bb 2582 TNamed *fn = (TNamed*)fList->FindObject(pName.Data());
46698ae4 2583 printf("fn Size: %d \n",fn->Sizeof());
2584
605cb8bb 2585 TString fTmp(fn->GetName()); // to be 100% sure in principle pName also works
46698ae4 2586 const char* cdata = fn->GetTitle();
2587 printf("fTmp Size %d\n",fTmp.Sizeof());
2588
2589 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2590 printf("calculated size %d\n",size);
605cb8bb 2591 ofstream out(pName.Data(),ios::out | ios::binary);
46698ae4 2592 out.write(cdata,size);
2593 out.close();
2594
2595}
6efecea1 2596
8661738e 2597//_____________________________________________________________________________
2598void AliReconstruction::CheckQA()
2599{
2600// check the QA of SIM for this run and remove the detectors
2601// with status Fatal
2602
abe0c04e 2603 TString newRunLocalReconstruction ;
2604 TString newRunTracking ;
2605 TString newFillESD ;
2606
8661738e 2607 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2608 TString detName(AliQA::GetDetName(iDet)) ;
96d67a8d 2609 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2610 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
8661738e 2611 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
abe0c04e 2612 } else {
2613 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2614 fRunLocalReconstruction.Contains("ALL") ) {
2615 newRunLocalReconstruction += detName ;
2616 newRunLocalReconstruction += " " ;
2617 }
2618 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2619 fRunTracking.Contains("ALL") ) {
2620 newRunTracking += detName ;
2621 newRunTracking += " " ;
2622 }
2623 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2624 fFillESD.Contains("ALL") ) {
2625 newFillESD += detName ;
2626 newFillESD += " " ;
8661738e 2627 }
2628 }
2629 }
abe0c04e 2630 fRunLocalReconstruction = newRunLocalReconstruction ;
2631 fRunTracking = newRunTracking ;
2632 fFillESD = newFillESD ;
a5fa6165 2633}
5b188f2f 2634
2635//_____________________________________________________________________________
2636Int_t AliReconstruction::GetDetIndex(const char* detector)
2637{
2638 // return the detector index corresponding to detector
2639 Int_t index = -1 ;
2640 for (index = 0; index < fgkNDetectors ; index++) {
2641 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2642 break ;
2643 }
2644 return index ;
2645}
7167ae53 2646//_____________________________________________________________________________
2647Bool_t AliReconstruction::FinishPlaneEff() {
2648 //
2649 // Here execute all the necessary operationis, at the end of the tracking phase,
d7f8fd68 2650 // in case that evaluation of PlaneEfficiencies was required for some detector.
2651 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
7167ae53 2652 //
2653 // This Preliminary version works only FOR ITS !!!!!
2654 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2655 //
2656 // Input: none
d7f8fd68 2657 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
7167ae53 2658 //
2659 Bool_t ret=kFALSE;
2660 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
d7f8fd68 2661 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
7167ae53 2662 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
5fbd4fd6 2663 if(fTracker[iDet]) {
d7f8fd68 2664 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2665 TString name=planeeff->GetName();
2666 name+=".root";
2667 TFile* pefile = TFile::Open(name, "RECREATE");
2668 ret=(Bool_t)planeeff->Write();
2669 pefile->Close();
5fbd4fd6 2670 if(planeeff->GetCreateHistos()) {
d7f8fd68 2671 TString hname=planeeff->GetName();
2672 hname+="Histo.root";
2673 ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
5fbd4fd6 2674 }
2675 }
7167ae53 2676 }
2677 return ret;
2678}
2679//_____________________________________________________________________________
2680Bool_t AliReconstruction::InitPlaneEff() {
2681//
2682 // Here execute all the necessary operations, before of the tracking phase,
2683 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2684 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2685 // which should be updated/recalculated.
2686 //
2687 // This Preliminary version will work only FOR ITS !!!!!
2688 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2689 //
2690 // Input: none
2691 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2692 //
2693 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));
2694 return kTRUE;
7520312d 2695}
14dd053c 2696
2697//_____________________________________________________________________________
2698Bool_t AliReconstruction::InitAliEVE()
2699{
2700 // This method should be called only in case
2701 // AliReconstruction is run
2702 // within the alieve environment.
2703 // It will initialize AliEVE in a way
2704 // so that it can visualize event processed
2705 // by AliReconstruction.
2706 // The return flag shows whenever the
2707 // AliEVE initialization was successful or not.
2708
2709 TString macroStr;
2710 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
2711 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
2712 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
2713
de33999e 2714 gROOT->ProcessLine("if (!gAliEveEvent) {gAliEveEvent = new AliEveEventManager();gAliEveEvent->SetAutoLoad(kTRUE);gAliEveEvent->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(gAliEveEvent);};");
2715 gROOT->ProcessLine("alieve_online_init()");
14dd053c 2716
2717 return kTRUE;
2718}
2719
2720//_____________________________________________________________________________
2721void AliReconstruction::RunAliEVE()
2722{
2723 // Runs AliEVE visualisation of
2724 // the current event.
2725 // Should be executed only after
2726 // successful initialization of AliEVE.
2727
2728 AliInfo("Running AliEVE...");
2729 gROOT->ProcessLine(Form("gAliEveEvent->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p);",fRunLoader,fRawReader,fesd));
2730 gROOT->ProcessLine("gAliEveEvent->StartStopAutoLoadTimer();");
2731 gSystem->Run();
2732}
ce43afbe 2733
2734//_____________________________________________________________________________
2735Bool_t AliReconstruction::SetRunQA(TString detAndAction)
2736{
2737 // Allows to run QA for a selected set of detectors
2738 // and a selected set of tasks among RAWS, RECPOINTS and ESDS
2739 // all selected detectors run the same selected tasks
2740
2741 if (!detAndAction.Contains(":")) {
2742 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
2743 fRunQA = kFALSE ;
2744 return kFALSE ;
2745 }
2746 Int_t colon = detAndAction.Index(":") ;
2747 fQADetectors = detAndAction(0, colon) ;
2748 if (fQADetectors.Contains("ALL") )
2749 fQADetectors = fFillESD ;
e84c88f5 2750 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
ce43afbe 2751 if (fQATasks.Contains("ALL") ) {
2752 fQATasks = Form("%d %d %d", AliQA::kRAWS, AliQA::kRECPOINTS, AliQA::kESDS) ;
2753 } else {
2754 fQATasks.ToUpper() ;
2755 TString tempo("") ;
2756 if ( fQATasks.Contains("RAW") )
2757 tempo = Form("%d ", AliQA::kRAWS) ;
2758 if ( fQATasks.Contains("RECPOINT") )
2759 tempo += Form("%d ", AliQA::kRECPOINTS) ;
2760 if ( fQATasks.Contains("ESD") )
2761 tempo += Form("%d ", AliQA::kESDS) ;
2762 fQATasks = tempo ;
2763 if (fQATasks.IsNull()) {
2764 AliInfo("No QA requested\n") ;
2765 fRunQA = kFALSE ;
2766 return kTRUE ;
2767 }
2768 }
2769 TString tempo(fQATasks) ;
e84c88f5 2770 tempo.ReplaceAll(Form("%d", AliQA::kRAWS), AliQA::GetTaskName(AliQA::kRAWS)) ;
2771 tempo.ReplaceAll(Form("%d", AliQA::kRECPOINTS), AliQA::GetTaskName(AliQA::kRECPOINTS)) ;
2772 tempo.ReplaceAll(Form("%d", AliQA::kESDS), AliQA::GetTaskName(AliQA::kESDS)) ;
2773 fQASteer->SetActiveDetectors(fQADetectors) ;
2774 fQASteer->SetTasks(fQATasks) ;
ce43afbe 2775 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
2776 fRunQA = kTRUE ;
2777 return kTRUE;
2778}
2779
7e88424f 2780//_____________________________________________________________________________
2781Bool_t AliReconstruction::InitRecoParams()
2782{
2783 // The method accesses OCDB and retrieves all
2784 // the available reco-param objects from there.
2785
2786 Bool_t isOK = kTRUE;
2787
2788 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2789
2790 if (fRecoParam.GetDetRecoParamArray(iDet)) {
2791 AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
2792 continue;
2793 }
2794
2795 AliDebug(1, Form("Loading RecoParam objects for detector: %s",fgkDetectorName[iDet]));
2796
2797 AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
2798 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
2799 if(!entry){
2800 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
2801 isOK = kFALSE;
2802 }
2803 else {
2804 TObject *recoParamObj = entry->GetObject();
2805 if (dynamic_cast<TObjArray*>(recoParamObj)) {
2806 // The detector has a normal TobjArray of AliDetectorRecoParam objects
2807 // Registering them in AliRecoParam
2808 fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
2809 }
2810 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
2811 // The detector has only onse set of reco parameters
2812 // Registering it in AliRecoParam
2813 AliInfo(Form("Single set of reco parameters found for detector %s",fgkDetectorName[iDet]));
2814 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
2815 fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
2816 }
2817 else {
2818 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
2819 isOK = kFALSE;
2820 }
2821 entry->SetOwner(0);
2822 }
2823 }
2824
2825 return isOK;
2826}
2827
2828//_____________________________________________________________________________
2829Bool_t AliReconstruction::GetEventInfo()
2830{
2831 // Fill the event info object
2832 // ...
2833 AliCodeTimerAuto("")
2834
2835 AliCentralTrigger *aCTP = NULL;
2836 if (fRawReader) {
2837 fEventInfo.SetEventType(fRawReader->GetType());
2838
2839 ULong64_t mask = fRawReader->GetClassMask();
2840 fEventInfo.SetTriggerMask(mask);
2841 UInt_t clmask = fRawReader->GetDetectorPattern()[0];
2842 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
2843
2844 aCTP = new AliCentralTrigger();
2845 TString configstr("");
2846 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
2847 AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
2848 delete aCTP;
2849 return kFALSE;
2850 }
2851 aCTP->SetClassMask(mask);
2852 aCTP->SetClusterMask(clmask);
2853 }
2854 else {
2855 fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
2856
2857 if (fRunLoader && (!fRunLoader->LoadTrigger())) {
2858 aCTP = fRunLoader->GetTrigger();
2859 fEventInfo.SetTriggerMask(aCTP->GetClassMask());
2860 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
2861 }
2862 else {
2863 AliWarning("No trigger can be loaded! The trigger information will not be used!");
2864 return kFALSE;
2865 }
2866 }
2867
2868 AliTriggerConfiguration *config = aCTP->GetConfiguration();
2869 if (!config) {
2870 AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
2871 if (fRawReader) delete aCTP;
2872 return kFALSE;
2873 }
2874
2875 TString trclasses;
2876 ULong64_t trmask = fEventInfo.GetTriggerMask();
2877 const TObjArray& classesArray = config->GetClasses();
2878 Int_t nclasses = classesArray.GetEntriesFast();
2879 for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
2880 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
2881 if (trclass) {
2882 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
2883 fesd->SetTriggerClass(trclass->GetName(),trindex);
2884 if (trmask & (1 << trindex)) {
2885 trclasses += " ";
2886 trclasses += trclass->GetName();
2887 trclasses += " ";
2888 }
2889 }
2890 }
2891 fEventInfo.SetTriggerClasses(trclasses);
2892
2893 if (!aCTP->CheckTriggeredDetectors()) {
2894 if (fRawReader) delete aCTP;
2895 return kFALSE;
2896 }
2897
2898 if (fRawReader) delete aCTP;
2899
2900 // We have to fill also the HLT decision here!!
2901 // ...
2902
2903 return kTRUE;
2904}
2905
2906const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
2907{
2908 // Match the detector list found in the rec.C or the default 'ALL'
2909 // to the list found in the GRP (stored there by the shuttle PP which
2910 // gets the information from ECS)
2911 static TString resultList;
2912 TString detList = detectorList;
2913
2914 resultList = "";
2915
2916 for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
2917 if ((detectorMask >> iDet) & 0x1) {
2918 TString det = AliDAQ::OfflineModuleName(iDet);
2919 if ((detList.CompareTo("ALL") == 0) ||
2920 detList.BeginsWith("ALL ") ||
2921 detList.EndsWith(" ALL") ||
2922 detList.Contains(" ALL ") ||
2923 (detList.CompareTo(det) == 0) ||
2924 detList.BeginsWith(det) ||
2925 detList.EndsWith(det) ||
2926 detList.Contains( " "+det+" " )) {
2927 if (!resultList.EndsWith(det + " ")) {
2928 resultList += det;
2929 resultList += " ";
2930 }
2931 }
2932 }
2933 }
2934
2935 // HLT
2936 if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
2937 TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
2938 if ((detList.CompareTo("ALL") == 0) ||
2939 detList.BeginsWith("ALL ") ||
2940 detList.EndsWith(" ALL") ||
2941 detList.Contains(" ALL ") ||
2942 (detList.CompareTo(hltDet) == 0) ||
2943 detList.BeginsWith(hltDet) ||
2944 detList.EndsWith(hltDet) ||
2945 detList.Contains( " "+hltDet+" " )) {
2946 resultList += hltDet;
2947 }
2948 }
2949
2950 return resultList.Data();
2951
2952}