Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:11

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/InstanceCount.h>
0016 #include <DDDigi/DigiData.h>
0017 #include <DDDigi/DigiContext.h>
0018 #include <DDDigi/DigiEventAction.h>
0019 
0020 
0021 /// Namespace for the AIDA detector description toolkit
0022 namespace dd4hep {
0023 
0024   /// Namespace for the Digitization part of the AIDA detector description toolkit
0025   namespace digi {
0026 
0027     /// Default base class for all Digitizer actions and derivates thereof.
0028     /**
0029      *  This is a utility class supporting properties, output and access to
0030      *  event and run objects through the context.
0031      *
0032      *  \author  M.Frank
0033      *  \version 1.0
0034      *  \ingroup DD4HEP_DIGITIZATION
0035      */
0036     class DigiHitHistoryDrop : public DigiEventAction   {
0037     protected:
0038       /// Property: Masks to act on
0039       std::vector<int> m_masks  { };
0040       /// Property: Input data segment name
0041       std::string      m_input  { };
0042 
0043     protected:
0044       /// Define standard assignments and constructors
0045       DDDIGI_DEFINE_ACTION_CONSTRUCTORS(DigiHitHistoryDrop);
0046 
0047       /// Default destructor
0048       virtual ~DigiHitHistoryDrop()  {
0049         InstanceCount::decrement(this);
0050       }
0051 
0052     public:
0053       /// Standard constructor
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       /// Main functional callback
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   }    // End namespace digi
0115 }      // End namespace dd4hep
0116 
0117 #include <DDDigi/DigiFactories.h>
0118 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiHitHistoryDrop)