trout
Phlex-based reconstruction framework for the SHiP experiment.
Loading...
Searching...
No Matches
multiplicity_histogrammer.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 CERN for the benefit of the SHiP Collaboration
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5// multiplicity_histogrammer.hpp — per-event hit-multiplicity validation
6// histogram. Not instantiated directly: it is the base the per-subdetector
7// histogrammers derive from while their monitoring is (so far) just a
8// multiplicity count, so each detector keeps a named class and header of its
9// own to grow into. A detector that outgrows this drops the base class and
10// books its own histograms (see SpectrometerHistogrammer).
11
12#pragma once
13
14#include "HistoFileService.hpp"
15
16#include <ROOT/RHist.hxx>
17#include <ROOT/RHistConcurrentFiller.hxx>
18#include <ROOT/RHistFillContext.hxx>
19
20#include <memory>
21#include <oneapi/tbb/enumerable_thread_specific.h>
22#include <string>
23#include <utility>
24#include <vector>
25
26namespace SHiP::trout {
27
28template <typename Hit>
30 public:
31 MultiplicityHistogrammer(std::shared_ptr<HistoFileService> file_service, std::string hist_name,
32 std::string hist_title)
33 : file_service_{std::move(file_service)},
34 hist_name_{std::move(hist_name)},
35 hist_title_{std::move(hist_title)},
36 h_multiplicity_{make_hist(1000, -0.5, 999.5)},
37 f_multiplicity_{h_multiplicity_} {}
38
39 void observe(std::vector<Hit> const& hits) {
40 ensure_context().Fill(static_cast<double>(hits.size()));
41 }
42
44 fill_contexts_.clear();
45 file_service_->put(hist_name_.c_str(), hist_title_.c_str(), *h_multiplicity_);
46 }
47
48 protected:
49 // For subclasses booking histograms of their own: Put() them into this
50 // file from the subclass destructor, which runs before this one.
51 std::shared_ptr<HistoFileService> const& file_service() const { return file_service_; }
52
53 private:
54 using HistD = ROOT::Experimental::RHist<double>;
55 using FillerD = ROOT::Experimental::RHistConcurrentFiller<double>;
56 using ContextD = ROOT::Experimental::RHistFillContext<double>;
57
58 ContextD& ensure_context() {
59 auto& ctx = fill_contexts_.local();
60 if (!ctx) {
61 ctx = f_multiplicity_.CreateFillContext();
62 }
63 return *ctx;
64 }
65
66 std::shared_ptr<HistoFileService> file_service_;
67 std::string hist_name_;
68 std::string hist_title_;
69 std::shared_ptr<HistD> h_multiplicity_;
70 FillerD f_multiplicity_;
71 tbb::enumerable_thread_specific<std::shared_ptr<ContextD>> fill_contexts_;
72};
73
74} // namespace SHiP::trout
~MultiplicityHistogrammer()
Definition multiplicity_histogrammer.hpp:43
void observe(std::vector< Hit > const &hits)
Definition multiplicity_histogrammer.hpp:39
MultiplicityHistogrammer(std::shared_ptr< HistoFileService > file_service, std::string hist_name, std::string hist_title)
Definition multiplicity_histogrammer.hpp:31
std::shared_ptr< HistoFileService > const & file_service() const
Definition multiplicity_histogrammer.hpp:51
Definition fit_seed.cpp:16
std::shared_ptr< ROOT::Experimental::RHist< double > > make_hist(std::uint64_t nbins, double low, double high)
Definition HistoFileService.hpp:56