]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/MUONRefit.C
Adding counter for TOKEN_LOST errors in AliMUONRawStreamTrackerHP.
[u/mrichter/AliRoot.git] / MUON / MUONRefit.C
index 706675927589c353ea5b04bd2ecc7758c78712e9..69d299d5c7169e5e4123d6771cce7ce273c1a566 100644 (file)
 #include <TROOT.h>
 
 // STEER includes
-#include "AliMagFMaps.h"
-#include "AliTracker.h"
 #include "AliESDEvent.h"
 #include "AliESDMuonTrack.h"
-#include "AliRecoParam.h"
 #include "AliCDBManager.h"
 #include "AliGeomManager.h"
 
 // MUON includes
-#include "AliMpCDB.h"
+#include "AliMUONCDB.h"
 #include "AliMUONRecoParam.h"
 #include "AliMUONESDInterface.h"
 #include "AliMUONRefitter.h"
 #include "AliMUONVDigit.h"
-#include "AliMUONVCluster.h"
-#include "AliMUONVClusterStore.h"
 #include "AliMUONTrack.h"
 #include "AliMUONVTrackStore.h"
 #include "AliMUONTrackParam.h"
-#include "AliMUONTrackExtrap.h"
 #endif
 
 const Int_t printLevel = 1;
 
-void Prepare();
 TTree* GetESDTree(TFile *esdFile);
 
 //-----------------------------------------------------------------------
-void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", const char* esdFileNameOut = "AliESDs_New.root")
+void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", const char* esdFileNameOut = "AliESDs_New.root",
+              const char* geoFilename = "geometry.root", const char* ocdbPath = "local://$ALICE_ROOT/OCDB")
 {
+  /// Example of muon refitting:
   /// refit ESD tracks from ESD pads (i.e. re-clusterized the attached ESD clusters);
   /// reset the charge of the digit using their raw charge before refitting;
   /// compare results with original ESD tracks; 
   /// write results in a new ESD file
   
-  // prepare the refitting
-  gRandom->SetSeed(1);
-  Prepare();
-  AliMUONESDInterface esdInterface;
-  AliMUONRefitter refitter;
-  refitter.Connect(&esdInterface);
-  
   // open the ESD file and tree
   TFile* esdFile = TFile::Open(esdFileNameIn);
   TTree* esdTree = GetESDTree(esdFile);
   
-  // create the ESD output tree
-  gROOT->cd();
+  // create the ESD output file and tree
+  TFile* newESDFile = TFile::Open(esdFileNameOut, "RECREATE");
+  newESDFile->SetCompressionLevel(2);
   TTree* newESDTree = esdTree->CloneTree(0);
   
   // connect ESD event to the ESD tree
   AliESDEvent* esd = new AliESDEvent();
   esd->ReadFromTree(esdTree);
-
+  
+  // get run number
+  if (esdTree->GetEvent(0) <= 0) {
+    Error("MUONRefit", "no ESD object found for event 0");
+    return;
+  }
+  Int_t runNumber = esd->GetRunNumber();
+  
+  // Import TGeo geometry
+  if (!gGeoManager) {
+    AliGeomManager::LoadGeometry(geoFilename);
+    if (!gGeoManager) {
+      Error("MUONRefit", "getting geometry from file %s failed", "generated/galice.root");
+      exit(-1);
+    }
+  }
+  
+  // load necessary data from OCDB
+  AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
+  AliCDBManager::Instance()->SetRun(runNumber);
+  if (!AliMUONCDB::LoadField()) return;
+  if (!AliMUONCDB::LoadMapping(kTRUE)) return;
+  
+  // reconstruction parameters for the refitting
+  AliMUONRecoParam* recoParam = AliMUONRecoParam::GetLowFluxParam();
+  Info("MUONRefit", "\n Reconstruction parameters for refitting:");
+  recoParam->Print("FULL");
+  
+  AliMUONESDInterface esdInterface;
+  AliMUONRefitter refitter(recoParam);
+  refitter.Connect(&esdInterface);
+  gRandom->SetSeed(1);
+  
   // timer start...
   TStopwatch timer;
   
@@ -101,19 +122,22 @@ void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", c
     // get the ESD of current event
     esdTree->GetEvent(iEvent);
     if (!esd) {
-      Error("CheckESD", "no ESD object found for event %d", iEvent);
+      Error("MUONRefit", "no ESD object found for event %d", iEvent);
       return;
     }
     Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks();
     if (nTracks < 1) continue;
     
     // load the current event
-    esdInterface.LoadEvent(*esd);
+    esdInterface.LoadEvent(*esd, kFALSE);
     
     // loop over digit to modify their charge
     AliMUONVDigit *digit;
     TIter next(esdInterface.CreateDigitIterator());
-    while ((digit = static_cast<AliMUONVDigit*>(next()))) digit->SetCharge(digit->ADC());
+    while ((digit = static_cast<AliMUONVDigit*>(next()))) {
+      digit->SetCharge(digit->ADC());
+      digit->Calibrated(kFALSE);
+    }
     
     // refit the tracks from digits
     AliMUONVTrackStore* newTrackStore = refitter.ReconstructFromDigits();
@@ -127,8 +151,13 @@ void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", c
       
       // get the ESD track
       AliESDMuonTrack* esdTrack = (AliESDMuonTrack*) esdTracks->UncheckedAt(iTrack);
+      
+      // skip ghost tracks (leave them unchanged in the new ESD file)
+      if (!esdTrack->ContainTrackerData()) continue;
+      
       // get the corresponding MUON track
       AliMUONTrack* track = esdInterface.FindTrack(esdTrack->GetUniqueID());
+      
       // Find the corresponding re-fitted MUON track
       AliMUONTrack* newTrack = (AliMUONTrack*) newTrackStore->FindObject(esdTrack->GetUniqueID());
       
@@ -171,56 +200,19 @@ void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", c
   timer.Stop();
   
   // write output ESD tree
-  TFile* newESDFile = TFile::Open(esdFileNameOut, "RECREATE");
-  newESDFile->SetCompressionLevel(2);
+  newESDFile->cd();
   newESDTree->Write();
+  delete newESDTree;
   newESDFile->Close();
   
   // free memory
   esdFile->Close();
-  delete newESDTree;
   delete esd;
+  delete recoParam;
   
   cout<<endl<<"time to refit: R:"<<timer.RealTime()<<" C:"<<timer.CpuTime()<<endl<<endl;
 }
 
-//-----------------------------------------------------------------------
-void Prepare()
-{
-  /// Set the geometry, the magnetic field, the mapping and the reconstruction parameters
-  
-  // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
-  if (!gGeoManager) {
-    AliGeomManager::LoadGeometry("geometry.root");
-    if (!gGeoManager) {
-      Error("MUONRefit", "getting geometry from file %s failed", "generated/galice.root");
-      return;
-    }
-  }
-  
-  // set mag field
-  printf("Loading field map...\n");
-  AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
-  AliTracker::SetFieldMap(field, kFALSE);
-  AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
-  
-  // Load mapping
-  AliCDBManager* man = AliCDBManager::Instance();
-  man->SetDefaultStorage("local://$ALICE_ROOT");
-  man->SetRun(0);
-  if ( ! AliMpCDB::LoadDDLStore() ) {
-    Error("MUONRefit","Could not access mapping from OCDB !");
-    exit(-1);
-  }
-  
-  // set reconstruction parameters
-  AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLowFluxParam();
-  muonRecoParam->CombineClusterTrackReco(kFALSE);
-  muonRecoParam->Print("FULL");
-  AliRecoParam::Instance()->RegisterRecoParam(muonRecoParam);
-  
-}
-
 //-----------------------------------------------------------------------
 TTree* GetESDTree(TFile *esdFile)
 {