Typedefs | Functions
test_FembLinearCalibration.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_FembLinearCalibration (bool useExistingFcl=false)
 
int main (int argc, char *argv[])
 

Typedef Documentation

using Index = unsigned int

Definition at line 25 of file test_FembLinearCalibration.cxx.

Function Documentation

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

Definition at line 152 of file test_FembLinearCalibration.cxx.

152  {
153  bool useExistingFcl = false;
154  if ( argc > 1 ) {
155  string sarg(argv[1]);
156  if ( sarg == "-h" ) {
157  cout << "Usage: " << argv[0] << " [ARG]" << endl;
158  cout << " If ARG = true, existing FCL file is used." << endl;
159  return 0;
160  }
161  useExistingFcl = sarg == "true" || sarg == "1";
162  }
163  return test_FembLinearCalibration(useExistingFcl);
164 }
int test_FembLinearCalibration(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_FembLinearCalibration ( bool  useExistingFcl = false)

Definition at line 29 of file test_FembLinearCalibration.cxx.

29  {
30  const string myname = "test_FembLinearCalibration: ";
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_FembLinearCalibration.fcl";
39  if ( ! useExistingFcl ) {
40  cout << myname << "Creating top-level FCL." << endl;
41  ofstream fout(fclfile.c_str());
42  fout << "tools: {" << endl;
43  fout << " mytool: {" << endl;
44  fout << " tool_type: FembLinearCalibration" << endl;
45  fout << " LogLevel: 1" << endl;
46  fout << " Units: Coulombs" << 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 << "}" << endl;
54  fout.close();
55  } else {
56  cout << myname << "Using existing top-level FCL." << endl;
57  }
58 
59  cout << myname << line << endl;
60  cout << myname << "Fetching tool manager." << endl;
62  assert ( ptm != nullptr );
63  DuneToolManager& tm = *ptm;
64  tm.print();
65  assert( tm.toolNames().size() == 1 );
66 
67  cout << myname << line << endl;
68  cout << myname << "Fetching tool." << endl;
69  auto pmod = tm.getPrivate<TpcDataTool>("mytool");
70  assert( pmod != nullptr );
71 
72  cout << myname << line << endl;
73  cout << myname << "Create data." << endl;
74  AdcChannelData acd0;
75  acd0.pedestal = 1000.0;
76  acd0.raw.push_back(1100);
77  acd0.raw.push_back(1200);
78  acd0.raw.push_back(1300);
79  acd0.raw.push_back(1400);
80  acd0.raw.push_back(1500);
81  acd0.pedestal = 1000.0;
82  AdcSignal dped = 0.0;
83  AdcChannelDataMap acds;
84  for ( AdcChannel icha=0; icha<5; ++icha ) {
85  AdcChannelData& acd = acds[icha];
86  acd.setChannelInfo(icha);
87  for ( AdcCount& adc : acd0.raw ) acd.raw.push_back(adc+dped);
88  acd.pedestal = acd0.pedestal + dped;
89  dped += 100.0;
90  }
91  int w = 8;
92  Index nsam = acd0.raw.size();
93  for ( auto& ient : acds ) {
94  AdcChannel icha = ient.first;
95  AdcChannelData& acd = ient.second;
96  AdcSignalVector sigchk(nsam);
97  for ( Index isam=0; isam<nsam; ++isam ) {
98  sigchk[isam] = (icha+1)*(acd0.raw[isam] - acd0.pedestal);
99  }
100  cout << myname << line << endl;
101  assert( acd.sampleUnit == "" );
102  cout << myname << "Channel " << icha << endl;
103  DataMap res = pmod->update(acd);
104  cout << myname << "Modify:" << endl;
105  res.print();
106  Index nsamRes = res.getInt("calibSampleCount");
107  Index nunder = res.getInt("calibUnderflowCount");
108  Index nover = res.getInt("calibOverflowCount");
109  assert( res.status() == 0 );
110  assert( nsamRes == nsam );
111  cout << myname << " Raw:";
112  for ( AdcCount adc : acd.raw ) cout << setw(w) << adc;
113  cout << endl;
114  cout << myname << " Prep:";
115  for ( AdcSignal sam : acd.samples ) cout << setw(w) << sam;
116  cout << endl;
117  cout << myname << "Check:";
118  for ( AdcSignal sam : sigchk ) cout << setw(w) << sam;
119  cout << endl;
120  cout << myname << " Flag:";
121  for ( AdcFlag flg : acd.flags ) cout << setw(w) << flg;
122  cout << endl;
123  cout << myname << "Check samples." << endl;
124  for ( Index isam=0; isam<nsam; ++isam ) {
125  assert( acd.samples[isam] == sigchk[isam] );
126  }
127  cout << myname << "Check under and overflows." << endl;
128  Index nunderExp = 2;
129  Index noverExp = icha > 2 ? icha - 2 : 0;
130  assert ( nunder == nunderExp );
131  assert ( nover == noverExp );
132  for ( Index isam=0; isam<nsam; ++isam ) {
133  AdcFlag flgExp = isam < nunderExp ? AdcUnderflow :
134  isam >= nsam-noverExp ? AdcOverflow :
135  AdcGood;
136  if ( acd.flags[isam] != flgExp ) {
137  cout << myname << "Sample " << isam << ": " << acd.flags[isam]
138  << " != " << flgExp << endl;
139  }
140  assert( acd.flags[isam] == flgExp );
141  }
142  assert( acd.sampleUnit == "Coulombs" );
143  }
144 
145  cout << myname << line << endl;
146  cout << myname << "Done." << endl;
147  return 0;
148 }
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