]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliReconstruction.cxx
As part of the efforts of the combined PID subgroup we are continuing to develop...
[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
c757bafd 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
596a855f 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
f1c1204d 607//_____________________________________________________________________________
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
fc07289e 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
024cf675 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
f1c1204d 744//_____________________________________________________________________________
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}
00aa02d5 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
795e4a22 853//_____________________________________________________________________________
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
f9fc20b4 861//_____________________________________________________________________________
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}
6bae477a 870//_____________________________________________________________________________
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
21a3aa09 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
975320a0 949//_____________________________________________________________________________
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
efd2085e 958//_____________________________________________________________________________
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
7e88424f 968//_____________________________________________________________________________
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
61807e09 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
4b71572b 1193//_____________________________________________________________________________
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}
596a855f 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();
5b3ea9c5 1722
396f89bc 1723 if (fRawReader && fRawReader->UseAutoSaveESD())
4b71572b 1724 fRunLoader->TreeE()->AutoSave("SaveSelf");
21a3aa09 1725 }
1726
1727 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
21a3aa09 1728 return kTRUE;
1729 }
1730
aa3c69a9 1731
16447f18 1732 fRunLoader->GetEvent(iEvent);
1733
7e88424f 1734 // Fill Event-info object
1735 GetEventInfo();
77ba28ba 1736 fRecoParam.SetEventSpecie(fRunInfo,fEventInfo,fListOfCosmicTriggers);
d97f1dbe 1737
1738 ProcInfo_t procInfo;
1739 if(iEvent==fFirstEvent) {
1740 gSystem->GetProcInfo(&procInfo);
1741 oldMres=procInfo.fMemResident;
1742 oldMvir=procInfo.fMemVirtual;
1743 oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
1744 }
470f88b0 1745 AliInfo(Form("================================= Processing event %d of type %-10s ==================================", iEvent,fRecoParam.PrintEventSpecie()));
7e88424f 1746
a00021a7 1747 // Set the reco-params
1748 {
1749 TString detStr = fLoadCDB;
ac4a7581 1750 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
a00021a7 1751 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1752 AliReconstructor *reconstructor = GetReconstructor(iDet);
1753 if (reconstructor && fRecoParam.GetDetRecoParamArray(iDet)) {
57acd2d2 1754 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
1755 reconstructor->SetRecoParam(par);
0a035be5 1756 reconstructor->GetPidSettings(&pid);
10d100d4 1757 reconstructor->SetEventInfo(&fEventInfo);
57acd2d2 1758 if (fRunQA) {
eca4fa66 1759 AliQAManager::QAManager()->SetRecoParam(iDet, par) ;
619aafe6 1760 if (par) AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(par->GetEventSpecie())) ;
57acd2d2 1761 }
a00021a7 1762 }
1763 }
9dad1020 1764 if (fRunQA) {
1765 const AliDetectorRecoParam *grppar = fRecoParam.GetDetRecoParam(kNDetectors);
1766 AliQAManager::QAManager()->SetRecoParam(AliQAv1::kGLOBAL, grppar) ;
1767 AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(grppar->GetEventSpecie())) ;
1768 }
a00021a7 1769 }
1770
ca13fb87 1771 // QA on single raw
514cb8c7 1772 if (fRunQA && IsInTasks(AliQAv1::kRAWS)) {
eca4fa66 1773 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
1774 AliQAManager::QAManager()->RunOneEvent(fRawReader) ;
57acd2d2 1775 }
d506c543 1776 // local single event reconstruction
b26c3770 1777 if (!fRunLocalReconstruction.IsNull()) {
d506c543 1778 TString detectors=fRunLocalReconstruction;
a441bf51 1779 // run HLT event reconstruction first
d506c543 1780 // ;-( IsSelected changes the string
1781 if (IsSelected("HLT", detectors) &&
1782 !RunLocalEventReconstruction("HLT")) {
4b71572b 1783 if (fStopOnError) {CleanUp(); return kFALSE;}
a441bf51 1784 }
1785 detectors=fRunLocalReconstruction;
1786 detectors.ReplaceAll("HLT", "");
1787 if (!RunLocalEventReconstruction(detectors)) {
13effe3f 1788 if (fStopOnError) {
1789 CleanUp();
1790 return kFALSE;
1791 }
b26c3770 1792 }
1793 }
1794
6b3a883f 1795
1796 // fill Event header information from the RawEventHeader
1797 if (fRawReader){FillRawEventHeaderESD(fesd);}
1798 if (fRawReader){FillRawEventHeaderESD(fhltesd);}
1799
21a3aa09 1800 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1801 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
7b649c02 1802
1803 ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
1804 ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
1805 ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
1806 ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
1807
21a3aa09 1808 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1809 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
fd2e2210 1810
1811 fesd->SetEventSpecie(fRecoParam.GetEventSpecie());
1812 fhltesd->SetEventSpecie(fRecoParam.GetEventSpecie());
46698ae4 1813
d6ee376f 1814 // Set magnetic field from the tracker
21a3aa09 1815 fesd->SetMagneticField(AliTracker::GetBz());
1816 fhltesd->SetMagneticField(AliTracker::GetBz());
33fe5eb1 1817 //
3d84ad67 1818 AliESDRun *esdRun,*esdRunH;
1819 esdRun = (AliESDRun*)fesd->GetESDRun();
1820 esdRunH = (AliESDRun*)fhltesd->GetESDRun();
1821 esdRun->SetBeamEnergyIsSqrtSHalfGeV();
1822 esdRunH->SetBeamEnergyIsSqrtSHalfGeV();
1823 //
1824 for (int ib=2;ib--;) for (int it=2;it--;) {
1825 esdRun->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
1826 esdRunH->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
1827 }
c587bcde 1828 //
33fe5eb1 1829 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
1830 if (fld) { // set info needed for field initialization
1831 fesd->SetCurrentL3(fld->GetCurrentSol());
1832 fesd->SetCurrentDip(fld->GetCurrentDip());
1833 fesd->SetBeamEnergy(fld->GetBeamEnergy());
1834 fesd->SetBeamType(fld->GetBeamTypeText());
1835 fesd->SetUniformBMap(fld->IsUniform());
1836 fesd->SetBInfoStored();
1837 //
1838 fhltesd->SetCurrentL3(fld->GetCurrentSol());
1839 fhltesd->SetCurrentDip(fld->GetCurrentDip());
1840 fhltesd->SetBeamEnergy(fld->GetBeamEnergy());
1841 fhltesd->SetBeamType(fld->GetBeamTypeText());
1842 fhltesd->SetUniformBMap(fld->IsUniform());
1843 fhltesd->SetBInfoStored();
1844 }
1845 //
71f6cda4 1846 // Set most probable pt, for B=0 tracking
9257a1bd 1847 // Get the global reco-params. They are atposition 16 inside the array of detectors in fRecoParam
ac4a7581 1848 const AliGRPRecoParam *grpRecoParam = dynamic_cast<const AliGRPRecoParam*>(fRecoParam.GetDetRecoParam(kNDetectors));
71f6cda4 1849 if (grpRecoParam) AliExternalTrackParam::SetMostProbablePt(grpRecoParam->GetMostProbablePt());
46698ae4 1850
2e3550da 1851 // Fill raw-data error log into the ESD
21a3aa09 1852 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 1853
2257f27e 1854 // vertex finder
1855 if (fRunVertexFinder) {
4b71572b 1856 if (!RunVertexFinder(fesd)) {
1857 if (fStopOnError) {CleanUp(); return kFALSE;}
2257f27e 1858 }
1859 }
1860
58e8dc31 1861 // For Plane Efficiency: run the SPD trackleter
1862 if (fRunPlaneEff && fSPDTrackleter) {
1863 if (!RunSPDTrackleting(fesd)) {
1864 if (fStopOnError) {CleanUp(); return kFALSE;}
1865 }
1866 }
1867
e66fbafb 1868 // Muon tracking
b8cd5251 1869 if (!fRunTracking.IsNull()) {
e66fbafb 1870 if (fRunMuonTracking) {
21a3aa09 1871 if (!RunMuonTracking(fesd)) {
4b71572b 1872 if (fStopOnError) {CleanUp(); return kFALSE;}
24f7a148 1873 }
596a855f 1874 }
1875 }
1876
e66fbafb 1877 // barrel tracking
1878 if (!fRunTracking.IsNull()) {
0a035be5 1879 if (!RunTracking(fesd,pid)) {
4b71572b 1880 if (fStopOnError) {CleanUp(); return kFALSE;}
e66fbafb 1881 }
1882 }
21c573b7 1883
596a855f 1884 // fill ESD
1885 if (!fFillESD.IsNull()) {
d506c543 1886 TString detectors=fFillESD;
f6806ad3 1887 // run HLT first and on hltesd
d506c543 1888 // ;-( IsSelected changes the string
1889 if (IsSelected("HLT", detectors) &&
1890 !FillESD(fhltesd, "HLT")) {
4b71572b 1891 if (fStopOnError) {CleanUp(); return kFALSE;}
f6806ad3 1892 }
1893 detectors=fFillESD;
d5105682 1894 // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
1895 if (detectors.Contains("ALL")) {
1896 detectors="";
ac4a7581 1897 for (Int_t idet=0; idet<kNDetectors; ++idet){
d5105682 1898 detectors += fgkDetectorName[idet];
1899 detectors += " ";
1900 }
1901 }
f6806ad3 1902 detectors.ReplaceAll("HLT", "");
1903 if (!FillESD(fesd, detectors)) {
4b71572b 1904 if (fStopOnError) {CleanUp(); return kFALSE;}
596a855f 1905 }
1906 }
f858b00e 1907
1908 // AdC+FN
bc334fcd 1909 if (fReconstructor[3])
1910 GetReconstructor(3)->FillEventTimeWithTOF(fesd,&pid);
f858b00e 1911
596a855f 1912 // combined PID
0a035be5 1913 pid.MakePID(fesd);
596a855f 1914
b647652d 1915 if (fFillTriggerESD) {
4b71572b 1916 if (!FillTriggerESD(fesd)) {
1917 if (fStopOnError) {CleanUp(); return kFALSE;}
b647652d 1918 }
1919 }
f7812afc 1920 // Always fill scalers
1921 if (!FillTriggerScalers(fesd)) {
1922 if (fStopOnError) {CleanUp(); return kFALSE;}
1923 }
1924
b647652d 1925
21a3aa09 1926 ffile->cd();
a6ee503a 1927
3c3709c4 1928 //
67be5c77 1929 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 1930 //
21a3aa09 1931 const Int_t ntracks = fesd->GetNumberOfTracks();
3c3709c4 1932 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1933
1934 TObjArray trkArray;
1935 UShort_t *selectedIdx=new UShort_t[ntracks];
1936
1937 for (Int_t itrack=0; itrack<ntracks; itrack++){
98a50ff3 1938 const Double_t kMaxStep = 1; //max step over the material
3c3709c4 1939 Bool_t ok;
1940
21a3aa09 1941 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 1942 if (!track) continue;
1943
1944 AliExternalTrackParam *tpcTrack =
1945 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 1946 ok = kFALSE;
1947 if (tpcTrack)
1948 ok = AliTracker::
52dd4a8c 1949 PropagateTrackToBxByBz(tpcTrack,kRadius,track->GetMass(),kMaxStep,kFALSE);
43c9dae1 1950
3c3709c4 1951 if (ok) {
1952 Int_t n=trkArray.GetEntriesFast();
1953 selectedIdx[n]=track->GetID();
1954 trkArray.AddLast(tpcTrack);
1955 }
1956
3d65e645 1957 //Tracks refitted by ITS should already be at the SPD vertex
1958 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1959
1960 AliTracker::
52dd4a8c 1961 PropagateTrackToBxByBz(track,kRadius,track->GetMass(),kMaxStep,kFALSE);
1962 Double_t x[3]; track->GetXYZ(x);
1963 Double_t b[3]; AliTracker::GetBxByBz(x,b);
1964 track->RelateToVertexBxByBz(fesd->GetPrimaryVertexSPD(), b, kVeryBig);
3c3709c4 1965
3c3709c4 1966 }
1967
1968 //
1969 // Improve the reconstructed primary vertex position using the tracks
1970 //
59224b2b 1971 Bool_t runVertexFinderTracks = fRunVertexFinderTracks;
1972 if(fesd->GetPrimaryVertexSPD()) {
1973 TString vtitle = fesd->GetPrimaryVertexSPD()->GetTitle();
1974 if(vtitle.Contains("cosmics")) {
1975 runVertexFinderTracks=kFALSE;
1976 }
c060d7fe 1977 }
a00021a7 1978
1979 if (runVertexFinderTracks) {
3c3709c4 1980 // TPC + ITS primary vertex
f09c879d 1981 ftVertexer->SetITSMode();
f2a195c1 1982 ftVertexer->SetConstraintOff();
a00021a7 1983 // get cuts for vertexer from AliGRPRecoParam
1c7554f9 1984 Bool_t constrSPD=kFALSE;
a00021a7 1985 if (grpRecoParam) {
1986 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
1987 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
1988 grpRecoParam->GetVertexerTracksCutsITS(cutsVertexer);
1989 ftVertexer->SetCuts(cutsVertexer);
1990 delete [] cutsVertexer; cutsVertexer = NULL;
1c7554f9 1991 if(grpRecoParam->GetVertexerTracksConstraintITS()) {
1992 if(fDiamondProfile && fDiamondProfile->GetXRes()<kRadius){
1993 ftVertexer->SetVtxStart(fDiamondProfile); // apply constraint only if sigmax is smaller than the beam pipe radius
1994 }else{
1995 if(fDiamondProfileSPD && fDiamondProfileSPD->GetXRes()<kRadius){
1996 ftVertexer->SetVtxStart(fDiamondProfileSPD);
1997 constrSPD=kTRUE;
1998 }
1999 }
dd15203b 2000 }
43c9dae1 2001 }
21a3aa09 2002 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 2003 if (pvtx) {
1c7554f9 2004 if(constrSPD){
2005 TString title=pvtx->GetTitle();
2006 title.Append("SPD");
2007 pvtx->SetTitle(title);
2008 }
3c3709c4 2009 if (pvtx->GetStatus()) {
c264b61b 2010 fesd->SetPrimaryVertexTracks(pvtx);
3c3709c4 2011 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 2012 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 2013 Double_t x[3]; t->GetXYZ(x);
2014 Double_t b[3]; AliTracker::GetBxByBz(x,b);
2015 t->RelateToVertexBxByBz(pvtx, b, kVeryBig);
3c3709c4 2016 }
2017 }
9bcaa1d7 2018 delete pvtx; pvtx=NULL;
3c3709c4 2019 }
2020
2021 // TPC-only primary vertex
f09c879d 2022 ftVertexer->SetTPCMode();
f2a195c1 2023 ftVertexer->SetConstraintOff();
a00021a7 2024 // get cuts for vertexer from AliGRPRecoParam
2025 if (grpRecoParam) {
2026 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
2027 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
2028 grpRecoParam->GetVertexerTracksCutsTPC(cutsVertexer);
2029 ftVertexer->SetCuts(cutsVertexer);
2030 delete [] cutsVertexer; cutsVertexer = NULL;
dd15203b 2031 if(fDiamondProfileTPC && grpRecoParam->GetVertexerTracksConstraintTPC()) {
2032 if(fDiamondProfileTPC->GetXRes()<kRadius) ftVertexer->SetVtxStart(fDiamondProfileTPC); // apply constraint only if sigmax is smaller than the beam pipe radius
2033 }
43c9dae1 2034 }
21a3aa09 2035 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 2036 if (pvtx) {
2037 if (pvtx->GetStatus()) {
21a3aa09 2038 fesd->SetPrimaryVertexTPC(pvtx);
3d65e645 2039 for (Int_t i=0; i<ntracks; i++) {
2040 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 2041 Double_t x[3]; t->GetXYZ(x);
2042 Double_t b[3]; AliTracker::GetBxByBz(x,b);
2043 t->RelateToVertexTPCBxByBz(pvtx, b, kVeryBig);
3c3709c4 2044 }
2045 }
9bcaa1d7 2046 delete pvtx; pvtx=NULL;
3c3709c4 2047 }
2048
2049 }
2050 delete[] selectedIdx;
2051
1c7554f9 2052 if(fDiamondProfile && fDiamondProfile->GetXRes()<kRadius) fesd->SetDiamond(fDiamondProfile);
2053 else fesd->SetDiamond(fDiamondProfileSPD);
c5e3e5d1 2054
d1683eef 2055 if (fRunV0Finder) {
2056 // V0 finding
2057 AliV0vertexer vtxer;
61a14552 2058 // get cuts for V0vertexer from AliGRPRecoParam
2059 if (grpRecoParam) {
2060 Int_t nCutsV0vertexer = grpRecoParam->GetVertexerV0NCuts();
2061 Double_t *cutsV0vertexer = new Double_t[nCutsV0vertexer];
2062 grpRecoParam->GetVertexerV0Cuts(cutsV0vertexer);
2063 vtxer.SetCuts(cutsV0vertexer);
2064 delete [] cutsV0vertexer; cutsV0vertexer = NULL;
2065 }
21a3aa09 2066 vtxer.Tracks2V0vertices(fesd);
5e4ff34d 2067
d1683eef 2068 if (fRunCascadeFinder) {
2069 // Cascade finding
2070 AliCascadeVertexer cvtxer;
61a14552 2071 // get cuts for CascadeVertexer from AliGRPRecoParam
2072 if (grpRecoParam) {
2073 Int_t nCutsCascadeVertexer = grpRecoParam->GetVertexerCascadeNCuts();
2074 Double_t *cutsCascadeVertexer = new Double_t[nCutsCascadeVertexer];
2075 grpRecoParam->GetVertexerCascadeCuts(cutsCascadeVertexer);
2076 cvtxer.SetCuts(cutsCascadeVertexer);
2077 delete [] cutsCascadeVertexer; cutsCascadeVertexer = NULL;
2078 }
21a3aa09 2079 cvtxer.V0sTracks2CascadeVertices(fesd);
d1683eef 2080 }
5e4ff34d 2081 }
c8122432 2082
2083 // write ESD
2084 if (fCleanESD) CleanESD(fesd);
2085 //
1f9831ab 2086 // RS run updated trackleter: since we want to mark the clusters used by tracks and also mark the
2087 // tracks interpreted as primary, this step should be done in the very end, when full
2088 // ESD info is available (particulalry, V0s)
2089 // vertex finder
c8122432 2090 if (fRunMultFinder) {
2091 if (!RunMultFinder(fesd)) {
2092 if (fStopOnError) {CleanUp(); return kFALSE;}
2093 }
2094 }
854c6476 2095
514cb8c7 2096 if (fRunQA && IsInTasks(AliQAv1::kESDS)) {
eca4fa66 2097 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
aeb8fc30 2098 AliQAManager::QAManager()->RunOneEvent(fesd, fhltesd) ;
57acd2d2 2099 }
bea94759 2100 if (fRunGlobalQA) {
eca4fa66 2101 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
4018c387 2102 if (qadm)
57acd2d2 2103 qadm->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
514cb8c7 2104 if (qadm && IsInTasks(AliQAv1::kESDS))
4e25ac79 2105 qadm->Exec(AliQAv1::kESDS, fesd);
b03591ab 2106 }
854c6476 2107
8b12d288 2108 // copy HLT decision from HLTesd to esd
2109 // the most relevant information is stored in a reduced container in the esd,
2110 // while the full information can be found in the HLTesd
2111 TObject* pHLTSrc=fhltesd->FindListObject(AliESDHLTDecision::Name());
2112 TObject* pHLTTgt=fesd->FindListObject(AliESDHLTDecision::Name());
2113 if (pHLTSrc && pHLTTgt) {
2114 pHLTSrc->Copy(*pHLTTgt);
2115 }
2116
ee7c441c 2117 if (fWriteESDfriend)
21a3aa09 2118 fesd->GetESDfriend(fesdf);
ee7c441c 2119
21a3aa09 2120 ftree->Fill();
fc01854a 2121 if (fWriteESDfriend) {
f00558b6 2122 WriteESDfriend();
fc01854a 2123 }
500d54ab 2124
2d91a353 2125 // Auto-save the ESD tree in case of prompt reco @P2
396f89bc 2126 if (fRawReader && fRawReader->UseAutoSaveESD()) {
2d91a353 2127 ftree->AutoSave("SaveSelf");
ee7c441c 2128 if (fWriteESDfriend) ftreeF->AutoSave("SaveSelf");
be103ac8 2129 }
2d91a353 2130
500d54ab 2131 // write HLT ESD
21a3aa09 2132 fhlttree->Fill();
1d99986f 2133
14dd053c 2134 // call AliEVE
2135 if (fRunAliEVE) RunAliEVE();
2136
21a3aa09 2137 fesd->Reset();
2138 fhltesd->Reset();
5728d3d5 2139 if (fWriteESDfriend) {
21a3aa09 2140 fesdf->~AliESDfriend();
2141 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 2142 }
a5fa6165 2143
ac4a7581 2144 gSystem->GetProcInfo(&procInfo);
d97f1dbe 2145 Long_t dMres=(procInfo.fMemResident-oldMres)/1024;
2146 Long_t dMvir=(procInfo.fMemVirtual-oldMvir)/1024;
2147 Float_t dCPU=procInfo.fCpuUser+procInfo.fCpuSys-oldCPU;
2148 aveDMres+=(dMres-aveDMres)/(iEvent-fFirstEvent+1);
2149 aveDMvir+=(dMvir-aveDMvir)/(iEvent-fFirstEvent+1);
2150 aveDCPU+=(dCPU-aveDCPU)/(iEvent-fFirstEvent+1);
73bbf779 2151 AliInfo(Form("======================= End Event %d: Res %ld(%3ld <%3ld>) Vir %ld(%3ld <%3ld>) CPU %5.2f <%5.2f> ===================",
d97f1dbe 2152 iEvent, procInfo.fMemResident/1024, dMres, aveDMres, procInfo.fMemVirtual/1024, dMvir, aveDMvir, dCPU, aveDCPU));
470f88b0 2153 oldMres=procInfo.fMemResident;
2154 oldMvir=procInfo.fMemVirtual;
2155 oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
a5fa6165 2156
ca13fb87 2157 fEventInfo.Reset();
ac4a7581 2158 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
42ec5d3d 2159 if (fReconstructor[iDet]) {
a00021a7 2160 fReconstructor[iDet]->SetRecoParam(NULL);
42ec5d3d 2161 fReconstructor[iDet]->SetEventInfo(NULL);
2162 }
1f26f3e7 2163 if (fTracker[iDet]) fTracker[iDet]->SetEventInfo(NULL);
ca13fb87 2164 }
2165
53c8f690 2166 if (fRunQA || fRunGlobalQA)
eca4fa66 2167 AliQAManager::QAManager()->Increment() ;
53c8f690 2168
ca13fb87 2169 return kTRUE;
21a3aa09 2170}
2171
21a3aa09 2172//_____________________________________________________________________________
4b71572b 2173void AliReconstruction::SlaveTerminate()
21a3aa09 2174{
4b71572b 2175 // Finalize the run on the slave side
21a3aa09 2176 // Called after the exit
2177 // from the event loop
52dd4a8c 2178 AliCodeTimerAuto("",0);
21a3aa09 2179
2180 if (fIsNewRunLoader) { // galice.root didn't exist
2181 fRunLoader->WriteHeader("OVERWRITE");
5b3ea9c5 2182 fRunLoader->WriteTrigger("OVERWRITE");
21a3aa09 2183 fRunLoader->CdGAFile();
2184 fRunLoader->Write(0, TObject::kOverwrite);
2185 }
2186
f747912b 2187 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
2188 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
2189
2190 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
2191 cdbMapCopy->SetOwner(1);
2192 cdbMapCopy->SetName("cdbMap");
2193 TIter iter(cdbMap->GetTable());
2194
2195 TPair* pair = 0;
2196 while((pair = dynamic_cast<TPair*> (iter.Next()))){
2197 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
c7a22819 2198 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
2199 if (keyStr && valStr)
2200 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
f747912b 2201 }
2202
2203 TList *cdbListCopy = new TList();
2204 cdbListCopy->SetOwner(1);
2205 cdbListCopy->SetName("cdbList");
2206
2207 TIter iter2(cdbList);
2208
b940cb9b 2209 AliCDBId* id=0;
e84c88f5 2210 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 2211 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 2212 }
2213
21a3aa09 2214 ftree->GetUserInfo()->Add(cdbMapCopy);
2215 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 2216
46698ae4 2217
21a3aa09 2218 ffile->cd();
aa3c69a9 2219
562dd0b4 2220 // we want to have only one tree version number
21a3aa09 2221 ftree->Write(ftree->GetName(),TObject::kOverwrite);
63314086 2222 fhlttree->Write(fhlttree->GetName(),TObject::kOverwrite);
f3a97c86 2223
ee7c441c 2224 if (fWriteESDfriend) {
2225 ffileF->cd();
2226 ftreeF->Write(ftreeF->GetName(),TObject::kOverwrite);
2227 }
2228
a7a1e1c7 2229// Finish with Plane Efficiency evaluation: before of CleanUp !!!
2230 if (fRunPlaneEff && !FinishPlaneEff()) {
2231 AliWarning("Finish PlaneEff evaluation failed");
2232 }
2233
930e6e3e 2234 // End of cycle for the in-loop
87da0921 2235
2236 if (fRunQA || fRunGlobalQA) {
5cbed243 2237 AliQAManager::QAManager()->EndOfCycle() ;
81d57268 2238 if (fInput &&
2239 !fProofOutputLocation.IsNull() &&
2240 fProofOutputArchive.IsNull() &&
2241 !fProofOutputDataset) {
2242 TString qaOutputFile(Form("%sMerged.%s.Data.root",
2243 fProofOutputLocation.Data(),
2244 AliQAv1::GetQADataFileName()));
2245 TProofOutputFile *qaProofFile = new TProofOutputFile(Form("Merged.%s.Data.root",
2246 AliQAv1::GetQADataFileName()));
2247 qaProofFile->SetOutputFileName(qaOutputFile.Data());
2248 if (AliDebugLevel() > 0) qaProofFile->Dump();
2249 fOutput->Add(qaProofFile);
2250 MergeQA(qaProofFile->GetFileName());
87da0921 2251 }
2252 else {
2253 MergeQA();
2254 }
2255 }
2256
4b71572b 2257 gROOT->cd();
2258 CleanUp();
81d57268 2259
2260 if (fInput) {
2261 if (!fProofOutputFileName.IsNull() &&
2262 !fProofOutputLocation.IsNull() &&
2263 fProofOutputDataset &&
2264 !fProofOutputArchive.IsNull()) {
2265 TProofOutputFile *zipProofFile = new TProofOutputFile(fProofOutputFileName.Data(),
2266 "DROV",
2267 fProofOutputLocation.Data());
2268 if (AliDebugLevel() > 0) zipProofFile->Dump();
2269 fOutput->Add(zipProofFile);
2270 TString fileList(fProofOutputArchive.Data());
2271 fileList.ReplaceAll(","," ");
38c18bf1 2272 TString command;
2273#if ROOT_SVN_REVISION >= 30174
2274 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(kTRUE),zipProofFile->GetFileName(),fileList.Data());
2275#else
2276 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(),zipProofFile->GetFileName(),fileList.Data());
2277#endif
2278 AliInfo(Form("Executing: %s",command.Data()));
2279 gSystem->Exec(command.Data());
81d57268 2280 }
2281 }
4b71572b 2282}
2283
2284//_____________________________________________________________________________
2285void AliReconstruction::Terminate()
2286{
f3a97c86 2287 // Create tags for the events in the ESD tree (the ESD tree is always present)
2288 // In case of empty events the tags will contain dummy values
52dd4a8c 2289 AliCodeTimerAuto("",0);
4b71572b 2290
e6d66370 2291 // Do not call the ESD tag creator in case of PROOF-based reconstruction
2292 if (!fInput) {
2293 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
2294 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData, AliQAv1::Instance()->GetQA(), AliQAv1::Instance()->GetEventSpecies(), AliQAv1::kNDET, AliRecoParam::kNSpecies);
9bcaa1d7 2295 delete esdtagCreator;
e6d66370 2296 }
e84c88f5 2297
795e4a22 2298 // Cleanup of CDB manager: cache and active storages!
2299 AliCDBManager::Instance()->ClearCache();
596a855f 2300}
2301
b26c3770 2302//_____________________________________________________________________________
2303Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
2304{
2305// run the local reconstruction
aa3c69a9 2306
0f88822a 2307 static Int_t eventNr=0;
52dd4a8c 2308 AliCodeTimerAuto("",0)
b26c3770 2309
2310 TString detStr = detectors;
9533b54d 2311 // execute HLT reconstruction first since other detector reconstruction
2312 // might depend on HLT data
2313 // key 'HLT' is removed from detStr by IsSelected
2314 if (!IsSelected("HLT", detStr)) {
2315 AliReconstructor* reconstructor = GetReconstructor(kNDetectors-1);
2316 if (reconstructor) {
2317 // there is no AliLoader for HLT, see
2318 // https://savannah.cern.ch/bugs/?35473
2319 AliInfo("running reconstruction for HLT");
f6806ad3 2320 if (fRawReader) {
44ed7a66 2321 reconstructor->Reconstruct(fRawReader, NULL);
f6806ad3 2322 } else {
44ed7a66 2323 TTree* dummy=NULL;
2324 reconstructor->Reconstruct(dummy, NULL);
f6806ad3 2325 }
f6806ad3 2326 }
9533b54d 2327 }
2328 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2329 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2330 AliReconstructor* reconstructor = GetReconstructor(iDet);
2331 if (!reconstructor) continue;
2332 AliLoader* loader = fLoader[iDet];
d76c31f4 2333 if (!loader) {
2334 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
2335 continue;
2336 }
b26c3770 2337 // conversion of digits
2338 if (fRawReader && reconstructor->HasDigitConversion()) {
2339 AliInfo(Form("converting raw data digits into root objects for %s",
2340 fgkDetectorName[iDet]));
30bbd491 2341// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
52dd4a8c 2342// fgkDetectorName[iDet]),0);
b26c3770 2343 loader->LoadDigits("update");
2344 loader->CleanDigits();
2345 loader->MakeDigitsContainer();
2346 TTree* digitsTree = loader->TreeD();
2347 reconstructor->ConvertDigits(fRawReader, digitsTree);
2348 loader->WriteDigits("OVERWRITE");
2349 loader->UnloadDigits();
b26c3770 2350 }
b26c3770 2351 // local reconstruction
b26c3770 2352 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
52dd4a8c 2353 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]),0);
b26c3770 2354 loader->LoadRecPoints("update");
2355 loader->CleanRecPoints();
2356 loader->MakeRecPointsContainer();
2357 TTree* clustersTree = loader->TreeR();
2358 if (fRawReader && !reconstructor->HasDigitConversion()) {
2359 reconstructor->Reconstruct(fRawReader, clustersTree);
2360 } else {
2361 loader->LoadDigits("read");
2362 TTree* digitsTree = loader->TreeD();
2363 if (!digitsTree) {
44ed7a66 2364 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
13effe3f 2365 if (fStopOnError)
2366 return kFALSE;
b26c3770 2367 } else {
44ed7a66 2368 reconstructor->Reconstruct(digitsTree, clustersTree);
514cb8c7 2369 if (fRunQA && IsInTasks(AliQAv1::kDIGITSR)) {
eca4fa66 2370 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
2371 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, digitsTree) ;
44ed7a66 2372 }
b26c3770 2373 }
2374 loader->UnloadDigits();
2375 }
514cb8c7 2376 if (fRunQA && IsInTasks(AliQAv1::kRECPOINTS)) {
eca4fa66 2377 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
2378 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, clustersTree) ;
57acd2d2 2379 }
eca4fa66 2380 loader->WriteRecPoints("OVERWRITE");
2381 loader->UnloadRecPoints();
2382 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
a00021a7 2383 }
c7a22819 2384 if (!IsSelected("CTP", detStr)) AliDebug(10,"No CTP");
a00021a7 2385 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
b26c3770 2386 AliError(Form("the following detectors were not found: %s",
2387 detStr.Data()));
13effe3f 2388 if (fStopOnError)
2389 return kFALSE;
b26c3770 2390 }
0f88822a 2391 eventNr++;
b26c3770 2392 return kTRUE;
2393}
58e8dc31 2394//_____________________________________________________________________________
2395Bool_t AliReconstruction::RunSPDTrackleting(AliESDEvent*& esd)
2396{
2397// run the SPD trackleting (for SPD efficiency purpouses)
2398
52dd4a8c 2399 AliCodeTimerAuto("",0)
58e8dc31 2400
2401 Double_t vtxPos[3] = {0, 0, 0};
2402 Double_t vtxErr[3] = {0.0, 0.0, 0.0};
2403/*
2404 TArrayF mcVertex(3);
2405 // if(MC)
2406 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
2407 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
2408 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
2409 }
2410*/
2411 const AliESDVertex *vertex = esd->GetVertex();
2412 if(!vertex){
2413 AliWarning("Vertex not found");
2414 return kFALSE;
2415 }
2416 vertex->GetXYZ(vtxPos);
2417 vertex->GetSigmaXYZ(vtxErr);
2418 if (fSPDTrackleter) {
2419 AliInfo("running the SPD Trackleter for Plane Efficiency Evaluation");
2420
2421 // load clusters
2422 fLoader[0]->LoadRecPoints("read");
2423 TTree* tree = fLoader[0]->TreeR();
2424 if (!tree) {
2425 AliError("Can't get the ITS cluster tree");
2426 return kFALSE;
2427 }
2428 fSPDTrackleter->LoadClusters(tree);
2429 fSPDTrackleter->SetVertex(vtxPos, vtxErr);
2430 // run trackleting
2431 if (fSPDTrackleter->Clusters2Tracks(esd) != 0) {
84290fcc 2432 AliWarning("AliITSTrackleterSPDEff Clusters2Tracks failed");
58e8dc31 2433 // fLoader[0]->UnloadRecPoints();
2434 return kFALSE;
2435 }
2436//fSPDTrackleter->UnloadRecPoints();
2437 } else {
2438 AliWarning("SPDTrackleter not available");
2439 return kFALSE;
2440 }
2441 return kTRUE;
2442}
b26c3770 2443
596a855f 2444//_____________________________________________________________________________
af885e0f 2445Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 2446{
2447// run the barrel tracking
2448
52dd4a8c 2449 AliCodeTimerAuto("",0)
030b532d 2450
92bffc4d 2451 AliVertexer *vertexer = CreateVertexer();
2452 if (!vertexer) return kFALSE;
2453
3c99b88f 2454 AliInfo(Form("running the ITS vertex finder: %s",vertexer->ClassName()));
2257f27e 2455 AliESDVertex* vertex = NULL;
92bffc4d 2456 if (fLoader[0]) {
2457 fLoader[0]->LoadRecPoints();
2458 TTree* cltree = fLoader[0]->TreeR();
2459 if (cltree) {
2460 if(fDiamondProfileSPD) vertexer->SetVtxStart(fDiamondProfileSPD);
2461 vertex = vertexer->FindVertexForCurrentEvent(cltree);
308c2f7c 2462 }
2463 else {
92bffc4d 2464 AliError("Can't get the ITS cluster tree");
308c2f7c 2465 }
92bffc4d 2466 fLoader[0]->UnloadRecPoints();
2257f27e 2467 }
92bffc4d 2468 else {
2469 AliError("Can't get the ITS loader");
2470 }
2471 if(!vertex){
2472 AliWarning("Vertex not found");
2473 vertex = new AliESDVertex();
2474 vertex->SetName("default");
2475 }
2476 else {
2477 vertex->SetName("reconstructed");
2257f27e 2478 }
92bffc4d 2479
2480 Double_t vtxPos[3];
2481 Double_t vtxErr[3];
2482 vertex->GetXYZ(vtxPos);
2483 vertex->GetSigmaXYZ(vtxErr);
2484
06cc9d95 2485 esd->SetPrimaryVertexSPD(vertex);
73c51de2 2486 AliESDVertex *vpileup = NULL;
2487 Int_t novertices = 0;
2488 vpileup = vertexer->GetAllVertices(novertices);
2489 if(novertices>1){
2490 for (Int_t kk=1; kk<novertices; kk++)esd->AddPileupVertexSPD(&vpileup[kk]);
2491 }
1f9831ab 2492 /*
32e449be 2493 // if SPD multiplicity has been determined, it is stored in the ESD
92bffc4d 2494 AliMultiplicity *mult = vertexer->GetMultiplicity();
32e449be 2495 if(mult)esd->SetMultiplicity(mult);
1f9831ab 2496 */
ac4a7581 2497 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2498 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
2499 }
2257f27e 2500 delete vertex;
2501
92bffc4d 2502 delete vertexer;
2503
2257f27e 2504 return kTRUE;
2505}
2506
1f9831ab 2507//_____________________________________________________________________________
2508Bool_t AliReconstruction::RunMultFinder(AliESDEvent*& esd)
2509{
2510 // run the trackleter for multiplicity study
2511
2512 AliCodeTimerAuto("",0)
2513
2514 AliTrackleter *trackleter = CreateMultFinder();
2515 if (!trackleter) return kFALSE;
2516
2517 AliInfo(Form("running the ITS multiplicity finder: %s",trackleter->ClassName()));
2518
2519 if (fLoader[0]) {
2520 fLoader[0]->LoadRecPoints();
2521 TTree* cltree = fLoader[0]->TreeR();
2522 if (cltree) {
2523 trackleter->Reconstruct(esd,cltree);
2524 AliMultiplicity *mult = trackleter->GetMultiplicity();
2525 if(mult) esd->SetMultiplicity(mult);
2526 }
2527 else {
2528 AliError("Can't get the ITS cluster tree");
2529 }
2530 fLoader[0]->UnloadRecPoints();
2531 }
2532 else {
2533 AliError("Can't get the ITS loader");
2534 }
2535
2536 delete trackleter;
2537
2538 return kTRUE;
2539}
2540
1f46a9ae 2541//_____________________________________________________________________________
af885e0f 2542Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 2543{
2544// run the HLT barrel tracking
2545
52dd4a8c 2546 AliCodeTimerAuto("",0)
1f46a9ae 2547
2548 if (!fRunLoader) {
2549 AliError("Missing runLoader!");
2550 return kFALSE;
2551 }
2552
2553 AliInfo("running HLT tracking");
2554
2555 // Get a pointer to the HLT reconstructor
ac4a7581 2556 AliReconstructor *reconstructor = GetReconstructor(kNDetectors-1);
1f46a9ae 2557 if (!reconstructor) return kFALSE;
2558
2559 // TPC + ITS
2560 for (Int_t iDet = 1; iDet >= 0; iDet--) {
2561 TString detName = fgkDetectorName[iDet];
2562 AliDebug(1, Form("%s HLT tracking", detName.Data()));
2563 reconstructor->SetOption(detName.Data());
d76c31f4 2564 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 2565 if (!tracker) {
2566 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
2567 if (fStopOnError) return kFALSE;
9dcc06e1 2568 continue;
1f46a9ae 2569 }
2570 Double_t vtxPos[3];
2571 Double_t vtxErr[3]={0.005,0.005,0.010};
2572 const AliESDVertex *vertex = esd->GetVertex();
2573 vertex->GetXYZ(vtxPos);
2574 tracker->SetVertex(vtxPos,vtxErr);
2575 if(iDet != 1) {
2576 fLoader[iDet]->LoadRecPoints("read");
2577 TTree* tree = fLoader[iDet]->TreeR();
2578 if (!tree) {
2579 AliError(Form("Can't get the %s cluster tree", detName.Data()));
2580 return kFALSE;
2581 }
2582 tracker->LoadClusters(tree);
2583 }
2584 if (tracker->Clusters2Tracks(esd) != 0) {
2585 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
2586 return kFALSE;
2587 }
2588 if(iDet != 1) {
2589 tracker->UnloadClusters();
2590 }
2591 delete tracker;
2592 }
2593
1f46a9ae 2594 return kTRUE;
2595}
2596
e66fbafb 2597//_____________________________________________________________________________
af885e0f 2598Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 2599{
2600// run the muon spectrometer tracking
2601
52dd4a8c 2602 AliCodeTimerAuto("",0)
e66fbafb 2603
2604 if (!fRunLoader) {
2605 AliError("Missing runLoader!");
2606 return kFALSE;
2607 }
2608 Int_t iDet = 7; // for MUON
2609
2610 AliInfo("is running...");
2611
2612 // Get a pointer to the MUON reconstructor
2613 AliReconstructor *reconstructor = GetReconstructor(iDet);
2614 if (!reconstructor) return kFALSE;
2615
2616
2617 TString detName = fgkDetectorName[iDet];
2618 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 2619 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 2620 if (!tracker) {
2621 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
2622 return kFALSE;
2623 }
2624
e66fbafb 2625 // read RecPoints
761350a6 2626 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 2627
761350a6 2628 tracker->LoadClusters(fLoader[iDet]->TreeR());
2629
2630 Int_t rv = tracker->Clusters2Tracks(esd);
2631
e66fbafb 2632 fLoader[iDet]->UnloadRecPoints();
2633
c1954ee5 2634 tracker->UnloadClusters();
2635
e66fbafb 2636 delete tracker;
2637
cb23c6ca 2638 if ( rv )
2639 {
2640 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
2641 return kFALSE;
2642 }
2643
e66fbafb 2644 return kTRUE;
2645}
2646
2647
2257f27e 2648//_____________________________________________________________________________
10d100d4 2649Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd,AliESDpid &PID)
2257f27e 2650{
2651// run the barrel tracking
0f88822a 2652 static Int_t eventNr=0;
52dd4a8c 2653 AliCodeTimerAuto("",0)
24f7a148 2654
815c2b38 2655 AliInfo("running tracking");
596a855f 2656
1f26f3e7 2657 // Set the event info which is used
2658 // by the trackers in order to obtain
2659 // information about read-out detectors,
2660 // trigger etc.
2661 AliDebug(1, "Setting event info");
2662 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2663 if (!fTracker[iDet]) continue;
2664 fTracker[iDet]->SetEventInfo(&fEventInfo);
2665 }
2666
91b876d1 2667 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 2668 if (fReconstructor[11] && fLoader[11]) {
2669 fLoader[11]->LoadRecPoints("READ");
2670 TTree *treeR = fLoader[11]->TreeR();
89916438 2671 if (treeR) {
2672 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
2673 }
d76c31f4 2674 }
91b876d1 2675
b8cd5251 2676 // pass 1: TPC + ITS inwards
2677 for (Int_t iDet = 1; iDet >= 0; iDet--) {
2678 if (!fTracker[iDet]) continue;
2679 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 2680
b8cd5251 2681 // load clusters
2682 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2683 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 2684 TTree* tree = fLoader[iDet]->TreeR();
2685 if (!tree) {
2686 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2687 return kFALSE;
2688 }
b8cd5251 2689 fTracker[iDet]->LoadClusters(tree);
6efecea1 2690 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2691 // run tracking
2692 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
2693 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 2694 return kFALSE;
2695 }
878e1fe1 2696 // preliminary PID in TPC needed by the ITS tracker
2697 if (iDet == 1) {
b26c3770 2698 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
10d100d4 2699 PID.MakePID(esd,kTRUE);
0f88822a 2700 }
6efecea1 2701 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 2702 }
596a855f 2703
b8cd5251 2704 // pass 2: ALL backwards
aa3c69a9 2705
ac4a7581 2706 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2707 if (!fTracker[iDet]) continue;
2708 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
2709
2710 // load clusters
2711 if (iDet > 1) { // all except ITS, TPC
2712 TTree* tree = NULL;
7b61cd9c 2713 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2714 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 2715 tree = fLoader[iDet]->TreeR();
b8cd5251 2716 if (!tree) {
eca4fa66 2717 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
2718 return kFALSE;
24f7a148 2719 }
0f88822a 2720 fTracker[iDet]->LoadClusters(tree);
6efecea1 2721 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2722 }
24f7a148 2723
b8cd5251 2724 // run tracking
283f39c6 2725 if (iDet>1) // start filling residuals for the "outer" detectors
eca4fa66 2726 if (fRunGlobalQA) {
2727 AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);
2728 TObjArray ** arr = AliTracker::GetResidualsArray() ;
c9526f68 2729 if (arr) {
0a349581 2730 AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
2731 TObjArray * elem = arr[AliRecoParam::AConvert(es)];
c9526f68 2732 if ( elem && (! elem->At(0)) ) {
2733 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
2734 if (qadm) qadm->InitRecPointsForTracker() ;
2735 }
2736 }
eca4fa66 2737 }
b8cd5251 2738 if (fTracker[iDet]->PropagateBack(esd) != 0) {
2739 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 2740 // return kFALSE;
b8cd5251 2741 }
24f7a148 2742
b8cd5251 2743 // unload clusters
6e65648b 2744 if (iDet > 3) { // all except ITS, TPC, TRD and TOF
b8cd5251 2745 fTracker[iDet]->UnloadClusters();
7b61cd9c 2746 fLoader[iDet]->UnloadRecPoints();
b8cd5251 2747 }
8f37df88 2748 // updated PID in TPC needed by the ITS tracker -MI
2749 if (iDet == 1) {
10d100d4 2750 //GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
2751 //AliESDpid::MakePID(esd);
2752 PID.MakePID(esd,kTRUE);
8f37df88 2753 }
6efecea1 2754 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 2755 }
283f39c6 2756 //stop filling residuals for the "outer" detectors
57acd2d2 2757 if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);
596a855f 2758
b8cd5251 2759 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 2760
b8cd5251 2761 for (Int_t iDet = 2; iDet >= 0; iDet--) {
2762 if (!fTracker[iDet]) continue;
2763 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 2764
b8cd5251 2765 // run tracking
283f39c6 2766 if (iDet<2) // start filling residuals for TPC and ITS
eca4fa66 2767 if (fRunGlobalQA) {
2768 AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);
2769 TObjArray ** arr = AliTracker::GetResidualsArray() ;
c9526f68 2770 if (arr) {
0a349581 2771 AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
2772 TObjArray * elem = arr[AliRecoParam::AConvert(es)];
c9526f68 2773 if ( elem && (! elem->At(0)) ) {
2774 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
2775 if (qadm) qadm->InitRecPointsForTracker() ;
2776 }
2777 }
eca4fa66 2778 }
2779
b8cd5251 2780 if (fTracker[iDet]->RefitInward(esd) != 0) {
2781 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 2782 // return kFALSE;
b8cd5251 2783 }
db2368d0 2784 // run postprocessing
2785 if (fTracker[iDet]->PostProcess(esd) != 0) {
2786 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
2787 // return kFALSE;
2788 }
6efecea1 2789 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
6e65648b 2790 }
2791
2792 // write space-points to the ESD in case alignment data output
2793 // is switched on
2794 if (fWriteAlignmentData)
2795 WriteAlignmentData(esd);
2796
2797 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2798 if (!fTracker[iDet]) continue;
b8cd5251 2799 // unload clusters
2800 fTracker[iDet]->UnloadClusters();
6efecea1 2801 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 2802 fLoader[iDet]->UnloadRecPoints();
6efecea1 2803 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 2804 }
283f39c6 2805 // stop filling residuals for TPC and ITS
57acd2d2 2806 if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);
854c6476 2807
0f88822a 2808 eventNr++;
596a855f 2809 return kTRUE;
2810}
2811
d64bd07d 2812//_____________________________________________________________________________
2813Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
2814 //
2815 // Remove the data which are not needed for the physics analysis.
2816 //
2817
d64bd07d 2818 Int_t nTracks=esd->GetNumberOfTracks();
18571674 2819 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 2820 AliInfo
2821 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 2822
18571674 2823 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 2824 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 2825
7f68891d 2826 nTracks=esd->GetNumberOfTracks();
18571674 2827 nV0s=esd->GetNumberOfV0s();
cf37fd88 2828 AliInfo
ae5d5566 2829 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 2830
7f68891d 2831 return rc;
d64bd07d 2832}
2833
596a855f 2834//_____________________________________________________________________________
af885e0f 2835Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 2836{
2837// fill the event summary data
2838
52dd4a8c 2839 AliCodeTimerAuto("",0)
0f88822a 2840 static Int_t eventNr=0;
596a855f 2841 TString detStr = detectors;
abe0c04e 2842
f1640d23 2843 AliSysInfo::AddStamp(Form("FillESDb%d",eventNr), -19,-19, eventNr);
ac4a7581 2844 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
abe0c04e 2845 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 2846 AliReconstructor* reconstructor = GetReconstructor(iDet);
2847 if (!reconstructor) continue;
4b71572b 2848 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
2849 TTree* clustersTree = NULL;
2850 if (fLoader[iDet]) {
2851 fLoader[iDet]->LoadRecPoints("read");
2852 clustersTree = fLoader[iDet]->TreeR();
2853 if (!clustersTree) {
2854 AliError(Form("Can't get the %s clusters tree",
2855 fgkDetectorName[iDet]));
2856 if (fStopOnError) return kFALSE;
2857 }
2858 }
2859 if (fRawReader && !reconstructor->HasDigitConversion()) {
2860 reconstructor->FillESD(fRawReader, clustersTree, esd);
2861 } else {
2862 TTree* digitsTree = NULL;
d76c31f4 2863 if (fLoader[iDet]) {
4b71572b 2864 fLoader[iDet]->LoadDigits("read");
2865 digitsTree = fLoader[iDet]->TreeD();
2866 if (!digitsTree) {
2867 AliError(Form("Can't get the %s digits tree",
b26c3770 2868 fgkDetectorName[iDet]));
2869 if (fStopOnError) return kFALSE;
2870 }
2871 }
4b71572b 2872 reconstructor->FillESD(digitsTree, clustersTree, esd);
2873 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
2874 }
2875 if (fLoader[iDet]) {
2876 fLoader[iDet]->UnloadRecPoints();
596a855f 2877 }
2878 }
13effe3f 2879
c7a22819 2880 if (!IsSelected("CTP", detStr)) AliDebug(10,"No CTP");
596a855f 2881 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 2882 AliError(Form("the following detectors were not found: %s",
2883 detStr.Data()));
596a855f 2884 if (fStopOnError) return kFALSE;
2885 }
f1640d23 2886 AliSysInfo::AddStamp(Form("FillESDe%d",eventNr), -20,-20, eventNr);
0f88822a 2887 eventNr++;
596a855f 2888 return kTRUE;
2889}
2890
b647652d 2891//_____________________________________________________________________________
af885e0f 2892Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 2893{
2894 // Reads the trigger decision which is
2895 // stored in Trigger.root file and fills
2896 // the corresponding esd entries
2897
52dd4a8c 2898 AliCodeTimerAuto("",0)
87932dab 2899
b647652d 2900 AliInfo("Filling trigger information into the ESD");
2901
2902 if (fRawReader) {
2903 AliCTPRawStream input(fRawReader);
2904 if (!input.Next()) {
7e88424f 2905 AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
b647652d 2906 }
2907 else {
7e88424f 2908 if (esd->GetTriggerMask() != input.GetClassMask())
2909 AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
2910 input.GetClassMask(),esd->GetTriggerMask()));
2911 if (esd->GetOrbitNumber() != input.GetOrbitID())
2912 AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
2913 input.GetOrbitID(),esd->GetOrbitNumber()));
2914 if (esd->GetBunchCrossNumber() != input.GetBCID())
2915 AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
2916 input.GetBCID(),esd->GetBunchCrossNumber()));
e61ed4b1 2917 AliESDHeader* esdheader = esd->GetHeader();
2918 esdheader->SetL0TriggerInputs(input.GetL0Inputs());
2919 esdheader->SetL1TriggerInputs(input.GetL1Inputs());
2920 esdheader->SetL2TriggerInputs(input.GetL2Inputs());
a6dd87ad 2921 // IR
2922 UInt_t orbit=input.GetOrbitID();
2923 for(Int_t i=0 ; i<input.GetNIRs() ; i++ )
2924 if(TMath::Abs(Int_t(orbit-(input.GetIR(i))->GetOrbit()))<=1){
2925 esdheader->AddTriggerIR(input.GetIR(i));
2926 }
5b3ea9c5 2927 AliCentralTrigger* rlCTP = fRunLoader->GetTrigger();
2928 rlCTP->SetL0TriggerInputs(input.GetL0Inputs());
2929 rlCTP->SetL1TriggerInputs(input.GetL1Inputs());
2930 rlCTP->SetL2TriggerInputs(input.GetL2Inputs());
b647652d 2931 }
5b3ea9c5 2932 if (fIsNewRunLoader) fRunLoader->TreeCT()->Fill();
b024fd7f 2933 }
f7812afc 2934 return kTRUE;
2935}
2936//_____________________________________________________________________________
2937Bool_t AliReconstruction::FillTriggerScalers(AliESDEvent*& esd)
2938{
522fdd91 2939 //Scalers
82ebedd6 2940 //fRunScalers->Print();
2941 if(fRunScalers && fRunScalers->CheckRunScalers()){
a6dd87ad 2942 AliTimeStamp* timestamp = new AliTimeStamp(esd->GetOrbitNumber(), esd->GetPeriodNumber(), esd->GetBunchCrossNumber());
82ebedd6 2943 //AliTimeStamp* timestamp = new AliTimeStamp(10308000, 0, (ULong64_t)486238);
522fdd91 2944 AliESDHeader* esdheader = fesd->GetHeader();
2945 for(Int_t i=0;i<50;i++){
1e78ae8c 2946 if((1ull<<i) & esd->GetTriggerMask()){
6863d231 2947 AliTriggerScalersESD* scalesd = fRunScalers->GetScalersForEventClass( timestamp, i+1);
82ebedd6 2948 if(scalesd)esdheader->SetTriggerScalersRecord(scalesd);
522fdd91 2949 }
2950 }
2951 }
b647652d 2952 return kTRUE;
2953}
001397cd 2954//_____________________________________________________________________________
af885e0f 2955Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 2956{
2957 //
2958 // Filling information from RawReader Header
2959 //
2960
151bea4e 2961 if (!fRawReader) return kFALSE;
2962
001397cd 2963 AliInfo("Filling information from RawReader Header");
151bea4e 2964
2965 esd->SetBunchCrossNumber(fRawReader->GetBCID());
2966 esd->SetOrbitNumber(fRawReader->GetOrbitID());
2967 esd->SetPeriodNumber(fRawReader->GetPeriod());
2968
2969 esd->SetTimeStamp(fRawReader->GetTimestamp());
2970 esd->SetEventType(fRawReader->GetType());
001397cd 2971
2972 return kTRUE;
2973}
2974
2975
596a855f 2976//_____________________________________________________________________________
2977Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
2978{
2979// check whether detName is contained in detectors
2980// if yes, it is removed from detectors
2981
2982 // check if all detectors are selected
2983 if ((detectors.CompareTo("ALL") == 0) ||
2984 detectors.BeginsWith("ALL ") ||
2985 detectors.EndsWith(" ALL") ||
2986 detectors.Contains(" ALL ")) {
2987 detectors = "ALL";
2988 return kTRUE;
2989 }
2990
2991 // search for the given detector
2992 Bool_t result = kFALSE;
2993 if ((detectors.CompareTo(detName) == 0) ||
2994 detectors.BeginsWith(detName+" ") ||
2995 detectors.EndsWith(" "+detName) ||
2996 detectors.Contains(" "+detName+" ")) {
2997 detectors.ReplaceAll(detName, "");
2998 result = kTRUE;
2999 }
3000
3001 // clean up the detectors string
3002 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
3003 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
3004 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
3005
3006 return result;
3007}
e583c30d 3008
f08fc9f5 3009//_____________________________________________________________________________
3010Bool_t AliReconstruction::InitRunLoader()
3011{
3012// get or create the run loader
3013
3014 if (gAlice) delete gAlice;
3015 gAlice = NULL;
3016
52dd4a8c 3017 TFile *gafile = TFile::Open(fGAliceFileName.Data());
3018 // if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
3019 if (gafile) { // galice.root exists
3020 gafile->Close();
3021 delete gafile;
3022
b26c3770 3023 // load all base libraries to get the loader classes
3024 TString libs = gSystem->GetLibraries();
ac4a7581 3025 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b26c3770 3026 TString detName = fgkDetectorName[iDet];
3027 if (detName == "HLT") continue;
3028 if (libs.Contains("lib" + detName + "base.so")) continue;
3029 gSystem->Load("lib" + detName + "base.so");
3030 }
f08fc9f5 3031 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
3032 if (!fRunLoader) {
3033 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
3034 CleanUp();
3035 return kFALSE;
3036 }
325aa76f 3037
b26c3770 3038 fRunLoader->CdGAFile();
325aa76f 3039 fRunLoader->LoadgAlice();
f08fc9f5 3040
6cae184e 3041 //PH This is a temporary fix to give access to the kinematics
3042 //PH that is needed for the labels of ITS clusters
f2ee4290 3043 fRunLoader->LoadHeader();
6cae184e 3044 fRunLoader->LoadKinematics();
3045
f08fc9f5 3046 } else { // galice.root does not exist
3047 if (!fRawReader) {
3048 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
f08fc9f5 3049 }
3050 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
3051 AliConfig::GetDefaultEventFolderName(),
3052 "recreate");
3053 if (!fRunLoader) {
3054 AliError(Form("could not create run loader in file %s",
3055 fGAliceFileName.Data()));
3056 CleanUp();
3057 return kFALSE;
3058 }
21a3aa09 3059 fIsNewRunLoader = kTRUE;
f08fc9f5 3060 fRunLoader->MakeTree("E");
5b3ea9c5 3061 fRunLoader->MakeTree("GG");
21a3aa09 3062
973388c2 3063 if (fNumberOfEventsPerFile > 0)
3064 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
3065 else
21a3aa09 3066 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 3067 }
3068
3069 return kTRUE;
3070}
3071
c757bafd 3072//_____________________________________________________________________________
b8cd5251 3073AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 3074{
f08fc9f5 3075// get the reconstructor object and the loader for a detector
c757bafd 3076
7e88424f 3077 if (fReconstructor[iDet]) {
3078 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
3079 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
3080 fReconstructor[iDet]->SetRecoParam(par);
42ec5d3d 3081 fReconstructor[iDet]->SetRunInfo(fRunInfo);
7e88424f 3082 }
3083 return fReconstructor[iDet];
3084 }
b8cd5251 3085
3086 // load the reconstructor object
3087 TPluginManager* pluginManager = gROOT->GetPluginManager();
3088 TString detName = fgkDetectorName[iDet];
3089 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 3090
3091 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 3092
b8cd5251 3093 AliReconstructor* reconstructor = NULL;
3094 // first check if a plugin is defined for the reconstructor
3095 TPluginHandler* pluginHandler =
3096 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 3097 // if not, add a plugin for it
3098 if (!pluginHandler) {
b8cd5251 3099 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 3100 TString libs = gSystem->GetLibraries();
3101 if (libs.Contains("lib" + detName + "base.so") ||
3102 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 3103 pluginManager->AddHandler("AliReconstructor", detName,
3104 recName, detName + "rec", recName + "()");
3105 } else {
3106 pluginManager->AddHandler("AliReconstructor", detName,
3107 recName, detName, recName + "()");
c757bafd 3108 }
b8cd5251 3109 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
3110 }
3111 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
3112 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 3113 }
f9fc20b4 3114
3115 // check if the upgrade reconstructor should be used instead of the standard one
3116 if(fUpgradeMask[iDet]) {
3117 if(reconstructor) delete reconstructor;
3118 TClass *cl = new TClass(Form("Ali%sUpgradeReconstructor",fgkDetectorName[iDet]));
3119 reconstructor = (AliReconstructor*)(cl->New());
3120 }
3121
b8cd5251 3122 if (reconstructor) {
3123 TObject* obj = fOptions.FindObject(detName.Data());
3124 if (obj) reconstructor->SetOption(obj->GetTitle());
1e500f25 3125 reconstructor->SetRunInfo(fRunInfo);
d76c31f4 3126 reconstructor->Init();
b8cd5251 3127 fReconstructor[iDet] = reconstructor;
3128 }
3129
f08fc9f5 3130 // get or create the loader
3131 if (detName != "HLT") {
3132 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
3133 if (!fLoader[iDet]) {
3134 AliConfig::Instance()
3135 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
3136 detName, detName);
3137 // first check if a plugin is defined for the loader
bb0901a4 3138 pluginHandler =
f08fc9f5 3139 pluginManager->FindHandler("AliLoader", detName);
3140 // if not, add a plugin for it
3141 if (!pluginHandler) {
3142 TString loaderName = "Ali" + detName + "Loader";
3143 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
3144 pluginManager->AddHandler("AliLoader", detName,
3145 loaderName, detName + "base",
3146 loaderName + "(const char*, TFolder*)");
3147 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
3148 }
3149 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
3150 fLoader[iDet] =
3151 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
3152 fRunLoader->GetEventFolder());
3153 }
3154 if (!fLoader[iDet]) { // use default loader
3155 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
3156 }
3157 if (!fLoader[iDet]) {
3158 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 3159 if (fStopOnError) return NULL;
f08fc9f5 3160 } else {
3161 fRunLoader->AddLoader(fLoader[iDet]);
3162 fRunLoader->CdGAFile();
3163 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
3164 fRunLoader->Write(0, TObject::kOverwrite);
3165 }
3166 }
3167 }
3168
7e88424f 3169 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
3170 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
c7a22819 3171 if (reconstructor) {
3172 reconstructor->SetRecoParam(par);
3173 reconstructor->SetRunInfo(fRunInfo);
3174 }
7e88424f 3175 }
b8cd5251 3176 return reconstructor;
c757bafd 3177}
3178
2257f27e 3179//_____________________________________________________________________________
92bffc4d 3180AliVertexer* AliReconstruction::CreateVertexer()
2257f27e 3181{
3182// create the vertexer
92bffc4d 3183// Please note that the caller is the owner of the
3184// vertexer
2257f27e 3185
92bffc4d 3186 AliVertexer* vertexer = NULL;
b8cd5251 3187 AliReconstructor* itsReconstructor = GetReconstructor(0);
903b1262 3188 if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) ||
3189 fRunTracking.Contains("ITS") || fFillESD.Contains("ITS") )) {
92bffc4d 3190 vertexer = itsReconstructor->CreateVertexer();
2257f27e 3191 }
92bffc4d 3192 if (!vertexer) {
815c2b38 3193 AliWarning("couldn't create a vertexer for ITS");
2257f27e 3194 }
3195
92bffc4d 3196 return vertexer;
2257f27e 3197}
3198
1f9831ab 3199//_____________________________________________________________________________
3200AliTrackleter* AliReconstruction::CreateMultFinder()
3201{
3202// create the ITS trackleter for mult. estimation
3203// Please note that the caller is the owner of the
3204// trackleter
3205
3206 AliTrackleter* trackleter = NULL;
3207 AliReconstructor* itsReconstructor = GetReconstructor(0);
903b1262 3208 if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) ||
3209 fRunTracking.Contains("ITS") || fFillESD.Contains("ITS") )) {
1f9831ab 3210 trackleter = itsReconstructor->CreateMultFinder();
3211 }
a0ef2c64 3212 else {
3213 AliWarning("ITS is not in reconstruction, switching off RunMultFinder");
3214 fRunMultFinder = kFALSE;
1f9831ab 3215 }
3216
3217 return trackleter;
3218}
3219
24f7a148 3220//_____________________________________________________________________________
b8cd5251 3221Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 3222{
f08fc9f5 3223// create the trackers
44e45fac 3224 AliInfo("Creating trackers");
24f7a148 3225
b8cd5251 3226 TString detStr = detectors;
ac4a7581 3227 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 3228 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
3229 AliReconstructor* reconstructor = GetReconstructor(iDet);
3230 if (!reconstructor) continue;
3231 TString detName = fgkDetectorName[iDet];
1f46a9ae 3232 if (detName == "HLT") {
3233 fRunHLTTracking = kTRUE;
3234 continue;
3235 }
e66fbafb 3236 if (detName == "MUON") {
3237 fRunMuonTracking = kTRUE;
3238 continue;
3239 }
3240
d76c31f4 3241 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 3242 if (!fTracker[iDet] && (iDet < 7)) {
3243 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 3244 if (fStopOnError) return kFALSE;
3245 }
6efecea1 3246 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 3247 }
3248
24f7a148 3249 return kTRUE;
3250}
3251
e583c30d 3252//_____________________________________________________________________________
4b71572b 3253void AliReconstruction::CleanUp()
e583c30d 3254{
3255// delete trackers and the run loader and close and delete the file
3256
ac4a7581 3257 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 3258 delete fReconstructor[iDet];
3259 fReconstructor[iDet] = NULL;
3260 fLoader[iDet] = NULL;
3261 delete fTracker[iDet];
3262 fTracker[iDet] = NULL;
3263 }
4b71572b 3264 delete fRunInfo;
7e88424f 3265 fRunInfo = NULL;
3266
58e8dc31 3267 delete fSPDTrackleter;
3268 fSPDTrackleter = NULL;
3269
4b71572b 3270 delete ftVertexer;
21a3aa09 3271 ftVertexer = NULL;
795e4a22 3272
e583c30d 3273 delete fRunLoader;
3274 fRunLoader = NULL;
b649205a 3275 delete fRawReader;
3276 fRawReader = NULL;
4b71572b 3277 delete fParentRawReader;
cd0b062e 3278 fParentRawReader=NULL;
e583c30d 3279
4b71572b 3280 if (ffile) {
3281 ffile->Close();
3282 delete ffile;
3283 ffile = NULL;
24f7a148 3284 }
87da0921 3285
bf76b847 3286 if (AliQAManager::QAManager())
3287 AliQAManager::QAManager()->ShowQA() ;
eca4fa66 3288 AliQAManager::Destroy() ;
3289
24f7a148 3290}
f3a97c86 3291
af885e0f 3292void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 3293{
3294 // Write space-points which are then used in the alignment procedures
6e65648b 3295 // For the moment only ITS, TPC, TRD and TOF
98937d93 3296
98937d93 3297 Int_t ntracks = esd->GetNumberOfTracks();
3298 for (Int_t itrack = 0; itrack < ntracks; itrack++)
3299 {
3300 AliESDtrack *track = esd->GetTrack(itrack);
3301 Int_t nsp = 0;
ef7253ac 3302 Int_t idx[200];
76741755 3303 for (Int_t i=0; i<200; ++i) idx[i] = -1; //PH avoid uninitialized values
81aa7a0d 3304 for (Int_t iDet = 5; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
0ad488b0 3305 nsp += (iDet==GetDetIndex("TRD")) ? track->GetTRDntracklets():track->GetNcls(iDet);
6e65648b 3306
0ad488b0 3307 if (iDet==GetDetIndex("ITS")) { // ITS "extra" clusters
6e65648b 3308 track->GetClusters(iDet,idx);
3309 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
3310 }
3311 }
3312
98937d93 3313 if (nsp) {
3314 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
3315 track->SetTrackPointArray(sp);
3316 Int_t isptrack = 0;
81aa7a0d 3317 for (Int_t iDet = 5; iDet >= 0; iDet--) {
98937d93 3318 AliTracker *tracker = fTracker[iDet];
3319 if (!tracker) continue;
0ad488b0 3320 Int_t nspdet = (iDet==GetDetIndex("TRD")) ? track->GetTRDtracklets(idx):track->GetClusters(iDet,idx);
6e65648b 3321
0ad488b0 3322 if (iDet==GetDetIndex("ITS")) // ITS "extra" clusters
6e65648b 3323 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
3324
98937d93 3325 if (nspdet <= 0) continue;
98937d93 3326 AliTrackPoint p;
3327 Int_t isp = 0;
3328 Int_t isp2 = 0;
4ed6fb1c 3329 while (isp2 < nspdet) {
f3c6e4c9 3330 Bool_t isvalid=kTRUE;
3331
3332 Int_t index=idx[isp++];
3333 if (index < 0) continue;
3334
c12b6e44 3335 TString dets = fgkDetectorName[iDet];
3336 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
3337 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
3338 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
3339 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
f3c6e4c9 3340 isvalid = tracker->GetTrackPointTrackingError(index,p,track);
48ce48d1 3341 } else {
f3c6e4c9 3342 isvalid = tracker->GetTrackPoint(index,p);
48ce48d1 3343 }
3344 isp2++;
98937d93 3345 if (!isvalid) continue;
0ad488b0 3346 if (iDet==GetDetIndex("ITS") && (isp-1)>=6) p.SetExtra();
f3c6e4c9 3347 sp->AddPoint(isptrack,&p); isptrack++;
98937d93 3348 }
98937d93 3349 }
3350 }
3351 }
98937d93 3352}
2e3550da 3353
3354//_____________________________________________________________________________
af885e0f 3355void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 3356{
3357 // The method reads the raw-data error log
3358 // accumulated within the rawReader.
3359 // It extracts the raw-data errors related to
3360 // the current event and stores them into
3361 // a TClonesArray inside the esd object.
3362
3363 if (!fRawReader) return;
3364
3365 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
3366
3367 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
3368 if (!log) continue;
3369 if (iEvent != log->GetEventNumber()) continue;
3370
3371 esd->AddRawDataErrorLog(log);
3372 }
3373
3374}
46698ae4 3375
8661738e 3376//_____________________________________________________________________________
0a035be5 3377// void AliReconstruction::CheckQA()
3378// {
8661738e 3379// check the QA of SIM for this run and remove the detectors
3380// with status Fatal
3381
57acd2d2 3382// TString newRunLocalReconstruction ;
3383// TString newRunTracking ;
3384// TString newFillESD ;
3385//
4e25ac79 3386// for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
3387// TString detName(AliQAv1::GetDetName(iDet)) ;
3388// AliQAv1 * qa = AliQAv1::Instance(AliQAv1::DETECTORINDEX_t(iDet)) ;
3389// if ( qa->IsSet(AliQAv1::DETECTORINDEX_t(iDet), AliQAv1::kSIM, specie, AliQAv1::kFATAL)) {
57acd2d2 3390// AliInfo(Form("QA status for %s %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed",
3391// detName.Data(), AliRecoParam::GetEventSpecieName(es))) ;
3392// } else {
4e25ac79 3393// if ( fRunLocalReconstruction.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3394// fRunLocalReconstruction.Contains("ALL") ) {
3395// newRunLocalReconstruction += detName ;
3396// newRunLocalReconstruction += " " ;
3397// }
4e25ac79 3398// if ( fRunTracking.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3399// fRunTracking.Contains("ALL") ) {
3400// newRunTracking += detName ;
3401// newRunTracking += " " ;
3402// }
4e25ac79 3403// if ( fFillESD.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3404// fFillESD.Contains("ALL") ) {
3405// newFillESD += detName ;
3406// newFillESD += " " ;
3407// }
3408// }
3409// }
3410// fRunLocalReconstruction = newRunLocalReconstruction ;
3411// fRunTracking = newRunTracking ;
3412// fFillESD = newFillESD ;
0a035be5 3413// }
5b188f2f 3414
3415//_____________________________________________________________________________
3416Int_t AliReconstruction::GetDetIndex(const char* detector)
3417{
3418 // return the detector index corresponding to detector
3419 Int_t index = -1 ;
ac4a7581 3420 for (index = 0; index < kNDetectors ; index++) {
5b188f2f 3421 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
3422 break ;
3423 }
3424 return index ;
3425}
7167ae53 3426//_____________________________________________________________________________
3427Bool_t AliReconstruction::FinishPlaneEff() {
3428 //
3429 // Here execute all the necessary operationis, at the end of the tracking phase,
d7f8fd68 3430 // in case that evaluation of PlaneEfficiencies was required for some detector.
3431 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
7167ae53 3432 //
3433 // This Preliminary version works only FOR ITS !!!!!
3434 // other detectors (TOF,TRD, etc. have to develop their specific codes)
3435 //
3436 // Input: none
d7f8fd68 3437 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
7167ae53 3438 //
3439 Bool_t ret=kFALSE;
5ee13eb5 3440 TString detStr = fLoadCDB;
58e8dc31 3441 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
d7f8fd68 3442 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
5ee13eb5 3443 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
58e8dc31 3444 if(fTracker[iDet] && fTracker[iDet]->GetPlaneEff()) {
d7f8fd68 3445 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
3446 TString name=planeeff->GetName();
3447 name+=".root";
3448 TFile* pefile = TFile::Open(name, "RECREATE");
3449 ret=(Bool_t)planeeff->Write();
3450 pefile->Close();
5fbd4fd6 3451 if(planeeff->GetCreateHistos()) {
d7f8fd68 3452 TString hname=planeeff->GetName();
3453 hname+="Histo.root";
3454 ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
5fbd4fd6 3455 }
3456 }
58e8dc31 3457 if(fSPDTrackleter) {
3458 AliPlaneEff *planeeff=fSPDTrackleter->GetPlaneEff();
3459 TString name="AliITSPlaneEffSPDtracklet.root";
3460 TFile* pefile = TFile::Open(name, "RECREATE");
3461 ret=(Bool_t)planeeff->Write();
3462 pefile->Close();
3463 AliESDEvent *dummy=NULL;
3464 ret=(Bool_t)fSPDTrackleter->PostProcess(dummy); // take care of writing other files
3465 }
7167ae53 3466 }
3467 return ret;
3468}
3469//_____________________________________________________________________________
3470Bool_t AliReconstruction::InitPlaneEff() {
3471//
3472 // Here execute all the necessary operations, before of the tracking phase,
3473 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
58e8dc31 3474 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
7167ae53 3475 // which should be updated/recalculated.
3476 //
3477 // This Preliminary version will work only FOR ITS !!!!!
3478 // other detectors (TOF,TRD, etc. have to develop their specific codes)
3479 //
3480 // Input: none
3481 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
3482 //
58e8dc31 3483
3484 fSPDTrackleter = NULL;
b8604b34 3485 TString detStr = fLoadCDB;
3486 if (IsSelected(fgkDetectorName[0], detStr)) {
3487 AliReconstructor* itsReconstructor = GetReconstructor(0);
3488 if (itsReconstructor) {
3489 fSPDTrackleter = itsReconstructor->CreateTrackleter(); // this is NULL unless required in RecoParam
3490 }
3491 if (fSPDTrackleter) {
3492 AliInfo("Trackleter for SPD has been created");
3493 }
58e8dc31 3494 }
7167ae53 3495 return kTRUE;
7520312d 3496}
14dd053c 3497
3498//_____________________________________________________________________________
3499Bool_t AliReconstruction::InitAliEVE()
3500{
3501 // This method should be called only in case
3502 // AliReconstruction is run
3503 // within the alieve environment.
3504 // It will initialize AliEVE in a way
3505 // so that it can visualize event processed
3506 // by AliReconstruction.
3507 // The return flag shows whenever the
3508 // AliEVE initialization was successful or not.
3509
5239ebd6 3510 TString macroStr(gSystem->Getenv("ALIEVE_ONLINE_MACRO"));
3511
3512 if (macroStr.IsNull())
3513 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
3514
3515 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
3516
14dd053c 3517 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
3518
6a840f1e 3519 gROOT->ProcessLine("if (!AliEveEventManager::GetMaster()){new AliEveEventManager();AliEveEventManager::GetMaster()->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(AliEveEventManager::GetMaster());};");
de33999e 3520 gROOT->ProcessLine("alieve_online_init()");
14dd053c 3521
3522 return kTRUE;
3523}
3524
3525//_____________________________________________________________________________
3526void AliReconstruction::RunAliEVE()
3527{
3528 // Runs AliEVE visualisation of
3529 // the current event.
3530 // Should be executed only after
3531 // successful initialization of AliEVE.
3532
3533 AliInfo("Running AliEVE...");
72c084a0 3534 gROOT->ProcessLine(Form("AliEveEventManager::GetMaster()->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p,(AliESDfriend*)%p);",fRunLoader,fRawReader,fesd,fesdf));
14dd053c 3535 gSystem->Run();
3536}
ce43afbe 3537
3538//_____________________________________________________________________________
3539Bool_t AliReconstruction::SetRunQA(TString detAndAction)
3540{
3541 // Allows to run QA for a selected set of detectors
44ed7a66 3542 // and a selected set of tasks among RAWS, DIGITSR, RECPOINTS and ESDS
ce43afbe 3543 // all selected detectors run the same selected tasks
3544
3545 if (!detAndAction.Contains(":")) {
3546 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
3547 fRunQA = kFALSE ;
3548 return kFALSE ;
3549 }
3550 Int_t colon = detAndAction.Index(":") ;
3551 fQADetectors = detAndAction(0, colon) ;
59b1e631 3552 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
ce43afbe 3553 if (fQATasks.Contains("ALL") ) {
44ed7a66 3554 fQATasks = Form("%d %d %d %d", AliQAv1::kRAWS, AliQAv1::kDIGITSR, AliQAv1::kRECPOINTS, AliQAv1::kESDS) ;
ce43afbe 3555 } else {
3556 fQATasks.ToUpper() ;
3557 TString tempo("") ;
3558 if ( fQATasks.Contains("RAW") )
4e25ac79 3559 tempo = Form("%d ", AliQAv1::kRAWS) ;
44ed7a66 3560 if ( fQATasks.Contains("DIGIT") )
3561 tempo += Form("%d ", AliQAv1::kDIGITSR) ;
ce43afbe 3562 if ( fQATasks.Contains("RECPOINT") )
4e25ac79 3563 tempo += Form("%d ", AliQAv1::kRECPOINTS) ;
ce43afbe 3564 if ( fQATasks.Contains("ESD") )
4e25ac79 3565 tempo += Form("%d ", AliQAv1::kESDS) ;
ce43afbe 3566 fQATasks = tempo ;
3567 if (fQATasks.IsNull()) {
3568 AliInfo("No QA requested\n") ;
3569 fRunQA = kFALSE ;
3570 return kTRUE ;
3571 }
3572 }
3573 TString tempo(fQATasks) ;
4e25ac79 3574 tempo.ReplaceAll(Form("%d", AliQAv1::kRAWS), AliQAv1::GetTaskName(AliQAv1::kRAWS)) ;
44ed7a66 3575 tempo.ReplaceAll(Form("%d", AliQAv1::kDIGITSR), AliQAv1::GetTaskName(AliQAv1::kDIGITSR)) ;
4e25ac79 3576 tempo.ReplaceAll(Form("%d", AliQAv1::kRECPOINTS), AliQAv1::GetTaskName(AliQAv1::kRECPOINTS)) ;
3577 tempo.ReplaceAll(Form("%d", AliQAv1::kESDS), AliQAv1::GetTaskName(AliQAv1::kESDS)) ;
ce43afbe 3578 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
3579 fRunQA = kTRUE ;
3580 return kTRUE;
3581}
3582
7e88424f 3583//_____________________________________________________________________________
3584Bool_t AliReconstruction::InitRecoParams()
3585{
3586 // The method accesses OCDB and retrieves all
3587 // the available reco-param objects from there.
3588
3589 Bool_t isOK = kTRUE;
3590
8b26452d 3591 if (fRecoParam.GetDetRecoParamArray(kNDetectors)) {
3592 AliInfo("Using custom GRP reconstruction parameters");
3593 }
3594 else {
3595 AliInfo("Loading GRP reconstruction parameter objects");
3596
3597 AliCDBPath path("GRP","Calib","RecoParam");
3598 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
3599 if(!entry){
3600 AliWarning("Couldn't find GRP RecoParam entry in OCDB");
3601 isOK = kFALSE;
3602 }
3603 else {
3604 TObject *recoParamObj = entry->GetObject();
3605 if (dynamic_cast<TObjArray*>(recoParamObj)) {
3606 // GRP has a normal TobjArray of AliDetectorRecoParam objects
3607 // Registering them in AliRecoParam
3608 fRecoParam.AddDetRecoParamArray(kNDetectors,dynamic_cast<TObjArray*>(recoParamObj));
3609 }
3610 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
3611 // GRP has only onse set of reco parameters
3612 // Registering it in AliRecoParam
3613 AliInfo("Single set of GRP reconstruction parameters found");
3614 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
3615 fRecoParam.AddDetRecoParam(kNDetectors,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
3616 }
3617 else {
3618 AliError("No valid GRP RecoParam object found in the OCDB");
3619 isOK = kFALSE;
3620 }
3621 entry->SetOwner(0);
3622 }
3623 }
3624
7d566c20 3625 TString detStr = fLoadCDB;
ac4a7581 3626 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
7e88424f 3627
7d566c20 3628 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
3629
7e88424f 3630 if (fRecoParam.GetDetRecoParamArray(iDet)) {
3631 AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
3632 continue;
3633 }
3634
ac232c75 3635 AliInfo(Form("Loading reconstruction parameter objects for detector %s",fgkDetectorName[iDet]));
7e88424f 3636
3637 AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
3638 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
3639 if(!entry){
3640 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
3641 isOK = kFALSE;
3642 }
3643 else {
3644 TObject *recoParamObj = entry->GetObject();
3645 if (dynamic_cast<TObjArray*>(recoParamObj)) {
3646 // The detector has a normal TobjArray of AliDetectorRecoParam objects
3647 // Registering them in AliRecoParam
3648 fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
3649 }
3650 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
3651 // The detector has only onse set of reco parameters
3652 // Registering it in AliRecoParam
ac232c75 3653 AliInfo(Form("Single set of reconstruction parameters found for detector %s",fgkDetectorName[iDet]));
7e88424f 3654 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
3655 fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
3656 }
3657 else {
3658 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
3659 isOK = kFALSE;
3660 }
3661 entry->SetOwner(0);
f168abba 3662 // FIX ME: We have to disable the unloading of reco-param CDB
3663 // entries because QA framework is using them. Has to be fix in
3664 // a way that the QA takes the objects already constructed in
3665 // this method.
3666 // AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
7e88424f 3667 }
3668 }
3669
e30a9b4d 3670 if (AliDebugLevel() > 0) fRecoParam.Print();
ac232c75 3671
7e88424f 3672 return isOK;
3673}
3674
3675//_____________________________________________________________________________
3676Bool_t AliReconstruction::GetEventInfo()
3677{
3678 // Fill the event info object
3679 // ...
52dd4a8c 3680 AliCodeTimerAuto("",0)
7e88424f 3681
3682 AliCentralTrigger *aCTP = NULL;
3683 if (fRawReader) {
3684 fEventInfo.SetEventType(fRawReader->GetType());
3685
3686 ULong64_t mask = fRawReader->GetClassMask();
3687 fEventInfo.SetTriggerMask(mask);
3688 UInt_t clmask = fRawReader->GetDetectorPattern()[0];
3689 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
3690
3691 aCTP = new AliCentralTrigger();
3692 TString configstr("");
3693 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
3694 AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
3695 delete aCTP;
3696 return kFALSE;
3697 }
3698 aCTP->SetClassMask(mask);
3699 aCTP->SetClusterMask(clmask);
5b3ea9c5 3700
3701 AliCentralTrigger* rlCTP = fRunLoader->GetTrigger();
3702 rlCTP->SetClassMask(mask);
3703 rlCTP->SetClusterMask(clmask);
7e88424f 3704 }
3705 else {
3706 fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
3707
3708 if (fRunLoader && (!fRunLoader->LoadTrigger())) {
3709 aCTP = fRunLoader->GetTrigger();
3710 fEventInfo.SetTriggerMask(aCTP->GetClassMask());
e61ed4b1 3711 // get inputs from actp - just get
3712 AliESDHeader* esdheader = fesd->GetHeader();
3713 esdheader->SetL0TriggerInputs(aCTP->GetL0TriggerInputs());
3714 esdheader->SetL1TriggerInputs(aCTP->GetL1TriggerInputs());
3715 esdheader->SetL2TriggerInputs(aCTP->GetL2TriggerInputs());
7e88424f 3716 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
3717 }
3718 else {
3719 AliWarning("No trigger can be loaded! The trigger information will not be used!");
3720 return kFALSE;
3721 }
3722 }
3723
3724 AliTriggerConfiguration *config = aCTP->GetConfiguration();
3725 if (!config) {
3726 AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
3727 if (fRawReader) delete aCTP;
3728 return kFALSE;
3729 }
3730
a0c2cf2d 3731 UChar_t clustmask = 0;
7e88424f 3732 TString trclasses;
3733 ULong64_t trmask = fEventInfo.GetTriggerMask();
3734 const TObjArray& classesArray = config->GetClasses();
3735 Int_t nclasses = classesArray.GetEntriesFast();
3736 for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
3737 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
a2ec4f82 3738 if (trclass && trclass->GetMask()>0) {
a4b0683d 3739 Int_t trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
7e88424f 3740 fesd->SetTriggerClass(trclass->GetName(),trindex);
8a933107 3741 if (fRawReader) fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
e61ed4b1 3742 if (trmask & (1ull << trindex)) {
7e88424f 3743 trclasses += " ";
3744 trclasses += trclass->GetName();
3745 trclasses += " ";
a0c2cf2d 3746 clustmask |= trclass->GetCluster()->GetClusterMask();
7e88424f 3747 }
3748 }
3749 }
3750 fEventInfo.SetTriggerClasses(trclasses);
3751
6ef9caeb 3752 // Write names of active trigger inputs in ESD Header
3753 const TObjArray& inputsArray = config->GetInputs();
3754 Int_t ninputs = inputsArray.GetEntriesFast();
3755 for( Int_t iinput=0; iinput < ninputs; iinput++ ) {
3756 AliTriggerInput* trginput = (AliTriggerInput*)inputsArray.At(iinput);
a2ec4f82 3757 if (trginput && trginput->GetMask()>0) {
6ef9caeb 3758 Int_t inputIndex = (Int_t)TMath::Nint(TMath::Log2(trginput->GetMask()));
3759 AliESDHeader* headeresd = fesd->GetHeader();
3760 Int_t trglevel = (Int_t)trginput->GetLevel();
3761 if (trglevel == 0) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex);
3762 if (trglevel == 1) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+24);
3763 if (trglevel == 2) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+48);
3764 }
3765 }
3766
a0c2cf2d 3767 // Set the information in ESD
3768 fesd->SetTriggerMask(trmask);
3769 fesd->SetTriggerCluster(clustmask);
3770
7e88424f 3771 if (!aCTP->CheckTriggeredDetectors()) {
3772 if (fRawReader) delete aCTP;
3773 return kFALSE;
3774 }
3775
3776 if (fRawReader) delete aCTP;
3777
3778 // We have to fill also the HLT decision here!!
3779 // ...
3780
3781 return kTRUE;
3782}
3783
3784const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
3785{
3786 // Match the detector list found in the rec.C or the default 'ALL'
3787 // to the list found in the GRP (stored there by the shuttle PP which
3788 // gets the information from ECS)
3789 static TString resultList;
3790 TString detList = detectorList;
3791
3792 resultList = "";
3793
3794 for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
3795 if ((detectorMask >> iDet) & 0x1) {
3796 TString det = AliDAQ::OfflineModuleName(iDet);
3797 if ((detList.CompareTo("ALL") == 0) ||
a101e1dd 3798 ((detList.BeginsWith("ALL ") ||
3799 detList.EndsWith(" ALL") ||
3800 detList.Contains(" ALL ")) &&
3801 !(detList.BeginsWith("-"+det+" ") ||
3802 detList.EndsWith(" -"+det) ||
3803 detList.Contains(" -"+det+" "))) ||
7e88424f 3804 (detList.CompareTo(det) == 0) ||
a101e1dd 3805 detList.BeginsWith(det+" ") ||
3806 detList.EndsWith(" "+det) ||
7e88424f 3807 detList.Contains( " "+det+" " )) {
3808 if (!resultList.EndsWith(det + " ")) {
3809 resultList += det;
3810 resultList += " ";
3811 }
3812 }
3813 }
3814 }
3815
3816 // HLT
3817 if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
3818 TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
3819 if ((detList.CompareTo("ALL") == 0) ||
a101e1dd 3820 ((detList.BeginsWith("ALL ") ||
3821 detList.EndsWith(" ALL") ||
3822 detList.Contains(" ALL ")) &&
3823 !(detList.BeginsWith("-"+hltDet+" ") ||
3824 detList.EndsWith(" -"+hltDet) ||
3825 detList.Contains(" -"+hltDet+" "))) ||
7e88424f 3826 (detList.CompareTo(hltDet) == 0) ||
a101e1dd 3827 detList.BeginsWith(hltDet+" ") ||
3828 detList.EndsWith(" "+hltDet) ||
7e88424f 3829 detList.Contains( " "+hltDet+" " )) {
3830 resultList += hltDet;
3831 }
3832 }
3833
3834 return resultList.Data();
3835
3836}
4b71572b 3837
3838//______________________________________________________________________________
3839void AliReconstruction::Abort(const char *method, EAbort what)
3840{
3841 // Abort processing. If what = kAbortProcess, the Process() loop will be
3842 // aborted. If what = kAbortFile, the current file in a chain will be
3843 // aborted and the processing will continue with the next file, if there
3844 // is no next file then Process() will be aborted. Abort() can also be
3845 // called from Begin(), SlaveBegin(), Init() and Notify(). After abort
3846 // the SlaveTerminate() and Terminate() are always called. The abort flag
3847 // can be checked in these methods using GetAbort().
3848 //
3849 // The method is overwritten in AliReconstruction for better handling of
3850 // reco specific errors
3851
3852 if (!fStopOnError) return;
3853
3854 CleanUp();
3855
3856 TString whyMess = method;
3857 whyMess += " failed! Aborting...";
3858
3859 AliError(whyMess.Data());
3860
3861 fAbort = what;
3862 TString mess = "Abort";
3863 if (fAbort == kAbortProcess)
3864 mess = "AbortProcess";
3865 else if (fAbort == kAbortFile)
3866 mess = "AbortFile";
3867
3868 Info(mess, whyMess.Data());
3869}
3870
2f954aba 3871//______________________________________________________________________________
3872Bool_t AliReconstruction::ProcessEvent(void* event)
3873{
3874 // Method that is used in case the event loop
3875 // is steered from outside, for example by AMORE
3876 // 'event' is a pointer to the DATE event in the memory
3877
3878 if (fRawReader) delete fRawReader;
3879 fRawReader = new AliRawReaderDate(event);
3880 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
3881 delete fRawReader;
3882 fRawReader = NULL;
3883
3884 return fStatus;
3885}
81d57268 3886
3887//______________________________________________________________________________
3888Bool_t AliReconstruction::ParseOutput()
3889{
3890 // The method parses the output file
3891 // location string in order to steer
3892 // properly the selector
3893
3894 TPMERegexp re1("(\\w+\\.zip#\\w+\\.root):([,*\\w+\\.root,*]+)@dataset://(\\w++)");
3895 TPMERegexp re2("(\\w+\\.root)?@?dataset://(\\w++)");
3896
3897 if (re1.Match(fESDOutput) == 4) {
3898 // root archive with output files stored and regustered
3899 // in proof dataset
3900 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",re1[1].Data()));
3901 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re1[3].Data()));
3902 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
3903 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_ARCHIVE",re1[2].Data()));
3904 AliInfo(Form("%s files will be stored within %s in dataset %s",
3905 re1[2].Data(),
3906 re1[1].Data(),
3907 re1[3].Data()));
3908 }
3909 else if (re2.Match(fESDOutput) == 3) {
3910 // output file stored and registered
3911 // in proof dataset
3912 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",(re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data()));
3913 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re2[2].Data()));
3914 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
3915 AliInfo(Form("%s will be stored in dataset %s",
3916 (re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data(),
3917 re2[2].Data()));
3918 }
3919 else {
3920 if (fESDOutput.IsNull()) {
3921 // Output location not given.
3922 // Assuming xrootd has been already started and
3923 // the output file has to be sent back
3924 // to the client machine
3925 TString esdUrl(Form("root://%s/%s/",
3926 TUrl(gSystem->HostName()).GetHostFQDN(),
3927 gSystem->pwd()));
3928 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE","AliESDs.root"));
3929 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",esdUrl.Data()));
3930 AliInfo(Form("AliESDs.root will be stored in %s",
3931 esdUrl.Data()));
3932 }
3933 else {
3934 // User specified an output location.
3935 // Ones has just to parse it here
3936 TUrl outputUrl(fESDOutput.Data());
3937 TString outputFile(gSystem->BaseName(outputUrl.GetFile()));
3938 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",outputFile.IsNull() ? "AliESDs.root" : outputFile.Data()));
3939 TString outputLocation(outputUrl.GetUrl());
3940 outputLocation.ReplaceAll(outputFile.Data(),"");
3941 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",outputLocation.Data()));
3942 AliInfo(Form("%s will be stored in %s",
3943 outputFile.IsNull() ? "AliESDs.root" : outputFile.Data(),
3944 outputLocation.Data()));
3945 }
3946 }
3947
3948 return kTRUE;
3949}
f00558b6 3950
3951//______________________________________________________________________________
3952Bool_t AliReconstruction::IsHighPt() const {
3953 // Selection of events containing "high" pT tracks
3954 // If at least one track is found within 1.5 and 100 GeV (pT)
3955 // that was reconstructed by both ITS and TPC, the event is accepted
3956
3957 // Track cuts
f00558b6 3958 const Double_t pTmin = 1.5;
3959 const Double_t pTmax = 100;
3960 ULong_t mask = 0;
3961 mask |= (AliESDtrack::kITSrefit);
3962 mask |= (AliESDtrack::kTPCrefit);
a307e234 3963 const Double_t pTminCosmic = 5.;
3964 const Double_t pTmaxCosmic = 100;
3965 ULong_t maskCosmic = 0;
d0fc0a32 3966 Int_t cosmicCount=0;
a307e234 3967 maskCosmic |= (AliESDtrack::kTPCrefit);
f00558b6 3968
3969 Bool_t isOK = kFALSE;
3970
3971 if (fesd && fesd->GetEventType()==AliRawEventHeaderBase::kPhysicsEvent) {
3972 // Check if this ia a physics event (code 7)
3973 Int_t ntrk = fesd->GetNumberOfTracks();
3974 for (Int_t itrk=0; itrk<ntrk; ++itrk) {
3975
3976 AliESDtrack * trk = fesd->GetTrack(itrk);
3977 if (trk
3978 && trk->Pt() > pTmin
3979 && trk->Pt() < pTmax
3980 && (trk->GetStatus() & mask) == mask ) {
3981
3982 isOK = kTRUE;
3983 break;
3984 }
a307e234 3985 if (trk
3986 && trk->GetInnerParam()
3987 && trk->GetInnerParam()->Pt() > pTminCosmic
3988 && trk->GetInnerParam()->Pt() < pTmaxCosmic
3989 && (trk->GetStatus() & maskCosmic) == maskCosmic ) {
3990
d0fc0a32 3991 cosmicCount++;
a307e234 3992 break;
3993 }
f00558b6 3994 }
d0fc0a32 3995 if (cosmicCount>1) isOK=kTRUE;
f00558b6 3996 }
3997 return isOK;
3998}
3999
4000//______________________________________________________________________________
4001Bool_t AliReconstruction::IsCosmicOrCalibSpecie() const {
4002 // Select cosmic or calibration events
4003
4004 Bool_t isOK = kFALSE;
4005
4006 if (fesd && fesd->GetEventType()==AliRawEventHeaderBase::kPhysicsEvent) {
4007 // Check if this ia a physics event (code 7)
4008
4009 UInt_t specie = fesd->GetEventSpecie();
4010 if (specie==AliRecoParam::kCosmic || specie==AliRecoParam::kCalib) {
4011 isOK = kTRUE;
4012 }
4013 }
4014 return isOK;
4015}
4016
4017//______________________________________________________________________________
4018void AliReconstruction::WriteESDfriend() {
4019 // Fill the ESD friend in the tree. The required fraction of ESD friends is stored
4020 // in fFractionFriends. We select events where we store the ESD friends according
4021 // to the following algorithm:
4022 // 1. Store all Cosmic or Calibration events within the required fraction
4023 // 2. Sample "high Pt" events within the remaining fraction after step 1.
4024 // 3. Sample randomly events if we still have remaining slot
4025
4026 fNall++;
f00558b6 4027 Bool_t isSelected = kFALSE;
d0fc0a32 4028 //
4029 // Store all friends for B field OFF
4030 if (TMath::Abs(AliTrackerBase::GetBz())<0.5) isSelected=kTRUE;
f00558b6 4031
4032 if (IsCosmicOrCalibSpecie()) { // Selection of calib or cosmic events
4033 fNspecie++;
4034 Double_t curentSpecieFraction = ((Double_t)(fNspecie+1))/((Double_t)(fNall+1));
4035 // "Bayesian" estimate supposing that without events all the events are of the required type
4036
4037 Double_t rnd = gRandom->Rndm()*curentSpecieFraction;
4038 if (rnd<fFractionFriends) {
4039 isSelected = kTRUE;
4040 fSspecie++;
4041 }
4042 }
4043
4044 Double_t remainingFraction = fFractionFriends;
4045 remainingFraction -= ((Double_t)(fSspecie)/(Double_t)(fNall));
4046
4047 if (IsHighPt()) { // Selection of "high Pt" events
4048 fNhighPt++;
4049 Double_t curentHighPtFraction = ((Double_t)(fNhighPt+1))/((Double_t)(fNall+1));
4050 // "Bayesian" estimate supposing that without events all the events are of the required type
4051
4052 if (!isSelected) {
4053 Double_t rnd = gRandom->Rndm()*curentHighPtFraction;
4054 if (rnd<remainingFraction) {
4055 isSelected = kTRUE;
4056 fShighPt++;
4057 }
4058 }
4059 }
4060 remainingFraction -= ((Double_t)(fShighPt)/(Double_t)(fNall));
4061
4062 // Random selection to fill the remaining fraction (if any)
4063 if (!isSelected) {
4064 Double_t rnd = gRandom->Rndm();
4065 if (rnd<remainingFraction) {
4066 isSelected = kTRUE;
4067 }
4068 }
4069
4070 if (!isSelected) {
4071 fesdf->~AliESDfriend();
4072 new (fesdf) AliESDfriend(); // Reset...
4073 fesdf->SetSkipBit(kTRUE);
4074 }
4075
4076 ftreeF->Fill();
4077}