From 771f81f057bc241ed941fd168fc35c19fa3dc45d Mon Sep 17 00:00:00 2001
From: Carl Gwilliam <gwilliam@hep.ph.liv.ac.uk>
Date: Fri, 8 Apr 2022 13:42:57 +0100
Subject: [PATCH] Update foresee generation to allow testing with new version. 
 Old version default for now

---
 .../share/generate_forsee_events.py                 | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/Generators/ForeseeGenerator/share/generate_forsee_events.py b/Generators/ForeseeGenerator/share/generate_forsee_events.py
index b8448f2ef..bd44eb2fa 100644
--- a/Generators/ForeseeGenerator/share/generate_forsee_events.py
+++ b/Generators/ForeseeGenerator/share/generate_forsee_events.py
@@ -4,8 +4,6 @@ import numpy as np
 import matplotlib.pyplot as plt
 import matplotlib
 
-from foresee import Foresee, Model, Utility
-
 class ForeseeGenerator(object):
     """
     Generate LLP particles within FASER acceptance from FORESEE
@@ -328,6 +326,11 @@ def setup_foresee(path):
         
     return
 
+def add_to_python_path(path):
+    if path in sys.path: return
+    path = os.path.expandvars(os.path.expanduser(path))
+    os.sys.path.append(path)
+    return
 
 def parse_couplings(data, write_hepMC = False):    
 
@@ -364,6 +367,10 @@ if __name__ == "__main__":
     parser.add_argument("--nevents", "-n", default = 10, type = int, help = "Number of HepMC events ")    
     args = parser.parse_args()
 
+    add_to_python_path(f"{args.path}/src")
+
+    from foresee import Foresee, Model, Utility
+
     # Create PIDs
     if args.pid2 is None:
         args.pid2 = -args.pid1
@@ -373,7 +380,7 @@ if __name__ == "__main__":
     print(f"Generating {args.model} events at Ecom = {args.Ecom}") 
     print(f"   mother mass = {args.mass} GeV")
     print(f"   decay = {args.pid1} {args.pid2}")
-    print(f"   couplings = {couplings}")
+    print(f"   couplings = {couplings}")    
 
     f = ForeseeGenerator(args.model, args.Ecom, args.mass, couplings, args.pid1, args.pid2, outdir = args.outdir, path = args.path)
 
-- 
GitLab