From b59d2f3f8b60b5f54bbc99c7b1ec8266b4e92efd Mon Sep 17 00:00:00 2001
From: Simon Spannagel <simon.spannagel@cern.ch>
Date: Wed, 7 Nov 2018 10:51:10 +0100
Subject: [PATCH] Rename CLICpix2Analysis -> AnalysisDUT, make DUT_MODULE

---
 .../AnalysisDUT.cpp}                          | 121 ++++++++++--------
 .../AnalysisDUT.h}                            |  14 +-
 .../CMakeLists.txt                            |   4 +-
 .../README.md                                 |   0
 4 files changed, 77 insertions(+), 62 deletions(-)
 rename src/modules/{CLICpix2Analysis/CLICpix2Analysis.cpp => AnalysisDUT/AnalysisDUT.cpp} (77%)
 rename src/modules/{CLICpix2Analysis/CLICpix2Analysis.h => AnalysisDUT/AnalysisDUT.h} (84%)
 rename src/modules/{CLICpix2Analysis => AnalysisDUT}/CMakeLists.txt (76%)
 rename src/modules/{CLICpix2Analysis => AnalysisDUT}/README.md (100%)

diff --git a/src/modules/CLICpix2Analysis/CLICpix2Analysis.cpp b/src/modules/AnalysisDUT/AnalysisDUT.cpp
similarity index 77%
rename from src/modules/CLICpix2Analysis/CLICpix2Analysis.cpp
rename to src/modules/AnalysisDUT/AnalysisDUT.cpp
index 4865a865d..5fc12cb66 100644
--- a/src/modules/CLICpix2Analysis/CLICpix2Analysis.cpp
+++ b/src/modules/AnalysisDUT/AnalysisDUT.cpp
@@ -1,4 +1,4 @@
-#include "CLICpix2Analysis.h"
+#include "AnalysisDUT.h"
 
 #include "objects/Cluster.h"
 #include "objects/Pixel.h"
@@ -6,58 +6,72 @@
 
 using namespace corryvreckan;
 
