File indexing completed on 2025-01-18 09:14:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DDDigi/DigiContainerProcessor.h>
0016 #include <DD4hep/DD4hepUnits.h>
0017
0018
0019 #include <limits>
0020
0021
0022 namespace dd4hep {
0023
0024
0025 namespace digi {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 class DigiDepositSmearEnergy : public DigiDepositsProcessor {
0073 protected:
0074
0075 double m_intrinsic_fluctuation { 0e0 };
0076
0077 double m_systematic_resolution { 0e0 };
0078
0079 double m_instrumentation_resolution { 0e0 };
0080
0081 double m_pair_ionization_energy { 0e0 };
0082
0083 bool m_ionization_fluctuation { false };
0084
0085 bool m_modify_energy { true };
0086
0087 public:
0088
0089 DigiDepositSmearEnergy(const DigiKernel& krnl, const std::string& nam)
0090 : DigiDepositsProcessor(krnl, nam)
0091 {
0092 declareProperty("intrinsic_fluctuation", m_intrinsic_fluctuation = 0e0);
0093 declareProperty("instrumentation_resolution", m_instrumentation_resolution = 0e0);
0094 declareProperty("systematic_resolution", m_systematic_resolution = 0e0);
0095 declareProperty("pair_ionisation_energy", m_pair_ionization_energy = 3.6*dd4hep::eV);
0096 declareProperty("ionization_fluctuation", m_ionization_fluctuation = false);
0097 declareProperty("modify_energy", m_modify_energy = true);
0098 DEPOSIT_PROCESSOR_BIND_HANDLERS(DigiDepositSmearEnergy::smear);
0099 }
0100
0101
0102 template <typename T> void
0103 smear(DigiContext& context, T& cont, work_t& , const predicate_t& predicate) const {
0104 auto& random = context.randomGenerator();
0105 std::size_t updated = 0UL;
0106
0107 for( auto& dep : cont ) {
0108 if ( predicate(dep) ) {
0109 CellID cell = dep.first;
0110 EnergyDeposit& depo = dep.second;
0111 double deposit = depo.deposit;
0112 double delta_E = 0e0;
0113 double energy = deposit / dd4hep::GeV;
0114 double sigma_E_systematic = m_systematic_resolution * energy;
0115 double sigma_E_intrin_fluct = m_intrinsic_fluctuation * std::sqrt(energy);
0116 double sigma_E_instrument = m_instrumentation_resolution / dd4hep::GeV;
0117 double delta_ion = 0e0, num_pairs = 0e0;
0118 constexpr static double eps = std::numeric_limits<double>::epsilon();
0119 if ( sigma_E_systematic > eps ) {
0120 delta_E += sigma_E_systematic * random.gaussian(0e0, 1e0);
0121 }
0122 if ( sigma_E_intrin_fluct > eps ) {
0123 delta_E += sigma_E_intrin_fluct * random.gaussian(0e0, 1e0);
0124 }
0125 if ( sigma_E_instrument > eps ) {
0126 delta_E += sigma_E_instrument * random.gaussian(0e0, 1e0);
0127 }
0128 if ( m_ionization_fluctuation ) {
0129 num_pairs = energy / (m_pair_ionization_energy/dd4hep::GeV);
0130 delta_ion = energy * (random.poisson(num_pairs)/num_pairs);
0131 delta_E += delta_ion;
0132 }
0133 if ( dd4hep::isActivePrintLevel(outputLevel()) ) {
0134 print("%s+++ %016lX [GeV] E:%9.2e [%9.2e %9.2e] intrin_fluct:%9.2e systematic:%9.2e instrument:%9.2e ioni:%9.2e/%.0f",
0135 context.event->id(), cell, energy, deposit/dd4hep::GeV, delta_E,
0136 sigma_E_intrin_fluct, sigma_E_systematic, sigma_E_instrument, delta_ion, num_pairs);
0137 }
0138
0139 delta_E *= dd4hep::GeV;
0140 depo.depositError = delta_E;
0141 if ( m_monitor ) {
0142 m_monitor->energy_shift(dep, delta_E);
0143 }
0144 if ( m_modify_energy ) {
0145 depo.deposit = deposit + delta_E;
0146 depo.flag |= EnergyDeposit::ENERGY_SMEARED;
0147 }
0148 ++updated;
0149 }
0150 }
0151 info("%s+++ %-32s Smear energy: updated %6ld out of %6ld entries from mask: %04X",
0152 context.event->id(), cont.name.c_str(), updated, cont.size(), cont.key.mask());
0153 }
0154 };
0155
0156
0157
0158
0159
0160
0161
0162
0163 class DigiDepositSetEnergyError : public DigiDepositSmearEnergy {
0164 public:
0165
0166 DigiDepositSetEnergyError(const DigiKernel& krnl, const std::string& nam)
0167 : DigiDepositSmearEnergy(krnl, nam)
0168 {
0169 m_modify_energy = false;
0170 }
0171 };
0172 }
0173 }
0174
0175 #include <DDDigi/DigiFactories.h>
0176 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiDepositSmearEnergy)
0177 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiDepositSetEnergyError)