]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
Conding violations fixed. The code is now included in libSTEER (Mikolaj)
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index 9507f1c5e313d75e1b6e9497b55ea12abcfb32dd..23d528f4263743b7272f556d57a67195b57049c9 100644 (file)
 #include <TArrayS.h>
 #include <TArrayD.h>
 #include <TObjArray.h>
+#include <TMap.h>
 
 #include "AliReconstruction.h"
 #include "AliCodeTimer.h"
 #include "AliSysInfo.h" // memory snapshots
 #include "AliRawHLTManager.h"
 
+#include "AliMagWrapCheb.h"
 
 ClassImp(AliReconstruction)
 
@@ -199,7 +201,8 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename,
                                     const char* name, const char* title) :
   TNamed(name, title),
 
-  fUniformField(kTRUE),
+  fUniformField(kFALSE),
+  fForcedFieldMap(0x0),
   fRunVertexFinder(kTRUE),
   fRunVertexFinderTracks(kTRUE),
   fRunHLTTracking(kFALSE),
@@ -244,13 +247,15 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename,
   fDiamondProfileTPC(NULL),
   fMeanVertexConstraint(kTRUE),
 
-  fGRPList(NULL),
+  fGRPData(NULL),
 
   fAlignObjArray(NULL),
   fCDBUri(),
   fSpecCDBUri(), 
   fInitCDBCalled(kFALSE),
   fSetRunNumberFromDataCalled(kFALSE),
+  fQADetectors("ALL"), 
+  fQATasks("ALL"), 
   fRunQA(kTRUE),  
   fRunGlobalQA(kTRUE),
   fInLoopQA(kFALSE),
@@ -268,7 +273,8 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename,
   ftreeOld(NULL),
   fhlttreeOld(NULL),
   ftVertexer(NULL),
-  fIsNewRunLoader(kFALSE)
+  fIsNewRunLoader(kFALSE),
+  fRunAliEVE(kFALSE)
 {
 // create reconstruction object with default parameters
   
@@ -288,6 +294,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   TNamed(rec),
 
   fUniformField(rec.fUniformField),
+  fForcedFieldMap(0x0),
   fRunVertexFinder(rec.fRunVertexFinder),
   fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
   fRunHLTTracking(rec.fRunHLTTracking),
@@ -332,13 +339,15 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fDiamondProfileTPC(NULL),
   fMeanVertexConstraint(rec.fMeanVertexConstraint),
 
-  fGRPList(NULL),
+  fGRPData(NULL),
 
   fAlignObjArray(rec.fAlignObjArray),
   fCDBUri(rec.fCDBUri),
   fSpecCDBUri(), 
   fInitCDBCalled(rec.fInitCDBCalled),
   fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
+  fQADetectors(rec.fQADetectors), 
+  fQATasks(rec.fQATasks), 
   fRunQA(rec.fRunQA),  
   fRunGlobalQA(rec.fRunGlobalQA),
   fInLoopQA(rec.fInLoopQA),
@@ -355,7 +364,8 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   ftreeOld(NULL),
   fhlttreeOld(NULL),
   ftVertexer(NULL),
-  fIsNewRunLoader(rec.fIsNewRunLoader)
+  fIsNewRunLoader(rec.fIsNewRunLoader),
+  fRunAliEVE(kFALSE)
 {
 // copy constructor
 
@@ -373,6 +383,8 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
     if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
   }
+
+  fForcedFieldMap=new AliMagWrapCheb(*((AliMagWrapCheb*)rec.fForcedFieldMap));
 }
 
 //_____________________________________________________________________________
@@ -393,6 +405,7 @@ AliReconstruction::~AliReconstruction()
   CleanUp();
   fOptions.Delete();
   fSpecCDBUri.Delete();
+  delete fForcedFieldMap;
 
   AliCodeTimer::Instance()->Print();
 }
@@ -635,6 +648,160 @@ void AliReconstruction::SetOption(const char* detector, const char* option)
   fOptions.Add(new TNamed(detector, option));
 }
 
+//_____________________________________________________________________________
+Bool_t AliReconstruction::SetFieldMap(Float_t l3Current, Float_t diCurrent, Float_t factor, const char *path) {
+  //------------------------------------------------
+  // The magnetic field map, defined externally...
+  // L3 current 30000 A  -> 0.5 T
+  // L3 current 12000 A  -> 0.2 T
+  // dipole current 6000 A
+  // The polarities must be the same
+  //------------------------------------------------
+  const Float_t l3NominalCurrent1=30000.; // (A)
+  const Float_t l3NominalCurrent2=12000.; // (A)
+  const Float_t diNominalCurrent =6000. ; // (A)
+
+  const Float_t tolerance=0.03; // relative current tolerance
+  const Float_t zero=77.;       // "zero" current (A)
+
+  Int_t map=0;
+  Bool_t dipoleON=kFALSE;
+
+  TString s=(factor < 0) ? "L3: -" : "L3: +";
+
+  l3Current = TMath::Abs(l3Current);
+  if (TMath::Abs(l3Current-l3NominalCurrent1)/l3NominalCurrent1 < tolerance) {
+    map=AliMagWrapCheb::k5kG;
+    s+="0.5 T;  ";
+  } else
+  if (TMath::Abs(l3Current-l3NominalCurrent2)/l3NominalCurrent2 < tolerance) {
+    map=AliMagWrapCheb::k2kG;
+    s+="0.2 T;  ";
+  } else
+  if (l3Current < zero) {
+    map=AliMagWrapCheb::k2kG;
+    s+="0.0 T;  ";
+    factor=0.;                  // in fact, this is a global factor...
+    fUniformField=kTRUE;        // track with the uniform (zero) B field
+  } else {
+    AliError(Form("Wrong L3 current (%f A)!",l3Current));
+    return kFALSE;
+  }
+
+  diCurrent = TMath::Abs(diCurrent);
+  if (TMath::Abs(diCurrent-diNominalCurrent)/diNominalCurrent < tolerance) {
+    // 3% current tolerance...
+    dipoleON=kTRUE;
+    s+="Dipole ON";
+  } else
+  if (diCurrent < zero) { // some small current..
+    dipoleON=kFALSE;
+    s+="Dipole OFF";
+  } else {
+    AliError(Form("Wrong dipole current (%f A)!",diCurrent));
+    return kFALSE;
+  }
+
+  delete fForcedFieldMap;
+  fForcedFieldMap=
+    new AliMagWrapCheb("B field map  ",s,2,factor,10.,map,dipoleON,path);
+
+  fForcedFieldMap->Print();
+
+  AliTracker::SetFieldMap(fForcedFieldMap,fUniformField);    
+
+  return kTRUE;
+}
+
+
+Bool_t AliReconstruction::InitGRP() {
+  //------------------------------------
+  // Initialization of the GRP entry 
+  //------------------------------------
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
+
+  if (entry) fGRPData = dynamic_cast<TMap*>(entry->GetObject());  
+
+  if (!fGRPData) {
+     AliError("No GRP entry found in OCDB!");
+     return kFALSE;
+  }
+
+
+  //*** Dealing with the magnetic field map
+  if (AliTracker::GetFieldMap()) {
+    AliInfo("Running with the externally set B field !");
+  } else {
+    // Construct the field map out of the information retrieved from GRP.
+
+    Bool_t ok = kTRUE;
+
+    // L3
+    TObjString *l3Current=
+       dynamic_cast<TObjString*>(fGRPData->GetValue("fL3Current"));
+    if (!l3Current) {
+      AliError("GRP/GRP/Data entry:  missing value for the L3 current !");
+      ok = kFALSE;
+    }
+    TObjString *l3Polarity=
+       dynamic_cast<TObjString*>(fGRPData->GetValue("fL3Polarity"));
+    if (!l3Polarity) {
+      AliError("GRP/GRP/Data entry:  missing value for the L3 polarity !");
+      ok = kFALSE;
+    }
+
+    // Dipole
+    TObjString *diCurrent=
+       dynamic_cast<TObjString*>(fGRPData->GetValue("fDipoleCurrent"));
+    if (!diCurrent) {
+      AliError("GRP/GRP/Data entry:  missing value for the dipole current !");
+      ok = kFALSE;
+    }
+    TObjString *diPolarity=
+       dynamic_cast<TObjString*>(fGRPData->GetValue("fDipolePolarity"));
+    if (!diPolarity) {
+      AliError("GRP/GRP/Data entry:  missing value for the dipole polarity !");
+      ok = kFALSE;
+    }
+
+    if (ok) { 
+       Float_t l3Cur=TMath::Abs(atof(l3Current->GetName()));
+       Float_t diCur=TMath::Abs(atof(diCurrent->GetName()));
+       Float_t l3Pol=atof(l3Polarity->GetName());
+       Float_t factor=1.;
+       if (l3Pol != 0.) factor=-1.;
+    
+
+      if (!SetFieldMap(l3Cur, diCur, factor)) {
+         AliFatal("Failed to creat a B field map ! Exiting...");
+      }
+      AliInfo("Running with the B field constructed out of GRP !");
+    }
+    else {
+      AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
+    }
+
+  }
+
+
+  //*** Get the diamond profile from OCDB
+  entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
+  if (entry) {
+     fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());  
+  } else {
+     AliError("No diamond profile found in OCDB!");
+  }
+
+  entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexTPC");
+  if (entry) {
+     fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());  
+  } else {
+     AliError("No diamond profile found in OCDB!");
+  }
+
+  return kTRUE;
+} 
+
 //_____________________________________________________________________________
 Bool_t AliReconstruction::Run(const char* input)
 {
@@ -642,7 +809,6 @@ Bool_t AliReconstruction::Run(const char* input)
   AliCodeTimerAuto("");
 
   if (!InitRun(input)) return kFALSE;
-  
   //******* The loop over events
   Int_t iEvent = 0;
   while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
@@ -710,21 +876,22 @@ Bool_t AliReconstruction::InitRun(const char* input)
     TString geom(gSystem->DirName(fGAliceFileName));
     geom += "/geometry.root";
     AliGeomManager::LoadGeometry(geom.Data());
+
+    TString detsToCheck=fRunLocalReconstruction;
+    if(!AliGeomManager::CheckSymNamesLUT(detsToCheck.Data()))
+         AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
     if (!gGeoManager) if (fStopOnError) return kFALSE;
   }
 
   if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
    AliSysInfo::AddStamp("LoadGeom");
 
-  
-  /*
-  // local reconstruction
-  if (!fRunLocalReconstruction.IsNull()) {
-    if (!RunLocalReconstruction(fRunLocalReconstruction)) {
-      if (fStopOnError) {CleanUp(); return kFALSE;}
-    }
-  }
-  */
+
+  if (!InitGRP()) return kFALSE;
+
+
+  ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
+  if(fDiamondProfile && fMeanVertexConstraint) ftVertexer->SetVtxStart(fDiamondProfile);
 
   // get vertexer
   if (fRunVertexFinder && !CreateVertexer()) {
@@ -775,13 +942,6 @@ Bool_t AliReconstruction::InitRun(const char* input)
   fhltesd->CreateStdContent();
   fhltesd->WriteToTree(fhlttree);
 
-  /* CKB Why?
-  delete esd; delete hltesd;
-  esd = NULL; hltesd = NULL;
-  */
-  // create the branch with ESD additions
-
-
 
   if (fWriteESDfriend) {
     fesdf = new AliESDfriend();
@@ -790,38 +950,7 @@ Bool_t AliReconstruction::InitRun(const char* input)
     fesd->AddObject(fesdf);
   }
 
-  
-  // Get the GRP CDB entry
-  AliCDBEntry* entryGRP = AliCDBManager::Instance()->Get("GRP/GRP/Data");
-       
-  if(entryGRP) {
-       fGRPList = dynamic_cast<TList*> (entryGRP->GetObject());  
-  } else {
-       AliError("No GRP entry found in OCDB!");
-  }
-
-  // Get the diamond profile from OCDB
-  AliCDBEntry* entry = AliCDBManager::Instance()
-       ->Get("GRP/Calib/MeanVertex");
-       
-  if(entry) {
-       fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());  
-  } else {
-       AliError("No diamond profile found in OCDB!");
-  }
-
-  entry = 0;
-  entry = AliCDBManager::Instance()
-       ->Get("GRP/Calib/MeanVertexTPC");
-       
-  if(entry) {
-       fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());  
-  } else {
-       AliError("No diamond profile found in OCDB!");
-  }
 
-  ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
-  if(fDiamondProfile && fMeanVertexConstraint) ftVertexer->SetVtxStart(fDiamondProfile);
 
   if (fRawReader) fRawReader->RewindEvents();
 
@@ -829,48 +958,61 @@ Bool_t AliReconstruction::InitRun(const char* input)
   gSystem->GetProcInfo(&ProcInfo);
   AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
   
