]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliReconstruction.cxx
Added verbosity and updated call to overlap checker
[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
c757bafd 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
596a855f 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
00aa02d5 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
795e4a22 665//_____________________________________________________________________________
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
6bae477a 673//_____________________________________________________________________________
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
21a3aa09 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
efd2085e 744//_____________________________________________________________________________
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
7e88424f 754//_____________________________________________________________________________
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
61807e09 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
4b71572b 979//_____________________________________________________________________________
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
596a855f 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;
281270d3 1009 gProof->AddInput(const_cast<TMap*>(AliCDBManager::Instance()->GetEntryCache()));
1010 gProof->SetParameter("RunNumber",AliCDBManager::Instance()->GetRun());
4b71572b 1011 gProof->AddInput((AliMagF*)AliTracker::GetFieldMap());
1012 gProof->AddInput(this);
1013 chain->SetProof();
1014 chain->Process("AliReconstruction");
1015 }
1016 else {
1017 chain->Process(this);
1018 }
1019 }
1020 else {
1021 Begin(NULL);
1022 if (GetAbort() != TSelector::kContinue) return kFALSE;
1023 SlaveBegin(NULL);
1024 if (GetAbort() != TSelector::kContinue) return kFALSE;
1025 //******* The loop over events
1026 Int_t iEvent = 0;
1027 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
1028 (fRawReader && fRawReader->NextEvent())) {
1029 if (!ProcessEvent(iEvent)) {
1030 Abort("ProcessEvent",TSelector::kAbortFile);
1031 return kFALSE;
1032 }
1033 iEvent++;
1034 }
1035 SlaveTerminate();
1036 if (GetAbort() != TSelector::kContinue) return kFALSE;
1037 Terminate();
1038 if (GetAbort() != TSelector::kContinue) return kFALSE;
21a3aa09 1039 }
21a3aa09 1040
1041 return kTRUE;
1042}
1043
1044//_____________________________________________________________________________
4b71572b 1045void AliReconstruction::InitRawReader(const char* input)
21a3aa09 1046{
21a3aa09 1047 AliCodeTimerAuto("");
1048
4b71572b 1049 // Init raw-reader and
21a3aa09 1050 // set the input in case of raw data
4b71572b 1051 if (input) fRawInput = input;
1052 fRawReader = AliRawReader::Create(fRawInput.Data());
b58710ef 1053 if (!fRawReader)
21a3aa09 1054 AliInfo("Reconstruction will run over digits");
e0027792 1055
35042093 1056 if (!fEquipIdMap.IsNull() && fRawReader)
1057 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1058
cd0b062e 1059 if (!fUseHLTData.IsNull()) {
1060 // create the RawReaderHLT which performs redirection of HLT input data for
1061 // the specified detectors
1062 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
1063 if (pRawReader) {
1064 fParentRawReader=fRawReader;
1065 fRawReader=pRawReader;
1066 } else {
1067 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
1068 }
1069 }
4b71572b 1070 AliSysInfo::AddStamp("CreateRawReader");
1071}
cd0b062e 1072
4b71572b 1073//_____________________________________________________________________________
1074void AliReconstruction::InitRun(const char* input)
1075{
1076 // Initialization of raw-reader,
1077 // run number, CDB etc.
1078 AliCodeTimerAuto("");
1079 AliSysInfo::AddStamp("Start");
1080
1081 InitRawReader(input);
1082 AliSysInfo::AddStamp("CreateRawReader");
596a855f 1083
ec92bee0 1084 // Initialize the CDB storage
795e4a22 1085 InitCDB();
4b71572b 1086 AliSysInfo::AddStamp("InitCDB");
ec92bee0 1087
6bae477a 1088 // Set run number in CDBManager (if it is not already set by the user)
4b71572b 1089 if (!SetRunNumberFromData()) {
1090 Abort("SetRunNumberFromData", TSelector::kAbortProcess);
1091 return;
1092 }
795e4a22 1093
1094 // Set CDB lock: from now on it is forbidden to reset the run number
1095 // or the default storage or to activate any further storage!
1096 SetCDBLock();
1097
6bae477a 1098 // Import ideal TGeo geometry and apply misalignment
1099 if (!gGeoManager) {
1100 TString geom(gSystem->DirName(fGAliceFileName));
1101 geom += "/geometry.root";
98e303d9 1102 AliGeomManager::LoadGeometry(geom.Data());
4b71572b 1103 if (!gGeoManager) {
1104 Abort("LoadGeometry", TSelector::kAbortProcess);
1105 return;
1106 }
281270d3 1107 AliSysInfo::AddStamp("LoadGeom");
ff5970a3 1108 TString detsToCheck=fRunLocalReconstruction;
4b71572b 1109 if(!AliGeomManager::CheckSymNamesLUT(detsToCheck.Data())) {
1110 Abort("CheckSymNamesLUT", TSelector::kAbortProcess);
1111 return;
1112 }
281270d3 1113 AliSysInfo::AddStamp("CheckGeom");
6bae477a 1114 }
8e245d15 1115
4b71572b 1116 if (!MisalignGeometry(fLoadAlignData)) {
1117 Abort("MisalignGeometry", TSelector::kAbortProcess);
1118 return;
1119 }
1120 AliCDBManager::Instance()->UnloadFromCache("GRP/Geometry/Data");
281270d3 1121 AliSysInfo::AddStamp("MisalignGeom");
6bae477a 1122
4b71572b 1123 if (!InitGRP()) {
1124 Abort("InitGRP", TSelector::kAbortProcess);
1125 return;
1126 }
1127 AliSysInfo::AddStamp("InitGRP");
325aa76f 1128
4b71572b 1129 if (!LoadCDB()) {
1130 Abort("LoadCDB", TSelector::kAbortProcess);
1131 return;
1132 }
1133 AliSysInfo::AddStamp("LoadCDB");
325aa76f 1134
7e88424f 1135 // Read the reconstruction parameters from OCDB
1136 if (!InitRecoParams()) {
4b71572b 1137 Abort("InitRecoParams", TSelector::kAbortProcess);
1138 return;
1139 }
1140 AliSysInfo::AddStamp("InitRecoParams");
1141
1142}
1143
1144//_____________________________________________________________________________
1145void AliReconstruction::Begin(TTree *)
1146{
1147 // Initialize AlReconstruction before
1148 // going into the event loop
1149 // Should follow the TSelector convention
1150 // i.e. initialize only the object on the client side
1151
1152}
1153
1154//_____________________________________________________________________________
1155void AliReconstruction::SlaveBegin(TTree*)
1156{
1157 // Initialization related to run-loader,
1158 // vertexer, trackers, recontructors
1159 // In proof mode it is executed on the slave
1160 AliCodeTimerAuto("");
1161
1162 if (fInput) {
1163 if (TGeoManager *tgeo = (TGeoManager*)fInput->FindObject("Geometry")) {
1164 gGeoManager = tgeo;
1165 AliGeomManager::SetGeometry(tgeo);
7e88424f 1166 }
281270d3 1167 if (TMap *entryCache = (TMap*)fInput->FindObject("CDBEntryCache")) {
1168 Int_t runNumber = -1;
1169 if (TProof::GetParameter(fInput,"RunNumber",runNumber) == 0) {
1170 AliCDBManager *man = AliCDBManager::Instance(entryCache,runNumber);
1171 man->SetCacheFlag(kTRUE);
1172 man->SetLock(kTRUE);
1173 man->Print();
1174 }
4b71572b 1175 }
1176 if (AliMagF *map = (AliMagF*)fInput->FindObject("Maps")) {
1177 AliTracker::SetFieldMap(map,fUniformField);
1178 }
1179 if (AliReconstruction *reco = (AliReconstruction*)fInput->FindObject("AliReconstruction")) {
1180 *this = *reco;
1181 }
1182 AliSysInfo::AddStamp("ReadSelectorInput");
7e88424f 1183 }
325aa76f 1184
4b71572b 1185 // get the run loader
1186 if (!InitRunLoader()) {
1187 Abort("InitRunLoader", TSelector::kAbortProcess);
1188 return;
1189 }
1190 AliSysInfo::AddStamp("LoadLoader");
1191
325aa76f 1192 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
1193 if(fDiamondProfile && fMeanVertexConstraint) ftVertexer->SetVtxStart(fDiamondProfile);
2257f27e 1194
1195 // get vertexer
1196 if (fRunVertexFinder && !CreateVertexer()) {
4b71572b 1197 Abort("CreateVertexer", TSelector::kAbortProcess);
1198 return;
2257f27e 1199 }
4b71572b 1200 AliSysInfo::AddStamp("CreateVertexer");
596a855f 1201
f08fc9f5 1202 // get trackers
b8cd5251 1203 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
4b71572b 1204 Abort("CreateTrackers", TSelector::kAbortProcess);
1205 return;
1206 }
1207 AliSysInfo::AddStamp("CreateTrackers");
24f7a148 1208
36711aa4 1209 // create the ESD output file and tree
21a3aa09 1210 ffile = TFile::Open("AliESDs.root", "RECREATE");
1211 ffile->SetCompressionLevel(2);
1212 if (!ffile->IsOpen()) {
4b71572b 1213 Abort("OpenESDFile", TSelector::kAbortProcess);
1214 return;
596a855f 1215 }
46698ae4 1216
21a3aa09 1217 ftree = new TTree("esdTree", "Tree with ESD objects");
1218 fesd = new AliESDEvent();
1219 fesd->CreateStdContent();
1220 fesd->WriteToTree(ftree);
46698ae4 1221
21a3aa09 1222 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
1223 fhltesd = new AliESDEvent();
1224 fhltesd->CreateStdContent();
1225 fhltesd->WriteToTree(fhlttree);
46698ae4 1226
5728d3d5 1227
1d99986f 1228 if (fWriteESDfriend) {
21a3aa09 1229 fesdf = new AliESDfriend();
1230 TBranch *br=ftree->Branch("ESDfriend.","AliESDfriend", &fesdf);
46698ae4 1231 br->SetFile("AliESDfriends.root");
21a3aa09 1232 fesd->AddObject(fesdf);
1d99986f 1233 }
5728d3d5 1234
95cee32f 1235 ProcInfo_t ProcInfo;
1236 gSystem->GetProcInfo(&ProcInfo);
1237 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
8661738e 1238
325aa76f 1239 //QA
4b71572b 1240 fQASteer = new AliQADataMakerSteer("rec") ;
1241 fQASteer->SetActiveDetectors(fQADetectors) ;
1242 fQASteer->SetTasks(fQATasks) ;
1243
ca13fb87 1244 if ( !fInLoopQA ) {
1245 if (fRunQA && fRawReader && fQATasks.Contains(Form("%d", AliQA::kRAWS))) {
1246 fQASteer->Run(fQADetectors, fRawReader) ;
1247 fSameQACycle = kTRUE ;
1248 }
325aa76f 1249 }
ca13fb87 1250
e84c88f5 1251 //Initialize the QA and start of cycle for out-of-loop QA
f6806ad3 1252 if (fRunQA) {
4b71572b 1253 fQASteer->InitQADataMaker(AliCDBManager::Instance()->GetRun(), fRecoParam, fSameQACycle, !fInLoopQA) ;
1254 }
e84c88f5 1255
4b71572b 1256 if (fRunGlobalQA) {
1257 fSameQACycle = kFALSE;
1258 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1259 AliInfo(Form("Initializing the global QA data maker"));
1260 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1261 TObjArray *arr=qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
1262 AliTracker::SetResidualsArray(arr);
1263 if (!fInLoopQA) {
1264 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
1265 fSameQACycle = kTRUE;
1266 }
1267 }
1268 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
1269 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
1270 if (!fInLoopQA) {
1271 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
1272 fSameQACycle = kTRUE;
1273 }
1274 }
1275 }
aa3c69a9 1276
7167ae53 1277 //Initialize the Plane Efficiency framework
1278 if (fRunPlaneEff && !InitPlaneEff()) {
4b71572b 1279 Abort("InitPlaneEff", TSelector::kAbortProcess);
1280 return;
7167ae53 1281 }
aa3c69a9 1282
14dd053c 1283 if (strcmp(gProgName,"alieve") == 0)
1284 fRunAliEVE = InitAliEVE();
1285
4b71572b 1286 return;
21a3aa09 1287}
1288
1289//_____________________________________________________________________________
4b71572b 1290Bool_t AliReconstruction::Process(Long64_t entry)
1291{
1292 // run the reconstruction over a single entry
1293 // from the chain with raw data
1294 AliCodeTimerAuto("");
1295
1296 TTree *currTree = fChain->GetTree();
1297 AliRawEvent *event = new AliRawEvent;
1298 currTree->SetBranchAddress("rawevent",&event);
1299 currTree->GetEntry(entry);
1300 fRawReader = new AliRawReaderRoot(event);
1301 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
1302 delete fRawReader;
1303 fRawReader = NULL;
1304 delete event;
1305
1306 return fStatus;
1307}
1308
1309//_____________________________________________________________________________
1310void AliReconstruction::Init(TTree *tree)
1311{
1312 if (tree == 0) {
1313 AliError("The input tree is not found!");
1314 return;
1315 }
1316 fChain = tree;
1317}
1318
1319//_____________________________________________________________________________
1320Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
21a3aa09 1321{
1322 // run the reconstruction over a single event
1323 // The event loop is steered in Run method
1324
1325 AliCodeTimerAuto("");
1326
1327 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
1328 fRunLoader->SetEventNumber(iEvent);
1329 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1330 iEvent, iEvent);
21a3aa09 1331 fRunLoader->TreeE()->Fill();
4b71572b 1332 if (fRawReader && fRawReader->UseAutoSaveESD())
1333 fRunLoader->TreeE()->AutoSave("SaveSelf");
21a3aa09 1334 }
1335
1336 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
21a3aa09 1337 return kTRUE;
1338 }
1339
1340 AliInfo(Form("processing event %d", iEvent));
aa3c69a9 1341
7e88424f 1342 // Fill Event-info object
1343 GetEventInfo();
1344 fRecoParam.SetEventSpecie(fRunInfo,fEventInfo);
1345
ca13fb87 1346 //Start of cycle for the in-loop QA
1347 if (fInLoopQA && fRunQA) {
4b71572b 1348 fQASteer->InitQADataMaker(AliCDBManager::Instance()->GetRun(), fRecoParam, fSameQACycle, fInLoopQA) ;
1349 }
1350 if (fInLoopQA && fRunGlobalQA) {
1351 fSameQACycle = kFALSE;
1352 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1353 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1354 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
1355 fSameQACycle = kTRUE;
1356 }
1357 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
1358 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
1359 fSameQACycle = kTRUE;
1360 }
1361 }
24f7a148 1362
4b71572b 1363 fRunLoader->GetEvent(iEvent);
24f7a148 1364
ca13fb87 1365 // QA on single raw
e84c88f5 1366 if (fInLoopQA && fRunQA)
1367 fQASteer->RunOneEvent(fRawReader) ;
ca13fb87 1368
d506c543 1369 // local single event reconstruction
b26c3770 1370 if (!fRunLocalReconstruction.IsNull()) {
d506c543 1371 TString detectors=fRunLocalReconstruction;
a441bf51 1372 // run HLT event reconstruction first
d506c543 1373 // ;-( IsSelected changes the string
1374 if (IsSelected("HLT", detectors) &&
1375 !RunLocalEventReconstruction("HLT")) {
4b71572b 1376 if (fStopOnError) {CleanUp(); return kFALSE;}
a441bf51 1377 }
1378 detectors=fRunLocalReconstruction;
1379 detectors.ReplaceAll("HLT", "");
1380 if (!RunLocalEventReconstruction(detectors)) {
4b71572b 1381 if (fStopOnError) {CleanUp(); return kFALSE;}
b26c3770 1382 }
1383 }
1384
21a3aa09 1385 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1386 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1387 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1388 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
46698ae4 1389
d6ee376f 1390 // Set magnetic field from the tracker
21a3aa09 1391 fesd->SetMagneticField(AliTracker::GetBz());
1392 fhltesd->SetMagneticField(AliTracker::GetBz());
596a855f 1393
46698ae4 1394
1395
2e3550da 1396 // Fill raw-data error log into the ESD
21a3aa09 1397 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 1398
2257f27e 1399 // vertex finder
1400 if (fRunVertexFinder) {
4b71572b 1401 if (!RunVertexFinder(fesd)) {
1402 if (fStopOnError) {CleanUp(); return kFALSE;}
2257f27e 1403 }
1404 }
1405
e66fbafb 1406 // Muon tracking
b8cd5251 1407 if (!fRunTracking.IsNull()) {
e66fbafb 1408 if (fRunMuonTracking) {
21a3aa09 1409 if (!RunMuonTracking(fesd)) {
4b71572b 1410 if (fStopOnError) {CleanUp(); return kFALSE;}
24f7a148 1411 }
596a855f 1412 }
1413 }
1414
e66fbafb 1415 // barrel tracking
1416 if (!fRunTracking.IsNull()) {
4b71572b 1417 if (!RunTracking(fesd)) {
1418 if (fStopOnError) {CleanUp(); return kFALSE;}
e66fbafb 1419 }
1420 }
21c573b7 1421
596a855f 1422 // fill ESD
1423 if (!fFillESD.IsNull()) {
d506c543 1424 TString detectors=fFillESD;
f6806ad3 1425 // run HLT first and on hltesd
d506c543 1426 // ;-( IsSelected changes the string
1427 if (IsSelected("HLT", detectors) &&
1428 !FillESD(fhltesd, "HLT")) {
4b71572b 1429 if (fStopOnError) {CleanUp(); return kFALSE;}
f6806ad3 1430 }
1431 detectors=fFillESD;
d5105682 1432 // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
1433 if (detectors.Contains("ALL")) {
1434 detectors="";
1435 for (Int_t idet=0; idet<fgkNDetectors; ++idet){
1436 detectors += fgkDetectorName[idet];
1437 detectors += " ";
1438 }
1439 }
f6806ad3 1440 detectors.ReplaceAll("HLT", "");
1441 if (!FillESD(fesd, detectors)) {
4b71572b 1442 if (fStopOnError) {CleanUp(); return kFALSE;}
596a855f 1443 }
1444 }
a5fa6165 1445
001397cd 1446 // fill Event header information from the RawEventHeader
21a3aa09 1447 if (fRawReader){FillRawEventHeaderESD(fesd);}
596a855f 1448
1449 // combined PID
21a3aa09 1450 AliESDpid::MakePID(fesd);
596a855f 1451
b647652d 1452 if (fFillTriggerESD) {
4b71572b 1453 if (!FillTriggerESD(fesd)) {
1454 if (fStopOnError) {CleanUp(); return kFALSE;}
b647652d 1455 }
1456 }
1457
21a3aa09 1458 ffile->cd();
a6ee503a 1459
3c3709c4 1460 //
67be5c77 1461 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 1462 //
21a3aa09 1463 const Int_t ntracks = fesd->GetNumberOfTracks();
1464 const Double_t kBz = fesd->GetMagneticField();
3c3709c4 1465 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1466
1467 TObjArray trkArray;
1468 UShort_t *selectedIdx=new UShort_t[ntracks];
1469
1470 for (Int_t itrack=0; itrack<ntracks; itrack++){
1471 const Double_t kMaxStep = 5; //max step over the material
1472 Bool_t ok;
1473
21a3aa09 1474 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 1475 if (!track) continue;
1476
1477 AliExternalTrackParam *tpcTrack =
1478 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 1479 ok = kFALSE;
1480 if (tpcTrack)
1481 ok = AliTracker::
1482 PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
43c9dae1 1483
3c3709c4 1484 if (ok) {
1485 Int_t n=trkArray.GetEntriesFast();
1486 selectedIdx[n]=track->GetID();
1487 trkArray.AddLast(tpcTrack);
1488 }
1489
3d65e645 1490 //Tracks refitted by ITS should already be at the SPD vertex
1491 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1492
1493 AliTracker::
1494 PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1495 track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kVeryBig);
3c3709c4 1496
3c3709c4 1497 }
1498
1499 //
1500 // Improve the reconstructed primary vertex position using the tracks
1501 //
1502 TObject *obj = fOptions.FindObject("ITS");
c060d7fe 1503 if (obj) {
1504 TString optITS = obj->GetTitle();
1505 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
a84e2607 1506 fRunVertexFinderTracks=kFALSE;
c060d7fe 1507 }
3c3709c4 1508 if (fRunVertexFinderTracks) {
1509 // TPC + ITS primary vertex
21a3aa09 1510 ftVertexer->SetITSrefitRequired();
43c9dae1 1511 if(fDiamondProfile && fMeanVertexConstraint) {
21a3aa09 1512 ftVertexer->SetVtxStart(fDiamondProfile);
43c9dae1 1513 } else {
21a3aa09 1514 ftVertexer->SetConstraintOff();
43c9dae1 1515 }
21a3aa09 1516 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 1517 if (pvtx) {
1518 if (pvtx->GetStatus()) {
21a3aa09 1519 fesd->SetPrimaryVertex(pvtx);
3c3709c4 1520 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 1521 AliESDtrack *t = fesd->GetTrack(i);
3d65e645 1522 t->RelateToVertex(pvtx, kBz, kVeryBig);
3c3709c4 1523 }
1524 }
1525 }
1526
1527 // TPC-only primary vertex
21a3aa09 1528 ftVertexer->SetITSrefitNotRequired();
43c9dae1 1529 if(fDiamondProfileTPC && fMeanVertexConstraint) {
21a3aa09 1530 ftVertexer->SetVtxStart(fDiamondProfileTPC);
43c9dae1 1531 } else {
21a3aa09 1532 ftVertexer->SetConstraintOff();
43c9dae1 1533 }
21a3aa09 1534 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 1535 if (pvtx) {
1536 if (pvtx->GetStatus()) {
21a3aa09 1537 fesd->SetPrimaryVertexTPC(pvtx);
3d65e645 1538 for (Int_t i=0; i<ntracks; i++) {
1539 AliESDtrack *t = fesd->GetTrack(i);
1540 t->RelateToVertexTPC(pvtx, kBz, kVeryBig);
3c3709c4 1541 }
1542 }
1543 }
1544
1545 }
1546 delete[] selectedIdx;
1547
21a3aa09 1548 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
17c86e90 1549
c5e3e5d1 1550
d1683eef 1551 if (fRunV0Finder) {
1552 // V0 finding
1553 AliV0vertexer vtxer;
21a3aa09 1554 vtxer.Tracks2V0vertices(fesd);
5e4ff34d 1555
d1683eef 1556 if (fRunCascadeFinder) {
1557 // Cascade finding
1558 AliCascadeVertexer cvtxer;
21a3aa09 1559 cvtxer.V0sTracks2CascadeVertices(fesd);
d1683eef 1560 }
5e4ff34d 1561 }
1562
596a855f 1563 // write ESD
21a3aa09 1564 if (fCleanESD) CleanESD(fesd);
854c6476 1565
0d106d88 1566 if (fRunGlobalQA) {
1567 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1568 if (qadm && fQATasks.Contains(Form("%d", AliQA::kESDS)))
1569 qadm->Exec(AliQA::kESDS, fesd);
b8bd1ab8 1570 }
854c6476 1571
1d99986f 1572 if (fWriteESDfriend) {
21a3aa09 1573 fesdf->~AliESDfriend();
1574 new (fesdf) AliESDfriend(); // Reset...
1575 fesd->GetESDfriend(fesdf);
1d99986f 1576 }
21a3aa09 1577 ftree->Fill();
500d54ab 1578
2d91a353 1579 // Auto-save the ESD tree in case of prompt reco @P2
1580 if (fRawReader && fRawReader->UseAutoSaveESD())
1581 ftree->AutoSave("SaveSelf");
1582
500d54ab 1583 // write HLT ESD
21a3aa09 1584 fhlttree->Fill();
1d99986f 1585
14dd053c 1586 // call AliEVE
1587 if (fRunAliEVE) RunAliEVE();
1588
21a3aa09 1589 fesd->Reset();
1590 fhltesd->Reset();
5728d3d5 1591 if (fWriteESDfriend) {
21a3aa09 1592 fesdf->~AliESDfriend();
1593 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 1594 }
a5fa6165 1595
21a3aa09 1596 ProcInfo_t ProcInfo;
95cee32f 1597 gSystem->GetProcInfo(&ProcInfo);
1598 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
a5fa6165 1599
7e963665 1600
ce43afbe 1601 // End of cycle for the in-loop
ca13fb87 1602 if (fInLoopQA && fRunQA) {
0d106d88 1603 fQASteer->RunOneEvent(fesd) ;
1604 fQASteer->EndOfCycle() ;
1605 }
1606 if (fInLoopQA && fRunGlobalQA) {
ca13fb87 1607 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1608 if (qadm) {
0d106d88 1609 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1610 qadm->EndOfCycle(AliQA::kRECPOINTS);
1611 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1612 qadm->EndOfCycle(AliQA::kESDS);
1613 qadm->Finish();
ca13fb87 1614 }
1615 }
7e88424f 1616
ca13fb87 1617 fEventInfo.Reset();
1618 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1619 if (fReconstructor[iDet])
e84c88f5 1620 fReconstructor[iDet]->SetRecoParam(NULL);
ca13fb87 1621 }
1622
1623 return kTRUE;
21a3aa09 1624}
1625
21a3aa09 1626//_____________________________________________________________________________
4b71572b 1627void AliReconstruction::SlaveTerminate()
21a3aa09 1628{
4b71572b 1629 // Finalize the run on the slave side
21a3aa09 1630 // Called after the exit
1631 // from the event loop
1632 AliCodeTimerAuto("");
1633
1634 if (fIsNewRunLoader) { // galice.root didn't exist
1635 fRunLoader->WriteHeader("OVERWRITE");
1636 fRunLoader->CdGAFile();
1637 fRunLoader->Write(0, TObject::kOverwrite);
1638 }
1639
1640 ftree->GetUserInfo()->Add(fesd);
1641 fhlttree->GetUserInfo()->Add(fhltesd);
f747912b 1642
1643 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1644 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1645
1646 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1647 cdbMapCopy->SetOwner(1);
1648 cdbMapCopy->SetName("cdbMap");
1649 TIter iter(cdbMap->GetTable());
1650
1651 TPair* pair = 0;
1652 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1653 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1654 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1655 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1656 }
1657
1658 TList *cdbListCopy = new TList();
1659 cdbListCopy->SetOwner(1);
1660 cdbListCopy->SetName("cdbList");
1661
1662 TIter iter2(cdbList);
1663
b940cb9b 1664 AliCDBId* id=0;
e84c88f5 1665 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 1666 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 1667 }
1668
21a3aa09 1669 ftree->GetUserInfo()->Add(cdbMapCopy);
1670 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 1671
46698ae4 1672
1673 if(fESDPar.Contains("ESD.par")){
1674 AliInfo("Attaching ESD.par to Tree");
1675 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
21a3aa09 1676 ftree->GetUserInfo()->Add(fn);
596a855f 1677 }
1678
46698ae4 1679
21a3aa09 1680 ffile->cd();
aa3c69a9 1681
a9c0e6db 1682 if (fWriteESDfriend)
21a3aa09 1683 ftree->SetBranchStatus("ESDfriend*",0);
562dd0b4 1684 // we want to have only one tree version number
21a3aa09 1685 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1686 fhlttree->Write();
f3a97c86 1687
a7a1e1c7 1688// Finish with Plane Efficiency evaluation: before of CleanUp !!!
1689 if (fRunPlaneEff && !FinishPlaneEff()) {
1690 AliWarning("Finish PlaneEff evaluation failed");
1691 }
1692
4b71572b 1693 //Finish QA and end of cycle for out-of-loop QA
1694 if (!fInLoopQA && fRunQA)
1695 fQASteer->Run(fRunLocalReconstruction.Data(), AliQA::kNULLTASKINDEX, fSameQACycle) ;
1696 if (!fInLoopQA && fRunGlobalQA) {
1697 AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
1698 if (qadm) {
1699 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS)))
1700 qadm->EndOfCycle(AliQA::kRECPOINTS);
1701 if (fQATasks.Contains(Form("%d", AliQA::kESDS)))
1702 qadm->EndOfCycle(AliQA::kESDS);
1703 qadm->Finish();
1704 }
a7807689 1705 }
1706
4b71572b 1707 gROOT->cd();
1708 CleanUp();
1709}
1710
1711//_____________________________________________________________________________
1712void AliReconstruction::Terminate()
1713{
f3a97c86 1714 // Create tags for the events in the ESD tree (the ESD tree is always present)
1715 // In case of empty events the tags will contain dummy values
4b71572b 1716 AliCodeTimerAuto("");
1717
08e1a23e 1718 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
6b6e4472 1719 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData);
e84c88f5 1720
795e4a22 1721 // Cleanup of CDB manager: cache and active storages!
1722 AliCDBManager::Instance()->ClearCache();
596a855f 1723}
1724
b26c3770 1725//_____________________________________________________________________________
1726Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1727{
1728// run the local reconstruction
aa3c69a9 1729
0f88822a 1730 static Int_t eventNr=0;
87932dab 1731 AliCodeTimerAuto("")
b26c3770 1732
1733 TString detStr = detectors;
1734 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1735 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1736 AliReconstructor* reconstructor = GetReconstructor(iDet);
1737 if (!reconstructor) continue;
1738 AliLoader* loader = fLoader[iDet];
f6806ad3 1739 // Matthias April 2008: temporary fix to run HLT reconstruction
1740 // although the HLT loader is missing
1741 if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
1742 if (fRawReader) {
1743 reconstructor->Reconstruct(fRawReader, NULL);
1744 } else {
1745 TTree* dummy=NULL;
1746 reconstructor->Reconstruct(dummy, NULL);
1747 }
1748 continue;
1749 }
d76c31f4 1750 if (!loader) {
1751 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1752 continue;
1753 }
b26c3770 1754 // conversion of digits
1755 if (fRawReader && reconstructor->HasDigitConversion()) {
1756 AliInfo(Form("converting raw data digits into root objects for %s",
1757 fgkDetectorName[iDet]));
30bbd491 1758// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1759// fgkDetectorName[iDet]));
b26c3770 1760 loader->LoadDigits("update");
1761 loader->CleanDigits();
1762 loader->MakeDigitsContainer();
1763 TTree* digitsTree = loader->TreeD();
1764 reconstructor->ConvertDigits(fRawReader, digitsTree);
1765 loader->WriteDigits("OVERWRITE");
1766 loader->UnloadDigits();
b26c3770 1767 }
b26c3770 1768 // local reconstruction
b26c3770 1769 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
30bbd491 1770 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
b26c3770 1771 loader->LoadRecPoints("update");
1772 loader->CleanRecPoints();
1773 loader->MakeRecPointsContainer();
1774 TTree* clustersTree = loader->TreeR();
1775 if (fRawReader && !reconstructor->HasDigitConversion()) {
1776 reconstructor->Reconstruct(fRawReader, clustersTree);
1777 } else {
1778 loader->LoadDigits("read");
1779 TTree* digitsTree = loader->TreeD();
1780 if (!digitsTree) {
1781 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1782 if (fStopOnError) return kFALSE;
1783 } else {
1784 reconstructor->Reconstruct(digitsTree, clustersTree);
1785 }
1786 loader->UnloadDigits();
1787 }
d76c31f4 1788
aa3c69a9 1789 // In-loop QA for local reconstrucion
30bbd491 1790 TString detQAStr(fQADetectors) ;
e84c88f5 1791 if (fRunQA && fInLoopQA)
1792 fQASteer->RunOneEventInOneDetector(iDet, clustersTree) ;
1793
1794 loader->WriteRecPoints("OVERWRITE");
1795 loader->UnloadRecPoints();
1796 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
1797 }
1798 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
b26c3770 1799 AliError(Form("the following detectors were not found: %s",
1800 detStr.Data()));
1801 if (fStopOnError) return kFALSE;
1802 }
0f88822a 1803 eventNr++;
b26c3770 1804 return kTRUE;
1805}
1806
596a855f 1807//_____________________________________________________________________________
af885e0f 1808Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 1809{
1810// run the barrel tracking
1811
87932dab 1812 AliCodeTimerAuto("")
030b532d 1813
2257f27e 1814 AliESDVertex* vertex = NULL;
1815 Double_t vtxPos[3] = {0, 0, 0};
1816 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1817 TArrayF mcVertex(3);
a6b0b91b 1818 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1819 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1820 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1821 }
2257f27e 1822
b8cd5251 1823 if (fVertexer) {
815c2b38 1824 AliInfo("running the ITS vertex finder");
308c2f7c 1825 if (fLoader[0]) {
1826 fLoader[0]->LoadRecPoints();
1827 TTree* cltree = fLoader[0]->TreeR();
1828 if (cltree) {
1829 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1830 vertex = fVertexer->FindVertexForCurrentEvent(cltree);
1831 }
1832 else {
1833 AliError("Can't get the ITS cluster tree");
1834 }
1835 fLoader[0]->UnloadRecPoints();
1836 }
1837 else {
1838 AliError("Can't get the ITS loader");
1839 }
2257f27e 1840 if(!vertex){
815c2b38 1841 AliWarning("Vertex not found");
c710f220 1842 vertex = new AliESDVertex();
d1a50cb5 1843 vertex->SetName("default");
2257f27e 1844 }
1845 else {
d1a50cb5 1846 vertex->SetName("reconstructed");
2257f27e 1847 }
1848
1849 } else {
815c2b38 1850 AliInfo("getting the primary vertex from MC");
2257f27e 1851 vertex = new AliESDVertex(vtxPos, vtxErr);
1852 }
1853
1854 if (vertex) {
1855 vertex->GetXYZ(vtxPos);
1856 vertex->GetSigmaXYZ(vtxErr);
1857 } else {
815c2b38 1858 AliWarning("no vertex reconstructed");
2257f27e 1859 vertex = new AliESDVertex(vtxPos, vtxErr);
1860 }
06cc9d95 1861 esd->SetPrimaryVertexSPD(vertex);
32e449be 1862 // if SPD multiplicity has been determined, it is stored in the ESD
25be1e5c 1863 AliMultiplicity *mult = fVertexer->GetMultiplicity();
32e449be 1864 if(mult)esd->SetMultiplicity(mult);
1865
b8cd5251 1866 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1867 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1868 }
2257f27e 1869 delete vertex;
1870
2257f27e 1871 return kTRUE;
1872}
1873
1f46a9ae 1874//_____________________________________________________________________________
af885e0f 1875Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 1876{
1877// run the HLT barrel tracking
1878
87932dab 1879 AliCodeTimerAuto("")
1f46a9ae 1880
1881 if (!fRunLoader) {
1882 AliError("Missing runLoader!");
1883 return kFALSE;
1884 }
1885
1886 AliInfo("running HLT tracking");
1887
1888 // Get a pointer to the HLT reconstructor
1889 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1890 if (!reconstructor) return kFALSE;
1891
1892 // TPC + ITS
1893 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1894 TString detName = fgkDetectorName[iDet];
1895 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1896 reconstructor->SetOption(detName.Data());
d76c31f4 1897 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 1898 if (!tracker) {
1899 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1900 if (fStopOnError) return kFALSE;
9dcc06e1 1901 continue;
1f46a9ae 1902 }
1903 Double_t vtxPos[3];
1904 Double_t vtxErr[3]={0.005,0.005,0.010};
1905 const AliESDVertex *vertex = esd->GetVertex();
1906 vertex->GetXYZ(vtxPos);
1907 tracker->SetVertex(vtxPos,vtxErr);
1908 if(iDet != 1) {
1909 fLoader[iDet]->LoadRecPoints("read");
1910 TTree* tree = fLoader[iDet]->TreeR();
1911 if (!tree) {
1912 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1913 return kFALSE;
1914 }
1915 tracker->LoadClusters(tree);
1916 }
1917 if (tracker->Clusters2Tracks(esd) != 0) {
1918 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1919 return kFALSE;
1920 }
1921 if(iDet != 1) {
1922 tracker->UnloadClusters();
1923 }
1924 delete tracker;
1925 }
1926
1f46a9ae 1927 return kTRUE;
1928}
1929
e66fbafb 1930//_____________________________________________________________________________
af885e0f 1931Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 1932{
1933// run the muon spectrometer tracking
1934
87932dab 1935 AliCodeTimerAuto("")
e66fbafb 1936
1937 if (!fRunLoader) {
1938 AliError("Missing runLoader!");
1939 return kFALSE;
1940 }
1941 Int_t iDet = 7; // for MUON
1942
1943 AliInfo("is running...");
1944
1945 // Get a pointer to the MUON reconstructor
1946 AliReconstructor *reconstructor = GetReconstructor(iDet);
1947 if (!reconstructor) return kFALSE;
1948
1949
1950 TString detName = fgkDetectorName[iDet];
1951 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 1952 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 1953 if (!tracker) {
1954 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1955 return kFALSE;
1956 }
1957
e66fbafb 1958 // read RecPoints
761350a6 1959 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 1960
761350a6 1961 tracker->LoadClusters(fLoader[iDet]->TreeR());
1962
1963 Int_t rv = tracker->Clusters2Tracks(esd);
1964
761350a6 1965 if ( rv )
1966 {
e66fbafb 1967 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1968 return kFALSE;
1969 }
761350a6 1970
e66fbafb 1971 fLoader[iDet]->UnloadRecPoints();
1972
c1954ee5 1973 tracker->UnloadClusters();
1974
e66fbafb 1975 delete tracker;
1976
e66fbafb 1977 return kTRUE;
1978}
1979
1980
2257f27e 1981//_____________________________________________________________________________
af885e0f 1982Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
2257f27e 1983{
1984// run the barrel tracking
0f88822a 1985 static Int_t eventNr=0;
87932dab 1986 AliCodeTimerAuto("")
24f7a148 1987
815c2b38 1988 AliInfo("running tracking");
596a855f 1989
91b876d1 1990 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 1991 if (fReconstructor[11] && fLoader[11]) {
1992 fLoader[11]->LoadRecPoints("READ");
1993 TTree *treeR = fLoader[11]->TreeR();
1994 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1995 }
91b876d1 1996
b8cd5251 1997 // pass 1: TPC + ITS inwards
1998 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1999 if (!fTracker[iDet]) continue;
2000 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 2001
b8cd5251 2002 // load clusters
2003 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2004 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 2005 TTree* tree = fLoader[iDet]->TreeR();
2006 if (!tree) {
2007 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2008 return kFALSE;
2009 }
b8cd5251 2010 fTracker[iDet]->LoadClusters(tree);
6efecea1 2011 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2012 // run tracking
2013 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
2014 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 2015 return kFALSE;
2016 }
878e1fe1 2017 // preliminary PID in TPC needed by the ITS tracker
2018 if (iDet == 1) {
b26c3770 2019 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
878e1fe1 2020 AliESDpid::MakePID(esd);
0f88822a 2021 }
6efecea1 2022 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 2023 }
596a855f 2024
b8cd5251 2025 // pass 2: ALL backwards
aa3c69a9 2026
b8cd5251 2027 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2028 if (!fTracker[iDet]) continue;
2029 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
2030
2031 // load clusters
2032 if (iDet > 1) { // all except ITS, TPC
2033 TTree* tree = NULL;
7b61cd9c 2034 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2035 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 2036 tree = fLoader[iDet]->TreeR();
b8cd5251 2037 if (!tree) {
2038 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2039 return kFALSE;
2040 }
0f88822a 2041 fTracker[iDet]->LoadClusters(tree);
6efecea1 2042 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2043 }
24f7a148 2044
b8cd5251 2045 // run tracking
283f39c6 2046 if (iDet>1) // start filling residuals for the "outer" detectors
2047 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
2048
b8cd5251 2049 if (fTracker[iDet]->PropagateBack(esd) != 0) {
2050 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 2051 // return kFALSE;
b8cd5251 2052 }
24f7a148 2053
b8cd5251 2054 // unload clusters
6e65648b 2055 if (iDet > 3) { // all except ITS, TPC, TRD and TOF
b8cd5251 2056 fTracker[iDet]->UnloadClusters();
7b61cd9c 2057 fLoader[iDet]->UnloadRecPoints();
b8cd5251 2058 }
8f37df88 2059 // updated PID in TPC needed by the ITS tracker -MI
2060 if (iDet == 1) {
8f37df88 2061 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
2062 AliESDpid::MakePID(esd);
2063 }
6efecea1 2064 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 2065 }
283f39c6 2066 //stop filling residuals for the "outer" detectors
2067 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
596a855f 2068
b8cd5251 2069 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 2070
b8cd5251 2071 for (Int_t iDet = 2; iDet >= 0; iDet--) {
2072 if (!fTracker[iDet]) continue;
2073 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 2074
b8cd5251 2075 // run tracking
283f39c6 2076 if (iDet<2) // start filling residuals for TPC and ITS
2077 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
2078
b8cd5251 2079 if (fTracker[iDet]->RefitInward(esd) != 0) {
2080 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 2081 // return kFALSE;
b8cd5251 2082 }
db2368d0 2083 // run postprocessing
2084 if (fTracker[iDet]->PostProcess(esd) != 0) {
2085 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
2086 // return kFALSE;
2087 }
6efecea1 2088 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
6e65648b 2089 }
2090
2091 // write space-points to the ESD in case alignment data output
2092 // is switched on
2093 if (fWriteAlignmentData)
2094 WriteAlignmentData(esd);
2095
2096 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2097 if (!fTracker[iDet]) continue;
b8cd5251 2098 // unload clusters
2099 fTracker[iDet]->UnloadClusters();
6efecea1 2100 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 2101 fLoader[iDet]->UnloadRecPoints();
6efecea1 2102 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 2103 }
283f39c6 2104 // stop filling residuals for TPC and ITS
3b378a42 2105 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
854c6476 2106
0f88822a 2107 eventNr++;
596a855f 2108 return kTRUE;
2109}
2110
d64bd07d 2111//_____________________________________________________________________________
2112Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
2113 //
2114 // Remove the data which are not needed for the physics analysis.
2115 //
2116
d64bd07d 2117 Int_t nTracks=esd->GetNumberOfTracks();
18571674 2118 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 2119 AliInfo
2120 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 2121
18571674 2122 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 2123 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 2124
7f68891d 2125 nTracks=esd->GetNumberOfTracks();
18571674 2126 nV0s=esd->GetNumberOfV0s();
cf37fd88 2127 AliInfo
ae5d5566 2128 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 2129
7f68891d 2130 return rc;
d64bd07d 2131}
2132
596a855f 2133//_____________________________________________________________________________
af885e0f 2134Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 2135{
2136// fill the event summary data
2137
87932dab 2138 AliCodeTimerAuto("")
0f88822a 2139 static Int_t eventNr=0;
596a855f 2140 TString detStr = detectors;
abe0c04e 2141
b8cd5251 2142 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
abe0c04e 2143 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 2144 AliReconstructor* reconstructor = GetReconstructor(iDet);
2145 if (!reconstructor) continue;
4b71572b 2146 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
2147 TTree* clustersTree = NULL;
2148 if (fLoader[iDet]) {
2149 fLoader[iDet]->LoadRecPoints("read");
2150 clustersTree = fLoader[iDet]->TreeR();
2151 if (!clustersTree) {
2152 AliError(Form("Can't get the %s clusters tree",
2153 fgkDetectorName[iDet]));
2154 if (fStopOnError) return kFALSE;
2155 }
2156 }
2157 if (fRawReader && !reconstructor->HasDigitConversion()) {
2158 reconstructor->FillESD(fRawReader, clustersTree, esd);
2159 } else {
2160 TTree* digitsTree = NULL;
d76c31f4 2161 if (fLoader[iDet]) {
4b71572b 2162 fLoader[iDet]->LoadDigits("read");
2163 digitsTree = fLoader[iDet]->TreeD();
2164 if (!digitsTree) {
2165 AliError(Form("Can't get the %s digits tree",
b26c3770 2166 fgkDetectorName[iDet]));
2167 if (fStopOnError) return kFALSE;
2168 }
2169 }
4b71572b 2170 reconstructor->FillESD(digitsTree, clustersTree, esd);
2171 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
2172 }
2173 if (fLoader[iDet]) {
2174 fLoader[iDet]->UnloadRecPoints();
596a855f 2175 }
2176 }
2177
2178 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 2179 AliError(Form("the following detectors were not found: %s",
2180 detStr.Data()));
596a855f 2181 if (fStopOnError) return kFALSE;
2182 }
6efecea1 2183 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
0f88822a 2184 eventNr++;
596a855f 2185 return kTRUE;
2186}
2187
b647652d 2188//_____________________________________________________________________________
af885e0f 2189Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 2190{
2191 // Reads the trigger decision which is
2192 // stored in Trigger.root file and fills
2193 // the corresponding esd entries
2194
87932dab 2195 AliCodeTimerAuto("")
2196
b647652d 2197 AliInfo("Filling trigger information into the ESD");
2198
2199 if (fRawReader) {
2200 AliCTPRawStream input(fRawReader);
2201 if (!input.Next()) {
7e88424f 2202 AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
b647652d 2203 }
2204 else {
7e88424f 2205 if (esd->GetTriggerMask() != input.GetClassMask())
2206 AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
2207 input.GetClassMask(),esd->GetTriggerMask()));
2208 if (esd->GetOrbitNumber() != input.GetOrbitID())
2209 AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
2210 input.GetOrbitID(),esd->GetOrbitNumber()));
2211 if (esd->GetBunchCrossNumber() != input.GetBCID())
2212 AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
2213 input.GetBCID(),esd->GetBunchCrossNumber()));
b647652d 2214 }
b024fd7f 2215
7e88424f 2216 // Here one has to add the filling of trigger inputs and
2217 // interaction records
2218 // ...
b024fd7f 2219 }
b647652d 2220 return kTRUE;
2221}
596a855f 2222
001397cd 2223
2224
2225
2226
2227//_____________________________________________________________________________
af885e0f 2228Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 2229{
2230 //
2231 // Filling information from RawReader Header
2232 //
2233
151bea4e 2234 if (!fRawReader) return kFALSE;
2235
001397cd 2236 AliInfo("Filling information from RawReader Header");
151bea4e 2237
2238 esd->SetBunchCrossNumber(fRawReader->GetBCID());
2239 esd->SetOrbitNumber(fRawReader->GetOrbitID());
2240 esd->SetPeriodNumber(fRawReader->GetPeriod());
2241
2242 esd->SetTimeStamp(fRawReader->GetTimestamp());
2243 esd->SetEventType(fRawReader->GetType());
001397cd 2244
2245 return kTRUE;
2246}
2247
2248
596a855f 2249//_____________________________________________________________________________
2250Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
2251{
2252// check whether detName is contained in detectors
2253// if yes, it is removed from detectors
2254
2255 // check if all detectors are selected
2256 if ((detectors.CompareTo("ALL") == 0) ||
2257 detectors.BeginsWith("ALL ") ||
2258 detectors.EndsWith(" ALL") ||
2259 detectors.Contains(" ALL ")) {
2260 detectors = "ALL";
2261 return kTRUE;
2262 }
2263
2264 // search for the given detector
2265 Bool_t result = kFALSE;
2266 if ((detectors.CompareTo(detName) == 0) ||
2267 detectors.BeginsWith(detName+" ") ||
2268 detectors.EndsWith(" "+detName) ||
2269 detectors.Contains(" "+detName+" ")) {
2270 detectors.ReplaceAll(detName, "");
2271 result = kTRUE;
2272 }
2273
2274 // clean up the detectors string
2275 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2276 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2277 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2278
2279 return result;
2280}
e583c30d 2281
f08fc9f5 2282//_____________________________________________________________________________
2283Bool_t AliReconstruction::InitRunLoader()
2284{
2285// get or create the run loader
2286
2287 if (gAlice) delete gAlice;
2288 gAlice = NULL;
2289
b26c3770 2290 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2291 // load all base libraries to get the loader classes
2292 TString libs = gSystem->GetLibraries();
2293 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2294 TString detName = fgkDetectorName[iDet];
2295 if (detName == "HLT") continue;
2296 if (libs.Contains("lib" + detName + "base.so")) continue;
2297 gSystem->Load("lib" + detName + "base.so");
2298 }
f08fc9f5 2299 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2300 if (!fRunLoader) {
2301 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2302 CleanUp();
2303 return kFALSE;
2304 }
325aa76f 2305
b26c3770 2306 fRunLoader->CdGAFile();
325aa76f 2307 fRunLoader->LoadgAlice();
f08fc9f5 2308
6cae184e 2309 //PH This is a temporary fix to give access to the kinematics
2310 //PH that is needed for the labels of ITS clusters
f2ee4290 2311 fRunLoader->LoadHeader();
6cae184e 2312 fRunLoader->LoadKinematics();
2313
f08fc9f5 2314 } else { // galice.root does not exist
2315 if (!fRawReader) {
2316 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
f08fc9f5 2317 }
2318 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2319 AliConfig::GetDefaultEventFolderName(),
2320 "recreate");
2321 if (!fRunLoader) {
2322 AliError(Form("could not create run loader in file %s",
2323 fGAliceFileName.Data()));
2324 CleanUp();
2325 return kFALSE;
2326 }
21a3aa09 2327 fIsNewRunLoader = kTRUE;
f08fc9f5 2328 fRunLoader->MakeTree("E");
21a3aa09 2329
973388c2 2330 if (fNumberOfEventsPerFile > 0)
2331 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2332 else
21a3aa09 2333 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 2334 }
2335
2336 return kTRUE;
2337}
2338
c757bafd 2339//_____________________________________________________________________________
b8cd5251 2340AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 2341{
f08fc9f5 2342// get the reconstructor object and the loader for a detector
c757bafd 2343
7e88424f 2344 if (fReconstructor[iDet]) {
2345 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2346 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2347 fReconstructor[iDet]->SetRecoParam(par);
2348 }
2349 return fReconstructor[iDet];
2350 }
b8cd5251 2351
2352 // load the reconstructor object
2353 TPluginManager* pluginManager = gROOT->GetPluginManager();
2354 TString detName = fgkDetectorName[iDet];
2355 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 2356
2357 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 2358
b8cd5251 2359 AliReconstructor* reconstructor = NULL;
2360 // first check if a plugin is defined for the reconstructor
2361 TPluginHandler* pluginHandler =
2362 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 2363 // if not, add a plugin for it
2364 if (!pluginHandler) {
b8cd5251 2365 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 2366 TString libs = gSystem->GetLibraries();
2367 if (libs.Contains("lib" + detName + "base.so") ||
2368 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 2369 pluginManager->AddHandler("AliReconstructor", detName,
2370 recName, detName + "rec", recName + "()");
2371 } else {
2372 pluginManager->AddHandler("AliReconstructor", detName,
2373 recName, detName, recName + "()");
c757bafd 2374 }
b8cd5251 2375 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2376 }
2377 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2378 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 2379 }
b8cd5251 2380 if (reconstructor) {
2381 TObject* obj = fOptions.FindObject(detName.Data());
2382 if (obj) reconstructor->SetOption(obj->GetTitle());
d76c31f4 2383 reconstructor->Init();
b8cd5251 2384 fReconstructor[iDet] = reconstructor;
2385 }
2386
f08fc9f5 2387 // get or create the loader
2388 if (detName != "HLT") {
2389 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2390 if (!fLoader[iDet]) {
2391 AliConfig::Instance()
2392 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2393 detName, detName);
2394 // first check if a plugin is defined for the loader
bb0901a4 2395 pluginHandler =
f08fc9f5 2396 pluginManager->FindHandler("AliLoader", detName);
2397 // if not, add a plugin for it
2398 if (!pluginHandler) {
2399 TString loaderName = "Ali" + detName + "Loader";
2400 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2401 pluginManager->AddHandler("AliLoader", detName,
2402 loaderName, detName + "base",
2403 loaderName + "(const char*, TFolder*)");
2404 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2405 }
2406 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2407 fLoader[iDet] =
2408 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2409 fRunLoader->GetEventFolder());
2410 }
2411 if (!fLoader[iDet]) { // use default loader
2412 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2413 }
2414 if (!fLoader[iDet]) {
2415 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 2416 if (fStopOnError) return NULL;
f08fc9f5 2417 } else {
2418 fRunLoader->AddLoader(fLoader[iDet]);
2419 fRunLoader->CdGAFile();
2420 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2421 fRunLoader->Write(0, TObject::kOverwrite);
2422 }
2423 }
2424 }
2425
7e88424f 2426 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2427 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2428 reconstructor->SetRecoParam(par);
2429 }
b8cd5251 2430 return reconstructor;
c757bafd 2431}
2432
2257f27e 2433//_____________________________________________________________________________
2434Bool_t AliReconstruction::CreateVertexer()
2435{
2436// create the vertexer
2437
b8cd5251 2438 fVertexer = NULL;
2439 AliReconstructor* itsReconstructor = GetReconstructor(0);
59697224 2440 if (itsReconstructor) {
d76c31f4 2441 fVertexer = itsReconstructor->CreateVertexer();
2257f27e 2442 }
b8cd5251 2443 if (!fVertexer) {
815c2b38 2444 AliWarning("couldn't create a vertexer for ITS");
2257f27e 2445 if (fStopOnError) return kFALSE;
2446 }
2447
2448 return kTRUE;
2449}
2450
24f7a148 2451//_____________________________________________________________________________
b8cd5251 2452Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 2453{
f08fc9f5 2454// create the trackers
24f7a148 2455
b8cd5251 2456 TString detStr = detectors;
2457 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2458 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2459 AliReconstructor* reconstructor = GetReconstructor(iDet);
2460 if (!reconstructor) continue;
2461 TString detName = fgkDetectorName[iDet];
1f46a9ae 2462 if (detName == "HLT") {
2463 fRunHLTTracking = kTRUE;
2464 continue;
2465 }
e66fbafb 2466 if (detName == "MUON") {
2467 fRunMuonTracking = kTRUE;
2468 continue;
2469 }
2470
f08fc9f5 2471
d76c31f4 2472 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 2473 if (!fTracker[iDet] && (iDet < 7)) {
2474 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 2475 if (fStopOnError) return kFALSE;
2476 }
6efecea1 2477 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 2478 }
2479
24f7a148 2480 return kTRUE;
2481}
2482
e583c30d 2483//_____________________________________________________________________________
4b71572b 2484void AliReconstruction::CleanUp()
e583c30d 2485{
2486// delete trackers and the run loader and close and delete the file
2487
b8cd5251 2488 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2489 delete fReconstructor[iDet];
2490 fReconstructor[iDet] = NULL;
2491 fLoader[iDet] = NULL;
2492 delete fTracker[iDet];
2493 fTracker[iDet] = NULL;
2494 }
4b71572b 2495 delete fRunInfo;
7e88424f 2496 fRunInfo = NULL;
2497
b8cd5251 2498 delete fVertexer;
2499 fVertexer = NULL;
21a3aa09 2500
4b71572b 2501 delete ftVertexer;
21a3aa09 2502 ftVertexer = NULL;
795e4a22 2503
2504 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
4b71572b 2505 delete fDiamondProfile;
2506 fDiamondProfile = NULL;
2507 delete fDiamondProfileTPC;
2508 fDiamondProfileTPC = NULL;
795e4a22 2509 }
4b71572b 2510 delete fGRPData;
2511 fGRPData = NULL;
444753c6 2512
e583c30d 2513 delete fRunLoader;
2514 fRunLoader = NULL;
b649205a 2515 delete fRawReader;
2516 fRawReader = NULL;
4b71572b 2517 delete fParentRawReader;
cd0b062e 2518 fParentRawReader=NULL;
e583c30d 2519
4b71572b 2520 if (ffile) {
2521 ffile->Close();
2522 delete ffile;
2523 ffile = NULL;
24f7a148 2524 }
24f7a148 2525}
f3a97c86 2526
af885e0f 2527void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 2528{
2529 // Write space-points which are then used in the alignment procedures
6e65648b 2530 // For the moment only ITS, TPC, TRD and TOF
98937d93 2531
98937d93 2532 Int_t ntracks = esd->GetNumberOfTracks();
2533 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2534 {
2535 AliESDtrack *track = esd->GetTrack(itrack);
2536 Int_t nsp = 0;
ef7253ac 2537 Int_t idx[200];
6e65648b 2538 for (Int_t iDet = 3; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
2539 nsp += track->GetNcls(iDet);
2540
2541 if (iDet==0) { // ITS "extra" clusters
2542 track->GetClusters(iDet,idx);
2543 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
2544 }
2545 }
2546
98937d93 2547 if (nsp) {
2548 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2549 track->SetTrackPointArray(sp);
2550 Int_t isptrack = 0;
2551 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2552 AliTracker *tracker = fTracker[iDet];
2553 if (!tracker) continue;
6e65648b 2554 Int_t nspdet = track->GetClusters(iDet,idx);
2555
2556 if (iDet==0) // ITS "extra" clusters
2557 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
2558
98937d93 2559 if (nspdet <= 0) continue;
98937d93 2560 AliTrackPoint p;
2561 Int_t isp = 0;
2562 Int_t isp2 = 0;
4ed6fb1c 2563 while (isp2 < nspdet) {
f3c6e4c9 2564 Bool_t isvalid=kTRUE;
2565
2566 Int_t index=idx[isp++];
2567 if (index < 0) continue;
2568
c12b6e44 2569 TString dets = fgkDetectorName[iDet];
2570 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2571 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2572 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2573 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
f3c6e4c9 2574 isvalid = tracker->GetTrackPointTrackingError(index,p,track);
48ce48d1 2575 } else {
f3c6e4c9 2576 isvalid = tracker->GetTrackPoint(index,p);
48ce48d1 2577 }
2578 isp2++;
98937d93 2579 if (!isvalid) continue;
f3c6e4c9 2580 sp->AddPoint(isptrack,&p); isptrack++;
98937d93 2581 }
98937d93 2582 }
2583 }
2584 }
98937d93 2585}
2e3550da 2586
2587//_____________________________________________________________________________
af885e0f 2588void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 2589{
2590 // The method reads the raw-data error log
2591 // accumulated within the rawReader.
2592 // It extracts the raw-data errors related to
2593 // the current event and stores them into
2594 // a TClonesArray inside the esd object.
2595
2596 if (!fRawReader) return;
2597
2598 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2599
2600 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2601 if (!log) continue;
2602 if (iEvent != log->GetEventNumber()) continue;
2603
2604 esd->AddRawDataErrorLog(log);
2605 }
2606
2607}
46698ae4 2608
605cb8bb 2609TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString pName){
b545009a 2610 // Dump a file content into a char in TNamed
46698ae4 2611 ifstream in;
2612 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2613 Int_t kBytes = (Int_t)in.tellg();
2614 printf("Size: %d \n",kBytes);
2615 TNamed *fn = 0;
2616 if(in.good()){
2617 char* memblock = new char [kBytes];
2618 in.seekg (0, ios::beg);
2619 in.read (memblock, kBytes);
2620 in.close();
2621 TString fData(memblock,kBytes);
605cb8bb 2622 fn = new TNamed(pName,fData);
46698ae4 2623 printf("fData Size: %d \n",fData.Sizeof());
605cb8bb 2624 printf("pName Size: %d \n",pName.Sizeof());
46698ae4 2625 printf("fn Size: %d \n",fn->Sizeof());
2626 delete[] memblock;
2627 }
2628 else{
2629 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2630 }
2631
2632 return fn;
2633}
2634
605cb8bb 2635void AliReconstruction::TNamedToFile(TTree* fTree, TString pName){
46698ae4 2636 // This is not really needed in AliReconstruction at the moment
2637 // but can serve as a template
2638
2639 TList *fList = fTree->GetUserInfo();
605cb8bb 2640 TNamed *fn = (TNamed*)fList->FindObject(pName.Data());
46698ae4 2641 printf("fn Size: %d \n",fn->Sizeof());
2642
605cb8bb 2643 TString fTmp(fn->GetName()); // to be 100% sure in principle pName also works
46698ae4 2644 const char* cdata = fn->GetTitle();
2645 printf("fTmp Size %d\n",fTmp.Sizeof());
2646
2647 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2648 printf("calculated size %d\n",size);
605cb8bb 2649 ofstream out(pName.Data(),ios::out | ios::binary);
46698ae4 2650 out.write(cdata,size);
2651 out.close();
2652
2653}
6efecea1 2654
8661738e 2655//_____________________________________________________________________________
2656void AliReconstruction::CheckQA()
2657{
2658// check the QA of SIM for this run and remove the detectors
2659// with status Fatal
2660
abe0c04e 2661 TString newRunLocalReconstruction ;
2662 TString newRunTracking ;
2663 TString newFillESD ;
2664
8661738e 2665 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2666 TString detName(AliQA::GetDetName(iDet)) ;
96d67a8d 2667 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2668 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
8661738e 2669 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
abe0c04e 2670 } else {
2671 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2672 fRunLocalReconstruction.Contains("ALL") ) {
2673 newRunLocalReconstruction += detName ;
2674 newRunLocalReconstruction += " " ;
2675 }
2676 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2677 fRunTracking.Contains("ALL") ) {
2678 newRunTracking += detName ;
2679 newRunTracking += " " ;
2680 }
2681 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2682 fFillESD.Contains("ALL") ) {
2683 newFillESD += detName ;
2684 newFillESD += " " ;
8661738e 2685 }
2686 }
2687 }
abe0c04e 2688 fRunLocalReconstruction = newRunLocalReconstruction ;
2689 fRunTracking = newRunTracking ;
2690 fFillESD = newFillESD ;
a5fa6165 2691}
5b188f2f 2692
2693//_____________________________________________________________________________
2694Int_t AliReconstruction::GetDetIndex(const char* detector)
2695{
2696 // return the detector index corresponding to detector
2697 Int_t index = -1 ;
2698 for (index = 0; index < fgkNDetectors ; index++) {
2699 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2700 break ;
2701 }
2702 return index ;
2703}
7167ae53 2704//_____________________________________________________________________________
2705Bool_t AliReconstruction::FinishPlaneEff() {
2706 //
2707 // Here execute all the necessary operationis, at the end of the tracking phase,
d7f8fd68 2708 // in case that evaluation of PlaneEfficiencies was required for some detector.
2709 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
7167ae53 2710 //
2711 // This Preliminary version works only FOR ITS !!!!!
2712 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2713 //
2714 // Input: none
d7f8fd68 2715 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
7167ae53 2716 //
2717 Bool_t ret=kFALSE;
2718 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
d7f8fd68 2719 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
7167ae53 2720 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
5fbd4fd6 2721 if(fTracker[iDet]) {
d7f8fd68 2722 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2723 TString name=planeeff->GetName();
2724 name+=".root";
2725 TFile* pefile = TFile::Open(name, "RECREATE");
2726 ret=(Bool_t)planeeff->Write();
2727 pefile->Close();
5fbd4fd6 2728 if(planeeff->GetCreateHistos()) {
d7f8fd68 2729 TString hname=planeeff->GetName();
2730 hname+="Histo.root";
2731 ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
5fbd4fd6 2732 }
2733 }
7167ae53 2734 }
2735 return ret;
2736}
2737//_____________________________________________________________________________
2738Bool_t AliReconstruction::InitPlaneEff() {
2739//
2740 // Here execute all the necessary operations, before of the tracking phase,
2741 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2742 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2743 // which should be updated/recalculated.
2744 //
2745 // This Preliminary version will work only FOR ITS !!!!!
2746 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2747 //
2748 // Input: none
2749 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2750 //
2751 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));
2752 return kTRUE;
7520312d 2753}
14dd053c 2754
2755//_____________________________________________________________________________
2756Bool_t AliReconstruction::InitAliEVE()
2757{
2758 // This method should be called only in case
2759 // AliReconstruction is run
2760 // within the alieve environment.
2761 // It will initialize AliEVE in a way
2762 // so that it can visualize event processed
2763 // by AliReconstruction.
2764 // The return flag shows whenever the
2765 // AliEVE initialization was successful or not.
2766
2767 TString macroStr;
2768 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
2769 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
2770 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
2771
de33999e 2772 gROOT->ProcessLine("if (!gAliEveEvent) {gAliEveEvent = new AliEveEventManager();gAliEveEvent->SetAutoLoad(kTRUE);gAliEveEvent->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(gAliEveEvent);};");
2773 gROOT->ProcessLine("alieve_online_init()");
14dd053c 2774
2775 return kTRUE;
2776}
2777
2778//_____________________________________________________________________________
2779void AliReconstruction::RunAliEVE()
2780{
2781 // Runs AliEVE visualisation of
2782 // the current event.
2783 // Should be executed only after
2784 // successful initialization of AliEVE.
2785
2786 AliInfo("Running AliEVE...");
2787 gROOT->ProcessLine(Form("gAliEveEvent->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p);",fRunLoader,fRawReader,fesd));
2788 gROOT->ProcessLine("gAliEveEvent->StartStopAutoLoadTimer();");
2789 gSystem->Run();
2790}
ce43afbe 2791
2792//_____________________________________________________________________________
2793Bool_t AliReconstruction::SetRunQA(TString detAndAction)
2794{
2795 // Allows to run QA for a selected set of detectors
2796 // and a selected set of tasks among RAWS, RECPOINTS and ESDS
2797 // all selected detectors run the same selected tasks
2798
2799 if (!detAndAction.Contains(":")) {
2800 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
2801 fRunQA = kFALSE ;
2802 return kFALSE ;
2803 }
2804 Int_t colon = detAndAction.Index(":") ;
2805 fQADetectors = detAndAction(0, colon) ;
2806 if (fQADetectors.Contains("ALL") )
2807 fQADetectors = fFillESD ;
e84c88f5 2808 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
ce43afbe 2809 if (fQATasks.Contains("ALL") ) {
2810 fQATasks = Form("%d %d %d", AliQA::kRAWS, AliQA::kRECPOINTS, AliQA::kESDS) ;
2811 } else {
2812 fQATasks.ToUpper() ;
2813 TString tempo("") ;
2814 if ( fQATasks.Contains("RAW") )
2815 tempo = Form("%d ", AliQA::kRAWS) ;
2816 if ( fQATasks.Contains("RECPOINT") )
2817 tempo += Form("%d ", AliQA::kRECPOINTS) ;
2818 if ( fQATasks.Contains("ESD") )
2819 tempo += Form("%d ", AliQA::kESDS) ;
2820 fQATasks = tempo ;
2821 if (fQATasks.IsNull()) {
2822 AliInfo("No QA requested\n") ;
2823 fRunQA = kFALSE ;
2824 return kTRUE ;
2825 }
2826 }
2827 TString tempo(fQATasks) ;
e84c88f5 2828 tempo.ReplaceAll(Form("%d", AliQA::kRAWS), AliQA::GetTaskName(AliQA::kRAWS)) ;
2829 tempo.ReplaceAll(Form("%d", AliQA::kRECPOINTS), AliQA::GetTaskName(AliQA::kRECPOINTS)) ;
2830 tempo.ReplaceAll(Form("%d", AliQA::kESDS), AliQA::GetTaskName(AliQA::kESDS)) ;
ce43afbe 2831 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
2832 fRunQA = kTRUE ;
2833 return kTRUE;
2834}
2835
7e88424f 2836//_____________________________________________________________________________
2837Bool_t AliReconstruction::InitRecoParams()
2838{
2839 // The method accesses OCDB and retrieves all
2840 // the available reco-param objects from there.
2841
2842 Bool_t isOK = kTRUE;
2843
2844 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2845
2846 if (fRecoParam.GetDetRecoParamArray(iDet)) {
2847 AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
2848 continue;
2849 }
2850
ac232c75 2851 AliInfo(Form("Loading reconstruction parameter objects for detector %s",fgkDetectorName[iDet]));
7e88424f 2852
2853 AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
2854 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
2855 if(!entry){
2856 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
2857 isOK = kFALSE;
2858 }
2859 else {
2860 TObject *recoParamObj = entry->GetObject();
2861 if (dynamic_cast<TObjArray*>(recoParamObj)) {
2862 // The detector has a normal TobjArray of AliDetectorRecoParam objects
2863 // Registering them in AliRecoParam
2864 fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
2865 }
2866 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
2867 // The detector has only onse set of reco parameters
2868 // Registering it in AliRecoParam
ac232c75 2869 AliInfo(Form("Single set of reconstruction parameters found for detector %s",fgkDetectorName[iDet]));
7e88424f 2870 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
2871 fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
2872 }
2873 else {
2874 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
2875 isOK = kFALSE;
2876 }
2877 entry->SetOwner(0);
4b71572b 2878 AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
7e88424f 2879 }
2880 }
2881
ac232c75 2882 fRecoParam.Print();
2883
7e88424f 2884 return isOK;
2885}
2886
2887//_____________________________________________________________________________
2888Bool_t AliReconstruction::GetEventInfo()
2889{
2890 // Fill the event info object
2891 // ...
2892 AliCodeTimerAuto("")
2893
2894 AliCentralTrigger *aCTP = NULL;
2895 if (fRawReader) {
2896 fEventInfo.SetEventType(fRawReader->GetType());
2897
2898 ULong64_t mask = fRawReader->GetClassMask();
2899 fEventInfo.SetTriggerMask(mask);
2900 UInt_t clmask = fRawReader->GetDetectorPattern()[0];
2901 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
2902
2903 aCTP = new AliCentralTrigger();
2904 TString configstr("");
2905 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
2906 AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
2907 delete aCTP;
2908 return kFALSE;
2909 }
2910 aCTP->SetClassMask(mask);
2911 aCTP->SetClusterMask(clmask);
2912 }
2913 else {
2914 fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
2915
2916 if (fRunLoader && (!fRunLoader->LoadTrigger())) {
2917 aCTP = fRunLoader->GetTrigger();
2918 fEventInfo.SetTriggerMask(aCTP->GetClassMask());
2919 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
2920 }
2921 else {
2922 AliWarning("No trigger can be loaded! The trigger information will not be used!");
2923 return kFALSE;
2924 }
2925 }
2926
2927 AliTriggerConfiguration *config = aCTP->GetConfiguration();
2928 if (!config) {
2929 AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
2930 if (fRawReader) delete aCTP;
2931 return kFALSE;
2932 }
2933
a0c2cf2d 2934 UChar_t clustmask = 0;
7e88424f 2935 TString trclasses;
2936 ULong64_t trmask = fEventInfo.GetTriggerMask();
2937 const TObjArray& classesArray = config->GetClasses();
2938 Int_t nclasses = classesArray.GetEntriesFast();
2939 for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
2940 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
2941 if (trclass) {
2942 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
2943 fesd->SetTriggerClass(trclass->GetName(),trindex);
2944 if (trmask & (1 << trindex)) {
2945 trclasses += " ";
2946 trclasses += trclass->GetName();
2947 trclasses += " ";
a0c2cf2d 2948 clustmask |= trclass->GetCluster()->GetClusterMask();
7e88424f 2949 }
2950 }
2951 }
2952 fEventInfo.SetTriggerClasses(trclasses);
2953
a0c2cf2d 2954 // Set the information in ESD
2955 fesd->SetTriggerMask(trmask);
2956 fesd->SetTriggerCluster(clustmask);
2957
7e88424f 2958 if (!aCTP->CheckTriggeredDetectors()) {
2959 if (fRawReader) delete aCTP;
2960 return kFALSE;
2961 }
2962
2963 if (fRawReader) delete aCTP;
2964
2965 // We have to fill also the HLT decision here!!
2966 // ...
2967
2968 return kTRUE;
2969}
2970
2971const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
2972{
2973 // Match the detector list found in the rec.C or the default 'ALL'
2974 // to the list found in the GRP (stored there by the shuttle PP which
2975 // gets the information from ECS)
2976 static TString resultList;
2977 TString detList = detectorList;
2978
2979 resultList = "";
2980
2981 for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
2982 if ((detectorMask >> iDet) & 0x1) {
2983 TString det = AliDAQ::OfflineModuleName(iDet);
2984 if ((detList.CompareTo("ALL") == 0) ||
2985 detList.BeginsWith("ALL ") ||
2986 detList.EndsWith(" ALL") ||
2987 detList.Contains(" ALL ") ||
2988 (detList.CompareTo(det) == 0) ||
2989 detList.BeginsWith(det) ||
2990 detList.EndsWith(det) ||
2991 detList.Contains( " "+det+" " )) {
2992 if (!resultList.EndsWith(det + " ")) {
2993 resultList += det;
2994 resultList += " ";
2995 }
2996 }
2997 }
2998 }
2999
3000 // HLT
3001 if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
3002 TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
3003 if ((detList.CompareTo("ALL") == 0) ||
3004 detList.BeginsWith("ALL ") ||
3005 detList.EndsWith(" ALL") ||
3006 detList.Contains(" ALL ") ||
3007 (detList.CompareTo(hltDet) == 0) ||
3008 detList.BeginsWith(hltDet) ||
3009 detList.EndsWith(hltDet) ||
3010 detList.Contains( " "+hltDet+" " )) {
3011 resultList += hltDet;
3012 }
3013 }
3014
3015 return resultList.Data();
3016
3017}
4b71572b 3018
3019//______________________________________________________________________________
3020void AliReconstruction::Abort(const char *method, EAbort what)
3021{
3022 // Abort processing. If what = kAbortProcess, the Process() loop will be
3023 // aborted. If what = kAbortFile, the current file in a chain will be
3024 // aborted and the processing will continue with the next file, if there
3025 // is no next file then Process() will be aborted. Abort() can also be
3026 // called from Begin(), SlaveBegin(), Init() and Notify(). After abort
3027 // the SlaveTerminate() and Terminate() are always called. The abort flag
3028 // can be checked in these methods using GetAbort().
3029 //
3030 // The method is overwritten in AliReconstruction for better handling of
3031 // reco specific errors
3032
3033 if (!fStopOnError) return;
3034
3035 CleanUp();
3036
3037 TString whyMess = method;
3038 whyMess += " failed! Aborting...";
3039
3040 AliError(whyMess.Data());
3041
3042 fAbort = what;
3043 TString mess = "Abort";
3044 if (fAbort == kAbortProcess)
3045 mess = "AbortProcess";
3046 else if (fAbort == kAbortFile)
3047 mess = "AbortFile";
3048
3049 Info(mess, whyMess.Data());
3050}
3051