test_StandardAdcWireBuildingService.cxx
Go to the documentation of this file.
1 // test_StandardAdcWireBuildingService.cxx
2 //
3 // David Adams
4 // May 2016
5 //
6 // Test StandardAdcWireBuildingService.
7 //
8 
9 #include <string>
10 #include <iostream>
11 #include <sstream>
12 #include <fstream>
13 #include <iomanip>
18 
19 #undef NDEBUG
20 #include <cassert>
21 
22 using std::string;
23 using std::vector;
24 using std::cout;
25 using std::endl;
26 using std::istringstream;
27 using std::ofstream;
28 using std::setw;
29 using std::setprecision;
30 using std::fixed;
31 using art::ServiceHandle;
32 using recob::Wire;
33 
34 typedef vector<unsigned int> IndexVector;
35 
36 //**********************************************************************
37 
38 int test_StandardAdcWireBuildingService(int a_LogLevel =1) {
39  const string myname = "test_StandardAdcWireBuildingService: ";
40 #ifdef NDEBUG
41  cout << myname << "NDEBUG must be off." << endl;
42  abort();
43 #endif
44  string line = "-----------------------------";
45 
46  cout << myname << line << endl;
47  cout << myname << "Create top-level FCL." << endl;
48 
49  std::ostringstream oss;
50  oss << "#include \"services_dune.fcl\"" << endl;
51  oss << "services: @local::dune35t_services_legacy" << endl;
52  oss << "services.AdcWireBuildingService: {" << endl;
53  oss << " service_provider: StandardAdcWireBuildingService" << endl;
54  oss << " LogLevel: " << a_LogLevel << endl;
55  oss << "}" << endl;
57 
58  cout << myname << line << endl;
59  float fac = 250.0;
60  cout << myname << "Create a response function." << endl;
61  const int nsigshape = 10;
62  AdcSignalVector sigshape;
63  for ( unsigned int isig=0; isig<5; ++isig ) sigshape.push_back(fac*isig);
64  for ( unsigned int isig=0; isig<5; ++isig ) sigshape.push_back(-sigshape.at(5-isig-1));
65  assert( sigshape.size() == nsigshape );
66 
67  cout << myname << line << endl;
68  cout << myname << "Create digits." << endl;
69  const unsigned int ndig = 4;
70  const unsigned int ntrk = 3;
71  cout << myname << " Digit count: " << ndig << endl;
72  cout << myname << " Track count: " << ntrk << endl;
73  std::vector<raw::RawDigit> digits;
74  digits.reserve(ndig);
75  unsigned int sigoff[ntrk][ndig];
76  sigoff[0][0] = 10;
77  sigoff[0][1] = 11;
78  sigoff[0][2] = 12;
79  sigoff[0][3] = 13;
80  sigoff[1][0] = 30;
81  sigoff[1][1] = 32;
82  sigoff[1][2] = 34;
83  sigoff[1][3] = 36;
84  sigoff[2][0] = 60;
85  sigoff[2][1] = 59;
86  sigoff[2][2] = 58;
87  sigoff[2][3] = 57;
88  unsigned int nsig = 80;
89  float ped[ndig] = {2000.2, 2000.4, 2001.0, 1999.5};
90  unsigned int chan[ndig] = {120, 121, 122, 123};
91  AdcSignalVector sigsin(nsig, 0.0);
92  AdcChannelDataMap acds;
93  for ( unsigned int idig=0; idig<ndig; ++idig ) {
94  cout << myname << " Digit " << idig << endl;
95  for ( int isig=0; isig<10; ++isig ) {
96  sigsin[sigoff[0][idig]+isig] += sigshape[isig];
97  sigsin[sigoff[1][idig]+isig] += sigshape[isig];
98  sigsin[sigoff[2][idig]+isig] += sigshape[isig];
99  }
100  assert(sigsin.size() == nsig);
101  AdcCountVector adcsin;
102  for ( unsigned int isig=0; isig<nsig; ++isig) {
103  AdcSignal sig = sigsin[isig] + ped[idig];
104  AdcCount adc = 0.0;
105  if ( sig > 0.0 ) adc = int(sig+0.5);
106  if ( adc > 4095 ) adc = 4095;
107  adcsin.push_back(adc);
108  }
109  assert(adcsin.size() == nsig);
110  raw::RawDigit dig(chan[idig], nsig, adcsin, raw::kNone);
111  dig.SetPedestal(ped[idig]);
112  cout << myname << " Compressed size: " << dig.NADC() << endl;
113  cout << myname << " Uncompressed size: " << dig.Samples() << endl;
114  cout << myname << " Pedestal: " << dig.GetPedestal() << endl;
115  cout << myname << " Channel: " << dig.Channel() << endl;
116  assert(dig.Samples() == nsig);
117  assert(dig.Channel() == chan[idig]);
118  assert(dig.GetPedestal() == ped[idig]);
119  AdcRoiVector rois;
120  rois.push_back(AdcRoi(sigoff[0][idig], sigoff[0][idig]+nsigshape));
121  rois.push_back(AdcRoi(sigoff[1][idig], sigoff[1][idig]+nsigshape));
122  rois.push_back(AdcRoi(sigoff[2][idig], sigoff[2][idig]+nsigshape));
123  cout << myname << " ROI count: " << rois.size() << endl;
124  for ( const AdcRoi& roi : rois ) {
125  cout << myname << " (" << roi.first << ", " << roi.second << ")" << endl;
126  }
127  cout << myname << " ROI count: " << rois.size() << endl;
128  AdcChannelData acd;
129  acd.samples = sigsin;
130  acd.setChannelInfo(chan[idig]);
131  acd.rois = rois;
132  digits.push_back(std::move(dig));
133  acd.digit = &digits.back();
134  const AdcChannelData& acdMoved = acds[chan[idig]] = std::move(acd);
135  cout << myname << " Moved data channel: " << chan[idig] << " ?= " << acdMoved.channel()
136  << " ?= " << acdMoved.digit->Channel() << endl;
137  }
138 
139  cout << myname << line << endl;
140  cout << myname << "Fetch wire building service." << endl;
142  hwib->print(cout, myname);
143 
144  cout << myname << line << endl;
145  cout << myname << "Build wires." << endl;
146  vector<Wire> wires;
147  wires.reserve(ndig);
148  for ( AdcChannelDataMap::value_type& iacd : acds ) {
149  AdcChannelData& acd = iacd.second;
150  assert( acd.channel() == iacd.first );
151  assert( acd.digit->Channel() == iacd.first );
152  int rstat = hwib->build(acd, &wires);
153  cout << myname << "Channel: " << acd.channel()
154  << ", # samples: " << acd.samples.size()
155  << ", # ROI: " << acd.rois.size()
156  << ", wire: " << acd.wire
157  << ", " << &(wires.back()) << endl;
158  assert( rstat == 0 );
159  cout << myname << " Size of Wire: " << sizeof(wires[0]) << endl;
160  for ( unsigned int iwir=0; iwir<wires.size(); ++iwir ) {
161  cout << myname << " Wire " << iwir << ": " << &(wires[iwir])
162  << " is for channel " << wires[iwir].Channel() << endl;
163  }
164  }
165 
166  cout << myname << line << endl;
167  cout << myname << "Check wires." << endl;
168  cout << myname << "Wire count: " << wires.size() << endl;
169  assert( wires.size() == ndig );
170  for ( unsigned int idig=0; idig<ndig; ++idig ) {
171  const Wire& wire = wires[idig];
172  const AdcChannelData& acd = acds[wire.Channel()];
173  cout << myname << " Wire " << idig << endl;
174  cout << myname << " Channel " << wire.Channel() << endl;
175  cout << myname << " Signal count: " << wire.NSignal() << endl;
176  cout << myname << " ROI count: " << wire.SignalROI().n_ranges() << endl;
177  cout << myname << " Wire: " << acd.wire << " ?= " << &(wires[idig]) << endl;
178  assert( wire.Channel() == acd.channel() );
179  assert( wire.NSignal() == acd.samples.size() );
180  assert( wire.SignalROI().size() == acd.samples.size() );
181  assert( wire.SignalROI().n_ranges() == acd.rois.size() );
182  }
183 
184  cout << myname << line << endl;
185  cout << myname << "Done." << endl;
186  return 0;
187 }
188 
189 //**********************************************************************
190 
191 int main(int argc, char* argv[]) {
192  int a_LogLevel = 1;
193  if ( argc > 1 ) {
194  istringstream ssarg(argv[1]);
195  ssarg >> a_LogLevel;
196  }
197  return test_StandardAdcWireBuildingService(a_LogLevel);
198 }
199 
200 //**********************************************************************
std::vector< AdcCount > AdcCountVector
Definition: AdcTypes.h:19
size_type n_ranges() const
Returns the internal list of non-void ranges.
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
size_type size() const
Returns the size of the vector.
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
struct vector vector
std::pair< AdcIndex, AdcIndex > AdcRoi
Definition: AdcTypes.h:54
int16_t adc
Definition: CRTFragment.hh:202
const recob::Wire * wire
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
virtual int build(AdcChannelData &data, WireVector *wires) const =0
void setChannelInfo(ChannelInfoPtr pchi)
AdcRoiVector rois
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:231
def move(depos, offset)
Definition: depos.py:107
int main(int argc, char *argv[])
const RegionsOfInterest_t & SignalROI() const
Returns the list of regions of interest.
Definition: Wire.h:228
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::vector< AdcRoi > AdcRoiVector
Definition: AdcTypes.h:55
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const =0
Channel channel() const
int test_StandardAdcWireBuildingService(int a_LogLevel=1)
void line(double t, double *p, double &x, double &y, double &z)
Class holding the regions of interest of signal from a channel.
Definition: Wire.h:118
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
short AdcCount
Definition: AdcTypes.h:18
vector< unsigned int > IndexVector
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
std::size_t NSignal() const
Returns the number of time ticks, or samples, in the channel.
Definition: Wire.h:229