handling of steering events
[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
b8bd1ab8 1559 if (fRunQA) {
1560 if (fRunGlobalQA) {
1561 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1562 if (qadm && fQATasks.Contains(Form("%d", AliQA::kESDS)))
1563 qadm->Exec(AliQA::kESDS, fesd);
1564 }
1565 }
854c6476 1566
1d99986f 1567 if (fWriteESDfriend) {
21a3aa09 1568 fesdf->~AliESDfriend();
1569 new (fesdf) AliESDfriend(); // Reset...
1570 fesd->GetESDfriend(fesdf);
1d99986f 1571 }
21a3aa09 1572 ftree->Fill();
500d54ab 1573
2d91a353 1574 // Auto-save the ESD tree in case of prompt reco @P2
1575 if (fRawReader && fRawReader->UseAutoSaveESD())
1576 ftree->AutoSave("SaveSelf");
1577
500d54ab 1578 // write HLT ESD
21a3aa09 1579 fhlttree->Fill();
1d99986f 1580
14dd053c 1581 // call AliEVE
1582 if (fRunAliEVE) RunAliEVE();
1583
21a3aa09 1584 fesd->Reset();
1585 fhltesd->Reset();
5728d3d5 1586 if (fWriteESDfriend) {
21a3aa09 1587 fesdf->~AliESDfriend();
1588 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 1589 }
a5fa6165 1590
21a3aa09 1591 ProcInfo_t ProcInfo;
95cee32f 1592 gSystem->GetProcInfo(&ProcInfo);
1593 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
a5fa6165 1594
7e963665 1595
ce43afbe 1596 // End of cycle for the in-loop
ca13fb87 1597 if (fInLoopQA && fRunQA) {
e84c88f5 1598 fQASteer->RunOneEvent(fesd) ;
1599 fQASteer->EndOfCycle() ;
1600 }
ca13fb87 1601 if (fRunGlobalQA) {
1602 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1603 if (qadm) {
e84c88f5 1604 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1605 qadm->EndOfCycle(AliQA::kRECPOINTS);
1606 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1607 qadm->EndOfCycle(AliQA::kESDS);
1608 qadm->Finish();
ca13fb87 1609 }
1610 }
7e88424f 1611
ca13fb87 1612 fEventInfo.Reset();
1613 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1614 if (fReconstructor[iDet])
e84c88f5 1615 fReconstructor[iDet]->SetRecoParam(NULL);
ca13fb87 1616 }
1617
1618 return kTRUE;
21a3aa09 1619}
1620
1621//_____________________________________________________________________________
4b71572b 1622void AliReconstruction::SlaveTerminate()
21a3aa09 1623{
4b71572b 1624 // Finalize the run on the slave side
21a3aa09 1625 // Called after the exit
1626 // from the event loop
1627 AliCodeTimerAuto("");
1628
1629 if (fIsNewRunLoader) { // galice.root didn't exist
1630 fRunLoader->WriteHeader("OVERWRITE");
1631 fRunLoader->CdGAFile();
1632 fRunLoader->Write(0, TObject::kOverwrite);
1633 }
1634
1635 ftree->GetUserInfo()->Add(fesd);
1636 fhlttree->GetUserInfo()->Add(fhltesd);
f747912b 1637
1638 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1639 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1640
1641 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1642 cdbMapCopy->SetOwner(1);
1643 cdbMapCopy->SetName("cdbMap");
1644 TIter iter(cdbMap->GetTable());
1645
1646 TPair* pair = 0;
1647 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1648 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1649 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1650 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1651 }
1652
1653 TList *cdbListCopy = new TList();
1654 cdbListCopy->SetOwner(1);
1655 cdbListCopy->SetName("cdbList");
1656
1657 TIter iter2(cdbList);
1658
b940cb9b 1659 AliCDBId* id=0;
e84c88f5 1660 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 1661 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 1662 }
1663
21a3aa09 1664 ftree->GetUserInfo()->Add(cdbMapCopy);
1665 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 1666
46698ae4 1667
1668 if(fESDPar.Contains("ESD.par")){
1669 AliInfo("Attaching ESD.par to Tree");
1670 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
21a3aa09 1671 ftree->GetUserInfo()->Add(fn);
596a855f 1672 }
1673
46698ae4 1674
21a3aa09 1675 ffile->cd();
aa3c69a9 1676
a9c0e6db 1677 if (fWriteESDfriend)
21a3aa09 1678 ftree->SetBranchStatus("ESDfriend*",0);
562dd0b4 1679 // we want to have only one tree version number
21a3aa09 1680 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1681 fhlttree->Write();
f3a97c86 1682
a7a1e1c7 1683// Finish with Plane Efficiency evaluation: before of CleanUp !!!
1684 if (fRunPlaneEff && !FinishPlaneEff()) {
1685 AliWarning("Finish PlaneEff evaluation failed");
1686 }
1687
4b71572b 1688 //Finish QA and end of cycle for out-of-loop QA
1689 if (!fInLoopQA && fRunQA)
1690 fQASteer->Run(fRunLocalReconstruction.Data(), AliQA::kNULLTASKINDEX, fSameQACycle) ;
1691 if (!fInLoopQA && fRunGlobalQA) {
1692 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1693 if (qadm) {
1694 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1695 qadm->EndOfCycle(AliQA::kRECPOINTS);
1696 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1697 qadm->EndOfCycle(AliQA::kESDS);
1698 qadm->Finish();
1699 }
a7807689 1700 }
1701
4b71572b 1702 gROOT->cd();
1703 CleanUp();
1704}
1705
1706//_____________________________________________________________________________
1707void AliReconstruction::Terminate()
1708{
f3a97c86 1709 // Create tags for the events in the ESD tree (the ESD tree is always present)
1710 // In case of empty events the tags will contain dummy values
4b71572b 1711 AliCodeTimerAuto("");
1712
08e1a23e 1713 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
6b6e4472 1714 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData);
e84c88f5 1715
795e4a22 1716 // Cleanup of CDB manager: cache and active storages!
1717 AliCDBManager::Instance()->ClearCache();
596a855f 1718}
1719
1720//_____________________________________________________________________________
b26c3770 1721Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1722{
1723// run the local reconstruction
aa3c69a9 1724
0f88822a 1725 static Int_t eventNr=0;
87932dab 1726 AliCodeTimerAuto("")
b26c3770 1727
1728 TString detStr = detectors;
1729 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1730 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1731 AliReconstructor* reconstructor = GetReconstructor(iDet);
1732 if (!reconstructor) continue;
1733 AliLoader* loader = fLoader[iDet];
f6806ad3 1734 // Matthias April 2008: temporary fix to run HLT reconstruction
1735 // although the HLT loader is missing
1736 if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
1737 if (fRawReader) {
1738 reconstructor->Reconstruct(fRawReader, NULL);
1739 } else {
1740 TTree* dummy=NULL;
1741 reconstructor->Reconstruct(dummy, NULL);
1742 }
1743 continue;
1744 }
d76c31f4 1745 if (!loader) {
1746 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1747 continue;
1748 }
b26c3770 1749 // conversion of digits
1750 if (fRawReader && reconstructor->HasDigitConversion()) {
1751 AliInfo(Form("converting raw data digits into root objects for %s",
1752 fgkDetectorName[iDet]));
30bbd491 1753// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1754// fgkDetectorName[iDet]));
b26c3770 1755 loader->LoadDigits("update");
1756 loader->CleanDigits();
1757 loader->MakeDigitsContainer();
1758 TTree* digitsTree = loader->TreeD();
1759 reconstructor->ConvertDigits(fRawReader, digitsTree);
1760 loader->WriteDigits("OVERWRITE");
1761 loader->UnloadDigits();
b26c3770 1762 }
b26c3770 1763 // local reconstruction
b26c3770 1764 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
30bbd491 1765 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
b26c3770 1766 loader->LoadRecPoints("update");
1767 loader->CleanRecPoints();
1768 loader->MakeRecPointsContainer();
1769 TTree* clustersTree = loader->TreeR();
1770 if (fRawReader && !reconstructor->HasDigitConversion()) {
1771 reconstructor->Reconstruct(fRawReader, clustersTree);
1772 } else {
1773 loader->LoadDigits("read");
1774 TTree* digitsTree = loader->TreeD();
1775 if (!digitsTree) {
1776 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1777 if (fStopOnError) return kFALSE;
1778 } else {
1779 reconstructor->Reconstruct(digitsTree, clustersTree);
1780 }
1781 loader->UnloadDigits();
1782 }
d76c31f4 1783
aa3c69a9 1784 // In-loop QA for local reconstrucion
30bbd491 1785 TString detQAStr(fQADetectors) ;
e84c88f5 1786 if (fRunQA && fInLoopQA)
1787 fQASteer->RunOneEventInOneDetector(iDet, clustersTree) ;
1788
1789 loader->WriteRecPoints("OVERWRITE");
1790 loader->UnloadRecPoints();
1791 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
1792 }
1793 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
b26c3770 1794 AliError(Form("the following detectors were not found: %s",
1795 detStr.Data()));
1796 if (fStopOnError) return kFALSE;
1797 }
0f88822a 1798 eventNr++;
b26c3770 1799 return kTRUE;
1800}
1801
1802//_____________________________________________________________________________
af885e0f 1803Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 1804{
1805// run the barrel tracking
1806
87932dab 1807 AliCodeTimerAuto("")
030b532d 1808
2257f27e 1809 AliESDVertex* vertex = NULL;
1810 Double_t vtxPos[3] = {0, 0, 0};
1811 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1812 TArrayF mcVertex(3);
a6b0b91b 1813 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1814 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1815 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1816 }
2257f27e 1817
b8cd5251 1818 if (fVertexer) {
815c2b38 1819 AliInfo("running the ITS vertex finder");
308c2f7c 1820 if (fLoader[0]) {
1821 fLoader[0]->LoadRecPoints();
1822 TTree* cltree = fLoader[0]->TreeR();
1823 if (cltree) {
1824 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1825 vertex = fVertexer->FindVertexForCurrentEvent(cltree);
1826 }
1827 else {
1828 AliError("Can't get the ITS cluster tree");
1829 }
1830 fLoader[0]->UnloadRecPoints();
1831 }
1832 else {
1833 AliError("Can't get the ITS loader");
1834 }
2257f27e 1835 if(!vertex){
815c2b38 1836 AliWarning("Vertex not found");
c710f220 1837 vertex = new AliESDVertex();
d1a50cb5 1838 vertex->SetName("default");
2257f27e 1839 }
1840 else {
d1a50cb5 1841 vertex->SetName("reconstructed");
2257f27e 1842 }
1843
1844 } else {
815c2b38 1845 AliInfo("getting the primary vertex from MC");
2257f27e 1846 vertex = new AliESDVertex(vtxPos, vtxErr);
1847 }
1848
1849 if (vertex) {
1850 vertex->GetXYZ(vtxPos);
1851 vertex->GetSigmaXYZ(vtxErr);
1852 } else {
815c2b38 1853 AliWarning("no vertex reconstructed");
2257f27e 1854 vertex = new AliESDVertex(vtxPos, vtxErr);
1855 }
06cc9d95 1856 esd->SetPrimaryVertexSPD(vertex);
32e449be 1857 // if SPD multiplicity has been determined, it is stored in the ESD
25be1e5c 1858 AliMultiplicity *mult = fVertexer->GetMultiplicity();
32e449be 1859 if(mult)esd->SetMultiplicity(mult);
1860
b8cd5251 1861 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1862 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1863 }
2257f27e 1864 delete vertex;
1865
2257f27e 1866 return kTRUE;
1867}
1868
1869//_____________________________________________________________________________
af885e0f 1870Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 1871{
1872// run the HLT barrel tracking
1873
87932dab 1874 AliCodeTimerAuto("")
1f46a9ae 1875
1876 if (!fRunLoader) {
1877 AliError("Missing runLoader!");
1878 return kFALSE;
1879 }
1880
1881 AliInfo("running HLT tracking");
1882
1883 // Get a pointer to the HLT reconstructor
1884 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1885 if (!reconstructor) return kFALSE;
1886
1887 // TPC + ITS
1888 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1889 TString detName = fgkDetectorName[iDet];
1890 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1891 reconstructor->SetOption(detName.Data());
d76c31f4 1892 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 1893 if (!tracker) {
1894 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1895 if (fStopOnError) return kFALSE;
9dcc06e1 1896 continue;
1f46a9ae 1897 }
1898 Double_t vtxPos[3];
1899 Double_t vtxErr[3]={0.005,0.005,0.010};
1900 const AliESDVertex *vertex = esd->GetVertex();
1901 vertex->GetXYZ(vtxPos);
1902 tracker->SetVertex(vtxPos,vtxErr);
1903 if(iDet != 1) {
1904 fLoader[iDet]->LoadRecPoints("read");
1905 TTree* tree = fLoader[iDet]->TreeR();
1906 if (!tree) {
1907 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1908 return kFALSE;
1909 }
1910 tracker->LoadClusters(tree);
1911 }
1912 if (tracker->Clusters2Tracks(esd) != 0) {
1913 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1914 return kFALSE;
1915 }
1916 if(iDet != 1) {
1917 tracker->UnloadClusters();
1918 }
1919 delete tracker;
1920 }
1921
1f46a9ae 1922 return kTRUE;
1923}
1924
1925//_____________________________________________________________________________
af885e0f 1926Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 1927{
1928// run the muon spectrometer tracking
1929
87932dab 1930 AliCodeTimerAuto("")
e66fbafb 1931
1932 if (!fRunLoader) {
1933 AliError("Missing runLoader!");
1934 return kFALSE;
1935 }
1936 Int_t iDet = 7; // for MUON
1937
1938 AliInfo("is running...");
1939
1940 // Get a pointer to the MUON reconstructor
1941 AliReconstructor *reconstructor = GetReconstructor(iDet);
1942 if (!reconstructor) return kFALSE;
1943
1944
1945 TString detName = fgkDetectorName[iDet];
1946 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 1947 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 1948 if (!tracker) {
1949 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1950 return kFALSE;
1951 }
1952
e66fbafb 1953 // read RecPoints
761350a6 1954 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 1955
761350a6 1956 tracker->LoadClusters(fLoader[iDet]->TreeR());
1957
1958 Int_t rv = tracker->Clusters2Tracks(esd);
1959
761350a6 1960 if ( rv )
1961 {
e66fbafb 1962 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1963 return kFALSE;
1964 }
761350a6 1965
e66fbafb 1966 fLoader[iDet]->UnloadRecPoints();
1967
c1954ee5 1968 tracker->UnloadClusters();
1969
e66fbafb 1970 delete tracker;
1971
e66fbafb 1972 return kTRUE;
1973}
1974
1975
1976//_____________________________________________________________________________
af885e0f 1977Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
2257f27e 1978{
1979// run the barrel tracking
0f88822a 1980 static Int_t eventNr=0;
87932dab 1981 AliCodeTimerAuto("")
24f7a148 1982
815c2b38 1983 AliInfo("running tracking");
596a855f 1984
91b876d1 1985 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 1986 if (fReconstructor[11] && fLoader[11]) {
1987 fLoader[11]->LoadRecPoints("READ");
1988 TTree *treeR = fLoader[11]->TreeR();
1989 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1990 }
91b876d1 1991
b8cd5251 1992 // pass 1: TPC + ITS inwards
1993 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1994 if (!fTracker[iDet]) continue;
1995 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 1996
b8cd5251 1997 // load clusters
1998 fLoader[iDet]->LoadRecPoints("read");
6efecea1 1999 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 2000 TTree* tree = fLoader[iDet]->TreeR();
2001 if (!tree) {
2002 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2003 return kFALSE;
2004 }
b8cd5251 2005 fTracker[iDet]->LoadClusters(tree);
6efecea1 2006 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2007 // run tracking
2008 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
2009 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 2010 return kFALSE;
2011 }
878e1fe1 2012 // preliminary PID in TPC needed by the ITS tracker
2013 if (iDet == 1) {
b26c3770 2014 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
878e1fe1 2015 AliESDpid::MakePID(esd);
0f88822a 2016 }
6efecea1 2017 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 2018 }
596a855f 2019
b8cd5251 2020 // pass 2: ALL backwards
aa3c69a9 2021
b8cd5251 2022 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2023 if (!fTracker[iDet]) continue;
2024 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
2025
2026 // load clusters
2027 if (iDet > 1) { // all except ITS, TPC
2028 TTree* tree = NULL;
7b61cd9c 2029 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2030 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 2031 tree = fLoader[iDet]->TreeR();
b8cd5251 2032 if (!tree) {
2033 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2034 return kFALSE;
2035 }
0f88822a 2036 fTracker[iDet]->LoadClusters(tree);
6efecea1 2037 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2038 }
24f7a148 2039
b8cd5251 2040 // run tracking
283f39c6 2041 if (iDet>1) // start filling residuals for the "outer" detectors
2042 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
2043
b8cd5251 2044 if (fTracker[iDet]->PropagateBack(esd) != 0) {
2045 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 2046 // return kFALSE;
b8cd5251 2047 }
24f7a148 2048
b8cd5251 2049 // unload clusters
6e65648b 2050 if (iDet > 3) { // all except ITS, TPC, TRD and TOF
b8cd5251 2051 fTracker[iDet]->UnloadClusters();
7b61cd9c 2052 fLoader[iDet]->UnloadRecPoints();
b8cd5251 2053 }
8f37df88 2054 // updated PID in TPC needed by the ITS tracker -MI
2055 if (iDet == 1) {
8f37df88 2056 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
2057 AliESDpid::MakePID(esd);
2058 }
6efecea1 2059 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 2060 }
283f39c6 2061 //stop filling residuals for the "outer" detectors
2062 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
596a855f 2063
b8cd5251 2064 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 2065
b8cd5251 2066 for (Int_t iDet = 2; iDet >= 0; iDet--) {
2067 if (!fTracker[iDet]) continue;
2068 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 2069
b8cd5251 2070 // run tracking
283f39c6 2071 if (iDet<2) // start filling residuals for TPC and ITS
2072 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
2073
b8cd5251 2074 if (fTracker[iDet]->RefitInward(esd) != 0) {
2075 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 2076 // return kFALSE;
b8cd5251 2077 }
db2368d0 2078 // run postprocessing
2079 if (fTracker[iDet]->PostProcess(esd) != 0) {
2080 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
2081 // return kFALSE;
2082 }
6efecea1 2083 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
6e65648b 2084 }
2085
2086 // write space-points to the ESD in case alignment data output
2087 // is switched on
2088 if (fWriteAlignmentData)
2089 WriteAlignmentData(esd);
2090
2091 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2092 if (!fTracker[iDet]) continue;
b8cd5251 2093 // unload clusters
2094 fTracker[iDet]->UnloadClusters();
6efecea1 2095 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 2096 fLoader[iDet]->UnloadRecPoints();
6efecea1 2097 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 2098 }
283f39c6 2099 // stop filling residuals for TPC and ITS
3b378a42 2100 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
854c6476 2101
0f88822a 2102 eventNr++;
596a855f 2103 return kTRUE;
2104}
2105
2106//_____________________________________________________________________________
d64bd07d 2107Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
2108 //
2109 // Remove the data which are not needed for the physics analysis.
2110 //
2111
d64bd07d 2112 Int_t nTracks=esd->GetNumberOfTracks();
18571674 2113 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 2114 AliInfo
2115 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 2116
18571674 2117 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 2118 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 2119
7f68891d 2120 nTracks=esd->GetNumberOfTracks();
18571674 2121 nV0s=esd->GetNumberOfV0s();
cf37fd88 2122 AliInfo
ae5d5566 2123 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 2124
7f68891d 2125 return rc;
d64bd07d 2126}
2127
2128//_____________________________________________________________________________
af885e0f 2129Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 2130{
2131// fill the event summary data
2132
87932dab 2133 AliCodeTimerAuto("")
0f88822a 2134 static Int_t eventNr=0;
596a855f 2135 TString detStr = detectors;
abe0c04e 2136
b8cd5251 2137 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
abe0c04e 2138 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 2139 AliReconstructor* reconstructor = GetReconstructor(iDet);
2140 if (!reconstructor) continue;
4b71572b 2141 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
2142 TTree* clustersTree = NULL;
2143 if (fLoader[iDet]) {
2144 fLoader[iDet]->LoadRecPoints("read");
2145 clustersTree = fLoader[iDet]->TreeR();
2146 if (!clustersTree) {
2147 AliError(Form("Can't get the %s clusters tree",
2148 fgkDetectorName[iDet]));
2149 if (fStopOnError) return kFALSE;
2150 }
2151 }
2152 if (fRawReader && !reconstructor->HasDigitConversion()) {
2153 reconstructor->FillESD(fRawReader, clustersTree, esd);
2154 } else {
2155 TTree* digitsTree = NULL;
d76c31f4 2156 if (fLoader[iDet]) {
4b71572b 2157 fLoader[iDet]->LoadDigits("read");
2158 digitsTree = fLoader[iDet]->TreeD();
2159 if (!digitsTree) {
2160 AliError(Form("Can't get the %s digits tree",
b26c3770 2161 fgkDetectorName[iDet]));
2162 if (fStopOnError) return kFALSE;
2163 }
2164 }
4b71572b 2165 reconstructor->FillESD(digitsTree, clustersTree, esd);
2166 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
2167 }
2168 if (fLoader[iDet]) {
2169 fLoader[iDet]->UnloadRecPoints();
596a855f 2170 }
2171 }
2172
2173 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 2174 AliError(Form("the following detectors were not found: %s",
2175 detStr.Data()));
596a855f 2176 if (fStopOnError) return kFALSE;
2177 }
6efecea1 2178 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
0f88822a 2179 eventNr++;
596a855f 2180 return kTRUE;
2181}
2182
b647652d 2183//_____________________________________________________________________________
af885e0f 2184Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 2185{
2186 // Reads the trigger decision which is
2187 // stored in Trigger.root file and fills
2188 // the corresponding esd entries
2189
87932dab 2190 AliCodeTimerAuto("")
2191
b647652d 2192 AliInfo("Filling trigger information into the ESD");
2193
2194 if (fRawReader) {
2195 AliCTPRawStream input(fRawReader);
2196 if (!input.Next()) {
7e88424f 2197 AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
b647652d 2198 }
2199 else {
7e88424f 2200 if (esd->GetTriggerMask() != input.GetClassMask())
2201 AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
2202 input.GetClassMask(),esd->GetTriggerMask()));
2203 if (esd->GetOrbitNumber() != input.GetOrbitID())
2204 AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
2205 input.GetOrbitID(),esd->GetOrbitNumber()));
2206 if (esd->GetBunchCrossNumber() != input.GetBCID())
2207 AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
2208 input.GetBCID(),esd->GetBunchCrossNumber()));
b647652d 2209 }
b024fd7f 2210
7e88424f 2211 // Here one has to add the filling of trigger inputs and
2212 // interaction records
2213 // ...
b024fd7f 2214 }
b647652d 2215 return kTRUE;
2216}
596a855f 2217
001397cd 2218
2219
2220
2221
2222//_____________________________________________________________________________
af885e0f 2223Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 2224{
2225 //
2226 // Filling information from RawReader Header
2227 //
2228
151bea4e 2229 if (!fRawReader) return kFALSE;
2230
001397cd 2231 AliInfo("Filling information from RawReader Header");
151bea4e 2232
2233 esd->SetBunchCrossNumber(fRawReader->GetBCID());
2234 esd->SetOrbitNumber(fRawReader->GetOrbitID());
2235 esd->SetPeriodNumber(fRawReader->GetPeriod());
2236
2237 esd->SetTimeStamp(fRawReader->GetTimestamp());
2238 esd->SetEventType(fRawReader->GetType());
001397cd 2239
2240 return kTRUE;
2241}
2242
2243
596a855f 2244//_____________________________________________________________________________
2245Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
2246{
2247// check whether detName is contained in detectors
2248// if yes, it is removed from detectors
2249
2250 // check if all detectors are selected
2251 if ((detectors.CompareTo("ALL") == 0) ||
2252 detectors.BeginsWith("ALL ") ||
2253 detectors.EndsWith(" ALL") ||
2254 detectors.Contains(" ALL ")) {
2255 detectors = "ALL";
2256 return kTRUE;
2257 }
2258
2259 // search for the given detector
2260 Bool_t result = kFALSE;
2261 if ((detectors.CompareTo(detName) == 0) ||
2262 detectors.BeginsWith(detName+" ") ||
2263 detectors.EndsWith(" "+detName) ||
2264 detectors.Contains(" "+detName+" ")) {
2265 detectors.ReplaceAll(detName, "");
2266 result = kTRUE;
2267 }
2268
2269 // clean up the detectors string
2270 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2271 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2272 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2273
2274 return result;
2275}
e583c30d 2276
2277//_____________________________________________________________________________
f08fc9f5 2278Bool_t AliReconstruction::InitRunLoader()
2279{
2280// get or create the run loader
2281
2282 if (gAlice) delete gAlice;
2283 gAlice = NULL;
2284
b26c3770 2285 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2286 // load all base libraries to get the loader classes
2287 TString libs = gSystem->GetLibraries();
2288 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2289 TString detName = fgkDetectorName[iDet];
2290 if (detName == "HLT") continue;
2291 if (libs.Contains("lib" + detName + "base.so")) continue;
2292 gSystem->Load("lib" + detName + "base.so");
2293 }
f08fc9f5 2294 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2295 if (!fRunLoader) {
2296 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2297 CleanUp();
2298 return kFALSE;
2299 }
325aa76f 2300
b26c3770 2301 fRunLoader->CdGAFile();
325aa76f 2302 fRunLoader->LoadgAlice();
f08fc9f5 2303
6cae184e 2304 //PH This is a temporary fix to give access to the kinematics
2305 //PH that is needed for the labels of ITS clusters
f2ee4290 2306 fRunLoader->LoadHeader();
6cae184e 2307 fRunLoader->LoadKinematics();
2308
f08fc9f5 2309 } else { // galice.root does not exist
2310 if (!fRawReader) {
2311 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
f08fc9f5 2312 }
2313 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2314 AliConfig::GetDefaultEventFolderName(),
2315 "recreate");
2316 if (!fRunLoader) {
2317 AliError(Form("could not create run loader in file %s",
2318 fGAliceFileName.Data()));
2319 CleanUp();
2320 return kFALSE;
2321 }
21a3aa09 2322 fIsNewRunLoader = kTRUE;
f08fc9f5 2323 fRunLoader->MakeTree("E");
21a3aa09 2324
973388c2 2325 if (fNumberOfEventsPerFile > 0)
2326 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2327 else
21a3aa09 2328 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 2329 }
2330
2331 return kTRUE;
2332}
2333
2334//_____________________________________________________________________________
b8cd5251 2335AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 2336{
f08fc9f5 2337// get the reconstructor object and the loader for a detector
c757bafd 2338
7e88424f 2339 if (fReconstructor[iDet]) {
2340 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2341 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2342 fReconstructor[iDet]->SetRecoParam(par);
2343 }
2344 return fReconstructor[iDet];
2345 }
b8cd5251 2346
2347 // load the reconstructor object
2348 TPluginManager* pluginManager = gROOT->GetPluginManager();
2349 TString detName = fgkDetectorName[iDet];
2350 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 2351
2352 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 2353
b8cd5251 2354 AliReconstructor* reconstructor = NULL;
2355 // first check if a plugin is defined for the reconstructor
2356 TPluginHandler* pluginHandler =
2357 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 2358 // if not, add a plugin for it
2359 if (!pluginHandler) {
b8cd5251 2360 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 2361 TString libs = gSystem->GetLibraries();
2362 if (libs.Contains("lib" + detName + "base.so") ||
2363 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 2364 pluginManager->AddHandler("AliReconstructor", detName,
2365 recName, detName + "rec", recName + "()");
2366 } else {
2367 pluginManager->AddHandler("AliReconstructor", detName,
2368 recName, detName, recName + "()");
c757bafd 2369 }
b8cd5251 2370 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2371 }
2372 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2373 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 2374 }
b8cd5251 2375 if (reconstructor) {
2376 TObject* obj = fOptions.FindObject(detName.Data());
2377 if (obj) reconstructor->SetOption(obj->GetTitle());
d76c31f4 2378 reconstructor->Init();
b8cd5251 2379 fReconstructor[iDet] = reconstructor;
2380 }
2381
f08fc9f5 2382 // get or create the loader
2383 if (detName != "HLT") {
2384 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2385 if (!fLoader[iDet]) {
2386 AliConfig::Instance()
2387 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2388 detName, detName);
2389 // first check if a plugin is defined for the loader
bb0901a4 2390 pluginHandler =
f08fc9f5 2391 pluginManager->FindHandler("AliLoader", detName);
2392 // if not, add a plugin for it
2393 if (!pluginHandler) {
2394 TString loaderName = "Ali" + detName + "Loader";
2395 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2396 pluginManager->AddHandler("AliLoader", detName,
2397 loaderName, detName + "base",
2398 loaderName + "(const char*, TFolder*)");
2399 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2400 }
2401 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2402 fLoader[iDet] =
2403 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2404 fRunLoader->GetEventFolder());
2405 }
2406 if (!fLoader[iDet]) { // use default loader
2407 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2408 }
2409 if (!fLoader[iDet]) {
2410 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 2411 if (fStopOnError) return NULL;
f08fc9f5 2412 } else {
2413 fRunLoader->AddLoader(fLoader[iDet]);
2414 fRunLoader->CdGAFile();
2415 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2416 fRunLoader->Write(0, TObject::kOverwrite);
2417 }
2418 }
2419 }
2420
7e88424f 2421 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2422 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2423 reconstructor->SetRecoParam(par);
2424 }
b8cd5251 2425 return reconstructor;
c757bafd 2426}
2427
2428//_____________________________________________________________________________
2257f27e 2429Bool_t AliReconstruction::CreateVertexer()
2430{
2431// create the vertexer
2432
b8cd5251 2433 fVertexer = NULL;
2434 AliReconstructor* itsReconstructor = GetReconstructor(0);
59697224 2435 if (itsReconstructor) {
d76c31f4 2436 fVertexer = itsReconstructor->CreateVertexer();
2257f27e 2437 }
b8cd5251 2438 if (!fVertexer) {
815c2b38 2439 AliWarning("couldn't create a vertexer for ITS");
2257f27e 2440 if (fStopOnError) return kFALSE;
2441 }
2442
2443 return kTRUE;
2444}
2445
2446//_____________________________________________________________________________
b8cd5251 2447Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 2448{
f08fc9f5 2449// create the trackers
24f7a148 2450
b8cd5251 2451 TString detStr = detectors;
2452 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2453 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2454 AliReconstructor* reconstructor = GetReconstructor(iDet);
2455 if (!reconstructor) continue;
2456 TString detName = fgkDetectorName[iDet];
1f46a9ae 2457 if (detName == "HLT") {
2458 fRunHLTTracking = kTRUE;
2459 continue;
2460 }
e66fbafb 2461 if (detName == "MUON") {
2462 fRunMuonTracking = kTRUE;
2463 continue;
2464 }
2465
f08fc9f5 2466
d76c31f4 2467 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 2468 if (!fTracker[iDet] && (iDet < 7)) {
2469 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 2470 if (fStopOnError) return kFALSE;
2471 }
6efecea1 2472 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 2473 }
2474
24f7a148 2475 return kTRUE;
2476}
2477
2478//_____________________________________________________________________________
4b71572b 2479void AliReconstruction::CleanUp()
e583c30d 2480{
2481// delete trackers and the run loader and close and delete the file
2482
b8cd5251 2483 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2484 delete fReconstructor[iDet];
2485 fReconstructor[iDet] = NULL;
2486 fLoader[iDet] = NULL;
2487 delete fTracker[iDet];
2488 fTracker[iDet] = NULL;
2489 }
4b71572b 2490 delete fRunInfo;
7e88424f 2491 fRunInfo = NULL;
2492
b8cd5251 2493 delete fVertexer;
2494 fVertexer = NULL;
21a3aa09 2495
4b71572b 2496 delete ftVertexer;
21a3aa09 2497 ftVertexer = NULL;
795e4a22 2498
2499 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
4b71572b 2500 delete fDiamondProfile;
2501 fDiamondProfile = NULL;
2502 delete fDiamondProfileTPC;
2503 fDiamondProfileTPC = NULL;
795e4a22 2504 }
4b71572b 2505 delete fGRPData;
2506 fGRPData = NULL;
444753c6 2507
e583c30d 2508 delete fRunLoader;
2509 fRunLoader = NULL;
b649205a 2510 delete fRawReader;
2511 fRawReader = NULL;
4b71572b 2512 delete fParentRawReader;
cd0b062e 2513 fParentRawReader=NULL;
e583c30d 2514
4b71572b 2515 if (ffile) {
2516 ffile->Close();
2517 delete ffile;
2518 ffile = NULL;
24f7a148 2519 }
24f7a148 2520}
f3a97c86 2521
af885e0f 2522void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 2523{
2524 // Write space-points which are then used in the alignment procedures
6e65648b 2525 // For the moment only ITS, TPC, TRD and TOF
98937d93 2526
98937d93 2527 Int_t ntracks = esd->GetNumberOfTracks();
2528 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2529 {
2530 AliESDtrack *track = esd->GetTrack(itrack);
2531 Int_t nsp = 0;
ef7253ac 2532 Int_t idx[200];
6e65648b 2533 for (Int_t iDet = 3; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
2534 nsp += track->GetNcls(iDet);
2535
2536 if (iDet==0) { // ITS "extra" clusters
2537 track->GetClusters(iDet,idx);
2538 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
2539 }
2540 }
2541
98937d93 2542 if (nsp) {
2543 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2544 track->SetTrackPointArray(sp);
2545 Int_t isptrack = 0;
2546 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2547 AliTracker *tracker = fTracker[iDet];
2548 if (!tracker) continue;
6e65648b 2549 Int_t nspdet = track->GetClusters(iDet,idx);
2550
2551 if (iDet==0) // ITS "extra" clusters
2552 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
2553
98937d93 2554 if (nspdet <= 0) continue;
98937d93 2555 AliTrackPoint p;
2556 Int_t isp = 0;
2557 Int_t isp2 = 0;
4ed6fb1c 2558 while (isp2 < nspdet) {
f3c6e4c9 2559 Bool_t isvalid=kTRUE;
2560
2561 Int_t index=idx[isp++];
2562 if (index < 0) continue;
2563
c12b6e44 2564 TString dets = fgkDetectorName[iDet];
2565 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2566 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2567 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2568 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
f3c6e4c9 2569 isvalid = tracker->GetTrackPointTrackingError(index,p,track);
48ce48d1 2570 } else {
f3c6e4c9 2571 isvalid = tracker->GetTrackPoint(index,p);
48ce48d1 2572 }
2573 isp2++;
98937d93 2574 if (!isvalid) continue;
f3c6e4c9 2575 sp->AddPoint(isptrack,&p); isptrack++;
98937d93 2576 }
98937d93 2577 }
2578 }
2579 }
98937d93 2580}
2e3550da 2581
2582//_____________________________________________________________________________
af885e0f 2583void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 2584{
2585 // The method reads the raw-data error log
2586 // accumulated within the rawReader.
2587 // It extracts the raw-data errors related to
2588 // the current event and stores them into
2589 // a TClonesArray inside the esd object.
2590
2591 if (!fRawReader) return;
2592
2593 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2594
2595 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2596 if (!log) continue;
2597 if (iEvent != log->GetEventNumber()) continue;
2598
2599 esd->AddRawDataErrorLog(log);
2600 }
2601
2602}
46698ae4 2603
605cb8bb 2604TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString pName){
b545009a 2605 // Dump a file content into a char in TNamed
46698ae4 2606 ifstream in;
2607 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2608 Int_t kBytes = (Int_t)in.tellg();
2609 printf("Size: %d \n",kBytes);
2610 TNamed *fn = 0;
2611 if(in.good()){
2612 char* memblock = new char [kBytes];
2613 in.seekg (0, ios::beg);
2614 in.read (memblock, kBytes);
2615 in.close();
2616 TString fData(memblock,kBytes);
605cb8bb 2617 fn = new TNamed(pName,fData);
46698ae4 2618 printf("fData Size: %d \n",fData.Sizeof());
605cb8bb 2619 printf("pName Size: %d \n",pName.Sizeof());
46698ae4 2620 printf("fn Size: %d \n",fn->Sizeof());
2621 delete[] memblock;
2622 }
2623 else{
2624 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2625 }
2626
2627 return fn;
2628}
2629
605cb8bb 2630void AliReconstruction::TNamedToFile(TTree* fTree, TString pName){
46698ae4 2631 // This is not really needed in AliReconstruction at the moment
2632 // but can serve as a template
2633
2634 TList *fList = fTree->GetUserInfo();
605cb8bb 2635 TNamed *fn = (TNamed*)fList->FindObject(pName.Data());
46698ae4 2636 printf("fn Size: %d \n",fn->Sizeof());
2637
605cb8bb 2638 TString fTmp(fn->GetName()); // to be 100% sure in principle pName also works
46698ae4 2639 const char* cdata = fn->GetTitle();
2640 printf("fTmp Size %d\n",fTmp.Sizeof());
2641
2642 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2643 printf("calculated size %d\n",size);
605cb8bb 2644 ofstream out(pName.Data(),ios::out | ios::binary);
46698ae4 2645 out.write(cdata,size);
2646 out.close();
2647
2648}
6efecea1 2649
7e963665 2650//_____________________________________________________________________________
8661738e 2651void AliReconstruction::CheckQA()
2652{
2653// check the QA of SIM for this run and remove the detectors
2654// with status Fatal
2655
abe0c04e 2656 TString newRunLocalReconstruction ;
2657 TString newRunTracking ;
2658 TString newFillESD ;
2659
8661738e 2660 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2661 TString detName(AliQA::GetDetName(iDet)) ;
96d67a8d 2662 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2663 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
8661738e 2664 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
abe0c04e 2665 } else {
2666 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2667 fRunLocalReconstruction.Contains("ALL") ) {
2668 newRunLocalReconstruction += detName ;
2669 newRunLocalReconstruction += " " ;
2670 }
2671 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2672 fRunTracking.Contains("ALL") ) {
2673 newRunTracking += detName ;
2674 newRunTracking += " " ;
2675 }
2676 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2677 fFillESD.Contains("ALL") ) {
2678 newFillESD += detName ;
2679 newFillESD += " " ;
8661738e 2680 }
2681 }
2682 }
abe0c04e 2683 fRunLocalReconstruction = newRunLocalReconstruction ;
2684 fRunTracking = newRunTracking ;
2685 fFillESD = newFillESD ;
a5fa6165 2686}
5b188f2f 2687
2688//_____________________________________________________________________________
2689Int_t AliReconstruction::GetDetIndex(const char* detector)
2690{
2691 // return the detector index corresponding to detector
2692 Int_t index = -1 ;
2693 for (index = 0; index < fgkNDetectors ; index++) {
2694 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2695 break ;
2696 }
2697 return index ;
2698}
7167ae53 2699//_____________________________________________________________________________
2700Bool_t AliReconstruction::FinishPlaneEff() {
2701 //
2702 // Here execute all the necessary operationis, at the end of the tracking phase,
d7f8fd68 2703 // in case that evaluation of PlaneEfficiencies was required for some detector.
2704 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
7167ae53 2705 //
2706 // This Preliminary version works only FOR ITS !!!!!
2707 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2708 //
2709 // Input: none
d7f8fd68 2710 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
7167ae53 2711 //
2712 Bool_t ret=kFALSE;
2713 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
d7f8fd68 2714 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
7167ae53 2715 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
5fbd4fd6 2716 if(fTracker[iDet]) {
d7f8fd68 2717 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2718 TString name=planeeff->GetName();
2719 name+=".root";
2720 TFile* pefile = TFile::Open(name, "RECREATE");
2721 ret=(Bool_t)planeeff->Write();
2722 pefile->Close();
5fbd4fd6 2723 if(planeeff->GetCreateHistos()) {
d7f8fd68 2724 TString hname=planeeff->GetName();
2725 hname+="Histo.root";
2726 ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
5fbd4fd6 2727 }
2728 }
7167ae53 2729 }
2730 return ret;
2731}
2732//_____________________________________________________________________________
2733Bool_t AliReconstruction::InitPlaneEff() {
2734//
2735 // Here execute all the necessary operations, before of the tracking phase,
2736 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2737 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2738 // which should be updated/recalculated.
2739 //
2740 // This Preliminary version will work only FOR ITS !!!!!
2741 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2742 //
2743 // Input: none
2744 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2745 //
2746 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));
2747 return kTRUE;
7520312d 2748}
14dd053c 2749
2750//_____________________________________________________________________________
2751Bool_t AliReconstruction::InitAliEVE()
2752{
2753 // This method should be called only in case
2754 // AliReconstruction is run
2755 // within the alieve environment.
2756 // It will initialize AliEVE in a way
2757 // so that it can visualize event processed
2758 // by AliReconstruction.
2759 // The return flag shows whenever the
2760 // AliEVE initialization was successful or not.
2761
2762 TString macroStr;
2763 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
2764 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
2765 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
2766
de33999e 2767 gROOT->ProcessLine("if (!gAliEveEvent) {gAliEveEvent = new AliEveEventManager();gAliEveEvent->SetAutoLoad(kTRUE);gAliEveEvent->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(gAliEveEvent);};");
2768 gROOT->ProcessLine("alieve_online_init()");
14dd053c 2769
2770 return kTRUE;
2771}
2772
2773//_____________________________________________________________________________
2774void AliReconstruction::RunAliEVE()
2775{
2776 // Runs AliEVE visualisation of
2777 // the current event.
2778 // Should be executed only after
2779 // successful initialization of AliEVE.
2780
2781 AliInfo("Running AliEVE...");
2782 gROOT->ProcessLine(Form("gAliEveEvent->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p);",fRunLoader,fRawReader,fesd));
2783 gROOT->ProcessLine("gAliEveEvent->StartStopAutoLoadTimer();");
2784 gSystem->Run();
2785}
ce43afbe 2786
2787//_____________________________________________________________________________
2788Bool_t AliReconstruction::SetRunQA(TString detAndAction)
2789{
2790 // Allows to run QA for a selected set of detectors
2791 // and a selected set of tasks among RAWS, RECPOINTS and ESDS
2792 // all selected detectors run the same selected tasks
2793
2794 if (!detAndAction.Contains(":")) {
2795 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
2796 fRunQA = kFALSE ;
2797 return kFALSE ;
2798 }
2799 Int_t colon = detAndAction.Index(":") ;
2800 fQADetectors = detAndAction(0, colon) ;
2801 if (fQADetectors.Contains("ALL") )
2802 fQADetectors = fFillESD ;
e84c88f5 2803 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
ce43afbe 2804 if (fQATasks.Contains("ALL") ) {
2805 fQATasks = Form("%d %d %d", AliQA::kRAWS, AliQA::kRECPOINTS, AliQA::kESDS) ;
2806 } else {
2807 fQATasks.ToUpper() ;
2808 TString tempo("") ;
2809 if ( fQATasks.Contains("RAW") )
2810 tempo = Form("%d ", AliQA::kRAWS) ;
2811 if ( fQATasks.Contains("RECPOINT") )
2812 tempo += Form("%d ", AliQA::kRECPOINTS) ;
2813 if ( fQATasks.Contains("ESD") )
2814 tempo += Form("%d ", AliQA::kESDS) ;
2815 fQATasks = tempo ;
2816 if (fQATasks.IsNull()) {
2817 AliInfo("No QA requested\n") ;
2818 fRunQA = kFALSE ;
2819 return kTRUE ;
2820 }
2821 }
2822 TString tempo(fQATasks) ;
e84c88f5 2823 tempo.ReplaceAll(Form("%d", AliQA::kRAWS), AliQA::GetTaskName(AliQA::kRAWS)) ;
2824 tempo.ReplaceAll(Form("%d", AliQA::kRECPOINTS), AliQA::GetTaskName(AliQA::kRECPOINTS)) ;
2825 tempo.ReplaceAll(Form("%d", AliQA::kESDS), AliQA::GetTaskName(AliQA::kESDS)) ;
ce43afbe 2826 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
2827 fRunQA = kTRUE ;
2828 return kTRUE;
2829}
2830
7e88424f 2831//_____________________________________________________________________________
2832Bool_t AliReconstruction::InitRecoParams()
2833{
2834 // The method accesses OCDB and retrieves all
2835 // the available reco-param objects from there.
2836
2837 Bool_t isOK = kTRUE;
2838
2839 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2840
2841 if (fRecoParam.GetDetRecoParamArray(iDet)) {
2842 AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
2843 continue;
2844 }
2845
ac232c75 2846 AliInfo(Form("Loading reconstruction parameter objects for detector %s",fgkDetectorName[iDet]));
7e88424f 2847
2848 AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
2849 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
2850 if(!entry){
2851 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
2852 isOK = kFALSE;
2853 }
2854 else {
2855 TObject *recoParamObj = entry->GetObject();
2856 if (dynamic_cast<TObjArray*>(recoParamObj)) {
2857 // The detector has a normal TobjArray of AliDetectorRecoParam objects
2858 // Registering them in AliRecoParam
2859 fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
2860 }
2861 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
2862 // The detector has only onse set of reco parameters
2863 // Registering it in AliRecoParam
ac232c75 2864 AliInfo(Form("Single set of reconstruction parameters found for detector %s",fgkDetectorName[iDet]));
7e88424f 2865 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
2866 fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
2867 }
2868 else {
2869 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
2870 isOK = kFALSE;
2871 }
2872 entry->SetOwner(0);
4b71572b 2873 AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
7e88424f 2874 }
2875 }
2876
ac232c75 2877 fRecoParam.Print();
2878
7e88424f 2879 return isOK;
2880}
2881
2882//_____________________________________________________________________________
2883Bool_t AliReconstruction::GetEventInfo()
2884{
2885 // Fill the event info object
2886 // ...
2887 AliCodeTimerAuto("")
2888
2889 AliCentralTrigger *aCTP = NULL;
2890 if (fRawReader) {
2891 fEventInfo.SetEventType(fRawReader->GetType());
2892
2893 ULong64_t mask = fRawReader->GetClassMask();
2894 fEventInfo.SetTriggerMask(mask);
2895 UInt_t clmask = fRawReader->GetDetectorPattern()[0];
2896 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
2897
2898 aCTP = new AliCentralTrigger();
2899 TString configstr("");
2900 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
2901 AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
2902 delete aCTP;
2903 return kFALSE;
2904 }
2905 aCTP->SetClassMask(mask);
2906 aCTP->SetClusterMask(clmask);
2907 }
2908 else {
2909 fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
2910
2911 if (fRunLoader && (!fRunLoader->LoadTrigger())) {
2912 aCTP = fRunLoader->GetTrigger();
2913 fEventInfo.SetTriggerMask(aCTP->GetClassMask());
2914 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
2915 }
2916 else {
2917 AliWarning("No trigger can be loaded! The trigger information will not be used!");
2918 return kFALSE;
2919 }
2920 }
2921
2922 AliTriggerConfiguration *config = aCTP->GetConfiguration();
2923 if (!config) {
2924 AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
2925 if (fRawReader) delete aCTP;
2926 return kFALSE;
2927 }
2928
a0c2cf2d 2929 UChar_t clustmask = 0;
7e88424f 2930 TString trclasses;
2931 ULong64_t trmask = fEventInfo.GetTriggerMask();
2932 const TObjArray& classesArray = config->GetClasses();
2933 Int_t nclasses = classesArray.GetEntriesFast();
2934 for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
2935 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
2936 if (trclass) {
2937 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
2938 fesd->SetTriggerClass(trclass->GetName(),trindex);
2939 if (trmask & (1 << trindex)) {
2940 trclasses += " ";
2941 trclasses += trclass->GetName();
2942 trclasses += " ";
a0c2cf2d 2943 clustmask |= trclass->GetCluster()->GetClusterMask();
7e88424f 2944 }
2945 }
2946 }
2947 fEventInfo.SetTriggerClasses(trclasses);
2948
a0c2cf2d 2949 // Set the information in ESD
2950 fesd->SetTriggerMask(trmask);
2951 fesd->SetTriggerCluster(clustmask);
2952
7e88424f 2953 if (!aCTP->CheckTriggeredDetectors()) {
2954 if (fRawReader) delete aCTP;
2955 return kFALSE;
2956 }
2957
2958 if (fRawReader) delete aCTP;
2959
2960 // We have to fill also the HLT decision here!!
2961 // ...
2962
2963 return kTRUE;
2964}
2965
2966const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
2967{
2968 // Match the detector list found in the rec.C or the default 'ALL'
2969 // to the list found in the GRP (stored there by the shuttle PP which
2970 // gets the information from ECS)
2971 static TString resultList;
2972 TString detList = detectorList;
2973
2974 resultList = "";
2975
2976 for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
2977 if ((detectorMask >> iDet) & 0x1) {
2978 TString det = AliDAQ::OfflineModuleName(iDet);
2979 if ((detList.CompareTo("ALL") == 0) ||
2980 detList.BeginsWith("ALL ") ||
2981 detList.EndsWith(" ALL") ||
2982 detList.Contains(" ALL ") ||
2983 (detList.CompareTo(det) == 0) ||
2984 detList.BeginsWith(det) ||
2985 detList.EndsWith(det) ||
2986 detList.Contains( " "+det+" " )) {
2987 if (!resultList.EndsWith(det + " ")) {
2988 resultList += det;
2989 resultList += " ";
2990 }
2991 }
2992 }
2993 }
2994
2995 // HLT
2996 if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
2997 TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
2998 if ((detList.CompareTo("ALL") == 0) ||
2999 detList.BeginsWith("ALL ") ||
3000 detList.EndsWith(" ALL") ||
3001 detList.Contains(" ALL ") ||
3002 (detList.CompareTo(hltDet) == 0) ||
3003 detList.BeginsWith(hltDet) ||
3004 detList.EndsWith(hltDet) ||
3005 detList.Contains( " "+hltDet+" " )) {
3006 resultList += hltDet;
3007 }
3008 }
3009
3010 return resultList.Data();
3011
3012}
4b71572b 3013
3014//______________________________________________________________________________
3015void AliReconstruction::Abort(const char *method, EAbort what)
3016{
3017 // Abort processing. If what = kAbortProcess, the Process() loop will be
3018 // aborted. If what = kAbortFile, the current file in a chain will be
3019 // aborted and the processing will continue with the next file, if there
3020 // is no next file then Process() will be aborted. Abort() can also be
3021 // called from Begin(), SlaveBegin(), Init() and Notify(). After abort
3022 // the SlaveTerminate() and Terminate() are always called. The abort flag
3023 // can be checked in these methods using GetAbort().
3024 //
3025 // The method is overwritten in AliReconstruction for better handling of
3026 // reco specific errors
3027
3028 if (!fStopOnError) return;
3029
3030 CleanUp();
3031
3032 TString whyMess = method;
3033 whyMess += " failed! Aborting...";
3034
3035 AliError(whyMess.Data());
3036
3037 fAbort = what;
3038 TString mess = "Abort";
3039 if (fAbort == kAbortProcess)
3040 mess = "AbortProcess";
3041 else if (fAbort == kAbortFile)
3042 mess = "AbortFile";
3043
3044 Info(mess, whyMess.Data());
3045}
3046