]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEER/AliReconstruction.cxx
Don't unload geometry from the CDB cache
[u/mrichter/AliRoot.git] / STEER / STEER / AliReconstruction.cxx
CommitLineData
596a855f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
fc07289e 3 * *
596a855f 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
5e319bd5 16/* $Id: AliReconstruction.cxx 63911 2013-08-19 16:46:41Z hristov $ */
596a855f 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
f7a1cc68 111#include <TArrayD.h>
024a7e64 112#include <TArrayF.h>
f7a1cc68 113#include <TArrayS.h>
114#include <TChain.h>
024a7e64 115#include <TFile.h>
f7a1cc68 116#include <TGeoGlobalMagField.h>
3103d196 117#include <TGeoManager.h>
f7a1cc68 118#include <TList.h>
2bdb9d38 119#include <TLorentzVector.h>
325aa76f 120#include <TMap.h>
f7a1cc68 121#include <TObjArray.h>
122#include <TPRegexp.h>
123#include <TParameter.h>
124#include <TPluginManager.h>
4b71572b 125#include <TProof.h>
db4aeca1 126#include <TProofOutputFile.h>
f7a1cc68 127#include <TROOT.h>
128#include <TSystem.h>
77ba28ba 129#include <THashTable.h>
6c6f2624 130#include <TGrid.h>
131#include <TMessage.h>
0a035be5 132#include <TUrl.h>
fc01854a 133#include <TRandom.h>
5dfb32c1 134#include <THashList.h>
596a855f 135
f7a1cc68 136#include "AliAlignObj.h"
42457748 137#include "AliAnalysisManager.h"
138#include "AliAnalysisDataContainer.h"
f7a1cc68 139#include "AliCDBEntry.h"
140#include "AliCDBManager.h"
141#include "AliCDBStorage.h"
142#include "AliCTPRawStream.h"
143#include "AliCascadeVertexer.h"
144#include "AliCentralTrigger.h"
87932dab 145#include "AliCodeTimer.h"
f7a1cc68 146#include "AliDAQ.h"
147#include "AliDetectorRecoParam.h"
148#include "AliESDCaloCells.h"
149#include "AliESDCaloCluster.h"
af885e0f 150#include "AliESDEvent.h"
faffd83e 151#include "AliESDMuonTrack.h"
f7a1cc68 152#include "AliESDPmdTrack.h"
153#include "AliESDTagCreator.h"
2257f27e 154#include "AliESDVertex.h"
faffd83e 155#include "AliESDcascade.h"
f7a1cc68 156#include "AliESDfriend.h"
faffd83e 157#include "AliESDkink.h"
596a855f 158#include "AliESDpid.h"
ff8bb5ae 159#include "AliESDtrack.h"
f7a1cc68 160#include "AliESDtrack.h"
161#include "AliEventInfo.h"
162#include "AliGRPObject.h"
163#include "AliGRPRecoParam.h"
164#include "AliGenEventHeader.h"
25be1e5c 165#include "AliGeomManager.h"
aa3c69a9 166#include "AliGlobalQADataMaker.h"
f7a1cc68 167#include "AliHeader.h"
168#include "AliLog.h"
169#include "AliMagF.h"
170#include "AliMultiplicity.h"
171#include "AliPID.h"
172#include "AliPlaneEff.h"
4e25ac79 173#include "AliQAv1.h"
f7a1cc68 174#include "AliQADataMakerRec.h"
b03591ab 175#include "AliQAManager.h"
33314186 176#include "AliRawVEvent.h"
f7a1cc68 177#include "AliRawEventHeaderBase.h"
cd0b062e 178#include "AliRawHLTManager.h"
f7a1cc68 179#include "AliRawReaderDate.h"
180#include "AliRawReaderFile.h"
181#include "AliRawReaderRoot.h"
42457748 182#include "AliRecoInputHandler.h"
f7a1cc68 183#include "AliReconstruction.h"
184#include "AliReconstructor.h"
185#include "AliRun.h"
7e88424f 186#include "AliRunInfo.h"
f7a1cc68 187#include "AliRunLoader.h"
188#include "AliSysInfo.h" // memory snapshots
189#include "AliTrackPointArray.h"
190#include "AliTracker.h"
191#include "AliTriggerClass.h"
192#include "AliTriggerCluster.h"
a6dd87ad 193#include "AliTriggerIR.h"
f7a1cc68 194#include "AliTriggerConfiguration.h"
195#include "AliV0vertexer.h"
196#include "AliVertexer.h"
1f9831ab 197#include "AliTrackleter.h"
f7a1cc68 198#include "AliVertexerTracks.h"
52dd4a8c 199#include "AliTriggerRunScalers.h"
200#include "AliCTPTimeParams.h"
8b12d288 201#include "AliESDHLTDecision.h"
6ef9caeb 202#include "AliTriggerInput.h"
3d84ad67 203#include "AliLHCData.h"
27aa8455 204#include "ARVersion.h"
205#include <RVersion.h>
e973a743 206#include <stdlib.h>
30b916f7 207#include <unistd.h>
208#include <sys/resource.h>
596a855f 209ClassImp(AliReconstruction)
210
e61afb80 211using std::endl;
212
c757bafd 213//_____________________________________________________________________________
30b916f7 214const char* AliReconstruction::fgkStopEvFName = "_stopEvent_";
c1c44db3 215const char* AliReconstruction::fgkDetectorName[AliReconstruction::kNDetectors] = {"ITS", "TPC", "TRD",
216"TOF", "PHOS",
217"HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE","AD","FIT","MFT", "HLT"};
c757bafd 218
596a855f 219//_____________________________________________________________________________
4b71572b 220AliReconstruction::AliReconstruction(const char* gAliceFilename) :
221 TSelector(),
2257f27e 222 fRunVertexFinder(kTRUE),
a84e2607 223 fRunVertexFinderTracks(kTRUE),
e66fbafb 224 fRunMuonTracking(kFALSE),
d3eabe96 225 fRunMFTTrackingMU(kFALSE),
d1683eef 226 fRunV0Finder(kTRUE),
227 fRunCascadeFinder(kTRUE),
1f9831ab 228 fRunMultFinder(kTRUE),
c8025cc8 229 fStopOnError(kTRUE),
07472556 230 fStopOnMissingTriggerFile(kTRUE),
1d99986f 231 fWriteAlignmentData(kFALSE),
232 fWriteESDfriend(kFALSE),
b647652d 233 fFillTriggerESD(kTRUE),
1d99986f 234
7f68891d 235 fCleanESD(kTRUE),
a023d8d8 236 fV0DCAmax(3.),
237 fV0CsPmin(0.),
7f68891d 238 fDmax(50.),
239 fZmax(50.),
240
1d99986f 241 fRunLocalReconstruction("ALL"),
b8cd5251 242 fRunTracking("ALL"),
e583c30d 243 fFillESD("ALL"),
e54c9180 244 fDeleteRecPoints(""),
245 fDeleteDigits(""),
7d566c20 246 fLoadCDB(""),
48ce48d1 247 fUseTrackingErrorsForAlignment(""),
e583c30d 248 fGAliceFileName(gAliceFilename),
4b71572b 249 fRawInput(""),
975320a0 250 fESDOutput(""),
81d57268 251 fProofOutputFileName(""),
252 fProofOutputLocation(""),
253 fProofOutputDataset(kFALSE),
254 fProofOutputArchive(""),
35042093 255 fEquipIdMap(""),
b26c3770 256 fFirstEvent(0),
257 fLastEvent(-1),
9d705769 258 fNumberOfEventsPerFile((UInt_t)-1),
fc01854a 259 fFractionFriends(0.04),
b8cd5251 260 fOptions(),
6bae477a 261 fLoadAlignFromCDB(kTRUE),
262 fLoadAlignData("ALL"),
cd0b062e 263 fUseHLTData(),
7e88424f 264 fRunInfo(NULL),
265 fEventInfo(),
522fdd91 266 fRunScalers(NULL),
52dd4a8c 267 fCTPTimeParams(NULL),
c7ff1a33 268 fCTPTimeAlign(NULL),
e583c30d 269
270 fRunLoader(NULL),
b649205a 271 fRawReader(NULL),
cd0b062e 272 fParentRawReader(NULL),
b8cd5251 273
7e88424f 274 fRecoParam(),
275
58e8dc31 276 fSPDTrackleter(NULL),
277
f2a195c1 278 fDiamondProfileSPD(NULL),
9178838a 279 fDiamondProfile(NULL),
43c9dae1 280 fDiamondProfileTPC(NULL),
77ba28ba 281 fListOfCosmicTriggers(NULL),
f2a195c1 282
6b6e4472 283 fGRPData(NULL),
444753c6 284
6bae477a 285 fAlignObjArray(NULL),
795e4a22 286 fCDBUri(),
f1c1204d 287 fQARefUri(),
759c1df1 288 fSpecCDBUri(),
92258ce2 289 fCheckRecoCDBvsSimuCDB(),
795e4a22 290 fInitCDBCalled(kFALSE),
989744a6 291 fCDBSnapshotMode(kFALSE),
795e4a22 292 fSetRunNumberFromDataCalled(kFALSE),
ce43afbe 293 fQADetectors("ALL"),
294 fQATasks("ALL"),
7e963665 295 fRunQA(kTRUE),
6b150027 296 fRunGlobalQA(kTRUE),
e4a998ed 297 fSameQACycle(kFALSE),
f1c1204d 298 fInitQACalled(kFALSE),
75373542 299 fWriteQAExpertData(kTRUE),
21a3aa09 300 fRunPlaneEff(kFALSE),
301
1d26da6d 302 fESDpid(NULL),
303
21a3aa09 304 fesd(NULL),
305 fhltesd(NULL),
306 fesdf(NULL),
307 ffile(NULL),
ee7c441c 308 ffileF(NULL),
21a3aa09 309 ftree(NULL),
ee7c441c 310 ftreeF(NULL),
21a3aa09 311 fhlttree(NULL),
21a3aa09 312 ftVertexer(NULL),
14dd053c 313 fIsNewRunLoader(kFALSE),
4b71572b 314 fRunAliEVE(kFALSE),
f00558b6 315 fChain(NULL),
316 fNall(0),
317 fNspecie(0),
318 fSspecie(0),
319 fNhighPt(0),
f9fc20b4 320 fShighPt(0),
5ee8b64f 321 //
322 fTreeBuffSize(30000000),
323 fMemCountESD(0),
324 fMemCountESDF(0),
325 fMemCountESDHLT(0),
326 //
42457748 327 fUpgradeModule(""),
328 fAnalysisMacro(),
329 fAnalysis(0),
764daca3 330 fRecoHandler(0),
30b916f7 331 fDeclTriggerClasses(""),
332 fStopped(kFALSE),
333 fMaxRSS(0),
334 fMaxVMEM(0)
596a855f 335{
336// create reconstruction object with default parameters
002c9d1b 337 gGeoManager = NULL;
b8cd5251 338
ac4a7581 339 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 340 fReconstructor[iDet] = NULL;
f9fc20b4 341 fUpgradeMask[iDet]=kFALSE;
b8cd5251 342 fLoader[iDet] = NULL;
343 fTracker[iDet] = NULL;
344 }
4e25ac79 345 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
252f8aa8 346 fQACycles[iDet] = 999999 ;
347 fQAWriteExpert[iDet] = kFALSE ;
348 }
3d84ad67 349 fBeamInt[0][0]=fBeamInt[0][1]=fBeamInt[1][0]=fBeamInt[1][1] = -1;
92258ce2 350 //
351 AddCheckRecoCDBvsSimuCDB("TPC/Calib/RecoParam"); // check for similarity in the sim and rec
352 //
e47c4c2e 353 AliPID pid;
596a855f 354}
355
356//_____________________________________________________________________________
357AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
4b71572b 358 TSelector(),
2257f27e 359 fRunVertexFinder(rec.fRunVertexFinder),
a84e2607 360 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
e66fbafb 361 fRunMuonTracking(rec.fRunMuonTracking),
d3eabe96 362 fRunMFTTrackingMU(rec.fRunMFTTrackingMU),
d1683eef 363 fRunV0Finder(rec.fRunV0Finder),
364 fRunCascadeFinder(rec.fRunCascadeFinder),
1f9831ab 365 fRunMultFinder(rec.fRunMultFinder),
1d99986f 366 fStopOnError(rec.fStopOnError),
07472556 367 fStopOnMissingTriggerFile(rec.fStopOnMissingTriggerFile),
1d99986f 368 fWriteAlignmentData(rec.fWriteAlignmentData),
369 fWriteESDfriend(rec.fWriteESDfriend),
b647652d 370 fFillTriggerESD(rec.fFillTriggerESD),
1d99986f 371
7f68891d 372 fCleanESD(rec.fCleanESD),
a023d8d8 373 fV0DCAmax(rec.fV0DCAmax),
5e5c1aa9 374 fV0CsPmin(rec.fV0CsPmin),
7f68891d 375 fDmax(rec.fDmax),
376 fZmax(rec.fZmax),
377
1d99986f 378 fRunLocalReconstruction(rec.fRunLocalReconstruction),
e583c30d 379 fRunTracking(rec.fRunTracking),
380 fFillESD(rec.fFillESD),
e54c9180 381 fDeleteRecPoints(""),
382 fDeleteDigits(""),
7d566c20 383 fLoadCDB(rec.fLoadCDB),
48ce48d1 384 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
e583c30d 385 fGAliceFileName(rec.fGAliceFileName),
4b71572b 386 fRawInput(rec.fRawInput),
975320a0 387 fESDOutput(rec.fESDOutput),
81d57268 388 fProofOutputFileName(rec.fProofOutputFileName),
389 fProofOutputLocation(rec.fProofOutputLocation),
390 fProofOutputDataset(rec.fProofOutputDataset),
391 fProofOutputArchive(rec.fProofOutputArchive),
35042093 392 fEquipIdMap(rec.fEquipIdMap),
b26c3770 393 fFirstEvent(rec.fFirstEvent),
394 fLastEvent(rec.fLastEvent),
973388c2 395 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
fc01854a 396 fFractionFriends(rec.fFractionFriends),
b8cd5251 397 fOptions(),
6bae477a 398 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
399 fLoadAlignData(rec.fLoadAlignData),
2972d4eb 400 fUseHLTData(rec.fUseHLTData),
7e88424f 401 fRunInfo(NULL),
402 fEventInfo(),
522fdd91 403 fRunScalers(NULL),
52dd4a8c 404 fCTPTimeParams(NULL),
c7ff1a33 405 fCTPTimeAlign(NULL),
e583c30d 406
407 fRunLoader(NULL),
b649205a 408 fRawReader(NULL),
2972d4eb 409 fParentRawReader(NULL),
b8cd5251 410
4b71572b 411 fRecoParam(rec.fRecoParam),
7e88424f 412
58e8dc31 413 fSPDTrackleter(NULL),
414
f2a195c1 415 fDiamondProfileSPD(rec.fDiamondProfileSPD),
4b71572b 416 fDiamondProfile(rec.fDiamondProfile),
417 fDiamondProfileTPC(rec.fDiamondProfileTPC),
77ba28ba 418 fListOfCosmicTriggers(NULL),
f2a195c1 419
6b6e4472 420 fGRPData(NULL),
444753c6 421
6bae477a 422 fAlignObjArray(rec.fAlignObjArray),
ec92bee0 423 fCDBUri(rec.fCDBUri),
f1c1204d 424 fQARefUri(rec.fQARefUri),
7e963665 425 fSpecCDBUri(),
92258ce2 426 fCheckRecoCDBvsSimuCDB(),
795e4a22 427 fInitCDBCalled(rec.fInitCDBCalled),
989744a6 428 fCDBSnapshotMode(rec.fCDBSnapshotMode),
795e4a22 429 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
ce43afbe 430 fQADetectors(rec.fQADetectors),
431 fQATasks(rec.fQATasks),
aa3c69a9 432 fRunQA(rec.fRunQA),
433 fRunGlobalQA(rec.fRunGlobalQA),
e4a998ed 434 fSameQACycle(rec.fSameQACycle),
f1c1204d 435 fInitQACalled(rec.fInitQACalled),
75373542 436 fWriteQAExpertData(rec.fWriteQAExpertData),
21a3aa09 437 fRunPlaneEff(rec.fRunPlaneEff),
438
1d26da6d 439 fESDpid(NULL),
440
21a3aa09 441 fesd(NULL),
442 fhltesd(NULL),
443 fesdf(NULL),
444 ffile(NULL),
ee7c441c 445 ffileF(NULL),
21a3aa09 446 ftree(NULL),
ee7c441c 447 ftreeF(NULL),
21a3aa09 448 fhlttree(NULL),
21a3aa09 449 ftVertexer(NULL),
14dd053c 450 fIsNewRunLoader(rec.fIsNewRunLoader),
4b71572b 451 fRunAliEVE(kFALSE),
f00558b6 452 fChain(NULL),
453 fNall(0),
454 fNspecie(0),
455 fSspecie(0),
456 fNhighPt(0),
f9fc20b4 457 fShighPt(0),
5ee8b64f 458 //
459 fTreeBuffSize(rec.fTreeBuffSize),
460 fMemCountESD(0),
461 fMemCountESDF(0),
462 fMemCountESDHLT(0),
463 //
42457748 464 fUpgradeModule(""),
465 fAnalysisMacro(rec.fAnalysisMacro),
466 fAnalysis(0),
764daca3 467 fRecoHandler(0),
30b916f7 468 fDeclTriggerClasses(rec.fDeclTriggerClasses),
469 fStopped(kFALSE),
470 fMaxRSS(0),
471 fMaxVMEM(0)
596a855f 472{
473// copy constructor
474
ec92bee0 475 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
efd2085e 476 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
477 }
ac4a7581 478 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 479 fReconstructor[iDet] = NULL;
f9fc20b4 480 fUpgradeMask[iDet] = kFALSE;
b8cd5251 481 fLoader[iDet] = NULL;
482 fTracker[iDet] = NULL;
b1af1125 483 }
484
4e25ac79 485 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
b1af1125 486 fQACycles[iDet] = rec.fQACycles[iDet];
252f8aa8 487 fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
488 }
b1af1125 489
ec92bee0 490 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
491 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
492 }
3d84ad67 493
92258ce2 494 for (Int_t i = 0; i < rec.fCheckRecoCDBvsSimuCDB.GetEntriesFast(); i++) {
495 if (rec.fCheckRecoCDBvsSimuCDB[i]) fCheckRecoCDBvsSimuCDB.AddLast(rec.fCheckRecoCDBvsSimuCDB[i]->Clone());
496 }
497
3d84ad67 498 for (int i=2;i--;) for (int j=2;j--;) fBeamInt[i][j] = rec.fBeamInt[i][j];
499
596a855f 500}
501
502//_____________________________________________________________________________
503AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
504{
505// assignment operator
4b71572b 506// Used in PROOF mode
507// Be very careful while modifing it!
508// Simple rules to follow:
509// for persistent data members - use their assignment operators
510// for non-persistent ones - do nothing or take the default values from constructor
511// TSelector members should not be touched
512 if(&rec == this) return *this;
513
4b71572b 514 fRunVertexFinder = rec.fRunVertexFinder;
515 fRunVertexFinderTracks = rec.fRunVertexFinderTracks;
4b71572b 516 fRunMuonTracking = rec.fRunMuonTracking;
d3eabe96 517 fRunMFTTrackingMU = rec.fRunMFTTrackingMU;
4b71572b 518 fRunV0Finder = rec.fRunV0Finder;
519 fRunCascadeFinder = rec.fRunCascadeFinder;
1f9831ab 520 fRunMultFinder = rec.fRunMultFinder;
4b71572b 521 fStopOnError = rec.fStopOnError;
07472556 522 fStopOnMissingTriggerFile = rec.fStopOnMissingTriggerFile;
4b71572b 523 fWriteAlignmentData = rec.fWriteAlignmentData;
524 fWriteESDfriend = rec.fWriteESDfriend;
525 fFillTriggerESD = rec.fFillTriggerESD;
526
527 fCleanESD = rec.fCleanESD;
528 fV0DCAmax = rec.fV0DCAmax;
529 fV0CsPmin = rec.fV0CsPmin;
530 fDmax = rec.fDmax;
531 fZmax = rec.fZmax;
532
533 fRunLocalReconstruction = rec.fRunLocalReconstruction;
534 fRunTracking = rec.fRunTracking;
535 fFillESD = rec.fFillESD;
e54c9180 536 fDeleteRecPoints = rec.fDeleteRecPoints;
537 fDeleteDigits = rec.fDeleteDigits;
7d566c20 538 fLoadCDB = rec.fLoadCDB;
4b71572b 539 fUseTrackingErrorsForAlignment = rec.fUseTrackingErrorsForAlignment;
540 fGAliceFileName = rec.fGAliceFileName;
541 fRawInput = rec.fRawInput;
975320a0 542 fESDOutput = rec.fESDOutput;
81d57268 543 fProofOutputFileName = rec.fProofOutputFileName;
544 fProofOutputLocation = rec.fProofOutputLocation;
545 fProofOutputDataset = rec.fProofOutputDataset;
546 fProofOutputArchive = rec.fProofOutputArchive;
4b71572b 547 fEquipIdMap = rec.fEquipIdMap;
548 fFirstEvent = rec.fFirstEvent;
549 fLastEvent = rec.fLastEvent;
550 fNumberOfEventsPerFile = rec.fNumberOfEventsPerFile;
fc01854a 551 fFractionFriends = rec.fFractionFriends;
4b71572b 552
553 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
554 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
555 }
556
557 fLoadAlignFromCDB = rec.fLoadAlignFromCDB;
558 fLoadAlignData = rec.fLoadAlignData;
4b71572b 559 fUseHLTData = rec.fUseHLTData;
560
561 delete fRunInfo; fRunInfo = NULL;
562 if (rec.fRunInfo) fRunInfo = new AliRunInfo(*rec.fRunInfo);
563
564 fEventInfo = rec.fEventInfo;
565
522fdd91 566 delete fRunScalers; fRunScalers = NULL;
567 if (rec.fRunScalers) fRunScalers = new AliTriggerRunScalers(*rec.fRunScalers);
568
52dd4a8c 569 delete fCTPTimeParams; fCTPTimeParams = NULL;
570 if (rec.fCTPTimeParams) fCTPTimeParams = new AliCTPTimeParams(*rec.fCTPTimeParams);
c7ff1a33 571 delete fCTPTimeAlign; fCTPTimeAlign = NULL;
572 if (rec.fCTPTimeAlign) fCTPTimeAlign = new AliCTPTimeParams(*rec.fCTPTimeAlign);
52dd4a8c 573
4b71572b 574 fRunLoader = NULL;
575 fRawReader = NULL;
576 fParentRawReader = NULL;
577
578 fRecoParam = rec.fRecoParam;
579
ac4a7581 580 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
f9fc20b4 581 fUpgradeMask[iDet] = kFALSE;
4b71572b 582 delete fReconstructor[iDet]; fReconstructor[iDet] = NULL;
583 delete fLoader[iDet]; fLoader[iDet] = NULL;
584 delete fTracker[iDet]; fTracker[iDet] = NULL;
4b71572b 585 }
b1af1125 586
4e25ac79 587 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
b1af1125 588 fQACycles[iDet] = rec.fQACycles[iDet];
252f8aa8 589 fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
590 }
58e8dc31 591
592 delete fSPDTrackleter; fSPDTrackleter = NULL;
252f8aa8 593
f2a195c1 594 delete fDiamondProfileSPD; fDiamondProfileSPD = NULL;
595 if (rec.fDiamondProfileSPD) fDiamondProfileSPD = new AliESDVertex(*rec.fDiamondProfileSPD);
4b71572b 596 delete fDiamondProfile; fDiamondProfile = NULL;
597 if (rec.fDiamondProfile) fDiamondProfile = new AliESDVertex(*rec.fDiamondProfile);
598 delete fDiamondProfileTPC; fDiamondProfileTPC = NULL;
599 if (rec.fDiamondProfileTPC) fDiamondProfileTPC = new AliESDVertex(*rec.fDiamondProfileTPC);
4b71572b 600
77ba28ba 601 delete fListOfCosmicTriggers; fListOfCosmicTriggers = NULL;
602 if (rec.fListOfCosmicTriggers) fListOfCosmicTriggers = (THashTable*)((rec.fListOfCosmicTriggers)->Clone());
603
4b71572b 604 delete fGRPData; fGRPData = NULL;
44e45fac 605 // if (rec.fGRPData) fGRPData = (TMap*)((rec.fGRPData)->Clone());
606 if (rec.fGRPData) fGRPData = (AliGRPObject*)((rec.fGRPData)->Clone());
4b71572b 607
608 delete fAlignObjArray; fAlignObjArray = NULL;
609
610 fCDBUri = "";
f1c1204d 611 fQARefUri = rec.fQARefUri;
4b71572b 612 fSpecCDBUri.Delete();
92258ce2 613 fCheckRecoCDBvsSimuCDB.Delete();
614 //
615 for (Int_t i = 0; i < rec.fCheckRecoCDBvsSimuCDB.GetEntriesFast(); i++) {
616 if (rec.fCheckRecoCDBvsSimuCDB[i]) fCheckRecoCDBvsSimuCDB.AddLast(rec.fCheckRecoCDBvsSimuCDB[i]->Clone());
617 }
618 //
4b71572b 619 fInitCDBCalled = rec.fInitCDBCalled;
989744a6 620 fCDBSnapshotMode = rec.fCDBSnapshotMode;
4b71572b 621 fSetRunNumberFromDataCalled = rec.fSetRunNumberFromDataCalled;
622 fQADetectors = rec.fQADetectors;
4b71572b 623 fQATasks = rec.fQATasks;
624 fRunQA = rec.fRunQA;
625 fRunGlobalQA = rec.fRunGlobalQA;
4b71572b 626 fSameQACycle = rec.fSameQACycle;
f1c1204d 627 fInitQACalled = rec.fInitQACalled;
75373542 628 fWriteQAExpertData = rec.fWriteQAExpertData;
4b71572b 629 fRunPlaneEff = rec.fRunPlaneEff;
3d84ad67 630 for (int i=2;i--;) for (int j=2;j--;) fBeamInt[i][j] = rec.fBeamInt[i][j];
1d26da6d 631 fESDpid = NULL;
4b71572b 632 fesd = NULL;
633 fhltesd = NULL;
634 fesdf = NULL;
635 ffile = NULL;
ee7c441c 636 ffileF = NULL;
4b71572b 637 ftree = NULL;
ee7c441c 638 ftreeF = NULL;
4b71572b 639 fhlttree = NULL;
640 ftVertexer = NULL;
641 fIsNewRunLoader = rec.fIsNewRunLoader;
642 fRunAliEVE = kFALSE;
643 fChain = NULL;
f00558b6 644 fNall = 0;
645 fNspecie = 0;
646 fSspecie = 0;
647 fNhighPt = 0;
648 fShighPt = 0;
5ee8b64f 649 //
650 fTreeBuffSize = rec.fTreeBuffSize;
651 fMemCountESD = 0;
652 fMemCountESDF = 0;
653 fMemCountESDHLT = 0;
654 //
f9fc20b4 655 fUpgradeModule="";
42457748 656 fAnalysisMacro = rec.fAnalysisMacro;
657 fAnalysis = 0;
658 fRecoHandler = 0;
764daca3 659 fDeclTriggerClasses = rec.fDeclTriggerClasses;
596a855f 660
596a855f 661 return *this;
662}
663
664//_____________________________________________________________________________
665AliReconstruction::~AliReconstruction()
666{
667// clean up
668
e583c30d 669 CleanUp();
77ba28ba 670 if (fListOfCosmicTriggers) {
671 fListOfCosmicTriggers->Delete();
672 delete fListOfCosmicTriggers;
673 }
4f3c479a 674 delete fGRPData;
522fdd91 675 delete fRunScalers;
52dd4a8c 676 delete fCTPTimeParams;
c7ff1a33 677 delete fCTPTimeAlign;
efd2085e 678 fOptions.Delete();
4b71572b 679 if (fAlignObjArray) {
680 fAlignObjArray->Delete();
681 delete fAlignObjArray;
682 }
ec92bee0 683 fSpecCDBUri.Delete();
92258ce2 684 fCheckRecoCDBvsSimuCDB.Delete();
87932dab 685 AliCodeTimer::Instance()->Print();
596a855f 686}
687
f1c1204d 688//_____________________________________________________________________________
689void AliReconstruction::InitQA()
690{
691 //Initialize the QA and start of cycle
52dd4a8c 692 AliCodeTimerAuto("",0);
f1c1204d 693
694 if (fInitQACalled) return;
695 fInitQACalled = kTRUE;
696
92664bc8 697 if (fGRPData) AliQADataMaker::SetCloningRequest( fGRPData->GetQATrigClasses(), fGRPData->GetQACloningRequest());
698
699
634696f5 700 AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kRECMODE) ;
2ad98fc5 701 qam->SetSaveData(kTRUE);
702 qam->SetCycleLength(AliQAv1::kITS, 5) ;
75373542 703 if (fWriteQAExpertData)
eca4fa66 704 qam->SetWriteExpert() ;
75373542 705
eca4fa66 706 if (qam->IsDefaultStorageSet()) {
f1c1204d 707 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
708 AliWarning("Default QA reference storage has been already set !");
709 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fQARefUri.Data()));
710 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
eca4fa66 711 fQARefUri = qam->GetDefaultStorage()->GetURI();
f1c1204d 712 } else {
713 if (fQARefUri.Length() > 0) {
714 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
715 AliDebug(2, Form("Default QA reference storage is set to: %s", fQARefUri.Data()));
716 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
717 } else {
718 fQARefUri="local://$ALICE_ROOT/QAref";
719 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
720 AliWarning("Default QA refeference storage not yet set !!!!");
721 AliWarning(Form("Setting it now to: %s", fQARefUri.Data()));
722 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
723
724 }
eca4fa66 725 qam->SetDefaultStorage(fQARefUri);
f1c1204d 726 }
727
728 if (fRunQA) {
7b830a3f 729 qam->SetActiveDetectors(fQADetectors) ;
730 qam->SetActiveOnlineDetectors(fRunInfo->GetActiveDetectors());
731
4e25ac79 732 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) {
eca4fa66 733 qam->SetCycleLength(AliQAv1::DETECTORINDEX_t(det), fQACycles[det]) ;
734 qam->SetWriteExpert(AliQAv1::DETECTORINDEX_t(det)) ;
f1c1204d 735 }
514cb8c7 736 if (!fRawReader && !fInput && IsInTasks(AliQAv1::kRAWS))
4e25ac79 737 fQATasks.ReplaceAll(Form("%d",AliQAv1::kRAWS), "") ;
eca4fa66 738 qam->SetTasks(fQATasks) ;
739 qam->InitQADataMaker(AliCDBManager::Instance()->GetRun()) ;
f1c1204d 740 }
741 if (fRunGlobalQA) {
742 Bool_t sameCycle = kFALSE ;
eca4fa66 743 AliQADataMaker *qadm = qam->GetQADataMaker(AliQAv1::kGLOBAL);
f1c1204d 744 AliInfo(Form("Initializing the global QA data maker"));
514cb8c7 745 if (IsInTasks(AliQAv1::kRECPOINTS)) {
4e25ac79 746 qadm->StartOfCycle(AliQAv1::kRECPOINTS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
747 TObjArray **arr=qadm->Init(AliQAv1::kRECPOINTS);
f1c1204d 748 AliTracker::SetResidualsArray(arr);
749 sameCycle = kTRUE ;
750 }
514cb8c7 751 if (IsInTasks(AliQAv1::kESDS)) {
4e25ac79 752 qadm->StartOfCycle(AliQAv1::kESDS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
753 qadm->Init(AliQAv1::kESDS);
f1c1204d 754 }
f1c1204d 755 }
fc07289e 756 AliSysInfo::AddStamp("InitQA") ;
f1c1204d 757}
758
fc07289e 759//_____________________________________________________________________________
87da0921 760void AliReconstruction::MergeQA(const char *fileName)
fc07289e 761{
762 //Initialize the QA and start of cycle
52dd4a8c 763 AliCodeTimerAuto("",0) ;
eca4fa66 764 AliQAManager::QAManager()->Merge(AliCDBManager::Instance()->GetRun(),fileName) ;
fc07289e 765 AliSysInfo::AddStamp("MergeQA") ;
766}
767
024cf675 768//_____________________________________________________________________________
795e4a22 769void AliReconstruction::InitCDB()
024cf675 770{
771// activate a default CDB storage
772// First check if we have any CDB storage set, because it is used
773// to retrieve the calibration and alignment constants
52dd4a8c 774 AliCodeTimerAuto("",0);
024cf675 775
795e4a22 776 if (fInitCDBCalled) return;
777 fInitCDBCalled = kTRUE;
778
024cf675 779 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 780 if (man->IsDefaultStorageSet())
024cf675 781 {
782 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 783 AliWarning("Default CDB storage has been already set !");
784 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
024cf675 785 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 786 fCDBUri = man->GetDefaultStorage()->GetURI();
ec92bee0 787 }
788 else {
795e4a22 789 if (fCDBUri.Length() > 0)
790 {
791 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
792 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
793 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
52dd4a8c 794 man->SetDefaultStorage(fCDBUri);
795 }
796 else if (!man->GetRaw()){
797 fCDBUri="local://$ALICE_ROOT/OCDB";
795e4a22 798 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
799 AliWarning("Default CDB storage not yet set !!!!");
800 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
801 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
52dd4a8c 802 man->SetDefaultStorage(fCDBUri);
803 }
804 else {
805 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
806 AliWarning("Default storage will be set after setting the Run Number!!!");
807 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 808 }
ec92bee0 809 }
810
811 // Now activate the detector specific CDB storage locations
c3a7b59a 812 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
813 TObject* obj = fSpecCDBUri[i];
814 if (!obj) continue;
b8ec52f6 815 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
816 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
817 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 818 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 819 }
002c9d1b 820 AliSysInfo::AddStamp("InitCDB");
024cf675 821}
822
7c41d36a 823//_____________________________________________________________________________
824void AliReconstruction::SetCDBSnapshotMode(const char* snapshotFileName) {
989744a6 825 fCDBSnapshotMode = kTRUE;
7c41d36a 826 AliCDBManager::Instance()->SetSnapshotMode(snapshotFileName);
827}
828
024cf675 829//_____________________________________________________________________________
830void AliReconstruction::SetDefaultStorage(const char* uri) {
ec92bee0 831// Store the desired default CDB storage location
832// Activate it later within the Run() method
024cf675 833
ec92bee0 834 fCDBUri = uri;
024cf675 835
836}
837
f1c1204d 838//_____________________________________________________________________________
839void AliReconstruction::SetQARefDefaultStorage(const char* uri) {
840 // Store the desired default CDB storage location
841 // Activate it later within the Run() method
842
843 fQARefUri = uri;
4e25ac79 844 AliQAv1::SetQARefStorage(fQARefUri.Data()) ;
f1c1204d 845
846}
92258ce2 847
00aa02d5 848//_____________________________________________________________________________
c3a7b59a 849void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 850// Store a detector-specific CDB storage location
851// Activate it later within the Run() method
024cf675 852
c3a7b59a 853 AliCDBPath aPath(calibType);
854 if(!aPath.IsValid()){
855 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
ac4a7581 856 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
c3a7b59a 857 if(!strcmp(calibType, fgkDetectorName[iDet])) {
858 aPath.SetPath(Form("%s/*", calibType));
859 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
860 break;
861 }
862 }
863 if(!aPath.IsValid()){
864 AliError(Form("Not a valid path or detector: %s", calibType));
865 return;
866 }
867 }
868
53dd3c3d 869// // check that calibType refers to a "valid" detector name
870// Bool_t isDetector = kFALSE;
ac4a7581 871// for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
53dd3c3d 872// TString detName = fgkDetectorName[iDet];
873// if(aPath.GetLevel0() == detName) {
874// isDetector = kTRUE;
875// break;
876// }
877// }
878//
879// if(!isDetector) {
880// AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
881// return;
882// }
c3a7b59a 883
884 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
ec92bee0 885 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 886 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
024cf675 887
888}
889
92258ce2 890//_____________________________________________________________________________
891void AliReconstruction::AddCheckRecoCDBvsSimuCDB(const char* cdbpath,const char* comment)
892{
893 // require the cdb item to be the same in the rec as in the sim
894 // Activate it later within the Run() method
895 TString newent = cdbpath;
896 if (newent.IsNull()) return;
897 TIter nextit(&fCheckRecoCDBvsSimuCDB);
898 TNamed* cdbent=0;
899 while ((cdbent=(TNamed*)nextit())) {
900 TString str = cdbent->GetName();
901 if (str==newent) {
902 AliInfo(Form("%s is already in the list to check",cdbpath));
903 return;
904 }
905 }
906 fCheckRecoCDBvsSimuCDB.AddLast(new TNamed(cdbpath,comment));
907 //
908}
909
910//_____________________________________________________________________________
911void AliReconstruction::RemCheckRecoCDBvsSimuCDB(const char* cdbpath)
912{
913 // require the cdb item to be the same in the rec as in the sim
914 // Activate it later within the Run() method
915 TString newent = cdbpath;
916 if (newent.IsNull()) return;
917 TIter nextit(&fCheckRecoCDBvsSimuCDB);
918 TNamed* cdbent=0;
919 while ((cdbent=(TNamed*)nextit())) {
920 TString str = cdbent->GetName();
921 if (str==newent) {
922 AliInfo(Form("Removing %s from the list to check",cdbpath));
923 delete fCheckRecoCDBvsSimuCDB.Remove(cdbent);
924 fCheckRecoCDBvsSimuCDB.Compress();
925 return;
926 }
927 }
928 AliInfo(Form("%s is not in the list to check",cdbpath));
929 //
930}
931
6bae477a 932//_____________________________________________________________________________
795e4a22 933Bool_t AliReconstruction::SetRunNumberFromData()
6bae477a 934{
935 // The method is called in Run() in order
936 // to set a correct run number.
937 // In case of raw data reconstruction the
938 // run number is taken from the raw data header
939
795e4a22 940 if (fSetRunNumberFromDataCalled) return kTRUE;
941 fSetRunNumberFromDataCalled = kTRUE;
942
943 AliCDBManager* man = AliCDBManager::Instance();
4b71572b 944
945 if(fRawReader) {
946 if(fRawReader->NextEvent()) {
947 if(man->GetRun() > 0) {
21a3aa09 948 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
4b71572b 949 }
950 man->SetRun(fRawReader->GetRunNumber());
532fe099 951 GetEventInfo();
4b71572b 952 fRawReader->RewindEvents();
953 }
954 else {
955 if(man->GetRun() > 0) {
956 AliWarning("No raw-data events are found ! Using settings in AliCDBManager !");
957 }
958 else {
959 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
960 return kFALSE;
961 }
962 }
963 }
964 else {
965 AliRunLoader *rl = AliRunLoader::Open(fGAliceFileName.Data());
966 if (!rl) {
967 AliError(Form("No run loader found in file %s", fGAliceFileName.Data()));
6bae477a 968 return kFALSE;
969 }
ec92bee0 970 else {
4b71572b 971 rl->LoadHeader();
972 // read run number from gAlice
973 if(rl->GetHeader()) {
974 man->SetRun(rl->GetHeader()->GetRun());
975 rl->UnloadHeader();
976 delete rl;
ec92bee0 977 }
978 else {
4b71572b 979 AliError("Neither run-loader header nor RawReader objects are found !");
980 delete rl;
ec92bee0 981 return kFALSE;
982 }
4b71572b 983 }
6bae477a 984 }
795e4a22 985
986 man->Print();
987
6bae477a 988 return kTRUE;
989}
990
795e4a22 991//_____________________________________________________________________________
992void AliReconstruction::SetCDBLock() {
993 // Set CDB lock: from now on it is forbidden to reset the run number
994 // or the default storage or to activate any further storage!
995
996 AliCDBManager::Instance()->SetLock(1);
997}
998
f9fc20b4 999//_____________________________________________________________________________
1000void AliReconstruction::MatchUpgradeDetector() {
1001 // Translates detector name in a boolean.
1002 // The boolean is used in GetReconstructor to load the
1003 // upgrade reconstructor instead of the standard one.
1004 for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
1005 if(fUpgradeModule.Contains(fgkDetectorName[iDet])) fUpgradeMask[iDet]=kTRUE;
1006 }
1007}
6bae477a 1008//_____________________________________________________________________________
1009Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
1010{
1011 // Read the alignment objects from CDB.
1012 // Each detector is supposed to have the
1013 // alignment objects in DET/Align/Data CDB path.
1014 // All the detector objects are then collected,
1015 // sorted by geometry level (starting from ALIC) and
1016 // then applied to the TGeo geometry.
1017 // Finally an overlaps check is performed.
1018
1019 // Load alignment data from CDB and fill fAlignObjArray
1020 if(fLoadAlignFromCDB){
6bae477a 1021
25be1e5c 1022 TString detStr = detectors;
1023 TString loadAlObjsListOfDets = "";
1024
ac4a7581 1025 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
8cb26cdf 1026 if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
f12d42ce 1027 if(!strcmp(fgkDetectorName[iDet],"HLT")) continue;
4fbb8e9d 1028
1029 if(AliGeomManager::GetNalignable(fgkDetectorName[iDet]) != 0)
8cb26cdf 1030 {
1031 loadAlObjsListOfDets += fgkDetectorName[iDet];
1032 loadAlObjsListOfDets += " ";
1033 }
25be1e5c 1034 } // end loop over detectors
4fbb8e9d 1035
1036 if(AliGeomManager::GetNalignable("GRP") != 0)
8cb26cdf 1037 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
98e303d9 1038 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
25be1e5c 1039 }else{
1040 // Check if the array with alignment objects was
1041 // provided by the user. If yes, apply the objects
1042 // to the present TGeo geometry
1043 if (fAlignObjArray) {
1044 if (gGeoManager && gGeoManager->IsClosed()) {
98e303d9 1045 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
25be1e5c 1046 AliError("The misalignment of one or more volumes failed!"
1047 "Compare the list of simulated detectors and the list of detector alignment data!");
1048 return kFALSE;
1049 }
1050 }
1051 else {
1052 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
6bae477a 1053 return kFALSE;
1054 }
1055 }
6bae477a 1056 }
25be1e5c 1057
4b71572b 1058 if (fAlignObjArray) {
1059 fAlignObjArray->Delete();
1060 delete fAlignObjArray; fAlignObjArray=NULL;
1061 }
a03b0371 1062
6bae477a 1063 return kTRUE;
1064}
596a855f 1065
1066//_____________________________________________________________________________
1067void AliReconstruction::SetGAliceFile(const char* fileName)
1068{
1069// set the name of the galice file
1070
1071 fGAliceFileName = fileName;
1072}
1073
21a3aa09 1074//_____________________________________________________________________________
b58710ef 1075void AliReconstruction::SetInput(const char* input)
21a3aa09 1076{
b58710ef 1077 // In case the input string starts with 'mem://', we run in an online mode
1078 // and AliRawReaderDateOnline object is created. In all other cases a raw-data
1079 // file is assumed. One can give as an input:
1080 // mem://: - events taken from DAQ monitoring libs online
1081 // or
1082 // mem://<filename> - emulation of the above mode (via DATE monitoring libs)
4b71572b 1083 if (input) fRawInput = input;
21a3aa09 1084}
1085
975320a0 1086//_____________________________________________________________________________
1087void AliReconstruction::SetOutput(const char* output)
1088{
1089 // Set the output ESD filename
1090 // 'output' is a normalt ROOT url
1091 // The method is used in case of raw-data reco with PROOF
81d57268 1092 if (output) fESDOutput = output;
975320a0 1093}
1094
efd2085e 1095//_____________________________________________________________________________
1096void AliReconstruction::SetOption(const char* detector, const char* option)
1097{
1098// set options for the reconstruction of a detector
1099
1100 TObject* obj = fOptions.FindObject(detector);
1101 if (obj) fOptions.Remove(obj);
1102 fOptions.Add(new TNamed(detector, option));
1103}
1104
7e88424f 1105//_____________________________________________________________________________
1106void AliReconstruction::SetRecoParam(const char* detector, AliDetectorRecoParam *par)
1107{
1108 // Set custom reconstruction parameters for a given detector
1109 // Single set of parameters for all the events
a00021a7 1110
1111 // First check if the reco-params are global
1112 if(!strcmp(detector, "GRP")) {
1113 par->SetAsDefault();
ac4a7581 1114 fRecoParam.AddDetRecoParam(kNDetectors,par);
a00021a7 1115 return;
1116 }
1117
ac4a7581 1118 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
7e88424f 1119 if(!strcmp(detector, fgkDetectorName[iDet])) {
1120 par->SetAsDefault();
1121 fRecoParam.AddDetRecoParam(iDet,par);
1122 break;
1123 }
1124 }
1125
1126}
1127
61807e09 1128//_____________________________________________________________________________
61807e09 1129Bool_t AliReconstruction::InitGRP() {
1130 //------------------------------------
1131 // Initialization of the GRP entry
1132 //------------------------------------
1133 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
1134
4b71572b 1135 if (entry) {
44e45fac 1136
1137 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
1138
1139 if (m) {
1140 AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
1141 m->Print();
1142 fGRPData = new AliGRPObject();
1143 fGRPData->ReadValuesFromMap(m);
1144 }
1145
1146 else {
1147 AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it");
1148 fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
1149 entry->SetOwner(0);
1150 }
1151
f168abba 1152 // FIX ME: The unloading of GRP entry is temporarily disabled
1153 // because ZDC and VZERO are using it in order to initialize
1154 // their reconstructor objects. In the future one has to think
1155 // of propagating AliRunInfo to the reconstructors.
1156 // AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
4b71572b 1157 }
61807e09 1158
1159 if (!fGRPData) {
1160 AliError("No GRP entry found in OCDB!");
1161 return kFALSE;
1162 }
1163
44e45fac 1164 TString lhcState = fGRPData->GetLHCState();
1165 if (lhcState==AliGRPObject::GetInvalidString()) {
7e88424f 1166 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
44e45fac 1167 lhcState = "UNKNOWN";
7e88424f 1168 }
1169
44e45fac 1170 TString beamType = fGRPData->GetBeamType();
1171 if (beamType==AliGRPObject::GetInvalidString()) {
7e88424f 1172 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
44e45fac 1173 beamType = "UNKNOWN";
7e88424f 1174 }
1175
44e45fac 1176 Float_t beamEnergy = fGRPData->GetBeamEnergy();
1177 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
7e88424f 1178 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
44e45fac 1179 beamEnergy = 0;
7e88424f 1180 }
1181
44e45fac 1182 TString runType = fGRPData->GetRunType();
1183 if (runType==AliGRPObject::GetInvalidString()) {
7e88424f 1184 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
44e45fac 1185 runType = "UNKNOWN";
7e88424f 1186 }
1187
44e45fac 1188 Int_t activeDetectors = fGRPData->GetDetectorMask();
a5dede5c 1189 if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
7e88424f 1190 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
44e45fac 1191 activeDetectors = 1074790399;
7e88424f 1192 }
820b4d9e 1193 AliDebug(1, Form("activeDetectors = %d", activeDetectors));
7e88424f 1194
44e45fac 1195 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
44e45fac 1196 fRunInfo->Dump();
1197
7e88424f 1198
1199 // Process the list of active detectors
44e45fac 1200 if (activeDetectors) {
1201 UInt_t detMask = activeDetectors;
820b4d9e 1202 AliDebug(1, Form("Detector List = %s", fRunLocalReconstruction.Data()));
7a317bef 1203 fRunLocalReconstruction = MatchDetectorList(fRunLocalReconstruction,detMask);
820b4d9e 1204 AliDebug(1, Form("Detector List = %s", fRunLocalReconstruction.Data()));
7a317bef 1205 fRunTracking = MatchDetectorList(fRunTracking,detMask);
1206 fFillESD = MatchDetectorList(fFillESD,detMask);
1207 fQADetectors = MatchDetectorList(fQADetectors,detMask);
7b830a3f 1208 AliInfo(Form("fQADetectors=%s",fQADetectors.Data()));
e54c9180 1209 fDeleteRecPoints = MatchDetectorList(fDeleteRecPoints,detMask);
1210 fDeleteDigits = MatchDetectorList(fDeleteDigits,detMask);
7d566c20 1211 fLoadCDB.Form("%s %s %s %s",
1212 fRunLocalReconstruction.Data(),
1213 fRunTracking.Data(),
1214 fFillESD.Data(),
1215 fQADetectors.Data());
7d566c20 1216 fLoadCDB = MatchDetectorList(fLoadCDB,detMask);
d0f84c42 1217 if (!((detMask >> AliDAQ::DetectorID("ITSSPD")) & 0x1) &&
1218 !((detMask >> AliDAQ::DetectorID("ITSSDD")) & 0x1) &&
1219 !((detMask >> AliDAQ::DetectorID("ITSSSD")) & 0x1) ) {
91e2f025 1220 // switch off the vertexer
1f9831ab 1221 AliInfo("SPD,SDD,SSD is not in the list of active detectors. Vertexer and Trackleter are switched off.");
91e2f025 1222 fRunVertexFinder = kFALSE;
1f9831ab 1223 fRunMultFinder = kFALSE;
91e2f025 1224 }
304d7f0b 1225 if (!((detMask >> AliDAQ::DetectorID("TRG")) & 0x1)) {
1226 // switch off the reading of CTP raw-data payload
1227 if (fFillTriggerESD) {
1228 AliInfo("CTP is not in the list of active detectors. CTP data reading switched off.");
1229 fFillTriggerESD = kFALSE;
1230 }
1231 }
7e88424f 1232 }
1233
1234 AliInfo("===================================================================================");
1235 AliInfo(Form("Running local reconstruction for detectors: %s",fRunLocalReconstruction.Data()));
1236 AliInfo(Form("Running tracking for detectors: %s",fRunTracking.Data()));
1237 AliInfo(Form("Filling ESD for detectors: %s",fFillESD.Data()));
ca13fb87 1238 AliInfo(Form("Quality assurance is active for detectors: %s",fQADetectors.Data()));
7d566c20 1239 AliInfo(Form("CDB and reconstruction parameters are loaded for detectors: %s",fLoadCDB.Data()));
7e88424f 1240 AliInfo("===================================================================================");
61807e09 1241
1242 //*** Dealing with the magnetic field map
5a004fb4 1243 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
1244 if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
1245 AliInfo("ExpertMode!!! GRP information will be ignored !");
1246 AliInfo("ExpertMode!!! Running with the externally locked B field !");
1247 }
1248 else {
1249 AliInfo("Destroying existing B field instance!");
1250 delete TGeoGlobalMagField::Instance();
1251 }
1252 }
1253 if ( !TGeoGlobalMagField::Instance()->IsLocked() ) {
61807e09 1254 // Construct the field map out of the information retrieved from GRP.
856024f0 1255 Bool_t ok = kTRUE;
61807e09 1256 // L3
44e45fac 1257 Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
1258 if (l3Current == AliGRPObject::GetInvalidFloat()) {
1259 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
1260 ok = kFALSE;
1261 }
f7a1cc68 1262
44e45fac 1263 Char_t l3Polarity = fGRPData->GetL3Polarity();
1264 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
1265 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
1266 ok = kFALSE;
1267 }
1268
1269 // Dipole
1270 Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
1271 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
1272 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
1273 ok = kFALSE;
1274 }
1275
1276 Char_t diPolarity = fGRPData->GetDipolePolarity();
1277 if (diPolarity == AliGRPObject::GetInvalidChar()) {
1278 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
1279 ok = kFALSE;
1280 }
1281
99c7d495 1282 // read special bits for the polarity convention and map type
1283 Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
1284 Bool_t uniformB = fGRPData->IsUniformBMap();
61807e09 1285
856024f0 1286 if (ok) {
33fe5eb1 1287 AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
1288 TMath::Abs(diCurrent) * (diPolarity ? -1:1),
1289 polConvention,uniformB,beamEnergy, beamType.Data());
1290 if (fld) {
1291 TGeoGlobalMagField::Instance()->SetField( fld );
1292 TGeoGlobalMagField::Instance()->Lock();
1293 AliInfo("Running with the B field constructed out of GRP !");
1294 }
1295 else AliFatal("Failed to create a B field map !");
856024f0 1296 }
f7a1cc68 1297 else AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
61807e09 1298 }
f7a1cc68 1299
f2a195c1 1300 //*** Get the diamond profiles from OCDB
1301 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD");
1302 if (entry) {
1303 fDiamondProfileSPD = dynamic_cast<AliESDVertex*> (entry->GetObject());
1304 } else {
1305 AliError("No SPD diamond profile found in OCDB!");
1306 }
1307
61807e09 1308 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
1309 if (entry) {
f2a195c1 1310 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
61807e09 1311 } else {
1312 AliError("No diamond profile found in OCDB!");
1313 }
1314
1315 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexTPC");
1316 if (entry) {
f2a195c1 1317 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
61807e09 1318 } else {
f2a195c1 1319 AliError("No TPC diamond profile found in OCDB!");
61807e09 1320 }
1321
77ba28ba 1322 entry = AliCDBManager::Instance()->Get("GRP/Calib/CosmicTriggers");
1323 if (entry) {
1324 fListOfCosmicTriggers = dynamic_cast<THashTable*>(entry->GetObject());
1325 entry->SetOwner(0);
77ba28ba 1326 }
1327
1328 if (!fListOfCosmicTriggers) {
1329 AliWarning("Can not get list of cosmic triggers from OCDB! Cosmic event specie will be effectively disabled!");
1330 }
1331
61807e09 1332 return kTRUE;
1333}
1334
4b71572b 1335//_____________________________________________________________________________
1336Bool_t AliReconstruction::LoadCDB()
1337{
0a035be5 1338 // Load CDB entries for all active detectors.
1339 // By default we load all the entries in <det>/Calib
1340 // folder.
1341
52dd4a8c 1342 AliCodeTimerAuto("",0);
4b71572b 1343
1344 AliCDBManager::Instance()->Get("GRP/CTP/Config");
1345
30d5d647 1346 AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
1347
7d566c20 1348 TString detStr = fLoadCDB;
ac4a7581 1349 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4b71572b 1350 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1351 AliCDBManager::Instance()->GetAll(Form("%s/Calib/*",fgkDetectorName[iDet]));
b6af2cb6 1352 AliCDBManager::Instance()->GetAll(Form("%s/Trigger/*",fgkDetectorName[iDet]));
4b71572b 1353 }
e122592f 1354
1355 // Temporary fix - one has to define the correct policy in order
1356 // to load the trigger OCDB entries only for the detectors that
1357 // in the trigger or that are needed in order to put correct
1358 // information in ESD
1359 AliCDBManager::Instance()->GetAll("TRIGGER/*/*");
e6608c2e 1360 AliCDBManager::Instance()->GetAll("HLT/*/*");
e122592f 1361
4b71572b 1362 return kTRUE;
1363}
522fdd91 1364//_____________________________________________________________________________
1365Bool_t AliReconstruction::LoadTriggerScalersCDB()
1366{
0a035be5 1367 // Load CTP scalers from OCDB.
1368 // The scalers are checked for consistency.
1369
52dd4a8c 1370 AliCodeTimerAuto("",0);
522fdd91 1371
1372 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/Scalers");
4b71572b 1373
522fdd91 1374 if (entry) {
1375
1376 AliInfo("Found an AliTriggerRunScalers in GRP/CTP/Scalers, reading it");
1377 fRunScalers = dynamic_cast<AliTriggerRunScalers*> (entry->GetObject());
1378 entry->SetOwner(0);
c7a22819 1379 if (fRunScalers && (fRunScalers->CorrectScalersOverflow() == 0)) AliInfo("32bit Trigger counters corrected for overflow");
82ebedd6 1380
522fdd91 1381 }
1382 return kTRUE;
1383}
596a855f 1384//_____________________________________________________________________________
52dd4a8c 1385Bool_t AliReconstruction::LoadCTPTimeParamsCDB()
1386{
0a035be5 1387 // Load CTP timing information (alignment)
1388 // from OCDB.
1389
52dd4a8c 1390 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
c7ff1a33 1391 if (!entry) return kFALSE;
52dd4a8c 1392
c7ff1a33 1393 AliInfo("Found an AliCTPTimeParams in GRP/CTP/CTPtiming, reading it");
1394 fCTPTimeParams = dynamic_cast<AliCTPTimeParams*> (entry->GetObject());
1395 entry->SetOwner(0);
52dd4a8c 1396
c7ff1a33 1397 AliCDBEntry* entry2 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
1398 if (!entry2) return kFALSE;
1399
1400 AliInfo("Found an AliCTPTimeParams in GRP/CTP/TimeAlign, reading it");
028be258 1401 fCTPTimeAlign = dynamic_cast<AliCTPTimeParams*> (entry2->GetObject());
1402 entry2->SetOwner(0);
c7ff1a33 1403
1404 return kTRUE;
52dd4a8c 1405}
3d84ad67 1406
1407//_____________________________________________________________________________
1408Bool_t AliReconstruction::ReadIntensityInfoCDB()
1409{
1410 // Load LHC DIP data
2af04ffd 1411 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/LHCData");
1412 AliCDBEntry* entryCTP = AliCDBManager::Instance()->Get("GRP/CTP/Config");
1413 //
bc5c8516 1414 if (!entry || !entryCTP) {
1415 AliError(Form("Failed to extract CDB objects GRP/GRP/LHCData: %p or GRP/CTP/Config: %p",entry,entryCTP));
1416 return kFALSE;
1417 }
2af04ffd 1418 // extract BC masks
1419 enum {kA,kB,kC,kE,kNMasks};
1420 AliTriggerConfiguration* conf = (AliTriggerConfiguration*)entryCTP->GetObject();
1421 const TObjArray& clArr = conf->GetClasses();
1422 TObjArray masks(kNMasks);
1423 TIter next(&clArr);
1424 AliTriggerClass* trClass = 0;
1425 int nFound = 0;
1426 masks.SetOwner(kFALSE);
1427 //
1428 while ( (trClass=(AliTriggerClass*)next()) ) {
1429 TString trName = trClass->GetName();
1430 int ind = trName.Index("-"); // prefix in front of A,B,C,E
1431 if (ind<1) continue; // anomaly
1432 //
1433 trName = trName.Data() + ind;
1434 AliTriggerBCMask* bcMask = trClass->GetBCMask();
1435 if (!bcMask) continue;
1436 UInt_t which = 0;
1437 if (trName.BeginsWith("-A-")) which |= 0x1<<kA;
1438 else if (trName.BeginsWith("-B-")) which |= 0x1<<kB;
1439 else if (trName.BeginsWith("-C-")) which |= 0x1<<kC;
1440 else if (trName.BeginsWith("-E-")) which |= 0x1<<kE;
1441 else if (trName.BeginsWith("-AC-")) which |= (0x1<<kA) | (0x1<<kC);
1442 else if (trName.BeginsWith("-CA-")) which |= (0x1<<kA) | (0x1<<kC);
1443 else { AliWarning(Form("Unknown trigger type %s\n",trClass->GetName())); continue;}
1444 //
1445 for (int ip=kNMasks;ip--;) {
1446 if ( !(which&(0x1<<ip)) || masks[ip] ) continue; // does not match or already done
1447 masks[ip] = (TObject*)bcMask;
1448 nFound++;
1449 }
1450 if (nFound==kNMasks) break;
1451 }
1452 //
1453 AliInfo("Reading mean bunch intensities from GRP/GRP/LHCData");
1454 AliLHCData* dipData = dynamic_cast<AliLHCData*> (entry->GetObject());
1455 //
1456 for (int ib=2;ib--;) {
1457 double intI,intNI;
1458 if (dipData && (dipData->GetMeanIntensity(ib,intI,intNI,&masks)>=0)) {
1459 fBeamInt[ib][0] = intI;
1460 fBeamInt[ib][1] = intNI;
1461 AliInfo(Form("Mean intensity for beam %d: Interacting:%.2e Non-Interacting:%.2e",ib,intI,intNI));
3d84ad67 1462 }
3d84ad67 1463 }
2af04ffd 1464 return kTRUE;
1465 //
3d84ad67 1466}
1467
1468
52dd4a8c 1469//_____________________________________________________________________________
21a3aa09 1470Bool_t AliReconstruction::Run(const char* input)
596a855f 1471{
21a3aa09 1472 // Run Run Run
52dd4a8c 1473 AliCodeTimerAuto("",0);
596a855f 1474
4b71572b 1475 InitRun(input);
1476 if (GetAbort() != TSelector::kContinue) return kFALSE;
1477
1478 TChain *chain = NULL;
1479 if (fRawReader && (chain = fRawReader->GetChain())) {
2a284cef 1480 Long64_t nEntries = (fLastEvent < 0) ? (TChain::kBigNumber) : (fLastEvent - fFirstEvent + 1);
4b71572b 1481 // Proof mode
1482 if (gProof) {
52dd4a8c 1483 // Temporary fix for long raw-data runs (until socket timeout handling in PROOF is revised)
1484 gProof->Exec("gEnv->SetValue(\"Proof.SocketActivityTimeout\",-1)", kTRUE);
6c6f2624 1485
1486 if (gGrid)
1487 gProof->Exec("TGrid::Connect(\"alien://\")",kTRUE);
1488
1489 TMessage::EnableSchemaEvolutionForAll(kTRUE);
1490 gProof->Exec("TMessage::EnableSchemaEvolutionForAll(kTRUE)",kTRUE);
1491
4b71572b 1492 gProof->AddInput(this);
81d57268 1493
1494 if (!ParseOutput()) return kFALSE;
1495
975320a0 1496 gProof->SetParameter("PROOF_MaxSlavesPerNode", 9999);
4b71572b 1497 chain->SetProof();
2a284cef 1498 chain->Process("AliReconstruction","",nEntries,fFirstEvent);
4b71572b 1499 }
1500 else {
2a284cef 1501 chain->Process(this,"",nEntries,fFirstEvent);
4b71572b 1502 }
1503 }
1504 else {
1505 Begin(NULL);
1506 if (GetAbort() != TSelector::kContinue) return kFALSE;
1507 SlaveBegin(NULL);
1508 if (GetAbort() != TSelector::kContinue) return kFALSE;
1509 //******* The loop over events
44e45fac 1510 AliInfo("Starting looping over events");
4b71572b 1511 Int_t iEvent = 0;
1512 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
1513 (fRawReader && fRawReader->NextEvent())) {
30b916f7 1514 //
1515 // check if process has enough resources
1516 if (!HasEnoughResources(iEvent)) break;
4b71572b 1517 if (!ProcessEvent(iEvent)) {
930e6e3e 1518 Abort("ProcessEvent",TSelector::kAbortFile);
1519 return kFALSE;
4b71572b 1520 }
7e0cf530 1521 CleanProcessedEvent();
4b71572b 1522 iEvent++;
1523 }
b9a3ce3d 1524 if (!iEvent) AliWarning("No events passed trigger selection");
4b71572b 1525 SlaveTerminate();
1526 if (GetAbort() != TSelector::kContinue) return kFALSE;
1527 Terminate();
1528 if (GetAbort() != TSelector::kContinue) return kFALSE;
21a3aa09 1529 }
21a3aa09 1530
1531 return kTRUE;
1532}
1533
1534//_____________________________________________________________________________
4b71572b 1535void AliReconstruction::InitRawReader(const char* input)
21a3aa09 1536{
4b71572b 1537 // Init raw-reader and
21a3aa09 1538 // set the input in case of raw data
0a035be5 1539
1540 AliCodeTimerAuto("",0);
1541
4b71572b 1542 if (input) fRawInput = input;
1543 fRawReader = AliRawReader::Create(fRawInput.Data());
c35f192e 1544 if (!fRawReader) {
1545 if (fRawInput.IsNull()) {
1546 AliInfo("Reconstruction will run over digits");
1547 }
1548 else {
1549 AliFatal("Can not create raw-data reader ! Exiting...");
1550 }
1551 }
e0027792 1552
35042093 1553 if (!fEquipIdMap.IsNull() && fRawReader)
1554 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1555
cd0b062e 1556 if (!fUseHLTData.IsNull()) {
1557 // create the RawReaderHLT which performs redirection of HLT input data for
1558 // the specified detectors
1559 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
1560 if (pRawReader) {
1561 fParentRawReader=fRawReader;
1562 fRawReader=pRawReader;
1563 } else {
1564 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
1565 }
1566 }
4b71572b 1567 AliSysInfo::AddStamp("CreateRawReader");
1568}
cd0b062e 1569
4b71572b 1570//_____________________________________________________________________________
1571void AliReconstruction::InitRun(const char* input)
1572{
1573 // Initialization of raw-reader,
1574 // run number, CDB etc.
52dd4a8c 1575 AliCodeTimerAuto("",0);
4b71572b 1576 AliSysInfo::AddStamp("Start");
1577
002c9d1b 1578 // Initialize raw-reader if any
4b71572b 1579 InitRawReader(input);
596a855f 1580
ec92bee0 1581 // Initialize the CDB storage
795e4a22 1582 InitCDB();
ec92bee0 1583
6bae477a 1584 // Set run number in CDBManager (if it is not already set by the user)
4b71572b 1585 if (!SetRunNumberFromData()) {
1586 Abort("SetRunNumberFromData", TSelector::kAbortProcess);
1587 return;
1588 }
002c9d1b 1589
795e4a22 1590 // Set CDB lock: from now on it is forbidden to reset the run number
1591 // or the default storage or to activate any further storage!
1592 SetCDBLock();
1593
002c9d1b 1594}
1595
1596//_____________________________________________________________________________
1597void AliReconstruction::Begin(TTree *)
1598{
1599 // Initialize AlReconstruction before
1600 // going into the event loop
1601 // Should follow the TSelector convention
1602 // i.e. initialize only the object on the client side
52dd4a8c 1603 AliCodeTimerAuto("",0);
db4aeca1 1604
b4fef0d2 1605 AliReconstruction *reco = NULL;
002c9d1b 1606 if (fInput) {
8fb1f1dc 1607 if ((reco = (AliReconstruction*)fInput->FindObject("AliReconstruction"))) {
002c9d1b 1608 *this = *reco;
002c9d1b 1609 }
1610 AliSysInfo::AddStamp("ReadInputInBegin");
1611 }
1612
6bae477a 1613 // Import ideal TGeo geometry and apply misalignment
49caaca8 1614 if (!AliGeomManager::GetGeometry()) {
6bae477a 1615 TString geom(gSystem->DirName(fGAliceFileName));
1616 geom += "/geometry.root";
98e303d9 1617 AliGeomManager::LoadGeometry(geom.Data());
4b71572b 1618 if (!gGeoManager) {
1619 Abort("LoadGeometry", TSelector::kAbortProcess);
1620 return;
1621 }
281270d3 1622 AliSysInfo::AddStamp("LoadGeom");
ff5970a3 1623 TString detsToCheck=fRunLocalReconstruction;
4b71572b 1624 if(!AliGeomManager::CheckSymNamesLUT(detsToCheck.Data())) {
1625 Abort("CheckSymNamesLUT", TSelector::kAbortProcess);
1626 return;
1627 }
281270d3 1628 AliSysInfo::AddStamp("CheckGeom");
6bae477a 1629 }
8e245d15 1630
7ec0d3df 1631 Bool_t toCDBSnapshot=kFALSE;
1632 TString snapshotFileOut(""); // we could use fSnapshotFileName if we are not interested
1633 // in reading from and writing to a snapshot file at the same time
f3664c51 1634 if(TString(getenv("OCDB_SNAPSHOT_CREATE")) == TString("kTRUE")){
7ec0d3df 1635 toCDBSnapshot=kTRUE;
1636 //fFromCDBSnapshot=kFALSE;
f3664c51 1637 TString snapshotFile(getenv("OCDB_SNAPSHOT_FILENAME"));
7ec0d3df 1638 if(!(snapshotFile.IsNull() || snapshotFile.IsWhitespace()))
1639 snapshotFileOut = snapshotFile;
1640 else
1641 snapshotFileOut="OCDB.root";
1642 }
647d2bb8 1643
4b71572b 1644 if (!MisalignGeometry(fLoadAlignData)) {
1645 Abort("MisalignGeometry", TSelector::kAbortProcess);
1646 return;
1647 }
e9ce6cb7 1648
1649 const TMap* cdbCache = AliCDBManager::Instance()->GetEntryCache();
e945e641 1650 if(!toCDBSnapshot) {
1651 if(cdbCache->Contains("GRP/Geometry/Data"))
1652 AliCDBManager::Instance()->UnloadFromCache("GRP/Geometry/Data");
1653 AliCDBManager::Instance()->UnloadFromCache("*/Align/*");
1654 }
281270d3 1655 AliSysInfo::AddStamp("MisalignGeom");
6bae477a 1656
8cb26cdf 1657 if (!InitGRP()) {
1658 Abort("InitGRP", TSelector::kAbortProcess);
1659 return;
1660 }
1661 AliSysInfo::AddStamp("InitGRP");
e9ce6cb7 1662 if(!toCDBSnapshot)
1663 if(cdbCache->Contains("GRP/Calib/CosmicTriggers"))
1664 AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
8cb26cdf 1665
989744a6 1666 if(!fCDBSnapshotMode || toCDBSnapshot){
647d2bb8 1667 if (!LoadCDB()) {
1668 Abort("LoadCDB", TSelector::kAbortProcess);
1669 return;
1670 }
989744a6 1671 AliSysInfo::AddStamp("LoadCDB");
4b71572b 1672 }
325aa76f 1673
a6dd87ad 1674 if (!LoadTriggerScalersCDB()) {
1675 Abort("LoadTriggerScalersCDB", TSelector::kAbortProcess);
1676 return;
1677 }
1678 AliSysInfo::AddStamp("LoadTriggerScalersCDB");
1679
52dd4a8c 1680 if (!LoadCTPTimeParamsCDB()) {
1681 Abort("LoadCTPTimeParamsCDB", TSelector::kAbortProcess);
1682 return;
1683 }
1684 AliSysInfo::AddStamp("LoadCTPTimeParamsCDB");
a6dd87ad 1685
bd26f597 1686 if (!ReadIntensityInfoCDB()) {
1687 Abort("ReadIntensityInfoCDB", TSelector::kAbortProcess);
1688 return;
1689 }
1690 AliSysInfo::AddStamp("ReadIntensityInfoCDB");
1691
7e88424f 1692 // Read the reconstruction parameters from OCDB
1693 if (!InitRecoParams()) {
002c9d1b 1694 AliWarning("Not all detectors have correct RecoParam objects initialized");
4b71572b 1695 }
1696 AliSysInfo::AddStamp("InitRecoParams");
1697
e0a6e696 1698 if(toCDBSnapshot)
989744a6 1699 {
c022b397 1700 AliCDBManager::Instance()->DumpToSnapshotFile(snapshotFileOut.Data(),kFALSE);
e973a743 1701 exit(0);
989744a6 1702 }
7ec0d3df 1703
fd2b273c 1704 if (fInput && gProof) {
b4fef0d2 1705 if (reco) *reco = *this;
fd2b273c 1706
45a6dee6 1707 gGeoManager->SetName("Geometry");
fd2b273c 1708 gProof->AddInputData(gGeoManager,kTRUE);
002c9d1b 1709 gGeoManager = NULL;
fd2b273c 1710 gProof->AddInputData(const_cast<TMap*>(AliCDBManager::Instance()->GetEntryCache()),kTRUE);
002c9d1b 1711 fInput->Add(new TParameter<Int_t>("RunNumber",AliCDBManager::Instance()->GetRun()));
f7a1cc68 1712 AliMagF *magFieldMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
ead7b391 1713 magFieldMap->SetName("MagneticFieldMap");
fd2b273c 1714 gProof->AddInputData(magFieldMap,kTRUE);
42457748 1715 if (fAnalysis) {
1716 fAnalysis->SetName("Analysis");
1717 gProof->AddInputData(fAnalysis,kTRUE);
1718 }
002c9d1b 1719 }
4b71572b 1720
1721}
1722
1723//_____________________________________________________________________________
1724void AliReconstruction::SlaveBegin(TTree*)
1725{
1726 // Initialization related to run-loader,
1727 // vertexer, trackers, recontructors
1728 // In proof mode it is executed on the slave
52dd4a8c 1729 AliCodeTimerAuto("",0);
4b71572b 1730
db4aeca1 1731 TProofOutputFile *outProofFile = NULL;
81d57268 1732 if (fInput) {
1733 if (AliDebugLevel() > 0) fInput->Print();
ef5e52f6 1734 if (AliDebugLevel() > 10) fInput->Dump();
db4aeca1 1735 if (AliReconstruction *reco = (AliReconstruction*)fInput->FindObject("AliReconstruction")) {
1736 *this = *reco;
1737 }
4b71572b 1738 if (TGeoManager *tgeo = (TGeoManager*)fInput->FindObject("Geometry")) {
1739 gGeoManager = tgeo;
1740 AliGeomManager::SetGeometry(tgeo);
7e88424f 1741 }
281270d3 1742 if (TMap *entryCache = (TMap*)fInput->FindObject("CDBEntryCache")) {
1743 Int_t runNumber = -1;
1744 if (TProof::GetParameter(fInput,"RunNumber",runNumber) == 0) {
1745 AliCDBManager *man = AliCDBManager::Instance(entryCache,runNumber);
1746 man->SetCacheFlag(kTRUE);
1747 man->SetLock(kTRUE);
1748 man->Print();
1749 }
4b71572b 1750 }
ead7b391 1751 if (AliMagF *map = (AliMagF*)fInput->FindObject("MagneticFieldMap")) {
ef5e52f6 1752 AliMagF *newMap = new AliMagF(*map);
1753 if (!newMap->LoadParameterization()) {
1754 Abort("AliMagF::LoadParameterization", TSelector::kAbortProcess);
1755 return;
1756 }
1757 TGeoGlobalMagField::Instance()->SetField(newMap);
1758 TGeoGlobalMagField::Instance()->Lock();
4b71572b 1759 }
42457748 1760 if (!fAnalysis) {
1761 // Attempt to get the analysis manager from the input list
1762 fAnalysis = (AliAnalysisManager*)fInput->FindObject("Analysis");
1763 if (fAnalysis) AliInfo("==== Analysis manager retrieved from input list ====");
1764 }
81d57268 1765 if (TNamed *outputFileName = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE"))
1766 fProofOutputFileName = outputFileName->GetTitle();
1767 if (TNamed *outputLocation = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_LOCATION"))
1768 fProofOutputLocation = outputLocation->GetTitle();
1769 if (fInput->FindObject("PROOF_OUTPUTFILE_DATASET"))
1770 fProofOutputDataset = kTRUE;
1771 if (TNamed *archiveList = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_ARCHIVE"))
1772 fProofOutputArchive = archiveList->GetTitle();
1773 if (!fProofOutputFileName.IsNull() &&
1774 !fProofOutputLocation.IsNull() &&
1775 fProofOutputArchive.IsNull()) {
1776 if (!fProofOutputDataset) {
1777 outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"M");
1778 outProofFile->SetOutputFileName(Form("%s%s",fProofOutputLocation.Data(),fProofOutputFileName.Data()));
1779 }
1780 else {
1781 outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"DROV",fProofOutputLocation.Data());
1782 }
1783 if (AliDebugLevel() > 0) outProofFile->Dump();
db4aeca1 1784 fOutput->Add(outProofFile);
4b71572b 1785 }
002c9d1b 1786 AliSysInfo::AddStamp("ReadInputInSlaveBegin");
7e88424f 1787 }
42457748 1788 // Check if analysis was requested in the reconstruction event loop
1789 if (!fAnalysis) {
1790 // Attempt to connect in-memory singleton
1791 fAnalysis = AliAnalysisManager::GetAnalysisManager();
1792 if (fAnalysis) AliInfo(Form("==== Analysis manager <%s> found in memory ====", fAnalysis->GetName()));
1793 // Check if an analysis macro was specified
1794 if (!fAnalysis && !fAnalysisMacro.IsNull()) {
1795 // Run specified analysis macro
1796 gROOT->ProcessLine(Form(".x %s",fAnalysisMacro.Data()));
1797 fAnalysis = AliAnalysisManager::GetAnalysisManager();
1798 if (!fAnalysis) AliError(Form("No analysis manager produced by analysis macro %s", fAnalysisMacro.Data()));
1799 else AliInfo(Form("==== Analysis manager <%s> produced by analysis macro <%s> ====",
1800 fAnalysis->GetName(), fAnalysisMacro.Data()));
1801 }
1802 }
1803
4b71572b 1804 // get the run loader
1805 if (!InitRunLoader()) {
1806 Abort("InitRunLoader", TSelector::kAbortProcess);
1807 return;
1808 }
1809 AliSysInfo::AddStamp("LoadLoader");
1810
92258ce2 1811 CheckRecoCDBvsSimuCDB();
1812
325aa76f 1813 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
2257f27e 1814
f08fc9f5 1815 // get trackers
b8cd5251 1816 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
4b71572b 1817 Abort("CreateTrackers", TSelector::kAbortProcess);
1818 return;
1819 }
1820 AliSysInfo::AddStamp("CreateTrackers");
24f7a148 1821
36711aa4 1822 // create the ESD output file and tree
db4aeca1 1823 if (!outProofFile) {
1824 ffile = TFile::Open("AliESDs.root", "RECREATE");
1825 ffile->SetCompressionLevel(2);
1826 if (!ffile->IsOpen()) {
1827 Abort("OpenESDFile", TSelector::kAbortProcess);
1828 return;
1829 }
1830 }
1831 else {
81d57268 1832 AliInfo(Form("Opening output PROOF file: %s/%s",
1833 outProofFile->GetDir(), outProofFile->GetFileName()));
db4aeca1 1834 if (!(ffile = outProofFile->OpenFile("RECREATE"))) {
1835 Abort(Form("Problems opening output PROOF file: %s/%s",
1836 outProofFile->GetDir(), outProofFile->GetFileName()),
1837 TSelector::kAbortProcess);
1838 return;
1839 }
596a855f 1840 }
46698ae4 1841
21a3aa09 1842 ftree = new TTree("esdTree", "Tree with ESD objects");
1843 fesd = new AliESDEvent();
1844 fesd->CreateStdContent();
8b12d288 1845 // add a so far non-std object to the ESD, this will
1846 // become part of the std content
1847 fesd->AddObject(new AliESDHLTDecision);
ddfbc51a 1848
32ba9c61 1849 fesd->WriteToTree(ftree);
1d99986f 1850 if (fWriteESDfriend) {
ee7c441c 1851 ffileF = TFile::Open("AliESDfriends.root", "RECREATE");
03a8000a 1852 ftreeF = new TTree("esdFriendTree", "Tree with ESD Friend objects");
ee7c441c 1853 fesdf = new AliESDfriend();
ddfbc51a 1854 ftreeF->Branch("ESDfriend.","AliESDfriend", &fesdf);
21a3aa09 1855 fesd->AddObject(fesdf);
ee7c441c 1856 ffile->cd();
1d99986f 1857 }
f9604a22 1858 ftree->GetUserInfo()->Add(fesd);
1859
1860 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
1861 fhltesd = new AliESDEvent();
1862 fhltesd->CreateStdContent();
7491aea6 1863 // read the ESD template from CDB
1864 // HLT is allowed to put non-std content to its ESD, the non-std
1865 // objects need to be created before invocation of WriteToTree in
1866 // order to create all branches. Initialization is done from an
1867 // ESD layout template in CDB
1868 AliCDBManager* man = AliCDBManager::Instance();
df3fcecb 1869 AliCDBEntry* hltESDConfig = man->Get("HLT/Calib/esdLayout");
7cca01eb 1870 if(!hltESDConfig){
1871 AliError(Form("Error getting \"HLT/Calib/esdLayout\""));
1872 return;
1873 }
df3fcecb 1874 AliESDEvent* pESDLayout=dynamic_cast<AliESDEvent*>(hltESDConfig->GetObject());
1875 if (pESDLayout) {
7491aea6 1876 // init all internal variables from the list of objects
1877 pESDLayout->GetStdContent();
1878
1879 // copy content and create non-std objects
1880 *fhltesd=*pESDLayout;
1881 fhltesd->Reset();
df3fcecb 1882 } else {
1883 AliError(Form("error setting hltEsd layout from \"HLT/Calib/esdLayout\": invalid object type"));
7491aea6 1884 }
1885
f9604a22 1886 fhltesd->WriteToTree(fhlttree);
1887 fhlttree->GetUserInfo()->Add(fhltesd);
5728d3d5 1888
ac4a7581 1889 ProcInfo_t procInfo;
1890 gSystem->GetProcInfo(&procInfo);
73bbf779 1891 AliInfo(Form("Current memory usage %ld %ld", procInfo.fMemResident, procInfo.fMemVirtual));
8661738e 1892
1d26da6d 1893 // PID
1894 fESDpid = new AliESDpid();
1895
325aa76f 1896 //QA
930e6e3e 1897 //Initialize the QA and start of cycle
f1c1204d 1898 if (fRunQA || fRunGlobalQA)
1899 InitQA() ;
aa3c69a9 1900
7167ae53 1901 //Initialize the Plane Efficiency framework
1902 if (fRunPlaneEff && !InitPlaneEff()) {
4b71572b 1903 Abort("InitPlaneEff", TSelector::kAbortProcess);
1904 return;
7167ae53 1905 }
aa3c69a9 1906
14dd053c 1907 if (strcmp(gProgName,"alieve") == 0)
1908 fRunAliEVE = InitAliEVE();
42457748 1909 // If we have an analysis manager, connect the AliRecoInputHandler here
1910 if (fAnalysis) {
1911 if (!dynamic_cast<AliRecoInputHandler*>(fAnalysis->GetInputEventHandler())) {
1912 AliError("Analysis manager used in reconstruction should use AliRecoInputHandler - \
1913 \n ->Replacing with AliRecoInputHandler instance.");
1914 delete fAnalysis->GetInputEventHandler();
1915 }
1916 // Set the event and other data pointers
1917 fRecoHandler = new AliRecoInputHandler();
6ee8a83a 1918// fRecoHandler->Init(ftree, "LOCAL");
42457748 1919 fRecoHandler->SetEvent(fesd);
1920 fRecoHandler->SetESDfriend(fesdf);
1921 fRecoHandler->SetHLTEvent(fhltesd);
1922 fRecoHandler->SetHLTTree(fhlttree);
1923 fAnalysis->SetInputEventHandler(fRecoHandler);
1924 // Enter external loop mode
1925 fAnalysis->SetExternalLoop(kTRUE);
1926 // Initialize analysis
6ee8a83a 1927 fAnalysis->SlaveBegin(ftree);
42457748 1928 fAnalysis->StartAnalysis("local", (TTree*)0);
1929 // Connect ESD tree with the input container
1930 fAnalysis->GetCommonInputContainer()->SetData(ftree);
1931 }
4b71572b 1932 return;
21a3aa09 1933}
1934
1935//_____________________________________________________________________________
4b71572b 1936Bool_t AliReconstruction::Process(Long64_t entry)
1937{
1938 // run the reconstruction over a single entry
1939 // from the chain with raw data
52dd4a8c 1940 AliCodeTimerAuto("",0);
4b71572b 1941
1942 TTree *currTree = fChain->GetTree();
33314186 1943 AliRawVEvent *event = NULL;
4b71572b 1944 currTree->SetBranchAddress("rawevent",&event);
1945 currTree->GetEntry(entry);
1946 fRawReader = new AliRawReaderRoot(event);
30b916f7 1947 // check if process has enough resources
1948 if (!HasEnoughResources(entry)) return kFALSE;
42457748 1949 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
4b71572b 1950 delete fRawReader;
1951 fRawReader = NULL;
1952 delete event;
1953
1954 return fStatus;
1955}
1956
1957//_____________________________________________________________________________
1958void AliReconstruction::Init(TTree *tree)
1959{
0a035be5 1960 // Implementation of TSelector::Init()
1961 // method
4b71572b 1962 if (tree == 0) {
1963 AliError("The input tree is not found!");
1964 return;
1965 }
1966 fChain = tree;
1967}
1968
1969//_____________________________________________________________________________
1970Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
21a3aa09 1971{
1972 // run the reconstruction over a single event
1973 // The event loop is steered in Run method
1974
10d100d4 1975
470f88b0 1976 static Long_t oldMres=0;
1977 static Long_t oldMvir=0;
1978 static Float_t oldCPU=0;
91772e6b 1979 static Long_t aveDMres=0;
1980 static Long_t aveDMvir=0;
1981 static Float_t aveDCPU=0;
470f88b0 1982
52dd4a8c 1983 AliCodeTimerAuto("",0);
21a3aa09 1984
8d25d294 1985 AliSysInfo::AddStamp(Form("StartEv_%d",iEvent), 0,0,iEvent);
1986
21a3aa09 1987 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
1988 fRunLoader->SetEventNumber(iEvent);
4018c387 1989 if (fRawReader)
1990 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1991 iEvent, iEvent);
21a3aa09 1992 fRunLoader->TreeE()->Fill();
5b3ea9c5 1993
396f89bc 1994 if (fRawReader && fRawReader->UseAutoSaveESD())
4b71572b 1995 fRunLoader->TreeE()->AutoSave("SaveSelf");
21a3aa09 1996 }
1997
1998 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
21a3aa09 1999 return kTRUE;
2000 }
ddfbc51a 2001
2002
16447f18 2003 fRunLoader->GetEvent(iEvent);
2004
7e88424f 2005 // Fill Event-info object
2006 GetEventInfo();
77ba28ba 2007 fRecoParam.SetEventSpecie(fRunInfo,fEventInfo,fListOfCosmicTriggers);
d97f1dbe 2008
2009 ProcInfo_t procInfo;
2010 if(iEvent==fFirstEvent) {
2011 gSystem->GetProcInfo(&procInfo);
2012 oldMres=procInfo.fMemResident;
2013 oldMvir=procInfo.fMemVirtual;
2014 oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
2015 }
470f88b0 2016 AliInfo(Form("================================= Processing event %d of type %-10s ==================================", iEvent,fRecoParam.PrintEventSpecie()));
7e88424f 2017
8d25d294 2018 AliSysInfo::AddStamp(Form("StartReco_%d",iEvent), 0,0,iEvent);
2019
a00021a7 2020 // Set the reco-params
2021 {
2022 TString detStr = fLoadCDB;
ac4a7581 2023 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
a00021a7 2024 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2025 AliReconstructor *reconstructor = GetReconstructor(iDet);
2026 if (reconstructor && fRecoParam.GetDetRecoParamArray(iDet)) {
57acd2d2 2027 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2028 reconstructor->SetRecoParam(par);
1d26da6d 2029 reconstructor->GetPidSettings(fESDpid);
10d100d4 2030 reconstructor->SetEventInfo(&fEventInfo);
57acd2d2 2031 if (fRunQA) {
c3c10397 2032 AliQAManager::QAManager()->SetEventInfo(&fEventInfo) ;
eca4fa66 2033 AliQAManager::QAManager()->SetRecoParam(iDet, par) ;
619aafe6 2034 if (par) AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(par->GetEventSpecie())) ;
57acd2d2 2035 }
a00021a7 2036 }
2037 }
92664bc8 2038 //
2039 if (fRunQA || fRunGlobalQA) AliQADataMaker::SetEventTrigClasses(fEventInfo.GetTriggerClasses()); // RS: select which histo clones are to be filled
2040 //
9dad1020 2041 if (fRunQA) {
2042 const AliDetectorRecoParam *grppar = fRecoParam.GetDetRecoParam(kNDetectors);
2043 AliQAManager::QAManager()->SetRecoParam(AliQAv1::kGLOBAL, grppar) ;
2044 AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(grppar->GetEventSpecie())) ;
2045 }
a00021a7 2046 }
2047
ca13fb87 2048 // QA on single raw
514cb8c7 2049 if (fRunQA && IsInTasks(AliQAv1::kRAWS)) {
eca4fa66 2050 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
2051 AliQAManager::QAManager()->RunOneEvent(fRawReader) ;
8d25d294 2052 AliSysInfo::AddStamp(Form("RawQA_%d",iEvent), 0,0,iEvent);
57acd2d2 2053 }
b26c3770 2054
6b3a883f 2055 // fill Event header information from the RawEventHeader
2056 if (fRawReader){FillRawEventHeaderESD(fesd);}
2057 if (fRawReader){FillRawEventHeaderESD(fhltesd);}
8bc95619 2058 if (fRawReader){
2059 // Store DAQ detector pattern and attributes
2060 fesd->SetDAQDetectorPattern(fRawReader->GetDetectorPattern()[0]);
2061 fesd->SetDAQAttributes(fRawReader->GetAttributes()[2]);
2062 }
6b3a883f 2063
21a3aa09 2064 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
2065 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
7b649c02 2066
2067 ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
2068 ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
2069 ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
2070 ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
2071
21a3aa09 2072 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
2073 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
fd2e2210 2074
2075 fesd->SetEventSpecie(fRecoParam.GetEventSpecie());
2076 fhltesd->SetEventSpecie(fRecoParam.GetEventSpecie());
46698ae4 2077
d6ee376f 2078 // Set magnetic field from the tracker
21a3aa09 2079 fesd->SetMagneticField(AliTracker::GetBz());
2080 fhltesd->SetMagneticField(AliTracker::GetBz());
33fe5eb1 2081 //
3d84ad67 2082 AliESDRun *esdRun,*esdRunH;
2083 esdRun = (AliESDRun*)fesd->GetESDRun();
2084 esdRunH = (AliESDRun*)fhltesd->GetESDRun();
2085 esdRun->SetBeamEnergyIsSqrtSHalfGeV();
2086 esdRunH->SetBeamEnergyIsSqrtSHalfGeV();
2087 //
2088 for (int ib=2;ib--;) for (int it=2;it--;) {
2089 esdRun->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
2090 esdRunH->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
2091 }
c587bcde 2092 //
91460b26 2093 fesd->SetBeamEnergy(fGRPData->GetBeamEnergy());
2094 fesd->SetBeamType(fGRPData->GetBeamType().Data());
2095 fesd->SetBeamParticle(fGRPData->GetSingleBeamType(0).Atoi(),0);
2096 fesd->SetBeamParticle(fGRPData->GetSingleBeamType(1).Atoi(),1);
2097 fhltesd->SetBeamEnergy(fGRPData->GetBeamEnergy());
2098 fhltesd->SetBeamType(fGRPData->GetBeamType().Data());
2099 fhltesd->SetBeamParticle(fGRPData->GetSingleBeamType(0).Atoi(),0);
2100 fhltesd->SetBeamParticle(fGRPData->GetSingleBeamType(1).Atoi(),1);
2101 //
33fe5eb1 2102 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
2103 if (fld) { // set info needed for field initialization
2104 fesd->SetCurrentL3(fld->GetCurrentSol());
2105 fesd->SetCurrentDip(fld->GetCurrentDip());
33fe5eb1 2106 fesd->SetUniformBMap(fld->IsUniform());
2107 fesd->SetBInfoStored();
2108 //
2109 fhltesd->SetCurrentL3(fld->GetCurrentSol());
2110 fhltesd->SetCurrentDip(fld->GetCurrentDip());
33fe5eb1 2111 fhltesd->SetUniformBMap(fld->IsUniform());
2112 fhltesd->SetBInfoStored();
2113 }
bd072da4 2114
2115 //
2116 // run full HLT reconstruction first
2117 //
2118 {
2119 TString detectors=fRunLocalReconstruction;
2120 if (IsSelected("HLT", detectors) &&
2121 !RunLocalEventReconstruction("HLT")) {
2122 if (fStopOnError) {CleanUp(); return kFALSE;}
2123 }
2124 detectors=fFillESD;
2125 // run HLT on hltesd
2126 if (IsSelected("HLT", detectors) &&
2127 !FillESD(fhltesd, "HLT")) {
2128 if (fStopOnError) {CleanUp(); return kFALSE;}
2129 }
2130 }
2131
2132 // local single event reconstruction
2133 if (!fRunLocalReconstruction.IsNull()) {
2134 TString detectors=fRunLocalReconstruction;
2135 // the logic for selection and correct sequence of reconstruction relies on the
2136 // full list of detectors. Keyword 'ALL' should have been replaced at this point.
2137 if (detectors.Contains("ALL")) {
2138 AliFatal("Keyword 'ALL' needs to be replaced by the full list of detectors in "
2139 "fRunLocalReconstruction. This should have been done by the framework");
2140 }
2141 detectors.ReplaceAll("HLT", "");
2142 if (!RunLocalEventReconstruction(detectors)) {
2143 if (fStopOnError) {
2144 CleanUp();
2145 return kFALSE;
2146 }
2147 }
2148 }
2149
2150
33fe5eb1 2151 //
71f6cda4 2152 // Set most probable pt, for B=0 tracking
9257a1bd 2153 // Get the global reco-params. They are atposition 16 inside the array of detectors in fRecoParam
ac4a7581 2154 const AliGRPRecoParam *grpRecoParam = dynamic_cast<const AliGRPRecoParam*>(fRecoParam.GetDetRecoParam(kNDetectors));
71f6cda4 2155 if (grpRecoParam) AliExternalTrackParam::SetMostProbablePt(grpRecoParam->GetMostProbablePt());
46698ae4 2156
2e3550da 2157 // Fill raw-data error log into the ESD
21a3aa09 2158 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 2159
8d25d294 2160 AliSysInfo::AddStamp(Form("FillHeadErrs_%d",iEvent), 0,0,iEvent);
2161
2257f27e 2162 // vertex finder
2163 if (fRunVertexFinder) {
4b71572b 2164 if (!RunVertexFinder(fesd)) {
2165 if (fStopOnError) {CleanUp(); return kFALSE;}
2257f27e 2166 }
8d25d294 2167 AliSysInfo::AddStamp(Form("VtxFinder_%d",iEvent), 0,0,iEvent);
2257f27e 2168 }
2169
58e8dc31 2170 // For Plane Efficiency: run the SPD trackleter
2171 if (fRunPlaneEff && fSPDTrackleter) {
2172 if (!RunSPDTrackleting(fesd)) {
2173 if (fStopOnError) {CleanUp(); return kFALSE;}
2174 }
8d25d294 2175 AliSysInfo::AddStamp(Form("TrackletEff_%d",iEvent), 0,0,iEvent);
58e8dc31 2176 }
2177
e66fbafb 2178 // Muon tracking
b8cd5251 2179 if (!fRunTracking.IsNull()) {
e66fbafb 2180 if (fRunMuonTracking) {
21a3aa09 2181 if (!RunMuonTracking(fesd)) {
4b71572b 2182 if (fStopOnError) {CleanUp(); return kFALSE;}
24f7a148 2183 }
596a855f 2184 }
8d25d294 2185 AliSysInfo::AddStamp(Form("TrackingMUON_%d",iEvent), 0,0,iEvent);
596a855f 2186 }
2187
d3eabe96 2188 //---------------- AU From here...
2189
2190 // MFT tracking of MUON tracks
2191 if (!fRunTracking.IsNull()) {
2192 if (fRunMFTTrackingMU && fRunMuonTracking) {
2193 if (!RunMFTTrackingMU(fesd)) {
2194 if (fStopOnError) {CleanUp(); return kFALSE;}
2195 }
2196 }
2197 AliSysInfo::AddStamp(Form("TrackingMFT_MUON_%d",iEvent), 0,0,iEvent);
2198 }
2199
2200 //---------------- ...to here
2201
e66fbafb 2202 // barrel tracking
2203 if (!fRunTracking.IsNull()) {
1d26da6d 2204 if (!RunTracking(fesd,*fESDpid)) {
4b71572b 2205 if (fStopOnError) {CleanUp(); return kFALSE;}
e66fbafb 2206 }
2207 }
21c573b7 2208
596a855f 2209 // fill ESD
2210 if (!fFillESD.IsNull()) {
d506c543 2211 TString detectors=fFillESD;
bd072da4 2212 // the logic for selection and correct sequence of reconstruction relies on the
2213 // full list of detectors. Keyword 'ALL' should have been replaced at this point.
d5105682 2214 if (detectors.Contains("ALL")) {
bd072da4 2215 AliFatal("Keyword 'ALL' needs to be replaced by the full list of detectors in "
2216 "fFillESD. This should have been done by the framework");
d5105682 2217 }
bd072da4 2218 // remove HLT as this has been executed at the beginning of the event reconstruction
f6806ad3 2219 detectors.ReplaceAll("HLT", "");
2220 if (!FillESD(fesd, detectors)) {
4b71572b 2221 if (fStopOnError) {CleanUp(); return kFALSE;}
596a855f 2222 }
2223 }
b647652d 2224
21a3aa09 2225 ffile->cd();
a6ee503a 2226
3c3709c4 2227 //
67be5c77 2228 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 2229 //
21a3aa09 2230 const Int_t ntracks = fesd->GetNumberOfTracks();
3c3709c4 2231 const Double_t kRadius = 2.8; //something less than the beam pipe radius
2232
2233 TObjArray trkArray;
30b916f7 2234 UShort_t selectedIdx[ntracks];
3c3709c4 2235
2236 for (Int_t itrack=0; itrack<ntracks; itrack++){
98a50ff3 2237 const Double_t kMaxStep = 1; //max step over the material
3c3709c4 2238 Bool_t ok;
2239
21a3aa09 2240 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 2241 if (!track) continue;
2242
2243 AliExternalTrackParam *tpcTrack =
2244 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 2245 ok = kFALSE;
2246 if (tpcTrack)
2247 ok = AliTracker::
1d26da6d 2248 PropagateTrackToBxByBz(tpcTrack,kRadius,track->GetMassForTracking(),kMaxStep,kFALSE);
43c9dae1 2249
3c3709c4 2250 if (ok) {
2251 Int_t n=trkArray.GetEntriesFast();
2252 selectedIdx[n]=track->GetID();
2253 trkArray.AddLast(tpcTrack);
2254 }
2255
3d65e645 2256 //Tracks refitted by ITS should already be at the SPD vertex
2257 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
2258
2259 AliTracker::
1d26da6d 2260 PropagateTrackToBxByBz(track,kRadius,track->GetMassForTracking(),kMaxStep,kFALSE);
52dd4a8c 2261 Double_t x[3]; track->GetXYZ(x);
2262 Double_t b[3]; AliTracker::GetBxByBz(x,b);
2263 track->RelateToVertexBxByBz(fesd->GetPrimaryVertexSPD(), b, kVeryBig);
3c3709c4 2264
3c3709c4 2265 }
8d25d294 2266 AliSysInfo::AddStamp(Form("RelToSPDVtx_%d",iEvent), 0,0,iEvent);
3c3709c4 2267 //
2268 // Improve the reconstructed primary vertex position using the tracks
2269 //
59224b2b 2270 Bool_t runVertexFinderTracks = fRunVertexFinderTracks;
2271 if(fesd->GetPrimaryVertexSPD()) {
2272 TString vtitle = fesd->GetPrimaryVertexSPD()->GetTitle();
2273 if(vtitle.Contains("cosmics")) {
2274 runVertexFinderTracks=kFALSE;
2275 }
c060d7fe 2276 }
a00021a7 2277
2278 if (runVertexFinderTracks) {
3c3709c4 2279 // TPC + ITS primary vertex
f09c879d 2280 ftVertexer->SetITSMode();
f2a195c1 2281 ftVertexer->SetConstraintOff();
a00021a7 2282 // get cuts for vertexer from AliGRPRecoParam
1c7554f9 2283 Bool_t constrSPD=kFALSE;
a00021a7 2284 if (grpRecoParam) {
2285 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
2286 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
8eaa1a42 2287 grpRecoParam->GetVertexerTracksCutsITS(cutsVertexer,nCutsVertexer);
2288 ftVertexer->SetCuts(cutsVertexer,nCutsVertexer);
a00021a7 2289 delete [] cutsVertexer; cutsVertexer = NULL;
1c7554f9 2290 if(grpRecoParam->GetVertexerTracksConstraintITS()) {
2291 if(fDiamondProfile && fDiamondProfile->GetXRes()<kRadius){
2292 ftVertexer->SetVtxStart(fDiamondProfile); // apply constraint only if sigmax is smaller than the beam pipe radius
2293 }else{
2294 if(fDiamondProfileSPD && fDiamondProfileSPD->GetXRes()<kRadius){
2295 ftVertexer->SetVtxStart(fDiamondProfileSPD);
2296 constrSPD=kTRUE;
2297 }
2298 }
dd15203b 2299 }
43c9dae1 2300 }
21a3aa09 2301 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 2302 if (pvtx) {
1c7554f9 2303 if(constrSPD){
2304 TString title=pvtx->GetTitle();
2305 title.Append("SPD");
2306 pvtx->SetTitle(title);
2307 }
3c3709c4 2308 if (pvtx->GetStatus()) {
c264b61b 2309 fesd->SetPrimaryVertexTracks(pvtx);
3c3709c4 2310 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 2311 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 2312 Double_t x[3]; t->GetXYZ(x);
2313 Double_t b[3]; AliTracker::GetBxByBz(x,b);
2314 t->RelateToVertexBxByBz(pvtx, b, kVeryBig);
3c3709c4 2315 }
2316 }
9bcaa1d7 2317 delete pvtx; pvtx=NULL;
3c3709c4 2318 }
8d25d294 2319 AliSysInfo::AddStamp(Form("VtxTrk_%d",iEvent), 0,0,iEvent);
3c3709c4 2320
2321 // TPC-only primary vertex
f09c879d 2322 ftVertexer->SetTPCMode();
f2a195c1 2323 ftVertexer->SetConstraintOff();
a00021a7 2324 // get cuts for vertexer from AliGRPRecoParam
2325 if (grpRecoParam) {
2326 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
2327 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
8eaa1a42 2328 grpRecoParam->GetVertexerTracksCutsTPC(cutsVertexer,nCutsVertexer);
2329 ftVertexer->SetCuts(cutsVertexer,nCutsVertexer);
a00021a7 2330 delete [] cutsVertexer; cutsVertexer = NULL;
dd15203b 2331 if(fDiamondProfileTPC && grpRecoParam->GetVertexerTracksConstraintTPC()) {
2332 if(fDiamondProfileTPC->GetXRes()<kRadius) ftVertexer->SetVtxStart(fDiamondProfileTPC); // apply constraint only if sigmax is smaller than the beam pipe radius
2333 }
43c9dae1 2334 }
21a3aa09 2335 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 2336 if (pvtx) {
2337 if (pvtx->GetStatus()) {
21a3aa09 2338 fesd->SetPrimaryVertexTPC(pvtx);
3d65e645 2339 for (Int_t i=0; i<ntracks; i++) {
2340 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 2341 Double_t x[3]; t->GetXYZ(x);
2342 Double_t b[3]; AliTracker::GetBxByBz(x,b);
2343 t->RelateToVertexTPCBxByBz(pvtx, b, kVeryBig);
3c3709c4 2344 }
2345 }
9bcaa1d7 2346 delete pvtx; pvtx=NULL;
3c3709c4 2347 }
8d25d294 2348 AliSysInfo::AddStamp(Form("VtxTPC_%d",iEvent), 0,0,iEvent);
3c3709c4 2349
2350 }
30b916f7 2351
1c7554f9 2352 if(fDiamondProfile && fDiamondProfile->GetXRes()<kRadius) fesd->SetDiamond(fDiamondProfile);
2353 else fesd->SetDiamond(fDiamondProfileSPD);
c5e3e5d1 2354
d1683eef 2355 if (fRunV0Finder) {
2356 // V0 finding
2357 AliV0vertexer vtxer;
61a14552 2358 // get cuts for V0vertexer from AliGRPRecoParam
2359 if (grpRecoParam) {
2360 Int_t nCutsV0vertexer = grpRecoParam->GetVertexerV0NCuts();
30b916f7 2361 Double_t cutsV0vertexer[nCutsV0vertexer];
61a14552 2362 grpRecoParam->GetVertexerV0Cuts(cutsV0vertexer);
2363 vtxer.SetCuts(cutsV0vertexer);
61a14552 2364 }
21a3aa09 2365 vtxer.Tracks2V0vertices(fesd);
8d25d294 2366 AliSysInfo::AddStamp(Form("V0Finder_%d",iEvent), 0,0,iEvent);
5e4ff34d 2367
d1683eef 2368 if (fRunCascadeFinder) {
2369 // Cascade finding
2370 AliCascadeVertexer cvtxer;
61a14552 2371 // get cuts for CascadeVertexer from AliGRPRecoParam
2372 if (grpRecoParam) {
2373 Int_t nCutsCascadeVertexer = grpRecoParam->GetVertexerCascadeNCuts();
30b916f7 2374 Double_t cutsCascadeVertexer[nCutsCascadeVertexer];
61a14552 2375 grpRecoParam->GetVertexerCascadeCuts(cutsCascadeVertexer);
2376 cvtxer.SetCuts(cutsCascadeVertexer);
61a14552 2377 }
21a3aa09 2378 cvtxer.V0sTracks2CascadeVertices(fesd);
8d25d294 2379 AliSysInfo::AddStamp(Form("CascadeFinder_%d",iEvent), 0,0,iEvent);
d1683eef 2380 }
5e4ff34d 2381 }
c8122432 2382
50f012a8 2383 // AdC+FN
2384 if (fReconstructor[3])
1d26da6d 2385 GetReconstructor(3)->FillEventTimeWithTOF(fesd,fESDpid);
50f012a8 2386
2387 // combined PID
1d26da6d 2388 // fESDpid->MakePID(fesd);
50f012a8 2389
2390 if (fFillTriggerESD) {
2391 if (!FillTriggerESD(fesd)) {
2392 if (fStopOnError) {CleanUp(); return kFALSE;}
2393 }
2394 }
2395 // Always fill scalers
2396 if (!FillTriggerScalers(fesd)) {
2397 if (fStopOnError) {CleanUp(); return kFALSE;}
2398 }
2399
8d25d294 2400 AliSysInfo::AddStamp(Form("FillVaria_%d",iEvent), 0,0,iEvent);
2401
c8122432 2402 // write ESD
3f0e1025 2403 UInt_t specie = fesd->GetEventSpecie();
2404 Bool_t keepAll = (specie==AliRecoParam::kCosmic || specie==AliRecoParam::kCalib);
2405 if (fCleanESD && (!keepAll) ) {
8d25d294 2406 CleanESD(fesd);
2407 AliSysInfo::AddStamp(Form("CleanESD_%d",iEvent), 0,0,iEvent);
2408 }
c8122432 2409 //
1f9831ab 2410 // RS run updated trackleter: since we want to mark the clusters used by tracks and also mark the
2411 // tracks interpreted as primary, this step should be done in the very end, when full
2412 // ESD info is available (particulalry, V0s)
2413 // vertex finder
c8122432 2414 if (fRunMultFinder) {
2415 if (!RunMultFinder(fesd)) {
2416 if (fStopOnError) {CleanUp(); return kFALSE;}
2417 }
8d25d294 2418 AliSysInfo::AddStamp(Form("MultFinder_%d",iEvent), 0,0,iEvent);
c8122432 2419 }
854c6476 2420
514cb8c7 2421 if (fRunQA && IsInTasks(AliQAv1::kESDS)) {
eca4fa66 2422 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
aeb8fc30 2423 AliQAManager::QAManager()->RunOneEvent(fesd, fhltesd) ;
8d25d294 2424 AliSysInfo::AddStamp(Form("RunQA_%d",iEvent), 0,0,iEvent);
57acd2d2 2425 }
bea94759 2426 if (fRunGlobalQA) {
eca4fa66 2427 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
4018c387 2428 if (qadm)
57acd2d2 2429 qadm->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
514cb8c7 2430 if (qadm && IsInTasks(AliQAv1::kESDS))
4e25ac79 2431 qadm->Exec(AliQAv1::kESDS, fesd);
8d25d294 2432 AliSysInfo::AddStamp(Form("RunGlobQA_%d",iEvent), 0,0,iEvent);
b03591ab 2433 }
854c6476 2434
8b12d288 2435 // copy HLT decision from HLTesd to esd
2436 // the most relevant information is stored in a reduced container in the esd,
2437 // while the full information can be found in the HLTesd
2438 TObject* pHLTSrc=fhltesd->FindListObject(AliESDHLTDecision::Name());
2439 TObject* pHLTTgt=fesd->FindListObject(AliESDHLTDecision::Name());
2440 if (pHLTSrc && pHLTTgt) {
2441 pHLTSrc->Copy(*pHLTTgt);
2442 }
3ba71cb5 2443 //
2444 // Perform analysis of this event if requested
2445 // RS: Should be done before WriteESDfriend, since the latter may clean the esdfriend
2446 if (fAnalysis) {
2447 fRecoHandler->BeginEvent(iEvent);
2448 fAnalysis->ExecAnalysis();
2449 fRecoHandler->FinishEvent();
8d25d294 2450 AliSysInfo::AddStamp(Form("Analysis_%d",iEvent), 0,0,iEvent);
3ba71cb5 2451 }
2452 //
30b916f7 2453 if (fWriteESDfriend) {
ddfbc51a 2454 fesd->GetESDfriend(fesdf);
2455 AliSysInfo::AddStamp(Form("CreateFriend_%d",iEvent), 0,0,iEvent);
2456
30b916f7 2457 }
2458 //
5ee8b64f 2459 Long64_t nbf;
2460 nbf = ftree->Fill();
2461 if (fTreeBuffSize>0 && ftree->GetAutoFlush()<0 && (fMemCountESD += nbf)>fTreeBuffSize ) { // default limit is still not reached
2462 nbf = ftree->GetZipBytes();
2463 if (nbf>0) nbf = -nbf;
2464 else nbf = ftree->GetEntries();
2465 ftree->SetAutoFlush(nbf);
2466 AliInfo(Form("Calling ftree->SetAutoFlush(%lld) | W:%lld T:%lld Z:%lld",
2467 nbf,fMemCountESD,ftree->GetTotBytes(),ftree->GetZipBytes()));
2468 }
e546b023 2469 AliSysInfo::AddStamp(Form("ESDFill_%d",iEvent), 0,0,iEvent);
ddfbc51a 2470 //
e546b023 2471 if (fWriteESDfriend) {
ddfbc51a 2472 WriteESDfriend();
2473 AliSysInfo::AddStamp(Form("WriteFriend_%d",iEvent), 0,0,iEvent);
2474 }
2475 //
2476 //
2477 // Auto-save the ESD tree in case of prompt reco @P2
2478 if (fRawReader && fRawReader->UseAutoSaveESD()) {
2479 ftree->AutoSave("SaveSelf");
2480 if (fWriteESDfriend) ftreeF->AutoSave("SaveSelf");
30b916f7 2481 }
5ee8b64f 2482 // write HLT ESD
2483
2484 nbf = fhlttree->Fill();
2485 if (fTreeBuffSize>0 && fhlttree->GetAutoFlush()<0 && (fMemCountESDHLT += nbf)>fTreeBuffSize ) { // default limit is still not reached
2486 nbf = fhlttree->GetZipBytes();
2487 if (nbf>0) nbf = -nbf;
2488 else nbf = fhlttree->GetEntries();
2489 fhlttree->SetAutoFlush(nbf);
2490 AliInfo(Form("Calling fhlttree->SetAutoFlush(%lld) | W:%lld T:%lld Z:%lld",
2491 nbf,fMemCountESDHLT,fhlttree->GetTotBytes(),fhlttree->GetZipBytes()));
2492 }
2493
91772e6b 2494 gSystem->GetProcInfo(&procInfo);
2495 Long_t dMres=(procInfo.fMemResident-oldMres)/1024;
2496 Long_t dMvir=(procInfo.fMemVirtual-oldMvir)/1024;
2497 Float_t dCPU=procInfo.fCpuUser+procInfo.fCpuSys-oldCPU;
2498 aveDMres+=(dMres-aveDMres)/(iEvent-fFirstEvent+1);
2499 aveDMvir+=(dMvir-aveDMvir)/(iEvent-fFirstEvent+1);
2500 aveDCPU+=(dCPU-aveDCPU)/(iEvent-fFirstEvent+1);
2501 AliInfo(Form("======================= End Event %d: Res %ld(%3ld <%3ld>) Vir %ld(%3ld <%3ld>) CPU %5.2f <%5.2f> ===================",
2502 iEvent, procInfo.fMemResident/1024, dMres, aveDMres, procInfo.fMemVirtual/1024, dMvir, aveDMvir, dCPU, aveDCPU));
2503 oldMres=procInfo.fMemResident;
2504 oldMvir=procInfo.fMemVirtual;
2505 oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
2506
7e0cf530 2507
2508 return kTRUE;
2509}
1d99986f 2510
7e0cf530 2511void AliReconstruction::CleanProcessedEvent()
2512{
0c4df52e 2513 //
21a3aa09 2514 fesd->Reset();
2515 fhltesd->Reset();
5728d3d5 2516 if (fWriteESDfriend) {
ddfbc51a 2517 fesdf->~AliESDfriend();
2518 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 2519 }
bd072da4 2520
2521 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2522 if (fReconstructor[iDet]) fReconstructor[iDet]->FinishEvent();
2523 }
a5fa6165 2524
7e0cf530 2525 AliInfo("======================= End Event ===================");
2526
ca13fb87 2527 fEventInfo.Reset();
ac4a7581 2528 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
42ec5d3d 2529 if (fReconstructor[iDet]) {
a00021a7 2530 fReconstructor[iDet]->SetRecoParam(NULL);
42ec5d3d 2531 fReconstructor[iDet]->SetEventInfo(NULL);
2532 }
1f26f3e7 2533 if (fTracker[iDet]) fTracker[iDet]->SetEventInfo(NULL);
ca13fb87 2534 }
2535
53c8f690 2536 if (fRunQA || fRunGlobalQA)
eca4fa66 2537 AliQAManager::QAManager()->Increment() ;
ddfbc51a 2538
e54c9180 2539 DeleteRecPoints(fDeleteRecPoints);
2540 DeleteDigits(fDeleteDigits);
ddfbc51a 2541 //
7e0cf530 2542
21a3aa09 2543}
2544
21a3aa09 2545//_____________________________________________________________________________
4b71572b 2546void AliReconstruction::SlaveTerminate()
21a3aa09 2547{
4b71572b 2548 // Finalize the run on the slave side
21a3aa09 2549 // Called after the exit
2550 // from the event loop
52dd4a8c 2551 AliCodeTimerAuto("",0);
42457748 2552 // If analysis was done during reconstruction, we need to call SlaveTerminate for it
2553 if (fAnalysis) {
2554 fAnalysis->PackOutput(fOutput);
2555 fAnalysis->SetSkipTerminate(kTRUE);
2556 fAnalysis->Terminate();
2557 }
21a3aa09 2558
2559 if (fIsNewRunLoader) { // galice.root didn't exist
2560 fRunLoader->WriteHeader("OVERWRITE");
5b3ea9c5 2561 fRunLoader->WriteTrigger("OVERWRITE");
21a3aa09 2562 fRunLoader->CdGAFile();
2563 fRunLoader->Write(0, TObject::kOverwrite);
2564 }
2565
f747912b 2566 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
2567 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
2568
2569 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
2570 cdbMapCopy->SetOwner(1);
2571 cdbMapCopy->SetName("cdbMap");
2572 TIter iter(cdbMap->GetTable());
2573
2574 TPair* pair = 0;
2575 while((pair = dynamic_cast<TPair*> (iter.Next()))){
2576 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
c7a22819 2577 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
2578 if (keyStr && valStr)
2579 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
f747912b 2580 }
2581
2582 TList *cdbListCopy = new TList();
2583 cdbListCopy->SetOwner(1);
2584 cdbListCopy->SetName("cdbList");
2585
2586 TIter iter2(cdbList);
2587
b940cb9b 2588 AliCDBId* id=0;
e84c88f5 2589 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 2590 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 2591 }
2592
21a3aa09 2593 ftree->GetUserInfo()->Add(cdbMapCopy);
2594 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 2595
27aa8455 2596 // Add the AliRoot version that created this file
2597 TString sVersion("aliroot ");
0492edf5 2598 sVersion += ALIROOT_BRANCH;
27aa8455 2599 sVersion += ":";
0492edf5 2600 sVersion += ALIROOT_REVISION;
27aa8455 2601 sVersion += "; root ";
c28cf643 2602#ifdef ROOT_SVN_BRANCH
27aa8455 2603 sVersion += ROOT_SVN_BRANCH;
d9298a37 2604#elif defined(ROOT_GIT_BRANCH)
c28cf643 2605 sVersion += ROOT_GIT_BRANCH;
d9298a37 2606#else
2607 sVersion += "?";
c28cf643 2608#endif
27aa8455 2609 sVersion += ":";
d9298a37 2610#ifdef ROOT_SVN_REVSION
27aa8455 2611 sVersion += ROOT_SVN_REVISION;
d9298a37 2612#elif defined(ROOT_GIT_COMMIT)
2613 sVersion += ROOT_GIT_COMMIT;
2614#else
2615 sVersion += "?";
2616#endif
27aa8455 2617 sVersion += "; metadata ";
f3664c51 2618 sVersion += getenv("PRODUCTION_METADATA");
27aa8455 2619
2620
2621 TNamed * alirootVersion = new TNamed("alirootVersion",sVersion.Data());
2622 ftree->GetUserInfo()->Add(alirootVersion); // The list becomes owner of alirootVersion
46698ae4 2623
21a3aa09 2624 ffile->cd();
aa3c69a9 2625
562dd0b4 2626 // we want to have only one tree version number
21a3aa09 2627 ftree->Write(ftree->GetName(),TObject::kOverwrite);
63314086 2628 fhlttree->Write(fhlttree->GetName(),TObject::kOverwrite);
f3a97c86 2629
ee7c441c 2630 if (fWriteESDfriend) {
2631 ffileF->cd();
2632 ftreeF->Write(ftreeF->GetName(),TObject::kOverwrite);
2633 }
2634
a7a1e1c7 2635// Finish with Plane Efficiency evaluation: before of CleanUp !!!
2636 if (fRunPlaneEff && !FinishPlaneEff()) {
2637 AliWarning("Finish PlaneEff evaluation failed");
2638 }
2639
323a7f87 2640 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
0d45a46a 2641 if (fReconstructor[iDet]) fReconstructor[iDet]->Terminate();
323a7f87 2642 }
930e6e3e 2643 // End of cycle for the in-loop
87da0921 2644
2645 if (fRunQA || fRunGlobalQA) {
5cbed243 2646 AliQAManager::QAManager()->EndOfCycle() ;
81d57268 2647 if (fInput &&
2648 !fProofOutputLocation.IsNull() &&
2649 fProofOutputArchive.IsNull() &&
2650 !fProofOutputDataset) {
2651 TString qaOutputFile(Form("%sMerged.%s.Data.root",
2652 fProofOutputLocation.Data(),
2653 AliQAv1::GetQADataFileName()));
2654 TProofOutputFile *qaProofFile = new TProofOutputFile(Form("Merged.%s.Data.root",
2655 AliQAv1::GetQADataFileName()));
2656 qaProofFile->SetOutputFileName(qaOutputFile.Data());
2657 if (AliDebugLevel() > 0) qaProofFile->Dump();
2658 fOutput->Add(qaProofFile);
2659 MergeQA(qaProofFile->GetFileName());
87da0921 2660 }
2661 else {
2662 MergeQA();
2663 }
2664 }
2665
4b71572b 2666 gROOT->cd();
2667 CleanUp();
81d57268 2668
2669 if (fInput) {
2670 if (!fProofOutputFileName.IsNull() &&
2671 !fProofOutputLocation.IsNull() &&
2672 fProofOutputDataset &&
2673 !fProofOutputArchive.IsNull()) {
2674 TProofOutputFile *zipProofFile = new TProofOutputFile(fProofOutputFileName.Data(),
2675 "DROV",
2676 fProofOutputLocation.Data());
2677 if (AliDebugLevel() > 0) zipProofFile->Dump();
2678 fOutput->Add(zipProofFile);
2679 TString fileList(fProofOutputArchive.Data());
2680 fileList.ReplaceAll(","," ");
38c18bf1 2681 TString command;
2682#if ROOT_SVN_REVISION >= 30174
2683 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(kTRUE),zipProofFile->GetFileName(),fileList.Data());
2684#else
2685 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(),zipProofFile->GetFileName(),fileList.Data());
2686#endif
2687 AliInfo(Form("Executing: %s",command.Data()));
2688 gSystem->Exec(command.Data());
81d57268 2689 }
2690 }
4b71572b 2691}
2692
2693//_____________________________________________________________________________
2694void AliReconstruction::Terminate()
2695{
f3a97c86 2696 // Create tags for the events in the ESD tree (the ESD tree is always present)
2697 // In case of empty events the tags will contain dummy values
52dd4a8c 2698 AliCodeTimerAuto("",0);
4b71572b 2699
ddfbc51a 2700 // Do not call the ESD tag creator in case of PROOF-based reconstruction
e6d66370 2701 if (!fInput) {
2702 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
2703 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData, AliQAv1::Instance()->GetQA(), AliQAv1::Instance()->GetEventSpecies(), AliQAv1::kNDET, AliRecoParam::kNSpecies);
9bcaa1d7 2704 delete esdtagCreator;
e6d66370 2705 }
e84c88f5 2706
795e4a22 2707 // Cleanup of CDB manager: cache and active storages!
2708 AliCDBManager::Instance()->ClearCache();
596a855f 2709}
2710
b26c3770 2711//_____________________________________________________________________________
2712Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
2713{
2714// run the local reconstruction
aa3c69a9 2715
0f88822a 2716 static Int_t eventNr=0;
52dd4a8c 2717 AliCodeTimerAuto("",0)
b26c3770 2718
2719 TString detStr = detectors;
9533b54d 2720 // execute HLT reconstruction first since other detector reconstruction
2721 // might depend on HLT data
2722 // key 'HLT' is removed from detStr by IsSelected
bd072da4 2723 if (IsSelected("HLT", detStr)) {
9533b54d 2724 AliReconstructor* reconstructor = GetReconstructor(kNDetectors-1);
2725 if (reconstructor) {
2726 // there is no AliLoader for HLT, see
2727 // https://savannah.cern.ch/bugs/?35473
2728 AliInfo("running reconstruction for HLT");
f6806ad3 2729 if (fRawReader) {
820b4d9e 2730 AliInfo("reconstructor->Reconstruct(fRawReader, NULL)");
44ed7a66 2731 reconstructor->Reconstruct(fRawReader, NULL);
820b4d9e 2732 }
2733 else {
2734 AliInfo("reconstructor->Reconstruct(dummy, NULL)");
44ed7a66 2735 TTree* dummy=NULL;
2736 reconstructor->Reconstruct(dummy, NULL);
f6806ad3 2737 }
f6806ad3 2738 }
8d25d294 2739 AliSysInfo::AddStamp(Form("LRecHLT_%d",eventNr), -1,1,eventNr);
9533b54d 2740 }
820b4d9e 2741
2742 AliInfo(Form("kNDetectors = %d",kNDetectors));
2743
9533b54d 2744 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2745 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
820b4d9e 2746 AliDebug(1, Form("Detector: %s", fgkDetectorName[iDet]));
9533b54d 2747 AliReconstructor* reconstructor = GetReconstructor(iDet);
2748 if (!reconstructor) continue;
2749 AliLoader* loader = fLoader[iDet];
d76c31f4 2750 if (!loader) {
2751 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
2752 continue;
2753 }
b26c3770 2754 // conversion of digits
2755 if (fRawReader && reconstructor->HasDigitConversion()) {
2756 AliInfo(Form("converting raw data digits into root objects for %s",
2757 fgkDetectorName[iDet]));
30bbd491 2758// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
52dd4a8c 2759// fgkDetectorName[iDet]),0);
b26c3770 2760 loader->LoadDigits("update");
2761 loader->CleanDigits();
2762 loader->MakeDigitsContainer();
2763 TTree* digitsTree = loader->TreeD();
2764 reconstructor->ConvertDigits(fRawReader, digitsTree);
2765 loader->WriteDigits("OVERWRITE");
2766 loader->UnloadDigits();
b26c3770 2767 }
b26c3770 2768 // local reconstruction
b26c3770 2769 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
52dd4a8c 2770 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]),0);
820b4d9e 2771 AliDebug(1, "Loading Rec Points");
b26c3770 2772 loader->LoadRecPoints("update");
820b4d9e 2773 AliDebug(1, "Cleaning Rec Points");
b26c3770 2774 loader->CleanRecPoints();
820b4d9e 2775 AliDebug(1, "Making Rec Points Container");
b26c3770 2776 loader->MakeRecPointsContainer();
2777 TTree* clustersTree = loader->TreeR();
2778 if (fRawReader && !reconstructor->HasDigitConversion()) {
2779 reconstructor->Reconstruct(fRawReader, clustersTree);
820b4d9e 2780 }
2781 else {
2782 AliDebug(1, "Loading Digits");
b26c3770 2783 loader->LoadDigits("read");
2784 TTree* digitsTree = loader->TreeD();
820b4d9e 2785 AliDebug(1, Form("Digits Tree = %p",digitsTree));
b26c3770 2786 if (!digitsTree) {
44ed7a66 2787 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
13effe3f 2788 if (fStopOnError)
2789 return kFALSE;
820b4d9e 2790 }
2791 else {
2792 AliDebug(1, "Digits -> Clusters");
44ed7a66 2793 reconstructor->Reconstruct(digitsTree, clustersTree);
514cb8c7 2794 if (fRunQA && IsInTasks(AliQAv1::kDIGITSR)) {
eca4fa66 2795 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
2796 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, digitsTree) ;
44ed7a66 2797 }
b26c3770 2798 }
2799 loader->UnloadDigits();
2800 }
92664bc8 2801 if (fRunQA && IsInTasks(AliQAv1::kRECPOINTS)) {
eca4fa66 2802 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
92664bc8 2803 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, clustersTree) ;
57acd2d2 2804 }
eca4fa66 2805 loader->WriteRecPoints("OVERWRITE");
2806 loader->UnloadRecPoints();
2807 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
a00021a7 2808 }
c7a22819 2809 if (!IsSelected("CTP", detStr)) AliDebug(10,"No CTP");
a00021a7 2810 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
b26c3770 2811 AliError(Form("the following detectors were not found: %s",
2812 detStr.Data()));
13effe3f 2813 if (fStopOnError)
2814 return kFALSE;
b26c3770 2815 }
0f88822a 2816 eventNr++;
b26c3770 2817 return kTRUE;
2818}
58e8dc31 2819//_____________________________________________________________________________
2820Bool_t AliReconstruction::RunSPDTrackleting(AliESDEvent*& esd)
2821{
2822// run the SPD trackleting (for SPD efficiency purpouses)
2823
52dd4a8c 2824 AliCodeTimerAuto("",0)
58e8dc31 2825
2826 Double_t vtxPos[3] = {0, 0, 0};
2827 Double_t vtxErr[3] = {0.0, 0.0, 0.0};
2828/*
09b62f0a 2829 TArrayF m
2830/
2831cVertex(3);
58e8dc31 2832 // if(MC)
2833 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
2834 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
2835 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
2836 }
2837*/
2838 const AliESDVertex *vertex = esd->GetVertex();
2839 if(!vertex){
2840 AliWarning("Vertex not found");
2841 return kFALSE;
2842 }
2843 vertex->GetXYZ(vtxPos);
2844 vertex->GetSigmaXYZ(vtxErr);
2845 if (fSPDTrackleter) {
2846 AliInfo("running the SPD Trackleter for Plane Efficiency Evaluation");
2847
2848 // load clusters
2849 fLoader[0]->LoadRecPoints("read");
2850 TTree* tree = fLoader[0]->TreeR();
2851 if (!tree) {
2852 AliError("Can't get the ITS cluster tree");
2853 return kFALSE;
2854 }
2855 fSPDTrackleter->LoadClusters(tree);
2856 fSPDTrackleter->SetVertex(vtxPos, vtxErr);
2857 // run trackleting
2858 if (fSPDTrackleter->Clusters2Tracks(esd) != 0) {
84290fcc 2859 AliWarning("AliITSTrackleterSPDEff Clusters2Tracks failed");
58e8dc31 2860 // fLoader[0]->UnloadRecPoints();
2861 return kFALSE;
2862 }
2863//fSPDTrackleter->UnloadRecPoints();
2864 } else {
2865 AliWarning("SPDTrackleter not available");
2866 return kFALSE;
2867 }
2868 return kTRUE;
2869}
b26c3770 2870
596a855f 2871//_____________________________________________________________________________
af885e0f 2872Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 2873{
2874// run the barrel tracking
2875
52dd4a8c 2876 AliCodeTimerAuto("",0)
030b532d 2877
92bffc4d 2878 AliVertexer *vertexer = CreateVertexer();
2879 if (!vertexer) return kFALSE;
2880
3c99b88f 2881 AliInfo(Form("running the ITS vertex finder: %s",vertexer->ClassName()));
2257f27e 2882 AliESDVertex* vertex = NULL;
92bffc4d 2883 if (fLoader[0]) {
2884 fLoader[0]->LoadRecPoints();
2885 TTree* cltree = fLoader[0]->TreeR();
2886 if (cltree) {
2887 if(fDiamondProfileSPD) vertexer->SetVtxStart(fDiamondProfileSPD);
2888 vertex = vertexer->FindVertexForCurrentEvent(cltree);
308c2f7c 2889 }
2890 else {
92bffc4d 2891 AliError("Can't get the ITS cluster tree");
308c2f7c 2892 }
92bffc4d 2893 fLoader[0]->UnloadRecPoints();
2257f27e 2894 }
92bffc4d 2895 else {
2896 AliError("Can't get the ITS loader");
2897 }
2898 if(!vertex){
2899 AliWarning("Vertex not found");
2900 vertex = new AliESDVertex();
2901 vertex->SetName("default");
2902 }
2903 else {
2904 vertex->SetName("reconstructed");
2257f27e 2905 }
92bffc4d 2906
2907 Double_t vtxPos[3];
2908 Double_t vtxErr[3];
2909 vertex->GetXYZ(vtxPos);
2910 vertex->GetSigmaXYZ(vtxErr);
2911
06cc9d95 2912 esd->SetPrimaryVertexSPD(vertex);
73c51de2 2913 AliESDVertex *vpileup = NULL;
2914 Int_t novertices = 0;
2915 vpileup = vertexer->GetAllVertices(novertices);
2916 if(novertices>1){
2917 for (Int_t kk=1; kk<novertices; kk++)esd->AddPileupVertexSPD(&vpileup[kk]);
2918 }
1f9831ab 2919 /*
32e449be 2920 // if SPD multiplicity has been determined, it is stored in the ESD
92bffc4d 2921 AliMultiplicity *mult = vertexer->GetMultiplicity();
32e449be 2922 if(mult)esd->SetMultiplicity(mult);
1f9831ab 2923 */
ac4a7581 2924 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2925 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
2926 }
2257f27e 2927 delete vertex;
2928
92bffc4d 2929 delete vertexer;
2930
2257f27e 2931 return kTRUE;
2932}
2933
1f9831ab 2934//_____________________________________________________________________________
2935Bool_t AliReconstruction::RunMultFinder(AliESDEvent*& esd)
2936{
2937 // run the trackleter for multiplicity study
2938
2939 AliCodeTimerAuto("",0)
2940
2941 AliTrackleter *trackleter = CreateMultFinder();
2942 if (!trackleter) return kFALSE;
2943
2944 AliInfo(Form("running the ITS multiplicity finder: %s",trackleter->ClassName()));
2945
2946 if (fLoader[0]) {
2947 fLoader[0]->LoadRecPoints();
2948 TTree* cltree = fLoader[0]->TreeR();
2949 if (cltree) {
2950 trackleter->Reconstruct(esd,cltree);
2951 AliMultiplicity *mult = trackleter->GetMultiplicity();
2952 if(mult) esd->SetMultiplicity(mult);
2953 }
2954 else {
2955 AliError("Can't get the ITS cluster tree");
2956 }
2957 fLoader[0]->UnloadRecPoints();
2958 }
2959 else {
2960 AliError("Can't get the ITS loader");
2961 }
2962
2963 delete trackleter;
2964
2965 return kTRUE;
2966}
2967
e66fbafb 2968//_____________________________________________________________________________
af885e0f 2969Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 2970{
2971// run the muon spectrometer tracking
2972
52dd4a8c 2973 AliCodeTimerAuto("",0)
e66fbafb 2974
2975 if (!fRunLoader) {
2976 AliError("Missing runLoader!");
2977 return kFALSE;
2978 }
cfeca9e2 2979 Int_t iDet = GetDetIndex("MUON"); // for MUON
e66fbafb 2980
2981 // Get a pointer to the MUON reconstructor
2982 AliReconstructor *reconstructor = GetReconstructor(iDet);
2983 if (!reconstructor) return kFALSE;
2984
2985
2986 TString detName = fgkDetectorName[iDet];
2987 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 2988 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 2989 if (!tracker) {
2990 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
2991 return kFALSE;
2992 }
2993
e66fbafb 2994 // read RecPoints
761350a6 2995 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 2996
761350a6 2997 tracker->LoadClusters(fLoader[iDet]->TreeR());
2998
2999 Int_t rv = tracker->Clusters2Tracks(esd);
3000
e66fbafb 3001 fLoader[iDet]->UnloadRecPoints();
3002
c1954ee5 3003 tracker->UnloadClusters();
3004
cb23c6ca 3005 if ( rv )
3006 {
3007 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
3008 return kFALSE;
3009 }
3010
e66fbafb 3011 return kTRUE;
3012}
3013
3014
d3eabe96 3015//_____________________________________________________________________________
3016Bool_t AliReconstruction::RunMFTTrackingMU(AliESDEvent*& esd) {
3017
3018 // AU
3019
3020 // run the global muon tracking: matching the MUON tracks with the MFT clusters
3021
3022 AliCodeTimerAuto("",0)
3023
3024 if (!fRunLoader) {
3025 AliError("Missing runLoader!");
3026 return kFALSE;
3027 }
3028 Int_t iDet = GetDetIndex("MFT"); // for MFT
3029
3030 // Get a pointer to the MFT reconstructor
3031 AliReconstructor *reconstructor = GetReconstructor(iDet);
3032 if (!reconstructor) return kFALSE;
3033
3034 TString detName = fgkDetectorName[iDet];
3035 AliDebug(1, Form("%s tracking for muon tracks", detName.Data()));
3036 AliTracker *tracker = reconstructor->CreateTracker();
3037 if (!tracker) {
3038 AliWarning(Form("couldn't create a Muon tracker for %s", detName.Data()));
3039 return kFALSE;
3040 }
3041
3042 // read RecPoints
3043 fLoader[iDet]->LoadRecPoints("read");
3044
3045 tracker->LoadClusters(fLoader[iDet]->TreeR());
3046
3047 Int_t rv = tracker->Clusters2Tracks(esd);
3048
3049 fLoader[iDet]->UnloadRecPoints();
3050
3051 tracker->UnloadClusters();
3052
3053 if (rv) {
3054 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
3055 return kFALSE;
3056 }
3057
3058 return kTRUE;
3059
3060}
3061
2257f27e 3062//_____________________________________________________________________________
10d100d4 3063Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd,AliESDpid &PID)
2257f27e 3064{
3065// run the barrel tracking
0f88822a 3066 static Int_t eventNr=0;
52dd4a8c 3067 AliCodeTimerAuto("",0)
24f7a148 3068
815c2b38 3069 AliInfo("running tracking");
596a855f 3070
1f26f3e7 3071 // Set the event info which is used
3072 // by the trackers in order to obtain
3073 // information about read-out detectors,
3074 // trigger etc.
3075 AliDebug(1, "Setting event info");
3076 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
3077 if (!fTracker[iDet]) continue;
3078 fTracker[iDet]->SetEventInfo(&fEventInfo);
3079 }
3080
91b876d1 3081 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 3082 if (fReconstructor[11] && fLoader[11]) {
3083 fLoader[11]->LoadRecPoints("READ");
3084 TTree *treeR = fLoader[11]->TreeR();
89916438 3085 if (treeR) {
3086 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
3087 }
d76c31f4 3088 }
91b876d1 3089
b8cd5251 3090 // pass 1: TPC + ITS inwards
3091 for (Int_t iDet = 1; iDet >= 0; iDet--) {
3092 if (!fTracker[iDet]) continue;
3093 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 3094
b8cd5251 3095 // load clusters
3096 fLoader[iDet]->LoadRecPoints("read");
6efecea1 3097 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 3098 TTree* tree = fLoader[iDet]->TreeR();
3099 if (!tree) {
3100 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 3101 return kFALSE;
3102 }
b8cd5251 3103 fTracker[iDet]->LoadClusters(tree);
6efecea1 3104 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 3105 // run tracking
156b8439 3106 if (fTracker[iDet]->Clusters2TracksHLT(esd, fhltesd) != 0) {
b8cd5251 3107 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 3108 return kFALSE;
3109 }
8d25d294 3110 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
878e1fe1 3111 // preliminary PID in TPC needed by the ITS tracker
3112 if (iDet == 1) {
b26c3770 3113 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1d26da6d 3114 PID.MakePIDForTracking(esd);
8d25d294 3115 AliSysInfo::AddStamp(Form("MakePID0%s_%d",fgkDetectorName[iDet],eventNr), iDet,4,eventNr);
0f88822a 3116 }
b8cd5251 3117 }
596a855f 3118
b8cd5251 3119 // pass 2: ALL backwards
aa3c69a9 3120
ac4a7581 3121 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 3122 if (!fTracker[iDet]) continue;
3123 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
3124
3125 // load clusters
3126 if (iDet > 1) { // all except ITS, TPC
3127 TTree* tree = NULL;
7b61cd9c 3128 fLoader[iDet]->LoadRecPoints("read");
6efecea1 3129 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 3130 tree = fLoader[iDet]->TreeR();
b8cd5251 3131 if (!tree) {
eca4fa66 3132 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
3133 return kFALSE;
24f7a148 3134 }
0f88822a 3135 fTracker[iDet]->LoadClusters(tree);
6efecea1 3136 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 3137 }
24f7a148 3138
b8cd5251 3139 // run tracking
283f39c6 3140 if (iDet>1) // start filling residuals for the "outer" detectors
eca4fa66 3141 if (fRunGlobalQA) {
3142 AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);
3143 TObjArray ** arr = AliTracker::GetResidualsArray() ;
c9526f68 3144 if (arr) {
0a349581 3145 AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
3146 TObjArray * elem = arr[AliRecoParam::AConvert(es)];
c9526f68 3147 if ( elem && (! elem->At(0)) ) {
3148 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
3149 if (qadm) qadm->InitRecPointsForTracker() ;
3150 }
3151 }
8d25d294 3152 // AliSysInfo::AddStamp(Form("QAInitResid%s_%d",fgkDetectorName[iDet],eventNr), iDet,0, eventNr);
eca4fa66 3153 }
b8cd5251 3154 if (fTracker[iDet]->PropagateBack(esd) != 0) {
3155 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 3156 // return kFALSE;
b8cd5251 3157 }
8d25d294 3158 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
24f7a148 3159
b8cd5251 3160 // unload clusters
6e65648b 3161 if (iDet > 3) { // all except ITS, TPC, TRD and TOF
b8cd5251 3162 fTracker[iDet]->UnloadClusters();
7b61cd9c 3163 fLoader[iDet]->UnloadRecPoints();
b8cd5251 3164 }
8f37df88 3165 // updated PID in TPC needed by the ITS tracker -MI
3166 if (iDet == 1) {
10d100d4 3167 //GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
3168 //AliESDpid::MakePID(esd);
1d26da6d 3169 PID.MakePIDForTracking(esd);
8d25d294 3170 AliSysInfo::AddStamp(Form("MakePID1%s_%d",fgkDetectorName[iDet],eventNr), iDet,4,eventNr);
8f37df88 3171 }
8d25d294 3172
b8cd5251 3173 }
283f39c6 3174 //stop filling residuals for the "outer" detectors
57acd2d2 3175 if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);
596a855f 3176
b8cd5251 3177 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 3178
b8cd5251 3179 for (Int_t iDet = 2; iDet >= 0; iDet--) {
3180 if (!fTracker[iDet]) continue;
3181 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 3182
b8cd5251 3183 // run tracking
283f39c6 3184 if (iDet<2) // start filling residuals for TPC and ITS
eca4fa66 3185 if (fRunGlobalQA) {
3186 AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);
3187 TObjArray ** arr = AliTracker::GetResidualsArray() ;
c9526f68 3188 if (arr) {
0a349581 3189 AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
3190 TObjArray * elem = arr[AliRecoParam::AConvert(es)];
c9526f68 3191 if ( elem && (! elem->At(0)) ) {
3192 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
3193 if (qadm) qadm->InitRecPointsForTracker() ;
3194 }
3195 }
eca4fa66 3196 }
3197
b8cd5251 3198 if (fTracker[iDet]->RefitInward(esd) != 0) {
3199 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 3200 // return kFALSE;
b8cd5251 3201 }
db2368d0 3202 // run postprocessing
3203 if (fTracker[iDet]->PostProcess(esd) != 0) {
3204 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
3205 // return kFALSE;
3206 }
6efecea1 3207 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
6e65648b 3208 }
3209
3210 // write space-points to the ESD in case alignment data output
3211 // is switched on
8d25d294 3212 if (fWriteAlignmentData) {
6e65648b 3213 WriteAlignmentData(esd);
8d25d294 3214 AliSysInfo::AddStamp(Form("WrtAlignData_%d",eventNr), 0,0, eventNr);
3215 }
3216
6e65648b 3217 for (Int_t iDet = 3; iDet >= 0; iDet--) {
3218 if (!fTracker[iDet]) continue;
b8cd5251 3219 // unload clusters
3220 fTracker[iDet]->UnloadClusters();
6efecea1 3221 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 3222 fLoader[iDet]->UnloadRecPoints();
6efecea1 3223 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 3224 }
283f39c6 3225 // stop filling residuals for TPC and ITS
57acd2d2 3226 if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);
854c6476 3227
0f88822a 3228 eventNr++;
596a855f 3229 return kTRUE;
3230}
3231
d64bd07d 3232//_____________________________________________________________________________
3233Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
3234 //
3235 // Remove the data which are not needed for the physics analysis.
3236 //
3237
d64bd07d 3238 Int_t nTracks=esd->GetNumberOfTracks();
18571674 3239 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 3240 AliInfo
3241 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 3242
18571674 3243 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 3244 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 3245
7f68891d 3246 nTracks=esd->GetNumberOfTracks();
18571674 3247 nV0s=esd->GetNumberOfV0s();
cf37fd88 3248 AliInfo
ae5d5566 3249 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 3250
7f68891d 3251 return rc;
d64bd07d 3252}
3253
596a855f 3254//_____________________________________________________________________________
af885e0f 3255Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 3256{
3257// fill the event summary data
3258
52dd4a8c 3259 AliCodeTimerAuto("",0)
0f88822a 3260 static Int_t eventNr=0;
596a855f 3261 TString detStr = detectors;
abe0c04e 3262
f1640d23 3263 AliSysInfo::AddStamp(Form("FillESDb%d",eventNr), -19,-19, eventNr);
ac4a7581 3264 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
abe0c04e 3265 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 3266 AliReconstructor* reconstructor = GetReconstructor(iDet);
3267 if (!reconstructor) continue;
4b71572b 3268 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
3269 TTree* clustersTree = NULL;
3270 if (fLoader[iDet]) {
3271 fLoader[iDet]->LoadRecPoints("read");
3272 clustersTree = fLoader[iDet]->TreeR();
3273 if (!clustersTree) {
3274 AliError(Form("Can't get the %s clusters tree",
3275 fgkDetectorName[iDet]));
3276 if (fStopOnError) return kFALSE;
3277 }
3278 }
3279 if (fRawReader && !reconstructor->HasDigitConversion()) {
3280 reconstructor->FillESD(fRawReader, clustersTree, esd);
3281 } else {
3282 TTree* digitsTree = NULL;
d76c31f4 3283 if (fLoader[iDet]) {
4b71572b 3284 fLoader[iDet]->LoadDigits("read");
3285 digitsTree = fLoader[iDet]->TreeD();
3286 if (!digitsTree) {
3287 AliError(Form("Can't get the %s digits tree",
b26c3770 3288 fgkDetectorName[iDet]));
3289 if (fStopOnError) return kFALSE;
3290 }
3291 }
4b71572b 3292 reconstructor->FillESD(digitsTree, clustersTree, esd);
3293 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
3294 }
3295 if (fLoader[iDet]) {
3296 fLoader[iDet]->UnloadRecPoints();
596a855f 3297 }
3298 }
13effe3f 3299
c7a22819 3300 if (!IsSelected("CTP", detStr)) AliDebug(10,"No CTP");
596a855f 3301 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 3302 AliError(Form("the following detectors were not found: %s",
3303 detStr.Data()));
596a855f 3304 if (fStopOnError) return kFALSE;
3305 }
f1640d23 3306 AliSysInfo::AddStamp(Form("FillESDe%d",eventNr), -20,-20, eventNr);
0f88822a 3307 eventNr++;
596a855f 3308 return kTRUE;
3309}
3310
b647652d 3311//_____________________________________________________________________________
af885e0f 3312Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 3313{
3314 // Reads the trigger decision which is
3315 // stored in Trigger.root file and fills
3316 // the corresponding esd entries
3317
52dd4a8c 3318 AliCodeTimerAuto("",0)
87932dab 3319
b647652d 3320 AliInfo("Filling trigger information into the ESD");
3321
3322 if (fRawReader) {
3323 AliCTPRawStream input(fRawReader);
3324 if (!input.Next()) {
7e88424f 3325 AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
b647652d 3326 }
3327 else {
7e88424f 3328 if (esd->GetTriggerMask() != input.GetClassMask())
3329 AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
3330 input.GetClassMask(),esd->GetTriggerMask()));
3331 if (esd->GetOrbitNumber() != input.GetOrbitID())
3332 AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
3333 input.GetOrbitID(),esd->GetOrbitNumber()));
3334 if (esd->GetBunchCrossNumber() != input.GetBCID())
3335 AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
3336 input.GetBCID(),esd->GetBunchCrossNumber()));
e61ed4b1 3337 AliESDHeader* esdheader = esd->GetHeader();
3338 esdheader->SetL0TriggerInputs(input.GetL0Inputs());
3339 esdheader->SetL1TriggerInputs(input.GetL1Inputs());
3340 esdheader->SetL2TriggerInputs(input.GetL2Inputs());
a6dd87ad 3341 // IR
6ac1d1f4 3342 // UInt_t orbit=input.GetOrbitID();
96bf4ffc 3343 for(Int_t i=0 ; i<input.GetNIRs() ; i++ ) {
3344 esdheader->AddTriggerIR(input.GetIR(i));
3345 }
5b3ea9c5 3346 AliCentralTrigger* rlCTP = fRunLoader->GetTrigger();
173b7e07 3347 if (rlCTP) {
3348 rlCTP->SetL0TriggerInputs(input.GetL0Inputs());
3349 rlCTP->SetL1TriggerInputs(input.GetL1Inputs());
3350 rlCTP->SetL2TriggerInputs(input.GetL2Inputs());
3351 }
b647652d 3352 }
5b3ea9c5 3353 if (fIsNewRunLoader) fRunLoader->TreeCT()->Fill();
b024fd7f 3354 }
f7812afc 3355 return kTRUE;
3356}
3357//_____________________________________________________________________________
3358Bool_t AliReconstruction::FillTriggerScalers(AliESDEvent*& esd)
3359{
522fdd91 3360 //Scalers
82ebedd6 3361 //fRunScalers->Print();
3362 if(fRunScalers && fRunScalers->CheckRunScalers()){
a6dd87ad 3363 AliTimeStamp* timestamp = new AliTimeStamp(esd->GetOrbitNumber(), esd->GetPeriodNumber(), esd->GetBunchCrossNumber());
82ebedd6 3364 //AliTimeStamp* timestamp = new AliTimeStamp(10308000, 0, (ULong64_t)486238);
522fdd91 3365 AliESDHeader* esdheader = fesd->GetHeader();
3366 for(Int_t i=0;i<50;i++){
1e78ae8c 3367 if((1ull<<i) & esd->GetTriggerMask()){
6863d231 3368 AliTriggerScalersESD* scalesd = fRunScalers->GetScalersForEventClass( timestamp, i+1);
82ebedd6 3369 if(scalesd)esdheader->SetTriggerScalersRecord(scalesd);
522fdd91 3370 }
3371 }
09b62f0a 3372 const AliTriggerScalersRecordESD* scalrecEvent = fRunScalers->GetScalersDeltaForEvent( timestamp);
3373 const AliTriggerScalersRecordESD* scalrecRun = fRunScalers->GetScalersDeltaForRun();
3374 if (scalrecEvent) esdheader->SetTriggerScalersDeltaEvent(scalrecEvent);
3375 if (scalrecRun) esdheader->SetTriggerScalersDeltaRun(scalrecRun);
522fdd91 3376 }
b647652d 3377 return kTRUE;
3378}
001397cd 3379//_____________________________________________________________________________
af885e0f 3380Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 3381{
3382 //
3383 // Filling information from RawReader Header
3384 //
3385
151bea4e 3386 if (!fRawReader) return kFALSE;
3387
001397cd 3388 AliInfo("Filling information from RawReader Header");
151bea4e 3389
3390 esd->SetBunchCrossNumber(fRawReader->GetBCID());
3391 esd->SetOrbitNumber(fRawReader->GetOrbitID());
3392 esd->SetPeriodNumber(fRawReader->GetPeriod());
3393
3394 esd->SetTimeStamp(fRawReader->GetTimestamp());
3395 esd->SetEventType(fRawReader->GetType());
001397cd 3396
3397 return kTRUE;
3398}
3399
3400
596a855f 3401//_____________________________________________________________________________
3402Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
3403{
3404// check whether detName is contained in detectors
3405// if yes, it is removed from detectors
3406
3407 // check if all detectors are selected
3408 if ((detectors.CompareTo("ALL") == 0) ||
3409 detectors.BeginsWith("ALL ") ||
3410 detectors.EndsWith(" ALL") ||
3411 detectors.Contains(" ALL ")) {
3412 detectors = "ALL";
3413 return kTRUE;
3414 }
3415
3416 // search for the given detector
3417 Bool_t result = kFALSE;
3418 if ((detectors.CompareTo(detName) == 0) ||
3419 detectors.BeginsWith(detName+" ") ||
3420 detectors.EndsWith(" "+detName) ||
3421 detectors.Contains(" "+detName+" ")) {
3422 detectors.ReplaceAll(detName, "");
3423 result = kTRUE;
3424 }
3425
3426 // clean up the detectors string
3427 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
3428 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
3429 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
3430
3431 return result;
3432}
e583c30d 3433
f08fc9f5 3434//_____________________________________________________________________________
3435Bool_t AliReconstruction::InitRunLoader()
3436{
3437// get or create the run loader
3438
3439 if (gAlice) delete gAlice;
3440 gAlice = NULL;
3441
52dd4a8c 3442 TFile *gafile = TFile::Open(fGAliceFileName.Data());
3443 // if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
3444 if (gafile) { // galice.root exists
3445 gafile->Close();
3446 delete gafile;
3447
b26c3770 3448 // load all base libraries to get the loader classes
3449 TString libs = gSystem->GetLibraries();
ac4a7581 3450 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b26c3770 3451 TString detName = fgkDetectorName[iDet];
b26c3770 3452 if (libs.Contains("lib" + detName + "base.so")) continue;
3453 gSystem->Load("lib" + detName + "base.so");
3454 }
f08fc9f5 3455 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
3456 if (!fRunLoader) {
3457 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
3458 CleanUp();
3459 return kFALSE;
3460 }
325aa76f 3461
b26c3770 3462 fRunLoader->CdGAFile();
325aa76f 3463 fRunLoader->LoadgAlice();
f08fc9f5 3464
6cae184e 3465 //PH This is a temporary fix to give access to the kinematics
3466 //PH that is needed for the labels of ITS clusters
f2ee4290 3467 fRunLoader->LoadHeader();
6cae184e 3468 fRunLoader->LoadKinematics();
3469
f08fc9f5 3470 } else { // galice.root does not exist
3471 if (!fRawReader) {
3472 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
f08fc9f5 3473 }
3474 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
3475 AliConfig::GetDefaultEventFolderName(),
3476 "recreate");
3477 if (!fRunLoader) {
3478 AliError(Form("could not create run loader in file %s",
3479 fGAliceFileName.Data()));
3480 CleanUp();
3481 return kFALSE;
3482 }
21a3aa09 3483 fIsNewRunLoader = kTRUE;
f08fc9f5 3484 fRunLoader->MakeTree("E");
5b3ea9c5 3485 fRunLoader->MakeTree("GG");
21a3aa09 3486
973388c2 3487 if (fNumberOfEventsPerFile > 0)
3488 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
3489 else
21a3aa09 3490 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 3491 }
3492
3493 return kTRUE;
3494}
3495
c757bafd 3496//_____________________________________________________________________________
b8cd5251 3497AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 3498{
f08fc9f5 3499// get the reconstructor object and the loader for a detector
c757bafd 3500
7e88424f 3501 if (fReconstructor[iDet]) {
3502 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
3503 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
3504 fReconstructor[iDet]->SetRecoParam(par);
42ec5d3d 3505 fReconstructor[iDet]->SetRunInfo(fRunInfo);
7e88424f 3506 }
3507 return fReconstructor[iDet];
3508 }
b8cd5251 3509
3510 // load the reconstructor object
3511 TPluginManager* pluginManager = gROOT->GetPluginManager();
3512 TString detName = fgkDetectorName[iDet];
3513 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 3514
3515 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 3516
b8cd5251 3517 AliReconstructor* reconstructor = NULL;
3518 // first check if a plugin is defined for the reconstructor
3519 TPluginHandler* pluginHandler =
3520 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 3521 // if not, add a plugin for it
3522 if (!pluginHandler) {
b8cd5251 3523 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 3524 TString libs = gSystem->GetLibraries();
3525 if (libs.Contains("lib" + detName + "base.so") ||
3526 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 3527 pluginManager->AddHandler("AliReconstructor", detName,
3528 recName, detName + "rec", recName + "()");
3529 } else {
3530 pluginManager->AddHandler("AliReconstructor", detName,
3531 recName, detName, recName + "()");
c757bafd 3532 }
b8cd5251 3533 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
3534 }
3535 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
3536 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 3537 }
f9fc20b4 3538
3539 // check if the upgrade reconstructor should be used instead of the standard one
3540 if(fUpgradeMask[iDet]) {
3541 if(reconstructor) delete reconstructor;
3542 TClass *cl = new TClass(Form("Ali%sUpgradeReconstructor",fgkDetectorName[iDet]));
3543 reconstructor = (AliReconstructor*)(cl->New());
3544 }
3545
b8cd5251 3546 if (reconstructor) {
3547 TObject* obj = fOptions.FindObject(detName.Data());
3548 if (obj) reconstructor->SetOption(obj->GetTitle());
1e500f25 3549 reconstructor->SetRunInfo(fRunInfo);
bd072da4 3550 reconstructor->SetHLTESD(fhltesd);
d76c31f4 3551 reconstructor->Init();
b8cd5251 3552 fReconstructor[iDet] = reconstructor;
3553 }
3554
f08fc9f5 3555 // get or create the loader
3556 if (detName != "HLT") {
3557 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
3558 if (!fLoader[iDet]) {
3559 AliConfig::Instance()
3560 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
3561 detName, detName);
3562 // first check if a plugin is defined for the loader
bb0901a4 3563 pluginHandler =
f08fc9f5 3564 pluginManager->FindHandler("AliLoader", detName);
3565 // if not, add a plugin for it
3566 if (!pluginHandler) {
3567 TString loaderName = "Ali" + detName + "Loader";
3568 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
3569 pluginManager->AddHandler("AliLoader", detName,
3570 loaderName, detName + "base",
3571 loaderName + "(const char*, TFolder*)");
3572 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
3573 }
3574 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
3575 fLoader[iDet] =
3576 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
3577 fRunLoader->GetEventFolder());
3578 }
3579 if (!fLoader[iDet]) { // use default loader
3580 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
3581 }
3582 if (!fLoader[iDet]) {
3583 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 3584 if (fStopOnError) return NULL;
f08fc9f5 3585 } else {
3586 fRunLoader->AddLoader(fLoader[iDet]);
3587 fRunLoader->CdGAFile();
3588 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
3589 fRunLoader->Write(0, TObject::kOverwrite);
3590 }
3591 }
3592 }
3593
7e88424f 3594 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
3595 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
c7a22819 3596 if (reconstructor) {
3597 reconstructor->SetRecoParam(par);
3598 reconstructor->SetRunInfo(fRunInfo);
3599 }
7e88424f 3600 }
b8cd5251 3601 return reconstructor;
c757bafd 3602}
3603
2257f27e 3604//_____________________________________________________________________________
92bffc4d 3605AliVertexer* AliReconstruction::CreateVertexer()
2257f27e 3606{
3607// create the vertexer
92bffc4d 3608// Please note that the caller is the owner of the
3609// vertexer
2257f27e 3610
92bffc4d 3611 AliVertexer* vertexer = NULL;
b8cd5251 3612 AliReconstructor* itsReconstructor = GetReconstructor(0);
903b1262 3613 if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) ||
3614 fRunTracking.Contains("ITS") || fFillESD.Contains("ITS") )) {
92bffc4d 3615 vertexer = itsReconstructor->CreateVertexer();
2257f27e 3616 }
92bffc4d 3617 if (!vertexer) {
815c2b38 3618 AliWarning("couldn't create a vertexer for ITS");
2257f27e 3619 }
3620
92bffc4d 3621 return vertexer;
2257f27e 3622}
3623
1f9831ab 3624//_____________________________________________________________________________
3625AliTrackleter* AliReconstruction::CreateMultFinder()
3626{
3627// create the ITS trackleter for mult. estimation
3628// Please note that the caller is the owner of the
3629// trackleter
3630
3631 AliTrackleter* trackleter = NULL;
3632 AliReconstructor* itsReconstructor = GetReconstructor(0);
903b1262 3633 if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) ||
3634 fRunTracking.Contains("ITS") || fFillESD.Contains("ITS") )) {
1f9831ab 3635 trackleter = itsReconstructor->CreateMultFinder();
3636 }
a0ef2c64 3637 else {
3638 AliWarning("ITS is not in reconstruction, switching off RunMultFinder");
3639 fRunMultFinder = kFALSE;
1f9831ab 3640 }
3641
3642 return trackleter;
3643}
3644
24f7a148 3645//_____________________________________________________________________________
b8cd5251 3646Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 3647{
f08fc9f5 3648// create the trackers
44e45fac 3649 AliInfo("Creating trackers");
24f7a148 3650
b8cd5251 3651 TString detStr = detectors;
ac4a7581 3652 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 3653 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
3654 AliReconstructor* reconstructor = GetReconstructor(iDet);
3655 if (!reconstructor) continue;
3656 TString detName = fgkDetectorName[iDet];
e66fbafb 3657 if (detName == "MUON") {
3658 fRunMuonTracking = kTRUE;
3659 continue;
3660 }
d3eabe96 3661 if (detName == "MFT") { // AU
3662 fRunMFTTrackingMU = kTRUE; // AU
3663 continue; // AU
3664 } // AU
e66fbafb 3665
d76c31f4 3666 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 3667 if (!fTracker[iDet] && (iDet < 7)) {
3668 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 3669 if (fStopOnError) return kFALSE;
3670 }
6efecea1 3671 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 3672 }
3673
24f7a148 3674 return kTRUE;
3675}
3676
e583c30d 3677//_____________________________________________________________________________
4b71572b 3678void AliReconstruction::CleanUp()
e583c30d 3679{
3680// delete trackers and the run loader and close and delete the file
ac4a7581 3681 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 3682 delete fReconstructor[iDet];
3683 fReconstructor[iDet] = NULL;
3684 fLoader[iDet] = NULL;
3685 delete fTracker[iDet];
3686 fTracker[iDet] = NULL;
3687 }
92664bc8 3688
4b71572b 3689 delete fRunInfo;
7e88424f 3690 fRunInfo = NULL;
3691
58e8dc31 3692 delete fSPDTrackleter;
3693 fSPDTrackleter = NULL;
3694
4b71572b 3695 delete ftVertexer;
21a3aa09 3696 ftVertexer = NULL;
795e4a22 3697
e583c30d 3698 delete fRunLoader;
3699 fRunLoader = NULL;
b649205a 3700 delete fRawReader;
3701 fRawReader = NULL;
4b71572b 3702 delete fParentRawReader;
cd0b062e 3703 fParentRawReader=NULL;
e583c30d 3704
1d26da6d 3705 delete fESDpid;
3706 fESDpid = NULL;
3707
4b71572b 3708 if (ffile) {
3709 ffile->Close();
3710 delete ffile;
3711 ffile = NULL;
24f7a148 3712 }
87da0921 3713
bf76b847 3714 if (AliQAManager::QAManager())
3715 AliQAManager::QAManager()->ShowQA() ;
42457748 3716 // AliQAManager::Destroy() ;
3717 delete fAnalysis;
0c4df52e 3718 fAnalysis = NULL;
24f7a148 3719}
f3a97c86 3720
af885e0f 3721void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 3722{
3723 // Write space-points which are then used in the alignment procedures
6e65648b 3724 // For the moment only ITS, TPC, TRD and TOF
98937d93 3725
98937d93 3726 Int_t ntracks = esd->GetNumberOfTracks();
3727 for (Int_t itrack = 0; itrack < ntracks; itrack++)
3728 {
3729 AliESDtrack *track = esd->GetTrack(itrack);
3730 Int_t nsp = 0;
ef7253ac 3731 Int_t idx[200];
76741755 3732 for (Int_t i=0; i<200; ++i) idx[i] = -1; //PH avoid uninitialized values
81aa7a0d 3733 for (Int_t iDet = 5; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
0ad488b0 3734 nsp += (iDet==GetDetIndex("TRD")) ? track->GetTRDntracklets():track->GetNcls(iDet);
6e65648b 3735
0ad488b0 3736 if (iDet==GetDetIndex("ITS")) { // ITS "extra" clusters
6e65648b 3737 track->GetClusters(iDet,idx);
3738 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
3739 }
3740 }
3741
98937d93 3742 if (nsp) {
ddfbc51a 3743 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
98937d93 3744 track->SetTrackPointArray(sp);
3745 Int_t isptrack = 0;
81aa7a0d 3746 for (Int_t iDet = 5; iDet >= 0; iDet--) {
98937d93 3747 AliTracker *tracker = fTracker[iDet];
3748 if (!tracker) continue;
0ad488b0 3749 Int_t nspdet = (iDet==GetDetIndex("TRD")) ? track->GetTRDtracklets(idx):track->GetClusters(iDet,idx);
6e65648b 3750
0ad488b0 3751 if (iDet==GetDetIndex("ITS")) // ITS "extra" clusters
6e65648b 3752 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
3753
98937d93 3754 if (nspdet <= 0) continue;
98937d93 3755 AliTrackPoint p;
3756 Int_t isp = 0;
3757 Int_t isp2 = 0;
4ed6fb1c 3758 while (isp2 < nspdet) {
f3c6e4c9 3759 Bool_t isvalid=kTRUE;
3760
3761 Int_t index=idx[isp++];
3762 if (index < 0) continue;
3763
c12b6e44 3764 TString dets = fgkDetectorName[iDet];
3765 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
3766 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
3767 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
3768 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
f3c6e4c9 3769 isvalid = tracker->GetTrackPointTrackingError(index,p,track);
48ce48d1 3770 } else {
f3c6e4c9 3771 isvalid = tracker->GetTrackPoint(index,p);
48ce48d1 3772 }
3773 isp2++;
98937d93 3774 if (!isvalid) continue;
0ad488b0 3775 if (iDet==GetDetIndex("ITS") && (isp-1)>=6) p.SetExtra();
f3c6e4c9 3776 sp->AddPoint(isptrack,&p); isptrack++;
98937d93 3777 }
98937d93 3778 }
3779 }
3780 }
98937d93 3781}
2e3550da 3782
3783//_____________________________________________________________________________
af885e0f 3784void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 3785{
3786 // The method reads the raw-data error log
3787 // accumulated within the rawReader.
3788 // It extracts the raw-data errors related to
3789 // the current event and stores them into
3790 // a TClonesArray inside the esd object.
3791
3792 if (!fRawReader) return;
3793
3794 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
3795
3796 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
3797 if (!log) continue;
3798 if (iEvent != log->GetEventNumber()) continue;
3799
3800 esd->AddRawDataErrorLog(log);
3801 }
3802
3803}
46698ae4 3804
8661738e 3805//_____________________________________________________________________________
0a035be5 3806// void AliReconstruction::CheckQA()
3807// {
8661738e 3808// check the QA of SIM for this run and remove the detectors
3809// with status Fatal
3810
57acd2d2 3811// TString newRunLocalReconstruction ;
3812// TString newRunTracking ;
3813// TString newFillESD ;
3814//
4e25ac79 3815// for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
3816// TString detName(AliQAv1::GetDetName(iDet)) ;
3817// AliQAv1 * qa = AliQAv1::Instance(AliQAv1::DETECTORINDEX_t(iDet)) ;
3818// if ( qa->IsSet(AliQAv1::DETECTORINDEX_t(iDet), AliQAv1::kSIM, specie, AliQAv1::kFATAL)) {
57acd2d2 3819// AliInfo(Form("QA status for %s %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed",
3820// detName.Data(), AliRecoParam::GetEventSpecieName(es))) ;
3821// } else {
4e25ac79 3822// if ( fRunLocalReconstruction.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3823// fRunLocalReconstruction.Contains("ALL") ) {
3824// newRunLocalReconstruction += detName ;
3825// newRunLocalReconstruction += " " ;
3826// }
4e25ac79 3827// if ( fRunTracking.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3828// fRunTracking.Contains("ALL") ) {
3829// newRunTracking += detName ;
3830// newRunTracking += " " ;
3831// }
4e25ac79 3832// if ( fFillESD.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3833// fFillESD.Contains("ALL") ) {
3834// newFillESD += detName ;
3835// newFillESD += " " ;
3836// }
3837// }
3838// }
3839// fRunLocalReconstruction = newRunLocalReconstruction ;
3840// fRunTracking = newRunTracking ;
3841// fFillESD = newFillESD ;
0a035be5 3842// }
5b188f2f 3843
3844//_____________________________________________________________________________
3845Int_t AliReconstruction::GetDetIndex(const char* detector)
3846{
3847 // return the detector index corresponding to detector
3848 Int_t index = -1 ;
ac4a7581 3849 for (index = 0; index < kNDetectors ; index++) {
5b188f2f 3850 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
3851 break ;
3852 }
3853 return index ;
3854}
7167ae53 3855//_____________________________________________________________________________
3856Bool_t AliReconstruction::FinishPlaneEff() {
3857 //
3858 // Here execute all the necessary operationis, at the end of the tracking phase,
d7f8fd68 3859 // in case that evaluation of PlaneEfficiencies was required for some detector.
3860 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
7167ae53 3861 //
3862 // This Preliminary version works only FOR ITS !!!!!
3863 // other detectors (TOF,TRD, etc. have to develop their specific codes)
3864 //
3865 // Input: none
d7f8fd68 3866 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
7167ae53 3867 //
3868 Bool_t ret=kFALSE;
5ee13eb5 3869 TString detStr = fLoadCDB;
58e8dc31 3870 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
d7f8fd68 3871 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
5ee13eb5 3872 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
58e8dc31 3873 if(fTracker[iDet] && fTracker[iDet]->GetPlaneEff()) {
d7f8fd68 3874 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
3875 TString name=planeeff->GetName();
3876 name+=".root";
3877 TFile* pefile = TFile::Open(name, "RECREATE");
3878 ret=(Bool_t)planeeff->Write();
3879 pefile->Close();
5fbd4fd6 3880 if(planeeff->GetCreateHistos()) {
d7f8fd68 3881 TString hname=planeeff->GetName();
3882 hname+="Histo.root";
3883 ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
5fbd4fd6 3884 }
3885 }
58e8dc31 3886 if(fSPDTrackleter) {
3887 AliPlaneEff *planeeff=fSPDTrackleter->GetPlaneEff();
3888 TString name="AliITSPlaneEffSPDtracklet.root";
3889 TFile* pefile = TFile::Open(name, "RECREATE");
3890 ret=(Bool_t)planeeff->Write();
3891 pefile->Close();
3892 AliESDEvent *dummy=NULL;
3893 ret=(Bool_t)fSPDTrackleter->PostProcess(dummy); // take care of writing other files
3894 }
7167ae53 3895 }
3896 return ret;
3897}
3898//_____________________________________________________________________________
3899Bool_t AliReconstruction::InitPlaneEff() {
3900//
3901 // Here execute all the necessary operations, before of the tracking phase,
3902 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
58e8dc31 3903 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
7167ae53 3904 // which should be updated/recalculated.
3905 //
3906 // This Preliminary version will work only FOR ITS !!!!!
3907 // other detectors (TOF,TRD, etc. have to develop their specific codes)
3908 //
3909 // Input: none
3910 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
3911 //
58e8dc31 3912
3913 fSPDTrackleter = NULL;
b8604b34 3914 TString detStr = fLoadCDB;
3915 if (IsSelected(fgkDetectorName[0], detStr)) {
3916 AliReconstructor* itsReconstructor = GetReconstructor(0);
3917 if (itsReconstructor) {
3918 fSPDTrackleter = itsReconstructor->CreateTrackleter(); // this is NULL unless required in RecoParam
3919 }
3920 if (fSPDTrackleter) {
3921 AliInfo("Trackleter for SPD has been created");
3922 }
58e8dc31 3923 }
7167ae53 3924 return kTRUE;
7520312d 3925}
14dd053c 3926
3927//_____________________________________________________________________________
3928Bool_t AliReconstruction::InitAliEVE()
3929{
3930 // This method should be called only in case
3931 // AliReconstruction is run
3932 // within the alieve environment.
3933 // It will initialize AliEVE in a way
3934 // so that it can visualize event processed
3935 // by AliReconstruction.
3936 // The return flag shows whenever the
3937 // AliEVE initialization was successful or not.
3938
f3664c51 3939 TString macroStr(getenv("ALIEVE_ONLINE_MACRO"));
5239ebd6 3940
3941 if (macroStr.IsNull())
3942 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
3943
3944 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
3945
14dd053c 3946 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
3947
6a840f1e 3948 gROOT->ProcessLine("if (!AliEveEventManager::GetMaster()){new AliEveEventManager();AliEveEventManager::GetMaster()->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(AliEveEventManager::GetMaster());};");
de33999e 3949 gROOT->ProcessLine("alieve_online_init()");
14dd053c 3950
3951 return kTRUE;
3952}
3953
3954//_____________________________________________________________________________
3955void AliReconstruction::RunAliEVE()
3956{
3957 // Runs AliEVE visualisation of
3958 // the current event.
3959 // Should be executed only after
3960 // successful initialization of AliEVE.
3961
3962 AliInfo("Running AliEVE...");
72c084a0 3963 gROOT->ProcessLine(Form("AliEveEventManager::GetMaster()->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p,(AliESDfriend*)%p);",fRunLoader,fRawReader,fesd,fesdf));
14dd053c 3964 gSystem->Run();
3965}
ce43afbe 3966
3967//_____________________________________________________________________________
3968Bool_t AliReconstruction::SetRunQA(TString detAndAction)
3969{
3970 // Allows to run QA for a selected set of detectors
44ed7a66 3971 // and a selected set of tasks among RAWS, DIGITSR, RECPOINTS and ESDS
ce43afbe 3972 // all selected detectors run the same selected tasks
3973
3974 if (!detAndAction.Contains(":")) {
3975 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
3976 fRunQA = kFALSE ;
3977 return kFALSE ;
3978 }
3979 Int_t colon = detAndAction.Index(":") ;
3980 fQADetectors = detAndAction(0, colon) ;
59b1e631 3981 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
ce43afbe 3982 if (fQATasks.Contains("ALL") ) {
44ed7a66 3983 fQATasks = Form("%d %d %d %d", AliQAv1::kRAWS, AliQAv1::kDIGITSR, AliQAv1::kRECPOINTS, AliQAv1::kESDS) ;
ce43afbe 3984 } else {
3985 fQATasks.ToUpper() ;
3986 TString tempo("") ;
3987 if ( fQATasks.Contains("RAW") )
4e25ac79 3988 tempo = Form("%d ", AliQAv1::kRAWS) ;
44ed7a66 3989 if ( fQATasks.Contains("DIGIT") )
3990 tempo += Form("%d ", AliQAv1::kDIGITSR) ;
ce43afbe 3991 if ( fQATasks.Contains("RECPOINT") )
4e25ac79 3992 tempo += Form("%d ", AliQAv1::kRECPOINTS) ;
ce43afbe 3993 if ( fQATasks.Contains("ESD") )
4e25ac79 3994 tempo += Form("%d ", AliQAv1::kESDS) ;
ce43afbe 3995 fQATasks = tempo ;
3996 if (fQATasks.IsNull()) {
3997 AliInfo("No QA requested\n") ;
3998 fRunQA = kFALSE ;
3999 return kTRUE ;
4000 }
4001 }
4002 TString tempo(fQATasks) ;
4e25ac79 4003 tempo.ReplaceAll(Form("%d", AliQAv1::kRAWS), AliQAv1::GetTaskName(AliQAv1::kRAWS)) ;
44ed7a66 4004 tempo.ReplaceAll(Form("%d", AliQAv1::kDIGITSR), AliQAv1::GetTaskName(AliQAv1::kDIGITSR)) ;
4e25ac79 4005 tempo.ReplaceAll(Form("%d", AliQAv1::kRECPOINTS), AliQAv1::GetTaskName(AliQAv1::kRECPOINTS)) ;
4006 tempo.ReplaceAll(Form("%d", AliQAv1::kESDS), AliQAv1::GetTaskName(AliQAv1::kESDS)) ;
ce43afbe 4007 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
4008 fRunQA = kTRUE ;
4009 return kTRUE;
4010}
4011
7e88424f 4012//_____________________________________________________________________________
4013Bool_t AliReconstruction::InitRecoParams()
4014{
4015 // The method accesses OCDB and retrieves all
4016 // the available reco-param objects from there.
4017
4018 Bool_t isOK = kTRUE;
4019
8b26452d 4020 if (fRecoParam.GetDetRecoParamArray(kNDetectors)) {
4021 AliInfo("Using custom GRP reconstruction parameters");
4022 }
4023 else {
4024 AliInfo("Loading GRP reconstruction parameter objects");
4025
4026 AliCDBPath path("GRP","Calib","RecoParam");
4027 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
4028 if(!entry){
4029 AliWarning("Couldn't find GRP RecoParam entry in OCDB");
4030 isOK = kFALSE;
4031 }
4032 else {
4033 TObject *recoParamObj = entry->GetObject();
4034 if (dynamic_cast<TObjArray*>(recoParamObj)) {
4035 // GRP has a normal TobjArray of AliDetectorRecoParam objects
4036 // Registering them in AliRecoParam
4037 fRecoParam.AddDetRecoParamArray(kNDetectors,dynamic_cast<TObjArray*>(recoParamObj));
4038 }
4039 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
4040 // GRP has only onse set of reco parameters
4041 // Registering it in AliRecoParam
4042 AliInfo("Single set of GRP reconstruction parameters found");
4043 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
4044 fRecoParam.AddDetRecoParam(kNDetectors,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
4045 }
4046 else {
4047 AliError("No valid GRP RecoParam object found in the OCDB");
4048 isOK = kFALSE;
4049 }
4050 entry->SetOwner(0);
4051 }
4052 }
4053
7d566c20 4054 TString detStr = fLoadCDB;
ac4a7581 4055 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
7e88424f 4056
7d566c20 4057 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
4058
7e88424f 4059 if (fRecoParam.GetDetRecoParamArray(iDet)) {
4060 AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
4061 continue;
4062 }
4063
ac232c75 4064 AliInfo(Form("Loading reconstruction parameter objects for detector %s",fgkDetectorName[iDet]));
7e88424f 4065
4066 AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
4067 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
4068 if(!entry){
4069 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
4070 isOK = kFALSE;
4071 }
4072 else {
4073 TObject *recoParamObj = entry->GetObject();
4074 if (dynamic_cast<TObjArray*>(recoParamObj)) {
4075 // The detector has a normal TobjArray of AliDetectorRecoParam objects
4076 // Registering them in AliRecoParam
4077 fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
4078 }
4079 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
4080 // The detector has only onse set of reco parameters
4081 // Registering it in AliRecoParam
ac232c75 4082 AliInfo(Form("Single set of reconstruction parameters found for detector %s",fgkDetectorName[iDet]));
7e88424f 4083 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
4084 fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
4085 }
4086 else {
4087 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
4088 isOK = kFALSE;
4089 }
4090 entry->SetOwner(0);
f168abba 4091 // FIX ME: We have to disable the unloading of reco-param CDB
4092 // entries because QA framework is using them. Has to be fix in
4093 // a way that the QA takes the objects already constructed in
4094 // this method.
4095 // AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
7e88424f 4096 }
4097 }
4098
e30a9b4d 4099 if (AliDebugLevel() > 0) fRecoParam.Print();
ac232c75 4100
7e88424f 4101 return isOK;
4102}
4103
4104//_____________________________________________________________________________
4105Bool_t AliReconstruction::GetEventInfo()
4106{
4107 // Fill the event info object
4108 // ...
52dd4a8c 4109 AliCodeTimerAuto("",0)
7e88424f 4110
4111 AliCentralTrigger *aCTP = NULL;
4112 if (fRawReader) {
4113 fEventInfo.SetEventType(fRawReader->GetType());
4114
4115 ULong64_t mask = fRawReader->GetClassMask();
f4332838 4116 ULong64_t maskNext50 = fRawReader->GetClassMaskNext50();
7e88424f 4117 fEventInfo.SetTriggerMask(mask);
f4332838 4118 fEventInfo.SetTriggerMaskNext50(maskNext50);
7e88424f 4119 UInt_t clmask = fRawReader->GetDetectorPattern()[0];
4120 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
4121
4122 aCTP = new AliCentralTrigger();
4123 TString configstr("");
4124 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
4125 AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
4126 delete aCTP;
4127 return kFALSE;
4128 }
4129 aCTP->SetClassMask(mask);
4130 aCTP->SetClusterMask(clmask);
5b3ea9c5 4131
532fe099 4132 if (fRunLoader) {
4133 AliCentralTrigger* rlCTP = fRunLoader->GetTrigger();
4134 if (rlCTP) {
4135 rlCTP->SetClassMask(mask);
4136 rlCTP->SetClusterMask(clmask);
4137 }
173b7e07 4138 }
7e88424f 4139 }
4140 else {
4141 fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
4142
4143 if (fRunLoader && (!fRunLoader->LoadTrigger())) {
4144 aCTP = fRunLoader->GetTrigger();
4145 fEventInfo.SetTriggerMask(aCTP->GetClassMask());
f4332838 4146 fEventInfo.SetTriggerMaskNext50(aCTP->GetClassMaskNext50());
e61ed4b1 4147 // get inputs from actp - just get
4148 AliESDHeader* esdheader = fesd->GetHeader();
4149 esdheader->SetL0TriggerInputs(aCTP->GetL0TriggerInputs());
4150 esdheader->SetL1TriggerInputs(aCTP->GetL1TriggerInputs());
4151 esdheader->SetL2TriggerInputs(aCTP->GetL2TriggerInputs());
7e88424f 4152 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
4153 }
4154 else {
07472556 4155 if (fStopOnMissingTriggerFile) AliFatal("No trigger can be loaded! Stopping reconstruction!");
7e88424f 4156 AliWarning("No trigger can be loaded! The trigger information will not be used!");
4157 return kFALSE;
4158 }
4159 }
4160
4161 AliTriggerConfiguration *config = aCTP->GetConfiguration();
4162 if (!config) {
4163 AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
4164 if (fRawReader) delete aCTP;
4165 return kFALSE;
4166 }
4167
5dfb32c1 4168 // Load trigger aliases and declare the trigger classes included in aliases
3a5bd3f5 4169 //PH Why do we do it in each event and not only once in the beginning of the chunk??
4170 //PH Temporary fix for #99725: AliReconstruction::GetEventInfo bug
4171 fDeclTriggerClasses.Clear();
5dfb32c1 4172 AliCDBEntry * entry = AliCDBManager::Instance()->Get("GRP/CTP/Aliases");
4173 if (entry) {
4174 THashList * lst = dynamic_cast<THashList*>(entry->GetObject());
5dfb32c1 4175 if (lst) {
34e67a0e 4176 lst->Sort(kSortDescending); // to avoid problems with substrungs
5dfb32c1 4177 if (fRawReader) fRawReader->LoadTriggerAlias(lst);
4178 // Now declare all the triggers present in the aliases
4179 TIter iter(lst);
4180 TNamed *nmd = 0;
4181 while((nmd = dynamic_cast<TNamed*>(iter.Next()))){
4182 fDeclTriggerClasses += " ";
4183 fDeclTriggerClasses += nmd->GetName();
4184 }
4185 }
4186 else {
4187 AliError("Cannot cast the object with trigger aliases to THashList!");
4188 }
4189 }
4190 else {
4191 AliError("No OCDB ebtry for the trigger aliases!");
4192 }
4193 // Load trigger classes for this run
a0c2cf2d 4194 UChar_t clustmask = 0;
7e88424f 4195 TString trclasses;
4196 ULong64_t trmask = fEventInfo.GetTriggerMask();
4197 const TObjArray& classesArray = config->GetClasses();
4198 Int_t nclasses = classesArray.GetEntriesFast();
4199 for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
4200 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
a2ec4f82 4201 if (trclass && trclass->GetMask()>0) {
a4b0683d 4202 Int_t trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
532fe099 4203 if (fesd) fesd->SetTriggerClass(trclass->GetName(),trindex);
8a933107 4204 if (fRawReader) fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
e61ed4b1 4205 if (trmask & (1ull << trindex)) {
7e88424f 4206 trclasses += " ";
4207 trclasses += trclass->GetName();
4208 trclasses += " ";
a0c2cf2d 4209 clustmask |= trclass->GetCluster()->GetClusterMask();
7e88424f 4210 }
4211 }
4212 }
4213 fEventInfo.SetTriggerClasses(trclasses);
764daca3 4214 // Now put the declared trigger classes (not present in the run)
4215 // to 0/false in the event selection
4216 if (!fDeclTriggerClasses.IsNull()) {
4217 TObjArray *tokens = fDeclTriggerClasses.Tokenize(" ");
4218 Int_t ntokens = tokens->GetEntriesFast();
4219 for (Int_t itoken = 0; itoken < ntokens; ++itoken) {
4220 if (fRawReader) fRawReader->LoadTriggerClass((((TObjString*)tokens->At(itoken))->String()).Data(),-1);
4221 }
4222 delete tokens;
4223 }
7e88424f 4224
6ef9caeb 4225 // Write names of active trigger inputs in ESD Header
4226 const TObjArray& inputsArray = config->GetInputs();
4227 Int_t ninputs = inputsArray.GetEntriesFast();
4228 for( Int_t iinput=0; iinput < ninputs; iinput++ ) {
4229 AliTriggerInput* trginput = (AliTriggerInput*)inputsArray.At(iinput);
a2ec4f82 4230 if (trginput && trginput->GetMask()>0) {
6ef9caeb 4231 Int_t inputIndex = (Int_t)TMath::Nint(TMath::Log2(trginput->GetMask()));
532fe099 4232 AliESDHeader* headeresd = 0x0;
4233 if (fesd) headeresd = fesd->GetHeader();
4234 if (headeresd) {
4235 Int_t trglevel = (Int_t)trginput->GetLevel();
4236 if (trglevel == 0) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex);
4237 if (trglevel == 1) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+24);
4238 if (trglevel == 2) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+48);
4239 }
6ef9caeb 4240 }
4241 }
4242
a0c2cf2d 4243 // Set the information in ESD
532fe099 4244 if (fesd) {
4245 fesd->SetTriggerMask(trmask);
4246 fesd->SetTriggerCluster(clustmask);
4247 }
a0c2cf2d 4248
7e88424f 4249 if (!aCTP->CheckTriggeredDetectors()) {
4250 if (fRawReader) delete aCTP;
4251 return kFALSE;
4252 }
4253
4254 if (fRawReader) delete aCTP;
4255
4256 // We have to fill also the HLT decision here!!
4257 // ...
4258
4259 return kTRUE;
4260}
4261
4262const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
4263{
4264 // Match the detector list found in the rec.C or the default 'ALL'
4265 // to the list found in the GRP (stored there by the shuttle PP which
4266 // gets the information from ECS)
4267 static TString resultList;
4268 TString detList = detectorList;
4269
4270 resultList = "";
4271
4272 for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
4273 if ((detectorMask >> iDet) & 0x1) {
4274 TString det = AliDAQ::OfflineModuleName(iDet);
4275 if ((detList.CompareTo("ALL") == 0) ||
a101e1dd 4276 ((detList.BeginsWith("ALL ") ||
4277 detList.EndsWith(" ALL") ||
4278 detList.Contains(" ALL ")) &&
4279 !(detList.BeginsWith("-"+det+" ") ||
4280 detList.EndsWith(" -"+det) ||
4281 detList.Contains(" -"+det+" "))) ||
7e88424f 4282 (detList.CompareTo(det) == 0) ||
a101e1dd 4283 detList.BeginsWith(det+" ") ||
4284 detList.EndsWith(" "+det) ||
7e88424f 4285 detList.Contains( " "+det+" " )) {
4286 if (!resultList.EndsWith(det + " ")) {
4287 resultList += det;
4288 resultList += " ";
4289 }
4290 }
4291 }
4292 }
4293
4294 // HLT
4295 if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
4296 TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
4297 if ((detList.CompareTo("ALL") == 0) ||
a101e1dd 4298 ((detList.BeginsWith("ALL ") ||
4299 detList.EndsWith(" ALL") ||
4300 detList.Contains(" ALL ")) &&
4301 !(detList.BeginsWith("-"+hltDet+" ") ||
4302 detList.EndsWith(" -"+hltDet) ||
4303 detList.Contains(" -"+hltDet+" "))) ||
7e88424f 4304 (detList.CompareTo(hltDet) == 0) ||
a101e1dd 4305 detList.BeginsWith(hltDet+" ") ||
4306 detList.EndsWith(" "+hltDet) ||
7e88424f 4307 detList.Contains( " "+hltDet+" " )) {
4308 resultList += hltDet;
4309 }
4310 }
4311
4312 return resultList.Data();
4313
4314}
4b71572b 4315
4316//______________________________________________________________________________
4317void AliReconstruction::Abort(const char *method, EAbort what)
4318{
4319 // Abort processing. If what = kAbortProcess, the Process() loop will be
4320 // aborted. If what = kAbortFile, the current file in a chain will be
4321 // aborted and the processing will continue with the next file, if there
4322 // is no next file then Process() will be aborted. Abort() can also be
4323 // called from Begin(), SlaveBegin(), Init() and Notify(). After abort
4324 // the SlaveTerminate() and Terminate() are always called. The abort flag
4325 // can be checked in these methods using GetAbort().
4326 //
4327 // The method is overwritten in AliReconstruction for better handling of
4328 // reco specific errors
4329
4330 if (!fStopOnError) return;
4331
4332 CleanUp();
4333
4334 TString whyMess = method;
4335 whyMess += " failed! Aborting...";
4336
4337 AliError(whyMess.Data());
4338
4339 fAbort = what;
4340 TString mess = "Abort";
4341 if (fAbort == kAbortProcess)
4342 mess = "AbortProcess";
4343 else if (fAbort == kAbortFile)
4344 mess = "AbortFile";
4345
6ac1d1f4 4346 Info(mess.Data(), "%s", whyMess.Data());
4b71572b 4347}
4348
2f954aba 4349//______________________________________________________________________________
4350Bool_t AliReconstruction::ProcessEvent(void* event)
4351{
4352 // Method that is used in case the event loop
4353 // is steered from outside, for example by AMORE
4354 // 'event' is a pointer to the DATE event in the memory
4355
4356 if (fRawReader) delete fRawReader;
4357 fRawReader = new AliRawReaderDate(event);
4358 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
4359 delete fRawReader;
4360 fRawReader = NULL;
4361
4362 return fStatus;
4363}
81d57268 4364
4365//______________________________________________________________________________
4366Bool_t AliReconstruction::ParseOutput()
4367{
4368 // The method parses the output file
4369 // location string in order to steer
4370 // properly the selector
4371
4372 TPMERegexp re1("(\\w+\\.zip#\\w+\\.root):([,*\\w+\\.root,*]+)@dataset://(\\w++)");
4373 TPMERegexp re2("(\\w+\\.root)?@?dataset://(\\w++)");
4374
4375 if (re1.Match(fESDOutput) == 4) {
4376 // root archive with output files stored and regustered
4377 // in proof dataset
4378 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",re1[1].Data()));
4379 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re1[3].Data()));
4380 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
4381 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_ARCHIVE",re1[2].Data()));
4382 AliInfo(Form("%s files will be stored within %s in dataset %s",
4383 re1[2].Data(),
4384 re1[1].Data(),
4385 re1[3].Data()));
4386 }
4387 else if (re2.Match(fESDOutput) == 3) {
4388 // output file stored and registered
4389 // in proof dataset
4390 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",(re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data()));
4391 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re2[2].Data()));
4392 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
4393 AliInfo(Form("%s will be stored in dataset %s",
4394 (re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data(),
4395 re2[2].Data()));
4396 }
4397 else {
4398 if (fESDOutput.IsNull()) {
4399 // Output location not given.
4400 // Assuming xrootd has been already started and
4401 // the output file has to be sent back
4402 // to the client machine
4403 TString esdUrl(Form("root://%s/%s/",
4404 TUrl(gSystem->HostName()).GetHostFQDN(),
4405 gSystem->pwd()));
4406 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE","AliESDs.root"));
4407 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",esdUrl.Data()));
4408 AliInfo(Form("AliESDs.root will be stored in %s",
4409 esdUrl.Data()));
4410 }
4411 else {
4412 // User specified an output location.
4413 // Ones has just to parse it here
4414 TUrl outputUrl(fESDOutput.Data());
4415 TString outputFile(gSystem->BaseName(outputUrl.GetFile()));
4416 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",outputFile.IsNull() ? "AliESDs.root" : outputFile.Data()));
4417 TString outputLocation(outputUrl.GetUrl());
4418 outputLocation.ReplaceAll(outputFile.Data(),"");
4419 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",outputLocation.Data()));
4420 AliInfo(Form("%s will be stored in %s",
4421 outputFile.IsNull() ? "AliESDs.root" : outputFile.Data(),
4422 outputLocation.Data()));
4423 }
4424 }
4425
4426 return kTRUE;
4427}
f00558b6 4428
4429//______________________________________________________________________________
4430Bool_t AliReconstruction::IsHighPt() const {
4431 // Selection of events containing "high" pT tracks
4432 // If at least one track is found within 1.5 and 100 GeV (pT)
4433 // that was reconstructed by both ITS and TPC, the event is accepted
4434
4435 // Track cuts
f00558b6 4436 const Double_t pTmin = 1.5;
4437 const Double_t pTmax = 100;
4438 ULong_t mask = 0;
4439 mask |= (AliESDtrack::kITSrefit);
4440 mask |= (AliESDtrack::kTPCrefit);
a307e234 4441 const Double_t pTminCosmic = 5.;
4442 const Double_t pTmaxCosmic = 100;
4443 ULong_t maskCosmic = 0;
d0fc0a32 4444 Int_t cosmicCount=0;
a307e234 4445 maskCosmic |= (AliESDtrack::kTPCrefit);
f00558b6 4446
4447 Bool_t isOK = kFALSE;
4448
4449 if (fesd && fesd->GetEventType()==AliRawEventHeaderBase::kPhysicsEvent) {
4450 // Check if this ia a physics event (code 7)
4451 Int_t ntrk = fesd->GetNumberOfTracks();
4452 for (Int_t itrk=0; itrk<ntrk; ++itrk) {
4453
4454 AliESDtrack * trk = fesd->GetTrack(itrk);
4455 if (trk
4456 && trk->Pt() > pTmin
4457 && trk->Pt() < pTmax
4458 && (trk->GetStatus() & mask) == mask ) {
4459
4460 isOK = kTRUE;
4461 break;
4462 }
a307e234 4463 if (trk
4464 && trk->GetInnerParam()
4465 && trk->GetInnerParam()->Pt() > pTminCosmic
4466 && trk->GetInnerParam()->Pt() < pTmaxCosmic
4467 && (trk->GetStatus() & maskCosmic) == maskCosmic ) {
4468
d0fc0a32 4469 cosmicCount++;
a307e234 4470 break;
4471 }
f00558b6 4472 }
d0fc0a32 4473 if (cosmicCount>1) isOK=kTRUE;
f00558b6 4474 }
4475 return isOK;
4476}
4477
4478//______________________________________________________________________________
4479Bool_t AliReconstruction::IsCosmicOrCalibSpecie() const {
4480 // Select cosmic or calibration events
4481
4482 Bool_t isOK = kFALSE;
4483
4484 if (fesd && fesd->GetEventType()==AliRawEventHeaderBase::kPhysicsEvent) {
4485 // Check if this ia a physics event (code 7)
4486
4487 UInt_t specie = fesd->GetEventSpecie();
4488 if (specie==AliRecoParam::kCosmic || specie==AliRecoParam::kCalib) {
4489 isOK = kTRUE;
4490 }
4491 }
4492 return isOK;
4493}
4494
4495//______________________________________________________________________________
4496void AliReconstruction::WriteESDfriend() {
4497 // Fill the ESD friend in the tree. The required fraction of ESD friends is stored
4498 // in fFractionFriends. We select events where we store the ESD friends according
4499 // to the following algorithm:
4500 // 1. Store all Cosmic or Calibration events within the required fraction
4501 // 2. Sample "high Pt" events within the remaining fraction after step 1.
4502 // 3. Sample randomly events if we still have remaining slot
ddfbc51a 4503
f00558b6 4504 fNall++;
f00558b6 4505 Bool_t isSelected = kFALSE;
d0fc0a32 4506 //
4507 // Store all friends for B field OFF
4508 if (TMath::Abs(AliTrackerBase::GetBz())<0.5) isSelected=kTRUE;
f00558b6 4509
4510 if (IsCosmicOrCalibSpecie()) { // Selection of calib or cosmic events
4511 fNspecie++;
0623e625 4512
4513 isSelected = kTRUE;
4514 fSspecie++;
f00558b6 4515 }
4516
4517 Double_t remainingFraction = fFractionFriends;
4518 remainingFraction -= ((Double_t)(fSspecie)/(Double_t)(fNall));
4519
4520 if (IsHighPt()) { // Selection of "high Pt" events
4521 fNhighPt++;
4522 Double_t curentHighPtFraction = ((Double_t)(fNhighPt+1))/((Double_t)(fNall+1));
4523 // "Bayesian" estimate supposing that without events all the events are of the required type
4524
4525 if (!isSelected) {
4526 Double_t rnd = gRandom->Rndm()*curentHighPtFraction;
4527 if (rnd<remainingFraction) {
4528 isSelected = kTRUE;
4529 fShighPt++;
4530 }
4531 }
4532 }
4533 remainingFraction -= ((Double_t)(fShighPt)/(Double_t)(fNall));
4534
4535 // Random selection to fill the remaining fraction (if any)
4536 if (!isSelected) {
4537 Double_t rnd = gRandom->Rndm();
4538 if (rnd<remainingFraction) {
4539 isSelected = kTRUE;
4540 }
4541 }
ddfbc51a 4542
f00558b6 4543 if (!isSelected) {
ddfbc51a 4544 fesdf->~AliESDfriend();
4545 new (fesdf) AliESDfriend(); // Reset...
f00558b6 4546 fesdf->SetSkipBit(kTRUE);
4547 }
e54c9180 4548 //
5ee8b64f 4549 Long64_t nbf = ftreeF->Fill();
4550 if (fTreeBuffSize>0 && ftreeF->GetAutoFlush()<0 && (fMemCountESDF += nbf)>fTreeBuffSize ) { // default limit is still not reached
4551 nbf = ftreeF->GetZipBytes();
4552 if (nbf>0) nbf = -nbf;
4553 else nbf = ftreeF->GetEntries();
4554 ftreeF->SetAutoFlush(nbf);
4555 AliInfo(Form("Calling ftreeF->SetAutoFlush(%lld) | W:%lld T:%lld Z:%lld",
4556 nbf,fMemCountESDF,ftreeF->GetTotBytes(),ftreeF->GetZipBytes()));
4557 }
4558
f00558b6 4559}
e54c9180 4560
4561//_________________________________________________________________
4562void AliReconstruction::DeleteDigits(const TString& detectors)
4563{
4564 // delete requested digit files produced at current event
4565 static int iEvent = 0;
4566 if (detectors.IsNull()) return;
4567 TString detStr = detectors;
4568 AliInfo(Form("Deleting Digits: %s",detectors.Data()));
4569
4570 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
a17b41cb 4571 if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
f3664c51 4572 unlink(Form("%s.Digits.root",fgkDetectorName[iDet]));
e54c9180 4573 }
4574 AliSysInfo::AddStamp(Form("DelDigits_%d",iEvent), 0,0,iEvent);
4575 iEvent++;
4576}
4577
4578//_________________________________________________________________
4579void AliReconstruction::DeleteRecPoints(const TString& detectors)
4580{
4581 // delete requested recpoint files produced at current event
4582 static int iEvent = 0;
4583 if (detectors.IsNull()) return;
4584 TString detStr = detectors;
4585 AliInfo(Form("Deleting Recpoints: %s",detectors.Data()));
4586 //
4587 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
a17b41cb 4588 if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
f3664c51 4589 unlink(Form("%s.RecPoints.root",fgkDetectorName[iDet]));
e54c9180 4590 }
4591 AliSysInfo::AddStamp(Form("DelRecPoints_%d",iEvent), 0,0,iEvent);
4592 iEvent++;
4593}
30b916f7 4594
4595//_________________________________________________________________
4596void AliReconstruction::SetStopOnResourcesExcess(Int_t vRSS,Int_t vVMEM)
4597{
4598 // require checking the resources left and stopping on excess
4599 // if 0 : no check is done
4600 // if >0 : stop reconstruction if exceeds this value
4601 // if <0 : use as margin to system limits
4602 //
4603 const int kKB2MB = 1024;
4604 const int kInfMem = 9999999;
4605 //
4606 struct rlimit r;
4607 int pgSize = getpagesize();
4608 //
4609 if (vRSS>0) {
4610 fMaxRSS = vRSS;
4611 AliInfo(Form("Setting max. RSS usage to user value %d MB",fMaxRSS));
4612 }
4613 else if (vRSS<0) {
4614 getrlimit(RLIMIT_RSS,&r);
4615 fMaxRSS = r.rlim_max==RLIM_INFINITY ? kInfMem : int(r.rlim_max*pgSize/kKB2MB/kKB2MB) + vRSS;
4616 AliInfo(Form("Setting max. RSS usage to system hard limit %d%s MB (%d margin)",fMaxRSS,r.rlim_max==RLIM_INFINITY ? "(inf)":"",-vRSS));
4617 }
4618 else {AliInfo("No check on RSS memory usage will be applied");}
4619 //
4620 if (vVMEM>0) {
4621 fMaxVMEM = vVMEM;
4622 AliInfo(Form("Setting max. VMEM usage to user value %d MB",fMaxVMEM));
4623 }
4624 else if (vVMEM<0) {
4625 getrlimit(RLIMIT_AS,&r);
4626 fMaxVMEM = r.rlim_max==RLIM_INFINITY ? kInfMem : int(r.rlim_max*pgSize/kKB2MB/kKB2MB) + vVMEM;
4627 AliInfo(Form("Setting max. VMEM usage to system hard limit %d%s MB (%d margin)",fMaxVMEM,r.rlim_max==RLIM_INFINITY ? "(inf)":"",-vVMEM));
4628 }
4629 else {AliInfo("No check on RSS memory usage will be applied");}
4630 //
4631}
4632
4633//_________________________________________________________________
4634Bool_t AliReconstruction::HasEnoughResources(int ev)
4635{
4636 // check if process consumed more than allowed resources
4637 const int kKB2MB = 1024;
4638 Bool_t res = kTRUE;
4639 if (!fMaxRSS && !fMaxVMEM) return res;
4640 //
4641 ProcInfo_t procInfo;
4642 gSystem->GetProcInfo(&procInfo);
4643 if (procInfo.fMemResident/kKB2MB > fMaxRSS) res = kFALSE;
4644 if (procInfo.fMemVirtual/kKB2MB > fMaxVMEM) res = kFALSE;
4645 //
4646 if (!res) {
4647 AliInfo(Form("Job exceeded allowed limits: RSS:%d (%d) VMEM:%d (%d), will stop",
4648 int(procInfo.fMemResident/kKB2MB),fMaxRSS,
4649 int(procInfo.fMemVirtual/kKB2MB) ,fMaxVMEM));
4650 //
f3664c51 4651 unlink(Form("%s",fgkStopEvFName));
4652 ofstream outfile(fgkStopEvFName);
2ad98fc5 4653 outfile << ev << std::endl;
f3664c51 4654 outfile.close();
30b916f7 4655 fStopped = kTRUE;
4656 }
4657 return res;
4658}
7e0cf530 4659
4660Bool_t AliReconstruction::HasNextEventAfter(Int_t eventId)
4661{
4662 return ( (eventId < fRunLoader->GetNumberOfEvents()) ||
4663 (fRawReader && fRawReader->NextEvent()) );
4664}
92258ce2 4665
4666//_________________________________________________________________
4667void AliReconstruction::CheckRecoCDBvsSimuCDB()
4668{
4669 // if some CDB entries must be the same in the simulation
4670 // and reconstruction, check here
4671 int nent = fCheckRecoCDBvsSimuCDB.GetEntriesFast();
4672 AliInfo(Form("Check %d entries for matching between sim and rec",nent));
4673 //
4674 // get simulation CDB
4675 fRunLoader->CdGAFile();
4676 TMap* cdbMapSim = (TMap*)gDirectory->Get("cdbMap");
4677 TList* cdbListSim = (TList*)gDirectory->Get("cdbList");
4678 if (!(cdbMapSim && cdbListSim)) {
4679 AliInfo(Form("No CDBMap/List found in %s, nothing to check",fGAliceFileName.Data()));
4680 return;
4681 }
4682 // read the requested objects to make sure they will appear in the reco list
4683 for (Int_t i=0;i<nent;i++) {
4684 TNamed* cdbent = (TNamed*) fCheckRecoCDBvsSimuCDB[i];
4685 if (!cdbent) continue;
4686 AliCDBManager::Instance()->Get(cdbent->GetName());
4687 }
4688 // get default path for simulation
4689 TPair* pair;
4690 TObjString* stro;
4691 pair = (TPair*)cdbMapSim->FindObject("default");
4692 if (!pair) {AliFatal("Did not find default storage used for simulations"); return;}
4693 TString defSimStore = ((TObjString*)pair->Value())->GetString();
4694 RectifyCDBurl(defSimStore);
4695 //
4696 // get reconstruction CDB
4697 const TMap *cdbMapRec = AliCDBManager::Instance()->GetStorageMap();
0c460d65 4698 const TList *cdbListRec = AliCDBManager::Instance()->GetRetrievedIds();
92258ce2 4699 //
4700 // get default path for reconstruction
4701 pair = (TPair*)cdbMapRec->FindObject("default");
4702 if (!pair) {AliFatal("Did not find default storage used for reconstruction"); return;}
4703 TString defRecStore = ((TObjString*)pair->Value())->GetString();
4704 RectifyCDBurl(defRecStore);
4705 //
4706 for (Int_t i=0;i<nent;i++) {
4707 TNamed* cdbent = (TNamed*) fCheckRecoCDBvsSimuCDB[i];
4708 if (!cdbent) continue;
4709 //
4710 AliInfo(Form("#%d Checking %s",i,cdbent->GetName()));
4711 //
7ad7315a 4712 // find cdbID used for sim
4713 TString idSim="",storSim="";
4714 TIter nextSim(cdbListSim);
4715 while ((stro=(TObjString*)nextSim())) {
4716 if (stro->GetString().Contains(cdbent->GetName())) {
4717 idSim = stro->GetString();
4718 break;
4719 }
4720 }
4721 // find the storage used for sim
4722 // check in the simuCDB special paths
92258ce2 4723 pair = (TPair*)cdbMapSim->FindObject(cdbent->GetName());
92258ce2 4724 if (pair) { // specific path is used
7ad7315a 4725 storSim = ((TObjString*)pair->Value())->GetString();
4726 RectifyCDBurl(storSim);
92258ce2 4727 }
7ad7315a 4728 else storSim = defSimStore; // default storage list is used
4729 //
4730 if (!idSim.IsNull()) AliInfo(Form("Sim. used %s from %s",idSim.Data(), storSim.Data()));
4731 else AliInfo("Sim. did not use this object");
92258ce2 4732 //
7ad7315a 4733 // find cdbID used for rec
4734 TString idRec="",storRec="";
4735 TIter nextRec(cdbListRec);
4736 AliCDBId* id=0;
4737 while ((id=(AliCDBId*)nextRec())) {
4738 idRec = id->ToString();
4739 if (idRec.Contains(cdbent->GetName())) break;
4740 idRec="";
4741 }
4742 //
4743 // find storage used for the rec
92258ce2 4744 pair = (TPair*)cdbMapRec->FindObject(cdbent->GetName());
92258ce2 4745 if (pair) { // specific path is used
7ad7315a 4746 storRec = ((TObjString*)pair->Value())->GetString();
4747 RectifyCDBurl(storRec);
92258ce2 4748 }
7ad7315a 4749 else storRec = defRecStore; // default storage list is used
4750 //
4751 if (!idRec.IsNull()) AliInfo(Form("Rec. used %s from %s",idRec.Data(), storRec.Data()));
4752 else AliInfo("Rec. did not use this object");
4753 //
4754 if (!idSim.IsNull() && !idRec.IsNull() && ((idSim!=idRec) || (storSim!=storRec)) )
4755 AliFatal("Different objects were used in sim and rec");
92258ce2 4756 }
7ad7315a 4757
92258ce2 4758}
4759
4760//_________________________________________________________
4761void AliReconstruction::RectifyCDBurl(TString& url)
4762{
4763 // TBD RS
4764 // remove everything but the url
4765 TString sbs;
4766 if (!(sbs=url("\\?User=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4767 if (!(sbs=url("\\?DBFolder=[^?]*")).IsNull()) url.ReplaceAll("?DB","");
4768 if (!(sbs=url("\\?SE=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4769 if (!(sbs=url("\\?CacheFolder=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4770 if (!(sbs=url("\\?OperateDisconnected=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4771 if (!(sbs=url("\\?CacheSize=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4772 if (!(sbs=url("\\?CleanupInterval=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4773 Bool_t slash=kFALSE,space=kFALSE;
4774 while ( (slash=url.EndsWith("/")) || (space=url.EndsWith(" ")) ) {
4775 if (slash) url = url.Strip(TString::kTrailing,'/');
4776 if (space) url = url.Strip(TString::kTrailing,' ');
4777 }
4778 //url.ToLower();
4779 //
4780}