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