11 #include <unordered_map> 21 : m_filepat("histframe-%02
d.root")
22 , m_anode_tn("AnodePlane")
27 Root::HistFrameSink::~HistFrameSink()
48 cerr <<
"Root::HistFrameSink: failed to get anode: \"" << m_anode_tn <<
"\"\n";
51 cerr <<
"Root::HistFrameSink: configured with: " 53 <<
"units:" << m_units <<
", " 54 <<
"anode:" << m_anode_tn <<
endl;
62 cerr <<
"Root::HistFrameSink: no frame\n";
67 TFile*
file = TFile::Open(fname.c_str(),
"recreate");
70 typedef std::tuple< ITrace::vector, std::vector<int>, std::vector<int> > tct_tuple;
71 std::unordered_map<int, tct_tuple> perplane;
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();
82 auto& tct = perplane[wpident];
89 cerr <<
"Channel "<<ch<<
" has illegal wire plane ident: " << wpid <<
endl;
93 const double t0 = frame->time();
94 const double tick = frame->tick();
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());
106 const double tmin = t0 + tick*(*tbmm.first);
107 const double tmax = t0 + tick*(*tbmm.second);
108 const int ntbins = (*tbmm.second)-(*tbmm.first);
110 const int chmin = round(*chmm.first);
111 const int chmax = round(*chmm.second + 1);
112 const int nchbins = chmax - chmin;
114 TH2F*
hist =
new TH2F(Form(
"plane%d", wpident),
115 Form(
"Plane %d", wpident),
117 nchbins, chmin, chmax);
118 hist->SetDirectory(file);
119 hist->SetXTitle(
"time [us]");
120 hist->SetYTitle(
"channel");
124 for (
auto&
trace : traces) {
125 double fch =
trace->channel() + 0.5;
126 int tbin =
trace->tbin();
127 auto& charge =
trace->charge();
128 int nbins = charge.size();
130 for (
int ibin=0; ibin<
nbins; ++ibin) {
131 const double t = t0 + (
tick)*(tbin+ibin+0.5);
133 qtot += charge[ibin];
138 <<
" ntraces:" << traces.size() <<
" " 139 <<
" nsamples:" << nbins_tot <<
" " 140 <<
" qtot:" << qtot/
m_units <<
" " 142 <<
" integ:" << hist->Integral()
143 <<
" min:" << hist->GetMinimum()
144 <<
" max:" << hist->GetMaximum()
145 <<
" chan:"<<nchbins<<
"[" << chmin <<
"," << chmax <<
"] " code to link reconstructed objects back to the MC truth information
std::shared_ptr< const IFrame > pointer
IAnodePlane::pointer m_anode
WIRECELL_FACTORY(HistFrameSink, WireCell::Root::HistFrameSink, WireCell::IFrameSink, WireCell::IConfigurable) using namespace std
Binning tbins(nticks, t0, t0+readout_time)
virtual bool operator()(const IFrame::pointer &frame)
Frame sink interface.
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
Json::Value Configuration
virtual void configure(const WireCell::Configuration &config)
Configurable interface.
std::shared_ptr< const vector > shared_vector
QTextStream & endl(QTextStream &s)