From 577851d32098d6ad2982066102009c8486e73f67 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sat, 6 Jul 2024 08:23:20 +0200 Subject: [PATCH] Use the histogram service instead of saving our own file manually --- .../DDPlanarDigi/components/DDPlanarDigi.cpp | 24 ------------------- k4Reco/DDPlanarDigi/components/DDPlanarDigi.h | 1 - .../DDPlanarDigi/options/runDDPlanarDigi.py | 8 ++++++- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/k4Reco/DDPlanarDigi/components/DDPlanarDigi.cpp b/k4Reco/DDPlanarDigi/components/DDPlanarDigi.cpp index a72d0c5..aaa4b52 100644 --- a/k4Reco/DDPlanarDigi/components/DDPlanarDigi.cpp +++ b/k4Reco/DDPlanarDigi/components/DDPlanarDigi.cpp @@ -23,13 +23,11 @@ #include "edm4hep/TrackerHitPlaneCollection.h" #include "Gaudi/Accumulators/RootHistogram.h" -#include "Gaudi/Histograming/Sink/Utils.h" #include "DD4hep/DD4hepUnits.h" #include "DD4hep/Detector.h" #include "DDSegmentation/BitFieldCoder.h" -#include "TFile.h" #include "TMath.h" #include @@ -311,25 +309,3 @@ std::tuple names = {"hu", "hv", "hT", "hitE", "hitsAccepted", "diffu", "diffv", "diffT", "hSize"}; - - std::string directory = this->name(); - - for (size_t i = 0; i < m_histograms.size(); ++i) { - std::string histName = names[i]; - const nlohmann::json& json = *m_histograms[i]; - - auto [histo, dir] = - Gaudi::Histograming::Sink::jsonToRootHistogram>( - directory, histName, json); - - histo.Write(histName.c_str()); - } - - file->Close(); - return StatusCode::SUCCESS; -} diff --git a/k4Reco/DDPlanarDigi/components/DDPlanarDigi.h b/k4Reco/DDPlanarDigi/components/DDPlanarDigi.h index a51523b..2fc327e 100644 --- a/k4Reco/DDPlanarDigi/components/DDPlanarDigi.h +++ b/k4Reco/DDPlanarDigi/components/DDPlanarDigi.h @@ -77,7 +77,6 @@ struct DDPlanarDigi final DDPlanarDigi(const std::string& name, ISvcLocator* svcLoc); StatusCode initialize() override; - StatusCode finalize() override; std::tuple operator()( const edm4hep::SimTrackerHitCollection& simTrackerHits, diff --git a/k4Reco/DDPlanarDigi/options/runDDPlanarDigi.py b/k4Reco/DDPlanarDigi/options/runDDPlanarDigi.py index 75d58c6..2d2a3dd 100644 --- a/k4Reco/DDPlanarDigi/options/runDDPlanarDigi.py +++ b/k4Reco/DDPlanarDigi/options/runDDPlanarDigi.py @@ -22,6 +22,8 @@ from Configurables import DDPlanarDigi from Configurables import GeoSvc from Configurables import UniqueIDGenSvc +from Configurables import RootHistSvc +from Configurables import Gaudi__Histograming__Sink__Root as RootHistoSink import os id_service = UniqueIDGenSvc("UniqueIDGenSvc") @@ -50,9 +52,13 @@ # "EventHeader", # ] +hps = RootHistSvc("HistogramPersistencySvc") +root_hist_svc = RootHistoSink("RootHistoSink") +root_hist_svc.FileName = "ddplanardigi_hist.root" + ApplicationMgr(TopAlg=[digi], EvtSel="NONE", EvtMax=-1, - ExtSvc=[EventDataSvc("EventDataSvc")], + ExtSvc=[EventDataSvc("EventDataSvc"), root_hist_svc], OutputLevel=INFO, )