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 class DigiDepositSmearTime : public DigiDepositsProcessor {
0036 protected:
0037 using limit_t = std::numeric_limits<double>;
0038
0039 double m_resolution_time { 0e0 };
0040
0041 std::pair<double, double> m_window_time { limit_t::min(), limit_t::max() };
0042
0043 public:
0044
0045 template <typename T> void
0046 smear(DigiContext& context, T& cont, work_t& , const predicate_t& predicate) const {
0047 auto& random = context.randomGenerator();
0048 std::size_t killed = 0UL;
0049 std::size_t updated = 0UL;
0050 for( auto& dep : cont ) {
0051 if ( predicate(dep) ) {
0052 int flag = EnergyDeposit::TIME_SMEARED;
0053 double delta_T = m_resolution_time * random.gaussian();
0054 if ( delta_T < m_window_time.first || delta_T > m_window_time.second ) {
0055 flag |= EnergyDeposit::KILLED;
0056 ++killed;
0057 }
0058 if ( m_monitor ) m_monitor->time_shift(dep, delta_T);
0059 dep.second.time += delta_T;
0060 dep.second.flag |= flag;
0061 ++updated;
0062 }
0063 }
0064 if ( m_monitor ) m_monitor->count_shift(cont.size(), -killed);
0065 info("%s+++ %-32s Smeared time resolution: %6ld entries, updated %6ld killed %6ld entries from mask: %04X",
0066 context.event->id(), cont.name.c_str(), cont.size(), updated, killed, cont.key.mask());
0067 }
0068
0069
0070 DigiDepositSmearTime(const DigiKernel& krnl, const std::string& nam)
0071 : DigiDepositsProcessor(krnl, nam)
0072 {
0073 declareProperty("resolution_time", m_resolution_time);
0074 declareProperty("window_time", m_window_time);
0075 DEPOSIT_PROCESSOR_BIND_HANDLERS(DigiDepositSmearTime::smear);
0076 }
0077 };
0078 }
0079 }
0080
0081 #include <DDDigi/DigiFactories.h>
0082 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiDepositSmearTime)