From d3c3818a44102da6c9c85a801788e3ed61ee8496 Mon Sep 17 00:00:00 2001
From: Martin Beyer <martin.beyer@physik.uni-giessen.de>
Date: Fri, 1 Dec 2023 10:47:31 +0000
Subject: [PATCH] Rich: update macro/rich/run macros to be compilable and
 update batch scripts (remove hardcoded paths)

---
 macro/rich/run/batch_job.py    | 67 ++++++++++++++++-------------
 macro/rich/run/batch_send.py   | 45 +++++++++++++-------
 macro/rich/run/run_digi.C      | 24 +++++++----
 macro/rich/run/run_many.py     | 45 ++++++++++++++++++--
 macro/rich/run/run_one.py      | 77 ++++++++++++++++++----------------
 macro/rich/run/run_qa.C        | 18 ++++++--
 macro/rich/run/run_reco.C      | 23 +++++++---
 macro/rich/run/run_transport.C | 34 ++++++++++-----
 8 files changed, 223 insertions(+), 110 deletions(-)

diff --git a/macro/rich/run/batch_job.py b/macro/rich/run/batch_job.py
index 5b2b04ca92..af49218320 100755
--- a/macro/rich/run/batch_job.py
+++ b/macro/rich/run/batch_job.py
@@ -5,53 +5,62 @@ import sys
 import shutil
 
 dataDir = sys.argv[1]
-geoSetup = sys.argv[2]
-cbmrootConfigPath = "/lustre/cbm/users/mabeyer/cbmroot/build/config.sh"
-macroDir = "/lustre/cbm/users/mabeyer/cbmroot/macro/rich/run"
+configPath = sys.argv[2]
 taskId = os.environ.get('SLURM_ARRAY_TASK_ID')
 jobId = os.environ.get('SLURM_ARRAY_JOB_ID')
 
-print("dataDir:" + dataDir)
-
 workDir = dataDir + "/workdir/" + jobId + "_" + taskId + "/"
 if os.path.exists(workDir):
     shutil.rmtree(workDir)
 os.makedirs(workDir)
 os.chdir(workDir)
 
-# Settings
-nEvents = 1000
+## Settings begin ##
+randomSeed = 0
+monitor    = 0
+
+# Transport
+nEvents    = 1000
 urqmdFile  = "/lustre/cbm/prod/gen/urqmd/auau/10gev/centr/urqmd.auau.10gev.centr." + str(taskId).zfill(5) + ".root"
 plutoFile  = ""
 nElectrons = 5
 nPositrons = 5
+geoSetup   = "sis100_electron"
 engine     = 0 # 0: geant3 1: geant4
 
-randomSeed = 0
-
+# Digitization
 eventRate = -1e7
-tsLength = -1
+tsLength  = -1
+
+# Reconstruction
 eventBuilder = "Ideal"
-useMC = 1
-monitor = 0
+useMC        = 1
+
+# Qa
 resultDir = ""
 
+## Settings end ##
+
 # Files
 fileName = "data"
-traFile  = dataDir + fileName + taskId + ".tra.root"
-parFile  = dataDir + fileName + taskId + ".par.root"
-geoFile  = dataDir + fileName + taskId + ".geo.root"
-digiFile = dataDir + fileName + taskId + ".digi.root"
-recoFile = dataDir + fileName + taskId + ".reco.root"
-qaFile   = dataDir + fileName + taskId + ".qa.root"
-
-
-traCmd=('root -l -b -q {}/run_transport.C\(\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",{},{},{},\\"{}\\",\\"{}\\",{},{}\)').format(macroDir, urqmdFile, traFile, parFile, geoFile, nEvents, nElectrons, nPositrons, plutoFile, geoSetup, engine, randomSeed)
-digiCmd=('root -l -b -q {}/run_digi.C\(\\"{}\\",\\"{}\\",\\"{}\\",{},{},{},{},{}\)').format(macroDir, traFile, parFile, digiFile, nEvents, eventRate, tsLength, randomSeed, monitor)
-recoCmd=('root -l -b -q {}/run_reco.C\(\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",{},\\"{}\\",\\"{}\\",{},{}\)').format(macroDir, traFile, parFile, digiFile, recoFile, nEvents, geoSetup, eventBuilder, useMC, monitor)
-qaCmd=('root -l -b -q {}/run_qa.C\(\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",{},\\"{}\\",\\"{}\\",{}\)').format(macroDir, traFile, parFile, digiFile, recoFile, qaFile, nEvents, geoSetup, resultDir, monitor)
-
-os.system((". {} -a ; {}").format(cbmrootConfigPath, traCmd))
-os.system((". {} -a ; {}").format(cbmrootConfigPath, digiCmd))
-os.system((". {} -a ; {}").format(cbmrootConfigPath, recoCmd))
-os.system((". {} -a ; {}").format(cbmrootConfigPath, qaCmd))
+filePathNoExt = dataDir + "/data/" + fileName + taskId
+traFile  = filePathNoExt + ".tra.root"
+parFile  = filePathNoExt + ".par.root"
+geoFile  = filePathNoExt + ".geo.root"
+digiFile = filePathNoExt + ".digi.root"
+recoFile = filePathNoExt + ".reco.root"
+qaFile   = filePathNoExt + ".qa.root"
+
+traCmd  = f'root -l -b -q {"${VMCWORKDIR}"}/macro/rich/run/run_transport.C' \
+          f'\(\\"{urqmdFile}\\",\\"{traFile}\\",\\"{parFile}\\",\\"{geoFile}\\",{nEvents},{nElectrons},{nPositrons},\\"{plutoFile}\\",\\"{geoSetup}\\",{engine},{randomSeed}\)'
+digiCmd = f'root -l -b -q {"${VMCWORKDIR}"}/macro/rich/run/run_digi.C' \
+          f'\(\\"{traFile}\\",\\"{parFile}\\",\\"{digiFile}\\",{nEvents},{eventRate},{tsLength},{randomSeed},{monitor}\)'
+recoCmd = f'root -l -b -q {"${VMCWORKDIR}"}/macro/rich/run/run_reco.C' \
+          f'\(\\"{traFile}\\",\\"{parFile}\\",\\"{digiFile}\\",\\"{recoFile}\\",{nEvents},\\"{geoSetup}\\",\\"{eventBuilder}\\",{useMC},{monitor}\)'
+qaCmd   = f'root -l -b -q {"${VMCWORKDIR}"}/macro/rich/run/run_qa.C' \
+          f'\(\\"{traFile}\\",\\"{parFile}\\",\\"{digiFile}\\",\\"{recoFile}\\",\\"{qaFile}\\",{nEvents},\\"{geoSetup}\\",\\"{resultDir}\\",{monitor}\)'
+
+os.system(f'. {configPath} -a ; {traCmd}')
+os.system(f'. {configPath} -a ; {digiCmd}')
+os.system(f'. {configPath} -a ; {recoCmd}')
+os.system(f'. {configPath} -a ; {qaCmd}')
diff --git a/macro/rich/run/batch_send.py b/macro/rich/run/batch_send.py
index e79c2045cd..3e28f70c0a 100755
--- a/macro/rich/run/batch_send.py
+++ b/macro/rich/run/batch_send.py
@@ -2,23 +2,41 @@
 
 import os
 import shutil
+import argparse
 
-nJobs = 100
-timeLimit="08:00:00"
-geoSetup="sis100_electron"
-# All data in data dir will be removed
-removeData = False
-dataDir = "/lustre/cbm/users/mabeyer/cbmdata/test/"
-logFile = dataDir + "/log/log_slurm-%A_%a.out"
+parser = argparse.ArgumentParser()
+parser.description = 'Submit jobs to slurm. Change input parameters for transport/digitization/reconstruction/qa in batch_job.py'
+parser.add_argument('-r', '--remove', dest='removeData', type=bool, default=True, help='Remove all data in directory given by -d / --data')
+parser.add_argument('-j', '--jobs', dest='nJobs', type=int, required=True, help='Number of jobs')
+parser.add_argument('-c', '--config', dest='configPath', type=str, required=True, help='Path of cbmroot config file')
+parser.add_argument('-d', '--data', dest='dataDir', type=str, required=True, help='Data directory to store tra/digi/reco etc. files')
+parser.add_argument('-n', '--name', dest='jobName', type=str, default="RICH", help='Job name for slurm')
+args = parser.parse_args()
+
+print("--- Provided arguments ---")
+print("Remove data: " + str(args.removeData))
+print("Number of jobs: " + str(args.nJobs))
+print("Config Path: " + args.configPath)
+print("Data directory: " + args.dataDir)
+print("Job name: " + args.jobName)
+
+removeData = args.removeData
+nJobs      = args.nJobs
+configPath = args.configPath
+dataDir    = (args.dataDir).rstrip("/")
+jobName    = args.jobName
+
+timeLimit = "08:00:00"
+logFile   = dataDir + "/log/log_slurm-%A_%a.out"
 errorFile = dataDir + "/error/error_slurm-%A_%a.out"
-jobName = "RICH"
 
 if removeData:
-    print("All data in dataDir will be removed. Dir:" + dataDir)
-    print("Removing...")
+    print(f'\nAll data in {dataDir} will be removed.')
+    print("Removing ...")
     if os.path.exists(dataDir):
         shutil.rmtree(dataDir)
     os.makedirs(dataDir)
+    print("Done removing.")
 
 if os.path.exists(os.path.dirname(logFile)):
     shutil.rmtree(os.path.dirname(logFile))
@@ -28,8 +46,7 @@ if os.path.exists(os.path.dirname(errorFile)):
     shutil.rmtree(os.path.dirname(errorFile))
 os.makedirs(os.path.dirname(errorFile))
 
-#-p debug
-commandStr=('sbatch --job-name={} --time={} --output={} --error={} --array=1-{} batch_job.py {} {}').format(jobName, timeLimit, 
-                            logFile, errorFile, nJobs, dataDir, geoSetup)
-#print(commandStr)
+commandStr = f'sbatch --job-name={jobName} --time={timeLimit} --output={logFile} --error={errorFile} --array=1-{nJobs} batch_job.py {dataDir} {configPath}'
+# commandStr = f'sbatch -p debug --job-name={jobName} --time={timeLimit} --output={logFile} --error={errorFile} --array=1-{nJobs} batch_job.py {dataDir} {configPath}'
+print("\n--- Executing command ---\n" + commandStr)
 os.system(commandStr)
diff --git a/macro/rich/run/run_digi.C b/macro/rich/run/run_digi.C
index c43a07e903..4073d6c545 100644
--- a/macro/rich/run/run_digi.C
+++ b/macro/rich/run/run_digi.C
@@ -2,7 +2,7 @@
    SPDX-License-Identifier: GPL-3.0-only
    Authors: Semen Lebedev [committer], Andrey Lebedev, Martin Beyer */
 
-#if !defined(__CLING__)
+#if !defined(__CLING__) || defined(__ROOTCLING__)
 #include "CbmDigitization.h"
 #include "CbmRichDigitizer.h"
 
@@ -15,16 +15,24 @@
 #include <iostream>
 #endif
 
-void run_digi(TString traFile = "data/test.tra.root", TString parFile = "data/test.par.root",
-              TString digiFile = "data/test.digi.root", Int_t nEvents = -1, Double_t eventRate = -1.e7,
-              Double_t tsLength = -1, Int_t randomSeed = 0, Bool_t monitor = true)
+void run_digi(TString traFile = "", TString parFile = "", TString digiFile = "",  // i/o files
+              Int_t nEvents = -1, Double_t eventRate = -1.e7, Double_t tsLength = -1, Int_t randomSeed = 0,
+              Bool_t monitor = true)
 {
   TTree::SetMaxTreeSize(90000000000);
 
-  remove(digiFile);
-
   gRandom->SetSeed(randomSeed);
 
+  // -----   Files   --------------------------------------------------------
+  TString macroPath = __FILE__;
+  TString macroDir  = macroPath(0, macroPath.Last('/') + 1);
+  if (traFile.IsNull()) traFile = macroDir + "data/test.tra.root";
+  if (parFile.IsNull()) parFile = macroDir + "data/test.par.root";
+  if (digiFile.IsNull()) digiFile = macroDir + "data/test.geo.root";
+
+  remove(digiFile);
+  // ------------------------------------------------------------------------
+
   // -----   Logger settings   ----------------------------------------------
   FairLogger::GetLogger()->SetLogScreenLevel("INFO");
   FairLogger::GetLogger()->SetLogVerbosityLevel("LOW");
@@ -54,9 +62,7 @@ void run_digi(TString traFile = "data/test.tra.root", TString parFile = "data/te
   run.SetDigitizer(ECbmModuleId::kRich, richDigitizer, "RichPoint", true);
   // ------------------------------------------------------------------------
 
-  if (nEvents < 0) run.Run();
-  else
-    run.Run(nEvents);
+  (nEvents < 0) ? run.Run() : run.Run(nEvents);
   // ------------------------------------------------------------------------
 
   // -----   Finish   -------------------------------------------------------
diff --git a/macro/rich/run/run_many.py b/macro/rich/run/run_many.py
index 857d6a4e72..4b42669a4b 100755
--- a/macro/rich/run/run_many.py
+++ b/macro/rich/run/run_many.py
@@ -1,5 +1,44 @@
+#!/usr/bin/env python3
+
 import os
+import shutil
+import argparse
+
+parser = argparse.ArgumentParser()
+parser.description = 'Run jobs locally in parallel. Change input parameters for transport/digitization/reconstruction/qa in run_one.py'
+parser.add_argument('-r', '--remove', dest='removeData', type=bool, default=True, help='Remove all data in directory given by -d / --data')
+parser.add_argument('-j', '--jobs', dest='nJobs', type=int, default=4, help='Number of jobs')
+parser.add_argument('-c', '--config', dest='configPath', type=str, required=True, help='Path of cbmroot config file')
+parser.add_argument('-d', '--data', dest='dataDir', type=str, required=True, help='Data directory to store tra/digi/reco etc. files')
+args = parser.parse_args()
+
+print("--- Provided arguments ---")
+print("Remove data: " + str(args.removeData))
+print("Number of jobs: " + str(args.nJobs))
+print("Config Path: " + args.configPath)
+print("Data directory: " + args.dataDir)
+
+removeData = args.removeData
+nJobs      = args.nJobs
+configPath = args.configPath
+dataDir    = (args.dataDir).rstrip("/")
+
+logDir = dataDir + "/logs"
+
+if removeData:
+    print(f'\nAll data in {dataDir} will be removed.')
+    print("Removing ...")
+    if os.path.exists(dataDir):
+        shutil.rmtree(dataDir)
+    os.makedirs(dataDir)
+    print("Done removing.")
+
+if os.path.exists(logDir):
+    shutil.rmtree(logDir)
+os.makedirs(logDir)
 
-for taskId in range(4):
-	commandXterm = ('xterm -hold -e python3 run_one.py {}&').format(taskId)
-	os.system(commandXterm)
+print("\n--- Executing commands ---")
+for taskId in range(nJobs):
+    commandStr = (f'python3 run_one.py {args.dataDir} {args.configPath} {taskId} > {dataDir}/logs/output{taskId}.txt 2>&1 &')
+    print(commandStr)
+    os.system(commandStr)
diff --git a/macro/rich/run/run_one.py b/macro/rich/run/run_one.py
index 980a384b92..f1a313a46a 100755
--- a/macro/rich/run/run_one.py
+++ b/macro/rich/run/run_one.py
@@ -3,49 +3,56 @@
 import os
 import sys
 
-runId = sys.argv[1]
-cbmrootConfigPath = "/home/martin/cbm/cbmroot/build/config.sh"
-macroDir = "/home/martin/cbm/cbmroot/macro/rich/run"
+dataDir = sys.argv[1]
+configPath = sys.argv[2]
+runId = sys.argv[3]
 
-# Settings
-nEvents = 100
-urqmdFile  = "default10gev"
+## Settings begin ##
+randomSeed = 0
+monitor    = 0
+
+# Transport
+nEvents    = 1
+urqmdFile  = ""
 plutoFile  = ""
 nElectrons = 5
 nPositrons = 5
-engine     = 0 # 0: geant3 1: geant4
-
 geoSetup   = "sis100_electron"
-randomSeed = 0
+engine     = 0 # 0: geant3 1: geant4
 
+# Digitization
 eventRate = -1e7
-tsLength = -1
+tsLength  = -1
+
+# Reconstruction
 eventBuilder = "Ideal"
-useMC = 1
-monitor = 0
+useMC        = 1
+
+# Qa
 resultDir = ""
-# resultDir = "results_recoqa_" + runId + "/"
+
+## Settings end ##
 
 # Files
-dataDir  = "/home/martin/cbm/cbmroot/macro/rich/run/data/"
-fileName = "test"
-traFile  = dataDir + fileName + runId + ".tra.root"
-parFile  = dataDir + fileName + runId + ".par.root"
-geoFile  = dataDir + fileName + runId + ".geo.root"
-digiFile = dataDir + fileName + runId + ".digi.root"
-recoFile = dataDir + fileName + runId + ".reco.root"
-qaFile   = dataDir + fileName + runId + ".qa.root"
-# traFile = "/home/martin/cbm/cbmroot/macro/rich/run/data/test.tra.root"
-# parFile = "/home/martin/cbm/cbmroot/macro/rich/run/data/test.par.root"
-# digiFile = "/home/martin/cbm/cbmroot/macro/rich/run/data/test.digi.root"
-
-
-traCmd=('root -l -b -q {}/run_transport.C\(\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",{},{},{},\\"{}\\",\\"{}\\",{},{}\)').format(macroDir, urqmdFile, traFile, parFile, geoFile, nEvents, nElectrons, nPositrons, plutoFile, geoSetup, engine, randomSeed)
-digiCmd=('root -l -b -q {}/run_digi.C\(\\"{}\\",\\"{}\\",\\"{}\\",{},{},{},{},{}\)').format(macroDir, traFile, parFile, digiFile, nEvents, eventRate, tsLength, randomSeed, monitor)
-recoCmd=('root -l -b -q {}/run_reco.C\(\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",{},\\"{}\\",\\"{}\\",{},{}\)').format(macroDir, traFile, parFile, digiFile, recoFile, nEvents, geoSetup, eventBuilder, useMC, monitor)
-qaCmd=('root -l -b -q {}/run_qa.C\(\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",{},\\"{}\\",\\"{}\\",{}\)').format(macroDir, traFile, parFile, digiFile, recoFile, qaFile, nEvents, geoSetup, resultDir, monitor)
-
-os.system((". {} -a ; {}").format(cbmrootConfigPath, traCmd))
-os.system((". {} -a ; {}").format(cbmrootConfigPath, digiCmd))
-os.system((". {} -a ; {}").format(cbmrootConfigPath, recoCmd))
-os.system((". {} -a ; {}").format(cbmrootConfigPath, qaCmd))
+fileName = "data"
+filePathNoExt = dataDir + "/data/" + fileName + runId
+traFile  = filePathNoExt + ".tra.root"
+parFile  = filePathNoExt + ".par.root"
+geoFile  = filePathNoExt + ".geo.root"
+digiFile = filePathNoExt + ".digi.root"
+recoFile = filePathNoExt + ".reco.root"
+qaFile   = filePathNoExt + ".qa.root"
+
+traCmd  = f'root -l -b -q {"${VMCWORKDIR}"}/macro/rich/run/run_transport.C' \
+          f'\(\\"{urqmdFile}\\",\\"{traFile}\\",\\"{parFile}\\",\\"{geoFile}\\",{nEvents},{nElectrons},{nPositrons},\\"{plutoFile}\\",\\"{geoSetup}\\",{engine},{randomSeed}\)'
+digiCmd = f'root -l -b -q {"${VMCWORKDIR}"}/macro/rich/run/run_digi.C' \
+          f'\(\\"{traFile}\\",\\"{parFile}\\",\\"{digiFile}\\",{nEvents},{eventRate},{tsLength},{randomSeed},{monitor}\)'
+recoCmd = f'root -l -b -q {"${VMCWORKDIR}"}/macro/rich/run/run_reco.C' \
+          f'\(\\"{traFile}\\",\\"{parFile}\\",\\"{digiFile}\\",\\"{recoFile}\\",{nEvents},\\"{geoSetup}\\",\\"{eventBuilder}\\",{useMC},{monitor}\)'
+qaCmd   = f'root -l -b -q {"${VMCWORKDIR}"}/macro/rich/run/run_qa.C' \
+          f'\(\\"{traFile}\\",\\"{parFile}\\",\\"{digiFile}\\",\\"{recoFile}\\",\\"{qaFile}\\",{nEvents},\\"{geoSetup}\\",\\"{resultDir}\\",{monitor}\)'
+
+os.system(f'. {configPath} -a ; {traCmd}')
+os.system(f'. {configPath} -a ; {digiCmd}')
+os.system(f'. {configPath} -a ; {recoCmd}')
+os.system(f'. {configPath} -a ; {qaCmd}')
diff --git a/macro/rich/run/run_qa.C b/macro/rich/run/run_qa.C
index a146ff4a92..aecfafd390 100644
--- a/macro/rich/run/run_qa.C
+++ b/macro/rich/run/run_qa.C
@@ -33,14 +33,24 @@
 #include <string>
 #endif
 
-void run_qa(TString traFile = "data/test.tra.root", TString parFile = "data/test.par.root",
-            TString digiFile = "data/test.digi.root", TString recoFile = "data/test.reco.root",
-            TString qaFile = "data/test.qa.root", Int_t nofTimeSlices = -1, TString geoSetup = "sis100_electron",
-            TString resultDir = "", Bool_t monitor = true)
+void run_qa(TString traFile = "", TString parFile = "", TString digiFile = "", TString recoFile = "",
+            TString qaFile      = "",  // i/o files
+            Int_t nofTimeSlices = -1, TString geoSetup = "sis100_electron", TString resultDir = "",
+            Bool_t monitor = true)
 {
   TTree::SetMaxTreeSize(90000000000);
 
+  // -----   Files   --------------------------------------------------------
+  TString macroPath = __FILE__;
+  TString macroDir  = macroPath(0, macroPath.Last('/') + 1);
+  if (traFile.IsNull()) traFile = macroDir + "data/test.tra.root";
+  if (parFile.IsNull()) parFile = macroDir + "data/test.par.root";
+  if (digiFile.IsNull()) digiFile = macroDir + "data/test.geo.root";
+  if (recoFile.IsNull()) recoFile = macroDir + "data/test.reco.root";
+  if (qaFile.IsNull()) qaFile = macroDir + "data/test.qa.root";
+
   remove(qaFile);
+  // ------------------------------------------------------------------------
 
   // -----   Logger settings   ----------------------------------------------
   FairLogger::GetLogger()->SetLogScreenLevel("INFO");
diff --git a/macro/rich/run/run_reco.C b/macro/rich/run/run_reco.C
index fd74221d42..92d7ddd9d4 100644
--- a/macro/rich/run/run_reco.C
+++ b/macro/rich/run/run_reco.C
@@ -2,7 +2,7 @@
    SPDX-License-Identifier: GPL-3.0-only
    Authors: Semen Lebedev [committer], Andrey Lebedev, Martin Beyer */
 
-#if !defined(__CLING__)
+#if !defined(__CLING__) || defined(__ROOTCLING__)
 #include "CbmBuildEventsFromTracksReal.h"
 #include "CbmBuildEventsIdeal.h"
 #include "CbmBuildEventsQa.h"
@@ -49,14 +49,22 @@
 #include <iostream>
 #endif
 
-void run_reco(TString traFile = "data/test.tra.root", TString parFile = "data/test.par.root",
-              TString digiFile = "data/test.digi.root", TString recoFile = "data/test.reco.root",
+void run_reco(TString traFile = "", TString parFile = "", TString digiFile = "", TString recoFile = "",  // i/o files
               Int_t nofTimeSlices = -1, TString geoSetup = "sis100_electron", TString sEvBuildRaw = "Ideal",
               Bool_t useMC = true, Bool_t monitor = true)
 {
   TTree::SetMaxTreeSize(90000000000);
 
+  // -----   Files   --------------------------------------------------------
+  TString macroPath = __FILE__;
+  TString macroDir  = macroPath(0, macroPath.Last('/') + 1);
+  if (traFile.IsNull()) traFile = macroDir + "data/test.tra.root";
+  if (parFile.IsNull()) parFile = macroDir + "data/test.par.root";
+  if (digiFile.IsNull()) digiFile = macroDir + "data/test.geo.root";
+  if (recoFile.IsNull()) recoFile = macroDir + "data/test.reco.root";
+
   remove(recoFile);
+  // ------------------------------------------------------------------------
 
   // --- Logger settings ----------------------------------------------------
   FairLogger::GetLogger()->SetLogScreenLevel("INFO");
@@ -119,7 +127,7 @@ void run_reco(TString traFile = "data/test.tra.root", TString parFile = "data/te
 
   // -----   FairRunAna   ---------------------------------------------------
   FairFileSource* inputSource = new FairFileSource(digiFile);
-  if (useMC) { inputSource->AddFriend(traFile); }
+  if (useMC) inputSource->AddFriend(traFile);
 
   FairRunAna* run = new FairRunAna();
   run->SetSource(inputSource);
@@ -239,9 +247,12 @@ void run_reco(TString traFile = "data/test.tra.root", TString parFile = "data/te
 
     Double_t triggerThreshold       = 0.5e-6;  // SIS100
     CbmTrdClusterFinder* trdCluster = new CbmTrdClusterFinder();
-    if (eventBased) trdCluster->SetTimeBased(kFALSE);
-    else
+    if (eventBased) {
+      trdCluster->SetTimeBased(kFALSE);
+    }
+    else {
       trdCluster->SetTimeBased(kTRUE);
+    }
     trdCluster->SetNeighbourEnable(true, false);
     trdCluster->SetMinimumChargeTH(triggerThreshold);
     trdCluster->SetRowMerger(true);
diff --git a/macro/rich/run/run_transport.C b/macro/rich/run/run_transport.C
index f8753bb3d9..e29ddb7397 100644
--- a/macro/rich/run/run_transport.C
+++ b/macro/rich/run/run_transport.C
@@ -2,8 +2,7 @@
    SPDX-License-Identifier: GPL-3.0-only
    Authors: Semen Lebedev [committer], Martin Beyer */
 
-#if !defined(__CLING__)
-#include "CbmRich.h"
+#if !defined(__CLING__) || defined(__ROOTCLING__)
 #include "CbmTransport.h"
 
 #include <FairBoxGenerator.h>
@@ -17,8 +16,8 @@
 #endif
 
 void run_transport(TString urqmdFile = "default10gev",  // if "", no urqmd; "default10gev" or "default25gev"
-                   TString traFile = "data/test.tra.root", TString parFile = "data/test.par.root",
-                   TString geoFile = "data/test.geo.root", Int_t nEvents = 1,
+                   TString traFile = "", TString parFile = "", TString geoFile = "",  // i/o files
+                   Int_t nEvents     = 1,
                    Int_t nElectrons  = 5,   // number of embedded e- into each event, generated by the BoxGenerator
                    Int_t nPositrons  = 5,   // number of embedded e+ into each event, generated by the BoxGenerator
                    TString plutoFile = "",  // if "", no pluto particles are embedded into event
@@ -27,11 +26,19 @@ void run_transport(TString urqmdFile = "default10gev",  // if "", no urqmd; "def
 {
   TTree::SetMaxTreeSize(90000000000);
 
+  Double_t targetZ = -44.0;
+
+  // -----   Files   --------------------------------------------------------
+  TString macroPath = __FILE__;
+  TString macroDir  = macroPath(0, macroPath.Last('/') + 1);
+  if (traFile.IsNull()) traFile = macroDir + "data/test.tra.root";
+  if (parFile.IsNull()) parFile = macroDir + "data/test.par.root";
+  if (geoFile.IsNull()) geoFile = macroDir + "data/test.geo.root";
+
   remove(traFile);
   remove(parFile);
   remove(geoFile);
-
-  Double_t targetZ = -44.0;
+  // ------------------------------------------------------------------------
 
   // -----   Logger settings   ----------------------------------------------
   FairLogger::GetLogger()->SetLogScreenLevel("INFO");
@@ -76,15 +83,22 @@ void run_transport(TString urqmdFile = "default10gev",  // if "", no urqmd; "def
     run.AddInput(boxGen2);
   }
 
-  if (!plutoFile.IsNull()) { run.AddInput(plutoFile, kPluto); }
+  if (!plutoFile.IsNull()) {
+    run.AddInput(plutoFile, kPluto);
+  }
 
   if (!urqmdFile.IsNull()) {
-    if (urqmdFile == "default10gev") run.AddInput(defaultInput10gev);
-    else if (urqmdFile == "default25gev")
+    if (urqmdFile == "default10gev") {
+      run.AddInput(defaultInput10gev);
+    }
+    else if (urqmdFile == "default25gev") {
       run.AddInput(defaultInput25gev);
-    else
+    }
+    else {
       run.AddInput(urqmdFile);
+    }
   }
+
   run.SetOutFileName(traFile);
   run.SetParFileName(parFile);
   run.SetGeoFileName(geoFile);
-- 
GitLab