Tpc2dRoi.h
Go to the documentation of this file.
1 // Tpc2dRoi.h
2 //
3 // David Adams
4 // January 2021
5 //
6 // Class that holds the prepared data for a rectangular TPC 2D ROI (region of interest),
7 // i.e. an array of floats indexed by channel and tick.
8 //
9 // The data may be read with data().value(..) and written wiht data().setValue(..).
10 
11 #ifndef Tpc2dRoi_H
12 #define Tpc2dRoi_H
13 
16 #include <memory>
17 
18 class Tpc2dRoi {
19 
20 public:
21 
22  using Index = unsigned int;
23  using LongIndex = unsigned long int;
27  using DftPtr = std::unique_ptr<Dft>;
28 
29  // Ctor for an ROI with no size.
31 
32  // Ctor for an ROI with size.
33  Tpc2dRoi(Index ncha, Index nsam, Index icha0, LongIndex isam0 =0)
34  : m_data({ncha, nsam}), m_sampleOffset(isam0), m_channelOffset(icha0) { }
35 
36  // Return the offset for the first tick wrt to a common reference.
37  // Step size is one data tick assumed the same for all channels in the plane.
39 
40  // Return the number of ticks.
41  Index sampleSize() const { return data().nSamples()[1]; }
42 
43  // Return the first channel.
44  Index channelOffset() const { return m_channelOffset; }
45 
46  // Return the number of channels.
47  Index channelSize() const { return data().nSamples()[0]; }
48 
49  // Return the data array.
50  const DataArray& data() const { return m_data; }
51  DataArray& data() { return m_data; }
52 
53  // Return a value.
54  // Returns valdef for indices out of range.
55  float value(Index icha, LongIndex itck, float valdef =0.0) const {
56  if ( icha < channelOffset() ) return valdef;
57  if ( itck < sampleOffset() ) return valdef;
58  Index chk = 0;
60  idxs[0] = icha - channelOffset();
61  idxs[1] = itck - sampleOffset();
62  float val = data().value(idxs, &chk);
63  if ( chk ) return valdef;
64  return val;
65  }
66 
67  // Return a pointer to DFT. Null if undefined.
68  Dft* dft() { return m_pdft.get(); }
69  const Dft* dft() const { return m_pdft.get(); }
70 
71  // Reset the DFT data pointer. Existing data is deleted.
72  // This class now owns that DFT data.
73  void resetDft(Dft* pdft) { m_pdft.reset(pdft); }
74 
75 private:
76 
81 
82 };
83 
84 #endif
Index sampleSize() const
Definition: Tpc2dRoi.h:41
Index m_channelOffset
Definition: Tpc2dRoi.h:79
const IndexArray & nSamples() const
Definition: Real2dData.h:86
Real2dData< float > m_data
Definition: Tpc2dRoi.h:77
Tpc2dRoi()
Definition: Tpc2dRoi.h:30
float value(Index icha, LongIndex itck, float valdef=0.0) const
Definition: Tpc2dRoi.h:55
DataArray::IndexArray IndexArray
Definition: Tpc2dRoi.h:25
std::array< Index, 2 > IndexArray
Definition: Real2dData.h:34
unsigned int Index
Definition: Tpc2dRoi.h:22
unsigned long int LongIndex
Definition: Tpc2dRoi.h:23
Tpc2dRoi(Index ncha, Index nsam, Index icha0, LongIndex isam0=0)
Definition: Tpc2dRoi.h:33
void resetDft(Dft *pdft)
Definition: Tpc2dRoi.h:73
FftwReal2dDftData< double > FftwDouble2dDftData
Float value(const IndexArray &isams, Index *pchk=nullptr) const
Definition: Real2dData.h:184
std::unique_ptr< Dft > DftPtr
Definition: Tpc2dRoi.h:27
Index channelOffset() const
Definition: Tpc2dRoi.h:44
const Dft * dft() const
Definition: Tpc2dRoi.h:69
const DataArray & data() const
Definition: Tpc2dRoi.h:50
Index channelSize() const
Definition: Tpc2dRoi.h:47
DataArray & data()
Definition: Tpc2dRoi.h:51
LongIndex sampleOffset() const
Definition: Tpc2dRoi.h:38
DftPtr m_pdft
Definition: Tpc2dRoi.h:80
LongIndex m_sampleOffset
Definition: Tpc2dRoi.h:78
Dft * dft()
Definition: Tpc2dRoi.h:68