-
-  //Initialize the QA and start of cycle for out-of-cycle QA
-       //QA
-       AliQADataMakerSteer qas ; 
-       if (fRunQA && fRawReader) { 
-               qas.SetEventRange(fFirstEvent, fLastEvent) ; 
+  //QA
+  if (fRunQA && fRawReader && fQATasks.Contains(Form("%d", AliQA::kRAWS))) { 
+               AliQADataMakerSteer qas ; 
                qas.Run(fRunLocalReconstruction, fRawReader) ; 
                fSameQACycle = kTRUE ; 
-       }
-       // checking the QA of previous steps
-       //CheckQA() ; 
-       if (fRunQA) {
-     TString detStr(fFillESD); 
-     for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
-        if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
-        AliQADataMakerRec *qadm = GetQADataMaker(iDet);  
-        if (!qadm) continue;
-        AliInfo(Form("Initializing the QA data maker for %s", 
-               fgkDetectorName[iDet]));
-
-               if (fInLoopQA) {
-                       qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
-                       qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
-               } else {
-                       qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
-                       qadm->StartOfCycle(AliQA::kESDS,"same");
-        }
-     }
+  }
+  //Initialize the QA and start of cycle for out-of-cycle QA
+  if (fRunQA) {
+         TString detStr(fQADetectors) ; 
+      for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
+         if (!IsSelected(fgkDetectorName[iDet], detStr)) 
+                        continue;
+         AliQADataMakerRec *qadm = GetQADataMaker(iDet);  
+         if (!qadm) 
+                        continue;
+         AliInfo(Form("Initializing the QA data maker for %s", 
+                fgkDetectorName[iDet]));
+                if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) 
+                        qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
+                if (fQATasks.Contains(Form("%d", AliQA::kESDS)))  
+                        qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
+         if (!fInLoopQA) {
+                        if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
+                                qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
+                                fSameQACycle = kTRUE;
+                        }
+                        if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {  
+                                qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
+                                fSameQACycle = kTRUE;
+                        }
+                }
+      }
          if (fRunGlobalQA) {
                  AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
                  AliInfo(Form("Initializing the global QA data maker"));
-                 TObjArray *arr=
-                       qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
-                 AliTracker::SetResidualsArray(arr);
-                 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
+                 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
+                         TObjArray *arr=
+                               qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
+                         AliTracker::SetResidualsArray(arr);
+                 }
+                 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
+                         qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
+                 }
                  if (!fInLoopQA) {
-                         qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
-                         qadm->StartOfCycle(AliQA::kESDS, "same");
+                         fSameQACycle = kFALSE;
+                         if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {                                 
+                                 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
+                                 fSameQACycle = kTRUE;
+                         }
+                         if (fQATasks.Contains(Form("%d", AliQA::kESDS))) { 
+                                 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
+                                 fSameQACycle = kTRUE; 
+                         }
                  }
          }
-         if (!fInLoopQA) 
-                 fSameQACycle = kTRUE; 
   }
 
   //Initialize the Plane Efficiency framework
@@ -878,6 +1020,9 @@ Bool_t AliReconstruction::InitRun(const char* input)
     if(fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
   }
 
+  if (strcmp(gProgName,"alieve") == 0)
+    fRunAliEVE = InitAliEVE();
+
   return kTRUE;
 }
 
@@ -905,7 +1050,7 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
       ftree->Fill();
     }
     if (fhlttreeOld) {
-      fesd->ReadFromTree(fhlttreeOld);
+      fhltesd->ReadFromTree(fhlttreeOld);
       fhlttreeOld->GetEntry(iEvent);
       fhlttree->Fill();
     }
@@ -917,20 +1062,34 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
     //Start of cycle for the in-loop QA
     if (fInLoopQA) {
        if (fRunQA) {
-          TString detStr(fFillESD); 
+                 fSameQACycle = kFALSE ;
+          TString detStr(fQADetectors); 
           for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
              if (!IsSelected(fgkDetectorName[iDet], detStr)) 
                                 continue;
              AliQADataMakerRec *qadm = GetQADataMaker(iDet);  
              if (!qadm) 
                                 continue;
-             qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
-             qadm->StartOfCycle(AliQA::kESDS, "same") ;        
+                         if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
+                                 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
+                                 fSameQACycle = kTRUE;
+                         }
+                         if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
+                                 qadm->StartOfCycle(AliQA::kESDS, fSameQACycle) ;
+                                 fSameQACycle = kTRUE;
+                         }
           }
                   if (fRunGlobalQA) {
+                          fSameQACycle = kFALSE;
                           AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
-                          qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
-                          qadm->StartOfCycle(AliQA::kESDS, "same");
+                          if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
+                                  qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
+                                  fSameQACycle = kTRUE;
+                          }
+                          if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
+                                  qadm->StartOfCycle(AliQA::kESDS, fSameQACycle);
+                                  fSameQACycle = kTRUE;
+                          }
                   }               
           }
     }
@@ -943,12 +1102,13 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
            fRunLoader->GetHeader()->GetEventNrInRun());
     if (!gSystem->AccessPathName(aFileName)) return kTRUE;
 
