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