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

Typedef Documentation

using Index = unsigned int

Definition at line 25 of file test_FloatArrayGainCalibration.cxx.

Function Documentation

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

Definition at line 147 of file test_FloatArrayGainCalibration.cxx.

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

Definition at line 29 of file test_FloatArrayGainCalibration.cxx.

29  {
30  const string myname = "test_FloatArrayGainCalibration: ";
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_FloatArrayGainCalibration.fcl";
39  double scaleFac = 2.0;
40  if ( ! useExistingFcl ) {
41  cout << myname << "Creating top-level FCL." << endl;
42  ofstream fout(fclfile.c_str());
43  fout << "tools: {" << endl;
44  fout << " calvals: {" << endl;
45  fout << " tool_type: FclFloatArray" << endl;
46  fout << " LogLevel: 2" << endl;
47  fout << " DefaultValue: -1" << endl;
48  fout << " Offset: 0" << endl;
49  fout << " Label: myvals" << endl;
50  fout << " Unit: ke" << endl;
51  fout << " Values: [ 0.012, 0.014, 0.016, 0.018, 0.020 ]" << endl;
52  fout << " }" << endl;
53  fout << " mytool: {" << endl;
54  fout << " tool_type: FloatArrayGainCalibration" << endl;
55  fout << " LogLevel: 2" << endl;
56  fout << " Unit: fC" << endl;
57  fout << " GainDefault: \"1.0\"" << endl;
58  fout << " AdcUnderflowDefault: 0" << endl;
59  fout << " AdcOverflowDefault: 255" << endl;
60  fout << " GainTool: calvals" << endl;
61  fout << " ScaleFactor: \"" << scaleFac << "*[gain]/14.0\"" << endl;
62  fout << " }" << endl;
63  fout << " runDataTool: {" << endl;
64  fout << " tool_type: FclRunDataTool" << endl;
65  fout << " LogLevel: 1" << endl;
66  fout << " FileNames: [\"rundata.fcl\"]" << endl;
67  fout << " }" << endl;
68  fout << "}" << endl;
69  fout.close();
70  ofstream fout2("rundata.fcl");
71  fout2 << "run: 123" << endl;
72  fout2 << "gain: 14.0" << endl;
73  fout2 << "shaping: 2.0" << endl;
74  fout2.close();
75  fout.close();
76  } else {
77  cout << myname << "Using existing top-level FCL." << endl;
78  }
79 
80  cout << myname << line << endl;
81  cout << myname << "Fetching tool manager." << endl;
83  assert ( ptm != nullptr );
84  DuneToolManager& tm = *ptm;
85  tm.print();
86  assert( tm.toolNames().size() == 3 );
87 
88  cout << myname << line << endl;
89  cout << myname << "Fetching tool." << endl;
90  auto ptoo = tm.getPrivate<TpcDataTool>("mytool");
91  assert( ptoo != nullptr );
92 
93  cout << myname << line << endl;
94  cout << myname << "Create data." << endl;
95  AdcChannelData acd0;
96  // Specify the true signal (same for all channels).
97  AdcSignalVector sigvals= {20, 21, 22, 23, 24, 25, 26, 27, 28, 29};
98  AdcIndex nsam = sigvals.size();
99  assert( nsam == 10 );
100  // Build data for five channels with different pedestal and gain for each.
101  AdcSignal ped = 10.0;
102  AdcSignal dped = 1.0;
103  AdcChannelDataMap acds;
104  for ( AdcChannel icha=0; icha<5; ++icha ) {
105  float gain = 0.01 + 0.002*(icha+1);
106  AdcChannelData& acd = acds[icha];
107  acd.setChannelInfo(icha);
108  acd.pedestal = ped;
109  for ( AdcSignal sigval : sigvals ) {
110  AdcIndex adc = sigval/gain/scaleFac + ped;
111  acd.raw.push_back(adc);
112  }
113  ped += dped;
114  }
115 
116  cout << myname << line << endl;
117  cout << myname << "Calibrate and check data." << endl;
118  //int w = 8;
119  for ( auto& ient : acds ) {
120  AdcChannel icha = ient.first;
121  cout << myname << "-------------------- Channel " << icha << endl;
122  AdcChannelData& acd = ient.second;
123  DataMap res = ptoo->update(acd);
124  res.print();
125  assert( res.status() == 0 );
126  assert( res.getInt("calibSampleCount") == int(nsam) );
127  assert( acd.channel() == icha );
128  assert( acd.raw.size() == nsam );
129  assert( acd.samples.size() == nsam );
130  //cout.precision(2);
131  cout << " ADC signal flag [ exp]" << endl;
132  for ( Index isam=0; isam<nsam; ++isam ) {
133  cout << setw(3) << isam << ": " << setw(5) << acd.raw[isam]
134  << setw(11) << acd.samples[isam]
135  << setw(6) << acd.flags[isam]
136  << " [" << setw(6) << sigvals[isam] << "]" << endl;
137  assert( fabs(acd.samples[isam] - sigvals[isam]) < 0.2 );
138  }
139  }
140 
141  cout << myname << "Done." << endl;
142  return 0;
143 }
const std::vector< std::string > & toolNames() const
float AdcSignal
Definition: AdcTypes.h:21
int16_t adc
Definition: CRTFragment.hh:202
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
int status() const
Definition: DataMap.h:202
void setChannelInfo(ChannelInfoPtr pchi)
AdcCountVector raw
unsigned int AdcIndex
Definition: AdcTypes.h:15
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
Channel channel() const
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
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags