From 27f037f4a4bc1897d7d2c09e011c726a59d2acba Mon Sep 17 00:00:00 2001 From: BrieucF Date: Tue, 6 Aug 2024 11:42:49 +0200 Subject: [PATCH] [PlotTrackHitResiduals] Remove overflow bin and use RootHistSvc --- Tracking/components/PlotTrackHitResiduals.cpp | 16 ---------------- Tracking/test/runTracksFromGenParticles.py | 8 ++++++-- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Tracking/components/PlotTrackHitResiduals.cpp b/Tracking/components/PlotTrackHitResiduals.cpp index 02ea68e..5b8c725 100644 --- a/Tracking/components/PlotTrackHitResiduals.cpp +++ b/Tracking/components/PlotTrackHitResiduals.cpp @@ -76,22 +76,6 @@ struct PlotTrackHitDistances final Gaudi::Property m_Bz{this, "Bz", 2., "Z component of the (assumed constant) magnetic field in Tesla."}; mutable Gaudi::Accumulators::Histogram<1> m_residualHist{this, "", "Track-hit Distances", {100, 0, 1, "Distance [mm];Entries"}}; - StatusCode finalize() override { - TFile file("track_hit_distances.root", "RECREATE"); - std::string name = ""; - // Name that will appear in the stats table - std::string histName = "Distances"; - nlohmann::json jH {m_residualHist}; - auto [histo, dir] = Gaudi::Histograming::Sink::jsonToRootHistogram>(name, histName, jH[0]); - // Add overflow bin to the last bin - int lastBinIndex = histo.GetNbinsX(); - histo.SetBinContent(lastBinIndex, histo.GetBinContent(lastBinIndex) + histo.GetBinContent(lastBinIndex + 1)); - // Name of the histogram in the ROOT file - histo.Write("Distances"); - file.Close(); - return StatusCode::SUCCESS; - } - }; DECLARE_COMPONENT(PlotTrackHitDistances) diff --git a/Tracking/test/runTracksFromGenParticles.py b/Tracking/test/runTracksFromGenParticles.py index 51742d1..6a1b188 100644 --- a/Tracking/test/runTracksFromGenParticles.py +++ b/Tracking/test/runTracksFromGenParticles.py @@ -21,12 +21,16 @@ OutputLevel = INFO) # produce a TH1 with distances between tracks and simTrackerHits -from Configurables import PlotTrackHitDistances +from Configurables import PlotTrackHitDistances, RootHistSvc plotTrackHitDistances = PlotTrackHitDistances("PlotTrackHitDistances", InputSimTrackerHits = ["CDCHHits"], InputTracksFromGenParticlesAssociation = tracksFromGenParticles.OutputMCRecoTrackParticleAssociation, Bz = 2.0) +hps = RootHistSvc("HistogramPersistencySvc") +root_hist_svc = RootHistoSink("RootHistoSink") +root_hist_svc.FileName = "TrackHitDistances.root" + # Set auditor service from Configurables import AuditorSvc, ChronoAuditor chra = ChronoAuditor() @@ -45,6 +49,6 @@ TopAlg= [event_counter, tracksFromGenParticles, plotTrackHitDistances], EvtSel='NONE', EvtMax=-1, - ExtSvc=[EventDataSvc("EventDataSvc"), audsvc], + ExtSvc=[root_hist_svc, EventDataSvc("EventDataSvc"), audsvc], StopOnSignal=True, )