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