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