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