Public Member Functions | Private Attributes | List of all members
WireCell::Root::HistFrameSink Class Reference

#include <HistFrameSink.h>

Inheritance diagram for WireCell::Root::HistFrameSink:
WireCell::IFrameSink WireCell::IConfigurable WireCell::ISinkNode< IFrame > WireCell::IComponent< IConfigurable > WireCell::ISinkNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 HistFrameSink ()
 
virtual ~HistFrameSink ()
 
virtual bool operator() (const IFrame::pointer &frame)
 Frame sink interface. More...
 
virtual void configure (const WireCell::Configuration &config)
 Configurable interface. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
- Public Member Functions inherited from WireCell::IFrameSink
virtual ~IFrameSink ()
 
virtual std::string signature ()
 
- Public Member Functions inherited from WireCell::ISinkNode< IFrame >
virtual ~ISinkNode ()
 
virtual bool operator() (const boost::any &anyin)
 
virtual std::vector< std::stringinput_types ()
 
- Public Member Functions inherited from WireCell::ISinkNodeBase
virtual ~ISinkNodeBase ()
 
virtual NodeCategory category ()
 Return the behavior category type. More...
 
- Public Member Functions inherited from WireCell::INode
virtual ~INode ()
 
virtual int concurrency ()
 
virtual std::vector< std::stringoutput_types ()
 
virtual void reset ()
 
- 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 Attributes

std::string m_filepat
 
std::string m_anode_tn
 
IAnodePlane::pointer m_anode
 
double m_units
 

Additional Inherited Members

- Public Types inherited from WireCell::IFrameSink
typedef std::shared_ptr< IFrameSinkpointer
 
- Public Types inherited from WireCell::ISinkNode< IFrame >
typedef IFrame input_type
 
typedef std::shared_ptr< const IFrameinput_pointer
 
- Public Types inherited from WireCell::ISinkNodeBase
typedef std::shared_ptr< ISinkNodeBasepointer
 
- 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 19 of file HistFrameSink.h.

Constructor & Destructor Documentation

Root::HistFrameSink::HistFrameSink ( )

Definition at line 20 of file HistFrameSink.cxx.

21  : m_filepat("histframe-%02d.root")
22  , m_anode_tn("AnodePlane")
23  , m_units(1.0)
24 {
25 }
Root::HistFrameSink::~HistFrameSink ( )
virtual

Definition at line 27 of file HistFrameSink.cxx.

28 {
29 }

Member Function Documentation

void Root::HistFrameSink::configure ( const WireCell::Configuration config)
virtual

Configurable interface.

Implements WireCell::IConfigurable.

Definition at line 41 of file HistFrameSink.cxx.

42 {
43  m_filepat = get<std::string>(cfg, "filename", m_filepat);
44  m_units = get<double>(cfg, "units", m_units);
45  m_anode_tn = get<std::string>(cfg, "anode", m_anode_tn);
46  m_anode = Factory::lookup_tn<IAnodePlane>(m_anode_tn);
47  if (!m_anode) {
48  cerr << "Root::HistFrameSink: failed to get anode: \"" << m_anode_tn << "\"\n";
49  return;
50  }
51  cerr << "Root::HistFrameSink: configured with: "
52  << "file:" << m_filepat << ", "
53  << "units:" << m_units << ", "
54  << "anode:" << m_anode_tn << endl;
55 }
IAnodePlane::pointer m_anode
Definition: HistFrameSink.h:35
cfg
Definition: dbjson.py:29
QTextStream & endl(QTextStream &s)
WireCell::Configuration Root::HistFrameSink::default_configuration ( ) const
virtual

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

Reimplemented from WireCell::IConfigurable.

Definition at line 32 of file HistFrameSink.cxx.

33 {
35  cfg["filename"] = m_filepat;
36  cfg["anode"] = m_anode_tn;
37  cfg["units"] = units::mV;
38  return cfg;
39 }
static const double mV
Definition: Units.h:180
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Root::HistFrameSink::operator() ( const IFrame::pointer frame)
virtual

Frame sink interface.

Implements WireCell::ISinkNode< IFrame >.

Definition at line 59 of file HistFrameSink.cxx.

