Public Types | Public Member Functions | Private Attributes | List of all members
WireCell::Gen::BinnedDiffusion Class Reference

#include <BinnedDiffusion.h>

Public Types

enum  ImpactDataCalculationStrategy { constant =1, linear =2 }
 Useful to client code to mark a calculation strategy. More...
 

Public Member Functions

 BinnedDiffusion (const Pimpos &pimpos, const Binning &tbins, double nsigma=3.0, IRandom::pointer fluctuate=nullptr, ImpactDataCalculationStrategy calcstrat=linear)
 
const Pimpospimpos () const
 
const Binningtbins () const
 
bool add (IDepo::pointer deposition, double sigma_time, double sigma_pitch)
 
void add (std::shared_ptr< GaussianDiffusion > gd, int impact_index)
 
void erase (int begin_impact_index, int end_impact_index)
 
ImpactData::pointer impact_data (int bin) const
 
std::pair< double, double > pitch_range (double nsigma=0.0) const
 
std::pair< int, int > impact_bin_range (double nsigma=0.0) const
 
std::pair< double, double > time_range (double nsigma=0.0) const
 
std::pair< int, int > time_bin_range (double nsigma=0.0) const
 
double get_nsigma () const
 

Private Attributes

const Pimposm_pimpos
 
const Binningm_tbins
 
double m_nsigma
 
IRandom::pointer m_fluctuate
 
ImpactDataCalculationStrategy m_calcstrat
 
std::pair< int, int > m_window
 
std::map< int, ImpactData::mutable_pointerm_impacts
 
std::set< std::shared_ptr< GaussianDiffusion > > m_diffs
 
int m_outside_pitch
 
int m_outside_time
 

Detailed Description

A BinnedDiffusion maintains an association between impact positions along the pitch direction of a wire plane and the diffused depositions that drift to them.

It covers a fixed and discretely sampled time and pitch domain.

Definition at line 23 of file BinnedDiffusion.h.

Member Enumeration Documentation

Useful to client code to mark a calculation strategy.

Create a BinnedDiffusion.

Arguments are:

  • pimpos :: a Pimpos instance defining the wire and impact binning.
  • tbins :: a Binning instance defining the time sampling binning.
  • nsigma :: number of sigma the 2D (transverse X longitudinal) Gaussian extends.
  • fluctuate :: set to an IRandom if charge-preserving Poisson fluctuations are to be applied.
  • calcstrat :: set a calculation strategy that gives how the microscopic distribution of charge between two impacts will be interpolated toward either edge.
Enumerator
constant 
linear 

Definition at line 47 of file BinnedDiffusion.h.

Constructor & Destructor Documentation

Gen::BinnedDiffusion::BinnedDiffusion ( const Pimpos pimpos,
const Binning tbins,
double  nsigma = 3.0,
IRandom::pointer  fluctuate = nullptr,
ImpactDataCalculationStrategy  calcstrat = linear 
)

Definition at line 11 of file BinnedDiffusion.cxx.

14  : m_pimpos(pimpos)
15  , m_tbins(tbins)
16  , m_nsigma(nsigma)
17  , m_fluctuate(fluctuate)
18  , m_calcstrat(calcstrat)
19  , m_window(0,0)
20  , m_outside_pitch(0)
21  , m_outside_time(0)
22 {
23 }
std::pair< int, int > m_window
ImpactDataCalculationStrategy m_calcstrat

Member Function Documentation

bool Gen::BinnedDiffusion::add ( IDepo::pointer  deposition,
double  sigma_time,
double  sigma_pitch 
)

Add a deposition and its associated diffusion sigmas. Return false if no activity falls within the domain.

Definition at line 25 of file BinnedDiffusion.cxx.

26 {
27 
28  const double center_time = depo->time();
29  const double center_pitch = m_pimpos.distance(depo->pos());
30 
31  Gen::GausDesc time_desc(center_time, sigma_time);
32  {
33  double nmin_sigma = time_desc.distance(m_tbins.min());
34  double nmax_sigma = time_desc.distance(m_tbins.max());
35 
36  double eff_nsigma = sigma_time>0?m_nsigma:0;
37  if (nmin_sigma > eff_nsigma || nmax_sigma < -eff_nsigma) {
38  // std::cerr << "BinnedDiffusion: depo too far away in time sigma:"
39  // << " t_depo=" << center_time/units::ms << "ms not in:"
40  // << " t_bounds=[" << m_tbins.min()/units::ms << ","
41  // << m_tbins.max()/units::ms << "]ms"
42  // << " in Nsigma: [" << nmin_sigma << "," << nmax_sigma << "]\n";
44  return false;
45  }
46  }
47 
48  auto ibins = m_pimpos.impact_binning();
49 
50  Gen::GausDesc pitch_desc(center_pitch, sigma_pitch);
51  {
52  double nmin_sigma = pitch_desc.distance(ibins.min());
53  double nmax_sigma = pitch_desc.distance(ibins.max());
54 
55  double eff_nsigma = sigma_pitch>0?m_nsigma:0;
56  if (nmin_sigma > eff_nsigma || nmax_sigma < -eff_nsigma) {
57  // std::cerr << "BinnedDiffusion: depo too far away in pitch sigma: "
58  // << " p_depo=" << center_pitch/units::cm << "cm not in:"
59  // << " p_bounds=[" << ibins.min()/units::cm << ","
60  // << ibins.max()/units::cm << "]cm"
61  // << " in Nsigma:[" << nmin_sigma << "," << nmax_sigma << "]\n";
63  return false;
64  }
65  }
66 
67  // make GD and add to all covered impacts
68  int bin_beg = std::max(ibins.bin(center_pitch - sigma_pitch*m_nsigma), 0);
69  int bin_end = std::min(ibins.bin(center_pitch + sigma_pitch*m_nsigma)+1, ibins.nbins());
70  // debug
71  //int bin_center = ibins.bin(center_pitch);
72  //cerr << "DEBUG center_pitch: "<<center_pitch/units::cm<<endl;
73  //cerr << "DEBUG bin_center: "<<bin_center<<endl;
74 
75  auto gd = std::make_shared<GaussianDiffusion>(depo, time_desc, pitch_desc);
76  for (int bin = bin_beg; bin < bin_end; ++bin) {
77  // if (bin == bin_beg) m_diffs.insert(gd);
78  this->add(gd, bin);
79  }
80 
81  return true;
82 }
bool add(IDepo::pointer deposition, double sigma_time, double sigma_pitch)
double distance(const Point &pt, int axis=2) const
Definition: Pimpos.cxx:71
double max() const
Definition: Binning.h:52
const Binning & impact_binning() const
Definition: Pimpos.h:113
double min() const
Definition: Binning.h:47
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
QTextStream & bin(QTextStream &s)
void Gen::BinnedDiffusion::add ( std::shared_ptr< GaussianDiffusion gd,
int  impact_index 
)

Unconditionally associate an already built GaussianDiffusion to one impact.

Definition at line 84 of file BinnedDiffusion.cxx.

85 {
86  ImpactData::mutable_pointer idptr = nullptr;
87  auto it = m_impacts.find(bin);
88  if (it == m_impacts.end()) {
89  idptr = std::make_shared<ImpactData>(bin);
90  m_impacts[bin] = idptr;
91  }
92  else {
93  idptr = it->second;
94  }
95  idptr->add(gd);
96  if (false) { // debug
97  auto mm = idptr->span();
98  cerr << "Gen::BinnedDiffusion: add: "
99  << " poffoset="<<gd->poffset_bin()
100  << " toffoset="<<gd->toffset_bin()
101  << " charge=" << gd->depo()->charge()/units::eplus << " eles"
102  <<", for bin " << bin << " t=[" << mm.first/units::us << "," << mm.second/units::us << "]us\n";
103  }
104  m_diffs.insert(gd);
105  //m_diffs.push_back(gd);
106 }
static const double eplus
Definition: Units.h:110
static const double mm
Definition: Units.h:73
QTextStream & bin(QTextStream &s)
static const double us
Definition: Units.h:105
std::set< std::shared_ptr< GaussianDiffusion > > m_diffs
std::shared_ptr< ImpactData > mutable_pointer
Definition: ImpactData.h:29
std::map< int, ImpactData::mutable_pointer > m_impacts
void Gen::BinnedDiffusion::erase ( int  begin_impact_index,
int  end_impact_index 
)

Drop any stored ImpactData within the half open impact index range.

Definition at line 108 of file BinnedDiffusion.cxx.

109 {
110  for (int bin=begin_impact_number; bin<end_impact_number; ++bin) {
111  m_impacts.erase(bin);
112  }
113 }
QTextStream & bin(QTextStream &s)
std::map< int, ImpactData::mutable_pointer > m_impacts
double WireCell::Gen::BinnedDiffusion::get_nsigma ( ) const
inline

Definition at line 96 of file BinnedDiffusion.h.

std::pair< int, int > Gen::BinnedDiffusion::impact_bin_range ( double  nsigma = 0.0) const

Return the half open bin range of impact bins, constrained so that either number is in [0,nimpacts].

Definition at line 170 of file BinnedDiffusion.cxx.

171 {
172  const auto ibins = m_pimpos.impact_binning();
173  auto mm = pitch_range(nsigma);
174  return std::make_pair(std::max(ibins.bin(mm.first), 0),
175  std::min(ibins.bin(mm.second)+1, ibins.nbins()));
176 }
std::pair< double, double > pitch_range(double nsigma=0.0) const
const Binning & impact_binning() const
Definition: Pimpos.h:113
static int max(int a, int b)
static const double mm
Definition: Units.h:73
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
Gen::ImpactData::pointer Gen::BinnedDiffusion::impact_data ( int  bin) const

Return the data in the given impact bin. Note, this bin represents drifted charge between two impact positions. Take care when using BinnedDiffusion and field responses because epsilon above or below the impact position exactly in the middle of two wires drastically different response.

Definition at line 116 of file BinnedDiffusion.cxx.

117 {
118  const auto ib = m_pimpos.impact_binning();
119  if (! ib.inbounds(bin)) {
120  return nullptr;
121  }
122 
123  auto it = m_impacts.find(bin);
124  if (it == m_impacts.end()) {
125  return nullptr;
126  }
127  auto idptr = it->second;
128 
129  // make sure all diffusions have been sampled
130  for (auto diff : idptr->diffusions()) {
131  diff->set_sampling(m_tbins, ib, m_nsigma, m_fluctuate, m_calcstrat);
132  //diff->set_sampling(m_tbins, ib, m_nsigma, 0, m_calcstrat);
133  }
134 
135  idptr->calculate(m_tbins.nbins());
136  return idptr;
137 }
const Binning & impact_binning() const
Definition: Pimpos.h:113
ImpactDataCalculationStrategy m_calcstrat
QTextStream & bin(QTextStream &s)
std::map< int, ImpactData::mutable_pointer > m_impacts
int nbins() const
Definition: Binning.h:42
const Pimpos& WireCell::Gen::BinnedDiffusion::pimpos ( ) const
inline

Definition at line 53 of file BinnedDiffusion.h.

53 { return m_pimpos; }
std::pair< double, double > Gen::BinnedDiffusion::pitch_range ( double  nsigma = 0.0) const

Return the range of pitch containing depos out to given nsigma and without bounds checking.

Definition at line 161 of file BinnedDiffusion.cxx.

162 {
163  std::vector<Gen::GausDesc> gds;
164  for (auto diff : m_diffs) {
165  gds.push_back(diff->pitch_desc());
166  }
167  return gausdesc_range(gds, nsigma);
168 }
static std::pair< double, double > gausdesc_range(const std::vector< Gen::GausDesc > gds, double nsigma)
std::set< std::shared_ptr< GaussianDiffusion > > m_diffs
const Binning& WireCell::Gen::BinnedDiffusion::tbins ( ) const
inline

Definition at line 54 of file BinnedDiffusion.h.

54 { return m_tbins; }
std::pair< int, int > Gen::BinnedDiffusion::time_bin_range ( double  nsigma = 0.0) const

Return the half open bin range for time bins constrained so that either number is in [0,nticks].

Definition at line 187 of file BinnedDiffusion.cxx.

188 {
189  auto mm = time_range(nsigma);
190  return std::make_pair(std::max(m_tbins.bin(mm.first),0),
191  std::min(m_tbins.bin(mm.second)+1, m_tbins.nbins()));
192 }
int bin(double val) const
Definition: Binning.h:80
static int max(int a, int b)
static const double mm
Definition: Units.h:73
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
std::pair< double, double > time_range(double nsigma=0.0) const
int nbins() const
Definition: Binning.h:42
std::pair< double, double > Gen::BinnedDiffusion::time_range ( double  nsigma = 0.0) const

Return the range of time containing depos out to given nsigma and without bounds checking.

Definition at line 178 of file BinnedDiffusion.cxx.

179 {
180  std::vector<Gen::GausDesc> gds;
181  for (auto diff : m_diffs) {
182  gds.push_back(diff->time_desc());
183  }
184  return gausdesc_range(gds, nsigma);
185 }
static std::pair< double, double > gausdesc_range(const std::vector< Gen::GausDesc > gds, double nsigma)
std::set< std::shared_ptr< GaussianDiffusion > > m_diffs

Member Data Documentation

ImpactDataCalculationStrategy WireCell::Gen::BinnedDiffusion::m_calcstrat
private

Definition at line 105 of file BinnedDiffusion.h.

std::set<std::shared_ptr<GaussianDiffusion> > WireCell::Gen::BinnedDiffusion::m_diffs
private

Definition at line 113 of file BinnedDiffusion.h.

IRandom::pointer WireCell::Gen::BinnedDiffusion::m_fluctuate
private

Definition at line 104 of file BinnedDiffusion.h.

std::map<int, ImpactData::mutable_pointer> WireCell::Gen::BinnedDiffusion::m_impacts
private

Definition at line 110 of file BinnedDiffusion.h.

double WireCell::Gen::BinnedDiffusion::m_nsigma
private

Definition at line 103 of file BinnedDiffusion.h.

int WireCell::Gen::BinnedDiffusion::m_outside_pitch
private

Definition at line 115 of file BinnedDiffusion.h.

int WireCell::Gen::BinnedDiffusion::m_outside_time
private

Definition at line 116 of file BinnedDiffusion.h.

const Pimpos& WireCell::Gen::BinnedDiffusion::m_pimpos
private

Definition at line 96 of file BinnedDiffusion.h.

const Binning& WireCell::Gen::BinnedDiffusion::m_tbins
private

Definition at line 101 of file BinnedDiffusion.h.

std::pair<int,int> WireCell::Gen::BinnedDiffusion::m_window
private

Definition at line 108 of file BinnedDiffusion.h.


The documentation for this class was generated from the following files: