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