Skip to content

Commit

Permalink
[PlotTrackHitResiduals] Remove overflow bin and use RootHistSvc
Browse files Browse the repository at this point in the history
  • Loading branch information
BrieucF committed Aug 6, 2024
1 parent a9f592f commit 27f037f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
16 changes: 0 additions & 16 deletions Tracking/components/PlotTrackHitResiduals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,6 @@ struct PlotTrackHitDistances final
Gaudi::Property<float> 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<Gaudi::Histograming::Sink::Traits<false, TH1D, 1>>(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)
8 changes: 6 additions & 2 deletions Tracking/test/runTracksFromGenParticles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
)

0 comments on commit 27f037f

Please sign in to comment.