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),
258 fSameQACycle(kFALSE),
260 fRunPlaneEff(kFALSE),
272 fIsNewRunLoader(kFALSE)
274 // create reconstruction object with default parameters
276 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
277 fReconstructor[iDet] = NULL;
278 fLoader[iDet] = NULL;
279 fTracker[iDet] = NULL;
280 fQADataMaker[iDet] = NULL;
281 fQACycles[iDet] = 999999;
283 fQADataMaker[fgkNDetectors]=NULL; //Global QA
287 //_____________________________________________________________________________
288 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
291 fUniformField(rec.fUniformField),
292 fRunVertexFinder(rec.fRunVertexFinder),
293 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
294 fRunHLTTracking(rec.fRunHLTTracking),
295 fRunMuonTracking(rec.fRunMuonTracking),
296 fRunV0Finder(rec.fRunV0Finder),
297 fRunCascadeFinder(rec.fRunCascadeFinder),
298 fStopOnError(rec.fStopOnError),
299 fWriteAlignmentData(rec.fWriteAlignmentData),
300 fWriteESDfriend(rec.fWriteESDfriend),
301 fWriteAOD(rec.fWriteAOD),
302 fFillTriggerESD(rec.fFillTriggerESD),
304 fCleanESD(rec.fCleanESD),
305 fV0DCAmax(rec.fV0DCAmax),
306 fV0CsPmin(rec.fV0CsPmin),
310 fRunLocalReconstruction(rec.fRunLocalReconstruction),
311 fRunTracking(rec.fRunTracking),
312 fFillESD(rec.fFillESD),
313 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
314 fGAliceFileName(rec.fGAliceFileName),
316 fpEvent(rec.fpEvent),
317 fEquipIdMap(rec.fEquipIdMap),
318 fFirstEvent(rec.fFirstEvent),
319 fLastEvent(rec.fLastEvent),
320 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
323 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
324 fLoadAlignData(rec.fLoadAlignData),
325 fESDPar(rec.fESDPar),
326 fUseHLTData(rec.fUseHLTData),
330 fParentRawReader(NULL),
333 fDiamondProfile(NULL),
334 fDiamondProfileTPC(NULL),
335 fMeanVertexConstraint(rec.fMeanVertexConstraint),
339 fAlignObjArray(rec.fAlignObjArray),
340 fCDBUri(rec.fCDBUri),
342 fInitCDBCalled(rec.fInitCDBCalled),
343 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
345 fRunGlobalQA(rec.fRunGlobalQA),
346 fInLoopQA(rec.fInLoopQA),
347 fSameQACycle(rec.fSameQACycle),
348 fRunPlaneEff(rec.fRunPlaneEff),
360 fIsNewRunLoader(rec.fIsNewRunLoader)
364 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
365 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
367 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
368 fReconstructor[iDet] = NULL;
369 fLoader[iDet] = NULL;
370 fTracker[iDet] = NULL;
371 fQADataMaker[iDet] = NULL;
372 fQACycles[iDet] = rec.fQACycles[iDet];
374 fQADataMaker[fgkNDetectors]=NULL; //Global QA
375 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
376 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
380 //_____________________________________________________________________________
381 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
383 // assignment operator
385 this->~AliReconstruction();
386 new(this) AliReconstruction(rec);
390 //_____________________________________________________________________________
391 AliReconstruction::~AliReconstruction()
397 fSpecCDBUri.Delete();
399 AliCodeTimer::Instance()->Print();
402 //_____________________________________________________________________________
403 void AliReconstruction::InitCDB()
405 // activate a default CDB storage
406 // First check if we have any CDB storage set, because it is used
407 // to retrieve the calibration and alignment constants
409 if (fInitCDBCalled) return;
410 fInitCDBCalled = kTRUE;
412 AliCDBManager* man = AliCDBManager::Instance();
413 if (man->IsDefaultStorageSet())
415 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
416 AliWarning("Default CDB storage has been already set !");
417 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
418 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
419 fCDBUri = man->GetDefaultStorage()->GetURI();
422 if (fCDBUri.Length() > 0)
424 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
425 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
426 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
428 fCDBUri="local://$ALICE_ROOT";
429 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
430 AliWarning("Default CDB storage not yet set !!!!");
431 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
432 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
435 man->SetDefaultStorage(fCDBUri);
438 // Now activate the detector specific CDB storage locations
439 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
440 TObject* obj = fSpecCDBUri[i];
442 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
443 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
444 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
445 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
450 //_____________________________________________________________________________
451 void AliReconstruction::SetDefaultStorage(const char* uri) {
452 // Store the desired default CDB storage location
453 // Activate it later within the Run() method
459 //_____________________________________________________________________________
460 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
461 // Store a detector-specific CDB storage location
462 // Activate it later within the Run() method
464 AliCDBPath aPath(calibType);
465 if(!aPath.IsValid()){
466 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
467 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
468 if(!strcmp(calibType, fgkDetectorName[iDet])) {
469 aPath.SetPath(Form("%s/*", calibType));
470 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
474 if(!aPath.IsValid()){
475 AliError(Form("Not a valid path or detector: %s", calibType));
480 // // check that calibType refers to a "valid" detector name
481 // Bool_t isDetector = kFALSE;
482 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
483 // TString detName = fgkDetectorName[iDet];
484 // if(aPath.GetLevel0() == detName) {
485 // isDetector = kTRUE;
491 // AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
495 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
496 if (obj) fSpecCDBUri.Remove(obj);
497 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
501 //_____________________________________________________________________________
502 Bool_t AliReconstruction::SetRunNumberFromData()
504 // The method is called in Run() in order
505 // to set a correct run number.
506 // In case of raw data reconstruction the
507 // run number is taken from the raw data header
509 if (fSetRunNumberFromDataCalled) return kTRUE;
510 fSetRunNumberFromDataCalled = kTRUE;
512 AliCDBManager* man = AliCDBManager::Instance();
514 if(man->GetRun() > 0) {
515 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
519 AliError("No run loader is found !");
522 // read run number from gAlice
523 if(fRunLoader->GetAliRun())
524 AliCDBManager::Instance()->SetRun(fRunLoader->GetHeader()->GetRun());
527 if(fRawReader->NextEvent()) {
528 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
529 fRawReader->RewindEvents();
532 if(man->GetRun() > 0) {
533 AliWarning("No raw events is found ! Using settings in AliCDBManager !");
538 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
544 AliError("Neither gAlice nor RawReader objects are found !");
554 //_____________________________________________________________________________
555 void AliReconstruction::SetCDBLock() {
556 // Set CDB lock: from now on it is forbidden to reset the run number
557 // or the default storage or to activate any further storage!
559 AliCDBManager::Instance()->SetLock(1);
562 //_____________________________________________________________________________
563 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
565 // Read the alignment objects from CDB.
566 // Each detector is supposed to have the
567 // alignment objects in DET/Align/Data CDB path.
568 // All the detector objects are then collected,
569 // sorted by geometry level (starting from ALIC) and
570 // then applied to the TGeo geometry.
571 // Finally an overlaps check is performed.
573 // Load alignment data from CDB and fill fAlignObjArray
574 if(fLoadAlignFromCDB){
576 TString detStr = detectors;
577 TString loadAlObjsListOfDets = "";
579 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
580 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
581 loadAlObjsListOfDets += fgkDetectorName[iDet];
582 loadAlObjsListOfDets += " ";
583 } // end loop over detectors
584 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
585 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
587 // Check if the array with alignment objects was
588 // provided by the user. If yes, apply the objects
589 // to the present TGeo geometry
590 if (fAlignObjArray) {
591 if (gGeoManager && gGeoManager->IsClosed()) {
592 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
593 AliError("The misalignment of one or more volumes failed!"
594 "Compare the list of simulated detectors and the list of detector alignment data!");
599 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
605 delete fAlignObjArray; fAlignObjArray=0;
610 //_____________________________________________________________________________
611 void AliReconstruction::SetGAliceFile(const char* fileName)
613 // set the name of the galice file
615 fGAliceFileName = fileName;
618 //_____________________________________________________________________________
619 void AliReconstruction::SetInput(const char* input,void **pEvent)
621 // In case event pointer is given, we run in an online mode
622 // and the first argument is ignored.
623 // In case event pointer is NULL, we run in a normal
624 // mode over a raw-data file and the first argument points
625 // to the name of that file
636 //_____________________________________________________________________________
637 void AliReconstruction::SetOption(const char* detector, const char* option)
639 // set options for the reconstruction of a detector
641 TObject* obj = fOptions.FindObject(detector);
642 if (obj) fOptions.Remove(obj);
643 fOptions.Add(new TNamed(detector, option));
646 //_____________________________________________________________________________
647 Bool_t AliReconstruction::Run(const char* input)
650 AliCodeTimerAuto("");
652 if (!InitRun(input)) return kFALSE;
654 //******* The loop over events
656 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
657 (fRawReader && fRawReader->NextEvent())) {
658 if (!RunEvent(iEvent)) return kFALSE;
662 if (!FinishRun()) return kFALSE;
667 //_____________________________________________________________________________
668 Bool_t AliReconstruction::InitRun(const char* input, void **pEvent)
670 // Initialize all the stuff before
671 // going into the event loop
672 // If the second argument is given, the first one is ignored and
673 // the reconstruction works in an online mode
674 AliCodeTimerAuto("");
676 if (pEvent) fpEvent = pEvent;
677 if (input) fInput = input;
679 // set the input in case of raw data
680 if (!fInput.IsNull() || fpEvent) {
681 if (!fInput.IsNull()) {
682 AliInfo(Form("Reconstruction will run over a raw-data file: %s",fInput.Data()));
683 TString fileName(fInput);
684 if (fInput.EndsWith("/")) {
685 fRawReader = new AliRawReaderFile(fInput);
686 } else if (fInput.EndsWith(".root")) {
687 fRawReader = new AliRawReaderRoot(fInput);
689 fRawReader = new AliRawReaderDate(fInput);
693 AliInfo(Form("Reconstruction will run over an event in memory at: %p",*fpEvent));
694 fRawReader = new AliRawReaderDate((void *)(*fpEvent));
698 AliInfo("Reconstruction will run over digits");
701 if (!fEquipIdMap.IsNull() && fRawReader)
702 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
704 if (!fUseHLTData.IsNull()) {
705 // create the RawReaderHLT which performs redirection of HLT input data for
706 // the specified detectors
707 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
709 fParentRawReader=fRawReader;
710 fRawReader=pRawReader;
712 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
716 AliSysInfo::AddStamp("Start");
717 // get the run loader
718 if (!InitRunLoader()) return kFALSE;
719 AliSysInfo::AddStamp("LoadLoader");
721 // Initialize the CDB storage
724 AliSysInfo::AddStamp("LoadCDB");
726 // Set run number in CDBManager (if it is not already set by the user)
727 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
729 // Set CDB lock: from now on it is forbidden to reset the run number
730 // or the default storage or to activate any further storage!
733 // Import ideal TGeo geometry and apply misalignment
735 TString geom(gSystem->DirName(fGAliceFileName));
736 geom += "/geometry.root";
737 AliGeomManager::LoadGeometry(geom.Data());
738 if (!gGeoManager) if (fStopOnError) return kFALSE;
741 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
742 AliSysInfo::AddStamp("LoadGeom");
745 AliQADataMakerSteer qas ;
746 if (fRunQA && fRawReader) {
747 qas.Run(fRunLocalReconstruction, fRawReader) ;
748 fSameQACycle = kTRUE ;
750 // checking the QA of previous steps
754 // local reconstruction
755 if (!fRunLocalReconstruction.IsNull()) {
756 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
757 if (fStopOnError) {CleanUp(); return kFALSE;}
763 if (fRunVertexFinder && !CreateVertexer()) {
769 AliSysInfo::AddStamp("Vertexer");
772 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
778 AliSysInfo::AddStamp("LoadTrackers");
780 // get the possibly already existing ESD file and tree
781 fesd = new AliESDEvent(); fhltesd = new AliESDEvent();
782 if (!gSystem->AccessPathName("AliESDs.root")){
783 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
784 ffileOld = TFile::Open("AliESDs.old.root");
785 if (ffileOld && ffileOld->IsOpen()) {
786 ftreeOld = (TTree*) ffileOld->Get("esdTree");
787 if (ftreeOld)fesd->ReadFromTree(ftreeOld);
788 fhlttreeOld = (TTree*) ffileOld->Get("HLTesdTree");
789 if (fhlttreeOld) fhltesd->ReadFromTree(fhlttreeOld);
793 // create the ESD output file and tree
794 ffile = TFile::Open("AliESDs.root", "RECREATE");
795 ffile->SetCompressionLevel(2);
796 if (!ffile->IsOpen()) {
797 AliError("opening AliESDs.root failed");
798 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
801 ftree = new TTree("esdTree", "Tree with ESD objects");
802 fesd = new AliESDEvent();
803 fesd->CreateStdContent();
804 fesd->WriteToTree(ftree);
806 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
807 fhltesd = new AliESDEvent();
808 fhltesd->CreateStdContent();
809 fhltesd->WriteToTree(fhlttree);
812 delete esd; delete hltesd;
813 esd = NULL; hltesd = NULL;
815 // create the branch with ESD additions
819 if (fWriteESDfriend) {
820 fesdf = new AliESDfriend();
821 TBranch *br=ftree->Branch("ESDfriend.","AliESDfriend", &fesdf);
822 br->SetFile("AliESDfriends.root");
823 fesd->AddObject(fesdf);
827 // Get the GRP CDB entry
828 AliCDBEntry* entryGRP = AliCDBManager::Instance()->Get("GRP/GRP/Data");
831 fGRPList = dynamic_cast<TList*> (entryGRP->GetObject());
833 AliError("No GRP entry found in OCDB!");
836 // Get the diamond profile from OCDB
837 AliCDBEntry* entry = AliCDBManager::Instance()
838 ->Get("GRP/Calib/MeanVertex");
841 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
843 AliError("No diamond profile found in OCDB!");
847 entry = AliCDBManager::Instance()
848 ->Get("GRP/Calib/MeanVertexTPC");
851 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
853 AliError("No diamond profile found in OCDB!");
856 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
857 if(fDiamondProfile && fMeanVertexConstraint) ftVertexer->SetVtxStart(fDiamondProfile);
859 if (fRawReader) fRawReader->RewindEvents();
862 gSystem->GetProcInfo(&ProcInfo);
863 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
866 //Initialize the QA and start of cycle for out-of-cycle QA
868 TString detStr(fFillESD);
869 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
870 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
871 AliQADataMakerRec *qadm = GetQADataMaker(iDet);
873 AliInfo(Form("Initializing the QA data maker for %s",
874 fgkDetectorName[iDet]));
875 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
876 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
878 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
879 qadm->StartOfCycle(AliQA::kESDS,"same");
883 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
884 AliInfo(Form("Initializing the global QA data maker"));
886 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
887 AliTracker::SetResidualsArray(arr);
888 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
890 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
891 qadm->StartOfCycle(AliQA::kESDS, "same");
895 fSameQACycle = kTRUE;
898 //Initialize the Plane Efficiency framework
899 if (fRunPlaneEff && !InitPlaneEff()) {
900 if(fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
906 //_____________________________________________________________________________
907 Bool_t AliReconstruction::RunEvent(Int_t iEvent)
909 // run the reconstruction over a single event
910 // The event loop is steered in Run method
912 AliCodeTimerAuto("");
914 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
915 fRunLoader->SetEventNumber(iEvent);
916 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
918 //?? fRunLoader->MakeTree("H");
919 fRunLoader->TreeE()->Fill();
922 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
923 // copy old ESD to the new one
925 fesd->ReadFromTree(ftreeOld);
926 ftreeOld->GetEntry(iEvent);
930 fesd->ReadFromTree(fhlttreeOld);
931 fhlttreeOld->GetEntry(iEvent);
937 AliInfo(Form("processing event %d", iEvent));
939 //Start of cycle for the in-loop QA
942 TString detStr(fFillESD);
943 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
944 if (!IsSelected(fgkDetectorName[iDet], detStr))
946 AliQADataMakerRec *qadm = GetQADataMaker(iDet);
949 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
950 qadm->StartOfCycle(AliQA::kESDS, "same") ;
953 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
954 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
955 qadm->StartOfCycle(AliQA::kESDS, "same");
960 fRunLoader->GetEvent(iEvent);
963 sprintf(aFileName, "ESD_%d.%d_final.root",
964 fRunLoader->GetHeader()->GetRun(),
965 fRunLoader->GetHeader()->GetEventNrInRun());
966 if (!gSystem->AccessPathName(aFileName)) return kTRUE;
968 // local signle event reconstruction
969 if (!fRunLocalReconstruction.IsNull()) {
970 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
971 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
975 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
976 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
977 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
978 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
980 // Set magnetic field from the tracker
981 fesd->SetMagneticField(AliTracker::GetBz());
982 fhltesd->SetMagneticField(AliTracker::GetBz());
986 // Fill raw-data error log into the ESD
987 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
990 if (fRunVertexFinder) {
991 if (!ReadESD(fesd, "vertex")) {
992 if (!RunVertexFinder(fesd)) {
993 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
995 if (fCheckPointLevel > 0) WriteESD(fesd, "vertex");
1000 if (!fRunTracking.IsNull()) {
1001 if (fRunHLTTracking) {
1002 fhltesd->SetPrimaryVertexSPD(fesd->GetVertex());
1003 if (!RunHLTTracking(fhltesd)) {
1004 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1010 if (!fRunTracking.IsNull()) {
1011 if (fRunMuonTracking) {
1012 if (!RunMuonTracking(fesd)) {
1013 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1019 if (!fRunTracking.IsNull()) {
1020 if (!ReadESD(fesd, "tracking")) {
1021 if (!RunTracking(fesd)) {
1022 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1024 if (fCheckPointLevel > 0) WriteESD(fesd, "tracking");
1029 if (!fFillESD.IsNull()) {
1030 if (!FillESD(fesd, fFillESD)) {
1031 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1035 // fill Event header information from the RawEventHeader
1036 if (fRawReader){FillRawEventHeaderESD(fesd);}
1039 AliESDpid::MakePID(fesd);
1040 if (fCheckPointLevel > 1) WriteESD(fesd, "PID");
1042 if (fFillTriggerESD) {
1043 if (!ReadESD(fesd, "trigger")) {
1044 if (!FillTriggerESD(fesd)) {
1045 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1047 if (fCheckPointLevel > 1) WriteESD(fesd, "trigger");
1054 // Propagate track to the beam pipe (if not laready done by ITS)
1056 const Int_t ntracks = fesd->GetNumberOfTracks();
1057 const Double_t kBz = fesd->GetMagneticField();
1058 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1061 UShort_t *selectedIdx=new UShort_t[ntracks];
1063 for (Int_t itrack=0; itrack<ntracks; itrack++){
1064 const Double_t kMaxStep = 5; //max step over the material
1067 AliESDtrack *track = fesd->GetTrack(itrack);
1068 if (!track) continue;
1070 AliExternalTrackParam *tpcTrack =
1071 (AliExternalTrackParam *)track->GetTPCInnerParam();
1075 PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
1080 Int_t n=trkArray.GetEntriesFast();
1081 selectedIdx[n]=track->GetID();
1082 trkArray.AddLast(tpcTrack);
1085 if (track->GetX() < kRadius) continue;
1088 PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1090 track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kRadius);
1095 // Improve the reconstructed primary vertex position using the tracks
1097 TObject *obj = fOptions.FindObject("ITS");
1099 TString optITS = obj->GetTitle();
1100 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
1101 fRunVertexFinderTracks=kFALSE;
1103 if (fRunVertexFinderTracks) {
1104 // TPC + ITS primary vertex
1105 ftVertexer->SetITSrefitRequired();
1106 if(fDiamondProfile && fMeanVertexConstraint) {
1107 ftVertexer->SetVtxStart(fDiamondProfile);
1109 ftVertexer->SetConstraintOff();
1111 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
1113 if (pvtx->GetStatus()) {
1114 fesd->SetPrimaryVertex(pvtx);
1115 for (Int_t i=0; i<ntracks; i++) {
1116 AliESDtrack *t = fesd->GetTrack(i);
1117 t->RelateToVertex(pvtx, kBz, kRadius);
1122 // TPC-only primary vertex
1123 ftVertexer->SetITSrefitNotRequired();
1124 if(fDiamondProfileTPC && fMeanVertexConstraint) {
1125 ftVertexer->SetVtxStart(fDiamondProfileTPC);
1127 ftVertexer->SetConstraintOff();
1129 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
1131 if (pvtx->GetStatus()) {
1132 fesd->SetPrimaryVertexTPC(pvtx);
1133 Int_t nsel=trkArray.GetEntriesFast();
1134 for (Int_t i=0; i<nsel; i++) {
1135 AliExternalTrackParam *t =
1136 (AliExternalTrackParam *)trkArray.UncheckedAt(i);
1137 t->PropagateToDCA(pvtx, kBz, kRadius);
1143 delete[] selectedIdx;
1145 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
1150 AliV0vertexer vtxer;
1151 vtxer.Tracks2V0vertices(fesd);
1153 if (fRunCascadeFinder) {
1155 AliCascadeVertexer cvtxer;
1156 cvtxer.V0sTracks2CascadeVertices(fesd);
1161 if (fCleanESD) CleanESD(fesd);
1165 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1166 if (qadm) qadm->Exec(AliQA::kESDS, fesd);
1170 if (fWriteESDfriend) {
1171 fesdf->~AliESDfriend();
1172 new (fesdf) AliESDfriend(); // Reset...
1173 fesd->GetESDfriend(fesdf);
1180 if (fCheckPointLevel > 0) WriteESD(fesd, "final");
1183 if (fWriteESDfriend) {
1184 fesdf->~AliESDfriend();
1185 new (fesdf) AliESDfriend(); // Reset...
1188 ProcInfo_t ProcInfo;
1189 gSystem->GetProcInfo(&ProcInfo);
1190 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
1193 // End of cycle for the in-loop QA
1196 RunQA(fFillESD.Data(), fesd);
1197 TString detStr(fFillESD);
1198 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1199 if (!IsSelected(fgkDetectorName[iDet], detStr))
1201 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
1204 qadm->EndOfCycle(AliQA::kRECPOINTS);
1205 qadm->EndOfCycle(AliQA::kESDS);
1210 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1212 qadm->EndOfCycle(AliQA::kRECPOINTS);
1213 qadm->EndOfCycle(AliQA::kESDS);
1222 //_____________________________________________________________________________
1223 Bool_t AliReconstruction::AddEventAndRun()
1225 // for online usage only
1226 // Add an event to the run-loader
1228 // re-creates AliRawReaderDate for this new event
1229 AliCodeTimerAuto("");
1232 AliError("No raw-data event in memory given as an input! Do nothing!");
1236 // New raw-reader. Could be redone in a better way... To do
1237 fRawReader->~AliRawReader();
1238 new (fRawReader) AliRawReaderDate((void*)(*fpEvent));
1239 if (!fRawReader->NextEvent()) return kFALSE;
1241 // Expand the number of events in the run-loader
1243 Int_t nEvents = fRunLoader->GetNumberOfEvents();
1245 return RunEvent(nEvents);
1248 //_____________________________________________________________________________
1249 Bool_t AliReconstruction::FinishRun()
1252 // Called after the exit
1253 // from the event loop
1254 AliCodeTimerAuto("");
1256 if (fIsNewRunLoader) { // galice.root didn't exist
1257 fRunLoader->WriteHeader("OVERWRITE");
1258 fRunLoader->CdGAFile();
1259 fRunLoader->Write(0, TObject::kOverwrite);
1262 ftree->GetUserInfo()->Add(fesd);
1263 fhlttree->GetUserInfo()->Add(fhltesd);
1265 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1266 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1268 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1269 cdbMapCopy->SetOwner(1);
1270 cdbMapCopy->SetName("cdbMap");
1271 TIter iter(cdbMap->GetTable());
1274 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1275 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1276 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1277 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1280 TList *cdbListCopy = new TList();
1281 cdbListCopy->SetOwner(1);
1282 cdbListCopy->SetName("cdbList");
1284 TIter iter2(cdbList);
1287 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
1288 cdbListCopy->Add(new TObjString(id->ToString().Data()));
1291 ftree->GetUserInfo()->Add(cdbMapCopy);
1292 ftree->GetUserInfo()->Add(cdbListCopy);
1295 if(fESDPar.Contains("ESD.par")){
1296 AliInfo("Attaching ESD.par to Tree");
1297 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
1298 ftree->GetUserInfo()->Add(fn);
1304 if (fWriteESDfriend)
1305 ftree->SetBranchStatus("ESDfriend*",0);
1306 // we want to have only one tree version number
1307 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1310 // Finish with Plane Efficiency evaluation: before of CleanUp !!!
1311 if (fRunPlaneEff && !FinishPlaneEff()) {
1312 AliWarning("Finish PlaneEff evaluation failed");
1316 CleanUp(ffile, ffileOld);
1319 AliWarning("AOD creation not supported anymore during reconstruction. See ANALYSIS/AliAnalysisTaskESDfilter.cxx instead.");
1322 // Create tags for the events in the ESD tree (the ESD tree is always present)
1323 // In case of empty events the tags will contain dummy values
1324 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
1325 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPList);
1327 AliWarning("AOD tag creation not supported anymore during reconstruction.");
1330 //Finish QA and end of cycle for out-of-loop QA
1333 AliQADataMakerSteer qas;
1334 qas.Run(fRunLocalReconstruction.Data(), AliQA::kRECPOINTS, fSameQACycle);
1336 qas.Run(fRunTracking.Data(), AliQA::kESDS, fSameQACycle);
1338 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1340 qadm->EndOfCycle(AliQA::kRECPOINTS);
1341 qadm->EndOfCycle(AliQA::kESDS);
1348 // Cleanup of CDB manager: cache and active storages!
1349 AliCDBManager::Instance()->ClearCache();
1355 //_____________________________________________________________________________
1356 Bool_t AliReconstruction::RunLocalReconstruction(const TString& /*detectors*/)
1358 // run the local reconstruction
1359 static Int_t eventNr=0;
1360 AliCodeTimerAuto("")
1362 // AliCDBManager* man = AliCDBManager::Instance();
1363 // Bool_t origCache = man->GetCacheFlag();
1365 // TString detStr = detectors;
1366 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1367 // if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1368 // AliReconstructor* reconstructor = GetReconstructor(iDet);
1369 // if (!reconstructor) continue;
1370 // if (reconstructor->HasLocalReconstruction()) continue;
1372 // AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1373 // AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1375 // AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1376 // AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1378 // man->SetCacheFlag(kTRUE);
1379 // TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
1380 // man->GetAll(calibPath); // entries are cached!
1382 // AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1384 // if (fRawReader) {
1385 // fRawReader->RewindEvents();
1386 // reconstructor->Reconstruct(fRunLoader, fRawReader);
1388 // reconstructor->Reconstruct(fRunLoader);
1391 // AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1392 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
1394 // // unload calibration data
1395 // man->UnloadFromCache(calibPath);
1396 // //man->ClearCache();
1399 // man->SetCacheFlag(origCache);
1401 // if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1402 // AliError(Form("the following detectors were not found: %s",
1404 // if (fStopOnError) return kFALSE;
1411 //_____________________________________________________________________________
1412 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1414 // run the local reconstruction
1416 static Int_t eventNr=0;
1417 AliCodeTimerAuto("")
1419 TString detStr = detectors;
1420 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1421 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1422 AliReconstructor* reconstructor = GetReconstructor(iDet);
1423 if (!reconstructor) continue;
1424 AliLoader* loader = fLoader[iDet];
1426 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1429 // conversion of digits
1430 if (fRawReader && reconstructor->HasDigitConversion()) {
1431 AliInfo(Form("converting raw data digits into root objects for %s",
1432 fgkDetectorName[iDet]));
1433 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1434 fgkDetectorName[iDet]));
1435 loader->LoadDigits("update");
1436 loader->CleanDigits();
1437 loader->MakeDigitsContainer();
1438 TTree* digitsTree = loader->TreeD();
1439 reconstructor->ConvertDigits(fRawReader, digitsTree);
1440 loader->WriteDigits("OVERWRITE");
1441 loader->UnloadDigits();
1443 // local reconstruction
1444 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1445 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1446 loader->LoadRecPoints("update");
1447 loader->CleanRecPoints();
1448 loader->MakeRecPointsContainer();
1449 TTree* clustersTree = loader->TreeR();
1450 if (fRawReader && !reconstructor->HasDigitConversion()) {
1451 reconstructor->Reconstruct(fRawReader, clustersTree);
1453 loader->LoadDigits("read");
1454 TTree* digitsTree = loader->TreeD();
1456 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1457 if (fStopOnError) return kFALSE;
1459 reconstructor->Reconstruct(digitsTree, clustersTree);
1461 loader->UnloadDigits();
1464 // In-loop QA for local reconstrucion
1465 if (fRunQA && fInLoopQA) {
1466 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
1469 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1471 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1473 qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
1476 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1480 loader->WriteRecPoints("OVERWRITE");
1481 loader->UnloadRecPoints();
1482 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
1485 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1486 AliError(Form("the following detectors were not found: %s",
1488 if (fStopOnError) return kFALSE;
1494 //_____________________________________________________________________________
1495 Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
1497 // run the barrel tracking
1499 AliCodeTimerAuto("")
1501 AliESDVertex* vertex = NULL;
1502 Double_t vtxPos[3] = {0, 0, 0};
1503 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1504 TArrayF mcVertex(3);
1505 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1506 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1507 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1511 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1512 AliInfo("running the ITS vertex finder");
1513 if (fLoader[0]) fLoader[0]->LoadRecPoints();
1514 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
1515 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
1517 AliWarning("Vertex not found");
1518 vertex = new AliESDVertex();
1519 vertex->SetName("default");
1522 vertex->SetName("reconstructed");
1526 AliInfo("getting the primary vertex from MC");
1527 vertex = new AliESDVertex(vtxPos, vtxErr);
1531 vertex->GetXYZ(vtxPos);
1532 vertex->GetSigmaXYZ(vtxErr);
1534 AliWarning("no vertex reconstructed");
1535 vertex = new AliESDVertex(vtxPos, vtxErr);
1537 esd->SetPrimaryVertexSPD(vertex);
1538 // if SPD multiplicity has been determined, it is stored in the ESD
1539 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1540 if(mult)esd->SetMultiplicity(mult);
1542 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1543 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1550 //_____________________________________________________________________________
1551 Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1553 // run the HLT barrel tracking
1555 AliCodeTimerAuto("")
1558 AliError("Missing runLoader!");
1562 AliInfo("running HLT tracking");
1564 // Get a pointer to the HLT reconstructor
1565 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1566 if (!reconstructor) return kFALSE;
1569 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1570 TString detName = fgkDetectorName[iDet];
1571 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1572 reconstructor->SetOption(detName.Data());
1573 AliTracker *tracker = reconstructor->CreateTracker();
1575 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1576 if (fStopOnError) return kFALSE;
1580 Double_t vtxErr[3]={0.005,0.005,0.010};
1581 const AliESDVertex *vertex = esd->GetVertex();
1582 vertex->GetXYZ(vtxPos);
1583 tracker->SetVertex(vtxPos,vtxErr);
1585 fLoader[iDet]->LoadRecPoints("read");
1586 TTree* tree = fLoader[iDet]->TreeR();
1588 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1591 tracker->LoadClusters(tree);
1593 if (tracker->Clusters2Tracks(esd) != 0) {
1594 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1598 tracker->UnloadClusters();
1606 //_____________________________________________________________________________
1607 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
1609 // run the muon spectrometer tracking
1611 AliCodeTimerAuto("")
1614 AliError("Missing runLoader!");
1617 Int_t iDet = 7; // for MUON
1619 AliInfo("is running...");
1621 // Get a pointer to the MUON reconstructor
1622 AliReconstructor *reconstructor = GetReconstructor(iDet);
1623 if (!reconstructor) return kFALSE;
1626 TString detName = fgkDetectorName[iDet];
1627 AliDebug(1, Form("%s tracking", detName.Data()));
1628 AliTracker *tracker = reconstructor->CreateTracker();
1630 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1635 fLoader[iDet]->LoadRecPoints("read");
1637 tracker->LoadClusters(fLoader[iDet]->TreeR());
1639 Int_t rv = tracker->Clusters2Tracks(esd);
1643 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1647 fLoader[iDet]->UnloadRecPoints();
1649 tracker->UnloadClusters();
1657 //_____________________________________________________________________________
1658 Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
1660 // run the barrel tracking
1661 static Int_t eventNr=0;
1662 AliCodeTimerAuto("")
1664 AliInfo("running tracking");
1666 //Fill the ESD with the T0 info (will be used by the TOF)
1667 if (fReconstructor[11] && fLoader[11]) {
1668 fLoader[11]->LoadRecPoints("READ");
1669 TTree *treeR = fLoader[11]->TreeR();
1670 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1673 // pass 1: TPC + ITS inwards
1674 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1675 if (!fTracker[iDet]) continue;
1676 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1679 fLoader[iDet]->LoadRecPoints("read");
1680 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
1681 TTree* tree = fLoader[iDet]->TreeR();
1683 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1686 fTracker[iDet]->LoadClusters(tree);
1687 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1689 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1690 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1693 if (fCheckPointLevel > 1) {
1694 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1696 // preliminary PID in TPC needed by the ITS tracker
1698 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1699 AliESDpid::MakePID(esd);
1701 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
1704 // pass 2: ALL backwards
1706 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1707 if (!fTracker[iDet]) continue;
1708 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1711 if (iDet > 1) { // all except ITS, TPC
1713 fLoader[iDet]->LoadRecPoints("read");
1714 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
1715 tree = fLoader[iDet]->TreeR();
1717 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1720 fTracker[iDet]->LoadClusters(tree);
1721 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1725 if (iDet>1) // start filling residuals for the "outer" detectors
1726 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1728 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1729 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1732 if (fCheckPointLevel > 1) {
1733 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1737 if (iDet > 2) { // all except ITS, TPC, TRD
1738 fTracker[iDet]->UnloadClusters();
1739 fLoader[iDet]->UnloadRecPoints();
1741 // updated PID in TPC needed by the ITS tracker -MI
1743 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1744 AliESDpid::MakePID(esd);
1746 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1748 //stop filling residuals for the "outer" detectors
1749 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
1751 // write space-points to the ESD in case alignment data output
1753 if (fWriteAlignmentData)
1754 WriteAlignmentData(esd);
1756 // pass 3: TRD + TPC + ITS refit inwards
1758 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1759 if (!fTracker[iDet]) continue;
1760 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1763 if (iDet<2) // start filling residuals for TPC and ITS
1764 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1766 if (fTracker[iDet]->RefitInward(esd) != 0) {
1767 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1770 // run postprocessing
1771 if (fTracker[iDet]->PostProcess(esd) != 0) {
1772 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
1775 if (fCheckPointLevel > 1) {
1776 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1778 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1780 fTracker[iDet]->UnloadClusters();
1781 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
1782 fLoader[iDet]->UnloadRecPoints();
1783 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
1785 // stop filling residuals for TPC and ITS
1786 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
1792 //_____________________________________________________________________________
1793 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1795 // Remove the data which are not needed for the physics analysis.
1798 Int_t nTracks=esd->GetNumberOfTracks();
1799 Int_t nV0s=esd->GetNumberOfV0s();
1801 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
1803 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
1804 Bool_t rc=esd->Clean(cleanPars);
1806 nTracks=esd->GetNumberOfTracks();
1807 nV0s=esd->GetNumberOfV0s();
1809 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
1814 //_____________________________________________________________________________
1815 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
1817 // fill the event summary data
1819 AliCodeTimerAuto("")
1820 static Int_t eventNr=0;
1821 TString detStr = detectors;
1823 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1824 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1825 AliReconstructor* reconstructor = GetReconstructor(iDet);
1826 if (!reconstructor) continue;
1827 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1828 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1829 TTree* clustersTree = NULL;
1830 if (fLoader[iDet]) {
1831 fLoader[iDet]->LoadRecPoints("read");
1832 clustersTree = fLoader[iDet]->TreeR();
1833 if (!clustersTree) {
1834 AliError(Form("Can't get the %s clusters tree",
1835 fgkDetectorName[iDet]));
1836 if (fStopOnError) return kFALSE;
1839 if (fRawReader && !reconstructor->HasDigitConversion()) {
1840 reconstructor->FillESD(fRawReader, clustersTree, esd);
1842 TTree* digitsTree = NULL;
1843 if (fLoader[iDet]) {
1844 fLoader[iDet]->LoadDigits("read");
1845 digitsTree = fLoader[iDet]->TreeD();
1847 AliError(Form("Can't get the %s digits tree",
1848 fgkDetectorName[iDet]));
1849 if (fStopOnError) return kFALSE;
1852 reconstructor->FillESD(digitsTree, clustersTree, esd);
1853 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1855 if (fLoader[iDet]) {
1856 fLoader[iDet]->UnloadRecPoints();
1859 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1863 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1864 AliError(Form("the following detectors were not found: %s",
1866 if (fStopOnError) return kFALSE;
1868 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
1873 //_____________________________________________________________________________
1874 Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
1876 // Reads the trigger decision which is
1877 // stored in Trigger.root file and fills
1878 // the corresponding esd entries
1880 AliCodeTimerAuto("")
1882 AliInfo("Filling trigger information into the ESD");
1884 AliCentralTrigger *aCTP = NULL;
1887 AliCTPRawStream input(fRawReader);
1888 if (!input.Next()) {
1889 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1892 esd->SetTriggerMask(input.GetClassMask());
1893 esd->SetTriggerCluster(input.GetClusterMask());
1895 aCTP = new AliCentralTrigger();
1896 TString configstr("");
1897 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
1898 AliError("No trigger configuration found in OCDB! The trigger classes information will no be stored in ESD!");
1904 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1906 if (!runloader->LoadTrigger()) {
1907 aCTP = runloader->GetTrigger();
1908 esd->SetTriggerMask(aCTP->GetClassMask());
1909 esd->SetTriggerCluster(aCTP->GetClusterMask());
1912 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1917 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1922 // Now fill the trigger class names into AliESDRun object
1923 AliTriggerConfiguration *config = aCTP->GetConfiguration();
1925 AliError("No trigger configuration has been found! The trigger classes information will no be stored in ESD!");
1926 if (fRawReader) delete aCTP;
1930 const TObjArray& classesArray = config->GetClasses();
1931 Int_t nclasses = classesArray.GetEntriesFast();
1932 for( Int_t j=0; j<nclasses; j++ ) {
1933 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
1934 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
1935 esd->SetTriggerClass(trclass->GetName(),trindex);
1938 if (fRawReader) delete aCTP;
1946 //_____________________________________________________________________________
1947 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
1950 // Filling information from RawReader Header
1953 AliInfo("Filling information from RawReader Header");
1954 esd->SetBunchCrossNumber(0);
1955 esd->SetOrbitNumber(0);
1956 esd->SetPeriodNumber(0);
1957 esd->SetTimeStamp(0);
1958 esd->SetEventType(0);
1959 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1962 const UInt_t *id = eventHeader->GetP("Id");
1963 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1964 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1965 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1967 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1968 esd->SetEventType((eventHeader->Get("Type")));
1975 //_____________________________________________________________________________
1976 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1978 // check whether detName is contained in detectors
1979 // if yes, it is removed from detectors
1981 // check if all detectors are selected
1982 if ((detectors.CompareTo("ALL") == 0) ||
1983 detectors.BeginsWith("ALL ") ||
1984 detectors.EndsWith(" ALL") ||
1985 detectors.Contains(" ALL ")) {
1990 // search for the given detector
1991 Bool_t result = kFALSE;
1992 if ((detectors.CompareTo(detName) == 0) ||
1993 detectors.BeginsWith(detName+" ") ||
1994 detectors.EndsWith(" "+detName) ||
1995 detectors.Contains(" "+detName+" ")) {
1996 detectors.ReplaceAll(detName, "");
2000 // clean up the detectors string
2001 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2002 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2003 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2008 //_____________________________________________________________________________
2009 Bool_t AliReconstruction::InitRunLoader()
2011 // get or create the run loader
2013 if (gAlice) delete gAlice;
2016 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2017 // load all base libraries to get the loader classes
2018 TString libs = gSystem->GetLibraries();
2019 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2020 TString detName = fgkDetectorName[iDet];
2021 if (detName == "HLT") continue;
2022 if (libs.Contains("lib" + detName + "base.so")) continue;
2023 gSystem->Load("lib" + detName + "base.so");
2025 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2027 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2031 fRunLoader->CdGAFile();
2032 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
2033 if (fRunLoader->LoadgAlice() == 0) {
2034 gAlice = fRunLoader->GetAliRun();
2035 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
2038 if (!gAlice && !fRawReader) {
2039 AliError(Form("no gAlice object found in file %s",
2040 fGAliceFileName.Data()));
2045 //PH This is a temporary fix to give access to the kinematics
2046 //PH that is needed for the labels of ITS clusters
2047 fRunLoader->LoadHeader();
2048 fRunLoader->LoadKinematics();
2050 } else { // galice.root does not exist
2052 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
2056 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2057 AliConfig::GetDefaultEventFolderName(),
2060 AliError(Form("could not create run loader in file %s",
2061 fGAliceFileName.Data()));
2065 fIsNewRunLoader = kTRUE;
2066 fRunLoader->MakeTree("E");
2068 if (fNumberOfEventsPerFile > 0)
2069 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2071 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
2077 //_____________________________________________________________________________
2078 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
2080 // get the reconstructor object and the loader for a detector
2082 if (fReconstructor[iDet]) return fReconstructor[iDet];
2084 // load the reconstructor object
2085 TPluginManager* pluginManager = gROOT->GetPluginManager();
2086 TString detName = fgkDetectorName[iDet];
2087 TString recName = "Ali" + detName + "Reconstructor";
2088 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
2090 AliReconstructor* reconstructor = NULL;
2091 // first check if a plugin is defined for the reconstructor
2092 TPluginHandler* pluginHandler =
2093 pluginManager->FindHandler("AliReconstructor", detName);
2094 // if not, add a plugin for it
2095 if (!pluginHandler) {
2096 AliDebug(1, Form("defining plugin for %s", recName.Data()));
2097 TString libs = gSystem->GetLibraries();
2098 if (libs.Contains("lib" + detName + "base.so") ||
2099 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2100 pluginManager->AddHandler("AliReconstructor", detName,
2101 recName, detName + "rec", recName + "()");
2103 pluginManager->AddHandler("AliReconstructor", detName,
2104 recName, detName, recName + "()");
2106 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2108 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2109 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
2111 if (reconstructor) {
2112 TObject* obj = fOptions.FindObject(detName.Data());
2113 if (obj) reconstructor->SetOption(obj->GetTitle());
2114 reconstructor->Init();
2115 fReconstructor[iDet] = reconstructor;
2118 // get or create the loader
2119 if (detName != "HLT") {
2120 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2121 if (!fLoader[iDet]) {
2122 AliConfig::Instance()
2123 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2125 // first check if a plugin is defined for the loader
2127 pluginManager->FindHandler("AliLoader", detName);
2128 // if not, add a plugin for it
2129 if (!pluginHandler) {
2130 TString loaderName = "Ali" + detName + "Loader";
2131 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2132 pluginManager->AddHandler("AliLoader", detName,
2133 loaderName, detName + "base",
2134 loaderName + "(const char*, TFolder*)");
2135 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2137 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2139 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2140 fRunLoader->GetEventFolder());
2142 if (!fLoader[iDet]) { // use default loader
2143 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2145 if (!fLoader[iDet]) {
2146 AliWarning(Form("couldn't get loader for %s", detName.Data()));
2147 if (fStopOnError) return NULL;
2149 fRunLoader->AddLoader(fLoader[iDet]);
2150 fRunLoader->CdGAFile();
2151 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2152 fRunLoader->Write(0, TObject::kOverwrite);
2157 return reconstructor;
2160 //_____________________________________________________________________________
2161 Bool_t AliReconstruction::CreateVertexer()
2163 // create the vertexer
2166 AliReconstructor* itsReconstructor = GetReconstructor(0);
2167 if (itsReconstructor) {
2168 fVertexer = itsReconstructor->CreateVertexer();
2171 AliWarning("couldn't create a vertexer for ITS");
2172 if (fStopOnError) return kFALSE;
2178 //_____________________________________________________________________________
2179 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
2181 // create the trackers
2183 TString detStr = detectors;
2184 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2185 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2186 AliReconstructor* reconstructor = GetReconstructor(iDet);
2187 if (!reconstructor) continue;
2188 TString detName = fgkDetectorName[iDet];
2189 if (detName == "HLT") {
2190 fRunHLTTracking = kTRUE;
2193 if (detName == "MUON") {
2194 fRunMuonTracking = kTRUE;
2199 fTracker[iDet] = reconstructor->CreateTracker();
2200 if (!fTracker[iDet] && (iDet < 7)) {
2201 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
2202 if (fStopOnError) return kFALSE;
2204 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
2210 //_____________________________________________________________________________
2211 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
2213 // delete trackers and the run loader and close and delete the file
2215 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2216 delete fReconstructor[iDet];
2217 fReconstructor[iDet] = NULL;
2218 fLoader[iDet] = NULL;
2219 delete fTracker[iDet];
2220 fTracker[iDet] = NULL;
2221 // delete fQADataMaker[iDet];
2222 // fQADataMaker[iDet] = NULL;
2227 if (ftVertexer) delete ftVertexer;
2230 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
2231 delete fDiamondProfile;
2232 fDiamondProfile = NULL;
2233 delete fDiamondProfileTPC;
2234 fDiamondProfileTPC = NULL;
2244 if (fParentRawReader) delete fParentRawReader;
2245 fParentRawReader=NULL;
2255 gSystem->Unlink("AliESDs.old.root");
2260 //_____________________________________________________________________________
2262 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
2264 // read the ESD event from a file
2266 if (!esd) return kFALSE;
2268 sprintf(fileName, "ESD_%d.%d_%s.root",
2269 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
2270 if (gSystem->AccessPathName(fileName)) return kFALSE;
2272 AliInfo(Form("reading ESD from file %s", fileName));
2273 AliDebug(1, Form("reading ESD from file %s", fileName));
2274 TFile* file = TFile::Open(fileName);
2275 if (!file || !file->IsOpen()) {
2276 AliError(Form("opening %s failed", fileName));
2283 esd = (AliESDEvent*) file->Get("ESD");
2292 //_____________________________________________________________________________
2293 void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
2295 // write the ESD event to a file
2299 sprintf(fileName, "ESD_%d.%d_%s.root",
2300 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
2302 AliDebug(1, Form("writing ESD to file %s", fileName));
2303 TFile* file = TFile::Open(fileName, "recreate");
2304 if (!file || !file->IsOpen()) {
2305 AliError(Form("opening %s failed", fileName));
2314 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
2316 // Write space-points which are then used in the alignment procedures
2317 // For the moment only ITS, TRD and TPC
2319 // Load TOF clusters
2321 fLoader[3]->LoadRecPoints("read");
2322 TTree* tree = fLoader[3]->TreeR();
2324 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2327 fTracker[3]->LoadClusters(tree);
2329 Int_t ntracks = esd->GetNumberOfTracks();
2330 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2332 AliESDtrack *track = esd->GetTrack(itrack);
2335 for (Int_t iDet = 3; iDet >= 0; iDet--)
2336 nsp += track->GetNcls(iDet);
2338 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2339 track->SetTrackPointArray(sp);
2341 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2342 AliTracker *tracker = fTracker[iDet];
2343 if (!tracker) continue;
2344 Int_t nspdet = track->GetNcls(iDet);
2345 if (nspdet <= 0) continue;
2346 track->GetClusters(iDet,idx);
2350 while (isp2 < nspdet) {
2352 TString dets = fgkDetectorName[iDet];
2353 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2354 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2355 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2356 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
2357 isvalid = tracker->GetTrackPointTrackingError(idx[isp2],p,track);
2359 isvalid = tracker->GetTrackPoint(idx[isp2],p);
2362 const Int_t kNTPCmax = 159;
2363 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2364 if (!isvalid) continue;
2365 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2371 fTracker[3]->UnloadClusters();
2372 fLoader[3]->UnloadRecPoints();
2376 //_____________________________________________________________________________
2377 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2379 // The method reads the raw-data error log
2380 // accumulated within the rawReader.
2381 // It extracts the raw-data errors related to
2382 // the current event and stores them into
2383 // a TClonesArray inside the esd object.
2385 if (!fRawReader) return;
2387 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2389 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2391 if (iEvent != log->GetEventNumber()) continue;
2393 esd->AddRawDataErrorLog(log);
2398 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
2399 // Dump a file content into a char in TNamed
2401 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2402 Int_t kBytes = (Int_t)in.tellg();
2403 printf("Size: %d \n",kBytes);
2406 char* memblock = new char [kBytes];
2407 in.seekg (0, ios::beg);
2408 in.read (memblock, kBytes);
2410 TString fData(memblock,kBytes);
2411 fn = new TNamed(fName,fData);
2412 printf("fData Size: %d \n",fData.Sizeof());
2413 printf("fName Size: %d \n",fName.Sizeof());
2414 printf("fn Size: %d \n",fn->Sizeof());
2418 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2424 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
2425 // This is not really needed in AliReconstruction at the moment
2426 // but can serve as a template
2428 TList *fList = fTree->GetUserInfo();
2429 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2430 printf("fn Size: %d \n",fn->Sizeof());
2432 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2433 const char* cdata = fn->GetTitle();
2434 printf("fTmp Size %d\n",fTmp.Sizeof());
2436 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2437 printf("calculated size %d\n",size);
2438 ofstream out(fName.Data(),ios::out | ios::binary);
2439 out.write(cdata,size);
2444 //_____________________________________________________________________________
2445 AliQADataMakerRec * AliReconstruction::GetQADataMaker(Int_t iDet)
2447 // get the quality assurance data maker object and the loader for a detector
2449 if (fQADataMaker[iDet])
2450 return fQADataMaker[iDet];
2452 AliQADataMakerRec * qadm = NULL;
2453 if (iDet == fgkNDetectors) { //Global QA
2454 qadm = new AliGlobalQADataMaker();
2455 fQADataMaker[iDet] = qadm;
2459 // load the QA data maker object
2460 TPluginManager* pluginManager = gROOT->GetPluginManager();
2461 TString detName = fgkDetectorName[iDet];
2462 TString qadmName = "Ali" + detName + "QADataMakerRec";
2463 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT"))
2466 // first check if a plugin is defined for the quality assurance data maker
2467 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
2468 // if not, add a plugin for it
2469 if (!pluginHandler) {
2470 AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
2471 TString libs = gSystem->GetLibraries();
2472 if (libs.Contains("lib" + detName + "base.so") ||
2473 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2474 pluginManager->AddHandler("AliQADataMakerRec", detName,
2475 qadmName, detName + "qadm", qadmName + "()");
2477 pluginManager->AddHandler("AliQADataMakerRec", detName,
2478 qadmName, detName, qadmName + "()");
2480 pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
2482 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2483 qadm = (AliQADataMakerRec *) pluginHandler->ExecPlugin(0);
2486 fQADataMaker[iDet] = qadm;
2491 //_____________________________________________________________________________
2492 Bool_t AliReconstruction::RunQA(const char* detectors, AliESDEvent *& esd)
2494 // run the Quality Assurance data producer
2496 AliCodeTimerAuto("")
2497 TString detStr = detectors;
2498 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2499 if (!IsSelected(fgkDetectorName[iDet], detStr))
2501 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
2504 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2505 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2507 qadm->Exec(AliQA::kESDS, esd) ;
2510 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2512 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2513 AliError(Form("the following detectors were not found: %s",
2523 //_____________________________________________________________________________
2524 void AliReconstruction::CheckQA()
2526 // check the QA of SIM for this run and remove the detectors
2527 // with status Fatal
2529 TString newRunLocalReconstruction ;
2530 TString newRunTracking ;
2531 TString newFillESD ;
2533 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2534 TString detName(AliQA::GetDetName(iDet)) ;
2535 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2536 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
2537 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
2539 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2540 fRunLocalReconstruction.Contains("ALL") ) {
2541 newRunLocalReconstruction += detName ;
2542 newRunLocalReconstruction += " " ;
2544 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2545 fRunTracking.Contains("ALL") ) {
2546 newRunTracking += detName ;
2547 newRunTracking += " " ;
2549 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2550 fFillESD.Contains("ALL") ) {
2551 newFillESD += detName ;
2556 fRunLocalReconstruction = newRunLocalReconstruction ;
2557 fRunTracking = newRunTracking ;
2558 fFillESD = newFillESD ;
2561 //_____________________________________________________________________________
2562 Int_t AliReconstruction::GetDetIndex(const char* detector)
2564 // return the detector index corresponding to detector
2566 for (index = 0; index < fgkNDetectors ; index++) {
2567 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2572 //_____________________________________________________________________________
2573 Bool_t AliReconstruction::FinishPlaneEff() {
2575 // Here execute all the necessary operationis, at the end of the tracking phase,
2576 // in case that evaluation of PlaneEfficiencies was required for some detector.
2577 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
2579 // This Preliminary version works only FOR ITS !!!!!
2580 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2583 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2586 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2587 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
2588 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2589 if(fTracker[iDet]) {
2590 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2591 ret=planeeff->WriteIntoCDB();
2592 if(planeeff->GetCreateHistos()) {
2593 TString name="PlaneEffHisto";
2594 name+=fgkDetectorName[iDet];
2596 ret*=planeeff->WriteHistosToFile(name,"RECREATE");
2602 //_____________________________________________________________________________
2603 Bool_t AliReconstruction::InitPlaneEff() {
2605 // Here execute all the necessary operations, before of the tracking phase,
2606 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2607 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2608 // which should be updated/recalculated.
2610 // This Preliminary version will work only FOR ITS !!!!!
2611 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2614 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2616 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));