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