]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
Fixes in the memory managment, additional protections
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index 8c98ad405f53336c3133d265872a3698292e0d7c..2435e159d024c4f95581251a29e057c8e5d16e5b 100644 (file)
 // The reconstruction requires digits or raw data as input. For the creation //
 // of digits and raw data have a look at the class AliSimulation.            //
 //                                                                           //
+// The input data of a detector can be replaced by the corresponding HLT     //
+// data by calling (usual detector string)                                   //
+// SetUseHLTData("...");                                                     //
+//                                                                           //
 // For debug purposes the method SetCheckPointLevel can be used. If the      //
 // argument is greater than 0, files with ESD events will be written after   //
 // selected steps of the reconstruction for each event:                      //
 #include <TLorentzVector.h>
 #include <TArrayS.h>
 #include <TArrayD.h>
+#include <TObjArray.h>
 
 #include "AliReconstruction.h"
 #include "AliCodeTimer.h"
 #include "AliAlignObj.h"
 
 #include "AliCentralTrigger.h"
+#include "AliTriggerConfiguration.h"
+#include "AliTriggerClass.h"
 #include "AliCTPRawStream.h"
 
 #include "AliAODEvent.h"
 #include "AliPlaneEff.h"
 
 #include "AliSysInfo.h" // memory snapshots
+#include "AliRawHLTManager.h"
 
 
 ClassImp(AliReconstruction)
@@ -205,6 +213,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename,
 
   fUniformField(kTRUE),
   fRunVertexFinder(kTRUE),
+  fRunVertexFinderTracks(kTRUE),
   fRunHLTTracking(kFALSE),
   fRunMuonTracking(kFALSE),
   fRunV0Finder(kTRUE),
@@ -236,9 +245,11 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename,
   fLoadAlignFromCDB(kTRUE),
   fLoadAlignData("ALL"),
   fESDPar(""),
+  fUseHLTData(),
 
   fRunLoader(NULL),
   fRawReader(NULL),
+  fParentRawReader(NULL),
 
   fVertexer(NULL),
   fDiamondProfile(NULL),
@@ -276,6 +287,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
 
   fUniformField(rec.fUniformField),
   fRunVertexFinder(rec.fRunVertexFinder),
+  fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
   fRunHLTTracking(rec.fRunHLTTracking),
   fRunMuonTracking(rec.fRunMuonTracking),
   fRunV0Finder(rec.fRunV0Finder),
@@ -617,6 +629,18 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
   if (!fEquipIdMap.IsNull() && fRawReader)
     fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
 
+  if (!fUseHLTData.IsNull()) {
+    // create the RawReaderHLT which performs redirection of HLT input data for
+    // the specified detectors
+    AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
+    if (pRawReader) {
+      fParentRawReader=fRawReader;
+      fRawReader=pRawReader;
+    } else {
+      AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
+    }
+  }
+
    AliSysInfo::AddStamp("Start");
   // get the run loader
   if (!InitRunLoader()) return kFALSE;
@@ -779,8 +803,10 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
         TObjArray *arr=
           qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
        AliTracker::SetResidualsArray(arr);
+        qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
         if (!fInLoopQA) {
            qadm->StartOfCycle(AliQA::kRECPOINTS);
+           qadm->StartOfCycle(AliQA::kESDS,"same");
         }
      }
   }
@@ -823,6 +849,7 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
        if (fRunGlobalQA) {
           AliQADataMakerRec *qadm = GetQADataMaker(fgkNDetectors);
           qadm->StartOfCycle(AliQA::kRECPOINTS);
+          qadm->StartOfCycle(AliQA::kESDS,"same");
        }
     }
 
