All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMTFlashTriggerFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: PMTFlashTriggerFilter
3 // Plugin Type: filter (art v3_03_01)
4 // File: PMTFlashTriggerFilter_module.cc
5 //
6 // Generated at Fri Apr 3 11:02:06 2020 by Gray Putnam using cetskelgen
7 // from cetlib version v3_08_00.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDFilter.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 
20 #include <memory>
22 
23 #include <memory>
24 #include <iostream>
25 #include <vector>
26 
27 namespace sbn {
28  class PMTFlashTriggerFilter;
29 }
30 
31 
32 class sbn::PMTFlashTriggerFilter : public art::EDFilter {
33 public:
34  explicit PMTFlashTriggerFilter(fhicl::ParameterSet const& p);
35  // The compiler-generated destructor is fine for non-base
36  // classes without bare pointers or other resource use.
37 
38  // Plugins should not be copied or assigned.
43 
44  // Required functions.
45  bool filter(art::Event& e) override;
46 
47 private:
48 
53 
54  bool HasTrigger(const std::vector<FlashTriggerPrimitive> &primitives, int threshold, unsigned n_above_threshold);
55 };
56 
57 
59  : EDFilter{p},
60  fFlashTriggerPrimitiveLabel(p.get<std::string>("FlashTriggerPrimitiveLabel")),
61  fNPMTAboveThreshold(p.get<unsigned>("NPMTAboveThreshold")),
62  fPMTTriggerThreshold(p.get<int>("PMTTriggerThreshold")),
63  fStoreDataProduct(p.get<bool>("StoreDataProduct", false))
64  // More initializers here.
65 {
66 
67  if (fStoreDataProduct) produces<bool>();
68 }
69 
71 {
72  art::Handle<std::vector<sbn::FlashTriggerPrimitive>> flashtrig_handle;
73  e.getByLabel(fFlashTriggerPrimitiveLabel, flashtrig_handle);
74 
75  bool ret = false;
76  if (flashtrig_handle.isValid()) {
77  ret = HasTrigger(*flashtrig_handle, fPMTTriggerThreshold, fNPMTAboveThreshold);
78  }
79 
80  if (fStoreDataProduct) {
81  std::unique_ptr<bool> store(new bool);
82  *store = ret;
83  e.put(std::move(store));
84  return true;
85  }
86  return ret;
87 }
88 
89 bool sbn::PMTFlashTriggerFilter::HasTrigger(const std::vector<sbn::FlashTriggerPrimitive> &primitives, int threshold, unsigned n_above_threshold) {
90  if (n_above_threshold == 0) return true;
91 
92  std::map<int, std::vector<unsigned>> above_threshold;
93 
94  for (const sbn::FlashTriggerPrimitive &primitive: primitives) {
95  for (const sbn::FlashTriggerPrimitive::Trig &trig: primitive.triggers) {
96  if (trig.adc <= threshold) {
97  above_threshold[trig.tdc].push_back(primitive.channel);
98  }
99  }
100  }
101 
102  for (auto const &pair: above_threshold) {
103  if (pair.second.size() >= n_above_threshold) {
104  return true;
105  }
106  }
107 
108  return false;
109 }
110 
111 
112 DEFINE_ART_MODULE(sbn::PMTFlashTriggerFilter)
process_name opflash opflashana store
pdgs p
Definition: selectors.fcl:22
bool filter(art::Event &e) override
PMTFlashTriggerFilter(fhicl::ParameterSet const &p)
bool HasTrigger(const std::vector< FlashTriggerPrimitive > &primitives, int threshold, unsigned n_above_threshold)
PMTFlashTriggerFilter & operator=(PMTFlashTriggerFilter const &)=delete
do i e
bool HasTrigger(const std::vector< FlashTriggerPrimitive > &primitives, int threshold, unsigned n_above_threshold)
Definition: PMTTrigger.cc:65