25 using std::istringstream;
49 if ( acd.
signal.size() < nsam )
return;
51 for (
Index isam=0; isam<nsam; ++isam ) {
52 if ( acd.
signal[isam] )
continue;
57 if ( dbg ) cout << lab <<
setw(5) << isam <<
":" <<
setw(10) << sig <<
endl;
59 if ( nSig == 0 )
return;
64 cout << lab <<
" # signal: " <<
count <<
endl;
65 cout << lab <<
" mean: " << mean <<
endl;
66 cout << lab <<
" RMS: " <<
rms <<
endl;
75 const string myname =
"test_ExpTailRemover: ";
77 cout << myname <<
"NDEBUG must be off." <<
endl;
80 string line =
"-----------------------------";
82 cout << myname << line <<
endl;
83 string fclfile =
"test_ExpTailRemover.fcl";
84 float decayTime = 100.0;
87 if ( ! useExistingFcl ) {
88 cout << myname <<
"Creating top-level FCL." <<
endl;
89 ofstream
fout(fclfile.c_str());
92 fout <<
" tool_type: AdcThresholdSignalFinder" <<
endl;
97 fout <<
" FlagPositive: true" <<
endl;
98 fout <<
" FlagNegative: true" <<
endl;
101 fout <<
" tool_type: ExpTailRemover" <<
endl;
103 fout <<
" SignalFlag: " << flag <<
endl;
104 fout <<
" SignalIterationLimit: 10" <<
endl;
105 fout <<
" SignalTool: \"sigfind\"" <<
endl;
106 fout <<
" DecayTime: " << decayTime <<
endl;
107 fout <<
" IncludeChannelRanges: [\"all\"]" <<
endl;
108 fout <<
" ExcludeChannelRanges: []" <<
endl;
113 cout << myname <<
"Using existing top-level FCL." <<
endl;
116 cout << myname << line <<
endl;
117 cout << myname <<
"Fetching tool manager." <<
endl;
119 assert ( ptm !=
nullptr );
124 cout << myname << line <<
endl;
125 cout << myname <<
"Fetching tool." <<
endl;
127 assert( ptoo !=
nullptr );
129 cout << myname <<
"Create signals." <<
endl;
131 FloatVector pulse = { 0.1, 4.5, 15.2, 66.4, 94.3, 100.0, 96.5, 88.4, 72.6, 58.4,
132 42.3, 35.1, 26.0, 18.6, 12.6, 8.8, 6.9, 4.4, 2.0, 0.3 };
133 Index npul = pulse.size();
138 Index npea = peakPoss.size();
139 for (
Index ipea=0; ipea<npea; ++ipea ) {
140 Index iposPeak = peakPoss[ipea];
141 float norm = peakAmps[ipea];
142 for (
Index ipul=0; ipul<npul; ++ipul ) {
143 Index isam = iposPeak + ipul;
144 if ( isam >= nsam )
break;
145 sigs1[isam] += norm*pulse[ipul];
146 isSignal[isam] =
true;
150 cout << myname << line <<
endl;
151 cout << myname <<
"Add noise to the signal." <<
endl;
152 if ( setSeed ) gRandom->SetSeed();
153 for (
float& sig : sigs1 ) sig += gRandom->Gaus(0.0, noiseSigma);
155 cout << myname <<
"Create sample tailer." <<
endl;
161 cout << myname <<
" beta: " << sta.
beta() <<
endl;
162 cout << myname <<
" alpha: " << sta.
alpha() <<
endl;
163 cout << myname <<
" pedestal: " << sta.
pedestal() <<
endl;
164 cout << myname <<
" tail0: " << sta.
tail0() <<
endl;
166 cout << myname << line <<
endl;
167 cout << myname <<
"Add pedestal and tail to the signal to create data." <<
endl;
170 cout << myname << line <<
endl;
171 cout << myname <<
"Create channel data." <<
endl;
179 cout << myname << line <<
endl;
180 cout << myname <<
"Check input noise." <<
endl;
181 SigStats inStats(acd, myname);
182 assert( inStats.count > 0 );
184 cout << myname << line <<
endl;
185 cout << myname <<
"Use tool to remove tail from data." <<
endl;
186 DataMap res = ptoo->update(acd);
190 cout << myname << line <<
endl;
191 cout << myname <<
"Check output noise." <<
endl;
192 SigStats ouStats(acd, myname);
193 assert( ouStats.count > 0 );
195 cout << myname <<
"Done." <<
endl;
202 bool useExistingFcl =
false;
204 float noiseSigma = 2.0;
205 bool setSeed =
false;
207 string sarg(argv[1]);
208 if ( sarg ==
"-h" ) {
209 cout <<
"Usage: " << argv[0] <<
" [ARG [OPT [noise [setSeed]]]]" <<
endl;
210 cout <<
" If ARG = true, existing FCL file is used." <<
endl;
211 cout <<
" OPT [2] is SignalOption = 0, 1, 2, or 3" <<
endl;
212 cout <<
" noise [2.0] is the sigma of the noise added to the data" <<
endl;
213 cout <<
" setSeed nonzero means a random random seed for the noise" <<
endl;
216 useExistingFcl = sarg ==
"true" || sarg ==
"1";
219 string sarg(argv[2]);
220 flag = std::stoi(sarg);
223 string sarg(argv[3]);
224 istringstream ssarg(sarg);
228 string sarg(argv[3]);
229 setSeed = sarg !=
"0";
int main(int argc, char *argv[])
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
int setSignal(const FloatVector &inSignal)
void print(std::ostream *pout) const
int setPedestal(float val)
void setChannelInfo(ChannelInfoPtr pchi)
const FloatVector & data() const
void setEventInfo(EventInfoPtr pevi)
int test_ExpTailRemover(bool useExistingFcl, Index flag, float noiseSigma, bool setSeed)
auto norm(Vector const &v)
Return norm of the specified vector.
Q_EXPORT QTSManip setw(int w)
std::vector< bool > AdcFilterVector
void line(double t, double *p, double &x, double &y, double &z)
std::vector< AdcSignal > AdcSignalVector
Dft::FloatVector FloatVector
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
QTextStream & endl(QTextStream &s)