34 string track_types =
"point";
36 track_types = argv[1];
38 cerr <<
"Using tracks type: \"" << track_types <<
"\"\n";
40 string response_file =
"ub-10-half.json.bz2";
42 response_file = argv[2];
43 cerr <<
"Using Wire Cell field response file:\n" 44 << response_file <<
endl;
47 cerr <<
"No Wire Cell field response input file given, will try to use:\n" 48 << response_file <<
endl;
51 string out_basename = argv[0];
53 out_basename = argv[3];
61 pm.
add(
"WireCellGen");
62 pm.
add(
"WireCellSigProc");
64 auto rngcfg = Factory::lookup<IConfigurable>(
"Random");
65 auto cfg = rngcfg->default_configuration();
66 rngcfg->configure(cfg);
78 const std::string er_tn =
"ElecResponse", rc_tn =
"RCResponse";
81 auto icfg = Factory::lookup_tn<IConfigurable>(er_tn);
82 auto cfg = icfg->default_configuration();
84 cfg[
"shaping"] = shaping;
86 cerr <<
"Setting: " << cfg[
"nticks"].asInt() <<
" ticks\n";
92 auto icfg = Factory::lookup_tn<IConfigurable>(rc_tn);
93 auto cfg = icfg->default_configuration();
100 auto icfg = Factory::lookup<IConfigurable>(
"FieldResponse");
101 auto cfg = icfg->default_configuration();
102 cfg[
"filename"] = response_file;
103 icfg->configure(cfg);
106 std::vector<std::string> pir_tns{
"PlaneImpactResponse:U",
107 "PlaneImpactResponse:V",
"PlaneImpactResponse:W"};
109 for (
int iplane=0; iplane<3; ++iplane) {
110 auto icfg = Factory::lookup_tn<IConfigurable>(pir_tns[iplane]);
111 auto cfg = icfg->default_configuration();
112 cfg[
"plane"] = iplane;
115 cfg[
"other_responses"][0] = er_tn;
116 cfg[
"other_responses"][1] = rc_tn;
117 cfg[
"other_responses"][2] = rc_tn;
118 icfg->configure(cfg);
125 auto ifr = Factory::find_tn<IFieldResponse>(
"FieldResponse");
126 auto fr = ifr->field_response();
129 em(
"loaded response");
131 const char* uvw =
"UVW";
135 const Vector upitch(0, -sin(angle), cos(angle));
136 const Vector uwire (0, cos(angle), sin(angle));
137 const Vector vpitch(0, sin(angle), cos(angle));
138 const Vector vwire (0, cos(angle), -sin(angle));
139 const Vector wpitch(0, 0, 1);
140 const Vector wwire (0, 1, 0);
146 Point field_origin(fr.origin, 0, 0);
147 cerr <<
"Field response origin: " << field_origin/
units::mm <<
"mm\n";
152 const int nregion_bins = 10;
153 const double halfwireextent = wire_pitch * 0.5 * (nwires - 1);
154 cerr <<
"Max wire at pitch=" << halfwireextent <<
endl;
156 std::vector<Pimpos> uvw_pimpos{
157 Pimpos(nwires, -halfwireextent, halfwireextent,
158 uwire, upitch, field_origin, nregion_bins),
159 Pimpos(nwires, -halfwireextent, halfwireextent,
160 vwire, vpitch, field_origin, nregion_bins),
161 Pimpos(nwires, -halfwireextent, halfwireextent,
162 wwire, wpitch, field_origin, nregion_bins)};
168 const int ndiffision_sigma = 3.0;
169 bool fluctuate =
false;
178 const double charge_per_depo = -(dqdx)*stepsize;
180 const double event_time = t0 + 1*
units::ms;
184 if (track_types.find(
"prolong") < track_types.size()) {
196 if (track_types.find(
"isoch") < track_types.size()) {
203 if (track_types.find(
"driftlike") < track_types.size()) {
211 if (track_types.find(
"plus") < track_types.size()) {
231 if (track_types.find(
"point") < track_types.size()) {
233 for(
int i=0; i<6; i++)
239 vt +
Vector(0, 0, 0.1*stepsize)),
254 std::cerr <<
"got " <<
depos.size() <<
" depos from tracks\n";
257 TFile* rootfile = TFile::Open(Form(
"%s-uvw.root", out_basename.c_str()),
"recreate");
258 TCanvas* canvas =
new TCanvas(
"c",
"canvas",1000,1000);
259 gStyle->SetOptStat(0);
263 canvas->Print((pdfname+
"[").c_str(),
"pdf");
268 rng = Factory::lookup<IRandom>(
"Random");
271 for (
int plane_id = 0; plane_id < 3; ++plane_id) {
272 em(
"start loop over planes");
276 Gen::BinnedDiffusion bindiff(pimpos, tbins, ndiffision_sigma, rng, Gen::BinnedDiffusion::ImpactDataCalculationStrategy::constant);
277 em(
"made BinnedDiffusion");
278 for (
auto depo :
depos) {
279 auto drifted = std::make_shared<Gen::TransportedDepo>(depo, field_origin.x(),
drift_speed);
290 const double sigma_pitch = 1.5*
units::mm;
292 bool ok = bindiff.
add(drifted, sigma_time, sigma_pitch);
301 <<
" pt=" << drifted->pos() /
units::mm <<
" mm\n";
304 em(
"added track depositions");
306 auto ipir = Factory::find_tn<IPlaneImpactResponse>(pir_tns[plane_id]);
308 em(
"looked up " + pir_tns[plane_id]);
311 const double pmax = 0.5*ipir->pitch_range();
313 const int npbins = 2.0*pmax/pstep;
314 const int ntbins = pr->
paths[0].current.size();
316 const double tmin = fr.tstart;
317 const double tmax = fr.tstart + fr.period*ntbins;
318 TH2F* hpir =
new TH2F(Form(
"hfr%d", plane_id), Form(
"Field Response %c-plane", uvw[plane_id]),
320 npbins, -pmax, pmax);
321 for (
auto& path : pr->
paths) {
322 const double cpitch = path.pitchpos;
323 for (
size_t ic=0; ic<path.current.size(); ++ic) {
324 const double ctime = fr.tstart + ic*fr.period;
325 const double charge = path.current[ic]*fr.period;
329 hpir->SetZTitle(
"Induced charge [eles]");
333 if (track_types.find(
"point") < track_types.size()) {
339 canvas->Print(pdfname.c_str(),
"pdf");
341 em(
"wrote and leaked response hist");
344 em(
"made ImpactZipper");
349 const int wbin0 =
max(0, rbins.bin(pmm.first) - 40);
350 const int wbinf =
min(rbins.nbins()-1, rbins.bin(pmm.second) + 40);
351 const int nwbins = 1+wbinf-wbin0;
354 const int tbin0 = 3500, tbinf=5500;
355 const int ntbins = tbinf-tbin0;
357 std::map<int, Waveform::realseq_t> frame;
359 for (
int iwire=wbin0; iwire <= wbinf; ++iwire) {
363 auto mm = std::minmax_element(wave.begin(), wave.end());
364 cerr <<
"^ Wire " << iwire <<
" tot=" << tot/
units::uV <<
" uV" 371 auto mm = std::minmax_element(wave.begin(), wave.end());
372 std::cerr <<
"central wire: " << iwire
380 em(
"zipped through wires");
381 cerr <<
"Tottot = " << tottot <<
endl;
384 TH2F *
hist =
new TH2F(Form(
"h%d", plane_id),
385 Form(
"Wire vs Tick %c-plane", uvw[plane_id]),
386 ntbins, tbin0, tbin0+ntbins,
387 nwbins, wbin0, wbin0+nwbins);
388 hist->SetXTitle(
"tick");
389 hist->SetYTitle(
"wire");
390 hist->SetZTitle(
"Voltage [-#muV]");
392 std::cerr << nwbins <<
" wires: [" << wbin0 <<
"," << wbinf <<
"], " 393 << ntbins <<
" ticks: [" << tbin0 <<
"," << tbinf <<
"]\n";
396 for (
auto wire : frame) {
397 const int iwire = wire.first;
398 Assert(rbins.inbounds(iwire));
402 for (
int itick=tbin0; itick <= tbinf; ++itick) {
407 if (track_types.find(
"point") < track_types.size()) {
408 hist->GetXaxis()->SetRangeUser(3950,4100);
409 hist->GetYaxis()->SetRangeUser(996, 1004);
411 if (track_types.find(
"isoch") < track_types.size()) {
412 hist->GetXaxis()->SetRangeUser(3900,4000);
413 hist->GetYaxis()->SetRangeUser(995, 1020);
419 canvas->SetRightMargin(0.15);
421 std::vector<TLine*> lines;
422 auto trqs = tracks.
tracks();
423 for (
size_t iline=0; iline<trqs.size(); ++iline) {
424 auto trq = trqs[iline];
425 const double time = get<0>(trq);
426 const Ray ray = get<1>(trq);
432 const int tick1 = tbins.
bin(time + (ray.first.x()-fr.origin)/drift_speed);
433 const int tick2 = tbins.
bin(time + (ray.second.x()-fr.origin)/drift_speed);
435 const int wire1 = rbins.bin(pimpos.
distance(ray.first));
436 const int wire2 = rbins.bin(pimpos.
distance(ray.second));
438 cerr <<
"digitrack: t=" << time <<
" ticks=["<<tick1<<
","<<tick2<<
"] wires=["<<wire1<<
","<<wire2<<
"]\n";
441 TLine*
line =
new TLine(tick1-fudge, wire1, tick2-fudge, wire2);
442 line->Write(Form(
"l%c%d", uvw[plane_id], (
int)iline));
445 canvas->Print(pdfname.c_str(),
"pdf");
447 em(
"printed PNG canvases");
448 em(
"end of PIR scope");
453 canvas->Print((pdfname+
"]").c_str(),
"pdf");
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.
static const double eplus
std::shared_ptr< IRandom > pointer
Access subclass facet by pointer.
void add_track(double time, const WireCell::Ray &ray, double dedx=-1.0)
D3Vector< double > Point
A 3D Cartesian point in double precision.
bool add(IDepo::pointer deposition, double sigma_time, double sigma_pitch)
const Binning & region_binning() const
double distance(const Point &pt, int axis=2) const
std::pair< double, double > pitch_range(double nsigma=0.0) const
static PluginManager & instance()
Binning tbins(nticks, t0, t0+readout_time)
static const double microvolt
A producer of depositions created from some number of simple, linear tracks.
int bin(double val) const
WireCell::IDepo::vector depos()
std::vector< track_t > tracks() const
static int max(int a, int b)
Point Vector
An alias for Point.
std::vector< float > Vector
int main(const int argc, char *argv[])
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Pimpos pimpos(nwires, min_wire_pitch, max_wire_pitch)
Waveform::realseq_t waveform(int wire) const
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
std::vector< PathResponse > paths
List of PathResponse objects.
QTextStream & endl(QTextStream &s)
const double readout_time
static const double degree