]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
New base for all classes in HLT/PHOS
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index 6f404007155031921300254d4ddfc7c7b39f93de..d1ffddb9669fce13fc4434d7c6ed597bb95dcd71 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 "AliESDfriend.h"
 #include "AliESDVertex.h"
 #include "AliMultiplicity.h"
 #include "AliDetectorTag.h"
 #include "AliEventTag.h"
 
+#include "AliGeomManager.h"
 #include "AliTrackPointArray.h"
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
@@ -200,6 +201,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdb
   fOptions(),
   fLoadAlignFromCDB(kTRUE),
   fLoadAlignData("ALL"),
+  fESDPar(""),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -248,6 +250,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fOptions(),
   fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
   fLoadAlignData(rec.fLoadAlignData),
+  fESDPar(rec.fESDPar),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -292,6 +295,8 @@ AliReconstruction::~AliReconstruction()
   CleanUp();
   fOptions.Delete();
   fSpecCDBUri.Delete();
+
+  AliCodeTimer::Instance()->Print();
 }
 
 //_____________________________________________________________________________
@@ -380,6 +385,9 @@ void AliReconstruction::SetSpecificStorage(const char* calibType, const char* ur
 
 }
 
+
+
+
 //_____________________________________________________________________________
 Bool_t AliReconstruction::SetRunNumber()
 {
@@ -417,72 +425,6 @@ Bool_t AliReconstruction::SetRunNumber()
   return kTRUE;
 }
 
-//_____________________________________________________________________________
-Bool_t AliReconstruction::ApplyAlignObjsToGeom(TObjArray* alObjArray)
-{
-  // Read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName and apply them to the geometry
-  // manager singleton.
-  //
-  alObjArray->Sort();
-  Int_t nvols = alObjArray->GetEntriesFast();
-
-  Bool_t flag = kTRUE;
-
-  for(Int_t j=0; j<nvols; j++)
-    {
-      AliAlignObj* alobj = (AliAlignObj*) alObjArray->UncheckedAt(j);
-      if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
-    }
-
-  if (AliDebugLevelClass() >= 1) {
-    gGeoManager->GetTopNode()->CheckOverlaps(20);
-    TObjArray* ovexlist = gGeoManager->GetListOfOverlaps();
-    if(ovexlist->GetEntriesFast()){  
-      AliError("The application of alignment objects to the geometry caused huge overlaps/extrusions!");
-   }
-  }
-
-  return flag;
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliReconstruction::SetAlignObjArraySingleDet(const char* detName)
-{
-  // Fills array of single detector's alignable objects from CDB
-  
-  AliDebug(2, Form("Loading alignment data for detector: %s",detName));
-  
-  AliCDBEntry *entry;
-       
-  AliCDBPath path(detName,"Align","Data");
-       
-  entry=AliCDBManager::Instance()->Get(path.GetPath());
-  if(!entry){ 
-       AliDebug(2,Form("Couldn't load alignment data for detector %s",detName));
-       return kFALSE;
-  }
-  entry->SetOwner(1);
-  TClonesArray *alignArray = (TClonesArray*) entry->GetObject();       
-  alignArray->SetOwner(0);
-  AliDebug(2,Form("Found %d alignment objects for %s",
-                       alignArray->GetEntries(),detName));
-
-  AliAlignObj *alignObj=0;
-  TIter iter(alignArray);
-       
-  // loop over align objects in detector
-  while( ( alignObj=(AliAlignObj *) iter.Next() ) ){
-       fAlignObjArray->Add(alignObj);
-  }
-  // delete entry --- Don't delete, it is cached!
-       
-  AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() ));
-  return kTRUE;
-
-}
-
 //_____________________________________________________________________________
 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
 {
@@ -496,57 +438,37 @@ Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
 
   // Load alignment data from CDB and fill fAlignObjArray 
   if(fLoadAlignFromCDB){
-       if(!fAlignObjArray) fAlignObjArray = new TObjArray();
        
-       //fAlignObjArray->RemoveAll(); 
-       fAlignObjArray->Clear();        
-       fAlignObjArray->SetOwner(0);
-       TString detStr = detectors;
-       TString dataNotLoaded="";
-       TString dataLoaded="";
-  
-       for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
-         if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
-         if(!SetAlignObjArraySingleDet(fgkDetectorName[iDet])){
-           dataNotLoaded += fgkDetectorName[iDet];
-           dataNotLoaded += " ";
-         } else {
-           dataLoaded += fgkDetectorName[iDet];
-           dataLoaded += " ";
-         }
-       } // end loop over detectors
-  
-       if ((detStr.CompareTo("ALL") == 0)) detStr = "";
-       dataNotLoaded += detStr;
-       if(!dataLoaded.IsNull()) AliInfo(Form("Alignment data loaded for: %s",
-                         dataLoaded.Data()));
-       if(!dataNotLoaded.IsNull()) AliInfo(Form("Didn't/couldn't load alignment data for: %s",
-                         dataNotLoaded.Data()));
-  } // fLoadAlignFromCDB flag
-  // 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 (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!");
+    TString detStr = detectors;
+    TString loadAlObjsListOfDets = "";
+    
+    for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
+      if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
+      loadAlObjsListOfDets += fgkDetectorName[iDet];
+      loadAlObjsListOfDets += " ";
+    } // end loop over detectors
+    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::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;
+       }
+      }
+      else {
+       AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
        return kFALSE;
       }
     }
