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

#include <TruthTraceID.h>

Inheritance diagram for WireCell::Gen::TruthTraceID:
WireCell::IDuctor WireCell::IConfigurable WireCell::IQueuedoutNode< IDepo, IFrame > WireCell::IComponent< IConfigurable > WireCell::IQueuedoutNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 TruthTraceID ()
 
virtual void reset ()
 
virtual bool operator() (const input_pointer &depo, output_queue &frames)
 The calling signature: More...
 
virtual void configure (const WireCell::Configuration &config)
 Accept a configuration. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
- Public Member Functions inherited from WireCell::IDuctor
virtual ~IDuctor ()
 
virtual std::string signature ()
 
- Public Member Functions inherited from WireCell::IQueuedoutNode< IDepo, IFrame >
virtual ~IQueuedoutNode ()
 
virtual bool operator() (const boost::any &anyin, queuedany &outanyq)
 The calling signature: More...
 
virtual std::vector< std::stringinput_types ()
 
virtual std::vector< std::stringoutput_types ()
 
- Public Member Functions inherited from WireCell::IQueuedoutNodeBase
virtual ~IQueuedoutNodeBase ()
 
virtual NodeCategory category ()
 Return the behavior category type. More...
 
virtual int concurrency ()
 By default assume all subclasses maintain state. More...
 
- Public Member Functions inherited from WireCell::INode
virtual ~INode ()
 
- Public Member Functions inherited from WireCell::IComponent< INode >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 
- Public Member Functions inherited from WireCell::IConfigurable
virtual ~IConfigurable ()
 
- Public Member Functions inherited from WireCell::IComponent< IConfigurable >
virtual ~IComponent ()
 

Private Member Functions

void process (output_queue &frame)
 

Private Attributes

std::string m_anode_tn
 
std::string m_rng_tn
 
IAnodePlane::pointer m_anode
 
IRandom::pointer m_rng
 
IDepo::vector m_depos
 
double m_start_time
 
double m_readout_time
 
double m_tick
 
double m_pitch_range
 
double m_drift_speed
 
double m_nsigma
 
double m_truth_gain
 
bool m_fluctuate
 
int m_frame_count
 
bool m_eos
 
std::string m_truth_type
 
double m_num_ind_wire
 
double m_num_col_wire
 
double m_ind_sigma
 
double m_col_sigma
 
double m_time_sigma
 
double m_wire_power
 
double m_time_power
 
double m_max_wire_freq
 
double m_max_time_freq
 
bool m_wire_flag
 
bool m_time_flag
 

Additional Inherited Members

- Public Types inherited from WireCell::IDuctor
typedef std::shared_ptr< IDuctorpointer
 
- Public Types inherited from WireCell::IQueuedoutNode< IDepo, IFrame >
typedef std::shared_ptr< IQueuedoutNodeBasepointer
 
typedef IDepo input_type
 
typedef IFrame output_type
 
typedef std::shared_ptr< const IDepoinput_pointer
 
typedef std::shared_ptr< const IFrameoutput_pointer
 
typedef std::deque< output_pointeroutput_queue
 
- Public Types inherited from WireCell::IQueuedoutNodeBase
typedef std::shared_ptr< IQueuedoutNodeBasepointer
 
typedef std::deque< boost::any > queuedany
 
- Public Types inherited from WireCell::INode
enum  NodeCategory {
  unknown, sourceNode, sinkNode, functionNode,
  queuedoutNode, joinNode, splitNode, faninNode,
  fanoutNode, multioutNode, hydraNode
}
 
- Public Types inherited from WireCell::IComponent< INode >
typedef std::shared_ptr< INodepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Public Types inherited from WireCell::Interface
typedef std::shared_ptr< Interfacepointer
 
- Public Types inherited from WireCell::IComponent< IConfigurable >
typedef std::shared_ptr< IConfigurablepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 

Detailed Description

Definition at line 16 of file TruthTraceID.h.

Constructor & Destructor Documentation

Gen::TruthTraceID::TruthTraceID ( )

Definition at line 17 of file TruthTraceID.cxx.

18  : m_anode_tn("AnodePlane")
19  , m_rng_tn("Random")
20  , m_start_time(0.0*units::ns)
22  , m_tick(0.5*units::us)
23  , m_pitch_range(20*3*units::mm) // +/- 10 wires
25  , m_nsigma(3.0)
26  , m_truth_gain(-1.0)
27  , m_fluctuate(true)
28  , m_frame_count(0)
29  , m_eos(false)
30  , m_truth_type("Bare")
31  , m_num_ind_wire(2400.0)
32  , m_num_col_wire(3456.0)
33  , m_ind_sigma(1./std::sqrt(3.1415926)*1.4)
34  , m_col_sigma(1./std::sqrt(3.1415926)*3.0)
36  , m_wire_power(2.0)
37  , m_time_power(2.0)
38  , m_max_wire_freq(1.0)
40  , m_wire_flag(false)
41  , m_time_flag(true)
42 {
43 }
static const double ms
Definition: Units.h:104
static const double ns
Definition: Units.h:102
static const double mm
Definition: Units.h:55
static const double us
Definition: Units.h:105
static const double megahertz
Definition: Units.h:99

