All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROIConverter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // ROIConvert class - An ROI finding module for complete deconvolved waveforms
4 //
5 // usher@slac.stanford.edu
6 //
7 ////////////////////////////////////////////////////////////////////////
8 
9 // C/C++ standard libraries
10 #include <string>
11 #include <vector>
12 #include <utility> // std::pair<>
13 #include <memory> // std::unique_ptr<>
14 
15 // framework libraries
16 #include "fhiclcpp/ParameterSet.h"
17 #include "messagefacility/MessageLogger/MessageLogger.h"
18 #include "art/Framework/Core/ModuleMacros.h"
19 #include "art/Framework/Core/EDProducer.h"
20 #include "art/Framework/Principal/Event.h"
21 #include "art/Framework/Principal/Handle.h"
22 #include "art/Framework/Services/Registry/ServiceHandle.h"
23 #include "canvas/Utilities/Exception.h"
24 #include "canvas/Utilities/InputTag.h"
25 
26 // LArSoft libraries
27 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
29 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
33 
35 
36 ///creation of calibrated signals on wires
37 namespace caldata {
38 
39 class ROIConvert : public art::EDProducer
40 {
41 public:
42 // create calibrated signals on wires. this class runs
43 // an fft to remove the electronics shaping.
44  explicit ROIConvert(fhicl::ParameterSet const& pset);
45  void produce(art::Event& evt);
46  void beginJob();
47  void endJob();
48  void reconfigure(fhicl::ParameterSet const& p);
49 private:
50 
51  std::vector<art::InputTag> fWireModuleLabelVec; ///< vector of modules that made digits
52  std::vector<std::string> fOutInstanceLabelVec; ///< The output instance labels to apply
53  bool fDiagnosticOutput; ///< secret diagnostics flag
54  size_t fEventCount; ///< count of event processed
55 
56  const geo::GeometryCore* fGeometry = lar::providerFrom<geo::Geometry>();
57 
58 }; // class ROIConvert
59 
60 DEFINE_ART_MODULE(ROIConvert)
61 
62 //-------------------------------------------------
63 ROIConvert::ROIConvert(fhicl::ParameterSet const& pset) : EDProducer{pset}
64 {
65  this->reconfigure(pset);
66 
67  for(const auto& wireLabel : fOutInstanceLabelVec)
68  {
69  produces<std::vector<recob::Wire>>(wireLabel);
70  }
71 }
72 
73 //////////////////////////////////////////////////////
74 void ROIConvert::reconfigure(fhicl::ParameterSet const& pset)
75 {
76  // Recover the parameters
77  fWireModuleLabelVec = pset.get<std::vector<art::InputTag>>("WireModuleLabelVec", std::vector<art::InputTag>()={"decon1droi"});
78  fOutInstanceLabelVec = pset.get<std::vector<std::string>> ("OutInstanceLabelVec", {"PHYSCRATEDATA"});
79  fDiagnosticOutput = pset.get< bool >("DaignosticOutput", false);
80 
81  if (fWireModuleLabelVec.size() != fWireModuleLabelVec.size())
82  {
83  throw art::Exception(art::errors::Configuration) << " Configured " << fOutInstanceLabelVec.size()
84  << " instance names (`OutInstanceLabelVec`) for " << fWireModuleLabelVec.size()
85  << " input products (`WireModuleLabelVec`)\n";
86  }
87 
88  return;
89 }
90 
91 //-------------------------------------------------
93 {
94  fEventCount = 0;
95 } // beginJob
96 
97 //////////////////////////////////////////////////////
99 {
100 }
101 
102 //////////////////////////////////////////////////////
103 void ROIConvert::produce(art::Event& evt)
104 {
105  // We need to loop through the list of Wire data we have been given
106  // This construct from Gianluca Petrillo who invented it and should be given all credit for it!
107  for(auto const& [channelLabel, instanceName] : util::zip(fWireModuleLabelVec, fOutInstanceLabelVec))
108  {
109  // make a collection of Wires
110  std::unique_ptr<std::vector<recob::Wire>> wireCol = std::make_unique<std::vector<recob::Wire>>();
111 
112  mf::LogInfo("ROIConvert") << "ROIConvert, looking for ChannelROI data at " << channelLabel.encode();
113 
114  // Read in the collection of full length deconvolved waveforms
115  const std::vector<recob::ChannelROI>& channelVec = evt.getProduct<std::vector<recob::ChannelROI>>(channelLabel);
116 
117  mf::LogInfo("ROIConvert") << "--> Recovered ChannelROI data, size: " << channelVec.size();
118 
119  if (!channelVec.empty())
120  {
121  // Reserve the room for the output
122  wireCol->reserve(channelVec.size());
123 
124  // Loop through the input ChannelROI collection
125  for(const auto& channelROI : channelVec)
126  {
127  // Recover the channel and the view
128  raw::ChannelID_t channel = channelROI.Channel();
129  geo::View_t view = fGeometry->View(channel);
130 
131  // Create an ROI vector for output
133 
134  // Loop through the ROIs for this channel
135  const recob::ChannelROI::RegionsOfInterest_t& channelROIs = channelROI.SignalROI();
136 
137  for(const auto& range : channelROIs.get_ranges())
138  {
139  size_t startTick = range.begin_index();
140 
141  std::vector<float> dataVec(range.data().size());
142 
143  for(size_t binIdx = 0; binIdx < range.data().size(); binIdx++) dataVec[binIdx] = range.data()[binIdx];
144 
145  ROIVec.add_range(startTick, std::move(dataVec));
146  }
147 
148  wireCol->push_back(recob::WireCreator(std::move(ROIVec),channel,view).move());
149  }
150 
151  // Time to stroe everything
152  if(wireCol->empty()) mf::LogWarning("ROIConvert") << "No wires made for this event.";
153  }
154 
155  evt.put(std::move(wireCol), instanceName);
156  }
157 
158  fEventCount++;
159 
160  return;
161 } // produce
162 
163 } // end namespace caldata
void produce(art::Event &evt)
Definition of util::zip().
Utilities related to art service access.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Helper functions to create a wire.
pdgs p
Definition: selectors.fcl:22
const geo::GeometryCore * fGeometry
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
ROIConvert(fhicl::ParameterSet const &pset)
for pfile in ack l reconfigure(.*) override"` do echo "checking $
Class managing the creation of a new recob::Wire object.
Definition: WireCreator.h:53
std::vector< std::string > fOutInstanceLabelVec
The output instance labels to apply.
std::vector< art::InputTag > fWireModuleLabelVec
vector of modules that made digits
Description of geometry of one entire detector.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
size_t fEventCount
count of event processed
Declaration of basic channel signal object for ICARUS.
Declaration of basic channel signal object.
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
TCEvent evt
Definition: DataStructs.cxx:8
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
process_name can override from command line with o or output caldata
Definition: pid.fcl:40
void reconfigure(fhicl::ParameterSet const &p)
art framework interface to geometry description
bool fDiagnosticOutput
secret diagnostics flag