All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FilterNoMCParticles_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file FilterNoMCParticles_module.cc
3 /// \brief Simple EDFilter filter events with no MCParticles
4 ///
5 /// \author echurch@fnal.gov
6 ////////////////////////////////////////////////////////////////////////
7 
8 /// Framework includes
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Core/SharedFilter.h"
11 #include "art/Framework/Principal/Event.h"
12 #include "art/Framework/Principal/Handle.h"
13 #include "fhiclcpp/ParameterSet.h"
14 
15 // LArSoft Includes
16 #include "nusimdata/SimulationBase/MCParticle.h"
17 
18 #include <vector>
19 
20 /// Geant4 interface
21 namespace simfilter {
22 
23  class FilterNoMCParticles : public art::SharedFilter {
24  public:
25  explicit FilterNoMCParticles(fhicl::ParameterSet const& pset,
26  art::ProcessingFrame const&);
27 
28  private:
29  bool filter(art::Event&, art::ProcessingFrame const&) override;
30  std::string const fLArG4ModuleLabel;
31  };
32 
33 } // namespace simfilter
34 
35 namespace simfilter {
36 
37  //-----------------------------------------------------------------------
38  // Constructor
39  FilterNoMCParticles::FilterNoMCParticles(fhicl::ParameterSet const& pset,
40  art::ProcessingFrame const&)
41  : SharedFilter{pset}
42  , fLArG4ModuleLabel{pset.get<std::string>("LArG4ModuleLabel", "NoLabel")}
43  {
44  async<art::InEvent>();
45  }
46 
47  //-----------------------------------------------------------------------
48  bool
49  FilterNoMCParticles::filter(art::Event& evt, art::ProcessingFrame const&)
50  {
51  auto const& mcps =
52  *evt.getValidHandle<std::vector<simb::MCParticle>>(fLArG4ModuleLabel);
53  return not mcps.empty();
54  }
55 
56 } // namespace simfilter
57 
58 DEFINE_ART_MODULE(simfilter::FilterNoMCParticles)
bool filter(art::Event &, art::ProcessingFrame const &) override
FilterNoMCParticles(fhicl::ParameterSet const &pset, art::ProcessingFrame const &)
TCEvent evt
Definition: DataStructs.cxx:8