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