Back to home page

EIC code displayed by LXR

 
 

    


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

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/Readout.h>
0016 #include <DD4hep/InstanceCount.h>
0017 #include <DD4hep/detail/ObjectsInterna.h>
0018 #include <DDG4/Geant4Mapping.h>
0019 #include <DDG4/Geant4StepHandler.h>
0020 #include <DDG4/Geant4VolumeManager.h>
0021 #include <DDG4/Geant4FastSimHandler.h>
0022 #include <DDG4/Geant4ReadoutVolumeFilter.h>
0023 
0024 using namespace dd4hep::sim;
0025 
0026 /// Standard constructor
0027 Geant4ReadoutVolumeFilter::Geant4ReadoutVolumeFilter(Geant4Context* ctxt, 
0028                                                      const std::string& nam, 
0029                                                      Readout ro, 
0030                                                      const std::string& coll)
0031   : Geant4Filter(ctxt, nam), m_readout(ro), m_collection(0), m_key(0)
0032 {
0033   InstanceCount::increment(this);
0034   for(size_t i=0; i<ro->hits.size(); ++i)  {
0035     const HitCollection& c = ro->hits[i];
0036     if ( c.name == coll )   {
0037       m_collection = &c;
0038       m_key = ro.idSpec().field(c.key);
0039       return;
0040     }
0041   }
0042   except("+++ Custom collection name '%s' not defined in the Readout object: %s.",
0043          coll.c_str(), ro.name());      
0044 }
0045 
0046 /// Default destructor
0047 Geant4ReadoutVolumeFilter::~Geant4ReadoutVolumeFilter() {
0048   InstanceCount::decrement(this);
0049 }
0050 
0051 /// Filter action. Return true if hits should be processed
0052 bool Geant4ReadoutVolumeFilter::operator()(const G4Step* step) const    {
0053   Geant4StepHandler stepH(step);
0054   Geant4VolumeManager volMgr = Geant4Mapping::instance().volumeManager();
0055   VolumeID id  = volMgr.volumeID(stepH.preTouchable());
0056   FieldID  key = m_key->value(id);
0057   if ( m_collection->key_min <= key && m_collection->key_max >= key )
0058     return true;
0059   return false;
0060 }
0061 
0062 /// GFLASH/FastSim interface: Filter action. Return true if hits should be processed
0063 bool Geant4ReadoutVolumeFilter::operator()(const Geant4FastSimSpot* spot) const    {
0064   Geant4FastSimHandler spotH(spot);
0065   Geant4VolumeManager volMgr = Geant4Mapping::instance().volumeManager();
0066   VolumeID id  = volMgr.volumeID(spotH.touchable());
0067   FieldID  key = m_key->value(id);
0068   if ( m_collection->key_min <= key && m_collection->key_max >= key )
0069     return true;
0070   return false;
0071 }