RawDigit.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief RawDigit class
3 /// \author jpaley@indiana.edu
4 /// \date
5 ////////////////////////////////////////////////////////////////////////
6 #include "RawData/RawDigit.h"
7 
8 #include "DAQDataFormats/NanoSliceVersionConvention.h"
9 
10 #include <iomanip>
11 #include <iostream>
12 #include <cassert>
13 
14 namespace rawdata{
15 
16  //----------------------------------------------------------------------
17 
19  fFrameSequenceNumber(1),
20  fFEBStatus(1),
21  fDebugMode(false),
22  fDataPresent(false),
23  fLinkStatus(false),
24  fReserved(1),
25  fADC(0),
26  fTDC(1, 0),
27  fVersion(0),
28  fChannel(0),
29  fDaqChannel(0),
30  fMCBits(0)
31  {
32  }
33 
34  //----------------------------------------------------------------------
35 
36  RawDigit::RawDigit(uint32_t channel,
37  uint32_t daqchannel,
38  std::vector<int16_t> adclist,
39  int32_t tdc) :
41  fFEBStatus(1),
42  fDebugMode(false),
43  fDataPresent(false),
44  fLinkStatus(false),
45  fReserved(1),
46  fADC(adclist),
47  fTDC(tdc),
48  fVersion(0),
49  fChannel(channel),
50  fDaqChannel(daqchannel),
51  fMCBits(0)
52  {
53  }
54 
55  //----------------------------------------------------------------------
56 
57  //--------------------------------------------------
58  int16_t RawDigit::ADC(uint32_t i) const
59  {
60  if(i > fADC.size()){
61  printf("RawDigit::ADC(%d) out of range!\n", i);
62  }
63  return fADC[i];
64  }
65 
66  //--------------------------------------------------
67  int16_t RawDigit::ADC() const
68  {
69  if(IsMC() && fVersion == 0 && fADC.size() == 3){
70  // This is the old-style MC version of fast timing. ADC(0) is the DCS
71  // value.
72  return fADC[0];
73  }
74 
76 
77  const unsigned int nSamples = conv.getNSamples(fVersion);
78  const unsigned int nPretrig = conv.getNPretriggeredSamples(fVersion);
79 
80  assert(fADC.size() == nSamples);
81 
82  if(fVersion == 0){
83  // Version zero is a single DCS value. But I don't see anywhere that
84  // tells us it's DCS, so hardcode it. Check all the sizes make sense.
85  assert(nSamples == 1);
86  assert(nPretrig == 0);
87 
88  return fADC[0];
89  }
90 
91  // Otherwise it's raw and we need to calculate the DCS value for ourselves
92 
93  // Otherwise we don't have the peak value in our dataset
94  assert(nSamples > nPretrig);
95 
96  // Look back 3 samples (1.5us in the FD)
97  const unsigned int kDCSDistance = 3;
98 
99  // Otherwise we don't have the baseline point in our dataset
100  assert(nPretrig >= kDCSDistance);
101 
102  // The DCS value is the peak value minus the baseline value
103  return fADC[nPretrig]-fADC[nPretrig-kDCSDistance];
104  }
105 
106  //--------------------------------------------------
107 
108  void RawDigit::SetADC(uint32_t i, int16_t iADC) {
109  if (fADC.size()<i+1) fADC.resize(i+1);
110  fADC[i]=iADC;
111  return;
112  }
113 
114  //--------------------------------------------------
115 
116  void RawDigit::SetTDC(int32_t iTDC) {
117  assert(fTDC.size() == 1);
118  fTDC[0] = iTDC;
119  }
120 
121  //------------------------------------------------------------
122  std::ostream& operator<< (std::ostream& o, const RawDigit& r)
123  {
124  if(r.IsMC()){
125  o << std::setiosflags(std::ios::fixed) << std::setprecision(2);
126  o << " Version = " << std::setw(5) << std::right << (int)r.Version()
127  << " NADC = " << std::setw(5) << std::right << r.NADC();
128  }
129  else if (r.IsRealData()){
130  o << std::setiosflags(std::ios::fixed) << std::setprecision(2);
131  o << " Channel = " << std::setw(5) << std::right << r.Channel()
132  << " Version = " << std::setw(5) << std::right << (int)r.Version()
133  << " NADC = " << std::setw(5) << std::right << r.NADC();
134  }
135  return o;
136  }
137 
138 } // end namespace rawdata
139 //////////////////////////////////////////////////////////////////////////////
friend std::ostream & operator<<(std::ostream &o, const RawDigit &r)
Definition: RawDigit.cxx:122
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
void SetTDC(int32_t iTDC)
Definition: RawDigit.cxx:116
uint16_t fReserved
Should be 0xCAFE.
Definition: RawDigit.h:47
Definition of connection map class.
Definition: CMap.h:19
uint32_t fDaqChannel
DAQ readout channel.
Definition: RawDigit.h:58
void SetADC(uint32_t i, int16_t iADC)
Definition: RawDigit.cxx:108
uint32_t fMCBits
status bits for MC information
Definition: RawDigit.h:70
uint8_t fVersion
NanoSlice version.
Definition: RawDigit.h:52
uint32_t getNSamples(const version_t ver) const
Get the number of samples.
uint32_t fChannel
channel ID
Definition: RawDigit.h:57
uint32_t getNPretriggeredSamples(const version_t ver) const
Get number of pretriggered samples.
uint8_t fFrameSequenceNumber
Definition: RawDigit.h:39
int16_t ADC() const
Best estimator of the hit charge.
Definition: RawDigit.cxx:67
printf("%d Experimental points found\n", nlines)
bool IsMC() const
Definition: RawDigit.h:108
std::vector< int32_t > fTDC
TDC(-like) time value. Event time is subtracted. Vector structure is a historical artifact...
Definition: RawDigit.h:50
uint8_t Version() const
Definition: RawDigit.h:87
std::vector< int16_t > fADC
list of ADC(-like) charge values
Definition: RawDigit.h:49
uint32_t NADC() const
Definition: RawDigit.h:81
uint32_t Channel() const
Definition: RawDigit.h:84
assert(nhit_max >=nhit_nbins)
TRandom3 r(0)
uint8_t fFEBStatus
Definition: RawDigit.h:43
bool IsRealData() const
Definition: RawDigit.h:107