29 const string myname =
"TestErrorHandler: ";
30 cout << myname << msg <<
endl;
37 const string myname =
"test_AdcTickModViewer: ";
39 cout << myname <<
"NDEBUG must be off." <<
endl;
42 string line =
"-----------------------------";
48 cout << myname << line <<
endl;
49 string fclfile =
"test_AdcTickModViewer.fcl";
50 if ( ! useExistingFcl ) {
51 cout << myname <<
"Creating top-level FCL." <<
endl;
52 ofstream
fout(fclfile.c_str());
53 fout <<
"#include \"dataprep_tools.fcl\"" <<
endl;
55 fout <<
" tool_type: AdcTickModViewer" <<
endl;
58 fout <<
" TimeOffsetTool: myTimeOffsetTool" <<
endl;
60 fout <<
" FitSigmaMax: 20.0" <<
endl;
61 fout <<
" HistName: \"adctm_ch%0CHAN%_tm%0TICKMOD%\"" <<
endl;
62 fout <<
" HistTitle: \"ADC spectrum for channel %CHAN% tickmod %TICKMOD%\"" <<
endl;
63 fout <<
" HistChannelCount: 100" <<
endl;
65 fout <<
" AllPlotFileName: \"adctm%TICKMOD%_ch%0CHAN%.png\"" <<
endl;
66 fout <<
" MinPlotFileName: \"adctmMin_ch%0CHAN%.png\"" <<
endl;
67 fout <<
" MaxPlotFileName: \"adctmMax_ch%0CHAN%.png\"" <<
endl;
68 fout <<
" PhaseGrouping: channel" <<
endl;
69 fout <<
" PhasePlotFileName: \"adcPhase_ch%0CHAN%.png\"" <<
endl;
70 fout <<
" PhaseVariable: phase" <<
endl;
71 fout <<
" RootFileName: \"adctm.root\"" <<
endl;
72 fout <<
" TreeFileName: \"tickmod.root\"" <<
endl;
73 fout <<
" TreeFileName: \"\"" <<
endl;
80 fout <<
" PhasePlotSizeX: 1400" <<
endl;
81 fout <<
" PhasePlotSizeY: 1000" <<
endl;
82 fout <<
" PhasePlotSplitX: 2" <<
endl;
83 fout <<
" PhasePlotSplitY: 2" <<
endl;
85 fout <<
"tools.myTimeOffsetTool: {" <<
endl;
86 fout <<
" tool_type: FixedTimeOffsetTool" <<
endl;
94 cout << myname <<
"Using existing top-level FCL." <<
endl;
97 cout << myname << line <<
endl;
98 cout << myname <<
"Fetching tool manager." <<
endl;
100 assert ( ptm !=
nullptr );
105 cout << myname << line <<
endl;
107 assert( pvtm !=
nullptr );
108 if ( ! doUpdate ) pvtm =
nullptr;
110 cout << myname << line <<
endl;
111 cout << myname <<
"Create data." <<
endl;
113 string lab =
"plane 3u";
114 float peds[10] = {701.1, 711.2, 733.3, 690.4, 688.5, 703.6, 720.7, 720.8, 695.9, 702.0};
115 vector<AdcChannelDataMap> acms(nevt);
117 for (
AdcIndex ievt=0; ievt<nevt; ++ievt ) {
118 cout << myname <<
"Event " << ievt <<
endl;
120 for (
AdcIndex icha=0; icha<ncha; ++icha ) {
121 std::pair<AdcChannelDataMap::iterator, bool> kdat = datamap.emplace(icha,
AdcChannelData());
125 float ped = peds[icha];
129 for (
AdcIndex itic=0; itic<100; ++itic ) {
130 float xadc = ped + rand()%20 - 10.0;
132 if ( iticeff > 20 && iticeff < 45 ) xadc +=600;
134 data.
raw.push_back(iadc);
135 data.
flags.push_back(0);
136 data.
samples.push_back(iadc - ped);
137 data.
signal.push_back(xadc - ped > 300.0 );
140 AdcIndex tp = 10*ievt + 60 - 2.3*icha;
151 cout << myname << line <<
endl;
152 cout << myname <<
"Call tool." <<
endl;
153 unsigned int expCount = 0;
155 cout << myname <<
"Event " << acm.begin()->second.event() <<
endl;
157 for (
const AdcChannelDataMap::value_type& iacd : acm ) {
159 cout << myname <<
"Event " << acd.
event() <<
", channel " << acd.
channel() <<
endl;
160 cout << myname <<
"ADC channel data size: " << acd.
raw.size() <<
endl;
163 assert( dm.
status() == 0 );
166 assert( phs.size() == 4 );
167 for (
const TH1* ph : phs ) {
168 cout << myname <<
" " << ph->GetName() <<
": " << ph->GetTitle() <<
endl;
169 double countSum = ph->Integral();
170 double countUnder = ph->GetBinContent(0);
171 double countOver = ph->GetBinContent(ph->GetNbinsX()+1);
172 cout << myname <<
" Hist integral:" << countSum <<
endl;
173 cout << myname <<
" Hist undrflow:" << countUnder <<
endl;
174 cout << myname <<
" Hist overflow:" << countOver <<
endl;
175 double countTot = countSum + countUnder + countOver;
176 assert( countTot == expCount );
181 cout << myname << line <<
endl;
182 cout << myname <<
"Done." <<
endl;
189 bool useExistingFcl =
false;
190 bool doUpdate =
true;
191 bool doUpdateMap =
true;
193 string sarg(argv[1]);
194 if ( sarg ==
"-h" ) {
195 cout <<
"Usage: " << argv[0] <<
" [ARG]" <<
endl;
196 cout <<
" If ARG = true, existing FCL file is used." <<
endl;
199 useExistingFcl = sarg ==
"true" || sarg ==
"1";
void TestErrorHandler(Int_t, Bool_t, const char *, const char *msg)
void msg(const char *fmt,...)
int test_AdcTickModViewer(bool useExistingFcl, bool doUpdate, bool doUpdateMap)
void print(std::ostream *pout) const
int main(int argc, char *argv[])
const HistVector & getHistVector(Name name) const
void setChannelInfo(ChannelInfoPtr pchi)
void setEventInfo(EventInfoPtr pevi)
void line(double t, double *p, double &x, double &y, double &z)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
bool haveHistVector(Name name) const
std::vector< TH1 * > HistVector
QTextStream & endl(QTextStream &s)