Functions
test_gaussiandiffusion.cxx File Reference
#include "WireCellGen/GaussianDiffusion.h"
#include "WireCellIface/SimpleDepo.h"
#include "WireCellUtil/ExecMon.h"
#include "WireCellUtil/Testing.h"
#include "WireCellUtil/Point.h"
#include "WireCellUtil/Units.h"
#include "WireCellUtil/PluginManager.h"
#include "WireCellUtil/NamedFactory.h"
#include "WireCellIface/IRandom.h"
#include "WireCellIface/IConfigurable.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TFile.h"
#include "TH2F.h"
#include "TPolyMarker.h"
#include <iostream>

Go to the source code of this file.

Functions

void test_binint ()
 
void test_gd (IRandom::pointer fluctuate)
 
int main (int argc, char *argv[])
 

Function Documentation

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

Definition at line 145 of file test_gaussiandiffusion.cxx.

146 {
148  pm.add("WireCellGen");
149  {
150  auto rngcfg = Factory::lookup<IConfigurable>("Random");
151  auto cfg = rngcfg->default_configuration();
152  rngcfg->configure(cfg);
153  }
154  auto rng = Factory::lookup<IRandom>("Random");
155 
156  const char* me = argv[0];
157 
158  TApplication* theApp = 0;
159  if (argc > 1) {
160  theApp = new TApplication (me,0,0);
161  }
162  TFile output(Form("%s.root", me), "RECREATE");
163  TCanvas canvas("canvas","canvas",500,500);
164  canvas.Print(Form("%s.pdf[", me),"pdf");
165  gStyle->SetOptStat(0);
166 
167  test_binint();
168  canvas.Print(Form("%s.pdf",me),"pdf");
169 
170  test_gd(nullptr);
171  canvas.Print(Form("%s.pdf",me),"pdf");
172  test_gd(rng);
173  canvas.Print(Form("%s.pdf",me),"pdf");
174 
175  if (theApp) {
176  theApp->Run();
177  }
178  else { // batch
179  canvas.Print(Form("%s.pdf]",me),"pdf");
180  }
181 
182  return 0;
183 }
void test_gd(IRandom::pointer fluctuate)
const std::string instance
cfg
Definition: dbjson.py:29
void test_binint()
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
void test_binint ( )

Definition at line 24 of file test_gaussiandiffusion.cxx.

25 {
26  const double mean = 1.7;
27  const double sigma = 2.0;
28  const double xmin = -5;
29  const double xmax = +5;
30 
31  const Gen::GausDesc gd(mean, sigma);
32  const vector<int> nbinsv{100, 50, 20, 10, 5};
33  const vector<int> color{1,2,4,6,7,8};
34 
35  cerr << "erf(+1) = " << std::erf(+1.0) << endl;
36  cerr << "erf(-1) = " << std::erf(-1.0) << endl;
37 
38  for (size_t ind=0; ind < nbinsv.size(); ++ind) {
39  const int nbins = nbinsv[ind];
40  Binning b(nbins, xmin, xmax);
41  auto bi = gd.binint(b.min(), b.binsize(), nbins);
42  TH1F* h = new TH1F("h","binint Gaussian per binsize", nbins, xmin, xmax);
43  for (int bin=0; bin<nbins; ++bin) {
44  h->Fill(b.center(bin), bi[bin]/b.binsize());
45  }
46  const double integ = h->Integral();
47  cerr << ind << " integ=" << b.binsize()*integ << " raw=" << integ << endl;
48  h->SetLineColor(color[ind]);
49  if (ind) {
50  h->Draw("HIST,SAME");
51  }
52  else {
53  h->Draw("HIST");
54  }
55  }
56 }
color
Definition: color.h:50
QTextStream & bin(QTextStream &s)
static bool * b
Definition: config.cpp:1043
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
void test_gd ( IRandom::pointer  fluctuate)

Time Gaussian

Pitch Gaussian

Time bins

Pitch bins

Make a single deposition

Note it is up to caller to assure that depo and tdesc/pdesc are consistent! See BinnedDiffussion for one class that does this.

Rastering to an array is delayed

patch only covers +/- nsigma

Definition at line 59 of file test_gaussiandiffusion.cxx.

60 {
61  const double nsigma = 3.0;
62 
63  /// Time Gaussian
64  const double t_center = 3*units::ms;
65  const double t_sigma = 1*units::us;
66  Gen::GausDesc tdesc(t_center, t_sigma);
67 
68  /// Pitch Gaussian
69  const double p_center = 1*units::m;
70  const double p_sigma = 1*units::mm;
71  Gen::GausDesc pdesc(p_center, p_sigma);
72 
73  const double nsigma_binning = 2.0*nsigma;
74  /// Time bins
75  const double t_sample = 0.5*units::us;
76  const double t_min = t_center - nsigma_binning*t_sigma;
77  const double t_max = t_center + nsigma_binning*t_sigma;
78  const int nt = (t_max-t_min)/t_sample;
79  const Binning tbins(nt, t_min, t_max);
80 
81  /// Pitch bins
82  const double p_sample = 0.3*units::mm;
83  const double p_min = p_center - nsigma_binning*p_sigma;
84  const double p_max = p_center + nsigma_binning*p_sigma;
85  const int np = (p_max-p_min)/p_sample;
86  const Binning pbins(np, p_min, p_max);
87 
88  /// Make a single deposition
89  const double qdepo = -1000.0;
90  const Point pdepo(10*units::cm, 0.0, p_center);
91  auto depo = std::make_shared<SimpleDepo>(t_center, pdepo, qdepo);
92 
93  /// Note it is up to caller to assure that depo and tdesc/pdesc
94  /// are consistent! See BinnedDiffussion for one class that does
95  /// this.
96  Gen::GaussianDiffusion gd(depo, tdesc, pdesc);
97 
98  /// Rastering to an array is delayed
99  cerr << "Set sampling: tbins="<<tbins<<", pbins="<<pbins<<", nsigma="<<nsigma<<", fluctuate:"<<fluctuate<<endl;
100  gd.set_sampling(tbins, pbins, nsigma, fluctuate);
101 
102  /// patch only covers +/- nsigma
103  auto patch = gd.patch();
104  const int toffset = gd.toffset_bin();
105  const int poffset = gd.poffset_bin();
106 
107  cerr << "rows=" << patch.rows() << " cols=" << patch.cols() << endl;
108  cerr << "toffset=" << toffset <<" poffset=" << poffset << endl;
109 
110  Assert(toffset >= 0);
111  Assert(poffset >= 0);
112 
113  const double tunit = units::us; // for display
114  const double punit = units::mm; // for display
115 
116  TPolyMarker* marker = new TPolyMarker(1);
117  marker->SetPoint(0, t_center/tunit, p_center/punit);
118  marker->SetMarkerStyle(5);
119  cerr << "center t=" << t_center/tunit << ", p=" << p_center/punit << endl;
120 
121  TH2F* hist = new TH2F("patch1","Diffusion Patch",
122  tbins.nbins(), tbins.min()/tunit, tbins.max()/tunit,
123  pbins.nbins(), pbins.min()/punit, pbins.max()/punit);
124 
125  double total = 0.0;
126  hist->SetXTitle("time (us)");
127  hist->SetYTitle("pitch (mm)");
128  for (int it=0; it < patch.cols(); ++it) {
129  double tval = tbins.center(it+toffset);
130  Assert(tbins.inside(tval));
131  for (int ip=0; ip < patch.rows(); ++ip) {
132  double pval = pbins.edge(ip+poffset)+0.0001;
133  Assert(pbins.inside(pval));
134  const double value = patch(ip,it);
135  hist->Fill(tval/tunit, pval/punit, value);
136  total += value;
137  }
138  }
139  hist->Write();
140  hist->Draw("colz");
141  marker->Draw();
142  cerr << "total=" << total << " integ=" << hist->Integral() << " maximum=" << hist->GetMaximum() << endl;
143 }
static const double m
Definition: Units.h:79
double center(int ind) const
Definition: Binning.h:86
double max() const
Definition: Binning.h:52
Binning tbins(nticks, t0, t0+readout_time)
#define Assert
Definition: Testing.h:7
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
double min() const
Definition: Binning.h:47
static const double mm
Definition: Units.h:73
bool inside(double val) const
Definition: Binning.h:105
static const double us
Definition: Units.h:101
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
static const double ms
Definition: Units.h:100
static const double cm
Definition: Units.h:76
int nbins() const
Definition: Binning.h:42
QTextStream & endl(QTextStream &s)