Repository: peterridolfi/Pyhf-to-Combine-converter (language: python)

Issue:
Add test scripts for conversion
As a compliment to Issue #13, it would be great if there could be a test script under `tests`/ that adds a round-trip conversion, and to could be a runnable conversion test in general (which would be useful for things like Issue #7). Just ask if any part on this in particualr isn't clear! :+1: 


Discussion / hints:

Fix patch:
diff --git a/docs/tutorial.bash b/docs/tutorial.bash
new file mode 100644
index 0000000..feecdec
--- /dev/null
+++ b/docs/tutorial.bash
@@ -0,0 +1,4 @@
+#convert datacard to pyhf
+combine-to-pyhf converted_datacard.txt --out-file pyhf_workspace.json
+#convert pyhf back to datacard
+pyhf-to-combine pyhf_workspace.json --out-datacard combine_datacard.txt --shape-file shapes.root
diff --git a/docs/tutorial.md b/docs/tutorial.md
new file mode 100644
index 0000000..7b12e04
--- /dev/null
+++ b/docs/tutorial.md
@@ -0,0 +1,48 @@
+Once you are in an environment with both cvmfs commands and pyhf supported, as well as the package installed, you are ready to run the translation
+
+### pyhf to Combine
+
+To go from a pyhf workspace to a datacard, you only need the workspace JSON file
+
+The translation can be run either via the CLI or with a python script. First, to run it in the CLI:
+
+```
+pyhf-to-combine $JSON_FILE_NAME
+```
+
+If you want to designate the names of the datacard and/or shapes files that are generated by the conversion, add the following flags respectively
+
+```
+--out-datacard $DATACARD_FILE_NAME
+--shape-file $SHAPES_FILE_NAME
+```
+
+To run the translation in a python script, run the following code:
+
+```
+from pyhf_combine_converter import pyhf_convert_to_datacard
+pyhf_convert_to_datacard(workspace = $JSON_FILE, outdatacard = $DATACARD_FILE_NAME, shapefile = $SHAPES_FILE_NAME)
+```
+
+### Combine to pyhf
+
+To run the translation in the other direction, the method is very similar. However, if the model has shapes, meaning there are samples with multiple bins and a shapes file is designated in the datacard, this shapes file must be present in the directory from which you are running the command. Otherwise there will be an error that the shapes file was not found.
+
+In the CLI:
+
+```
+combine-to-pyhf $DATACARD_FILE_NAME
+```
+
+To add the desired JSON file name, add the following flag:
+
+```
+--out-file $JSON_FILE_NAME
+```
+
+To run this conversion in a python script, run the following:
+
+```
+from pyhf_combine_converter import pyhf_converted_from_datacard
+pyhf_converted_from_datacard(input_datacard = $DATACARD_FILE, outfile = $JSON_FILE_NAME)
+```
\ No newline at end of file
diff --git a/docs/tutorial.py b/docs/tutorial.py
new file mode 100644
index 0000000..c347c7d
--- /dev/null
+++ b/docs/tutorial.py
@@ -0,0 +1,8 @@
+from pyhf_combine_converter import pyhf_converted_from_datacard
+from pyhf_combine_converter import pyhf_convert_to_datacard
+
+##convert to pyhf
+pyhf_converted_from_datacard(input_datacard = "converted_datacard.txt", outfile = "pyhf_workspace.json")
+##convert back to datacard
+pyhf_convert_to_datacard(workspace = "pyhf_workspace.json", outdatacard = "combine_datacard.txt", shapefile = "shapes.root")
+


Test patch:
diff --git a/test/verification_model/converted_datacard.txt b/test/converted_datacard.txt
similarity index 100%
rename from test/verification_model/converted_datacard.txt
rename to test/converted_datacard.txt
diff --git a/test/verification_model/shapes.root b/test/shapes.root
similarity index 100%
rename from test/verification_model/shapes.root
rename to test/shapes.root