LArSoft  v10_04_05
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 #include "fhiclcpp/fwd.h"
21 
22 // LArSoft libraries
28 
29 namespace hit {
30 
79  public:
80  std::vector<recob::Hit> allhits;
81 
82  explicit CCHitFinderAlg(fhicl::ParameterSet const& pset);
83  void RunCCHitFinder(std::vector<recob::Wire> const& Wires);
84 
86  std::vector<recob::Hit>&& YieldHits() { return std::move(allhits); }
87 
89  template <typename Stream>
90  void PrintStats(Stream& out) const;
91 
92  private:
93  std::vector<float> fMinPeak;
94  std::vector<float> fMinRMS;
95  unsigned short fMaxBumps; // make a crude hit if > MaxBumps are found in the RAT
96  unsigned short fMaxXtraHits; // max num of hits in Region Above Threshold
97  float fChiSplit;
98  // float ChgNorm; // Area norm for the wire we are working on
99 
100  std::vector<float> fChiNorms;
101  std::vector<float> fTimeOffsets;
102  std::vector<float> fChgNorms;
103 
105  unsigned short theWireNum;
106  unsigned short thePlane;
107 
108  float chinorm;
109  static constexpr float Sqrt2Pi = 2.5066;
110  static constexpr float SqrtPi = 1.7725;
111 
113 
116 
117  // fit n Gaussians possibly with bounds setting (parmin, parmax)
118  void FitNG(unsigned short nGaus, unsigned short npt, float* ticks, float* signl);
119  // parameters, errors, lower limit, upper limits for FitNG
120  std::vector<double> par;
121  std::vector<double> parerr;
122  std::vector<double> parmin;
123  std::vector<double> parmax;
124  float chidof;
125  int dof;
126  std::vector<unsigned short> bumps;
127 
133  };
134 
135  // make a cruddy hit if fitting fails
136  void MakeCrudeHit(unsigned short npt, float* ticks, float* signl);
137  // store the hits
138  void StoreHits(unsigned short TStart, unsigned short npt, HitChannelInfo_t info, float adcsum);
139 
140  // study hit finding and fitting
142  std::vector<short> fUWireRange, fUTickRange;
143  std::vector<short> fVWireRange, fVTickRange;
144  std::vector<short> fWWireRange, fWTickRange;
145  void StudyHits(unsigned short flag,
146  unsigned short npt = 0,
147  float* signl = nullptr,
148  unsigned short tstart = 0);
149  std::vector<int> bumpCnt;
150  std::vector<int> RATCnt;
151  std::vector<float> bumpChi;
152  std::vector<float> bumpRMS;
153  std::vector<int> hitCnt;
154  std::vector<float> hitRMS;
155  // use to determine the slope of protons
156  std::vector<float> loWire;
157  std::vector<float> loTime;
158  std::vector<float> hiWire;
159  std::vector<float> hiTime;
160  bool SelRAT; // set true if a Region Above Threshold should be studied
161 
162  bool fUseFastFit;
163 
165 
166  struct FitStats_t {
167  unsigned int FastFits;
168  std::vector<unsigned int> MultiGausFits;
169 
170  void Reset(unsigned int nGaus);
171  void AddMultiGaus(unsigned int nGaus);
172  void AddFast() { ++FastFits; }
173  };
174 
177 
195  static bool FastGaussianFit(unsigned short npt,
196  float const* ticks,
197  float const* signl,
198  std::array<double, 3>& params,
199  std::array<double, 3>& paramerrors,
200  float& chidof);
201 
202  static constexpr unsigned int MaxGaussians = 20;
203 
204  }; // class CCHitFinderAlg
205 
206 } // namespace hit
207 
208 //==============================================================================
209 //=== Template implementation
210 //===
211 template <typename Stream>
212 void hit::CCHitFinderAlg::PrintStats(Stream& out) const
213 {
214  out << "CCHitFinderAlg fit statistics:";
215  if (fUseFastFit) {
216  out << "\n fast 1-Gaussian fits: " << FinalFitStats.FastFits << " succeeded ("
217  << TriedFitStats.FastFits << " tried)";
218  }
219  else
220  out << "\n fast 1-Gaussian fits: disabled";
221 
222  for (unsigned int nGaus = 1; nGaus < MaxGaussians; ++nGaus) {
223  if (TriedFitStats.MultiGausFits[nGaus - 1] == 0) continue;
224  out << "\n " << nGaus << "-Gaussian fits: " << FinalFitStats.MultiGausFits[nGaus - 1]
225  << " accepted (" << TriedFitStats.MultiGausFits[nGaus - 1] << " tried)";
226  } // for nGaus
227  if (TriedFitStats.MultiGausFits.back() > 0) {
228  out << "\n " << FinalFitStats.MultiGausFits.size()
229  << "-Gaussian fits or higher: " << FinalFitStats.MultiGausFits.back() << " accepted ("
230  << TriedFitStats.MultiGausFits.back() << " tried)";
231  }
232  out << std::endl;
233 } // CCHitFinderAlg::FitStats_t::Print()
234 
236 
237 #endif // ifndef CCHITFINDERALG_H
unsigned short fMaxBumps
void RunCCHitFinder(std::vector< recob::Wire > const &Wires)
std::vector< short > fWTickRange
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)
GausFitCache FitCache
a set of functions ready to be used
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)
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.
CCHitFinderAlg(fhicl::ParameterSet const &pset)
std::vector< float > fChgNorms
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
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
A set of TF1 linear sum of base functions (Gaussians)
Definition: GausFitCache.h:45
std::vector< short > fUTickRange
std::vector< recob::Hit > allhits
unsigned short thePlane
ntupleExperimental Reset()
enum geo::_plane_sigtype SigType_t
Enumerate the possible plane projections.
Interface for a class providing readout channel mapping to geometry.
geo::WireReadoutGeom const * wireReadoutGeom
std::vector< float > hiTime
std::vector< short > fUWireRange
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.
void StudyHits(unsigned short flag, unsigned short npt=0, float *signl=nullptr, unsigned short tstart=0)
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
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.
std::vector< short > fVWireRange
std::vector< short > fVTickRange
unsigned short fMaxXtraHits
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: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
std::vector< float > fMinRMS
std::vector< float > bumpChi
exchange data about the originating wire
std::vector< double > par