60 {
61  if (!frame) {
62  cerr << "Root::HistFrameSink: no frame\n";
63  return true;
64  }
65 
66  std::string fname = Form(m_filepat.c_str(), frame->ident());
67  TFile* file = TFile::Open(fname.c_str(), "recreate");
68 
69 
70  typedef std::tuple< ITrace::vector, std::vector<int>, std::vector<int> > tct_tuple;
71  std::unordered_map<int, tct_tuple> perplane;
72 
73  // collate traces into per plane and also calculate bounds
74  ITrace::shared_vector traces = frame->traces();
75  for (ITrace::pointer trace : *traces) {
76  int ch = trace->channel();
77  auto wpid = m_anode->resolve(ch);
78  int wpident = wpid.ident();
79  double tmin = trace->tbin();
80  double tlen = trace->charge().size();
81 
82  auto& tct = perplane[wpident];
83  get<0>(tct).push_back(trace);
84  get<1>(tct).push_back(ch);
85  get<2>(tct).push_back(tmin);
86  get<2>(tct).push_back(tmin+tlen);
87 
88  if (wpident < 0) {
89  cerr << "Channel "<<ch<<" has illegal wire plane ident: " << wpid << endl;
90  }
91  }
92 
93  const double t0 = frame->time();
94  const double tick = frame->tick();
95 
96  for (auto& thisplane : perplane) {
97  int wpident = thisplane.first;
98  auto& tct = thisplane.second;
99  auto& traces = get<0>(tct);
100  auto& chans = get<1>(tct);
101  auto chmm = std::minmax_element(chans.begin(), chans.end());
102  auto& tbins = get<2>(tct);
103  auto tbmm = std::minmax_element(tbins.begin(), tbins.end());
104 
105 
106  const double tmin = t0 + tick*(*tbmm.first);
107  const double tmax = t0 + tick*(*tbmm.second);
108  const int ntbins = (*tbmm.second)-(*tbmm.first);
109 
110  const int chmin = round(*chmm.first);
111  const int chmax = round(*chmm.second + 1);
112  const int nchbins = chmax - chmin;
113 
114  TH2F* hist = new TH2F(Form("plane%d", wpident),
115  Form("Plane %d", wpident),
116  ntbins, tmin/units::us, tmax/units::us,
117  nchbins, chmin, chmax);
118  hist->SetDirectory(file); // needed?
119  hist->SetXTitle("time [us]");
120  hist->SetYTitle("channel");
121 
122  double qtot = 0;
123  int nbins_tot = 0;
124  for (auto& trace : traces) {
125  double fch = trace->channel() + 0.5; // make sure we land in bin-center.
126  int tbin = trace->tbin();
127  auto& charge = trace->charge();
128  int nbins = charge.size();
129  nbins_tot += nbins;
130  for (int ibin=0; ibin<nbins; ++ibin) {
131  const double t = t0 + (tick)*(tbin+ibin+0.5); // 0.5 to land in bin-center
132  hist->Fill(t/units::us, fch, charge[ibin]/m_units);
133  qtot += charge[ibin];
134  }
135  }
136 
137  cerr << wpident
138  << " ntraces:" << traces.size() << " "
139  << " nsamples:" << nbins_tot << " "
140  << " qtot:" << qtot/m_units << " "
141  << " qunit:" << m_units << " "
142  << " integ:" << hist->Integral()
143  << " min:" << hist->GetMinimum()
144  << " max:" << hist->GetMaximum()
145  << " chan:"<<nchbins<<"[" << chmin << "," << chmax << "] "
146  << " time:"<<ntbins<<"[" << tmin/units::us << "," << tmax/units::us <<"]us\n";
147 
148 
149  hist->Write();
150  }
151  file->Close();
152  delete file;
153  file = nullptr;
154  return true;
155 }
code to link reconstructed objects back to the MC truth information
hfilts push_back(hfilt)
std::shared_ptr< const ITrace > pointer
Definition: IData.h:19
Definition: posix.h:188
std::string string
Definition: nybbler.cc:12
IAnodePlane::pointer m_anode
Definition: HistFrameSink.h:35
const double tick
Binning tbins(nticks, t0, t0+readout_time)
static const double us
Definition: Units.h:105
std::shared_ptr< const vector > shared_vector
Definition: IData.h:22
QTextStream & endl(QTextStream &s)

Member Data Documentation

IAnodePlane::pointer WireCell::Root::HistFrameSink::m_anode
private

Definition at line 35 of file HistFrameSink.h.

std::string WireCell::Root::HistFrameSink::m_anode_tn
private

Definition at line 34 of file HistFrameSink.h.

std::string WireCell::Root::HistFrameSink::m_filepat
private

Definition at line 34 of file HistFrameSink.h.

double WireCell::Root::HistFrameSink::m_units
private

Definition at line 36 of file HistFrameSink.h.


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