test_diffuser.cxx
Go to the documentation of this file.
1 #include "WireCellGen/Diffuser.h"
2 
4 
5 #include "WireCellUtil/Testing.h"
6 #include "WireCellUtil/Units.h"
7 
8 
9 #include "TH2F.h"
10 #include "TStyle.h"
11 #include "TPolyMarker.h"
12 #include "MultiPdf.h"
13 
14 
15 #include <iostream>
16 
17 using namespace WireCell;
18 using namespace WireCell::Test;
19 using namespace std;
20 
21 
23 {
24  cerr << "L: [ " << smear->lpos(0) << " , " << smear->lpos(smear->lsize()) << " ]"<< endl;
25  cerr << "L: [ " << smear->tpos(0) << " , " << smear->tpos(smear->tsize()) << " ]"<< endl;
26 
27  for (int tind = 0; tind < smear->tsize(); ++tind) {
28  for (int lind = 0; lind < smear->lsize(); ++lind) {
29  cerr << "\t" << smear->get(lind, tind);
30  }
31  cerr << endl;
32  }
33 }
34 
35 void test_one()
36 {
37  Ray pitch(Point(0,0,0), Point(0,0,10));
38 
39  // binsize_l, binsize_t
40  Diffuser diff(pitch, 1000);
41  // mean_l, mean_t, sigma_l, sigma_t
42  dump_smear(diff.diffuse(20000, 20, 2000, 2));
43 
44  for (double mean = -100; mean <= 100; mean += 0.11) {
45  Diffuser::bounds_type bb = diff.bounds(mean, 1.5, 1.0);
46  //cerr << "mean=" << mean << " [" << bb.first << " --> " << bb.second << "]" << endl;
47  Assert(bb.second - bb.first == 10.0);
48  }
49 }
50 
51 
53 {
54  pdf.canvas.Clear();
55 
56  //const int nsigma = 3;
57  const double drift_velocity = 1.6 * units::mm/units::microsecond;
58  const double binsize_l = 0.5*units::microsecond*drift_velocity;
59  const double binsize_t = 5*units::mm;
60 
61  const double sigma_l = 3.0*units::microsecond*drift_velocity;
62  const double sigma_t = 3*units::mm;
63 
64  Ray pitch(Point(0,0,0), Point(0,0,binsize_t));
65 
66  Diffuser diff(pitch, binsize_l);
67 
68  vector< IDiffusion::pointer> diffs;
69  vector< pair<double,double> > pts;
70 
71  // make a diagnonal
72  for (double step=0; step<200; step += 5) {
73  double mean_l = (0.5+step)*binsize_l;
74  double mean_t = (0.5+step)*binsize_t;
75  diffs.push_back(diff.diffuse(mean_l, mean_t, sigma_l, sigma_t));
76  pts.push_back(make_pair(mean_l, mean_t));
77  }
78 
79  // and two isolated dots
80  diffs.push_back(diff.diffuse(10*binsize_l, 100*binsize_t, 3*sigma_l, 3*sigma_t, 10.0));
81  diffs.push_back(diff.diffuse(100*binsize_l, 10*binsize_t, 3*sigma_l, 3*sigma_t, 10.0));
82 
83  double min_l=0,min_t=0,max_l=0,max_t=0;
84  for (auto d : diffs) {
85  min_l = min(min_l, d->lpos(0));
86  min_t = min(min_t, d->tpos(0));
87  max_l = max(max_l, d->lpos(d->lsize()));
88  max_t = max(max_t, d->tpos(d->tsize()));
89  }
90 
91 
92  TH2F* h = new TH2F("smear","Smear",
93  (max_l-min_l)/binsize_l, min_l, max_l,
94  (max_t-min_t)/binsize_t, min_t, max_t);
95  for (auto smear : diffs) {
96  for (int tind = 0; tind < smear->tsize(); ++tind) {
97  for (int lind = 0; lind < smear->lsize(); ++lind) {
98  h->Fill(smear->lpos(lind,0.5), smear->tpos(tind,0.5), smear->get(lind, tind));
99  }
100  }
101  }
102 
103  h->SetXTitle("Longitudinal direction");
104  h->SetYTitle("Transverse direction");
105  h->Draw("colz");
106 
107  TPolyMarker* pm = new TPolyMarker;
108  pm->SetMarkerColor(5);
109  pm->SetMarkerStyle(8);
110  int count = 0;
111  for (auto xy : pts) {
112  pm->SetPoint(count++, xy.first, xy.second);
113  }
114  pm->Draw();
115 
116  gStyle->SetOptStat(11111111);
117  pdf();
118 }
119 
120 
121 int main(int argc, char* argv[])
122 {
123  test_one();
124 
125  MultiPdf pdf(argv[0]);
126 
127  test_plot_hist(pdf);
128 
129  return 0;
130 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
std::shared_ptr< const IDiffusion > pointer
Definition: IData.h:19
void test_plot_hist(MultiPdf &pdf)
D3Vector< double > Point
A 3D Cartesian point in double precision.
Definition: Point.h:15
void dump_smear(IDiffusion::pointer smear)
IDiffusion::pointer diffuse(double mean_l, double mean_t, double sigma_l, double sigma_t, double weight=1.0, IDepo::pointer depo=nullptr)
Definition: Diffuser.cxx:204
STL namespace.
static const double microsecond
Definition: Units.h:94
int main(int argc, char *argv[])
#define Assert
Definition: Testing.h:7
static int max(int a, int b)
static const double mm
Definition: Units.h:55
std::pair< double, double > bounds_type
Definition: Diffuser.h:34
Definition: Main.h:22
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
void test_one()
bounds_type bounds(double mean, double sigma, double binsize, double origin=0.0)
Definition: Diffuser.cxx:195
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:15
QTextStream & endl(QTextStream &s)
h
training ###############################
Definition: train_cnn.py:186