From 1e50637051012ddff24e583bd1dc3cb118a2b0df Mon Sep 17 00:00:00 2001
From: Wudr-1995 <wudr@ihep.ac.cn>
Date: Thu, 17 Aug 2023 15:09:10 +0800
Subject: [PATCH] Add README

---
 Analysis/NoiseAnaTool/src/NoiseAnaTool.cc |   1 +
 README.md                                 | 125 ++++++++++++++++++++++
 2 files changed, 126 insertions(+)
 create mode 100644 README.md

diff --git a/Analysis/NoiseAnaTool/src/NoiseAnaTool.cc b/Analysis/NoiseAnaTool/src/NoiseAnaTool.cc
index 1c653c0..89afc57 100644
--- a/Analysis/NoiseAnaTool/src/NoiseAnaTool.cc
+++ b/Analysis/NoiseAnaTool/src/NoiseAnaTool.cc
@@ -1,4 +1,5 @@
 #include "NoiseAnaTool.h"
+
 DECLARE_TOOL(NoiseAnaTool);
 NoiseAnaTool::NoiseAnaTool(const string &name)
 	: ToolBase(name)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..437fe1a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,125 @@
+# For SPMT commissioning (based on SNiPER)
+The software was intentionally designed to separate the data input and analysis tools.
+
+Similar to JUNO Offline, two main structures exist: one is named `**algorithm**`, and the other is named `**tool**`. Each of these structures has its own set of rules for definition.
+1. `**algorithm**` can accept the input **arguments** and input **data** (only `ROOT` data can be accepted now). The **data** is input as a list written in a text file, **arguments** can be delivered to the `algorithm` by setting in the python script. Besides, the `**algorithm**` can call analysis `tool` to process the data.
+2. `**tool**` contains the true analysis algorithm
+
+## Create your own algorithm
+
+Create an algorithm named `ExampleAlg` in `./Analysis`
+```bash=
+cd Analysis
+mkdir ExampleAlg
+cd ExampleAlg
+mkdir src
+mkdir python
+mkdir python/ExampleAlg
+touch CMakeLists.txt
+```
+
+In `python/ExampleAlg/__init__.py`
+
+```python=
+import Sniper as sn
+sn.loadDll("libExampleAlg.so")
+```
+
+In `CMakeLists.txt`
+```cmake=
+PKG(ExampleAlg
+	DEPENDS
+	AnaTool
+)
+```
+
+An `**algorithm**` is defined as a `c++ class` like
+
+```c++=
+// Similar to JUNO Offline, this line will register the algorithm
+DECLARE_ALGORITHM(ExampleAlg);
+// The *Alg class must inherit from AlgBase
+class ExampleAlg : public AlgBase {
+	public:
+		// necessary
+		ExampleAlg(const string&);
+		virtual ~ExampleAlg();
+
+		// initialize, execute, finalize will be called automatically
+		bool initialize();
+		bool execute();
+		bool finalize();
+
+		// ...
+
+	private:
+		Params m_paras;
+		vector<Anatool*> m_tools;
+		//SPMTMap *m_spmtMap;
+
+		// ...
+};
+
+// The constructor of AlgBase must be called
+ExampleAlg::ExampleAlg(const string &name) : AlgBase(name) {
+	// ...
+}
+```
+
+More detail can be found in `./Analysis/CommissioningAlg/`.
+
+## Create your own analsis tool
+
+Similar to `ExampleAlg`, the folders, CMakeLists.txt and __init__.py should be created
+
+A `**tool**` is defined as a `c++ class` too.
+
+```c++=
+DECLARE_TOOL(ExampleTool);
+
+class ExampleTool : public AnaTool, public ToolBase {
+	public:
+		ExampleTool(const string&);
+		virtual ~ExampleTool();
+
+		bool configure(string, const SPMTMap*);
+		bool analyze(const Params&);
+		bool output();
+
+	private:
+		// ...
+};
+
+ExampleTool::ExampleTool(const string &name) : ToolBase(name) {}
+
+bool ExampleTool::configure(string outputDir, const SPMTMap *map) {
+	// initialization
+	return true;
+}
+
+bool ExampleTool::analyze(const Params& paras) {
+	// output gcu ID
+	LogInfo << paras.get("GCU_ID") << endl;
+	return true;
+}
+
+bool ExampleTool::output() {
+	m_canvas->cd();
+	m_hist->Draw();
+	m_canvas->SaveAs("dir.pdf");
+}
+```
+More detail can be found in `./Analysis/NoiseAnaTool/`
+
+## How to compile
+```bash=
+source setup.sh
+./build.sh
+```
+
+## How to add your own algorithm or tool
+If the algorithm named `ExampleAlg` was created in `./Analysis`, the folder's name should be add in the `./Analysis/CMakeLists.txt` as
+```cmake=
+add_subdirectory(ExampleAlg)
+```
+
-- 
GitLab