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