ADCShapeFit.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief Function to perform, and table to cache, timing fits to ADC values
3 /// \author bckhouse@caltech.edu
4 /// \date
5 ////////////////////////////////////////////////////////////////////////
6 
7 // Please, do not introduce any art dependencies into this file. It needs to be
8 // able to be compiled standalone (as part of genADCShapeFitLookupTable) to
9 // produce the lookup table file in the first place. It should be possible to
10 // do any required artyness in Calibrator.cxx
11 
12 #ifndef CALIB_ADCSHAPEFIT_H
13 #define CALIB_ADCSHAPEFIT_H
14 
15 #include "stdint.h"
16 
17 #include <string>
18 #include <unordered_set>
19 #include <vector>
20 
21 namespace calib
22 {
23  /// Scans a pulseheight shape across the given ADC values and returns the
24  /// best offset. Offset is in internal units. Use \ref OffsetToTNS to convert
25  /// to an absolute time in nanoseconds.
26  ///
27  /// Rise and fall time should be in units of the spacing between samples
28  uint16_t ADCShapeFit(int16_t adc1, int16_t adc2, int16_t adc3,
29  double riseTime, double fallTime, double preAmp,
30  bool& goodTime, int mode);
31 
33  {
34  public:
35  ADCShapeFitTable(const std::string& fname, bool isND, bool isMC, int mode);
37  /// Returns equivalent of OffsetToTNS(tdc, ADCShapeFit(adc1...)) but in
38  /// most cases can do so more rapidly via a lookup table. \a adcpeak is the
39  /// estimated peak curve value at the best fit time.
40  double TNS(double tns0, int16_t adc1, int16_t adc2, int16_t adc3,
41  double& adcpeak, bool& goodTime, double& base) const;
42  /// What fraction of calls to \a TNS went via the table?
43  double TableHitFraction() const;
44 
45  // Sadly this stuff needs to be in the header to allow the size of the
46  // members to be known.
47 
48  // Bounds within which adc values must lie in order for them to be in our
49  // table. adc1 must be less than adc3. adc2 is measured relative to
50  // adc3. See genADCShapeFitLookupTable for more detail about the looping
51  // order.
52  const static int kADC3Max = 800;
53  const static int kADC1Min = -10;
54  const static int kADC2RelMin = -140;
55  const static int kADC2RelMax = +10;
56  // To understand this you need to understand the constraints the looping in
57  // genADCShapeFitLookupTable and be ready to think about the 3D shape this
58  // produces in ADC space.
59  const static unsigned int kNumTableEntries =
60  (-kADC1Min*kADC3Max + // Rectangular part, where adc1 < 0
61  (kADC3Max*(kADC3Max-1))/2)* // Triangular part, where 0 <= adc1 < adc0
62  (kADC2RelMax-kADC2RelMin); // Thickness of the wedge due to adc2
63 
64  protected:
65  // No copy constructors
66  ADCShapeFitTable(const ADCShapeFitTable&) = delete;
68 
69  /// Access the table entry at index \a i
70  uint16_t Table(int i) const;
71 
72  bool fIsND;
73  bool fIsMC;
74  int fMode;
75  std::unordered_set<int> fIsBad;
76  mutable int fNHit, fNMiss;
77 
78  /// Chunks of LZ4-compressed data containing the lookup table
79  std::vector<std::vector<char>> fCompressedTable;
80  };
81 }
82 
83 #endif
std::vector< std::vector< char > > fCompressedTable
Chunks of LZ4-compressed data containing the lookup table.
Definition: ADCShapeFit.h:79
uint16_t Table(int i) const
Access the table entry at index i.
static const unsigned int kNumTableEntries
Definition: ADCShapeFit.h:59
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
static const int kADC2RelMax
Definition: ADCShapeFit.h:55
static const int kADC2RelMin
Definition: ADCShapeFit.h:54
ADCShapeFitTable & operator=(const ADCShapeFitTable &)=delete
CDPStorage service.
double TNS(double tns0, int16_t adc1, int16_t adc2, int16_t adc3, double &adcpeak, bool &goodTime, double &base) const
static const int kADC1Min
Definition: ADCShapeFit.h:53
uint16_t ADCShapeFit(int16_t adc1, int16_t adc2, int16_t adc3, double riseTime, double fallTime, double preAmp, bool &goodTime, int fMode)
ADCShapeFitTable(const std::string &fname, bool isND, bool isMC, int mode)
double TableHitFraction() const
What fraction of calls to TNS went via the table?
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::unordered_set< int > fIsBad
Definition: ADCShapeFit.h:75
static const int kADC3Max
Definition: ADCShapeFit.h:52