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 <DD4hep/InstanceCount.h>
0016 #include <DDDigi/DigiData.h>
0017 #include <DDDigi/DigiContext.h>
0018 #include <DDDigi/DigiEventAction.h>
0019
0020
0021
0022 namespace dd4hep {
0023
0024
0025 namespace digi {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 class DigiHitHistoryDrop : public DigiEventAction {
0037 protected:
0038
0039 std::vector<int> m_masks { };
0040
0041 std::string m_input { };
0042
0043 protected:
0044
0045 DDDIGI_DEFINE_ACTION_CONSTRUCTORS(DigiHitHistoryDrop);
0046
0047
0048 virtual ~DigiHitHistoryDrop() {
0049 InstanceCount::decrement(this);
0050 }
0051
0052 public:
0053
0054 DigiHitHistoryDrop(const DigiKernel& krnl, const std::string& nam)
0055 : DigiEventAction(krnl, nam)
0056 {
0057 declareProperty("masks", m_masks);
0058 declareProperty("input", m_input = "inputs");
0059 InstanceCount::increment(this);
0060 }
0061
0062 template <typename T>
0063 std::pair<std::size_t, std::size_t> drop_history(T& cont) const {
0064 std::size_t num_drop_hit = 0;
0065 std::size_t num_drop_particle = 0;
0066 for( auto& dep : cont ) {
0067 auto ret = dep.second.history.drop();
0068 num_drop_hit += ret.first;
0069 num_drop_particle += ret.second;
0070 }
0071 return std::make_pair(num_drop_hit,num_drop_particle);
0072 }
0073 std::pair<std::size_t, std::size_t> drop_history(DetectorHistory& cont) const {
0074 std::size_t num_drop_hit = 0;
0075 std::size_t num_drop_particle = 0;
0076 for( auto& dep : cont ) {
0077 auto ret = dep.second.drop();
0078 num_drop_hit += ret.first;
0079 num_drop_particle += ret.second;
0080 }
0081 return std::make_pair(num_drop_hit,num_drop_particle);
0082 }
0083
0084
0085 virtual void execute(DigiContext& context) const final {
0086 auto& inputs = context.event->get_segment(m_input);
0087 std::size_t num_drop_hit = 0;
0088 std::size_t num_drop_particle = 0;
0089 for( auto& i : inputs ) {
0090 Key key(i.first);
0091 auto im = std::find(m_masks.begin(), m_masks.end(), key.mask());
0092 if( im != m_masks.end() ) {
0093 if ( DepositMapping* m = std::any_cast<DepositMapping>(&i.second) ) {
0094 auto ret = drop_history(*m);
0095 num_drop_hit += ret.first;
0096 num_drop_particle += ret.second;
0097 }
0098 else if ( DepositVector* v = std::any_cast<DepositVector>(&i.second) ) {
0099 auto ret = drop_history(*v);
0100 num_drop_hit += ret.first;
0101 num_drop_particle += ret.second;
0102 }
0103 else if( DetectorHistory* h = std::any_cast<DetectorHistory>(&i.second) ) {
0104 auto [nhit, npart] = drop_history(*h);
0105 num_drop_hit += nhit;
0106 num_drop_particle += npart;
0107 }
0108 }
0109 }
0110 info("%s+++ Dropped history of %6ld hits %6ld particles",
0111 context.event->id(), num_drop_hit, num_drop_particle);
0112 }
0113 };
0114 }
0115 }
0116
0117 #include <DDDigi/DigiFactories.h>
0118 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiHitHistoryDrop)