Avoid doing multiple copies of the same file in AliEn if migration was requested...
[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
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class for running the reconstruction //
21// //
22// Clusters and tracks are created for all detectors and all events by //
23// typing: //
24// //
25// AliReconstruction rec; //
26// rec.Run(); //
27// //
28// The Run method returns kTRUE in case of successful execution. //
c71de921 29// //
30// If the input to the reconstruction are not simulated digits but raw data, //
31// this can be specified by an argument of the Run method or by the method //
32// //
33// rec.SetInput("..."); //
34// //
35// The input formats and the corresponding argument are: //
36// - DDL raw data files: directory name, ends with "/" //
37// - raw data root file: root file name, extension ".root" //
38// - raw data DATE file: DATE file name, any other non-empty string //
39// - MC root files : empty string, default //
40// //
b26c3770 41// By default all events are reconstructed. The reconstruction can be //
42// limited to a range of events by giving the index of the first and the //
43// last event as an argument to the Run method or by calling //
44// //
45// rec.SetEventRange(..., ...); //
46// //
47// The index -1 (default) can be used for the last event to indicate no //
48// upper limit of the event range. //
49// //
973388c2 50// In case of raw-data reconstruction the user can modify the default //
51// number of events per digits/clusters/tracks file. In case the option //
52// is not used the number is set 1. In case the user provides 0, than //
53// the number of events is equal to the number of events inside the //
54// raw-data file (i.e. one digits/clusters/tracks file): //
55// //
56// rec.SetNumberOfEventsPerFile(...); //
57// //
58// //
596a855f 59// The name of the galice file can be changed from the default //
e583c30d 60// "galice.root" by passing it as argument to the AliReconstruction //
61// constructor or by //
596a855f 62// //
63// rec.SetGAliceFile("..."); //
64// //
59697224 65// The local reconstruction can be switched on or off for individual //
66// detectors by //
596a855f 67// //
59697224 68// rec.SetRunLocalReconstruction("..."); //
596a855f 69// //
70// The argument is a (case sensitive) string with the names of the //
71// detectors separated by a space. The special string "ALL" selects all //
72// available detectors. This is the default. //
73// //
c71de921 74// The reconstruction of the primary vertex position can be switched off by //
75// //
76// rec.SetRunVertexFinder(kFALSE); //
77// //
b8cd5251 78// The tracking and the creation of ESD tracks can be switched on for //
79// selected detectors by //
596a855f 80// //
b8cd5251 81// rec.SetRunTracking("..."); //
596a855f 82// //
c84a5e9e 83// Uniform/nonuniform field tracking switches (default: uniform field) //
84// //
1d99986f 85// rec.SetUniformFieldTracking(); ( rec.SetUniformFieldTracking(kFALSE); ) //
c84a5e9e 86// //
596a855f 87// The filling of additional ESD information can be steered by //
88// //
89// rec.SetFillESD("..."); //
90// //
b8cd5251 91// Again, for both methods the string specifies the list of detectors. //
92// The default is "ALL". //
93// //
94// The call of the shortcut method //
95// //
96// rec.SetRunReconstruction("..."); //
97// //
98// is equivalent to calling SetRunLocalReconstruction, SetRunTracking and //
99// SetFillESD with the same detector selecting string as argument. //
596a855f 100// //
c71de921 101// The reconstruction requires digits or raw data as input. For the creation //
102// of digits and raw data have a look at the class AliSimulation. //
596a855f 103// //
cd0b062e 104// The input data of a detector can be replaced by the corresponding HLT //
105// data by calling (usual detector string) //
106// SetUseHLTData("..."); //
107// //
24f7a148 108// //
596a855f 109///////////////////////////////////////////////////////////////////////////////
110
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>
596a855f 134
f7a1cc68 135#include "AliAlignObj.h"
42457748 136#include "AliAnalysisManager.h"
137#include "AliAnalysisDataContainer.h"
f7a1cc68 138#include "AliCDBEntry.h"
139#include "AliCDBManager.h"
140#include "AliCDBStorage.h"
141#include "AliCTPRawStream.h"
142#include "AliCascadeVertexer.h"
143#include "AliCentralTrigger.h"
87932dab 144#include "AliCodeTimer.h"
f7a1cc68 145#include "AliDAQ.h"
146#include "AliDetectorRecoParam.h"
147#include "AliESDCaloCells.h"
148#include "AliESDCaloCluster.h"
af885e0f 149#include "AliESDEvent.h"
faffd83e 150#include "AliESDMuonTrack.h"
f7a1cc68 151#include "AliESDPmdTrack.h"
152#include "AliESDTagCreator.h"
2257f27e 153#include "AliESDVertex.h"
faffd83e 154#include "AliESDcascade.h"
f7a1cc68 155#include "AliESDfriend.h"
faffd83e 156#include "AliESDkink.h"
596a855f 157#include "AliESDpid.h"
ff8bb5ae 158#include "AliESDtrack.h"
f7a1cc68 159#include "AliESDtrack.h"
160#include "AliEventInfo.h"
161#include "AliGRPObject.h"
162#include "AliGRPRecoParam.h"
163#include "AliGenEventHeader.h"
25be1e5c 164#include "AliGeomManager.h"
aa3c69a9 165#include "AliGlobalQADataMaker.h"
f7a1cc68 166#include "AliHeader.h"
167#include "AliLog.h"
168#include "AliMagF.h"
169#include "AliMultiplicity.h"
170#include "AliPID.h"
171#include "AliPlaneEff.h"
4e25ac79 172#include "AliQAv1.h"
f7a1cc68 173#include "AliQADataMakerRec.h"
b03591ab 174#include "AliQAManager.h"
33314186 175#include "AliRawVEvent.h"
f7a1cc68 176#include "AliRawEventHeaderBase.h"
cd0b062e 177#include "AliRawHLTManager.h"
f7a1cc68 178#include "AliRawReaderDate.h"
179#include "AliRawReaderFile.h"
180#include "AliRawReaderRoot.h"
42457748 181#include "AliRecoInputHandler.h"
f7a1cc68 182#include "AliReconstruction.h"
183#include "AliReconstructor.h"
184#include "AliRun.h"
7e88424f 185#include "AliRunInfo.h"
f7a1cc68 186#include "AliRunLoader.h"
187#include "AliSysInfo.h" // memory snapshots
188#include "AliTrackPointArray.h"
189#include "AliTracker.h"
190#include "AliTriggerClass.h"
191#include "AliTriggerCluster.h"
a6dd87ad 192#include "AliTriggerIR.h"
f7a1cc68 193#include "AliTriggerConfiguration.h"
194#include "AliV0vertexer.h"
195#include "AliVertexer.h"
1f9831ab 196#include "AliTrackleter.h"
f7a1cc68 197#include "AliVertexerTracks.h"
52dd4a8c 198#include "AliTriggerRunScalers.h"
199#include "AliCTPTimeParams.h"
8b12d288 200#include "AliESDHLTDecision.h"
6ef9caeb 201#include "AliTriggerInput.h"
3d84ad67 202#include "AliLHCData.h"
27aa8455 203#include "ARVersion.h"
204#include <RVersion.h>
596a855f 205ClassImp(AliReconstruction)
206
596a855f 207//_____________________________________________________________________________
820b4d9e 208const char* AliReconstruction::fgkDetectorName[AliReconstruction::kNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE"
209// #ifdef MFT_UPGRADE
210// , "MFT"
211// #endif
212 , "MFT" // AU
213 , "HLT"
214};
c757bafd 215
216//_____________________________________________________________________________
4b71572b 217AliReconstruction::AliReconstruction(const char* gAliceFilename) :
218 TSelector(),
2257f27e 219 fRunVertexFinder(kTRUE),
a84e2607 220 fRunVertexFinderTracks(kTRUE),
1f46a9ae 221 fRunHLTTracking(kFALSE),
e66fbafb 222 fRunMuonTracking(kFALSE),
d1683eef 223 fRunV0Finder(kTRUE),
224 fRunCascadeFinder(kTRUE),
1f9831ab 225 fRunMultFinder(kTRUE),
c8025cc8 226 fStopOnError(kTRUE),
1d99986f 227 fWriteAlignmentData(kFALSE),
228 fWriteESDfriend(kFALSE),
b647652d 229 fFillTriggerESD(kTRUE),
1d99986f 230
7f68891d 231 fCleanESD(kTRUE),
a023d8d8 232 fV0DCAmax(3.),
233 fV0CsPmin(0.),
7f68891d 234 fDmax(50.),
235 fZmax(50.),
236
1d99986f 237 fRunLocalReconstruction("ALL"),
b8cd5251 238 fRunTracking("ALL"),
e583c30d 239 fFillESD("ALL"),
7d566c20 240 fLoadCDB(""),
48ce48d1 241 fUseTrackingErrorsForAlignment(""),
e583c30d 242 fGAliceFileName(gAliceFilename),
4b71572b 243 fRawInput(""),
975320a0 244 fESDOutput(""),
81d57268 245 fProofOutputFileName(""),
246 fProofOutputLocation(""),
247 fProofOutputDataset(kFALSE),
248 fProofOutputArchive(""),
35042093 249 fEquipIdMap(""),
b26c3770 250 fFirstEvent(0),
251 fLastEvent(-1),
9d705769 252 fNumberOfEventsPerFile((UInt_t)-1),
fc01854a 253 fFractionFriends(0.04),
b8cd5251 254 fOptions(),
6bae477a 255 fLoadAlignFromCDB(kTRUE),
256 fLoadAlignData("ALL"),
cd0b062e 257 fUseHLTData(),
7e88424f 258 fRunInfo(NULL),
259 fEventInfo(),
522fdd91 260 fRunScalers(NULL),
52dd4a8c 261 fCTPTimeParams(NULL),
c7ff1a33 262 fCTPTimeAlign(NULL),
e583c30d 263
264 fRunLoader(NULL),
b649205a 265 fRawReader(NULL),
cd0b062e 266 fParentRawReader(NULL),
b8cd5251 267
7e88424f 268 fRecoParam(),
269
58e8dc31 270 fSPDTrackleter(NULL),
271
f2a195c1 272 fDiamondProfileSPD(NULL),
9178838a 273 fDiamondProfile(NULL),
43c9dae1 274 fDiamondProfileTPC(NULL),
77ba28ba 275 fListOfCosmicTriggers(NULL),
f2a195c1 276
6b6e4472 277 fGRPData(NULL),
444753c6 278
6bae477a 279 fAlignObjArray(NULL),
795e4a22 280 fCDBUri(),
f1c1204d 281 fQARefUri(),
759c1df1 282 fSpecCDBUri(),
795e4a22 283 fInitCDBCalled(kFALSE),
647d2bb8 284 fFromCDBSnapshot(kFALSE),
69e8e906 285 fSnapshotFileName(""),
795e4a22 286 fSetRunNumberFromDataCalled(kFALSE),
ce43afbe 287 fQADetectors("ALL"),
288 fQATasks("ALL"),
7e963665 289 fRunQA(kTRUE),
6b150027 290 fRunGlobalQA(kTRUE),
e4a998ed 291 fSameQACycle(kFALSE),
f1c1204d 292 fInitQACalled(kFALSE),
75373542 293 fWriteQAExpertData(kTRUE),
21a3aa09 294 fRunPlaneEff(kFALSE),
295
296 fesd(NULL),
297 fhltesd(NULL),
298 fesdf(NULL),
299 ffile(NULL),
ee7c441c 300 ffileF(NULL),
21a3aa09 301 ftree(NULL),
ee7c441c 302 ftreeF(NULL),
21a3aa09 303 fhlttree(NULL),
21a3aa09 304 ftVertexer(NULL),
14dd053c 305 fIsNewRunLoader(kFALSE),
4b71572b 306 fRunAliEVE(kFALSE),
f00558b6 307 fChain(NULL),
308 fNall(0),
309 fNspecie(0),
310 fSspecie(0),
311 fNhighPt(0),
f9fc20b4 312 fShighPt(0),
42457748 313 fUpgradeModule(""),
314 fAnalysisMacro(),
315 fAnalysis(0),
764daca3 316 fRecoHandler(0),
317 fDeclTriggerClasses("")
596a855f 318{
319// create reconstruction object with default parameters
002c9d1b 320 gGeoManager = NULL;
b8cd5251 321
ac4a7581 322 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 323 fReconstructor[iDet] = NULL;
f9fc20b4 324 fUpgradeMask[iDet]=kFALSE;
b8cd5251 325 fLoader[iDet] = NULL;
326 fTracker[iDet] = NULL;
327 }
4e25ac79 328 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
252f8aa8 329 fQACycles[iDet] = 999999 ;
330 fQAWriteExpert[iDet] = kFALSE ;
331 }
3d84ad67 332 fBeamInt[0][0]=fBeamInt[0][1]=fBeamInt[1][0]=fBeamInt[1][1] = -1;
333
e47c4c2e 334 AliPID pid;
596a855f 335}
336
337//_____________________________________________________________________________
338AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
4b71572b 339 TSelector(),
2257f27e 340 fRunVertexFinder(rec.fRunVertexFinder),
a84e2607 341 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
1f46a9ae 342 fRunHLTTracking(rec.fRunHLTTracking),
e66fbafb 343 fRunMuonTracking(rec.fRunMuonTracking),
d1683eef 344 fRunV0Finder(rec.fRunV0Finder),
345 fRunCascadeFinder(rec.fRunCascadeFinder),
1f9831ab 346 fRunMultFinder(rec.fRunMultFinder),
1d99986f 347 fStopOnError(rec.fStopOnError),
348 fWriteAlignmentData(rec.fWriteAlignmentData),
349 fWriteESDfriend(rec.fWriteESDfriend),
b647652d 350 fFillTriggerESD(rec.fFillTriggerESD),
1d99986f 351
7f68891d 352 fCleanESD(rec.fCleanESD),
a023d8d8 353 fV0DCAmax(rec.fV0DCAmax),
5e5c1aa9 354 fV0CsPmin(rec.fV0CsPmin),
7f68891d 355 fDmax(rec.fDmax),
356 fZmax(rec.fZmax),
357
1d99986f 358 fRunLocalReconstruction(rec.fRunLocalReconstruction),
e583c30d 359 fRunTracking(rec.fRunTracking),
360 fFillESD(rec.fFillESD),
7d566c20 361 fLoadCDB(rec.fLoadCDB),
48ce48d1 362 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
e583c30d 363 fGAliceFileName(rec.fGAliceFileName),
4b71572b 364 fRawInput(rec.fRawInput),
975320a0 365 fESDOutput(rec.fESDOutput),
81d57268 366 fProofOutputFileName(rec.fProofOutputFileName),
367 fProofOutputLocation(rec.fProofOutputLocation),
368 fProofOutputDataset(rec.fProofOutputDataset),
369 fProofOutputArchive(rec.fProofOutputArchive),
35042093 370 fEquipIdMap(rec.fEquipIdMap),
b26c3770 371 fFirstEvent(rec.fFirstEvent),
372 fLastEvent(rec.fLastEvent),
973388c2 373 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
fc01854a 374 fFractionFriends(rec.fFractionFriends),
b8cd5251 375 fOptions(),
6bae477a 376 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
377 fLoadAlignData(rec.fLoadAlignData),
2972d4eb 378 fUseHLTData(rec.fUseHLTData),
7e88424f 379 fRunInfo(NULL),
380 fEventInfo(),
522fdd91 381 fRunScalers(NULL),
52dd4a8c 382 fCTPTimeParams(NULL),
c7ff1a33 383 fCTPTimeAlign(NULL),
e583c30d 384
385 fRunLoader(NULL),
b649205a 386 fRawReader(NULL),
2972d4eb 387 fParentRawReader(NULL),
b8cd5251 388
4b71572b 389 fRecoParam(rec.fRecoParam),
7e88424f 390
58e8dc31 391 fSPDTrackleter(NULL),
392
f2a195c1 393 fDiamondProfileSPD(rec.fDiamondProfileSPD),
4b71572b 394 fDiamondProfile(rec.fDiamondProfile),
395 fDiamondProfileTPC(rec.fDiamondProfileTPC),
77ba28ba 396 fListOfCosmicTriggers(NULL),
f2a195c1 397
6b6e4472 398 fGRPData(NULL),
444753c6 399
6bae477a 400 fAlignObjArray(rec.fAlignObjArray),
ec92bee0 401 fCDBUri(rec.fCDBUri),
f1c1204d 402 fQARefUri(rec.fQARefUri),
7e963665 403 fSpecCDBUri(),
795e4a22 404 fInitCDBCalled(rec.fInitCDBCalled),
647d2bb8 405 fFromCDBSnapshot(rec.fFromCDBSnapshot),
69e8e906 406 fSnapshotFileName(rec.fSnapshotFileName),
795e4a22 407 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
ce43afbe 408 fQADetectors(rec.fQADetectors),
409 fQATasks(rec.fQATasks),
aa3c69a9 410 fRunQA(rec.fRunQA),
411 fRunGlobalQA(rec.fRunGlobalQA),
e4a998ed 412 fSameQACycle(rec.fSameQACycle),
f1c1204d 413 fInitQACalled(rec.fInitQACalled),
75373542 414 fWriteQAExpertData(rec.fWriteQAExpertData),
21a3aa09 415 fRunPlaneEff(rec.fRunPlaneEff),
416
417 fesd(NULL),
418 fhltesd(NULL),
419 fesdf(NULL),
420 ffile(NULL),
ee7c441c 421 ffileF(NULL),
21a3aa09 422 ftree(NULL),
ee7c441c 423 ftreeF(NULL),
21a3aa09 424 fhlttree(NULL),
21a3aa09 425 ftVertexer(NULL),
14dd053c 426 fIsNewRunLoader(rec.fIsNewRunLoader),
4b71572b 427 fRunAliEVE(kFALSE),
f00558b6 428 fChain(NULL),
429 fNall(0),
430 fNspecie(0),
431 fSspecie(0),
432 fNhighPt(0),
f9fc20b4 433 fShighPt(0),
42457748 434 fUpgradeModule(""),
435 fAnalysisMacro(rec.fAnalysisMacro),
436 fAnalysis(0),
764daca3 437 fRecoHandler(0),
438 fDeclTriggerClasses(rec.fDeclTriggerClasses)
596a855f 439{
440// copy constructor
441
ec92bee0 442 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
efd2085e 443 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
444 }
ac4a7581 445 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 446 fReconstructor[iDet] = NULL;
f9fc20b4 447 fUpgradeMask[iDet] = kFALSE;
b8cd5251 448 fLoader[iDet] = NULL;
449 fTracker[iDet] = NULL;
b1af1125 450 }
451
4e25ac79 452 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
b1af1125 453 fQACycles[iDet] = rec.fQACycles[iDet];
252f8aa8 454 fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
455 }
b1af1125 456
ec92bee0 457 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
458 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
459 }
3d84ad67 460
461 for (int i=2;i--;) for (int j=2;j--;) fBeamInt[i][j] = rec.fBeamInt[i][j];
462
596a855f 463}
464
465//_____________________________________________________________________________
466AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
467{
468// assignment operator
4b71572b 469// Used in PROOF mode
470// Be very careful while modifing it!
471// Simple rules to follow:
472// for persistent data members - use their assignment operators
473// for non-persistent ones - do nothing or take the default values from constructor
474// TSelector members should not be touched
475 if(&rec == this) return *this;
476
4b71572b 477 fRunVertexFinder = rec.fRunVertexFinder;
478 fRunVertexFinderTracks = rec.fRunVertexFinderTracks;
479 fRunHLTTracking = rec.fRunHLTTracking;
480 fRunMuonTracking = rec.fRunMuonTracking;
481 fRunV0Finder = rec.fRunV0Finder;
482 fRunCascadeFinder = rec.fRunCascadeFinder;
1f9831ab 483 fRunMultFinder = rec.fRunMultFinder;
4b71572b 484 fStopOnError = rec.fStopOnError;
485 fWriteAlignmentData = rec.fWriteAlignmentData;
486 fWriteESDfriend = rec.fWriteESDfriend;
487 fFillTriggerESD = rec.fFillTriggerESD;
488
489 fCleanESD = rec.fCleanESD;
490 fV0DCAmax = rec.fV0DCAmax;
491 fV0CsPmin = rec.fV0CsPmin;
492 fDmax = rec.fDmax;
493 fZmax = rec.fZmax;
494
495 fRunLocalReconstruction = rec.fRunLocalReconstruction;
496 fRunTracking = rec.fRunTracking;
497 fFillESD = rec.fFillESD;
7d566c20 498 fLoadCDB = rec.fLoadCDB;
4b71572b 499 fUseTrackingErrorsForAlignment = rec.fUseTrackingErrorsForAlignment;
500 fGAliceFileName = rec.fGAliceFileName;
501 fRawInput = rec.fRawInput;
975320a0 502 fESDOutput = rec.fESDOutput;
81d57268 503 fProofOutputFileName = rec.fProofOutputFileName;
504 fProofOutputLocation = rec.fProofOutputLocation;
505 fProofOutputDataset = rec.fProofOutputDataset;
506 fProofOutputArchive = rec.fProofOutputArchive;
4b71572b 507 fEquipIdMap = rec.fEquipIdMap;
508 fFirstEvent = rec.fFirstEvent;
509 fLastEvent = rec.fLastEvent;
510 fNumberOfEventsPerFile = rec.fNumberOfEventsPerFile;
fc01854a 511 fFractionFriends = rec.fFractionFriends;
4b71572b 512
513 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
514 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
515 }
516
517 fLoadAlignFromCDB = rec.fLoadAlignFromCDB;
518 fLoadAlignData = rec.fLoadAlignData;
4b71572b 519 fUseHLTData = rec.fUseHLTData;
520
521 delete fRunInfo; fRunInfo = NULL;
522 if (rec.fRunInfo) fRunInfo = new AliRunInfo(*rec.fRunInfo);
523
524 fEventInfo = rec.fEventInfo;
525
522fdd91 526 delete fRunScalers; fRunScalers = NULL;
527 if (rec.fRunScalers) fRunScalers = new AliTriggerRunScalers(*rec.fRunScalers);
528
52dd4a8c 529 delete fCTPTimeParams; fCTPTimeParams = NULL;
530 if (rec.fCTPTimeParams) fCTPTimeParams = new AliCTPTimeParams(*rec.fCTPTimeParams);
c7ff1a33 531 delete fCTPTimeAlign; fCTPTimeAlign = NULL;
532 if (rec.fCTPTimeAlign) fCTPTimeAlign = new AliCTPTimeParams(*rec.fCTPTimeAlign);
52dd4a8c 533
4b71572b 534 fRunLoader = NULL;
535 fRawReader = NULL;
536 fParentRawReader = NULL;
537
538 fRecoParam = rec.fRecoParam;
539
ac4a7581 540 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
f9fc20b4 541 fUpgradeMask[iDet] = kFALSE;
4b71572b 542 delete fReconstructor[iDet]; fReconstructor[iDet] = NULL;
543 delete fLoader[iDet]; fLoader[iDet] = NULL;
544 delete fTracker[iDet]; fTracker[iDet] = NULL;
4b71572b 545 }
b1af1125 546
4e25ac79 547 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
b1af1125 548 fQACycles[iDet] = rec.fQACycles[iDet];
252f8aa8 549 fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
550 }
58e8dc31 551
552 delete fSPDTrackleter; fSPDTrackleter = NULL;
252f8aa8 553
f2a195c1 554 delete fDiamondProfileSPD; fDiamondProfileSPD = NULL;
555 if (rec.fDiamondProfileSPD) fDiamondProfileSPD = new AliESDVertex(*rec.fDiamondProfileSPD);
4b71572b 556 delete fDiamondProfile; fDiamondProfile = NULL;
557 if (rec.fDiamondProfile) fDiamondProfile = new AliESDVertex(*rec.fDiamondProfile);
558 delete fDiamondProfileTPC; fDiamondProfileTPC = NULL;
559 if (rec.fDiamondProfileTPC) fDiamondProfileTPC = new AliESDVertex(*rec.fDiamondProfileTPC);
4b71572b 560
77ba28ba 561 delete fListOfCosmicTriggers; fListOfCosmicTriggers = NULL;
562 if (rec.fListOfCosmicTriggers) fListOfCosmicTriggers = (THashTable*)((rec.fListOfCosmicTriggers)->Clone());
563
4b71572b 564 delete fGRPData; fGRPData = NULL;
44e45fac 565 // if (rec.fGRPData) fGRPData = (TMap*)((rec.fGRPData)->Clone());
566 if (rec.fGRPData) fGRPData = (AliGRPObject*)((rec.fGRPData)->Clone());
4b71572b 567
568 delete fAlignObjArray; fAlignObjArray = NULL;
569
570 fCDBUri = "";
f1c1204d 571 fQARefUri = rec.fQARefUri;
4b71572b 572 fSpecCDBUri.Delete();
573 fInitCDBCalled = rec.fInitCDBCalled;
647d2bb8 574 fFromCDBSnapshot = rec.fFromCDBSnapshot;
69e8e906 575 fSnapshotFileName = rec.fSnapshotFileName;
4b71572b 576 fSetRunNumberFromDataCalled = rec.fSetRunNumberFromDataCalled;
577 fQADetectors = rec.fQADetectors;
4b71572b 578 fQATasks = rec.fQATasks;
579 fRunQA = rec.fRunQA;
580 fRunGlobalQA = rec.fRunGlobalQA;
4b71572b 581 fSameQACycle = rec.fSameQACycle;
f1c1204d 582 fInitQACalled = rec.fInitQACalled;
75373542 583 fWriteQAExpertData = rec.fWriteQAExpertData;
4b71572b 584 fRunPlaneEff = rec.fRunPlaneEff;
3d84ad67 585 for (int i=2;i--;) for (int j=2;j--;) fBeamInt[i][j] = rec.fBeamInt[i][j];
4b71572b 586 fesd = NULL;
587 fhltesd = NULL;
588 fesdf = NULL;
589 ffile = NULL;
ee7c441c 590 ffileF = NULL;
4b71572b 591 ftree = NULL;
ee7c441c 592 ftreeF = NULL;
4b71572b 593 fhlttree = NULL;
594 ftVertexer = NULL;
595 fIsNewRunLoader = rec.fIsNewRunLoader;
596 fRunAliEVE = kFALSE;
597 fChain = NULL;
f00558b6 598 fNall = 0;
599 fNspecie = 0;
600 fSspecie = 0;
601 fNhighPt = 0;
602 fShighPt = 0;
f9fc20b4 603 fUpgradeModule="";
42457748 604 fAnalysisMacro = rec.fAnalysisMacro;
605 fAnalysis = 0;
606 fRecoHandler = 0;
764daca3 607 fDeclTriggerClasses = rec.fDeclTriggerClasses;
596a855f 608
596a855f 609 return *this;
610}
611
612//_____________________________________________________________________________
613AliReconstruction::~AliReconstruction()
614{
615// clean up
616
e583c30d 617 CleanUp();
77ba28ba 618 if (fListOfCosmicTriggers) {
619 fListOfCosmicTriggers->Delete();
620 delete fListOfCosmicTriggers;
621 }
4f3c479a 622 delete fGRPData;
522fdd91 623 delete fRunScalers;
52dd4a8c 624 delete fCTPTimeParams;
c7ff1a33 625 delete fCTPTimeAlign;
efd2085e 626 fOptions.Delete();
4b71572b 627 if (fAlignObjArray) {
628 fAlignObjArray->Delete();
629 delete fAlignObjArray;
630 }
ec92bee0 631 fSpecCDBUri.Delete();
e6d66370 632
87932dab 633 AliCodeTimer::Instance()->Print();
596a855f 634}
635
024cf675 636//_____________________________________________________________________________
f1c1204d 637void AliReconstruction::InitQA()
638{
639 //Initialize the QA and start of cycle
52dd4a8c 640 AliCodeTimerAuto("",0);
f1c1204d 641
642 if (fInitQACalled) return;
643 fInitQACalled = kTRUE;
644
92664bc8 645 if (fGRPData) AliQADataMaker::SetCloningRequest( fGRPData->GetQATrigClasses(), fGRPData->GetQACloningRequest());
646
647
634696f5 648 AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kRECMODE) ;
75373542 649 if (fWriteQAExpertData)
eca4fa66 650 qam->SetWriteExpert() ;
75373542 651
eca4fa66 652 if (qam->IsDefaultStorageSet()) {
f1c1204d 653 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
654 AliWarning("Default QA reference storage has been already set !");
655 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fQARefUri.Data()));
656 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
eca4fa66 657 fQARefUri = qam->GetDefaultStorage()->GetURI();
f1c1204d 658 } else {
659 if (fQARefUri.Length() > 0) {
660 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
661 AliDebug(2, Form("Default QA reference storage is set to: %s", fQARefUri.Data()));
662 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
663 } else {
664 fQARefUri="local://$ALICE_ROOT/QAref";
665 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
666 AliWarning("Default QA refeference storage not yet set !!!!");
667 AliWarning(Form("Setting it now to: %s", fQARefUri.Data()));
668 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
669
670 }
eca4fa66 671 qam->SetDefaultStorage(fQARefUri);
f1c1204d 672 }
673
674 if (fRunQA) {
eca4fa66 675 qam->SetActiveDetectors(fQADetectors) ;
4e25ac79 676 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) {
eca4fa66 677 qam->SetCycleLength(AliQAv1::DETECTORINDEX_t(det), fQACycles[det]) ;
678 qam->SetWriteExpert(AliQAv1::DETECTORINDEX_t(det)) ;
f1c1204d 679 }
514cb8c7 680 if (!fRawReader && !fInput && IsInTasks(AliQAv1::kRAWS))
4e25ac79 681 fQATasks.ReplaceAll(Form("%d",AliQAv1::kRAWS), "") ;
eca4fa66 682 qam->SetTasks(fQATasks) ;
683 qam->InitQADataMaker(AliCDBManager::Instance()->GetRun()) ;
f1c1204d 684 }
685 if (fRunGlobalQA) {
686 Bool_t sameCycle = kFALSE ;
eca4fa66 687 AliQADataMaker *qadm = qam->GetQADataMaker(AliQAv1::kGLOBAL);
f1c1204d 688 AliInfo(Form("Initializing the global QA data maker"));
514cb8c7 689 if (IsInTasks(AliQAv1::kRECPOINTS)) {
4e25ac79 690 qadm->StartOfCycle(AliQAv1::kRECPOINTS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
691 TObjArray **arr=qadm->Init(AliQAv1::kRECPOINTS);
f1c1204d 692 AliTracker::SetResidualsArray(arr);
693 sameCycle = kTRUE ;
694 }
514cb8c7 695 if (IsInTasks(AliQAv1::kESDS)) {
4e25ac79 696 qadm->StartOfCycle(AliQAv1::kESDS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
697 qadm->Init(AliQAv1::kESDS);
f1c1204d 698 }
f1c1204d 699 }
fc07289e 700 AliSysInfo::AddStamp("InitQA") ;
f1c1204d 701}
702
703//_____________________________________________________________________________
87da0921 704void AliReconstruction::MergeQA(const char *fileName)
fc07289e 705{
706 //Initialize the QA and start of cycle
52dd4a8c 707 AliCodeTimerAuto("",0) ;
eca4fa66 708 AliQAManager::QAManager()->Merge(AliCDBManager::Instance()->GetRun(),fileName) ;
fc07289e 709 AliSysInfo::AddStamp("MergeQA") ;
710}
711
712//_____________________________________________________________________________
795e4a22 713void AliReconstruction::InitCDB()
024cf675 714{
715// activate a default CDB storage
716// First check if we have any CDB storage set, because it is used
717// to retrieve the calibration and alignment constants
52dd4a8c 718 AliCodeTimerAuto("",0);
024cf675 719
795e4a22 720 if (fInitCDBCalled) return;
721 fInitCDBCalled = kTRUE;
722
024cf675 723 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 724 if (man->IsDefaultStorageSet())
024cf675 725 {
726 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 727 AliWarning("Default CDB storage has been already set !");
728 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
024cf675 729 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 730 fCDBUri = man->GetDefaultStorage()->GetURI();
ec92bee0 731 }
732 else {
795e4a22 733 if (fCDBUri.Length() > 0)
734 {
735 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
736 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
737 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
52dd4a8c 738 man->SetDefaultStorage(fCDBUri);
739 }
740 else if (!man->GetRaw()){
741 fCDBUri="local://$ALICE_ROOT/OCDB";
795e4a22 742 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
743 AliWarning("Default CDB storage not yet set !!!!");
744 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
745 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
52dd4a8c 746 man->SetDefaultStorage(fCDBUri);
747 }
748 else {
749 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
750 AliWarning("Default storage will be set after setting the Run Number!!!");
751 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 752 }
ec92bee0 753 }
754
755 // Now activate the detector specific CDB storage locations
c3a7b59a 756 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
757 TObject* obj = fSpecCDBUri[i];
758 if (!obj) continue;
b8ec52f6 759 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
760 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
761 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 762 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 763 }
002c9d1b 764 AliSysInfo::AddStamp("InitCDB");
024cf675 765}
766
767//_____________________________________________________________________________
768void AliReconstruction::SetDefaultStorage(const char* uri) {
ec92bee0 769// Store the desired default CDB storage location
770// Activate it later within the Run() method
024cf675 771
ec92bee0 772 fCDBUri = uri;
024cf675 773
774}
775
776//_____________________________________________________________________________
f1c1204d 777void AliReconstruction::SetQARefDefaultStorage(const char* uri) {
778 // Store the desired default CDB storage location
779 // Activate it later within the Run() method
780
781 fQARefUri = uri;
4e25ac79 782 AliQAv1::SetQARefStorage(fQARefUri.Data()) ;
f1c1204d 783
784}
785//_____________________________________________________________________________
c3a7b59a 786void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 787// Store a detector-specific CDB storage location
788// Activate it later within the Run() method
024cf675 789
c3a7b59a 790 AliCDBPath aPath(calibType);
791 if(!aPath.IsValid()){
792 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
ac4a7581 793 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
c3a7b59a 794 if(!strcmp(calibType, fgkDetectorName[iDet])) {
795 aPath.SetPath(Form("%s/*", calibType));
796 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
797 break;
798 }
799 }
800 if(!aPath.IsValid()){
801 AliError(Form("Not a valid path or detector: %s", calibType));
802 return;
803 }
804 }
805
53dd3c3d 806// // check that calibType refers to a "valid" detector name
807// Bool_t isDetector = kFALSE;
ac4a7581 808// for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
53dd3c3d 809// TString detName = fgkDetectorName[iDet];
810// if(aPath.GetLevel0() == detName) {
811// isDetector = kTRUE;
812// break;
813// }
814// }
815//
816// if(!isDetector) {
817// AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
818// return;
819// }
c3a7b59a 820
821 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
ec92bee0 822 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 823 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
024cf675 824
825}
826
6bae477a 827//_____________________________________________________________________________
795e4a22 828Bool_t AliReconstruction::SetRunNumberFromData()
6bae477a 829{
830 // The method is called in Run() in order
831 // to set a correct run number.
832 // In case of raw data reconstruction the
833 // run number is taken from the raw data header
834
795e4a22 835 if (fSetRunNumberFromDataCalled) return kTRUE;
836 fSetRunNumberFromDataCalled = kTRUE;
837
838 AliCDBManager* man = AliCDBManager::Instance();
4b71572b 839
840 if(fRawReader) {
841 if(fRawReader->NextEvent()) {
842 if(man->GetRun() > 0) {
21a3aa09 843 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
4b71572b 844 }
845 man->SetRun(fRawReader->GetRunNumber());
846 fRawReader->RewindEvents();
847 }
848 else {
849 if(man->GetRun() > 0) {
850 AliWarning("No raw-data events are found ! Using settings in AliCDBManager !");
851 }
852 else {
853 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
854 return kFALSE;
855 }
856 }
857 }
858 else {
859 AliRunLoader *rl = AliRunLoader::Open(fGAliceFileName.Data());
860 if (!rl) {
861 AliError(Form("No run loader found in file %s", fGAliceFileName.Data()));
6bae477a 862 return kFALSE;
863 }
ec92bee0 864 else {
4b71572b 865 rl->LoadHeader();
866 // read run number from gAlice
867 if(rl->GetHeader()) {
868 man->SetRun(rl->GetHeader()->GetRun());
869 rl->UnloadHeader();
870 delete rl;
ec92bee0 871 }
872 else {
4b71572b 873 AliError("Neither run-loader header nor RawReader objects are found !");
874 delete rl;
ec92bee0 875 return kFALSE;
876 }
4b71572b 877 }
6bae477a 878 }
795e4a22 879
880 man->Print();
881
6bae477a 882 return kTRUE;
883}
884
885//_____________________________________________________________________________
795e4a22 886void AliReconstruction::SetCDBLock() {
887 // Set CDB lock: from now on it is forbidden to reset the run number
888 // or the default storage or to activate any further storage!
889
890 AliCDBManager::Instance()->SetLock(1);
891}
892
893//_____________________________________________________________________________
f9fc20b4 894void AliReconstruction::MatchUpgradeDetector() {
895 // Translates detector name in a boolean.
896 // The boolean is used in GetReconstructor to load the
897 // upgrade reconstructor instead of the standard one.
898 for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
899 if(fUpgradeModule.Contains(fgkDetectorName[iDet])) fUpgradeMask[iDet]=kTRUE;
900 }
901}
902//_____________________________________________________________________________
6bae477a 903Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
904{
905 // Read the alignment objects from CDB.
906 // Each detector is supposed to have the
907 // alignment objects in DET/Align/Data CDB path.
908 // All the detector objects are then collected,
909 // sorted by geometry level (starting from ALIC) and
910 // then applied to the TGeo geometry.
911 // Finally an overlaps check is performed.
912
913 // Load alignment data from CDB and fill fAlignObjArray
914 if(fLoadAlignFromCDB){
6bae477a 915
25be1e5c 916 TString detStr = detectors;
917 TString loadAlObjsListOfDets = "";
918
ac4a7581 919 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
8cb26cdf 920 if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
f12d42ce 921 if(!strcmp(fgkDetectorName[iDet],"HLT")) continue;
4fbb8e9d 922
923 if(AliGeomManager::GetNalignable(fgkDetectorName[iDet]) != 0)
8cb26cdf 924 {
925 loadAlObjsListOfDets += fgkDetectorName[iDet];
926 loadAlObjsListOfDets += " ";
927 }
25be1e5c 928 } // end loop over detectors
4fbb8e9d 929
930 if(AliGeomManager::GetNalignable("GRP") != 0)
8cb26cdf 931 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
98e303d9 932 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
e30a9b4d 933 AliCDBManager::Instance()->UnloadFromCache("*/Align/*");
25be1e5c 934 }else{
935 // Check if the array with alignment objects was
936 // provided by the user. If yes, apply the objects
937 // to the present TGeo geometry
938 if (fAlignObjArray) {
939 if (gGeoManager && gGeoManager->IsClosed()) {
98e303d9 940 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
25be1e5c 941 AliError("The misalignment of one or more volumes failed!"
942 "Compare the list of simulated detectors and the list of detector alignment data!");
943 return kFALSE;
944 }
945 }
946 else {
947 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
6bae477a 948 return kFALSE;
949 }
950 }
6bae477a 951 }
25be1e5c 952
4b71572b 953 if (fAlignObjArray) {
954 fAlignObjArray->Delete();
955 delete fAlignObjArray; fAlignObjArray=NULL;
956 }
a03b0371 957
6bae477a 958 return kTRUE;
959}
596a855f 960
961//_____________________________________________________________________________
962void AliReconstruction::SetGAliceFile(const char* fileName)
963{
964// set the name of the galice file
965
966 fGAliceFileName = fileName;
967}
968
efd2085e 969//_____________________________________________________________________________
b58710ef 970void AliReconstruction::SetInput(const char* input)
21a3aa09 971{
b58710ef 972 // In case the input string starts with 'mem://', we run in an online mode
973 // and AliRawReaderDateOnline object is created. In all other cases a raw-data
974 // file is assumed. One can give as an input:
975 // mem://: - events taken from DAQ monitoring libs online
976 // or
977 // mem://<filename> - emulation of the above mode (via DATE monitoring libs)
4b71572b 978 if (input) fRawInput = input;
21a3aa09 979}
980
981//_____________________________________________________________________________
975320a0 982void AliReconstruction::SetOutput(const char* output)
983{
984 // Set the output ESD filename
985 // 'output' is a normalt ROOT url
986 // The method is used in case of raw-data reco with PROOF
81d57268 987 if (output) fESDOutput = output;
975320a0 988}
989
990//_____________________________________________________________________________
efd2085e 991void AliReconstruction::SetOption(const char* detector, const char* option)
992{
993// set options for the reconstruction of a detector
994
995 TObject* obj = fOptions.FindObject(detector);
996 if (obj) fOptions.Remove(obj);
997 fOptions.Add(new TNamed(detector, option));
998}
999
596a855f 1000//_____________________________________________________________________________
7e88424f 1001void AliReconstruction::SetRecoParam(const char* detector, AliDetectorRecoParam *par)
1002{
1003 // Set custom reconstruction parameters for a given detector
1004 // Single set of parameters for all the events
a00021a7 1005
1006 // First check if the reco-params are global
1007 if(!strcmp(detector, "GRP")) {
1008 par->SetAsDefault();
ac4a7581 1009 fRecoParam.AddDetRecoParam(kNDetectors,par);
a00021a7 1010 return;
1011 }
1012
ac4a7581 1013 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
7e88424f 1014 if(!strcmp(detector, fgkDetectorName[iDet])) {
1015 par->SetAsDefault();
1016 fRecoParam.AddDetRecoParam(iDet,par);
1017 break;
1018 }
1019 }
1020
1021}
1022
1023//_____________________________________________________________________________
61807e09 1024Bool_t AliReconstruction::InitGRP() {
1025 //------------------------------------
1026 // Initialization of the GRP entry
1027 //------------------------------------
1028 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
1029
4b71572b 1030 if (entry) {
44e45fac 1031
1032 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
1033
1034 if (m) {
1035 AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
1036 m->Print();
1037 fGRPData = new AliGRPObject();
1038 fGRPData->ReadValuesFromMap(m);
1039 }
1040
1041 else {
1042 AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it");
1043 fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
1044 entry->SetOwner(0);
1045 }
1046
f168abba 1047 // FIX ME: The unloading of GRP entry is temporarily disabled
1048 // because ZDC and VZERO are using it in order to initialize
1049 // their reconstructor objects. In the future one has to think
1050 // of propagating AliRunInfo to the reconstructors.
1051 // AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
4b71572b 1052 }
61807e09 1053
1054 if (!fGRPData) {
1055 AliError("No GRP entry found in OCDB!");
1056 return kFALSE;
1057 }
1058
44e45fac 1059 TString lhcState = fGRPData->GetLHCState();
1060 if (lhcState==AliGRPObject::GetInvalidString()) {
7e88424f 1061 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
44e45fac 1062 lhcState = "UNKNOWN";
7e88424f 1063 }
1064
44e45fac 1065 TString beamType = fGRPData->GetBeamType();
1066 if (beamType==AliGRPObject::GetInvalidString()) {
7e88424f 1067 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
44e45fac 1068 beamType = "UNKNOWN";
7e88424f 1069 }
1070
44e45fac 1071 Float_t beamEnergy = fGRPData->GetBeamEnergy();
1072 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
7e88424f 1073 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
44e45fac 1074 beamEnergy = 0;
7e88424f 1075 }
1076
44e45fac 1077 TString runType = fGRPData->GetRunType();
1078 if (runType==AliGRPObject::GetInvalidString()) {
7e88424f 1079 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
44e45fac 1080 runType = "UNKNOWN";
7e88424f 1081 }
1082
44e45fac 1083 Int_t activeDetectors = fGRPData->GetDetectorMask();
a5dede5c 1084 if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
7e88424f 1085 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
44e45fac 1086 activeDetectors = 1074790399;
7e88424f 1087 }
820b4d9e 1088 AliDebug(1, Form("activeDetectors = %d", activeDetectors));
7e88424f 1089
44e45fac 1090 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
44e45fac 1091 fRunInfo->Dump();
1092
7e88424f 1093
1094 // Process the list of active detectors
44e45fac 1095 if (activeDetectors) {
1096 UInt_t detMask = activeDetectors;
820b4d9e 1097 AliDebug(1, Form("Detector List = %s", fRunLocalReconstruction.Data()));
7a317bef 1098 fRunLocalReconstruction = MatchDetectorList(fRunLocalReconstruction,detMask);
820b4d9e 1099 AliDebug(1, Form("Detector List = %s", fRunLocalReconstruction.Data()));
7a317bef 1100 fRunTracking = MatchDetectorList(fRunTracking,detMask);
1101 fFillESD = MatchDetectorList(fFillESD,detMask);
1102 fQADetectors = MatchDetectorList(fQADetectors,detMask);
7d566c20 1103 fLoadCDB.Form("%s %s %s %s",
1104 fRunLocalReconstruction.Data(),
1105 fRunTracking.Data(),
1106 fFillESD.Data(),
1107 fQADetectors.Data());
7d566c20 1108 fLoadCDB = MatchDetectorList(fLoadCDB,detMask);
d0f84c42 1109 if (!((detMask >> AliDAQ::DetectorID("ITSSPD")) & 0x1) &&
1110 !((detMask >> AliDAQ::DetectorID("ITSSDD")) & 0x1) &&
1111 !((detMask >> AliDAQ::DetectorID("ITSSSD")) & 0x1) ) {
91e2f025 1112 // switch off the vertexer
1f9831ab 1113 AliInfo("SPD,SDD,SSD is not in the list of active detectors. Vertexer and Trackleter are switched off.");
91e2f025 1114 fRunVertexFinder = kFALSE;
1f9831ab 1115 fRunMultFinder = kFALSE;
91e2f025 1116 }
304d7f0b 1117 if (!((detMask >> AliDAQ::DetectorID("TRG")) & 0x1)) {
1118 // switch off the reading of CTP raw-data payload
1119 if (fFillTriggerESD) {
1120 AliInfo("CTP is not in the list of active detectors. CTP data reading switched off.");
1121 fFillTriggerESD = kFALSE;
1122 }
1123 }
7e88424f 1124 }
1125
1126 AliInfo("===================================================================================");
1127 AliInfo(Form("Running local reconstruction for detectors: %s",fRunLocalReconstruction.Data()));
1128 AliInfo(Form("Running tracking for detectors: %s",fRunTracking.Data()));
1129 AliInfo(Form("Filling ESD for detectors: %s",fFillESD.Data()));
ca13fb87 1130 AliInfo(Form("Quality assurance is active for detectors: %s",fQADetectors.Data()));
7d566c20 1131 AliInfo(Form("CDB and reconstruction parameters are loaded for detectors: %s",fLoadCDB.Data()));
7e88424f 1132 AliInfo("===================================================================================");
61807e09 1133
1134 //*** Dealing with the magnetic field map
5a004fb4 1135 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
1136 if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
1137 AliInfo("ExpertMode!!! GRP information will be ignored !");
1138 AliInfo("ExpertMode!!! Running with the externally locked B field !");
1139 }
1140 else {
1141 AliInfo("Destroying existing B field instance!");
1142 delete TGeoGlobalMagField::Instance();
1143 }
1144 }
1145 if ( !TGeoGlobalMagField::Instance()->IsLocked() ) {
61807e09 1146 // Construct the field map out of the information retrieved from GRP.
856024f0 1147 Bool_t ok = kTRUE;
61807e09 1148 // L3
44e45fac 1149 Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
1150 if (l3Current == AliGRPObject::GetInvalidFloat()) {
1151 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
1152 ok = kFALSE;
1153 }
f7a1cc68 1154
44e45fac 1155 Char_t l3Polarity = fGRPData->GetL3Polarity();
1156 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
1157 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
1158 ok = kFALSE;
1159 }
1160
1161 // Dipole
1162 Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
1163 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
1164 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
1165 ok = kFALSE;
1166 }
1167
1168 Char_t diPolarity = fGRPData->GetDipolePolarity();
1169 if (diPolarity == AliGRPObject::GetInvalidChar()) {
1170 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
1171 ok = kFALSE;
1172 }
1173
99c7d495 1174 // read special bits for the polarity convention and map type
1175 Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
1176 Bool_t uniformB = fGRPData->IsUniformBMap();
61807e09 1177
856024f0 1178 if (ok) {
33fe5eb1 1179 AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
1180 TMath::Abs(diCurrent) * (diPolarity ? -1:1),
1181 polConvention,uniformB,beamEnergy, beamType.Data());
1182 if (fld) {
1183 TGeoGlobalMagField::Instance()->SetField( fld );
1184 TGeoGlobalMagField::Instance()->Lock();
1185 AliInfo("Running with the B field constructed out of GRP !");
1186 }
1187 else AliFatal("Failed to create a B field map !");
856024f0 1188 }
f7a1cc68 1189 else AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
61807e09 1190 }
f7a1cc68 1191
f2a195c1 1192 //*** Get the diamond profiles from OCDB
1193 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD");
1194 if (entry) {
1195 fDiamondProfileSPD = dynamic_cast<AliESDVertex*> (entry->GetObject());
1196 } else {
1197 AliError("No SPD diamond profile found in OCDB!");
1198 }
1199
61807e09 1200 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
1201 if (entry) {
f2a195c1 1202 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
61807e09 1203 } else {
1204 AliError("No diamond profile found in OCDB!");
1205 }
1206
1207 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexTPC");
1208 if (entry) {
f2a195c1 1209 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
61807e09 1210 } else {
f2a195c1 1211 AliError("No TPC diamond profile found in OCDB!");
61807e09 1212 }
1213
77ba28ba 1214 entry = AliCDBManager::Instance()->Get("GRP/Calib/CosmicTriggers");
1215 if (entry) {
1216 fListOfCosmicTriggers = dynamic_cast<THashTable*>(entry->GetObject());
1217 entry->SetOwner(0);
1218 AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
1219 }
1220
1221 if (!fListOfCosmicTriggers) {
1222 AliWarning("Can not get list of cosmic triggers from OCDB! Cosmic event specie will be effectively disabled!");
1223 }
1224
61807e09 1225 return kTRUE;
1226}
1227
1228//_____________________________________________________________________________
4b71572b 1229Bool_t AliReconstruction::LoadCDB()
1230{
0a035be5 1231 // Load CDB entries for all active detectors.
1232 // By default we load all the entries in <det>/Calib
1233 // folder.
1234
52dd4a8c 1235 AliCodeTimerAuto("",0);
4b71572b 1236
1237 AliCDBManager::Instance()->Get("GRP/CTP/Config");
1238
30d5d647 1239 AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
1240
7d566c20 1241 TString detStr = fLoadCDB;
ac4a7581 1242 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4b71572b 1243 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1244 AliCDBManager::Instance()->GetAll(Form("%s/Calib/*",fgkDetectorName[iDet]));
b6af2cb6 1245 AliCDBManager::Instance()->GetAll(Form("%s/Trigger/*",fgkDetectorName[iDet]));
4b71572b 1246 }
e122592f 1247
1248 // Temporary fix - one has to define the correct policy in order
1249 // to load the trigger OCDB entries only for the detectors that
1250 // in the trigger or that are needed in order to put correct
1251 // information in ESD
1252 AliCDBManager::Instance()->GetAll("TRIGGER/*/*");
1253
4b71572b 1254 return kTRUE;
1255}
522fdd91 1256//_____________________________________________________________________________
1257Bool_t AliReconstruction::LoadTriggerScalersCDB()
1258{
0a035be5 1259 // Load CTP scalers from OCDB.
1260 // The scalers are checked for consistency.
1261
52dd4a8c 1262 AliCodeTimerAuto("",0);
522fdd91 1263
1264 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/Scalers");
4b71572b 1265
522fdd91 1266 if (entry) {
1267
1268 AliInfo("Found an AliTriggerRunScalers in GRP/CTP/Scalers, reading it");
1269 fRunScalers = dynamic_cast<AliTriggerRunScalers*> (entry->GetObject());
1270 entry->SetOwner(0);
c7a22819 1271 if (fRunScalers && (fRunScalers->CorrectScalersOverflow() == 0)) AliInfo("32bit Trigger counters corrected for overflow");
82ebedd6 1272
522fdd91 1273 }
1274 return kTRUE;
1275}
4b71572b 1276//_____________________________________________________________________________
52dd4a8c 1277Bool_t AliReconstruction::LoadCTPTimeParamsCDB()
1278{
0a035be5 1279 // Load CTP timing information (alignment)
1280 // from OCDB.
1281
52dd4a8c 1282 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
c7ff1a33 1283 if (!entry) return kFALSE;
52dd4a8c 1284
c7ff1a33 1285 AliInfo("Found an AliCTPTimeParams in GRP/CTP/CTPtiming, reading it");
1286 fCTPTimeParams = dynamic_cast<AliCTPTimeParams*> (entry->GetObject());
1287 entry->SetOwner(0);
52dd4a8c 1288
c7ff1a33 1289 AliCDBEntry* entry2 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
1290 if (!entry2) return kFALSE;
1291
1292 AliInfo("Found an AliCTPTimeParams in GRP/CTP/TimeAlign, reading it");
028be258 1293 fCTPTimeAlign = dynamic_cast<AliCTPTimeParams*> (entry2->GetObject());
1294 entry2->SetOwner(0);
c7ff1a33 1295
1296 return kTRUE;
52dd4a8c 1297}
3d84ad67 1298
1299//_____________________________________________________________________________
1300Bool_t AliReconstruction::ReadIntensityInfoCDB()
1301{
1302 // Load LHC DIP data
2af04ffd 1303 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/LHCData");
1304 AliCDBEntry* entryCTP = AliCDBManager::Instance()->Get("GRP/CTP/Config");
1305 //
bc5c8516 1306 if (!entry || !entryCTP) {
1307 AliError(Form("Failed to extract CDB objects GRP/GRP/LHCData: %p or GRP/CTP/Config: %p",entry,entryCTP));
1308 return kFALSE;
1309 }
2af04ffd 1310 // extract BC masks
1311 enum {kA,kB,kC,kE,kNMasks};
1312 AliTriggerConfiguration* conf = (AliTriggerConfiguration*)entryCTP->GetObject();
1313 const TObjArray& clArr = conf->GetClasses();
1314 TObjArray masks(kNMasks);
1315 TIter next(&clArr);
1316 AliTriggerClass* trClass = 0;
1317 int nFound = 0;
1318 masks.SetOwner(kFALSE);
1319 //
1320 while ( (trClass=(AliTriggerClass*)next()) ) {
1321 TString trName = trClass->GetName();
1322 int ind = trName.Index("-"); // prefix in front of A,B,C,E
1323 if (ind<1) continue; // anomaly
1324 //
1325 trName = trName.Data() + ind;
1326 AliTriggerBCMask* bcMask = trClass->GetBCMask();
1327 if (!bcMask) continue;
1328 UInt_t which = 0;
1329 if (trName.BeginsWith("-A-")) which |= 0x1<<kA;
1330 else if (trName.BeginsWith("-B-")) which |= 0x1<<kB;
1331 else if (trName.BeginsWith("-C-")) which |= 0x1<<kC;
1332 else if (trName.BeginsWith("-E-")) which |= 0x1<<kE;
1333 else if (trName.BeginsWith("-AC-")) which |= (0x1<<kA) | (0x1<<kC);
1334 else if (trName.BeginsWith("-CA-")) which |= (0x1<<kA) | (0x1<<kC);
1335 else { AliWarning(Form("Unknown trigger type %s\n",trClass->GetName())); continue;}
1336 //
1337 for (int ip=kNMasks;ip--;) {
1338 if ( !(which&(0x1<<ip)) || masks[ip] ) continue; // does not match or already done
1339 masks[ip] = (TObject*)bcMask;
1340 nFound++;
1341 }
1342 if (nFound==kNMasks) break;
1343 }
1344 //
1345 AliInfo("Reading mean bunch intensities from GRP/GRP/LHCData");
1346 AliLHCData* dipData = dynamic_cast<AliLHCData*> (entry->GetObject());
1347 //
1348 for (int ib=2;ib--;) {
1349 double intI,intNI;
1350 if (dipData && (dipData->GetMeanIntensity(ib,intI,intNI,&masks)>=0)) {
1351 fBeamInt[ib][0] = intI;
1352 fBeamInt[ib][1] = intNI;
1353 AliInfo(Form("Mean intensity for beam %d: Interacting:%.2e Non-Interacting:%.2e",ib,intI,intNI));
3d84ad67 1354 }
3d84ad67 1355 }
2af04ffd 1356 return kTRUE;
1357 //
3d84ad67 1358}
1359
1360
52dd4a8c 1361//_____________________________________________________________________________
21a3aa09 1362Bool_t AliReconstruction::Run(const char* input)
596a855f 1363{
21a3aa09 1364 // Run Run Run
52dd4a8c 1365 AliCodeTimerAuto("",0);
596a855f 1366
4b71572b 1367 InitRun(input);
1368 if (GetAbort() != TSelector::kContinue) return kFALSE;
1369
1370 TChain *chain = NULL;
1371 if (fRawReader && (chain = fRawReader->GetChain())) {
2a284cef 1372 Long64_t nEntries = (fLastEvent < 0) ? (TChain::kBigNumber) : (fLastEvent - fFirstEvent + 1);
4b71572b 1373 // Proof mode
1374 if (gProof) {
52dd4a8c 1375 // Temporary fix for long raw-data runs (until socket timeout handling in PROOF is revised)
1376 gProof->Exec("gEnv->SetValue(\"Proof.SocketActivityTimeout\",-1)", kTRUE);
6c6f2624 1377
1378 if (gGrid)
1379 gProof->Exec("TGrid::Connect(\"alien://\")",kTRUE);
1380
1381 TMessage::EnableSchemaEvolutionForAll(kTRUE);
1382 gProof->Exec("TMessage::EnableSchemaEvolutionForAll(kTRUE)",kTRUE);
1383
4b71572b 1384 gProof->AddInput(this);
81d57268 1385
1386 if (!ParseOutput()) return kFALSE;
1387
975320a0 1388 gProof->SetParameter("PROOF_MaxSlavesPerNode", 9999);
4b71572b 1389 chain->SetProof();
2a284cef 1390 chain->Process("AliReconstruction","",nEntries,fFirstEvent);
4b71572b 1391 }
1392 else {
2a284cef 1393 chain->Process(this,"",nEntries,fFirstEvent);
4b71572b 1394 }
1395 }
1396 else {
1397 Begin(NULL);
1398 if (GetAbort() != TSelector::kContinue) return kFALSE;
1399 SlaveBegin(NULL);
1400 if (GetAbort() != TSelector::kContinue) return kFALSE;
1401 //******* The loop over events
44e45fac 1402 AliInfo("Starting looping over events");
4b71572b 1403 Int_t iEvent = 0;
1404 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
1405 (fRawReader && fRawReader->NextEvent())) {
1406 if (!ProcessEvent(iEvent)) {
930e6e3e 1407 Abort("ProcessEvent",TSelector::kAbortFile);
1408 return kFALSE;
4b71572b 1409 }
1410 iEvent++;
1411 }
1412 SlaveTerminate();
1413 if (GetAbort() != TSelector::kContinue) return kFALSE;
1414 Terminate();
1415 if (GetAbort() != TSelector::kContinue) return kFALSE;
21a3aa09 1416 }
21a3aa09 1417
1418 return kTRUE;
1419}
1420
1421//_____________________________________________________________________________
4b71572b 1422void AliReconstruction::InitRawReader(const char* input)
21a3aa09 1423{
4b71572b 1424 // Init raw-reader and
21a3aa09 1425 // set the input in case of raw data
0a035be5 1426
1427 AliCodeTimerAuto("",0);
1428
4b71572b 1429 if (input) fRawInput = input;
1430 fRawReader = AliRawReader::Create(fRawInput.Data());
c35f192e 1431 if (!fRawReader) {
1432 if (fRawInput.IsNull()) {
1433 AliInfo("Reconstruction will run over digits");
1434 }
1435 else {
1436 AliFatal("Can not create raw-data reader ! Exiting...");
1437 }
1438 }
e0027792 1439
35042093 1440 if (!fEquipIdMap.IsNull() && fRawReader)
1441 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1442
cd0b062e 1443 if (!fUseHLTData.IsNull()) {
1444 // create the RawReaderHLT which performs redirection of HLT input data for
1445 // the specified detectors
1446 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
1447 if (pRawReader) {
1448 fParentRawReader=fRawReader;
1449 fRawReader=pRawReader;
1450 } else {
1451 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
1452 }
1453 }
4b71572b 1454 AliSysInfo::AddStamp("CreateRawReader");
1455}
cd0b062e 1456
4b71572b 1457//_____________________________________________________________________________
1458void AliReconstruction::InitRun(const char* input)
1459{
1460 // Initialization of raw-reader,
1461 // run number, CDB etc.
52dd4a8c 1462 AliCodeTimerAuto("",0);
4b71572b 1463 AliSysInfo::AddStamp("Start");
1464
002c9d1b 1465 // Initialize raw-reader if any
4b71572b 1466 InitRawReader(input);
596a855f 1467
ec92bee0 1468 // Initialize the CDB storage
795e4a22 1469 InitCDB();
ec92bee0 1470
6bae477a 1471 // Set run number in CDBManager (if it is not already set by the user)
4b71572b 1472 if (!SetRunNumberFromData()) {
1473 Abort("SetRunNumberFromData", TSelector::kAbortProcess);
1474 return;
1475 }
002c9d1b 1476
795e4a22 1477 // Set CDB lock: from now on it is forbidden to reset the run number
1478 // or the default storage or to activate any further storage!
1479 SetCDBLock();
1480
002c9d1b 1481}
1482
1483//_____________________________________________________________________________
1484void AliReconstruction::Begin(TTree *)
1485{
1486 // Initialize AlReconstruction before
1487 // going into the event loop
1488 // Should follow the TSelector convention
1489 // i.e. initialize only the object on the client side
52dd4a8c 1490 AliCodeTimerAuto("",0);
db4aeca1 1491
b4fef0d2 1492 AliReconstruction *reco = NULL;
002c9d1b 1493 if (fInput) {
8fb1f1dc 1494 if ((reco = (AliReconstruction*)fInput->FindObject("AliReconstruction"))) {
002c9d1b 1495 *this = *reco;
002c9d1b 1496 }
1497 AliSysInfo::AddStamp("ReadInputInBegin");
1498 }
1499
6bae477a 1500 // Import ideal TGeo geometry and apply misalignment
1501 if (!gGeoManager) {
1502 TString geom(gSystem->DirName(fGAliceFileName));
1503 geom += "/geometry.root";
98e303d9 1504 AliGeomManager::LoadGeometry(geom.Data());
4b71572b 1505 if (!gGeoManager) {
1506 Abort("LoadGeometry", TSelector::kAbortProcess);
1507 return;
1508 }
281270d3 1509 AliSysInfo::AddStamp("LoadGeom");
ff5970a3 1510 TString detsToCheck=fRunLocalReconstruction;
4b71572b 1511 if(!AliGeomManager::CheckSymNamesLUT(detsToCheck.Data())) {
1512 Abort("CheckSymNamesLUT", TSelector::kAbortProcess);
1513 return;
1514 }
281270d3 1515 AliSysInfo::AddStamp("CheckGeom");
6bae477a 1516 }
8e245d15 1517
647d2bb8 1518 if(fFromCDBSnapshot){
1519 AliDebug(2,"Initializing from a CDB snapshot");
1520 if(!AliCDBManager::Instance()->InitFromSnapshot(fSnapshotFileName.Data())){
1521 Abort("InitFromSnapshot", TSelector::kAbortProcess);
1522 return;
1523 }
1524 }
1525
4b71572b 1526 if (!MisalignGeometry(fLoadAlignData)) {
1527 Abort("MisalignGeometry", TSelector::kAbortProcess);
1528 return;
1529 }
1530 AliCDBManager::Instance()->UnloadFromCache("GRP/Geometry/Data");
281270d3 1531 AliSysInfo::AddStamp("MisalignGeom");
6bae477a 1532
8cb26cdf 1533 if (!InitGRP()) {
1534 Abort("InitGRP", TSelector::kAbortProcess);
1535 return;
1536 }
1537 AliSysInfo::AddStamp("InitGRP");
1538
647d2bb8 1539 if(!fFromCDBSnapshot){
1540 if (!LoadCDB()) {
1541 Abort("LoadCDB", TSelector::kAbortProcess);
1542 return;
1543 }
1544 AliSysInfo::AddStamp("LoadCDB");
4b71572b 1545 }
325aa76f 1546
a6dd87ad 1547 if (!LoadTriggerScalersCDB()) {
1548 Abort("LoadTriggerScalersCDB", TSelector::kAbortProcess);
1549 return;
1550 }
1551 AliSysInfo::AddStamp("LoadTriggerScalersCDB");
1552
52dd4a8c 1553 if (!LoadCTPTimeParamsCDB()) {
1554 Abort("LoadCTPTimeParamsCDB", TSelector::kAbortProcess);
1555 return;
1556 }
1557 AliSysInfo::AddStamp("LoadCTPTimeParamsCDB");
a6dd87ad 1558
bd26f597 1559 if (!ReadIntensityInfoCDB()) {
1560 Abort("ReadIntensityInfoCDB", TSelector::kAbortProcess);
1561 return;
1562 }
1563 AliSysInfo::AddStamp("ReadIntensityInfoCDB");
1564
7e88424f 1565 // Read the reconstruction parameters from OCDB
1566 if (!InitRecoParams()) {
002c9d1b 1567 AliWarning("Not all detectors have correct RecoParam objects initialized");
4b71572b 1568 }
1569 AliSysInfo::AddStamp("InitRecoParams");
1570
fd2b273c 1571 if (fInput && gProof) {
b4fef0d2 1572 if (reco) *reco = *this;
fd2b273c 1573
45a6dee6 1574 gGeoManager->SetName("Geometry");
fd2b273c 1575 gProof->AddInputData(gGeoManager,kTRUE);
002c9d1b 1576 gGeoManager = NULL;
fd2b273c 1577 gProof->AddInputData(const_cast<TMap*>(AliCDBManager::Instance()->GetEntryCache()),kTRUE);
002c9d1b 1578 fInput->Add(new TParameter<Int_t>("RunNumber",AliCDBManager::Instance()->GetRun()));
f7a1cc68 1579 AliMagF *magFieldMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
ead7b391 1580 magFieldMap->SetName("MagneticFieldMap");
fd2b273c 1581 gProof->AddInputData(magFieldMap,kTRUE);
42457748 1582 if (fAnalysis) {
1583 fAnalysis->SetName("Analysis");
1584 gProof->AddInputData(fAnalysis,kTRUE);
1585 }
002c9d1b 1586 }
4b71572b 1587
1588}
1589
1590//_____________________________________________________________________________
1591void AliReconstruction::SlaveBegin(TTree*)
1592{
1593 // Initialization related to run-loader,
1594 // vertexer, trackers, recontructors
1595 // In proof mode it is executed on the slave
52dd4a8c 1596 AliCodeTimerAuto("",0);
4b71572b 1597
db4aeca1 1598 TProofOutputFile *outProofFile = NULL;
81d57268 1599 if (fInput) {
1600 if (AliDebugLevel() > 0) fInput->Print();
ef5e52f6 1601 if (AliDebugLevel() > 10) fInput->Dump();
db4aeca1 1602 if (AliReconstruction *reco = (AliReconstruction*)fInput->FindObject("AliReconstruction")) {
1603 *this = *reco;
1604 }
4b71572b 1605 if (TGeoManager *tgeo = (TGeoManager*)fInput->FindObject("Geometry")) {
1606 gGeoManager = tgeo;
1607 AliGeomManager::SetGeometry(tgeo);
7e88424f 1608 }
281270d3 1609 if (TMap *entryCache = (TMap*)fInput->FindObject("CDBEntryCache")) {
1610 Int_t runNumber = -1;
1611 if (TProof::GetParameter(fInput,"RunNumber",runNumber) == 0) {
1612 AliCDBManager *man = AliCDBManager::Instance(entryCache,runNumber);
1613 man->SetCacheFlag(kTRUE);
1614 man->SetLock(kTRUE);
1615 man->Print();
1616 }
4b71572b 1617 }
ead7b391 1618 if (AliMagF *map = (AliMagF*)fInput->FindObject("MagneticFieldMap")) {
ef5e52f6 1619 AliMagF *newMap = new AliMagF(*map);
1620 if (!newMap->LoadParameterization()) {
1621 Abort("AliMagF::LoadParameterization", TSelector::kAbortProcess);
1622 return;
1623 }
1624 TGeoGlobalMagField::Instance()->SetField(newMap);
1625 TGeoGlobalMagField::Instance()->Lock();
4b71572b 1626 }
42457748 1627 if (!fAnalysis) {
1628 // Attempt to get the analysis manager from the input list
1629 fAnalysis = (AliAnalysisManager*)fInput->FindObject("Analysis");
1630 if (fAnalysis) AliInfo("==== Analysis manager retrieved from input list ====");
1631 }
81d57268 1632 if (TNamed *outputFileName = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE"))
1633 fProofOutputFileName = outputFileName->GetTitle();
1634 if (TNamed *outputLocation = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_LOCATION"))
1635 fProofOutputLocation = outputLocation->GetTitle();
1636 if (fInput->FindObject("PROOF_OUTPUTFILE_DATASET"))
1637 fProofOutputDataset = kTRUE;
1638 if (TNamed *archiveList = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_ARCHIVE"))
1639 fProofOutputArchive = archiveList->GetTitle();
1640 if (!fProofOutputFileName.IsNull() &&
1641 !fProofOutputLocation.IsNull() &&
1642 fProofOutputArchive.IsNull()) {
1643 if (!fProofOutputDataset) {
1644 outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"M");
1645 outProofFile->SetOutputFileName(Form("%s%s",fProofOutputLocation.Data(),fProofOutputFileName.Data()));
1646 }
1647 else {
1648 outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"DROV",fProofOutputLocation.Data());
1649 }
1650 if (AliDebugLevel() > 0) outProofFile->Dump();
db4aeca1 1651 fOutput->Add(outProofFile);
4b71572b 1652 }
002c9d1b 1653 AliSysInfo::AddStamp("ReadInputInSlaveBegin");
7e88424f 1654 }
42457748 1655 // Check if analysis was requested in the reconstruction event loop
1656 if (!fAnalysis) {
1657 // Attempt to connect in-memory singleton
1658 fAnalysis = AliAnalysisManager::GetAnalysisManager();
1659 if (fAnalysis) AliInfo(Form("==== Analysis manager <%s> found in memory ====", fAnalysis->GetName()));
1660 // Check if an analysis macro was specified
1661 if (!fAnalysis && !fAnalysisMacro.IsNull()) {
1662 // Run specified analysis macro
1663 gROOT->ProcessLine(Form(".x %s",fAnalysisMacro.Data()));
1664 fAnalysis = AliAnalysisManager::GetAnalysisManager();
1665 if (!fAnalysis) AliError(Form("No analysis manager produced by analysis macro %s", fAnalysisMacro.Data()));
1666 else AliInfo(Form("==== Analysis manager <%s> produced by analysis macro <%s> ====",
1667 fAnalysis->GetName(), fAnalysisMacro.Data()));
1668 }
1669 }
1670
4b71572b 1671 // get the run loader
1672 if (!InitRunLoader()) {
1673 Abort("InitRunLoader", TSelector::kAbortProcess);
1674 return;
1675 }
1676 AliSysInfo::AddStamp("LoadLoader");
1677
325aa76f 1678 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
2257f27e 1679
f08fc9f5 1680 // get trackers
b8cd5251 1681 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
4b71572b 1682 Abort("CreateTrackers", TSelector::kAbortProcess);
1683 return;
1684 }
1685 AliSysInfo::AddStamp("CreateTrackers");
24f7a148 1686
36711aa4 1687 // create the ESD output file and tree
db4aeca1 1688 if (!outProofFile) {
1689 ffile = TFile::Open("AliESDs.root", "RECREATE");
1690 ffile->SetCompressionLevel(2);
1691 if (!ffile->IsOpen()) {
1692 Abort("OpenESDFile", TSelector::kAbortProcess);
1693 return;
1694 }
1695 }
1696 else {
81d57268 1697 AliInfo(Form("Opening output PROOF file: %s/%s",
1698 outProofFile->GetDir(), outProofFile->GetFileName()));
db4aeca1 1699 if (!(ffile = outProofFile->OpenFile("RECREATE"))) {
1700 Abort(Form("Problems opening output PROOF file: %s/%s",
1701 outProofFile->GetDir(), outProofFile->GetFileName()),
1702 TSelector::kAbortProcess);
1703 return;
1704 }
596a855f 1705 }
46698ae4 1706
21a3aa09 1707 ftree = new TTree("esdTree", "Tree with ESD objects");
1708 fesd = new AliESDEvent();
1709 fesd->CreateStdContent();
8b12d288 1710 // add a so far non-std object to the ESD, this will
1711 // become part of the std content
1712 fesd->AddObject(new AliESDHLTDecision);
1713
32ba9c61 1714 fesd->WriteToTree(ftree);
1d99986f 1715 if (fWriteESDfriend) {
ee7c441c 1716 ffileF = TFile::Open("AliESDfriends.root", "RECREATE");
03a8000a 1717 ftreeF = new TTree("esdFriendTree", "Tree with ESD Friend objects");
ee7c441c 1718 fesdf = new AliESDfriend();
03a8000a 1719 ftreeF->Branch("ESDfriend.","AliESDfriend", &fesdf);
21a3aa09 1720 fesd->AddObject(fesdf);
ee7c441c 1721 ffile->cd();
1d99986f 1722 }
f9604a22 1723 ftree->GetUserInfo()->Add(fesd);
1724
1725 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
1726 fhltesd = new AliESDEvent();
1727 fhltesd->CreateStdContent();
7491aea6 1728 // read the ESD template from CDB
1729 // HLT is allowed to put non-std content to its ESD, the non-std
1730 // objects need to be created before invocation of WriteToTree in
1731 // order to create all branches. Initialization is done from an
1732 // ESD layout template in CDB
1733 AliCDBManager* man = AliCDBManager::Instance();
1734 AliCDBPath hltESDConfigPath("HLT/ConfigHLT/esdLayout");
1735 AliCDBEntry* hltESDConfig=NULL;
1736 if (man->GetId(hltESDConfigPath)!=NULL &&
1737 (hltESDConfig=man->Get(hltESDConfigPath))!=NULL) {
1738 AliESDEvent* pESDLayout=dynamic_cast<AliESDEvent*>(hltESDConfig->GetObject());
1739 if (pESDLayout) {
1740 // init all internal variables from the list of objects
1741 pESDLayout->GetStdContent();
1742
1743 // copy content and create non-std objects
1744 *fhltesd=*pESDLayout;
1745 fhltesd->Reset();
1746 } else {
1747 AliError(Form("error setting hltEsd layout from %s: invalid object type",
1748 hltESDConfigPath.GetPath().Data()));
1749 }
1750 }
1751
f9604a22 1752 fhltesd->WriteToTree(fhlttree);
1753 fhlttree->GetUserInfo()->Add(fhltesd);
5728d3d5 1754
ac4a7581 1755 ProcInfo_t procInfo;
1756 gSystem->GetProcInfo(&procInfo);
73bbf779 1757 AliInfo(Form("Current memory usage %ld %ld", procInfo.fMemResident, procInfo.fMemVirtual));
8661738e 1758
325aa76f 1759 //QA
930e6e3e 1760 //Initialize the QA and start of cycle
f1c1204d 1761 if (fRunQA || fRunGlobalQA)
1762 InitQA() ;
aa3c69a9 1763
7167ae53 1764 //Initialize the Plane Efficiency framework
1765 if (fRunPlaneEff && !InitPlaneEff()) {
4b71572b 1766 Abort("InitPlaneEff", TSelector::kAbortProcess);
1767 return;
7167ae53 1768 }
aa3c69a9 1769
14dd053c 1770 if (strcmp(gProgName,"alieve") == 0)
1771 fRunAliEVE = InitAliEVE();
42457748 1772 // If we have an analysis manager, connect the AliRecoInputHandler here
1773 if (fAnalysis) {
1774 if (!dynamic_cast<AliRecoInputHandler*>(fAnalysis->GetInputEventHandler())) {
1775 AliError("Analysis manager used in reconstruction should use AliRecoInputHandler - \
1776 \n ->Replacing with AliRecoInputHandler instance.");
1777 delete fAnalysis->GetInputEventHandler();
1778 }
1779 // Set the event and other data pointers
1780 fRecoHandler = new AliRecoInputHandler();
1781 fRecoHandler->Init(ftree, "LOCAL");
1782 fRecoHandler->SetEvent(fesd);
1783 fRecoHandler->SetESDfriend(fesdf);
1784 fRecoHandler->SetHLTEvent(fhltesd);
1785 fRecoHandler->SetHLTTree(fhlttree);
1786 fAnalysis->SetInputEventHandler(fRecoHandler);
1787 // Enter external loop mode
1788 fAnalysis->SetExternalLoop(kTRUE);
1789 // Initialize analysis
1790 fAnalysis->StartAnalysis("local", (TTree*)0);
1791 // Connect ESD tree with the input container
1792 fAnalysis->GetCommonInputContainer()->SetData(ftree);
1793 }
4b71572b 1794 return;
21a3aa09 1795}
1796
1797//_____________________________________________________________________________
4b71572b 1798Bool_t AliReconstruction::Process(Long64_t entry)
1799{
1800 // run the reconstruction over a single entry
1801 // from the chain with raw data
52dd4a8c 1802 AliCodeTimerAuto("",0);
4b71572b 1803
1804 TTree *currTree = fChain->GetTree();
33314186 1805 AliRawVEvent *event = NULL;
4b71572b 1806 currTree->SetBranchAddress("rawevent",&event);
1807 currTree->GetEntry(entry);
1808 fRawReader = new AliRawReaderRoot(event);
42457748 1809 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
4b71572b 1810 delete fRawReader;
1811 fRawReader = NULL;
1812 delete event;
1813
1814 return fStatus;
1815}
1816
1817//_____________________________________________________________________________
1818void AliReconstruction::Init(TTree *tree)
1819{
0a035be5 1820 // Implementation of TSelector::Init()
1821 // method
4b71572b 1822 if (tree == 0) {
1823 AliError("The input tree is not found!");
1824 return;
1825 }
1826 fChain = tree;
1827}
1828
1829//_____________________________________________________________________________
1830Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
21a3aa09 1831{
1832 // run the reconstruction over a single event
1833 // The event loop is steered in Run method
1834
10d100d4 1835
470f88b0 1836 static Long_t oldMres=0;
1837 static Long_t oldMvir=0;
1838 static Float_t oldCPU=0;
d97f1dbe 1839 static Long_t aveDMres=0;
1840 static Long_t aveDMvir=0;
1841 static Float_t aveDCPU=0;
470f88b0 1842
52dd4a8c 1843 AliCodeTimerAuto("",0);
21a3aa09 1844
0a035be5 1845 AliESDpid pid;
10d100d4 1846
21a3aa09 1847 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
1848 fRunLoader->SetEventNumber(iEvent);
4018c387 1849 if (fRawReader)
1850 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1851 iEvent, iEvent);
21a3aa09 1852 fRunLoader->TreeE()->Fill();
5b3ea9c5 1853
396f89bc 1854 if (fRawReader && fRawReader->UseAutoSaveESD())
4b71572b 1855 fRunLoader->TreeE()->AutoSave("SaveSelf");
21a3aa09 1856 }
1857
1858 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
21a3aa09 1859 return kTRUE;
1860 }
1861
aa3c69a9 1862
16447f18 1863 fRunLoader->GetEvent(iEvent);
1864
7e88424f 1865 // Fill Event-info object
1866 GetEventInfo();
77ba28ba 1867 fRecoParam.SetEventSpecie(fRunInfo,fEventInfo,fListOfCosmicTriggers);
d97f1dbe 1868
1869 ProcInfo_t procInfo;
1870 if(iEvent==fFirstEvent) {
1871 gSystem->GetProcInfo(&procInfo);
1872 oldMres=procInfo.fMemResident;
1873 oldMvir=procInfo.fMemVirtual;
1874 oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
1875 }
470f88b0 1876 AliInfo(Form("================================= Processing event %d of type %-10s ==================================", iEvent,fRecoParam.PrintEventSpecie()));
7e88424f 1877
a00021a7 1878 // Set the reco-params
1879 {
1880 TString detStr = fLoadCDB;
ac4a7581 1881 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
a00021a7 1882 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1883 AliReconstructor *reconstructor = GetReconstructor(iDet);
1884 if (reconstructor && fRecoParam.GetDetRecoParamArray(iDet)) {
57acd2d2 1885 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
1886 reconstructor->SetRecoParam(par);
0a035be5 1887 reconstructor->GetPidSettings(&pid);
10d100d4 1888 reconstructor->SetEventInfo(&fEventInfo);
57acd2d2 1889 if (fRunQA) {
c3c10397 1890 AliQAManager::QAManager()->SetEventInfo(&fEventInfo) ;
eca4fa66 1891 AliQAManager::QAManager()->SetRecoParam(iDet, par) ;
619aafe6 1892 if (par) AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(par->GetEventSpecie())) ;
57acd2d2 1893 }
a00021a7 1894 }
1895 }
92664bc8 1896 //
1897 if (fRunQA || fRunGlobalQA) AliQADataMaker::SetEventTrigClasses(fEventInfo.GetTriggerClasses()); // RS: select which histo clones are to be filled
1898 //
9dad1020 1899 if (fRunQA) {
1900 const AliDetectorRecoParam *grppar = fRecoParam.GetDetRecoParam(kNDetectors);
1901 AliQAManager::QAManager()->SetRecoParam(AliQAv1::kGLOBAL, grppar) ;
1902 AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(grppar->GetEventSpecie())) ;
1903 }
a00021a7 1904 }
1905
ca13fb87 1906 // QA on single raw
514cb8c7 1907 if (fRunQA && IsInTasks(AliQAv1::kRAWS)) {
eca4fa66 1908 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
1909 AliQAManager::QAManager()->RunOneEvent(fRawReader) ;
57acd2d2 1910 }
d506c543 1911 // local single event reconstruction
b26c3770 1912 if (!fRunLocalReconstruction.IsNull()) {
d506c543 1913 TString detectors=fRunLocalReconstruction;
a441bf51 1914 // run HLT event reconstruction first
d506c543 1915 // ;-( IsSelected changes the string
1916 if (IsSelected("HLT", detectors) &&
1917 !RunLocalEventReconstruction("HLT")) {
4b71572b 1918 if (fStopOnError) {CleanUp(); return kFALSE;}
a441bf51 1919 }
1920 detectors=fRunLocalReconstruction;
1921 detectors.ReplaceAll("HLT", "");
1922 if (!RunLocalEventReconstruction(detectors)) {
13effe3f 1923 if (fStopOnError) {
1924 CleanUp();
1925 return kFALSE;
1926 }
b26c3770 1927 }
1928 }
1929
6b3a883f 1930
1931 // fill Event header information from the RawEventHeader
1932 if (fRawReader){FillRawEventHeaderESD(fesd);}
1933 if (fRawReader){FillRawEventHeaderESD(fhltesd);}
1934
21a3aa09 1935 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1936 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
7b649c02 1937
1938 ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
1939 ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
1940 ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
1941 ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
1942
21a3aa09 1943 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1944 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
fd2e2210 1945
1946 fesd->SetEventSpecie(fRecoParam.GetEventSpecie());
1947 fhltesd->SetEventSpecie(fRecoParam.GetEventSpecie());
46698ae4 1948
d6ee376f 1949 // Set magnetic field from the tracker
21a3aa09 1950 fesd->SetMagneticField(AliTracker::GetBz());
1951 fhltesd->SetMagneticField(AliTracker::GetBz());
33fe5eb1 1952 //
3d84ad67 1953 AliESDRun *esdRun,*esdRunH;
1954 esdRun = (AliESDRun*)fesd->GetESDRun();
1955 esdRunH = (AliESDRun*)fhltesd->GetESDRun();
1956 esdRun->SetBeamEnergyIsSqrtSHalfGeV();
1957 esdRunH->SetBeamEnergyIsSqrtSHalfGeV();
1958 //
1959 for (int ib=2;ib--;) for (int it=2;it--;) {
1960 esdRun->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
1961 esdRunH->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
1962 }
c587bcde 1963 //
33fe5eb1 1964 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
1965 if (fld) { // set info needed for field initialization
1966 fesd->SetCurrentL3(fld->GetCurrentSol());
1967 fesd->SetCurrentDip(fld->GetCurrentDip());
1968 fesd->SetBeamEnergy(fld->GetBeamEnergy());
1969 fesd->SetBeamType(fld->GetBeamTypeText());
1970 fesd->SetUniformBMap(fld->IsUniform());
1971 fesd->SetBInfoStored();
1972 //
1973 fhltesd->SetCurrentL3(fld->GetCurrentSol());
1974 fhltesd->SetCurrentDip(fld->GetCurrentDip());
1975 fhltesd->SetBeamEnergy(fld->GetBeamEnergy());
1976 fhltesd->SetBeamType(fld->GetBeamTypeText());
1977 fhltesd->SetUniformBMap(fld->IsUniform());
1978 fhltesd->SetBInfoStored();
1979 }
1980 //
71f6cda4 1981 // Set most probable pt, for B=0 tracking
9257a1bd 1982 // Get the global reco-params. They are atposition 16 inside the array of detectors in fRecoParam
ac4a7581 1983 const AliGRPRecoParam *grpRecoParam = dynamic_cast<const AliGRPRecoParam*>(fRecoParam.GetDetRecoParam(kNDetectors));
71f6cda4 1984 if (grpRecoParam) AliExternalTrackParam::SetMostProbablePt(grpRecoParam->GetMostProbablePt());
46698ae4 1985
2e3550da 1986 // Fill raw-data error log into the ESD
21a3aa09 1987 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 1988
2257f27e 1989 // vertex finder
1990 if (fRunVertexFinder) {
4b71572b 1991 if (!RunVertexFinder(fesd)) {
1992 if (fStopOnError) {CleanUp(); return kFALSE;}
2257f27e 1993 }
1994 }
1995
58e8dc31 1996 // For Plane Efficiency: run the SPD trackleter
1997 if (fRunPlaneEff && fSPDTrackleter) {
1998 if (!RunSPDTrackleting(fesd)) {
1999 if (fStopOnError) {CleanUp(); return kFALSE;}
2000 }
2001 }
2002
e66fbafb 2003 // Muon tracking
b8cd5251 2004 if (!fRunTracking.IsNull()) {
e66fbafb 2005 if (fRunMuonTracking) {
21a3aa09 2006 if (!RunMuonTracking(fesd)) {
4b71572b 2007 if (fStopOnError) {CleanUp(); return kFALSE;}
24f7a148 2008 }
596a855f 2009 }
2010 }
2011
e66fbafb 2012 // barrel tracking
2013 if (!fRunTracking.IsNull()) {
0a035be5 2014 if (!RunTracking(fesd,pid)) {
4b71572b 2015 if (fStopOnError) {CleanUp(); return kFALSE;}
e66fbafb 2016 }
2017 }
21c573b7 2018
596a855f 2019 // fill ESD
2020 if (!fFillESD.IsNull()) {
d506c543 2021 TString detectors=fFillESD;
f6806ad3 2022 // run HLT first and on hltesd
d506c543 2023 // ;-( IsSelected changes the string
2024 if (IsSelected("HLT", detectors) &&
2025 !FillESD(fhltesd, "HLT")) {
4b71572b 2026 if (fStopOnError) {CleanUp(); return kFALSE;}
f6806ad3 2027 }
2028 detectors=fFillESD;
d5105682 2029 // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
2030 if (detectors.Contains("ALL")) {
2031 detectors="";
ac4a7581 2032 for (Int_t idet=0; idet<kNDetectors; ++idet){
d5105682 2033 detectors += fgkDetectorName[idet];
2034 detectors += " ";
2035 }
2036 }
f6806ad3 2037 detectors.ReplaceAll("HLT", "");
2038 if (!FillESD(fesd, detectors)) {
4b71572b 2039 if (fStopOnError) {CleanUp(); return kFALSE;}
596a855f 2040 }
2041 }
f7812afc 2042
b647652d 2043
21a3aa09 2044 ffile->cd();
a6ee503a 2045
3c3709c4 2046 //
67be5c77 2047 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 2048 //
21a3aa09 2049 const Int_t ntracks = fesd->GetNumberOfTracks();
3c3709c4 2050 const Double_t kRadius = 2.8; //something less than the beam pipe radius
2051
2052 TObjArray trkArray;
2053 UShort_t *selectedIdx=new UShort_t[ntracks];
2054
2055 for (Int_t itrack=0; itrack<ntracks; itrack++){
98a50ff3 2056 const Double_t kMaxStep = 1; //max step over the material
3c3709c4 2057 Bool_t ok;
2058
21a3aa09 2059 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 2060 if (!track) continue;
2061
2062 AliExternalTrackParam *tpcTrack =
2063 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 2064 ok = kFALSE;
2065 if (tpcTrack)
2066 ok = AliTracker::
52dd4a8c 2067 PropagateTrackToBxByBz(tpcTrack,kRadius,track->GetMass(),kMaxStep,kFALSE);
43c9dae1 2068
3c3709c4 2069 if (ok) {
2070 Int_t n=trkArray.GetEntriesFast();
2071 selectedIdx[n]=track->GetID();
2072 trkArray.AddLast(tpcTrack);
2073 }
2074
3d65e645 2075 //Tracks refitted by ITS should already be at the SPD vertex
2076 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
2077
2078 AliTracker::
52dd4a8c 2079 PropagateTrackToBxByBz(track,kRadius,track->GetMass(),kMaxStep,kFALSE);
2080 Double_t x[3]; track->GetXYZ(x);
2081 Double_t b[3]; AliTracker::GetBxByBz(x,b);
2082 track->RelateToVertexBxByBz(fesd->GetPrimaryVertexSPD(), b, kVeryBig);
3c3709c4 2083
3c3709c4 2084 }
2085
2086 //
2087 // Improve the reconstructed primary vertex position using the tracks
2088 //
59224b2b 2089 Bool_t runVertexFinderTracks = fRunVertexFinderTracks;
2090 if(fesd->GetPrimaryVertexSPD()) {
2091 TString vtitle = fesd->GetPrimaryVertexSPD()->GetTitle();
2092 if(vtitle.Contains("cosmics")) {
2093 runVertexFinderTracks=kFALSE;
2094 }
c060d7fe 2095 }
a00021a7 2096
2097 if (runVertexFinderTracks) {
3c3709c4 2098 // TPC + ITS primary vertex
f09c879d 2099 ftVertexer->SetITSMode();
f2a195c1 2100 ftVertexer->SetConstraintOff();
a00021a7 2101 // get cuts for vertexer from AliGRPRecoParam
1c7554f9 2102 Bool_t constrSPD=kFALSE;
a00021a7 2103 if (grpRecoParam) {
2104 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
2105 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
8eaa1a42 2106 grpRecoParam->GetVertexerTracksCutsITS(cutsVertexer,nCutsVertexer);
2107 ftVertexer->SetCuts(cutsVertexer,nCutsVertexer);
a00021a7 2108 delete [] cutsVertexer; cutsVertexer = NULL;
1c7554f9 2109 if(grpRecoParam->GetVertexerTracksConstraintITS()) {
2110 if(fDiamondProfile && fDiamondProfile->GetXRes()<kRadius){
2111 ftVertexer->SetVtxStart(fDiamondProfile); // apply constraint only if sigmax is smaller than the beam pipe radius
2112 }else{
2113 if(fDiamondProfileSPD && fDiamondProfileSPD->GetXRes()<kRadius){
2114 ftVertexer->SetVtxStart(fDiamondProfileSPD);
2115 constrSPD=kTRUE;
2116 }
2117 }
dd15203b 2118 }
43c9dae1 2119 }
21a3aa09 2120 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 2121 if (pvtx) {
1c7554f9 2122 if(constrSPD){
2123 TString title=pvtx->GetTitle();
2124 title.Append("SPD");
2125 pvtx->SetTitle(title);
2126 }
3c3709c4 2127 if (pvtx->GetStatus()) {
c264b61b 2128 fesd->SetPrimaryVertexTracks(pvtx);
3c3709c4 2129 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 2130 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 2131 Double_t x[3]; t->GetXYZ(x);
2132 Double_t b[3]; AliTracker::GetBxByBz(x,b);
2133 t->RelateToVertexBxByBz(pvtx, b, kVeryBig);
3c3709c4 2134 }
2135 }
9bcaa1d7 2136 delete pvtx; pvtx=NULL;
3c3709c4 2137 }
2138
2139 // TPC-only primary vertex
f09c879d 2140 ftVertexer->SetTPCMode();
f2a195c1 2141 ftVertexer->SetConstraintOff();
a00021a7 2142 // get cuts for vertexer from AliGRPRecoParam
2143 if (grpRecoParam) {
2144 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
2145 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
8eaa1a42 2146 grpRecoParam->GetVertexerTracksCutsTPC(cutsVertexer,nCutsVertexer);
2147 ftVertexer->SetCuts(cutsVertexer,nCutsVertexer);
a00021a7 2148 delete [] cutsVertexer; cutsVertexer = NULL;
dd15203b 2149 if(fDiamondProfileTPC && grpRecoParam->GetVertexerTracksConstraintTPC()) {
2150 if(fDiamondProfileTPC->GetXRes()<kRadius) ftVertexer->SetVtxStart(fDiamondProfileTPC); // apply constraint only if sigmax is smaller than the beam pipe radius
2151 }
43c9dae1 2152 }
21a3aa09 2153 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 2154 if (pvtx) {
2155 if (pvtx->GetStatus()) {
21a3aa09 2156 fesd->SetPrimaryVertexTPC(pvtx);
3d65e645 2157 for (Int_t i=0; i<ntracks; i++) {
2158 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 2159 Double_t x[3]; t->GetXYZ(x);
2160 Double_t b[3]; AliTracker::GetBxByBz(x,b);
2161 t->RelateToVertexTPCBxByBz(pvtx, b, kVeryBig);
3c3709c4 2162 }
2163 }
9bcaa1d7 2164 delete pvtx; pvtx=NULL;
3c3709c4 2165 }
2166
2167 }
2168 delete[] selectedIdx;
2169
1c7554f9 2170 if(fDiamondProfile && fDiamondProfile->GetXRes()<kRadius) fesd->SetDiamond(fDiamondProfile);
2171 else fesd->SetDiamond(fDiamondProfileSPD);
c5e3e5d1 2172
d1683eef 2173 if (fRunV0Finder) {
2174 // V0 finding
2175 AliV0vertexer vtxer;
61a14552 2176 // get cuts for V0vertexer from AliGRPRecoParam
2177 if (grpRecoParam) {
2178 Int_t nCutsV0vertexer = grpRecoParam->GetVertexerV0NCuts();
2179 Double_t *cutsV0vertexer = new Double_t[nCutsV0vertexer];
2180 grpRecoParam->GetVertexerV0Cuts(cutsV0vertexer);
2181 vtxer.SetCuts(cutsV0vertexer);
2182 delete [] cutsV0vertexer; cutsV0vertexer = NULL;
2183 }
21a3aa09 2184 vtxer.Tracks2V0vertices(fesd);
5e4ff34d 2185
d1683eef 2186 if (fRunCascadeFinder) {
2187 // Cascade finding
2188 AliCascadeVertexer cvtxer;
61a14552 2189 // get cuts for CascadeVertexer from AliGRPRecoParam
2190 if (grpRecoParam) {
2191 Int_t nCutsCascadeVertexer = grpRecoParam->GetVertexerCascadeNCuts();
2192 Double_t *cutsCascadeVertexer = new Double_t[nCutsCascadeVertexer];
2193 grpRecoParam->GetVertexerCascadeCuts(cutsCascadeVertexer);
2194 cvtxer.SetCuts(cutsCascadeVertexer);
2195 delete [] cutsCascadeVertexer; cutsCascadeVertexer = NULL;
2196 }
21a3aa09 2197 cvtxer.V0sTracks2CascadeVertices(fesd);
d1683eef 2198 }
5e4ff34d 2199 }
c8122432 2200
50f012a8 2201 // AdC+FN
2202 if (fReconstructor[3])
2203 GetReconstructor(3)->FillEventTimeWithTOF(fesd,&pid);
2204
2205 // combined PID
2206 pid.MakePID(fesd);
2207
2208 if (fFillTriggerESD) {
2209 if (!FillTriggerESD(fesd)) {
2210 if (fStopOnError) {CleanUp(); return kFALSE;}
2211 }
2212 }
2213 // Always fill scalers
2214 if (!FillTriggerScalers(fesd)) {
2215 if (fStopOnError) {CleanUp(); return kFALSE;}
2216 }
2217
c8122432 2218 // write ESD
2219 if (fCleanESD) CleanESD(fesd);
2220 //
1f9831ab 2221 // RS run updated trackleter: since we want to mark the clusters used by tracks and also mark the
2222 // tracks interpreted as primary, this step should be done in the very end, when full
2223 // ESD info is available (particulalry, V0s)
2224 // vertex finder
c8122432 2225 if (fRunMultFinder) {
2226 if (!RunMultFinder(fesd)) {
2227 if (fStopOnError) {CleanUp(); return kFALSE;}
2228 }
2229 }
854c6476 2230
514cb8c7 2231 if (fRunQA && IsInTasks(AliQAv1::kESDS)) {
eca4fa66 2232 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
aeb8fc30 2233 AliQAManager::QAManager()->RunOneEvent(fesd, fhltesd) ;
57acd2d2 2234 }
bea94759 2235 if (fRunGlobalQA) {
eca4fa66 2236 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
4018c387 2237 if (qadm)
57acd2d2 2238 qadm->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
514cb8c7 2239 if (qadm && IsInTasks(AliQAv1::kESDS))
4e25ac79 2240 qadm->Exec(AliQAv1::kESDS, fesd);
b03591ab 2241 }
854c6476 2242
8b12d288 2243 // copy HLT decision from HLTesd to esd
2244 // the most relevant information is stored in a reduced container in the esd,
2245 // while the full information can be found in the HLTesd
2246 TObject* pHLTSrc=fhltesd->FindListObject(AliESDHLTDecision::Name());
2247 TObject* pHLTTgt=fesd->FindListObject(AliESDHLTDecision::Name());
2248 if (pHLTSrc && pHLTTgt) {
2249 pHLTSrc->Copy(*pHLTTgt);
2250 }
3ba71cb5 2251 //
2252 // Perform analysis of this event if requested
2253 // RS: Should be done before WriteESDfriend, since the latter may clean the esdfriend
2254 if (fAnalysis) {
2255 fRecoHandler->BeginEvent(iEvent);
2256 fAnalysis->ExecAnalysis();
2257 fRecoHandler->FinishEvent();
2258 }
2259 //
ee7c441c 2260 if (fWriteESDfriend)
21a3aa09 2261 fesd->GetESDfriend(fesdf);
ee7c441c 2262
21a3aa09 2263 ftree->Fill();
fc01854a 2264 if (fWriteESDfriend) {
f00558b6 2265 WriteESDfriend();
fc01854a 2266 }
2d91a353 2267 // Auto-save the ESD tree in case of prompt reco @P2
396f89bc 2268 if (fRawReader && fRawReader->UseAutoSaveESD()) {
2d91a353 2269 ftree->AutoSave("SaveSelf");
ee7c441c 2270 if (fWriteESDfriend) ftreeF->AutoSave("SaveSelf");
be103ac8 2271 }
2d91a353 2272
500d54ab 2273 // write HLT ESD
21a3aa09 2274 fhlttree->Fill();
1d99986f 2275
14dd053c 2276 // call AliEVE
2277 if (fRunAliEVE) RunAliEVE();
0c4df52e 2278 //
21a3aa09 2279 fesd->Reset();
2280 fhltesd->Reset();
5728d3d5 2281 if (fWriteESDfriend) {
21a3aa09 2282 fesdf->~AliESDfriend();
2283 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 2284 }
a5fa6165 2285
ac4a7581 2286 gSystem->GetProcInfo(&procInfo);
d97f1dbe 2287 Long_t dMres=(procInfo.fMemResident-oldMres)/1024;
2288 Long_t dMvir=(procInfo.fMemVirtual-oldMvir)/1024;
2289 Float_t dCPU=procInfo.fCpuUser+procInfo.fCpuSys-oldCPU;
2290 aveDMres+=(dMres-aveDMres)/(iEvent-fFirstEvent+1);
2291 aveDMvir+=(dMvir-aveDMvir)/(iEvent-fFirstEvent+1);
2292 aveDCPU+=(dCPU-aveDCPU)/(iEvent-fFirstEvent+1);
73bbf779 2293 AliInfo(Form("======================= End Event %d: Res %ld(%3ld <%3ld>) Vir %ld(%3ld <%3ld>) CPU %5.2f <%5.2f> ===================",
d97f1dbe 2294 iEvent, procInfo.fMemResident/1024, dMres, aveDMres, procInfo.fMemVirtual/1024, dMvir, aveDMvir, dCPU, aveDCPU));
470f88b0 2295 oldMres=procInfo.fMemResident;
2296 oldMvir=procInfo.fMemVirtual;
2297 oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
a5fa6165 2298
ca13fb87 2299 fEventInfo.Reset();
ac4a7581 2300 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
42ec5d3d 2301 if (fReconstructor[iDet]) {
a00021a7 2302 fReconstructor[iDet]->SetRecoParam(NULL);
42ec5d3d 2303 fReconstructor[iDet]->SetEventInfo(NULL);
2304 }
1f26f3e7 2305 if (fTracker[iDet]) fTracker[iDet]->SetEventInfo(NULL);
ca13fb87 2306 }
2307
53c8f690 2308 if (fRunQA || fRunGlobalQA)
eca4fa66 2309 AliQAManager::QAManager()->Increment() ;
0c4df52e 2310
ca13fb87 2311 return kTRUE;
21a3aa09 2312}
2313
2314//_____________________________________________________________________________
4b71572b 2315void AliReconstruction::SlaveTerminate()
21a3aa09 2316{
4b71572b 2317 // Finalize the run on the slave side
21a3aa09 2318 // Called after the exit
2319 // from the event loop
52dd4a8c 2320 AliCodeTimerAuto("",0);
42457748 2321 // If analysis was done during reconstruction, we need to call SlaveTerminate for it
2322 if (fAnalysis) {
2323 fAnalysis->PackOutput(fOutput);
2324 fAnalysis->SetSkipTerminate(kTRUE);
2325 fAnalysis->Terminate();
2326 }
21a3aa09 2327
2328 if (fIsNewRunLoader) { // galice.root didn't exist
2329 fRunLoader->WriteHeader("OVERWRITE");
5b3ea9c5 2330 fRunLoader->WriteTrigger("OVERWRITE");
21a3aa09 2331 fRunLoader->CdGAFile();
2332 fRunLoader->Write(0, TObject::kOverwrite);
2333 }
2334
f747912b 2335 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
2336 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
2337
2338 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
2339 cdbMapCopy->SetOwner(1);
2340 cdbMapCopy->SetName("cdbMap");
2341 TIter iter(cdbMap->GetTable());
2342
2343 TPair* pair = 0;
2344 while((pair = dynamic_cast<TPair*> (iter.Next()))){
2345 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
c7a22819 2346 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
2347 if (keyStr && valStr)
2348 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
f747912b 2349 }
2350
2351 TList *cdbListCopy = new TList();
2352 cdbListCopy->SetOwner(1);
2353 cdbListCopy->SetName("cdbList");
2354
2355 TIter iter2(cdbList);
2356
b940cb9b 2357 AliCDBId* id=0;
e84c88f5 2358 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 2359 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 2360 }
2361
21a3aa09 2362 ftree->GetUserInfo()->Add(cdbMapCopy);
2363 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 2364
27aa8455 2365 // Add the AliRoot version that created this file
2366 TString sVersion("aliroot ");
2367 sVersion += ALIROOT_SVN_BRANCH;
2368 sVersion += ":";
2369 sVersion += ALIROOT_SVN_REVISION;
2370 sVersion += "; root ";
2371 sVersion += ROOT_SVN_BRANCH;
2372 sVersion += ":";
2373 sVersion += ROOT_SVN_REVISION;
2374 sVersion += "; metadata ";
2375 sVersion += gSystem->Getenv("PRODUCTION_METADATA");
2376
2377
2378 TNamed * alirootVersion = new TNamed("alirootVersion",sVersion.Data());
2379 ftree->GetUserInfo()->Add(alirootVersion); // The list becomes owner of alirootVersion
46698ae4 2380
21a3aa09 2381 ffile->cd();
aa3c69a9 2382
562dd0b4 2383 // we want to have only one tree version number
21a3aa09 2384 ftree->Write(ftree->GetName(),TObject::kOverwrite);
63314086 2385 fhlttree->Write(fhlttree->GetName(),TObject::kOverwrite);
f3a97c86 2386
ee7c441c 2387 if (fWriteESDfriend) {
2388 ffileF->cd();
2389 ftreeF->Write(ftreeF->GetName(),TObject::kOverwrite);
2390 }
2391
a7a1e1c7 2392// Finish with Plane Efficiency evaluation: before of CleanUp !!!
2393 if (fRunPlaneEff && !FinishPlaneEff()) {
2394 AliWarning("Finish PlaneEff evaluation failed");
2395 }
2396
323a7f87 2397 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
0d45a46a 2398 if (fReconstructor[iDet]) fReconstructor[iDet]->Terminate();
323a7f87 2399 }
930e6e3e 2400 // End of cycle for the in-loop
87da0921 2401
2402 if (fRunQA || fRunGlobalQA) {
5cbed243 2403 AliQAManager::QAManager()->EndOfCycle() ;
81d57268 2404 if (fInput &&
2405 !fProofOutputLocation.IsNull() &&
2406 fProofOutputArchive.IsNull() &&
2407 !fProofOutputDataset) {
2408 TString qaOutputFile(Form("%sMerged.%s.Data.root",
2409 fProofOutputLocation.Data(),
2410 AliQAv1::GetQADataFileName()));
2411 TProofOutputFile *qaProofFile = new TProofOutputFile(Form("Merged.%s.Data.root",
2412 AliQAv1::GetQADataFileName()));
2413 qaProofFile->SetOutputFileName(qaOutputFile.Data());
2414 if (AliDebugLevel() > 0) qaProofFile->Dump();
2415 fOutput->Add(qaProofFile);
2416 MergeQA(qaProofFile->GetFileName());
87da0921 2417 }
2418 else {
2419 MergeQA();
2420 }
2421 }
2422
4b71572b 2423 gROOT->cd();
2424 CleanUp();
81d57268 2425
2426 if (fInput) {
2427 if (!fProofOutputFileName.IsNull() &&
2428 !fProofOutputLocation.IsNull() &&
2429 fProofOutputDataset &&
2430 !fProofOutputArchive.IsNull()) {
2431 TProofOutputFile *zipProofFile = new TProofOutputFile(fProofOutputFileName.Data(),
2432 "DROV",
2433 fProofOutputLocation.Data());
2434 if (AliDebugLevel() > 0) zipProofFile->Dump();
2435 fOutput->Add(zipProofFile);
2436 TString fileList(fProofOutputArchive.Data());
2437 fileList.ReplaceAll(","," ");
38c18bf1 2438 TString command;
2439#if ROOT_SVN_REVISION >= 30174
2440 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(kTRUE),zipProofFile->GetFileName(),fileList.Data());
2441#else
2442 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(),zipProofFile->GetFileName(),fileList.Data());
2443#endif
2444 AliInfo(Form("Executing: %s",command.Data()));
2445 gSystem->Exec(command.Data());
81d57268 2446 }
2447 }
4b71572b 2448}
2449
2450//_____________________________________________________________________________
2451void AliReconstruction::Terminate()
2452{
f3a97c86 2453 // Create tags for the events in the ESD tree (the ESD tree is always present)
2454 // In case of empty events the tags will contain dummy values
52dd4a8c 2455 AliCodeTimerAuto("",0);
4b71572b 2456
e6d66370 2457 // Do not call the ESD tag creator in case of PROOF-based reconstruction
2458 if (!fInput) {
2459 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
2460 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData, AliQAv1::Instance()->GetQA(), AliQAv1::Instance()->GetEventSpecies(), AliQAv1::kNDET, AliRecoParam::kNSpecies);
9bcaa1d7 2461 delete esdtagCreator;
e6d66370 2462 }
e84c88f5 2463
795e4a22 2464 // Cleanup of CDB manager: cache and active storages!
2465 AliCDBManager::Instance()->ClearCache();
596a855f 2466}
2467
2468//_____________________________________________________________________________
b26c3770 2469Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
2470{
2471// run the local reconstruction
aa3c69a9 2472
0f88822a 2473 static Int_t eventNr=0;
52dd4a8c 2474 AliCodeTimerAuto("",0)
b26c3770 2475
2476 TString detStr = detectors;
9533b54d 2477 // execute HLT reconstruction first since other detector reconstruction
2478 // might depend on HLT data
2479 // key 'HLT' is removed from detStr by IsSelected
2480 if (!IsSelected("HLT", detStr)) {
2481 AliReconstructor* reconstructor = GetReconstructor(kNDetectors-1);
2482 if (reconstructor) {
2483 // there is no AliLoader for HLT, see
2484 // https://savannah.cern.ch/bugs/?35473
2485 AliInfo("running reconstruction for HLT");
f6806ad3 2486 if (fRawReader) {
820b4d9e 2487 AliInfo("reconstructor->Reconstruct(fRawReader, NULL)");
44ed7a66 2488 reconstructor->Reconstruct(fRawReader, NULL);
820b4d9e 2489 }
2490 else {
2491 AliInfo("reconstructor->Reconstruct(dummy, NULL)");
44ed7a66 2492 TTree* dummy=NULL;
2493 reconstructor->Reconstruct(dummy, NULL);
f6806ad3 2494 }
f6806ad3 2495 }
9533b54d 2496 }
820b4d9e 2497
2498 AliInfo(Form("kNDetectors = %d",kNDetectors));
2499
9533b54d 2500 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2501 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
820b4d9e 2502 AliDebug(1, Form("Detector: %s", fgkDetectorName[iDet]));
9533b54d 2503 AliReconstructor* reconstructor = GetReconstructor(iDet);
2504 if (!reconstructor) continue;
2505 AliLoader* loader = fLoader[iDet];
d76c31f4 2506 if (!loader) {
2507 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
2508 continue;
2509 }
b26c3770 2510 // conversion of digits
2511 if (fRawReader && reconstructor->HasDigitConversion()) {
2512 AliInfo(Form("converting raw data digits into root objects for %s",
2513 fgkDetectorName[iDet]));
30bbd491 2514// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
52dd4a8c 2515// fgkDetectorName[iDet]),0);
b26c3770 2516 loader->LoadDigits("update");
2517 loader->CleanDigits();
2518 loader->MakeDigitsContainer();
2519 TTree* digitsTree = loader->TreeD();
2520 reconstructor->ConvertDigits(fRawReader, digitsTree);
2521 loader->WriteDigits("OVERWRITE");
2522 loader->UnloadDigits();
b26c3770 2523 }
b26c3770 2524 // local reconstruction
b26c3770 2525 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
52dd4a8c 2526 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]),0);
820b4d9e 2527 AliDebug(1, "Loading Rec Points");
b26c3770 2528 loader->LoadRecPoints("update");
820b4d9e 2529 AliDebug(1, "Cleaning Rec Points");
b26c3770 2530 loader->CleanRecPoints();
820b4d9e 2531 AliDebug(1, "Making Rec Points Container");
b26c3770 2532 loader->MakeRecPointsContainer();
2533 TTree* clustersTree = loader->TreeR();
2534 if (fRawReader && !reconstructor->HasDigitConversion()) {
2535 reconstructor->Reconstruct(fRawReader, clustersTree);
820b4d9e 2536 }
2537 else {
2538 AliDebug(1, "Loading Digits");
b26c3770 2539 loader->LoadDigits("read");
2540 TTree* digitsTree = loader->TreeD();
820b4d9e 2541 AliDebug(1, Form("Digits Tree = %p",digitsTree));
b26c3770 2542 if (!digitsTree) {
44ed7a66 2543 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
13effe3f 2544 if (fStopOnError)
2545 return kFALSE;
820b4d9e 2546 }
2547 else {
2548 AliDebug(1, "Digits -> Clusters");
44ed7a66 2549 reconstructor->Reconstruct(digitsTree, clustersTree);
514cb8c7 2550 if (fRunQA && IsInTasks(AliQAv1::kDIGITSR)) {
eca4fa66 2551 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
2552 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, digitsTree) ;
44ed7a66 2553 }
b26c3770 2554 }
2555 loader->UnloadDigits();
2556 }
92664bc8 2557 if (fRunQA && IsInTasks(AliQAv1::kRECPOINTS)) {
eca4fa66 2558 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
92664bc8 2559 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, clustersTree) ;
57acd2d2 2560 }
eca4fa66 2561 loader->WriteRecPoints("OVERWRITE");
2562 loader->UnloadRecPoints();
2563 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
a00021a7 2564 }
c7a22819 2565 if (!IsSelected("CTP", detStr)) AliDebug(10,"No CTP");
a00021a7 2566 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
b26c3770 2567 AliError(Form("the following detectors were not found: %s",
2568 detStr.Data()));
13effe3f 2569 if (fStopOnError)
2570 return kFALSE;
b26c3770 2571 }
0f88822a 2572 eventNr++;
b26c3770 2573 return kTRUE;
2574}
58e8dc31 2575//_____________________________________________________________________________
2576Bool_t AliReconstruction::RunSPDTrackleting(AliESDEvent*& esd)
2577{
2578// run the SPD trackleting (for SPD efficiency purpouses)
2579
52dd4a8c 2580 AliCodeTimerAuto("",0)
58e8dc31 2581
2582 Double_t vtxPos[3] = {0, 0, 0};
2583 Double_t vtxErr[3] = {0.0, 0.0, 0.0};
2584/*
09b62f0a 2585 TArrayF m
2586/
2587cVertex(3);
58e8dc31 2588 // if(MC)
2589 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
2590 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
2591 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
2592 }
2593*/
2594 const AliESDVertex *vertex = esd->GetVertex();
2595 if(!vertex){
2596 AliWarning("Vertex not found");
2597 return kFALSE;
2598 }
2599 vertex->GetXYZ(vtxPos);
2600 vertex->GetSigmaXYZ(vtxErr);
2601 if (fSPDTrackleter) {
2602 AliInfo("running the SPD Trackleter for Plane Efficiency Evaluation");
2603
2604 // load clusters
2605 fLoader[0]->LoadRecPoints("read");
2606 TTree* tree = fLoader[0]->TreeR();
2607 if (!tree) {
2608 AliError("Can't get the ITS cluster tree");
2609 return kFALSE;
2610 }
2611 fSPDTrackleter->LoadClusters(tree);
2612 fSPDTrackleter->SetVertex(vtxPos, vtxErr);
2613 // run trackleting
2614 if (fSPDTrackleter->Clusters2Tracks(esd) != 0) {
84290fcc 2615 AliWarning("AliITSTrackleterSPDEff Clusters2Tracks failed");
58e8dc31 2616 // fLoader[0]->UnloadRecPoints();
2617 return kFALSE;
2618 }
2619//fSPDTrackleter->UnloadRecPoints();
2620 } else {
2621 AliWarning("SPDTrackleter not available");
2622 return kFALSE;
2623 }
2624 return kTRUE;
2625}
b26c3770 2626
2627//_____________________________________________________________________________
af885e0f 2628Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 2629{
2630// run the barrel tracking
2631
52dd4a8c 2632 AliCodeTimerAuto("",0)
030b532d 2633
92bffc4d 2634 AliVertexer *vertexer = CreateVertexer();
2635 if (!vertexer) return kFALSE;
2636
3c99b88f 2637 AliInfo(Form("running the ITS vertex finder: %s",vertexer->ClassName()));
2257f27e 2638 AliESDVertex* vertex = NULL;
92bffc4d 2639 if (fLoader[0]) {
2640 fLoader[0]->LoadRecPoints();
2641 TTree* cltree = fLoader[0]->TreeR();
2642 if (cltree) {
2643 if(fDiamondProfileSPD) vertexer->SetVtxStart(fDiamondProfileSPD);
2644 vertex = vertexer->FindVertexForCurrentEvent(cltree);
308c2f7c 2645 }
2646 else {
92bffc4d 2647 AliError("Can't get the ITS cluster tree");
308c2f7c 2648 }
92bffc4d 2649 fLoader[0]->UnloadRecPoints();
2257f27e 2650 }
92bffc4d 2651 else {
2652 AliError("Can't get the ITS loader");
2653 }
2654 if(!vertex){
2655 AliWarning("Vertex not found");
2656 vertex = new AliESDVertex();
2657 vertex->SetName("default");
2658 }
2659 else {
2660 vertex->SetName("reconstructed");
2257f27e 2661 }
92bffc4d 2662
2663 Double_t vtxPos[3];
2664 Double_t vtxErr[3];
2665 vertex->GetXYZ(vtxPos);
2666 vertex->GetSigmaXYZ(vtxErr);
2667
06cc9d95 2668 esd->SetPrimaryVertexSPD(vertex);
73c51de2 2669 AliESDVertex *vpileup = NULL;
2670 Int_t novertices = 0;
2671 vpileup = vertexer->GetAllVertices(novertices);
2672 if(novertices>1){
2673 for (Int_t kk=1; kk<novertices; kk++)esd->AddPileupVertexSPD(&vpileup[kk]);
2674 }
1f9831ab 2675 /*
32e449be 2676 // if SPD multiplicity has been determined, it is stored in the ESD
92bffc4d 2677 AliMultiplicity *mult = vertexer->GetMultiplicity();
32e449be 2678 if(mult)esd->SetMultiplicity(mult);
1f9831ab 2679 */
ac4a7581 2680 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2681 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
2682 }
2257f27e 2683 delete vertex;
2684
92bffc4d 2685 delete vertexer;
2686
2257f27e 2687 return kTRUE;
2688}
2689
2690//_____________________________________________________________________________
1f9831ab 2691Bool_t AliReconstruction::RunMultFinder(AliESDEvent*& esd)
2692{
2693 // run the trackleter for multiplicity study
2694
2695 AliCodeTimerAuto("",0)
2696
2697 AliTrackleter *trackleter = CreateMultFinder();
2698 if (!trackleter) return kFALSE;
2699
2700 AliInfo(Form("running the ITS multiplicity finder: %s",trackleter->ClassName()));
2701
2702 if (fLoader[0]) {
2703 fLoader[0]->LoadRecPoints();
2704 TTree* cltree = fLoader[0]->TreeR();
2705 if (cltree) {
2706 trackleter->Reconstruct(esd,cltree);
2707 AliMultiplicity *mult = trackleter->GetMultiplicity();
2708 if(mult) esd->SetMultiplicity(mult);
2709 }
2710 else {
2711 AliError("Can't get the ITS cluster tree");
2712 }
2713 fLoader[0]->UnloadRecPoints();
2714 }
2715 else {
2716 AliError("Can't get the ITS loader");
2717 }
2718
2719 delete trackleter;
2720
2721 return kTRUE;
2722}
2723
2724//_____________________________________________________________________________
af885e0f 2725Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 2726{
2727// run the HLT barrel tracking
2728
52dd4a8c 2729 AliCodeTimerAuto("",0)
1f46a9ae 2730
2731 if (!fRunLoader) {
2732 AliError("Missing runLoader!");
2733 return kFALSE;
2734 }
2735
2736 AliInfo("running HLT tracking");
2737
2738 // Get a pointer to the HLT reconstructor
ac4a7581 2739 AliReconstructor *reconstructor = GetReconstructor(kNDetectors-1);
1f46a9ae 2740 if (!reconstructor) return kFALSE;
2741
2742 // TPC + ITS
2743 for (Int_t iDet = 1; iDet >= 0; iDet--) {
2744 TString detName = fgkDetectorName[iDet];
2745 AliDebug(1, Form("%s HLT tracking", detName.Data()));
2746 reconstructor->SetOption(detName.Data());
d76c31f4 2747 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 2748 if (!tracker) {
2749 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
2750 if (fStopOnError) return kFALSE;
9dcc06e1 2751 continue;
1f46a9ae 2752 }
2753 Double_t vtxPos[3];
2754 Double_t vtxErr[3]={0.005,0.005,0.010};
2755 const AliESDVertex *vertex = esd->GetVertex();
2756 vertex->GetXYZ(vtxPos);
2757 tracker->SetVertex(vtxPos,vtxErr);
2758 if(iDet != 1) {
2759 fLoader[iDet]->LoadRecPoints("read");
2760 TTree* tree = fLoader[iDet]->TreeR();
2761 if (!tree) {
2762 AliError(Form("Can't get the %s cluster tree", detName.Data()));
2763 return kFALSE;
2764 }
2765 tracker->LoadClusters(tree);
2766 }
2767 if (tracker->Clusters2Tracks(esd) != 0) {
2768 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
2769 return kFALSE;
2770 }
2771 if(iDet != 1) {
2772 tracker->UnloadClusters();
2773 }
2774 delete tracker;
2775 }
2776
1f46a9ae 2777 return kTRUE;
2778}
2779
2780//_____________________________________________________________________________
af885e0f 2781Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 2782{
2783// run the muon spectrometer tracking
2784
52dd4a8c 2785 AliCodeTimerAuto("",0)
e66fbafb 2786
2787 if (!fRunLoader) {
2788 AliError("Missing runLoader!");
2789 return kFALSE;
2790 }
cfeca9e2 2791 Int_t iDet = GetDetIndex("MUON"); // for MUON
e66fbafb 2792
2793 // Get a pointer to the MUON reconstructor
2794 AliReconstructor *reconstructor = GetReconstructor(iDet);
2795 if (!reconstructor) return kFALSE;
2796
2797
2798 TString detName = fgkDetectorName[iDet];
2799 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 2800 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 2801 if (!tracker) {
2802 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
2803 return kFALSE;
2804 }
2805
e66fbafb 2806 // read RecPoints
761350a6 2807 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 2808
761350a6 2809 tracker->LoadClusters(fLoader[iDet]->TreeR());
2810
2811 Int_t rv = tracker->Clusters2Tracks(esd);
2812
e66fbafb 2813 fLoader[iDet]->UnloadRecPoints();
2814
c1954ee5 2815 tracker->UnloadClusters();
2816
cb23c6ca 2817 if ( rv )
2818 {
2819 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
2820 return kFALSE;
2821 }
2822
e66fbafb 2823 return kTRUE;
2824}
2825
2826
2827//_____________________________________________________________________________
10d100d4 2828Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd,AliESDpid &PID)
2257f27e 2829{
2830// run the barrel tracking
0f88822a 2831 static Int_t eventNr=0;
52dd4a8c 2832 AliCodeTimerAuto("",0)
24f7a148 2833
815c2b38 2834 AliInfo("running tracking");
596a855f 2835
1f26f3e7 2836 // Set the event info which is used
2837 // by the trackers in order to obtain
2838 // information about read-out detectors,
2839 // trigger etc.
2840 AliDebug(1, "Setting event info");
2841 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2842 if (!fTracker[iDet]) continue;
2843 fTracker[iDet]->SetEventInfo(&fEventInfo);
2844 }
2845
91b876d1 2846 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 2847 if (fReconstructor[11] && fLoader[11]) {
2848 fLoader[11]->LoadRecPoints("READ");
2849 TTree *treeR = fLoader[11]->TreeR();
89916438 2850 if (treeR) {
2851 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
2852 }
d76c31f4 2853 }
91b876d1 2854
b8cd5251 2855 // pass 1: TPC + ITS inwards
2856 for (Int_t iDet = 1; iDet >= 0; iDet--) {
2857 if (!fTracker[iDet]) continue;
2858 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 2859
b8cd5251 2860 // load clusters
2861 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2862 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 2863 TTree* tree = fLoader[iDet]->TreeR();
2864 if (!tree) {
2865 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2866 return kFALSE;
2867 }
b8cd5251 2868 fTracker[iDet]->LoadClusters(tree);
6efecea1 2869 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2870 // run tracking
2871 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
2872 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 2873 return kFALSE;
2874 }
878e1fe1 2875 // preliminary PID in TPC needed by the ITS tracker
2876 if (iDet == 1) {
b26c3770 2877 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
10d100d4 2878 PID.MakePID(esd,kTRUE);
0f88822a 2879 }
6efecea1 2880 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 2881 }
596a855f 2882
b8cd5251 2883 // pass 2: ALL backwards
aa3c69a9 2884
ac4a7581 2885 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2886 if (!fTracker[iDet]) continue;
2887 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
2888
2889 // load clusters
2890 if (iDet > 1) { // all except ITS, TPC
2891 TTree* tree = NULL;
7b61cd9c 2892 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2893 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 2894 tree = fLoader[iDet]->TreeR();
b8cd5251 2895 if (!tree) {
eca4fa66 2896 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
2897 return kFALSE;
24f7a148 2898 }
0f88822a 2899 fTracker[iDet]->LoadClusters(tree);
6efecea1 2900 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2901 }
24f7a148 2902
b8cd5251 2903 // run tracking
283f39c6 2904 if (iDet>1) // start filling residuals for the "outer" detectors
eca4fa66 2905 if (fRunGlobalQA) {
2906 AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);
2907 TObjArray ** arr = AliTracker::GetResidualsArray() ;
c9526f68 2908 if (arr) {
0a349581 2909 AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
2910 TObjArray * elem = arr[AliRecoParam::AConvert(es)];
c9526f68 2911 if ( elem && (! elem->At(0)) ) {
2912 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
2913 if (qadm) qadm->InitRecPointsForTracker() ;
2914 }
2915 }
eca4fa66 2916 }
b8cd5251 2917 if (fTracker[iDet]->PropagateBack(esd) != 0) {
2918 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 2919 // return kFALSE;
b8cd5251 2920 }
24f7a148