]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
- Renaming fEventNumber (and the associated getters/setters) to
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index efe91bf16b6938534678a080803e9337a851b041..1c03396d3c38e4a63dde28e408170e19b6f9b3b4 100644 (file)
 // The index -1 (default) can be used for the last event to indicate no      //
 // upper limit of the event range.                                           //
 //                                                                           //
+// In case of raw-data reconstruction the user can modify the default        //
+// number of events per digits/clusters/tracks file. In case the option      //
+// is not used the number is set 1. In case the user provides 0, than        //
+// the number of events is equal to the number of events inside the          //
+// raw-data file (i.e. one digits/clusters/tracks file):                     //
+//                                                                           //
+//   rec.SetNumberOfEventsPerFile(...);                                      //
+//                                                                           //
+//                                                                           //
 // The name of the galice file can be changed from the default               //
 // "galice.root" by passing it as argument to the AliReconstruction          //
 // constructor or by                                                         //
 #include "AliRawReaderFile.h"
 #include "AliRawReaderDate.h"
 #include "AliRawReaderRoot.h"
+#include "AliRawEventHeaderBase.h"
 #include "AliESD.h"
 #include "AliESDfriend.h"
 #include "AliESDVertex.h"
 #include "AliTracker.h"
 #include "AliVertexer.h"
 #include "AliVertexerTracks.h"
+#include "AliV0vertexer.h"
+#include "AliCascadeVertexer.h"
 #include "AliHeader.h"
 #include "AliGenEventHeader.h"
 #include "AliPID.h"
@@ -151,7 +163,7 @@ ClassImp(AliReconstruction)
 
 
 //_____________________________________________________________________________
-const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "RICH", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "START", "VZERO", "CRT", "HLT"};
+const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
 
 //_____________________________________________________________________________
 AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
@@ -164,6 +176,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdb
   fStopOnError(kFALSE),
   fWriteAlignmentData(kFALSE),
   fWriteESDfriend(kFALSE),
+  fWriteAOD(kFALSE),
   fFillTriggerESD(kTRUE),
 
   fRunLocalReconstruction("ALL"),
@@ -174,6 +187,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdb
   fEquipIdMap(""),
   fFirstEvent(0),
   fLastEvent(-1),
+  fNumberOfEventsPerFile(1),
   fCheckPointLevel(0),
   fOptions(),
   fLoadAlignFromCDB(kTRUE),
@@ -209,6 +223,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fStopOnError(rec.fStopOnError),
   fWriteAlignmentData(rec.fWriteAlignmentData),
   fWriteESDfriend(rec.fWriteESDfriend),
+  fWriteAOD(rec.fWriteAOD),
   fFillTriggerESD(rec.fFillTriggerESD),
 
   fRunLocalReconstruction(rec.fRunLocalReconstruction),
@@ -219,6 +234,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fEquipIdMap(rec.fEquipIdMap),
   fFirstEvent(rec.fFirstEvent),
   fLastEvent(rec.fLastEvent),
+  fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
   fCheckPointLevel(0),
   fOptions(),
   fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
@@ -286,9 +302,9 @@ void AliReconstruction::InitCDBStorage()
     fCDBUri = "";
   }
   else {
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    AliWarning(Form("Default CDB storage is set to: %s",fCDBUri.Data()));
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     man->SetDefaultStorage(fCDBUri);
   }
 
@@ -296,9 +312,9 @@ void AliReconstruction::InitCDBStorage()
   for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
     TObject* obj = fSpecCDBUri[i];
     if (!obj) continue;
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    AliWarning(Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
   }
   man->Print();
@@ -517,6 +533,7 @@ Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
     }
   }
 
+  delete fAlignObjArray; fAlignObjArray=0;
   return kTRUE;
 }
 
