From b4f3d7e077a3168f3ea9e226ba0dccd898ca13e0 Mon Sep 17 00:00:00 2001
From: Sylvester Joosten <sjoosten@anl.gov>
Date: Tue, 5 Oct 2021 23:36:03 +0000
Subject: [PATCH] (cherry picked from commit 6cc1bfab )

---
 .gitlab-ci.yml                                |  3 +-
 athena.xml                                    |  1 +
 bin/set_beam_energy                           | 75 +++++++++++++++++++
 compact/subsystem_views/calorimeters.xml      |  1 +
 compact/subsystem_views/dirc_only.xml         |  1 +
 compact/subsystem_views/inner_detector.xml    |  1 +
 .../subsystem_views/inner_tracking_only.xml   |  1 +
 compact/subsystem_views/pid_only.xml          |  1 +
 compact/subsystem_views/tracking_only.xml     |  1 +
 compact/subsystem_views/vertex_only.xml       |  1 +
 10 files changed, 85 insertions(+), 1 deletion(-)
 create mode 100755 bin/set_beam_energy

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5b9ffb10..4044e00c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -131,7 +131,8 @@ dump_geometry:
     - sed -i '/forward_ion_beamline/d' ${DETECTOR_PATH}/athena.xml
     - sed -i '/beampipe_hadron_B0/d' ${DETECTOR_PATH}/athena.xml
     - sed -i '/B0_/d' ${DETECTOR_PATH}/athena.xml
-    - sed -i '/far_forward/d' ${DETECTOR_PATH}/athena.xml
+    - sed -i '/far_forward_offM/d' ${DETECTOR_PATH}/athena.xml
+    - sed -i '/far_forward_detectors/d' ${DETECTOR_PATH}/athena.xml
     - sed -i '/roman_pots/d' ${DETECTOR_PATH}/athena.xml
     - sed -i '/inner_vacuum_FF_magnets/d' ${DETECTOR_PATH}/athena.xml
     - dd_web_display --output geo/detector_geo.root ${DETECTOR_PATH}/athena.xml
diff --git a/athena.xml b/athena.xml
index 300992c2..8ef1ae0c 100644
--- a/athena.xml
+++ b/athena.xml
@@ -34,6 +34,7 @@
       These files have only a define tags.
   </documentation>
     <include ref="ip6/ip6_defs.xml" /> 
+    <include ref="ip6/far_forward_fields_275.xml" />
     <include ref="compact/definitions.xml" />
   </define>
 
diff --git a/bin/set_beam_energy b/bin/set_beam_energy
new file mode 100755
index 00000000..cd75bb3a
--- /dev/null
+++ b/bin/set_beam_energy
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+function print_the_help {
+  echo "USAGE:    --ebeam E --pbeam E -c compact.xml"
+  echo "REQUIRED ARGUMENTS:"
+  echo "          -h|--help     Print this message"
+  echo "          --ebeam       Electron beam energy (5, 10 or 18)"
+  echo "          --pbeam       Ion beam energy (41, 100 or 275)"
+  echo "          -c|--compact  Compact file to set beam energy for"
+  exit
+}
+
+EBEAM=
+PBEAM=
+COMPACT=
+
+while [ $# -gt 0 ]
+do
+  key="$1"
+  case $key in
+    -h|--help)
+      print_the_help
+      ;;
+    --ebeam)
+      EBEAM=$2
+      shift
+      shift
+      ;;
+    --pbeam)
+      PBEAM=$2
+      shift
+      shift
+      ;;
+    -c|--compact)
+      COMPACT=$2
+      shift
+      shift
+      ;;
+    *)    # unknown option
+      echo "unknown option"
+      exit 1
+      ;;
+  esac
+done
+
+echo "Setting beam energies to $EBEAM on $PBEAM for $COMPACT"
+
+if [ -z $COMPACT ]; then
+  echo "Error: no compact file given, use -h for help"
+  exit 1
+fi
+if [ -z $EBEAM ]; then
+  echo "Error: --ebeam argument missing, use -h for help"
+  exit 1
+fi
+if [ -z $PBEAM ]; then
+  echo "Error: --pbeam argument missing, use -h for help"
+  exit 1
+fi
+
+if [[ $PBEAM != "41" &&  $PBEAM != "100" && $PBEAM != "275" ]]; then
+  echo "Error: Ion beam energy should be 41, 100, or 275 GeV"
+  exit 1
+fi
+if [[ $EBEAM != 5 && $EBEAM != 10 && $EBEAM != 18 ]]; then
+  echo "Error: Electron beam energy should be 5, 10, or 18 GeV"
+  exit 1
+fi
+if [ ! -f ${COMPACT} ]; then
+  echo "Error: Compact file ${COMPACT} does not exist"
+  exit 1
+fi
+
+sed -i "s?far_forward_fields_.\{2,3\}.xml?far_forward_fields_${PBEAM}.xml?" athena.xml
+sed -i "s?far_backward_fields_.\{1,2\}.xml?far_backward_fields_${EBEAM}.xml?" athena.xml
diff --git a/compact/subsystem_views/calorimeters.xml b/compact/subsystem_views/calorimeters.xml
index 7e52ee1c..81386563 100644
--- a/compact/subsystem_views/calorimeters.xml
+++ b/compact/subsystem_views/calorimeters.xml
@@ -34,6 +34,7 @@
       These files have only a define tags.
   </documentation>
     <include ref="ip6/ip6_defs.xml" /> 
+    <include ref="ip6/far_forward_fields_275.xml" />
     <include ref="compact/definitions.xml" />
   </define>
 
diff --git a/compact/subsystem_views/dirc_only.xml b/compact/subsystem_views/dirc_only.xml
index cdcd1dd4..a60d413b 100644
--- a/compact/subsystem_views/dirc_only.xml
+++ b/compact/subsystem_views/dirc_only.xml
@@ -34,6 +34,7 @@
       These files have only a define tags.
   </documentation>
     <include ref="ip6/ip6_defs.xml" /> 
+    <include ref="ip6/far_forward_fields_275.xml" />
     <include ref="compact/definitions.xml" />
   </define>
 
diff --git a/compact/subsystem_views/inner_detector.xml b/compact/subsystem_views/inner_detector.xml
index df19d69a..9031454a 100644
--- a/compact/subsystem_views/inner_detector.xml
+++ b/compact/subsystem_views/inner_detector.xml
@@ -34,6 +34,7 @@
       These files have only a define tags.
   </documentation>
     <include ref="ip6/ip6_defs.xml" /> 
+    <include ref="ip6/far_forward_fields_275.xml" />
     <include ref="compact/definitions.xml" />
   </define>
 
diff --git a/compact/subsystem_views/inner_tracking_only.xml b/compact/subsystem_views/inner_tracking_only.xml
index c0b5ff5b..9b0bb13e 100644
--- a/compact/subsystem_views/inner_tracking_only.xml
+++ b/compact/subsystem_views/inner_tracking_only.xml
@@ -34,6 +34,7 @@
       These files have only a define tags.
   </documentation>
     <include ref="ip6/ip6_defs.xml" /> 
+    <include ref="ip6/far_forward_fields_275.xml" />
     <include ref="compact/definitions.xml" />
   </define>
 
diff --git a/compact/subsystem_views/pid_only.xml b/compact/subsystem_views/pid_only.xml
index 07d26593..c5103a4a 100644
--- a/compact/subsystem_views/pid_only.xml
+++ b/compact/subsystem_views/pid_only.xml
@@ -34,6 +34,7 @@
       These files have only a define tags.
   </documentation>
     <include ref="ip6/ip6_defs.xml" /> 
+    <include ref="ip6/far_forward_fields_275.xml" />
     <include ref="compact/definitions.xml" />
   </define>
 
diff --git a/compact/subsystem_views/tracking_only.xml b/compact/subsystem_views/tracking_only.xml
index 0f482504..1f23d873 100644
--- a/compact/subsystem_views/tracking_only.xml
+++ b/compact/subsystem_views/tracking_only.xml
@@ -34,6 +34,7 @@
       These files have only a define tags.
   </documentation>
     <include ref="ip6/ip6_defs.xml" /> 
+    <include ref="ip6/far_forward_fields_275.xml" />
     <include ref="compact/definitions.xml" />
   </define>
 
diff --git a/compact/subsystem_views/vertex_only.xml b/compact/subsystem_views/vertex_only.xml
index 1c2f4b69..20852f15 100644
--- a/compact/subsystem_views/vertex_only.xml
+++ b/compact/subsystem_views/vertex_only.xml
@@ -34,6 +34,7 @@
       These files have only a define tags.
   </documentation>
     <include ref="ip6/ip6_defs.xml" /> 
+    <include ref="ip6/far_forward_fields_275.xml" />
     <include ref="compact/definitions.xml" />
   </define>
 
-- 
GitLab