-    else {
-      AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
-      return kFALSE;
-    }
   }
-
+  
   delete fAlignObjArray; fAlignObjArray=0;
 
-  // Update the TGeoPhysicalNodes
-  gGeoManager->RefreshPhysicalNodes();
-
   return kTRUE;
 }
 
@@ -574,6 +496,8 @@ Bool_t AliReconstruction::Run(const char* input)
 {
 // run the reconstruction
 
+  AliCodeTimerAuto("")
+  
   // set the input
   if (!input) input = fInput.Data();
   TString fileName(input);
@@ -602,7 +526,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;
   }
 
@@ -634,12 +558,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")){
@@ -647,32 +567,47 @@ Bool_t AliReconstruction::Run(const char* input)
     fileOld = TFile::Open("AliESDs.old.root");
     if (fileOld && fileOld->IsOpen()) {
       treeOld = (TTree*) fileOld->Get("esdTree");
-      if (treeOld) treeOld->SetBranchAddress("ESD", &esd);
+      if (treeOld)esd->ReadFromTree(treeOld);
       hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
-      if (hlttreeOld) hlttreeOld->SetBranchAddress("ESD", &hltesd);
+      if (hlttreeOld)  hltesd->ReadFromTree(hlttreeOld);
     }
   }
 
   // create the ESD output file and tree
   TFile* file = TFile::Open("AliESDs.root", "RECREATE");
+  file->SetCompressionLevel(2);
   if (!file->IsOpen()) {
     AliError("opening AliESDs.root failed");
     if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}    
   }
+
   TTree* tree = new TTree("esdTree", "Tree with ESD objects");
-  tree->Branch("ESD", "AliESD", &esd);
+  esd = new AliESDEvent();
+  esd->CreateStdContent();
+  esd->WriteToTree(tree);
+
   TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
-  hlttree->Branch("ESD", "AliESD", &hltesd);
+  hltesd = new AliESDEvent();
+  hltesd->CreateStdContent();
+  hltesd->WriteToTree(hlttree);
+
+  /* CKB Why?
   delete esd; delete hltesd;
   esd = NULL; hltesd = NULL;
-
+  */
   // create the branch with ESD additions
-  AliESDfriend *esdf=0;
+
+
+
+  AliESDfriend *esdf = 0; 
   if (fWriteESDfriend) {
-     TBranch *br=tree->Branch("ESDfriend.", "AliESDfriend", &esdf);
-     br->SetFile("AliESDfriends.root");
+    esdf = new AliESDfriend();
+    TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf);
+    br->SetFile("AliESDfriends.root");
+    esd->AddObject(esdf);
   }
 
+  
   // Get the diamond profile from OCDB
   AliCDBEntry* entry = AliCDBManager::Instance()
        ->Get("GRP/Calib/MeanVertex");
@@ -694,18 +629,18 @@ Bool_t AliReconstruction::Run(const char* input)
     if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
       // copy old ESD to the new one
       if (treeOld) {
-       treeOld->SetBranchAddress("ESD", &esd);
+       esd->ReadFromTree(treeOld);
        treeOld->GetEntry(iEvent);
       }
       tree->Fill();
       if (hlttreeOld) {
-       hlttreeOld->SetBranchAddress("ESD", &hltesd);
+       esd->ReadFromTree(hlttreeOld);
        hlttreeOld->GetEntry(iEvent);
       }
       hlttree->Fill();
       continue;
     }
