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