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