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