Member Function Documentation

void Gen::TruthTraceID::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 73 of file TruthTraceID.cxx.

73  {
74  m_anode_tn = get<string>(cfg, "anode", m_anode_tn);
75  m_anode = Factory::find_tn<IAnodePlane>(m_anode_tn);
76  if(!m_anode){
77  cerr << "Gen::Truth: failed to get anode: \"" << m_anode_tn << "\"\n";
78  return;
79  }
80 
81  m_nsigma = get<double>(cfg, "nsigma", m_nsigma);
82  m_fluctuate = get<bool>(cfg, "fluctuate", m_fluctuate);
83  m_rng = nullptr;
84  if(m_fluctuate){
85  m_rng_tn = get(cfg, "rng", m_rng_tn);
86  m_rng = Factory::find_tn<IRandom>(m_rng_tn);
87  }
88 
89  m_readout_time = get<double>(cfg, "readout_time", m_readout_time);
90  m_tick = get<double>(cfg, "tick", m_tick);
91  m_start_time = get<double>(cfg, "start_time", m_start_time);
92  m_drift_speed = get<double>(cfg, "drift_speed", m_drift_speed);
93  m_frame_count = get<int>(cfg, "first_frame_number", m_frame_count);
94  m_truth_gain = get<double>(cfg, "truth_gain", m_truth_gain);
95 
96  m_truth_type = get<string>(cfg, "truth_type", m_truth_type);
97  m_num_ind_wire = get<double>(cfg, "number_induction_wire", m_num_ind_wire);
98  m_num_col_wire = get<double>(cfg, "number_collection_wire", m_num_col_wire);
99  m_ind_sigma = get<double>(cfg, "induction_sigma", m_ind_sigma);
100  m_col_sigma = get<double>(cfg, "collection_sigma", m_col_sigma);
101  m_time_sigma = get<double>(cfg, "time_sigma", m_time_sigma);
102  m_wire_power = get<double>(cfg, "wire_power", m_wire_power);
103  m_time_power = get<double>(cfg, "time_power", m_time_power);
104  m_max_wire_freq = get<double>(cfg, "max_wire_frequency", m_max_wire_freq);
105  m_max_time_freq = get<double>(cfg, "max_time_frequency", m_max_time_freq);
106  m_wire_flag = get<bool>(cfg, "wire_filter_flag", m_wire_flag);
107  m_time_flag = get<bool>(cfg, "time_filter_flag", m_time_flag);
108 }
cfg
Definition: dbjson.py:29
IAnodePlane::pointer m_anode
Definition: TruthTraceID.h:29
IRandom::pointer m_rng
Definition: TruthTraceID.h:30
WireCell::Configuration Gen::TruthTraceID::default_configuration ( ) const
virtual

Optional, override to return a hard-coded default configuration.

Reimplemented from WireCell::IConfigurable.

Definition at line 45 of file TruthTraceID.cxx.

45  {
47  put(cfg, "nsigma", m_nsigma);
48  put(cfg, "fluctuate", m_fluctuate);
49  put(cfg, "start_time", m_start_time);
50  put(cfg, "readout_time", m_readout_time);
51  put(cfg, "tick", m_tick);
52  put(cfg, "pitch_range", m_pitch_range);
53  put(cfg, "drift_speed", m_drift_speed);
54  put(cfg, "first_frame_number", m_frame_count);
55  put(cfg, "anode", m_anode_tn);
56  put(cfg, "rng", m_rng_tn);
57  put(cfg, "truth_type", m_truth_type);
58  put(cfg, "number_induction_wire", m_num_ind_wire);
59  put(cfg, "number_collection_wire", m_num_col_wire);
60  put(cfg, "induction_sigma", m_ind_sigma);
61  put(cfg, "collection_sigma", m_col_sigma);
62  put(cfg, "time_sigma", m_time_sigma);
63  put(cfg, "wire_power", m_wire_power);
64  put(cfg, "time_power", m_time_power);
65  put(cfg, "max_wire_frequency", m_max_wire_freq);
66  put(cfg, "max_time_frequency", m_max_time_freq);
67  put(cfg, "wire_filter_flag", m_wire_flag);
68  put(cfg, "time_filter_flag", m_time_flag);
69  put(cfg, "truth_gain", m_truth_gain);
70  return cfg;
71 }
void put(Configuration &cfg, const std::string &dotpath, const T &val)
Put value in configuration at the dotted path.
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Gen::TruthTraceID::operator() ( const input_pointer in,
output_queue outq 
)
virtual

