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