-    // local signle event reconstruction
+    // local single event reconstruction
     if (!fRunLocalReconstruction.IsNull()) {
-      TString detectors="HLT";
+      TString detectors=fRunLocalReconstruction;
       // run HLT event reconstruction first
-      if (IsSelected(detectors, fRunLocalReconstruction) &&
-         !RunLocalEventReconstruction(detectors)) {
+      // ;-( IsSelected changes the string
+      if (IsSelected("HLT", detectors) &&
+         !RunLocalEventReconstruction("HLT")) {
        if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
       }
       detectors=fRunLocalReconstruction;
@@ -982,16 +1142,6 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
       }
     }
 
-    // HLT tracking
-    if (!fRunTracking.IsNull()) {
-      if (fRunHLTTracking) {
-       fhltesd->SetPrimaryVertexSPD(fesd->GetVertex());
-       if (!RunHLTTracking(fhltesd)) {
-         if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
-       }
-      }
-    }
-
     // Muon tracking
     if (!fRunTracking.IsNull()) {
       if (fRunMuonTracking) {
@@ -1013,7 +1163,24 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
 
     // fill ESD
     if (!fFillESD.IsNull()) {
-      if (!FillESD(fesd, fFillESD)) {
+      TString detectors=fFillESD;
+      // run HLT first and on hltesd
+      // ;-( IsSelected changes the string
+      if (IsSelected("HLT", detectors) &&
+         !FillESD(fhltesd, "HLT")) {
+       if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
+      }
+      detectors=fFillESD;
+      // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
+      if (detectors.Contains("ALL")) {
+       detectors="";
+       for (Int_t idet=0; idet<fgkNDetectors; ++idet){
+         detectors += fgkDetectorName[idet];
+         detectors += " ";
+       }
+      }
+      detectors.ReplaceAll("HLT", "");
+      if (!FillESD(fesd, detectors)) {
        if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
       }
     }
@@ -1037,7 +1204,7 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
     ffile->cd();
 
     //
-    // Propagate track to the beam pipe  (if not laready done by ITS)
+    // Propagate track to the beam pipe  (if not already done by ITS)
     //
     const Int_t ntracks = fesd->GetNumberOfTracks();
     const Double_t kBz = fesd->GetMagneticField();
@@ -1060,21 +1227,17 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
        ok = AliTracker::
          PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
 
-
-
       if (ok) {
        Int_t n=trkArray.GetEntriesFast();
         selectedIdx[n]=track->GetID();
         trkArray.AddLast(tpcTrack);
       }
 
-
       //Tracks refitted by ITS should already be at the SPD vertex
       if (track->IsOn(AliESDtrack::kITSrefit)) continue;
 
-
       AliTracker::
-           PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
+         PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
       track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kVeryBig);
 
     }
@@ -1118,11 +1281,9 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
        if (pvtx) {
           if (pvtx->GetStatus()) {
              fesd->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);
+             for (Int_t i=0; i<ntracks; i++) {
+                AliESDtrack *t = fesd->GetTrack(i);
+                 t->RelateToVertexTPC(pvtx, kBz, kVeryBig);
              } 
           }
        }
@@ -1151,7 +1312,8 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
        if (fRunQA) {
                if (fRunGlobalQA) {
                        AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
-                       if (qadm) qadm->Exec(AliQA::kESDS, fesd);
+                       if (qadm && fQATasks.Contains(Form("%d", AliQA::kESDS)))
+                               qadm->Exec(AliQA::kESDS, fesd);
                }
        }
 
@@ -1165,6 +1327,9 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
     // write HLT ESD
     fhlttree->Fill();
 
+    // call AliEVE
+    if (fRunAliEVE) RunAliEVE();
+
     if (fCheckPointLevel > 0)  WriteESD(fesd, "final"); 
     fesd->Reset();
     fhltesd->Reset();
@@ -1178,29 +1343,32 @@ Bool_t AliReconstruction::RunEvent(Int_t iEvent)
     AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
   
 
