29 using std::ostringstream;
30 using std::istringstream;
49 Plot(
Index npad) : topman(400, 800) {
50 topman.
split(1, npad);
52 void setRange(
float a_ymin,
float a_ymax) {
56 int addData(
const TpcData& tpd,
Name roinam,
int col,
int lwid,
int lsty) {
57 string myname =
"Plot::addData: ";
66 for (
auto& ent : data ) {
68 Index nsam = sams.size();
69 Index icha = ent.first;
71 string slab = roinam.size() ? roinam :
"ADC";
72 if ( dbg > 0 ) cout << myname << slab <<
" sample count is " << nsam <<
" for channel " 75 if ( pman ==
nullptr ) {
76 cout << myname <<
"ERROR: Unable to find subpad " << iman <<
endl;
80 Name hnam =
"hch" + scha;
81 Name httl =
"Channel " + scha +
";Tick;Charge";
82 TH1* ph =
new TH1F(hnam.c_str(), httl.c_str(), nsam, 0, nsam);
83 ph->SetDirectory(
nullptr);
85 ph->SetLineColor(col);
86 ph->SetLineWidth(lwid);
87 ph->SetLineStyle(lsty);
88 if ( roinam.size() ) {
91 assert( rois.size() == 1 );
93 assert( roi.sampleSize() == nsam );
94 for (
Index isam=0; isam<nsam; ++isam ) {
95 float val = roi.value(icha, isam);
96 if ( dbg > 2 || (dbg > 1 && sams[isam]) ) {
97 cout << myname <<
"... " <<
setw(3) << isam <<
": " << val <<
endl;
99 ph->Fill(isam+1, val);
102 for (
Index isam=0; isam<nsam; ++isam ) {
103 if ( dbg > 2 || (dbg > 1 && sams[isam]) ) {
104 cout << myname <<
"... " <<
setw(3) << isam <<
": " << sams[isam] <<
endl;
106 ph->Fill(isam+1, sams[isam]);
121 string myname =
"Plot::print: ";
130 if ( x1 == x2 )
return true;
131 if ( x1 > 0.0 && x2 > 0.0 ) {
132 return fabs(x1-x2)/x1+x2 < 1.e-6;
142 const string mypre =
"test_Tpc2dDeconvolute";
143 const string myname = mypre +
": ";
145 cout << myname <<
"NDEBUG must be off." <<
endl;
148 string line =
"-----------------------------";
150 cout << myname << line <<
endl;
151 string fclfile =
"test_Tpc2dDeconvolute.fcl";
156 if ( ! useExistingFcl ) {
157 cout << myname <<
"Creating top-level FCL." <<
endl;
158 ofstream
fout(fclfile.c_str());
160 fout <<
" [0.2, 0.4, 0.3, 0.1]," <<
endl;
161 fout <<
" [-0.04, -0.08, -0.06, -0.02]," <<
endl;
162 fout <<
" [0.04, 0.08, 0.06, 0.02]" <<
endl;
166 fout <<
" tool_type: Adc2dConvolute" <<
endl;
168 fout <<
" ResponseVectors: @local::data.response" <<
endl;
169 fout <<
" ResponseCenter: 1" <<
endl;;
172 fout <<
" MinChannel: 100" <<
endl;;
173 fout <<
" MaxChannel: 104" <<
endl;;
176 fout <<
" tool_type: AdcToRoi2d" <<
endl;
181 fout <<
" tool_type: Tpc2dDeconvolute" <<
endl;
184 fout <<
" ResponseVectors: @local::data.response" <<
endl;
185 fout <<
" ResponseCenter: 1" <<
endl;
186 fout <<
" InPath: \"conv\"" <<
endl;
187 fout <<
" OutPath: \"dcon\"" <<
endl;
188 fout <<
" SampleSigma: 2.0" <<
endl;
189 fout <<
" ChannelSigma: 0.0" <<
endl;
190 fout <<
" LowFilterPower: 0.0" <<
endl;
191 fout <<
" LowFilterWidth: 0.0" <<
endl;
196 cout << myname <<
"Using existing top-level FCL." <<
endl;
199 cout << myname << line <<
endl;
200 cout << myname <<
"Fetching tool manager." <<
endl;
202 assert ( ptm !=
nullptr );
207 cout << myname << line <<
endl;
208 cout << myname <<
"Fetching tools." <<
endl;
210 assert( pcon !=
nullptr );
212 assert( pdco !=
nullptr );
214 cout << myname << line <<
endl;
215 cout << myname <<
"Create empty input data." <<
endl;
221 for (
Index icha=100; icha<105; ++icha ) {
227 std::map<Index,float> expAreas;
228 for (
Index icha=100; icha<106; ++icha ) expAreas[icha] = 0.0;
234 cout << myname <<
"Add signal " << ++isig <<
endl;
236 data[102].samples[20] = 100.0*sfac;
237 expAreas[100] += +20.0*sfac;
238 expAreas[101] += -20.0*sfac;
239 expAreas[102] += 100.0*sfac;
240 expAreas[103] += -20.0*sfac;
241 expAreas[104] += +20.0*sfac;
245 cout << myname <<
"Add signal " << ++isig <<
endl;
246 data[103].samples[10] = 100.0;
247 expAreas[101] += 20.0;
248 expAreas[102] += -20.0;
249 expAreas[103] += 100.0;
250 expAreas[104] += -20.0;
253 cout << myname << line <<
endl;
254 cout << myname <<
"Check signals." <<
endl;
256 cout << myname <<
"Add signal " << ++isig <<
endl;
257 data[101].samples[30] = 100.0;
258 expAreas[100] += -20.0;
259 expAreas[101] += 100.0;
260 expAreas[102] += -20.0;
261 expAreas[103] += 20.0;
264 cout << myname <<
"Check signals." <<
endl;
265 cout << myname <<
"Signal count: " << nsig <<
endl;
266 assert( isig == nsig );
268 cout << myname << line <<
endl;
269 string fnam =
"noconvhist.png";
270 cout << myname <<
"Create plot " << fnam <<
endl;
271 Plot plt1(data.size());
273 plt1.addData(tpd,
"", lc.green(), 2, 1);
274 plt1.setRange(0, 105);
277 cout << myname << line <<
endl;
278 cout << myname <<
"Call convolution tool." <<
endl;
279 DataMap ret = pcon->updateMap(data);
282 assert( ret.
getInt(
"responseVectorCount") == 3 );
283 assert( ret.
getInt(
"channelMin") == 100 );
284 assert( ret.
getInt(
"channelMax") == 104 );
286 cout << myname << line <<
endl;
287 cout << myname <<
"Copy samples to ROI." <<
endl;
296 Index& kcha = idxs[0];
297 Index& ksam = idxs[1];
298 for ( kcha=0; kcha<ncha; ++kcha ) {
299 for ( ksam=0; ksam<nsam; ++ksam ) {
300 roi.data().setValue(idxs, data[chan0+kcha].samples[ksam]);
305 cout << myname << line <<
endl;
306 fnam =
"convhist.png";
307 cout << myname <<
"Create plot " << fnam <<
endl;
308 Plot plt2(data.size());
309 plt2.setRange(-10, 45);
310 plt2.addData(tpd,
"", lc.blue(), 2, 1);
311 plt2.addData(tpd,
"conv", lc.red(), 2, 2);
314 cout << myname << line <<
endl;
315 cout << myname <<
"Check convoluted areas" <<
endl;
316 cout << myname <<
"Chan Nsam Area" <<
endl;
317 cout << myname <<
"---- ---- -----------" <<
endl;
318 for (
const auto& kdat : data ) {
319 Index icha = kdat.first;
323 for (
float sam : sams ) area +=
sam;
324 cout << myname <<
setw(4) << icha <<
setw(6) << nsam <<
setw(13) << area
325 <<
" (" << expAreas[icha] <<
")" <<
endl;
329 cout << myname << line <<
endl;
330 cout << myname <<
"Call deconvolution tool." <<
endl;
331 ret = pdco->updateTpcData(tpd);
334 assert( ret.
getInt(
"dcoNroiIn") == 1 );
335 assert( ret.
getInt(
"dcoNroiOut") == 1 );
338 cout << myname <<
"Input normalization: " 341 cout << myname <<
"Output normaization: " 347 cout << myname << line <<
endl;
348 fnam =
"dcovhist.png";
349 cout << myname <<
"Create plot " << fnam <<
endl;
350 Plot plt3(data.size());
351 plt3.setRange(-10, 45);
352 plt3.addData(tpd,
"", lc.blue(), 2, 1);
353 plt2.addData(tpd,
"conv", lc.red(), 2, 2);
354 plt3.addData(tpd,
"dcon", lc.orange(), 2, 3);
357 cout << myname << line <<
endl;
358 cout << myname <<
"Done." <<
endl;
365 bool useExistingFcl =
false;
367 string sarg(argv[1]);
368 if ( sarg ==
"-h" ) {
369 cout <<
"Usage: " << argv[0] <<
" [KEEPFCL [NOISE [SIGMAFIL [NSAM [SETSEED]]]]]" <<
endl;
370 cout <<
" KEEPFCL = if 1 (or true), existing FCL file is used [false]" <<
endl;
373 useExistingFcl = sarg ==
"true" || sarg ==
"1";
int setGridY(bool flag=true)
int add(unsigned int ipad, TObject *pobj, std::string sopt="", bool replace=false)
ChannelGroupService::Name Name
int split(Index nx, Index ny)
TpcData * addTpcData(Name nam, bool copyAdcData=true)
void print(std::ostream *pout) const
bool checkEqual(string s1, string s2)
AdcDataVector & getAdcData()
int test_Tpc2dDeconvolute(bool useExistingFcl)
void setChannelInfo(ChannelInfoPtr pchi)
DataArray::IndexArray IndexArray
void setEventInfo(EventInfoPtr pevi)
TPadManipulator * man(unsigned int ipad=0)
Q_EXPORT QTSManip setw(int w)
TpcData * getTpcData(Name nam)
int getInt(Name name, int def=0) const
std::vector< Tpc2dRoi > Tpc2dRoiVector
void line(double t, double *p, double &x, double &y, double &z)
int main(int argc, char *argv[])
std::vector< AdcSignal > AdcSignalVector
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
int setRangeY(double y1, double y2)
std::string to_string(ModuleType const mt)
int print(std::string fname, std::string spat="{,}")
Tpc2dRoiVector & get2dRois()
QTextStream & endl(QTextStream &s)