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