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