diff --git a/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEvent.cxx b/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEvent.cxx
index fa8cbcae3dbaf40755c79b45b05358711da06143..0c87b143a2a0e3775c79760e7b37b93cbd33214c 100644
--- a/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEvent.cxx
+++ b/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEvent.cxx
@@ -58,8 +58,17 @@ void CbmAnaJpsiSuperEvent::Run() {
 
   Draw();
 
+  /// Save old global file and folder pointer to avoid messing with FairRoot
+  TFile* oldFile     = gFile;
+  TDirectory* oldDir = gDirectory;
+
   TFile* file = new TFile(fOutputFile.c_str(), "RECREATE");
   fHM->WriteToFile();
+
+  /// Restore old global file and folder pointer to avoid messing with FairRoot
+  gFile      = oldFile;
+  gDirectory = oldDir;
+
   file->Close();
 
   cout << "-I- Output file:" << fOutputFile << endl;
@@ -234,6 +243,11 @@ void CbmAnaJpsiSuperEvent::ReadCandidates() {
   fPlusCandidates.clear();
   cout << "-I- ReadCandidates" << endl;
   cout << "-I- fFileNames.size:" << fFileNames.size() << endl;
+
+  /// Save old global file and folder pointer to avoid messing with FairRoot
+  TFile* oldFile     = gFile;
+  TDirectory* oldDir = gDirectory;
+
   for (UInt_t iFile = 0; iFile < fFileNames.size(); iFile++) {
     cout << "-I- Reading file No " << iFile << " path:" << fFileNames[iFile]
          << endl;
@@ -278,6 +292,10 @@ void CbmAnaJpsiSuperEvent::ReadCandidates() {
     f->Close();
     delete f;
   }
+  /// Restore old global file and folder pointer to avoid messing with FairRoot
+  gFile      = oldFile;
+  gDirectory = oldDir;
+
   cout << "-I- fMinusCandidates.size:" << fMinusCandidates.size() << endl;
   cout << "-I- fPlusCandidates.size:" << fPlusCandidates.size() << endl;
   cout << "-I- number of events:" << fHM->H1("fh_se_event_number")->GetEntries()
diff --git a/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEventReport.cxx b/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEventReport.cxx
index b0f9c9f95cd4e8787a5a3fe1f664ff34ea65cbfd..6ec304c9b24529a689c226c559532a4d6143234b 100644
--- a/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEventReport.cxx
+++ b/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEventReport.cxx
@@ -38,6 +38,10 @@ CbmAnaJpsiSuperEventReport::~CbmAnaJpsiSuperEventReport() {}
 void CbmAnaJpsiSuperEventReport::Create(const string& fileEventByEvent,
                                         const string& fileSuperEvent,
                                         const string& outputDir) {
+  /// Save old global file and folder pointer to avoid messing with FairRoot
+  TFile* oldFile     = gFile;
+  TDirectory* oldDir = gDirectory;
+
   fHMSuperEvent = new CbmHistManager();
   TFile* fileSE = new TFile(fileSuperEvent.c_str());
   fHMSuperEvent->ReadFromFile(fileSE);
@@ -48,6 +52,10 @@ void CbmAnaJpsiSuperEventReport::Create(const string& fileEventByEvent,
 
   SetOutputDir(outputDir);
   CreateReports();
+
+  /// Restore old global file and folder pointer to avoid messing with FairRoot
+  gFile      = oldFile;
+  gDirectory = oldDir;
 }
 void CbmAnaJpsiSuperEventReport::Create() {
   //Out().precision(3);