LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
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
18 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
27 
28 // Framework includes
35 #include "fhiclcpp/ParameterSet.h"
37 
38 // ROOT includes
39 
40 // C++ Includes
41 #include <map>
42 #include <memory>
43 #include <string>
44 
45 namespace {
46 
80  fhicl::ParameterSet makeAlgoToolConfig(fhicl::ParameterSet const& baseConfig,
81  std::string const& configKey,
82  std::string const& algoClassPrefix = "",
83  std::string const& algoNameKey = "Name")
84  {
85 
86  fhicl::ParameterSet toolConfig;
87 
88  // add algo configuration
89  fhicl::ParameterSet algoConfig = baseConfig.get<fhicl::ParameterSet>(configKey);
90 
91  if (auto toolType = algoConfig.get_if_present<std::string>("tool_type")) {
92  toolConfig.put("tool_type", *toolType);
93  algoConfig.erase("tool_type");
94  }
95  else if (auto algoName = algoConfig.get_if_present<std::string>(algoNameKey)) {
96  toolConfig.put("tool_type", algoClassPrefix + *algoName + "Maker");
97  // we leave the algorithm Name in its configuration for compatibility
98  }
99  toolConfig.put(configKey, std::move(algoConfig));
100 
101  return toolConfig;
102  } // makeAlgoToolConfig()
103 
114  fhicl::ParameterSet makePedAlgoToolConfig(fhicl::ParameterSet const& baseConfig)
115  {
116  return makeAlgoToolConfig(baseConfig, "PedAlgoPset", "PedAlgo");
117  }
118 
140  fhicl::ParameterSet makeHitAlgoToolConfig(fhicl::ParameterSet const& baseConfig)
141  {
142  fhicl::ParameterSet toolConfig = makeAlgoToolConfig(baseConfig, "HitAlgoPset", "Algo");
143 
144  // add rise time calculator configuration ("no configuration" is ok)
145  if (auto riseCalcCfg = baseConfig.get_if_present<fhicl::ParameterSet>("RiseTimeCalculator")) {
146  toolConfig.put("RiseTimeCalculator", std::move(*riseCalcCfg));
147  }
148 
149  return toolConfig;
150  } // makeHitAlgoToolConfig()
151 
152 }
153 
154 namespace opdet {
155 
156  class OpHitFinder : public art::EDProducer {
157  public:
158  // Standard constructor and destructor for an ART module.
159  explicit OpHitFinder(const fhicl::ParameterSet&);
160 
161  // The producer routine, called once per event.
162  void produce(art::Event&);
163 
164  private:
165  std::map<int, int> GetChannelMap();
166  std::vector<double> GetSPEScales();
167  std::vector<double> GetSPEShifts();
168 
169  // The parameters we'll read from the .fcl file.
170  std::string fInputModule; // Input tag for OpDetWaveform collection
171  std::string fGenModule;
172  std::vector<std::string> fInputLabels;
173  std::set<unsigned int> fChannelMasks;
174 
176  std::unique_ptr<pmtana::PMTPulseRecoBase> const fThreshAlg;
177  std::unique_ptr<pmtana::PMTPedestalBase> const fPedAlg;
178 
180  unsigned int fMaxOpChannel;
182 
184  };
185 
186 }
187 
189 
190 namespace opdet {
191 
192  //----------------------------------------------------------------------------
193  // Constructor
195  : EDProducer{pset}
196  , fPulseRecoMgr()
197  , fThreshAlg{art::make_tool<opdet::IHitAlgoMakerTool>(makeHitAlgoToolConfig(pset))->makeAlgo()}
198  , fPedAlg{art::make_tool<opdet::IPedAlgoMakerTool>(makePedAlgoToolConfig(pset))->makeAlgo()}
199  {
200  // Indicate that the Input Module comes from .fcl
201  fInputModule = pset.get<std::string>("InputModule");
202  fGenModule = pset.get<std::string>("GenModule");
203  fInputLabels = pset.get<std::vector<std::string>>("InputLabels");
204  fUseStartTime = pset.get<bool>("UseStartTime", false);
205 
206  for (auto const& ch :
207  pset.get<std::vector<unsigned int>>("ChannelMasks", std::vector<unsigned int>()))
208  fChannelMasks.insert(ch);
209 
210  fHitThreshold = pset.get<float>("HitThreshold");
211  bool useCalibrator = pset.get<bool>("UseCalibrator", false);
212 
214 
215  if (useCalibrator) {
216  // If useCalibrator, get it from ART
217  fCalib = lar::providerFrom<calib::IPhotonCalibratorService>();
218  }
219  else {
220  // If not useCalibrator, make an internal one based
221  // on fhicl settings to hit finder.
222  bool areaToPE = pset.get<bool>("AreaToPE");
223  float SPEArea = pset.get<float>("SPEArea");
224  float SPEShift = pset.get<float>("SPEShift", 0.);
225 
226  // Reproduce behavior from GetSPEScales()
227  if (!areaToPE) SPEArea = 20;
228 
229  // Delete and replace if we are reconfiguring
230  if (fCalib) { delete fCalib; }
231 
232  fCalib = new calib::PhotonCalibratorStandard(SPEArea, SPEShift, areaToPE);
233  }
234 
235  produces<std::vector<recob::OpHit>>();
236 
239 
240  // show the algorithm selection on screen
241  mf::LogInfo{"OpHitFinder"} << "Pulse finder algorithm: '" << fThreshAlg->Name() << "'"
242  << "\nPedestal algorithm: '" << fPedAlg->Name() << "'";
243  }
244 
245  //----------------------------------------------------------------------------
247  {
248  // These is the storage pointer we will put in the event
249  std::unique_ptr<std::vector<recob::OpHit>> HitPtr(new std::vector<recob::OpHit>);
250 
251  std::vector<const sim::BeamGateInfo*> beamGateArray;
252  try {
253  evt.getView(fGenModule, beamGateArray);
254  }
255  catch (art::Exception const& err) {
256  if (err.categoryCode() != art::errors::ProductNotFound) throw;
257  }
258 
259  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
260  auto const clock_data =
262  auto const& calibrator(*fCalib);
263  //
264  // Get the pulses from the event
265  //
266 
267  // Load pulses into WaveformVector
268  if (fChannelMasks.empty() && fInputLabels.size() < 2) {
270  if (fInputLabels.empty())
271  evt.getByLabel(fInputModule, wfHandle);
272  else
273  evt.getByLabel(fInputModule, fInputLabels.front(), wfHandle);
274  assert(wfHandle.isValid());
275  RunHitFinder(*wfHandle,
276  *HitPtr,
278  *fThreshAlg,
279  wireReadoutGeom,
281  clock_data,
282  calibrator,
283  fUseStartTime);
284  }
285  else {
286 
287  // Reserve a large enough array
288  int totalsize = 0;
289  for (auto label : fInputLabels) {
291  evt.getByLabel(fInputModule, label, wfHandle);
292  if (!wfHandle.isValid()) continue; // Skip non-existent collections
293  totalsize += wfHandle->size();
294  }
295 
296  std::vector<raw::OpDetWaveform> WaveformVector;
297  WaveformVector.reserve(totalsize);
298 
299  for (auto label : fInputLabels) {
301  evt.getByLabel(fInputModule, label, wfHandle);
302  if (!wfHandle.isValid()) continue; // Skip non-existent collections
303 
304  for (auto const& wf : *wfHandle) {
305  if (fChannelMasks.find(wf.ChannelNumber()) != fChannelMasks.end()) continue;
306  WaveformVector.push_back(wf);
307  }
308  }
309 
310  RunHitFinder(WaveformVector,
311  *HitPtr,
313  *fThreshAlg,
314  wireReadoutGeom,
316  clock_data,
317  calibrator,
318  fUseStartTime);
319  }
320  // Store results into the event
321  evt.put(std::move(HitPtr));
322  }
323 
324 } // namespace opdet
Utilities related to art service access.
Tool interface for creating a pedestal estimator algorithm.
std::unique_ptr< pmtana::PMTPedestalBase > const fPedAlg
std::map< int, int > GetChannelMap()
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
void AddRecoAlgo(pmtana::PMTPulseRecoBase *algo, PMTPedestalBase *ped_algo=nullptr)
A method to set pulse reconstruction algorithm.
OpHitFinder(const fhicl::ParameterSet &)
Class definition file of PMTPedestalBase.
std::set< unsigned int > fChannelMasks
bool isValid() const noexcept
Definition: Handle.h:203
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
void RunHitFinder(std::vector< raw::OpDetWaveform > const &opDetWaveformVector, std::vector< recob::OpHit > &hitVector, pmtana::PulseRecoManager const &pulseRecoMgr, pmtana::PMTPulseRecoBase const &threshAlg, geo::WireReadoutGeom const &wireReadoutGeom, float hitThreshold, detinfo::DetectorClocksData const &clocksData, calib::IPhotonCalibrator const &calibrator, bool use_start_time)
Definition: OpHitAlg.cxx:29
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
T get(std::string const &key) const
Definition: ParameterSet.h:314
std::vector< double > GetSPEShifts()
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
void produce(art::Event &)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
calib::IPhotonCalibrator const * fCalib
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Tool interface for creating a hit finder algorithm.
pmtana::PulseRecoManager fPulseRecoMgr
void SetDefaultPedAlgo(pmtana::PMTPedestalBase *algo)
A method to set a choice of pedestal estimation method.
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:267
std::vector< double > GetSPEScales()
bool erase(std::string const &key)
Class definition file of PMTPulseRecoBase.
TCEvent evt
Definition: DataStructs.cxx:8
std::vector< std::string > fInputLabels
void put(std::string const &key)
std::unique_ptr< pmtana::PMTPulseRecoBase > const fThreshAlg
Class definition file of PulseRecoManager.