DAQHit.cxx
Go to the documentation of this file.
3 
4 #include <algorithm>
5 #include <cstdio>
6 
7 using namespace daqchannelmap;
8 
10  _theDetID(novadaq::cnv::kUNKNOWN_DET),
11  _theChannel(0),
12  _thePlane(0),
13  _theCell(0),
14  _theView(0),
15  _theADC(0),
16  _theTDC(0),
17  _FEBOverflowError(false)
18 {
19 }
20 
22 {
23 }
26  _theDetID(theMilli->getHeader()->getDetId()),
27  // encode the DAQ Format Channel (dchan)
28  _theChannel(DAQChannelMap::getInstance(_theDetID)
29  ->encodeDChan(_theDetID,
30  theMilli->getHeader()->getDiblockId(),
31  theMilli->getHeader()->getDCMId(),
32  theNano->getHeader()->getFEBId(),
33  theNano->getHeader()->getPixelAddr())),
34  // getPlane() requires Logical Format Channel (lchan)
35  _thePlane(DAQChannelMap::getInstance(_theDetID)->getPlane
36  (DAQChannelMap::getInstance(_theDetID)->encodeLChan(_theChannel))),
37  // getCell() requires lchan
38  _theCell(DAQChannelMap::getInstance(_theDetID)->getCell
39  (DAQChannelMap::getInstance(_theDetID)->encodeLChan(_theChannel))),
40  // getView() requires dchan
41  _theView(DAQChannelMap::getInstance(_theDetID)->getView(_theChannel)),
42  _theTDC(theNano->getTimeStamp()),
43  _FEBOverflowError(theNano->getHeader()->getOverflowError())
44 {
45  uint64_t time_high = theMilli->getFloatingMicroSlice()->getHighWord();
46 
47  // Combine the high 32 bits with the low 32 bits to
48  // form the 64-bit time:
49  _theTDC = (time_high << 32) | theNano->getTimeStamp();
50 
51  _theADC = ADC_Extraction(theNano);
52 
53  if (_theADC.val > 4096)
54  {
55  std::cerr << "Invalid ADC Value: " << _theADC.val << std::endl;
56  assert(false);
57  }
58 }
59 
63  _theChannel(0),
64  _thePlane(plane),
65  _theCell(0),
66  _theView(0),
67  _theADC(adc),
68  _theTDC(tdc),
69  _FEBOverflowError(false)
70 {
71 }
72 
74 DAQHit(int detID,
75  daqchannelmap::dchan channel,
76  novaddt::ADC adc,
77  novaddt::TDC tdc):
78  _theDetID(detID),
79  // pass the dchan
80  _theChannel(channel),
81  // getPlane() requires lchan
82  _thePlane(DAQChannelMap::getInstance(_theDetID)->getPlane
83  (DAQChannelMap::getInstance(_theDetID)->encodeLChan(_theChannel))),
84  // getCell() requires lchan
85  _theCell(DAQChannelMap::getInstance(_theDetID)->getCell
86  (DAQChannelMap::getInstance(_theDetID)->encodeLChan(_theChannel))),
87  // getView() requires dchan
88  _theView(DAQChannelMap::getInstance(_theDetID)->getView(_theChannel)),
89  _theADC(adc),
90  _theTDC(tdc),
91  _FEBOverflowError(false)
92 {
93 }
94 
97 {
98  /*
99  This code is shamelessly copied and adapted from the offline
100  rawdata::RawDigit::ADC() method (see link below). It interprets the
101  raw data format and extracts the ADC value.
102 
103  https://cdcvs.fnal.gov/redmine/projects/novaart/repository/entry/trunk/RawData/RawDigit.cxx#L66
104  */
105 
106  const uint32_t version = theNano->getHeader()->getVersion();
107 
108  // non-multipoint nanoslice version
109  if (version == 0)
110  return theNano->getPulseHeight();
111 
112 
114 
115  const unsigned int nSamples = conv.getNSamples(version);
116  const unsigned int nPretrig = conv.getNPretriggeredSamples(version);
117 
118  // Otherwise it's raw and we need to calculate the DCS value for ourselves
119 
120  // Otherwise we don't have the peak value in our dataset
121  assert(nSamples > nPretrig);
122 
123  // Look back 3 samples (1.5us in the FD)
124  const unsigned int kDCSDistance = 3;
125 
126  // Otherwise we don't have the baseline point in our dataset
127  assert(nPretrig >= kDCSDistance);
128 
129  // The DCS value is the peak value minus the baseline value
130  return theNano->getValue(nPretrig) -
131  theNano->getValue(nPretrig - kDCSDistance);
132 }
133 
135 {
136  // getDCM() require dchan
137  dcm_id_t dcm_id =
138  DAQChannelMap::getInstance(_theDetID)->getDCM(_theChannel);
139  // getDiBlock require dchan
140  int db_id =
141  DAQChannelMap::getInstance(_theDetID)->getDiBlock(_theChannel);
142 
143  DCM result(dcm_id + 12 * (db_id - 1));
144 
145  return result;
146 }
147 
149 {
150  // this method was undefined so I defined it to be a "do-nothing"
151  // method as it is referenced by HoughPoint/cxx/src/HoughPoint.cpp
152  //
153  // ...great programming...
154  return;
155 }
156 
158 {
159  return;
160 }
161 
162 /*
163  ADC Conversion using Environment Switches
164 
165 // decode the multipoint readout as if it were single point readout
166 #define USE_DCS_WAVEFORMS
167 #define DCS_TRIGGER_POINT 3
168 
169 // unpack the entire wave form and then decode it using a lookup table
170 // (available, but simplisticly implemented)
171 //#define USE_RAW_WAVEFORMS
172 
173 // use this if we have to decompress the data (8 bit to 12 bit decomnpression)
174 //#define COMPRESSION_8BIT
175 
176 
177 
178 novaddt::ADC
179 novaddt::DAQHit::ADC_Extraction(daqdataformats::RawNanoSlice* theNano) const
180 {
181  if(version == 0){
182  return theNano->getPulseHeight();
183  }
184 
185  if(version > 0){
186 
187 #ifdef USE_DCS_WAVEFORMS
188  // This block unpacks the data into a DCS waveform
189  int DCSform[20]; // DCS baseline subtracted waveform
190  const int DCSoffset=2;
191 
192  // The effective number of samples is the number of raw samples minus the DCS comparision offset
193  const int effsamples = theNano->getNSamples() - DCSoffset;
194 
195  adc=0;
196  for(int i=0; i< effsamples; ++i){
197 #ifdef COMPRESSION_8BIT
198  DCSform[i]= DataCompression::decodeVal8Bit(theNano->getValue(i+DCSoffset))
199  - DataCompression::decodeVal8Bit(theNano->getValue(i));
200 #else
201  DCSform[i]= theNano->getValue(i+DCSoffset) - theNano->getValue(i);
202 #endif
203  // Return the maximum in the DCS profile
204  if( adc < DCSform[i]){
205  adc = DCSform[i];
206  } //endif
207  } // endfor i
208 #endif
209 
210 #ifdef USE_RAW_WAVEFORMS
211  int waveform[20]; // Raw waveforms
212 
213  const int nsamples = theNano->getNSamples();
214  for(int i=0; i< nsamples; ++i){
215 #ifdef COMPRESSION_8BIT
216  waveform[i] = DataCompression::decodeVal8Bit(theNano->getValue(i));
217 #else
218  waveform[i] = theNano->getValue(i);
219 #endif
220  }
221  // Now do a lookup table for the fit values
222  // i.e. FitLookup(waveform, &pulseheight, &time)
223 
224  // For now we just pull out the Nth point
225  adc = <waveform[DCS_TRIGGER_POINT];
226 #endif
227 
228  } // endif Version > 0
229 
230  return adc;
231 }
232 
233 */
novaddt::Plane _thePlane
Definition: DAQHit.h:96
novaddt::ADC ADC_Extraction(daqdataformats::RawNanoSlice *theNano) const
Definition: DAQHit.cxx:96
IMPLEMENT_MAIN_STANDARD IMPLEMENT_MAIN_setBufferSource daqdataformats::RawNanoSliceHeader * getHeader() const
Get the NanoSlice header pointer.
Definition: RawNanoSlice.h:57
bool _FEBOverflowError
Definition: DAQHit.h:102
void reset()
Definition: DAQHit.cxx:157
OStream cerr
Definition: OStream.cxx:7
daqdataformats::RawMicroSlice * getFloatingMicroSlice() const
Definition: RawMilliSlice.h:48
int _theDetID
Definition: DAQHit.h:94
uint32_t getNSamples(const version_t ver) const
Get the number of samples.
uint32_t getNPretriggeredSamples(const version_t ver) const
Get number of pretriggered samples.
novaddt::Cell _theCell
Definition: DAQHit.h:97
novaddt::TDC _theTDC
Definition: DAQHit.h:100
novaddt::View _theView
Definition: DAQHit.h:98
novaddt::DCM getDCM() const
Definition: DAQHit.cxx:134
const XML_Char * version
Definition: expat.h:187
uint32_t dcm_id_t
Type for DCM number, counts from 1.
novaddt::ADC _theADC
Definition: DAQHit.h:99
assert(nhit_max >=nhit_nbins)
value_type val
Definition: BaseProducts.h:65
uint32_t getHighWord() const
Get method for lower half of timing word.
void print() const
Definition: DAQHit.cxx:148
uint32_t dchan
< DAQ Channel Map Package
daqchannelmap::dchan _theChannel
Definition: DAQHit.h:95