File indexing completed on 2025-01-18 09:14:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/InstanceCount.h>
0016 #include <DDDigi/DigiKernel.h>
0017 #include <DDDigi/DigiDepositMonitor.h>
0018
0019
0020 #include <TH1F.h>
0021 #include <TH2F.h>
0022
0023
0024
0025 using namespace dd4hep::digi;
0026
0027
0028 void Histo1D::fill(double x, double weight) {
0029 hist->Fill(x, weight);
0030 }
0031
0032
0033 void Histo2D::fill(double x, double y, double weight) {
0034 hist->Fill(x, y, weight);
0035 }
0036
0037
0038 DigiDepositMonitor::DigiDepositMonitor(const DigiKernel& krnl, const std::string& nam)
0039 : DigiAction(krnl, nam)
0040 {
0041 m_kernel.register_initialize(std::bind(&DigiDepositMonitor::initialize,this));
0042 InstanceCount::increment(this);
0043 }
0044
0045
0046 DigiDepositMonitor::~DigiDepositMonitor() {
0047 InstanceCount::decrement(this);
0048 }
0049
0050
0051 void DigiDepositMonitor::initialize() {
0052 }
0053
0054
0055 Histo1D DigiDepositMonitor::book1D(const std::string& name, const std::string& title,
0056 std::size_t nbin_x, double min_x, double max_x) {
0057 auto* h = new TH1F(name.c_str(), title.c_str(), nbin_x, min_x, max_x);
0058 m_kernel.register_monitor(this, h);
0059 return { h };
0060 }
0061
0062
0063 Histo2D DigiDepositMonitor::book2D(const std::string& name, const std::string& title,
0064 std::size_t nbin_x, double min_x, double max_x,
0065 std::size_t nbin_y, double min_y, double max_y) {
0066 auto* h = new TH2F(name.c_str(), title.c_str(), nbin_x, min_x, max_x, nbin_y, min_y, max_y);
0067 m_kernel.register_monitor(this, h);
0068 return { h };
0069 }
0070
0071
0072 DigiDepositEnergyMonitor::DigiDepositEnergyMonitor(const kernel_t& kernel, const std::string& name)
0073 : DigiDepositMonitor(kernel, name)
0074 {
0075 declareProperty("histo1D_deposits", histo1D_deposits);
0076 declareProperty("histo1D_delta", histo1D_delta);
0077 }
0078
0079
0080 void DigiDepositEnergyMonitor::initialize() {
0081 declare_monitor_energy(this, &DigiDepositEnergyMonitor::monitor_energy_shift);
0082 m_deltas = book1D(histo1D_delta.name.c_str(), histo1D_delta.title.c_str(),
0083 histo1D_delta.nbin_x, histo1D_delta.min_x, histo1D_delta.max_x);
0084 m_deposits = book1D(histo1D_deposits.name.c_str(), histo1D_deposits.title.c_str(),
0085 histo1D_deposits.nbin_x, histo1D_deposits.min_x, histo1D_deposits.max_x);
0086 }
0087
0088
0089 void DigiDepositEnergyMonitor::monitor_energy_shift(const deposit_t& deposit, double change) {
0090 m_deposits.fill(deposit.second.deposit, 1e0);
0091 m_deltas.fill(change, 1e0);
0092 }
0093
0094
0095 DigiDepositTimeMonitor::DigiDepositTimeMonitor(const kernel_t& kernel, const std::string& name)
0096 : DigiDepositMonitor(kernel, name)
0097 {
0098 declareProperty("histo1D_deposits", histo1D_deposits);
0099 declareProperty("histo1D_delta", histo1D_delta);
0100 }
0101
0102
0103 void DigiDepositTimeMonitor::initialize() {
0104 declare_monitor_time(this, &DigiDepositTimeMonitor::monitor_time_shift);
0105 m_deltas = book1D(histo1D_delta.name.c_str(), histo1D_delta.title.c_str(),
0106 histo1D_delta.nbin_x, histo1D_delta.min_x, histo1D_delta.max_x);
0107 m_deposits = book1D(histo1D_deposits.name.c_str(), histo1D_deposits.title.c_str(),
0108 histo1D_deposits.nbin_x, histo1D_deposits.min_x, histo1D_deposits.max_x);
0109 }
0110
0111
0112 void DigiDepositTimeMonitor::monitor_time_shift(const deposit_t& deposit, double change) {
0113 m_deposits.fill(deposit.second.time, 1e0);
0114 m_deltas.fill(change, 1e0);
0115 }
0116
0117
0118 DigiDepositPositionMonitor::DigiDepositPositionMonitor(const kernel_t& kernel, const std::string& name)
0119 : DigiDepositMonitor(kernel, name)
0120 {
0121 declareProperty("histo1D_deposits", histo1D_deposits);
0122 declareProperty("histo1D_delta", histo1D_delta);
0123 }
0124
0125
0126 void DigiDepositPositionMonitor::initialize() {
0127 declare_monitor_position(this, &DigiDepositPositionMonitor::monitor_position_shift);
0128 m_deltas = book1D(histo1D_delta.name.c_str(), histo1D_delta.title.c_str(),
0129 histo1D_delta.nbin_x, histo1D_delta.min_x, histo1D_delta.max_x);
0130 m_deposits = book1D(histo1D_deposits.name.c_str(), histo1D_deposits.title.c_str(),
0131 histo1D_deposits.nbin_x, histo1D_deposits.min_x, histo1D_deposits.max_x);
0132 }
0133
0134
0135 void DigiDepositPositionMonitor::monitor_position_shift(const deposit_t&, const Position& position, const Position& change) {
0136 m_deposits.fill(std::sqrt(position.Mag2()), 1e0);
0137 m_deltas.fill(std::sqrt(change.Mag2()), 1e0);
0138 }