From aac5170cdd6817a86cb6e03ce30ce3d5b19e6a5d Mon Sep 17 00:00:00 2001
From: FaserMC <fasermc@cern.ch>
Date: Mon, 15 Jan 2024 00:15:13 +0100
Subject: [PATCH] Update logic of job submission scripts

---
 .../Digitization/scripts/faser_digi.py        |  2 +-
 .../Digitization/scripts/faser_digi_merge.py  |  2 +-
 .../Digitization/scripts/submit_faser_digi.sh | 55 ++++++++++---
 .../scripts/submit_faser_digi_merge.sh        | 63 +++++++++++---
 .../scripts/submit_faser_particlegun.sh       | 67 +++++++++++----
 .../Reconstruction/scripts/faser_reco.py      | 19 +++--
 .../scripts/submit_faser_reco.sh              | 57 ++++++++++---
 .../Simulation/scripts/faser_simulate.py      |  2 +-
 .../scripts/submit_faser_simulate.sh          | 82 ++++++++++++++-----
 .../scripts/faser_ntuple_maker.py             | 30 ++++++-
 .../scripts/submit_faser_ntuple_maker.sh      | 14 +++-
 11 files changed, 310 insertions(+), 83 deletions(-)

diff --git a/Control/CalypsoExample/Digitization/scripts/faser_digi.py b/Control/CalypsoExample/Digitization/scripts/faser_digi.py
index 0fba47c33..e718e7c2d 100755
--- a/Control/CalypsoExample/Digitization/scripts/faser_digi.py
+++ b/Control/CalypsoExample/Digitization/scripts/faser_digi.py
@@ -87,7 +87,7 @@ elif runtype == "TI12MC" or runtype == "TI12MC04":
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"
 
 elif runtype == "TI12MC03":
-    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" # New geometry
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" 
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03"
 
 else:
diff --git a/Control/CalypsoExample/Digitization/scripts/faser_digi_merge.py b/Control/CalypsoExample/Digitization/scripts/faser_digi_merge.py
index 12419040e..bc60bc057 100755
--- a/Control/CalypsoExample/Digitization/scripts/faser_digi_merge.py
+++ b/Control/CalypsoExample/Digitization/scripts/faser_digi_merge.py
@@ -197,7 +197,7 @@ elif runtype == "TI12MC" or runtype == "TI12MC04":
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"
 
 elif runtype == "TI12MC03":
-    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" # New geometry
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" # Old geometry
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03"
 
 else:
diff --git a/Control/CalypsoExample/Digitization/scripts/submit_faser_digi.sh b/Control/CalypsoExample/Digitization/scripts/submit_faser_digi.sh
index fcf5e2045..539c836a7 100644
--- a/Control/CalypsoExample/Digitization/scripts/submit_faser_digi.sh
+++ b/Control/CalypsoExample/Digitization/scripts/submit_faser_digi.sh
@@ -2,9 +2,9 @@
 # Used with a condor file to submit to vanilla universe
 #
 # Usage:
-# submit_faser_digi.sh filepath [release_directory] [working_directory]
+# submit_faser_digi.sh [--script_options --] filepath [release_directory] [working_directory] [--other_options]
 #
-# Options:
+# Script Options:
 #   --digiTag <tag> - override digitization tag for calo gain
 #   --geom - geometry setting
 #   --out - specify output location (in EOS) to copy output HITS file
@@ -14,6 +14,8 @@
 # release_directory - optional path to release install directory (default pwd)
 # working_directory - optional path to output directory location (default pwd)
 #
+# Other Options will be passed to digi script
+#
 # The release directory must already be set up 
 # (so an unqualified asetup can set up the release properly)
 #
@@ -68,9 +70,36 @@ do
 done
 #
 # Parse command-line options
-file_path=${1}
-release_directory=${2}
-working_directory=${3}
+while [ -n "$1" ]
+do
+    case "$1" in
+        --) # Stop parsing
+            shift;  # Eat this
+            break;; # and stop parsing
+
+	-*) # Some option                                          
+            break;; # Stop parsing
+
+        *)  # Not an option, fill next parameter value
+
+	    if [ -z "$file_path" ]
+	    then
+		file_path=${1}
+		shift
+	    elif [ -z "$release_directory" ]
+	    then
+		release_directory=${1}
+		shift
+	    elif [ -z "$working_directory" ]
+	    then
+		working_directory=${1}
+		shift
+	    else
+		break # Already filled everything
+	    fi
+	    ;;
+    esac
+done
 #
 # Set defaults if arguments aren't provided
 if [ -z "$file_path" ]
@@ -125,17 +154,16 @@ echo "Time: $timestr"
 echo "Release: $release_directory"
 echo "Output: $output_directory"
 echo "Starting: $starting_directory"
+echo "Remaining: $@"
 #
 # Set up the release (do this automatically)?
+# Must follow with -- to avoid command-line arguments being passed
 export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
-source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh 
+source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh --
 #
-# Try automatic
 # Always go back to the starting directory in case paths are relative
 cd "$starting_directory"
 cd "$release_directory"
-# asetup
-# source build/x8*/setup.sh
 #
 # Do this by hand
 asetup --input=calypso/asetup.faser Athena,22.0.49
@@ -185,10 +213,15 @@ cd "$file_stem"
 #
 # Run job
 #
-faser_digi.py $geomstr $gainstr $timestr $tagstr "$file_path"
+echo
+echo "Submit job:"
+echo faser_digi.py $geomstr $gainstr $timestr $tagstr "$@" "$file_path"
+echo
+#
+faser_digi.py $geomstr $gainstr $timestr $tagstr "$@" "$file_path"
 digi_code=$?
+#
 echo "Return code: $digi_code"
-
 #
 # Print out ending time
 date
diff --git a/Control/CalypsoExample/Digitization/scripts/submit_faser_digi_merge.sh b/Control/CalypsoExample/Digitization/scripts/submit_faser_digi_merge.sh
index 50278c33e..ab9e886e4 100755
--- a/Control/CalypsoExample/Digitization/scripts/submit_faser_digi_merge.sh
+++ b/Control/CalypsoExample/Digitization/scripts/submit_faser_digi_merge.sh
@@ -2,9 +2,9 @@
 # Used with a condor file to submit to vanilla universe
 #
 # Usage:
-# submit_faser_digi_merge.sh dirpath slice nfiles [release_directory] [working_directory] 
+# submit_faser_digi_merge.sh [--script_options --] dirpath slice nfiles [release_directory] [working_directory] [--other_options]
 #
-# Options:
+# Script Options:
 #   --digiTag <tag> - override digitization tag for calo gain
 #   --partial - allow missing files in merge
 #   --geom - geometry setting
@@ -17,6 +17,8 @@
 # release_directory - optional path to release install directory (default pwd)
 # working_directory - optional path to output directory location (default pwd)
 #
+# Other Options will be passed to job script
+#
 # The release directory must already be set up 
 # (so an unqualified asetup can set up the release properly)
 #
@@ -82,11 +84,44 @@ do
 done
 #
 # Parse command-line options
-dir_path=${1}
-slice=${2}
-nfiles=${3}
-release_directory=${4}
-working_directory=${5}
+while [ -n "$1" ]
+do
+    case "$1" in
+        --) # Stop parsing
+            shift;  # Eat this
+            break;; # and stop parsing
+
+	-*) # Some option                                          
+            break;; # Stop parsing
+
+        *)  # Not an option, fill next parameter value
+
+	    if [ -z "$dir_path" ]
+	    then
+		dir_path=${1}
+		shift
+	    elif [ -z "$slice" ]
+	    then
+		slice=${1}
+		shift
+	    elif [ -z "$nfiles" ]
+	    then
+		nfiles=${1}
+		shift
+	    elif [ -z "$release_directory" ]
+	    then
+		release_directory=${1}
+		shift
+	    elif [ -z "$working_directory" ]
+	    then
+		working_directory=${1}
+		shift
+	    else
+		break # Already filled everything
+	    fi
+	    ;;
+    esac
+done
 #
 # Set defaults if arguments aren't provided
 if [ -z "$dir_path" ]
