]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
Updated QA classes (Yves)
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index 99d202cbffa6a8b16fa382669740b8116d5724ed..607ca486a618116cee67c0cd8d30c419e764ee6d 100644 (file)
 #include "AliRawReaderRoot.h"
 #include "AliRawEventHeaderBase.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),
@@ -622,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();
@@ -717,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);}
 
@@ -770,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);
@@ -787,10 +811,20 @@ Bool_t AliReconstruction::Run(const char* input)
     }
     // 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);
@@ -817,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;
 }
@@ -1233,13 +1272,39 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& 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);
   }
   
   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(AliESDEvent*& esd, const TString& detectors)
 {
@@ -1448,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()));
@@ -1662,7 +1731,6 @@ void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
   }
 }
 
-
 //_____________________________________________________________________________
 
 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
@@ -1719,304 +1787,12 @@ void AliReconstruction::WriteESD(AliESDEvent* 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");
-  AliESDEvent *esd = new AliESDEvent();
-  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();
@@ -2025,7 +1801,7 @@ 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
@@ -2051,11 +1827,12 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
     Int_t nTracks   = esd->GetNumberOfTracks();
     Int_t nPosTracks = 0;
     for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) 
-      if (esd->GetTrack(iTrack)->GetSign()> 0) nPosTracks++;
+      if (esd->GetTrack(iTrack)->Charge()> 0) nPosTracks++;
 
-    // Update the header
-    AliAODHeader* header = aod->GetHeader();
-    
+    // Access the header
+    AliAODHeader *header = aod->GetHeader();
+
+    // fill the header
     header->SetRunNumber       (esd->GetRunNumber()       );
     header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
     header->SetOrbitNumber     (esd->GetOrbitNumber()     );
@@ -2074,8 +1851,6 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
     header->SetRefMultiplicityNeg(nTracks - nPosTracks);
     header->SetMuonMagFieldScale(-999.); // FIXME
     header->SetCentrality(-999.);        // FIXME
-//
-//
 
     Int_t nV0s      = esd->GetNumberOfV0s();
     Int_t nCascades = esd->GetNumberOfCascades();
@@ -2085,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) {
@@ -2121,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
       
@@ -2137,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();
@@ -2179,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 {
 
@@ -2194,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);
       }
@@ -2218,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,
@@ -2253,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,
@@ -2290,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,
@@ -2325,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);
 
@@ -2351,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,
@@ -2386,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,
@@ -2472,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,
@@ -2495,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
 
@@ -2518,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,
@@ -2570,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,
@@ -2590,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,
@@ -2616,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,
@@ -2624,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
@@ -2652,17 +2439,17 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
       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,
@@ -2672,27 +2459,41 @@ 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;
 }
 
@@ -2816,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;
+}