File indexing completed on 2025-01-30 09:17:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DDDigi/DigiContainerProcessor.h>
0016 #include <DDDigi/DigiKernel.h>
0017
0018 #include <DD4hep/DD4hepUnits.h>
0019 #include <DD4hep/Detector.h>
0020 #include <DD4hep/VolumeManager.h>
0021
0022
0023 #include <limits>
0024
0025
0026 namespace dd4hep {
0027
0028 namespace digi {
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 class DigiDepositSmearPositionResolution : public DigiDepositsProcessor {
0039 protected:
0040
0041 double m_resolution_u { 0e0 * dd4hep::mm };
0042
0043 double m_resolution_v { 0e0 * dd4hep::mm };
0044
0045
0046 DigiDepositMonitor* m_local_monitor { nullptr };
0047
0048 public:
0049
0050 DigiDepositSmearPositionResolution(const DigiKernel& krnl, const std::string& nam)
0051 : DigiDepositsProcessor(krnl, nam)
0052 {
0053 declareProperty("resolution_u", m_resolution_u);
0054 declareProperty("resolution_v", m_resolution_v);
0055 DEPOSIT_PROCESSOR_BIND_HANDLERS(DigiDepositSmearPositionResolution::smear);
0056 }
0057
0058
0059 template <typename T> void
0060 smear(DigiContext& context, T& cont, work_t& , const predicate_t& predicate) const {
0061 VolumeManager volMgr = m_kernel.detectorDescription().volumeManager();
0062 auto& random = context.randomGenerator();
0063 std::size_t updated = 0UL;
0064
0065 for( auto& dep : cont ) {
0066 if ( predicate(dep) ) {
0067 CellID cell = dep.first;
0068 EnergyDeposit& depo = dep.second;
0069 auto* ctxt = volMgr.lookupContext(cell);
0070 Position local_pos = ctxt->worldToLocal(depo.position);
0071 double delta_u = m_resolution_u * random.gaussian();
0072 double delta_v = m_resolution_v * random.gaussian();
0073 Position delta_pos(delta_u, delta_v, 0e0);
0074 Position oldpos = depo.position;
0075 Position newpos = ctxt->localToWorld(local_pos + delta_pos);
0076
0077 if ( m_local_monitor ) m_local_monitor->position_shift(dep, local_pos, delta_pos);
0078 delta_pos = newpos - oldpos;
0079 if ( m_monitor ) m_monitor->position_shift(dep, oldpos, delta_pos);
0080
0081 info("+++ %016lX Smeared position [%9.2e %9.2e %9.2e] by [%9.2e %9.2e %9.2e] to [%9.2e %9.2e %9.2e] [mm]",
0082 oldpos.X(), oldpos.Y(), oldpos.Z(), delta_pos.X(), delta_pos.Y(), delta_pos.Z(),
0083 newpos.X(), newpos.Y(), newpos.Z());
0084
0085 depo.position = newpos;
0086 depo.flag |= EnergyDeposit::POSITION_SMEARED;
0087 ++updated;
0088 }
0089 }
0090 info("%s+++ %-32s Smear position(resolution): updated %6ld out of %6ld entries from mask: %04X",
0091 context.event->id(), cont.name.c_str(), updated, cont.size(), cont.key.mask());
0092 }
0093 };
0094 }
0095 }
0096
0097 #include <DDDigi/DigiFactories.h>
0098 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiDepositSmearPositionResolution)