Typedefs | Functions
test_FembMappedAdcModifier.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include "dunecore/DuneInterface/Tool/TpcDataTool.h"
#include "dunecore/ArtSupport/DuneToolManager.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using Index = unsigned int
 

Functions

int test_FembMappedAdcModifier (bool useExistingFcl=false)
 
int main (int argc, char *argv[])
 

Typedef Documentation

using Index = unsigned int

Definition at line 25 of file test_FembMappedAdcModifier.cxx.

Function Documentation

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

Definition at line 196 of file test_FembMappedAdcModifier.cxx.

196  {
197  bool useExistingFcl = false;
198  if ( argc > 1 ) {
199  string sarg(argv[1]);
200  if ( sarg == "-h" ) {
201  cout << "Usage: " << argv[0] << " [ARG]" << endl;
202  cout << " If ARG = true, existing FCL file is used." << endl;
203  return 0;
204  }
205  useExistingFcl = sarg == "true" || sarg == "1";
206  }
207  return test_FembMappedAdcModifier(useExistingFcl);
208 }
int test_FembMappedAdcModifier(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_FembMappedAdcModifier ( bool  useExistingFcl = false)

Definition at line 29 of file test_FembMappedAdcModifier.cxx.

29  {
30  const string myname = "test_FembMappedAdcModifier: ";
31 #ifdef NDEBUG
32  cout << myname << "NDEBUG must be off." << endl;
33  abort();
34 #endif
35  string line = "-----------------------------";
36 
37  cout << myname << line << endl;
38  string fclfile = "test_FembMappedAdcModifier.fcl";
39  if ( ! useExistingFcl ) {
40  cout << myname << "Creating top-level FCL." << endl;
41  ofstream fout(fclfile.c_str());
42  fout << "tools: {" << endl;
43  fout << " modtool100: {" << endl;
44  fout << " tool_type: FembLinearCalibration" << endl;
45  fout << " LogLevel: 1" << endl;
46  fout << " Units: fC" << endl;
47  fout << " Gains: [1.0, 2.0, 3.0, 4.0, 5.0]" << endl;
48  fout << " AdcMin: 0" << endl;
49  fout << " AdcMins: [1200, 1300, 1400, 1500, 1600]" << endl;
50  fout << " AdcMax: 1800" << endl;
51  fout << " AdcMaxs: []" << endl;
52  fout << " }" << endl;
53  fout << " modtool101: {" << endl;
54  fout << " tool_type: FembLinearCalibration" << endl;
55  fout << " LogLevel: 1" << endl;
56  fout << " Units: fC" << endl;
57  fout << " Gains: [1.0, 2.0, 3.0, 4.0, 5.0]" << endl;
58  fout << " AdcMin: 0" << endl;
59  fout << " AdcMins: [1200, 1300, 1400, 1500, 1600]" << endl;
60  fout << " AdcMax: 1800" << endl;
61  fout << " AdcMaxs: []" << endl;
62  fout << " }" << endl;
63  fout << " modtool102: {" << endl;
64  fout << " tool_type: FembLinearCalibration" << endl;
65  fout << " LogLevel: 1" << endl;
66  fout << " Units: fC" << endl;
67  fout << " Gains: [1.0, 2.0, 3.0, 4.0, 5.0]" << endl;
68  fout << " AdcMin: 0" << endl;
69  fout << " AdcMins: [1200, 1300, 1400, 1500, 1600]" << endl;
70  fout << " AdcMax: 1800" << endl;
71  fout << " AdcMaxs: []" << endl;
72  fout << " }" << endl;
73  fout << " modtool103: {" << endl;
74  fout << " tool_type: FembLinearCalibration" << endl;
75  fout << " LogLevel: 1" << endl;
76  fout << " Units: fC" << endl;
77  fout << " Gains: [1.0, 2.0, 3.0, 4.0, 5.0]" << endl;
78  fout << " AdcMin: 0" << endl;
79  fout << " AdcMins: [1200, 1300, 1400, 1500, 1600]" << endl;
80  fout << " AdcMax: 1800" << endl;
81  fout << " AdcMaxs: []" << endl;
82  fout << " }" << endl;
83  fout << " modtool104: {" << endl;
84  fout << " tool_type: FembLinearCalibration" << endl;
85  fout << " LogLevel: 1" << endl;
86  fout << " Units: fC" << endl;
87  fout << " Gains: [1.0, 2.0, 3.0, 4.0, 5.0]" << endl;
88  fout << " AdcMin: 0" << endl;
89  fout << " AdcMins: [1200, 1300, 1400, 1500, 1600]" << endl;
90  fout << " AdcMax: 1800" << endl;
91  fout << " AdcMaxs: []" << endl;
92  fout << " }" << endl;
93  fout << " mytool: {" << endl;
94  fout << " tool_type: FembMappedAdcModifier" << endl;
95  fout << " LogLevel: 1" << endl;
96  fout << " ToolBase: modtool" << endl;
97  fout << " DirName: \"\"" << endl;
98  fout << " }" << endl;
99  fout << "}" << endl;
100  fout.close();
101  } else {
102  cout << myname << "Using existing top-level FCL." << endl;
103  }
104 
105  cout << myname << line << endl;
106  cout << myname << "Fetching tool manager." << endl;
108  assert ( ptm != nullptr );
109  DuneToolManager& tm = *ptm;
110  tm.print();
111  assert( tm.toolNames().size() == 6 );
112 
113  cout << myname << line << endl;
114  cout << myname << "Fetching tool." << endl;
115  auto pmod = tm.getPrivate<TpcDataTool>("mytool");
116  assert( pmod != nullptr );
117 
118  cout << myname << line << endl;
119  cout << myname << "Create data." << endl;
120  AdcChannelData acd0;
121  acd0.pedestal = 1000.0;
122  acd0.raw.push_back(1100);
123  acd0.raw.push_back(1200);
124  acd0.raw.push_back(1300);
125  acd0.raw.push_back(1400);
126  acd0.raw.push_back(1500);
127  acd0.pedestal = 1000.0;
128  AdcSignal dped = 0.0;
129  AdcChannelDataMap acds;
130  for ( AdcChannel icha=0; icha<5; ++icha ) {
131  AdcChannelData& acd = acds[icha];
132  acd.setChannelInfo(icha, 100+icha);
133  for ( AdcCount& adc : acd0.raw ) acd.raw.push_back(adc+dped);
134  acd.pedestal = acd0.pedestal + dped;
135  dped += 100.0;
136  }
137  int w = 8;
138  Index nsam = acd0.raw.size();
139  for ( auto& ient : acds ) {
140  AdcChannel icha = ient.first;
141  AdcChannelData& acd = ient.second;
142  AdcSignalVector sigchk(nsam);
143  for ( Index isam=0; isam<nsam; ++isam ) {
144  sigchk[isam] = (icha+1)*(acd0.raw[isam] - acd0.pedestal);
145  }
146  cout << myname << line << endl;
147  cout << myname << "Channel " << icha << endl;
148  DataMap res = pmod->update(acd);
149  cout << myname << "Modify:" << endl;
150  res.print();
151  Index nsamRes = res.getInt("calibSampleCount");
152  Index nunder = res.getInt("calibUnderflowCount");
153  Index nover = res.getInt("calibOverflowCount");
154  assert( res.status() == 0 );
155  assert( nsamRes == nsam );
156  cout << myname << " Raw:";
157  for ( AdcCount adc : acd.raw ) cout << setw(w) << adc;
158  cout << endl;
159  cout << myname << " Prep:";
160  for ( AdcSignal sam : acd.samples ) cout << setw(w) << sam;
161  cout << endl;
162  cout << myname << "Check:";
163  for ( AdcSignal sam : sigchk ) cout << setw(w) << sam;
164  cout << endl;
165  cout << myname << " Flag:";
166  for ( AdcFlag flg : acd.flags ) cout << setw(w) << flg;
167  cout << endl;
168  cout << myname << "Check samples." << endl;
169  for ( Index isam=0; isam<nsam; ++isam ) {
170  assert( acd.samples[isam] == sigchk[isam] );
171  }
172  cout << myname << "Check under and overflows." << endl;
173  Index nunderExp = 2;
174  Index noverExp = icha > 2 ? icha - 2 : 0;
175  assert ( nunder == nunderExp );
176  assert ( nover == noverExp );
177  for ( Index isam=0; isam<nsam; ++isam ) {
178  AdcFlag flgExp = isam < nunderExp ? AdcUnderflow :
179  isam >= nsam-noverExp ? AdcOverflow :
180  AdcGood;
181  if ( acd.flags[isam] != flgExp ) {
182  cout << myname << "Sample " << isam << ": " << acd.flags[isam]
183  << " != " << flgExp << endl;
184  }
185  assert( acd.flags[isam] == flgExp );
186  }
187  }
188 
189  cout << myname << line << endl;
190  cout << myname << "Done." << endl;
191  return 0;
192 }
short AdcFlag
Definition: AdcTypes.h:29
const std::vector< std::string > & toolNames() const
float AdcSignal
Definition: AdcTypes.h:21
int16_t adc
Definition: CRTFragment.hh:202
const AdcFlag AdcUnderflow
Definition: AdcTypes.h:33
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
const AdcFlag AdcGood
Definition: AdcTypes.h:32
int status() const
Definition: DataMap.h:202
void setChannelInfo(ChannelInfoPtr pchi)
const AdcFlag AdcOverflow
Definition: AdcTypes.h:34
AdcCountVector raw
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
AdcSignal pedestal
int getInt(Name name, int def=0) const
Definition: DataMap.h:218
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
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
short AdcCount
Definition: AdcTypes.h:18
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags