9 #include "TClonesArray.h" 23 Root::CelltreeSource::~CelltreeSource()
29 if (cfg[
"filename"].
empty()) {
48 cfg[
"frames"][0] =
"orig";
58 std::cerr <<
"CelltreeSource: called " << m_calls <<
" times\n";
60 std::cerr <<
"CelltreeSource: past EOS\n";
64 std::cerr <<
"CelltreeSource: EOS\n";
71 TFile* tfile = TFile::Open(url.c_str());
75 TTree *tree = (TTree*)tfile->Get(
"/Event/Sim");
80 tree->SetBranchStatus(
"*",0);
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);
91 std::vector<int> *channelid =
new std::vector<int>;
92 TClonesArray* esignal =
new TClonesArray;
94 tree->SetBranchStatus(
"raw_channelId",1);
95 tree->SetBranchAddress(
"raw_channelId", &channelid);
96 tree->SetBranchStatus(
"raw_wf",1);
97 tree->SetBranchAddress(
"raw_wf", &esignal);
99 int frame_number = std::stoi(m_cfg[
"EventNo"].asString());
103 unsigned int entries = tree->GetEntries();
104 for(
unsigned int ent = 0; ent<entries; ent++)
106 siz = tree->GetEntry(ent);
107 if(event_no == frame_number)
115 int frame_ident = event_no;
119 std::cerr<<
"CelltreeSource: frame "<<frame_number<<
"\n";
120 std::cerr <<
"CelltreeSource: runNo "<<run_no<<
", subrunNo "<<subrun_no<<
", eventNo "<<event_no<<
"\n";
123 std::unordered_map<IFrame::tag_t, IFrame::trace_list_t>
tagged_traces;
129 if (siz>0 && frame_number == frame_ident){
130 int nchannels = channelid->size();
132 auto frametag = m_cfg[
"frames"][0].asString();
133 int channel_number = 0;
135 std::cerr<<
"CelltreeSource: loading "<<frametag<<
" "<<nchannels<<
" channels \n";
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));
146 if (signal_f==0 && signal_s!=0)
149 if (!signal_f && !signal_s)
continue;
150 channel_number = channelid->at(ind);
155 nticks = signal_f->GetNbinsX();
157 nticks = signal_s->GetNbinsX();
160 for (
int itickbin = 0; itickbin !=
nticks; itickbin++){
162 if(signal_f->GetBinContent(itickbin+1)!=0) {
163 charges.push_back(signal_f->GetBinContent(itickbin+1));
166 if(signal_s->GetBinContent(itickbin+1)!=0) {
167 charges.push_back(signal_s->GetBinContent(itickbin+1));
172 const size_t index = all_traces.size();
173 tagged_traces[frametag].push_back(index);
175 all_traces.push_back(std::make_shared<SimpleTrace>(channel_number, 0, charges));
177 auto sframe =
new SimpleFrame(frame_ident, frame_time,
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";
188 std::cerr <<
"CelltreeSource: Event Number is out of boundary! " <<
std::endl;
std::shared_ptr< const IFrame > pointer
Thrown when an error involving accessing input or output has occurred.
WIRECELL_FACTORY(CelltreeSource, WireCell::Root::CelltreeSource, WireCell::IFrameSource, WireCell::IConfigurable) using namespace WireCell
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
boost::error_info< struct tag_errmsg, std::string > errmsg
std::vector< pointer > vector
static ITrace::vector tagged_traces(IFrame::pointer frame, IFrame::tag_t tag)
Thrown when a wrong value has been encountered.
Json::Value Configuration
const GenericPointer< typename T::ValueType > & pointer
std::vector< float > ChargeSequence
Sequential collection of charge.
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
QTextStream & endl(QTextStream &s)