@@ -868,7 +895,7 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
     // HLT tracking
     if (!fRunTracking.IsNull()) {
       if (fRunHLTTracking) {
-       hltesd->SetVertex(esd->GetVertex());
+       hltesd->SetPrimaryVertexSPD(esd->GetVertex());
        if (!RunHLTTracking(hltesd)) {
          if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
        }
@@ -919,31 +946,85 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
 
     file->cd();
 
-    //Try to improve the reconstructed primary vertex position using the tracks
-    AliESDVertex *pvtx=0;
-    Bool_t dovertex=kTRUE;
-    TObject* obj = fOptions.FindObject("ITS");
+    //
+    // Propagate track to the beam pipe  (if not laready done by ITS)
+    //
+    const Int_t ntracks = esd->GetNumberOfTracks();
+    const Double_t kBz = esd->GetMagneticField();
+    const Double_t kRadius  = 2.8; //something less than the beam pipe radius
+
+    TObjArray trkArray;
+    UShort_t *selectedIdx=new UShort_t[ntracks];
+
+    for (Int_t itrack=0; itrack<ntracks; itrack++){
+      const Double_t kMaxStep = 5;   //max step over the material
+      Bool_t ok;
+
+      AliESDtrack *track = esd->GetTrack(itrack);
+      if (!track) continue;
+
+      AliExternalTrackParam *tpcTrack =
+           (AliExternalTrackParam *)track->GetTPCInnerParam();
+      ok = kFALSE;
+      if (tpcTrack)
+       ok = AliTracker::
+         PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
+      if (ok) {
+       Int_t n=trkArray.GetEntriesFast();
+        selectedIdx[n]=track->GetID();
+        trkArray.AddLast(tpcTrack);
+      }
+
+      if (track->GetX() < kRadius) continue;
+
+      ok = AliTracker::
+           PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
+      if (ok) {
+         track->RelateToVertex(esd->GetPrimaryVertexSPD(), kBz, kRadius);
+      }
+    }
+
+    //
+    // Improve the reconstructed primary vertex position using the tracks
+    //
+    TObject *obj = fOptions.FindObject("ITS");
     if (obj) {
       TString optITS = obj->GetTitle();
       if (optITS.Contains("cosmics") || optITS.Contains("COSMICS")) 
-       dovertex=kFALSE;
+       fRunVertexFinderTracks=kFALSE;
+    }
+    if (fRunVertexFinderTracks) {
+       // TPC + ITS primary vertex
+       AliESDVertex *pvtx=tVertexer.FindPrimaryVertex(esd);
+       if (pvtx) {
+          if (pvtx->GetStatus()) {
+             esd->SetPrimaryVertex(pvtx);
+             for (Int_t i=0; i<ntracks; i++) {
+                AliESDtrack *t = esd->GetTrack(i);
+                 t->RelateToVertex(pvtx, kBz, kRadius);
+             } 
+          }
+       }
+
+       // TPC-only primary vertex
+       pvtx=tVertexer.FindPrimaryVertex(&trkArray,selectedIdx);
+       if (pvtx) {
+          if (pvtx->GetStatus()) {
+             esd->SetPrimaryVertexTPC(pvtx);
+             Int_t nsel=trkArray.GetEntriesFast();
+             for (Int_t i=0; i<nsel; i++) {
+                AliExternalTrackParam *t = 
+                   (AliExternalTrackParam *)trkArray.UncheckedAt(i);
+                 t->PropagateToDCA(pvtx, kBz, kRadius);
+             } 
+          }
+       }
+
     }
-    if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
+    delete[] selectedIdx;
+
     if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
     
-    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);
-       } 
-    }
 
     if (fRunV0Finder) {
        // V0 finding
@@ -959,6 +1040,12 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
  
     // write ESD
     if (fCleanESD) CleanESD(esd);
+
+    if (fRunQA && fRunGlobalQA) {
+       AliQADataMakerRec *qadm = GetQADataMaker(fgkNDetectors);
+       if (qadm) qadm->Exec(AliQA::kESDS, esd);
+    }
+
     if (fWriteESDfriend) {
       esdf->~AliESDfriend();
       new (esdf) AliESDfriend(); // Reset...
@@ -997,6 +1084,7 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
            AliQADataMakerRec *qadm = GetQADataMaker(fgkNDetectors);
            if (qadm) {
              qadm->EndOfCycle(AliQA::kRECPOINTS);
+             qadm->EndOfCycle(AliQA::kESDS);
              qadm->Finish();
           }
         }
@@ -1054,6 +1142,11 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
   tree->Write(tree->GetName(),TObject::kOverwrite);
   hlttree->Write();
 
+// Finish with Plane Efficiency evaluation: before of CleanUp !!!
+  if (fRunPlaneEff && !FinishPlaneEff()) {
+   AliWarning("Finish PlaneEff evaluation failed");
+  }
+
   gROOT->cd();
   CleanUp(file, fileOld);
     
@@ -1065,14 +1158,6 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
     esdFile->Close();
   }
 
-// Finish with Plane Efficiency evaluation
-  if (fRunPlaneEff && !FinishPlaneEff()) {
-   AliWarning("Finish PlaneEff evaluation failed");
-  }
-
-  gROOT->cd();
-  CleanUp(file, fileOld);
-    
   // Create tags for the events in the ESD tree (the ESD tree is always present)
   // In case of empty events the tags will contain dummy values
   AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
@@ -1092,6 +1177,7 @@ Bool_t AliReconstruction::Run(const char* input, Bool_t IsOnline)
         AliQADataMakerRec *qadm = GetQADataMaker(fgkNDetectors);
         if (qadm) {
           qadm->EndOfCycle(AliQA::kRECPOINTS);
+          qadm->EndOfCycle(AliQA::kESDS);
           qadm->Finish();
        }
      }
