64 const string myname =
"test_ToolBasedRawDigitPrepService: ";
66 cout << myname <<
"NDEBUG must be off." <<
endl;
69 string line =
"-----------------------------";
71 cout << myname << line <<
endl;
72 cout << myname <<
"Create top-level FCL." <<
endl;
73 std::string const fclfile{
"test_ToolBasedRawDigitPrepService.fcl"};
74 if (!useExistingFcl) {
75 std::ofstream
fout{fclfile};
76 fout <<
"#include \"services_dune.fcl\"" <<
endl;
77 fout <<
"services: @local::dune35t_services_legacy" <<
endl;
78 fout <<
"#include \"tools_dune.fcl\"" <<
endl;
79 fout <<
"services.AdcWireBuildingService: {" <<
endl;
80 fout <<
" service_provider: StandardAdcWireBuildingService" <<
endl;
83 fout <<
"services.RawDigitPrepService: {" <<
endl;
84 fout <<
" service_provider: ToolBasedRawDigitPrepService" <<
endl;
90 fout <<
" \"rawAdcPlotter\"," <<
endl;
91 fout <<
" \"adcSampleFiller\"," <<
endl;
92 fout <<
" \"preparedAdcPlotter\"," <<
endl;
93 fout <<
" \"adcThresholdSignalFinder\"" <<
endl;
96 fout <<
" CallgrindToolNames: []" <<
endl;
100 std::ifstream
config{fclfile};
103 cout << myname << line <<
endl;
104 cout << myname <<
"Fetching tool manager." <<
endl;
106 assert ( ptm !=
nullptr );
114 cout << myname << line <<
endl;
115 cout << myname <<
"Create raw digits." <<
endl;
117 unsigned int nsig = 64;
120 unsigned int isig_stucklo = 15;
121 unsigned int isig_stuckhi = 25;
122 bool doSticky =
false;
124 AdcSignal peds[8] = {2000.2, 2010.1, 2020.3, 1990.4, 1979.6, 1979.2, 1995.0, 2001.3};
125 vector<RawDigit> digs;
126 map<AdcChannel, AdcCountVector> adcsmap;
127 map<AdcChannel, AdcFlagVector> expflagsmap;
129 for (
AdcChannel chan=0; chan<nchan; ++chan ) {
130 unsigned int isig1 = 10 + chan;
131 for (
unsigned int isig=0; isig<isig1; ++isig ) sigsin[chan].
push_back(0);
132 for (
unsigned int i=0; i<10; ++i ) sigsin[chan].
push_back(fac*i);
133 for (
unsigned int i=10; i<1000; --i ) sigsin[chan].
push_back(fac*i);
134 for (
unsigned int i=19; i<1000; --i ) sigsin[chan].
push_back(-sigsin[chan][i+isig1]);
135 for (
unsigned int isig=sigsin[chan].
size();
136 isig<nsig; ++isig ) sigsin[chan].
push_back(0);
137 assert(sigsin[chan].
size() == nsig);
139 for (
unsigned int isig=0; isig<nsig; ++isig) {
140 AdcSignal sig = sigsin[chan][isig] + peds[chan];
142 if ( sig > 0.0 ) adc =
int(sig+0.5);
143 if ( adc > 4095 ) adc = 4095;
146 if ( isig == isig_stucklo ) adc = adchigh;
147 if ( isig == isig_stuckhi ) adc = adchigh + lowbits;
149 adcsin.push_back(adc);
151 assert(adcsin.size() == nsig);
152 adcsmap[chan] = adcsin;
156 cout << myname <<
" Compressed size: " << dig.
NADC() <<
endl;
157 cout << myname <<
" Uncompressed size: " << dig.
Samples() <<
endl;
159 cout << myname <<
" Channel: " << dig.
Channel() <<
endl;
164 assert( adcsmap.size() == nchan );
166 cout << myname << line <<
endl;
167 cout << myname <<
"Create the expected flag vector." <<
endl;
168 for (
AdcChannel chan=0; chan<nchan; ++chan ) {
170 for (
unsigned int isig=0; isig<nsig; ++isig) {
174 else if ( adc >= 4095 ) expflags[isig] =
AdcOverflow;
175 else if ( doSticky ) {
177 else if ( adclow == lowbits ) expflags[isig] =
AdcStuckOn;
180 expflagsmap[chan] = expflags;
183 cout << myname << line <<
endl;
184 cout << myname <<
"Fetch raw digit prep service." <<
endl;
188 cout << myname << line <<
endl;
189 cout << myname <<
"Prep data from digits." <<
endl;
193 for (
unsigned int idig=0; idig<digs.size(); ++idig ) {
195 assert( prepdigs.find(dig.
Channel()) == prepdigs.end() );
197 data.setChannelInfo(dig.
Channel());
198 data.digitIndex = idig;
200 data.setEventInfo(123, 1);
202 std::vector<recob::Wire> wires;
203 wires.reserve(nchan);
204 vector<string> snames;
206 assert( intStates.dataMaps.size() == snames.size() );
207 assert( intStates.wires.size() == snames.size() );
209 assert( hrdp->
prepare(clockData, prepdigs, &wires, &intStates) == 0 );
210 cout << myname <<
" # prepared digit channels: " << prepdigs.size() <<
endl;
211 cout << myname <<
" # wire channels: " << wires.size() <<
endl;
212 cout << myname <<
" # intermediate state channels: " << intStates.dataMaps.size() <<
endl;
213 for (
const auto& namedadm : intStates.dataMaps ) {
214 string sname = namedadm.first;
216 auto iwco = intStates.wires.find(sname);
217 const vector<Wire>* pwires =
nullptr;
218 if ( iwco == intStates.wires.end() ) {
219 cout << myname <<
" Wires not found for intermediate state " << sname <<
"." <<
endl;
220 assert( iwco != intStates.wires.end() );
222 pwires = iwco->second;
224 assert( pwires !=
nullptr );
225 cout << myname <<
" State " << sname <<
" has " << adm.size() <<
" ADC channels";
226 if ( pwires !=
nullptr ) cout <<
" and " << pwires->size() <<
" wires";
228 assert( pwires->size() == adm.size() );
230 cout << myname <<
" # intermediate wires: " << intStates.wires.size() <<
endl;
239 cout << myname <<
"----- Channel " << chan <<
endl;
240 cout << myname <<
" Final signal tick count: " << sigs.size() <<
endl;
241 cout << myname <<
" Final flag tick count: " << flags.size() <<
endl;
242 cout << myname <<
" Final flag tick count: " << flags.size() <<
endl;
243 cout << myname <<
" Pedestal: " << ped <<
endl;
244 cout << myname <<
" samples[0]: " << sigs[0] <<
endl;
245 cout << myname <<
"Check final data." <<
endl;
246 assert( pwire !=
nullptr );
248 assert( sigs.size() == nsig );
249 assert( flags.size() == nsig );
250 assert( pdig !=
nullptr );
251 assert( pdig == &digs[chan] );
252 assert( pdig->
Channel() == chan );
253 assert( ichdat->second.digitIndex == chan );
255 assert( expflagsmap[chan].
size() == nsig );
257 cout << myname <<
"Fetch intermediate data." <<
endl;
258 vector<const AdcSignalVector*> intSigs;
259 vector<const AdcFlagVector*> intFlags;
260 cout << myname <<
" ...bad" <<
endl;
261 auto iacd = intStates.dataMaps.find(
"bad");
262 assert( iacd == intStates.dataMaps.end() );
263 string header =
" ch-tk raw";
264 unsigned int nintexp = 0;
265 for (
string sname : snames ) {
266 cout << myname <<
" ..." << sname <<
endl;
267 iacd = intStates.dataMaps.find(sname);
268 assert( iacd != intStates.dataMaps.end() );
270 intSigs.push_back(&intAcd.samples);
271 intFlags.push_back(&intAcd.flags);
272 assert( intAcd.wire !=
nullptr );
273 for (
unsigned int i=sname.size(); i<12; ++i ) header +=
" ";
276 cout << myname <<
" Checking sample and flag tick counts." <<
endl;
277 assert( intSigs.back() != nullptr );
278 assert( intSigs.back()->size() != 0 );
279 assert( intSigs.back()->size() == nsig );
280 assert( intFlags.back() != nullptr );
281 assert( intFlags.back()->size() != 0 );
282 assert( intFlags.back()->size() == nsig );
283 cout << myname <<
" Wire ROI count: " << intAcd.wire->SignalROI().n_ranges() <<
endl;
284 cout << myname <<
" Wire Tick count: " << intAcd.wire->SignalROI().size() <<
endl;
285 assert( intAcd.wire->SignalROI().n_ranges() == 1 );
286 assert( intAcd.wire->SignalROI().size() == nsig );
289 assert( intStates.dataMaps.size() == nintexp );
291 assert( intSigs.size() == nintexp );
292 assert( intFlags.size() == nintexp );
294 cout << myname <<
"Display intermediate and final samples." <<
endl;
295 cout << myname << header <<
endl;
296 for (
unsigned int isig=0; isig<nsig; ++isig ) {
298 cout <<
setw(4) << chan <<
"-" 299 <<
setw(2) << isig <<
": " <<
setw(4) << adcsmap[chan][isig];
300 for (
unsigned int ista=0; ista<intSigs.size(); ++ista ) {
302 cout <<
" [" << intFlags[ista]->at(isig) <<
"]";
305 <<
" [" << flags[isig] <<
"]" <<
endl;
306 assert( adcsmap[chan][isig] == acd.
raw[isig] );
307 if ( flags[isig] ==
AdcGood ) assert(
sigequal(sigs[isig], sigsin[chan][isig]) );
308 assert(
flagequal(flags[isig], expflags[isig]) );
312 cout << myname << line <<
endl;
313 cout <<
"Done." <<
endl;
float GetPedestal() const
std::vector< AdcCount > AdcCountVector
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Collection of charge vs time digitized from a single readout channel.
size_type size() const
Returns the size of the vector.
std::vector< AdcFlag > AdcFlagVector
ChannelID_t Channel() const
DAQ channel this raw data was read from.
const AdcFlag AdcUnderflow
const raw::RawDigit * digit
virtual int prepare(detinfo::DetectorClocksData const &clockData, AdcChannelDataMap &prepdigs, std::vector< recob::Wire > *pwires=nullptr, WiredAdcChannelDataMap *pwiredData=nullptr) const =0
static void load_services(std::string const &config)
Q_EXPORT QTSManip setprecision(int p)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
fInnerVessel push_back(Point(-578.400000, 0.000000, 0.000000))
const AdcFlag AdcOverflow
size_t NADC() const
Number of elements in the compressed ADC sample vector.
const RegionsOfInterest_t & SignalROI() const
Returns the list of regions of interest.
Q_EXPORT QTSManip setw(int w)
const AdcFlag AdcStuckOff
std::vector< AdcSignalVector > AdcSignalVectorVector
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
void line(double t, double *p, double &x, double &y, double &z)
Class holding the regions of interest of signal from a channel.
std::vector< AdcSignal > AdcSignalVector
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const =0
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
QTextStream & endl(QTextStream &s)