From 4fcb8c8990696f68ffeb84260b5656eaf46c82a6 Mon Sep 17 00:00:00 2001
From: Albert Puig <albert.puig@cern.ch>
Date: Tue, 12 Jun 2018 08:43:15 +0200
Subject: [PATCH 1/4] Dynamic loading of keyword actions.

---
 analysis/utils/__init__.py | 8 +++++---
 analysis/utils/actions.py  | 8 --------
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/analysis/utils/__init__.py b/analysis/utils/__init__.py
index 1413204..22bd48f 100644
--- a/analysis/utils/__init__.py
+++ b/analysis/utils/__init__.py
@@ -12,7 +12,7 @@ import inspect
 
 from analysis import get_global_var
 from analysis.utils.logging_color import get_logger
-from analysis.utils.actions import ACTION_KEYWORDS
+import analysis.utils.actions as _actions
 
 logger = get_logger('analysis.utils')
 
@@ -48,8 +48,10 @@ def register_config_action(name, action_function):
     return len(get_global_var('PARAMETER_KEYWORDS'))
 
 
-for keyword, action_func in ACTION_KEYWORDS.items():
-    register_config_action(keyword, action_func)
+for func_name, action_func in inspect.getmembers(_actions, inspect.isfunction):
+    if func_name.startswith('action_'):
+        keyword = func_name.lstrip('action_')
+        register_config_action(keyword, action_func)
 
 
 # Get the fit strategy
diff --git a/analysis/utils/actions.py b/analysis/utils/actions.py
index 157f93d..5219a16 100644
--- a/analysis/utils/actions.py
+++ b/analysis/utils/actions.py
@@ -257,12 +257,4 @@ def action_BLIND(name, title, action_params, external_vars):
     return parameter, constraint
 
 
-ACTION_KEYWORDS = {'VAR': action_VAR,
-                   'CONST': action_CONST,
-                   'GAUSS': action_GAUSS,
-                   'SHIFT': action_SHIFT,
-                   'SCALE': action_SCALE,
-                   'RATIO': action_RATIO,
-                   'BLIND': action_BLIND}
-
 # EOF
-- 
GitLab


From a41745001a3004d9a68295257fb76d364be45699 Mon Sep 17 00:00:00 2001
From: Albert Puig <albert.puig@cern.ch>
Date: Tue, 12 Jun 2018 08:59:46 +0200
Subject: [PATCH 2/4] Add offset blinding.

---
 analysis/utils/actions.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/analysis/utils/actions.py b/analysis/utils/actions.py
index 5219a16..54551c7 100644
--- a/analysis/utils/actions.py
+++ b/analysis/utils/actions.py
@@ -257,4 +257,29 @@ def action_BLIND(name, title, action_params, external_vars):
     return parameter, constraint
 
 
+def action_BLINDOFFSET(name, title, action_params, external_vars):
+    """Configure the blinding of a parameter using RooUnblindOffset.
+
+    The first parameter must be a shared variable whereas the following are a string and one float.
+    They represent a randomization string, and the scale used for the randomization of the blind
+    value.
+
+    """
+    try:
+        ref_var, blind_str, blind_scale = action_params
+    except ValueError:
+        raise ValueError("Wrong number of arguments for BLINDOFFSET -> {}".format(action_params))
+    try:
+        if ref_var.startswith('@'):
+            ref_var = ref_var[1:]
+        else:
+            raise ValueError("The first value for a BLINDOFFSET must be a reference.")
+        ref_var, constraint = external_vars[ref_var]
+    except KeyError as error:
+        raise ValueError("Missing parameter definition -> {}".format(error))
+    parameter = ROOT.RooUnblindOffset(name + "_blindoffset", title + "_blindoffset",
+                                      blind_str, float(blind_scale), ref_var)
+    return parameter, constraint
+
+
 # EOF
-- 
GitLab


From 01411494086aa96c5e05ff4b119e89f5e970d902 Mon Sep 17 00:00:00 2001
From: Albert Puig <albert.puig@cern.ch>
Date: Tue, 12 Jun 2018 12:17:55 +0200
Subject: [PATCH 3/4] Fix import error

---
 analysis/utils/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/analysis/utils/__init__.py b/analysis/utils/__init__.py
index 22bd48f..5b7b5d8 100644
--- a/analysis/utils/__init__.py
+++ b/analysis/utils/__init__.py
@@ -12,7 +12,7 @@ import inspect
 
 from analysis import get_global_var
 from analysis.utils.logging_color import get_logger
-import analysis.utils.actions as _actions
+from analysis.utils import actions as _actions
 
 logger = get_logger('analysis.utils')
 
-- 
GitLab


From 8c8984a1e20292c603cd61a188f7d72611ad3b3d Mon Sep 17 00:00:00 2001
From: Jonas Eschle 'Mayou36 <jonas.eschle@cern.ch>
Date: Tue, 12 Jun 2018 12:52:11 +0200
Subject: [PATCH 4/4] Small fix

---
 analysis/utils/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/analysis/utils/__init__.py b/analysis/utils/__init__.py
index 5b7b5d8..c87c532 100644
--- a/analysis/utils/__init__.py
+++ b/analysis/utils/__init__.py
@@ -50,7 +50,7 @@ def register_config_action(name, action_function):
 
 for func_name, action_func in inspect.getmembers(_actions, inspect.isfunction):
     if func_name.startswith('action_'):
-        keyword = func_name.lstrip('action_')
+        keyword = func_name[len('action_'):]  # stripping of 'action_'
         register_config_action(keyword, action_func)
 
 
-- 
GitLab