@@ -540,8 +557,7 @@ void AliReconstruction::SetOption(const char* detector, const char* option)
 
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::Run(const char* input,
-                             Int_t firstEvent, Int_t lastEvent)
+Bool_t AliReconstruction::Run(const char* input)
 {
 // run the reconstruction
 
@@ -576,6 +592,8 @@ Bool_t AliReconstruction::Run(const char* input,
     TGeoManager::Import(geom.Data());
     if (!gGeoManager) if (fStopOnError) return kFALSE;
   }
+
+  AliCDBManager* man = AliCDBManager::Instance();
   if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
 
   // local reconstruction
@@ -635,19 +653,13 @@ Bool_t AliReconstruction::Run(const char* input,
   delete esd; delete hltesd;
   esd = NULL; hltesd = NULL;
 
-  // create the file and tree with ESD additions
-  TFile *filef=0; TTree *treef=0; AliESDfriend *esdf=0;
+  // create the branch with ESD additions
+  AliESDfriend *esdf=0;
   if (fWriteESDfriend) {
-     filef = TFile::Open("AliESDfriends.root", "RECREATE");
-     if (!filef->IsOpen()) {
-        AliError("opening AliESDfriends.root failed");
-     }
-     treef = new TTree("esdFriendTree", "Tree with ESD friends");
-     treef->Branch("ESDfriend", "AliESDfriend", &esdf);
+     TBranch *br=tree->Branch("ESDfriend.", "AliESDfriend", &esdf);
+     br->SetFile("AliESDfriends.root");
   }
 
-  gROOT->cd();
-
   AliVertexerTracks tVertexer;
   if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
 
@@ -656,7 +668,7 @@ Bool_t AliReconstruction::Run(const char* input,
   
   for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
     if (fRawReader) fRawReader->NextEvent();
-    if ((iEvent < firstEvent) || ((lastEvent >= 0) && (iEvent > lastEvent))) {
+    if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
       // copy old ESD to the new one
       if (treeOld) {
        treeOld->SetBranchAddress("ESD", &esd);
@@ -674,11 +686,11 @@ Bool_t AliReconstruction::Run(const char* input,
     AliInfo(Form("processing event %d", iEvent));
     fRunLoader->GetEvent(iEvent);
 
-    char fileName[256];
-    sprintf(fileName, "ESD_%d.%d_final.root", 
+    char aFileName[256];
+    sprintf(aFileName, "ESD_%d.%d_final.root", 
            fRunLoader->GetHeader()->GetRun(), 
            fRunLoader->GetHeader()->GetEventNrInRun());
-    if (!gSystem->AccessPathName(fileName)) continue;
+    if (!gSystem->AccessPathName(aFileName)) continue;
 
     // local reconstruction
     if (!fRunLocalReconstruction.IsNull()) {
@@ -690,8 +702,8 @@ Bool_t AliReconstruction::Run(const char* input,
     esd = new AliESD; hltesd = new AliESD;
     esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
     hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
-    esd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
-    hltesd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
+    esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
+    hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
 
     // Set magnetic field from the tracker
     esd->SetMagneticField(AliTracker::GetBz());
@@ -733,6 +745,8 @@ Bool_t AliReconstruction::Run(const char* input,
        if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
       }
     }
+    // fill Event header information from the RawEventHeader
+    if (fRawReader){FillRawEventHeaderESD(esd);}
 
     // combined PID
     AliESDpid::MakePID(esd);
@@ -747,36 +761,59 @@ Bool_t AliReconstruction::Run(const char* input,
       }
     }
 
-    esd->SetPrimaryVertex(tVertexer.FindPrimaryVertex(esd));
+    //Try to improve the reconstructed primary vertex position using the tracks
+    AliESDVertex *pvtx=tVertexer.FindPrimaryVertex(esd);
+    if (pvtx)
+    if (pvtx->GetStatus()) {
+       // Store the improved primary vertex
+       esd->SetPrimaryVertex(pvtx);
+       // Propagate the tracks to the DCA to the improved primary vertex
+       Double_t somethingbig = 777.;
+       Double_t bz = esd->GetMagneticField();
+       Int_t nt=esd->GetNumberOfTracks();
+       while (nt--) {
+        AliESDtrack *t = esd->GetTrack(nt);
+         t->RelateToVertex(pvtx, bz, somethingbig);
+       } 
+    }
 
-    // write ESD
-    tree->Fill();
-    // write HLT ESD
-    hlttree->Fill();
+    {
+    // V0 finding
+    AliV0vertexer vtxer;
+    vtxer.Tracks2V0vertices(esd);
 
-    // write ESD friend
+    // Cascade finding
+    AliCascadeVertexer cvtxer;
+    cvtxer.V0sTracks2CascadeVertices(esd);
+    }
+    // write ESD
     if (fWriteESDfriend) {
        esdf=new AliESDfriend();
        esd->GetESDfriend(esdf);
-       treef->Fill();  
     }
+    tree->Fill();
+
+    // write HLT ESD
+    hlttree->Fill();
 
     if (fCheckPointLevel > 0)  WriteESD(esd, "final"); 
  
-    delete esd; delete hltesd;
-    esd = NULL; hltesd = NULL;
+    delete esd; delete esdf; delete hltesd;
+    esd = NULL; esdf=NULL; hltesd = NULL;
   }
 
   AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
               stopwatch.RealTime(),stopwatch.CpuTime()));
 
   file->cd();
+  if (fWriteESDfriend)
+    tree->SetBranchStatus("ESDfriend*",0);
   tree->Write();
   hlttree->Write();
 
-  if (fWriteESDfriend) {
-     filef->cd();
-     treef->Write(); delete treef; filef->Close(); delete filef; 
+  if (fWriteAOD) {
+    CreateAOD(file);
   }
 
   // Create tags for the events in the ESD tree (the ESD tree is always present)
@@ -796,6 +833,9 @@ Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
   TStopwatch stopwatch;
   stopwatch.Start();
 
+  AliCDBManager* man = AliCDBManager::Instance();
+  Bool_t origCache = man->GetCacheFlag();
+
   TString detStr = detectors;
   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
     if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
@@ -806,6 +846,13 @@ Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
     AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
     TStopwatch stopwatchDet;
     stopwatchDet.Start();
+
+    AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
+
+    man->SetCacheFlag(kTRUE);
+    TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
+    man->GetAll(calibPath); // entries are cached!
+
     if (fRawReader) {
       fRawReader->RewindEvents();
       reconstructor->Reconstruct(fRunLoader, fRawReader);
@@ -815,8 +862,13 @@ Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
     AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
                 fgkDetectorName[iDet],
                 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
+
+    // unload calibration data
+    man->ClearCache();
   }
 
+  man->SetCacheFlag(origCache);
+
   if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
     AliError(Form("the following detectors were not found: %s",
                   detStr.Data()));
@@ -1255,6 +1307,34 @@ Bool_t AliReconstruction::FillTriggerESD(AliESD*& esd)
   return kTRUE;
 }
 
+
+
+
+
+//_____________________________________________________________________________
+Bool_t AliReconstruction::FillRawEventHeaderESD(AliESD*& esd)
+{
+  // 
+  // Filling information from RawReader Header
+  // 
+
+  AliInfo("Filling information from RawReader Header");
+  esd->SetBunchCrossNumber(0);
+  esd->SetOrbitNumber(0);
+  esd->SetTimeStamp(0);
+  esd->SetEventType(0);
+  const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
+  if (eventHeader){
+    esd->SetBunchCrossNumber((eventHeader->GetP("Id")[0]));
+    esd->SetOrbitNumber((eventHeader->GetP("Id")[1]));
+    esd->SetTimeStamp((eventHeader->Get("Timestamp")));  
+    esd->SetEventType((eventHeader->Get("Type")));
+  }
+
+  return kTRUE;
+}
+
+
 //_____________________________________________________________________________
 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
 {
@@ -1351,6 +1431,10 @@ Bool_t AliReconstruction::InitRunLoader()
       iEvent++;
     }
     fRawReader->RewindEvents();
+    if (fNumberOfEventsPerFile > 0)
+      fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
+    else
+      fRunLoader->SetNumberOfEventsPerFile(iEvent);
     fRunLoader->WriteHeader("OVERWRITE");
     fRunLoader->CdGAFile();
     fRunLoader->Write(0, TObject::kOverwrite);
@@ -1375,10 +1459,10 @@ AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
 
   if (detName == "HLT") {
     if (!gROOT->GetClass("AliLevel3")) {
-      gSystem->Load("libAliL3Src.so");
-      gSystem->Load("libAliL3Misc.so");
-      gSystem->Load("libAliL3Hough.so");
-      gSystem->Load("libAliL3Comp.so");
+      gSystem->Load("libAliHLTSrc.so");
+      gSystem->Load("libAliHLTMisc.so");
+      gSystem->Load("libAliHLTHough.so");
+      gSystem->Load("libAliHLTComp.so");
     }
   }
 
@@ -1418,7 +1502,7 @@ AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
        ->CreateDetectorFolders(fRunLoader->GetEventFolder(), 
                                detName, detName);
       // first check if a plugin is defined for the loader
-      TPluginHandler* pluginHandler = 
+      pluginHandler = 
        pluginManager->FindHandler("AliLoader", detName);
       // if not, add a plugin for it
       if (!pluginHandler) {
@@ -1539,7 +1623,7 @@ Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
   if (!esd) return kFALSE;
   char fileName[256];
   sprintf(fileName, "ESD_%d.%d_%s.root", 
-         esd->GetRunNumber(), esd->GetEventNumber(), recStep);
+         esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
   if (gSystem->AccessPathName(fileName)) return kFALSE;
 
   AliInfo(Form("reading ESD from file %s", fileName));
@@ -1567,7 +1651,7 @@ void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
   if (!esd) return;
   char fileName[256];
   sprintf(fileName, "ESD_%d.%d_%s.root", 
-         esd->GetRunNumber(), esd->GetEventNumber(), recStep);
+         esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
 
   AliDebug(1, Form("writing ESD to file %s", fileName));
   TFile* file = TFile::Open(fileName, "recreate");
@@ -1633,17 +1717,18 @@ void AliReconstruction::CreateTag(TFile* file)
     delete file;
     return ;
   }  
-  Int_t firstEvent = 0,lastEvent = 0;
+  Int_t lastEvent = 0;
   TTree *t = (TTree*) file->Get("esdTree");
   TBranch * b = t->GetBranch("ESD");
   AliESD *esd = 0;
   b->SetAddress(&esd);
 
-  b->GetEntry(0);
+  b->GetEntry(fFirstEvent);
   Int_t iInitRunNumber = esd->GetRunNumber();
   
-  Int_t iNumberOfEvents = b->GetEntries();
-  for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
+  Int_t iNumberOfEvents = (Int_t)b->GetEntries();
+  if(fLastEvent != -1) iNumberOfEvents = fLastEvent + 1;
+  for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
     ntrack = 0;
     nPos = 0;
     nNeg = 0;
@@ -1847,14 +1932,15 @@ void AliReconstruction::CreateTag(TFile* file)
     tag->SetRunId(iInitRunNumber);
     tag->AddEventTag(*evTag);
   }
-  lastEvent = iNumberOfEvents;
+  if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries();
+  else lastEvent = fLastEvent;
        
   ttag.Fill();
   tag->Clear();
 
   char fileName[256];
   sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root", 
-         tag->GetRunId(),firstEvent,lastEvent );
+         tag->GetRunId(),fFirstEvent,lastEvent );
   AliInfo(Form("writing tags to file %s", fileName));
   AliDebug(1, Form("writing tags to file %s", fileName));
  
@@ -1867,6 +1953,15 @@ void AliReconstruction::CreateTag(TFile* file)
   delete evTag;
 }
 
+//_____________________________________________________________________________
+void AliReconstruction::CreateAOD(TFile* esdFile)
+{
+  // do nothing for now
+
+  return;
+}
+
+
 void AliReconstruction::WriteAlignmentData(AliESD* esd)
 {
   // Write space-points which are then used in the alignment procedures