diff --git a/analysis/PWGC2F/femtoscopy/nicafemto/format/anatree/CbmAnaTreeSource.cxx b/analysis/PWGC2F/femtoscopy/nicafemto/format/anatree/CbmAnaTreeSource.cxx
index 85b2389088665efc3342448ea4965ffc3873cc23..b4803bbadfb70b8140cf481f9a248380e47243fa 100644
--- a/analysis/PWGC2F/femtoscopy/nicafemto/format/anatree/CbmAnaTreeSource.cxx
+++ b/analysis/PWGC2F/femtoscopy/nicafemto/format/anatree/CbmAnaTreeSource.cxx
@@ -104,6 +104,10 @@ Int_t CbmAnaTreeSource::ReadEvent(UInt_t unsignedInt) {
 void CbmAnaTreeSource::Close() {}
 
 void CbmAnaTreeSource::LoadConf(TString name) {
+  /// Save old global file and folder pointer to avoid messing with FairRoot
+  TFile* oldFile     = gFile;
+  TDirectory* oldDir = gDirectory;
+
   TFile* f = new TFile(name);
   // TTree *tree = (TTree*)f->Get("aTree");
   AnalysisTree::Configuration* conf =
@@ -155,6 +159,10 @@ void CbmAnaTreeSource::LoadConf(TString name) {
       conf->GetBranchConfig("SimEventHeader").GetFieldId("psi_RP");
   }
 
+  /// Restore old global file and folder pointer to avoid messing with FairRoot
+  gFile      = oldFile;
+  gDirectory = oldDir;
+
   f->Close();
   delete f;
 }