The calling signature:

Implements WireCell::IQueuedoutNode< IDepo, IFrame >.

Definition at line 225 of file TruthTraceID.cxx.

225  {
226  if(m_eos){
227  return false;
228  }
229 
230  double target_time = m_start_time + m_readout_time;
231  if(!depo || depo->time() > target_time){
232  process(frames);
233  }
234 
235  if(depo){
236  m_depos.push_back(depo);
237  }
238  else{
239  m_eos = true;
240  }
241 
242  return true;
243 }
void process(output_queue &frame)
void Gen::TruthTraceID::process ( output_queue frame)
private

Definition at line 110 of file TruthTraceID.cxx.

110  {
111  ITrace::vector traces;
112  double tick = -1;
113 
114  // ### construct wire filters ###
117  auto indTruth = hf_ind.generate(indBins);
118 
121  auto colTruth = hf_col.generate(colBins);
122 
123  const int nbins = m_readout_time / m_tick;
124 
125  for(auto face : m_anode->faces()){
126  for(auto plane : face->planes()){
127  const Pimpos* pimpos = plane->pimpos();
128 
130  if(tick < 0){
131  tick = tbins.binsize();
132  }
133 
134  // ### construct time filter ###
135  Binning timeBins(tbins.nbins(),0.0,m_max_time_freq);
137  auto timeTruth = hf_time.generate(timeBins);
138 
139 
140  // ### apply diffusion at wire plane ###
141  Gen::BinnedDiffusion bindiff(*pimpos, tbins, m_nsigma, m_rng);
142  for(auto depo : m_depos){
143  bindiff.add(depo, depo->extent_long() / m_drift_speed, depo->extent_tran());
144 
145  auto& wires = plane->wires();
146  const int numwires = pimpos->region_binning().nbins();
147  for(int iwire=0; iwire<numwires; iwire++){
148  const auto rbins = pimpos->region_binning();
149  const auto ibins = pimpos->impact_binning();
150  const double wire_pos = rbins.center(iwire);
151  // fixme (?) this under-calculates the min/max impact position by 1/2 wire region (bv).
152  const int min_impact = ibins.edge_index(wire_pos - 0.5*m_pitch_range);
153  const int max_impact = ibins.edge_index(wire_pos + 0.5*m_pitch_range);
154  const int nsamples = tbins.nbins();
155  Waveform::compseq_t total_spectrum(nsamples, Waveform::complex_t(0.0,0.0));
156 
157  for(int imp = min_impact; imp<=max_impact; imp++){
158  auto id = bindiff.impact_data(imp);
159  if(!id){
160  continue;
161  }
162 
163  //debugging
164  std::cout<<"Truth: charge spectrum extracted." << imp << std::endl;
165 
166  if(m_truth_type == "Bare"){
167  const Waveform::compseq_t& charge_spectrum = id->spectrum();
168  if(charge_spectrum.empty()){
169  continue;
170  }
171  Waveform::increase(total_spectrum, charge_spectrum);
172  }
173  else{ // ### convolve with charge w/ hf filters ###
174  const Waveform::compseq_t& charge_spectrum = id->spectrum();
175  if(charge_spectrum.empty()){
176  continue;
177  }
178  Waveform::compseq_t conv_spectrum(nsamples, Waveform::complex_t(0.0,0.0));
179  std::complex<float> charge_gain = m_truth_gain;
180  for(int ind=0; ind<nsamples; ind++){
181  if(wires[iwire]->channel()<4800){
182  conv_spectrum[ind] = charge_gain*charge_spectrum[ind]*timeTruth[ind]*indTruth[iwire];
183  }
184  else{
185  conv_spectrum[ind] = charge_gain*charge_spectrum[ind]*timeTruth[ind]*colTruth[iwire];
186  }
187  }
188  Waveform::increase(total_spectrum, conv_spectrum);
189  }
190  }
191  bindiff.erase(0,min_impact);
192 
193  Waveform::realseq_t wave(nsamples,0.0);
194  wave = Waveform::idft(total_spectrum);
195  auto mm = Waveform::edge(wave);
196  if(mm.first == (int)wave.size()){
197  continue;
198  }
199 
200  // ### push to trace ###
201  int chid = wires[iwire]->channel();
202  ITrace::ChargeSequence charge(wave.begin()+mm.first,
203  wave.begin()+mm.second);
204  auto trace = make_shared<SimpleTrace>(chid, mm.first, charge);
205  traces.push_back(trace);
206  }
207  }
208  }
209  }
210 
211  // ### push to frame ###
212  auto frame = make_shared<SimpleFrame>(m_frame_count, m_start_time, traces, tick);
213  frames.push_back(frame);
214 
215  m_depos.clear();
216  m_start_time += m_readout_time;
217  ++m_frame_count;
218 }
Sequence< real_t > realseq_t
Definition: Waveform.h:31
double center(int ind) const
Definition: Binning.h:86
const Binning & region_binning() const
Definition: Pimpos.h:109
std::vector< pointer > vector
Definition: IData.h:21
std::pair< int, int > edge(const realseq_t &wave)
Definition: Waveform.cxx:121
const double tick
double binsize() const
Definition: Binning.h:73
Binning tbins(nticks, t0, t0+readout_time)
const Binning & impact_binning() const
Definition: Pimpos.h:113
void increase(Sequence< Val > &seq, Val scalar)
Increase (shift) sequence values by scalar.
Definition: Waveform.h:129
static const double mm
Definition: Units.h:73
realseq_t idft(compseq_t spec)
Definition: Waveform.cxx:149
Pimpos pimpos(nwires, min_wire_pitch, max_wire_pitch)
Pitch-Impact-Position.
Definition: Pimpos.h:36
std::complex< float > complex_t
The type for the spectrum in each bin.
Definition: Waveform.h:21
int nbins() const
Definition: Binning.h:42
IAnodePlane::pointer m_anode
Definition: TruthTraceID.h:29
Sequence< complex_t > compseq_t
A complex-valued sequence, eg for discrete spectrum powers.
Definition: Waveform.h:34
std::vector< float > ChargeSequence
Sequential collection of charge.
Definition: ITrace.h:21
IRandom::pointer m_rng
Definition: TruthTraceID.h:30
QTextStream & endl(QTextStream &s)
void Gen::TruthTraceID::reset ( void  )
virtual

