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