@@ -1287,7 +1373,7 @@ Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
     AliWarning("no vertex reconstructed");
     vertex = new AliESDVertex(vtxPos, vtxErr);
   }
-  esd->SetVertex(vertex);
+  esd->SetPrimaryVertexSPD(vertex);
   // if SPD multiplicity has been determined, it is stored in the ESD
   AliMultiplicity *mult = fVertexer->GetMultiplicity();
   if(mult)esd->SetMultiplicity(mult);
@@ -1456,8 +1542,6 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
 
   // pass 2: ALL backwards
 
-  if (fRunQA && fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);     
-
   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
     if (!fTracker[iDet]) continue;
     AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
@@ -1498,8 +1582,6 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
     AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
   }
 
-  if (fRunQA && fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);     
-
   // write space-points to the ESD in case alignment data output
   // is switched on
   if (fWriteAlignmentData)
@@ -1507,6 +1589,7 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
 
   // pass 3: TRD + TPC + ITS refit inwards
 
+  if (fRunQA && fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);     
 
   for (Int_t iDet = 2; iDet >= 0; iDet--) {
     if (!fTracker[iDet]) continue;
@@ -1533,21 +1616,8 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
     AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
   }
 
-  //
-  // Propagate track to the vertex - if not done by ITS
-  //
-  Int_t ntracks = esd->GetNumberOfTracks();
-  for (Int_t itrack=0; itrack<ntracks; itrack++){
-    const Double_t kRadius  = 3;   // beam pipe radius
-    const Double_t kMaxStep = 5;   // max step
-    const Double_t kMaxD    = 123456;  // max distance to prim vertex
-    Double_t       fieldZ   = AliTracker::GetBz();  //
-    AliESDtrack * track = esd->GetTrack(itrack);
-    if (!track) continue;
-    if (track->IsOn(AliESDtrack::kITSrefit)) continue;
-   AliTracker::PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
-    track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
-  }
+  if (fRunQA && fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);     
+
   eventNr++;
   return kTRUE;
 }
@@ -1644,6 +1714,8 @@ Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
   
   AliInfo("Filling trigger information into the ESD");
 
+  AliCentralTrigger *aCTP = NULL;
+
   if (fRawReader) {
     AliCTPRawStream input(fRawReader);
     if (!input.Next()) {
@@ -1652,12 +1724,19 @@ Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
     }
     esd->SetTriggerMask(input.GetClassMask());
     esd->SetTriggerCluster(input.GetClusterMask());
+
+    aCTP = new AliCentralTrigger();
+    TString configstr("");
+    if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
+      AliError("No trigger configuration found in OCDB! The trigger classes information will no be stored in ESD!");
+      return kFALSE;
+    }
   }
   else {
     AliRunLoader *runloader = AliRunLoader::GetRunLoader();
     if (runloader) {
       if (!runloader->LoadTrigger()) {
-       AliCentralTrigger *aCTP = runloader->GetTrigger();
+       aCTP = runloader->GetTrigger();
        esd->SetTriggerMask(aCTP->GetClassMask());
        esd->SetTriggerCluster(aCTP->GetClusterMask());
       }
@@ -1672,6 +1751,21 @@ Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
     }
   }
 
+  // Now fill the trigger class names into AliESDRun object
+  AliTriggerConfiguration *config = aCTP->GetConfiguration();
+  if (!config) {
+    AliError("No trigger configuration has been found! The trigger classes information will no be stored in ESD!");
+    return kFALSE;
+  }
+
+  const TObjArray& classesArray = config->GetClasses();
+  Int_t nclasses = classesArray.GetEntriesFast();
+  for( Int_t j=0; j<nclasses; j++ ) {
+    AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
+    Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
+    esd->SetTriggerClass(trclass->GetName(),trindex);
+  }
+
   return kTRUE;
 }
 
@@ -1984,6 +2078,8 @@ void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
   fRunLoader = NULL;
   delete fRawReader;
   fRawReader = NULL;
+  if (fParentRawReader) delete fParentRawReader;
+  fParentRawReader=NULL;
 
   if (file) {
     file->Close();
@@ -3080,8 +3176,7 @@ Bool_t AliReconstruction::FinishPlaneEff() {
  //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
  for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS  
    //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
-   //if(fReconstructor[iDet]->GetRecoParam()->GetComputePlaneEff()) continue;
-   ret=fTracker[iDet]->GetPlaneEff()->WriteIntoCDB();
+   if(fTracker[iDet]) ret=fTracker[iDet]->GetPlaneEff()->WriteIntoCDB();
  }
  return ret;
 }