]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
Fixes for bug #52499: Field polarities inconsistiency
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index c1ed0ac387df0181b7bb455a1b68cd6a3170e78c..19ddd855a8770f2af2b1f9bdd28af5602dfd1ff8 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include <TArrayD.h>
 #include <TArrayF.h>
+#include <TArrayS.h>
+#include <TChain.h>
 #include <TFile.h>
-#include <TList.h>
-#include <TSystem.h>
-#include <TROOT.h>
-#include <TPluginManager.h>
+#include <TGeoGlobalMagField.h>
 #include <TGeoManager.h>
+#include <TList.h>
 #include <TLorentzVector.h>
-#include <TArrayS.h>
-#include <TArrayD.h>
-#include <TObjArray.h>
 #include <TMap.h>
-#include <TChain.h>
+#include <TObjArray.h>
+#include <TPRegexp.h>
+#include <TParameter.h>
+#include <TPluginManager.h>
 #include <TProof.h>
 #include <TProofOutputFile.h>
-#include <TParameter.h>
+#include <TROOT.h>
+#include <TSystem.h>
+#include <THashTable.h>
 
-#include "AliReconstruction.h"
+#include "AliAlignObj.h"
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliCTPRawStream.h"
+#include "AliCascadeVertexer.h"
+#include "AliCentralTrigger.h"
 #include "AliCodeTimer.h"
-#include "AliReconstructor.h"
-#include "AliLog.h"
-#include "AliRunLoader.h"
-#include "AliRun.h"
-#include "AliRawReaderFile.h"
-#include "AliRawReaderDate.h"
-#include "AliRawReaderRoot.h"
-#include "AliRawEventHeaderBase.h"
-#include "AliRawEvent.h"
+#include "AliDAQ.h"
+#include "AliDetectorRecoParam.h"
+#include "AliESDCaloCells.h"
+#include "AliESDCaloCluster.h"
 #include "AliESDEvent.h"
 #include "AliESDMuonTrack.h"
-#include "AliESDfriend.h"
+#include "AliESDPmdTrack.h"
+#include "AliESDTagCreator.h"
 #include "AliESDVertex.h"
 #include "AliESDcascade.h"
+#include "AliESDfriend.h"
 #include "AliESDkink.h"
-#include "AliESDtrack.h"
-#include "AliESDCaloCluster.h"
-#include "AliESDCaloCells.h"
-#include "AliMultiplicity.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"
 #include "AliESDpid.h"
 #include "AliESDtrack.h"
-#include "AliESDPmdTrack.h"
-
-#include "AliESDTagCreator.h"
-
+#include "AliESDtrack.h"
+#include "AliEventInfo.h"
+#include "AliGRPObject.h"
+#include "AliGRPRecoParam.h"
+#include "AliGenEventHeader.h"
 #include "AliGeomManager.h"
-#include "AliTrackPointArray.h"
-#include "AliCDBManager.h"
-#include "AliCDBStorage.h"
-#include "AliCDBEntry.h"
-#include "AliAlignObj.h"
-
-#include "AliCentralTrigger.h"
-#include "AliTriggerConfiguration.h"
-#include "AliTriggerClass.h"
-#include "AliTriggerCluster.h"
-#include "AliCTPRawStream.h"
-
-#include "AliQADataMakerRec.h" 
 #include "AliGlobalQADataMaker.h" 
-#include "AliQA.h"
-#include "AliQADataMakerSteer.h"
-
+#include "AliHeader.h"
+#include "AliLog.h"
+#include "AliMagF.h"
+#include "AliMultiplicity.h"
+#include "AliPID.h"
 #include "AliPlaneEff.h"
-
-#include "AliSysInfo.h" // memory snapshots
+#include "AliQAv1.h"
+#include "AliQADataMakerRec.h" 
+#include "AliQAManager.h"
+#include "AliRawVEvent.h"
+#include "AliRawEventHeaderBase.h"
 #include "AliRawHLTManager.h"
-
-#include "AliMagWrapCheb.h"
-
-#include "AliDetectorRecoParam.h"
-#include "AliGRPRecoParam.h"
+#include "AliRawReaderDate.h"
+#include "AliRawReaderFile.h"
+#include "AliRawReaderRoot.h"
+#include "AliReconstruction.h"
+#include "AliReconstructor.h"
+#include "AliRun.h"
 #include "AliRunInfo.h"
-#include "AliEventInfo.h"
-
-#include "AliDAQ.h"
-
-#include "AliGRPObject.h"
+#include "AliRunLoader.h"
+#include "AliSysInfo.h" // memory snapshots
+#include "AliTrackPointArray.h"
+#include "AliTracker.h"
+#include "AliTriggerClass.h"
+#include "AliTriggerCluster.h"
+#include "AliTriggerIR.h"
+#include "AliTriggerConfiguration.h"
+#include "AliV0vertexer.h"
+#include "AliVertexer.h"
+#include "AliVertexerTracks.h"
 
 ClassImp(AliReconstruction)
 
@@ -202,8 +196,6 @@ const char* AliReconstruction::fgkDetectorName[AliReconstruction::kNDetectors] =
 //_____________________________________________________________________________
 AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   TSelector(),
-  fUniformField(kFALSE),
-  fForcedFieldMap(NULL),
   fRunVertexFinder(kTRUE),
   fRunVertexFinderTracks(kTRUE),
   fRunHLTTracking(kFALSE),
@@ -228,6 +220,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fUseTrackingErrorsForAlignment(""),
   fGAliceFileName(gAliceFilename),
   fRawInput(""),
+  fESDOutput(""),
   fEquipIdMap(""),
   fFirstEvent(0),
   fLastEvent(-1),
@@ -238,6 +231,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fUseHLTData(),
   fRunInfo(NULL),
   fEventInfo(),
+  fRunScalers(NULL),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -245,25 +239,28 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
 
   fRecoParam(),
 
-  fVertexer(NULL),
+  fSPDTrackleter(NULL),
+
   fDiamondProfileSPD(NULL),
   fDiamondProfile(NULL),
   fDiamondProfileTPC(NULL),
+  fListOfCosmicTriggers(NULL),
   
   fGRPData(NULL),
 
   fAlignObjArray(NULL),
   fCDBUri(),
+  fQARefUri(),
   fSpecCDBUri(), 
   fInitCDBCalled(kFALSE),
   fSetRunNumberFromDataCalled(kFALSE),
   fQADetectors("ALL"), 
-  fQASteer(NULL),  
   fQATasks("ALL"), 
   fRunQA(kTRUE),  
   fRunGlobalQA(kTRUE),
   fSameQACycle(kFALSE),
-
+  fInitQACalled(kFALSE), 
+  fWriteQAExpertData(kTRUE), 
   fRunPlaneEff(kFALSE),
 
   fesd(NULL),
@@ -285,7 +282,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
     fLoader[iDet] = NULL;
     fTracker[iDet] = NULL;
   }
-  for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
+  for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
     fQACycles[iDet] = 999999 ;
     fQAWriteExpert[iDet] = kFALSE ; 
   }
@@ -296,8 +293,6 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
 //_____________________________________________________________________________
 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   TSelector(),
-  fUniformField(rec.fUniformField),
-  fForcedFieldMap(NULL),
   fRunVertexFinder(rec.fRunVertexFinder),
   fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
   fRunHLTTracking(rec.fRunHLTTracking),
@@ -322,6 +317,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
   fGAliceFileName(rec.fGAliceFileName),
   fRawInput(rec.fRawInput),
+  fESDOutput(rec.fESDOutput),
   fEquipIdMap(rec.fEquipIdMap),
   fFirstEvent(rec.fFirstEvent),
   fLastEvent(rec.fLastEvent),
@@ -332,6 +328,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fUseHLTData(rec.fUseHLTData),
   fRunInfo(NULL),
   fEventInfo(),
+  fRunScalers(NULL),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -339,24 +336,28 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
 
   fRecoParam(rec.fRecoParam),
 
-  fVertexer(NULL),
+  fSPDTrackleter(NULL),
+
   fDiamondProfileSPD(rec.fDiamondProfileSPD),
   fDiamondProfile(rec.fDiamondProfile),
   fDiamondProfileTPC(rec.fDiamondProfileTPC),
+  fListOfCosmicTriggers(NULL),
   
   fGRPData(NULL),
 
   fAlignObjArray(rec.fAlignObjArray),
   fCDBUri(rec.fCDBUri),
+  fQARefUri(rec.fQARefUri),
   fSpecCDBUri(), 
   fInitCDBCalled(rec.fInitCDBCalled),
   fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
   fQADetectors(rec.fQADetectors), 
-  fQASteer(NULL),  
   fQATasks(rec.fQATasks), 
   fRunQA(rec.fRunQA),  
   fRunGlobalQA(rec.fRunGlobalQA),
   fSameQACycle(rec.fSameQACycle),
+  fInitQACalled(rec.fInitQACalled),
+  fWriteQAExpertData(rec.fWriteQAExpertData), 
   fRunPlaneEff(rec.fRunPlaneEff),
 
   fesd(NULL),
@@ -381,7 +382,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
     fTracker[iDet] = NULL;
   }  
   
-  for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
+  for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
     fQACycles[iDet] = rec.fQACycles[iDet];
     fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ; 
   }
@@ -403,8 +404,6 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
 // TSelector members should not be touched
   if(&rec == this) return *this;
 
-  fUniformField          = rec.fUniformField;
-  fForcedFieldMap        = NULL;
   fRunVertexFinder       = rec.fRunVertexFinder;
   fRunVertexFinderTracks = rec.fRunVertexFinderTracks;
   fRunHLTTracking        = rec.fRunHLTTracking;
@@ -429,6 +428,7 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
   fUseTrackingErrorsForAlignment = rec.fUseTrackingErrorsForAlignment;
   fGAliceFileName                = rec.fGAliceFileName;
   fRawInput                      = rec.fRawInput;
+  fESDOutput                     = rec.fESDOutput;
   fEquipIdMap                    = rec.fEquipIdMap;
   fFirstEvent                    = rec.fFirstEvent;
   fLastEvent                     = rec.fLastEvent;
@@ -447,6 +447,10 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
 
   fEventInfo                     = rec.fEventInfo;
 
+  delete fRunScalers; fRunScalers = NULL;
+  if (rec.fRunScalers) fRunScalers = new AliTriggerRunScalers(*rec.fRunScalers); 
+
+  
   fRunLoader       = NULL;
   fRawReader       = NULL;
   fParentRawReader = NULL;
@@ -459,12 +463,13 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
     delete fTracker[iDet]; fTracker[iDet] = NULL;
   }
   
-  for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
+  for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
     fQACycles[iDet] = rec.fQACycles[iDet];
     fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
   } 
+
+  delete fSPDTrackleter; fSPDTrackleter = NULL;
     
-  fVertexer             = NULL;
   delete fDiamondProfileSPD; fDiamondProfileSPD = NULL;
   if (rec.fDiamondProfileSPD) fDiamondProfileSPD = new AliESDVertex(*rec.fDiamondProfileSPD);
   delete fDiamondProfile; fDiamondProfile = NULL;
@@ -472,6 +477,9 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
   delete fDiamondProfileTPC; fDiamondProfileTPC = NULL;
   if (rec.fDiamondProfileTPC) fDiamondProfileTPC = new AliESDVertex(*rec.fDiamondProfileTPC);
 
+  delete fListOfCosmicTriggers; fListOfCosmicTriggers = NULL;
+  if (rec.fListOfCosmicTriggers) fListOfCosmicTriggers = (THashTable*)((rec.fListOfCosmicTriggers)->Clone());
+
   delete fGRPData; fGRPData = NULL;
   //  if (rec.fGRPData) fGRPData = (TMap*)((rec.fGRPData)->Clone());
   if (rec.fGRPData) fGRPData = (AliGRPObject*)((rec.fGRPData)->Clone());
@@ -479,15 +487,17 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
   delete fAlignObjArray; fAlignObjArray = NULL;
 
   fCDBUri        = "";
+  fQARefUri      = rec.fQARefUri;
   fSpecCDBUri.Delete();
   fInitCDBCalled               = rec.fInitCDBCalled;
   fSetRunNumberFromDataCalled  = rec.fSetRunNumberFromDataCalled;
   fQADetectors                 = rec.fQADetectors;
-  fQASteer                     = NULL;  
   fQATasks                     = rec.fQATasks; 
   fRunQA                       = rec.fRunQA;  
   fRunGlobalQA                 = rec.fRunGlobalQA;
   fSameQACycle                 = rec.fSameQACycle;
+  fInitQACalled                = rec.fInitQACalled;
+  fWriteQAExpertData           = rec.fWriteQAExpertData;
   fRunPlaneEff                 = rec.fRunPlaneEff;
 
   fesd     = NULL;
@@ -510,18 +520,95 @@ AliReconstruction::~AliReconstruction()
 // clean up
 
   CleanUp();
+  if (fListOfCosmicTriggers) {
+    fListOfCosmicTriggers->Delete();
+    delete fListOfCosmicTriggers;
+  }
   delete fGRPData;
-  delete fForcedFieldMap;
+  delete fRunScalers;
   fOptions.Delete();
   if (fAlignObjArray) {
     fAlignObjArray->Delete();
     delete fAlignObjArray;
   }
   fSpecCDBUri.Delete();
-  delete fQASteer;
+
   AliCodeTimer::Instance()->Print();
 }
 
+//_____________________________________________________________________________
+void AliReconstruction::InitQA()
+{
+  //Initialize the QA and start of cycle 
+  AliCodeTimerAuto("");
+  
+  if (fInitQACalled) return;
+  fInitQACalled = kTRUE;
+  
+  AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kRECMODE) ; 
+  if (fWriteQAExpertData)
+    qam->SetWriteExpert() ; 
+  if (qam->IsDefaultStorageSet()) {
+    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliWarning("Default QA reference storage has been already set !");
+    AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fQARefUri.Data()));
+    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    fQARefUri = qam->GetDefaultStorage()->GetURI();
+  } else {
+    if (fQARefUri.Length() > 0) {
+       AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+       AliDebug(2, Form("Default QA reference storage is set to: %s", fQARefUri.Data()));
+       AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+      } else {
+        fQARefUri="local://$ALICE_ROOT/QAref";
+        AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+        AliWarning("Default QA refeference storage not yet set !!!!");
+        AliWarning(Form("Setting it now to: %s", fQARefUri.Data()));
+        AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+               
+      }
+    qam->SetDefaultStorage(fQARefUri);
+  }
+  
+  if (fRunQA) {
+  qam->SetActiveDetectors(fQADetectors) ; 
+  for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) {
+    qam->SetCycleLength(AliQAv1::DETECTORINDEX_t(det), fQACycles[det]) ;  
+    qam->SetWriteExpert(AliQAv1::DETECTORINDEX_t(det)) ;
+  }
+  if (!fRawReader && !fInput && fQATasks.Contains(AliQAv1::kRAWS))
+    fQATasks.ReplaceAll(Form("%d",AliQAv1::kRAWS), "") ;
+  qam->SetTasks(fQATasks) ; 
+  qam->InitQADataMaker(AliCDBManager::Instance()->GetRun()) ; 
+  }
+  if (fRunGlobalQA) {
+    Bool_t sameCycle = kFALSE ;
+    AliQADataMaker *qadm = qam->GetQADataMaker(AliQAv1::kGLOBAL);
+    AliInfo(Form("Initializing the global QA data maker"));
+    if (fQATasks.Contains(Form("%d", AliQAv1::kRECPOINTS))) {
+      qadm->StartOfCycle(AliQAv1::kRECPOINTS, AliCDBManager::Instance()->GetRun(), sameCycle) ; 
+      TObjArray **arr=qadm->Init(AliQAv1::kRECPOINTS);
+      AliTracker::SetResidualsArray(arr);
+      sameCycle = kTRUE ; 
+    }
+    if (fQATasks.Contains(Form("%d", AliQAv1::kESDS))) {
+      qadm->StartOfCycle(AliQAv1::kESDS, AliCDBManager::Instance()->GetRun(), sameCycle) ; 
+      qadm->Init(AliQAv1::kESDS);
+    }
+  }
+    AliSysInfo::AddStamp("InitQA") ; 
+}
+
+//_____________________________________________________________________________
+void AliReconstruction::MergeQA(const char *fileName)
+{
+  //Initialize the QA and start of cycle 
+  AliCodeTimerAuto("") ;
+  AliQAManager::QAManager()->Merge(AliCDBManager::Instance()->GetRun(),fileName) ; 
+  AliSysInfo::AddStamp("MergeQA") ; 
+}
+  
 //_____________________________________________________________________________
 void AliReconstruction::InitCDB()
 {
@@ -549,7 +636,7 @@ void AliReconstruction::InitCDB()
        AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
        AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     } else {
-       fCDBUri="local://$ALICE_ROOT";
+       fCDBUri="local://$ALICE_ROOT/OCDB";
        AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        AliWarning("Default CDB storage not yet set !!!!");
        AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
@@ -580,6 +667,15 @@ void AliReconstruction::SetDefaultStorage(const char* uri) {
 
 }
 
+//_____________________________________________________________________________
+void AliReconstruction::SetQARefDefaultStorage(const char* uri) {
+  // Store the desired default CDB storage location
+  // Activate it later within the Run() method
+  
+  fQARefUri = uri;
+  AliQAv1::SetQARefStorage(fQARefUri.Data()) ;
+  
+}
 //_____________________________________________________________________________
 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
 // Store a detector-specific CDB storage location
@@ -767,6 +863,15 @@ void AliReconstruction::SetInput(const char* input)
   if (input) fRawInput = input;
 }
 
+//_____________________________________________________________________________
+void AliReconstruction::SetOutput(const char* output) 
+{
+  // Set the output ESD filename
+  // 'output' is a normalt ROOT url
+  // The method is used in case of raw-data reco with PROOF
+  if (output) fESDOutput.SetUrl(output);
+}
+
 //_____________________________________________________________________________
 void AliReconstruction::SetOption(const char* detector, const char* option)
 {
@@ -801,13 +906,17 @@ void AliReconstruction::SetRecoParam(const char* detector, AliDetectorRecoParam
 }
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::SetFieldMap(Float_t l3Current, Float_t diCurrent, Float_t factor, const char *path) {
+Bool_t AliReconstruction::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Pol, 
+                                 Float_t diPol, Int_t convention, Bool_t uniform,
+                                 Float_t beamenergy, const Char_t *beamtype, const Char_t *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
+  // The polarities must match the convention (LHC or DCS2008) 
+  // unless the special uniform map was used for MC
   //------------------------------------------------
   const Float_t l3NominalCurrent1=30000.; // (A)
   const Float_t l3NominalCurrent2=12000.; // (A)
@@ -815,57 +924,69 @@ Bool_t AliReconstruction::SetFieldMap(Float_t l3Current, Float_t diCurrent, Floa
 
   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;
+  //
+  AliMagF::BMap_t map;
+  double sclL3,sclDip;
+  //
+  l3Cur = TMath::Abs(l3Cur);
+  diCur = TMath::Abs(diCur);
+  //
+  if (TMath::Abs((sclDip=diCur/diNominalCurrent)-1.) > tolerance && !uniform) {
+    if (diCur <= zero) sclDip = 0.; // some small current.. -> Dipole OFF
+    else {
+      AliError(Form("Wrong dipole current (%f A)!",diCur));
+      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));
+  //
+  if (uniform) { 
+    // special treatment of special MC with uniform mag field (normalized to 0.5 T)
+    // no check for scaling/polarities are done
+    map   = AliMagF::k5kGUniform;
+    sclL3 = l3Cur/l3NominalCurrent1; 
+  }
+  else {
+    if      (TMath::Abs((sclL3=l3Cur/l3NominalCurrent1)-1.) < tolerance) map  = AliMagF::k5kG;
+    else if (TMath::Abs((sclL3=l3Cur/l3NominalCurrent2)-1.) < tolerance) map  = AliMagF::k2kG;
+    else if (l3Cur <= zero)                                { sclL3 = 0;  map  = AliMagF::k5kGUniform;}
+    else {
+      AliError(Form("Wrong L3 current (%f A)!",l3Cur));
+      return kFALSE;
+    }
+  }
+  //
+  if (sclDip!=0 && (map==AliMagF::k5kG || map==AliMagF::k2kG) &&
+      ((convention==AliMagF::kConvLHC     && l3Pol!=diPol) ||
+       (convention==AliMagF::kConvDCS2008 && l3Pol==diPol)) ) { 
+    AliError(Form("Wrong combination for L3/Dipole polarities (%c/%c) for convention %d",
+                 l3Pol>0?'+':'-',diPol>0?'+':'-',AliMagF::GetPolarityConvention()));
     return kFALSE;
   }
-
-  delete fForcedFieldMap;
-  fForcedFieldMap=
-    new AliMagWrapCheb("B field map  ",s,2,factor,10.,map,dipoleON,path);
-
-  fForcedFieldMap->Print();
-
-  AliTracker::SetFieldMap(fForcedFieldMap,fUniformField);    
-
+  //
+  if (l3Pol<0) sclL3  = -sclL3;
+  if (diPol<0) sclDip = -sclDip;
+  //
+  AliMagF::BeamType_t btype = AliMagF::kNoBeamField;
+  TString btypestr = beamtype;
+  btypestr.ToLower();
+  TPRegexp protonBeam("(proton|p)\\s*-?\\s*\\1");
+  TPRegexp ionBeam("(lead|pb|ion|a)\\s*-?\\s*\\1");
+  if (btypestr.Contains(ionBeam)) btype = AliMagF::kBeamTypeAA;
+  else if (btypestr.Contains(protonBeam)) btype = AliMagF::kBeamTypepp;
+  else {
+    AliInfo(Form("Cannot determine the beam type from %s, assume no LHC magnet field",beamtype));
+  }
+  char ttl[50];
+  sprintf(ttl,"L3: %+5d Dip: %+4d kA; %s",(int)TMath::Sign(l3Cur,float(sclL3)),
+         (int)TMath::Sign(diCur,float(sclDip)),uniform ? " Constant":"");
+  AliMagF* fld = new AliMagF("MagneticFieldMap", ttl, 2, sclL3, sclDip, 10., map, path, 
+                            btype,beamenergy);
+  TGeoGlobalMagField::Instance()->SetField( fld );
+  TGeoGlobalMagField::Instance()->Lock();
+  //
   return kTRUE;
 }
 
-
 Bool_t AliReconstruction::InitGRP() {
   //------------------------------------
   // Initialization of the GRP entry 
@@ -889,7 +1010,11 @@ Bool_t AliReconstruction::InitGRP() {
        entry->SetOwner(0);
     }
 
-    AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
+    //    FIX ME: The unloading of GRP entry is temporarily disabled
+    //    because ZDC and VZERO are using it in order to initialize
+    //    their reconstructor objects. In the future one has to think
+    //    of propagating AliRunInfo to the reconstructors.
+    //    AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
   }
 
   if (!fGRPData) {
@@ -914,6 +1039,8 @@ Bool_t AliReconstruction::InitGRP() {
     AliError("GRP/GRP/Data entry:  missing value for the beam energy ! Using 0");
     beamEnergy = 0;
   }
+  // energy is provided in MeV*120
+  beamEnergy /= 120E3;
 
   TString runType = fGRPData->GetRunType();
   if (runType==AliGRPObject::GetInvalidString()) {
@@ -928,7 +1055,6 @@ Bool_t AliReconstruction::InitGRP() {
   }
 
   fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
-
   fRunInfo->Dump();
 
 
@@ -968,20 +1094,17 @@ Bool_t AliReconstruction::InitGRP() {
   AliInfo("===================================================================================");
 
   //*** Dealing with the magnetic field map
-  if (AliTracker::GetFieldMap()) {
-    AliInfo("Running with the externally set B field !");
-  } else {
+  if ( TGeoGlobalMagField::Instance()->IsLocked() ) {AliInfo("Running with the externally locked B field !");}
+  else {
     // Construct the field map out of the information retrieved from GRP.
-
     Bool_t ok = kTRUE;
-
     // L3
     Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
     if (l3Current == AliGRPObject::GetInvalidFloat()) {
       AliError("GRP/GRP/Data entry:  missing value for the L3 current !");
       ok = kFALSE;
     }
-
+    
     Char_t l3Polarity = fGRPData->GetL3Polarity();
     if (l3Polarity == AliGRPObject::GetInvalidChar()) {
       AliError("GRP/GRP/Data entry:  missing value for the L3 polarity !");
@@ -1001,57 +1124,19 @@ Bool_t AliReconstruction::InitGRP() {
       ok = kFALSE;
     }
 
-    /*
-    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;
-    }
-    */
+    // read special bits for the polarity convention and map type
+    Int_t  polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
+    Bool_t uniformB = fGRPData->IsUniformBMap();
 
     if (ok) { 
-       Float_t l3Cur=TMath::Abs(l3Current);
-       Float_t diCur=TMath::Abs(diCurrent);
-       Float_t l3Pol=l3Polarity;
-       //       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...");
-      }
+      if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1, 
+                       polConvention,uniformB,beamEnergy, beamType.Data()))
+       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...");
-    }
-
+    else AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
   }
-
+  
   //*** Get the diamond profiles from OCDB
   entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD");
   if (entry) {
@@ -1074,6 +1159,17 @@ Bool_t AliReconstruction::InitGRP() {
      AliError("No TPC diamond profile found in OCDB!");
   }
 
+  entry = AliCDBManager::Instance()->Get("GRP/Calib/CosmicTriggers");
+  if (entry) {
+    fListOfCosmicTriggers = dynamic_cast<THashTable*>(entry->GetObject());
+    entry->SetOwner(0);
+    AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
+  }
+
+  if (!fListOfCosmicTriggers) {
+    AliWarning("Can not get list of cosmic triggers from OCDB! Cosmic event specie will be effectively disabled!");
+  }
+
   return kTRUE;
 } 
 
@@ -1091,7 +1187,23 @@ Bool_t AliReconstruction::LoadCDB()
   }
   return kTRUE;
 }
+//_____________________________________________________________________________
+Bool_t AliReconstruction::LoadTriggerScalersCDB()
+{
+  AliCodeTimerAuto("");
 
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/Scalers");
+
+  if (entry) { 
+   
+       AliInfo("Found an AliTriggerRunScalers in GRP/CTP/Scalers, reading it");
+       fRunScalers = dynamic_cast<AliTriggerRunScalers*> (entry->GetObject());
+       entry->SetOwner(0);
+       if (fRunScalers->CorrectScalersOverflow() == 0) AliInfo("32bit Trigger counters corrected for overflow");
+
+  }
+  return kTRUE;
+}
 //_____________________________________________________________________________
 Bool_t AliReconstruction::Run(const char* input)
 {
@@ -1106,12 +1218,14 @@ Bool_t AliReconstruction::Run(const char* input)
     // Proof mode
     if (gProof) {
       gProof->AddInput(this);
-      TUrl outputFile;
-      outputFile.SetProtocol("root",kTRUE);
-      outputFile.SetHost(gSystem->HostName());
-      outputFile.SetFile(Form("%s/AliESDs.root",gSystem->pwd()));
-      AliInfo(Form("Output file with ESDs is %s",outputFile.GetUrl()));
-      gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",outputFile.GetUrl()));
+      if (!fESDOutput.IsValid()) {
+       fESDOutput.SetProtocol("root",kTRUE);
+       fESDOutput.SetHost(gSystem->HostName());
+       fESDOutput.SetFile(Form("%s/AliESDs.root",gSystem->pwd()));
+      }
+      AliInfo(Form("Output file with ESDs is %s",fESDOutput.GetUrl()));
+      gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",fESDOutput.GetUrl()));
+      gProof->SetParameter("PROOF_MaxSlavesPerNode", 9999);
       chain->SetProof();
       chain->Process("AliReconstruction");
     }
@@ -1253,21 +1367,29 @@ void AliReconstruction::Begin(TTree *)
   }
   AliSysInfo::AddStamp("LoadCDB");
 
+  if (!LoadTriggerScalersCDB()) {
+    Abort("LoadTriggerScalersCDB", TSelector::kAbortProcess);
+    return;
+  }
+  AliSysInfo::AddStamp("LoadTriggerScalersCDB");
+
+
   // Read the reconstruction parameters from OCDB
   if (!InitRecoParams()) {
     AliWarning("Not all detectors have correct RecoParam objects initialized");
   }
   AliSysInfo::AddStamp("InitRecoParams");
 
-  if (fInput) {
+  if (fInput && gProof) {
     if (reco) *reco = *this;
-    fInput->Add(gGeoManager);
+
+    gProof->AddInputData(gGeoManager,kTRUE);
     gGeoManager = NULL;
-    fInput->Add(const_cast<TMap*>(AliCDBManager::Instance()->GetEntryCache()));
+    gProof->AddInputData(const_cast<TMap*>(AliCDBManager::Instance()->GetEntryCache()),kTRUE);
     fInput->Add(new TParameter<Int_t>("RunNumber",AliCDBManager::Instance()->GetRun()));
-    AliMagF *magFieldMap = (AliMagF*)AliTracker::GetFieldMap();
+    AliMagF *magFieldMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
     magFieldMap->SetName("MagneticFieldMap");
-    fInput->Add(magFieldMap);
+    gProof->AddInputData(magFieldMap,kTRUE);
   }
 
 }
@@ -1299,7 +1421,7 @@ void AliReconstruction::SlaveBegin(TTree*)
       }
     }
     if (AliMagF *map = (AliMagF*)fInput->FindObject("MagneticFieldMap")) {
-      AliTracker::SetFieldMap(map,fUniformField);
+      TGeoGlobalMagField::Instance()->SetField(map);
     }
     if (TNamed *outputFileName = (TNamed *) fInput->FindObject("PROOF_OUTPUTFILE")) {
       outProofFile = new TProofOutputFile(gSystem->BaseName(TUrl(outputFileName->GetTitle()).GetFile()));
@@ -1318,13 +1440,6 @@ void AliReconstruction::SlaveBegin(TTree*)
  
   ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
 
-  // get vertexer
-  if (fRunVertexFinder && !CreateVertexer()) {
-    Abort("CreateVertexer", TSelector::kAbortProcess);
-    return;
-  }
-  AliSysInfo::AddStamp("CreateVertexer");
-
   // get trackers
   if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
     Abort("CreateTrackers", TSelector::kAbortProcess);
@@ -1409,37 +1524,8 @@ void AliReconstruction::SlaveBegin(TTree*)
   
   //QA
   //Initialize the QA and start of cycle 
-  if (fRunQA) {
-    fQASteer = new AliQADataMakerSteer("rec") ; 
-    fQASteer->SetActiveDetectors(fQADetectors) ; 
-    for (Int_t det = 0 ; det < AliQA::kNDET ; det++) {
-      fQASteer->SetCycleLength(AliQA::DETECTORINDEX_t(det), fQACycles[det]) ;  
-      if (fQAWriteExpert[det])
-        fQASteer->SetWriteExpert(AliQA::DETECTORINDEX_t(det)) ;
-    }
-    
-    if (!fRawReader && fQATasks.Contains(AliQA::kRAWS))
-      fQATasks.ReplaceAll(Form("%d",AliQA::kRAWS), "") ;
-    fQASteer->SetTasks(fQATasks) ; 
-    fQASteer->InitQADataMaker(AliCDBManager::Instance()->GetRun(), fRecoParam) ; 
-  }
-  
-  if (fRunGlobalQA) {
-    Bool_t sameCycle = kFALSE ;
-    if (!fQASteer) fQASteer = new AliQADataMakerSteer("rec") ; 
-    AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
-    AliInfo(Form("Initializing the global QA data maker"));
-    if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
-      qadm->StartOfCycle(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun(), sameCycle) ; 
-      TObjArray *arr=qadm->Init(AliQA::kRECPOINTS);
-      AliTracker::SetResidualsArray(arr);
-      sameCycle = kTRUE ; 
-    }
-    if (fQATasks.Contains(Form("%d", AliQA::kESDS))) {
-      qadm->StartOfCycle(AliQA::kESDS, AliCDBManager::Instance()->GetRun(), sameCycle) ; 
-      qadm->Init(AliQA::kESDS);
-    }
-  }
+  if (fRunQA || fRunGlobalQA) 
+    InitQA() ; 
 
   //Initialize the Plane Efficiency framework
   if (fRunPlaneEff && !InitPlaneEff()) {
@@ -1461,7 +1547,7 @@ Bool_t AliReconstruction::Process(Long64_t entry)
   AliCodeTimerAuto("");
 
   TTree *currTree = fChain->GetTree();
-  AliRawEvent *event = new AliRawEvent;
+  AliRawVEvent *event = NULL;
   currTree->SetBranchAddress("rawevent",&event);
   currTree->GetEntry(entry);
   fRawReader = new AliRawReaderRoot(event);
@@ -1506,9 +1592,11 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
 
   AliInfo(Form("processing event %d", iEvent));
 
+  fRunLoader->GetEvent(iEvent);
+
   // Fill Event-info object
   GetEventInfo();
-  fRecoParam.SetEventSpecie(fRunInfo,fEventInfo);
+  fRecoParam.SetEventSpecie(fRunInfo,fEventInfo,fListOfCosmicTriggers);
   AliInfo(Form("Current event specie: %s",fRecoParam.PrintEventSpecie()));
 
   // Set the reco-params
@@ -1518,18 +1606,22 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
       if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
       AliReconstructor *reconstructor = GetReconstructor(iDet);
       if (reconstructor && fRecoParam.GetDetRecoParamArray(iDet)) {
-       const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
-       reconstructor->SetRecoParam(par);
+        const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
+        reconstructor->SetRecoParam(par);
+       reconstructor->SetEventInfo(&fEventInfo);
+        if (fRunQA) {
+          AliQAManager::QAManager()->SetRecoParam(iDet, par) ; 
+          AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(par->GetEventSpecie())) ;
+        }
       }
     }
   }
 