-
+    
     AliInfo(Form("processing event %d", iEvent));
     fRunLoader->GetEvent(iEvent);
 
@@ -722,16 +657,18 @@ Bool_t AliReconstruction::Run(const char* input)
       }
     }
 
-    esd = new AliESD; hltesd = new AliESD;
+  
     esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
     hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
     esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
     hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
-
+    
     // Set magnetic field from the tracker
     esd->SetMagneticField(AliTracker::GetBz());
     hltesd->SetMagneticField(AliTracker::GetBz());
 
+    
+    
     // Fill raw-data error log into the ESD
     if (fRawReader) FillRawDataErrorLog(iEvent,esd);
 
@@ -758,7 +695,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;}
        }
       }
@@ -797,7 +734,15 @@ Bool_t AliReconstruction::Run(const char* input)
     }
 
     //Try to improve the reconstructed primary vertex position using the tracks
-    AliESDVertex *pvtx=tVertexer.FindPrimaryVertex(esd);
+    AliESDVertex *pvtx=0;
+    Bool_t dovertex=kTRUE;
+    TObject* obj = fOptions.FindObject("ITS");
+    if (obj) {
+      TString optITS = obj->GetTitle();
+      if (optITS.Contains("cosmics") || optITS.Contains("COSMICS")) 
+       dovertex=kFALSE;
+    }
+    if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
     if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
     
     if (pvtx)
@@ -826,8 +771,8 @@ Bool_t AliReconstruction::Run(const char* input)
  
     // write ESD
     if (fWriteESDfriend) {
-       esdf=new AliESDfriend();
-       esd->GetESDfriend(esdf);
+      new (esdf) AliESDfriend(); // Reset...
+      esd->GetESDfriend(esdf);
     }
     tree->Fill();
 
@@ -835,13 +780,29 @@ Bool_t AliReconstruction::Run(const char* input)
     hlttree->Fill();
 
     if (fCheckPointLevel > 0)  WriteESD(esd, "final"); 
-    delete esd; delete esdf; delete hltesd;
-    esd = NULL; esdf=NULL; hltesd = NULL;
+    esd->Reset();
+    hltesd->Reset();
+    if (fWriteESDfriend) {
+      new (esdf) AliESDfriend(); // Reset...
+    }
+    // esdf->Reset();
+    // delete esdf; esdf = 0;
+  } 
+
+
+
+
+  tree->GetUserInfo()->Add(esd);
+  hlttree->GetUserInfo()->Add(hltesd);
+
+
+
+  if(fESDPar.Contains("ESD.par")){
+    AliInfo("Attaching ESD.par to Tree");
+    TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
+    tree->GetUserInfo()->Add(fn);
   }
 
-  AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
 
   file->cd();
   if (fWriteESDfriend)
@@ -855,10 +816,13 @@ Bool_t AliReconstruction::Run(const char* input)
     aodFile->Close();
   }
 
+  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);
+  CreateTag("AliESDs.root");
+
 
   return kTRUE;
 }
@@ -869,8 +833,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();
@@ -882,28 +845,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);
@@ -914,9 +879,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;
 }
 
@@ -925,8 +887,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++) {
@@ -939,8 +900,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();
@@ -948,16 +909,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();
@@ -977,9 +934,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()) {
@@ -988,19 +942,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};
@@ -1023,7 +973,6 @@ Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
       vertex->SetName("default");
     }
     else {
-      vertex->SetTruePos(vtxPos);  // store also the vertex from MC
       vertex->SetName("reconstructed");
     }
 
@@ -1041,29 +990,23 @@ Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
   }
   esd->SetVertex(vertex);
   // if SPD multiplicity has been determined, it is stored in the ESD
-  if (fVertexer) {
-  AliMultiplicity *mult= fVertexer->GetMultiplicity();
+  AliMultiplicity *mult = fVertexer->GetMultiplicity();
   if(mult)esd->SetMultiplicity(mult);
-  }
 
   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
     if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
   }  
   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!");
@@ -1111,19 +1054,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!");
@@ -1152,12 +1091,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");
@@ -1165,21 +1113,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");
 
@@ -1237,7 +1180,7 @@ Bool_t AliReconstruction::RunTracking(AliESD*& esd)
     // run tracking
     if (fTracker[iDet]->PropagateBack(esd) != 0) {
       AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
-      return kFALSE;
+      //      return kFALSE;
     }
     if (fCheckPointLevel > 1) {
       WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
@@ -1269,7 +1212,7 @@ Bool_t AliReconstruction::RunTracking(AliESD*& esd)
     // run tracking
     if (fTracker[iDet]->RefitInward(esd) != 0) {
       AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
-      return kFALSE;
+      //      return kFALSE;
     }
     if (fCheckPointLevel > 1) {
       WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
@@ -1295,20 +1238,15 @@ Bool_t AliReconstruction::RunTracking(AliESD*& esd)
     track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
   }
   
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   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++) {
@@ -1363,19 +1301,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) {
@@ -1414,7 +1351,7 @@ Bool_t AliReconstruction::FillTriggerESD(AliESD*& esd)
 
 
 //_____________________________________________________________________________
-Bool_t AliReconstruction::FillRawEventHeaderESD(AliESD*& esd)
+Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
 {
   // 
   // Filling information from RawReader Header
@@ -1728,7 +1665,8 @@ 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
 
@@ -1749,14 +1687,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
 
@@ -1780,7 +1721,7 @@ void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
 
 
 //_____________________________________________________________________________
-void AliReconstruction::CreateTag(TFile* file)
+void AliReconstruction::CreateTag(const char* fESDfilename)
 {
   //GRP
   Float_t lhcLuminosity = 0.0;
@@ -1828,17 +1769,17 @@ void AliReconstruction::CreateTag(TFile* file)
   btag->SetCompressionLevel(9);
   
   AliInfo(Form("Creating the tags......."));   
-  
+
+  TFile *file = TFile::Open(fESDfilename);
   if (!file || !file->IsOpen()) {
     AliError(Form("opening failed"));
     delete file;
     return ;
   }  
   Int_t lastEvent = 0;
-  TTree *t = (TTree*) file->Get("esdTree");
-  TBranch * b = t->GetBranch("ESD");
-  AliESD *esd = 0;
-  b->SetAddress(&esd);
+  TTree *b = (TTree*) file->Get("esdTree");
+  AliESDEvent *esd = new AliESDEvent();
+  esd->ReadFromTree(b);
 
   b->GetEntry(fFirstEvent);
   Int_t iInitRunNumber = esd->GetRunNumber();
@@ -2091,11 +2032,10 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
 
   // 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];
@@ -2107,7 +2047,7 @@ 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();
@@ -2115,25 +2055,29 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
     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()));
+    // Update the header
+    AliAODHeader* header = aod->GetHeader();
+    
+    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();
@@ -2705,8 +2649,8 @@ 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;
@@ -2754,8 +2698,7 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
   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
@@ -2808,7 +2751,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.
@@ -2828,3 +2771,50 @@ 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();
+  printf("Size: %d \n",kBytes);
+  TNamed *fn = 0;
+  if(in.good()){
+    char* memblock = new char [kBytes];
+    in.seekg (0, ios::beg);
+    in.read (memblock, kBytes);
+    in.close();
+    TString fData(memblock,kBytes);
+    fn = new TNamed(fName,fData);
+    printf("fData Size: %d \n",fData.Sizeof());
+    printf("fName Size: %d \n",fName.Sizeof());
+    printf("fn    Size: %d \n",fn->Sizeof());
+    delete[] memblock;
+  }
+  else{
+    AliInfo(Form("Could not Open %s\n",fPath.Data()));
+  }
+
+  return fn;
+}
+
+void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
+  // This is not really needed in AliReconstruction at the moment
+  // but can serve as a template
+
+  TList *fList = fTree->GetUserInfo();
+  TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
+  printf("fn Size: %d \n",fn->Sizeof());
+
+  TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
+  const char* cdata = fn->GetTitle();
+  printf("fTmp Size %d\n",fTmp.Sizeof());
+
+  int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
+  printf("calculated size %d\n",size);
+  ofstream out(fName.Data(),ios::out | ios::binary);
+  out.write(cdata,size);
+  out.close();
+
+}
+