From 97f0f032457f12a224f53587d09e32c92948f576 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Thu, 26 Sep 2024 17:59:03 +0200
Subject: [PATCH] CA-QA: adding the Setup QA task for full-CBM, adding material
 maps histograms to the Setup QA task

---
 algo/kf/core/geo/KfModuleIndexMap.h |  2 +-
 macro/run/run_qa.C                  |  5 +++++
 reco/L1/qa/CbmCaInputQaSetup.cxx    | 27 +++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/algo/kf/core/geo/KfModuleIndexMap.h b/algo/kf/core/geo/KfModuleIndexMap.h
index 9410ecd395..66b1cdb489 100644
--- a/algo/kf/core/geo/KfModuleIndexMap.h
+++ b/algo/kf/core/geo/KfModuleIndexMap.h
@@ -58,7 +58,7 @@ namespace cbm::algo::kf
     /// \tparam  EDetID  concrete index type of the det ID (can be either an enum, or an integral type)
     /// \param globId  Internal layer index
     /// \return  pair(detector ID, local ID) of the layer
-    template<class EDetID>
+    template<class EDetID = int>
     std::pair<EDetID, int> GlobalToLocal(int globId) const;
 
     /// \brief Converts external pair (detID, locID) to internal layer index
diff --git a/macro/run/run_qa.C b/macro/run/run_qa.C
index ad0442d387..16880b48a3 100644
--- a/macro/run/run_qa.C
+++ b/macro/run/run_qa.C
@@ -293,6 +293,11 @@ void run_qa(TString dataTraColl,
   TString caParFile = recFile;
   caParFile.ReplaceAll(".root", ".ca.par");
 
+  auto* pCaInputQaSetup = new cbm::ca::InputQaSetup(verbose, bUseMC);
+  pCaInputQaSetup->ReadParameters(caParFile.Data());
+  pCaInputQaSetup->SetSetupName(setup.Data());
+  qaManager->AddTask(pCaInputQaSetup);
+
   auto* pCaOutputQa = new cbm::ca::OutputQa(verbose, bUseMC, recoMode);
   pCaOutputQa->SetStsTrackingMode();
   pCaOutputQa->ReadParameters(caParFile.Data());
diff --git a/reco/L1/qa/CbmCaInputQaSetup.cxx b/reco/L1/qa/CbmCaInputQaSetup.cxx
index 1d49ab0bc1..41bb8fe5f6 100644
--- a/reco/L1/qa/CbmCaInputQaSetup.cxx
+++ b/reco/L1/qa/CbmCaInputQaSetup.cxx
@@ -11,6 +11,7 @@
 
 #include "CaInitManager.h"
 #include "CbmCaTrackingSetupBuilder.h"
+#include "CbmL1DetectorID.h"
 #include "CbmMCDataManager.h"
 #include "FairRootManager.h"
 #include "TAxis.h"
@@ -407,6 +408,32 @@ try {
     }
   }
 
+
+  auto CreateMaterialBudgetHistograms = [&](const auto& kfSetup, const TString& dir) {
+    for (int iLayer = 0; iLayer < kfSetup.GetNofLayers(); ++iLayer) {
+      const auto& matMap{kfSetup.GetMaterial(iLayer)};
+      auto [detID, stationID] = kfSetup.GetIndexMap().GlobalToLocal(iLayer);
+      TString sN              = Form("%s/mat_budget_%s_st%d", dir.Data(), kDetName[detID], stationID);
+      TString sT =
+        Form("Material budget map for %s station %d;x [cm];y [cm]; X/X_{0} [\%]", kDetName[detID], stationID);
+      auto nBins{matMap.GetNbins()};
+      auto xMin{-matMap.GetXYmax()};
+      auto xMax{+matMap.GetXYmax()};
+      auto* pHist = MakeQaObject<TH2F>(sN, sT, nBins, xMin, xMax, nBins, xMin, xMax);
+      for (int iX = 0; iX < nBins; ++iX) {
+        for (int iY = 0; iY < nBins; ++iY) {
+          pHist->SetBinContent(iX + 1, iY + 1, 100. * matMap.GetThicknessX0(iX, iY));
+        }
+      }
+    }
+  };
+
+  MakeQaDirectory("TrackingKFSetup");
+  MakeQaDirectory("TrackingKFSetup/geometry");
+  CreateMaterialBudgetHistograms(fpParameters->GetGeometrySetup(), "TrackingKFSetup/geometry");
+  MakeQaDirectory("TrackingKFSetup/active");
+  CreateMaterialBudgetHistograms(fpParameters->GetActiveSetup(), "TrackingKFSetup/active");
+
   LOG(error) << fName << ": initializing... \033[1;32mDone\033[0m";
   return kSUCCESS;
 }
-- 
GitLab