31 const string myname =
"test_AdcChannelMetric: ";
33 cout << myname <<
"NDEBUG must be off." <<
endl;
36 string line =
"-----------------------------";
38 cout << myname << line <<
endl;
39 string fclfile =
"test_AdcChannelMetric.fcl";
40 string hname =
"hchped_tpp3c";
41 if ( ! useExistingFcl ) {
42 cout << myname <<
"Creating top-level FCL." <<
endl;
43 ofstream
fout(fclfile.c_str());
44 fout <<
"#include \"protodune_dataprep_tools.fcl\"" <<
endl;
46 fout <<
" tool_type: AdcChannelMetric" <<
endl;
48 fout <<
" Metric: \"pedestal\"" <<
endl;
50 fout <<
" PedestalReference: \"\"" <<
endl;
51 fout <<
" MetricSummaryView: \"\"" <<
endl;
52 fout <<
" ChannelRanges: [tpp3c, tpp3z]" <<
endl;
54 fout <<
" MetricMin: \"0.0\"" <<
endl;
55 fout <<
" MetricMax: \"2000.0*[gain]/14.0\"" <<
endl;
56 fout <<
" ChannelLineModulus: 200" <<
endl;
57 fout <<
" ChannelLinePattern: [20, 40, 60, 80, 100, 120, 140, 160, 180]" <<
endl;
58 fout <<
" ChannelLinePatternSolid: [0]" <<
endl;
59 fout <<
" HistName: \"hchped_%CRNAME%\"" <<
endl;
60 fout <<
" HistTitle: \"ADC pedestals for run %RUN% event %EVENT% %CRLABEL%\"" <<
endl;
61 fout <<
" MetricLabel: \"Pedestal [ADC counts]\"" <<
endl;
64 fout <<
" PlotUsesStatus: 0" <<
endl;
65 fout <<
" PlotFileName: \"mypeds-run%RUN%-evt%EVENT%_%CRNAME%.png\"" <<
endl;
66 fout <<
" RootFileName: \"\"" <<
endl;
67 fout <<
" MetadataFlags: [\"write\"]" <<
endl;
69 fout <<
"tools.runDataTool: {" <<
endl;
70 fout <<
" tool_type: FclRunDataTool" <<
endl;
72 fout <<
" FileNames: [\"rundata.fcl\"]" <<
endl;
75 ofstream fout2(
"rundata.fcl");
76 fout2 <<
"run: 123" <<
endl;
77 fout2 <<
"gain: 14.0" <<
endl;
78 fout2 <<
"shaping: 2.0" <<
endl;
81 cout << myname <<
"Using existing top-level FCL." <<
endl;
84 cout << myname << line <<
endl;
85 cout << myname <<
"Fetching tool manager." <<
endl;
87 assert ( ptm !=
nullptr );
92 cout << myname << line <<
endl;
93 cout << myname <<
"Fetching tool." <<
endl;
95 assert( padv !=
nullptr );
97 cout << myname << line <<
endl;
98 cout << myname <<
"Create data and call tool." <<
endl;
101 float peds[nped] = {701, 711, 733, 690, 688, 703, 720, 720, 695, 702,
102 410, 404, 388, 389, 400, 401, 410, 404, 395, 396};
103 vector<double> wf = {5.0, 20.1, 53.2, 80.6, 130.2, 160.1, 150.4, 125.7, 72.5, 41.3, 18.4,
104 -6.5, -34.9, -56.6, -88.9, -132.6, -170.8, -172.9, -144.6, -112.6,
105 -79.4, -44.9, -22.1, -12.6, -4.7};
106 for (
AdcIndex ievt=0; ievt<nevt; ++ievt ) {
107 cout << myname <<
"Event " << ievt <<
endl;
112 for (
AdcIndex icha=icha1; icha<icha2; ++icha ) {
113 std::pair<AdcChannelDataMap::iterator, bool> kdat = datamap.emplace(icha,
AdcChannelData());
118 float ped = peds[(icha-icha1)%nped];
121 for (
AdcIndex itic=0; itic<100; ++itic ) {
122 float xadc = ped + gRandom->Gaus(0.0, 10.0);
124 data.
raw.push_back(iadc);
125 data.
samples.push_back(iadc - ped);
127 AdcIndex tp = 10*ievt + 60 - 2.3*(icha-icha1);
128 for (
unsigned int iwf=0; iwf<wf.
size(); ++iwf ) {
129 unsigned int isam = tp+iwf;
130 if ( isam < data.
samples.size() ) {
131 data.
raw[isam] += wf[iwf];
135 for (
unsigned int isam=0; isam<data.
samples.size(); ++isam ) {
141 DataMap ret = padv->updateMap(datamap);
144 cout << myname <<
"Checking histogram " << hname <<
endl;
145 TH1* phout = ret.getHist(hname);
146 assert( phout !=
nullptr );
147 assert( phout->GetName() == hname );
148 assert( phout->GetEntries() == ncha );
149 for (
const auto& idata : datamap ) {
150 assert( idata.second.hasMetadata(
"pedestal") );
154 cout << myname << line <<
endl;
155 cout << myname <<
"Done." <<
endl;
void print(std::ostream *pout) const
void setChannelInfo(ChannelInfoPtr pchi)
bool hasMetadata(Name mname) const
void setEventInfo(EventInfoPtr pevi)
void line(double t, double *p, double &x, double &y, double &z)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
QTextStream & endl(QTextStream &s)