]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
Updated QA classes (Yves)
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index 6c9c329408756478e0290d92264757218122099b..607ca486a618116cee67c0cd8d30c419e764ee6d 100644 (file)
 #include <TSystem.h>
 #include <TROOT.h>
 #include <TPluginManager.h>
-#include <TStopwatch.h>
 #include <TGeoManager.h>
 #include <TLorentzVector.h>
 
 #include "AliReconstruction.h"
+#include "AliCodeTimer.h"
 #include "AliReconstructor.h"
 #include "AliLog.h"
 #include "AliRunLoader.h"
 #include "AliRawReaderDate.h"
 #include "AliRawReaderRoot.h"
 #include "AliRawEventHeaderBase.h"
-#include "AliESD.h"
+#include "AliESDEvent.h"
+#include "AliESDMuonTrack.h"
 #include "AliESDfriend.h"
 #include "AliESDVertex.h"
+#include "AliESDcascade.h"
+#include "AliESDkink.h"
+#include "AliESDtrack.h"
+#include "AliESDCaloCluster.h"
 #include "AliMultiplicity.h"
 #include "AliTracker.h"
 #include "AliVertexer.h"
 #include "AliESDpid.h"
 #include "AliESDtrack.h"
 
-#include "AliRunTag.h"
-#include "AliDetectorTag.h"
-#include "AliEventTag.h"
+#include "AliESDTagCreator.h"
+#include "AliAODTagCreator.h"
 
 #include "AliGeomManager.h"
 #include "AliTrackPointArray.h"
 #include "AliAODVertex.h"
 #include "AliAODCluster.h"
 
+#include "AliQualAssDataMaker.h" 
 
 ClassImp(AliReconstruction)
 
@@ -184,6 +189,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdb
   fRunMuonTracking(kFALSE),
   fStopOnError(kFALSE),
   fWriteAlignmentData(kFALSE),
+  fCleanESD(kTRUE),
   fWriteESDfriend(kFALSE),
   fWriteAOD(kFALSE),
   fFillTriggerESD(kTRUE),
@@ -233,6 +239,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fRunMuonTracking(rec.fRunMuonTracking),
   fStopOnError(rec.fStopOnError),
   fWriteAlignmentData(rec.fWriteAlignmentData),
+  fCleanESD(rec.fCleanESD),
   fWriteESDfriend(rec.fWriteESDfriend),
   fWriteAOD(rec.fWriteAOD),
   fFillTriggerESD(rec.fFillTriggerESD),
@@ -295,6 +302,8 @@ AliReconstruction::~AliReconstruction()
   CleanUp();
   fOptions.Delete();
   fSpecCDBUri.Delete();
+
+  AliCodeTimer::Instance()->Print();
 }
 
 //_____________________________________________________________________________
@@ -445,14 +454,14 @@ Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
       loadAlObjsListOfDets += fgkDetectorName[iDet];
       loadAlObjsListOfDets += " ";
     } // end loop over detectors
-    (AliGeomManager::Instance())->ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
+    AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
   }else{
     // Check if the array with alignment objects was
     // provided by the user. If yes, apply the objects
     // to the present TGeo geometry
     if (fAlignObjArray) {
       if (gGeoManager && gGeoManager->IsClosed()) {
-       if ((AliGeomManager::Instance())->ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
+       if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
          AliError("The misalignment of one or more volumes failed!"
                   "Compare the list of simulated detectors and the list of detector alignment data!");
          return kFALSE;
@@ -467,9 +476,6 @@ Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
   
   delete fAlignObjArray; fAlignObjArray=0;
 
-  // Update the TGeoPhysicalNodes
-  gGeoManager->RefreshPhysicalNodes();
-
   return kTRUE;
 }
 
@@ -497,6 +503,8 @@ Bool_t AliReconstruction::Run(const char* input)
 {
 // run the reconstruction
 
+  AliCodeTimerAuto("")
+  
   // set the input
   if (!input) input = fInput.Data();
   TString fileName(input);
@@ -525,7 +533,7 @@ Bool_t AliReconstruction::Run(const char* input)
   if (!gGeoManager) {
     TString geom(gSystem->DirName(fGAliceFileName));
     geom += "/geometry.root";
-    TGeoManager::Import(geom.Data());
+    AliGeomManager::LoadGeometry(geom.Data());
     if (!gGeoManager) if (fStopOnError) return kFALSE;
   }
 
@@ -557,12 +565,8 @@ Bool_t AliReconstruction::Run(const char* input)
     }      
   }
 
-
-  TStopwatch stopwatch;
-  stopwatch.Start();
-
   // get the possibly already existing ESD file and tree
-  AliESD* esd = new AliESD(); AliESD* hltesd = new AliESD();
+  AliESDEvent* esd = new AliESDEvent(); AliESDEvent* hltesd = new AliESDEvent();
   TFile* fileOld = NULL;
   TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
   if (!gSystem->AccessPathName("AliESDs.root")){
@@ -585,12 +589,12 @@ Bool_t AliReconstruction::Run(const char* input)
   }
 
   TTree* tree = new TTree("esdTree", "Tree with ESD objects");
-  esd = new AliESD();
+  esd = new AliESDEvent();
   esd->CreateStdContent();
   esd->WriteToTree(tree);
 
   TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
-  hltesd = new AliESD();
+  hltesd = new AliESDEvent();
   hltesd->CreateStdContent();
   hltesd->WriteToTree(hlttree);
 
@@ -599,6 +603,9 @@ Bool_t AliReconstruction::Run(const char* input)
   esd = NULL; hltesd = NULL;
   */
   // create the branch with ESD additions
+
+
+
   AliESDfriend *esdf = 0; 
   if (fWriteESDfriend) {
     esdf = new AliESDfriend();
@@ -606,6 +613,7 @@ Bool_t AliReconstruction::Run(const char* input)
     br->SetFile("AliESDfriends.root");
     esd->AddObject(esdf);
   }
+
   
   // Get the diamond profile from OCDB
   AliCDBEntry* entry = AliCDBManager::Instance()
@@ -621,7 +629,19 @@ Bool_t AliReconstruction::Run(const char* input)
   if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
 
   // loop over events
   if (fRawReader) fRawReader->RewindEvents();
+   TString detStr(fFillESD) ; 
+
+// initialises quality assurance for ESDs
+   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
+    if (!IsSelected(fgkDetectorName[iDet], detStr)) 
+     continue;
+    AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet);
+    if (!qadm) 
+     continue;
+    qadm->Init(AliQualAss::kESDS) ; 
+    }
   
   for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
     if (fRawReader) fRawReader->NextEvent();
@@ -694,7 +714,7 @@ Bool_t AliReconstruction::Run(const char* input)
     // Muon tracking
     if (!fRunTracking.IsNull()) {
       if (fRunMuonTracking) {
-       if (!RunMuonTracking()) {
+       if (!RunMuonTracking(esd)) {
          if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
        }
       }
@@ -716,6 +736,10 @@ Bool_t AliReconstruction::Run(const char* input)
        if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
       }
     }
+  
+    if (!fFillESD.IsNull()) 
+    RunQualAss(fFillESD.Data(), esd);
+
     // fill Event header information from the RawEventHeader
     if (fRawReader){FillRawEventHeaderESD(esd);}
 
@@ -769,6 +793,7 @@ Bool_t AliReconstruction::Run(const char* input)
     }
  
     // write ESD
+    if (fCleanESD) CleanESD(esd);
     if (fWriteESDfriend) {
       new (esdf) AliESDfriend(); // Reset...
       esd->GetESDfriend(esdf);
@@ -781,10 +806,25 @@ Bool_t AliReconstruction::Run(const char* input)
     if (fCheckPointLevel > 0)  WriteESD(esd, "final"); 
     esd->Reset();
     hltesd->Reset();
+    if (fWriteESDfriend) {
+      new (esdf) AliESDfriend(); // Reset...
+    }
     // esdf->Reset();
     // delete esdf; esdf = 0;
-  } 
-
+  // ESD QA 
+  }
+  
+  detStr = fFillESD ; 
+  // write quality assurance ESDs data (one entry for all events)
+  for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
+       if (!IsSelected(fgkDetectorName[iDet], detStr)) 
+               continue;
+    AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet);
+    if (!qadm) 
+               continue;
+    qadm->Finish(AliQualAss::kESDS) ; 
+  }
 
   tree->GetUserInfo()->Add(esd);
   hlttree->GetUserInfo()->Add(hltesd);
@@ -798,9 +838,6 @@ Bool_t AliReconstruction::Run(const char* input)
   }
 
 
-  AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   file->cd();
   if (fWriteESDfriend)
     tree->SetBranchStatus("ESDfriend*",0);
@@ -814,11 +851,16 @@ Bool_t AliReconstruction::Run(const char* input)
   }
 
   gROOT->cd();
+  CleanUp(file, fileOld);
+  
   // Create tags for the events in the ESD tree (the ESD tree is always present)
   // In case of empty events the tags will contain dummy values
-  CreateTag(file);
-
- CleanUp(file, fileOld);
+  AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
+  esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent);
+  if (fWriteAOD) {
+    AliAODTagCreator *aodtagCreator = new AliAODTagCreator();
+    aodtagCreator->CreateAODTags(fFirstEvent,fLastEvent);
+  }
 
   return kTRUE;
 }
@@ -829,8 +871,7 @@ Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
 {
 // run the local reconstruction
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   AliCDBManager* man = AliCDBManager::Instance();
   Bool_t origCache = man->GetCacheFlag();
@@ -842,28 +883,30 @@ Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
     if (!reconstructor) continue;
     if (reconstructor->HasLocalReconstruction()) continue;
 
+    AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
     AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
-    TStopwatch stopwatchDet;
-    stopwatchDet.Start();
-
+    
+    AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));                          
     AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
 
     man->SetCacheFlag(kTRUE);
     TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
     man->GetAll(calibPath); // entries are cached!
 
+    AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
+     
     if (fRawReader) {
       fRawReader->RewindEvents();
       reconstructor->Reconstruct(fRunLoader, fRawReader);
     } else {
       reconstructor->Reconstruct(fRunLoader);
     }
-    AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
-                fgkDetectorName[iDet],
-                stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
+     
+     AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
 
     // unload calibration data
-    man->ClearCache();
+    man->UnloadFromCache(calibPath);
+    //man->ClearCache();
   }
 
   man->SetCacheFlag(origCache);
@@ -874,9 +917,6 @@ Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
     if (fStopOnError) return kFALSE;
   }
 
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   return kTRUE;
 }
 
