LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
RFFHitFinderAlg.cxx
Go to the documentation of this file.
1 
13 #include "fhiclcpp/ParameterSet.h"
16 
17 #include "RFFHitFinderAlg.h"
18 
19 #include <numeric>
20 
22 {
23  fMatchThresholdVec = p.get<std::vector<float>>("MeanMatchThreshold");
24  fMergeMultiplicityVec = p.get<std::vector<unsigned int>>("MinMergeMultiplicity");
25  fAmpThresholdVec = p.get<std::vector<float>>("AmplitudeThreshold", std::vector<float>(1, 0.0));
26 }
27 
29 {
30  const unsigned int n_planes = geo.Nplanes();
31 
32  //If size zero, throw. If size one, assume same for all planes.
33  //If size > 1 but < n_planes, throw. If size = n_plane, good.
34 
35  if (fMatchThresholdVec.size() == 0 || fMergeMultiplicityVec.size() == 0 ||
36  fAmpThresholdVec.size() == 0)
37  throw std::runtime_error("Error in RFFHitFinderAlg: Configured with zero planes.");
38 
39  if ((fMatchThresholdVec.size() > 1 && fMatchThresholdVec.size() < n_planes) ||
40  (fMergeMultiplicityVec.size() > 1 && fMergeMultiplicityVec.size() < n_planes) ||
41  (fAmpThresholdVec.size() > 1 && fAmpThresholdVec.size() < n_planes))
42  throw std::runtime_error("Error in RFFHitFinderAlg: Configured with incorrect n_planes.");
43 
44  if (fMatchThresholdVec.size() == 1) fMatchThresholdVec.resize(n_planes, fMatchThresholdVec[0]);
45 
46  if (fMergeMultiplicityVec.size() == 1)
47  fMergeMultiplicityVec.resize(n_planes, fMergeMultiplicityVec[0]);
48 
49  if (fAmpThresholdVec.size() == 1) fAmpThresholdVec.resize(n_planes, fAmpThresholdVec[0]);
50 }
51 
53 {
55 }
56 
57 void hit::RFFHitFinderAlg::Run(std::vector<recob::Wire> const& wireVector,
58  std::vector<recob::Hit>& hitVector,
59  geo::Geometry const& geo)
60 {
61  hitVector.reserve(wireVector.size());
62  for (auto const& wire : wireVector) {
63  geo::SigType_t const& sigtype = geo.SignalType(wire.Channel());
64  geo::WireID const wireID = geo.ChannelToWire(wire.Channel()).at(0);
65 
66  SetFitterParams(wire.View());
67 
68  for (auto const& roi : wire.SignalROI().get_ranges()) {
69  fFitter.RunFitter(roi.data());
70 
71  const float summedADCTotal = std::accumulate(roi.data().begin(), roi.data().end(), 0.0);
72  const raw::TDCtick_t startTick = roi.begin_index();
73  const raw::TDCtick_t endTick = roi.begin_index() + roi.size();
74 
75  EmplaceHit(hitVector, wire, summedADCTotal, startTick, endTick, sigtype, wireID);
76  } //end loop over ROIs on wire
77 
78  } //end loop over wires
79 }
80 
81 void hit::RFFHitFinderAlg::EmplaceHit(std::vector<recob::Hit>& hitVector,
82  recob::Wire const& wire,
83  float const& summedADCTotal,
84  raw::TDCtick_t const& startTick,
85  raw::TDCtick_t const& endTick,
86  geo::SigType_t const& sigtype,
87  geo::WireID const& wireID)
88 {
89 
90  float totalArea = 0.0;
91  std::vector<float> areaVector(fFitter.NHits());
92  std::vector<float> areaErrorVector(fFitter.NHits());
93  std::vector<float> areaFracVector(fFitter.NHits());
94 
95  for (size_t ihit = 0; ihit < fFitter.NHits(); ihit++) {
96  areaVector[ihit] = fFitter.AmplitudeVector()[ihit] * fFitter.SigmaVector()[ihit] * SQRT_TWO_PI;
97  areaErrorVector[ihit] =
98  SQRT_TWO_PI * std::sqrt(fFitter.AmplitudeVector()[ihit] * fFitter.SigmaErrorVector()[ihit] *
100  fFitter.AmplitudeErrorVector()[ihit] * fFitter.SigmaVector()[ihit] *
101  fFitter.AmplitudeErrorVector()[ihit] * fFitter.SigmaVector()[ihit]);
102  totalArea += areaVector[ihit];
103  }
104 
105  for (size_t ihit = 0; ihit < fFitter.NHits(); ihit++) {
106  areaFracVector[ihit] = areaVector[ihit] / totalArea;
107 
108  hitVector.emplace_back(wire.Channel(),
109  startTick,
110  endTick,
111  fFitter.MeanVector()[ihit] + (float)startTick,
112  fFitter.MeanErrorVector()[ihit],
113  fFitter.SigmaVector()[ihit],
114  fFitter.AmplitudeVector()[ihit],
116  summedADCTotal * areaFracVector[ihit],
117  areaVector[ihit],
118  areaErrorVector[ihit],
119  fFitter.NHits(),
120  ihit,
121  -999.,
122  -999,
123  wire.View(),
124  sigtype,
125  wireID);
126  }
127 }
void EmplaceHit(std::vector< recob::Hit > &, recob::Wire const &, float const &, raw::TDCtick_t const &, raw::TDCtick_t const &, geo::SigType_t const &, geo::WireID const &)
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
const std::vector< float > & AmplitudeVector()
Definition: RFFHitFitter.h:48
void Run(std::vector< recob::Wire > const &, std::vector< recob::Hit > &, geo::Geometry const &)
void RunFitter(const std::vector< float > &signal)
const std::vector< float > & MeanVector()
Definition: RFFHitFitter.h:44
void SetFitterParams(float, unsigned int, float)
const std::vector< float > & SigmaVector()
Definition: RFFHitFitter.h:45
void SetFitterParamsVectors(geo::Geometry const &)
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
geo::View_t View() const
Returns the view the channel belongs to.
Definition: Wire.h:219
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:223
enum geo::_plane_sigtype SigType_t
Enumerate the possible plane projections.
std::vector< float > fAmpThresholdVec
std::vector< float > fMatchThresholdVec
T get(std::string const &key) const
Definition: ParameterSet.h:314
The geometry of one entire detector, as served by art.
Definition: Geometry.h:181
const std::vector< float > & MeanErrorVector()
Definition: RFFHitFitter.h:46
RFFHitFinderAlg(fhicl::ParameterSet const &)
SigType_t SignalType(PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
std::vector< unsigned int > fMergeMultiplicityVec
void SetFitterParams(unsigned int)
Class holding the regions of interest of signal from a channel.
Definition: Wire.h:116
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
Definition: GeometryCore.h:977
unsigned int NHits()
Definition: RFFHitFitter.h:50
Namespace collecting geometry-related classes utilities.
const std::vector< float > & AmplitudeErrorVector()
Definition: RFFHitFitter.h:49
art framework interface to geometry description
const std::vector< float > & SigmaErrorVector()
Definition: RFFHitFitter.h:47