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