-  // End of cycle for the in-loop QA
+  // End of cycle for the in-loop  
      if (fInLoopQA) {
         if (fRunQA) {
-           RunQA(fFillESD.Data(), fesd);
-           TString detStr(fFillESD); 
+           RunQA(fesd);
            for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
-                          if (!IsSelected(fgkDetectorName[iDet], detStr)) 
+                          if (!IsSelected(fgkDetectorName[iDet], fQADetectors)) 
                                   continue;
                           AliQADataMakerRec * qadm = GetQADataMaker(iDet);
-                          if (!qadm) 
+                          if (!qadm)
                                   continue;
-                          qadm->EndOfCycle(AliQA::kRECPOINTS);
-                          qadm->EndOfCycle(AliQA::kESDS);
+                          if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) 
+                                  qadm->EndOfCycle(AliQA::kRECPOINTS);
+                          if (fQATasks.Contains(Form("%d", AliQA::kESDS))) 
+                                  qadm->EndOfCycle(AliQA::kESDS);
                           qadm->Finish();
                   }
         }
         if (fRunGlobalQA) {
            AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
            if (qadm) {
-             qadm->EndOfCycle(AliQA::kRECPOINTS);
-             qadm->EndOfCycle(AliQA::kESDS);
-             qadm->Finish();
-          }
+                          if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) 
+                                  qadm->EndOfCycle(AliQA::kRECPOINTS);
+                          if (fQATasks.Contains(Form("%d", AliQA::kESDS))) 
+                                  qadm->EndOfCycle(AliQA::kESDS);
+                          qadm->Finish();
+                  }
         }
      }
 
@@ -1284,7 +1452,7 @@ Bool_t AliReconstruction::FinishRun()
   // 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();
-  esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPList);
+  esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData);
   if (fWriteAOD) {
     AliWarning("AOD tag creation not supported anymore during reconstruction.");
   }
@@ -1293,15 +1461,18 @@ Bool_t AliReconstruction::FinishRun()
   if (!fInLoopQA) {
          if (fRunQA) {
                  AliQADataMakerSteer qas;
-                 qas.SetEventRange(fFirstEvent, fLastEvent) ; 
-                 qas.Run(fRunLocalReconstruction.Data(), AliQA::kRECPOINTS, fSameQACycle);
+                 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) 
+                         qas.Run(fRunLocalReconstruction.Data(), AliQA::kRECPOINTS, fSameQACycle);
                  //qas.Reset() ;
-                 qas.Run(fRunTracking.Data(), AliQA::kESDS, fSameQACycle);
+                 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) 
+                         qas.Run(fRunLocalReconstruction.Data(), AliQA::kESDS, fSameQACycle);
                  if (fRunGlobalQA) {
                         AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
                          if (qadm) {
-                                 qadm->EndOfCycle(AliQA::kRECPOINTS);
-                                 qadm->EndOfCycle(AliQA::kESDS);
+                                 if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) 
+                                         qadm->EndOfCycle(AliQA::kRECPOINTS);
+                                 if (fQATasks.Contains(Form("%d", AliQA::kESDS))) 
+                                         qadm->EndOfCycle(AliQA::kESDS);
                                  qadm->Finish();
                          }
                  }
@@ -1385,6 +1556,17 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
     AliReconstructor* reconstructor = GetReconstructor(iDet);
     if (!reconstructor) continue;
     AliLoader* loader = fLoader[iDet];
+    // Matthias April 2008: temporary fix to run HLT reconstruction
+    // although the HLT loader is missing
+    if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
+      if (fRawReader) {
+       reconstructor->Reconstruct(fRawReader, NULL);
+      } else {
+       TTree* dummy=NULL;
+       reconstructor->Reconstruct(dummy, NULL);
+      }
+      continue;
+    }
     if (!loader) {
       AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
       continue;
@@ -1433,8 +1615,8 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
          //AliInfo
           //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
 
-         qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
+                  if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) 
+                          qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
          //AliCodeTimerStop
           //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
        }
@@ -1471,11 +1653,22 @@ Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
   }
 
   if (fVertexer) {
-    if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
     AliInfo("running the ITS vertex finder");
-    if (fLoader[0]) fLoader[0]->LoadRecPoints();
-    vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
-    if (fLoader[0]) fLoader[0]->UnloadRecPoints();
+    if (fLoader[0]) {
+      fLoader[0]->LoadRecPoints();
+      TTree* cltree = fLoader[0]->TreeR();
+      if (cltree) {
+       if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
+       vertex = fVertexer->FindVertexForCurrentEvent(cltree);
+      }
+      else {
+       AliError("Can't get the ITS cluster tree");
+      }
+      fLoader[0]->UnloadRecPoints();
+    }
+    else {
+      AliError("Can't get the ITS loader");
+    }
     if(!vertex){
       AliWarning("Vertex not found");
       vertex = new AliESDVertex();
@@ -1849,11 +2042,16 @@ Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
   if (fRawReader) {
     AliCTPRawStream input(fRawReader);
     if (!input.Next()) {
-      AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
-      return kFALSE;
+      AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger mask will be taken from the event header, trigger cluster mask will be empty !");
+      ULong64_t mask = (((ULong64_t)fRawReader->GetTriggerPattern()[1]) << 32) +
+       fRawReader->GetTriggerPattern()[0];
+      esd->SetTriggerMask(mask);
+      esd->SetTriggerCluster(0);
+    }
+    else {
+      esd->SetTriggerMask(input.GetClassMask());
+      esd->SetTriggerCluster(input.GetClusterMask());
     }
-    esd->SetTriggerMask(input.GetClassMask());
-    esd->SetTriggerCluster(input.GetClusterMask());
 
     aCTP = new AliCentralTrigger();
     TString configstr("");
@@ -1885,7 +2083,7 @@ 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!");
+    AliError("No trigger configuration has been found! The trigger classes information will not be stored in ESD!");
     if (fRawReader) delete aCTP;
     return kFALSE;
   }
@@ -1991,19 +2189,9 @@ Bool_t AliReconstruction::InitRunLoader()
       CleanUp();
       return kFALSE;
     }
+
     fRunLoader->CdGAFile();
-    if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
-      if (fRunLoader->LoadgAlice() == 0) {
-       gAlice = fRunLoader->GetAliRun();
-       AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
-      }
-    }
-    if (!gAlice && !fRawReader) {
-      AliError(Form("no gAlice object found in file %s",
-                   fGAliceFileName.Data()));
-      CleanUp();
-      return kFALSE;
-    }
+    fRunLoader->LoadgAlice();
 
     //PH This is a temporary fix to give access to the kinematics
     //PH that is needed for the labels of ITS clusters
@@ -2048,7 +2236,8 @@ AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
   TPluginManager* pluginManager = gROOT->GetPluginManager();
   TString detName = fgkDetectorName[iDet];
   TString recName = "Ali" + detName + "Reconstructor";
-  if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
+
+  if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
 
   AliReconstructor* reconstructor = NULL;
   // first check if a plugin is defined for the reconstructor
@@ -2195,8 +2384,8 @@ void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
        fDiamondProfile = NULL;
        delete fDiamondProfileTPC;
        fDiamondProfileTPC = NULL;
-       delete fGRPList;
-       fGRPList = NULL;
+       delete fGRPData;
+       fGRPData = NULL;
   }
 
 
@@ -2358,7 +2547,7 @@ void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
 
 }
 
-TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
+TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString pName){
   // Dump a file content into a char in TNamed
   ifstream in;
   in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
@@ -2371,9 +2560,9 @@ TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
     in.read (memblock, kBytes);
     in.close();
     TString fData(memblock,kBytes);
-    fn = new TNamed(fName,fData);
+    fn = new TNamed(pName,fData);
     printf("fData Size: %d \n",fData.Sizeof());
-    printf("fName Size: %d \n",fName.Sizeof());
+    printf("pName Size: %d \n",pName.Sizeof());
     printf("fn    Size: %d \n",fn->Sizeof());
     delete[] memblock;
   }
@@ -2384,21 +2573,21 @@ TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
   return fn;
 }
 
-void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
+void AliReconstruction::TNamedToFile(TTree* fTree, TString pName){
   // This is not really needed in AliReconstruction at the moment
   // but can serve as a template
 
   TList *fList = fTree->GetUserInfo();
-  TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
+  TNamed *fn = (TNamed*)fList->FindObject(pName.Data());
   printf("fn Size: %d \n",fn->Sizeof());
 
-  TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
+  TString fTmp(fn->GetName()); // to be 100% sure in principle pName also works
   const char* cdata = fn->GetTitle();
   printf("fTmp Size %d\n",fTmp.Sizeof());
 
   int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
   printf("calculated size %d\n",size);
-  ofstream out(fName.Data(),ios::out | ios::binary);
+  ofstream out(pName.Data(),ios::out | ios::binary);
   out.write(cdata,size);
   out.close();
 
@@ -2423,7 +2612,7 @@ AliQADataMakerRec * AliReconstruction::GetQADataMaker(Int_t iDet)
   TPluginManager* pluginManager = gROOT->GetPluginManager();
   TString detName = fgkDetectorName[iDet];
   TString qadmName = "Ali" + detName + "QADataMakerRec";
-  if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) 
+  if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) 
     return NULL;
 
   // first check if a plugin is defined for the quality assurance data maker
