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