]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/MUONRefit.C
Fix aborting error
[u/mrichter/AliRoot.git] / MUON / MUONRefit.C
index 706675927589c353ea5b04bd2ecc7758c78712e9..a1b85eabe5fadad37b40380c0a8d7c56ed6c4f0f 100644 (file)
 #include <TROOT.h>
 
 // STEER includes
-#include "AliMagFMaps.h"
+#include "AliMagF.h"
 #include "AliTracker.h"
 #include "AliESDEvent.h"
 #include "AliESDMuonTrack.h"
 #include "AliRecoParam.h"
 #include "AliCDBManager.h"
+#include "AliCDBEntry.h"
+#include "AliCDBPath.h"
 #include "AliGeomManager.h"
 
 // MUON includes
@@ -46,8 +48,6 @@
 #include "AliMUONESDInterface.h"
 #include "AliMUONRefitter.h"
 #include "AliMUONVDigit.h"
-#include "AliMUONVCluster.h"
-#include "AliMUONVClusterStore.h"
 #include "AliMUONTrack.h"
 #include "AliMUONVTrackStore.h"
 #include "AliMUONTrackParam.h"
@@ -70,16 +70,23 @@ void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", c
   // prepare the refitting
   gRandom->SetSeed(1);
   Prepare();
+  
+  // reconstruction parameters for the refitting
+  AliMUONRecoParam* recoParam = AliMUONRecoParam::GetLowFluxParam();
+  Info("MUONRefit", "\n Reconstruction parameters for refitting:");
+  recoParam->Print("FULL");
+  
   AliMUONESDInterface esdInterface;
-  AliMUONRefitter refitter;
+  AliMUONRefitter refitter(recoParam);
   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
@@ -101,7 +108,7 @@ 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();
@@ -113,7 +120,10 @@ void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", c
     // 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 +137,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,14 +186,13 @@ 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;
   
   cout<<endl<<"time to refit: R:"<<timer.RealTime()<<" C:"<<timer.CpuTime()<<endl<<endl;
@@ -198,26 +212,41 @@ void Prepare()
     }
   }
   
-  // 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());
+  // set  mag field 
+  // waiting for mag field in CDB 
+  if (!TGeoGlobalMagField::Instance()->GetField()) {
+    printf("Loading field map...\n");
+    AliMagF* field = new AliMagF("Maps","Maps",2,1.,1., 10.,AliMagF::k5kG);
+    TGeoGlobalMagField::Instance()->SetField(field);
+  }
+  // set the magnetic field for track extrapolations
+  AliMUONTrackExtrap::SetField();
   
   // Load mapping
   AliCDBManager* man = AliCDBManager::Instance();
-  man->SetDefaultStorage("local://$ALICE_ROOT");
+  man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
   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);
+  // Load initial reconstruction parameters from OCDB
+  AliMUONRecoParam* recoParam = 0x0;
+  AliCDBPath path("MUON","Calib","RecoParam");
+  AliCDBEntry *entry=man->Get(path.GetPath());
+  if(entry) {
+    recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject());
+    entry->SetOwner(0);
+    AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
+  }
+  if (!recoParam) {
+    printf("Couldn't find RecoParam object in OCDB: create default one");
+    recoParam = AliMUONRecoParam::GetLowFluxParam();
+  }
+  Info("MUONRefit", "\n initial recontruction parameters:");
+  recoParam->Print("FULL");
+  AliMUONESDInterface::ResetTracker(recoParam);
   
 }