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

#include <MagnifySource.h>

Inheritance diagram for WireCell::Root::MagnifySource:
WireCell::IFrameSource WireCell::IConfigurable WireCell::ISourceNode< IFrame > WireCell::IComponent< IConfigurable > WireCell::ISourceNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 MagnifySource ()
 
virtual ~MagnifySource ()
 
virtual bool operator() (IFrame::pointer &out)
 IFrameSource. More...
 
virtual WireCell::Configuration default_configuration () const
 IConfigurable. More...
 
virtual void configure (const WireCell::Configuration &config)
 Accept a configuration. More...
 
- Public Member Functions inherited from WireCell::IFrameSource
virtual ~IFrameSource ()
 
- Public Member Functions inherited from WireCell::ISourceNode< IFrame >
virtual ~ISourceNode ()
 
virtual NodeCategory category ()
 Return the behavior category type. More...
 
virtual std::string signature ()
 Set the signature for all subclasses. More...
 
virtual bool operator() (boost::any &anyout)
 
virtual std::vector< std::stringoutput_types ()
 
- Public Member Functions inherited from WireCell::ISourceNodeBase
virtual ~ISourceNodeBase ()
 
- Public Member Functions inherited from WireCell::INode
virtual ~INode ()
 
virtual int concurrency ()
 
virtual std::vector< std::stringinput_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

Configuration m_cfg
 
int m_calls
 

Additional Inherited Members

- Public Types inherited from WireCell::IFrameSource
typedef std::shared_ptr< IFrameSourcepointer
 
- Public Types inherited from WireCell::ISourceNode< IFrame >
typedef IFrame output_type
 
typedef ISourceNode< IFramesignature_type
 
typedef std::shared_ptr< signature_typepointer
 
typedef std::shared_ptr< const IFrameoutput_pointer
 
- Public Types inherited from WireCell::ISourceNodeBase
typedef std::shared_ptr< ISourceNodeBasepointer
 
- 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 17 of file MagnifySource.h.

Constructor & Destructor Documentation

Root::MagnifySource::MagnifySource ( )

Definition at line 17 of file MagnifySource.cxx.

18  : m_calls(0)
19 {
20 }
Root::MagnifySource::~MagnifySource ( )
virtual

Definition at line 22 of file MagnifySource.cxx.

23 {
24 }

Member Function Documentation

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

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 26 of file MagnifySource.cxx.

27 {
28  if (cfg["filename"].empty()) {
29  THROW(ValueError() << errmsg{"MagnifySource: must supply input \"filename\" configuration item."});
30  }
31  m_cfg = cfg;
32 }
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
cfg
Definition: dbjson.py:29
#define THROW(e)
Definition: Exceptions.h:25
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:92
WireCell::Configuration Root::MagnifySource::default_configuration ( ) const
virtual

IConfigurable.

Reimplemented from WireCell::IConfigurable.

Definition at line 34 of file MagnifySource.cxx.

35 {
37  // Give a URL for the input file.
38  cfg["filename"] = "";
39 
40  // Give a list of frame tags. These are translated to histogram
41  // names h[uvw]_<tag> to be used for input. Missing histograms
42  // raise an exception. Each frame found will be loaded as tagged
43  // traces into the output frame. The ensemble of traces will be
44  // tagged by both <tag> and the per-plane subset as
45  // <planeletter>plane.
46  cfg["frames"][0] = "raw";
47 
48  // A list of pairs mapping a cmm key name to a ttree name.
49  cfg["cmmtree"] = Json::arrayValue;
50 
51  return cfg;
52 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Root::MagnifySource::operator() ( IFrame::pointer out)
virtual

IFrameSource.

Implements WireCell::ISourceNode< IFrame >.

Definition at line 55 of file MagnifySource.cxx.

56 {
57  out = nullptr;
58  ++m_calls;
59  std::cerr << "MagnifySource: called " << m_calls << " times\n";
60  if (m_calls > 2) {
61  std::cerr << "MagnifySource: past EOS\n";
62  return false;
63  }
64  if (m_calls > 1) {
65  std::cerr << "MagnifySource: EOS\n";
66  return true; // this is to send out EOS
67  }
68 
69 
70  std::string url = m_cfg["filename"].asString();
71 
72  TFile* tfile = TFile::Open(url.c_str());
73 
74  int frame_ident=0;
75  int nticks=0;
76  double frame_time=0;
77  {
78  TTree *trun = (TTree*)tfile->Get("Trun");
79  if (!trun) {
80  std::cerr << "No tree: Trun in input file \n";
81  }
82  else{
83  // runNo, subRunNo??
84  trun->SetBranchAddress("eventNo", &frame_ident);
85  trun->SetBranchAddress("total_time_bin", &nticks);
86  //trun->SetBranchAddress("time_offset", &frame_time); use this??
87  trun->GetEntry(0);
88  }
89  }
90  std::cerr << "MagnifySource: frame ident="<<frame_ident<<", time=0, nticks="<<nticks<<"\n";
91 
92 
94  for (auto jcmmtree : m_cfg["cmmtree"]) {
95  auto cmmkey = jcmmtree[0].asString();
96  auto treename = jcmmtree[1].asString();
97  TTree *tree = dynamic_cast<TTree*>(tfile->Get(treename.c_str()));
98  if (!tree) {
99  std::cerr << "MagnifySource: failed to find tree \"" << treename << "\" in " << tfile->GetName() << std::endl;
100  THROW(IOError() << errmsg{"MagnifySource: failed to find tree."});
101  }
102 
103  std::cerr << "MagnifySource: loading channel mask \"" << cmmkey << "\" from tree \"" << treename << "\"\n";
104 
105  int chid=0, plane=0, start_time=0, end_time=0;
106  tree->SetBranchAddress("chid",&chid);
107  tree->SetBranchAddress("plane",&plane);
108  tree->SetBranchAddress("start_time",&start_time);
109  tree->SetBranchAddress("end_time",&end_time);
110 
111  const int nentries = tree->GetEntries();
112  for (int ientry = 0; ientry < nentries; ++ientry){
113  tree->GetEntry(ientry);
115  br.first = start_time;
116  br.second = end_time;
117  cmm[cmmkey][chid].push_back(br);
118  }
119  }
120 
121 
122  ITrace::vector all_traces;
123  std::unordered_map<IFrame::tag_t, IFrame::trace_list_t> tagged_traces;
124 
125  {
126  for (auto jtag : m_cfg["frames"]) {
127  auto frametag = jtag.asString();
128  int channel_number = 0;
129  for (int iplane=0; iplane<3; ++iplane) {
130  std::string plane_name = Form("%cplane", 'u'+iplane);
131  std::string hist_name = Form("h%c_%s", 'u'+iplane, frametag.c_str());
132  std::cerr << "MagnifySource: loading " << hist_name << std::endl;
133  TH2* hist = (TH2*)tfile->Get(hist_name.c_str());
134 
135  ITrace::vector plane_traces;
136 
137  int nchannels = hist->GetNbinsX();
138  int nticks = hist->GetNbinsY();
139  double qtot = 0;
140 
141  // loop over channels in plane
142  for (int chip = 0; chip<nchannels; ++chip) {
143  const int ichbin = chip+1;
144 
145  ITrace::ChargeSequence charges;
146  for (int itickbin = 1; itickbin <= nticks; ++itickbin) {
147  auto q = hist->GetBinContent(ichbin, itickbin);
148  charges.push_back(q);
149  qtot += q;
150  }
151  const size_t index = all_traces.size();
152  tagged_traces[frametag].push_back(index);
153  all_traces.push_back(std::make_shared<SimpleTrace>(channel_number, 0, charges));
154 
155  ++channel_number;
156  }
157  std::cerr << "MagnifySource: plane " << iplane
158  << ": " << nchannels << " X " << nticks
159  << " qtot=" << qtot
160  << std::endl;
161  } // plane
162 
163  }
164  }
165 
166  auto sframe = new SimpleFrame(frame_ident, frame_time,
167  all_traces, 0.5*units::microsecond, cmm);
168  for (auto const& it : tagged_traces) {
169  sframe->tag_traces(it.first, it.second);
170  std::cerr << "MagnifySource: tag " << it.second.size() << " traces as: \"" << it.first << "\"\n";
171  }
172 
173  out = IFrame::pointer(sframe);
174  return true;
175 }
std::shared_ptr< const IFrame > pointer
Definition: IData.h:19
std::pair< int, int > BinRange
A half-open range of bins (from first bin to one past last bin)
Definition: Waveform.h:38
std::string string
Definition: nybbler.cc:12
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
static const double microsecond
Definition: Units.h:94
std::vector< pointer > vector
Definition: IData.h:21
const int nticks
static ITrace::vector tagged_traces(IFrame::pointer frame, IFrame::tag_t tag)
std::map< std::string, ChannelMasks > ChannelMaskMap
Collect channel masks by some label.
Definition: Waveform.h:59
#define THROW(e)
Definition: Exceptions.h:25
std::vector< float > ChargeSequence
Sequential collection of charge.
Definition: ITrace.h:21
QTextStream & endl(QTextStream &s)

Member Data Documentation

int WireCell::Root::MagnifySource::m_calls
private

Definition at line 31 of file MagnifySource.h.

Configuration WireCell::Root::MagnifySource::m_cfg
private

Definition at line 30 of file MagnifySource.h.


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