OpHitFinder_module.cc
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 2; -*-
2 // Gleb Sinev, Duke, 2016
3 //
4 // This module finds periods of time-localized activity
5 // on each channel of the optical system and creates OpHits.
6 //
7 // Split from OpFlashFinder_module.cc
8 // by Ben Jones, MIT, 2013
9 //
10 
11 // LArSoft includes
23 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
32 
33 // Framework includes
39 #include "fhiclcpp/ParameterSet.h"
40 
41 // ROOT includes
42 
43 // C++ Includes
44 #include <map>
45 #include <memory>
46 #include <string>
47 
48 namespace opdet {
49 
50  class OpHitFinder : public art::EDProducer {
51  public:
52  // Standard constructor and destructor for an ART module.
53  explicit OpHitFinder(const fhicl::ParameterSet&);
54  virtual ~OpHitFinder();
55 
56  // The producer routine, called once per event.
57  void produce(art::Event&);
58 
59  private:
60  std::map<int, int> GetChannelMap();
61  std::vector<double> GetSPEScales();
62  std::vector<double> GetSPEShifts();
63 
64  // The parameters we'll read from the .fcl file.
65  std::string fInputModule; // Input tag for OpDetWaveform collection
67  std::vector<std::string> fInputLabels;
68  std::set<unsigned int> fChannelMasks;
69 
73 
74  Float_t fHitThreshold;
75  unsigned int fMaxOpChannel;
77 
78  calib::IPhotonCalibrator const* fCalib = nullptr;
79  };
80 
81 }
82 
83 namespace opdet {
85 }
86 
87 namespace opdet {
88 
89  //----------------------------------------------------------------------------
90  // Constructor
92  {
93  // Indicate that the Input Module comes from .fcl
94  fInputModule = pset.get<std::string>("InputModule");
95  fGenModule = pset.get<std::string>("GenModule");
96  fInputLabels = pset.get<std::vector<std::string>>("InputLabels");
97  fUseStartTime = pset.get<bool>("UseStartTime", false);
98 
99  for (auto const& ch :
100  pset.get<std::vector<unsigned int>>("ChannelMasks", std::vector<unsigned int>()))
101  fChannelMasks.insert(ch);
102 
103  fHitThreshold = pset.get<float>("HitThreshold");
104  bool useCalibrator = pset.get<bool>("UseCalibrator", false);
105 
106  auto const& geometry(*lar::providerFrom<geo::Geometry>());
107  fMaxOpChannel = geometry.MaxOpChannel();
108 
109  if (useCalibrator) {
110  // If useCalibrator, get it from ART
111  fCalib = lar::providerFrom<calib::IPhotonCalibratorService>();
112  }
113  else {
114  // If not useCalibrator, make an internal one based
115  // on fhicl settings to hit finder.
116  bool areaToPE = pset.get<bool>("AreaToPE");
117  float SPEArea = pset.get<float>("SPEArea");
118  float SPEShift = pset.get<float>("SPEShift", 0.);
119 
120  // Reproduce behavior from GetSPEScales()
121  if (!areaToPE) SPEArea = 20;
122 
123  // Delete and replace if we are reconfiguring
124  if (fCalib) { delete fCalib; }
125 
126  fCalib = new calib::PhotonCalibratorStandard(SPEArea, SPEShift, areaToPE);
127  }
128 
129  // Initialize the hit finder algorithm
130  auto const hit_alg_pset = pset.get<fhicl::ParameterSet>("HitAlgoPset");
131  std::string threshAlgName = hit_alg_pset.get<std::string>("Name");
132  if (threshAlgName == "Threshold")
133  fThreshAlg = new pmtana::AlgoThreshold(hit_alg_pset);
134  else if (threshAlgName == "SiPM")
135  fThreshAlg = new pmtana::AlgoSiPM(hit_alg_pset);
136  else if (threshAlgName == "SlidingWindow")
137  fThreshAlg = new pmtana::AlgoSlidingWindow(hit_alg_pset);
138  else if (threshAlgName == "FixedWindow")
139  fThreshAlg = new pmtana::AlgoFixedWindow(hit_alg_pset);
140  else if (threshAlgName == "CFD")
141  fThreshAlg = new pmtana::AlgoCFD(hit_alg_pset);
142  else
144  << "Cannot find implementation for " << threshAlgName << " algorithm.\n";
145 
146  auto const ped_alg_pset = pset.get<fhicl::ParameterSet>("PedAlgoPset");
147  std::string pedAlgName = ped_alg_pset.get<std::string>("Name");
148  if (pedAlgName == "Edges")
149  fPedAlg = new pmtana::PedAlgoEdges(ped_alg_pset);
150  else if (pedAlgName == "RollingMean")
151  fPedAlg = new pmtana::PedAlgoRollingMean(ped_alg_pset);
152  else if (pedAlgName == "UB")
153  fPedAlg = new pmtana::PedAlgoUB(ped_alg_pset);
154  else
156  << "Cannot find implementation for " << pedAlgName << " algorithm.\n";
157 
158  produces<std::vector<recob::OpHit>>();
159 
162  }
163 
164  //----------------------------------------------------------------------------
165  // Destructor
167  {
168 
169  delete fThreshAlg;
170  delete fPedAlg;
171  }
172 
173  //----------------------------------------------------------------------------
174  void
176  {
177 
178  // These is the storage pointer we will put in the event
179  std::unique_ptr<std::vector<recob::OpHit>> HitPtr(new std::vector<recob::OpHit>);
180 
181  std::vector<const sim::BeamGateInfo*> beamGateArray;
182  try {
183  evt.getView(fGenModule, beamGateArray);
184  }
185  catch (art::Exception const& err) {
186  if (err.categoryCode() != art::errors::ProductNotFound) throw;
187  }
188 
189  auto const& geometry(*lar::providerFrom<geo::Geometry>());
190  auto const clock_data =
192  auto const& calibrator(*fCalib);
193  //
194  // Get the pulses from the event
195  //
196 
197  // Load pulses into WaveformVector
198  if (fChannelMasks.empty() && fInputLabels.size() < 2) {
200  if (fInputLabels.empty())
201  evt.getByLabel(fInputModule, wfHandle);
202  else
203  evt.getByLabel(fInputModule, fInputLabels.front(), wfHandle);
204  assert(wfHandle.isValid());
205  RunHitFinder(*wfHandle,
206  *HitPtr,
208  *fThreshAlg,
209  geometry,
211  clock_data,
212  calibrator,
213  fUseStartTime);
214  }
215  else {
216 
217  // Reserve a large enough array
218  int totalsize = 0;
219  for (auto label : fInputLabels) {
221  evt.getByLabel(fInputModule, label, wfHandle);
222  if (!wfHandle.isValid()) continue; // Skip non-existent collections
223  totalsize += wfHandle->size();
224  }
225 
226  std::vector<raw::OpDetWaveform> WaveformVector;
227  WaveformVector.reserve(totalsize);
228 
229  for (auto label : fInputLabels) {
231  evt.getByLabel(fInputModule, label, wfHandle);
232  if (!wfHandle.isValid()) continue; // Skip non-existent collections
233 
234  //WaveformVector.insert(WaveformVector.end(),
235  // wfHandle->begin(), wfHandle->end());
236  for (auto const& wf : *wfHandle) {
237  if (fChannelMasks.find(wf.ChannelNumber()) != fChannelMasks.end()) continue;
238  WaveformVector.push_back(wf);
239  }
240  }
241 
242  RunHitFinder(WaveformVector,
243  *HitPtr,
245  *fThreshAlg,
246  geometry,
248  clock_data,
249  calibrator,
250  fUseStartTime);
251  }
252  // Store results into the event
253  evt.put(std::move(HitPtr));
254  }
255 
256 } // namespace opdet
unsigned int fMaxOpChannel
std::string string
Definition: nybbler.cc:12
std::map< int, int > GetChannelMap()
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
void AddRecoAlgo(pmtana::PMTPulseRecoBase *algo, PMTPedestalBase *ped_algo=nullptr)
A method to set pulse reconstruction algorithm.
OpHitFinder(const fhicl::ParameterSet &)
std::set< unsigned int > fChannelMasks
art framework interface to geometry description
bool isValid() const noexcept
Definition: Handle.h:191
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
Class definition file of PedAlgoRollingMean.
def move(depos, offset)
Definition: depos.py:107
Class definition file of AlgoCFD.
std::vector< double > GetSPEShifts()
Class definition file of PedAlgoUB.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
void err(const char *fmt,...)
Definition: message.cpp:226
pmtana::PMTPulseRecoBase * fThreshAlg
void produce(art::Event &)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Class definition file of AlgoFixedWindow.
calib::IPhotonCalibrator const * fCalib
void RunHitFinder(std::vector< raw::OpDetWaveform > const &opDetWaveformVector, std::vector< recob::OpHit > &hitVector, pmtana::PulseRecoManager const &pulseRecoMgr, pmtana::PMTPulseRecoBase const &threshAlg, geo::GeometryCore const &geometry, float hitThreshold, detinfo::DetectorClocksData const &clocksData, calib::IPhotonCalibrator const &calibrator, bool use_start_time)
Definition: OpHitAlg.cxx:29
Class definition file of AlgoSlidingWindow.
Class definition file of AlgoThreshold.
pmtana::PulseRecoManager fPulseRecoMgr
void SetDefaultPedAlgo(pmtana::PMTPedestalBase *algo)
A method to set a choice of pedestal estimation method.
std::vector< double > GetSPEScales()
Class definition file of PMTPulseRecoBase.
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:500
Class definition file of PedAlgoEdges.
TCEvent evt
Definition: DataStructs.cxx:7
std::vector< std::string > fInputLabels
pmtana::PMTPedestalBase * fPedAlg
Class definition file of PulseRecoManager.