@@ -885,8 +925,7 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
 {
 // run the local reconstruction
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   TString detStr = detectors;
   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
@@ -899,8 +938,8 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
     if (fRawReader && reconstructor->HasDigitConversion()) {
       AliInfo(Form("converting raw data digits into root objects for %s", 
                   fgkDetectorName[iDet]));
-      TStopwatch stopwatchDet;
-      stopwatchDet.Start();
+      AliCodeTimerAuto(Form("converting raw data digits into root objects for %s", 
+                            fgkDetectorName[iDet]));
       loader->LoadDigits("update");
       loader->CleanDigits();
       loader->MakeDigitsContainer();
@@ -908,16 +947,12 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
       reconstructor->ConvertDigits(fRawReader, digitsTree);
       loader->WriteDigits("OVERWRITE");
       loader->UnloadDigits();
-      AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
-                  fgkDetectorName[iDet],
-                  stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
     }
 
     // local reconstruction
     if (!reconstructor->HasLocalReconstruction()) continue;
     AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
-    TStopwatch stopwatchDet;
-    stopwatchDet.Start();
+    AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
     loader->LoadRecPoints("update");
     loader->CleanRecPoints();
     loader->MakeRecPointsContainer();
@@ -937,9 +972,6 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
     }
     loader->WriteRecPoints("OVERWRITE");
     loader->UnloadRecPoints();
-    AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
-                fgkDetectorName[iDet],
-                stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
   }
 
   if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
