Classes | Functions | Variables
test_binneddiffusion.cxx File Reference
#include "WireCellGen/BinnedDiffusion.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 "TH1F.h"
#include "TPolyMarker.h"
#include <iostream>

Go to the source code of this file.

Classes

struct  Meta
 

Functions

Binning tbins (nticks, t0, t0+readout_time)
 
void test_track (Meta &meta, double charge, double track_time, const Ray &track_ray, double stepsize, IRandom::pointer fluctuate)
 
int main (int argc, char *argv[])
 

Variables

const double t0 = 1*units::s
 
const int nticks = 9600
 
const double tick = 0.5*units::us
 
const double readout_time = nticks*tick
 
const double drift_speed = 1.6*units::mm/units::us
 
const int nwires = 2001
 
const double wire_pitch = 3*units::mm
 
const double min_wire_pitch = -0.5*(nwires-1)*wire_pitch
 
const double max_wire_pitch = +0.5*(nwires-1)*wire_pitch
 
Pimpos pimpos (nwires, min_wire_pitch, max_wire_pitch)
 
const int npmwires = 10
 

Function Documentation

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

Definition at line 232 of file test_binneddiffusion.cxx.

233 {
235  pm.add("WireCellGen");
236  {
237  auto rngcfg = Factory::lookup<IConfigurable>("Random");
238  auto cfg = rngcfg->default_configuration();
239  rngcfg->configure(cfg);
240  }
241  auto rng = Factory::lookup<IRandom>("Random");
242 
243  const char* me = argv[0];
244 
245  TFile* rootfile = TFile::Open(Form("%s.root", me), "RECREATE");
246 
247  Meta meta(me);
248  gStyle->SetOptStat(0);
249 
250  const double track_time = t0+10*units::ns;
251  const double delta = 100*units::mm;
252  Ray track_ray(Point(1*units::m-delta, 0, -delta),
253  Point(1*units::m+delta, 0, +delta));
254  const double stepsize = 1*units::mm;
255  const double charge = 1e5;
256 
257 
258 
259  test_track(meta, charge, track_time, track_ray, stepsize, rng);
260 
261  meta.print("]");
262  rootfile->Close();
263  cerr << meta.em.summary() << endl;
264  return 0;
265 }
code to link reconstructed objects back to the MC truth information
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
static const double m
Definition: Units.h:79
const std::string instance
cfg
Definition: dbjson.py:29
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
void test_track(Meta &meta, double charge, double track_time, const Ray &track_ray, double stepsize, IRandom::pointer fluctuate)
static const double mm
Definition: Units.h:73
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
QAsciiDict< Entry > ns
QTextStream & endl(QTextStream &s)
Binning tbins ( nticks  ,
t0  ,
t0 readout_time 
)
void test_track ( Meta meta,
double  charge,
double  track_time,
const Ray track_ray,
double  stepsize,
IRandom::pointer  fluctuate 
)

Definition at line 68 of file test_binneddiffusion.cxx.

