]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliReconstruction.cxx
changing smoothing sigma for AliRelAlegnerKalman
[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>
0a035be5 132#include <TUrl.h>
596a855f 133
f7a1cc68 134#include "AliAlignObj.h"
135#include "AliCDBEntry.h"
136#include "AliCDBManager.h"
137#include "AliCDBStorage.h"
138#include "AliCTPRawStream.h"
139#include "AliCascadeVertexer.h"
140#include "AliCentralTrigger.h"
87932dab 141#include "AliCodeTimer.h"
f7a1cc68 142#include "AliDAQ.h"
143#include "AliDetectorRecoParam.h"
144#include "AliESDCaloCells.h"
145#include "AliESDCaloCluster.h"
af885e0f 146#include "AliESDEvent.h"
faffd83e 147#include "AliESDMuonTrack.h"
f7a1cc68 148#include "AliESDPmdTrack.h"
149#include "AliESDTagCreator.h"
2257f27e 150#include "AliESDVertex.h"
faffd83e 151#include "AliESDcascade.h"
f7a1cc68 152#include "AliESDfriend.h"
faffd83e 153#include "AliESDkink.h"
596a855f 154#include "AliESDpid.h"
ff8bb5ae 155#include "AliESDtrack.h"
f7a1cc68 156#include "AliESDtrack.h"
157#include "AliEventInfo.h"
158#include "AliGRPObject.h"
159#include "AliGRPRecoParam.h"
160#include "AliGenEventHeader.h"
25be1e5c 161#include "AliGeomManager.h"
aa3c69a9 162#include "AliGlobalQADataMaker.h"
f7a1cc68 163#include "AliHeader.h"
164#include "AliLog.h"
165#include "AliMagF.h"
166#include "AliMultiplicity.h"
167#include "AliPID.h"
168#include "AliPlaneEff.h"
4e25ac79 169#include "AliQAv1.h"
f7a1cc68 170#include "AliQADataMakerRec.h"
b03591ab 171#include "AliQAManager.h"
33314186 172#include "AliRawVEvent.h"
f7a1cc68 173#include "AliRawEventHeaderBase.h"
cd0b062e 174#include "AliRawHLTManager.h"
f7a1cc68 175#include "AliRawReaderDate.h"
176#include "AliRawReaderFile.h"
177#include "AliRawReaderRoot.h"
178#include "AliReconstruction.h"
179#include "AliReconstructor.h"
180#include "AliRun.h"
7e88424f 181#include "AliRunInfo.h"
f7a1cc68 182#include "AliRunLoader.h"
183#include "AliSysInfo.h" // memory snapshots
184#include "AliTrackPointArray.h"
185#include "AliTracker.h"
186#include "AliTriggerClass.h"
187#include "AliTriggerCluster.h"
a6dd87ad 188#include "AliTriggerIR.h"
f7a1cc68 189#include "AliTriggerConfiguration.h"
190#include "AliV0vertexer.h"
191#include "AliVertexer.h"
192#include "AliVertexerTracks.h"
52dd4a8c 193#include "AliTriggerRunScalers.h"
194#include "AliCTPTimeParams.h"
8b12d288 195#include "AliESDHLTDecision.h"
6ef9caeb 196#include "AliTriggerInput.h"
3d84ad67 197#include "AliLHCData.h"
596a855f 198ClassImp(AliReconstruction)
199
c757bafd 200//_____________________________________________________________________________
ac4a7581 201const char* AliReconstruction::fgkDetectorName[AliReconstruction::kNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
c757bafd 202
596a855f 203//_____________________________________________________________________________
4b71572b 204AliReconstruction::AliReconstruction(const char* gAliceFilename) :
205 TSelector(),
2257f27e 206 fRunVertexFinder(kTRUE),
a84e2607 207 fRunVertexFinderTracks(kTRUE),
1f46a9ae 208 fRunHLTTracking(kFALSE),
e66fbafb 209 fRunMuonTracking(kFALSE),
d1683eef 210 fRunV0Finder(kTRUE),
211 fRunCascadeFinder(kTRUE),
c8025cc8 212 fStopOnError(kTRUE),
1d99986f 213 fWriteAlignmentData(kFALSE),
214 fWriteESDfriend(kFALSE),
b647652d 215 fFillTriggerESD(kTRUE),
1d99986f 216
7f68891d 217 fCleanESD(kTRUE),
a023d8d8 218 fV0DCAmax(3.),
219 fV0CsPmin(0.),
7f68891d 220 fDmax(50.),
221 fZmax(50.),
222
1d99986f 223 fRunLocalReconstruction("ALL"),
b8cd5251 224 fRunTracking("ALL"),
e583c30d 225 fFillESD("ALL"),
7d566c20 226 fLoadCDB(""),
48ce48d1 227 fUseTrackingErrorsForAlignment(""),
e583c30d 228 fGAliceFileName(gAliceFilename),
4b71572b 229 fRawInput(""),
975320a0 230 fESDOutput(""),
81d57268 231 fProofOutputFileName(""),
232 fProofOutputLocation(""),
233 fProofOutputDataset(kFALSE),
234 fProofOutputArchive(""),
35042093 235 fEquipIdMap(""),
b26c3770 236 fFirstEvent(0),
237 fLastEvent(-1),
9d705769 238 fNumberOfEventsPerFile((UInt_t)-1),
b8cd5251 239 fOptions(),
6bae477a 240 fLoadAlignFromCDB(kTRUE),
241 fLoadAlignData("ALL"),
cd0b062e 242 fUseHLTData(),
7e88424f 243 fRunInfo(NULL),
244 fEventInfo(),
522fdd91 245 fRunScalers(NULL),
52dd4a8c 246 fCTPTimeParams(NULL),
e583c30d 247
248 fRunLoader(NULL),
b649205a 249 fRawReader(NULL),
cd0b062e 250 fParentRawReader(NULL),
b8cd5251 251
7e88424f 252 fRecoParam(),
253
58e8dc31 254 fSPDTrackleter(NULL),
255
f2a195c1 256 fDiamondProfileSPD(NULL),
9178838a 257 fDiamondProfile(NULL),
43c9dae1 258 fDiamondProfileTPC(NULL),
77ba28ba 259 fListOfCosmicTriggers(NULL),
f2a195c1 260
6b6e4472 261 fGRPData(NULL),
444753c6 262
6bae477a 263 fAlignObjArray(NULL),
795e4a22 264 fCDBUri(),
f1c1204d 265 fQARefUri(),
759c1df1 266 fSpecCDBUri(),
795e4a22 267 fInitCDBCalled(kFALSE),
268 fSetRunNumberFromDataCalled(kFALSE),
ce43afbe 269 fQADetectors("ALL"),
270 fQATasks("ALL"),
7e963665 271 fRunQA(kTRUE),
6b150027 272 fRunGlobalQA(kTRUE),
e4a998ed 273 fSameQACycle(kFALSE),
f1c1204d 274 fInitQACalled(kFALSE),
75373542 275 fWriteQAExpertData(kTRUE),
21a3aa09 276 fRunPlaneEff(kFALSE),
277
278 fesd(NULL),
279 fhltesd(NULL),
280 fesdf(NULL),
281 ffile(NULL),
ee7c441c 282 ffileF(NULL),
21a3aa09 283 ftree(NULL),
ee7c441c 284 ftreeF(NULL),
21a3aa09 285 fhlttree(NULL),
21a3aa09 286 ftVertexer(NULL),
14dd053c 287 fIsNewRunLoader(kFALSE),
4b71572b 288 fRunAliEVE(kFALSE),
289 fChain(NULL)
596a855f 290{
291// create reconstruction object with default parameters
002c9d1b 292 gGeoManager = NULL;
b8cd5251 293
ac4a7581 294 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 295 fReconstructor[iDet] = NULL;
296 fLoader[iDet] = NULL;
297 fTracker[iDet] = NULL;
298 }
4e25ac79 299 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
252f8aa8 300 fQACycles[iDet] = 999999 ;
301 fQAWriteExpert[iDet] = kFALSE ;
302 }
3d84ad67 303 fBeamInt[0][0]=fBeamInt[0][1]=fBeamInt[1][0]=fBeamInt[1][1] = -1;
304
e47c4c2e 305 AliPID pid;
596a855f 306}
307
308//_____________________________________________________________________________
309AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
4b71572b 310 TSelector(),
2257f27e 311 fRunVertexFinder(rec.fRunVertexFinder),
a84e2607 312 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
1f46a9ae 313 fRunHLTTracking(rec.fRunHLTTracking),
e66fbafb 314 fRunMuonTracking(rec.fRunMuonTracking),
d1683eef 315 fRunV0Finder(rec.fRunV0Finder),
316 fRunCascadeFinder(rec.fRunCascadeFinder),
1d99986f 317 fStopOnError(rec.fStopOnError),
318 fWriteAlignmentData(rec.fWriteAlignmentData),
319 fWriteESDfriend(rec.fWriteESDfriend),
b647652d 320 fFillTriggerESD(rec.fFillTriggerESD),
1d99986f 321
7f68891d 322 fCleanESD(rec.fCleanESD),
a023d8d8 323 fV0DCAmax(rec.fV0DCAmax),
5e5c1aa9 324 fV0CsPmin(rec.fV0CsPmin),
7f68891d 325 fDmax(rec.fDmax),
326 fZmax(rec.fZmax),
327
1d99986f 328 fRunLocalReconstruction(rec.fRunLocalReconstruction),
e583c30d 329 fRunTracking(rec.fRunTracking),
330 fFillESD(rec.fFillESD),
7d566c20 331 fLoadCDB(rec.fLoadCDB),
48ce48d1 332 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
e583c30d 333 fGAliceFileName(rec.fGAliceFileName),
4b71572b 334 fRawInput(rec.fRawInput),
975320a0 335 fESDOutput(rec.fESDOutput),
81d57268 336 fProofOutputFileName(rec.fProofOutputFileName),
337 fProofOutputLocation(rec.fProofOutputLocation),
338 fProofOutputDataset(rec.fProofOutputDataset),
339 fProofOutputArchive(rec.fProofOutputArchive),
35042093 340 fEquipIdMap(rec.fEquipIdMap),
b26c3770 341 fFirstEvent(rec.fFirstEvent),
342 fLastEvent(rec.fLastEvent),
973388c2 343 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
b8cd5251 344 fOptions(),
6bae477a 345 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
346 fLoadAlignData(rec.fLoadAlignData),
2972d4eb 347 fUseHLTData(rec.fUseHLTData),
7e88424f 348 fRunInfo(NULL),
349 fEventInfo(),
522fdd91 350 fRunScalers(NULL),
52dd4a8c 351 fCTPTimeParams(NULL),
e583c30d 352
353 fRunLoader(NULL),
b649205a 354 fRawReader(NULL),
2972d4eb 355 fParentRawReader(NULL),
b8cd5251 356
4b71572b 357 fRecoParam(rec.fRecoParam),
7e88424f 358
58e8dc31 359 fSPDTrackleter(NULL),
360
f2a195c1 361 fDiamondProfileSPD(rec.fDiamondProfileSPD),
4b71572b 362 fDiamondProfile(rec.fDiamondProfile),
363 fDiamondProfileTPC(rec.fDiamondProfileTPC),
77ba28ba 364 fListOfCosmicTriggers(NULL),
f2a195c1 365
6b6e4472 366 fGRPData(NULL),
444753c6 367
6bae477a 368 fAlignObjArray(rec.fAlignObjArray),
ec92bee0 369 fCDBUri(rec.fCDBUri),
f1c1204d 370 fQARefUri(rec.fQARefUri),
7e963665 371 fSpecCDBUri(),
795e4a22 372 fInitCDBCalled(rec.fInitCDBCalled),
373 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
ce43afbe 374 fQADetectors(rec.fQADetectors),
375 fQATasks(rec.fQATasks),
aa3c69a9 376 fRunQA(rec.fRunQA),
377 fRunGlobalQA(rec.fRunGlobalQA),
e4a998ed 378 fSameQACycle(rec.fSameQACycle),
f1c1204d 379 fInitQACalled(rec.fInitQACalled),
75373542 380 fWriteQAExpertData(rec.fWriteQAExpertData),
21a3aa09 381 fRunPlaneEff(rec.fRunPlaneEff),
382
383 fesd(NULL),
384 fhltesd(NULL),
385 fesdf(NULL),
386 ffile(NULL),
ee7c441c 387 ffileF(NULL),
21a3aa09 388 ftree(NULL),
ee7c441c 389 ftreeF(NULL),
21a3aa09 390 fhlttree(NULL),
21a3aa09 391 ftVertexer(NULL),
14dd053c 392 fIsNewRunLoader(rec.fIsNewRunLoader),
4b71572b 393 fRunAliEVE(kFALSE),
394 fChain(NULL)
596a855f 395{
396// copy constructor
397
ec92bee0 398 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
efd2085e 399 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
400 }
ac4a7581 401 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 402 fReconstructor[iDet] = NULL;
403 fLoader[iDet] = NULL;
404 fTracker[iDet] = NULL;
b1af1125 405 }
406
4e25ac79 407 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
b1af1125 408 fQACycles[iDet] = rec.fQACycles[iDet];
252f8aa8 409 fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
410 }
b1af1125 411
ec92bee0 412 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
413 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
414 }
3d84ad67 415
416 for (int i=2;i--;) for (int j=2;j--;) fBeamInt[i][j] = rec.fBeamInt[i][j];
417
596a855f 418}
419
420//_____________________________________________________________________________
421AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
422{
423// assignment operator
4b71572b 424// Used in PROOF mode
425// Be very careful while modifing it!
426// Simple rules to follow:
427// for persistent data members - use their assignment operators
428// for non-persistent ones - do nothing or take the default values from constructor
429// TSelector members should not be touched
430 if(&rec == this) return *this;
431
4b71572b 432 fRunVertexFinder = rec.fRunVertexFinder;
433 fRunVertexFinderTracks = rec.fRunVertexFinderTracks;
434 fRunHLTTracking = rec.fRunHLTTracking;
435 fRunMuonTracking = rec.fRunMuonTracking;
436 fRunV0Finder = rec.fRunV0Finder;
437 fRunCascadeFinder = rec.fRunCascadeFinder;
438 fStopOnError = rec.fStopOnError;
439 fWriteAlignmentData = rec.fWriteAlignmentData;
440 fWriteESDfriend = rec.fWriteESDfriend;
441 fFillTriggerESD = rec.fFillTriggerESD;
442
443 fCleanESD = rec.fCleanESD;
444 fV0DCAmax = rec.fV0DCAmax;
445 fV0CsPmin = rec.fV0CsPmin;
446 fDmax = rec.fDmax;
447 fZmax = rec.fZmax;
448
449 fRunLocalReconstruction = rec.fRunLocalReconstruction;
450 fRunTracking = rec.fRunTracking;
451 fFillESD = rec.fFillESD;
7d566c20 452 fLoadCDB = rec.fLoadCDB;
4b71572b 453 fUseTrackingErrorsForAlignment = rec.fUseTrackingErrorsForAlignment;
454 fGAliceFileName = rec.fGAliceFileName;
455 fRawInput = rec.fRawInput;
975320a0 456 fESDOutput = rec.fESDOutput;
81d57268 457 fProofOutputFileName = rec.fProofOutputFileName;
458 fProofOutputLocation = rec.fProofOutputLocation;
459 fProofOutputDataset = rec.fProofOutputDataset;
460 fProofOutputArchive = rec.fProofOutputArchive;
4b71572b 461 fEquipIdMap = rec.fEquipIdMap;
462 fFirstEvent = rec.fFirstEvent;
463 fLastEvent = rec.fLastEvent;
464 fNumberOfEventsPerFile = rec.fNumberOfEventsPerFile;
465
466 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
467 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
468 }
469
470 fLoadAlignFromCDB = rec.fLoadAlignFromCDB;
471 fLoadAlignData = rec.fLoadAlignData;
4b71572b 472 fUseHLTData = rec.fUseHLTData;
473
474 delete fRunInfo; fRunInfo = NULL;
475 if (rec.fRunInfo) fRunInfo = new AliRunInfo(*rec.fRunInfo);
476
477 fEventInfo = rec.fEventInfo;
478
522fdd91 479 delete fRunScalers; fRunScalers = NULL;
480 if (rec.fRunScalers) fRunScalers = new AliTriggerRunScalers(*rec.fRunScalers);
481
52dd4a8c 482 delete fCTPTimeParams; fCTPTimeParams = NULL;
483 if (rec.fCTPTimeParams) fCTPTimeParams = new AliCTPTimeParams(*rec.fCTPTimeParams);
484
4b71572b 485 fRunLoader = NULL;
486 fRawReader = NULL;
487 fParentRawReader = NULL;
488
489 fRecoParam = rec.fRecoParam;
490
ac4a7581 491 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4b71572b 492 delete fReconstructor[iDet]; fReconstructor[iDet] = NULL;
493 delete fLoader[iDet]; fLoader[iDet] = NULL;
494 delete fTracker[iDet]; fTracker[iDet] = NULL;
4b71572b 495 }
b1af1125 496
4e25ac79 497 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
b1af1125 498 fQACycles[iDet] = rec.fQACycles[iDet];
252f8aa8 499 fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
500 }
58e8dc31 501
502 delete fSPDTrackleter; fSPDTrackleter = NULL;
252f8aa8 503
f2a195c1 504 delete fDiamondProfileSPD; fDiamondProfileSPD = NULL;
505 if (rec.fDiamondProfileSPD) fDiamondProfileSPD = new AliESDVertex(*rec.fDiamondProfileSPD);
4b71572b 506 delete fDiamondProfile; fDiamondProfile = NULL;
507 if (rec.fDiamondProfile) fDiamondProfile = new AliESDVertex(*rec.fDiamondProfile);
508 delete fDiamondProfileTPC; fDiamondProfileTPC = NULL;
509 if (rec.fDiamondProfileTPC) fDiamondProfileTPC = new AliESDVertex(*rec.fDiamondProfileTPC);
4b71572b 510
77ba28ba 511 delete fListOfCosmicTriggers; fListOfCosmicTriggers = NULL;
512 if (rec.fListOfCosmicTriggers) fListOfCosmicTriggers = (THashTable*)((rec.fListOfCosmicTriggers)->Clone());
513
4b71572b 514 delete fGRPData; fGRPData = NULL;
44e45fac 515 // if (rec.fGRPData) fGRPData = (TMap*)((rec.fGRPData)->Clone());
516 if (rec.fGRPData) fGRPData = (AliGRPObject*)((rec.fGRPData)->Clone());
4b71572b 517
518 delete fAlignObjArray; fAlignObjArray = NULL;
519
520 fCDBUri = "";
f1c1204d 521 fQARefUri = rec.fQARefUri;
4b71572b 522 fSpecCDBUri.Delete();
523 fInitCDBCalled = rec.fInitCDBCalled;
524 fSetRunNumberFromDataCalled = rec.fSetRunNumberFromDataCalled;
525 fQADetectors = rec.fQADetectors;
4b71572b 526 fQATasks = rec.fQATasks;
527 fRunQA = rec.fRunQA;
528 fRunGlobalQA = rec.fRunGlobalQA;
4b71572b 529 fSameQACycle = rec.fSameQACycle;
f1c1204d 530 fInitQACalled = rec.fInitQACalled;
75373542 531 fWriteQAExpertData = rec.fWriteQAExpertData;
4b71572b 532 fRunPlaneEff = rec.fRunPlaneEff;
3d84ad67 533 for (int i=2;i--;) for (int j=2;j--;) fBeamInt[i][j] = rec.fBeamInt[i][j];
4b71572b 534 fesd = NULL;
535 fhltesd = NULL;
536 fesdf = NULL;
537 ffile = NULL;
ee7c441c 538 ffileF = NULL;
4b71572b 539 ftree = NULL;
ee7c441c 540 ftreeF = NULL;
4b71572b 541 fhlttree = NULL;
542 ftVertexer = NULL;
543 fIsNewRunLoader = rec.fIsNewRunLoader;
544 fRunAliEVE = kFALSE;
545 fChain = NULL;
596a855f 546
596a855f 547 return *this;
548}
549
550//_____________________________________________________________________________
551AliReconstruction::~AliReconstruction()
552{
553// clean up
554
e583c30d 555 CleanUp();
77ba28ba 556 if (fListOfCosmicTriggers) {
557 fListOfCosmicTriggers->Delete();
558 delete fListOfCosmicTriggers;
559 }
4f3c479a 560 delete fGRPData;
522fdd91 561 delete fRunScalers;
52dd4a8c 562 delete fCTPTimeParams;
efd2085e 563 fOptions.Delete();
4b71572b 564 if (fAlignObjArray) {
565 fAlignObjArray->Delete();
566 delete fAlignObjArray;
567 }
ec92bee0 568 fSpecCDBUri.Delete();
e6d66370 569
87932dab 570 AliCodeTimer::Instance()->Print();
596a855f 571}
572
f1c1204d 573//_____________________________________________________________________________
574void AliReconstruction::InitQA()
575{
576 //Initialize the QA and start of cycle
52dd4a8c 577 AliCodeTimerAuto("",0);
f1c1204d 578
579 if (fInitQACalled) return;
580 fInitQACalled = kTRUE;
581
634696f5 582 AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kRECMODE) ;
75373542 583 if (fWriteQAExpertData)
eca4fa66 584 qam->SetWriteExpert() ;
75373542 585
eca4fa66 586 if (qam->IsDefaultStorageSet()) {
f1c1204d 587 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
588 AliWarning("Default QA reference storage has been already set !");
589 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fQARefUri.Data()));
590 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
eca4fa66 591 fQARefUri = qam->GetDefaultStorage()->GetURI();
f1c1204d 592 } else {
593 if (fQARefUri.Length() > 0) {
594 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
595 AliDebug(2, Form("Default QA reference storage is set to: %s", fQARefUri.Data()));
596 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
597 } else {
598 fQARefUri="local://$ALICE_ROOT/QAref";
599 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
600 AliWarning("Default QA refeference storage not yet set !!!!");
601 AliWarning(Form("Setting it now to: %s", fQARefUri.Data()));
602 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
603
604 }
eca4fa66 605 qam->SetDefaultStorage(fQARefUri);
f1c1204d 606 }
607
608 if (fRunQA) {
eca4fa66 609 qam->SetActiveDetectors(fQADetectors) ;
4e25ac79 610 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) {
eca4fa66 611 qam->SetCycleLength(AliQAv1::DETECTORINDEX_t(det), fQACycles[det]) ;
612 qam->SetWriteExpert(AliQAv1::DETECTORINDEX_t(det)) ;
f1c1204d 613 }
514cb8c7 614 if (!fRawReader && !fInput && IsInTasks(AliQAv1::kRAWS))
4e25ac79 615 fQATasks.ReplaceAll(Form("%d",AliQAv1::kRAWS), "") ;
eca4fa66 616 qam->SetTasks(fQATasks) ;
617 qam->InitQADataMaker(AliCDBManager::Instance()->GetRun()) ;
f1c1204d 618 }
619 if (fRunGlobalQA) {
620 Bool_t sameCycle = kFALSE ;
eca4fa66 621 AliQADataMaker *qadm = qam->GetQADataMaker(AliQAv1::kGLOBAL);
f1c1204d 622 AliInfo(Form("Initializing the global QA data maker"));
514cb8c7 623 if (IsInTasks(AliQAv1::kRECPOINTS)) {
4e25ac79 624 qadm->StartOfCycle(AliQAv1::kRECPOINTS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
625 TObjArray **arr=qadm->Init(AliQAv1::kRECPOINTS);
f1c1204d 626 AliTracker::SetResidualsArray(arr);
627 sameCycle = kTRUE ;
628 }
514cb8c7 629 if (IsInTasks(AliQAv1::kESDS)) {
4e25ac79 630 qadm->StartOfCycle(AliQAv1::kESDS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
631 qadm->Init(AliQAv1::kESDS);
f1c1204d 632 }
f1c1204d 633 }
fc07289e 634 AliSysInfo::AddStamp("InitQA") ;
f1c1204d 635}
636
fc07289e 637//_____________________________________________________________________________
87da0921 638void AliReconstruction::MergeQA(const char *fileName)
fc07289e 639{
640 //Initialize the QA and start of cycle
52dd4a8c 641 AliCodeTimerAuto("",0) ;
eca4fa66 642 AliQAManager::QAManager()->Merge(AliCDBManager::Instance()->GetRun(),fileName) ;
fc07289e 643 AliSysInfo::AddStamp("MergeQA") ;
644}
645
024cf675 646//_____________________________________________________________________________
795e4a22 647void AliReconstruction::InitCDB()
024cf675 648{
649// activate a default CDB storage
650// First check if we have any CDB storage set, because it is used
651// to retrieve the calibration and alignment constants
52dd4a8c 652 AliCodeTimerAuto("",0);
024cf675 653
795e4a22 654 if (fInitCDBCalled) return;
655 fInitCDBCalled = kTRUE;
656
024cf675 657 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 658 if (man->IsDefaultStorageSet())
024cf675 659 {
660 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 661 AliWarning("Default CDB storage has been already set !");
662 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
024cf675 663 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 664 fCDBUri = man->GetDefaultStorage()->GetURI();
ec92bee0 665 }
666 else {
795e4a22 667 if (fCDBUri.Length() > 0)
668 {
669 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
670 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
671 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
52dd4a8c 672 man->SetDefaultStorage(fCDBUri);
673 }
674 else if (!man->GetRaw()){
675 fCDBUri="local://$ALICE_ROOT/OCDB";
795e4a22 676 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
677 AliWarning("Default CDB storage not yet set !!!!");
678 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
679 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
52dd4a8c 680 man->SetDefaultStorage(fCDBUri);
681 }
682 else {
683 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
684 AliWarning("Default storage will be set after setting the Run Number!!!");
685 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 686 }
ec92bee0 687 }
688
689 // Now activate the detector specific CDB storage locations
c3a7b59a 690 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
691 TObject* obj = fSpecCDBUri[i];
692 if (!obj) continue;
b8ec52f6 693 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
694 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
695 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 696 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 697 }
002c9d1b 698 AliSysInfo::AddStamp("InitCDB");
024cf675 699}
700
701//_____________________________________________________________________________
702void AliReconstruction::SetDefaultStorage(const char* uri) {
ec92bee0 703// Store the desired default CDB storage location
704// Activate it later within the Run() method
024cf675 705
ec92bee0 706 fCDBUri = uri;
024cf675 707
708}
709
f1c1204d 710//_____________________________________________________________________________
711void AliReconstruction::SetQARefDefaultStorage(const char* uri) {
712 // Store the desired default CDB storage location
713 // Activate it later within the Run() method
714
715 fQARefUri = uri;
4e25ac79 716 AliQAv1::SetQARefStorage(fQARefUri.Data()) ;
f1c1204d 717
718}
00aa02d5 719//_____________________________________________________________________________
c3a7b59a 720void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 721// Store a detector-specific CDB storage location
722// Activate it later within the Run() method
024cf675 723
c3a7b59a 724 AliCDBPath aPath(calibType);
725 if(!aPath.IsValid()){
726 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
ac4a7581 727 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
c3a7b59a 728 if(!strcmp(calibType, fgkDetectorName[iDet])) {
729 aPath.SetPath(Form("%s/*", calibType));
730 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
731 break;
732 }
733 }
734 if(!aPath.IsValid()){
735 AliError(Form("Not a valid path or detector: %s", calibType));
736 return;
737 }
738 }
739
53dd3c3d 740// // check that calibType refers to a "valid" detector name
741// Bool_t isDetector = kFALSE;
ac4a7581 742// for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
53dd3c3d 743// TString detName = fgkDetectorName[iDet];
744// if(aPath.GetLevel0() == detName) {
745// isDetector = kTRUE;
746// break;
747// }
748// }
749//
750// if(!isDetector) {
751// AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
752// return;
753// }
c3a7b59a 754
755 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
ec92bee0 756 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 757 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
024cf675 758
759}
760
6bae477a 761//_____________________________________________________________________________
795e4a22 762Bool_t AliReconstruction::SetRunNumberFromData()
6bae477a 763{
764 // The method is called in Run() in order
765 // to set a correct run number.
766 // In case of raw data reconstruction the
767 // run number is taken from the raw data header
768
795e4a22 769 if (fSetRunNumberFromDataCalled) return kTRUE;
770 fSetRunNumberFromDataCalled = kTRUE;
771
772 AliCDBManager* man = AliCDBManager::Instance();
4b71572b 773
774 if(fRawReader) {
775 if(fRawReader->NextEvent()) {
776 if(man->GetRun() > 0) {
21a3aa09 777 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
4b71572b 778 }
779 man->SetRun(fRawReader->GetRunNumber());
780 fRawReader->RewindEvents();
781 }
782 else {
783 if(man->GetRun() > 0) {
784 AliWarning("No raw-data events are found ! Using settings in AliCDBManager !");
785 }
786 else {
787 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
788 return kFALSE;
789 }
790 }
791 }
792 else {
793 AliRunLoader *rl = AliRunLoader::Open(fGAliceFileName.Data());
794 if (!rl) {
795 AliError(Form("No run loader found in file %s", fGAliceFileName.Data()));
6bae477a 796 return kFALSE;
797 }
ec92bee0 798 else {
4b71572b 799 rl->LoadHeader();
800 // read run number from gAlice
801 if(rl->GetHeader()) {
802 man->SetRun(rl->GetHeader()->GetRun());
803 rl->UnloadHeader();
804 delete rl;
ec92bee0 805 }
806 else {
4b71572b 807 AliError("Neither run-loader header nor RawReader objects are found !");
808 delete rl;
ec92bee0 809 return kFALSE;
810 }
4b71572b 811 }
6bae477a 812 }
795e4a22 813
814 man->Print();
815
6bae477a 816 return kTRUE;
817}
818
795e4a22 819//_____________________________________________________________________________
820void AliReconstruction::SetCDBLock() {
821 // Set CDB lock: from now on it is forbidden to reset the run number
822 // or the default storage or to activate any further storage!
823
824 AliCDBManager::Instance()->SetLock(1);
825}
826
6bae477a 827//_____________________________________________________________________________
828Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
829{
830 // Read the alignment objects from CDB.
831 // Each detector is supposed to have the
832 // alignment objects in DET/Align/Data CDB path.
833 // All the detector objects are then collected,
834 // sorted by geometry level (starting from ALIC) and
835 // then applied to the TGeo geometry.
836 // Finally an overlaps check is performed.
837
838 // Load alignment data from CDB and fill fAlignObjArray
839 if(fLoadAlignFromCDB){
6bae477a 840
25be1e5c 841 TString detStr = detectors;
842 TString loadAlObjsListOfDets = "";
843
ac4a7581 844 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
8cb26cdf 845 if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
f12d42ce 846 if(!strcmp(fgkDetectorName[iDet],"HLT")) continue;
4fbb8e9d 847
848 if(AliGeomManager::GetNalignable(fgkDetectorName[iDet]) != 0)
8cb26cdf 849 {
850 loadAlObjsListOfDets += fgkDetectorName[iDet];
851 loadAlObjsListOfDets += " ";
852 }
25be1e5c 853 } // end loop over detectors
4fbb8e9d 854
855 if(AliGeomManager::GetNalignable("GRP") != 0)
8cb26cdf 856 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
98e303d9 857 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
e30a9b4d 858 AliCDBManager::Instance()->UnloadFromCache("*/Align/*");
25be1e5c 859 }else{
860 // Check if the array with alignment objects was
861 // provided by the user. If yes, apply the objects
862 // to the present TGeo geometry
863 if (fAlignObjArray) {
864 if (gGeoManager && gGeoManager->IsClosed()) {
98e303d9 865 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
25be1e5c 866 AliError("The misalignment of one or more volumes failed!"
867 "Compare the list of simulated detectors and the list of detector alignment data!");
868 return kFALSE;
869 }
870 }
871 else {
872 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
6bae477a 873 return kFALSE;
874 }
875 }
6bae477a 876 }
25be1e5c 877
4b71572b 878 if (fAlignObjArray) {
879 fAlignObjArray->Delete();
880 delete fAlignObjArray; fAlignObjArray=NULL;
881 }
a03b0371 882
6bae477a 883 return kTRUE;
884}
596a855f 885
886//_____________________________________________________________________________
887void AliReconstruction::SetGAliceFile(const char* fileName)
888{
889// set the name of the galice file
890
891 fGAliceFileName = fileName;
892}
893
21a3aa09 894//_____________________________________________________________________________
b58710ef 895void AliReconstruction::SetInput(const char* input)
21a3aa09 896{
b58710ef 897 // In case the input string starts with 'mem://', we run in an online mode
898 // and AliRawReaderDateOnline object is created. In all other cases a raw-data
899 // file is assumed. One can give as an input:
900 // mem://: - events taken from DAQ monitoring libs online
901 // or
902 // mem://<filename> - emulation of the above mode (via DATE monitoring libs)
4b71572b 903 if (input) fRawInput = input;
21a3aa09 904}
905
975320a0 906//_____________________________________________________________________________
907void AliReconstruction::SetOutput(const char* output)
908{
909 // Set the output ESD filename
910 // 'output' is a normalt ROOT url
911 // The method is used in case of raw-data reco with PROOF
81d57268 912 if (output) fESDOutput = output;
975320a0 913}
914
efd2085e 915//_____________________________________________________________________________
916void AliReconstruction::SetOption(const char* detector, const char* option)
917{
918// set options for the reconstruction of a detector
919
920 TObject* obj = fOptions.FindObject(detector);
921 if (obj) fOptions.Remove(obj);
922 fOptions.Add(new TNamed(detector, option));
923}
924
7e88424f 925//_____________________________________________________________________________
926void AliReconstruction::SetRecoParam(const char* detector, AliDetectorRecoParam *par)
927{
928 // Set custom reconstruction parameters for a given detector
929 // Single set of parameters for all the events
a00021a7 930
931 // First check if the reco-params are global
932 if(!strcmp(detector, "GRP")) {
933 par->SetAsDefault();
ac4a7581 934 fRecoParam.AddDetRecoParam(kNDetectors,par);
a00021a7 935 return;
936 }
937
ac4a7581 938 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
7e88424f 939 if(!strcmp(detector, fgkDetectorName[iDet])) {
940 par->SetAsDefault();
941 fRecoParam.AddDetRecoParam(iDet,par);
942 break;
943 }
944 }
945
946}
947
61807e09 948//_____________________________________________________________________________
61807e09 949Bool_t AliReconstruction::InitGRP() {
950 //------------------------------------
951 // Initialization of the GRP entry
952 //------------------------------------
953 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
954
4b71572b 955 if (entry) {
44e45fac 956
957 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
958
959 if (m) {
960 AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
961 m->Print();
962 fGRPData = new AliGRPObject();
963 fGRPData->ReadValuesFromMap(m);
964 }
965
966 else {
967 AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it");
968 fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
969 entry->SetOwner(0);
970 }
971
f168abba 972 // FIX ME: The unloading of GRP entry is temporarily disabled
973 // because ZDC and VZERO are using it in order to initialize
974 // their reconstructor objects. In the future one has to think
975 // of propagating AliRunInfo to the reconstructors.
976 // AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
4b71572b 977 }
61807e09 978
979 if (!fGRPData) {
980 AliError("No GRP entry found in OCDB!");
981 return kFALSE;
982 }
983
44e45fac 984 TString lhcState = fGRPData->GetLHCState();
985 if (lhcState==AliGRPObject::GetInvalidString()) {
7e88424f 986 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
44e45fac 987 lhcState = "UNKNOWN";
7e88424f 988 }
989
44e45fac 990 TString beamType = fGRPData->GetBeamType();
991 if (beamType==AliGRPObject::GetInvalidString()) {
7e88424f 992 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
44e45fac 993 beamType = "UNKNOWN";
7e88424f 994 }
995
44e45fac 996 Float_t beamEnergy = fGRPData->GetBeamEnergy();
997 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
7e88424f 998 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
44e45fac 999 beamEnergy = 0;
7e88424f 1000 }
1001
44e45fac 1002 TString runType = fGRPData->GetRunType();
1003 if (runType==AliGRPObject::GetInvalidString()) {
7e88424f 1004 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
44e45fac 1005 runType = "UNKNOWN";
7e88424f 1006 }
1007
44e45fac 1008 Int_t activeDetectors = fGRPData->GetDetectorMask();
a5dede5c 1009 if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
7e88424f 1010 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
44e45fac 1011 activeDetectors = 1074790399;
7e88424f 1012 }
1013
44e45fac 1014 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
44e45fac 1015 fRunInfo->Dump();
1016
7e88424f 1017
1018 // Process the list of active detectors
44e45fac 1019 if (activeDetectors) {
1020 UInt_t detMask = activeDetectors;
7a317bef 1021 fRunLocalReconstruction = MatchDetectorList(fRunLocalReconstruction,detMask);
1022 fRunTracking = MatchDetectorList(fRunTracking,detMask);
1023 fFillESD = MatchDetectorList(fFillESD,detMask);
1024 fQADetectors = MatchDetectorList(fQADetectors,detMask);
7d566c20 1025 fLoadCDB.Form("%s %s %s %s",
1026 fRunLocalReconstruction.Data(),
1027 fRunTracking.Data(),
1028 fFillESD.Data(),
1029 fQADetectors.Data());
7d566c20 1030 fLoadCDB = MatchDetectorList(fLoadCDB,detMask);
d0f84c42 1031 if (!((detMask >> AliDAQ::DetectorID("ITSSPD")) & 0x1) &&
1032 !((detMask >> AliDAQ::DetectorID("ITSSDD")) & 0x1) &&
1033 !((detMask >> AliDAQ::DetectorID("ITSSSD")) & 0x1) ) {
91e2f025 1034 // switch off the vertexer
d0f84c42 1035 AliInfo("SPD,SDD,SSD is not in the list of active detectors. Vertexer switched off.");
91e2f025 1036 fRunVertexFinder = kFALSE;
1037 }
304d7f0b 1038 if (!((detMask >> AliDAQ::DetectorID("TRG")) & 0x1)) {
1039 // switch off the reading of CTP raw-data payload
1040 if (fFillTriggerESD) {
1041 AliInfo("CTP is not in the list of active detectors. CTP data reading switched off.");
1042 fFillTriggerESD = kFALSE;
1043 }
1044 }
7e88424f 1045 }
1046
1047 AliInfo("===================================================================================");
1048 AliInfo(Form("Running local reconstruction for detectors: %s",fRunLocalReconstruction.Data()));
1049 AliInfo(Form("Running tracking for detectors: %s",fRunTracking.Data()));
1050 AliInfo(Form("Filling ESD for detectors: %s",fFillESD.Data()));
ca13fb87 1051 AliInfo(Form("Quality assurance is active for detectors: %s",fQADetectors.Data()));
7d566c20 1052 AliInfo(Form("CDB and reconstruction parameters are loaded for detectors: %s",fLoadCDB.Data()));
7e88424f 1053 AliInfo("===================================================================================");
61807e09 1054
1055 //*** Dealing with the magnetic field map
5a004fb4 1056 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
1057 if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
1058 AliInfo("ExpertMode!!! GRP information will be ignored !");
1059 AliInfo("ExpertMode!!! Running with the externally locked B field !");
1060 }
1061 else {
1062 AliInfo("Destroying existing B field instance!");
1063 delete TGeoGlobalMagField::Instance();
1064 }
1065 }
1066 if ( !TGeoGlobalMagField::Instance()->IsLocked() ) {
61807e09 1067 // Construct the field map out of the information retrieved from GRP.
856024f0 1068 Bool_t ok = kTRUE;
61807e09 1069 // L3
44e45fac 1070 Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
1071 if (l3Current == AliGRPObject::GetInvalidFloat()) {
1072 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
1073 ok = kFALSE;
1074 }
f7a1cc68 1075
44e45fac 1076 Char_t l3Polarity = fGRPData->GetL3Polarity();
1077 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
1078 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
1079 ok = kFALSE;
1080 }
1081
1082 // Dipole
1083 Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
1084 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
1085 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
1086 ok = kFALSE;
1087 }
1088
1089 Char_t diPolarity = fGRPData->GetDipolePolarity();
1090 if (diPolarity == AliGRPObject::GetInvalidChar()) {
1091 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
1092 ok = kFALSE;
1093 }
1094
99c7d495 1095 // read special bits for the polarity convention and map type
1096 Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
1097 Bool_t uniformB = fGRPData->IsUniformBMap();
61807e09 1098
856024f0 1099 if (ok) {
33fe5eb1 1100 AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
1101 TMath::Abs(diCurrent) * (diPolarity ? -1:1),
1102 polConvention,uniformB,beamEnergy, beamType.Data());
1103 if (fld) {
1104 TGeoGlobalMagField::Instance()->SetField( fld );
1105 TGeoGlobalMagField::Instance()->Lock();
1106 AliInfo("Running with the B field constructed out of GRP !");
1107 }
1108 else AliFatal("Failed to create a B field map !");
856024f0 1109 }
f7a1cc68 1110 else AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
61807e09 1111 }
f7a1cc68 1112
f2a195c1 1113 //*** Get the diamond profiles from OCDB
1114 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD");
1115 if (entry) {
1116 fDiamondProfileSPD = dynamic_cast<AliESDVertex*> (entry->GetObject());
1117 } else {
1118 AliError("No SPD diamond profile found in OCDB!");
1119 }
1120
61807e09 1121 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
1122 if (entry) {
f2a195c1 1123 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
61807e09 1124 } else {
1125 AliError("No diamond profile found in OCDB!");
1126 }
1127
1128 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexTPC");
1129 if (entry) {
f2a195c1 1130 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
61807e09 1131 } else {
f2a195c1 1132 AliError("No TPC diamond profile found in OCDB!");
61807e09 1133 }
1134
77ba28ba 1135 entry = AliCDBManager::Instance()->Get("GRP/Calib/CosmicTriggers");
1136 if (entry) {
1137 fListOfCosmicTriggers = dynamic_cast<THashTable*>(entry->GetObject());
1138 entry->SetOwner(0);
1139 AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
1140 }
1141
1142 if (!fListOfCosmicTriggers) {
1143 AliWarning("Can not get list of cosmic triggers from OCDB! Cosmic event specie will be effectively disabled!");
1144 }
1145
61807e09 1146 return kTRUE;
1147}
1148
4b71572b 1149//_____________________________________________________________________________
1150Bool_t AliReconstruction::LoadCDB()
1151{
0a035be5 1152 // Load CDB entries for all active detectors.
1153 // By default we load all the entries in <det>/Calib
1154 // folder.
1155
52dd4a8c 1156 AliCodeTimerAuto("",0);
4b71572b 1157
1158 AliCDBManager::Instance()->Get("GRP/CTP/Config");
1159
7d566c20 1160 TString detStr = fLoadCDB;
ac4a7581 1161 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4b71572b 1162 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1163 AliCDBManager::Instance()->GetAll(Form("%s/Calib/*",fgkDetectorName[iDet]));
1164 }
e122592f 1165
1166 // Temporary fix - one has to define the correct policy in order
1167 // to load the trigger OCDB entries only for the detectors that
1168 // in the trigger or that are needed in order to put correct
1169 // information in ESD
1170 AliCDBManager::Instance()->GetAll("TRIGGER/*/*");
1171
4b71572b 1172 return kTRUE;
1173}
522fdd91 1174//_____________________________________________________________________________
1175Bool_t AliReconstruction::LoadTriggerScalersCDB()
1176{
0a035be5 1177 // Load CTP scalers from OCDB.
1178 // The scalers are checked for consistency.
1179
52dd4a8c 1180 AliCodeTimerAuto("",0);
522fdd91 1181
1182 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/Scalers");
4b71572b 1183
522fdd91 1184 if (entry) {
1185
1186 AliInfo("Found an AliTriggerRunScalers in GRP/CTP/Scalers, reading it");
1187 fRunScalers = dynamic_cast<AliTriggerRunScalers*> (entry->GetObject());
1188 entry->SetOwner(0);
82ebedd6 1189 if (fRunScalers->CorrectScalersOverflow() == 0) AliInfo("32bit Trigger counters corrected for overflow");
1190
522fdd91 1191 }
1192 return kTRUE;
1193}
596a855f 1194//_____________________________________________________________________________
52dd4a8c 1195Bool_t AliReconstruction::LoadCTPTimeParamsCDB()
1196{
0a035be5 1197 // Load CTP timing information (alignment)
1198 // from OCDB.
1199
52dd4a8c 1200 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
1201
1202 if (entry) {
1203
1204 AliInfo("Found an AliCTPTimeParams in GRP/CTP/CTPtiming, reading it");
1205 fCTPTimeParams = dynamic_cast<AliCTPTimeParams*> (entry->GetObject());
1206 entry->SetOwner(0);
1207 return kTRUE;
1208 }
1209
1210 return kFALSE;
1211}
3d84ad67 1212
1213//_____________________________________________________________________________
1214Bool_t AliReconstruction::ReadIntensityInfoCDB()
1215{
1216 // Load LHC DIP data
1217 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/LHCData");
1218
1219 if (entry) {
1220 AliInfo("Found an AliLHCData in GRP/GRP/LHCData, reading it");
1221 AliLHCData* dipData = dynamic_cast<AliLHCData*> (entry->GetObject());
1222 for (int ib=2;ib--;) {
1223 double intI,intNI;
1224 if (dipData->GetMeanIntensity(ib,intI,intNI)>=0) {
1225 fBeamInt[ib][0] = intI;
1226 fBeamInt[ib][1] = intNI;
1227 }
1228 }
1229 return kTRUE;
1230 }
1231 return kFALSE;
1232}
1233
1234
52dd4a8c 1235//_____________________________________________________________________________
21a3aa09 1236Bool_t AliReconstruction::Run(const char* input)
596a855f 1237{
21a3aa09 1238 // Run Run Run
52dd4a8c 1239 AliCodeTimerAuto("",0);
596a855f 1240
4b71572b 1241 InitRun(input);
1242 if (GetAbort() != TSelector::kContinue) return kFALSE;
1243
1244 TChain *chain = NULL;
1245 if (fRawReader && (chain = fRawReader->GetChain())) {
2a284cef 1246 Long64_t nEntries = (fLastEvent < 0) ? (TChain::kBigNumber) : (fLastEvent - fFirstEvent + 1);
4b71572b 1247 // Proof mode
1248 if (gProof) {
52dd4a8c 1249 // Temporary fix for long raw-data runs (until socket timeout handling in PROOF is revised)
1250 gProof->Exec("gEnv->SetValue(\"Proof.SocketActivityTimeout\",-1)", kTRUE);
6c6f2624 1251
1252 if (gGrid)
1253 gProof->Exec("TGrid::Connect(\"alien://\")",kTRUE);
1254
1255 TMessage::EnableSchemaEvolutionForAll(kTRUE);
1256 gProof->Exec("TMessage::EnableSchemaEvolutionForAll(kTRUE)",kTRUE);
1257
4b71572b 1258 gProof->AddInput(this);
81d57268 1259
1260 if (!ParseOutput()) return kFALSE;
1261
975320a0 1262 gProof->SetParameter("PROOF_MaxSlavesPerNode", 9999);
4b71572b 1263 chain->SetProof();
2a284cef 1264 chain->Process("AliReconstruction","",nEntries,fFirstEvent);
4b71572b 1265 }
1266 else {
2a284cef 1267 chain->Process(this,"",nEntries,fFirstEvent);
4b71572b 1268 }
1269 }
1270 else {
1271 Begin(NULL);
1272 if (GetAbort() != TSelector::kContinue) return kFALSE;
1273 SlaveBegin(NULL);
1274 if (GetAbort() != TSelector::kContinue) return kFALSE;
1275 //******* The loop over events
44e45fac 1276 AliInfo("Starting looping over events");
4b71572b 1277 Int_t iEvent = 0;
1278 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
1279 (fRawReader && fRawReader->NextEvent())) {
1280 if (!ProcessEvent(iEvent)) {
930e6e3e 1281 Abort("ProcessEvent",TSelector::kAbortFile);
1282 return kFALSE;
4b71572b 1283 }
1284 iEvent++;
1285 }
1286 SlaveTerminate();
1287 if (GetAbort() != TSelector::kContinue) return kFALSE;
1288 Terminate();
1289 if (GetAbort() != TSelector::kContinue) return kFALSE;
21a3aa09 1290 }
21a3aa09 1291
1292 return kTRUE;
1293}
1294
1295//_____________________________________________________________________________
4b71572b 1296void AliReconstruction::InitRawReader(const char* input)
21a3aa09 1297{
4b71572b 1298 // Init raw-reader and
21a3aa09 1299 // set the input in case of raw data
0a035be5 1300
1301 AliCodeTimerAuto("",0);
1302
4b71572b 1303 if (input) fRawInput = input;
1304 fRawReader = AliRawReader::Create(fRawInput.Data());
c35f192e 1305 if (!fRawReader) {
1306 if (fRawInput.IsNull()) {
1307 AliInfo("Reconstruction will run over digits");
1308 }
1309 else {
1310 AliFatal("Can not create raw-data reader ! Exiting...");
1311 }
1312 }
e0027792 1313
35042093 1314 if (!fEquipIdMap.IsNull() && fRawReader)
1315 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1316
cd0b062e 1317 if (!fUseHLTData.IsNull()) {
1318 // create the RawReaderHLT which performs redirection of HLT input data for
1319 // the specified detectors
1320 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
1321 if (pRawReader) {
1322 fParentRawReader=fRawReader;
1323 fRawReader=pRawReader;
1324 } else {
1325 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
1326 }
1327 }
4b71572b 1328 AliSysInfo::AddStamp("CreateRawReader");
1329}
cd0b062e 1330
4b71572b 1331//_____________________________________________________________________________
1332void AliReconstruction::InitRun(const char* input)
1333{
1334 // Initialization of raw-reader,
1335 // run number, CDB etc.
52dd4a8c 1336 AliCodeTimerAuto("",0);
4b71572b 1337 AliSysInfo::AddStamp("Start");
1338
002c9d1b 1339 // Initialize raw-reader if any
4b71572b 1340 InitRawReader(input);
596a855f 1341
ec92bee0 1342 // Initialize the CDB storage
795e4a22 1343 InitCDB();
ec92bee0 1344
6bae477a 1345 // Set run number in CDBManager (if it is not already set by the user)
4b71572b 1346 if (!SetRunNumberFromData()) {
1347 Abort("SetRunNumberFromData", TSelector::kAbortProcess);
1348 return;
1349 }
002c9d1b 1350
795e4a22 1351 // Set CDB lock: from now on it is forbidden to reset the run number
1352 // or the default storage or to activate any further storage!
1353 SetCDBLock();
1354
002c9d1b 1355}
1356
1357//_____________________________________________________________________________
1358void AliReconstruction::Begin(TTree *)
1359{
1360 // Initialize AlReconstruction before
1361 // going into the event loop
1362 // Should follow the TSelector convention
1363 // i.e. initialize only the object on the client side
52dd4a8c 1364 AliCodeTimerAuto("",0);
db4aeca1 1365
b4fef0d2 1366 AliReconstruction *reco = NULL;
002c9d1b 1367 if (fInput) {
8fb1f1dc 1368 if ((reco = (AliReconstruction*)fInput->FindObject("AliReconstruction"))) {
002c9d1b 1369 *this = *reco;
002c9d1b 1370 }
1371 AliSysInfo::AddStamp("ReadInputInBegin");
1372 }
1373
6bae477a 1374 // Import ideal TGeo geometry and apply misalignment
1375 if (!gGeoManager) {
1376 TString geom(gSystem->DirName(fGAliceFileName));
1377 geom += "/geometry.root";
98e303d9 1378 AliGeomManager::LoadGeometry(geom.Data());
4b71572b 1379 if (!gGeoManager) {
1380 Abort("LoadGeometry", TSelector::kAbortProcess);
1381 return;
1382 }
281270d3 1383 AliSysInfo::AddStamp("LoadGeom");
ff5970a3 1384 TString detsToCheck=fRunLocalReconstruction;
4b71572b 1385 if(!AliGeomManager::CheckSymNamesLUT(detsToCheck.Data())) {
1386 Abort("CheckSymNamesLUT", TSelector::kAbortProcess);
1387 return;
1388 }
281270d3 1389 AliSysInfo::AddStamp("CheckGeom");
6bae477a 1390 }
8e245d15 1391
4b71572b 1392 if (!MisalignGeometry(fLoadAlignData)) {
1393 Abort("MisalignGeometry", TSelector::kAbortProcess);
1394 return;
1395 }
1396 AliCDBManager::Instance()->UnloadFromCache("GRP/Geometry/Data");
281270d3 1397 AliSysInfo::AddStamp("MisalignGeom");
6bae477a 1398
8cb26cdf 1399 if (!InitGRP()) {
1400 Abort("InitGRP", TSelector::kAbortProcess);
1401 return;
1402 }
1403 AliSysInfo::AddStamp("InitGRP");
1404
4b71572b 1405 if (!LoadCDB()) {
1406 Abort("LoadCDB", TSelector::kAbortProcess);
1407 return;
1408 }
1409 AliSysInfo::AddStamp("LoadCDB");
325aa76f 1410
a6dd87ad 1411 if (!LoadTriggerScalersCDB()) {
1412 Abort("LoadTriggerScalersCDB", TSelector::kAbortProcess);
1413 return;
1414 }
1415 AliSysInfo::AddStamp("LoadTriggerScalersCDB");
1416
52dd4a8c 1417 if (!LoadCTPTimeParamsCDB()) {
1418 Abort("LoadCTPTimeParamsCDB", TSelector::kAbortProcess);
1419 return;
1420 }
1421 AliSysInfo::AddStamp("LoadCTPTimeParamsCDB");
a6dd87ad 1422
bd26f597 1423 if (!ReadIntensityInfoCDB()) {
1424 Abort("ReadIntensityInfoCDB", TSelector::kAbortProcess);
1425 return;
1426 }
1427 AliSysInfo::AddStamp("ReadIntensityInfoCDB");
1428
7e88424f 1429 // Read the reconstruction parameters from OCDB
1430 if (!InitRecoParams()) {
002c9d1b 1431 AliWarning("Not all detectors have correct RecoParam objects initialized");
4b71572b 1432 }
1433 AliSysInfo::AddStamp("InitRecoParams");
1434
fd2b273c 1435 if (fInput && gProof) {
b4fef0d2 1436 if (reco) *reco = *this;
fd2b273c 1437
45a6dee6 1438 gGeoManager->SetName("Geometry");
fd2b273c 1439 gProof->AddInputData(gGeoManager,kTRUE);
002c9d1b 1440 gGeoManager = NULL;
fd2b273c 1441 gProof->AddInputData(const_cast<TMap*>(AliCDBManager::Instance()->GetEntryCache()),kTRUE);
002c9d1b 1442 fInput->Add(new TParameter<Int_t>("RunNumber",AliCDBManager::Instance()->GetRun()));
f7a1cc68 1443 AliMagF *magFieldMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
ead7b391 1444 magFieldMap->SetName("MagneticFieldMap");
fd2b273c 1445 gProof->AddInputData(magFieldMap,kTRUE);
002c9d1b 1446 }
4b71572b 1447
1448}
1449
1450//_____________________________________________________________________________
1451void AliReconstruction::SlaveBegin(TTree*)
1452{
1453 // Initialization related to run-loader,
1454 // vertexer, trackers, recontructors
1455 // In proof mode it is executed on the slave
52dd4a8c 1456 AliCodeTimerAuto("",0);
4b71572b 1457
db4aeca1 1458 TProofOutputFile *outProofFile = NULL;
81d57268 1459 if (fInput) {
1460 if (AliDebugLevel() > 0) fInput->Print();
ef5e52f6 1461 if (AliDebugLevel() > 10) fInput->Dump();
db4aeca1 1462 if (AliReconstruction *reco = (AliReconstruction*)fInput->FindObject("AliReconstruction")) {
1463 *this = *reco;
1464 }
4b71572b 1465 if (TGeoManager *tgeo = (TGeoManager*)fInput->FindObject("Geometry")) {
1466 gGeoManager = tgeo;
1467 AliGeomManager::SetGeometry(tgeo);
7e88424f 1468 }
281270d3 1469 if (TMap *entryCache = (TMap*)fInput->FindObject("CDBEntryCache")) {
1470 Int_t runNumber = -1;
1471 if (TProof::GetParameter(fInput,"RunNumber",runNumber) == 0) {
1472 AliCDBManager *man = AliCDBManager::Instance(entryCache,runNumber);
1473 man->SetCacheFlag(kTRUE);
1474 man->SetLock(kTRUE);
1475 man->Print();
1476 }
4b71572b 1477 }
ead7b391 1478 if (AliMagF *map = (AliMagF*)fInput->FindObject("MagneticFieldMap")) {
ef5e52f6 1479 AliMagF *newMap = new AliMagF(*map);
1480 if (!newMap->LoadParameterization()) {
1481 Abort("AliMagF::LoadParameterization", TSelector::kAbortProcess);
1482 return;
1483 }
1484 TGeoGlobalMagField::Instance()->SetField(newMap);
1485 TGeoGlobalMagField::Instance()->Lock();
4b71572b 1486 }
81d57268 1487 if (TNamed *outputFileName = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE"))
1488 fProofOutputFileName = outputFileName->GetTitle();
1489 if (TNamed *outputLocation = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_LOCATION"))
1490 fProofOutputLocation = outputLocation->GetTitle();
1491 if (fInput->FindObject("PROOF_OUTPUTFILE_DATASET"))
1492 fProofOutputDataset = kTRUE;
1493 if (TNamed *archiveList = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_ARCHIVE"))
1494 fProofOutputArchive = archiveList->GetTitle();
1495 if (!fProofOutputFileName.IsNull() &&
1496 !fProofOutputLocation.IsNull() &&
1497 fProofOutputArchive.IsNull()) {
1498 if (!fProofOutputDataset) {
1499 outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"M");
1500 outProofFile->SetOutputFileName(Form("%s%s",fProofOutputLocation.Data(),fProofOutputFileName.Data()));
1501 }
1502 else {
1503 outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"DROV",fProofOutputLocation.Data());
1504 }
1505 if (AliDebugLevel() > 0) outProofFile->Dump();
db4aeca1 1506 fOutput->Add(outProofFile);
4b71572b 1507 }
002c9d1b 1508 AliSysInfo::AddStamp("ReadInputInSlaveBegin");
7e88424f 1509 }
325aa76f 1510
4b71572b 1511 // get the run loader
1512 if (!InitRunLoader()) {
1513 Abort("InitRunLoader", TSelector::kAbortProcess);
1514 return;
1515 }
1516 AliSysInfo::AddStamp("LoadLoader");
1517
325aa76f 1518 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
2257f27e 1519
f08fc9f5 1520 // get trackers
b8cd5251 1521 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
4b71572b 1522 Abort("CreateTrackers", TSelector::kAbortProcess);
1523 return;
1524 }
1525 AliSysInfo::AddStamp("CreateTrackers");
24f7a148 1526
36711aa4 1527 // create the ESD output file and tree
db4aeca1 1528 if (!outProofFile) {
1529 ffile = TFile::Open("AliESDs.root", "RECREATE");
1530 ffile->SetCompressionLevel(2);
1531 if (!ffile->IsOpen()) {
1532 Abort("OpenESDFile", TSelector::kAbortProcess);
1533 return;
1534 }
1535 }
1536 else {
81d57268 1537 AliInfo(Form("Opening output PROOF file: %s/%s",
1538 outProofFile->GetDir(), outProofFile->GetFileName()));
db4aeca1 1539 if (!(ffile = outProofFile->OpenFile("RECREATE"))) {
1540 Abort(Form("Problems opening output PROOF file: %s/%s",
1541 outProofFile->GetDir(), outProofFile->GetFileName()),
1542 TSelector::kAbortProcess);
1543 return;
1544 }
596a855f 1545 }
46698ae4 1546
21a3aa09 1547 ftree = new TTree("esdTree", "Tree with ESD objects");
1548 fesd = new AliESDEvent();
1549 fesd->CreateStdContent();
8b12d288 1550 // add a so far non-std object to the ESD, this will
1551 // become part of the std content
1552 fesd->AddObject(new AliESDHLTDecision);
1553
32ba9c61 1554 fesd->WriteToTree(ftree);
1d99986f 1555 if (fWriteESDfriend) {
ee7c441c 1556 ffileF = TFile::Open("AliESDfriends.root", "RECREATE");
03a8000a 1557 ftreeF = new TTree("esdFriendTree", "Tree with ESD Friend objects");
ee7c441c 1558 fesdf = new AliESDfriend();
03a8000a 1559 ftreeF->Branch("ESDfriend.","AliESDfriend", &fesdf);
21a3aa09 1560 fesd->AddObject(fesdf);
ee7c441c 1561 ffile->cd();
1d99986f 1562 }
f9604a22 1563 ftree->GetUserInfo()->Add(fesd);
1564
1565 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
1566 fhltesd = new AliESDEvent();
1567 fhltesd->CreateStdContent();
7491aea6 1568 // read the ESD template from CDB
1569 // HLT is allowed to put non-std content to its ESD, the non-std
1570 // objects need to be created before invocation of WriteToTree in
1571 // order to create all branches. Initialization is done from an
1572 // ESD layout template in CDB
1573 AliCDBManager* man = AliCDBManager::Instance();
1574 AliCDBPath hltESDConfigPath("HLT/ConfigHLT/esdLayout");
1575 AliCDBEntry* hltESDConfig=NULL;
1576 if (man->GetId(hltESDConfigPath)!=NULL &&
1577 (hltESDConfig=man->Get(hltESDConfigPath))!=NULL) {
1578 AliESDEvent* pESDLayout=dynamic_cast<AliESDEvent*>(hltESDConfig->GetObject());
1579 if (pESDLayout) {
1580 // init all internal variables from the list of objects
1581 pESDLayout->GetStdContent();
1582
1583 // copy content and create non-std objects
1584 *fhltesd=*pESDLayout;
1585 fhltesd->Reset();
1586 } else {
1587 AliError(Form("error setting hltEsd layout from %s: invalid object type",
1588 hltESDConfigPath.GetPath().Data()));
1589 }
1590 }
1591
f9604a22 1592 fhltesd->WriteToTree(fhlttree);
1593 fhlttree->GetUserInfo()->Add(fhltesd);
5728d3d5 1594
ac4a7581 1595 ProcInfo_t procInfo;
1596 gSystem->GetProcInfo(&procInfo);
1597 AliInfo(Form("Current memory usage %d %d", procInfo.fMemResident, procInfo.fMemVirtual));
8661738e 1598
325aa76f 1599 //QA
930e6e3e 1600 //Initialize the QA and start of cycle
f1c1204d 1601 if (fRunQA || fRunGlobalQA)
1602 InitQA() ;
aa3c69a9 1603
7167ae53 1604 //Initialize the Plane Efficiency framework
1605 if (fRunPlaneEff && !InitPlaneEff()) {
4b71572b 1606 Abort("InitPlaneEff", TSelector::kAbortProcess);
1607 return;
7167ae53 1608 }
aa3c69a9 1609
14dd053c 1610 if (strcmp(gProgName,"alieve") == 0)
1611 fRunAliEVE = InitAliEVE();
1612
4b71572b 1613 return;
21a3aa09 1614}
1615
1616//_____________________________________________________________________________
4b71572b 1617Bool_t AliReconstruction::Process(Long64_t entry)
1618{
1619 // run the reconstruction over a single entry
1620 // from the chain with raw data
52dd4a8c 1621 AliCodeTimerAuto("",0);
4b71572b 1622
1623 TTree *currTree = fChain->GetTree();
33314186 1624 AliRawVEvent *event = NULL;
4b71572b 1625 currTree->SetBranchAddress("rawevent",&event);
1626 currTree->GetEntry(entry);
1627 fRawReader = new AliRawReaderRoot(event);
1628 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
1629 delete fRawReader;
1630 fRawReader = NULL;
1631 delete event;
1632
1633 return fStatus;
1634}
1635
1636//_____________________________________________________________________________
1637void AliReconstruction::Init(TTree *tree)
1638{
0a035be5 1639 // Implementation of TSelector::Init()
1640 // method
4b71572b 1641 if (tree == 0) {
1642 AliError("The input tree is not found!");
1643 return;
1644 }
1645 fChain = tree;
1646}
1647
1648//_____________________________________________________________________________
1649Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
21a3aa09 1650{
1651 // run the reconstruction over a single event
1652 // The event loop is steered in Run method
1653
10d100d4 1654
470f88b0 1655 static Long_t oldMres=0;
1656 static Long_t oldMvir=0;
1657 static Float_t oldCPU=0;
d97f1dbe 1658 static Long_t aveDMres=0;
1659 static Long_t aveDMvir=0;
1660 static Float_t aveDCPU=0;
470f88b0 1661
52dd4a8c 1662 AliCodeTimerAuto("",0);
21a3aa09 1663
0a035be5 1664 AliESDpid pid;
10d100d4 1665
21a3aa09 1666 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
1667 fRunLoader->SetEventNumber(iEvent);
1668 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1669 iEvent, iEvent);
21a3aa09 1670 fRunLoader->TreeE()->Fill();
4b71572b 1671 if (fRawReader && fRawReader->UseAutoSaveESD())
1672 fRunLoader->TreeE()->AutoSave("SaveSelf");
21a3aa09 1673 }
1674
1675 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
21a3aa09 1676 return kTRUE;
1677 }
1678
aa3c69a9 1679
16447f18 1680 fRunLoader->GetEvent(iEvent);
1681
7e88424f 1682 // Fill Event-info object
1683 GetEventInfo();
77ba28ba 1684 fRecoParam.SetEventSpecie(fRunInfo,fEventInfo,fListOfCosmicTriggers);
d97f1dbe 1685
1686 ProcInfo_t procInfo;
1687 if(iEvent==fFirstEvent) {
1688 gSystem->GetProcInfo(&procInfo);
1689 oldMres=procInfo.fMemResident;
1690 oldMvir=procInfo.fMemVirtual;
1691 oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
1692 }
470f88b0 1693 AliInfo(Form("================================= Processing event %d of type %-10s ==================================", iEvent,fRecoParam.PrintEventSpecie()));
7e88424f 1694
a00021a7 1695 // Set the reco-params
1696 {
1697 TString detStr = fLoadCDB;
ac4a7581 1698 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
a00021a7 1699 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1700 AliReconstructor *reconstructor = GetReconstructor(iDet);
1701 if (reconstructor && fRecoParam.GetDetRecoParamArray(iDet)) {
57acd2d2 1702 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
1703 reconstructor->SetRecoParam(par);
0a035be5 1704 reconstructor->GetPidSettings(&pid);
10d100d4 1705 reconstructor->SetEventInfo(&fEventInfo);
57acd2d2 1706 if (fRunQA) {
eca4fa66 1707 AliQAManager::QAManager()->SetRecoParam(iDet, par) ;
619aafe6 1708 if (par) AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(par->GetEventSpecie())) ;
57acd2d2 1709 }
a00021a7 1710 }
1711 }
9dad1020 1712 if (fRunQA) {
1713 const AliDetectorRecoParam *grppar = fRecoParam.GetDetRecoParam(kNDetectors);
1714 AliQAManager::QAManager()->SetRecoParam(AliQAv1::kGLOBAL, grppar) ;
1715 AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(grppar->GetEventSpecie())) ;
1716 }
a00021a7 1717 }
1718
ca13fb87 1719 // QA on single raw
514cb8c7 1720 if (fRunQA && IsInTasks(AliQAv1::kRAWS)) {
eca4fa66 1721 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
1722 AliQAManager::QAManager()->RunOneEvent(fRawReader) ;
57acd2d2 1723 }
d506c543 1724 // local single event reconstruction
b26c3770 1725 if (!fRunLocalReconstruction.IsNull()) {
d506c543 1726 TString detectors=fRunLocalReconstruction;
a441bf51 1727 // run HLT event reconstruction first
d506c543 1728 // ;-( IsSelected changes the string
1729 if (IsSelected("HLT", detectors) &&
1730 !RunLocalEventReconstruction("HLT")) {
4b71572b 1731 if (fStopOnError) {CleanUp(); return kFALSE;}
a441bf51 1732 }
1733 detectors=fRunLocalReconstruction;
1734 detectors.ReplaceAll("HLT", "");
1735 if (!RunLocalEventReconstruction(detectors)) {
13effe3f 1736 if (fStopOnError) {
1737 CleanUp();
1738 return kFALSE;
1739 }
b26c3770 1740 }
1741 }
1742
6b3a883f 1743
1744 // fill Event header information from the RawEventHeader
1745 if (fRawReader){FillRawEventHeaderESD(fesd);}
1746 if (fRawReader){FillRawEventHeaderESD(fhltesd);}
1747
21a3aa09 1748 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1749 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
7b649c02 1750
1751 ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
1752 ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
1753 ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
1754 ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
1755
21a3aa09 1756 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1757 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
fd2e2210 1758
1759 fesd->SetEventSpecie(fRecoParam.GetEventSpecie());
1760 fhltesd->SetEventSpecie(fRecoParam.GetEventSpecie());
46698ae4 1761
d6ee376f 1762 // Set magnetic field from the tracker
21a3aa09 1763 fesd->SetMagneticField(AliTracker::GetBz());
1764 fhltesd->SetMagneticField(AliTracker::GetBz());
33fe5eb1 1765 //
3d84ad67 1766 AliESDRun *esdRun,*esdRunH;
1767 esdRun = (AliESDRun*)fesd->GetESDRun();
1768 esdRunH = (AliESDRun*)fhltesd->GetESDRun();
1769 esdRun->SetBeamEnergyIsSqrtSHalfGeV();
1770 esdRunH->SetBeamEnergyIsSqrtSHalfGeV();
1771 //
1772 for (int ib=2;ib--;) for (int it=2;it--;) {
1773 esdRun->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
1774 esdRunH->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
1775 }
c587bcde 1776 //
33fe5eb1 1777 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
1778 if (fld) { // set info needed for field initialization
1779 fesd->SetCurrentL3(fld->GetCurrentSol());
1780 fesd->SetCurrentDip(fld->GetCurrentDip());
1781 fesd->SetBeamEnergy(fld->GetBeamEnergy());
1782 fesd->SetBeamType(fld->GetBeamTypeText());
1783 fesd->SetUniformBMap(fld->IsUniform());
1784 fesd->SetBInfoStored();
1785 //
1786 fhltesd->SetCurrentL3(fld->GetCurrentSol());
1787 fhltesd->SetCurrentDip(fld->GetCurrentDip());
1788 fhltesd->SetBeamEnergy(fld->GetBeamEnergy());
1789 fhltesd->SetBeamType(fld->GetBeamTypeText());
1790 fhltesd->SetUniformBMap(fld->IsUniform());
1791 fhltesd->SetBInfoStored();
1792 }
1793 //
71f6cda4 1794 // Set most probable pt, for B=0 tracking
9257a1bd 1795 // Get the global reco-params. They are atposition 16 inside the array of detectors in fRecoParam
ac4a7581 1796 const AliGRPRecoParam *grpRecoParam = dynamic_cast<const AliGRPRecoParam*>(fRecoParam.GetDetRecoParam(kNDetectors));
71f6cda4 1797 if (grpRecoParam) AliExternalTrackParam::SetMostProbablePt(grpRecoParam->GetMostProbablePt());
46698ae4 1798
2e3550da 1799 // Fill raw-data error log into the ESD
21a3aa09 1800 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 1801
2257f27e 1802 // vertex finder
1803 if (fRunVertexFinder) {
4b71572b 1804 if (!RunVertexFinder(fesd)) {
1805 if (fStopOnError) {CleanUp(); return kFALSE;}
2257f27e 1806 }
1807 }
1808
58e8dc31 1809 // For Plane Efficiency: run the SPD trackleter
1810 if (fRunPlaneEff && fSPDTrackleter) {
1811 if (!RunSPDTrackleting(fesd)) {
1812 if (fStopOnError) {CleanUp(); return kFALSE;}
1813 }
1814 }
1815
e66fbafb 1816 // Muon tracking
b8cd5251 1817 if (!fRunTracking.IsNull()) {
e66fbafb 1818 if (fRunMuonTracking) {
21a3aa09 1819 if (!RunMuonTracking(fesd)) {
4b71572b 1820 if (fStopOnError) {CleanUp(); return kFALSE;}
24f7a148 1821 }
596a855f 1822 }
1823 }
1824
e66fbafb 1825 // barrel tracking
1826 if (!fRunTracking.IsNull()) {
0a035be5 1827 if (!RunTracking(fesd,pid)) {
4b71572b 1828 if (fStopOnError) {CleanUp(); return kFALSE;}
e66fbafb 1829 }
1830 }
21c573b7 1831
596a855f 1832 // fill ESD
1833 if (!fFillESD.IsNull()) {
d506c543 1834 TString detectors=fFillESD;
f6806ad3 1835 // run HLT first and on hltesd
d506c543 1836 // ;-( IsSelected changes the string
1837 if (IsSelected("HLT", detectors) &&
1838 !FillESD(fhltesd, "HLT")) {
4b71572b 1839 if (fStopOnError) {CleanUp(); return kFALSE;}
f6806ad3 1840 }
1841 detectors=fFillESD;
d5105682 1842 // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
1843 if (detectors.Contains("ALL")) {
1844 detectors="";
ac4a7581 1845 for (Int_t idet=0; idet<kNDetectors; ++idet){
d5105682 1846 detectors += fgkDetectorName[idet];
1847 detectors += " ";
1848 }
1849 }
f6806ad3 1850 detectors.ReplaceAll("HLT", "");
1851 if (!FillESD(fesd, detectors)) {
4b71572b 1852 if (fStopOnError) {CleanUp(); return kFALSE;}
596a855f 1853 }
1854 }
6b3a883f 1855
596a855f 1856 // combined PID
0a035be5 1857 pid.MakePID(fesd);
596a855f 1858
b647652d 1859 if (fFillTriggerESD) {
4b71572b 1860 if (!FillTriggerESD(fesd)) {
1861 if (fStopOnError) {CleanUp(); return kFALSE;}
b647652d 1862 }
1863 }
f7812afc 1864 // Always fill scalers
1865 if (!FillTriggerScalers(fesd)) {
1866 if (fStopOnError) {CleanUp(); return kFALSE;}
1867 }
1868
b647652d 1869
21a3aa09 1870 ffile->cd();
a6ee503a 1871
3c3709c4 1872 //
67be5c77 1873 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 1874 //
21a3aa09 1875 const Int_t ntracks = fesd->GetNumberOfTracks();
3c3709c4 1876 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1877
1878 TObjArray trkArray;
1879 UShort_t *selectedIdx=new UShort_t[ntracks];
1880
1881 for (Int_t itrack=0; itrack<ntracks; itrack++){
98a50ff3 1882 const Double_t kMaxStep = 1; //max step over the material
3c3709c4 1883 Bool_t ok;
1884
21a3aa09 1885 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 1886 if (!track) continue;
1887
1888 AliExternalTrackParam *tpcTrack =
1889 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 1890 ok = kFALSE;
1891 if (tpcTrack)
1892 ok = AliTracker::
52dd4a8c 1893 PropagateTrackToBxByBz(tpcTrack,kRadius,track->GetMass(),kMaxStep,kFALSE);
43c9dae1 1894
3c3709c4 1895 if (ok) {
1896 Int_t n=trkArray.GetEntriesFast();
1897 selectedIdx[n]=track->GetID();
1898 trkArray.AddLast(tpcTrack);
1899 }
1900
3d65e645 1901 //Tracks refitted by ITS should already be at the SPD vertex
1902 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1903
1904 AliTracker::
52dd4a8c 1905 PropagateTrackToBxByBz(track,kRadius,track->GetMass(),kMaxStep,kFALSE);
1906 Double_t x[3]; track->GetXYZ(x);
1907 Double_t b[3]; AliTracker::GetBxByBz(x,b);
1908 track->RelateToVertexBxByBz(fesd->GetPrimaryVertexSPD(), b, kVeryBig);
3c3709c4 1909
3c3709c4 1910 }
1911
1912 //
1913 // Improve the reconstructed primary vertex position using the tracks
1914 //
59224b2b 1915 Bool_t runVertexFinderTracks = fRunVertexFinderTracks;
1916 if(fesd->GetPrimaryVertexSPD()) {
1917 TString vtitle = fesd->GetPrimaryVertexSPD()->GetTitle();
1918 if(vtitle.Contains("cosmics")) {
1919 runVertexFinderTracks=kFALSE;
1920 }
c060d7fe 1921 }
a00021a7 1922
1923 if (runVertexFinderTracks) {
3c3709c4 1924 // TPC + ITS primary vertex
f09c879d 1925 ftVertexer->SetITSMode();
f2a195c1 1926 ftVertexer->SetConstraintOff();
a00021a7 1927 // get cuts for vertexer from AliGRPRecoParam
1c7554f9 1928 Bool_t constrSPD=kFALSE;
a00021a7 1929 if (grpRecoParam) {
1930 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
1931 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
1932 grpRecoParam->GetVertexerTracksCutsITS(cutsVertexer);
1933 ftVertexer->SetCuts(cutsVertexer);
1934 delete [] cutsVertexer; cutsVertexer = NULL;
1c7554f9 1935 if(grpRecoParam->GetVertexerTracksConstraintITS()) {
1936 if(fDiamondProfile && fDiamondProfile->GetXRes()<kRadius){
1937 ftVertexer->SetVtxStart(fDiamondProfile); // apply constraint only if sigmax is smaller than the beam pipe radius
1938 }else{
1939 if(fDiamondProfileSPD && fDiamondProfileSPD->GetXRes()<kRadius){
1940 ftVertexer->SetVtxStart(fDiamondProfileSPD);
1941 constrSPD=kTRUE;
1942 }
1943 }
dd15203b 1944 }
43c9dae1 1945 }
21a3aa09 1946 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 1947 if (pvtx) {
1c7554f9 1948 if(constrSPD){
1949 TString title=pvtx->GetTitle();
1950 title.Append("SPD");
1951 pvtx->SetTitle(title);
1952 }
3c3709c4 1953 if (pvtx->GetStatus()) {
c264b61b 1954 fesd->SetPrimaryVertexTracks(pvtx);
3c3709c4 1955 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 1956 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 1957 Double_t x[3]; t->GetXYZ(x);
1958 Double_t b[3]; AliTracker::GetBxByBz(x,b);
1959 t->RelateToVertexBxByBz(pvtx, b, kVeryBig);
3c3709c4 1960 }
1961 }
9bcaa1d7 1962 delete pvtx; pvtx=NULL;
3c3709c4 1963 }
1964
1965 // TPC-only primary vertex
f09c879d 1966 ftVertexer->SetTPCMode();
f2a195c1 1967 ftVertexer->SetConstraintOff();
a00021a7 1968 // get cuts for vertexer from AliGRPRecoParam
1969 if (grpRecoParam) {
1970 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
1971 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
1972 grpRecoParam->GetVertexerTracksCutsTPC(cutsVertexer);
1973 ftVertexer->SetCuts(cutsVertexer);
1974 delete [] cutsVertexer; cutsVertexer = NULL;
dd15203b 1975 if(fDiamondProfileTPC && grpRecoParam->GetVertexerTracksConstraintTPC()) {
1976 if(fDiamondProfileTPC->GetXRes()<kRadius) ftVertexer->SetVtxStart(fDiamondProfileTPC); // apply constraint only if sigmax is smaller than the beam pipe radius
1977 }
43c9dae1 1978 }
21a3aa09 1979 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 1980 if (pvtx) {
1981 if (pvtx->GetStatus()) {
21a3aa09 1982 fesd->SetPrimaryVertexTPC(pvtx);
3d65e645 1983 for (Int_t i=0; i<ntracks; i++) {
1984 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 1985 Double_t x[3]; t->GetXYZ(x);
1986 Double_t b[3]; AliTracker::GetBxByBz(x,b);
1987 t->RelateToVertexTPCBxByBz(pvtx, b, kVeryBig);
3c3709c4 1988 }
1989 }
9bcaa1d7 1990 delete pvtx; pvtx=NULL;
3c3709c4 1991 }
1992
1993 }
1994 delete[] selectedIdx;
1995
1c7554f9 1996 if(fDiamondProfile && fDiamondProfile->GetXRes()<kRadius) fesd->SetDiamond(fDiamondProfile);
1997 else fesd->SetDiamond(fDiamondProfileSPD);
c5e3e5d1 1998
d1683eef 1999 if (fRunV0Finder) {
2000 // V0 finding
2001 AliV0vertexer vtxer;
21a3aa09 2002 vtxer.Tracks2V0vertices(fesd);
5e4ff34d 2003
d1683eef 2004 if (fRunCascadeFinder) {
2005 // Cascade finding
2006 AliCascadeVertexer cvtxer;
21a3aa09 2007 cvtxer.V0sTracks2CascadeVertices(fesd);
d1683eef 2008 }
5e4ff34d 2009 }
2010
596a855f 2011 // write ESD
21a3aa09 2012 if (fCleanESD) CleanESD(fesd);
854c6476 2013
514cb8c7 2014 if (fRunQA && IsInTasks(AliQAv1::kESDS)) {
eca4fa66 2015 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
aeb8fc30 2016 AliQAManager::QAManager()->RunOneEvent(fesd, fhltesd) ;
57acd2d2 2017 }
bea94759 2018 if (fRunGlobalQA) {
eca4fa66 2019 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
57acd2d2 2020 qadm->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
514cb8c7 2021 if (qadm && IsInTasks(AliQAv1::kESDS))
4e25ac79 2022 qadm->Exec(AliQAv1::kESDS, fesd);
b03591ab 2023 }
854c6476 2024
8b12d288 2025 // copy HLT decision from HLTesd to esd
2026 // the most relevant information is stored in a reduced container in the esd,
2027 // while the full information can be found in the HLTesd
2028 TObject* pHLTSrc=fhltesd->FindListObject(AliESDHLTDecision::Name());
2029 TObject* pHLTTgt=fesd->FindListObject(AliESDHLTDecision::Name());
2030 if (pHLTSrc && pHLTTgt) {
2031 pHLTSrc->Copy(*pHLTTgt);
2032 }
2033
ee7c441c 2034 if (fWriteESDfriend)
21a3aa09 2035 fesd->GetESDfriend(fesdf);
ee7c441c 2036
21a3aa09 2037 ftree->Fill();
ee7c441c 2038 if (fWriteESDfriend) ftreeF->Fill();
500d54ab 2039
2d91a353 2040 // Auto-save the ESD tree in case of prompt reco @P2
be103ac8 2041 if (fRawReader && fRawReader->UseAutoSaveESD()) {
2d91a353 2042 ftree->AutoSave("SaveSelf");
ee7c441c 2043 if (fWriteESDfriend) ftreeF->AutoSave("SaveSelf");
be103ac8 2044 TFile *friendfile = (TFile *)(gROOT->GetListOfFiles()->FindObject("AliESDfriends.root"));
2045 if (friendfile) friendfile->Save();
2046 }
2d91a353 2047
500d54ab 2048 // write HLT ESD
21a3aa09 2049 fhlttree->Fill();
1d99986f 2050
14dd053c 2051 // call AliEVE
2052 if (fRunAliEVE) RunAliEVE();
2053
21a3aa09 2054 fesd->Reset();
2055 fhltesd->Reset();
5728d3d5 2056 if (fWriteESDfriend) {
21a3aa09 2057 fesdf->~AliESDfriend();
2058 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 2059 }
a5fa6165 2060
ac4a7581 2061 gSystem->GetProcInfo(&procInfo);
d97f1dbe 2062 Long_t dMres=(procInfo.fMemResident-oldMres)/1024;
2063 Long_t dMvir=(procInfo.fMemVirtual-oldMvir)/1024;
2064 Float_t dCPU=procInfo.fCpuUser+procInfo.fCpuSys-oldCPU;
2065 aveDMres+=(dMres-aveDMres)/(iEvent-fFirstEvent+1);
2066 aveDMvir+=(dMvir-aveDMvir)/(iEvent-fFirstEvent+1);
2067 aveDCPU+=(dCPU-aveDCPU)/(iEvent-fFirstEvent+1);
2068 AliInfo(Form("======================= End Event %d: Res %d(%3d <%3d>) Vir %d(%3d <%3d>) CPU %5.2f <%5.2f> ===================",
2069 iEvent, procInfo.fMemResident/1024, dMres, aveDMres, procInfo.fMemVirtual/1024, dMvir, aveDMvir, dCPU, aveDCPU));
470f88b0 2070 oldMres=procInfo.fMemResident;
2071 oldMvir=procInfo.fMemVirtual;
2072 oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
a5fa6165 2073
ca13fb87 2074 fEventInfo.Reset();
ac4a7581 2075 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
42ec5d3d 2076 if (fReconstructor[iDet]) {
a00021a7 2077 fReconstructor[iDet]->SetRecoParam(NULL);
42ec5d3d 2078 fReconstructor[iDet]->SetEventInfo(NULL);
2079 }
1f26f3e7 2080 if (fTracker[iDet]) fTracker[iDet]->SetEventInfo(NULL);
ca13fb87 2081 }
2082
53c8f690 2083 if (fRunQA || fRunGlobalQA)
eca4fa66 2084 AliQAManager::QAManager()->Increment() ;
53c8f690 2085
ca13fb87 2086 return kTRUE;
21a3aa09 2087}
2088
21a3aa09 2089//_____________________________________________________________________________
4b71572b 2090void AliReconstruction::SlaveTerminate()
21a3aa09 2091{
4b71572b 2092 // Finalize the run on the slave side
21a3aa09 2093 // Called after the exit
2094 // from the event loop
52dd4a8c 2095 AliCodeTimerAuto("",0);
21a3aa09 2096
2097 if (fIsNewRunLoader) { // galice.root didn't exist
2098 fRunLoader->WriteHeader("OVERWRITE");
2099 fRunLoader->CdGAFile();
2100 fRunLoader->Write(0, TObject::kOverwrite);
2101 }
2102
f747912b 2103 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
2104 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
2105
2106 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
2107 cdbMapCopy->SetOwner(1);
2108 cdbMapCopy->SetName("cdbMap");
2109 TIter iter(cdbMap->GetTable());
2110
2111 TPair* pair = 0;
2112 while((pair = dynamic_cast<TPair*> (iter.Next()))){
2113 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
2114 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
2115 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
2116 }
2117
2118 TList *cdbListCopy = new TList();
2119 cdbListCopy->SetOwner(1);
2120 cdbListCopy->SetName("cdbList");
2121
2122 TIter iter2(cdbList);
2123
b940cb9b 2124 AliCDBId* id=0;
e84c88f5 2125 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 2126 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 2127 }
2128
21a3aa09 2129 ftree->GetUserInfo()->Add(cdbMapCopy);
2130 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 2131
46698ae4 2132
21a3aa09 2133 ffile->cd();
aa3c69a9 2134
562dd0b4 2135 // we want to have only one tree version number
21a3aa09 2136 ftree->Write(ftree->GetName(),TObject::kOverwrite);
63314086 2137 fhlttree->Write(fhlttree->GetName(),TObject::kOverwrite);
f3a97c86 2138
ee7c441c 2139 if (fWriteESDfriend) {
2140 ffileF->cd();
2141 ftreeF->Write(ftreeF->GetName(),TObject::kOverwrite);
2142 }
2143
a7a1e1c7 2144// Finish with Plane Efficiency evaluation: before of CleanUp !!!
2145 if (fRunPlaneEff && !FinishPlaneEff()) {
2146 AliWarning("Finish PlaneEff evaluation failed");
2147 }
2148
930e6e3e 2149 // End of cycle for the in-loop
87da0921 2150
2151 if (fRunQA || fRunGlobalQA) {
5cbed243 2152 AliQAManager::QAManager()->EndOfCycle() ;
81d57268 2153 if (fInput &&
2154 !fProofOutputLocation.IsNull() &&
2155 fProofOutputArchive.IsNull() &&
2156 !fProofOutputDataset) {
2157 TString qaOutputFile(Form("%sMerged.%s.Data.root",
2158 fProofOutputLocation.Data(),
2159 AliQAv1::GetQADataFileName()));
2160 TProofOutputFile *qaProofFile = new TProofOutputFile(Form("Merged.%s.Data.root",
2161 AliQAv1::GetQADataFileName()));
2162 qaProofFile->SetOutputFileName(qaOutputFile.Data());
2163 if (AliDebugLevel() > 0) qaProofFile->Dump();
2164 fOutput->Add(qaProofFile);
2165 MergeQA(qaProofFile->GetFileName());
87da0921 2166 }
2167 else {
2168 MergeQA();
2169 }
2170 }
2171
4b71572b 2172 gROOT->cd();
2173 CleanUp();
81d57268 2174
2175 if (fInput) {
2176 if (!fProofOutputFileName.IsNull() &&
2177 !fProofOutputLocation.IsNull() &&
2178 fProofOutputDataset &&
2179 !fProofOutputArchive.IsNull()) {
2180 TProofOutputFile *zipProofFile = new TProofOutputFile(fProofOutputFileName.Data(),
2181 "DROV",
2182 fProofOutputLocation.Data());
2183 if (AliDebugLevel() > 0) zipProofFile->Dump();
2184 fOutput->Add(zipProofFile);
2185 TString fileList(fProofOutputArchive.Data());
2186 fileList.ReplaceAll(","," ");
38c18bf1 2187 TString command;
2188#if ROOT_SVN_REVISION >= 30174
2189 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(kTRUE),zipProofFile->GetFileName(),fileList.Data());
2190#else
2191 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(),zipProofFile->GetFileName(),fileList.Data());
2192#endif
2193 AliInfo(Form("Executing: %s",command.Data()));
2194 gSystem->Exec(command.Data());
81d57268 2195 }
2196 }
4b71572b 2197}
2198
2199//_____________________________________________________________________________
2200void AliReconstruction::Terminate()
2201{
f3a97c86 2202 // Create tags for the events in the ESD tree (the ESD tree is always present)
2203 // In case of empty events the tags will contain dummy values
52dd4a8c 2204 AliCodeTimerAuto("",0);
4b71572b 2205
e6d66370 2206 // Do not call the ESD tag creator in case of PROOF-based reconstruction
2207 if (!fInput) {
2208 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
2209 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData, AliQAv1::Instance()->GetQA(), AliQAv1::Instance()->GetEventSpecies(), AliQAv1::kNDET, AliRecoParam::kNSpecies);
9bcaa1d7 2210 delete esdtagCreator;
e6d66370 2211 }
e84c88f5 2212
795e4a22 2213 // Cleanup of CDB manager: cache and active storages!
2214 AliCDBManager::Instance()->ClearCache();
596a855f 2215}
2216
b26c3770 2217//_____________________________________________________________________________
2218Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
2219{
2220// run the local reconstruction
aa3c69a9 2221
0f88822a 2222 static Int_t eventNr=0;
52dd4a8c 2223 AliCodeTimerAuto("",0)
b26c3770 2224
2225 TString detStr = detectors;
ac4a7581 2226 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b26c3770 2227 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2228 AliReconstructor* reconstructor = GetReconstructor(iDet);
2229 if (!reconstructor) continue;
2230 AliLoader* loader = fLoader[iDet];
f6806ad3 2231 // Matthias April 2008: temporary fix to run HLT reconstruction
2232 // although the HLT loader is missing
2233 if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
2234 if (fRawReader) {
44ed7a66 2235 reconstructor->Reconstruct(fRawReader, NULL);
f6806ad3 2236 } else {
44ed7a66 2237 TTree* dummy=NULL;
2238 reconstructor->Reconstruct(dummy, NULL);
f6806ad3 2239 }
2240 continue;
2241 }
d76c31f4 2242 if (!loader) {
2243 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
2244 continue;
2245 }
b26c3770 2246 // conversion of digits
2247 if (fRawReader && reconstructor->HasDigitConversion()) {
2248 AliInfo(Form("converting raw data digits into root objects for %s",
2249 fgkDetectorName[iDet]));
30bbd491 2250// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
52dd4a8c 2251// fgkDetectorName[iDet]),0);
b26c3770 2252 loader->LoadDigits("update");
2253 loader->CleanDigits();
2254 loader->MakeDigitsContainer();
2255 TTree* digitsTree = loader->TreeD();
2256 reconstructor->ConvertDigits(fRawReader, digitsTree);
2257 loader->WriteDigits("OVERWRITE");
2258 loader->UnloadDigits();
b26c3770 2259 }
b26c3770 2260 // local reconstruction
b26c3770 2261 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
52dd4a8c 2262 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]),0);
b26c3770 2263 loader->LoadRecPoints("update");
2264 loader->CleanRecPoints();
2265 loader->MakeRecPointsContainer();
2266 TTree* clustersTree = loader->TreeR();
2267 if (fRawReader && !reconstructor->HasDigitConversion()) {
2268 reconstructor->Reconstruct(fRawReader, clustersTree);
2269 } else {
2270 loader->LoadDigits("read");
2271 TTree* digitsTree = loader->TreeD();
2272 if (!digitsTree) {
44ed7a66 2273 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
13effe3f 2274 if (fStopOnError)
2275 return kFALSE;
b26c3770 2276 } else {
44ed7a66 2277 reconstructor->Reconstruct(digitsTree, clustersTree);
514cb8c7 2278 if (fRunQA && IsInTasks(AliQAv1::kDIGITSR)) {
eca4fa66 2279 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
2280 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, digitsTree) ;
44ed7a66 2281 }
b26c3770 2282 }
2283 loader->UnloadDigits();
2284 }
514cb8c7 2285 if (fRunQA && IsInTasks(AliQAv1::kRECPOINTS)) {
eca4fa66 2286 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
2287 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, clustersTree) ;
57acd2d2 2288 }
eca4fa66 2289 loader->WriteRecPoints("OVERWRITE");
2290 loader->UnloadRecPoints();
2291 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
a00021a7 2292 }
13effe3f 2293 IsSelected("CTP", detStr);
a00021a7 2294 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
b26c3770 2295 AliError(Form("the following detectors were not found: %s",
2296 detStr.Data()));
13effe3f 2297 if (fStopOnError)
2298 return kFALSE;
b26c3770 2299 }
0f88822a 2300 eventNr++;
b26c3770 2301 return kTRUE;
2302}
58e8dc31 2303//_____________________________________________________________________________
2304Bool_t AliReconstruction::RunSPDTrackleting(AliESDEvent*& esd)
2305{
2306// run the SPD trackleting (for SPD efficiency purpouses)
2307
52dd4a8c 2308 AliCodeTimerAuto("",0)
58e8dc31 2309
2310 Double_t vtxPos[3] = {0, 0, 0};
2311 Double_t vtxErr[3] = {0.0, 0.0, 0.0};
2312/*
2313 TArrayF mcVertex(3);
2314 // if(MC)
2315 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
2316 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
2317 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
2318 }
2319*/
2320 const AliESDVertex *vertex = esd->GetVertex();
2321 if(!vertex){
2322 AliWarning("Vertex not found");
2323 return kFALSE;
2324 }
2325 vertex->GetXYZ(vtxPos);
2326 vertex->GetSigmaXYZ(vtxErr);
2327 if (fSPDTrackleter) {
2328 AliInfo("running the SPD Trackleter for Plane Efficiency Evaluation");
2329
2330 // load clusters
2331 fLoader[0]->LoadRecPoints("read");
2332 TTree* tree = fLoader[0]->TreeR();
2333 if (!tree) {
2334 AliError("Can't get the ITS cluster tree");
2335 return kFALSE;
2336 }
2337 fSPDTrackleter->LoadClusters(tree);
2338 fSPDTrackleter->SetVertex(vtxPos, vtxErr);
2339 // run trackleting
2340 if (fSPDTrackleter->Clusters2Tracks(esd) != 0) {
84290fcc 2341 AliWarning("AliITSTrackleterSPDEff Clusters2Tracks failed");
58e8dc31 2342 // fLoader[0]->UnloadRecPoints();
2343 return kFALSE;
2344 }
2345//fSPDTrackleter->UnloadRecPoints();
2346 } else {
2347 AliWarning("SPDTrackleter not available");
2348 return kFALSE;
2349 }
2350 return kTRUE;
2351}
b26c3770 2352
596a855f 2353//_____________________________________________________________________________
af885e0f 2354Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 2355{
2356// run the barrel tracking
2357
52dd4a8c 2358 AliCodeTimerAuto("",0)
030b532d 2359
92bffc4d 2360 AliVertexer *vertexer = CreateVertexer();
2361 if (!vertexer) return kFALSE;
2362
3c99b88f 2363 AliInfo(Form("running the ITS vertex finder: %s",vertexer->ClassName()));
2257f27e 2364 AliESDVertex* vertex = NULL;
92bffc4d 2365 if (fLoader[0]) {
2366 fLoader[0]->LoadRecPoints();
2367 TTree* cltree = fLoader[0]->TreeR();
2368 if (cltree) {
2369 if(fDiamondProfileSPD) vertexer->SetVtxStart(fDiamondProfileSPD);
2370 vertex = vertexer->FindVertexForCurrentEvent(cltree);
308c2f7c 2371 }
2372 else {
92bffc4d 2373 AliError("Can't get the ITS cluster tree");
308c2f7c 2374 }
92bffc4d 2375 fLoader[0]->UnloadRecPoints();
2257f27e 2376 }
92bffc4d 2377 else {
2378 AliError("Can't get the ITS loader");
2379 }
2380 if(!vertex){
2381 AliWarning("Vertex not found");
2382 vertex = new AliESDVertex();
2383 vertex->SetName("default");
2384 }
2385 else {
2386 vertex->SetName("reconstructed");
2257f27e 2387 }
92bffc4d 2388
2389 Double_t vtxPos[3];
2390 Double_t vtxErr[3];
2391 vertex->GetXYZ(vtxPos);
2392 vertex->GetSigmaXYZ(vtxErr);
2393
06cc9d95 2394 esd->SetPrimaryVertexSPD(vertex);
73c51de2 2395 AliESDVertex *vpileup = NULL;
2396 Int_t novertices = 0;
2397 vpileup = vertexer->GetAllVertices(novertices);
2398 if(novertices>1){
2399 for (Int_t kk=1; kk<novertices; kk++)esd->AddPileupVertexSPD(&vpileup[kk]);
2400 }
32e449be 2401 // if SPD multiplicity has been determined, it is stored in the ESD
92bffc4d 2402 AliMultiplicity *mult = vertexer->GetMultiplicity();
32e449be 2403 if(mult)esd->SetMultiplicity(mult);
2404
ac4a7581 2405 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2406 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
2407 }
2257f27e 2408 delete vertex;
2409
92bffc4d 2410 delete vertexer;
2411
2257f27e 2412 return kTRUE;
2413}
2414
1f46a9ae 2415//_____________________________________________________________________________
af885e0f 2416Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 2417{
2418// run the HLT barrel tracking
2419
52dd4a8c 2420 AliCodeTimerAuto("",0)
1f46a9ae 2421
2422 if (!fRunLoader) {
2423 AliError("Missing runLoader!");
2424 return kFALSE;
2425 }
2426
2427 AliInfo("running HLT tracking");
2428
2429 // Get a pointer to the HLT reconstructor
ac4a7581 2430 AliReconstructor *reconstructor = GetReconstructor(kNDetectors-1);
1f46a9ae 2431 if (!reconstructor) return kFALSE;
2432
2433 // TPC + ITS
2434 for (Int_t iDet = 1; iDet >= 0; iDet--) {
2435 TString detName = fgkDetectorName[iDet];
2436 AliDebug(1, Form("%s HLT tracking", detName.Data()));
2437 reconstructor->SetOption(detName.Data());
d76c31f4 2438 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 2439 if (!tracker) {
2440 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
2441 if (fStopOnError) return kFALSE;
9dcc06e1 2442 continue;
1f46a9ae 2443 }
2444 Double_t vtxPos[3];
2445 Double_t vtxErr[3]={0.005,0.005,0.010};
2446 const AliESDVertex *vertex = esd->GetVertex();
2447 vertex->GetXYZ(vtxPos);
2448 tracker->SetVertex(vtxPos,vtxErr);
2449 if(iDet != 1) {
2450 fLoader[iDet]->LoadRecPoints("read");
2451 TTree* tree = fLoader[iDet]->TreeR();
2452 if (!tree) {
2453 AliError(Form("Can't get the %s cluster tree", detName.Data()));
2454 return kFALSE;
2455 }
2456 tracker->LoadClusters(tree);
2457 }
2458 if (tracker->Clusters2Tracks(esd) != 0) {
2459 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
2460 return kFALSE;
2461 }
2462 if(iDet != 1) {
2463 tracker->UnloadClusters();
2464 }
2465 delete tracker;
2466 }
2467
1f46a9ae 2468 return kTRUE;
2469}
2470
e66fbafb 2471//_____________________________________________________________________________
af885e0f 2472Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 2473{
2474// run the muon spectrometer tracking
2475
52dd4a8c 2476 AliCodeTimerAuto("",0)
e66fbafb 2477
2478 if (!fRunLoader) {
2479 AliError("Missing runLoader!");
2480 return kFALSE;
2481 }
2482 Int_t iDet = 7; // for MUON
2483
2484 AliInfo("is running...");
2485
2486 // Get a pointer to the MUON reconstructor
2487 AliReconstructor *reconstructor = GetReconstructor(iDet);
2488 if (!reconstructor) return kFALSE;
2489
2490
2491 TString detName = fgkDetectorName[iDet];
2492 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 2493 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 2494 if (!tracker) {
2495 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
2496 return kFALSE;
2497 }
2498
e66fbafb 2499 // read RecPoints
761350a6 2500 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 2501
761350a6 2502 tracker->LoadClusters(fLoader[iDet]->TreeR());
2503
2504 Int_t rv = tracker->Clusters2Tracks(esd);
2505
e66fbafb 2506 fLoader[iDet]->UnloadRecPoints();
2507
c1954ee5 2508 tracker->UnloadClusters();
2509
e66fbafb 2510 delete tracker;
2511
cb23c6ca 2512 if ( rv )
2513 {
2514 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
2515 return kFALSE;
2516 }
2517
e66fbafb 2518 return kTRUE;
2519}
2520
2521
2257f27e 2522//_____________________________________________________________________________
10d100d4 2523Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd,AliESDpid &PID)
2257f27e 2524{
2525// run the barrel tracking
0f88822a 2526 static Int_t eventNr=0;
52dd4a8c 2527 AliCodeTimerAuto("",0)
24f7a148 2528
815c2b38 2529 AliInfo("running tracking");
596a855f 2530
1f26f3e7 2531 // Set the event info which is used
2532 // by the trackers in order to obtain
2533 // information about read-out detectors,
2534 // trigger etc.
2535 AliDebug(1, "Setting event info");
2536 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2537 if (!fTracker[iDet]) continue;
2538 fTracker[iDet]->SetEventInfo(&fEventInfo);
2539 }
2540
91b876d1 2541 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 2542 if (fReconstructor[11] && fLoader[11]) {
2543 fLoader[11]->LoadRecPoints("READ");
2544 TTree *treeR = fLoader[11]->TreeR();
89916438 2545 if (treeR) {
2546 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
2547 }
d76c31f4 2548 }
91b876d1 2549
b8cd5251 2550 // pass 1: TPC + ITS inwards
2551 for (Int_t iDet = 1; iDet >= 0; iDet--) {
2552 if (!fTracker[iDet]) continue;
2553 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 2554
b8cd5251 2555 // load clusters
2556 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2557 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 2558 TTree* tree = fLoader[iDet]->TreeR();
2559 if (!tree) {
2560 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2561 return kFALSE;
2562 }
b8cd5251 2563 fTracker[iDet]->LoadClusters(tree);
6efecea1 2564 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2565 // run tracking
2566 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
2567 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 2568 return kFALSE;
2569 }
878e1fe1 2570 // preliminary PID in TPC needed by the ITS tracker
2571 if (iDet == 1) {
b26c3770 2572 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
10d100d4 2573 PID.MakePID(esd,kTRUE);
0f88822a 2574 }
6efecea1 2575 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 2576 }
596a855f 2577
b8cd5251 2578 // pass 2: ALL backwards
aa3c69a9 2579
ac4a7581 2580 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2581 if (!fTracker[iDet]) continue;
2582 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
2583
2584 // load clusters
2585 if (iDet > 1) { // all except ITS, TPC
2586 TTree* tree = NULL;
7b61cd9c 2587 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2588 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 2589 tree = fLoader[iDet]->TreeR();
b8cd5251 2590 if (!tree) {
eca4fa66 2591 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
2592 return kFALSE;
24f7a148 2593 }
0f88822a 2594 fTracker[iDet]->LoadClusters(tree);
6efecea1 2595 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2596 }
24f7a148 2597
b8cd5251 2598 // run tracking
283f39c6 2599 if (iDet>1) // start filling residuals for the "outer" detectors
eca4fa66 2600 if (fRunGlobalQA) {
2601 AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);
2602 TObjArray ** arr = AliTracker::GetResidualsArray() ;
c9526f68 2603 if (arr) {
0a349581 2604 AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
2605 TObjArray * elem = arr[AliRecoParam::AConvert(es)];
c9526f68 2606 if ( elem && (! elem->At(0)) ) {
2607 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
2608 if (qadm) qadm->InitRecPointsForTracker() ;
2609 }
2610 }
eca4fa66 2611 }
b8cd5251 2612 if (fTracker[iDet]->PropagateBack(esd) != 0) {
2613 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 2614 // return kFALSE;
b8cd5251 2615 }
24f7a148 2616
b8cd5251 2617 // unload clusters
6e65648b 2618 if (iDet > 3) { // all except ITS, TPC, TRD and TOF
b8cd5251 2619 fTracker[iDet]->UnloadClusters();
7b61cd9c 2620 fLoader[iDet]->UnloadRecPoints();
b8cd5251 2621 }
8f37df88 2622 // updated PID in TPC needed by the ITS tracker -MI
2623 if (iDet == 1) {
10d100d4 2624 //GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
2625 //AliESDpid::MakePID(esd);
2626 PID.MakePID(esd,kTRUE);
8f37df88 2627 }
6efecea1 2628 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 2629 }
283f39c6 2630 //stop filling residuals for the "outer" detectors
57acd2d2 2631 if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);
596a855f 2632
b8cd5251 2633 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 2634
b8cd5251 2635 for (Int_t iDet = 2; iDet >= 0; iDet--) {
2636 if (!fTracker[iDet]) continue;
2637 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 2638
b8cd5251 2639 // run tracking
283f39c6 2640 if (iDet<2) // start filling residuals for TPC and ITS
eca4fa66 2641 if (fRunGlobalQA) {
2642 AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);
2643 TObjArray ** arr = AliTracker::GetResidualsArray() ;
c9526f68 2644 if (arr) {
0a349581 2645 AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
2646 TObjArray * elem = arr[AliRecoParam::AConvert(es)];
c9526f68 2647 if ( elem && (! elem->At(0)) ) {
2648 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
2649 if (qadm) qadm->InitRecPointsForTracker() ;
2650 }
2651 }
eca4fa66 2652 }
2653
b8cd5251 2654 if (fTracker[iDet]->RefitInward(esd) != 0) {
2655 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 2656 // return kFALSE;
b8cd5251 2657 }
db2368d0 2658 // run postprocessing
2659 if (fTracker[iDet]->PostProcess(esd) != 0) {
2660 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
2661 // return kFALSE;
2662 }
6efecea1 2663 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
6e65648b 2664 }
2665
2666 // write space-points to the ESD in case alignment data output
2667 // is switched on
2668 if (fWriteAlignmentData)
2669 WriteAlignmentData(esd);
2670
2671 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2672 if (!fTracker[iDet]) continue;
b8cd5251 2673 // unload clusters
2674 fTracker[iDet]->UnloadClusters();
6efecea1 2675 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 2676 fLoader[iDet]->UnloadRecPoints();
6efecea1 2677 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 2678 }
283f39c6 2679 // stop filling residuals for TPC and ITS
57acd2d2 2680 if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);
854c6476 2681
0f88822a 2682 eventNr++;
596a855f 2683 return kTRUE;
2684}
2685
d64bd07d 2686//_____________________________________________________________________________
2687Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
2688 //
2689 // Remove the data which are not needed for the physics analysis.
2690 //
2691
d64bd07d 2692 Int_t nTracks=esd->GetNumberOfTracks();
18571674 2693 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 2694 AliInfo
2695 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 2696
18571674 2697 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 2698 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 2699
7f68891d 2700 nTracks=esd->GetNumberOfTracks();
18571674 2701 nV0s=esd->GetNumberOfV0s();
cf37fd88 2702 AliInfo
ae5d5566 2703 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 2704
7f68891d 2705 return rc;
d64bd07d 2706}
2707
596a855f 2708//_____________________________________________________________________________
af885e0f 2709Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 2710{
2711// fill the event summary data
2712
52dd4a8c 2713 AliCodeTimerAuto("",0)
0f88822a 2714 static Int_t eventNr=0;
596a855f 2715 TString detStr = detectors;
abe0c04e 2716
f1640d23 2717 AliSysInfo::AddStamp(Form("FillESDb%d",eventNr), -19,-19, eventNr);
ac4a7581 2718 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
abe0c04e 2719 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 2720 AliReconstructor* reconstructor = GetReconstructor(iDet);
2721 if (!reconstructor) continue;
4b71572b 2722 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
2723 TTree* clustersTree = NULL;
2724 if (fLoader[iDet]) {
2725 fLoader[iDet]->LoadRecPoints("read");
2726 clustersTree = fLoader[iDet]->TreeR();
2727 if (!clustersTree) {
2728 AliError(Form("Can't get the %s clusters tree",
2729 fgkDetectorName[iDet]));
2730 if (fStopOnError) return kFALSE;
2731 }
2732 }
2733 if (fRawReader && !reconstructor->HasDigitConversion()) {
2734 reconstructor->FillESD(fRawReader, clustersTree, esd);
2735 } else {
2736 TTree* digitsTree = NULL;
d76c31f4 2737 if (fLoader[iDet]) {
4b71572b 2738 fLoader[iDet]->LoadDigits("read");
2739 digitsTree = fLoader[iDet]->TreeD();
2740 if (!digitsTree) {
2741 AliError(Form("Can't get the %s digits tree",
b26c3770 2742 fgkDetectorName[iDet]));
2743 if (fStopOnError) return kFALSE;
2744 }
2745 }
4b71572b 2746 reconstructor->FillESD(digitsTree, clustersTree, esd);
2747 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
2748 }
2749 if (fLoader[iDet]) {
2750 fLoader[iDet]->UnloadRecPoints();
596a855f 2751 }
2752 }
13effe3f 2753
2754 IsSelected("CTP", detStr);
596a855f 2755 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 2756 AliError(Form("the following detectors were not found: %s",
2757 detStr.Data()));
596a855f 2758 if (fStopOnError) return kFALSE;
2759 }
f1640d23 2760 AliSysInfo::AddStamp(Form("FillESDe%d",eventNr), -20,-20, eventNr);
0f88822a 2761 eventNr++;
596a855f 2762 return kTRUE;
2763}
2764
b647652d 2765//_____________________________________________________________________________
af885e0f 2766Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 2767{
2768 // Reads the trigger decision which is
2769 // stored in Trigger.root file and fills
2770 // the corresponding esd entries
2771
52dd4a8c 2772 AliCodeTimerAuto("",0)
87932dab 2773
b647652d 2774 AliInfo("Filling trigger information into the ESD");
2775
2776 if (fRawReader) {
2777 AliCTPRawStream input(fRawReader);
2778 if (!input.Next()) {
7e88424f 2779 AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
b647652d 2780 }
2781 else {
7e88424f 2782 if (esd->GetTriggerMask() != input.GetClassMask())
2783 AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
2784 input.GetClassMask(),esd->GetTriggerMask()));
2785 if (esd->GetOrbitNumber() != input.GetOrbitID())
2786 AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
2787 input.GetOrbitID(),esd->GetOrbitNumber()));
2788 if (esd->GetBunchCrossNumber() != input.GetBCID())
2789 AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
2790 input.GetBCID(),esd->GetBunchCrossNumber()));
e61ed4b1 2791 AliESDHeader* esdheader = esd->GetHeader();
2792 esdheader->SetL0TriggerInputs(input.GetL0Inputs());
2793 esdheader->SetL1TriggerInputs(input.GetL1Inputs());
2794 esdheader->SetL2TriggerInputs(input.GetL2Inputs());
a6dd87ad 2795 // IR
2796 UInt_t orbit=input.GetOrbitID();
2797 for(Int_t i=0 ; i<input.GetNIRs() ; i++ )
2798 if(TMath::Abs(Int_t(orbit-(input.GetIR(i))->GetOrbit()))<=1){
2799 esdheader->AddTriggerIR(input.GetIR(i));
2800 }
b647652d 2801 }
b024fd7f 2802 }
f7812afc 2803 return kTRUE;
2804}
2805//_____________________________________________________________________________
2806Bool_t AliReconstruction::FillTriggerScalers(AliESDEvent*& esd)
2807{
522fdd91 2808 //Scalers
82ebedd6 2809 //fRunScalers->Print();
2810 if(fRunScalers && fRunScalers->CheckRunScalers()){
a6dd87ad 2811 AliTimeStamp* timestamp = new AliTimeStamp(esd->GetOrbitNumber(), esd->GetPeriodNumber(), esd->GetBunchCrossNumber());
82ebedd6 2812 //AliTimeStamp* timestamp = new AliTimeStamp(10308000, 0, (ULong64_t)486238);
522fdd91 2813 AliESDHeader* esdheader = fesd->GetHeader();
2814 for(Int_t i=0;i<50;i++){
1e78ae8c 2815 if((1ull<<i) & esd->GetTriggerMask()){
6863d231 2816 AliTriggerScalersESD* scalesd = fRunScalers->GetScalersForEventClass( timestamp, i+1);
82ebedd6 2817 if(scalesd)esdheader->SetTriggerScalersRecord(scalesd);
522fdd91 2818 }
2819 }
2820 }
b647652d 2821 return kTRUE;
2822}
001397cd 2823//_____________________________________________________________________________
af885e0f 2824Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 2825{
2826 //
2827 // Filling information from RawReader Header
2828 //
2829
151bea4e 2830 if (!fRawReader) return kFALSE;
2831
001397cd 2832 AliInfo("Filling information from RawReader Header");
151bea4e 2833
2834 esd->SetBunchCrossNumber(fRawReader->GetBCID());
2835 esd->SetOrbitNumber(fRawReader->GetOrbitID());
2836 esd->SetPeriodNumber(fRawReader->GetPeriod());
2837
2838 esd->SetTimeStamp(fRawReader->GetTimestamp());
2839 esd->SetEventType(fRawReader->GetType());
001397cd 2840
2841 return kTRUE;
2842}
2843
2844
596a855f 2845//_____________________________________________________________________________
2846Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
2847{
2848// check whether detName is contained in detectors
2849// if yes, it is removed from detectors
2850
2851 // check if all detectors are selected
2852 if ((detectors.CompareTo("ALL") == 0) ||
2853 detectors.BeginsWith("ALL ") ||
2854 detectors.EndsWith(" ALL") ||
2855 detectors.Contains(" ALL ")) {
2856 detectors = "ALL";
2857 return kTRUE;
2858 }
2859
2860 // search for the given detector
2861 Bool_t result = kFALSE;
2862 if ((detectors.CompareTo(detName) == 0) ||
2863 detectors.BeginsWith(detName+" ") ||
2864 detectors.EndsWith(" "+detName) ||
2865 detectors.Contains(" "+detName+" ")) {
2866 detectors.ReplaceAll(detName, "");
2867 result = kTRUE;
2868 }
2869
2870 // clean up the detectors string
2871 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2872 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2873 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2874
2875 return result;
2876}
e583c30d 2877
f08fc9f5 2878//_____________________________________________________________________________
2879Bool_t AliReconstruction::InitRunLoader()
2880{
2881// get or create the run loader
2882
2883 if (gAlice) delete gAlice;
2884 gAlice = NULL;
2885
52dd4a8c 2886 TFile *gafile = TFile::Open(fGAliceFileName.Data());
2887 // if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2888 if (gafile) { // galice.root exists
2889 gafile->Close();
2890 delete gafile;
2891
b26c3770 2892 // load all base libraries to get the loader classes
2893 TString libs = gSystem->GetLibraries();
ac4a7581 2894 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b26c3770 2895 TString detName = fgkDetectorName[iDet];
2896 if (detName == "HLT") continue;
2897 if (libs.Contains("lib" + detName + "base.so")) continue;
2898 gSystem->Load("lib" + detName + "base.so");
2899 }
f08fc9f5 2900 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2901 if (!fRunLoader) {
2902 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2903 CleanUp();
2904 return kFALSE;
2905 }
325aa76f 2906
b26c3770 2907 fRunLoader->CdGAFile();
325aa76f 2908 fRunLoader->LoadgAlice();
f08fc9f5 2909
6cae184e 2910 //PH This is a temporary fix to give access to the kinematics
2911 //PH that is needed for the labels of ITS clusters
f2ee4290 2912 fRunLoader->LoadHeader();
6cae184e 2913 fRunLoader->LoadKinematics();
2914
f08fc9f5 2915 } else { // galice.root does not exist
2916 if (!fRawReader) {
2917 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
f08fc9f5 2918 }
2919 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2920 AliConfig::GetDefaultEventFolderName(),
2921 "recreate");
2922 if (!fRunLoader) {
2923 AliError(Form("could not create run loader in file %s",
2924 fGAliceFileName.Data()));
2925 CleanUp();
2926 return kFALSE;
2927 }
21a3aa09 2928 fIsNewRunLoader = kTRUE;
f08fc9f5 2929 fRunLoader->MakeTree("E");
21a3aa09 2930
973388c2 2931 if (fNumberOfEventsPerFile > 0)
2932 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2933 else
21a3aa09 2934 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 2935 }
2936
2937 return kTRUE;
2938}
2939
c757bafd 2940//_____________________________________________________________________________
b8cd5251 2941AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 2942{
f08fc9f5 2943// get the reconstructor object and the loader for a detector
c757bafd 2944
7e88424f 2945 if (fReconstructor[iDet]) {
2946 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2947 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2948 fReconstructor[iDet]->SetRecoParam(par);
42ec5d3d 2949 fReconstructor[iDet]->SetRunInfo(fRunInfo);
7e88424f 2950 }
2951 return fReconstructor[iDet];
2952 }
b8cd5251 2953
2954 // load the reconstructor object
2955 TPluginManager* pluginManager = gROOT->GetPluginManager();
2956 TString detName = fgkDetectorName[iDet];
2957 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 2958
2959 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 2960
b8cd5251 2961 AliReconstructor* reconstructor = NULL;
2962 // first check if a plugin is defined for the reconstructor
2963 TPluginHandler* pluginHandler =
2964 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 2965 // if not, add a plugin for it
2966 if (!pluginHandler) {
b8cd5251 2967 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 2968 TString libs = gSystem->GetLibraries();
2969 if (libs.Contains("lib" + detName + "base.so") ||
2970 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 2971 pluginManager->AddHandler("AliReconstructor", detName,
2972 recName, detName + "rec", recName + "()");
2973 } else {
2974 pluginManager->AddHandler("AliReconstructor", detName,
2975 recName, detName, recName + "()");
c757bafd 2976 }
b8cd5251 2977 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2978 }
2979 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2980 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 2981 }
b8cd5251 2982 if (reconstructor) {
2983 TObject* obj = fOptions.FindObject(detName.Data());
2984 if (obj) reconstructor->SetOption(obj->GetTitle());
1e500f25 2985 reconstructor->SetRunInfo(fRunInfo);
d76c31f4 2986 reconstructor->Init();
b8cd5251 2987 fReconstructor[iDet] = reconstructor;
2988 }
2989
f08fc9f5 2990 // get or create the loader
2991 if (detName != "HLT") {
2992 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2993 if (!fLoader[iDet]) {
2994 AliConfig::Instance()
2995 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2996 detName, detName);
2997 // first check if a plugin is defined for the loader
bb0901a4 2998 pluginHandler =
f08fc9f5 2999 pluginManager->FindHandler("AliLoader", detName);
3000 // if not, add a plugin for it
3001 if (!pluginHandler) {
3002 TString loaderName = "Ali" + detName + "Loader";
3003 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
3004 pluginManager->AddHandler("AliLoader", detName,
3005 loaderName, detName + "base",
3006 loaderName + "(const char*, TFolder*)");
3007 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
3008 }
3009 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
3010 fLoader[iDet] =
3011 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
3012 fRunLoader->GetEventFolder());
3013 }
3014 if (!fLoader[iDet]) { // use default loader
3015 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
3016 }
3017 if (!fLoader[iDet]) {
3018 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 3019 if (fStopOnError) return NULL;
f08fc9f5 3020 } else {
3021 fRunLoader->AddLoader(fLoader[iDet]);
3022 fRunLoader->CdGAFile();
3023 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
3024 fRunLoader->Write(0, TObject::kOverwrite);
3025 }
3026 }
3027 }
3028
7e88424f 3029 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
3030 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
3031 reconstructor->SetRecoParam(par);
42ec5d3d 3032 reconstructor->SetRunInfo(fRunInfo);
7e88424f 3033 }
b8cd5251 3034 return reconstructor;
c757bafd 3035}
3036
2257f27e 3037//_____________________________________________________________________________
92bffc4d 3038AliVertexer* AliReconstruction::CreateVertexer()
2257f27e 3039{
3040// create the vertexer
92bffc4d 3041// Please note that the caller is the owner of the
3042// vertexer
2257f27e 3043
92bffc4d 3044 AliVertexer* vertexer = NULL;
b8cd5251 3045 AliReconstructor* itsReconstructor = GetReconstructor(0);
5ec10f5d 3046 if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) || fRunTracking.Contains("ITS"))) {
92bffc4d 3047 vertexer = itsReconstructor->CreateVertexer();
2257f27e 3048 }
92bffc4d 3049 if (!vertexer) {
815c2b38 3050 AliWarning("couldn't create a vertexer for ITS");
2257f27e 3051 }
3052
92bffc4d 3053 return vertexer;
2257f27e 3054}
3055
24f7a148 3056//_____________________________________________________________________________
b8cd5251 3057Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 3058{
f08fc9f5 3059// create the trackers
44e45fac 3060 AliInfo("Creating trackers");
24f7a148 3061
b8cd5251 3062 TString detStr = detectors;
ac4a7581 3063 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 3064 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
3065 AliReconstructor* reconstructor = GetReconstructor(iDet);
3066 if (!reconstructor) continue;
3067 TString detName = fgkDetectorName[iDet];
1f46a9ae 3068 if (detName == "HLT") {
3069 fRunHLTTracking = kTRUE;
3070 continue;
3071 }
e66fbafb 3072 if (detName == "MUON") {
3073 fRunMuonTracking = kTRUE;
3074 continue;
3075 }
3076
f08fc9f5 3077
d76c31f4 3078 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 3079 if (!fTracker[iDet] && (iDet < 7)) {
3080 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 3081 if (fStopOnError) return kFALSE;
3082 }
6efecea1 3083 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 3084 }
3085
24f7a148 3086 return kTRUE;
3087}
3088
e583c30d 3089//_____________________________________________________________________________
4b71572b 3090void AliReconstruction::CleanUp()
e583c30d 3091{
3092// delete trackers and the run loader and close and delete the file
3093
ac4a7581 3094 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 3095 delete fReconstructor[iDet];
3096 fReconstructor[iDet] = NULL;
3097 fLoader[iDet] = NULL;
3098 delete fTracker[iDet];
3099 fTracker[iDet] = NULL;
3100 }
4b71572b 3101 delete fRunInfo;
7e88424f 3102 fRunInfo = NULL;
3103
58e8dc31 3104 delete fSPDTrackleter;
3105 fSPDTrackleter = NULL;
3106
4b71572b 3107 delete ftVertexer;
21a3aa09 3108 ftVertexer = NULL;
795e4a22 3109
e583c30d 3110 delete fRunLoader;
3111 fRunLoader = NULL;
b649205a 3112 delete fRawReader;
3113 fRawReader = NULL;
4b71572b 3114 delete fParentRawReader;
cd0b062e 3115 fParentRawReader=NULL;
e583c30d 3116
4b71572b 3117 if (ffile) {
3118 ffile->Close();
3119 delete ffile;
3120 ffile = NULL;
24f7a148 3121 }
87da0921 3122
bf76b847 3123 if (AliQAManager::QAManager())
3124 AliQAManager::QAManager()->ShowQA() ;
eca4fa66 3125 AliQAManager::Destroy() ;
3126
24f7a148 3127}
f3a97c86 3128
af885e0f 3129void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 3130{
3131 // Write space-points which are then used in the alignment procedures
6e65648b 3132 // For the moment only ITS, TPC, TRD and TOF
98937d93 3133
98937d93 3134 Int_t ntracks = esd->GetNumberOfTracks();
3135 for (Int_t itrack = 0; itrack < ntracks; itrack++)
3136 {
3137 AliESDtrack *track = esd->GetTrack(itrack);
3138 Int_t nsp = 0;
ef7253ac 3139 Int_t idx[200];
76741755 3140 for (Int_t i=0; i<200; ++i) idx[i] = -1; //PH avoid uninitialized values
81aa7a0d 3141 for (Int_t iDet = 5; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
0ad488b0 3142 nsp += (iDet==GetDetIndex("TRD")) ? track->GetTRDntracklets():track->GetNcls(iDet);
6e65648b 3143
0ad488b0 3144 if (iDet==GetDetIndex("ITS")) { // ITS "extra" clusters
6e65648b 3145 track->GetClusters(iDet,idx);
3146 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
3147 }
3148 }
3149
98937d93 3150 if (nsp) {
3151 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
3152 track->SetTrackPointArray(sp);
3153 Int_t isptrack = 0;
81aa7a0d 3154 for (Int_t iDet = 5; iDet >= 0; iDet--) {
98937d93 3155 AliTracker *tracker = fTracker[iDet];
3156 if (!tracker) continue;
0ad488b0 3157 Int_t nspdet = (iDet==GetDetIndex("TRD")) ? track->GetTRDtracklets(idx):track->GetClusters(iDet,idx);
6e65648b 3158
0ad488b0 3159 if (iDet==GetDetIndex("ITS")) // ITS "extra" clusters
6e65648b 3160 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
3161
98937d93 3162 if (nspdet <= 0) continue;
98937d93 3163 AliTrackPoint p;
3164 Int_t isp = 0;
3165 Int_t isp2 = 0;
4ed6fb1c 3166 while (isp2 < nspdet) {
f3c6e4c9 3167 Bool_t isvalid=kTRUE;
3168
3169 Int_t index=idx[isp++];
3170 if (index < 0) continue;
3171
c12b6e44 3172 TString dets = fgkDetectorName[iDet];
3173 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
3174 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
3175 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
3176 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
f3c6e4c9 3177 isvalid = tracker->GetTrackPointTrackingError(index,p,track);
48ce48d1 3178 } else {
f3c6e4c9 3179 isvalid = tracker->GetTrackPoint(index,p);
48ce48d1 3180 }
3181 isp2++;
98937d93 3182 if (!isvalid) continue;
0ad488b0 3183 if (iDet==GetDetIndex("ITS") && (isp-1)>=6) p.SetExtra();
f3c6e4c9 3184 sp->AddPoint(isptrack,&p); isptrack++;
98937d93 3185 }
98937d93 3186 }
3187 }
3188 }
98937d93 3189}
2e3550da 3190
3191//_____________________________________________________________________________
af885e0f 3192void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 3193{
3194 // The method reads the raw-data error log
3195 // accumulated within the rawReader.
3196 // It extracts the raw-data errors related to
3197 // the current event and stores them into
3198 // a TClonesArray inside the esd object.
3199
3200 if (!fRawReader) return;
3201
3202 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
3203
3204 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
3205 if (!log) continue;
3206 if (iEvent != log->GetEventNumber()) continue;
3207
3208 esd->AddRawDataErrorLog(log);
3209 }
3210
3211}
46698ae4 3212
8661738e 3213//_____________________________________________________________________________
0a035be5 3214// void AliReconstruction::CheckQA()
3215// {
8661738e 3216// check the QA of SIM for this run and remove the detectors
3217// with status Fatal
3218
57acd2d2 3219// TString newRunLocalReconstruction ;
3220// TString newRunTracking ;
3221// TString newFillESD ;
3222//
4e25ac79 3223// for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
3224// TString detName(AliQAv1::GetDetName(iDet)) ;
3225// AliQAv1 * qa = AliQAv1::Instance(AliQAv1::DETECTORINDEX_t(iDet)) ;
3226// if ( qa->IsSet(AliQAv1::DETECTORINDEX_t(iDet), AliQAv1::kSIM, specie, AliQAv1::kFATAL)) {
57acd2d2 3227// AliInfo(Form("QA status for %s %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed",
3228// detName.Data(), AliRecoParam::GetEventSpecieName(es))) ;
3229// } else {
4e25ac79 3230// if ( fRunLocalReconstruction.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3231// fRunLocalReconstruction.Contains("ALL") ) {
3232// newRunLocalReconstruction += detName ;
3233// newRunLocalReconstruction += " " ;
3234// }
4e25ac79 3235// if ( fRunTracking.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3236// fRunTracking.Contains("ALL") ) {
3237// newRunTracking += detName ;
3238// newRunTracking += " " ;
3239// }
4e25ac79 3240// if ( fFillESD.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3241// fFillESD.Contains("ALL") ) {
3242// newFillESD += detName ;
3243// newFillESD += " " ;
3244// }
3245// }
3246// }
3247// fRunLocalReconstruction = newRunLocalReconstruction ;
3248// fRunTracking = newRunTracking ;
3249// fFillESD = newFillESD ;
0a035be5 3250// }
5b188f2f 3251
3252//_____________________________________________________________________________
3253Int_t AliReconstruction::GetDetIndex(const char* detector)
3254{
3255 // return the detector index corresponding to detector
3256 Int_t index = -1 ;
ac4a7581 3257 for (index = 0; index < kNDetectors ; index++) {
5b188f2f 3258 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
3259 break ;
3260 }
3261 return index ;
3262}
7167ae53 3263//_____________________________________________________________________________
3264Bool_t AliReconstruction::FinishPlaneEff() {
3265 //
3266 // Here execute all the necessary operationis, at the end of the tracking phase,
d7f8fd68 3267 // in case that evaluation of PlaneEfficiencies was required for some detector.
3268 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
7167ae53 3269 //
3270 // This Preliminary version works only FOR ITS !!!!!
3271 // other detectors (TOF,TRD, etc. have to develop their specific codes)
3272 //
3273 // Input: none
d7f8fd68 3274 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
7167ae53 3275 //
3276 Bool_t ret=kFALSE;
5ee13eb5 3277 TString detStr = fLoadCDB;
58e8dc31 3278 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
d7f8fd68 3279 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
5ee13eb5 3280 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
58e8dc31 3281 if(fTracker[iDet] && fTracker[iDet]->GetPlaneEff()) {
d7f8fd68 3282 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
3283 TString name=planeeff->GetName();
3284 name+=".root";
3285 TFile* pefile = TFile::Open(name, "RECREATE");
3286 ret=(Bool_t)planeeff->Write();
3287 pefile->Close();
5fbd4fd6 3288 if(planeeff->GetCreateHistos()) {
d7f8fd68 3289 TString hname=planeeff->GetName();
3290 hname+="Histo.root";
3291 ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
5fbd4fd6 3292 }
3293 }
58e8dc31 3294 if(fSPDTrackleter) {
3295 AliPlaneEff *planeeff=fSPDTrackleter->GetPlaneEff();
3296 TString name="AliITSPlaneEffSPDtracklet.root";
3297 TFile* pefile = TFile::Open(name, "RECREATE");
3298 ret=(Bool_t)planeeff->Write();
3299 pefile->Close();
3300 AliESDEvent *dummy=NULL;
3301 ret=(Bool_t)fSPDTrackleter->PostProcess(dummy); // take care of writing other files
3302 }
7167ae53 3303 }
3304 return ret;
3305}
3306//_____________________________________________________________________________
3307Bool_t AliReconstruction::InitPlaneEff() {
3308//
3309 // Here execute all the necessary operations, before of the tracking phase,
3310 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
58e8dc31 3311 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
7167ae53 3312 // which should be updated/recalculated.
3313 //
3314 // This Preliminary version will work only FOR ITS !!!!!
3315 // other detectors (TOF,TRD, etc. have to develop their specific codes)
3316 //
3317 // Input: none
3318 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
3319 //
58e8dc31 3320
3321 fSPDTrackleter = NULL;
b8604b34 3322 TString detStr = fLoadCDB;
3323 if (IsSelected(fgkDetectorName[0], detStr)) {
3324 AliReconstructor* itsReconstructor = GetReconstructor(0);
3325 if (itsReconstructor) {
3326 fSPDTrackleter = itsReconstructor->CreateTrackleter(); // this is NULL unless required in RecoParam
3327 }
3328 if (fSPDTrackleter) {
3329 AliInfo("Trackleter for SPD has been created");
3330 }
58e8dc31 3331 }
7167ae53 3332 return kTRUE;
7520312d 3333}
14dd053c 3334
3335//_____________________________________________________________________________
3336Bool_t AliReconstruction::InitAliEVE()
3337{
3338 // This method should be called only in case
3339 // AliReconstruction is run
3340 // within the alieve environment.
3341 // It will initialize AliEVE in a way
3342 // so that it can visualize event processed
3343 // by AliReconstruction.
3344 // The return flag shows whenever the
3345 // AliEVE initialization was successful or not.
3346
3347 TString macroStr;
3348 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
3349 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
3350 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
3351
6a840f1e 3352 gROOT->ProcessLine("if (!AliEveEventManager::GetMaster()){new AliEveEventManager();AliEveEventManager::GetMaster()->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(AliEveEventManager::GetMaster());};");
de33999e 3353 gROOT->ProcessLine("alieve_online_init()");
14dd053c 3354
3355 return kTRUE;
3356}
3357
3358//_____________________________________________________________________________
3359void AliReconstruction::RunAliEVE()
3360{
3361 // Runs AliEVE visualisation of
3362 // the current event.
3363 // Should be executed only after
3364 // successful initialization of AliEVE.
3365
3366 AliInfo("Running AliEVE...");
519975fe 3367 gROOT->ProcessLine(Form("AliEveEventManager::GetMaster()->SetEvent((AliRunLoader*)0x%lx,(AliRawReader*)0x%lx,(AliESDEvent*)0x%lx,(AliESDfriend*)0x%lx);",fRunLoader,fRawReader,fesd,fesdf));
14dd053c 3368 gSystem->Run();
3369}
ce43afbe 3370
3371//_____________________________________________________________________________
3372Bool_t AliReconstruction::SetRunQA(TString detAndAction)
3373{
3374 // Allows to run QA for a selected set of detectors
44ed7a66 3375 // and a selected set of tasks among RAWS, DIGITSR, RECPOINTS and ESDS
ce43afbe 3376 // all selected detectors run the same selected tasks
3377
3378 if (!detAndAction.Contains(":")) {
3379 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
3380 fRunQA = kFALSE ;
3381 return kFALSE ;
3382 }
3383 Int_t colon = detAndAction.Index(":") ;
3384 fQADetectors = detAndAction(0, colon) ;
59b1e631 3385 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
ce43afbe 3386 if (fQATasks.Contains("ALL") ) {
44ed7a66 3387 fQATasks = Form("%d %d %d %d", AliQAv1::kRAWS, AliQAv1::kDIGITSR, AliQAv1::kRECPOINTS, AliQAv1::kESDS) ;
ce43afbe 3388 } else {
3389 fQATasks.ToUpper() ;
3390 TString tempo("") ;
3391 if ( fQATasks.Contains("RAW") )
4e25ac79 3392 tempo = Form("%d ", AliQAv1::kRAWS) ;
44ed7a66 3393 if ( fQATasks.Contains("DIGIT") )
3394 tempo += Form("%d ", AliQAv1::kDIGITSR) ;
ce43afbe 3395 if ( fQATasks.Contains("RECPOINT") )
4e25ac79 3396 tempo += Form("%d ", AliQAv1::kRECPOINTS) ;
ce43afbe 3397 if ( fQATasks.Contains("ESD") )
4e25ac79 3398 tempo += Form("%d ", AliQAv1::kESDS) ;
ce43afbe 3399 fQATasks = tempo ;
3400 if (fQATasks.IsNull()) {
3401 AliInfo("No QA requested\n") ;
3402 fRunQA = kFALSE ;
3403 return kTRUE ;
3404 }
3405 }
3406 TString tempo(fQATasks) ;
4e25ac79 3407 tempo.ReplaceAll(Form("%d", AliQAv1::kRAWS), AliQAv1::GetTaskName(AliQAv1::kRAWS)) ;
44ed7a66 3408 tempo.ReplaceAll(Form("%d", AliQAv1::kDIGITSR), AliQAv1::GetTaskName(AliQAv1::kDIGITSR)) ;
4e25ac79 3409 tempo.ReplaceAll(Form("%d", AliQAv1::kRECPOINTS), AliQAv1::GetTaskName(AliQAv1::kRECPOINTS)) ;
3410 tempo.ReplaceAll(Form("%d", AliQAv1::kESDS), AliQAv1::GetTaskName(AliQAv1::kESDS)) ;
ce43afbe 3411 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
3412 fRunQA = kTRUE ;
3413 return kTRUE;
3414}
3415
7e88424f 3416//_____________________________________________________________________________
3417Bool_t AliReconstruction::InitRecoParams()
3418{
3419 // The method accesses OCDB and retrieves all
3420 // the available reco-param objects from there.
3421
3422 Bool_t isOK = kTRUE;
3423
8b26452d 3424 if (fRecoParam.GetDetRecoParamArray(kNDetectors)) {
3425 AliInfo("Using custom GRP reconstruction parameters");
3426 }
3427 else {
3428 AliInfo("Loading GRP reconstruction parameter objects");
3429
3430 AliCDBPath path("GRP","Calib","RecoParam");
3431 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
3432 if(!entry){
3433 AliWarning("Couldn't find GRP RecoParam entry in OCDB");
3434 isOK = kFALSE;
3435 }
3436 else {
3437 TObject *recoParamObj = entry->GetObject();
3438 if (dynamic_cast<TObjArray*>(recoParamObj)) {
3439 // GRP has a normal TobjArray of AliDetectorRecoParam objects
3440 // Registering them in AliRecoParam
3441 fRecoParam.AddDetRecoParamArray(kNDetectors,dynamic_cast<TObjArray*>(recoParamObj));
3442 }
3443 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
3444 // GRP has only onse set of reco parameters
3445 // Registering it in AliRecoParam
3446 AliInfo("Single set of GRP reconstruction parameters found");
3447 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
3448 fRecoParam.AddDetRecoParam(kNDetectors,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
3449 }
3450 else {
3451 AliError("No valid GRP RecoParam object found in the OCDB");
3452 isOK = kFALSE;
3453 }
3454 entry->SetOwner(0);
3455 }
3456 }
3457
7d566c20 3458 TString detStr = fLoadCDB;
ac4a7581 3459 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
7e88424f 3460
7d566c20 3461 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
3462
7e88424f 3463 if (fRecoParam.GetDetRecoParamArray(iDet)) {
3464 AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
3465 continue;
3466 }
3467
ac232c75 3468 AliInfo(Form("Loading reconstruction parameter objects for detector %s",fgkDetectorName[iDet]));
7e88424f 3469
3470 AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
3471 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
3472 if(!entry){
3473 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
3474 isOK = kFALSE;
3475 }
3476 else {
3477 TObject *recoParamObj = entry->GetObject();
3478 if (dynamic_cast<TObjArray*>(recoParamObj)) {
3479 // The detector has a normal TobjArray of AliDetectorRecoParam objects
3480 // Registering them in AliRecoParam
3481 fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
3482 }
3483 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
3484 // The detector has only onse set of reco parameters
3485 // Registering it in AliRecoParam
ac232c75 3486 AliInfo(Form("Single set of reconstruction parameters found for detector %s",fgkDetectorName[iDet]));
7e88424f 3487 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
3488 fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
3489 }
3490 else {
3491 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
3492 isOK = kFALSE;
3493 }
3494 entry->SetOwner(0);
f168abba 3495 // FIX ME: We have to disable the unloading of reco-param CDB
3496 // entries because QA framework is using them. Has to be fix in
3497 // a way that the QA takes the objects already constructed in
3498 // this method.
3499 // AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
7e88424f 3500 }
3501 }
3502
e30a9b4d 3503 if (AliDebugLevel() > 0) fRecoParam.Print();
ac232c75 3504
7e88424f 3505 return isOK;
3506}
3507
3508//_____________________________________________________________________________
3509Bool_t AliReconstruction::GetEventInfo()
3510{
3511 // Fill the event info object
3512 // ...
52dd4a8c 3513 AliCodeTimerAuto("",0)
7e88424f 3514
3515 AliCentralTrigger *aCTP = NULL;
3516 if (fRawReader) {
3517 fEventInfo.SetEventType(fRawReader->GetType());
3518
3519 ULong64_t mask = fRawReader->GetClassMask();
3520 fEventInfo.SetTriggerMask(mask);
3521 UInt_t clmask = fRawReader->GetDetectorPattern()[0];
3522 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
3523
3524 aCTP = new AliCentralTrigger();
3525 TString configstr("");
3526 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
3527 AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
3528 delete aCTP;
3529 return kFALSE;
3530 }
3531 aCTP->SetClassMask(mask);
3532 aCTP->SetClusterMask(clmask);
3533 }
3534 else {
3535 fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
3536
3537 if (fRunLoader && (!fRunLoader->LoadTrigger())) {
3538 aCTP = fRunLoader->GetTrigger();
3539 fEventInfo.SetTriggerMask(aCTP->GetClassMask());
e61ed4b1 3540 // get inputs from actp - just get
3541 AliESDHeader* esdheader = fesd->GetHeader();
3542 esdheader->SetL0TriggerInputs(aCTP->GetL0TriggerInputs());
3543 esdheader->SetL1TriggerInputs(aCTP->GetL1TriggerInputs());
3544 esdheader->SetL2TriggerInputs(aCTP->GetL2TriggerInputs());
7e88424f 3545 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
3546 }
3547 else {
3548 AliWarning("No trigger can be loaded! The trigger information will not be used!");
3549 return kFALSE;
3550 }
3551 }
3552
3553 AliTriggerConfiguration *config = aCTP->GetConfiguration();
3554 if (!config) {
3555 AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
3556 if (fRawReader) delete aCTP;
3557 return kFALSE;
3558 }
3559
a0c2cf2d 3560 UChar_t clustmask = 0;
7e88424f 3561 TString trclasses;
3562 ULong64_t trmask = fEventInfo.GetTriggerMask();
3563 const TObjArray& classesArray = config->GetClasses();
3564 Int_t nclasses = classesArray.GetEntriesFast();
3565 for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
3566 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
a2ec4f82 3567 if (trclass && trclass->GetMask()>0) {
a4b0683d 3568 Int_t trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
7e88424f 3569 fesd->SetTriggerClass(trclass->GetName(),trindex);
8a933107 3570 if (fRawReader) fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
e61ed4b1 3571 if (trmask & (1ull << trindex)) {
7e88424f 3572 trclasses += " ";
3573 trclasses += trclass->GetName();
3574 trclasses += " ";
a0c2cf2d 3575 clustmask |= trclass->GetCluster()->GetClusterMask();
7e88424f 3576 }
3577 }
3578 }
3579 fEventInfo.SetTriggerClasses(trclasses);
3580
6ef9caeb 3581 // Write names of active trigger inputs in ESD Header
3582 const TObjArray& inputsArray = config->GetInputs();
3583 Int_t ninputs = inputsArray.GetEntriesFast();
3584 for( Int_t iinput=0; iinput < ninputs; iinput++ ) {
3585 AliTriggerInput* trginput = (AliTriggerInput*)inputsArray.At(iinput);
a2ec4f82 3586 if (trginput && trginput->GetMask()>0) {
6ef9caeb 3587 Int_t inputIndex = (Int_t)TMath::Nint(TMath::Log2(trginput->GetMask()));
3588 AliESDHeader* headeresd = fesd->GetHeader();
3589 Int_t trglevel = (Int_t)trginput->GetLevel();
3590 if (trglevel == 0) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex);
3591 if (trglevel == 1) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+24);
3592 if (trglevel == 2) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+48);
3593 }
3594 }
3595
a0c2cf2d 3596 // Set the information in ESD
3597 fesd->SetTriggerMask(trmask);
3598 fesd->SetTriggerCluster(clustmask);
3599
7e88424f 3600 if (!aCTP->CheckTriggeredDetectors()) {
3601 if (fRawReader) delete aCTP;
3602 return kFALSE;
3603 }
3604
3605 if (fRawReader) delete aCTP;
3606
3607 // We have to fill also the HLT decision here!!
3608 // ...
3609
3610 return kTRUE;
3611}
3612
3613const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
3614{
3615 // Match the detector list found in the rec.C or the default 'ALL'
3616 // to the list found in the GRP (stored there by the shuttle PP which
3617 // gets the information from ECS)
3618 static TString resultList;
3619 TString detList = detectorList;
3620
3621 resultList = "";
3622
3623 for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
3624 if ((detectorMask >> iDet) & 0x1) {
3625 TString det = AliDAQ::OfflineModuleName(iDet);
3626 if ((detList.CompareTo("ALL") == 0) ||
a101e1dd 3627 ((detList.BeginsWith("ALL ") ||
3628 detList.EndsWith(" ALL") ||
3629 detList.Contains(" ALL ")) &&
3630 !(detList.BeginsWith("-"+det+" ") ||
3631 detList.EndsWith(" -"+det) ||
3632 detList.Contains(" -"+det+" "))) ||
7e88424f 3633 (detList.CompareTo(det) == 0) ||
a101e1dd 3634 detList.BeginsWith(det+" ") ||
3635 detList.EndsWith(" "+det) ||
7e88424f 3636 detList.Contains( " "+det+" " )) {
3637 if (!resultList.EndsWith(det + " ")) {
3638 resultList += det;
3639 resultList += " ";
3640 }
3641 }
3642 }
3643 }
3644
3645 // HLT
3646 if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
3647 TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
3648 if ((detList.CompareTo("ALL") == 0) ||
a101e1dd 3649 ((detList.BeginsWith("ALL ") ||
3650 detList.EndsWith(" ALL") ||
3651 detList.Contains(" ALL ")) &&
3652 !(detList.BeginsWith("-"+hltDet+" ") ||
3653 detList.EndsWith(" -"+hltDet) ||
3654 detList.Contains(" -"+hltDet+" "))) ||
7e88424f 3655 (detList.CompareTo(hltDet) == 0) ||
a101e1dd 3656 detList.BeginsWith(hltDet+" ") ||
3657 detList.EndsWith(" "+hltDet) ||
7e88424f 3658 detList.Contains( " "+hltDet+" " )) {
3659 resultList += hltDet;
3660 }
3661 }
3662
3663 return resultList.Data();
3664
3665}
4b71572b 3666
3667//______________________________________________________________________________
3668void AliReconstruction::Abort(const char *method, EAbort what)
3669{
3670 // Abort processing. If what = kAbortProcess, the Process() loop will be
3671 // aborted. If what = kAbortFile, the current file in a chain will be
3672 // aborted and the processing will continue with the next file, if there
3673 // is no next file then Process() will be aborted. Abort() can also be
3674 // called from Begin(), SlaveBegin(), Init() and Notify(). After abort
3675 // the SlaveTerminate() and Terminate() are always called. The abort flag
3676 // can be checked in these methods using GetAbort().
3677 //
3678 // The method is overwritten in AliReconstruction for better handling of
3679 // reco specific errors
3680
3681 if (!fStopOnError) return;
3682
3683 CleanUp();
3684
3685 TString whyMess = method;
3686 whyMess += " failed! Aborting...";
3687
3688 AliError(whyMess.Data());
3689
3690 fAbort = what;
3691 TString mess = "Abort";
3692 if (fAbort == kAbortProcess)
3693 mess = "AbortProcess";
3694 else if (fAbort == kAbortFile)
3695 mess = "AbortFile";
3696
3697 Info(mess, whyMess.Data());
3698}
3699
2f954aba 3700//______________________________________________________________________________
3701Bool_t AliReconstruction::ProcessEvent(void* event)
3702{
3703 // Method that is used in case the event loop
3704 // is steered from outside, for example by AMORE
3705 // 'event' is a pointer to the DATE event in the memory
3706
3707 if (fRawReader) delete fRawReader;
3708 fRawReader = new AliRawReaderDate(event);
3709 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
3710 delete fRawReader;
3711 fRawReader = NULL;
3712
3713 return fStatus;
3714}
81d57268 3715
3716//______________________________________________________________________________
3717Bool_t AliReconstruction::ParseOutput()
3718{
3719 // The method parses the output file
3720 // location string in order to steer
3721 // properly the selector
3722
3723 TPMERegexp re1("(\\w+\\.zip#\\w+\\.root):([,*\\w+\\.root,*]+)@dataset://(\\w++)");
3724 TPMERegexp re2("(\\w+\\.root)?@?dataset://(\\w++)");
3725
3726 if (re1.Match(fESDOutput) == 4) {
3727 // root archive with output files stored and regustered
3728 // in proof dataset
3729 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",re1[1].Data()));
3730 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re1[3].Data()));
3731 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
3732 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_ARCHIVE",re1[2].Data()));
3733 AliInfo(Form("%s files will be stored within %s in dataset %s",
3734 re1[2].Data(),
3735 re1[1].Data(),
3736 re1[3].Data()));
3737 }
3738 else if (re2.Match(fESDOutput) == 3) {
3739 // output file stored and registered
3740 // in proof dataset
3741 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",(re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data()));
3742 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re2[2].Data()));
3743 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
3744 AliInfo(Form("%s will be stored in dataset %s",
3745 (re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data(),
3746 re2[2].Data()));
3747 }
3748 else {
3749 if (fESDOutput.IsNull()) {
3750 // Output location not given.
3751 // Assuming xrootd has been already started and
3752 // the output file has to be sent back
3753 // to the client machine
3754 TString esdUrl(Form("root://%s/%s/",
3755 TUrl(gSystem->HostName()).GetHostFQDN(),
3756 gSystem->pwd()));
3757 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE","AliESDs.root"));
3758 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",esdUrl.Data()));
3759 AliInfo(Form("AliESDs.root will be stored in %s",
3760 esdUrl.Data()));
3761 }
3762 else {
3763 // User specified an output location.
3764 // Ones has just to parse it here
3765 TUrl outputUrl(fESDOutput.Data());
3766 TString outputFile(gSystem->BaseName(outputUrl.GetFile()));
3767 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",outputFile.IsNull() ? "AliESDs.root" : outputFile.Data()));
3768 TString outputLocation(outputUrl.GetUrl());
3769 outputLocation.ReplaceAll(outputFile.Data(),"");
3770 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",outputLocation.Data()));
3771 AliInfo(Form("%s will be stored in %s",
3772 outputFile.IsNull() ? "AliESDs.root" : outputFile.Data(),
3773 outputLocation.Data()));
3774 }
3775 }
3776
3777 return kTRUE;
3778}