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