Functions
test_StandardRawDigitExtractService.cxx File Reference
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "lardataobj/RawData/RawDigit.h"
#include "dunecore/ArtSupport/ArtServiceHelper.h"
#include "dunecore/DuneInterface/Data/AdcTypes.h"
#include "dunecore/DuneInterface/Service/RawDigitExtractService.h"
#include <cassert>

Go to the source code of this file.

Functions

bool sigequal (AdcSignal sig1, AdcSignal sig2)
 
int test_StandardRawDigitExtractService ()
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 154 of file test_StandardRawDigitExtractService.cxx.

154  {
155  int logLevel = 1;
156  if ( argc > 1 ) {
157  istringstream ssarg(argv[1]);
158  ssarg >> logLevel;
159  }
161 }
int test_StandardRawDigitExtractService()
bool sigequal ( AdcSignal  sig1,
AdcSignal  sig2 
)

Definition at line 34 of file test_StandardRawDigitExtractService.cxx.

34  {
35  AdcSignal sigdiff = sig2 - sig1;
36  if ( sigdiff < -0.5 ) return false;
37  if ( sigdiff > 0.5 ) return false;
38  return true;
39 }
float AdcSignal
Definition: AdcTypes.h:21
int test_StandardRawDigitExtractService ( )

Definition at line 43 of file test_StandardRawDigitExtractService.cxx.

43  {
44  const string myname = "test_StandardRawDigitExtractService: ";
45 #ifdef NDEBUG
46  cout << myname << "NDEBUG must be off." << endl;
47  abort();
48 #endif
49  string line = "-----------------------------";
50 
51  cout << myname << line << endl;
52  cout << myname << "Create top-level FCL." << endl;
53 
54  int loglevel = 1;
55  std::ostringstream oss;
56  oss << "#include \"dataprep_tools.fcl\"" << endl;
57  oss << "services.RawDigitExtractService: {" << endl;
58  oss << " service_provider: StandardRawDigitExtractService" << endl;
59  oss << " LogLevel: " << loglevel << endl;
60  oss << " DigitReadTool: digitReader" << endl;
61  oss << " PedestalOption: 1" << endl;
62  oss << " FlagStuckOff: true" << endl;
63  oss << " FlagStuckOn: true" << endl;
64  oss << "}" << endl;
66 
67  AdcCount lowbits = 63;
68  AdcCount highbits = 4095 - 63;
69 
70  cout << myname << line << endl;
71  cout << myname << "Create a raw digit." << endl;
72  AdcSignalVector sigsin;
73  float fac = 250.0;
74  float ped = 2000.2;
75  for ( int i=0; i<10; ++i ) sigsin.push_back(fac*i);
76  for ( int i=10; i>=0; --i ) sigsin.push_back(fac*i);
77  for ( int i=19; i>=0; --i ) sigsin.push_back(-sigsin[i]);
78  unsigned int nsig = 41;
79  assert(sigsin.size() == nsig);
80  AdcCountVector adcsin;
81  unsigned int isig_stucklo = 5;
82  unsigned int isig_stuckhi = 15;
83  for ( unsigned int isig=0; isig<nsig; ++isig) {
84  AdcSignal sig = sigsin[isig] + ped;
85  AdcCount adc = 0.0;
86  if ( sig > 0.0 ) adc = int(sig+0.5);
87  if ( adc > 4095 ) adc = 4095;
88  AdcCount adchigh = adc & highbits;
89  if ( isig == isig_stucklo ) adc = adchigh; // Stuck low bits to zero.
90  if ( isig == isig_stuckhi ) adc = adchigh + lowbits; // Stuck low bits to one.
91  adcsin.push_back(adc);
92  }
93  assert(adcsin.size() == nsig);
94  unsigned int chan = 123;
95  raw::RawDigit dig(chan, nsig, adcsin, raw::kNone);
96  dig.SetPedestal(ped);
97  cout << myname << " Compressed size: " << dig.NADC() << endl;
98  cout << myname << " Uncompressed size: " << dig.Samples() << endl;
99  cout << myname << " Pedestal: " << dig.GetPedestal() << endl;
100  cout << myname << " Channel: " << dig.Channel() << endl;
101  assert(dig.Samples() == nsig);
102  assert(dig.Channel() == chan);
103  assert(dig.GetPedestal() == ped);
104 
105  cout << myname << line << endl;
106  cout << myname << "Create the expected flag vector." << endl;
107  AdcFlagVector expflags(nsig, AdcGood);
108  for ( unsigned int isig=0; isig<nsig; ++isig) {
109  AdcCount adc = adcsin[isig];
110  AdcCount adclow = adc & lowbits;
111  if ( adc <= 0 ) expflags[isig] = AdcUnderflow;
112  else if ( adc >= 4095 ) expflags[isig] = AdcOverflow;
113  else if ( adclow == 0 ) expflags[isig] = AdcStuckOff;
114  else if ( adclow == lowbits ) expflags[isig] = AdcStuckOn;
115  }
116 
117  cout << myname << line << endl;
118  cout << myname << "Fetch raw digit extract service." << endl;
120  hrdx->print();
121 
122  cout << myname << line << endl;
123  cout << myname << "Extract data from digit." << endl;
124  AdcChannelData acd;
125  acd.digit = &dig;
126  assert( hrdx->extract(acd) == 0 );
127  const AdcCountVector& raw = acd.raw;
128  const AdcSignalVector& sigs = acd.samples;
129  const AdcFlagVector& flags = acd.flags;
130  AdcChannel chanout = acd.channel();
131  AdcSignal pedout = acd.pedestal;
132  cout << myname << "Output raw vector size: " << sigs.size() << endl;
133  cout << myname << "Output prep vector size: " << sigs.size() << endl;
134  cout << myname << " Output flags size: " << flags.size() << endl;
135  cout << myname << " Pedestal: " << pedout << endl;
136  assert( raw.size() == nsig );
137  assert( sigs.size() == nsig );
138  assert( flags.size() == nsig );
139  assert( chanout == chan );
140  assert( pedout == ped );
141  for ( unsigned int isig=0; isig<nsig; ++isig ) {
142  cout << setw(4) << isig << ": " << setw(4) << adcsin[isig]
143  << fixed << setprecision(1) << setw(8) << sigs[isig]
144  << " [" << flags[isig] << "]" << endl;
145  if ( flags[isig] == AdcGood ) assert( sigequal(sigs[isig], sigsin[isig]) );
146  assert( flags[isig] == expflags[isig] );
147  }
148 
149  return 0;
150 }
std::vector< AdcCount > AdcCountVector
Definition: AdcTypes.h:19
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
virtual int extract(AdcChannelData &acd) const =0
float AdcSignal
Definition: AdcTypes.h:21
std::vector< AdcFlag > AdcFlagVector
Definition: AdcTypes.h:30
int16_t adc
Definition: CRTFragment.hh:202
const AdcFlag AdcUnderflow
Definition: AdcTypes.h:33
Raw data description.
const raw::RawDigit * digit
no compression
Definition: RawTypes.h:9
static void load_services(std::string const &config)
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
const AdcFlag AdcGood
Definition: AdcTypes.h:32
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const =0
const AdcFlag AdcOverflow
Definition: AdcTypes.h:34
const AdcFlag AdcStuckOn
Definition: AdcTypes.h:37
AdcCountVector raw
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
const AdcFlag AdcStuckOff
Definition: AdcTypes.h:36
Channel channel() const
AdcSignal pedestal
unsigned int AdcChannel
Definition: AdcTypes.h:50
void line(double t, double *p, double &x, double &y, double &z)
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
short AdcCount
Definition: AdcTypes.h:18
AdcSignalVector samples
bool sigequal(AdcSignal sig1, AdcSignal sig2)
QTextStream & endl(QTextStream &s)
AdcFlagVector flags