From 9e20d80879e8a389e786d4faebc82285001ce937 Mon Sep 17 00:00:00 2001
From: Stefan Reck <stefan.reck@fau.de>
Date: Fri, 5 Apr 2019 13:41:32 +0200
Subject: [PATCH] More docs.

---
 orcasong_plag/mc_info_types.py              | 14 ++++--
 orcasong_plag/modules.py                    | 25 +++++++++++
 orcasong_plag/util/binning_1d_visualizer.py | 47 +--------------------
 3 files changed, 38 insertions(+), 48 deletions(-)

diff --git a/orcasong_plag/mc_info_types.py b/orcasong_plag/mc_info_types.py
index 2bcb230..7385f85 100644
--- a/orcasong_plag/mc_info_types.py
+++ b/orcasong_plag/mc_info_types.py
@@ -6,16 +6,22 @@ in the h5 files.
 import numpy as np
 
 
-def get_mc_info_extr(mc_info_type):
+def get_mc_info_extr(mc_info_extr):
     """
     Get an existing mc info extractor function.
 
+    Attributes
+    ----------
+    mc_info_extr : function
+        Function to extract the info. Takes the blob as input, outputs
+        a dict with the desired mc_infos.
+
     """
-    if mc_info_type == "mupage":
+    if mc_info_extr == "mupage":
         mc_info_extr = get_mupage_mc
 
     else:
-        raise ValueError("Unknown mc_info_type " + mc_info_type)
+        raise ValueError("Unknown mc_info_type " + mc_info_extr)
 
     return mc_info_extr
 
@@ -24,6 +30,8 @@ def get_mupage_mc(blob):
     """
     For mupage muon simulations.
 
+    e.g. mcv5.1_r3.mupage_10G.km3_AAv1.jterbr00002800.5103.root.h5
+
     Parameters
     ----------
     blob : dict
diff --git a/orcasong_plag/modules.py b/orcasong_plag/modules.py
index e9b9292..bf089f0 100644
--- a/orcasong_plag/modules.py
+++ b/orcasong_plag/modules.py
@@ -9,6 +9,15 @@ import numpy as np
 class McInfoMaker(kp.Module):
     """
     Get the desired mc_info from the blob.
+
+    Attributes
+    ----------
+    mc_info_extr : function
+        Function to extract the info. Takes the blob as input, outputs
+        a dict with the desired mc_infos.
+    store_as : str
+        Store the mcinfo with this name in the blob.
+
     """
     def configure(self):
         self.mc_info_extr = self.require('mc_info_extr')
@@ -34,6 +43,13 @@ class TimePreproc(kp.Module):
     Time hits and mchits will be shifted by the time of the first
     triggered hit.
 
+    Attributes
+    ----------
+    correct_hits : bool
+        If true, will correct time of the hits.
+    correct_mchits : bool
+        If true, will correct the time of the McHits.
+
     """
     def configure(self):
         self.correct_hits = self.get('correct_hits', default=True)
@@ -76,6 +92,15 @@ def time_preproc(blob, correct_hits=True, correct_mchits=True):
 class ImageMaker(kp.Module):
     """
     Make a n-d histogram from the blob.
+
+    Attributes
+    ----------
+    bin_edges_list : List
+        List with the names of the fields to bin, and the respective bin edges,
+        including the left- and right-most bin edge.
+    store_as : str
+        Store the images with this name in the blob.
+
     """
     def configure(self):
         self.bin_edges_list = self.require('bin_edges_list')
diff --git a/orcasong_plag/util/binning_1d_visualizer.py b/orcasong_plag/util/binning_1d_visualizer.py
index a1ff4b0..ae97a6b 100644
--- a/orcasong_plag/util/binning_1d_visualizer.py
+++ b/orcasong_plag/util/binning_1d_visualizer.py
@@ -14,6 +14,8 @@ import numpy as np
 import km3pipe as kp
 import matplotlib.pyplot as plt
 
+from orcasong_plag.modules import time_preproc
+
 
 class FieldPlotter:
     """
@@ -337,51 +339,6 @@ class FieldPlotter:
         return "<FieldPlotter: {}>".format(self.files)
 
 
-class TimePreproc(kp.Module):
-    """
-    Preprocess the time in the blob.
-
-    t0 will be added to the time for real data, but not simulations.
-    Time hits and mchits will be shifted by the time of the first triggered hit.
-
-    """
-    def configure(self):
-        self.correct_hits = self.get('correct_hits', default=True)
-        self.correct_mchits = self.get('correct_mchits', default=True)
-
-    def process(self, blob):
-        blob = time_preproc(blob, self.correct_hits, self.correct_mchits)
-        return blob
-
-
-def time_preproc(blob, correct_hits=True, correct_mchits=True):
-    """
-    Preprocess the time in the blob.
-
-    t0 will be added to the time for real data, but not simulations.
-    Time hits and mchits will be shifted by the time of the first triggered hit.
-
-    """
-    hits_time = blob["Hits"].time
-
-    if "McHits" not in blob:
-        # add t0 only for real data, not sims
-        hits_t0 = blob["Hits"].t0
-        hits_time = np.add(hits_time, hits_t0)
-
-    hits_triggered = blob["Hits"].triggered
-    t_first_trigger = np.min(hits_time[hits_triggered == 1])
-
-    if correct_hits:
-        blob["Hits"].time = np.subtract(hits_time, t_first_trigger)
-
-    if correct_mchits:
-        mchits_time = blob["McHits"].time
-        blob["McHits"].time = np.subtract(mchits_time, t_first_trigger)
-
-    return blob
-
-
 class TimePlotter(FieldPlotter):
     """
     For plotting the time.
-- 
GitLab