-CLICpix2Analysis::CLICpix2Analysis(Configuration config, std::vector<std::shared_ptr<Detector>> detectors)
-    : Module(std::move(config), std::move(detectors)) {
+AnalysisDUT::AnalysisDUT(Configuration config, std::shared_ptr<Detector> detector)
+    : Module(std::move(config), detector), m_detector(detector) {
 
     m_timeCutFrameEdge = m_config.get<double>("timeCutFrameEdge", static_cast<double>(Units::convert(20, "ns")));
-
     spatialCut = m_config.get<double>("spatialCut", static_cast<double>(Units::convert(50, "um")));
     chi2ndofCut = m_config.get<double>("chi2ndofCut", 3.);
 }
 
-void CLICpix2Analysis::initialise() {
-
-    // Get DUT detector:
-    auto det = get_dut();
+void AnalysisDUT::initialise() {
 
-    hClusterMapAssoc = new TH2F(
-        "clusterMapAssoc", "clusterMapAssoc", det->nPixelsX(), 0, det->nPixelsX(), det->nPixelsY(), 0, det->nPixelsY());
+    hClusterMapAssoc = new TH2F("clusterMapAssoc",
+                                "clusterMapAssoc",
+                                m_detector->nPixelsX(),
+                                0,
+                                m_detector->nPixelsX(),
+                                m_detector->nPixelsY(),
+                                0,
+                                m_detector->nPixelsY());
     hClusterSizeMapAssoc = new TProfile2D("clusterSizeMapAssoc",
                                           "clusterSizeMapAssoc",
-                                          det->nPixelsX(),
+                                          m_detector->nPixelsX(),
                                           0,
-                                          det->nPixelsX(),
-                                          det->nPixelsY(),
+                                          m_detector->nPixelsX(),
+                                          m_detector->nPixelsY(),
                                           0,
-                                          det->nPixelsY(),
+                                          m_detector->nPixelsY(),
                                           0,
                                           100);
 
     hClusterToTMapAssoc = new TProfile2D("clusterSizeToTAssoc",
                                          "clusterToTMapAssoc",
-                                         det->nPixelsX(),
+                                         m_detector->nPixelsX(),
                                          0,
-                                         det->nPixelsX(),
-                                         det->nPixelsY(),
+                                         m_detector->nPixelsX(),
+                                         m_detector->nPixelsY(),
                                          0,
-                                         det->nPixelsY(),
+                                         m_detector->nPixelsY(),
                                          0,
                                          1000);
 
     // Per-pixel histograms
-    hHitMapAssoc =
-        new TH2F("hitMapAssoc", "hitMapAssoc", det->nPixelsX(), 0, det->nPixelsX(), det->nPixelsY(), 0, det->nPixelsY());
-    hHitMapROI =
-        new TH2F("hitMapROI", "hitMapROI", det->nPixelsX(), 0, det->nPixelsX(), det->nPixelsY(), 0, det->nPixelsY());
+    hHitMapAssoc = new TH2F("hitMapAssoc",
+                            "hitMapAssoc",
+                            m_detector->nPixelsX(),
+                            0,
+                            m_detector->nPixelsX(),
+                            m_detector->nPixelsY(),
+                            0,
+                            m_detector->nPixelsY());
+    hHitMapROI = new TH2F("hitMapROI",
+                          "hitMapROI",
+                          m_detector->nPixelsX(),
+                          0,
+                          m_detector->nPixelsX(),
+                          m_detector->nPixelsY(),
+                          0,
+                          m_detector->nPixelsY());
     hPixelToTAssoc = new TH1F("pixelToTAssoc", "pixelToTAssoc", 32, 0, 31);
     hPixelToTMapAssoc = new TProfile2D("pixelToTMapAssoc",
                                        "pixelToTMapAssoc",
-                                       det->nPixelsX(),
+                                       m_detector->nPixelsX(),
                                        0,
-                                       det->nPixelsX(),
-                                       det->nPixelsY(),
+                                       m_detector->nPixelsX(),
+                                       m_detector->nPixelsY(),
                                        0,
-                                       det->nPixelsY(),
+                                       m_detector->nPixelsY(),
                                        0,
                                        255);
 
@@ -75,8 +89,8 @@ void CLICpix2Analysis::initialise() {
     clusterSizeAssoc = new TH1F("clusterSizeAssociated", "clusterSizeAssociated", 30, 0, 30);
 
     // In-pixel studies:
-    auto pitch_x = static_cast<double>(Units::convert(det->pitch().X(), "um"));
-    auto pitch_y = static_cast<double>(Units::convert(det->pitch().Y(), "um"));
+    auto pitch_x = static_cast<double>(Units::convert(m_detector->pitch().X(), "um"));
+    auto pitch_y = static_cast<double>(Units::convert(m_detector->pitch().Y(), "um"));
     auto mod_axes = "x_{track} mod " + std::to_string(pitch_x) + "#mum;y_{track} mod " + std::to_string(pitch_y) + "#mum;";
 
     std::string title = "DUT x resolution;" + mod_axes + "MAD(#Deltax) [#mum]";
@@ -136,22 +150,22 @@ void CLICpix2Analysis::initialise() {
                                          1);
     hChipEfficiencyMap = new TProfile2D("hChipEfficiencyMap",
                                         "hChipEfficiencyMap",
-                                        det->nPixelsX(),
+                                        m_detector->nPixelsX(),
                                         0,
-                                        det->nPixelsX(),
-                                        det->nPixelsY(),
+                                        m_detector->nPixelsX(),
+                                        m_detector->nPixelsY(),
                                         0,
-                                        det->nPixelsY(),
+                                        m_detector->nPixelsY(),
                                         0,
                                         1);
     hGlobalEfficiencyMap = new TProfile2D("hGlobalEfficiencyMap",
                                           "hGlobalEfficiencyMap",
                                           300,
-                                          -1.5 * det->size().X(),
-                                          1.5 * det->size().X(),
+                                          -1.5 * m_detector->size().X(),
+                                          1.5 * m_detector->size().X(),
                                           300,
-                                          -1.5 * det->size().Y(),
-                                          1.5 * det->size().Y(),
+                                          -1.5 * m_detector->size().Y(),
+                                          1.5 * m_detector->size().Y(),
                                           0,
                                           1);
 
@@ -170,7 +184,7 @@ void CLICpix2Analysis::initialise() {
         new TH2F("hUnassociatedTracksGlobalPosition", "hUnassociatedTracksGlobalPosition", 200, -10, 10, 200, -10, 10);
 }
 
-StatusCode CLICpix2Analysis::run(Clipboard* clipboard) {
+StatusCode AnalysisDUT::run(Clipboard* clipboard) {
 
     // Get the telescope tracks from the clipboard
     Tracks* tracks = reinterpret_cast<Tracks*>(clipboard->get("tracks"));
@@ -179,9 +193,6 @@ StatusCode CLICpix2Analysis::run(Clipboard* clipboard) {
         return Success;
     }
 
-    // Get the DUT detector:
-    auto detector = get_dut();
-
     // Loop over all tracks
     for(auto& track : (*tracks)) {
         // Flags to select clusters and tracks
@@ -197,21 +208,21 @@ StatusCode CLICpix2Analysis::run(Clipboard* clipboard) {
         }
 
         // Check if it intercepts the DUT
-        auto globalIntercept = detector->getIntercept(track);
-        auto localIntercept = detector->globalToLocal(globalIntercept);
+        auto globalIntercept = m_detector->getIntercept(track);
+        auto localIntercept = m_detector->globalToLocal(globalIntercept);
 
-        if(!detector->hasIntercept(track, 1.)) {
+        if(!m_detector->hasIntercept(track, 1.)) {
             LOG(DEBUG) << " - track outside DUT area";
             continue;
         }
 
         // Check that track is within region of interest using winding number algorithm
-        if(!detector->isWithinROI(track)) {
+        if(!m_detector->isWithinROI(track)) {
             is_within_roi = false;
         }
 
         // Check that it doesn't go through/near a masked pixel
-        if(detector->hitMasked(track, 1.)) {
+        if(m_detector->hitMasked(track, 1.)) {
             LOG(DEBUG) << " - track close to masked pixel";
             continue;
         }
@@ -232,11 +243,11 @@ StatusCode CLICpix2Analysis::run(Clipboard* clipboard) {
         }
 
         // Calculate in-pixel position of track in microns
-        auto xmod = static_cast<double>(Units::convert(detector->inPixelX(localIntercept), "um"));
-        auto ymod = static_cast<double>(Units::convert(detector->inPixelY(localIntercept), "um"));
+        auto xmod = static_cast<double>(Units::convert(m_detector->inPixelX(localIntercept), "um"));
+        auto ymod = static_cast<double>(Units::convert(m_detector->inPixelY(localIntercept), "um"));
 
         // Get the DUT clusters from the clipboard
-        Clusters* clusters = reinterpret_cast<Clusters*>(clipboard->get(get_dut()->name(), "clusters"));
+        Clusters* clusters = reinterpret_cast<Clusters*>(clipboard->get(m_detector->name(), "clusters"));
         if(clusters == nullptr) {
             LOG(DEBUG) << " - no DUT clusters";
         } else {
@@ -268,11 +279,13 @@ StatusCode CLICpix2Analysis::run(Clipboard* clipboard) {
                 // We now have an associated cluster
                 has_associated_cluster = true;
                 // FIXME need to understand local coord of clusters - why shifted? what's normal?
-                auto clusterLocal = detector->globalToLocal(cluster->global());
-                hClusterMapAssoc->Fill(detector->getColumn(clusterLocal), detector->getRow(clusterLocal));
-                hClusterSizeMapAssoc->Fill(
-                    detector->getColumn(clusterLocal), detector->getRow(clusterLocal), static_cast<double>(cluster->size()));
-                hClusterToTMapAssoc->Fill(detector->getColumn(clusterLocal), detector->getRow(clusterLocal), cluster->tot());
+                auto clusterLocal = m_detector->globalToLocal(cluster->global());
+                hClusterMapAssoc->Fill(m_detector->getColumn(clusterLocal), m_detector->getRow(clusterLocal));
+                hClusterSizeMapAssoc->Fill(m_detector->getColumn(clusterLocal),
+                                           m_detector->getRow(clusterLocal),
+                                           static_cast<double>(cluster->size()));
+                hClusterToTMapAssoc->Fill(
+                    m_detector->getColumn(clusterLocal), m_detector->getRow(clusterLocal), cluster->tot());
 
                 clusterTotAssoc->Fill(cluster->tot());
 
@@ -344,7 +357,7 @@ StatusCode CLICpix2Analysis::run(Clipboard* clipboard) {
         // Efficiency plots:
         hGlobalEfficiencyMap->Fill(globalIntercept.X(), globalIntercept.Y(), has_associated_cluster);
         hChipEfficiencyMap->Fill(
-            detector->getColumn(localIntercept), detector->getRow(localIntercept), has_associated_cluster);
+            m_detector->getColumn(localIntercept), m_detector->getRow(localIntercept), has_associated_cluster);
 
         // For pixels, only look at the ROI:
         if(is_within_roi) {
diff --git a/src/modules/CLICpix2Analysis/CLICpix2Analysis.h b/src/modules/AnalysisDUT/AnalysisDUT.h
similarity index 84%
rename from src/modules/CLICpix2Analysis/CLICpix2Analysis.h
rename to src/modules/AnalysisDUT/AnalysisDUT.h
index ef89fc5d0..6401bb3d8 100644
--- a/src/modules/CLICpix2Analysis/CLICpix2Analysis.h
+++ b/src/modules/AnalysisDUT/AnalysisDUT.h
@@ -1,5 +1,5 @@
-#ifndef CORRYVRECKAN_CLICPIX2_ANALYSIS_H
-#define CORRYVRECKAN_CLICPIX2_ANALYSIS_H
+#ifndef CORRYVRECKAN_DUT_ANALYSIS_H
+#define CORRYVRECKAN_DUT_ANALYSIS_H
 
 #include <TCanvas.h>
 #include <TH1F.h>
@@ -11,18 +11,20 @@
 namespace corryvreckan {
     /** @ingroup Modules
      */
-    class CLICpix2Analysis : public Module {
+    class AnalysisDUT : public Module {
 
     public:
         // Constructors and destructors
-        CLICpix2Analysis(Configuration config, std::vector<std::shared_ptr<Detector>> detectors);
-        ~CLICpix2Analysis() {}
+        AnalysisDUT(Configuration config, std::shared_ptr<Detector> detector);
+        ~AnalysisDUT() {}
 
         // Functions
         void initialise();
         StatusCode run(Clipboard* clipboard);
 
     private:
+        std::shared_ptr<Detector> m_detector;
+
         // Histograms
         TH2F *hClusterMapAssoc, *hHitMapAssoc, *hHitMapROI;
         TProfile2D *hClusterSizeMapAssoc, *hClusterToTMapAssoc;
@@ -64,4 +66,4 @@ namespace corryvreckan {
     };
 } // namespace corryvreckan
 
-#endif // CORRYVRECKAN_CLICPIX2_ANALYSIS_H
+#endif // CORRYVRECKAN_DUT_ANALYSIS_H
diff --git a/src/modules/CLICpix2Analysis/CMakeLists.txt b/src/modules/AnalysisDUT/CMakeLists.txt
similarity index 76%
rename from src/modules/CLICpix2Analysis/CMakeLists.txt
rename to src/modules/AnalysisDUT/CMakeLists.txt
index 9ed5457b4..9120cde75 100644
--- a/src/modules/CLICpix2Analysis/CMakeLists.txt
+++ b/src/modules/AnalysisDUT/CMakeLists.txt
@@ -1,9 +1,9 @@
 # Define module and return the generated name as MODULE_NAME
-CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
+CORRYVRECKAN_DUT_MODULE(MODULE_NAME)
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
-    CLICpix2Analysis.cpp
+    AnalysisDUT.cpp
 )
 
 # Provide standard install target
diff --git a/src/modules/CLICpix2Analysis/README.md b/src/modules/AnalysisDUT/README.md
similarity index 100%
rename from src/modules/CLICpix2Analysis/README.md
rename to src/modules/AnalysisDUT/README.md
-- 
GitLab