All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMTFlashTriggerMaker_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: PMTFlashTriggerMaker
3 // Plugin Type: producer (art v3_02_06)
4 // File: PMTFlashTriggerMaker_module.cc
5 //
6 // Generated at Wed Feb 19 17:38:21 2020 by Gray Putnam using cetskelgen
7 // from cetlib version v3_07_02.
8 ////////////////////////////////////////////////////////////////////////
9 
10 
11 #include "sbncode/OpDet/PDMapAlg.h"
13 
19 
20 #include "art/Framework/Core/EDProducer.h"
21 #include "art/Framework/Core/ModuleMacros.h"
22 #include "art/Framework/Principal/Event.h"
23 #include "art/Framework/Principal/Handle.h"
24 #include "art/Framework/Principal/Run.h"
25 #include "art/Framework/Principal/SubRun.h"
26 #include "art/Utilities/make_tool.h"
27 
28 #include "canvas/Utilities/InputTag.h"
29 #include "fhiclcpp/ParameterSet.h"
30 #include "messagefacility/MessageLogger/MessageLogger.h"
31 
32 #include <memory>
33 #include <iostream>
34 #include <vector>
35 
36 
37 namespace sbn {
38  class PMTFlashTriggerMaker;
39 }
40 
41 class sbn::PMTFlashTriggerMaker : public art::EDProducer {
42 public:
43  explicit PMTFlashTriggerMaker(fhicl::ParameterSet const& p);
44  // The compiler-generated destructor is fine for non-base
45  // classes without bare pointers or other resource use.
46 
47  // Plugins should not be copied or assigned.
52 
53  // Required functions.
54  void produce(art::Event& e) override;
55 
56 private:
57  art::InputTag fWaveformLabel;
58  std::string fExperiment;
59  std::pair<double, double> fTriggerWindow;
62 
63  std::unique_ptr<opdet::PDMapAlg> fPDMapAlgPtr;
64 
65  std::vector<sbn::FlashTriggerPrimitive>
66  TriggerPrimitives(const std::vector<raw::OpDetWaveform> &waveforms,
67  double tick_period,
68  std::pair<double, double> &window,
69  int thresh);
70 
71 };
72 
74  : EDProducer{p},
75  fWaveformLabel(p.get<std::string>("WaveformLabel")),
76  fExperiment(p.get<std::string>("Experiment")),
77  fTriggerWindow({p.get<float>("TriggerStart"), p.get<float>("TriggerEnd")}),
78  fTriggerThreshold(p.get<int>("TriggerThreshold")),
79  fOffsetTriggerTime(p.get<bool>("OffsetTriggerTime"))
80 {
81  produces< std::vector<sbn::FlashTriggerPrimitive> >();
82 
83  fPDMapAlgPtr = art::make_tool<opdet::PDMapAlg>(p.get<fhicl::ParameterSet>("PDMapAlg"));
84 
85 }
86 
88 {
89  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
90 
91  std::unique_ptr<std::vector<sbn::FlashTriggerPrimitive>> trigs(new std::vector<sbn::FlashTriggerPrimitive>);
92 
93  art::Handle<std::vector<raw::OpDetWaveform>> waveform_handle;
94  e.getByLabel(fWaveformLabel, waveform_handle);
95 
96  std::pair<double, double> window = fTriggerWindow;
97  // don't apply offset in constructor in case time gets overwritten on input file open
98  if (fOffsetTriggerTime) {
99  float offset = clock_data.TriggerTime();
100  window.first += offset;
101  window.second += offset;
102  }
103 
104  if (waveform_handle.isValid()) {
105  const std::vector<raw::OpDetWaveform> &waveforms = *waveform_handle;
106  double tick_period = clock_data.OpticalClock().TickPeriod();
107  //bool is_sbnd = fExperiment == "SBND"; //replace with PDMapAlgPtr
108 
109  *trigs = TriggerPrimitives(waveforms, tick_period, window, fTriggerThreshold);
110  }
111 
112  e.put(std::move(trigs));
113 }
114 
115 std::vector<sbn::FlashTriggerPrimitive> sbn::PMTFlashTriggerMaker::TriggerPrimitives(const std::vector<raw::OpDetWaveform> &waveforms,
116  double tick_period,
117  std::pair<double, double> &window,
118  int thresh) {
119  std::vector<sbn::FlashTriggerPrimitive> ret;
120 
121  for (const raw::OpDetWaveform &wvf: waveforms) {
122  // check if this is a PMT
123  bool is_pmt = fPDMapAlgPtr->pdType(wvf.ChannelNumber()) == "pmt";
124 
125  if (!is_pmt) continue;
126 
127  // look for any overlap with the enable window
128  double waveform_start = wvf.TimeStamp();
129  int waveform_index_start = std::max((int)((window.first - waveform_start) / tick_period), 0);
130  int waveform_index_end = std::min((int)((window.second - waveform_start) / tick_period), (int) wvf.size());
131 
132  if (waveform_index_start < waveform_index_end) {
134  prim.channel = wvf.ChannelNumber();
135  for (int i = waveform_index_start; i < waveform_index_end; i++) {
136  if (wvf[i] <= thresh) { // PMT waveforms go down
137  FlashTriggerPrimitive::Trig this_trig {wvf[i], i + (int)((waveform_start - window.first) / tick_period)};
138  prim.triggers.push_back(this_trig);
139  }
140  }
141  ret.push_back(prim);
142  }
143  }
144  return ret;
145 }
146 
147 DEFINE_ART_MODULE(sbn::PMTFlashTriggerMaker)
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
Definition: CORSIKAGen.fcl:7
PMTFlashTriggerMaker(fhicl::ParameterSet const &p)
Utilities related to art service access.
pdgs p
Definition: selectors.fcl:22
std::vector< FlashTriggerPrimitive > TriggerPrimitives(const std::vector< raw::OpDetWaveform > &waveforms, double tick_period, std::pair< double, double > &window, int thresh, bool is_sbnd)
Definition: PMTTrigger.cc:7
std::vector< sbn::FlashTriggerPrimitive > TriggerPrimitives(const std::vector< raw::OpDetWaveform > &waveforms, double tick_period, std::pair< double, double > &window, int thresh)
This is the interface class for a tool to handle PD mapping in SBN detectors, used for flash matching...
fTriggerThreshold(p.get< int >("TriggerThreshold"))
std::pair< double, double > fTriggerWindow
void produce(art::Event &e) override
std::unique_ptr< opdet::PDMapAlg > fPDMapAlgPtr
PMTFlashTriggerMaker & operator=(PMTFlashTriggerMaker const &)=delete
do i e
int tick_period
Definition: constants.py:3