20 #include "TGraphErrors.h" 29 using std::istringstream;
57 if ( acd.
signal.size() < nsam )
return;
58 for (
Index isam=0; isam<nsam; ++isam ) {
61 double sig = acd.
samples[isam] - sigTrue[isam];
71 rms = sqrt(sumSig2/nSig);
74 bgrms = sqrt(sumNsg2/nNsg - bgmean*bgmean);
77 cout << lab <<
" # signal: " <<
count <<
endl;
78 cout << lab <<
" # BG: " << bgcount <<
endl;
79 cout << lab <<
" BG mean: " << bgmean <<
endl;
80 cout << lab <<
" BG RMS: " << bgrms <<
endl;
81 cout << lab <<
" Signal RMS: " <<
rms <<
endl;
86 const string myname =
"drawResults: ";
87 string line =
"-----------------------------";
88 cout << myname << line <<
endl;
90 cout << myname <<
"Draw data." <<
endl;
92 TH1* phi =
new TH1F(
"hin",
"ExpTailPedRemover fit;Tick;signal", nsam, 0, nsam);
95 phi->SetLineColor(lc.
blue());
96 TGraphErrors *pgr =
new TGraphErrors(nsam);
97 pgr->SetMarkerStyle(2);
98 pgr->SetMarkerColor(lc.
black());
99 TGraphErrors *pgo =
new TGraphErrors(nsam);
100 pgo->SetMarkerStyle(24);
101 pgo->SetMarkerColor(lc.
red());
102 for (
Index isam=0; isam<nsam; ++ isam ) {
103 phi->SetBinContent(isam+1, sigin[isam]);
104 pgr->SetPoint(isam, isam, sigraw[isam]);
105 pgo->SetPoint(isam, isam, sigout[isam]);
108 man.
add(phi,
"HIST");
111 string fnam =
"test_ExpTailPedRemover.png";
116 cout << myname <<
"Plot saved as " << fnam <<
endl;
124 const string myname =
"test_ExpTailPedRemover: ";
126 cout << myname <<
"NDEBUG must be off." <<
endl;
129 string line =
"-----------------------------";
131 cout << myname << line <<
endl;
132 string fclfile =
"test_ExpTailPedRemover.fcl";
133 float decayTime = 100.0;
136 int pedDegree = slope == 0.0 ? 0 : 1;
137 if ( ! useExistingFcl ) {
138 cout << myname <<
"Creating top-level FCL." <<
endl;
139 ofstream
fout(fclfile.c_str());
142 fout <<
" tool_type: AdcThresholdSignalFinder" <<
endl;
147 fout <<
" FlagPositive: true" <<
endl;
148 fout <<
" FlagNegative: true" <<
endl;
151 fout <<
" tool_type: ExpTailPedRemover" <<
endl;
153 fout <<
" SignalFlag: " << flag <<
endl;
154 fout <<
" SignalIterationLimit: 10" <<
endl;
155 fout <<
" SignalTool: \"sigfind\"" <<
endl;
156 fout <<
" DecayTime: " << decayTime <<
endl;
158 fout <<
" PedDegree: " << pedDegree <<
endl;
159 fout <<
" PedTick0: " << tick0 <<
endl;
161 fout <<
" NoWarnStatuses: []" <<
endl;
162 fout <<
" IncludeChannelRanges: [\"all\"]" <<
endl;
163 fout <<
" ExcludeChannelRanges: []" <<
endl;
168 cout << myname <<
"Using existing top-level FCL." <<
endl;
171 cout << myname << line <<
endl;
172 cout << myname <<
"Fetching tool manager." <<
endl;
174 assert ( ptm !=
nullptr );
179 cout << myname << line <<
endl;
180 cout << myname <<
"Fetching tool." <<
endl;
182 assert( ptoo !=
nullptr );
184 cout << myname <<
"Create signals." <<
endl;
186 FloatVector pulse = { 0.1, 4.5, 15.2, 66.4, 94.3, 100.0, 96.5, 88.4, 72.6, 58.4,
187 42.3, 35.1, 26.0, 18.6, 12.6, 8.8, 6.9, 4.4, 2.0, 0.3 };
188 Index npul = pulse.size();
193 Index npea = peakPoss.size();
194 for (
Index ipea=0; ipea<npea; ++ipea ) {
195 Index iposPeak = peakPoss[ipea];
196 float norm = peakAmps[ipea];
197 for (
Index ipul=0; ipul<npul; ++ipul ) {
198 Index isam = iposPeak + ipul;
199 if ( isam >= nsam )
break;
200 sigs1[isam] += norm*pulse[ipul];
201 isSignal[isam] =
true;
206 cout << myname << line <<
endl;
207 cout << myname <<
"Add noise to the signal." <<
endl;
208 if ( setSeed ) gRandom->SetSeed();
209 for (
float& sig : sigs1 ) sig += gRandom->Gaus(0.0, noiseSigma);
211 cout << myname <<
"Create sample tailer." <<
endl;
215 if ( slope == 0.0 ) {
219 for (
Index isam=0; isam<nsam; ++isam ) {
220 float x =
float(isam) - tick0;
221 peds[isam] = ped + slope*x + curv*x*
x;
228 cout << myname <<
" beta: " << sta.
beta() <<
endl;
229 cout << myname <<
" alpha: " << sta.
alpha() <<
endl;
230 cout << myname <<
" pedestal: " << ped <<
endl;
231 cout << myname <<
" slope: " << slope <<
endl;
232 cout << myname <<
" curvature: " << curv <<
endl;
233 cout << myname <<
" tail0: " << sta.
tail0() <<
endl;
235 cout << myname << line <<
endl;
236 cout << myname <<
"Add pedestal and tail to the signal to create data." <<
endl;
239 cout << myname << line <<
endl;
240 cout << myname <<
"Create channel data." <<
endl;
248 cout << myname << line <<
endl;
249 cout << myname <<
"Check input noise." <<
endl;
250 SigStats inStats(acd, sigs0, myname);
251 assert( inStats.count > 0 );
253 cout << myname << line <<
endl;
254 cout << myname <<
"Use tool to remove tail from data." <<
endl;
255 DataMap res = ptoo->update(acd);
259 cout << myname << line <<
endl;
260 cout << myname <<
"Check output noise." <<
endl;
261 SigStats ouStats(acd, sigs0, myname);
262 assert( ouStats.count > 0 );
266 cout << myname <<
"Done." <<
endl;
273 bool useExistingFcl =
false;
275 float noiseSigma = 2.0;
278 bool setSeed =
false;
280 string sarg(argv[1]);
281 if ( sarg ==
"-h" ) {
282 cout <<
"Usage: " << argv[0] <<
" [ARG [SLOPE [OPT [noise [setSeed]]]]]" <<
endl;
283 cout <<
" If ARG = true, existing FCL file is used." <<
endl;
284 cout <<
" SLOPE [0.02] is the pedestal slope" <<
endl;
285 cout <<
" OPT [2] is SignalOption = 0, 1, 2, or 3" <<
endl;
286 cout <<
" noise [2.0] is the sigma of the noise added to the data" <<
endl;
287 cout <<
" setSeed nonzero means a random random seed for the noise" <<
endl;
290 useExistingFcl = sarg ==
"true" || sarg ==
"1";
293 string sarg(argv[2]);
294 istringstream ssarg(sarg);
298 string sarg(argv[3]);
299 flag = std::stoi(sarg);
302 string sarg(argv[4]);
303 istringstream ssarg(sarg);
307 string sarg(argv[5]);
308 setSeed = sarg !=
"0";
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
int add(unsigned int ipad, TObject *pobj, std::string sopt="", bool replace=false)
int setSignal(const FloatVector &inSignal)
void print(std::ostream *pout) const
int setPedestal(float val)
int addHorizontalLine(double yoff=0.0, double lenfrac=1.0, int isty=1)
void setChannelInfo(ChannelInfoPtr pchi)
const FloatVector & data() const
void setEventInfo(EventInfoPtr pevi)
int addAxis(bool flag=true)
auto norm(Vector const &v)
Return norm of the specified vector.
Q_EXPORT QTSManip setw(int w)
int setPedestalVector(const FloatVector *pval)
int main(int argc, char *argv[])
std::vector< bool > AdcFilterVector
int test_ExpTailPedRemover(bool useExistingFcl, Index flag, float ped, float slope, float noiseSigma, bool setSeed)
void line(double t, double *p, double &x, double &y, double &z)
std::vector< AdcSignal > AdcSignalVector
Dft::FloatVector FloatVector
int setRangeY(double y1, double y2)
int print(std::string fname, std::string spat="{,}")
QTextStream & endl(QTextStream &s)