From 6dc28c27916d5c9ac2d87641b34997776c97c2b1 Mon Sep 17 00:00:00 2001
From: FaserMC <fasermc@cern.ch>
Date: Wed, 6 Dec 2023 22:31:14 +0100
Subject: [PATCH] Add calo response fluctuation amplitude, update scripts for
 new global tags

---
 .../CaloG4/EcalG4_SD/src/EcalSensorSDTool.cxx   |  2 +-
 .../Digitization/scripts/faser_digi.py          | 12 ++++++++----
 .../Digitization/scripts/faser_digi_merge.py    | 16 ++++++++++------
 .../Generation/scripts/faser_particlegun.py     | 14 +++++++++++---
 .../Reconstruction/scripts/faser_reco.py        | 17 +++++++++++++----
 .../Simulation/scripts/faser_simulate.py        | 14 +++++++++++---
 .../Simulation/scripts/submit_faser_simulate.sh | 16 ++++++++++++----
 7 files changed, 66 insertions(+), 25 deletions(-)

diff --git a/Calorimeter/CaloG4/EcalG4_SD/src/EcalSensorSDTool.cxx b/Calorimeter/CaloG4/EcalG4_SD/src/EcalSensorSDTool.cxx
index f2715e28a..d59abfdae 100644
--- a/Calorimeter/CaloG4/EcalG4_SD/src/EcalSensorSDTool.cxx
+++ b/Calorimeter/CaloG4/EcalG4_SD/src/EcalSensorSDTool.cxx
@@ -21,7 +21,7 @@ EcalSensorSDTool::EcalSensorSDTool(const std::string& type, const std::string& n
   , m_birk_c1 ( 0.013  * CLHEP::g/CLHEP::MeV/CLHEP::cm2 ) // 1st coef. of Birk's   
   , m_birk_c2 ( 9.6E-6 * CLHEP::g*CLHEP::g/CLHEP::MeV/CLHEP::MeV/CLHEP::cm2/CLHEP::cm2 ) // 2nd coef. of Birk's law 
   , m_birk_c1correction  ( 0.57142857)  //correction of c1 for 2e charged part.  
-  , m_a_local_outer_ecal ( 0. )
+  , m_a_local_outer_ecal ( 0.01 )
   , m_a_global_outer_ecal  ( 0.03  ) // global non uniformity amplitude
   , m_a_reflection_height ( 0.09 ) // reflection on the edges - height
   , m_a_reflection_width  ( 6. * CLHEP::mm ) // reflection on the edges - width
diff --git a/Control/CalypsoExample/Digitization/scripts/faser_digi.py b/Control/CalypsoExample/Digitization/scripts/faser_digi.py
index 0da1361ce..6b9d745d6 100755
--- a/Control/CalypsoExample/Digitization/scripts/faser_digi.py
+++ b/Control/CalypsoExample/Digitization/scripts/faser_digi.py
@@ -76,12 +76,16 @@ if runtype == "TI12OldMC":
 
 # Testbeam setup 
 elif runtype == "TestBeamMC" :
-    ConfigFlags.GeoModel.FaserVersion = "FASER-TB00" 
-    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB00"
+    ConfigFlags.GeoModel.FaserVersion = "FASER-TB01" # New geometry
+    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB01"
 
 # New TI12 geometry (ugh)
-elif runtype == "TI12MC":
-    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" 
+elif runtype == "TI12MC" or runtype == "TI12MC04":
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-04" # New geometry
+    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"
+
+elif runtype == "TI12MC03":
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" # New geometry
     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 b945ffbbd..0ada1e2a7 100755
--- a/Control/CalypsoExample/Digitization/scripts/faser_digi_merge.py
+++ b/Control/CalypsoExample/Digitization/scripts/faser_digi_merge.py
@@ -186,17 +186,21 @@ if runtype == "TI12OldMC":
 
 # Testbeam setup 
 elif runtype == "TestBeamMC" :
-    ConfigFlags.GeoModel.FaserVersion = "FASER-TB00" 
-    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB00"
+    ConfigFlags.GeoModel.FaserVersion = "FASER-TB01" # New geometry
+    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB01"
 
 # New TI12 geometry (ugh)
-elif runtype == "TI12MC":
-    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" 
+elif runtype == "TI12MC" or runtype == "TI12MC04":
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-04" # New geometry
+    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"
+
+elif runtype == "TI12MC03":
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" # New geometry
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03"
 
 else:
-    print("Invalid run type found:", runtype)
-    print("Specify correct type or update list")
+    print("Invalid geometry type found:", runtype)
+    print("Specify correct geometry or update list")
     sys.exit(-1)
 
 
diff --git a/Control/CalypsoExample/Generation/scripts/faser_particlegun.py b/Control/CalypsoExample/Generation/scripts/faser_particlegun.py
index 7ec05e2aa..e4a1ca645 100755
--- a/Control/CalypsoExample/Generation/scripts/faser_particlegun.py
+++ b/Control/CalypsoExample/Generation/scripts/faser_particlegun.py
@@ -72,7 +72,15 @@ if __name__ == '__main__':
     ConfigFlags.addFlag("Sim.Beam.xshift", 0)  # Potential beam shift
     ConfigFlags.addFlag("Sim.Beam.yshift", 0)        
 
-    if args.geom == "TI12MC":
+    if args.geom == "TI12MC" or args.geom == "TI12MC04":
+        # New TI12 geometry
+        ConfigFlags.GeoModel.FaserVersion = "FASERNU-04"  # Geometry set-up
+        ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"  # Conditions set-up
+        # TI12 detectors
+        detectors = ['Veto', 'VetoNu', 'Preshower', 'FaserSCT', 'Ecal', 'Trigger', 
+                     'Dipole', 'Emulsion', 'Trench']
+
+    elif args.geom == "TI12MC03":
         # 2022 TI12 geometry
         ConfigFlags.GeoModel.FaserVersion = "FASERNU-03"  # Geometry set-up
         ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03"  # Conditions set-up
@@ -82,8 +90,8 @@ if __name__ == '__main__':
 
     elif args.geom == "TestBeamMC":
         # Define 2021 test beam geometry
-        ConfigFlags.GeoModel.FaserVersion = "FASER-TB00"   # Geometry set-up
-        ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB00"   # Conditions set-up
+        ConfigFlags.GeoModel.FaserVersion = "FASER-TB01"   # Geometry set-up
+        ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB01"   # Conditions set-up
         # Testbeam detectors (trigger layers are actually veto counters)
         detectors = ['Veto', 'Preshower', 'FaserSCT', 'Ecal']
 
diff --git a/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py b/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py
index 744aafa0b..307e3fd79 100755
--- a/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py
+++ b/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py
@@ -59,7 +59,7 @@ elif args.testBeam:
 
 else:
     print(f"Assuming TI12 geometry")
-    runtype = "TI12Data03"
+    runtype = "TI12Data04"
 
     # Try to pick correct geometry from run number
     # This won't work for testbeam data, 
@@ -74,7 +74,7 @@ else:
     else:
         if runnumber > 6700: # Not sure if this is exact
             print(f"Found run number {runnumber}, using TI12 configuration with IFT+faserNu")
-            runtype = "TI12Data03"
+            runtype = "TI12Data04"
         elif runnumber > 5302: # Last TI12 run on Nov. 23, 2021 without IFT
             print(f"Found run number {runnumber}, using TI12 configuration with IFT")
             runtype = "TI12Data02"
@@ -126,8 +126,9 @@ if runtype == "TI12Data":
 
 # Testbeam setup 
 elif runtype == "TestBeamData" or runtype == "TestBeamMC":
-    ConfigFlags.GeoModel.FaserVersion = "FASER-TB00" 
-    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB00"
+    ConfigFlags.GeoModel.FaserVersion = "FASER-TB01" 
+    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB01"
+    print("Set global tag to OFLCOND-FASER-TB01")
     useCKF = False
     useCal = True
 
@@ -144,6 +145,14 @@ elif runtype == "TI12Data03":
     if not args.isMC:
         useLHC = True
 
+# Updated 2023 TI12 geometry
+elif runtype == "TI12Data04":
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-04" 
+    ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"
+    useCal = True
+    if not args.isMC:
+        useLHC = True
+
 else:
     print("Invalid run type found:", runtype)
     print("Specify correct type or update list")
diff --git a/Control/CalypsoExample/Simulation/scripts/faser_simulate.py b/Control/CalypsoExample/Simulation/scripts/faser_simulate.py
index 09c61de88..fcd8250c8 100755
--- a/Control/CalypsoExample/Simulation/scripts/faser_simulate.py
+++ b/Control/CalypsoExample/Simulation/scripts/faser_simulate.py
@@ -146,9 +146,17 @@ if __name__ == '__main__':
 #
 # Figure out configuration
 #
-    if args.geom == "TI12MC":
-        # 2022 TI12 geometry
+    if args.geom == "TI12MC" or args.geom == "TI12MC04":
+        # New TI12 geometry
         ConfigFlags.GeoModel.FaserVersion = "FASERNU-04"  # Geometry set-up
+        ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-04"  # Conditions set-up
+        # TI12 detectors
+        detectors = ['Veto', 'VetoNu', 'Preshower', 'FaserSCT', 'Ecal', 
+                     'Trigger', 'Dipole', 'Emulsion', 'Trench']
+
+    elif args.geom == "TI12MC03":
+        # Old TI12 geometry
+        ConfigFlags.GeoModel.FaserVersion = "FASERNU-03"  # Geometry set-up
         ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03"  # Conditions set-up
         # TI12 detectors
         detectors = ['Veto', 'VetoNu', 'Preshower', 'FaserSCT', 'Ecal', 
@@ -157,7 +165,7 @@ if __name__ == '__main__':
     elif args.geom == "TestBeamMC":
         # Define 2021 test beam geometry
         ConfigFlags.GeoModel.FaserVersion = "FASER-TB01"   # Geometry set-up
-        ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB00" # Conditions set-up
+        ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB01" # Conditions set-up
         # Testbeam detectors (trigger layers are actually veto counters)
         detectors = ['Veto', 'Preshower', 'FaserSCT', 'Ecal']
 
diff --git a/Control/CalypsoExample/Simulation/scripts/submit_faser_simulate.sh b/Control/CalypsoExample/Simulation/scripts/submit_faser_simulate.sh
index 6e4d4df2e..f68993fb3 100755
--- a/Control/CalypsoExample/Simulation/scripts/submit_faser_simulate.sh
+++ b/Control/CalypsoExample/Simulation/scripts/submit_faser_simulate.sh
@@ -2,10 +2,11 @@
 # Used with a condor file to submit to vanilla universe
 #
 # Usage:
-# submit_faserMDC_simluate.sh [--shift] input_file output_file [release_directory] [working_directory] [skip] [nevts]
+# submit_faser_simluate.sh [--shift] input_file output_file [release_directory] [working_directory] [skip] [nevts]
 #
 # Options:
 # --shift - apply crossing angle (and FASER shift)
+#  --geom - specify geometry (default TI12)
 #   --out - specify output location (in EOS) to copy output HITS file
 #   --log - specify output location (in EOS) for log file
 # 
@@ -40,6 +41,11 @@ do
 	  xangle=2
 	  shift;;
 
+      -g | --geom)
+	  geomstr="--geom $2";
+	  shift;
+	  shift;;
+
       -l | --log)
 	  logdest="$2";
 	  shift;
@@ -148,6 +154,7 @@ echo "Output: $output_directory"
 echo "Starting: $starting_directory"
 echo "Skip: $skip_events"
 echo "Nevts: $nevts"
+echo "Geom: $geomstr"
 #
 # Set up the release (do this automatically)?
 export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
@@ -186,15 +193,16 @@ cd "${file_stem}"
 # Run job
 #if [[ -z "$tag" ]]; then
 #fi
+#
 if [[ -z "$xangle" ]]; then
-    faser_simulate.py  --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
+    faser_simulate.py $geomstr --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
     sim_code=$?
 elif [[ $xangle == 1 ]]; then
-    faser_simulate.py  --yangle -0.000160 --yshift 12.0 --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
+    faser_simulate.py $geomstr  --yangle -0.000160 --yshift 12.0 --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
     sim_code=$?
 else
     echo "Applying double crossing-angle shift for FLUKA!"
-    faser_simulate.py  --yangle -0.000310 --yshift 12.0 --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
+    faser_simulate.py $geomstr  --yangle -0.000310 --yshift 12.0 --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
     sim_code=$?
 fi
 echo "Return code: $sim_code"
-- 
GitLab