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