@@ -161,17 +196,16 @@ echo "Release: $release_directory"
 echo "Output: $output_directory"
 echo "Starting: $starting_directory"
 echo "job: $file_stem"
+echo "Remaining: $@"
 #
 # Set up the release (do this automatically)?
+# Must follow with -- to avoid command-line arguments being passed
 export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
-source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh 
+source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh --
 #
-# Try automatic
 # Always go back to the starting directory in case paths are relative
 cd "$starting_directory"
 cd "$release_directory"
-# asetup
-# source build/x8*/setup.sh
 #
 # Do this by hand
 asetup --input=calypso/asetup.faser Athena,22.0.49
@@ -221,7 +255,12 @@ cd "$file_stem"
 #
 # Run job
 #
-faser_digi_merge.py $partialstr $geomstr $gainstr $timestr $tagstr --slice $slice --files $nfiles $dir_path
+echo
+echo "Submit job:"
+echo faser_digi_merge.py $partialstr $geomstr $gainstr $timestr $tagstr --slice $slice --files $nfiles "$@" $dir_path
+echo
+#
+faser_digi_merge.py $partialstr $geomstr $gainstr $timestr $tagstr --slice $slice --files $nfiles "$@" $dir_path
 digi_code=$?
 echo "Return code: $digi_code"
 #
diff --git a/Control/CalypsoExample/Generation/scripts/submit_faser_particlegun.sh b/Control/CalypsoExample/Generation/scripts/submit_faser_particlegun.sh
index 441ef2923..9706a6c3c 100755
--- a/Control/CalypsoExample/Generation/scripts/submit_faser_particlegun.sh
+++ b/Control/CalypsoExample/Generation/scripts/submit_faser_particlegun.sh
@@ -2,9 +2,9 @@
 # Used with a condor file to submit to vanilla universe
 #
 # Usage:
-# submit_faser_particlegun.sh config_file segment [release_directory] [working_directory] 
+# submit_faser_particlegun.sh [script_options --] config_file segment [release_directory] [working_directory] [--other_options]
 # 
-# Options:
+# Script Options:
 #   --out - specify output location (in EOS) to copy output HITS file
 #   --log - specify output location (in EOS) for log file
 #
@@ -13,6 +13,8 @@
 # release_directory - optional path to release install directory (default pwd)
 # working_directory - optional path to output directory location (default pwd)
 #
+# Other Options will be passed directly to job script
+#
 # Afterwards, the output file will be copied to the directory specified in working_directory
 #
 # The release directory must already be set up 
@@ -52,10 +54,40 @@ do
 done
 #
 # Parse command-line options
-config_path=${1}
-segment=${2}
-release_directory=${3}
-working_directory=${4}
+while [ -n "$1" ]
+do
+    case "$1" in
+	--) # Stop parsing
+	    shift;  # Eat this
+	    break;; # and stop parsing
+	
+	-*) # Some option
+	    break;; # Stop parsing
+
+	*)  # Not an option, fill next parameter value
+
+	    if [ -z "$config_path" ]
+	    then
+		config_path=${1}
+		shift
+	    elif [ -z "$segment" ]
+	    then
+		segment=${1}
+		shift
+	    elif [ -z "$release_directory" ]
+	    then
+		release_directory=${1}
+		shift
+	    elif [ -z "$working_directory" ]
+	    then
+		working_directory=${1}
+		shift
+	    else
+		break # Already filled everything
+	    fi
+	    ;;
+    esac
+done
 #
 # Set defaults if arguments aren't provided
 if [ -z "$config_path" ]; then
@@ -125,22 +157,21 @@ echo "Segment: $seg_str"
 echo "Release: $release_directory"
 echo "Output: $output_directory"
 echo "Starting: $starting_directory"
