From a4a0846373a7d3ec8944731b1131b7bf18a45db5 Mon Sep 17 00:00:00 2001
From: Dominik Smith <d.smith@gsi.de>
Date: Thu, 4 Nov 2021 15:54:32 +0100
Subject: [PATCH] Improved QA output for event builder and seed finder.

---
 macro/run/run_reco.C                             |  1 +
 reco/eventbuilder/digis/CbmBuildEventsQa.cxx     | 16 ++++++++++------
 .../digis/CbmSeedFinderSlidingWindow.cxx         |  5 +++++
 .../digis/CbmSeedFinderSlidingWindow.h           |  6 +++++-
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/macro/run/run_reco.C b/macro/run/run_reco.C
index b92cf78eba..14cb84cbe5 100644
--- a/macro/run/run_reco.C
+++ b/macro/run/run_reco.C
@@ -229,6 +229,7 @@ void run_reco(TString input = "", Int_t nTimeSlices = -1, Int_t firstTimeSlice =
       //evBuildRaw->SetReferenceDetector(kRawEventBuilderDetUndef);
       //evBuildRaw->AddSeedTimeFillerToList(kRawEventBuilderDetSts);
       //evBuildRaw->SetSlidingWindowSeedFinder(1000, 500, 500);
+      //evBuildRaw->SetSeedFinderQa(true);  // optional QA information for seed finder
 
       evBuildRaw->SetTsParameters(0.0, 1.e7, 0.0);
 
diff --git a/reco/eventbuilder/digis/CbmBuildEventsQa.cxx b/reco/eventbuilder/digis/CbmBuildEventsQa.cxx
index 2b61daf48c..d32be860d9 100644
--- a/reco/eventbuilder/digis/CbmBuildEventsQa.cxx
+++ b/reco/eventbuilder/digis/CbmBuildEventsQa.cxx
@@ -98,15 +98,19 @@ InitStatus CbmBuildEventsQa::Init()
 
   // --- Init histograms
   histFolder            = fOutFolder.AddFolder("hist", "Histogramms");
-  fhCorrectDigiRatioAll = new TH1F("fhCorrectDigiRatioAll", "\% correct digis per event", 1001, 0., 100.1);
-  fhFoundDigiRatioAll   = new TH1F("fhFoundDigiRatioAll", "\% found digis per event", 1001, 0., 100.1);
+  fhCorrectDigiRatioAll = new TH1F("fhCorrectDigiRatioAll", "Correct digis per event [pct]", 402, -0.25, 100.25);
+  fhFoundDigiRatioAll   = new TH1F("fhFoundDigiRatioAll", "Found digis per event [pct]", 402, -0.25, 100.25);
   histFolder->Add(fhCorrectDigiRatioAll);
   histFolder->Add(fhFoundDigiRatioAll);
   for (ECbmModuleId& system : fSystems) {
-    TString h1name                  = "fhCorrectDigiRatio" + CbmModuleList::GetModuleNameCaps(system);
-    TString h2name                  = "fhFoundDigiRatio" + CbmModuleList::GetModuleNameCaps(system);
-    fhMapSystemsCorrectDigi[system] = new TH1F(h1name, "\% correct digis per event", 1001, 0., 100.1);
-    fhMapSystemsFoundDigi[system]   = new TH1F(h2name, "\% found digis per event", 1001, 0., 100.1);
+    TString h1name = "fhCorrectDigiRatio" + CbmModuleList::GetModuleNameCaps(system);
+    TString h2name = "fhFoundDigiRatio" + CbmModuleList::GetModuleNameCaps(system);
+    fhMapSystemsCorrectDigi[system] =
+      new TH1F(h1name, Form("Correct digis per event, %s [pct]", (CbmModuleList::GetModuleNameCaps(system)).Data()),
+               402, -0.25, 100.25);
+    fhMapSystemsFoundDigi[system] =
+      new TH1F(h2name, Form("Found digis per event, %s [pct]", (CbmModuleList::GetModuleNameCaps(system)).Data()), 402,
+               -0.25, 100.25);
     histFolder->Add(fhMapSystemsCorrectDigi[system]);
     histFolder->Add(fhMapSystemsFoundDigi[system]);
   }
diff --git a/reco/eventbuilder/digis/CbmSeedFinderSlidingWindow.cxx b/reco/eventbuilder/digis/CbmSeedFinderSlidingWindow.cxx
index 715640a331..22172ba231 100644
--- a/reco/eventbuilder/digis/CbmSeedFinderSlidingWindow.cxx
+++ b/reco/eventbuilder/digis/CbmSeedFinderSlidingWindow.cxx
@@ -87,6 +87,11 @@ void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<inType>* vIn, c
       winStartT = GetTime(vIn, j);
     }
   }
+
+  if (vDigiMatch && fvEventMatches) {  // QA mode
+    std::cout << "CbmSeedFinderSlidingWindow::FillSeedTimes(): Found " << GetNofSeeds() << " seeds for this timeslice."
+              << std::endl;
+  }
 }
 template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmMuchBeamTimeDigi>*,
                                                         const std::vector<CbmMatch>*);
diff --git a/reco/eventbuilder/digis/CbmSeedFinderSlidingWindow.h b/reco/eventbuilder/digis/CbmSeedFinderSlidingWindow.h
index d76578428f..c3991887fa 100644
--- a/reco/eventbuilder/digis/CbmSeedFinderSlidingWindow.h
+++ b/reco/eventbuilder/digis/CbmSeedFinderSlidingWindow.h
@@ -24,6 +24,7 @@
 #include <vector>
 
 #include <stdint.h>
+#include <stdio.h>
 
 class CbmMatch;
 
@@ -61,6 +62,9 @@ public:
   template<class inType>
   void FillSeedTimes(const std::vector<inType>* vIn, const std::vector<CbmMatch>* vDigiMatch = nullptr);
 
+  /** @brief Returns number of seed times currently stored in buffer. */
+  size_t GetNofSeeds() { return fvSeedTimes->size(); }
+
 private:
   /** @brief Output of the algorithm. Stores seed times for current time slice. */
   std::vector<double>* fvSeedTimes = nullptr;
@@ -96,4 +100,4 @@ private:
   */
   void FillEventMatch(int32_t WinStart, int32_t WinEnd, const std::vector<CbmMatch>* vDigiMatch);
 };
-#endif  //CbmSeedFinderSlidingWindow_tmpl
+#endif  //CbmSeedFinderSlidingWindow_h
-- 
GitLab