All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SmallClusterFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // \file SmallClusterFilter_module.cc
4 //
5 // \author corey.adams@yale.edu
6 //
7 // \brief Filter out events and only keep those with a few hits.
8 /*
9  This filter is meant to search for radioactive decay products in "empty" frames.
10 
11  It will run on microboone, I claim, though it's really meant for argoneut.
12 
13  The algorithm is quite simple, it just makes a cut on the total number of hits (all
14  planes combined) and also a hit on the number of hits in each individual plane. Both
15  of those numbers are parameters from the .fcl file filters.fcl.
16  -Corey
17 */
18 //
19 //
20 ///////////////////////////////////////////////////////////////////////
21 
22 // include the proper bit of the framework
23 #include "art/Framework/Core/EDFilter.h"
24 #include "art/Framework/Core/ModuleMacros.h"
25 #include "art/Framework/Principal/Event.h"
26 #include "art/Framework/Principal/Handle.h"
27 #include "art/Framework/Services/Registry/ServiceHandle.h"
28 #include "messagefacility/MessageLogger/MessageLogger.h"
29 
33 
34 namespace cluster {
35 
36  class SmallClusterFilter : public art::EDFilter {
37  public:
38  explicit SmallClusterFilter(fhicl::ParameterSet const& pset);
39 
40  private:
41  bool filter(art::Event& evt) override;
42 
43  std::string fHitFinderModuleLabel; ///< label of module making hits
44  std::vector<std::size_t> fMaxHitsByPlane; ///< maximum hits on each plane
45  std::size_t fMaxTotalHits; ///< maximum number of hits allowed
46  std::size_t fNPlanes; ///< number of planes
47  };
48 
49 }
50 
51 cluster::SmallClusterFilter::SmallClusterFilter(fhicl::ParameterSet const& pset)
52  : EDFilter{pset}
53  , fHitFinderModuleLabel{pset.get<std::string>("HitFinderModuleLabel")}
54  , fMaxHitsByPlane{pset.get<std::vector<std::size_t>>("MaxHitsByPlane")}
55  , fMaxTotalHits{pset.get<std::size_t>("MaxTotalHits")}
56  , fNPlanes{art::ServiceHandle<geo::Geometry const>()->Nplanes()}
57 {
58  if (size(fMaxHitsByPlane) != fNPlanes) {
59  throw art::Exception{art::errors::Configuration}
60  << "Mismatch in number of planes specified in 'MaxHitsByPlane' (" << size(fMaxHitsByPlane)
61  << ") and the number of planes (" << fNPlanes << ")\n";
62  }
63 }
64 
65 bool
67 {
68  auto const& hits = *evt.getValidHandle<std::vector<recob::Hit>>(fHitFinderModuleLabel);
69 
70  mf::LogVerbatim("SmallClusterFilter")
71  << " ++++ Hitsreceived received " << size(hits) << " +++++ ";
72 
73  if (empty(hits)) {
74  mf::LogWarning("SmallClusterFilter") << " no hits received! exiting ";
75  return false;
76  }
77 
78  if (size(hits) > fMaxTotalHits) {
79  mf::LogWarning("SmallClusterFinder") << "Not an empty event, exiting.";
80  return false;
81  }
82 
83  bool collFound = false;
84 
85  std::map<unsigned int, std::size_t> hitsPerPlane;
86 
87  for (auto const& hit : hits) {
88 
89  // Skip crazy hits:
90  if (hit.Integral() > 500) continue;
91 
92  ++hitsPerPlane[hit.WireID().Plane];
93 
94  if (hit.SignalType() == geo::kCollection) collFound = true;
95 
96  }
97 
98  for (unsigned int i = 0; i < fNPlanes; i++) {
99  if (hitsPerPlane[i] > fMaxHitsByPlane[i]) return false;
100  }
101 
102  //check that there is at least 1 hit on collection:
103  return collFound;
104 }
105 
106 DEFINE_ART_MODULE(cluster::SmallClusterFilter)
process_name cluster
Definition: cheaterreco.fcl:51
Declaration of signal hit object.
std::vector< std::size_t > fMaxHitsByPlane
maximum hits on each plane
std::string fHitFinderModuleLabel
label of module making hits
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
process_name hit
Definition: cheaterreco.fcl:51
std::size_t fMaxTotalHits
maximum number of hits allowed
bool filter(art::Event &evt) override
std::size_t fNPlanes
number of planes
TCEvent evt
Definition: DataStructs.cxx:8
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
art framework interface to geometry description
SmallClusterFilter(fhicl::ParameterSet const &pset)
Signal from collection planes.
Definition: geo_types.h:146