@@ -948,19 +980,15 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
     if (fStopOnError) return kFALSE;
   }
   
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   return kTRUE;
 }
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
+Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
 {
 // run the barrel tracking
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   AliESDVertex* vertex = NULL;
   Double_t vtxPos[3] = {0, 0, 0};
@@ -1008,19 +1036,15 @@ Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
   }  
   delete vertex;
 
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   return kTRUE;
 }
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::RunHLTTracking(AliESD*& esd)
+Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
 {
 // run the HLT barrel tracking
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   if (!fRunLoader) {
     AliError("Missing runLoader!");
@@ -1068,19 +1092,15 @@ Bool_t AliReconstruction::RunHLTTracking(AliESD*& esd)
     delete tracker;
   }
 
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   return kTRUE;
 }
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::RunMuonTracking()
+Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
 {
 // run the muon spectrometer tracking
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   if (!fRunLoader) {
     AliError("Missing runLoader!");
@@ -1109,12 +1129,21 @@ Bool_t AliReconstruction::RunMuonTracking()
   fLoader[iDet]->MakeTracksContainer();
 
   // read RecPoints
-  fLoader[iDet]->LoadRecPoints("read");
-
-  if (!tracker->Clusters2Tracks(0x0)) {
+  fLoader[iDet]->LoadRecPoints("read");  
+  tracker->LoadClusters(fLoader[iDet]->TreeR());
+  
+  Int_t rv = tracker->Clusters2Tracks(esd);
+  
+  fLoader[iDet]->UnloadRecPoints();
+  
+  if ( rv )
+  {
     AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
     return kFALSE;
   }
+  
+  tracker->UnloadClusters();
+  
   fLoader[iDet]->UnloadRecPoints();
 
   fLoader[iDet]->WriteTracks("OVERWRITE");
@@ -1122,21 +1151,16 @@ Bool_t AliReconstruction::RunMuonTracking()
 
   delete tracker;
   
-
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   return kTRUE;
 }
 
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::RunTracking(AliESD*& esd)
+Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
 {
 // run the barrel tracking
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   AliInfo("running tracking");
 
@@ -1248,24 +1272,45 @@ Bool_t AliReconstruction::RunTracking(AliESD*& esd)
     AliESDtrack * track = esd->GetTrack(itrack);
     if (!track) continue;
     if (track->IsOn(AliESDtrack::kITSrefit)) continue;
-    track->PropagateTo(kRadius, fieldZ, track->GetMass(),kMaxStep,kTRUE);
+   AliTracker::PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
     track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
   }
   
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
+  return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
+  //
+  // Remove the data which are not needed for the physics analysis.
+  //
+
+  AliInfo("Cleaning the ESD...");
+
+  const AliESDVertex *vertex=esd->GetVertex();
+  Double_t vz=vertex->GetZv();
+  
+  Int_t nTracks=esd->GetNumberOfTracks();
+  for (Int_t i=0; i<nTracks; i++) {
+    AliESDtrack *track=esd->GetTrack(i);
+
+    Float_t xy,z; track->GetImpactParameters(xy,z);
+    if (TMath::Abs(xy) < 50.)    continue;  
+    if (vertex->GetStatus())
+      if (TMath::Abs(vz-z) < 5.) continue;  
+
+    esd->RemoveTrack(i);
+  }
 
   return kTRUE;
 }
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
+Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
 {
 // fill the event summary data
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
-  AliInfo("filling ESD");
+  AliCodeTimerAuto("")
 
   TString detStr = detectors;
   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
@@ -1320,19 +1365,18 @@ Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
     if (fStopOnError) return kFALSE;
   }
 
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   return kTRUE;
 }
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::FillTriggerESD(AliESD*& esd)
+Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
 {
   // Reads the trigger decision which is
   // stored in Trigger.root file and fills
   // the corresponding esd entries
 
+  AliCodeTimerAuto("")
+  
   AliInfo("Filling trigger information into the ESD");
 
   if (fRawReader) {
@@ -1371,7 +1415,7 @@ Bool_t AliReconstruction::FillTriggerESD(AliESD*& esd)
 
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::FillRawEventHeaderESD(AliESD*& esd)
+Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
 {
   // 
   // Filling information from RawReader Header
@@ -1469,6 +1513,10 @@ Bool_t AliReconstruction::InitRunLoader()
       return kFALSE;
     }
 
+    //PH This is a temporary fix to give access to the kinematics
+    //PH that is needed for the labels of ITS clusters
+    fRunLoader->LoadKinematics();
+
   } else {               // galice.root does not exist
     if (!fRawReader) {
       AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
@@ -1683,9 +1731,9 @@ void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
   }
 }
 
-
 //_____________________________________________________________________________
-Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
+
+Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
 {
 // read the ESD event from a file
 
@@ -1706,14 +1754,17 @@ Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
 
   gROOT->cd();
   delete esd;
-  esd = (AliESD*) file->Get("ESD");
+  esd = (AliESDEvent*) file->Get("ESD");
   file->Close();
   delete file;
   return kTRUE;
+
 }
 
+
+
 //_____________________________________________________________________________
-void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
+void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
 {
 // write the ESD event to a file
 
@@ -1736,304 +1787,12 @@ void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
 
 
 
-//_____________________________________________________________________________
-void AliReconstruction::CreateTag(TFile* file)
-{
-  //GRP
-  Float_t lhcLuminosity = 0.0;
-  TString lhcState = "test";
-  UInt_t detectorMask = 0;
-
-  /////////////
-  //muon code//
-  ////////////
-  Double_t fMUONMASS = 0.105658369;
-  //Variables
-  Double_t fX,fY,fZ ;
-  Double_t fThetaX, fThetaY, fPyz, fChisquare;
-  Double_t fPxRec,fPyRec, fPzRec, fEnergy;
-  Int_t fCharge;
-  TLorentzVector fEPvector;
-
-  Float_t fZVertexCut = 10.0; 
-  Float_t fRhoVertexCut = 2.0; 
-
-  Float_t fLowPtCut = 1.0;
-  Float_t fHighPtCut = 3.0;
-  Float_t fVeryHighPtCut = 10.0;
-  ////////////
-
-  Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
-
-  // Creates the tags for all the events in a given ESD file
-  Int_t ntrack;
-  Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
-  Int_t nPos, nNeg, nNeutr;
-  Int_t nK0s, nNeutrons, nPi0s, nGamas;
-  Int_t nCh1GeV, nCh3GeV, nCh10GeV;
-  Int_t nMu1GeV, nMu3GeV, nMu10GeV;
-  Int_t nEl1GeV, nEl3GeV, nEl10GeV;
-  Float_t maxPt = .0, meanPt = .0, totalP = .0;
-  Int_t fVertexflag;
-  Int_t iRunNumber = 0;
-  TString fVertexName("default");
-
-  AliRunTag *tag = new AliRunTag();
-  AliEventTag *evTag = new AliEventTag();
-  TTree ttag("T","A Tree with event tags");
-  TBranch * btag = ttag.Branch("AliTAG", &tag);
-  btag->SetCompressionLevel(9);
-  
-  AliInfo(Form("Creating the tags......."));   
-  
-  if (!file || !file->IsOpen()) {
-    AliError(Form("opening failed"));
-    delete file;
-    return ;
-  }  
-  Int_t lastEvent = 0;
-  TTree *b = (TTree*) file->Get("esdTree");
-  AliESD *esd = new AliESD();
-  esd->ReadFromTree(b);
-
-  b->GetEntry(fFirstEvent);
-  Int_t iInitRunNumber = esd->GetRunNumber();
-  
-  Int_t iNumberOfEvents = (Int_t)b->GetEntries();
-  if(fLastEvent != -1) iNumberOfEvents = fLastEvent + 1;
-  for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
-    ntrack = 0;
-    nPos = 0;
-    nNeg = 0;
-    nNeutr =0;
-    nK0s = 0;
-    nNeutrons = 0;
-    nPi0s = 0;
-    nGamas = 0;
-    nProtons = 0;
-    nKaons = 0;
-    nPions = 0;
-    nMuons = 0;
-    nElectrons = 0;      
-    nCh1GeV = 0;
-    nCh3GeV = 0;
-    nCh10GeV = 0;
-    nMu1GeV = 0;
-    nMu3GeV = 0;
-    nMu10GeV = 0;
-    nEl1GeV = 0;
-    nEl3GeV = 0;
-    nEl10GeV = 0;
-    maxPt = .0;
-    meanPt = .0;
-    totalP = .0;
-    fVertexflag = 0;
-
-    b->GetEntry(iEventNumber);
-    iRunNumber = esd->GetRunNumber();
-    if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
-    const AliESDVertex * vertexIn = esd->GetVertex();
-    if (!vertexIn) AliError("ESD has not defined vertex.");
-    if (vertexIn) fVertexName = vertexIn->GetName();
-    if(fVertexName != "default") fVertexflag = 1;
-    for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
-      AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
-      UInt_t status = esdTrack->GetStatus();
-      
-      //select only tracks with ITS refit
-      if ((status&AliESDtrack::kITSrefit)==0) continue;
-      //select only tracks with TPC refit
-      if ((status&AliESDtrack::kTPCrefit)==0) continue;
-      
-      //select only tracks with the "combined PID"
-      if ((status&AliESDtrack::kESDpid)==0) continue;
-      Double_t p[3];
-      esdTrack->GetPxPyPz(p);
-      Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
-      Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
-      totalP += momentum;
-      meanPt += fPt;
-      if(fPt > maxPt) maxPt = fPt;
-      
-      if(esdTrack->GetSign() > 0) {
-       nPos++;
-       if(fPt > fLowPtCut) nCh1GeV++;
-       if(fPt > fHighPtCut) nCh3GeV++;
-       if(fPt > fVeryHighPtCut) nCh10GeV++;
-      }
-      if(esdTrack->GetSign() < 0) {
-       nNeg++;
-       if(fPt > fLowPtCut) nCh1GeV++;
-       if(fPt > fHighPtCut) nCh3GeV++;
-       if(fPt > fVeryHighPtCut) nCh10GeV++;
-      }
-      if(esdTrack->GetSign() == 0) nNeutr++;
-      
-      //PID
-      Double_t prob[5];
-      esdTrack->GetESDpid(prob);
-      
-      Double_t rcc = 0.0;
-      for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
-      if(rcc == 0.0) continue;
-      //Bayes' formula
-      Double_t w[5];
-      for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
-      
-      //protons
-      if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
-      //kaons
-      if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
-      //pions
-      if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++; 
-      //electrons
-      if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
-       nElectrons++;
-       if(fPt > fLowPtCut) nEl1GeV++;
-       if(fPt > fHighPtCut) nEl3GeV++;
-       if(fPt > fVeryHighPtCut) nEl10GeV++;
-      }          
-      ntrack++;
-    }//track loop
-    
-    /////////////
-    //muon code//
-    ////////////
-    Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
-    // loop over all reconstructed tracks (also first track of combination)
-    for (Int_t iTrack = 0; iTrack <  nMuonTracks;  iTrack++) {
-      AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
-      if (muonTrack == 0x0) continue;
-      
-      // Coordinates at vertex
-      fZ = muonTrack->GetZ(); 
-      fY = muonTrack->GetBendingCoor();
-      fX = muonTrack->GetNonBendingCoor(); 
-      
-      fThetaX = muonTrack->GetThetaX();
-      fThetaY = muonTrack->GetThetaY();
-      
-      fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
-      fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
-      fPxRec = fPzRec * TMath::Tan(fThetaX);
-      fPyRec = fPzRec * TMath::Tan(fThetaY);
-      fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
-      
-      //ChiSquare of the track if needed
-      fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
-      fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
-      fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
-      
-      // total number of muons inside a vertex cut 
-      if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
-       nMuons++;
-       if(fEPvector.Pt() > fLowPtCut) {
-         nMu1GeV++; 
-         if(fEPvector.Pt() > fHighPtCut) {
-           nMu3GeV++; 
-           if (fEPvector.Pt() > fVeryHighPtCut) {
-             nMu10GeV++;
-           }
-         }
-       }
-      }
-    }//muon track loop
-    
-    // Fill the event tags 
-    if(ntrack != 0)
-      meanPt = meanPt/ntrack;
-    
-    evTag->SetEventId(iEventNumber+1);
-    if (vertexIn) {
-      evTag->SetVertexX(vertexIn->GetXv());
-      evTag->SetVertexY(vertexIn->GetYv());
-      evTag->SetVertexZ(vertexIn->GetZv());
-      evTag->SetVertexZError(vertexIn->GetZRes());
-    }  
-    evTag->SetVertexFlag(fVertexflag);
-
-    evTag->SetT0VertexZ(esd->GetT0zVertex());
-    
-    evTag->SetTriggerMask(esd->GetTriggerMask());
-    evTag->SetTriggerCluster(esd->GetTriggerCluster());
-    
-    evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
-    evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
-    evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
-    evTag->SetZDCProton2Energy(esd->GetZDCP2Energy());
-    evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
-    evTag->SetNumOfParticipants(esd->GetZDCParticipants());
-    
-    
-    evTag->SetNumOfTracks(esd->GetNumberOfTracks());
-    evTag->SetNumOfPosTracks(nPos);
-    evTag->SetNumOfNegTracks(nNeg);
-    evTag->SetNumOfNeutrTracks(nNeutr);
-    
-    evTag->SetNumOfV0s(esd->GetNumberOfV0s());
-    evTag->SetNumOfCascades(esd->GetNumberOfCascades());
-    evTag->SetNumOfKinks(esd->GetNumberOfKinks());
-    evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
-    
-    evTag->SetNumOfProtons(nProtons);
-    evTag->SetNumOfKaons(nKaons);
-    evTag->SetNumOfPions(nPions);
-    evTag->SetNumOfMuons(nMuons);
-    evTag->SetNumOfElectrons(nElectrons);
-    evTag->SetNumOfPhotons(nGamas);
-    evTag->SetNumOfPi0s(nPi0s);
-    evTag->SetNumOfNeutrons(nNeutrons);
-    evTag->SetNumOfKaon0s(nK0s);
-    
-    evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
-    evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
-    evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
-    evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
-    evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
-    evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
-    evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
-    evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
-    evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
-    
-    evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
-    evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
-    
-    evTag->SetTotalMomentum(totalP);
-    evTag->SetMeanPt(meanPt);
-    evTag->SetMaxPt(maxPt);
-    
-    tag->SetLHCTag(lhcLuminosity,lhcState);
-    tag->SetDetectorTag(detectorMask);
-
-    tag->SetRunId(iInitRunNumber);
-    tag->AddEventTag(*evTag);
-  }
-  if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries();
-  else lastEvent = fLastEvent;
-       
-  ttag.Fill();
-  tag->Clear();
-
-  char fileName[256];
-  sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root", 
-         tag->GetRunId(),fFirstEvent,lastEvent );
-  AliInfo(Form("writing tags to file %s", fileName));
-  AliDebug(1, Form("writing tags to file %s", fileName));
-  TFile* ftag = TFile::Open(fileName, "recreate");
-  ftag->cd();
-  ttag.Write();
-  ftag->Close();
-  file->cd();
-  delete tag;
-  delete evTag;
-}
 
 //_____________________________________________________________________________
 void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
 {
   // write all files from the given esd file to an aod file
-  
+
   // create an AliAOD object 
   AliAODEvent *aod = new AliAODEvent();
   aod->CreateStdContent();
@@ -2042,16 +1801,15 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
   aodFile->cd();
   
   // create the tree
-  TTree *aodTree = new TTree("AOD", "AliAOD tree");
+  TTree *aodTree = new TTree("aodTree", "AliAOD tree");
   aodTree->Branch(aod->GetList());
 
   // connect to ESD
   TTree *t = (TTree*) esdFile->Get("esdTree");
-  TBranch *b = t->GetBranch("ESD");
-  AliESD *esd = 0;
-  b->SetAddress(&esd);
+  AliESDEvent *esd = new AliESDEvent();
+  esd->ReadFromTree(t);
 
-  Int_t nEvents = b->GetEntries();
+  Int_t nEvents = t->GetEntries();
 
   // set arrays and pointers
   Float_t posF[3];
@@ -2063,33 +1821,36 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
 
   // loop over events and fill them
   for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
-    b->GetEntry(iEvent);
+    t->GetEntry(iEvent);
 
     // Multiplicity information needed by the header (to be revised!)
     Int_t nTracks   = esd->GetNumberOfTracks();
     Int_t nPosTracks = 0;
     for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) 
-      if (esd->GetTrack(iTrack)->GetSign()> 0) nPosTracks++;
-
-    // create the header
-    aod->AddHeader(new AliAODHeader(esd->GetRunNumber(),
-                                   esd->GetBunchCrossNumber(),
-                                   esd->GetOrbitNumber(),
-                                   esd->GetPeriodNumber(),
-                                   nTracks,
-                                   nPosTracks,
-                                   nTracks-nPosTracks,
-                                   esd->GetMagneticField(),
-                                   -999., // fill muon magnetic field
-                                   -999., // centrality; to be filled, still
-                                   esd->GetZDCN1Energy(),
-                                   esd->GetZDCP1Energy(),
-                                   esd->GetZDCN2Energy(),
-                                   esd->GetZDCP2Energy(),
-                                   esd->GetZDCEMEnergy(),
-                                   esd->GetTriggerMask(),
-                                   esd->GetTriggerCluster(),
-                                   esd->GetEventType()));
+      if (esd->GetTrack(iTrack)->Charge()> 0) nPosTracks++;
+
+    // Access the header
+    AliAODHeader *header = aod->GetHeader();
+
+    // fill the header
+    header->SetRunNumber       (esd->GetRunNumber()       );
+    header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
+    header->SetOrbitNumber     (esd->GetOrbitNumber()     );
+    header->SetPeriodNumber    (esd->GetPeriodNumber()    );
+    header->SetTriggerMask     (esd->GetTriggerMask()     ); 
+    header->SetTriggerCluster  (esd->GetTriggerCluster()  );
+    header->SetEventType       (esd->GetEventType()       );
+    header->SetMagneticField   (esd->GetMagneticField()   );
+    header->SetZDCN1Energy     (esd->GetZDCN1Energy()     );
+    header->SetZDCP1Energy     (esd->GetZDCP1Energy()     );
+    header->SetZDCN2Energy     (esd->GetZDCN2Energy()     );
+    header->SetZDCP2Energy     (esd->GetZDCP2Energy()     );
+    header->SetZDCEMEnergy     (esd->GetZDCEMEnergy()     );
+    header->SetRefMultiplicity   (nTracks);
+    header->SetRefMultiplicityPos(nPosTracks);
+    header->SetRefMultiplicityNeg(nTracks - nPosTracks);
+    header->SetMuonMagFieldScale(-999.); // FIXME
+    header->SetCentrality(-999.);        // FIXME
 
     Int_t nV0s      = esd->GetNumberOfV0s();
     Int_t nCascades = esd->GetNumberOfCascades();
@@ -2099,7 +1860,6 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
     aod->ResetStd(nTracks, nVertices);
     AliAODTrack *aodTrack;
     
-
     // Array to take into account the tracks already added to the AOD
     Bool_t * usedTrack = NULL;
     if (nTracks>0) {
@@ -2135,7 +1895,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
     vtx->GetCovMatrix(covVtx); //covariance matrix
 
     AliAODVertex * primary = new(vertices[jVertices++])
-      AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, AliAODVertex::kPrimary);
+      AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);
          
     // Create vertices starting from the most complex objects
       
@@ -2151,12 +1911,13 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                                                        covVtx,
                                                                        cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
                                                                        primary,
+                                                                       nCascade,
                                                                        AliAODVertex::kCascade);
 
       primary->AddDaughter(vcascade);
 
       // Add the V0 from the cascade. The ESD class have to be optimized...
-      // Now we have to search for the corresponding Vo in the list of V0s
+      // Now we have to search for the corresponding V0 in the list of V0s
       // using the indeces of the positive and negative tracks
 
       Int_t posFromV0 = cascade->GetPindex();
@@ -2193,6 +1954,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                                                 covVtx,
                                                                 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
                                                                 vcascade,
+                                                                indV0,
                                                                 AliAODVertex::kV0);
       } else {
 
@@ -2208,6 +1970,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                                                 covVtx,
                                                                 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
                                                                 vcascade,
+                                                                indV0,
                                                                 AliAODVertex::kV0);
        vcascade->AddDaughter(vV0FromCascade);
       }
@@ -2232,7 +1995,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                           pos,
                                           kFALSE,
                                           covTr, 
-                                          (Short_t)esdTrack->GetSign(),
+                                          (Short_t)esdTrack->Charge(),
                                           esdTrack->GetITSClusterMap(), 
                                           pid,
                                           vV0FromCascade,
@@ -2267,7 +2030,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                           pos,
                                           kFALSE,
                                           covTr, 
-                                          (Short_t)esdTrack->GetSign(),
+                                          (Short_t)esdTrack->Charge(),
                                           esdTrack->GetITSClusterMap(), 
                                           pid,
                                           vV0FromCascade,
@@ -2304,7 +2067,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                           pos,
                                           kFALSE,
                                           covTr, 
-                                          (Short_t)esdTrack->GetSign(),
+                                          (Short_t)esdTrack->Charge(),
                                           esdTrack->GetITSClusterMap(), 
                                           pid,
                                           vcascade,
@@ -2339,6 +2102,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                                covVtx,
                                                v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
                                                primary,
+                                               nV0,
                                                AliAODVertex::kV0);
       primary->AddDaughter(vV0);
 
@@ -2365,7 +2129,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                           pos,
                                           kFALSE,
                                           covTr, 
-                                          (Short_t)esdTrack->GetSign(),
+                                          (Short_t)esdTrack->Charge(),
                                           esdTrack->GetITSClusterMap(), 
                                           pid,
                                           vV0,
@@ -2400,7 +2164,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                           pos,
                                           kFALSE,
                                           covTr, 
-                                          (Short_t)esdTrack->GetSign(),
+                                          (Short_t)esdTrack->Charge(),
                                           esdTrack->GetITSClusterMap(), 
                                           pid,
                                           vV0,
@@ -2486,7 +2250,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                           pos,
                                           kFALSE,
                                           covTr, 
-                                          (Short_t)esdTrack->GetSign(),
+                                          (Short_t)esdTrack->Charge(),
                                           esdTrack->GetITSClusterMap(), 
                                           pid,
                                           primary,
@@ -2509,6 +2273,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                                    NULL,
                                                    0.,
                                                    mother,
+                                                   esdTrack->GetID(), // This is the track ID of the mother's track!
                                                    AliAODVertex::kKink);
            // Add the daughter track
 
@@ -2532,7 +2297,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                           pos,
                                           kFALSE,
                                           covTr, 
-                                          (Short_t)esdTrack->GetSign(),
+                                          (Short_t)esdTrack->Charge(),
                                           esdTrack->GetITSClusterMap(), 
                                           pid,
                                           vkink,
@@ -2584,7 +2349,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                         pos,
                                         kFALSE,
                                         covTr, 
-                                        (Short_t)esdTrack->GetSign(),
+                                        (Short_t)esdTrack->Charge(),
                                         esdTrack->GetITSClusterMap(), 
                                         pid,
                                         primary,
@@ -2604,7 +2369,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                         pos,
                                         kFALSE,
                                         covTr, 
-                                        (Short_t)esdTrack->GetSign(),
+                                        (Short_t)esdTrack->Charge(),
                                         esdTrack->GetITSClusterMap(), 
                                         pid,
                                         NULL,
@@ -2630,7 +2395,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
       // has to be changed once the muon pid is provided by the ESD
       for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
       
-      primary->AddDaughter(
+      primary->AddDaughter(aodTrack =
          new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
                                             0, // no label provided
                                             p,
@@ -2638,14 +2403,22 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                             pos,
                                             kFALSE,
                                             NULL, // no covariance matrix provided
-                                            (Short_t)-99, // no charge provided
-                                            0, // no ITSClusterMap
+                                            esdMuTrack->Charge(),
+                                            0, // ITSClusterMap is set below
                                             pid,
                                             primary,
-                                            kTRUE,  // check if this is right
-                                            kTRUE,  // not used for vertex fit
+                                            kFALSE,  // muon tracks are not used to fit the primary vtx
+                                            kFALSE,  // not used for vertex fit
                                             AliAODTrack::kPrimary)
          );
+
+      aodTrack->SetHitsPatternInTrigCh(esdMuTrack->GetHitsPatternInTrigCh());
+      Int_t track2Trigger = esdMuTrack->GetMatchTrigger();
+      aodTrack->SetMatchTrigger(track2Trigger);
+      if (track2Trigger) 
+       aodTrack->SetChi2MatchTrigger(esdMuTrack->GetChi2MatchTrigger());
+      else 
+       aodTrack->SetChi2MatchTrigger(0.);
     }
     
     // Access to the AOD container of clusters
@@ -2661,22 +2434,22 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
 
       Int_t id = cluster->GetID();
       Int_t label = -1;
-      Float_t energy = cluster->GetClusterEnergy();
-      cluster->GetGlobalPosition(posF);
+      Float_t energy = cluster->E();
+      cluster->GetPosition(posF);
       AliAODVertex *prodVertex = primary;
       AliAODTrack *primTrack = NULL;
       Char_t ttype=AliAODCluster::kUndef;
-      
+
       if (cluster->IsPHOS()) ttype=AliAODCluster::kPHOSNeutral;
       else if (cluster->IsEMCAL()) {
-       
+
        if (cluster->GetClusterType() == AliESDCaloCluster::kPseudoCluster)
          ttype = AliAODCluster::kEMCALPseudoCluster;
        else
          ttype = AliAODCluster::kEMCALClusterv1;
-       
+
       }
-      
+
       new(clusters[jClusters++]) AliAODCluster(id,
                                               label,
                                               energy,
@@ -2686,32 +2459,45 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
                                               prodVertex,
                                               primTrack,
                                               ttype);
-      
+
     } // end of loop on calo clusters
-    
+
+    // tracklets
+    const AliMultiplicity *mult = esd->GetMultiplicity();
+    if (mult) {
+      if (mult->GetNumberOfTracklets()>0) {
+       aod->GetTracklets()->CreateContainer(mult->GetNumberOfTracklets());
+
+       for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {
+         aod->GetTracklets()->SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n));
+       }
+      }
+    } else {
+      Printf("ERROR: AliMultiplicity could not be retrieved from ESD");
+    }
+
     delete [] usedTrack;
     delete [] usedV0;
     delete [] usedKink;
-    
+
     // fill the tree for this event
     aodTree->Fill();
   } // end of event loop
-  
+
   aodTree->GetUserInfo()->Add(aod);
-  
+
   // close ESD file
   esdFile->Close();
-  
+
   // write the tree to the specified file
   aodFile = aodTree->GetCurrentFile();
   aodFile->cd();
   aodTree->Write();
-  
+
   return;
 }
 
-
-void AliReconstruction::WriteAlignmentData(AliESD* esd)
+void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
 {
   // Write space-points which are then used in the alignment procedures
   // For the moment only ITS, TRD and TPC
@@ -2764,7 +2550,7 @@ void AliReconstruction::WriteAlignmentData(AliESD* esd)
 }
 
 //_____________________________________________________________________________
-void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESD* esd)
+void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
 {
   // The method reads the raw-data error log
   // accumulated within the rawReader.
@@ -2786,6 +2572,7 @@ void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESD* esd)
 }
 
 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
+  // Dump a file content into a char in TNamed
   ifstream in;
   in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
   Int_t kBytes = (Int_t)in.tellg();
@@ -2811,7 +2598,6 @@ TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
 }
 
 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
-
   // This is not really needed in AliReconstruction at the moment
   // but can serve as a template
 
@@ -2831,3 +2617,114 @@ void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
 
 }
 
+//_____________________________________________________________________________
+AliQualAssDataMaker * AliReconstruction::GetQualAssDataMaker(Int_t iDet)
+{
+// get the quality assurance data maker object and the loader for a detector
+
+  if (fQualAssDataMaker[iDet]) 
+    return fQualAssDataMaker[iDet];
+
+  // load the QA data maker object
+  TPluginManager* pluginManager = gROOT->GetPluginManager();
+  TString detName = fgkDetectorName[iDet];
+  TString qadmName = "Ali" + detName + "QualAssDataMaker";
+  if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) 
+    return NULL;
+
+  AliQualAssDataMaker * qadm = NULL;
+  // first check if a plugin is defined for the quality assurance data maker
+  TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQualAssDataMaker", detName);
+  // if not, add a plugin for it
+  if (!pluginHandler) {
+    AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
+    TString libs = gSystem->GetLibraries();
+    if (libs.Contains("lib" + detName + "base.so") ||
+       (gSystem->Load("lib" + detName + "base.so") >= 0)) {
+      pluginManager->AddHandler("AliQualAssDataMaker", detName, 
+                               qadmName, detName + "qadm", qadmName + "()");
+    } else {
+      pluginManager->AddHandler("AliQualAssDataMaker", detName, 
+                               qadmName, detName, qadmName + "()");
+    }
+    pluginHandler = pluginManager->FindHandler("AliQualAssDataMaker", detName);
+  }
+  if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
+    qadm = (AliQualAssDataMaker *) pluginHandler->ExecPlugin(0);
+  }
+  if (qadm) {
+    // TObject* obj = fOptions.FindObject(detName.Data());
+    //     if (obj) reconstructor->SetOption(obj->GetTitle());
+    fQualAssDataMaker[iDet] = qadm;
+  }
+
+  // get or create the loader
+  fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
+  if (!fLoader[iDet]) {
+    AliConfig::Instance()
+       ->CreateDetectorFolders(fRunLoader->GetEventFolder(), 
+                               detName, detName);
+    // first check if a plugin is defined for the loader
+    pluginHandler = 
+      pluginManager->FindHandler("AliLoader", detName);
+    // if not, add a plugin for it
+    if (!pluginHandler) {
+      TString loaderName = "Ali" + detName + "Loader";
+      AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
+      pluginManager->AddHandler("AliLoader", detName, 
+                               loaderName, detName + "base", 
+                               loaderName + "(const char*, TFolder*)");
+      pluginHandler = pluginManager->FindHandler("AliLoader", detName);
+    }
+    if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
+      fLoader[iDet] = 
+       (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(), 
+                                              fRunLoader->GetEventFolder());
+    }
+    if (!fLoader[iDet]) {   // use default loader
+      fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
+    }
+    if (!fLoader[iDet]) {
+      AliWarning(Form("couldn't get loader for %s", detName.Data()));
+      if (fStopOnError) return NULL;
+    } else {
+      fRunLoader->AddLoader(fLoader[iDet]);
+      fRunLoader->CdGAFile();
+      if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
+      fRunLoader->Write(0, TObject::kOverwrite);
+    }
+  }
+      
+  return qadm;
+}
+
+//_____________________________________________________________________________
+Bool_t AliReconstruction::RunQualAss(const char* detectors, AliESDEvent *& esd)
+{
+  // run the Quality Assurance data producer
+
+  AliCodeTimerAuto("")
+  TString detStr = detectors;
+  for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
+   if (!IsSelected(fgkDetectorName[iDet], detStr)) 
+     continue;
+   AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet);
+   if (!qadm) 
+     continue;
+   AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
+   AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
+    
+   qadm->SetData(esd) ; 
+   qadm->Exec(AliQualAss::kESDS) ; 
+
+   AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
+ }
+ if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
+   AliError(Form("the following detectors were not found: %s",
+                detStr.Data()));
+   if (fStopOnError) 
+     return kFALSE;
+ }
+ return kTRUE;
+}