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

#include <CelltreeSource.h>

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

Public Member Functions

 CelltreeSource ()
 
virtual ~CelltreeSource ()
 
virtual bool operator() (IFrame::pointer &out)
 The calling signature: More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. 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 10 of file CelltreeSource.h.

Constructor & Destructor Documentation

Root::CelltreeSource::CelltreeSource ( )

Definition at line 18 of file CelltreeSource.cxx.

19  : m_calls(0)
20 {
21 }
Root::CelltreeSource::~CelltreeSource ( )
virtual

Definition at line 23 of file CelltreeSource.cxx.

24 {
25 }

Member Function Documentation

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

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 27 of file CelltreeSource.cxx.

28 {
29  if (cfg["filename"].empty()) {
30  THROW(ValueError() << errmsg{"CelltreeSource: must supply input \"filename\" configuration item."});
31  }
32  m_cfg = cfg;
33 }
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::CelltreeSource::default_configuration ( ) const
virtual

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

Reimplemented from WireCell::IConfigurable.

Definition at line 35 of file CelltreeSource.cxx.

36 {
38  // Give a URL for the input file.
39  cfg["filename"] = "";
40 
41  // which event in the celltree file to be processed
42  cfg["EventNo"] = "0";
43 
44  // Give a list of frame/tree tags.
45 
46  // just raw waveform and no other choice at present
47  // Tree: Sim, Wf: raw_wf
48  cfg["frames"][0] = "orig";
49 
50 
51  return cfg;
52 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Root::CelltreeSource::operator() ( IFrame::pointer out)
virtual

The calling signature:

Implements WireCell::ISourceNode< IFrame >.

Definition at line 54 of file CelltreeSource.cxx.

55 {
56  out = nullptr;
57  ++m_calls;
58  std::cerr << "CelltreeSource: called " << m_calls << " times\n";
59  if (m_calls > 2) {
60  std::cerr << "CelltreeSource: past EOS\n";
61  return false;
62  }
63  if (m_calls > 1) {
64  std::cerr << "CelltreeSource: EOS\n";
65  return true; // this is to send out EOS
66  }
67 
68 
69  std::string url = m_cfg["filename"].asString();
70 
71  TFile* tfile = TFile::Open(url.c_str());
72 
73 
74 
75  TTree *tree = (TTree*)tfile->Get("/Event/Sim");
76  if (!tree) {
77  THROW(IOError() << errmsg{"No tree: /Event/Sim in input file"});
78  }
79 
80  tree->SetBranchStatus("*",0);
81 
82  int run_no, subrun_no, event_no;
83  tree->SetBranchStatus("eventNo",1);
84  tree->SetBranchAddress("eventNo" , &event_no);
85  tree->SetBranchStatus("runNo",1);
86  tree->SetBranchAddress("runNo" , &run_no);
87  tree->SetBranchStatus("subRunNo",1);
88  tree->SetBranchAddress("subRunNo", &subrun_no);
89 
90 
91  std::vector<int> *channelid = new std::vector<int>;
92  TClonesArray* esignal = new TClonesArray;
93 
94  tree->SetBranchStatus("raw_channelId",1);
95  tree->SetBranchAddress("raw_channelId", &channelid);
96  tree->SetBranchStatus("raw_wf",1);
97  tree->SetBranchAddress("raw_wf", &esignal);
98 
99  int frame_number = std::stoi(m_cfg["EventNo"].asString());
100 
101  // loop entry
102  int siz = 0;
103  unsigned int entries = tree->GetEntries();
104  for(unsigned int ent = 0; ent<entries; ent++)
105  {
106  siz = tree->GetEntry(ent);
107  if(event_no == frame_number)
108  {
109  break;
110  }
111  }
112 
113 
114  // need run number and subrunnumber
115  int frame_ident = event_no;
116  double frame_time=0;
117 
118  // some output using eventNo, runNo, subRunNO, ...
119  std::cerr<<"CelltreeSource: frame "<<frame_number<<"\n";
120  std::cerr << "CelltreeSource: runNo "<<run_no<<", subrunNo "<<subrun_no<<", eventNo "<<event_no<<"\n";
121 
122  ITrace::vector all_traces;
123  std::unordered_map<IFrame::tag_t, IFrame::trace_list_t> tagged_traces;
124  // celltree input now is raw data, no information about any noisy or bad channels
125  // leave cmm empty.
127 
128 
129  if (siz>0 && frame_number == frame_ident){
130  int nchannels = channelid->size();
131 
132  auto frametag = m_cfg["frames"][0].asString();
133  int channel_number = 0;
134 
135  std::cerr<<"CelltreeSource: loading "<<frametag<<" "<<nchannels<<" channels \n";
136 
137  // fill waveform ...
138  TH1S *signal_s;
139  TH1F *signal_f;
140 
141  for (int ind=0; ind < nchannels; ++ind) {
142  signal_s = dynamic_cast<TH1S*>(esignal->At(ind));
143  signal_f = dynamic_cast<TH1F*>(esignal->At(ind));
144 
145  bool flag_float = 1;
146  if (signal_f==0 && signal_s!=0)
147  flag_float = 0;
148 
149  if (!signal_f && !signal_s) continue;
150  channel_number = channelid->at(ind);
151 
152  ITrace::ChargeSequence charges;
153  int nticks;
154  if (flag_float==1)
155  nticks = signal_f->GetNbinsX();
156  else
157  nticks = signal_s->GetNbinsX();
158  //std::cerr<<"CelltreeSource: tick "<<nticks<<"\n";
159  //nticks = 9600, this could be an issue cause just 9594 have non-ZERO value around baseline
160  for (int itickbin = 0; itickbin != nticks; itickbin++){
161  if (flag_float==1){
162  if(signal_f->GetBinContent(itickbin+1)!=0) {
163  charges.push_back(signal_f->GetBinContent(itickbin+1));
164  }
165  }else{
166  if(signal_s->GetBinContent(itickbin+1)!=0) {
167  charges.push_back(signal_s->GetBinContent(itickbin+1));
168  }
169  }
170  }
171 
172  const size_t index = all_traces.size();
173  tagged_traces[frametag].push_back(index);
174 
175  all_traces.push_back(std::make_shared<SimpleTrace>(channel_number, 0, charges));
176  }
177  auto sframe = new SimpleFrame(frame_ident, frame_time,
178  all_traces, 0.5*units::microsecond, cmm);
179  for (auto const& it : tagged_traces) {
180  sframe->tag_traces(it.first, it.second);
181  std::cerr << "CelltreeSource: tag " << it.second.size() << " traces as: \"" << it.first << "\"\n";
182  }
183 
184  out = IFrame::pointer(sframe);
185 
186  return true;
187  }else{
188  std::cerr << "CelltreeSource: Event Number is out of boundary! " << std::endl;
189  return false;
190  }
191 
192 
193 
194 
195 
196 
197  // // runNo, subRunNo??
198  // trun->SetBranchAddress("eventNo", &frame_ident);
199  // trun->SetBranchAddress("total_time_bin", &nticks);
200  // //trun->SetBranchAddress("time_offset", &frame_time); use this??
201  // trun->GetEntry(0);
202 
203  // std::cerr << "CelltreeSource: frame ident="<<frame_ident<<", time=0, nticks="<<nticks<<"\n";
204 
205 
206 }
std::shared_ptr< const IFrame > pointer
Definition: IData.h:19
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::CelltreeSource::m_calls
private

Definition at line 22 of file CelltreeSource.h.

Configuration WireCell::Root::CelltreeSource::m_cfg
private

Definition at line 21 of file CelltreeSource.h.


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