Skip to content

Commit

Permalink
Use the histogram service instead of saving our own file manually
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Jul 6, 2024
1 parent 251ee0d commit 577851d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
24 changes: 0 additions & 24 deletions k4Reco/DDPlanarDigi/components/DDPlanarDigi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fmt/format.h>
Expand Down Expand Up @@ -311,25 +309,3 @@ std::tuple<edm4hep::TrackerHitPlaneCollection, edm4hep::MCRecoTrackerAssociation

return std::make_tuple(std::move(trkhitVec), std::move(thsthcol));
}

StatusCode DDPlanarDigi::finalize() {
auto file = TFile::Open(m_outputFileName.value().c_str(), "UPDATE");

std::vector<const char*> 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<Gaudi::Histograming::Sink::Traits<false, TH1D, 1>>(
directory, histName, json);

histo.Write(histName.c_str());
}

file->Close();
return StatusCode::SUCCESS;
}
1 change: 0 additions & 1 deletion k4Reco/DDPlanarDigi/components/DDPlanarDigi.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ struct DDPlanarDigi final
DDPlanarDigi(const std::string& name, ISvcLocator* svcLoc);

StatusCode initialize() override;
StatusCode finalize() override;

std::tuple<edm4hep::TrackerHitPlaneCollection, edm4hep::MCRecoTrackerAssociationCollection> operator()(
const edm4hep::SimTrackerHitCollection& simTrackerHits,
Expand Down
8 changes: 7 additions & 1 deletion k4Reco/DDPlanarDigi/options/runDDPlanarDigi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
)

0 comments on commit 577851d

Please sign in to comment.