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