+echo "Remaining: $@"
 #
 # Set up the release (do this automatically)?
+# Must follow with -- to avoid command-line arguments being passed
 export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
-source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh 
+source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh --
 #
-# Try automatic
 # Always go back to the starting directory in case paths are relative
 cd "$starting_directory"
 cd "$release_directory"
-# This doesn't seem to work, as we need the --input argument
-#asetup 
-#source build/x8*/setup.sh
 #
 # Do this by hand
 asetup --input=calypso/asetup.faser Athena,22.0.49
 source run/setup.sh
+#
 echo "ATLAS_POOLCOND_PATH = $ATLAS_POOLCOND_PATH"
 #
 #
@@ -184,12 +215,18 @@ cd "${config_file_stem}-${seg_str}"
 #
 # Run job
 if [[ -z "$tag" ]]; then
-    faser_particlegun.py  "--conf=$config_path" "--segment=$seg_str"
-    gen_code=$?
+    tagstr=""
 else
-    faser_particlegun.py  "--conf=$config_path" "--segment=$seg_str" "--tag=$tag"
-    gen_code=$?
+    tagstr="--reco=$tag"
 fi
+#
+echo
+echo "Submit job:"
+echo faser_particlegun.py  "--conf=$config_path" "--segment=$seg_str" $tagstr "$@" 
+echo
+faser_particlegun.py  "--conf=$config_path" "--segment=$seg_str" $tagstr "$@" 
+gen_code=$?
+#
 echo "Return code: $gen_code"
 #
 # Print out ending time
diff --git a/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py b/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py
index 3709866af..7364646c2 100755
--- a/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py
+++ b/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py
@@ -61,7 +61,7 @@ elif args.testBeam:
     runtype = "TestBeamData"
 
 else:
-    print(f"Assuming TI12 geometry")
+    print(f"Assuming 2024 TI12 geometry (TI12Data04)")
     runtype = "TI12Data04"
 
     # Try to pick correct geometry from run number
@@ -128,7 +128,7 @@ if runtype == "TI12Data":
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-01"
 
 # Testbeam setup 
-elif runtype == "TestBeamData" or runtype == "TestBeamMC":
+elif runtype in ["TestBeamData", "TestBeamMC"]:
     ConfigFlags.GeoModel.FaserVersion = "FASER-TB01" 
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB01"
     print("Set global tag to OFLCOND-FASER-TB01")
@@ -141,15 +141,22 @@ elif runtype == "TI12Data02":
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03"
 
 # Final 2022 TI12 geometry
-elif runtype == "TI12Data03":
-    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" 
-    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04" # Updated 2023 alignment
+elif runtype in ["TI12Data03", "TI12MC03"]:
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03"
+    # Ugh, this is a horrible hack
+    # and I am not sure it is even needed as there may not be a difference
+    # in reco between the MC global tags...
+    if args.isMC:
+        ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03" # Consistent with sim/digi
+    else:
+        ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04" # Updated 2023 alignment
+        
     useCal = True
     if not args.isMC:
         useLHC = True
 
 # Updated 2023 TI12 geometry
-elif runtype == "TI12Data04":
+elif runtype in ["TI12Data04", "TI12MC04"]:
     ConfigFlags.GeoModel.FaserVersion = "FASERNU-04" 
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"
     useCal = True
diff --git a/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh b/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh
index 35d5f638e..04ab88587 100755
--- a/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh
+++ b/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh
@@ -2,7 +2,7 @@
 # Used with a condor file to submit to vanilla universe
 #
 # Usage:
-# submit_faser_reco.sh file_path [release_directory] [working_directory] [nevents]
+# submit_faser_reco.sh [options --] file_path [release_directory] [working_directory] [nevents] --other_options
 # 
 # Options:
 #   --out - specify output location (in EOS) to copy output HITS file
@@ -12,6 +12,8 @@
 # Monte Carlo options:
 #   --isMC - needed for MC reco
 #   --caloTag <tag> - override MC reco tag for calo gain (to match digi tag)
+#
+# Other --options will be passed to faser_reco.py
 # 
 # file_path - full file name (with path)
 # release_directory - optional path to release install directory (default pwd)
@@ -74,15 +76,45 @@ do
 done
 #
 # Parse command-line arguments
-file_path=${1}
-release_directory=${2}
-working_directory=${3}
-nevents=${4}
+while [ -n "$1" ]
+do
+    case "$1" in
+     --) # Stop parsing
+	 shift; # Eat this
+	 break;; # and stop parsing
+
+     -*) # Some option
+	 break;; # Stop parsing
+
+     *)  # Not an option, fill next value
+
+	 if [ -z "$file_path" ]
+	 then
+	     file_path=${1}
+	     shift
+	 elif [ -z "$release_directory" ]
+	 then
+	     release_directory=${1}
+	     shift
+	 elif [ -z "$working_directory" ]
+	 then
+	     working_directory=${1}
+	     shift
+	 elif [ -z "$nevents" ]
+	 then
+	     nevents=${1}
+	     shift
+	 else
+	     break # Already filled everything
+	 fi
+	 ;;
+    esac
+done
 #
 # Set defaults if arguments aren't provided
 if [ -z "$file_path" ]
 then
-  echo "No file_path specified!"
+  echo "No file_path specified!"  
   exit 1
 fi
 #
@@ -136,16 +168,16 @@ echo "Gain: $gainstr"
 echo "Release: $release_directory"
 echo "Output: $output_directory"
 echo "Starting: $starting_directory"
+echo "Remaining: $@"
 #
 # Set up the release (do this automatically)?
+# Must follow with -- to avoid command-line arguments being passed
 export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
-source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh 
+source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh --
 #
 # Always go back to the starting directory in case paths are relative
 cd "$starting_directory"
 cd "$release_directory"
-#asetup 
-#source build/x8*/setup.sh
 #
 # Do this by hand
 asetup --input=calypso/asetup.faser Athena,22.0.49
@@ -230,7 +262,12 @@ else
     mcstr="--isMC"
 fi
 #
-faser_reco.py "--nevents=$nevents" $geomstr $tagstr $mcstr $gainstr "$file_path" 
+echo
+echo "Submit job:"
+echo faser_reco.py "--nevents=$nevents" $geomstr $tagstr $mcstr $gainstr "$@" "$file_path"
+echo
+#
+faser_reco.py "--nevents=$nevents" $geomstr $tagstr $mcstr $gainstr "$@" "$file_path" 
 reco_code=$?
 echo "Return code: $reco_code"
 #
diff --git a/Control/CalypsoExample/Simulation/scripts/faser_simulate.py b/Control/CalypsoExample/Simulation/scripts/faser_simulate.py
index fcd8250c8..a19ff44a2 100755
--- a/Control/CalypsoExample/Simulation/scripts/faser_simulate.py
+++ b/Control/CalypsoExample/Simulation/scripts/faser_simulate.py
@@ -155,7 +155,7 @@ if __name__ == '__main__':
                      'Trigger', 'Dipole', 'Emulsion', 'Trench']
 
     elif args.geom == "TI12MC03":
-        # Old TI12 geometry
+        # 2022 TI12 geometry
         ConfigFlags.GeoModel.FaserVersion = "FASERNU-03"  # Geometry set-up
         ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03"  # Conditions set-up
         # TI12 detectors
diff --git a/Control/CalypsoExample/Simulation/scripts/submit_faser_simulate.sh b/Control/CalypsoExample/Simulation/scripts/submit_faser_simulate.sh
index f68993fb3..4c32a716d 100755
--- a/Control/CalypsoExample/Simulation/scripts/submit_faser_simulate.sh
+++ b/Control/CalypsoExample/Simulation/scripts/submit_faser_simulate.sh
@@ -2,9 +2,9 @@
 # Used with a condor file to submit to vanilla universe
 #
 # Usage:
-# submit_faser_simluate.sh [--shift] input_file output_file [release_directory] [working_directory] [skip] [nevts]
+# submit_faser_simluate.sh [--script_options --] input_file output_file [release_directory] [working_directory] [skip] [nevts] [--other_options]
 #
-# Options:
+# Script Options:
 # --shift - apply crossing angle (and FASER shift)
 #  --geom - specify geometry (default TI12)
 #   --out - specify output location (in EOS) to copy output HITS file
@@ -17,6 +17,8 @@
 # skip - events in input file to skip
 # nevts = events in input file to process
 #
+# Other options will be passed to faser_simulate.py
+#
 # The release directory must already be set up 
 # (so an unqualified asetup can set up the release properly)
 #
@@ -70,12 +72,48 @@ done
 
 #
 # Parse command-line arguments
-infile=${1}
-outfile=${2}
-release_directory=${3}
-working_directory=${4}
-skip_events=${5}
-nevts=${6}
+while [ -n "$1" ]
+do
+    case "$1" in
+	--) # Stop parsing
+	    shift; # Eat this
+	    break;; # and stop parsing
+
+	-*) # Some option
+	    break;; # Stop parsing
+
+	*)  # Not an option, fill next parameter value
+
+	    if [ -z "$infile" ]
+	    then
+		infile=${1}
+		shift
+	    elif [ -z "$outfile" ]
+	    then
+		outfile=${1}
+		shift
+	    elif [ -z "$release_directory" ]
+	    then
+		release_directory=${1}
+		shift
+	    elif [ -z "$working_directory" ]
+	    then
+		working_directory=${1}
+		shift
+	    elif [ -z "$skip_events" ]
+	    then
+		skip_events=${1}
+		shift
+	    elif [ -z "$nevts" ]
+	    then	    
+		nevts=${1}
+		shift
+	    else
+		break # Already filled everything
+	    fi
+	    ;;
+    esac
+done
 #
 # Set defaults if arguments aren't provided
 if [ -z "$infile" ]
@@ -155,22 +193,21 @@ echo "Starting: $starting_directory"
 echo "Skip: $skip_events"
 echo "Nevts: $nevts"
 echo "Geom: $geomstr"
+echo "Remaining: $@"
 #
 # Set up the release (do this automatically)?
+# Must follow with -- to avoid command-line arguments being passed
 export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
-source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh 
+source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh --
 #
 # Try automatic
 # Always go back to the starting directory in case paths are relative
 cd "$starting_directory"
 cd "$release_directory"
-# This doesn't seem to work, as we need the --input argument
-#asetup 
-#source build/x8*/setup.sh
 #
 # Do this by hand
 asetup --input=calypso/asetup.faser Athena,22.0.49
-source build/x86*/setup.sh
+source run/setup.sh
 #
 # Move to the run directory
 cd "$starting_directory"
@@ -195,16 +232,23 @@ cd "${file_stem}"
 #fi
 #
 if [[ -z "$xangle" ]]; then
-    faser_simulate.py $geomstr --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
-    sim_code=$?
+    angle_string=""
 elif [[ $xangle == 1 ]]; then
-    faser_simulate.py $geomstr  --yangle -0.000160 --yshift 12.0 --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
-    sim_code=$?
+    echo "Applying standard crossing angle"
+    angle_string="--yangle -0.000160 --yshift 12.0"
 else
     echo "Applying double crossing-angle shift for FLUKA!"
-    faser_simulate.py $geomstr  --yangle -0.000310 --yshift 12.0 --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
-    sim_code=$?
+    angle_string="--yangle -0.000310 --yshift 12.0"
 fi
+#
+echo
+echo "Submit job:"
+echo faser_simulate.py $geomstr $angle_string "$@" --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
+echo
+#
+faser_simulate.py $geomstr $angle_string "$@" --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
+sim_code=$?
+
 echo "Return code: $sim_code"
 #
 # Print out ending time
diff --git a/PhysicsAnalysis/NtupleDumper/scripts/faser_ntuple_maker.py b/PhysicsAnalysis/NtupleDumper/scripts/faser_ntuple_maker.py
index 4bbd8c042..ac3c57ce5 100755
--- a/PhysicsAnalysis/NtupleDumper/scripts/faser_ntuple_maker.py
+++ b/PhysicsAnalysis/NtupleDumper/scripts/faser_ntuple_maker.py
@@ -239,9 +239,34 @@ Configurable.configurableRun3Behavior = True
 
 # Configure
 ConfigFlags.Input.Files = filelist
-if len(args.cond) == 0:
-    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"         # Always needed; must match FaserVersionS
+
+if len(args.geom) > 0:
+    runtype = args.geom
 else:
+    if args.isMC:
+        runtype = TI12MC04
+    else:
+        runtype = TI12Data04
+
+if runtype in ["TI12Data04", "TI12MC04"]:
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-04" # FASER geometry
+    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"   
+
+elif runtype == "TI12Data03":
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" # FASER geometry
+    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04" # Pick up new alignment   
+
+elif runtype == "TI12MC03":
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" # FASER geometry
+    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03"
+    
+else:
+    print(f"Unknown: --geom {runtype}!")
+    print("Specify correct type or update list")
+    sys.exit(1)
+
+# Check if we override the global conditions tag
+if len(args.cond):
     print(f"Setting ConfigFlags.IOVDb.GlobalTag = {args.cond}")
     ConfigFlags.IOVDb.GlobalTag = args.cond
 
@@ -253,7 +278,6 @@ else:
 
 ConfigFlags.Input.ProjectName = "data21"                     # Needed to bypass autoconfig
 
-ConfigFlags.GeoModel.FaserVersion   = "FASERNU-03"           # FASER geometry
 ConfigFlags.Common.isOnline = False
 ConfigFlags.GeoModel.Align.Dynamic = False
 ConfigFlags.Beam.NumberOfCollisions = 0.
diff --git a/PhysicsAnalysis/NtupleDumper/scripts/submit_faser_ntuple_maker.sh b/PhysicsAnalysis/NtupleDumper/scripts/submit_faser_ntuple_maker.sh
index 70b2f7cb6..6857f8e40 100755
--- a/PhysicsAnalysis/NtupleDumper/scripts/submit_faser_ntuple_maker.sh
+++ b/PhysicsAnalysis/NtupleDumper/scripts/submit_faser_ntuple_maker.sh
@@ -3,7 +3,7 @@
 # Used with a condor file to submit a physics ntuple job
 #
 # Usage:
-# submit_ntuple_maker.sh dirpath slice nfiles [release_directory] [working_directory] 
+# submit_ntuple_maker.sh [options --] dirpath slice nfiles [release_directory] [working_directory] --other_options
 #
 # Options:
 #   --out - specify output location (in EOS) to copy output HITS file
@@ -265,11 +265,14 @@ else
     ls -R data
 fi
 #
-export EOS_MGM_URL=root://eospublic.cern.ch
-#
 # Run job
 #
-faser_ntuple_maker.py $last_file_str $partialstr $tagstr $ismc --slice $slice --files $nfiles $mergestr $dir_path "$@"
+echo
+echo "Submit job:"
+echo faser_ntuple_maker.py $last_file_str $partialstr $tagstr $ismc --slice $slice --files $nfiles $mergestr "$@" $dir_path 
+echo
+#
+faser_ntuple_maker.py $last_file_str $partialstr $tagstr $ismc --slice $slice --files $nfiles $mergestr "$@" $dir_path 
 ntup_code=$?
 echo "Return code: $ntup_code"
 #
@@ -278,6 +281,9 @@ date
 echo "Job finished after $SECONDS seconds"
 # 
 # Copy output to EOS if desired
+#
+export EOS_MGM_URL=root://eospublic.cern.ch
+#
 if ! [ -z "$outdest" ]
 then
     ls -l
-- 
GitLab