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