Dummy routine for stand-allone use of dpmjet added.
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
CommitLineData
596a855f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class for running the reconstruction //
21// //
22// Clusters and tracks are created for all detectors and all events by //
23// typing: //
24// //
25// AliReconstruction rec; //
26// rec.Run(); //
27// //
28// The Run method returns kTRUE in case of successful execution. //
c71de921 29// //
30// If the input to the reconstruction are not simulated digits but raw data, //
31// this can be specified by an argument of the Run method or by the method //
32// //
33// rec.SetInput("..."); //
34// //
35// The input formats and the corresponding argument are: //
36// - DDL raw data files: directory name, ends with "/" //
37// - raw data root file: root file name, extension ".root" //
38// - raw data DATE file: DATE file name, any other non-empty string //
39// - MC root files : empty string, default //
40// //
b26c3770 41// By default all events are reconstructed. The reconstruction can be //
42// limited to a range of events by giving the index of the first and the //
43// last event as an argument to the Run method or by calling //
44// //
45// rec.SetEventRange(..., ...); //
46// //
47// The index -1 (default) can be used for the last event to indicate no //
48// upper limit of the event range. //
49// //
973388c2 50// In case of raw-data reconstruction the user can modify the default //
51// number of events per digits/clusters/tracks file. In case the option //
52// is not used the number is set 1. In case the user provides 0, than //
53// the number of events is equal to the number of events inside the //
54// raw-data file (i.e. one digits/clusters/tracks file): //
55// //
56// rec.SetNumberOfEventsPerFile(...); //
57// //
58// //
596a855f 59// The name of the galice file can be changed from the default //
e583c30d 60// "galice.root" by passing it as argument to the AliReconstruction //
61// constructor or by //
596a855f 62// //
63// rec.SetGAliceFile("..."); //
64// //
59697224 65// The local reconstruction can be switched on or off for individual //
66// detectors by //
596a855f 67// //
59697224 68// rec.SetRunLocalReconstruction("..."); //
596a855f 69// //
70// The argument is a (case sensitive) string with the names of the //
71// detectors separated by a space. The special string "ALL" selects all //
72// available detectors. This is the default. //
73// //
c71de921 74// The reconstruction of the primary vertex position can be switched off by //
75// //
76// rec.SetRunVertexFinder(kFALSE); //
77// //
b8cd5251 78// The tracking and the creation of ESD tracks can be switched on for //
79// selected detectors by //
596a855f 80// //
b8cd5251 81// rec.SetRunTracking("..."); //
596a855f 82// //
c84a5e9e 83// Uniform/nonuniform field tracking switches (default: uniform field) //
84// //
1d99986f 85// rec.SetUniformFieldTracking(); ( rec.SetUniformFieldTracking(kFALSE); ) //
c84a5e9e 86// //
596a855f 87// The filling of additional ESD information can be steered by //
88// //
89// rec.SetFillESD("..."); //
90// //
b8cd5251 91// Again, for both methods the string specifies the list of detectors. //
92// The default is "ALL". //
93// //
94// The call of the shortcut method //
95// //
96// rec.SetRunReconstruction("..."); //
97// //
98// is equivalent to calling SetRunLocalReconstruction, SetRunTracking and //
99// SetFillESD with the same detector selecting string as argument. //
596a855f 100// //
c71de921 101// The reconstruction requires digits or raw data as input. For the creation //
102// of digits and raw data have a look at the class AliSimulation. //
596a855f 103// //
cd0b062e 104// The input data of a detector can be replaced by the corresponding HLT //
105// data by calling (usual detector string) //
106// SetUseHLTData("..."); //
107// //
24f7a148 108// //
596a855f 109///////////////////////////////////////////////////////////////////////////////
110
024a7e64 111#include <TArrayF.h>
112#include <TFile.h>
444753c6 113#include <TList.h>
024a7e64 114#include <TSystem.h>
115#include <TROOT.h>
116#include <TPluginManager.h>
3103d196 117#include <TGeoManager.h>
2bdb9d38 118#include <TLorentzVector.h>
3dd9f9e3 119#include <TArrayS.h>
120#include <TArrayD.h>
3c3709c4 121#include <TObjArray.h>
325aa76f 122#include <TMap.h>
4b71572b 123#include <TChain.h>
124#include <TProof.h>
db4aeca1 125#include <TProofOutputFile.h>
002c9d1b 126#include <TParameter.h>
596a855f 127
128#include "AliReconstruction.h"
87932dab 129#include "AliCodeTimer.h"
b8cd5251 130#include "AliReconstructor.h"
815c2b38 131#include "AliLog.h"
596a855f 132#include "AliRunLoader.h"
133#include "AliRun.h"
b649205a 134#include "AliRawReaderFile.h"
135#include "AliRawReaderDate.h"
136#include "AliRawReaderRoot.h"
001397cd 137#include "AliRawEventHeaderBase.h"
4b71572b 138#include "AliRawEvent.h"
af885e0f 139#include "AliESDEvent.h"
faffd83e 140#include "AliESDMuonTrack.h"
1d99986f 141#include "AliESDfriend.h"
2257f27e 142#include "AliESDVertex.h"
faffd83e 143#include "AliESDcascade.h"
144#include "AliESDkink.h"
145#include "AliESDtrack.h"
146#include "AliESDCaloCluster.h"
e649177a 147#include "AliESDCaloCells.h"
32e449be 148#include "AliMultiplicity.h"
c84a5e9e 149#include "AliTracker.h"
2257f27e 150#include "AliVertexer.h"
c5e3e5d1 151#include "AliVertexerTracks.h"
5e4ff34d 152#include "AliV0vertexer.h"
153#include "AliCascadeVertexer.h"
596a855f 154#include "AliHeader.h"
155#include "AliGenEventHeader.h"
b26c3770 156#include "AliPID.h"
596a855f 157#include "AliESDpid.h"
ff8bb5ae 158#include "AliESDtrack.h"
3dd9f9e3 159#include "AliESDPmdTrack.h"
f3a97c86 160
08e1a23e 161#include "AliESDTagCreator.h"
f3a97c86 162
25be1e5c 163#include "AliGeomManager.h"
98937d93 164#include "AliTrackPointArray.h"
b0314964 165#include "AliCDBManager.h"
795e4a22 166#include "AliCDBStorage.h"
6bae477a 167#include "AliCDBEntry.h"
168#include "AliAlignObj.h"
f3a97c86 169
b647652d 170#include "AliCentralTrigger.h"
b024fd7f 171#include "AliTriggerConfiguration.h"
172#include "AliTriggerClass.h"
a0c2cf2d 173#include "AliTriggerCluster.h"
b647652d 174#include "AliCTPRawStream.h"
175
04236e67 176#include "AliQADataMakerRec.h"
aa3c69a9 177#include "AliGlobalQADataMaker.h"
c65c502a 178#include "AliQA.h"
179#include "AliQADataMakerSteer.h"
f29f1726 180
7167ae53 181#include "AliPlaneEff.h"
182
0f88822a 183#include "AliSysInfo.h" // memory snapshots
cd0b062e 184#include "AliRawHLTManager.h"
0f88822a 185
325aa76f 186#include "AliMagWrapCheb.h"
6efecea1 187
7e88424f 188#include "AliDetectorRecoParam.h"
189#include "AliRunInfo.h"
190#include "AliEventInfo.h"
191
192#include "AliDAQ.h"
193
596a855f 194ClassImp(AliReconstruction)
195
596a855f 196//_____________________________________________________________________________
b384f8a4 197const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
c757bafd 198
199//_____________________________________________________________________________
4b71572b 200AliReconstruction::AliReconstruction(const char* gAliceFilename) :
201 TSelector(),
f8b507e0 202 fUniformField(kFALSE),
4b71572b 203 fForcedFieldMap(NULL),
2257f27e 204 fRunVertexFinder(kTRUE),
a84e2607 205 fRunVertexFinderTracks(kTRUE),
1f46a9ae 206 fRunHLTTracking(kFALSE),
e66fbafb 207 fRunMuonTracking(kFALSE),
d1683eef 208 fRunV0Finder(kTRUE),
209 fRunCascadeFinder(kTRUE),
1d99986f 210 fStopOnError(kFALSE),
211 fWriteAlignmentData(kFALSE),
212 fWriteESDfriend(kFALSE),
b647652d 213 fFillTriggerESD(kTRUE),
1d99986f 214
7f68891d 215 fCleanESD(kTRUE),
a023d8d8 216 fV0DCAmax(3.),
217 fV0CsPmin(0.),
7f68891d 218 fDmax(50.),
219 fZmax(50.),
220
1d99986f 221 fRunLocalReconstruction("ALL"),
b8cd5251 222 fRunTracking("ALL"),
e583c30d 223 fFillESD("ALL"),
7d566c20 224 fLoadCDB(""),
48ce48d1 225 fUseTrackingErrorsForAlignment(""),
e583c30d 226 fGAliceFileName(gAliceFilename),
4b71572b 227 fRawInput(""),
35042093 228 fEquipIdMap(""),
b26c3770 229 fFirstEvent(0),
230 fLastEvent(-1),
973388c2 231 fNumberOfEventsPerFile(1),
b8cd5251 232 fOptions(),
6bae477a 233 fLoadAlignFromCDB(kTRUE),
234 fLoadAlignData("ALL"),
46698ae4 235 fESDPar(""),
cd0b062e 236 fUseHLTData(),
7e88424f 237 fRunInfo(NULL),
238 fEventInfo(),
e583c30d 239
240 fRunLoader(NULL),
b649205a 241 fRawReader(NULL),
cd0b062e 242 fParentRawReader(NULL),
b8cd5251 243
7e88424f 244 fRecoParam(),
245
98937d93 246 fVertexer(NULL),
9178838a 247 fDiamondProfile(NULL),
43c9dae1 248 fDiamondProfileTPC(NULL),
87317a47 249 fMeanVertexConstraint(kTRUE),
98937d93 250
6b6e4472 251 fGRPData(NULL),
444753c6 252
6bae477a 253 fAlignObjArray(NULL),
795e4a22 254 fCDBUri(),
759c1df1 255 fSpecCDBUri(),
795e4a22 256 fInitCDBCalled(kFALSE),
257 fSetRunNumberFromDataCalled(kFALSE),
ce43afbe 258 fQADetectors("ALL"),
30bbd491 259 fQASteer(NULL),
ce43afbe 260 fQATasks("ALL"),
7e963665 261 fRunQA(kTRUE),
6b150027 262 fRunGlobalQA(kTRUE),
e4a998ed 263 fSameQACycle(kFALSE),
7167ae53 264
21a3aa09 265 fRunPlaneEff(kFALSE),
266
267 fesd(NULL),
268 fhltesd(NULL),
269 fesdf(NULL),
270 ffile(NULL),
271 ftree(NULL),
272 fhlttree(NULL),
21a3aa09 273 ftVertexer(NULL),
14dd053c 274 fIsNewRunLoader(kFALSE),
4b71572b 275 fRunAliEVE(kFALSE),
276 fChain(NULL)
596a855f 277{
278// create reconstruction object with default parameters
002c9d1b 279 gGeoManager = NULL;
b8cd5251 280
281 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
282 fReconstructor[iDet] = NULL;
283 fLoader[iDet] = NULL;
284 fTracker[iDet] = NULL;
4b71572b 285 fQACycles[iDet] = 999999;
b8cd5251 286 }
e47c4c2e 287 AliPID pid;
596a855f 288}
289
290//_____________________________________________________________________________
291AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
4b71572b 292 TSelector(),
c84a5e9e 293 fUniformField(rec.fUniformField),
4b71572b 294 fForcedFieldMap(NULL),
2257f27e 295 fRunVertexFinder(rec.fRunVertexFinder),
a84e2607 296 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
1f46a9ae 297 fRunHLTTracking(rec.fRunHLTTracking),
e66fbafb 298 fRunMuonTracking(rec.fRunMuonTracking),
d1683eef 299 fRunV0Finder(rec.fRunV0Finder),
300 fRunCascadeFinder(rec.fRunCascadeFinder),
1d99986f 301 fStopOnError(rec.fStopOnError),
302 fWriteAlignmentData(rec.fWriteAlignmentData),
303 fWriteESDfriend(rec.fWriteESDfriend),
b647652d 304 fFillTriggerESD(rec.fFillTriggerESD),
1d99986f 305
7f68891d 306 fCleanESD(rec.fCleanESD),
a023d8d8 307 fV0DCAmax(rec.fV0DCAmax),
5e5c1aa9 308 fV0CsPmin(rec.fV0CsPmin),
7f68891d 309 fDmax(rec.fDmax),
310 fZmax(rec.fZmax),
311
1d99986f 312 fRunLocalReconstruction(rec.fRunLocalReconstruction),
e583c30d 313 fRunTracking(rec.fRunTracking),
314 fFillESD(rec.fFillESD),
7d566c20 315 fLoadCDB(rec.fLoadCDB),
48ce48d1 316 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
e583c30d 317 fGAliceFileName(rec.fGAliceFileName),
4b71572b 318 fRawInput(rec.fRawInput),
35042093 319 fEquipIdMap(rec.fEquipIdMap),
b26c3770 320 fFirstEvent(rec.fFirstEvent),
321 fLastEvent(rec.fLastEvent),
973388c2 322 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
b8cd5251 323 fOptions(),
6bae477a 324 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
325 fLoadAlignData(rec.fLoadAlignData),
46698ae4 326 fESDPar(rec.fESDPar),
2972d4eb 327 fUseHLTData(rec.fUseHLTData),
7e88424f 328 fRunInfo(NULL),
329 fEventInfo(),
e583c30d 330
331 fRunLoader(NULL),
b649205a 332 fRawReader(NULL),
2972d4eb 333 fParentRawReader(NULL),
b8cd5251 334
4b71572b 335 fRecoParam(rec.fRecoParam),
7e88424f 336
98937d93 337 fVertexer(NULL),
4b71572b 338 fDiamondProfile(rec.fDiamondProfile),
339 fDiamondProfileTPC(rec.fDiamondProfileTPC),
87317a47 340 fMeanVertexConstraint(rec.fMeanVertexConstraint),
98937d93 341
6b6e4472 342 fGRPData(NULL),
444753c6 343
6bae477a 344 fAlignObjArray(rec.fAlignObjArray),
ec92bee0 345 fCDBUri(rec.fCDBUri),
7e963665 346 fSpecCDBUri(),
795e4a22 347 fInitCDBCalled(rec.fInitCDBCalled),
348 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
ce43afbe 349 fQADetectors(rec.fQADetectors),
4b71572b 350 fQASteer(NULL),
ce43afbe 351 fQATasks(rec.fQATasks),
aa3c69a9 352 fRunQA(rec.fRunQA),
353 fRunGlobalQA(rec.fRunGlobalQA),
e4a998ed 354 fSameQACycle(rec.fSameQACycle),
21a3aa09 355 fRunPlaneEff(rec.fRunPlaneEff),
356
357 fesd(NULL),
358 fhltesd(NULL),
359 fesdf(NULL),
360 ffile(NULL),
361 ftree(NULL),
362 fhlttree(NULL),
21a3aa09 363 ftVertexer(NULL),
14dd053c 364 fIsNewRunLoader(rec.fIsNewRunLoader),
4b71572b 365 fRunAliEVE(kFALSE),
366 fChain(NULL)
596a855f 367{
368// copy constructor
369
ec92bee0 370 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
efd2085e 371 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
372 }
b8cd5251 373 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
374 fReconstructor[iDet] = NULL;
375 fLoader[iDet] = NULL;
376 fTracker[iDet] = NULL;
b1af1125 377 }
378
379 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++)
380 fQACycles[iDet] = rec.fQACycles[iDet];
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 }
596a855f 385}
386
387//_____________________________________________________________________________
388AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
389{
390// assignment operator
4b71572b 391// Used in PROOF mode
392// Be very careful while modifing it!
393// Simple rules to follow:
394// for persistent data members - use their assignment operators
395// for non-persistent ones - do nothing or take the default values from constructor
396// TSelector members should not be touched
397 if(&rec == this) return *this;
398
399 fUniformField = rec.fUniformField;
400 fForcedFieldMap = NULL;
401 fRunVertexFinder = rec.fRunVertexFinder;
402 fRunVertexFinderTracks = rec.fRunVertexFinderTracks;
403 fRunHLTTracking = rec.fRunHLTTracking;
404 fRunMuonTracking = rec.fRunMuonTracking;
405 fRunV0Finder = rec.fRunV0Finder;
406 fRunCascadeFinder = rec.fRunCascadeFinder;
407 fStopOnError = rec.fStopOnError;
408 fWriteAlignmentData = rec.fWriteAlignmentData;
409 fWriteESDfriend = rec.fWriteESDfriend;
410 fFillTriggerESD = rec.fFillTriggerESD;
411
412 fCleanESD = rec.fCleanESD;
413 fV0DCAmax = rec.fV0DCAmax;
414 fV0CsPmin = rec.fV0CsPmin;
415 fDmax = rec.fDmax;
416 fZmax = rec.fZmax;
417
418 fRunLocalReconstruction = rec.fRunLocalReconstruction;
419 fRunTracking = rec.fRunTracking;
420 fFillESD = rec.fFillESD;
7d566c20 421 fLoadCDB = rec.fLoadCDB;
4b71572b 422 fUseTrackingErrorsForAlignment = rec.fUseTrackingErrorsForAlignment;
423 fGAliceFileName = rec.fGAliceFileName;
424 fRawInput = rec.fRawInput;
425 fEquipIdMap = rec.fEquipIdMap;
426 fFirstEvent = rec.fFirstEvent;
427 fLastEvent = rec.fLastEvent;
428 fNumberOfEventsPerFile = rec.fNumberOfEventsPerFile;
429
430 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
431 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
432 }
433
434 fLoadAlignFromCDB = rec.fLoadAlignFromCDB;
435 fLoadAlignData = rec.fLoadAlignData;
436 fESDPar = rec.fESDPar;
437 fUseHLTData = rec.fUseHLTData;
438
439 delete fRunInfo; fRunInfo = NULL;
440 if (rec.fRunInfo) fRunInfo = new AliRunInfo(*rec.fRunInfo);
441
442 fEventInfo = rec.fEventInfo;
443
444 fRunLoader = NULL;
445 fRawReader = NULL;
446 fParentRawReader = NULL;
447
448 fRecoParam = rec.fRecoParam;
449
450 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
451 delete fReconstructor[iDet]; fReconstructor[iDet] = NULL;
452 delete fLoader[iDet]; fLoader[iDet] = NULL;
453 delete fTracker[iDet]; fTracker[iDet] = NULL;
4b71572b 454 }
b1af1125 455
456 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++)
457 fQACycles[iDet] = rec.fQACycles[iDet];
458
4b71572b 459 fVertexer = NULL;
460 delete fDiamondProfile; fDiamondProfile = NULL;
461 if (rec.fDiamondProfile) fDiamondProfile = new AliESDVertex(*rec.fDiamondProfile);
462 delete fDiamondProfileTPC; fDiamondProfileTPC = NULL;
463 if (rec.fDiamondProfileTPC) fDiamondProfileTPC = new AliESDVertex(*rec.fDiamondProfileTPC);
464 fMeanVertexConstraint = rec.fMeanVertexConstraint;
465
466 delete fGRPData; fGRPData = NULL;
467 if (rec.fGRPData) fGRPData = (TMap*)((rec.fGRPData)->Clone());
468
469 delete fAlignObjArray; fAlignObjArray = NULL;
470
471 fCDBUri = "";
472 fSpecCDBUri.Delete();
473 fInitCDBCalled = rec.fInitCDBCalled;
474 fSetRunNumberFromDataCalled = rec.fSetRunNumberFromDataCalled;
475 fQADetectors = rec.fQADetectors;
476 fQASteer = NULL;
477 fQATasks = rec.fQATasks;
478 fRunQA = rec.fRunQA;
479 fRunGlobalQA = rec.fRunGlobalQA;
4b71572b 480 fSameQACycle = rec.fSameQACycle;
481 fRunPlaneEff = rec.fRunPlaneEff;
482
483 fesd = NULL;
484 fhltesd = NULL;
485 fesdf = NULL;
486 ffile = NULL;
487 ftree = NULL;
488 fhlttree = NULL;
489 ftVertexer = NULL;
490 fIsNewRunLoader = rec.fIsNewRunLoader;
491 fRunAliEVE = kFALSE;
492 fChain = NULL;
596a855f 493
596a855f 494 return *this;
495}
496
497//_____________________________________________________________________________
498AliReconstruction::~AliReconstruction()
499{
500// clean up
501
e583c30d 502 CleanUp();
4b71572b 503 delete fForcedFieldMap;
efd2085e 504 fOptions.Delete();
4b71572b 505 if (fAlignObjArray) {
506 fAlignObjArray->Delete();
507 delete fAlignObjArray;
508 }
ec92bee0 509 fSpecCDBUri.Delete();
4b71572b 510 delete fQASteer;
87932dab 511 AliCodeTimer::Instance()->Print();
596a855f 512}
513
024cf675 514//_____________________________________________________________________________
795e4a22 515void AliReconstruction::InitCDB()
024cf675 516{
517// activate a default CDB storage
518// First check if we have any CDB storage set, because it is used
519// to retrieve the calibration and alignment constants
002c9d1b 520 AliCodeTimerAuto("");
024cf675 521
795e4a22 522 if (fInitCDBCalled) return;
523 fInitCDBCalled = kTRUE;
524
024cf675 525 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 526 if (man->IsDefaultStorageSet())
024cf675 527 {
528 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 529 AliWarning("Default CDB storage has been already set !");
530 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
024cf675 531 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 532 fCDBUri = man->GetDefaultStorage()->GetURI();
ec92bee0 533 }
534 else {
795e4a22 535 if (fCDBUri.Length() > 0)
536 {
537 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
538 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
539 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
540 } else {
541 fCDBUri="local://$ALICE_ROOT";
542 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
543 AliWarning("Default CDB storage not yet set !!!!");
544 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
545 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
546
547 }
ec92bee0 548 man->SetDefaultStorage(fCDBUri);
549 }
550
551 // Now activate the detector specific CDB storage locations
c3a7b59a 552 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
553 TObject* obj = fSpecCDBUri[i];
554 if (!obj) continue;
b8ec52f6 555 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
556 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
557 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 558 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 559 }
002c9d1b 560 AliSysInfo::AddStamp("InitCDB");
024cf675 561}
562
563//_____________________________________________________________________________
564void AliReconstruction::SetDefaultStorage(const char* uri) {
ec92bee0 565// Store the desired default CDB storage location
566// Activate it later within the Run() method
024cf675 567
ec92bee0 568 fCDBUri = uri;
024cf675 569
570}
571
572//_____________________________________________________________________________
c3a7b59a 573void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 574// Store a detector-specific CDB storage location
575// Activate it later within the Run() method
024cf675 576
c3a7b59a 577 AliCDBPath aPath(calibType);
578 if(!aPath.IsValid()){
579 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
580 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
581 if(!strcmp(calibType, fgkDetectorName[iDet])) {
582 aPath.SetPath(Form("%s/*", calibType));
583 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
584 break;
585 }
586 }
587 if(!aPath.IsValid()){
588 AliError(Form("Not a valid path or detector: %s", calibType));
589 return;
590 }
591 }
592
53dd3c3d 593// // check that calibType refers to a "valid" detector name
594// Bool_t isDetector = kFALSE;
595// for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
596// TString detName = fgkDetectorName[iDet];
597// if(aPath.GetLevel0() == detName) {
598// isDetector = kTRUE;
599// break;
600// }
601// }
602//
603// if(!isDetector) {
604// AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
605// return;
606// }
c3a7b59a 607
608 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
ec92bee0 609 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 610 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
024cf675 611
612}
613
6bae477a 614//_____________________________________________________________________________
795e4a22 615Bool_t AliReconstruction::SetRunNumberFromData()
6bae477a 616{
617 // The method is called in Run() in order
618 // to set a correct run number.
619 // In case of raw data reconstruction the
620 // run number is taken from the raw data header
621
795e4a22 622 if (fSetRunNumberFromDataCalled) return kTRUE;
623 fSetRunNumberFromDataCalled = kTRUE;
624
625 AliCDBManager* man = AliCDBManager::Instance();
4b71572b 626
627 if(fRawReader) {
628 if(fRawReader->NextEvent()) {
629 if(man->GetRun() > 0) {
21a3aa09 630 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
4b71572b 631 }
632 man->SetRun(fRawReader->GetRunNumber());
633 fRawReader->RewindEvents();
634 }
635 else {
636 if(man->GetRun() > 0) {
637 AliWarning("No raw-data events are found ! Using settings in AliCDBManager !");
638 }
639 else {
640 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
641 return kFALSE;
642 }
643 }
644 }
645 else {
646 AliRunLoader *rl = AliRunLoader::Open(fGAliceFileName.Data());
647 if (!rl) {
648 AliError(Form("No run loader found in file %s", fGAliceFileName.Data()));
6bae477a 649 return kFALSE;
650 }
ec92bee0 651 else {
4b71572b 652 rl->LoadHeader();
653 // read run number from gAlice
654 if(rl->GetHeader()) {
655 man->SetRun(rl->GetHeader()->GetRun());
656 rl->UnloadHeader();
657 delete rl;
ec92bee0 658 }
659 else {
4b71572b 660 AliError("Neither run-loader header nor RawReader objects are found !");
661 delete rl;
ec92bee0 662 return kFALSE;
663 }
4b71572b 664 }
6bae477a 665 }
795e4a22 666
667 man->Print();
668
6bae477a 669 return kTRUE;
670}
671
672//_____________________________________________________________________________
795e4a22 673void AliReconstruction::SetCDBLock() {
674 // Set CDB lock: from now on it is forbidden to reset the run number
675 // or the default storage or to activate any further storage!
676
677 AliCDBManager::Instance()->SetLock(1);
678}
679
680//_____________________________________________________________________________
6bae477a 681Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
682{
683 // Read the alignment objects from CDB.
684 // Each detector is supposed to have the
685 // alignment objects in DET/Align/Data CDB path.
686 // All the detector objects are then collected,
687 // sorted by geometry level (starting from ALIC) and
688 // then applied to the TGeo geometry.
689 // Finally an overlaps check is performed.
690
691 // Load alignment data from CDB and fill fAlignObjArray
692 if(fLoadAlignFromCDB){
6bae477a 693
25be1e5c 694 TString detStr = detectors;
695 TString loadAlObjsListOfDets = "";
696
697 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
698 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
699 loadAlObjsListOfDets += fgkDetectorName[iDet];
700 loadAlObjsListOfDets += " ";
701 } // end loop over detectors
53dd3c3d 702 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
98e303d9 703 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
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
efd2085e 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
752//_____________________________________________________________________________
efd2085e 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
596a855f 762//_____________________________________________________________________________
7e88424f 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
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
994//_____________________________________________________________________________
4b71572b 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
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)) {
930e6e3e 1046 Abort("ProcessEvent",TSelector::kAbortFile);
1047 return kFALSE;
4b71572b 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
930e6e3e 1290 //Initialize the QA and start of cycle
f6806ad3 1291 if (fRunQA) {
930e6e3e 1292 fQASteer = new AliQADataMakerSteer("rec") ;
1293 fQASteer->SetActiveDetectors(fQADetectors) ;
b1af1125 1294 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
930e6e3e 1295 fQASteer->SetCycleLength(AliQA::DETECTORINDEX_t(det), fQACycles[det]) ;
1296 if (!fRawReader && fQATasks.Contains(AliQA::kRAWS))
1297 fQATasks.ReplaceAll(Form("%d",AliQA::kRAWS), "") ;
1298 fQASteer->SetTasks(fQATasks) ;
1299 fQASteer->InitQADataMaker(AliCDBManager::Instance()->GetRun(), fRecoParam) ;
4b71572b 1300 }
930e6e3e 1301
4b71572b 1302 if (fRunGlobalQA) {
0de86d1a 1303 Bool_t sameCycle = kFALSE ;
1304 if (!fQASteer) fQASteer = new AliQADataMakerSteer("rec") ;
4b71572b 1305 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1306 AliInfo(Form("Initializing the global QA data maker"));
1307 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
930e6e3e 1308 qadm->StartOfCycle(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
1309 TObjArray *arr=qadm->Init(AliQA::kRECPOINTS);
4b71572b 1310 AliTracker::SetResidualsArray(arr);
930e6e3e 1311 sameCycle = kTRUE ;
4b71572b 1312 }
1313 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
930e6e3e 1314 qadm->StartOfCycle(AliQA::kESDS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
1315 qadm->Init(AliQA::kESDS);
4b71572b 1316 }
1317 }
aa3c69a9 1318
7167ae53 1319 //Initialize the Plane Efficiency framework
1320 if (fRunPlaneEff && !InitPlaneEff()) {
4b71572b 1321 Abort("InitPlaneEff", TSelector::kAbortProcess);
1322 return;
7167ae53 1323 }
aa3c69a9 1324
14dd053c 1325 if (strcmp(gProgName,"alieve") == 0)
1326 fRunAliEVE = InitAliEVE();
1327
4b71572b 1328 return;
21a3aa09 1329}
1330
1331//_____________________________________________________________________________
4b71572b 1332Bool_t AliReconstruction::Process(Long64_t entry)
1333{
1334 // run the reconstruction over a single entry
1335 // from the chain with raw data
1336 AliCodeTimerAuto("");
1337
1338 TTree *currTree = fChain->GetTree();
1339 AliRawEvent *event = new AliRawEvent;
1340 currTree->SetBranchAddress("rawevent",&event);
1341 currTree->GetEntry(entry);
1342 fRawReader = new AliRawReaderRoot(event);
1343 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
1344 delete fRawReader;
1345 fRawReader = NULL;
1346 delete event;
1347
1348 return fStatus;
1349}
1350
1351//_____________________________________________________________________________
1352void AliReconstruction::Init(TTree *tree)
1353{
1354 if (tree == 0) {
1355 AliError("The input tree is not found!");
1356 return;
1357 }
1358 fChain = tree;
1359}
1360
1361//_____________________________________________________________________________
1362Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
21a3aa09 1363{
1364 // run the reconstruction over a single event
1365 // The event loop is steered in Run method
1366
1367 AliCodeTimerAuto("");
1368
1369 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
1370 fRunLoader->SetEventNumber(iEvent);
1371 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1372 iEvent, iEvent);
21a3aa09 1373 fRunLoader->TreeE()->Fill();
4b71572b 1374 if (fRawReader && fRawReader->UseAutoSaveESD())
1375 fRunLoader->TreeE()->AutoSave("SaveSelf");
21a3aa09 1376 }
1377
1378 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
21a3aa09 1379 return kTRUE;
1380 }
1381
1382 AliInfo(Form("processing event %d", iEvent));
aa3c69a9 1383
7e88424f 1384 // Fill Event-info object
1385 GetEventInfo();
1386 fRecoParam.SetEventSpecie(fRunInfo,fEventInfo);
1387
4b71572b 1388 fRunLoader->GetEvent(iEvent);
24f7a148 1389
ca13fb87 1390 // QA on single raw
930e6e3e 1391 if (fRunQA)
e84c88f5 1392 fQASteer->RunOneEvent(fRawReader) ;
ca13fb87 1393
d506c543 1394 // local single event reconstruction
b26c3770 1395 if (!fRunLocalReconstruction.IsNull()) {
d506c543 1396 TString detectors=fRunLocalReconstruction;
a441bf51 1397 // run HLT event reconstruction first
d506c543 1398 // ;-( IsSelected changes the string
1399 if (IsSelected("HLT", detectors) &&
1400 !RunLocalEventReconstruction("HLT")) {
4b71572b 1401 if (fStopOnError) {CleanUp(); return kFALSE;}
a441bf51 1402 }
1403 detectors=fRunLocalReconstruction;
1404 detectors.ReplaceAll("HLT", "");
1405 if (!RunLocalEventReconstruction(detectors)) {
4b71572b 1406 if (fStopOnError) {CleanUp(); return kFALSE;}
b26c3770 1407 }
1408 }
1409
21a3aa09 1410 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1411 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1412 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1413 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
46698ae4 1414
d6ee376f 1415 // Set magnetic field from the tracker
21a3aa09 1416 fesd->SetMagneticField(AliTracker::GetBz());
1417 fhltesd->SetMagneticField(AliTracker::GetBz());
596a855f 1418
46698ae4 1419
1420
2e3550da 1421 // Fill raw-data error log into the ESD
21a3aa09 1422 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 1423
2257f27e 1424 // vertex finder
1425 if (fRunVertexFinder) {
4b71572b 1426 if (!RunVertexFinder(fesd)) {
1427 if (fStopOnError) {CleanUp(); return kFALSE;}
2257f27e 1428 }
1429 }
1430
e66fbafb 1431 // Muon tracking
b8cd5251 1432 if (!fRunTracking.IsNull()) {
e66fbafb 1433 if (fRunMuonTracking) {
21a3aa09 1434 if (!RunMuonTracking(fesd)) {
4b71572b 1435 if (fStopOnError) {CleanUp(); return kFALSE;}
24f7a148 1436 }
596a855f 1437 }
1438 }
1439
e66fbafb 1440 // barrel tracking
1441 if (!fRunTracking.IsNull()) {
4b71572b 1442 if (!RunTracking(fesd)) {
1443 if (fStopOnError) {CleanUp(); return kFALSE;}
e66fbafb 1444 }
1445 }
21c573b7 1446
596a855f 1447 // fill ESD
1448 if (!fFillESD.IsNull()) {
d506c543 1449 TString detectors=fFillESD;
f6806ad3 1450 // run HLT first and on hltesd
d506c543 1451 // ;-( IsSelected changes the string
1452 if (IsSelected("HLT", detectors) &&
1453 !FillESD(fhltesd, "HLT")) {
4b71572b 1454 if (fStopOnError) {CleanUp(); return kFALSE;}
f6806ad3 1455 }
1456 detectors=fFillESD;
d5105682 1457 // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
1458 if (detectors.Contains("ALL")) {
1459 detectors="";
1460 for (Int_t idet=0; idet<fgkNDetectors; ++idet){
1461 detectors += fgkDetectorName[idet];
1462 detectors += " ";
1463 }
1464 }
f6806ad3 1465 detectors.ReplaceAll("HLT", "");
1466 if (!FillESD(fesd, detectors)) {
4b71572b 1467 if (fStopOnError) {CleanUp(); return kFALSE;}
596a855f 1468 }
1469 }
a5fa6165 1470
001397cd 1471 // fill Event header information from the RawEventHeader
21a3aa09 1472 if (fRawReader){FillRawEventHeaderESD(fesd);}
596a855f 1473
1474 // combined PID
21a3aa09 1475 AliESDpid::MakePID(fesd);
596a855f 1476
b647652d 1477 if (fFillTriggerESD) {
4b71572b 1478 if (!FillTriggerESD(fesd)) {
1479 if (fStopOnError) {CleanUp(); return kFALSE;}
b647652d 1480 }
1481 }
1482
21a3aa09 1483 ffile->cd();
a6ee503a 1484
3c3709c4 1485 //
67be5c77 1486 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 1487 //
21a3aa09 1488 const Int_t ntracks = fesd->GetNumberOfTracks();
1489 const Double_t kBz = fesd->GetMagneticField();
3c3709c4 1490 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1491
1492 TObjArray trkArray;
1493 UShort_t *selectedIdx=new UShort_t[ntracks];
1494
1495 for (Int_t itrack=0; itrack<ntracks; itrack++){
1496 const Double_t kMaxStep = 5; //max step over the material
1497 Bool_t ok;
1498
21a3aa09 1499 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 1500 if (!track) continue;
1501
1502 AliExternalTrackParam *tpcTrack =
1503 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 1504 ok = kFALSE;
1505 if (tpcTrack)
1506 ok = AliTracker::
1507 PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
43c9dae1 1508
3c3709c4 1509 if (ok) {
1510 Int_t n=trkArray.GetEntriesFast();
1511 selectedIdx[n]=track->GetID();
1512 trkArray.AddLast(tpcTrack);
1513 }
1514
3d65e645 1515 //Tracks refitted by ITS should already be at the SPD vertex
1516 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1517
1518 AliTracker::
1519 PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1520 track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kVeryBig);
3c3709c4 1521
3c3709c4 1522 }
1523
1524 //
1525 // Improve the reconstructed primary vertex position using the tracks
1526 //
59224b2b 1527 Bool_t runVertexFinderTracks = fRunVertexFinderTracks;
1528 if(fesd->GetPrimaryVertexSPD()) {
1529 TString vtitle = fesd->GetPrimaryVertexSPD()->GetTitle();
1530 if(vtitle.Contains("cosmics")) {
1531 runVertexFinderTracks=kFALSE;
1532 }
c060d7fe 1533 }
59224b2b 1534 if (runVertexFinderTracks) {
3c3709c4 1535 // TPC + ITS primary vertex
f09c879d 1536 ftVertexer->SetITSMode();
43c9dae1 1537 if(fDiamondProfile && fMeanVertexConstraint) {
21a3aa09 1538 ftVertexer->SetVtxStart(fDiamondProfile);
43c9dae1 1539 } else {
21a3aa09 1540 ftVertexer->SetConstraintOff();
43c9dae1 1541 }
21a3aa09 1542 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 1543 if (pvtx) {
1544 if (pvtx->GetStatus()) {
21a3aa09 1545 fesd->SetPrimaryVertex(pvtx);
3c3709c4 1546 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 1547 AliESDtrack *t = fesd->GetTrack(i);
3d65e645 1548 t->RelateToVertex(pvtx, kBz, kVeryBig);
3c3709c4 1549 }
1550 }
1551 }
1552
1553 // TPC-only primary vertex
f09c879d 1554 ftVertexer->SetTPCMode();
43c9dae1 1555 if(fDiamondProfileTPC && fMeanVertexConstraint) {
21a3aa09 1556 ftVertexer->SetVtxStart(fDiamondProfileTPC);
43c9dae1 1557 } else {
21a3aa09 1558 ftVertexer->SetConstraintOff();
43c9dae1 1559 }
21a3aa09 1560 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 1561 if (pvtx) {
1562 if (pvtx->GetStatus()) {
21a3aa09 1563 fesd->SetPrimaryVertexTPC(pvtx);
3d65e645 1564 for (Int_t i=0; i<ntracks; i++) {
1565 AliESDtrack *t = fesd->GetTrack(i);
1566 t->RelateToVertexTPC(pvtx, kBz, kVeryBig);
3c3709c4 1567 }
1568 }
1569 }
1570
1571 }
1572 delete[] selectedIdx;
1573
21a3aa09 1574 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
17c86e90 1575
c5e3e5d1 1576
d1683eef 1577 if (fRunV0Finder) {
1578 // V0 finding
1579 AliV0vertexer vtxer;
21a3aa09 1580 vtxer.Tracks2V0vertices(fesd);
5e4ff34d 1581
d1683eef 1582 if (fRunCascadeFinder) {
1583 // Cascade finding
1584 AliCascadeVertexer cvtxer;
21a3aa09 1585 cvtxer.V0sTracks2CascadeVertices(fesd);
d1683eef 1586 }
5e4ff34d 1587 }
1588
596a855f 1589 // write ESD
21a3aa09 1590 if (fCleanESD) CleanESD(fesd);
854c6476 1591
bea94759 1592 if (fRunQA)
1593 fQASteer->RunOneEvent(fesd) ;
1594
1595 if (fRunGlobalQA) {
0d106d88 1596 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1597 if (qadm && fQATasks.Contains(Form("%d", AliQA::kESDS)))
bea94759 1598 qadm->Exec(AliQA::kESDS, fesd);
b8bd1ab8 1599 }
854c6476 1600
1d99986f 1601 if (fWriteESDfriend) {
21a3aa09 1602 fesdf->~AliESDfriend();
1603 new (fesdf) AliESDfriend(); // Reset...
1604 fesd->GetESDfriend(fesdf);
1d99986f 1605 }
21a3aa09 1606 ftree->Fill();
500d54ab 1607
2d91a353 1608 // Auto-save the ESD tree in case of prompt reco @P2
be103ac8 1609 if (fRawReader && fRawReader->UseAutoSaveESD()) {
2d91a353 1610 ftree->AutoSave("SaveSelf");
be103ac8 1611 TFile *friendfile = (TFile *)(gROOT->GetListOfFiles()->FindObject("AliESDfriends.root"));
1612 if (friendfile) friendfile->Save();
1613 }
2d91a353 1614
500d54ab 1615 // write HLT ESD
21a3aa09 1616 fhlttree->Fill();
1d99986f 1617
14dd053c 1618 // call AliEVE
1619 if (fRunAliEVE) RunAliEVE();
1620
21a3aa09 1621 fesd->Reset();
1622 fhltesd->Reset();
5728d3d5 1623 if (fWriteESDfriend) {
21a3aa09 1624 fesdf->~AliESDfriend();
1625 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 1626 }
a5fa6165 1627
21a3aa09 1628 ProcInfo_t ProcInfo;
95cee32f 1629 gSystem->GetProcInfo(&ProcInfo);
1630 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
a5fa6165 1631
ca13fb87 1632 fEventInfo.Reset();
1633 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1634 if (fReconstructor[iDet])
e84c88f5 1635 fReconstructor[iDet]->SetRecoParam(NULL);
ca13fb87 1636 }
1637
930e6e3e 1638 fQASteer->Increment() ;
ca13fb87 1639 return kTRUE;
21a3aa09 1640}
1641
1642//_____________________________________________________________________________
4b71572b 1643void AliReconstruction::SlaveTerminate()
21a3aa09 1644{
4b71572b 1645 // Finalize the run on the slave side
21a3aa09 1646 // Called after the exit
1647 // from the event loop
1648 AliCodeTimerAuto("");
1649
1650 if (fIsNewRunLoader) { // galice.root didn't exist
1651 fRunLoader->WriteHeader("OVERWRITE");
1652 fRunLoader->CdGAFile();
1653 fRunLoader->Write(0, TObject::kOverwrite);
1654 }
1655
1656 ftree->GetUserInfo()->Add(fesd);
1657 fhlttree->GetUserInfo()->Add(fhltesd);
f747912b 1658
1659 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1660 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1661
1662 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1663 cdbMapCopy->SetOwner(1);
1664 cdbMapCopy->SetName("cdbMap");
1665 TIter iter(cdbMap->GetTable());
1666
1667 TPair* pair = 0;
1668 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1669 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1670 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1671 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1672 }
1673
1674 TList *cdbListCopy = new TList();
1675 cdbListCopy->SetOwner(1);
1676 cdbListCopy->SetName("cdbList");
1677
1678 TIter iter2(cdbList);
1679
b940cb9b 1680 AliCDBId* id=0;
e84c88f5 1681 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 1682 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 1683 }
1684
21a3aa09 1685 ftree->GetUserInfo()->Add(cdbMapCopy);
1686 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 1687
46698ae4 1688
1689 if(fESDPar.Contains("ESD.par")){
1690 AliInfo("Attaching ESD.par to Tree");
1691 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
21a3aa09 1692 ftree->GetUserInfo()->Add(fn);
596a855f 1693 }
1694
46698ae4 1695
21a3aa09 1696 ffile->cd();
aa3c69a9 1697
a9c0e6db 1698 if (fWriteESDfriend)
21a3aa09 1699 ftree->SetBranchStatus("ESDfriend*",0);
562dd0b4 1700 // we want to have only one tree version number
21a3aa09 1701 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1702 fhlttree->Write();
f3a97c86 1703
a7a1e1c7 1704// Finish with Plane Efficiency evaluation: before of CleanUp !!!
1705 if (fRunPlaneEff && !FinishPlaneEff()) {
1706 AliWarning("Finish PlaneEff evaluation failed");
1707 }
1708
930e6e3e 1709 // End of cycle for the in-loop
1710 if (fRunQA) {
930e6e3e 1711 fQASteer->EndOfCycle() ;
1712 }
1713 if (fRunGlobalQA) {
4b71572b 1714 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1715 if (qadm) {
1716 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
930e6e3e 1717 qadm->EndOfCycle(AliQA::kRECPOINTS);
4b71572b 1718 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
930e6e3e 1719 qadm->EndOfCycle(AliQA::kESDS);
4b71572b 1720 qadm->Finish();
1721 }
a7807689 1722 }
4b71572b 1723 gROOT->cd();
1724 CleanUp();
1725}
1726
1727//_____________________________________________________________________________
1728void AliReconstruction::Terminate()
1729{
f3a97c86 1730 // Create tags for the events in the ESD tree (the ESD tree is always present)
1731 // In case of empty events the tags will contain dummy values
4b71572b 1732 AliCodeTimerAuto("");
1733
08e1a23e 1734 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
6b6e4472 1735 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData);
e84c88f5 1736
795e4a22 1737 // Cleanup of CDB manager: cache and active storages!
1738 AliCDBManager::Instance()->ClearCache();
596a855f 1739}
1740
1741//_____________________________________________________________________________
b26c3770 1742Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1743{
1744// run the local reconstruction
aa3c69a9 1745
0f88822a 1746 static Int_t eventNr=0;
87932dab 1747 AliCodeTimerAuto("")
b26c3770 1748
1749 TString detStr = detectors;
1750 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1751 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1752 AliReconstructor* reconstructor = GetReconstructor(iDet);
1753 if (!reconstructor) continue;
1754 AliLoader* loader = fLoader[iDet];
f6806ad3 1755 // Matthias April 2008: temporary fix to run HLT reconstruction
1756 // although the HLT loader is missing
1757 if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
1758 if (fRawReader) {
1759 reconstructor->Reconstruct(fRawReader, NULL);
1760 } else {
1761 TTree* dummy=NULL;
1762 reconstructor->Reconstruct(dummy, NULL);
1763 }
1764 continue;
1765 }
d76c31f4 1766 if (!loader) {
1767 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1768 continue;
1769 }
b26c3770 1770 // conversion of digits
1771 if (fRawReader && reconstructor->HasDigitConversion()) {
1772 AliInfo(Form("converting raw data digits into root objects for %s",
1773 fgkDetectorName[iDet]));
30bbd491 1774// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1775// fgkDetectorName[iDet]));
b26c3770 1776 loader->LoadDigits("update");
1777 loader->CleanDigits();
1778 loader->MakeDigitsContainer();
1779 TTree* digitsTree = loader->TreeD();
1780 reconstructor->ConvertDigits(fRawReader, digitsTree);
1781 loader->WriteDigits("OVERWRITE");
1782 loader->UnloadDigits();
b26c3770 1783 }
b26c3770 1784 // local reconstruction
b26c3770 1785 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
30bbd491 1786 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
b26c3770 1787 loader->LoadRecPoints("update");
1788 loader->CleanRecPoints();
1789 loader->MakeRecPointsContainer();
1790 TTree* clustersTree = loader->TreeR();
1791 if (fRawReader && !reconstructor->HasDigitConversion()) {
1792 reconstructor->Reconstruct(fRawReader, clustersTree);
1793 } else {
1794 loader->LoadDigits("read");
1795 TTree* digitsTree = loader->TreeD();
1796 if (!digitsTree) {
1797 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1798 if (fStopOnError) return kFALSE;
1799 } else {
1800 reconstructor->Reconstruct(digitsTree, clustersTree);
1801 }
1802 loader->UnloadDigits();
1803 }
d76c31f4 1804
30bbd491 1805 TString detQAStr(fQADetectors) ;
930e6e3e 1806 if (fRunQA)
e84c88f5 1807 fQASteer->RunOneEventInOneDetector(iDet, clustersTree) ;
1808
1809 loader->WriteRecPoints("OVERWRITE");
1810 loader->UnloadRecPoints();
1811 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
1812 }
1813 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
b26c3770 1814 AliError(Form("the following detectors were not found: %s",
1815 detStr.Data()));
1816 if (fStopOnError) return kFALSE;
1817 }
0f88822a 1818 eventNr++;
b26c3770 1819 return kTRUE;
1820}
1821
1822//_____________________________________________________________________________
af885e0f 1823Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 1824{
1825// run the barrel tracking
1826
87932dab 1827 AliCodeTimerAuto("")
030b532d 1828
2257f27e 1829 AliESDVertex* vertex = NULL;
1830 Double_t vtxPos[3] = {0, 0, 0};
1831 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1832 TArrayF mcVertex(3);
a6b0b91b 1833 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1834 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1835 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1836 }
2257f27e 1837
b8cd5251 1838 if (fVertexer) {
815c2b38 1839 AliInfo("running the ITS vertex finder");
308c2f7c 1840 if (fLoader[0]) {
1841 fLoader[0]->LoadRecPoints();
1842 TTree* cltree = fLoader[0]->TreeR();
1843 if (cltree) {
1844 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1845 vertex = fVertexer->FindVertexForCurrentEvent(cltree);
1846 }
1847 else {
1848 AliError("Can't get the ITS cluster tree");
1849 }
1850 fLoader[0]->UnloadRecPoints();
1851 }
1852 else {
1853 AliError("Can't get the ITS loader");
1854 }
2257f27e 1855 if(!vertex){
815c2b38 1856 AliWarning("Vertex not found");
c710f220 1857 vertex = new AliESDVertex();
d1a50cb5 1858 vertex->SetName("default");
2257f27e 1859 }
1860 else {
d1a50cb5 1861 vertex->SetName("reconstructed");
2257f27e 1862 }
1863
1864 } else {
815c2b38 1865 AliInfo("getting the primary vertex from MC");
2257f27e 1866 vertex = new AliESDVertex(vtxPos, vtxErr);
1867 }
1868
1869 if (vertex) {
1870 vertex->GetXYZ(vtxPos);
1871 vertex->GetSigmaXYZ(vtxErr);
1872 } else {
815c2b38 1873 AliWarning("no vertex reconstructed");
2257f27e 1874 vertex = new AliESDVertex(vtxPos, vtxErr);
1875 }
06cc9d95 1876 esd->SetPrimaryVertexSPD(vertex);
32e449be 1877 // if SPD multiplicity has been determined, it is stored in the ESD
25be1e5c 1878 AliMultiplicity *mult = fVertexer->GetMultiplicity();
32e449be 1879 if(mult)esd->SetMultiplicity(mult);
1880
b8cd5251 1881 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1882 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1883 }
2257f27e 1884 delete vertex;
1885
2257f27e 1886 return kTRUE;
1887}
1888
1889//_____________________________________________________________________________
af885e0f 1890Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 1891{
1892// run the HLT barrel tracking
1893
87932dab 1894 AliCodeTimerAuto("")
1f46a9ae 1895
1896 if (!fRunLoader) {
1897 AliError("Missing runLoader!");
1898 return kFALSE;
1899 }
1900
1901 AliInfo("running HLT tracking");
1902
1903 // Get a pointer to the HLT reconstructor
1904 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1905 if (!reconstructor) return kFALSE;
1906
1907 // TPC + ITS
1908 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1909 TString detName = fgkDetectorName[iDet];
1910 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1911 reconstructor->SetOption(detName.Data());
d76c31f4 1912 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 1913 if (!tracker) {
1914 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1915 if (fStopOnError) return kFALSE;
9dcc06e1 1916 continue;
1f46a9ae 1917 }
1918 Double_t vtxPos[3];
1919 Double_t vtxErr[3]={0.005,0.005,0.010};
1920 const AliESDVertex *vertex = esd->GetVertex();
1921 vertex->GetXYZ(vtxPos);
1922 tracker->SetVertex(vtxPos,vtxErr);
1923 if(iDet != 1) {
1924 fLoader[iDet]->LoadRecPoints("read");
1925 TTree* tree = fLoader[iDet]->TreeR();
1926 if (!tree) {
1927 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1928 return kFALSE;
1929 }
1930 tracker->LoadClusters(tree);
1931 }
1932 if (tracker->Clusters2Tracks(esd) != 0) {
1933 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1934 return kFALSE;
1935 }
1936 if(iDet != 1) {
1937 tracker->UnloadClusters();
1938 }
1939 delete tracker;
1940 }
1941
1f46a9ae 1942 return kTRUE;
1943}
1944
1945//_____________________________________________________________________________
af885e0f 1946Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 1947{
1948// run the muon spectrometer tracking
1949
87932dab 1950 AliCodeTimerAuto("")
e66fbafb 1951
1952 if (!fRunLoader) {
1953 AliError("Missing runLoader!");
1954 return kFALSE;
1955 }
1956 Int_t iDet = 7; // for MUON
1957
1958 AliInfo("is running...");
1959
1960 // Get a pointer to the MUON reconstructor
1961 AliReconstructor *reconstructor = GetReconstructor(iDet);
1962 if (!reconstructor) return kFALSE;
1963
1964
1965 TString detName = fgkDetectorName[iDet];
1966 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 1967 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 1968 if (!tracker) {
1969 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1970 return kFALSE;
1971 }
1972
e66fbafb 1973 // read RecPoints
761350a6 1974 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 1975
761350a6 1976 tracker->LoadClusters(fLoader[iDet]->TreeR());
1977
1978 Int_t rv = tracker->Clusters2Tracks(esd);
1979
761350a6 1980 if ( rv )
1981 {
e66fbafb 1982 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1983 return kFALSE;
1984 }
761350a6 1985
e66fbafb 1986 fLoader[iDet]->UnloadRecPoints();
1987
c1954ee5 1988 tracker->UnloadClusters();
1989
e66fbafb 1990 delete tracker;
1991
e66fbafb 1992 return kTRUE;
1993}
1994
1995
1996//_____________________________________________________________________________
af885e0f 1997Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
2257f27e 1998{
1999// run the barrel tracking
0f88822a 2000 static Int_t eventNr=0;
87932dab 2001 AliCodeTimerAuto("")
24f7a148 2002
815c2b38 2003 AliInfo("running tracking");
596a855f 2004
91b876d1 2005 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 2006 if (fReconstructor[11] && fLoader[11]) {
2007 fLoader[11]->LoadRecPoints("READ");
2008 TTree *treeR = fLoader[11]->TreeR();
2009 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
2010 }
91b876d1 2011
b8cd5251 2012 // pass 1: TPC + ITS inwards
2013 for (Int_t iDet = 1; iDet >= 0; iDet--) {
2014 if (!fTracker[iDet]) continue;
2015 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 2016
b8cd5251 2017 // load clusters
2018 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2019 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 2020 TTree* tree = fLoader[iDet]->TreeR();
2021 if (!tree) {
2022 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2023 return kFALSE;
2024 }
b8cd5251 2025 fTracker[iDet]->LoadClusters(tree);
6efecea1 2026 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2027 // run tracking
2028 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
2029 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 2030 return kFALSE;
2031 }
878e1fe1 2032 // preliminary PID in TPC needed by the ITS tracker
2033 if (iDet == 1) {
b26c3770 2034 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
878e1fe1 2035 AliESDpid::MakePID(esd);
0f88822a 2036 }
6efecea1 2037 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 2038 }
596a855f 2039
b8cd5251 2040 // pass 2: ALL backwards
aa3c69a9 2041
b8cd5251 2042 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2043 if (!fTracker[iDet]) continue;
2044 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
2045
2046 // load clusters
2047 if (iDet > 1) { // all except ITS, TPC
2048 TTree* tree = NULL;
7b61cd9c 2049 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2050 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 2051 tree = fLoader[iDet]->TreeR();
b8cd5251 2052 if (!tree) {
2053 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2054 return kFALSE;
2055 }
0f88822a 2056 fTracker[iDet]->LoadClusters(tree);
6efecea1 2057 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2058 }
24f7a148 2059
b8cd5251 2060 // run tracking
283f39c6 2061 if (iDet>1) // start filling residuals for the "outer" detectors
2062 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
2063
b8cd5251 2064 if (fTracker[iDet]->PropagateBack(esd) != 0) {
2065 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 2066 // return kFALSE;
b8cd5251 2067 }
24f7a148 2068
b8cd5251 2069 // unload clusters
6e65648b 2070 if (iDet > 3) { // all except ITS, TPC, TRD and TOF
b8cd5251 2071 fTracker[iDet]->UnloadClusters();
7b61cd9c 2072 fLoader[iDet]->UnloadRecPoints();
b8cd5251 2073 }
8f37df88 2074 // updated PID in TPC needed by the ITS tracker -MI
2075 if (iDet == 1) {
8f37df88 2076 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
2077 AliESDpid::MakePID(esd);
2078 }
6efecea1 2079 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 2080 }
283f39c6 2081 //stop filling residuals for the "outer" detectors
2082 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
596a855f 2083
b8cd5251 2084 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 2085
b8cd5251 2086 for (Int_t iDet = 2; iDet >= 0; iDet--) {
2087 if (!fTracker[iDet]) continue;
2088 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 2089
b8cd5251 2090 // run tracking
283f39c6 2091 if (iDet<2) // start filling residuals for TPC and ITS
2092 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
2093
b8cd5251 2094 if (fTracker[iDet]->RefitInward(esd) != 0) {
2095 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 2096 // return kFALSE;
b8cd5251 2097 }
db2368d0 2098 // run postprocessing
2099 if (fTracker[iDet]->PostProcess(esd) != 0) {
2100 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
2101 // return kFALSE;
2102 }
6efecea1 2103 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
6e65648b 2104 }
2105
2106 // write space-points to the ESD in case alignment data output
2107 // is switched on
2108 if (fWriteAlignmentData)
2109 WriteAlignmentData(esd);
2110
2111 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2112 if (!fTracker[iDet]) continue;
b8cd5251 2113 // unload clusters
2114 fTracker[iDet]->UnloadClusters();
6efecea1 2115 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 2116 fLoader[iDet]->UnloadRecPoints();
6efecea1 2117 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 2118 }
283f39c6 2119 // stop filling residuals for TPC and ITS
3b378a42 2120 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
854c6476 2121
0f88822a 2122 eventNr++;
596a855f 2123 return kTRUE;
2124}
2125
2126//_____________________________________________________________________________
d64bd07d 2127Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
2128 //
2129 // Remove the data which are not needed for the physics analysis.
2130 //
2131
d64bd07d 2132 Int_t nTracks=esd->GetNumberOfTracks();
18571674 2133 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 2134 AliInfo
2135 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 2136
18571674 2137 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 2138 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 2139
7f68891d 2140 nTracks=esd->GetNumberOfTracks();
18571674 2141 nV0s=esd->GetNumberOfV0s();
cf37fd88 2142 AliInfo
ae5d5566 2143 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 2144
7f68891d 2145 return rc;
d64bd07d 2146}
2147
2148//_____________________________________________________________________________
af885e0f 2149Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 2150{
2151// fill the event summary data
2152
87932dab 2153 AliCodeTimerAuto("")
0f88822a 2154 static Int_t eventNr=0;
596a855f 2155 TString detStr = detectors;
abe0c04e 2156
b8cd5251 2157 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
abe0c04e 2158 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 2159 AliReconstructor* reconstructor = GetReconstructor(iDet);
2160 if (!reconstructor) continue;
4b71572b 2161 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
2162 TTree* clustersTree = NULL;
2163 if (fLoader[iDet]) {
2164 fLoader[iDet]->LoadRecPoints("read");
2165 clustersTree = fLoader[iDet]->TreeR();
2166 if (!clustersTree) {
2167 AliError(Form("Can't get the %s clusters tree",
2168 fgkDetectorName[iDet]));
2169 if (fStopOnError) return kFALSE;
2170 }
2171 }
2172 if (fRawReader && !reconstructor->HasDigitConversion()) {
2173 reconstructor->FillESD(fRawReader, clustersTree, esd);
2174 } else {
2175 TTree* digitsTree = NULL;
d76c31f4 2176 if (fLoader[iDet]) {
4b71572b 2177 fLoader[iDet]->LoadDigits("read");
2178 digitsTree = fLoader[iDet]->TreeD();
2179 if (!digitsTree) {
2180 AliError(Form("Can't get the %s digits tree",
b26c3770 2181 fgkDetectorName[iDet]));
2182 if (fStopOnError) return kFALSE;
2183 }
2184 }
4b71572b 2185 reconstructor->FillESD(digitsTree, clustersTree, esd);
2186 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
2187 }
2188 if (fLoader[iDet]) {
2189 fLoader[iDet]->UnloadRecPoints();
596a855f 2190 }
2191 }
2192
2193 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 2194 AliError(Form("the following detectors were not found: %s",
2195 detStr.Data()));
596a855f 2196 if (fStopOnError) return kFALSE;
2197 }
6efecea1 2198 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
0f88822a 2199 eventNr++;
596a855f 2200 return kTRUE;
2201}
2202
b647652d 2203//_____________________________________________________________________________
af885e0f 2204Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 2205{
2206 // Reads the trigger decision which is
2207 // stored in Trigger.root file and fills
2208 // the corresponding esd entries
2209
87932dab 2210 AliCodeTimerAuto("")
2211
b647652d 2212 AliInfo("Filling trigger information into the ESD");
2213
2214 if (fRawReader) {
2215 AliCTPRawStream input(fRawReader);
2216 if (!input.Next()) {
7e88424f 2217 AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
b647652d 2218 }
2219 else {
7e88424f 2220 if (esd->GetTriggerMask() != input.GetClassMask())
2221 AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
2222 input.GetClassMask(),esd->GetTriggerMask()));
2223 if (esd->GetOrbitNumber() != input.GetOrbitID())
2224 AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
2225 input.GetOrbitID(),esd->GetOrbitNumber()));
2226 if (esd->GetBunchCrossNumber() != input.GetBCID())
2227 AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
2228 input.GetBCID(),esd->GetBunchCrossNumber()));
b647652d 2229 }
b024fd7f 2230
7e88424f 2231 // Here one has to add the filling of trigger inputs and
2232 // interaction records
2233 // ...
b024fd7f 2234 }
b647652d 2235 return kTRUE;
2236}
596a855f 2237
001397cd 2238
2239
2240
2241
2242//_____________________________________________________________________________
af885e0f 2243Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 2244{
2245 //
2246 // Filling information from RawReader Header
2247 //
2248
151bea4e 2249 if (!fRawReader) return kFALSE;
2250
001397cd 2251 AliInfo("Filling information from RawReader Header");
151bea4e 2252
2253 esd->SetBunchCrossNumber(fRawReader->GetBCID());
2254 esd->SetOrbitNumber(fRawReader->GetOrbitID());
2255 esd->SetPeriodNumber(fRawReader->GetPeriod());
2256
2257 esd->SetTimeStamp(fRawReader->GetTimestamp());
2258 esd->SetEventType(fRawReader->GetType());
001397cd 2259
2260 return kTRUE;
2261}
2262
2263
596a855f 2264//_____________________________________________________________________________
2265Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
2266{
2267// check whether detName is contained in detectors
2268// if yes, it is removed from detectors
2269
2270 // check if all detectors are selected
2271 if ((detectors.CompareTo("ALL") == 0) ||
2272 detectors.BeginsWith("ALL ") ||
2273 detectors.EndsWith(" ALL") ||
2274 detectors.Contains(" ALL ")) {
2275 detectors = "ALL";
2276 return kTRUE;
2277 }
2278
2279 // search for the given detector
2280 Bool_t result = kFALSE;
2281 if ((detectors.CompareTo(detName) == 0) ||
2282 detectors.BeginsWith(detName+" ") ||
2283 detectors.EndsWith(" "+detName) ||
2284 detectors.Contains(" "+detName+" ")) {
2285 detectors.ReplaceAll(detName, "");
2286 result = kTRUE;
2287 }
2288
2289 // clean up the detectors string
2290 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2291 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2292 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2293
2294 return result;
2295}
e583c30d 2296
2297//_____________________________________________________________________________
f08fc9f5 2298Bool_t AliReconstruction::InitRunLoader()
2299{
2300// get or create the run loader
2301
2302 if (gAlice) delete gAlice;
2303 gAlice = NULL;
2304
b26c3770 2305 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2306 // load all base libraries to get the loader classes
2307 TString libs = gSystem->GetLibraries();
2308 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2309 TString detName = fgkDetectorName[iDet];
2310 if (detName == "HLT") continue;
2311 if (libs.Contains("lib" + detName + "base.so")) continue;
2312 gSystem->Load("lib" + detName + "base.so");
2313 }
f08fc9f5 2314 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2315 if (!fRunLoader) {
2316 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2317 CleanUp();
2318 return kFALSE;
2319 }
325aa76f 2320
b26c3770 2321 fRunLoader->CdGAFile();
325aa76f 2322 fRunLoader->LoadgAlice();
f08fc9f5 2323
6cae184e 2324 //PH This is a temporary fix to give access to the kinematics
2325 //PH that is needed for the labels of ITS clusters
f2ee4290 2326 fRunLoader->LoadHeader();
6cae184e 2327 fRunLoader->LoadKinematics();
2328
f08fc9f5 2329 } else { // galice.root does not exist
2330 if (!fRawReader) {
2331 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
f08fc9f5 2332 }
2333 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2334 AliConfig::GetDefaultEventFolderName(),
2335 "recreate");
2336 if (!fRunLoader) {
2337 AliError(Form("could not create run loader in file %s",
2338 fGAliceFileName.Data()));
2339 CleanUp();
2340 return kFALSE;
2341 }
21a3aa09 2342 fIsNewRunLoader = kTRUE;
f08fc9f5 2343 fRunLoader->MakeTree("E");
21a3aa09 2344
973388c2 2345 if (fNumberOfEventsPerFile > 0)
2346 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2347 else
21a3aa09 2348 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 2349 }
2350
2351 return kTRUE;
2352}
2353
2354//_____________________________________________________________________________
b8cd5251 2355AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 2356{
f08fc9f5 2357// get the reconstructor object and the loader for a detector
c757bafd 2358
7e88424f 2359 if (fReconstructor[iDet]) {
2360 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2361 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2362 fReconstructor[iDet]->SetRecoParam(par);
2363 }
2364 return fReconstructor[iDet];
2365 }
b8cd5251 2366
2367 // load the reconstructor object
2368 TPluginManager* pluginManager = gROOT->GetPluginManager();
2369 TString detName = fgkDetectorName[iDet];
2370 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 2371
2372 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 2373
b8cd5251 2374 AliReconstructor* reconstructor = NULL;
2375 // first check if a plugin is defined for the reconstructor
2376 TPluginHandler* pluginHandler =
2377 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 2378 // if not, add a plugin for it
2379 if (!pluginHandler) {
b8cd5251 2380 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 2381 TString libs = gSystem->GetLibraries();
2382 if (libs.Contains("lib" + detName + "base.so") ||
2383 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 2384 pluginManager->AddHandler("AliReconstructor", detName,
2385 recName, detName + "rec", recName + "()");
2386 } else {
2387 pluginManager->AddHandler("AliReconstructor", detName,
2388 recName, detName, recName + "()");
c757bafd 2389 }
b8cd5251 2390 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2391 }
2392 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2393 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 2394 }
b8cd5251 2395 if (reconstructor) {
2396 TObject* obj = fOptions.FindObject(detName.Data());
2397 if (obj) reconstructor->SetOption(obj->GetTitle());
d76c31f4 2398 reconstructor->Init();
b8cd5251 2399 fReconstructor[iDet] = reconstructor;
2400 }
2401
f08fc9f5 2402 // get or create the loader
2403 if (detName != "HLT") {
2404 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2405 if (!fLoader[iDet]) {
2406 AliConfig::Instance()
2407 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2408 detName, detName);
2409 // first check if a plugin is defined for the loader
bb0901a4 2410 pluginHandler =
f08fc9f5 2411 pluginManager->FindHandler("AliLoader", detName);
2412 // if not, add a plugin for it
2413 if (!pluginHandler) {
2414 TString loaderName = "Ali" + detName + "Loader";
2415 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2416 pluginManager->AddHandler("AliLoader", detName,
2417 loaderName, detName + "base",
2418 loaderName + "(const char*, TFolder*)");
2419 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2420 }
2421 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2422 fLoader[iDet] =
2423 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2424 fRunLoader->GetEventFolder());
2425 }
2426 if (!fLoader[iDet]) { // use default loader
2427 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2428 }
2429 if (!fLoader[iDet]) {
2430 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 2431 if (fStopOnError) return NULL;
f08fc9f5 2432 } else {
2433 fRunLoader->AddLoader(fLoader[iDet]);
2434 fRunLoader->CdGAFile();
2435 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2436 fRunLoader->Write(0, TObject::kOverwrite);
2437 }
2438 }
2439 }
2440
7e88424f 2441 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2442 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2443 reconstructor->SetRecoParam(par);
2444 }
b8cd5251 2445 return reconstructor;
c757bafd 2446}
2447
2448//_____________________________________________________________________________
2257f27e 2449Bool_t AliReconstruction::CreateVertexer()
2450{
2451// create the vertexer
2452
b8cd5251 2453 fVertexer = NULL;
2454 AliReconstructor* itsReconstructor = GetReconstructor(0);
59697224 2455 if (itsReconstructor) {
d76c31f4 2456 fVertexer = itsReconstructor->CreateVertexer();
2257f27e 2457 }
b8cd5251 2458 if (!fVertexer) {
815c2b38 2459 AliWarning("couldn't create a vertexer for ITS");
2257f27e 2460 if (fStopOnError) return kFALSE;
2461 }
2462
2463 return kTRUE;
2464}
2465
2466//_____________________________________________________________________________
b8cd5251 2467Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 2468{
f08fc9f5 2469// create the trackers
24f7a148 2470
b8cd5251 2471 TString detStr = detectors;
2472 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2473 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2474 AliReconstructor* reconstructor = GetReconstructor(iDet);
2475 if (!reconstructor) continue;
2476 TString detName = fgkDetectorName[iDet];
1f46a9ae 2477 if (detName == "HLT") {
2478 fRunHLTTracking = kTRUE;
2479 continue;
2480 }
e66fbafb 2481 if (detName == "MUON") {
2482 fRunMuonTracking = kTRUE;
2483 continue;
2484 }
2485
f08fc9f5 2486
d76c31f4 2487 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 2488 if (!fTracker[iDet] && (iDet < 7)) {
2489 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 2490 if (fStopOnError) return kFALSE;
2491 }
6efecea1 2492 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 2493 }
2494
24f7a148 2495 return kTRUE;
2496}
2497
2498//_____________________________________________________________________________
4b71572b 2499void AliReconstruction::CleanUp()
e583c30d 2500{
2501// delete trackers and the run loader and close and delete the file
2502
b8cd5251 2503 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2504 delete fReconstructor[iDet];
2505 fReconstructor[iDet] = NULL;
2506 fLoader[iDet] = NULL;
2507 delete fTracker[iDet];
2508 fTracker[iDet] = NULL;
2509 }
4b71572b 2510 delete fRunInfo;
7e88424f 2511 fRunInfo = NULL;
2512
b8cd5251 2513 delete fVertexer;
2514 fVertexer = NULL;
21a3aa09 2515
4b71572b 2516 delete ftVertexer;
21a3aa09 2517 ftVertexer = NULL;
795e4a22 2518
2519 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
4b71572b 2520 delete fDiamondProfile;
2521 fDiamondProfile = NULL;
2522 delete fDiamondProfileTPC;
2523 fDiamondProfileTPC = NULL;
795e4a22 2524 }
4b71572b 2525 delete fGRPData;
2526 fGRPData = NULL;
444753c6 2527
e583c30d 2528 delete fRunLoader;
2529 fRunLoader = NULL;
b649205a 2530 delete fRawReader;
2531 fRawReader = NULL;
4b71572b 2532 delete fParentRawReader;
cd0b062e 2533 fParentRawReader=NULL;
e583c30d 2534
4b71572b 2535 if (ffile) {
2536 ffile->Close();
2537 delete ffile;
2538 ffile = NULL;
24f7a148 2539 }
24f7a148 2540}
f3a97c86 2541
af885e0f 2542void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 2543{
2544 // Write space-points which are then used in the alignment procedures
6e65648b 2545 // For the moment only ITS, TPC, TRD and TOF
98937d93 2546
98937d93 2547 Int_t ntracks = esd->GetNumberOfTracks();
2548 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2549 {
2550 AliESDtrack *track = esd->GetTrack(itrack);
2551 Int_t nsp = 0;
ef7253ac 2552 Int_t idx[200];
6e65648b 2553 for (Int_t iDet = 3; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
2554 nsp += track->GetNcls(iDet);
2555
2556 if (iDet==0) { // ITS "extra" clusters
2557 track->GetClusters(iDet,idx);
2558 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
2559 }
2560 }
2561
98937d93 2562 if (nsp) {
2563 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2564 track->SetTrackPointArray(sp);
2565 Int_t isptrack = 0;
2566 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2567 AliTracker *tracker = fTracker[iDet];
2568 if (!tracker) continue;
6e65648b 2569 Int_t nspdet = track->GetClusters(iDet,idx);
2570
2571 if (iDet==0) // ITS "extra" clusters
2572 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
2573
98937d93 2574 if (nspdet <= 0) continue;
98937d93 2575 AliTrackPoint p;
2576 Int_t isp = 0;
2577 Int_t isp2 = 0;
4ed6fb1c 2578 while (isp2 < nspdet) {
f3c6e4c9 2579 Bool_t isvalid=kTRUE;
2580
2581 Int_t index=idx[isp++];
2582 if (index < 0) continue;
2583
c12b6e44 2584 TString dets = fgkDetectorName[iDet];
2585 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2586 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2587 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2588 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
f3c6e4c9 2589 isvalid = tracker->GetTrackPointTrackingError(index,p,track);
48ce48d1 2590 } else {
f3c6e4c9 2591 isvalid = tracker->GetTrackPoint(index,p);
48ce48d1 2592 }
2593 isp2++;
98937d93 2594 if (!isvalid) continue;
f3c6e4c9 2595 sp->AddPoint(isptrack,&p); isptrack++;
98937d93 2596 }
98937d93 2597 }
2598 }
2599 }
98937d93 2600}
2e3550da 2601
2602//_____________________________________________________________________________
af885e0f 2603void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 2604{
2605 // The method reads the raw-data error log
2606 // accumulated within the rawReader.
2607 // It extracts the raw-data errors related to
2608 // the current event and stores them into
2609 // a TClonesArray inside the esd object.
2610
2611 if (!fRawReader) return;
2612
2613 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2614
2615 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2616 if (!log) continue;
2617 if (iEvent != log->GetEventNumber()) continue;
2618
2619 esd->AddRawDataErrorLog(log);
2620 }
2621
2622}
46698ae4 2623
605cb8bb 2624TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString pName){
b545009a 2625 // Dump a file content into a char in TNamed
46698ae4 2626 ifstream in;
2627 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2628 Int_t kBytes = (Int_t)in.tellg();
2629 printf("Size: %d \n",kBytes);
2630 TNamed *fn = 0;
2631 if(in.good()){
2632 char* memblock = new char [kBytes];
2633 in.seekg (0, ios::beg);
2634 in.read (memblock, kBytes);
2635 in.close();
2636 TString fData(memblock,kBytes);
605cb8bb 2637 fn = new TNamed(pName,fData);
46698ae4 2638 printf("fData Size: %d \n",fData.Sizeof());
605cb8bb 2639 printf("pName Size: %d \n",pName.Sizeof());
46698ae4 2640 printf("fn Size: %d \n",fn->Sizeof());
2641 delete[] memblock;
2642 }
2643 else{
2644 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2645 }
2646
2647 return fn;
2648}
2649
605cb8bb 2650void AliReconstruction::TNamedToFile(TTree* fTree, TString pName){
46698ae4 2651 // This is not really needed in AliReconstruction at the moment
2652 // but can serve as a template
2653
2654 TList *fList = fTree->GetUserInfo();
605cb8bb 2655 TNamed *fn = (TNamed*)fList->FindObject(pName.Data());
46698ae4 2656 printf("fn Size: %d \n",fn->Sizeof());
2657
605cb8bb 2658 TString fTmp(fn->GetName()); // to be 100% sure in principle pName also works
46698ae4 2659 const char* cdata = fn->GetTitle();
2660 printf("fTmp Size %d\n",fTmp.Sizeof());
2661
2662 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2663 printf("calculated size %d\n",size);
605cb8bb 2664 ofstream out(pName.Data(),ios::out | ios::binary);
46698ae4 2665 out.write(cdata,size);
2666 out.close();
2667
2668}
6efecea1 2669
7e963665 2670//_____________________________________________________________________________
8661738e 2671void AliReconstruction::CheckQA()
2672{
2673// check the QA of SIM for this run and remove the detectors
2674// with status Fatal
2675
abe0c04e 2676 TString newRunLocalReconstruction ;
2677 TString newRunTracking ;
2678 TString newFillESD ;
2679
8661738e 2680 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2681 TString detName(AliQA::GetDetName(iDet)) ;
96d67a8d 2682 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2683 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
8661738e 2684 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
abe0c04e 2685 } else {
2686 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2687 fRunLocalReconstruction.Contains("ALL") ) {
2688 newRunLocalReconstruction += detName ;
2689 newRunLocalReconstruction += " " ;
2690 }
2691 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2692 fRunTracking.Contains("ALL") ) {
2693 newRunTracking += detName ;
2694 newRunTracking += " " ;
2695 }
2696 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2697 fFillESD.Contains("ALL") ) {
2698 newFillESD += detName ;
2699 newFillESD += " " ;
8661738e 2700 }
2701 }
2702 }
abe0c04e 2703 fRunLocalReconstruction = newRunLocalReconstruction ;
2704 fRunTracking = newRunTracking ;
2705 fFillESD = newFillESD ;
a5fa6165 2706}
5b188f2f 2707
2708//_____________________________________________________________________________
2709Int_t AliReconstruction::GetDetIndex(const char* detector)
2710{
2711 // return the detector index corresponding to detector
2712 Int_t index = -1 ;
2713 for (index = 0; index < fgkNDetectors ; index++) {
2714 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2715 break ;
2716 }
2717 return index ;
2718}
7167ae53 2719//_____________________________________________________________________________
2720Bool_t AliReconstruction::FinishPlaneEff() {
2721 //
2722 // Here execute all the necessary operationis, at the end of the tracking phase,
d7f8fd68 2723 // in case that evaluation of PlaneEfficiencies was required for some detector.
2724 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
7167ae53 2725 //
2726 // This Preliminary version works only FOR ITS !!!!!
2727 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2728 //
2729 // Input: none
d7f8fd68 2730 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
7167ae53 2731 //
2732 Bool_t ret=kFALSE;
2733 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
d7f8fd68 2734 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
7167ae53 2735 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
5fbd4fd6 2736 if(fTracker[iDet]) {
d7f8fd68 2737 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2738 TString name=planeeff->GetName();
2739 name+=".root";
2740 TFile* pefile = TFile::Open(name, "RECREATE");
2741 ret=(Bool_t)planeeff->Write();
2742 pefile->Close();
5fbd4fd6 2743 if(planeeff->GetCreateHistos()) {
d7f8fd68 2744 TString hname=planeeff->GetName();
2745 hname+="Histo.root";
2746 ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
5fbd4fd6 2747 }
2748 }
7167ae53 2749 }
2750 return ret;
2751}
2752//_____________________________________________________________________________
2753Bool_t AliReconstruction::InitPlaneEff() {
2754//
2755 // Here execute all the necessary operations, before of the tracking phase,
2756 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2757 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2758 // which should be updated/recalculated.
2759 //
2760 // This Preliminary version will work only FOR ITS !!!!!
2761 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2762 //
2763 // Input: none
2764 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2765 //
2766 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));
2767 return kTRUE;
7520312d 2768}
14dd053c 2769
2770//_____________________________________________________________________________
2771Bool_t AliReconstruction::InitAliEVE()
2772{
2773 // This method should be called only in case
2774 // AliReconstruction is run
2775 // within the alieve environment.
2776 // It will initialize AliEVE in a way
2777 // so that it can visualize event processed
2778 // by AliReconstruction.
2779 // The return flag shows whenever the
2780 // AliEVE initialization was successful or not.
2781
2782 TString macroStr;
2783 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
2784 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
2785 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
2786
47aab29b 2787 gROOT->ProcessLine("if (!gAliEveEvent) {gAliEveEvent = new AliEveEventManager();gAliEveEvent->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(gAliEveEvent);};");
de33999e 2788 gROOT->ProcessLine("alieve_online_init()");
14dd053c 2789
2790 return kTRUE;
2791}
2792
2793//_____________________________________________________________________________
2794void AliReconstruction::RunAliEVE()
2795{
2796 // Runs AliEVE visualisation of
2797 // the current event.
2798 // Should be executed only after
2799 // successful initialization of AliEVE.
2800
2801 AliInfo("Running AliEVE...");
2802 gROOT->ProcessLine(Form("gAliEveEvent->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p);",fRunLoader,fRawReader,fesd));
14dd053c 2803 gSystem->Run();
2804}
ce43afbe 2805
2806//_____________________________________________________________________________
2807Bool_t AliReconstruction::SetRunQA(TString detAndAction)
2808{
2809 // Allows to run QA for a selected set of detectors
2810 // and a selected set of tasks among RAWS, RECPOINTS and ESDS
2811 // all selected detectors run the same selected tasks
2812
2813 if (!detAndAction.Contains(":")) {
2814 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
2815 fRunQA = kFALSE ;
2816 return kFALSE ;
2817 }
2818 Int_t colon = detAndAction.Index(":") ;
2819 fQADetectors = detAndAction(0, colon) ;
2820 if (fQADetectors.Contains("ALL") )
2821 fQADetectors = fFillESD ;
e84c88f5 2822 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
ce43afbe 2823 if (fQATasks.Contains("ALL") ) {
2824 fQATasks = Form("%d %d %d", AliQA::kRAWS, AliQA::kRECPOINTS, AliQA::kESDS) ;
2825 } else {
2826 fQATasks.ToUpper() ;
2827 TString tempo("") ;
2828 if ( fQATasks.Contains("RAW") )
2829 tempo = Form("%d ", AliQA::kRAWS) ;
2830 if ( fQATasks.Contains("RECPOINT") )
2831 tempo += Form("%d ", AliQA::kRECPOINTS) ;
2832 if ( fQATasks.Contains("ESD") )
2833 tempo += Form("%d ", AliQA::kESDS) ;
2834 fQATasks = tempo ;
2835 if (fQATasks.IsNull()) {
2836 AliInfo("No QA requested\n") ;
2837 fRunQA = kFALSE ;
2838 return kTRUE ;
2839 }
2840 }
2841 TString tempo(fQATasks) ;
e84c88f5 2842 tempo.ReplaceAll(Form("%d", AliQA::kRAWS), AliQA::GetTaskName(AliQA::kRAWS)) ;
2843 tempo.ReplaceAll(Form("%d", AliQA::kRECPOINTS), AliQA::GetTaskName(AliQA::kRECPOINTS)) ;
2844 tempo.ReplaceAll(Form("%d", AliQA::kESDS), AliQA::GetTaskName(AliQA::kESDS)) ;
ce43afbe 2845 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
2846 fRunQA = kTRUE ;
2847 return kTRUE;
2848}
2849
7e88424f 2850//_____________________________________________________________________________
2851Bool_t AliReconstruction::InitRecoParams()
2852{
2853 // The method accesses OCDB and retrieves all
2854 // the available reco-param objects from there.
2855
2856 Bool_t isOK = kTRUE;
2857
7d566c20 2858 TString detStr = fLoadCDB;
7e88424f 2859 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2860
7d566c20 2861 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2862
7e88424f 2863 if (fRecoParam.GetDetRecoParamArray(iDet)) {
2864 AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
2865 continue;
2866 }
2867
ac232c75 2868 AliInfo(Form("Loading reconstruction parameter objects for detector %s",fgkDetectorName[iDet]));
7e88424f 2869
2870 AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
2871 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
2872 if(!entry){
2873 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
2874 isOK = kFALSE;
2875 }
2876 else {
2877 TObject *recoParamObj = entry->GetObject();
2878 if (dynamic_cast<TObjArray*>(recoParamObj)) {
2879 // The detector has a normal TobjArray of AliDetectorRecoParam objects
2880 // Registering them in AliRecoParam
2881 fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
2882 }
2883 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
2884 // The detector has only onse set of reco parameters
2885 // Registering it in AliRecoParam
ac232c75 2886 AliInfo(Form("Single set of reconstruction parameters found for detector %s",fgkDetectorName[iDet]));
7e88424f 2887 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
2888 fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
2889 }
2890 else {
2891 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
2892 isOK = kFALSE;
2893 }
2894 entry->SetOwner(0);
4b71572b 2895 AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
7e88424f 2896 }
2897 }
2898
e30a9b4d 2899 if (AliDebugLevel() > 0) fRecoParam.Print();
ac232c75 2900
7e88424f 2901 return isOK;
2902}
2903
2904//_____________________________________________________________________________
2905Bool_t AliReconstruction::GetEventInfo()
2906{
2907 // Fill the event info object
2908 // ...
2909 AliCodeTimerAuto("")
2910
2911 AliCentralTrigger *aCTP = NULL;
2912 if (fRawReader) {
2913 fEventInfo.SetEventType(fRawReader->GetType());
2914
2915 ULong64_t mask = fRawReader->GetClassMask();
2916 fEventInfo.SetTriggerMask(mask);
2917 UInt_t clmask = fRawReader->GetDetectorPattern()[0];
2918 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
2919
2920 aCTP = new AliCentralTrigger();
2921 TString configstr("");
2922 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
2923 AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
2924 delete aCTP;
2925 return kFALSE;
2926 }
2927 aCTP->SetClassMask(mask);
2928 aCTP->SetClusterMask(clmask);
2929 }
2930 else {
2931 fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
2932
2933 if (fRunLoader && (!fRunLoader->LoadTrigger())) {
2934 aCTP = fRunLoader->GetTrigger();
2935 fEventInfo.SetTriggerMask(aCTP->GetClassMask());
2936 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
2937 }
2938 else {
2939 AliWarning("No trigger can be loaded! The trigger information will not be used!");
2940 return kFALSE;
2941 }
2942 }
2943
2944 AliTriggerConfiguration *config = aCTP->GetConfiguration();
2945 if (!config) {
2946 AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
2947 if (fRawReader) delete aCTP;
2948 return kFALSE;
2949 }
2950
a0c2cf2d 2951 UChar_t clustmask = 0;
7e88424f 2952 TString trclasses;
2953 ULong64_t trmask = fEventInfo.GetTriggerMask();
2954 const TObjArray& classesArray = config->GetClasses();
2955 Int_t nclasses = classesArray.GetEntriesFast();
2956 for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
2957 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
2958 if (trclass) {
2959 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
2960 fesd->SetTriggerClass(trclass->GetName(),trindex);
2961 if (trmask & (1 << trindex)) {
2962 trclasses += " ";
2963 trclasses += trclass->GetName();
2964 trclasses += " ";
a0c2cf2d 2965 clustmask |= trclass->GetCluster()->GetClusterMask();
7e88424f 2966 }
2967 }
2968 }
2969 fEventInfo.SetTriggerClasses(trclasses);
2970
a0c2cf2d 2971 // Set the information in ESD
2972 fesd->SetTriggerMask(trmask);
2973 fesd->SetTriggerCluster(clustmask);
2974
7e88424f 2975 if (!aCTP->CheckTriggeredDetectors()) {
2976 if (fRawReader) delete aCTP;
2977 return kFALSE;
2978 }
2979
2980 if (fRawReader) delete aCTP;
2981
2982 // We have to fill also the HLT decision here!!
2983 // ...
2984
2985 return kTRUE;
2986}
2987
2988const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
2989{
2990 // Match the detector list found in the rec.C or the default 'ALL'
2991 // to the list found in the GRP (stored there by the shuttle PP which
2992 // gets the information from ECS)
2993 static TString resultList;
2994 TString detList = detectorList;
2995
2996 resultList = "";
2997
2998 for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
2999 if ((detectorMask >> iDet) & 0x1) {
3000 TString det = AliDAQ::OfflineModuleName(iDet);
3001 if ((detList.CompareTo("ALL") == 0) ||
3002 detList.BeginsWith("ALL ") ||
3003 detList.EndsWith(" ALL") ||
3004 detList.Contains(" ALL ") ||
3005 (detList.CompareTo(det) == 0) ||
3006 detList.BeginsWith(det) ||
3007 detList.EndsWith(det) ||
3008 detList.Contains( " "+det+" " )) {
3009 if (!resultList.EndsWith(det + " ")) {
3010 resultList += det;
3011 resultList += " ";
3012 }
3013 }
3014 }
3015 }
3016
3017 // HLT
3018 if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
3019 TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
3020 if ((detList.CompareTo("ALL") == 0) ||
3021 detList.BeginsWith("ALL ") ||
3022 detList.EndsWith(" ALL") ||
3023 detList.Contains(" ALL ") ||
3024 (detList.CompareTo(hltDet) == 0) ||
3025 detList.BeginsWith(hltDet) ||
3026 detList.EndsWith(hltDet) ||
3027 detList.Contains( " "+hltDet+" " )) {
3028 resultList += hltDet;
3029 }
3030 }
3031
3032 return resultList.Data();
3033
3034}
4b71572b 3035
3036//______________________________________________________________________________
3037void AliReconstruction::Abort(const char *method, EAbort what)
3038{
3039 // Abort processing. If what = kAbortProcess, the Process() loop will be
3040 // aborted. If what = kAbortFile, the current file in a chain will be
3041 // aborted and the processing will continue with the next file, if there
3042 // is no next file then Process() will be aborted. Abort() can also be
3043 // called from Begin(), SlaveBegin(), Init() and Notify(). After abort
3044 // the SlaveTerminate() and Terminate() are always called. The abort flag
3045 // can be checked in these methods using GetAbort().
3046 //
3047 // The method is overwritten in AliReconstruction for better handling of
3048 // reco specific errors
3049
3050 if (!fStopOnError) return;
3051
3052 CleanUp();
3053
3054 TString whyMess = method;
3055 whyMess += " failed! Aborting...";
3056
3057 AliError(whyMess.Data());
3058
3059 fAbort = what;
3060 TString mess = "Abort";
3061 if (fAbort == kAbortProcess)
3062 mess = "AbortProcess";
3063 else if (fAbort == kAbortFile)
3064 mess = "AbortFile";
3065
3066 Info(mess, whyMess.Data());
3067}