Optional hook to be implemented in order to reset after an end of stream is encountered. Fixme: this should be removed.

Reimplemented from WireCell::INode.

Definition at line 220 of file TruthTraceID.cxx.

220  {
221  m_depos.clear();
222  m_eos = false;
223 }

Member Data Documentation

IAnodePlane::pointer WireCell::Gen::TruthTraceID::m_anode
private

Definition at line 29 of file TruthTraceID.h.

std::string WireCell::Gen::TruthTraceID::m_anode_tn
private

Definition at line 26 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_col_sigma
private

Definition at line 49 of file TruthTraceID.h.

IDepo::vector WireCell::Gen::TruthTraceID::m_depos
private

Definition at line 31 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_drift_speed
private

Definition at line 36 of file TruthTraceID.h.

bool WireCell::Gen::TruthTraceID::m_eos
private

Definition at line 43 of file TruthTraceID.h.

bool WireCell::Gen::TruthTraceID::m_fluctuate
private

Definition at line 39 of file TruthTraceID.h.

int WireCell::Gen::TruthTraceID::m_frame_count
private

Definition at line 42 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_ind_sigma
private

Definition at line 48 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_max_time_freq
private

Definition at line 54 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_max_wire_freq
private

Definition at line 53 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_nsigma
private

Definition at line 37 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_num_col_wire
private

Definition at line 47 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_num_ind_wire
private

Definition at line 46 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_pitch_range
private

Definition at line 35 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_readout_time
private

Definition at line 34 of file TruthTraceID.h.

IRandom::pointer WireCell::Gen::TruthTraceID::m_rng
private

Definition at line 30 of file TruthTraceID.h.

std::string WireCell::Gen::TruthTraceID::m_rng_tn
private

Definition at line 27 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_start_time
private

Definition at line 33 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_tick
private

Definition at line 35 of file TruthTraceID.h.

bool WireCell::Gen::TruthTraceID::m_time_flag
private

Definition at line 56 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_time_power
private

Definition at line 52 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_time_sigma
private

Definition at line 50 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_truth_gain
private

Definition at line 38 of file TruthTraceID.h.

std::string WireCell::Gen::TruthTraceID::m_truth_type
private

Definition at line 45 of file TruthTraceID.h.

bool WireCell::Gen::TruthTraceID::m_wire_flag
private

Definition at line 55 of file TruthTraceID.h.

double WireCell::Gen::TruthTraceID::m_wire_power
private

Definition at line 51 of file TruthTraceID.h.


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