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