test_frameutil.cxx
Go to the documentation of this file.
2 #include "WireCellUtil/Testing.h"
3 #include "WireCellUtil/Units.h"
6 
7 #include <iostream>
8 
9 using namespace std;
10 using namespace WireCell;
11 
12 int main()
13 {
14  const double tick = 0.5*units::us;
15  const double readout = 5*units::ms;
16  const int nsamples = round(readout/tick);
17 
18  // "Signal"
19  const int signal_frame_ident = 100;
20  const double signal_start_time = 6*units::ms;
21  vector<float> signal{0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,0.0};
22 
23  ITrace::vector signal_traces{
24  make_shared<SimpleTrace>(1, 10, signal),
25  make_shared<SimpleTrace>(1, 20, signal),
26  make_shared<SimpleTrace>(2, 30, signal),
27  make_shared<SimpleTrace>(2, 33, signal)};
28  auto f1 = make_shared<SimpleFrame>(signal_frame_ident, signal_start_time, signal_traces, tick);
29 
30  // "Noise"
31  const int noise_frame_ident = 0;
32  const double noise_start_time = 5*units::ms;
33  vector<float> noise(nsamples, -0.5);
34  ITrace::vector noise_traces{
35  make_shared<SimpleTrace>(0, 0, noise),
36  make_shared<SimpleTrace>(1, 0, noise),
37  make_shared<SimpleTrace>(2, 0, noise),
38  make_shared<SimpleTrace>(3, 0, noise)};
39  auto f2 = make_shared<SimpleFrame>(noise_frame_ident, noise_start_time, noise_traces, tick);
40 
41  const int summed_ident = 1;
42  auto f3 = Gen::sum({f1,f2}, summed_ident);
43  Assert(f3);
44  Assert(f3->ident() == summed_ident);
45  Assert(f3->time() == noise_start_time);
46  Assert(f3->tick() == tick);
47  auto traces = f3->traces();
48  Assert(traces->size() == 4);
49  cerr << "Frame #"<<f3->ident()<<" time=" << f3->time()/units::ms << "ms\n";
50  for (auto trace : *traces) {
51  const auto& charge = trace->charge();
52  cerr << "ch=" << trace->channel()
53  << " tbin=" << trace->tbin()
54  << " nsamples=" << charge.size()
55  << endl;
56  for (size_t ind=0; ind<charge.size(); ++ind) {
57  const float q = charge[ind];
58  if (q < 0) {
59  continue;
60  }
61  cerr << "\tq=" << q << " tbin=" << ind << " t=" << (ind*tick)/units::ms << "ms\n";
62  }
63  cerr << endl;
64  }
65 
66  return 0;
67 }
int main()
struct vector vector
DecayPhysicsFactory f3
STL namespace.
SynchrotronAndGN f2
const double tick
#define Assert
Definition: Testing.h:7
EmPhysicsFactory f1
IFrame::pointer sum(std::vector< IFrame::pointer > frames, int ident)
Definition: FrameUtil.cxx:15
Definition: Main.h:22
static const double us
Definition: Units.h:101
static const double ms
Definition: Units.h:100
QTextStream & endl(QTextStream &s)