71 {
72  const int ndiffision_sigma = 3.0;
73 
74  const auto rbins = pimpos.region_binning();
75  const auto ibins = pimpos.impact_binning();
76 
77  Gen::BinnedDiffusion bd(pimpos, tbins, ndiffision_sigma, fluctuate);
78 
79  auto track_start = track_ray.first;
80  auto track_dir = ray_unit(track_ray);
81  auto track_length = ray_length(track_ray);
82 
83  const double DL=5.3*units::centimeter2/units::second;
84  const double DT=12.8*units::centimeter2/units::second;
85 
86  const double xstop = pimpos.origin()[0];
87 
88  meta.em("begin adding Depp's");
89  for (double dist=0.0; dist < track_length; dist += stepsize) {
90  auto pt = track_start + dist*track_dir;
91  const double delta_x = pt.x() - xstop;
92  const double drift_time = delta_x / drift_speed;
93  pt.x(xstop); // insta-drift
94  const double time = track_time+drift_time;
95 
96  const double pitch = pimpos.distance(pt);
97  Assert(rbins.inside(pitch));
98  Assert(ibins.inside(pitch)); // should be identical
99  Assert(tbins.inside(time));
100 
101  const double tmpcm2 = 2*DL*drift_time/units::centimeter2;
102  const double sigmaL = sqrt(tmpcm2)*units::centimeter / drift_speed;
103  const double sigmaT = sqrt(2*DT*drift_time/units::centimeter2)*units::centimeter2;
104 
105  auto depo = std::make_shared<SimpleDepo>(time, pt, charge);
106  bd.add(depo, sigmaL, sigmaT);
107  //cerr << "dist: " <<dist/units::mm << "mm, drift: " << drift_time/units::us << "us depo:" << depo->pos() << " @ " << depo->time()/units::us << "us\n";
108  }
109 
110 
111  meta.em("begin swiping wires");
112 
113 
114  for (int iwire = 0; iwire < nwires; ++iwire) {
115 
116  const int min_wire = std::max(iwire-npmwires, 0);
117  const int max_wire = std::min(iwire+npmwires, nwires-1);
118 
119  const int min_impact = std::max(pimpos.wire_impacts(min_wire).first, 0);
120  const int max_impact = std::min(pimpos.wire_impacts(max_wire).second, ibins.nbins());
121 
122  std::pair<double,double> time_span(0,0);
123  std::vector<Gen::ImpactData::pointer> collect;
124 
125  std::set<int> seen;
126  for (int imp = min_impact; imp <= max_impact; ++imp) {
127  auto impact_data = bd.impact_data(imp);
128  if (!impact_data) {
129  continue;
130  }
131 
132  const int impnum = impact_data->impact_number();
133  if (seen.find(impnum) != seen.end()) {
134  cerr << "Got duplicate impact number: " << impnum << " in wire " << iwire << endl;
135  }
136  seen.insert(impnum);
137  if (iwire==974) {
138  cerr << "collecting: " << iwire << " " << impnum << endl;
139  }
140 
141  auto ts = impact_data->span(ndiffision_sigma);
142  if (collect.empty()) {
143  time_span = ts;
144  }
145  else {
146  time_span.first = std::min(time_span.first, ts.first);
147  time_span.second = std::max(time_span.second, ts.second);
148  }
149  collect.push_back(impact_data);
150  }
151 
152  if (collect.empty()) {
153  continue;
154  }
155 
156  //bd.erase(0, min_impact);
157 
158  if (false) {
159  cerr << "Not histogramming\n";
160  continue;
161  }
162 
163  const int min_tedge = tbins.edge_index(time_span.first);
164  const int max_tedge = tbins.edge_index(time_span.second);
165 
166  const double min_time = tbins.edge(min_tedge);
167  const double max_time = tbins.edge(max_tedge);
168  const int ntbins = max_tedge - min_tedge;
169 
170  const double min_pitch = ibins.edge(min_impact);
171  const double max_pitch = ibins.edge(max_impact);
172  const int npbins = (max_pitch-min_pitch)/ibins.binsize();
173 
174  // cerr << "t:"<<ntbins<<"["<<min_time/units::us<<","<<max_time/units::us<<"]us ("<<max_time-min_time<<")\n";
175  // cerr << "p:"<<npbins<<"["<<min_pitch/units::mm<<","<<max_pitch/units::mm<<"]mm\n";
176 
177  Assert(max_time > min_time);
178  Assert(ntbins>1);
179  Assert(max_pitch > min_pitch);
180  Assert(npbins>1);
181 
182  TH2F hist(Form("hwire%04d", iwire),Form("Diffused charge for wire %d", iwire),
183  ntbins, (min_time-t0)/units::us, (max_time-t0)/units::us,
184  npbins, min_pitch/units::mm, max_pitch/units::mm);
185  hist.SetXTitle("time (us)");
186  hist.SetYTitle("pitch (mm)");
187 
188  TH1F hp(Form("pwire%04d", iwire),Form("Pitches for wire %d", iwire),
189  npbins, min_pitch/units::mm, max_pitch/units::mm);
190  TH1F ht(Form("twire%04d", iwire),Form("Times for wire %d", iwire),
191  ntbins, (min_time-t0)/units::us, (max_time-t0)/units::us);
192 
193  for (auto idptr : collect) {
194  auto wave = idptr->waveform();
195  Assert (wave.size() == nticks);
196  const int impact = idptr->impact_number();
197  const double pitch_dist = ibins.center(impact);
198  if (iwire == 974) {
199  cerr << iwire << " impact=" << impact << " pitch=" << pitch_dist << endl;
200  }
201  auto mm = idptr->span(ndiffision_sigma);
202  const int min_tick = tbins.bin(mm.first);
203  const int max_tick = tbins.bin(mm.second);
204  //cerr << "impact:" << impact << " pitch="<<pitch_dist/units::mm << " ticks:["<<min_tick<<","<<max_tick<<"]\n";
205  for (int itick=min_tick; itick<=max_tick; ++itick) {
206  const double time = tbins.center(itick);
207  if (!tbins.inside(time)) {
208  cerr << "OOB time: " << time/units::us << "us tick:"<<itick
209  << " impact:" << idptr->impact_number()
210  << " pitch:" << pitch_dist/units::mm << "mm\n";
211  }
212 
213  Assert(tbins.inside(time));
214  Assert(rbins.inside(pitch_dist));
215  const double t_us = (time-t0)/units::us;
216  const double p_mm = pitch_dist/units::mm;
217  hist.Fill(t_us, p_mm, wave[itick]);
218  ht.Fill(t_us);
219  hp.Fill(p_mm);
220  }
221  }
222  hist.Draw("colz");
223  //hp.Draw();
224  hist.Write();
225  ht.Write();
226  hp.Write();
227  meta.print();
228  }
229  meta.em("done");
230 }
code to link reconstructed objects back to the MC truth information
const int nwires
int edge_index(double val) const
Definition: Binning.h:93
double center(int ind) const
Definition: Binning.h:86
const Point & origin() const
Return given 3-point origin for plane pitch.
Definition: Pimpos.h:85
const Binning & region_binning() const
Definition: Pimpos.h:109
double distance(const Point &pt, int axis=2) const
Definition: Pimpos.cxx:71
const int nticks
Binning tbins(nticks, t0, t0+readout_time)
#define Assert
Definition: Testing.h:7
const Binning & impact_binning() const
Definition: Pimpos.h:113
const double t0
int bin(double val) const
Definition: Binning.h:80
double ray_length(const Ray &ray)
Definition: Point.cxx:62
Vector ray_unit(const Ray &ray)
Definition: Point.cxx:71
static int max(int a, int b)
const double drift_speed
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
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
Pimpos pimpos(nwires, min_wire_pitch, max_wire_pitch)
std::pair< int, int > wire_impacts(int wireind) const
Definition: Pimpos.cxx:48
const int npmwires
double edge(int ind) const
Definition: Binning.h:99
static const double centimeter
Definition: Units.h:52
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:80
void print(const char *extra="")
QTextStream & endl(QTextStream &s)
static const double centimeter2
Definition: Units.h:53

Variable Documentation

const double drift_speed = 1.6*units::mm/units::us

Definition at line 53 of file test_binneddiffusion.cxx.

const double max_wire_pitch = +0.5*(nwires-1)*wire_pitch

Definition at line 58 of file test_binneddiffusion.cxx.

const double min_wire_pitch = -0.5*(nwires-1)*wire_pitch

Definition at line 57 of file test_binneddiffusion.cxx.

const int npmwires = 10

Definition at line 65 of file test_binneddiffusion.cxx.

const int nticks = 9600

Definition at line 50 of file test_binneddiffusion.cxx.

const int nwires = 2001

Definition at line 55 of file test_binneddiffusion.cxx.

const double readout_time = nticks*tick

Definition at line 52 of file test_binneddiffusion.cxx.

const double t0 = 1*units::s

Definition at line 48 of file test_binneddiffusion.cxx.

const double tick = 0.5*units::us

Definition at line 51 of file test_binneddiffusion.cxx.

const double wire_pitch = 3*units::mm

Definition at line 56 of file test_binneddiffusion.cxx.