27 const string myname =
"TestErrorHandler: ";
28 cout << myname << msg <<
endl;
35 const string myname =
"test_AdcPedestalFitter: ";
37 cout << myname <<
"NDEBUG must be off." <<
endl;
40 string line =
"-----------------------------";
46 cout << myname << line <<
endl;
47 string fclfile =
"test_AdcPedestalFitter.fcl";
48 if ( ! useExistingFcl ) {
49 cout << myname <<
"Creating top-level FCL." <<
endl;
50 ofstream
fout(fclfile.c_str());
51 fout <<
"#include \"test_dataprep.fcl\"" <<
endl;
53 fout <<
" tool_type: AdcPedestalFitter" <<
endl;
55 fout <<
" AdcRange: \"pow(2,12)\"" <<
endl;
57 fout <<
" FitPrecision: 1.0" <<
endl;
59 fout <<
" AdcFitRange: \"10*int(0.7*[gain]+1)\"" <<
endl;
60 fout <<
" FitRmsMin: \"1.0\"" <<
endl;
61 fout <<
" FitRmsMax: \"20.0\"" <<
endl;
62 fout <<
" RemoveStickyCode: false" <<
endl;
63 fout <<
" HistName: \"adcped_%EVENT%_%CHAN%\"" <<
endl;
64 fout <<
" HistTitle: \"ADC pedestal for event %EVENT% channel %CHAN%\"" <<
endl;
65 fout <<
" PlotFileName: \"adcped_ev%EVENT%_chan%CHAN%.png\"" <<
endl;
66 fout <<
" RootFileName: \"adcped.root\"" <<
endl;
67 fout <<
" HistManager: \"\"" <<
endl;
74 fout <<
"tools.mymaptool: @local::tools.mytool" <<
endl;
75 fout <<
"tools.mymaptool.LogLevel: 2" <<
endl;
76 fout <<
"tools.mymaptool.PlotFileName: \"adcpedmap_ev%EVENT%_chan%CHAN%.png\"" <<
endl;
77 fout <<
"tools.mymaptool.PlotSplitX: 2" <<
endl;
78 fout <<
"tools.mymaptool.RootFileName: \"\"" <<
endl;
79 fout <<
"tools.mymaptool.PlotSizeX: 1400" <<
endl;
80 fout <<
"tools.mymaptool.PlotSizeY: 1000" <<
endl;
81 fout <<
"tools.runDataTool: {" <<
endl;
82 fout <<
" tool_type: FclRunDataTool" <<
endl;
84 fout <<
" FileNames: [\"rundata.fcl\"]" <<
endl;
87 ofstream fout2(
"rundata.fcl");
88 fout2 <<
"run: 123" <<
endl;
89 fout2 <<
"gain: 14.0" <<
endl;
90 fout2 <<
"shaping: 2.0" <<
endl;
93 cout << myname <<
"Using existing top-level FCL." <<
endl;
96 cout << myname << line <<
endl;
97 cout << myname <<
"Fetching tool manager." <<
endl;
99 assert ( ptm !=
nullptr );
104 cout << myname << line <<
endl;
105 cout << myname <<
"Fetching histogram manaager." <<
endl;
107 assert( phm !=
nullptr );
109 cout << myname << line <<
endl;
110 cout << myname <<
"Fetching tool." <<
endl;
112 assert( padvNotUsed !=
nullptr );
114 assert( padvsin !=
nullptr );
116 assert( padvmap !=
nullptr );
117 if ( ! doUpdate ) padvsin =
nullptr;
118 if ( ! doUpdateMap ) padvmap =
nullptr;
120 cout << myname << line <<
endl;
121 cout << myname <<
"Create data and call tool." <<
endl;
123 string lab =
"plane 3u";
124 float peds[10] = {701.1, 711.2, 733.3, 690.4, 688.5, 703.6, 720.7, 720.8, 695.9, 702.0};
126 for (
AdcIndex ievt=0; ievt<nevt; ++ievt ) {
127 cout << myname <<
"Event " << ievt <<
endl;
130 for (
AdcIndex icha=0; icha<ncha; ++icha ) {
131 std::pair<AdcChannelDataMap::iterator, bool> kdat = datamap.emplace(icha,
AdcChannelData());
135 float ped = peds[icha];
139 for (
AdcIndex itic=0; itic<100; ++itic ) {
140 float xadc = ped + rand()%20 - 10.0;
142 if ( iticeff > 20 && iticeff < 40 ) xadc +=600;
144 data.
raw.push_back(iadc);
145 data.
flags.push_back(0);
146 data.
samples.push_back(iadc - ped);
147 data.
signal.push_back(xadc - ped > 300.0 );
150 AdcIndex tp = 10*ievt + 60 - 2.3*icha;
158 if ( padvsin !=
nullptr ) {
159 double ped0 = datamap[icha].pedestal;
161 double ped1 = datamap[icha].pedestal;
162 assert( ! datamap[icha].hasMetadata(
"fitPedPeakBinFraction") );
163 assert( padvsin->update(datamap[icha]) == 0 );
164 double ped2 = datamap[icha].pedestal;
165 cout << myname <<
"Old pedestal: " << ped0 <<
endl;
166 cout << myname <<
"New pedestal: " << ped2 <<
endl;
167 assert( ped1 == ped0 );
168 assert( ped2 != ped0 );
169 assert( ped2 != 0.0 );
170 assert( datamap[icha].hasMetadata(
"fitPedPeakBinFraction") );
171 assert( datamap[icha].hasMetadata(
"fitPedFractionLow") );
172 assert( datamap[icha].hasMetadata(
"fitPedFractionHigh") );
176 if ( padvmap !=
nullptr ) {
178 assert( ! datamap[0].hasMetadata(
"fitPedPeakBinFraction") );
179 assert( padvmap->updateMap(datamap) == 0 );
180 string mname =
"fitPedPeakBinFraction";
181 for (
AdcIndex icha=0; icha<ncha; ++icha ) {
182 cout << myname <<
"Checking channel " << icha <<
endl;
183 cout << myname <<
" Metadata size: " << datamap[icha].metadata.size() <<
endl;
184 cout << myname <<
" " << mname <<
" = " << datamap[icha].metadata[mname] <<
endl;
185 assert( datamap[icha].hasMetadata(mname) );
190 cout << myname << line <<
endl;
191 cout << myname <<
"Done." <<
endl;
198 bool useExistingFcl =
false;
199 bool doUpdate =
true;
200 bool doUpdateMap =
true;
202 string sarg(argv[1]);
203 if ( sarg ==
"-h" ) {
204 cout <<
"Usage: " << argv[0] <<
" [ARG]" <<
endl;
205 cout <<
" If ARG = true, existing FCL file is used." <<
endl;
208 useExistingFcl = sarg ==
"true" || sarg ==
"1";
void msg(const char *fmt,...)
int test_AdcPedestalFitter(bool useExistingFcl, bool doUpdate, bool doUpdateMap)
void setChannelInfo(ChannelInfoPtr pchi)
void setEventInfo(EventInfoPtr pevi)
int main(int argc, char *argv[])
void line(double t, double *p, double &x, double &y, double &z)
void TestErrorHandler(Int_t, Bool_t, const char *, const char *msg)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
QTextStream & endl(QTextStream &s)