LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 <array>
14 #include <memory> // std::unique_ptr<>
15 #include <ostream> // std::endl
16 #include <vector>
17 
18 // framework libraries
20 namespace fhicl {
21  class ParameterSet;
22 }
23 
24 // LArSoft libraries
30 
31 namespace hit {
32 
81 
82  public:
83  std::vector<recob::Hit> allhits;
84 
86  virtual ~CCHitFinderAlg() = default;
87 
88  virtual void reconfigure(fhicl::ParameterSet const& pset);
89 
90  void RunCCHitFinder(std::vector<recob::Wire> const& Wires);
91 
93  std::vector<recob::Hit>&& YieldHits() { return std::move(allhits); }
94 
96  template <typename Stream>
97  void PrintStats(Stream& out) const;
98 
99  private:
100  std::vector<float> fMinPeak;
101  std::vector<float> fMinRMS;
102  unsigned short fMaxBumps; // make a crude hit if > MaxBumps are found in the RAT
103  unsigned short fMaxXtraHits; // max num of hits in Region Above Threshold
104  float fChiSplit;
105  // float ChgNorm; // Area norm for the wire we are working on
106 
107  std::vector<float> fChiNorms;
108  std::vector<float> fTimeOffsets;
109  std::vector<float> fChgNorms;
110 
112  unsigned short theWireNum;
113  unsigned short thePlane;
114 
115  float chinorm;
116  // float timeoff;
117  static constexpr float Sqrt2Pi = 2.5066;
118  static constexpr float SqrtPi = 1.7725;
119 
121 
122  // bool prt;
123 
125 
126  // fit n Gaussians possibly with bounds setting (parmin, parmax)
127  void FitNG(unsigned short nGaus, unsigned short npt, float* ticks, float* signl);
128  // parameters, errors, lower limit, upper limits for FitNG
129  std::vector<double> par;
130  std::vector<double> parerr;
131  std::vector<double> parmin;
132  std::vector<double> parmax;
133  float chidof;
134  int dof;
135  std::vector<unsigned short> bumps;
136 
139  public:
143 
144  HitChannelInfo_t(recob::Wire const* w, geo::WireID wid, geo::Geometry const& geom);
145  }; // HitChannelInfo_t
146 
147  // make a cruddy hit if fitting fails
148  void MakeCrudeHit(unsigned short npt, float* ticks, float* signl);
149  // store the hits
150  void StoreHits(unsigned short TStart, unsigned short npt, HitChannelInfo_t info, float adcsum);
151 
152  // study hit finding and fitting
154  std::vector<short> fUWireRange, fUTickRange;
155  std::vector<short> fVWireRange, fVTickRange;
156  std::vector<short> fWWireRange, fWTickRange;
157  void StudyHits(unsigned short flag,
158  unsigned short npt = 0,
159  float* signl = nullptr,
160  unsigned short tstart = 0);
161  std::vector<int> bumpCnt;
162  std::vector<int> RATCnt;
163  std::vector<float> bumpChi;
164  std::vector<float> bumpRMS;
165  std::vector<int> hitCnt;
166  std::vector<float> hitRMS;
167  // use to determine the slope of protons
168  std::vector<float> loWire;
169  std::vector<float> loTime;
170  std::vector<float> hiWire;
171  std::vector<float> hiTime;
172  bool SelRAT; // set true if a Region Above Threshold should be studied
173 
174  bool fUseFastFit;
175 
176  std::unique_ptr<GausFitCache> FitCache;
177 
178  struct FitStats_t {
179  unsigned int FastFits;
180  std::vector<unsigned int> MultiGausFits;
181 
182  void Reset(unsigned int nGaus);
183 
184  void AddMultiGaus(unsigned int nGaus);
185 
186  void AddFast() { ++FastFits; }
187  };
188 
191 
209  static bool FastGaussianFit(unsigned short npt,
210  float const* ticks,
211  float const* signl,
212  std::array<double, 3>& params,
213  std::array<double, 3>& paramerrors,
214  float& chidof);
215 
216  static constexpr unsigned int MaxGaussians = 20;
217 
218  }; // class CCHitFinderAlg
219 
220 } // namespace hit
221 
222 //==============================================================================
223 //=== Template implementation
224 //===
225 template <typename Stream>
226 void hit::CCHitFinderAlg::PrintStats(Stream& out) const
227 {
228 
229  out << "CCHitFinderAlg fit statistics:";
230  if (fUseFastFit) {
231  out << "\n fast 1-Gaussian fits: " << FinalFitStats.FastFits << " succeeded ("
232  << TriedFitStats.FastFits << " tried)";
233  }
234  else
235  out << "\n fast 1-Gaussian fits: disabled";
236 
237  for (unsigned int nGaus = 1; nGaus < MaxGaussians; ++nGaus) {
238  if (TriedFitStats.MultiGausFits[nGaus - 1] == 0) continue;
239  out << "\n " << nGaus << "-Gaussian fits: " << FinalFitStats.MultiGausFits[nGaus - 1]
240  << " accepted (" << TriedFitStats.MultiGausFits[nGaus - 1] << " tried)";
241  } // for nGaus
242  if (TriedFitStats.MultiGausFits.back() > 0) {
243  out << "\n " << FinalFitStats.MultiGausFits.size()
244  << "-Gaussian fits or higher: " << FinalFitStats.MultiGausFits.back() << " accepted ("
245  << TriedFitStats.MultiGausFits.back() << " tried)";
246  }
247  out << std::endl;
248 
249 } // CCHitFinderAlg::FitStats_t::Print()
250 
252 
253 #endif // ifndef CCHITFINDERALG_H
unsigned short fMaxBumps
float fChiSplit
Estimated noise error on the Signal.
art::ServiceHandle< geo::Geometry const > geom
void PrintStats(Stream &out) const
Print the fit statistics.
exchange data about the originating wire
raw::ChannelID_t theChannel
std::vector< float > loWire
std::vector< double > parmax
Declaration of signal hit object.
std::vector< float > hiWire
std::vector< unsigned short > bumps
std::vector< float > fChiNorms
std::vector< float > bumpRMS
bool fUseFastFit
whether to attempt using a fast fit on single gauss.
std::vector< float > fChgNorms
FitStats_t TriedFitStats
counts of the tried fits
unsigned int FastFits
count of single-Gaussian fast fits
tick ticks
Alias for common language habits.
Definition: electronics.h:76
Hit finder algorithm designed to work with Cluster Crawler.
std::vector< float > fTimeOffsets
std::vector< recob::Hit > allhits
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.
parameter set interface
std::vector< float > hiTime
std::vector< short > fUWireRange
The geometry of one entire detector, as served by art.
Definition: Geometry.h:181
Definition of data types for geometry description.
std::vector< int > bumpCnt
Detector simulation of raw signals on wires.
std::vector< float > loTime
std::vector< short > fWWireRange
unsigned short theWireNum
std::vector< unsigned int > MultiGausFits
multi-Gaussian stats
std::vector< float > fMinPeak
Class holding the regions of interest of signal from a channel.
Definition: Wire.h:116
std::vector< int > hitCnt
Provide caches for TF1 functions to be used with ROOT fitters.
Declaration of basic channel signal object.
std::vector< short > fVWireRange
unsigned short fMaxXtraHits
std::vector< recob::Hit > && YieldHits()
Returns (and loses) the collection of reconstructed hits.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
std::vector< float > hitRMS
std::vector< double > parmin
std::vector< int > RATCnt
FitStats_t FinalFitStats
counts of the good fits
std::vector< double > parerr
Float_t w
Definition: plot.C:20
std::vector< float > fMinRMS
std::vector< float > bumpChi
std::vector< double > par
art framework interface to geometry description