1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for running the reconstruction //
22 // Clusters and tracks are created for all detectors and all events by //
25 // AliReconstruction rec; //
28 // The Run method returns kTRUE in case of successful execution. //
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 //
33 // rec.SetInput("..."); //
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 //
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 //
45 // rec.SetEventRange(..., ...); //
47 // The index -1 (default) can be used for the last event to indicate no //
48 // upper limit of the event range. //
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): //
56 // rec.SetNumberOfEventsPerFile(...); //
59 // The name of the galice file can be changed from the default //
60 // "galice.root" by passing it as argument to the AliReconstruction //
61 // constructor or by //
63 // rec.SetGAliceFile("..."); //
65 // The local reconstruction can be switched on or off for individual //
68 // rec.SetRunLocalReconstruction("..."); //
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. //
74 // The reconstruction of the primary vertex position can be switched off by //
76 // rec.SetRunVertexFinder(kFALSE); //
78 // The tracking and the creation of ESD tracks can be switched on for //
79 // selected detectors by //
81 // rec.SetRunTracking("..."); //
83 // Uniform/nonuniform field tracking switches (default: uniform field) //
85 // rec.SetUniformFieldTracking(); ( rec.SetUniformFieldTracking(kFALSE); ) //
87 // The filling of additional ESD information can be steered by //
89 // rec.SetFillESD("..."); //
91 // Again, for both methods the string specifies the list of detectors. //
92 // The default is "ALL". //
94 // The call of the shortcut method //
96 // rec.SetRunReconstruction("..."); //
98 // is equivalent to calling SetRunLocalReconstruction, SetRunTracking and //
99 // SetFillESD with the same detector selecting string as argument. //
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. //
104 // The input data of a detector can be replaced by the corresponding HLT //
105 // data by calling (usual detector string) //
106 // SetUseHLTData("..."); //
108 // For debug purposes the method SetCheckPointLevel can be used. If the //
109 // argument is greater than 0, files with ESD events will be written after //
110 // selected steps of the reconstruction for each event: //
111 // level 1: after tracking and after filling of ESD (final) //
112 // level 2: in addition after each tracking step //
113 // level 3: in addition after the filling of ESD for each detector //
114 // If a final check point file exists for an event, this event will be //
115 // skipped in the reconstruction. The tracking and the filling of ESD for //
116 // a detector will be skipped as well, if the corresponding check point //
117 // file exists. The ESD event will then be loaded from the file instead. //
119 ///////////////////////////////////////////////////////////////////////////////
126 #include <TPluginManager.h>
127 #include <TGeoManager.h>
128 #include <TLorentzVector.h>
131 #include <TObjArray.h>
133 #include "AliReconstruction.h"
134 #include "AliCodeTimer.h"
135 #include "AliReconstructor.h"
137 #include "AliRunLoader.h"
139 #include "AliRawReaderFile.h"
140 #include "AliRawReaderDate.h"
141 #include "AliRawReaderRoot.h"
142 #include "AliRawEventHeaderBase.h"
143 #include "AliESDEvent.h"
144 #include "AliESDMuonTrack.h"
145 #include "AliESDfriend.h"
146 #include "AliESDVertex.h"
147 #include "AliESDcascade.h"
148 #include "AliESDkink.h"
149 #include "AliESDtrack.h"
150 #include "AliESDCaloCluster.h"
151 #include "AliESDCaloCells.h"
152 #include "AliMultiplicity.h"
153 #include "AliTracker.h"
154 #include "AliVertexer.h"
155 #include "AliVertexerTracks.h"
156 #include "AliV0vertexer.h"
157 #include "AliCascadeVertexer.h"
158 #include "AliHeader.h"
159 #include "AliGenEventHeader.h"
161 #include "AliESDpid.h"
162 #include "AliESDtrack.h"
163 #include "AliESDPmdTrack.h"
165 #include "AliESDTagCreator.h"
166 #include "AliAODTagCreator.h"
168 #include "AliGeomManager.h"
169 #include "AliTrackPointArray.h"
170 #include "AliCDBManager.h"
171 #include "AliCDBStorage.h"
172 #include "AliCDBEntry.h"
173 #include "AliAlignObj.h"
175 #include "AliCentralTrigger.h"
176 #include "AliTriggerConfiguration.h"
177 #include "AliTriggerClass.h"
178 #include "AliCTPRawStream.h"
180 #include "AliQADataMakerRec.h"
181 #include "AliGlobalQADataMaker.h"
183 #include "AliQADataMakerSteer.h"
185 #include "AliPlaneEff.h"
187 #include "AliSysInfo.h" // memory snapshots
188 #include "AliRawHLTManager.h"
191 ClassImp(AliReconstruction)
194 //_____________________________________________________________________________
195 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
197 //_____________________________________________________________________________
198 AliReconstruction::AliReconstruction(const char* gAliceFilename,
199 const char* name, const char* title) :
202 fUniformField(kTRUE),
203 fRunVertexFinder(kTRUE),
204 fRunVertexFinderTracks(kTRUE),
205 fRunHLTTracking(kFALSE),
206 fRunMuonTracking(kFALSE),
208 fRunCascadeFinder(kTRUE),
209 fStopOnError(kFALSE),
210 fWriteAlignmentData(kFALSE),
211 fWriteESDfriend(kFALSE),
213 fFillTriggerESD(kTRUE),
221 fRunLocalReconstruction("ALL"),
224 fUseTrackingErrorsForAlignment(""),
225 fGAliceFileName(gAliceFilename),
231 fNumberOfEventsPerFile(1),
234 fLoadAlignFromCDB(kTRUE),
235 fLoadAlignData("ALL"),
241 fParentRawReader(NULL),
244 fDiamondProfile(NULL),
245 fDiamondProfileTPC(NULL),
246 fMeanVertexConstraint(kTRUE),
250 fAlignObjArray(NULL),
253 fInitCDBCalled(kFALSE),
254 fSetRunNumberFromDataCalled(kFALSE),
259 fRunPlaneEff(kFALSE),
271 fIsNewRunLoader(kFALSE)
273 // create reconstruction object with default parameters
275 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
276 fReconstructor[iDet] = NULL;
277 fLoader[iDet] = NULL;
278 fTracker[iDet] = NULL;
279 fQADataMaker[iDet] = NULL;
280 fQACycles[iDet] = 999999;
282 fQADataMaker[fgkNDetectors]=NULL; //Global QA
286 //_____________________________________________________________________________
287 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
290 fUniformField(rec.fUniformField),
291 fRunVertexFinder(rec.fRunVertexFinder),
292 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
293 fRunHLTTracking(rec.fRunHLTTracking),
294 fRunMuonTracking(rec.fRunMuonTracking),
295 fRunV0Finder(rec.fRunV0Finder),
296 fRunCascadeFinder(rec.fRunCascadeFinder),
297 fStopOnError(rec.fStopOnError),
298 fWriteAlignmentData(rec.fWriteAlignmentData),
299 fWriteESDfriend(rec.fWriteESDfriend),
300 fWriteAOD(rec.fWriteAOD),
301 fFillTriggerESD(rec.fFillTriggerESD),
303 fCleanESD(rec.fCleanESD),
304 fV0DCAmax(rec.fV0DCAmax),
305 fV0CsPmin(rec.fV0CsPmin),
309 fRunLocalReconstruction(rec.fRunLocalReconstruction),
310 fRunTracking(rec.fRunTracking),
311 fFillESD(rec.fFillESD),
312 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
313 fGAliceFileName(rec.fGAliceFileName),
315 fpEvent(rec.fpEvent),
316 fEquipIdMap(rec.fEquipIdMap),
317 fFirstEvent(rec.fFirstEvent),
318 fLastEvent(rec.fLastEvent),
319 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
322 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
323 fLoadAlignData(rec.fLoadAlignData),
324 fESDPar(rec.fESDPar),
325 fUseHLTData(rec.fUseHLTData),
329 fParentRawReader(NULL),
332 fDiamondProfile(NULL),
333 fDiamondProfileTPC(NULL),
334 fMeanVertexConstraint(rec.fMeanVertexConstraint),
338 fAlignObjArray(rec.fAlignObjArray),
339 fCDBUri(rec.fCDBUri),
341 fInitCDBCalled(rec.fInitCDBCalled),
342 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
344 fRunGlobalQA(rec.fRunGlobalQA),
345 fInLoopQA(rec.fInLoopQA),
346 fRunPlaneEff(rec.fRunPlaneEff),
358 fIsNewRunLoader(rec.fIsNewRunLoader)
362 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
363 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
365 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
366 fReconstructor[iDet] = NULL;
367 fLoader[iDet] = NULL;
368 fTracker[iDet] = NULL;
369 fQADataMaker[iDet] = NULL;
370 fQACycles[iDet] = rec.fQACycles[iDet];
372 fQADataMaker[fgkNDetectors]=NULL; //Global QA
373 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
374 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
378 //_____________________________________________________________________________
379 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
381 // assignment operator
383 this->~AliReconstruction();
384 new(this) AliReconstruction(rec);
388 //_____________________________________________________________________________
389 AliReconstruction::~AliReconstruction()
395 fSpecCDBUri.Delete();
397 AliCodeTimer::Instance()->Print();
400 //_____________________________________________________________________________
401 void AliReconstruction::InitCDB()
403 // activate a default CDB storage
404 // First check if we have any CDB storage set, because it is used
405 // to retrieve the calibration and alignment constants
407 if (fInitCDBCalled) return;
408 fInitCDBCalled = kTRUE;
410 AliCDBManager* man = AliCDBManager::Instance();
411 if (man->IsDefaultStorageSet())
413 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
414 AliWarning("Default CDB storage has been already set !");
415 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
416 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
417 fCDBUri = man->GetDefaultStorage()->GetURI();
420 if (fCDBUri.Length() > 0)
422 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
423 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
424 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
426 fCDBUri="local://$ALICE_ROOT";
427 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
428 AliWarning("Default CDB storage not yet set !!!!");
429 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
430 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
433 man->SetDefaultStorage(fCDBUri);
436 // Now activate the detector specific CDB storage locations
437 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
438 TObject* obj = fSpecCDBUri[i];
440 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
441 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
442 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
443 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
448 //_____________________________________________________________________________
449 void AliReconstruction::SetDefaultStorage(const char* uri) {
450 // Store the desired default CDB storage location
451 // Activate it later within the Run() method
457 //_____________________________________________________________________________
458 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
459 // Store a detector-specific CDB storage location
460 // Activate it later within the Run() method
462 AliCDBPath aPath(calibType);
463 if(!aPath.IsValid()){
464 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
465 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
466 if(!strcmp(calibType, fgkDetectorName[iDet])) {
467 aPath.SetPath(Form("%s/*", calibType));
468 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
472 if(!aPath.IsValid()){
473 AliError(Form("Not a valid path or detector: %s", calibType));
478 // // check that calibType refers to a "valid" detector name
479 // Bool_t isDetector = kFALSE;
480 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
481 // TString detName = fgkDetectorName[iDet];
482 // if(aPath.GetLevel0() == detName) {
483 // isDetector = kTRUE;
489 // AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
493 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
494 if (obj) fSpecCDBUri.Remove(obj);
495 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
499 //_____________________________________________________________________________
500 Bool_t AliReconstruction::SetRunNumberFromData()
502 // The method is called in Run() in order
503 // to set a correct run number.
504 // In case of raw data reconstruction the
505 // run number is taken from the raw data header
507 if (fSetRunNumberFromDataCalled) return kTRUE;
508 fSetRunNumberFromDataCalled = kTRUE;
510 AliCDBManager* man = AliCDBManager::Instance();
512 if(man->GetRun() > 0) {
513 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
517 AliError("No run loader is found !");
520 // read run number from gAlice
521 if(fRunLoader->GetAliRun())
522 AliCDBManager::Instance()->SetRun(fRunLoader->GetHeader()->GetRun());
525 if(fRawReader->NextEvent()) {
526 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
527 fRawReader->RewindEvents();
530 if(man->GetRun() > 0) {
531 AliWarning("No raw events is found ! Using settings in AliCDBManager !");
536 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
542 AliError("Neither gAlice nor RawReader objects are found !");
552 //_____________________________________________________________________________
553 void AliReconstruction::SetCDBLock() {
554 // Set CDB lock: from now on it is forbidden to reset the run number
555 // or the default storage or to activate any further storage!
557 AliCDBManager::Instance()->SetLock(1);
560 //_____________________________________________________________________________
561 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
563 // Read the alignment objects from CDB.
564 // Each detector is supposed to have the
565 // alignment objects in DET/Align/Data CDB path.
566 // All the detector objects are then collected,
567 // sorted by geometry level (starting from ALIC) and
568 // then applied to the TGeo geometry.
569 // Finally an overlaps check is performed.
571 // Load alignment data from CDB and fill fAlignObjArray
572 if(fLoadAlignFromCDB){
574 TString detStr = detectors;
575 TString loadAlObjsListOfDets = "";
577 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
578 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
579 loadAlObjsListOfDets += fgkDetectorName[iDet];
580 loadAlObjsListOfDets += " ";
581 } // end loop over detectors
582 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
583 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
585 // Check if the array with alignment objects was
586 // provided by the user. If yes, apply the objects
587 // to the present TGeo geometry
588 if (fAlignObjArray) {
589 if (gGeoManager && gGeoManager->IsClosed()) {
590 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
591 AliError("The misalignment of one or more volumes failed!"
592 "Compare the list of simulated detectors and the list of detector alignment data!");
597 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
603 delete fAlignObjArray; fAlignObjArray=0;
608 //_____________________________________________________________________________
609 void AliReconstruction::SetGAliceFile(const char* fileName)
611 // set the name of the galice file
613 fGAliceFileName = fileName;
616 //_____________________________________________________________________________
617 void AliReconstruction::SetInput(const char* input,void **pEvent)
619 // In case event pointer is given, we run in an online mode
620 // and the first argument is ignored.
621 // In case event pointer is NULL, we run in a normal
622 // mode over a raw-data file and the first argument points
623 // to the name of that file
634 //_____________________________________________________________________________
635 void AliReconstruction::SetOption(const char* detector, const char* option)
637 // set options for the reconstruction of a detector
639 TObject* obj = fOptions.FindObject(detector);
640 if (obj) fOptions.Remove(obj);
641 fOptions.Add(new TNamed(detector, option));
644 //_____________________________________________________________________________
645 Bool_t AliReconstruction::Run(const char* input)
648 AliCodeTimerAuto("");
650 if (!InitRun(input)) return kFALSE;
652 //******* The loop over events
654 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
655 (fRawReader && fRawReader->NextEvent())) {
656 if (!RunEvent(iEvent)) return kFALSE;
660 if (!FinishRun()) return kFALSE;
665 //_____________________________________________________________________________
666 Bool_t AliReconstruction::InitRun(const char* input, void **pEvent)
668 // Initialize all the stuff before
669 // going into the event loop
670 // If the second argument is given, the first one is ignored and
671 // the reconstruction works in an online mode
672 AliCodeTimerAuto("");
674 if (pEvent) fpEvent = pEvent;
675 if (input) fInput = input;
677 // set the input in case of raw data
678 if (!fInput.IsNull() || fpEvent) {
679 if (!fInput.IsNull()) {
680 AliInfo(Form("Reconstruction will run over a raw-data file: %s",fInput.Data()));
681 TString fileName(fInput);
682 if (fInput.EndsWith("/")) {
683 fRawReader = new AliRawReaderFile(fInput);
684 } else if (fInput.EndsWith(".root")) {
685 fRawReader = new AliRawReaderRoot(fInput);
687 fRawReader = new AliRawReaderDate(fInput);
691 AliInfo(Form("Reconstruction will run over an event in memory at: %p",*fpEvent));
692 fRawReader = new AliRawReaderDate((void *)(*fpEvent));
696 AliInfo("Reconstruction will run over digits");
699 if (!fEquipIdMap.IsNull() && fRawReader)
700 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
702 if (!fUseHLTData.IsNull()) {
703 // create the RawReaderHLT which performs redirection of HLT input data for
704 // the specified detectors
705 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
707 fParentRawReader=fRawReader;
708 fRawReader=pRawReader;
710 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
714 AliSysInfo::AddStamp("Start");
715 // get the run loader
716 if (!InitRunLoader()) return kFALSE;
717 AliSysInfo::AddStamp("LoadLoader");
719 // Initialize the CDB storage
722 AliSysInfo::AddStamp("LoadCDB");
724 // Set run number in CDBManager (if it is not already set by the user)
725 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
727 // Set CDB lock: from now on it is forbidden to reset the run number
728 // or the default storage or to activate any further storage!
731 // Import ideal TGeo geometry and apply misalignment
733 TString geom(gSystem->DirName(fGAliceFileName));
734 geom += "/geometry.root";
735 AliGeomManager::LoadGeometry(geom.Data());
736 if (!gGeoManager) if (fStopOnError) return kFALSE;
739 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
740 AliSysInfo::AddStamp("LoadGeom");
743 AliQADataMakerSteer qas ;
744 if (fRunQA && fRawReader) {
745 qas.Run(fRunLocalReconstruction, fRawReader) ;
747 // checking the QA of previous steps
751 // local reconstruction
752 if (!fRunLocalReconstruction.IsNull()) {
753 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
754 if (fStopOnError) {CleanUp(); return kFALSE;}
760 if (fRunVertexFinder && !CreateVertexer()) {
766 AliSysInfo::AddStamp("Vertexer");
769 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
775 AliSysInfo::AddStamp("LoadTrackers");
777 // get the possibly already existing ESD file and tree
778 fesd = new AliESDEvent(); fhltesd = new AliESDEvent();
779 if (!gSystem->AccessPathName("AliESDs.root")){
780 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
781 ffileOld = TFile::Open("AliESDs.old.root");
782 if (ffileOld && ffileOld->IsOpen()) {
783 ftreeOld = (TTree*) ffileOld->Get("esdTree");
784 if (ftreeOld)fesd->ReadFromTree(ftreeOld);
785 fhlttreeOld = (TTree*) ffileOld->Get("HLTesdTree");
786 if (fhlttreeOld) fhltesd->ReadFromTree(fhlttreeOld);
790 // create the ESD output file and tree
791 ffile = TFile::Open("AliESDs.root", "RECREATE");
792 ffile->SetCompressionLevel(2);
793 if (!ffile->IsOpen()) {
794 AliError("opening AliESDs.root failed");
795 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
798 ftree = new TTree("esdTree", "Tree with ESD objects");
799 fesd = new AliESDEvent();
800 fesd->CreateStdContent();
801 fesd->WriteToTree(ftree);
803 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
804 fhltesd = new AliESDEvent();
805 fhltesd->CreateStdContent();
806 fhltesd->WriteToTree(fhlttree);
809 delete esd; delete hltesd;
810 esd = NULL; hltesd = NULL;
812 // create the branch with ESD additions
816 if (fWriteESDfriend) {
817 fesdf = new AliESDfriend();
818 TBranch *br=ftree->Branch("ESDfriend.","AliESDfriend", &fesdf);
819 br->SetFile("AliESDfriends.root");
820 fesd->AddObject(fesdf);
824 // Get the GRP CDB entry
825 AliCDBEntry* entryGRP = AliCDBManager::Instance()->Get("GRP/GRP/Data");
828 fGRPList = dynamic_cast<TList*> (entryGRP->GetObject());
830 AliError("No GRP entry found in OCDB!");
833 // Get the diamond profile from OCDB
834 AliCDBEntry* entry = AliCDBManager::Instance()
835 ->Get("GRP/Calib/MeanVertex");
838 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
840 AliError("No diamond profile found in OCDB!");
844 entry = AliCDBManager::Instance()
845 ->Get("GRP/Calib/MeanVertexTPC");
848 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
850 AliError("No diamond profile found in OCDB!");
853 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
854 if(fDiamondProfile && fMeanVertexConstraint) ftVertexer->SetVtxStart(fDiamondProfile);
856 if (fRawReader) fRawReader->RewindEvents();
859 gSystem->GetProcInfo(&ProcInfo);
860 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
863 //Initialize the QA and start of cycle for out-of-cycle QA
865 TString detStr(fFillESD);
866 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
867 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
868 AliQADataMakerRec *qadm = GetQADataMaker(iDet);
870 AliInfo(Form("Initializing the QA data maker for %s",
871 fgkDetectorName[iDet]));
872 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
873 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
875 // qadm->StartOfCycle(AliQA::kRECPOINTS);
876 // qadm->StartOfCycle(AliQA::kESDS,"same");
881 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
882 AliInfo(Form("Initializing the global QA data maker"));
884 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
885 AliTracker::SetResidualsArray(arr);
886 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
888 qadm->StartOfCycle(AliQA::kRECPOINTS, (fRunQA && fRawReader));
889 qadm->StartOfCycle(AliQA::kESDS, "same");
893 //Initialize the Plane Efficiency framework
894 if (fRunPlaneEff && !InitPlaneEff()) {
895 if(fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
901 //_____________________________________________________________________________
902 Bool_t AliReconstruction::RunEvent(Int_t iEvent)
904 // run the reconstruction over a single event
905 // The event loop is steered in Run method
907 AliCodeTimerAuto("");
909 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
910 fRunLoader->SetEventNumber(iEvent);
911 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
913 //?? fRunLoader->MakeTree("H");
914 fRunLoader->TreeE()->Fill();
917 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
918 // copy old ESD to the new one
920 fesd->ReadFromTree(ftreeOld);
921 ftreeOld->GetEntry(iEvent);
925 fesd->ReadFromTree(fhlttreeOld);
926 fhlttreeOld->GetEntry(iEvent);
932 AliInfo(Form("processing event %d", iEvent));
934 //Start of cycle for the in-loop QA
937 TString detStr(fFillESD);
938 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
939 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
940 AliQADataMakerRec *qadm = GetQADataMaker(iDet);
942 qadm->StartOfCycle(AliQA::kRECPOINTS, (fRunQA && fRawReader));
943 qadm->StartOfCycle(AliQA::kESDS, "same") ;
947 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
948 qadm->StartOfCycle(AliQA::kRECPOINTS, (fRunQA && fRawReader));
949 qadm->StartOfCycle(AliQA::kESDS, "same");
953 fRunLoader->GetEvent(iEvent);
956 sprintf(aFileName, "ESD_%d.%d_final.root",
957 fRunLoader->GetHeader()->GetRun(),
958 fRunLoader->GetHeader()->GetEventNrInRun());
959 if (!gSystem->AccessPathName(aFileName)) return kTRUE;
961 // local signle event reconstruction
962 if (!fRunLocalReconstruction.IsNull()) {
963 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
964 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
968 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
969 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
970 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
971 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
973 // Set magnetic field from the tracker
974 fesd->SetMagneticField(AliTracker::GetBz());
975 fhltesd->SetMagneticField(AliTracker::GetBz());
979 // Fill raw-data error log into the ESD
980 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
983 if (fRunVertexFinder) {
984 if (!ReadESD(fesd, "vertex")) {
985 if (!RunVertexFinder(fesd)) {
986 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
988 if (fCheckPointLevel > 0) WriteESD(fesd, "vertex");
993 if (!fRunTracking.IsNull()) {
994 if (fRunHLTTracking) {
995 fhltesd->SetPrimaryVertexSPD(fesd->GetVertex());
996 if (!RunHLTTracking(fhltesd)) {
997 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1003 if (!fRunTracking.IsNull()) {
1004 if (fRunMuonTracking) {
1005 if (!RunMuonTracking(fesd)) {
1006 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1012 if (!fRunTracking.IsNull()) {
1013 if (!ReadESD(fesd, "tracking")) {
1014 if (!RunTracking(fesd)) {
1015 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1017 if (fCheckPointLevel > 0) WriteESD(fesd, "tracking");
1022 if (!fFillESD.IsNull()) {
1023 if (!FillESD(fesd, fFillESD)) {
1024 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1028 // fill Event header information from the RawEventHeader
1029 if (fRawReader){FillRawEventHeaderESD(fesd);}
1032 AliESDpid::MakePID(fesd);
1033 if (fCheckPointLevel > 1) WriteESD(fesd, "PID");
1035 if (fFillTriggerESD) {
1036 if (!ReadESD(fesd, "trigger")) {
1037 if (!FillTriggerESD(fesd)) {
1038 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1040 if (fCheckPointLevel > 1) WriteESD(fesd, "trigger");
1047 // Propagate track to the beam pipe (if not laready done by ITS)
1049 const Int_t ntracks = fesd->GetNumberOfTracks();
1050 const Double_t kBz = fesd->GetMagneticField();
1051 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1054 UShort_t *selectedIdx=new UShort_t[ntracks];
1056 for (Int_t itrack=0; itrack<ntracks; itrack++){
1057 const Double_t kMaxStep = 5; //max step over the material
1060 AliESDtrack *track = fesd->GetTrack(itrack);
1061 if (!track) continue;
1063 AliExternalTrackParam *tpcTrack =
1064 (AliExternalTrackParam *)track->GetTPCInnerParam();
1068 PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
1073 Int_t n=trkArray.GetEntriesFast();
1074 selectedIdx[n]=track->GetID();
1075 trkArray.AddLast(tpcTrack);
1078 if (track->GetX() < kRadius) continue;
1081 PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1083 track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kRadius);
1088 // Improve the reconstructed primary vertex position using the tracks
1090 TObject *obj = fOptions.FindObject("ITS");
1092 TString optITS = obj->GetTitle();
1093 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
1094 fRunVertexFinderTracks=kFALSE;
1096 if (fRunVertexFinderTracks) {
1097 // TPC + ITS primary vertex
1098 ftVertexer->SetITSrefitRequired();
1099 if(fDiamondProfile && fMeanVertexConstraint) {
1100 ftVertexer->SetVtxStart(fDiamondProfile);
1102 ftVertexer->SetConstraintOff();
1104 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
1106 if (pvtx->GetStatus()) {
1107 fesd->SetPrimaryVertex(pvtx);
1108 for (Int_t i=0; i<ntracks; i++) {
1109 AliESDtrack *t = fesd->GetTrack(i);
1110 t->RelateToVertex(pvtx, kBz, kRadius);
1115 // TPC-only primary vertex
1116 ftVertexer->SetITSrefitNotRequired();
1117 if(fDiamondProfileTPC && fMeanVertexConstraint) {
1118 ftVertexer->SetVtxStart(fDiamondProfileTPC);
1120 ftVertexer->SetConstraintOff();
1122 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
1124 if (pvtx->GetStatus()) {
1125 fesd->SetPrimaryVertexTPC(pvtx);
1126 Int_t nsel=trkArray.GetEntriesFast();
1127 for (Int_t i=0; i<nsel; i++) {
1128 AliExternalTrackParam *t =
1129 (AliExternalTrackParam *)trkArray.UncheckedAt(i);
1130 t->PropagateToDCA(pvtx, kBz, kRadius);
1136 delete[] selectedIdx;
1138 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
1143 AliV0vertexer vtxer;
1144 vtxer.Tracks2V0vertices(fesd);
1146 if (fRunCascadeFinder) {
1148 AliCascadeVertexer cvtxer;
1149 cvtxer.V0sTracks2CascadeVertices(fesd);
1154 if (fCleanESD) CleanESD(fesd);
1157 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1158 if (qadm) qadm->Exec(AliQA::kESDS, fesd);
1161 if (fWriteESDfriend) {
1162 fesdf->~AliESDfriend();
1163 new (fesdf) AliESDfriend(); // Reset...
1164 fesd->GetESDfriend(fesdf);
1171 if (fCheckPointLevel > 0) WriteESD(fesd, "final");
1174 if (fWriteESDfriend) {
1175 fesdf->~AliESDfriend();
1176 new (fesdf) AliESDfriend(); // Reset...
1179 ProcInfo_t ProcInfo;
1180 gSystem->GetProcInfo(&ProcInfo);
1181 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
1184 // End of cycle for the in-loop QA
1187 RunQA(fFillESD.Data(), fesd);
1188 TString detStr(fFillESD);
1189 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1190 if (!IsSelected(fgkDetectorName[iDet], detStr))
1192 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
1195 qadm->EndOfCycle(AliQA::kRECPOINTS);
1196 qadm->EndOfCycle(AliQA::kESDS);
1201 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1203 qadm->EndOfCycle(AliQA::kRECPOINTS);
1204 qadm->EndOfCycle(AliQA::kESDS);
1213 //_____________________________________________________________________________
1214 Bool_t AliReconstruction::AddEventAndRun()
1216 // for online usage only
1217 // Add an event to the run-loader
1219 // re-creates AliRawReaderDate for this new event
1220 AliCodeTimerAuto("");
1223 AliError("No raw-data event in memory given as an input! Do nothing!");
1227 // New raw-reader. Could be redone in a better way... To do
1228 fRawReader->~AliRawReader();
1229 new (fRawReader) AliRawReaderDate((void*)(*fpEvent));
1230 if (!fRawReader->NextEvent()) return kFALSE;
1232 // Expand the number of events in the run-loader
1234 Int_t nEvents = fRunLoader->GetNumberOfEvents();
1236 return RunEvent(nEvents);
1239 //_____________________________________________________________________________
1240 Bool_t AliReconstruction::FinishRun()
1243 // Called after the exit
1244 // from the event loop
1245 AliCodeTimerAuto("");
1247 if (fIsNewRunLoader) { // galice.root didn't exist
1248 fRunLoader->WriteHeader("OVERWRITE");
1249 fRunLoader->CdGAFile();
1250 fRunLoader->Write(0, TObject::kOverwrite);
1253 ftree->GetUserInfo()->Add(fesd);
1254 fhlttree->GetUserInfo()->Add(fhltesd);
1256 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1257 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1259 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1260 cdbMapCopy->SetOwner(1);
1261 cdbMapCopy->SetName("cdbMap");
1262 TIter iter(cdbMap->GetTable());
1265 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1266 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1267 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1268 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1271 TList *cdbListCopy = new TList();
1272 cdbListCopy->SetOwner(1);
1273 cdbListCopy->SetName("cdbList");
1275 TIter iter2(cdbList);
1278 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
1279 cdbListCopy->Add(new TObjString(id->ToString().Data()));
1282 ftree->GetUserInfo()->Add(cdbMapCopy);
1283 ftree->GetUserInfo()->Add(cdbListCopy);
1286 if(fESDPar.Contains("ESD.par")){
1287 AliInfo("Attaching ESD.par to Tree");
1288 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
1289 ftree->GetUserInfo()->Add(fn);
1295 if (fWriteESDfriend)
1296 ftree->SetBranchStatus("ESDfriend*",0);
1297 // we want to have only one tree version number
1298 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1301 // Finish with Plane Efficiency evaluation: before of CleanUp !!!
1302 if (fRunPlaneEff && !FinishPlaneEff()) {
1303 AliWarning("Finish PlaneEff evaluation failed");
1307 CleanUp(ffile, ffileOld);
1310 AliWarning("AOD creation not supported anymore during reconstruction. See ANALYSIS/AliAnalysisTaskESDfilter.cxx instead.");
1313 // Create tags for the events in the ESD tree (the ESD tree is always present)
1314 // In case of empty events the tags will contain dummy values
1315 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
1316 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPList);
1318 AliWarning("AOD tag creation not supported anymore during reconstruction.");
1321 //Finish QA and end of cycle for out-of-loop QA
1324 AliQADataMakerSteer qas;
1325 qas.Run(fRunLocalReconstruction.Data(), AliQA::kRECPOINTS, (fRunQA && fRawReader));
1327 qas.Run(fRunTracking.Data(), AliQA::kESDS, (fRunQA && fRawReader));
1330 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1332 qadm->EndOfCycle(AliQA::kRECPOINTS);
1333 qadm->EndOfCycle(AliQA::kESDS);
1339 // Cleanup of CDB manager: cache and active storages!
1340 AliCDBManager::Instance()->ClearCache();
1346 //_____________________________________________________________________________
1347 Bool_t AliReconstruction::RunLocalReconstruction(const TString& /*detectors*/)
1349 // run the local reconstruction
1350 static Int_t eventNr=0;
1351 AliCodeTimerAuto("")
1353 // AliCDBManager* man = AliCDBManager::Instance();
1354 // Bool_t origCache = man->GetCacheFlag();
1356 // TString detStr = detectors;
1357 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1358 // if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1359 // AliReconstructor* reconstructor = GetReconstructor(iDet);
1360 // if (!reconstructor) continue;
1361 // if (reconstructor->HasLocalReconstruction()) continue;
1363 // AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1364 // AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1366 // AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1367 // AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1369 // man->SetCacheFlag(kTRUE);
1370 // TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
1371 // man->GetAll(calibPath); // entries are cached!
1373 // AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1375 // if (fRawReader) {
1376 // fRawReader->RewindEvents();
1377 // reconstructor->Reconstruct(fRunLoader, fRawReader);
1379 // reconstructor->Reconstruct(fRunLoader);
1382 // AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1383 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
1385 // // unload calibration data
1386 // man->UnloadFromCache(calibPath);
1387 // //man->ClearCache();
1390 // man->SetCacheFlag(origCache);
1392 // if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1393 // AliError(Form("the following detectors were not found: %s",
1395 // if (fStopOnError) return kFALSE;
1402 //_____________________________________________________________________________
1403 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1405 // run the local reconstruction
1407 static Int_t eventNr=0;
1408 AliCodeTimerAuto("")
1410 TString detStr = detectors;
1411 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1412 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1413 AliReconstructor* reconstructor = GetReconstructor(iDet);
1414 if (!reconstructor) continue;
1415 AliLoader* loader = fLoader[iDet];
1417 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1420 // conversion of digits
1421 if (fRawReader && reconstructor->HasDigitConversion()) {
1422 AliInfo(Form("converting raw data digits into root objects for %s",
1423 fgkDetectorName[iDet]));
1424 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1425 fgkDetectorName[iDet]));
1426 loader->LoadDigits("update");
1427 loader->CleanDigits();
1428 loader->MakeDigitsContainer();
1429 TTree* digitsTree = loader->TreeD();
1430 reconstructor->ConvertDigits(fRawReader, digitsTree);
1431 loader->WriteDigits("OVERWRITE");
1432 loader->UnloadDigits();
1434 // local reconstruction
1435 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1436 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1437 loader->LoadRecPoints("update");
1438 loader->CleanRecPoints();
1439 loader->MakeRecPointsContainer();
1440 TTree* clustersTree = loader->TreeR();
1441 if (fRawReader && !reconstructor->HasDigitConversion()) {
1442 reconstructor->Reconstruct(fRawReader, clustersTree);
1444 loader->LoadDigits("read");
1445 TTree* digitsTree = loader->TreeD();
1447 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1448 if (fStopOnError) return kFALSE;
1450 reconstructor->Reconstruct(digitsTree, clustersTree);
1452 loader->UnloadDigits();
1455 // In-loop QA for local reconstrucion
1456 if (fRunQA && fInLoopQA) {
1457 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
1460 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1462 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1464 qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
1467 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1471 loader->WriteRecPoints("OVERWRITE");
1472 loader->UnloadRecPoints();
1473 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
1476 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1477 AliError(Form("the following detectors were not found: %s",
1479 if (fStopOnError) return kFALSE;
1485 //_____________________________________________________________________________
1486 Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
1488 // run the barrel tracking
1490 AliCodeTimerAuto("")
1492 AliESDVertex* vertex = NULL;
1493 Double_t vtxPos[3] = {0, 0, 0};
1494 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1495 TArrayF mcVertex(3);
1496 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1497 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1498 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1502 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1503 AliInfo("running the ITS vertex finder");
1504 if (fLoader[0]) fLoader[0]->LoadRecPoints();
1505 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
1506 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
1508 AliWarning("Vertex not found");
1509 vertex = new AliESDVertex();
1510 vertex->SetName("default");
1513 vertex->SetName("reconstructed");
1517 AliInfo("getting the primary vertex from MC");
1518 vertex = new AliESDVertex(vtxPos, vtxErr);
1522 vertex->GetXYZ(vtxPos);
1523 vertex->GetSigmaXYZ(vtxErr);
1525 AliWarning("no vertex reconstructed");
1526 vertex = new AliESDVertex(vtxPos, vtxErr);
1528 esd->SetPrimaryVertexSPD(vertex);
1529 // if SPD multiplicity has been determined, it is stored in the ESD
1530 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1531 if(mult)esd->SetMultiplicity(mult);
1533 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1534 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1541 //_____________________________________________________________________________
1542 Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1544 // run the HLT barrel tracking
1546 AliCodeTimerAuto("")
1549 AliError("Missing runLoader!");
1553 AliInfo("running HLT tracking");
1555 // Get a pointer to the HLT reconstructor
1556 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1557 if (!reconstructor) return kFALSE;
1560 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1561 TString detName = fgkDetectorName[iDet];
1562 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1563 reconstructor->SetOption(detName.Data());
1564 AliTracker *tracker = reconstructor->CreateTracker();
1566 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1567 if (fStopOnError) return kFALSE;
1571 Double_t vtxErr[3]={0.005,0.005,0.010};
1572 const AliESDVertex *vertex = esd->GetVertex();
1573 vertex->GetXYZ(vtxPos);
1574 tracker->SetVertex(vtxPos,vtxErr);
1576 fLoader[iDet]->LoadRecPoints("read");
1577 TTree* tree = fLoader[iDet]->TreeR();
1579 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1582 tracker->LoadClusters(tree);
1584 if (tracker->Clusters2Tracks(esd) != 0) {
1585 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1589 tracker->UnloadClusters();
1597 //_____________________________________________________________________________
1598 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
1600 // run the muon spectrometer tracking
1602 AliCodeTimerAuto("")
1605 AliError("Missing runLoader!");
1608 Int_t iDet = 7; // for MUON
1610 AliInfo("is running...");
1612 // Get a pointer to the MUON reconstructor
1613 AliReconstructor *reconstructor = GetReconstructor(iDet);
1614 if (!reconstructor) return kFALSE;
1617 TString detName = fgkDetectorName[iDet];
1618 AliDebug(1, Form("%s tracking", detName.Data()));
1619 AliTracker *tracker = reconstructor->CreateTracker();
1621 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1626 fLoader[iDet]->LoadRecPoints("read");
1628 tracker->LoadClusters(fLoader[iDet]->TreeR());
1630 Int_t rv = tracker->Clusters2Tracks(esd);
1634 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1638 fLoader[iDet]->UnloadRecPoints();
1640 tracker->UnloadClusters();
1648 //_____________________________________________________________________________
1649 Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
1651 // run the barrel tracking
1652 static Int_t eventNr=0;
1653 AliCodeTimerAuto("")
1655 AliInfo("running tracking");
1657 //Fill the ESD with the T0 info (will be used by the TOF)
1658 if (fReconstructor[11] && fLoader[11]) {
1659 fLoader[11]->LoadRecPoints("READ");
1660 TTree *treeR = fLoader[11]->TreeR();
1661 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1664 // pass 1: TPC + ITS inwards
1665 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1666 if (!fTracker[iDet]) continue;
1667 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1670 fLoader[iDet]->LoadRecPoints("read");
1671 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
1672 TTree* tree = fLoader[iDet]->TreeR();
1674 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1677 fTracker[iDet]->LoadClusters(tree);
1678 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1680 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1681 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1684 if (fCheckPointLevel > 1) {
1685 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1687 // preliminary PID in TPC needed by the ITS tracker
1689 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1690 AliESDpid::MakePID(esd);
1692 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
1695 // pass 2: ALL backwards
1697 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1698 if (!fTracker[iDet]) continue;
1699 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1702 if (iDet > 1) { // all except ITS, TPC
1704 fLoader[iDet]->LoadRecPoints("read");
1705 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
1706 tree = fLoader[iDet]->TreeR();
1708 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1711 fTracker[iDet]->LoadClusters(tree);
1712 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1716 if (iDet>1) // start filling residuals for the "outer" detectors
1717 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1719 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1720 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1723 if (fCheckPointLevel > 1) {
1724 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1728 if (iDet > 2) { // all except ITS, TPC, TRD
1729 fTracker[iDet]->UnloadClusters();
1730 fLoader[iDet]->UnloadRecPoints();
1732 // updated PID in TPC needed by the ITS tracker -MI
1734 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1735 AliESDpid::MakePID(esd);
1737 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1739 //stop filling residuals for the "outer" detectors
1740 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
1742 // write space-points to the ESD in case alignment data output
1744 if (fWriteAlignmentData)
1745 WriteAlignmentData(esd);
1747 // pass 3: TRD + TPC + ITS refit inwards
1749 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1750 if (!fTracker[iDet]) continue;
1751 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1754 if (iDet<2) // start filling residuals for TPC and ITS
1755 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1757 if (fTracker[iDet]->RefitInward(esd) != 0) {
1758 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1761 // run postprocessing
1762 if (fTracker[iDet]->PostProcess(esd) != 0) {
1763 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
1766 if (fCheckPointLevel > 1) {
1767 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1769 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1771 fTracker[iDet]->UnloadClusters();
1772 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
1773 fLoader[iDet]->UnloadRecPoints();
1774 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
1776 // stop filling residuals for TPC and ITS
1777 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
1783 //_____________________________________________________________________________
1784 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1786 // Remove the data which are not needed for the physics analysis.
1789 Int_t nTracks=esd->GetNumberOfTracks();
1790 Int_t nV0s=esd->GetNumberOfV0s();
1792 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
1794 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
1795 Bool_t rc=esd->Clean(cleanPars);
1797 nTracks=esd->GetNumberOfTracks();
1798 nV0s=esd->GetNumberOfV0s();
1800 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
1805 //_____________________________________________________________________________
1806 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
1808 // fill the event summary data
1810 AliCodeTimerAuto("")
1811 static Int_t eventNr=0;
1812 TString detStr = detectors;
1814 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1815 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1816 AliReconstructor* reconstructor = GetReconstructor(iDet);
1817 if (!reconstructor) continue;
1818 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1819 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1820 TTree* clustersTree = NULL;
1821 if (fLoader[iDet]) {
1822 fLoader[iDet]->LoadRecPoints("read");
1823 clustersTree = fLoader[iDet]->TreeR();
1824 if (!clustersTree) {
1825 AliError(Form("Can't get the %s clusters tree",
1826 fgkDetectorName[iDet]));
1827 if (fStopOnError) return kFALSE;
1830 if (fRawReader && !reconstructor->HasDigitConversion()) {
1831 reconstructor->FillESD(fRawReader, clustersTree, esd);
1833 TTree* digitsTree = NULL;
1834 if (fLoader[iDet]) {
1835 fLoader[iDet]->LoadDigits("read");
1836 digitsTree = fLoader[iDet]->TreeD();
1838 AliError(Form("Can't get the %s digits tree",
1839 fgkDetectorName[iDet]));
1840 if (fStopOnError) return kFALSE;
1843 reconstructor->FillESD(digitsTree, clustersTree, esd);
1844 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1846 if (fLoader[iDet]) {
1847 fLoader[iDet]->UnloadRecPoints();
1850 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1854 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1855 AliError(Form("the following detectors were not found: %s",
1857 if (fStopOnError) return kFALSE;
1859 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
1864 //_____________________________________________________________________________
1865 Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
1867 // Reads the trigger decision which is
1868 // stored in Trigger.root file and fills
1869 // the corresponding esd entries
1871 AliCodeTimerAuto("")
1873 AliInfo("Filling trigger information into the ESD");
1875 AliCentralTrigger *aCTP = NULL;
1878 AliCTPRawStream input(fRawReader);
1879 if (!input.Next()) {
1880 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1883 esd->SetTriggerMask(input.GetClassMask());
1884 esd->SetTriggerCluster(input.GetClusterMask());
1886 aCTP = new AliCentralTrigger();
1887 TString configstr("");
1888 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
1889 AliError("No trigger configuration found in OCDB! The trigger classes information will no be stored in ESD!");
1895 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1897 if (!runloader->LoadTrigger()) {
1898 aCTP = runloader->GetTrigger();
1899 esd->SetTriggerMask(aCTP->GetClassMask());
1900 esd->SetTriggerCluster(aCTP->GetClusterMask());
1903 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1908 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1913 // Now fill the trigger class names into AliESDRun object
1914 AliTriggerConfiguration *config = aCTP->GetConfiguration();
1916 AliError("No trigger configuration has been found! The trigger classes information will no be stored in ESD!");
1917 if (fRawReader) delete aCTP;
1921 const TObjArray& classesArray = config->GetClasses();
1922 Int_t nclasses = classesArray.GetEntriesFast();
1923 for( Int_t j=0; j<nclasses; j++ ) {
1924 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
1925 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
1926 esd->SetTriggerClass(trclass->GetName(),trindex);
1929 if (fRawReader) delete aCTP;
1937 //_____________________________________________________________________________
1938 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
1941 // Filling information from RawReader Header
1944 AliInfo("Filling information from RawReader Header");
1945 esd->SetBunchCrossNumber(0);
1946 esd->SetOrbitNumber(0);
1947 esd->SetPeriodNumber(0);
1948 esd->SetTimeStamp(0);
1949 esd->SetEventType(0);
1950 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1953 const UInt_t *id = eventHeader->GetP("Id");
1954 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1955 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1956 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1958 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1959 esd->SetEventType((eventHeader->Get("Type")));
1966 //_____________________________________________________________________________
1967 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1969 // check whether detName is contained in detectors
1970 // if yes, it is removed from detectors
1972 // check if all detectors are selected
1973 if ((detectors.CompareTo("ALL") == 0) ||
1974 detectors.BeginsWith("ALL ") ||
1975 detectors.EndsWith(" ALL") ||
1976 detectors.Contains(" ALL ")) {
1981 // search for the given detector
1982 Bool_t result = kFALSE;
1983 if ((detectors.CompareTo(detName) == 0) ||
1984 detectors.BeginsWith(detName+" ") ||
1985 detectors.EndsWith(" "+detName) ||
1986 detectors.Contains(" "+detName+" ")) {
1987 detectors.ReplaceAll(detName, "");
1991 // clean up the detectors string
1992 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1993 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1994 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1999 //_____________________________________________________________________________
2000 Bool_t AliReconstruction::InitRunLoader()
2002 // get or create the run loader
2004 if (gAlice) delete gAlice;
2007 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2008 // load all base libraries to get the loader classes
2009 TString libs = gSystem->GetLibraries();
2010 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2011 TString detName = fgkDetectorName[iDet];
2012 if (detName == "HLT") continue;
2013 if (libs.Contains("lib" + detName + "base.so")) continue;
2014 gSystem->Load("lib" + detName + "base.so");
2016 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2018 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2022 fRunLoader->CdGAFile();
2023 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
2024 if (fRunLoader->LoadgAlice() == 0) {
2025 gAlice = fRunLoader->GetAliRun();
2026 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
2029 if (!gAlice && !fRawReader) {
2030 AliError(Form("no gAlice object found in file %s",
2031 fGAliceFileName.Data()));
2036 //PH This is a temporary fix to give access to the kinematics
2037 //PH that is needed for the labels of ITS clusters
2038 fRunLoader->LoadHeader();
2039 fRunLoader->LoadKinematics();
2041 } else { // galice.root does not exist
2043 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
2047 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2048 AliConfig::GetDefaultEventFolderName(),
2051 AliError(Form("could not create run loader in file %s",
2052 fGAliceFileName.Data()));
2056 fIsNewRunLoader = kTRUE;
2057 fRunLoader->MakeTree("E");
2059 if (fNumberOfEventsPerFile > 0)
2060 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2062 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
2068 //_____________________________________________________________________________
2069 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
2071 // get the reconstructor object and the loader for a detector
2073 if (fReconstructor[iDet]) return fReconstructor[iDet];
2075 // load the reconstructor object
2076 TPluginManager* pluginManager = gROOT->GetPluginManager();
2077 TString detName = fgkDetectorName[iDet];
2078 TString recName = "Ali" + detName + "Reconstructor";
2079 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
2081 AliReconstructor* reconstructor = NULL;
2082 // first check if a plugin is defined for the reconstructor
2083 TPluginHandler* pluginHandler =
2084 pluginManager->FindHandler("AliReconstructor", detName);
2085 // if not, add a plugin for it
2086 if (!pluginHandler) {
2087 AliDebug(1, Form("defining plugin for %s", recName.Data()));
2088 TString libs = gSystem->GetLibraries();
2089 if (libs.Contains("lib" + detName + "base.so") ||
2090 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2091 pluginManager->AddHandler("AliReconstructor", detName,
2092 recName, detName + "rec", recName + "()");
2094 pluginManager->AddHandler("AliReconstructor", detName,
2095 recName, detName, recName + "()");
2097 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2099 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2100 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
2102 if (reconstructor) {
2103 TObject* obj = fOptions.FindObject(detName.Data());
2104 if (obj) reconstructor->SetOption(obj->GetTitle());
2105 reconstructor->Init();
2106 fReconstructor[iDet] = reconstructor;
2109 // get or create the loader
2110 if (detName != "HLT") {
2111 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2112 if (!fLoader[iDet]) {
2113 AliConfig::Instance()
2114 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2116 // first check if a plugin is defined for the loader
2118 pluginManager->FindHandler("AliLoader", detName);
2119 // if not, add a plugin for it
2120 if (!pluginHandler) {
2121 TString loaderName = "Ali" + detName + "Loader";
2122 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2123 pluginManager->AddHandler("AliLoader", detName,
2124 loaderName, detName + "base",
2125 loaderName + "(const char*, TFolder*)");
2126 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2128 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2130 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2131 fRunLoader->GetEventFolder());
2133 if (!fLoader[iDet]) { // use default loader
2134 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2136 if (!fLoader[iDet]) {
2137 AliWarning(Form("couldn't get loader for %s", detName.Data()));
2138 if (fStopOnError) return NULL;
2140 fRunLoader->AddLoader(fLoader[iDet]);
2141 fRunLoader->CdGAFile();
2142 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2143 fRunLoader->Write(0, TObject::kOverwrite);
2148 return reconstructor;
2151 //_____________________________________________________________________________
2152 Bool_t AliReconstruction::CreateVertexer()
2154 // create the vertexer
2157 AliReconstructor* itsReconstructor = GetReconstructor(0);
2158 if (itsReconstructor) {
2159 fVertexer = itsReconstructor->CreateVertexer();
2162 AliWarning("couldn't create a vertexer for ITS");
2163 if (fStopOnError) return kFALSE;
2169 //_____________________________________________________________________________
2170 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
2172 // create the trackers
2174 TString detStr = detectors;
2175 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2176 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2177 AliReconstructor* reconstructor = GetReconstructor(iDet);
2178 if (!reconstructor) continue;
2179 TString detName = fgkDetectorName[iDet];
2180 if (detName == "HLT") {
2181 fRunHLTTracking = kTRUE;
2184 if (detName == "MUON") {
2185 fRunMuonTracking = kTRUE;
2190 fTracker[iDet] = reconstructor->CreateTracker();
2191 if (!fTracker[iDet] && (iDet < 7)) {
2192 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
2193 if (fStopOnError) return kFALSE;
2195 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
2201 //_____________________________________________________________________________
2202 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
2204 // delete trackers and the run loader and close and delete the file
2206 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2207 delete fReconstructor[iDet];
2208 fReconstructor[iDet] = NULL;
2209 fLoader[iDet] = NULL;
2210 delete fTracker[iDet];
2211 fTracker[iDet] = NULL;
2212 // delete fQADataMaker[iDet];
2213 // fQADataMaker[iDet] = NULL;
2218 if (ftVertexer) delete ftVertexer;
2221 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
2222 delete fDiamondProfile;
2223 fDiamondProfile = NULL;
2224 delete fDiamondProfileTPC;
2225 fDiamondProfileTPC = NULL;
2235 if (fParentRawReader) delete fParentRawReader;
2236 fParentRawReader=NULL;
2246 gSystem->Unlink("AliESDs.old.root");
2251 //_____________________________________________________________________________
2253 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
2255 // read the ESD event from a file
2257 if (!esd) return kFALSE;
2259 sprintf(fileName, "ESD_%d.%d_%s.root",
2260 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
2261 if (gSystem->AccessPathName(fileName)) return kFALSE;
2263 AliInfo(Form("reading ESD from file %s", fileName));
2264 AliDebug(1, Form("reading ESD from file %s", fileName));
2265 TFile* file = TFile::Open(fileName);
2266 if (!file || !file->IsOpen()) {
2267 AliError(Form("opening %s failed", fileName));
2274 esd = (AliESDEvent*) file->Get("ESD");
2283 //_____________________________________________________________________________
2284 void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
2286 // write the ESD event to a file
2290 sprintf(fileName, "ESD_%d.%d_%s.root",
2291 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
2293 AliDebug(1, Form("writing ESD to file %s", fileName));
2294 TFile* file = TFile::Open(fileName, "recreate");
2295 if (!file || !file->IsOpen()) {
2296 AliError(Form("opening %s failed", fileName));
2305 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
2307 // Write space-points which are then used in the alignment procedures
2308 // For the moment only ITS, TRD and TPC
2310 // Load TOF clusters
2312 fLoader[3]->LoadRecPoints("read");
2313 TTree* tree = fLoader[3]->TreeR();
2315 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2318 fTracker[3]->LoadClusters(tree);
2320 Int_t ntracks = esd->GetNumberOfTracks();
2321 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2323 AliESDtrack *track = esd->GetTrack(itrack);
2326 for (Int_t iDet = 3; iDet >= 0; iDet--)
2327 nsp += track->GetNcls(iDet);
2329 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2330 track->SetTrackPointArray(sp);
2332 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2333 AliTracker *tracker = fTracker[iDet];
2334 if (!tracker) continue;
2335 Int_t nspdet = track->GetNcls(iDet);
2336 if (nspdet <= 0) continue;
2337 track->GetClusters(iDet,idx);
2341 while (isp2 < nspdet) {
2343 TString dets = fgkDetectorName[iDet];
2344 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2345 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2346 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2347 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
2348 isvalid = tracker->GetTrackPointTrackingError(idx[isp2],p,track);
2350 isvalid = tracker->GetTrackPoint(idx[isp2],p);
2353 const Int_t kNTPCmax = 159;
2354 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2355 if (!isvalid) continue;
2356 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2362 fTracker[3]->UnloadClusters();
2363 fLoader[3]->UnloadRecPoints();
2367 //_____________________________________________________________________________
2368 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2370 // The method reads the raw-data error log
2371 // accumulated within the rawReader.
2372 // It extracts the raw-data errors related to
2373 // the current event and stores them into
2374 // a TClonesArray inside the esd object.
2376 if (!fRawReader) return;
2378 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2380 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2382 if (iEvent != log->GetEventNumber()) continue;
2384 esd->AddRawDataErrorLog(log);
2389 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
2390 // Dump a file content into a char in TNamed
2392 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2393 Int_t kBytes = (Int_t)in.tellg();
2394 printf("Size: %d \n",kBytes);
2397 char* memblock = new char [kBytes];
2398 in.seekg (0, ios::beg);
2399 in.read (memblock, kBytes);
2401 TString fData(memblock,kBytes);
2402 fn = new TNamed(fName,fData);
2403 printf("fData Size: %d \n",fData.Sizeof());
2404 printf("fName Size: %d \n",fName.Sizeof());
2405 printf("fn Size: %d \n",fn->Sizeof());
2409 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2415 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
2416 // This is not really needed in AliReconstruction at the moment
2417 // but can serve as a template
2419 TList *fList = fTree->GetUserInfo();
2420 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2421 printf("fn Size: %d \n",fn->Sizeof());
2423 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2424 const char* cdata = fn->GetTitle();
2425 printf("fTmp Size %d\n",fTmp.Sizeof());
2427 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2428 printf("calculated size %d\n",size);
2429 ofstream out(fName.Data(),ios::out | ios::binary);
2430 out.write(cdata,size);
2435 //_____________________________________________________________________________
2436 AliQADataMakerRec * AliReconstruction::GetQADataMaker(Int_t iDet)
2438 // get the quality assurance data maker object and the loader for a detector
2440 if (fQADataMaker[iDet])
2441 return fQADataMaker[iDet];
2443 AliQADataMakerRec * qadm = NULL;
2444 if (iDet == fgkNDetectors) { //Global QA
2445 qadm = new AliGlobalQADataMaker();
2446 fQADataMaker[iDet] = qadm;
2450 // load the QA data maker object
2451 TPluginManager* pluginManager = gROOT->GetPluginManager();
2452 TString detName = fgkDetectorName[iDet];
2453 TString qadmName = "Ali" + detName + "QADataMakerRec";
2454 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT"))
2457 // first check if a plugin is defined for the quality assurance data maker
2458 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
2459 // if not, add a plugin for it
2460 if (!pluginHandler) {
2461 AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
2462 TString libs = gSystem->GetLibraries();
2463 if (libs.Contains("lib" + detName + "base.so") ||
2464 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2465 pluginManager->AddHandler("AliQADataMakerRec", detName,
2466 qadmName, detName + "qadm", qadmName + "()");
2468 pluginManager->AddHandler("AliQADataMakerRec", detName,
2469 qadmName, detName, qadmName + "()");
2471 pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
2473 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2474 qadm = (AliQADataMakerRec *) pluginHandler->ExecPlugin(0);
2477 fQADataMaker[iDet] = qadm;
2482 //_____________________________________________________________________________
2483 Bool_t AliReconstruction::RunQA(const char* detectors, AliESDEvent *& esd)
2485 // run the Quality Assurance data producer
2487 AliCodeTimerAuto("")
2488 TString detStr = detectors;
2489 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2490 if (!IsSelected(fgkDetectorName[iDet], detStr))
2492 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
2495 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2496 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2498 qadm->Exec(AliQA::kESDS, esd) ;
2501 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2503 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2504 AliError(Form("the following detectors were not found: %s",
2514 //_____________________________________________________________________________
2515 void AliReconstruction::CheckQA()
2517 // check the QA of SIM for this run and remove the detectors
2518 // with status Fatal
2520 TString newRunLocalReconstruction ;
2521 TString newRunTracking ;
2522 TString newFillESD ;
2524 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2525 TString detName(AliQA::GetDetName(iDet)) ;
2526 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2527 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
2528 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
2530 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2531 fRunLocalReconstruction.Contains("ALL") ) {
2532 newRunLocalReconstruction += detName ;
2533 newRunLocalReconstruction += " " ;
2535 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2536 fRunTracking.Contains("ALL") ) {
2537 newRunTracking += detName ;
2538 newRunTracking += " " ;
2540 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2541 fFillESD.Contains("ALL") ) {
2542 newFillESD += detName ;
2547 fRunLocalReconstruction = newRunLocalReconstruction ;
2548 fRunTracking = newRunTracking ;
2549 fFillESD = newFillESD ;
2552 //_____________________________________________________________________________
2553 Int_t AliReconstruction::GetDetIndex(const char* detector)
2555 // return the detector index corresponding to detector
2557 for (index = 0; index < fgkNDetectors ; index++) {
2558 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2563 //_____________________________________________________________________________
2564 Bool_t AliReconstruction::FinishPlaneEff() {
2566 // Here execute all the necessary operationis, at the end of the tracking phase,
2567 // in case that evaluation of PlaneEfficiencies was required for some detector.
2568 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
2570 // This Preliminary version works only FOR ITS !!!!!
2571 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2574 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2577 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2578 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
2579 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2580 if(fTracker[iDet]) {
2581 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2582 ret=planeeff->WriteIntoCDB();
2583 if(planeeff->GetCreateHistos()) {
2584 TString name="PlaneEffHisto";
2585 name+=fgkDetectorName[iDet];
2587 ret*=planeeff->WriteHistosToFile(name,"RECREATE");
2593 //_____________________________________________________________________________
2594 Bool_t AliReconstruction::InitPlaneEff() {
2596 // Here execute all the necessary operations, before of the tracking phase,
2597 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2598 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2599 // which should be updated/recalculated.
2601 // This Preliminary version will work only FOR ITS !!!!!
2602 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2605 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2607 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));