LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
CCHitFinderAlg.h
Go to the documentation of this file.
1 // ClusterCrawlerAlg.h
3 //
4 // ClusterCrawlerAlg class
5 //
6 // Bruce Baller
7 //
9 #ifndef CCHITFINDERALG_H
10 #define CCHITFINDERALG_H
11 
12 // C/C++ standard libraries
13 #include <string>
14 #include <vector>
15 #include <memory> // std::unique_ptr<>
16 #include <ostream> // std::endl
17 
18 // framework libraries
19 #include "fhiclcpp/ParameterSet.h"
24 
25 // LArSoft libraries
31 
32 
33 namespace hit {
34 
83 
84  public:
85 
86  std::vector<recob::Hit> allhits;
87 
89  virtual ~CCHitFinderAlg() = default;
90 
91  virtual void reconfigure(fhicl::ParameterSet const& pset);
92 
93  void RunCCHitFinder(std::vector<recob::Wire> const& Wires);
94 
96  std::vector<recob::Hit>&& YieldHits() { return std::move(allhits); }
97 
99  template <typename Stream>
100  void PrintStats(Stream& out) const;
101 
102  private:
103 
104  std::vector<float> fMinPeak;
105  std::vector<float> fMinRMS;
106  unsigned short fMaxBumps; // make a crude hit if > MaxBumps are found in the RAT
107  unsigned short fMaxXtraHits; // max num of hits in Region Above Threshold
108  float fChiSplit;
109  // float ChgNorm; // Area norm for the wire we are working on
110 
111  std::vector<float> fChiNorms;
112  std::vector<float> fTimeOffsets;
113  std::vector<float> fChgNorms;
114 
116  unsigned short theWireNum;
117  unsigned short thePlane;
118 
119  float chinorm;
120  // float timeoff;
121  static constexpr float Sqrt2Pi = 2.5066;
122  static constexpr float SqrtPi = 1.7725;
123 
125 
126 // bool prt;
127 
129 
130  // fit n Gaussians possibly with bounds setting (parmin, parmax)
131  void FitNG(unsigned short nGaus, unsigned short npt, float *ticks,
132  float *signl);
133  // parameters, errors, lower limit, upper limits for FitNG
134  std::vector<double> par;
135  std::vector<double> parerr;
136  std::vector<double> parmin;
137  std::vector<double> parmax;
138  float chidof;
139  int dof;
140  std::vector<unsigned short> bumps;
141 
144  public:
148 
150  (recob::Wire const* w, geo::WireID wid, geo::Geometry const& geom);
151  }; // HitChannelInfo_t
152 
153  // make a cruddy hit if fitting fails
154  void MakeCrudeHit(unsigned short npt, float *ticks, float *signl);
155  // store the hits
156  void StoreHits(unsigned short TStart, unsigned short npt,
157  HitChannelInfo_t info, float adcsum
158  );
159 
160  // study hit finding and fitting
162  std::vector< short > fUWireRange, fUTickRange;
163  std::vector< short > fVWireRange, fVTickRange;
164  std::vector< short > fWWireRange, fWTickRange;
165  void StudyHits(unsigned short flag, unsigned short npt = 0,
166  float *ticks = 0, float *signl = 0, unsigned short tstart = 0);
167  std::vector<int> bumpCnt;
168  std::vector<int> RATCnt;
169  std::vector<float> bumpChi;
170  std::vector<float> bumpRMS;
171  std::vector<int> hitCnt;
172  std::vector<float> hitRMS;
173  // use to determine the slope of protons
174  std::vector<float> loWire;
175  std::vector<float> loTime;
176  std::vector<float> hiWire;
177  std::vector<float> hiTime;
178  bool SelRAT; // set true if a Region Above Threshold should be studied
179 
180  bool fUseFastFit;
181 
182  std::unique_ptr<GausFitCache> FitCache;
183 
184 
185  typedef struct {
186  unsigned int FastFits;
187  std::vector<unsigned int> MultiGausFits;
188 
189  void Reset(unsigned int nGaus);
190 
191  void AddMultiGaus(unsigned int nGaus);
192 
193  void AddFast() { ++FastFits; }
194 
195  } FitStats_t;
196 
199 
217  static bool FastGaussianFit(
218  unsigned short npt, float const*ticks, float const*signl,
219  std::array<double, 3>& params,
220  std::array<double, 3>& paramerrors,
221  float& chidof
222  );
223 
224  static constexpr unsigned int MaxGaussians = 20;
225 
226  }; // class CCHitFinderAlg
227 
228 } // namespace hit
229 
230 
231 //==============================================================================
232 //=== Template implementation
233 //===
234 template <typename Stream>
235 void hit::CCHitFinderAlg::PrintStats(Stream& out) const {
236 
237  out << "CCHitFinderAlg fit statistics:";
238  if (fUseFastFit) {
239  out << "\n fast 1-Gaussian fits: " << FinalFitStats.FastFits
240  << " succeeded (" << TriedFitStats.FastFits << " tried)";
241  }
242  else
243  out << "\n fast 1-Gaussian fits: disabled";
244 
245  for (unsigned int nGaus = 1; nGaus < MaxGaussians; ++nGaus) {
246  if (TriedFitStats.MultiGausFits[nGaus-1] == 0) continue;
247  out << "\n " << nGaus << "-Gaussian fits: "
248  << FinalFitStats.MultiGausFits[nGaus-1]
249  << " accepted (" << TriedFitStats.MultiGausFits[nGaus-1] << " tried)";
250  } // for nGaus
251  if (TriedFitStats.MultiGausFits.back() > 0) {
252  out << "\n " << FinalFitStats.MultiGausFits.size()
253  << "-Gaussian fits or higher: " << FinalFitStats.MultiGausFits.back()
254  << " accepted (" << TriedFitStats.MultiGausFits.back() << " tried)";
255  }
256  out << std::endl;
257 
258 } // CCHitFinderAlg::FitStats_t::Print()
259 
260 
261 
263 
264 #endif // ifndef CCHITFINDERALG_H
unsigned short fMaxBumps
void RunCCHitFinder(std::vector< recob::Wire > const &Wires)
float fChiSplit
Estimated noise error on the Signal.
static constexpr float SqrtPi
void PrintStats(Stream &out) const
Print the fit statistics.
void FitNG(unsigned short nGaus, unsigned short npt, float *ticks, float *signl)
exchange data about the originating wire
std::vector< short > fWTickRange
std::vector< short > fWWireRange
virtual void reconfigure(fhicl::ParameterSet const &pset)
raw::ChannelID_t theChannel
std::vector< float > loWire
std::vector< double > parmax
void StoreHits(unsigned short TStart, unsigned short npt, HitChannelInfo_t info, float adcsum)
void StudyHits(unsigned short flag, unsigned short npt=0, float *ticks=0, float *signl=0, unsigned short tstart=0)
Declaration of signal hit object.
std::vector< float > hiWire
std::vector< unsigned short > bumps
std::vector< float > fChiNorms
std::vector< float > bumpRMS
std::vector< short > fUWireRange
bool fUseFastFit
whether to attempt using a fast fit on single gauss.
std::vector< short > fVWireRange
CCHitFinderAlg(fhicl::ParameterSet const &pset)
std::vector< float > fChgNorms
std::vector< short > fVTickRange
FitStats_t TriedFitStats
counts of the tried fits
unsigned int FastFits
count of single-Gaussian fast fits
Hit finder algorithm designed to work with Cluster Crawler.
std::vector< float > fTimeOffsets
std::vector< recob::Hit > allhits
art::ServiceHandle< geo::Geometry > geom
unsigned short thePlane
std::unique_ptr< GausFitCache > FitCache
a set of functions ready to be used
ntupleExperimental Reset()
enum geo::_plane_sigtype SigType_t
Enumerate the possible plane projections.
virtual ~CCHitFinderAlg()=default
std::vector< float > hiTime
The geometry of one entire detector, as served by art.
Definition: Geometry.h:110
Definition of data types for geometry description.
std::vector< int > bumpCnt
Detector simulation of raw signals on wires.
std::vector< float > loTime
static bool FastGaussianFit(unsigned short npt, float const *ticks, float const *signl, std::array< double, 3 > &params, std::array< double, 3 > &paramerrors, float &chidof)
Performs a "fast" fit.
unsigned short theWireNum
std::vector< unsigned int > MultiGausFits
multi-Gaussian stats
std::vector< float > fMinPeak
Class holding the deconvoluted signals from a channel.
Definition: Wire.h:80
static constexpr unsigned int MaxGaussians
std::vector< int > hitCnt
Provide caches for TF1 functions to be used with ROOT fitters.
static constexpr float Sqrt2Pi
Declaration of basic channel signal object.
unsigned short fMaxXtraHits
std::vector< short > fUTickRange
std::vector< recob::Hit > && YieldHits()
Returns (and loses) the collection of reconstructed hits.
void MakeCrudeHit(unsigned short npt, float *ticks, float *signl)
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
std::vector< float > hitRMS
std::vector< double > parmin
std::vector< int > RATCnt
FitStats_t FinalFitStats
counts of the good fits
std::vector< double > parerr
HitChannelInfo_t(recob::Wire const *w, geo::WireID wid, geo::Geometry const &geom)
Float_t w
Definition: plot.C:23
std::vector< float > fMinRMS
std::vector< float > bumpChi
std::vector< double > par
art framework interface to geometry description