@@ -2452,12 +2641,12 @@ AliQADataMakerRec * AliReconstruction::GetQADataMaker(Int_t iDet)
 }
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::RunQA(const char* detectors, AliESDEvent *& esd)
+Bool_t AliReconstruction::RunQA(AliESDEvent *& esd)
 {
   // run the Quality Assurance data producer
 
   AliCodeTimerAuto("")
-  TString detStr = detectors;
+  TString detStr = fQADetectors ;
   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
    if (!IsSelected(fgkDetectorName[iDet], detStr)) 
      continue;
@@ -2467,9 +2656,10 @@ Bool_t AliReconstruction::RunQA(const char* detectors, AliESDEvent *& esd)
    AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
    AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
     
-   qadm->Exec(AliQA::kESDS, esd) ; 
-   qadm->Increment() ; 
-
+   if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
+          qadm->Exec(AliQA::kESDS, esd) ; 
+          qadm->Increment() ; 
+   }
    AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
  }
  if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
@@ -2579,3 +2769,86 @@ Bool_t AliReconstruction::InitPlaneEff() {
  AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));
  return kTRUE;
 }
+
+//_____________________________________________________________________________
+Bool_t AliReconstruction::InitAliEVE()
+{
+  // This method should be called only in case 
+  // AliReconstruction is run
+  // within the alieve environment.
+  // It will initialize AliEVE in a way
+  // so that it can visualize event processed
+  // by AliReconstruction.
+  // The return flag shows whenever the
+  // AliEVE initialization was successful or not.
+
+  TString macroStr;
+  macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
+  AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
+  if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
+
+  gROOT->ProcessLine("if (!gAliEveEvent) {gAliEveEvent = new AliEveEventManager();gAliEveEvent->SetAutoLoad(kTRUE);gAliEveEvent->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(gAliEveEvent);};");
+  gROOT->ProcessLine("alieve_online_init()");
+
+  return kTRUE;
+}
+  
+//_____________________________________________________________________________
+void AliReconstruction::RunAliEVE()
+{
+  // Runs AliEVE visualisation of
+  // the current event.
+  // Should be executed only after
+  // successful initialization of AliEVE.
+
+  AliInfo("Running AliEVE...");
+  gROOT->ProcessLine(Form("gAliEveEvent->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p);",fRunLoader,fRawReader,fesd));
+  gROOT->ProcessLine("gAliEveEvent->StartStopAutoLoadTimer();");
+  gSystem->Run();
+}
+
+//_____________________________________________________________________________
+Bool_t AliReconstruction::SetRunQA(TString detAndAction) 
+{
+       // Allows to run QA for a selected set of detectors
+       // and a selected set of tasks among RAWS, RECPOINTS and ESDS
+       // all selected detectors run the same selected tasks
+       
+       if (!detAndAction.Contains(":")) {
+               AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
+               fRunQA = kFALSE ;
+               return kFALSE ;                 
+       }
+       Int_t colon = detAndAction.Index(":") ; 
+       fQADetectors = detAndAction(0, colon) ; 
+       if (fQADetectors.Contains("ALL") )
+               fQADetectors = fFillESD ; 
+       fQATasks   = detAndAction(colon+1, detAndAction.Sizeof() ) ; 
+       if (fQATasks.Contains("ALL") ) {
+               fQATasks = Form("%d %d %d", AliQA::kRAWS, AliQA::kRECPOINTS, AliQA::kESDS) ; 
+       } else {
+               fQATasks.ToUpper() ; 
+               TString tempo("") ; 
+               if ( fQATasks.Contains("RAW") ) 
+                       tempo = Form("%d ", AliQA::kRAWS) ; 
+               if ( fQATasks.Contains("RECPOINT") ) 
+                       tempo += Form("%d ", AliQA::kRECPOINTS) ; 
+               if ( fQATasks.Contains("ESD") ) 
+                       tempo += Form("%d ", AliQA::kESDS) ; 
+               fQATasks = tempo ; 
+               if (fQATasks.IsNull()) {
+                       AliInfo("No QA requested\n")  ;
+                       fRunQA = kFALSE ;
+                       return kTRUE ; 
+               }
+       }       
+       TString tempo(fQATasks) ; 
+    tempo.ReplaceAll(Form("%d", AliQA::kRAWS), AliQA::GetTaskName(AliQA::kRAWS))       ;
+    tempo.ReplaceAll(Form("%d", AliQA::kRECPOINTS), AliQA::GetTaskName(AliQA::kRECPOINTS)) ;   
+    tempo.ReplaceAll(Form("%d", AliQA::kESDS), AliQA::GetTaskName(AliQA::kESDS)) ;     
+       AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;  
+       fRunQA = kTRUE ;
+       return kTRUE; 
+} 
+
+