]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
Adding brand new 4 physics partition type - PHYSICS_X. Cross-checked and confirmed...
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index ff6e2b5f3f8133e186cb64c4ec10d2a7b7fe5b76..f82eef660a1372fe50a06b997b1457f8379ee98f 100644 (file)
 #include <TProofOutputFile.h>
 #include <TROOT.h>
 #include <TSystem.h>
+#include <THashTable.h>
+#include <TGrid.h>
+#include <TMessage.h>
 
 #include "AliAlignObj.h"
 #include "AliCDBEntry.h"
 #include "AliMultiplicity.h"
 #include "AliPID.h"
 #include "AliPlaneEff.h"
-#include "AliQA.h"
+#include "AliQAv1.h"
 #include "AliQADataMakerRec.h" 
 #include "AliQAManager.h"
-#include "AliRawEvent.h"
+#include "AliRawVEvent.h"
 #include "AliRawEventHeaderBase.h"
 #include "AliRawHLTManager.h"
 #include "AliRawReaderDate.h"
 #include "AliTracker.h"
 #include "AliTriggerClass.h"
 #include "AliTriggerCluster.h"
+#include "AliTriggerIR.h"
 #include "AliTriggerConfiguration.h"
 #include "AliV0vertexer.h"
 #include "AliVertexer.h"
@@ -194,7 +198,6 @@ const char* AliReconstruction::fgkDetectorName[AliReconstruction::kNDetectors] =
 //_____________________________________________________________________________
 AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   TSelector(),
-  fUniformField(kFALSE),
   fRunVertexFinder(kTRUE),
   fRunVertexFinderTracks(kTRUE),
   fRunHLTTracking(kFALSE),
@@ -219,6 +222,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fUseTrackingErrorsForAlignment(""),
   fGAliceFileName(gAliceFilename),
   fRawInput(""),
+  fESDOutput(""),
   fEquipIdMap(""),
   fFirstEvent(0),
   fLastEvent(-1),
@@ -229,6 +233,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fUseHLTData(),
   fRunInfo(NULL),
   fEventInfo(),
+  fRunScalers(NULL),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -241,6 +246,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fDiamondProfileSPD(NULL),
   fDiamondProfile(NULL),
   fDiamondProfileTPC(NULL),
+  fListOfCosmicTriggers(NULL),
   
   fGRPData(NULL),
 
@@ -251,7 +257,6 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fInitCDBCalled(kFALSE),
   fSetRunNumberFromDataCalled(kFALSE),
   fQADetectors("ALL"), 
-  fQAManager(NULL),  
   fQATasks("ALL"), 
   fRunQA(kTRUE),  
   fRunGlobalQA(kTRUE),
@@ -279,7 +284,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 ; 
   }
@@ -290,7 +295,6 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
 //_____________________________________________________________________________
 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   TSelector(),
-  fUniformField(rec.fUniformField),
   fRunVertexFinder(rec.fRunVertexFinder),
   fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
   fRunHLTTracking(rec.fRunHLTTracking),
@@ -315,6 +319,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),
@@ -325,6 +330,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fUseHLTData(rec.fUseHLTData),
   fRunInfo(NULL),
   fEventInfo(),
+  fRunScalers(NULL),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -337,6 +343,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fDiamondProfileSPD(rec.fDiamondProfileSPD),
   fDiamondProfile(rec.fDiamondProfile),
   fDiamondProfileTPC(rec.fDiamondProfileTPC),
+  fListOfCosmicTriggers(NULL),
   
   fGRPData(NULL),
 
@@ -347,7 +354,6 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fInitCDBCalled(rec.fInitCDBCalled),
   fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
   fQADetectors(rec.fQADetectors), 
-  fQAManager(NULL),  
   fQATasks(rec.fQATasks), 
   fRunQA(rec.fRunQA),  
   fRunGlobalQA(rec.fRunGlobalQA),
@@ -378,7 +384,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] ; 
   }
@@ -400,7 +406,6 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
 // TSelector members should not be touched
   if(&rec == this) return *this;
 
-  fUniformField          = rec.fUniformField;
   fRunVertexFinder       = rec.fRunVertexFinder;
   fRunVertexFinderTracks = rec.fRunVertexFinderTracks;
   fRunHLTTracking        = rec.fRunHLTTracking;
@@ -425,6 +430,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;
@@ -443,6 +449,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;
@@ -455,7 +465,7 @@ 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] ;
   } 
@@ -469,6 +479,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());
@@ -481,7 +494,6 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
   fInitCDBCalled               = rec.fInitCDBCalled;
   fSetRunNumberFromDataCalled  = rec.fSetRunNumberFromDataCalled;
   fQADetectors                 = rec.fQADetectors;
-  fQAManager                     = NULL;  
   fQATasks                     = rec.fQATasks; 
   fRunQA                       = rec.fRunQA;  
   fRunGlobalQA                 = rec.fRunGlobalQA;
@@ -510,14 +522,19 @@ AliReconstruction::~AliReconstruction()
 // clean up
 
   CleanUp();
+  if (fListOfCosmicTriggers) {
+    fListOfCosmicTriggers->Delete();
+    delete fListOfCosmicTriggers;
+  }
   delete fGRPData;
+  delete fRunScalers;
   fOptions.Delete();
   if (fAlignObjArray) {
     fAlignObjArray->Delete();
     delete fAlignObjArray;
   }
   fSpecCDBUri.Delete();
-  delete fQAManager;
+
   AliCodeTimer::Instance()->Print();
 }
 
@@ -530,16 +547,16 @@ void AliReconstruction::InitQA()
   if (fInitQACalled) return;
   fInitQACalled = kTRUE;
   
-  fQAManager = AliQAManager::QAManager("rec") ; 
+  AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kRECMODE) ; 
   if (fWriteQAExpertData)
-    fQAManager->SetWriteExpert() ; 
+    qam->SetWriteExpert() ; 
  
-  if (fQAManager->IsDefaultStorageSet()) {
+  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 = fQAManager->GetDefaultStorage()->GetURI();
+    fQARefUri = qam->GetDefaultStorage()->GetURI();
   } else {
     if (fQARefUri.Length() > 0) {
        AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
@@ -553,48 +570,44 @@ void AliReconstruction::InitQA()
         AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                
       }
-    fQAManager->SetDefaultStorage(fQARefUri);
+    qam->SetDefaultStorage(fQARefUri);
   }
   
   if (fRunQA) {
-  fQAManager->SetActiveDetectors(fQADetectors) ; 
-  for (Int_t det = 0 ; det < AliQA::kNDET ; det++) {
-    fQAManager->SetCycleLength(AliQA::DETECTORINDEX_t(det), fQACycles[det]) ;  
-    fQAManager->SetWriteExpert(AliQA::DETECTORINDEX_t(det)) ;
+  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 && fQATasks.Contains(AliQA::kRAWS))
-    fQATasks.ReplaceAll(Form("%d",AliQA::kRAWS), "") ;
-  fQAManager->SetTasks(fQATasks) ; 
-  fQAManager->InitQADataMaker(AliCDBManager::Instance()->GetRun()) ; 
+  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 = fQAManager->GetQADataMaker(AliQA::kGLOBAL);
+    AliQADataMaker *qadm = qam->GetQADataMaker(AliQAv1::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);
+    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", AliQA::kESDS))) {
-      qadm->StartOfCycle(AliQA::kESDS, AliCDBManager::Instance()->GetRun(), sameCycle) ; 
-      qadm->Init(AliQA::kESDS);
+    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()
+void AliReconstruction::MergeQA(const char *fileName)
 {
   //Initialize the QA and start of cycle 
   AliCodeTimerAuto("") ;
-  if ( ! fQAManager ) {
-    AliFatal("Hum... this should not happen") ; 
-  } else { 
-   fQAManager->Merge(AliCDBManager::Instance()->GetRun()) ; 
-  }
+  AliQAManager::QAManager()->Merge(AliCDBManager::Instance()->GetRun(),fileName) ; 
   AliSysInfo::AddStamp("MergeQA") ; 
 }
   
@@ -662,7 +675,7 @@ void AliReconstruction::SetQARefDefaultStorage(const char* uri) {
   // Activate it later within the Run() method
   
   fQARefUri = uri;
-  AliQA::SetQARefStorage(fQARefUri.Data()) ;
+  AliQAv1::SetQARefStorage(fQARefUri.Data()) ;
   
 }
 //_____________________________________________________________________________
@@ -852,6 +865,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)
 {
@@ -887,15 +909,16 @@ void AliReconstruction::SetRecoParam(const char* detector, AliDetectorRecoParam
 
 //_____________________________________________________________________________
 Bool_t AliReconstruction::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Pol, 
-                                     Float_t diPol, Float_t beamenergy, 
-                                     const Char_t *beamtype, const Char_t *path) 
+                                 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)
@@ -904,51 +927,46 @@ Bool_t AliReconstruction::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Po
   const Float_t tolerance=0.03; // relative current tolerance
   const Float_t zero=77.;       // "zero" current (A)
   //
-  TString s=(l3Pol < 0) ? "L3: -" : "L3: +";
-  //
-  AliMagF::BMap_t map = AliMagF::k5kG;
-  //
-  double fcL3,fcDip;
+  AliMagF::BMap_t map;
+  double sclL3,sclDip;
   //
   l3Cur = TMath::Abs(l3Cur);
-  if (TMath::Abs(l3Cur-l3NominalCurrent1)/l3NominalCurrent1 < tolerance) {
-    fcL3 = l3Cur/l3NominalCurrent1;
-    map  = AliMagF::k5kG;
-    s   += "0.5 T;  ";
-  } else if (TMath::Abs(l3Cur-l3NominalCurrent2)/l3NominalCurrent2 < tolerance) {
-    fcL3 = l3Cur/l3NominalCurrent2;
-    map  = AliMagF::k2kG;
-    s   += "0.2 T;  ";
-  } else if (l3Cur <= zero) {
-    fcL3 = 0;
-    map  = AliMagF::k5kGUniform;
-    s   += "0.0 T;  ";
-    fUniformField=kTRUE;        // track with the uniform (zero) B field
-  } else {
-    AliError(Form("Wrong L3 current (%f A)!",l3Cur));
-    return kFALSE;
+  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;
+    }
   }
   //
-  diCur = TMath::Abs(diCur);
-  if (TMath::Abs(diCur-diNominalCurrent)/diNominalCurrent < tolerance) {
-    // 3% current tolerance...
-    fcDip = diCur/diNominalCurrent;
-    s    += "Dipole ON";
-  } else if (diCur <= zero) { // some small current..
-    fcDip = 0.;
-    s    += "Dipole OFF";
-  } else {
-    AliError(Form("Wrong dipole current (%f A)!",diCur));
-    return kFALSE;
+  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 (l3Pol!=diPol && (map==AliMagF::k5kG || map==AliMagF::k2kG) && fcDip!=0) {
-    AliError("L3 and Dipole polarities must be the same");
+  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) in %s convention",
+                 l3Pol>0?'+':'-',diPol>0?'+':'-',convention==AliMagF::kConvDCS2008?"DCS2008":"LHC"));
     return kFALSE;
   }
   //
-  if (l3Pol<0) fcL3  = -fcL3;
-  if (diPol<0) fcDip = -fcDip;
+  if (l3Pol<0) sclL3  = -sclL3;
+  if (diPol<0) sclDip = -sclDip;
   //
   AliMagF::BeamType_t btype = AliMagF::kNoBeamField;
   TString btypestr = beamtype;
@@ -957,11 +975,16 @@ Bool_t AliReconstruction::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Po
   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));
-  }
-  
-  AliMagF* fld = new AliMagF("MagneticFieldMap", s.Data(), 2, fcL3, fcDip, 10., map, path, 
+  else AliInfo(Form("Assume no LHC magnet field for the beam type %s, ",beamtype));
+  //
+  char ttl[80];
+  sprintf(ttl,"L3: %+5d Dip: %+4d kA; %s | Polarities in %s convention",(int)TMath::Sign(l3Cur,float(sclL3)),
+         (int)TMath::Sign(diCur,float(sclDip)),uniform ? " Constant":"",
+         convention==AliMagF::kConvLHC ? "LHC":"DCS2008");
+  // LHC and DCS08 conventions have opposite dipole polarities
+  if ( AliMagF::GetPolarityConvention() != convention) sclDip = -sclDip;
+  //
+  AliMagF* fld = new AliMagF("MagneticFieldMap", ttl, 2, sclL3, sclDip, 10., map, path, 
                             btype,beamenergy);
   TGeoGlobalMagField::Instance()->SetField( fld );
   TGeoGlobalMagField::Instance()->Lock();
@@ -969,7 +992,6 @@ Bool_t AliReconstruction::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Po
   return kTRUE;
 }
 
-
 Bool_t AliReconstruction::InitGRP() {
   //------------------------------------
   // Initialization of the GRP entry 
@@ -993,7 +1015,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) {
@@ -1018,8 +1044,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;
+  // LHC: "multiply by 120 to get the energy in MeV"
+  beamEnergy *= 0.120;
 
   TString runType = fGRPData->GetRunType();
   if (runType==AliGRPObject::GetInvalidString()) {
@@ -1073,8 +1099,17 @@ Bool_t AliReconstruction::InitGRP() {
   AliInfo("===================================================================================");
 
   //*** Dealing with the magnetic field map
-  if ( TGeoGlobalMagField::Instance()->IsLocked() ) {AliInfo("Running with the externally locked B field !");}
-  else {
+  if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
+    if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
+      AliInfo("ExpertMode!!! GRP information will be ignored !");
+      AliInfo("ExpertMode!!! Running with the externally locked B field !");
+    }
+    else {
+      AliInfo("Destroying existing B field instance!");
+      delete TGeoGlobalMagField::Instance();
+    }    
+  }
+  if ( !TGeoGlobalMagField::Instance()->IsLocked() ) {
     // Construct the field map out of the information retrieved from GRP.
     Bool_t ok = kTRUE;
     // L3
@@ -1103,42 +1138,17 @@ 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) { 
-      if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1) )
+      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...");
-    
   }
   
   //*** Get the diamond profiles from OCDB
@@ -1163,6 +1173,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;
 } 
 
@@ -1180,7 +1201,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)
 {
@@ -1194,13 +1231,22 @@ Bool_t AliReconstruction::Run(const char* input)
   if (fRawReader && (chain = fRawReader->GetChain())) {
     // Proof mode
     if (gProof) {
+
+      if (gGrid)
+       gProof->Exec("TGrid::Connect(\"alien://\")",kTRUE);
+
+      TMessage::EnableSchemaEvolutionForAll(kTRUE);
+      gProof->Exec("TMessage::EnableSchemaEvolutionForAll(kTRUE)",kTRUE);
+
       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");
     }
@@ -1342,6 +1388,13 @@ 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");
@@ -1515,7 +1568,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);
@@ -1564,7 +1617,7 @@ Bool_t AliReconstruction::ProcessEvent(Int_t 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
@@ -1576,8 +1629,10 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
       if (reconstructor && fRecoParam.GetDetRecoParamArray(iDet)) {
         const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
         reconstructor->SetRecoParam(par);
+       reconstructor->SetEventInfo(&fEventInfo);
         if (fRunQA) {
-          fQAManager->SetRecoParam(iDet, par) ; 
+          AliQAManager::QAManager()->SetRecoParam(iDet, par) ; 
+          AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(par->GetEventSpecie())) ;
         }
       }
     }
@@ -1585,8 +1640,8 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
 
     // QA on single raw 
   if (fRunQA) {
-    fQAManager->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
-    fQAManager->RunOneEvent(fRawReader) ;  
+    AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
+    AliQAManager::QAManager()->RunOneEvent(fRawReader) ;  
   }
     // local single event reconstruction
     if (!fRunLocalReconstruction.IsNull()) {
@@ -1677,6 +1732,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);
@@ -1686,6 +1742,11 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
        if (fStopOnError) {CleanUp(); return kFALSE;}
       }
     }
+    // Always fill scalers
+    if (!FillTriggerScalers(fesd)) {
+       if (fStopOnError) {CleanUp(); return kFALSE;}
+    }
+    
 
     ffile->cd();
 
@@ -1810,14 +1871,14 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
     if (fCleanESD) CleanESD(fesd);
 
   if (fRunQA) {
-    fQAManager->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
-    fQAManager->RunOneEvent(fesd) ; 
+    AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
+    AliQAManager::QAManager()->RunOneEvent(fesd) ; 
   }
   if (fRunGlobalQA) {
-      AliQADataMaker *qadm = fQAManager->GetQADataMaker(AliQA::kGLOBAL);
+    AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
       qadm->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
-    if (qadm && fQATasks.Contains(Form("%d", AliQA::kESDS)))
-      qadm->Exec(AliQA::kESDS, fesd);
+    if (qadm && fQATasks.Contains(Form("%d", AliQAv1::kESDS)))
+      qadm->Exec(AliQAv1::kESDS, fesd);
   }
 
     if (fWriteESDfriend) {
@@ -1853,12 +1914,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) 
-      fQAManager->Increment() ; 
+    AliQAManager::QAManager()->Increment() ; 
   
     return kTRUE;
 }
@@ -1913,7 +1977,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()) {
@@ -1922,18 +1986,36 @@ void AliReconstruction::SlaveTerminate()
 
   // End of cycle for the in-loop  
   if (fRunQA) 
-    fQAManager->EndOfCycle() ;
+    AliQAManager::QAManager()->EndOfCycle() ;
   
   if (fRunGlobalQA) {
-    AliQADataMaker *qadm = fQAManager->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();
 }
@@ -1945,8 +2027,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, AliQA::Instance()->GetQA(), AliQA::Instance()->GetEventSpecies(), AliQA::kNDET, AliRecoParam::kNSpecies);
+  // 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();
@@ -1970,10 +2055,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;
     }
@@ -2008,22 +2093,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) {
-      fQAManager->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
-                       fQAManager->RunOneEventInOneDetector(iDet, clustersTree) ; 
+      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);
+    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",
@@ -2125,6 +2212,12 @@ Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
   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 = vertexer->GetMultiplicity();
   if(mult)esd->SetMultiplicity(mult);
@@ -2255,6 +2348,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");
@@ -2305,8 +2408,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);
@@ -2314,8 +2417,18 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
 
     // run tracking
     if (iDet>1) // start filling residuals for the "outer" detectors
-    if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), 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;
@@ -2344,8 +2457,19 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
 
     // run tracking
     if (iDet<2) // start filling residuals for TPC and ITS
-    if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), 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;
@@ -2481,19 +2605,38 @@ 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
-  // ...
   }
   return kTRUE;
 }
-
-
-
-
-
+//_____________________________________________________________________________
+Bool_t AliReconstruction::FillTriggerScalers(AliESDEvent*& esd)
+{
+  //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)
 {
@@ -2615,6 +2758,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];
   }
@@ -2650,6 +2794,7 @@ AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
   if (reconstructor) {
     TObject* obj = fOptions.FindObject(detName.Data());
     if (obj) reconstructor->SetOption(obj->GetTitle());
+    reconstructor->SetRunInfo(fRunInfo);
     reconstructor->Init();
     fReconstructor[iDet] = reconstructor;
   }
@@ -2696,6 +2841,7 @@ 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;
 }
@@ -2709,7 +2855,7 @@ AliVertexer* AliReconstruction::CreateVertexer()
 
   AliVertexer* vertexer = NULL;
   AliReconstructor* itsReconstructor = GetReconstructor(0);
-  if (itsReconstructor) {
+  if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) || fRunTracking.Contains("ITS"))) {
     vertexer = itsReconstructor->CreateVertexer();
   }
   if (!vertexer) {
@@ -2773,14 +2919,6 @@ void AliReconstruction::CleanUp()
   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;
@@ -2793,6 +2931,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)
@@ -2889,24 +3033,24 @@ void AliReconstruction::CheckQA()
 //     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, specie, AliQA::kFATAL)) {
+//     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(AliQA::GetDetName(iDet)) || 
+//                     if ( fRunLocalReconstruction.Contains(AliQAv1::GetDetName(iDet)) || 
 //                                     fRunLocalReconstruction.Contains("ALL") )  {
 //                             newRunLocalReconstruction += detName ; 
 //                             newRunLocalReconstruction += " " ;                      
 //                     }
-//                     if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) || 
+//                     if ( fRunTracking.Contains(AliQAv1::GetDetName(iDet)) || 
 //                                     fRunTracking.Contains("ALL") )  {
 //                             newRunTracking += detName ; 
 //                             newRunTracking += " " ;                         
 //                     }
-//                     if ( fFillESD.Contains(AliQA::GetDetName(iDet)) || 
+//                     if ( fFillESD.Contains(AliQAv1::GetDetName(iDet)) || 
 //                                     fFillESD.Contains("ALL") )  {
 //                             newFillESD += detName ; 
 //                             newFillESD += " " ;                     
@@ -3039,7 +3183,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(":")) {
@@ -3053,16 +3197,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")  ;
@@ -3071,9 +3217,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; 
@@ -3087,6 +3234,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++) {
 
@@ -3124,7 +3305,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());
     }
   }
 
@@ -3165,6 +3350,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 {
@@ -3191,7 +3381,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 += " ";
@@ -3305,3 +3495,18 @@ void AliReconstruction::Abort(const char *method, EAbort what)
   Info(mess, whyMess.Data());
 }
 
+//______________________________________________________________________________
+Bool_t AliReconstruction::ProcessEvent(void* event)
+{
+  // Method that is used in case the event loop
+  // is steered from outside, for example by AMORE
+  // 'event' is a pointer to the DATE event in the memory
+
+  if (fRawReader) delete fRawReader;
+  fRawReader = new AliRawReaderDate(event);
+  fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());  
+  delete fRawReader;
+  fRawReader = NULL;
+
+  return fStatus;
+}