Typedefs | Functions
test_ExpTailRemover.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include "dunecore/DuneInterface/Tool/TpcDataTool.h"
#include "dunecore/DuneCommon/Utility/SampleTailer.h"
#include "dunecore/ArtSupport/DuneToolManager.h"
#include "TRandom.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using Index = unsigned int
 
using IndexVector = std::vector< Index >
 
using FloatVector = AdcSignalVector
 

Functions

int test_ExpTailRemover (bool useExistingFcl, Index flag, float noiseSigma, bool setSeed)
 
int main (int argc, char *argv[])
 

Typedef Documentation

Definition at line 31 of file test_ExpTailRemover.cxx.

using Index = unsigned int

Definition at line 29 of file test_ExpTailRemover.cxx.

Definition at line 30 of file test_ExpTailRemover.cxx.

Function Documentation

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

Definition at line 201 of file test_ExpTailRemover.cxx.

201  {
202  bool useExistingFcl = false;
203  Index flag = 2;
204  float noiseSigma = 2.0;
205  bool setSeed = false;
206  if ( argc > 1 ) {
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;
214  return 0;
215  }
216  useExistingFcl = sarg == "true" || sarg == "1";
217  }
218  if ( argc > 2 ) {
219  string sarg(argv[2]);
220  flag = std::stoi(sarg);
221  }
222  if ( argc > 3 ) {
223  string sarg(argv[3]);
224  istringstream ssarg(sarg);
225  ssarg >> noiseSigma;
226  }
227  if ( argc > 4 ) {
228  string sarg(argv[3]);
229  setSeed = sarg != "0";
230  }
231  return test_ExpTailRemover(useExistingFcl, flag, noiseSigma, setSeed);
232 }
unsigned int Index
int test_ExpTailRemover(bool useExistingFcl, Index flag, float noiseSigma, bool setSeed)
QTextStream & endl(QTextStream &s)
int test_ExpTailRemover ( bool  useExistingFcl,
Index  flag,
float  noiseSigma,
bool  setSeed 
)

Definition at line 74 of file test_ExpTailRemover.cxx.

74  {
75  const string myname = "test_ExpTailRemover: ";
76 #ifdef NDEBUG
77  cout << myname << "NDEBUG must be off." << endl;
78  abort();
79 #endif
80  string line = "-----------------------------";
81 
82  cout << myname << line << endl;
83  string fclfile = "test_ExpTailRemover.fcl";
84  float decayTime = 100.0;
85  float ped = 5.0;
86  float tail0 = -15.0;
87  if ( ! useExistingFcl ) {
88  cout << myname << "Creating top-level FCL." << endl;
89  ofstream fout(fclfile.c_str());
90  fout << "tools: {" << endl;
91  fout << " sigfind: {" << endl;
92  fout << " tool_type: AdcThresholdSignalFinder" << endl;
93  fout << " LogLevel: 1" << endl;
94  fout << " Threshold: 10" << endl;
95  fout << " BinsAfter: 10" << endl;
96  fout << " BinsBefore: 5" << endl;
97  fout << " FlagPositive: true" << endl;
98  fout << " FlagNegative: true" << endl;
99  fout << " }" << endl;
100  fout << " mytool: {" << endl;
101  fout << " tool_type: ExpTailRemover" << endl;
102  fout << " LogLevel: 3" << 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;
109  fout << " }" << endl;
110  fout << "}" << endl;
111  fout.close();
112  } else {
113  cout << myname << "Using existing top-level FCL." << endl;
114  }
115 
116  cout << myname << line << endl;
117  cout << myname << "Fetching tool manager." << endl;
119  assert ( ptm != nullptr );
120  DuneToolManager& tm = *ptm;
121  tm.print();
122  assert( tm.toolNames().size() == 2 );
123 
124  cout << myname << line << endl;
125  cout << myname << "Fetching tool." << endl;
126  auto ptoo = tm.getPrivate<TpcDataTool>("mytool");
127  assert( ptoo != nullptr );
128 
129  cout << myname << "Create signals." << endl;
130  Index nsam = 300;
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();
134  FloatVector sigs1(nsam, 0.0);
135  AdcFilterVector isSignal(nsam, false);
136  IndexVector peakPoss = {10, 100, 115, 230};
137  FloatVector peakAmps = {0.5, 2.0, 0.7, 1.0};
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;
147  }
148  }
149 
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);
154 
155  cout << myname << "Create sample tailer." << endl;
156  SampleTailer sta(decayTime);
157  sta.setPedestal(ped);
158  sta.setTail0(tail0);
159  sta.setUnit("ADC count");
160  cout << myname << " decayTime: " << sta.decayTime() << 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;
165 
166  cout << myname << line << endl;
167  cout << myname << "Add pedestal and tail to the signal to create data." << endl;
168  assert( sta.setSignal(sigs1) == 0 );
169 
170  cout << myname << line << endl;
171  cout << myname << "Create channel data." << endl;
172  AdcChannelData acd;
173  acd.setEventInfo(123, 456);
174  acd.setChannelInfo(789);
175  acd.pedestal = 1000.0;
176  acd.samples = sta.data();
177  acd.signal = isSignal;
178 
179  cout << myname << line << endl;
180  cout << myname << "Check input noise." << endl;
181  SigStats inStats(acd, myname);
182  assert( inStats.count > 0 );
183 
184  cout << myname << line << endl;
185  cout << myname << "Use tool to remove tail from data." << endl;
186  DataMap res = ptoo->update(acd);
187  res.print();
188  assert ( res == 0 );
189 
190  cout << myname << line << endl;
191  cout << myname << "Check output noise." << endl;
192  SigStats ouStats(acd, myname);
193  assert( ouStats.count > 0 );
194 
195  cout << myname << "Done." << endl;
196  return 0;
197 }
std::vector< Index > IndexVector
const std::vector< std::string > & toolNames() const
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
void setChannelInfo(ChannelInfoPtr pchi)
void setEventInfo(EventInfoPtr pevi)
auto norm(Vector const &v)
Return norm of the specified vector.
std::unique_ptr< T > getPrivate(std::string name)
AdcSignal pedestal
AdcFilterVector signal
std::vector< bool > AdcFilterVector
Definition: AdcTypes.h:27
void line(double t, double *p, double &x, double &y, double &z)
Dft::FloatVector FloatVector
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)