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