-  fRunLoader->GetEvent(iEvent);
-
     // QA on single raw 
-    if (fRunQA) 
-                       fQASteer->RunOneEvent(fRawReader) ;  
-
+  if (fRunQA) {
+    AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
+    AliQAManager::QAManager()->RunOneEvent(fRawReader) ;  
+  }
     // local single event reconstruction
     if (!fRunLocalReconstruction.IsNull()) {
       TString detectors=fRunLocalReconstruction;
@@ -1570,6 +1662,13 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
       }
     }
 
+    // For Plane Efficiency: run the SPD trackleter
+    if (fRunPlaneEff && fSPDTrackleter) {
+      if (!RunSPDTrackleting(fesd)) {
+        if (fStopOnError) {CleanUp(); return kFALSE;}
+      }
+    }
+
     // Muon tracking
     if (!fRunTracking.IsNull()) {
       if (fRunMuonTracking) {
@@ -1612,6 +1711,7 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
   
     // fill Event header information from the RawEventHeader
     if (fRawReader){FillRawEventHeaderESD(fesd);}
+    if (fRawReader){FillRawEventHeaderESD(fhltesd);}
 
     // combined PID
     AliESDpid::MakePID(fesd);
@@ -1635,7 +1735,7 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
     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
+      const Double_t kMaxStep = 1;   //max step over the material
       Bool_t ok;
 
       AliESDtrack *track = fesd->GetTrack(itrack);
@@ -1744,14 +1844,16 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
     // write ESD
     if (fCleanESD) CleanESD(fesd);
 
-  if (fRunQA) 
-    fQASteer->RunOneEvent(fesd) ; 
-
+  if (fRunQA) {
+    AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
+    AliQAManager::QAManager()->RunOneEvent(fesd) ; 
+  }
   if (fRunGlobalQA) {
-      AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
-      if (qadm && fQATasks.Contains(Form("%d", AliQA::kESDS)))
-        qadm->Exec(AliQA::kESDS, fesd);
-    }
+    AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
+      qadm->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
+    if (qadm && fQATasks.Contains(Form("%d", AliQAv1::kESDS)))
+      qadm->Exec(AliQAv1::kESDS, fesd);
+  }
 
     if (fWriteESDfriend) {
       //      fesdf->~AliESDfriend();
@@ -1786,12 +1888,15 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
   
     fEventInfo.Reset();
     for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
-      if (fReconstructor[iDet])
+      if (fReconstructor[iDet]) {
        fReconstructor[iDet]->SetRecoParam(NULL);
+       fReconstructor[iDet]->SetEventInfo(NULL);
+      }
+      if (fTracker[iDet]) fTracker[iDet]->SetEventInfo(NULL);
     }
        
   if (fRunQA || fRunGlobalQA) 
-      fQASteer->Increment() ; 
+    AliQAManager::QAManager()->Increment() ; 
   
     return kTRUE;
 }
@@ -1846,7 +1951,7 @@ void AliReconstruction::SlaveTerminate()
     ftree->SetBranchStatus("ESDfriend*",0);
   // we want to have only one tree version number
   ftree->Write(ftree->GetName(),TObject::kOverwrite);
-  fhlttree->Write();
+  fhlttree->Write(fhlttree->GetName(),TObject::kOverwrite);
 
 // Finish with Plane Efficiency evaluation: before of CleanUp !!!
   if (fRunPlaneEff && !FinishPlaneEff()) {
@@ -1854,19 +1959,37 @@ void AliReconstruction::SlaveTerminate()
   }
 
   // End of cycle for the in-loop  
-  if (fRunQA) {
-    fQASteer->EndOfCycle() ;
-  }
+  if (fRunQA) 
+    AliQAManager::QAManager()->EndOfCycle() ;
+  
   if (fRunGlobalQA) {
-    AliQADataMaker *qadm = fQASteer->GetQADataMaker(AliQA::kGLOBAL);
+    AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
     if (qadm) {
-      if (fQATasks.Contains(Form("%d", AliQA::kRECPOINTS))) 
-        qadm->EndOfCycle(AliQA::kRECPOINTS);
-      if (fQATasks.Contains(Form("%d", AliQA::kESDS))) 
-        qadm->EndOfCycle(AliQA::kESDS);
+      if (fQATasks.Contains(Form("%d", AliQAv1::kRECPOINTS))) 
+        qadm->EndOfCycle(AliQAv1::kRECPOINTS);
+      if (fQATasks.Contains(Form("%d", AliQAv1::kESDS))) 
+        qadm->EndOfCycle(AliQAv1::kESDS);
       qadm->Finish();
     }
   }
+
+  if (fRunQA || fRunGlobalQA) {
+    if (fInput) { 
+      if (TNamed *outputFileName = (TNamed *) fInput->FindObject("PROOF_OUTPUTFILE")) {
+       TString qaOutputFile = outputFileName->GetTitle();
+       qaOutputFile.ReplaceAll(gSystem->BaseName(TUrl(outputFileName->GetTitle()).GetFile()),
+                               Form("Merged.%s.Data.root",AliQAv1::GetQADataFileName()));
+       TProofOutputFile *qaProofFile = new TProofOutputFile(Form("Merged.%s.Data.root",AliQAv1::GetQADataFileName()));
+       qaProofFile->SetOutputFileName(qaOutputFile.Data());
+       fOutput->Add(qaProofFile);
+       MergeQA(qaProofFile->GetFileName());
+      }
+    }
+    else {
+      MergeQA();
+    }
+  }
+
   gROOT->cd();
   CleanUp();
 }
@@ -1878,8 +2001,11 @@ void AliReconstruction::Terminate()
   // In case of empty events the tags will contain dummy values
   AliCodeTimerAuto("");
 
-  AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
-  esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData);
+  // Do not call the ESD tag creator in case of PROOF-based reconstruction
+  if (!fInput) {
+    AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
+    esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData, AliQAv1::Instance()->GetQA(), AliQAv1::Instance()->GetEventSpecies(), AliQAv1::kNDET, AliRecoParam::kNSpecies);
+  }
 
   // Cleanup of CDB manager: cache and active storages!
   AliCDBManager::Instance()->ClearCache();
@@ -1903,10 +2029,10 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
     // although the HLT loader is missing
     if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
       if (fRawReader) {
-       reconstructor->Reconstruct(fRawReader, NULL);
+        reconstructor->Reconstruct(fRawReader, NULL);
       } else {
-       TTree* dummy=NULL;
-       reconstructor->Reconstruct(dummy, NULL);
+        TTree* dummy=NULL;
+        reconstructor->Reconstruct(dummy, NULL);
       }
       continue;
     }
@@ -1941,21 +2067,24 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
       loader->LoadDigits("read");
       TTree* digitsTree = loader->TreeD();
       if (!digitsTree) {
-       AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
-       if (fStopOnError) return kFALSE;
+        AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
+        if (fStopOnError) return kFALSE;
       } else {
-       reconstructor->Reconstruct(digitsTree, clustersTree);
+        reconstructor->Reconstruct(digitsTree, clustersTree);
+        if (fRunQA) {
+          AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
+          AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, digitsTree) ; 
+        }
       }
       loader->UnloadDigits();
     }
-
-               TString detQAStr(fQADetectors) ; 
-               if (fRunQA) 
-                       fQASteer->RunOneEventInOneDetector(iDet, clustersTree) ; 
-    
-       loader->WriteRecPoints("OVERWRITE");
-       loader->UnloadRecPoints();
-       AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
+               if (fRunQA) {
+      AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
+                       AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, clustersTree) ; 
+    }
+    loader->WriteRecPoints("OVERWRITE");
+    loader->UnloadRecPoints();
+    AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
   }
   if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
     AliError(Form("the following detectors were not found: %s",
@@ -1965,64 +2094,106 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
   eventNr++;
   return kTRUE;
 }
-
 //_____________________________________________________________________________
-Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
+Bool_t AliReconstruction::RunSPDTrackleting(AliESDEvent*& esd)
 {
-// run the barrel tracking
+// run the SPD trackleting (for SPD efficiency purpouses)
 
   AliCodeTimerAuto("")
 
-  AliESDVertex* vertex = NULL;
   Double_t vtxPos[3] = {0, 0, 0};
-  Double_t vtxErr[3] = {0.07, 0.07, 0.1};
-  TArrayF mcVertex(3); 
+  Double_t vtxErr[3] = {0.0, 0.0, 0.0};
+/*
+  TArrayF mcVertex(3);
+  // if(MC)
   if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
     fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
     for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
   }
+*/
+  const AliESDVertex *vertex = esd->GetVertex();
+  if(!vertex){
+    AliWarning("Vertex not found");
+    return kFALSE;
+  }
+  vertex->GetXYZ(vtxPos);
+  vertex->GetSigmaXYZ(vtxErr);
+  if (fSPDTrackleter) {
+    AliInfo("running the SPD Trackleter for Plane Efficiency Evaluation");
 
-  if (fVertexer) {
-    AliInfo("running the ITS vertex finder");
-    if (fLoader[0]) {
-      fLoader[0]->LoadRecPoints();
-      TTree* cltree = fLoader[0]->TreeR();
-      if (cltree) {
-       if(fDiamondProfileSPD) fVertexer->SetVtxStart(fDiamondProfileSPD);
-       vertex = fVertexer->FindVertexForCurrentEvent(cltree);
-      }
-      else {
-       AliError("Can't get the ITS cluster tree");
-      }
-      fLoader[0]->UnloadRecPoints();
+    // load clusters
+    fLoader[0]->LoadRecPoints("read");
+    TTree* tree = fLoader[0]->TreeR();
+    if (!tree) {
+      AliError("Can't get the ITS cluster tree");
+      return kFALSE;
     }
-    else {
-      AliError("Can't get the ITS loader");
+    fSPDTrackleter->LoadClusters(tree);
+    fSPDTrackleter->SetVertex(vtxPos, vtxErr);
+    // run trackleting
+    if (fSPDTrackleter->Clusters2Tracks(esd) != 0) {
+      AliError("AliITSTrackleterSPDEff Clusters2Tracks failed");
+     // fLoader[0]->UnloadRecPoints();
+      return kFALSE;
     }
-    if(!vertex){
-      AliWarning("Vertex not found");
-      vertex = new AliESDVertex();
-      vertex->SetName("default");
+//fSPDTrackleter->UnloadRecPoints();
+  } else {
+    AliWarning("SPDTrackleter not available");
+    return kFALSE;
+  }
+  return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
+{
+// run the barrel tracking
+
+  AliCodeTimerAuto("")
+
+  AliVertexer *vertexer = CreateVertexer();
+  if (!vertexer) return kFALSE;
+
+  AliInfo("running the ITS vertex finder");
+  AliESDVertex* vertex = NULL;
+  if (fLoader[0]) {
+    fLoader[0]->LoadRecPoints();
+    TTree* cltree = fLoader[0]->TreeR();
+    if (cltree) {
+      if(fDiamondProfileSPD) vertexer->SetVtxStart(fDiamondProfileSPD);
+      vertex = vertexer->FindVertexForCurrentEvent(cltree);
     }
     else {
-      vertex->SetName("reconstructed");
+      AliError("Can't get the ITS cluster tree");
     }
-
-  } else {
-    AliInfo("getting the primary vertex from MC");
-    vertex = new AliESDVertex(vtxPos, vtxErr);
+    fLoader[0]->UnloadRecPoints();
   }
-
-  if (vertex) {
-    vertex->GetXYZ(vtxPos);
-    vertex->GetSigmaXYZ(vtxErr);
-  } else {
-    AliWarning("no vertex reconstructed");
-    vertex = new AliESDVertex(vtxPos, vtxErr);
+  else {
+    AliError("Can't get the ITS loader");
   }
+  if(!vertex){
+    AliWarning("Vertex not found");
+    vertex = new AliESDVertex();
+    vertex->SetName("default");
+  }
+  else {
+    vertex->SetName("reconstructed");
+  }
+
+  Double_t vtxPos[3];
+  Double_t vtxErr[3];
+  vertex->GetXYZ(vtxPos);
+  vertex->GetSigmaXYZ(vtxErr);
+
   esd->SetPrimaryVertexSPD(vertex);
+  AliESDVertex *vpileup = NULL;
+  Int_t novertices = 0;
+  vpileup = vertexer->GetAllVertices(novertices);
+  if(novertices>1){
+    for (Int_t kk=1; kk<novertices; kk++)esd->AddPileupVertexSPD(&vpileup[kk]);
+  }
   // if SPD multiplicity has been determined, it is stored in the ESD
-  AliMultiplicity *mult = fVertexer->GetMultiplicity();
+  AliMultiplicity *mult = vertexer->GetMultiplicity();
   if(mult)esd->SetMultiplicity(mult);
 
   for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
@@ -2030,6 +2201,8 @@ Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
   }  
   delete vertex;
 
+  delete vertexer;
+
   return kTRUE;
 }
 
@@ -2149,6 +2322,16 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
 
   AliInfo("running tracking");
 
+  // Set the event info which is used
+  // by the trackers in order to obtain
+  // information about read-out detectors,
+  // trigger etc.
+  AliDebug(1, "Setting event info");
+  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
+    if (!fTracker[iDet]) continue;
+    fTracker[iDet]->SetEventInfo(&fEventInfo);
+  }
+
   //Fill the ESD with the T0 info (will be used by the TOF) 
   if (fReconstructor[11] && fLoader[11]) {
     fLoader[11]->LoadRecPoints("READ");
@@ -2199,8 +2382,8 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
       AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
       tree = fLoader[iDet]->TreeR();
       if (!tree) {
-       AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
-       return kFALSE;
+        AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
+        return kFALSE;
       }
       fTracker[iDet]->LoadClusters(tree); 
       AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
@@ -2208,8 +2391,18 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
 
     // run tracking
     if (iDet>1) // start filling residuals for the "outer" detectors
-    if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);     
-
+      if (fRunGlobalQA) {
+        AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);     
+        TObjArray ** arr = AliTracker::GetResidualsArray() ; 
+       if (arr) {
+         AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
+         TObjArray * elem = arr[AliRecoParam::AConvert(es)];
+         if ( elem && (! elem->At(0)) ) {
+           AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
+           if (qadm) qadm->InitRecPointsForTracker() ; 
+         }
+       }
+      }
     if (fTracker[iDet]->PropagateBack(esd) != 0) {
       AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
       //      return kFALSE;
@@ -2228,7 +2421,7 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
     AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
   }
   //stop filling residuals for the "outer" detectors
-  if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);     
+  if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);     
 
   // pass 3: TRD + TPC + ITS refit inwards
 
@@ -2238,8 +2431,19 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
 
     // run tracking
     if (iDet<2) // start filling residuals for TPC and ITS
-    if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);     
-
+      if (fRunGlobalQA) {
+        AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);     
+        TObjArray ** arr = AliTracker::GetResidualsArray() ; 
+       if (arr) {
+         AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
+         TObjArray * elem = arr[AliRecoParam::AConvert(es)];
+         if ( elem && (! elem->At(0)) ) {
+           AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
+           if (qadm) qadm->InitRecPointsForTracker() ; 
+         }
+       }
+      }
+    
     if (fTracker[iDet]->RefitInward(esd) != 0) {
       AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
       //      return kFALSE;
@@ -2266,7 +2470,7 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
     AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
   }
   // stop filling residuals for TPC and ITS
-  if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);     
+  if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);     
 
   eventNr++;
   return kTRUE;
@@ -2375,19 +2579,33 @@ Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
       if (esd->GetBunchCrossNumber() != input.GetBCID())
        AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
                      input.GetBCID(),esd->GetBunchCrossNumber()));
+      AliESDHeader* esdheader = esd->GetHeader();
+      esdheader->SetL0TriggerInputs(input.GetL0Inputs());
+      esdheader->SetL1TriggerInputs(input.GetL1Inputs());
+      esdheader->SetL2TriggerInputs(input.GetL2Inputs());
+      // IR
+      UInt_t orbit=input.GetOrbitID();
+       for(Int_t i=0 ; i<input.GetNIRs() ; i++ )
+          if(TMath::Abs(Int_t(orbit-(input.GetIR(i))->GetOrbit()))<=1){
+            esdheader->AddTriggerIR(input.GetIR(i));
+         }
     }
-
-  // Here one has to add the filling of trigger inputs and
-  // interaction records
-  // ...
+  }
+  //Scalers
+  //fRunScalers->Print();
+  if(fRunScalers && fRunScalers->CheckRunScalers()){
+     AliTimeStamp* timestamp = new AliTimeStamp(esd->GetOrbitNumber(), esd->GetPeriodNumber(), esd->GetBunchCrossNumber());
+     //AliTimeStamp* timestamp = new AliTimeStamp(10308000, 0, (ULong64_t)486238);
+     AliESDHeader* esdheader = fesd->GetHeader();
+     for(Int_t i=0;i<50;i++){
+          if((1<<i) & esd->GetTriggerMask()){
+          AliTriggerScalersESD* scalesd = fRunScalers->GetScalersForEventClass( timestamp, i+1);
+          if(scalesd)esdheader->SetTriggerScalersRecord(scalesd);
+        }
+     }
   }
   return kTRUE;
 }
-
-
-
-
-
 //_____________________________________________________________________________
 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
 {
@@ -2509,6 +2727,7 @@ AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
     if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
       const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
       fReconstructor[iDet]->SetRecoParam(par);
+      fReconstructor[iDet]->SetRunInfo(fRunInfo);
     }
     return fReconstructor[iDet];
   }
@@ -2590,26 +2809,28 @@ AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
   if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
     const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
     reconstructor->SetRecoParam(par);
+    reconstructor->SetRunInfo(fRunInfo);
   }
   return reconstructor;
 }
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::CreateVertexer()
+AliVertexer* AliReconstruction::CreateVertexer()
 {
 // create the vertexer
+// Please note that the caller is the owner of the
+// vertexer
 
-  fVertexer = NULL;
+  AliVertexer* vertexer = NULL;
   AliReconstructor* itsReconstructor = GetReconstructor(0);
-  if (itsReconstructor) {
-    fVertexer = itsReconstructor->CreateVertexer();
+  if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) || fRunTracking.Contains("ITS"))) {
+    vertexer = itsReconstructor->CreateVertexer();
   }
-  if (!fVertexer) {
+  if (!vertexer) {
     AliWarning("couldn't create a vertexer for ITS");
-    if (fStopOnError) return kFALSE;
   }
 
-  return kTRUE;
+  return vertexer;
 }
 
 //_____________________________________________________________________________
@@ -2660,20 +2881,12 @@ void AliReconstruction::CleanUp()
   delete fRunInfo;
   fRunInfo = NULL;
 
-  delete fVertexer;
-  fVertexer = NULL;
+  delete fSPDTrackleter;
+  fSPDTrackleter = NULL;
 
   delete ftVertexer;
   ftVertexer = NULL;
   
-  if(!(AliCDBManager::Instance()->GetCacheFlag())) {
-    delete fDiamondProfileSPD;
-    fDiamondProfileSPD = NULL;
-    delete fDiamondProfile;
-    fDiamondProfile = NULL;
-    delete fDiamondProfileTPC;
-    fDiamondProfileTPC = NULL;
-  }
   delete fRunLoader;
   fRunLoader = NULL;
   delete fRawReader;
@@ -2686,6 +2899,12 @@ void AliReconstruction::CleanUp()
     delete ffile;
     ffile = NULL;
   }
+
+  if (AliQAManager::QAManager())
+    AliQAManager::QAManager()->ShowQA() ; 
+  AliQAManager::Destroy() ; 
+  
+  TGeoGlobalMagField::Instance()->SetField(NULL);
 }
 
 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
@@ -2699,6 +2918,7 @@ void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
       AliESDtrack *track = esd->GetTrack(itrack);
       Int_t nsp = 0;
       Int_t idx[200];
+      for (Int_t i=0; i<200; ++i) idx[i] = -1; //PH avoid uninitialized values
       for (Int_t iDet = 5; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
           nsp += track->GetNcls(iDet);
 
@@ -2741,6 +2961,7 @@ void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
            } 
            isp2++;
            if (!isvalid) continue;
+           if (iDet==0 && (isp-1)>=6) p.SetExtra();
            sp->AddPoint(isptrack,&p); isptrack++;
          }
        }       
@@ -2776,36 +2997,37 @@ void AliReconstruction::CheckQA()
 // check the QA of SIM for this run and remove the detectors 
 // with status Fatal
   
-       TString newRunLocalReconstruction ; 
-       TString newRunTracking ;
-       TString newFillESD ;
-        
-       for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
-               TString detName(AliQA::GetDetName(iDet)) ;
-               AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ; 
-               if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
-                               AliInfo(Form("QA status for %s in Hits and/or SDIGITS  and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
-               } else {
-                       if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) || 
-                                       fRunLocalReconstruction.Contains("ALL") )  {
-                               newRunLocalReconstruction += detName ; 
-                               newRunLocalReconstruction += " " ;                      
-                       }
-                       if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) || 
-                                       fRunTracking.Contains("ALL") )  {
-                               newRunTracking += detName ; 
-                               newRunTracking += " " ;                         
-                       }
-                       if ( fFillESD.Contains(AliQA::GetDetName(iDet)) || 
-                                       fFillESD.Contains("ALL") )  {
-                               newFillESD += detName ; 
-                               newFillESD += " " ;                     
-                       }
-               }
-       }
-       fRunLocalReconstruction = newRunLocalReconstruction ; 
-       fRunTracking            = newRunTracking ; 
-       fFillESD                = newFillESD ; 
+//     TString newRunLocalReconstruction ; 
+//     TString newRunTracking ;
+//     TString newFillESD ;
+//      
+//     for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
+//             TString detName(AliQAv1::GetDetName(iDet)) ;
+//             AliQAv1 * qa = AliQAv1::Instance(AliQAv1::DETECTORINDEX_t(iDet)) ;       
+//      if ( qa->IsSet(AliQAv1::DETECTORINDEX_t(iDet), AliQAv1::kSIM, specie, AliQAv1::kFATAL)) {
+//        AliInfo(Form("QA status for %s %s in Hits and/or SDIGITS  and/or Digits was Fatal; No reconstruction performed", 
+//                   detName.Data(), AliRecoParam::GetEventSpecieName(es))) ;
+//                     } else {
+//                     if ( fRunLocalReconstruction.Contains(AliQAv1::GetDetName(iDet)) || 
+//                                     fRunLocalReconstruction.Contains("ALL") )  {
+//                             newRunLocalReconstruction += detName ; 
+//                             newRunLocalReconstruction += " " ;                      
+//                     }
+//                     if ( fRunTracking.Contains(AliQAv1::GetDetName(iDet)) || 
+//                                     fRunTracking.Contains("ALL") )  {
+//                             newRunTracking += detName ; 
+//                             newRunTracking += " " ;                         
+//                     }
+//                     if ( fFillESD.Contains(AliQAv1::GetDetName(iDet)) || 
+//                                     fFillESD.Contains("ALL") )  {
+//                             newFillESD += detName ; 
+//                             newFillESD += " " ;                     
+//                     }
+//             }
+//     }
+//     fRunLocalReconstruction = newRunLocalReconstruction ; 
+//     fRunTracking            = newRunTracking ; 
+//     fFillESD                = newFillESD ; 
 }
 
 //_____________________________________________________________________________
@@ -2833,10 +3055,10 @@ Bool_t AliReconstruction::FinishPlaneEff() {
  //  Return: kTRUE if all operations have been done properly, kFALSE otherwise
  //
  Bool_t ret=kFALSE;
- //for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
+ //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(fTracker[iDet]) {
+   if(fTracker[iDet] && fTracker[iDet]->GetPlaneEff()) {
       AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
       TString name=planeeff->GetName();
       name+=".root";
@@ -2849,6 +3071,15 @@ Bool_t AliReconstruction::FinishPlaneEff() {
         ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
       }
    }
+   if(fSPDTrackleter) {
+     AliPlaneEff *planeeff=fSPDTrackleter->GetPlaneEff();
+      TString name="AliITSPlaneEffSPDtracklet.root";
+      TFile* pefile = TFile::Open(name, "RECREATE");
+      ret=(Bool_t)planeeff->Write();
+      pefile->Close();
+      AliESDEvent *dummy=NULL;
+      ret=(Bool_t)fSPDTrackleter->PostProcess(dummy); // take care of writing other files
+   }
  }
  return ret;
 }
@@ -2857,7 +3088,7 @@ Bool_t AliReconstruction::InitPlaneEff() {
 //
  // Here execute all the necessary operations, before of the tracking phase,
  // for the evaluation of PlaneEfficiencies, in case required for some detectors.
- // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency 
+ // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
  // which should be updated/recalculated.
  //
  // This Preliminary version will work only FOR ITS !!!!!
@@ -2866,7 +3097,17 @@ Bool_t AliReconstruction::InitPlaneEff() {
  //  Input: none
  //  Return: kTRUE if all operations have been done properly, kFALSE otherwise
  //
- AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));
+ AliWarning(Form("Implementation of this method not yet completed !! Method return kTRUE"));
+
+  fSPDTrackleter = NULL;
+  AliReconstructor* itsReconstructor = GetReconstructor(0);
+  if (itsReconstructor) {
+    fSPDTrackleter = itsReconstructor->CreateTrackleter(); // this is NULL unless required in RecoParam
+  }
+  if (fSPDTrackleter) { 
+    AliInfo("Trackleter for SPD has been created");
+  }
+
  return kTRUE;
 }
 
@@ -2902,7 +3143,7 @@ void AliReconstruction::RunAliEVE()
   // successful initialization of AliEVE.
 
   AliInfo("Running AliEVE...");
-  gROOT->ProcessLine(Form("AliEveEventManager::GetMaster()->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p);",fRunLoader,fRawReader,fesd));
+  gROOT->ProcessLine(Form("AliEveEventManager::GetMaster()->SetEvent((AliRunLoader*)0x%lx,(AliRawReader*)0x%lx,(AliESDEvent*)0x%lx,(AliESDfriend*)0x%lx);",fRunLoader,fRawReader,fesd,fesdf));
   gSystem->Run();
 }
 
@@ -2910,7 +3151,7 @@ void AliReconstruction::RunAliEVE()
 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
+       // and a selected set of tasks among RAWS, DIGITSR, RECPOINTS and ESDS
        // all selected detectors run the same selected tasks
        
        if (!detAndAction.Contains(":")) {
@@ -2924,16 +3165,18 @@ Bool_t AliReconstruction::SetRunQA(TString detAndAction)
                fQADetectors = fFillESD ; 
                fQATasks   = detAndAction(colon+1, detAndAction.Sizeof() ) ; 
        if (fQATasks.Contains("ALL") ) {
-               fQATasks = Form("%d %d %d", AliQA::kRAWS, AliQA::kRECPOINTS, AliQA::kESDS) ; 
+               fQATasks = Form("%d %d %d %d", AliQAv1::kRAWS, AliQAv1::kDIGITSR, AliQAv1::kRECPOINTS, AliQAv1::kESDS) ; 
        } else {
                fQATasks.ToUpper() ; 
                TString tempo("") ; 
                if ( fQATasks.Contains("RAW") ) 
-                       tempo = Form("%d ", AliQA::kRAWS) ; 
+                       tempo = Form("%d ", AliQAv1::kRAWS) ; 
+               if ( fQATasks.Contains("DIGIT") ) 
+                       tempo += Form("%d ", AliQAv1::kDIGITSR) ; 
                if ( fQATasks.Contains("RECPOINT") ) 
-                       tempo += Form("%d ", AliQA::kRECPOINTS) ; 
+                       tempo += Form("%d ", AliQAv1::kRECPOINTS) ; 
                if ( fQATasks.Contains("ESD") ) 
-                       tempo += Form("%d ", AliQA::kESDS) ; 
+                       tempo += Form("%d ", AliQAv1::kESDS) ; 
                fQATasks = tempo ; 
                if (fQATasks.IsNull()) {
                        AliInfo("No QA requested\n")  ;
@@ -2942,9 +3185,10 @@ Bool_t AliReconstruction::SetRunQA(TString detAndAction)
                }
        }       
        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)) ;  
+       tempo.ReplaceAll(Form("%d", AliQAv1::kRAWS), AliQAv1::GetTaskName(AliQAv1::kRAWS))      ;
+       tempo.ReplaceAll(Form("%d", AliQAv1::kDIGITSR), AliQAv1::GetTaskName(AliQAv1::kDIGITSR)) ;      
+       tempo.ReplaceAll(Form("%d", AliQAv1::kRECPOINTS), AliQAv1::GetTaskName(AliQAv1::kRECPOINTS)) ;  
+       tempo.ReplaceAll(Form("%d", AliQAv1::kESDS), AliQAv1::GetTaskName(AliQAv1::kESDS)) ;    
        AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;  
        fRunQA = kTRUE ;
        return kTRUE; 
@@ -2958,6 +3202,40 @@ Bool_t AliReconstruction::InitRecoParams()
 
   Bool_t isOK = kTRUE;
 
+  if (fRecoParam.GetDetRecoParamArray(kNDetectors)) {
+    AliInfo("Using custom GRP reconstruction parameters");
+  }
+  else {
+    AliInfo("Loading GRP reconstruction parameter objects");
+
+    AliCDBPath path("GRP","Calib","RecoParam");
+    AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
+    if(!entry){ 
+      AliWarning("Couldn't find GRP RecoParam entry in OCDB");
+      isOK = kFALSE;
+    }
+    else {
+      TObject *recoParamObj = entry->GetObject();
+      if (dynamic_cast<TObjArray*>(recoParamObj)) {
+       // GRP has a normal TobjArray of AliDetectorRecoParam objects
+       // Registering them in AliRecoParam
+       fRecoParam.AddDetRecoParamArray(kNDetectors,dynamic_cast<TObjArray*>(recoParamObj));
+      }
+      else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
+       // GRP has only onse set of reco parameters
+       // Registering it in AliRecoParam
+       AliInfo("Single set of GRP reconstruction parameters found");
+       dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
+       fRecoParam.AddDetRecoParam(kNDetectors,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
+      }
+      else {
+       AliError("No valid GRP RecoParam object found in the OCDB");
+       isOK = kFALSE;
+      }
+      entry->SetOwner(0);
+    }
+  }
+
   TString detStr = fLoadCDB;
   for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
 
@@ -2995,7 +3273,11 @@ Bool_t AliReconstruction::InitRecoParams()
        isOK = kFALSE;
       }
       entry->SetOwner(0);
-      AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
+      //      FIX ME: We have to disable the unloading of reco-param CDB
+      //      entries because QA framework is using them. Has to be fix in
+      //      a way that the QA takes the objects already constructed in
+      //      this method.
+      //      AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
     }
   }
 
@@ -3036,6 +3318,11 @@ Bool_t AliReconstruction::GetEventInfo()
     if (fRunLoader && (!fRunLoader->LoadTrigger())) {
       aCTP = fRunLoader->GetTrigger();
       fEventInfo.SetTriggerMask(aCTP->GetClassMask());
+      // get inputs from actp - just get
+      AliESDHeader* esdheader = fesd->GetHeader();
+      esdheader->SetL0TriggerInputs(aCTP->GetL0TriggerInputs());
+      esdheader->SetL1TriggerInputs(aCTP->GetL1TriggerInputs());
+      esdheader->SetL2TriggerInputs(aCTP->GetL2TriggerInputs());
       fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
     }
     else {
@@ -3062,7 +3349,7 @@ Bool_t AliReconstruction::GetEventInfo()
       Int_t trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
       fesd->SetTriggerClass(trclass->GetName(),trindex);
       if (fRawReader) fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
-      if (trmask & (1 << trindex)) {
+      if (trmask & (1ull << trindex)) {
        trclasses += " ";
        trclasses += trclass->GetName();
        trclasses += " ";