MCBTAlg.cxx
Go to the documentation of this file.
1 #include "MCBTAlg.h"
2 
12 
13 #include <string>
14 
15 namespace btutil {
16 
17  MCBTAlg::MCBTAlg(const std::vector<unsigned int>& g4_trackid_v,
18  const std::vector<sim::SimChannel>& simch_v)
19  {
20  Reset(g4_trackid_v, simch_v);
21  }
22 
23  void
24  MCBTAlg::Reset(const std::vector<unsigned int>& g4_trackid_v,
25  const std::vector<sim::SimChannel>& simch_v)
26  {
27  _num_parts = 0;
28  _sum_mcq.clear();
29  _trkid_to_index.clear();
30  _event_info.clear();
31  //
32  for (auto const& id : g4_trackid_v)
33  Register(id);
34  _num_parts++;
35  ProcessSimChannel(simch_v);
36  }
37 
38  void
39  MCBTAlg::Reset(const std::vector<std::vector<unsigned int>>& g4_trackid_v,
40  const std::vector<sim::SimChannel>& simch_v)
41  {
42  _num_parts = 0;
43  _sum_mcq.clear();
44  _trkid_to_index.clear();
45  _event_info.clear();
46  //
47  for (auto const& id : g4_trackid_v)
48  Register(id);
49  _num_parts++;
50  ProcessSimChannel(simch_v);
51  }
52 
53  void
54  MCBTAlg::ProcessSimChannel(const std::vector<sim::SimChannel>& simch_v)
55  {
56 
58  //auto geo = ::larutil::Geometry::GetME();
59  _sum_mcq.resize(geo->Nplanes(), std::vector<double>(_num_parts, 0));
60 
61  for (auto const& sch : simch_v) {
62 
63  auto const ch = sch.Channel();
64  if (_event_info.size() <= ch) _event_info.resize(ch + 1);
65 
66  auto& ch_info = _event_info[ch];
67 
68  size_t plane = geo->ChannelToWire(ch)[0].Plane;
69  //size_t plane = geo->ChannelToPlane(ch);
70 
71  for (auto const& time_ide : sch.TDCIDEMap()) {
72 
73  auto const& time = time_ide.first;
74  auto const& ide_v = time_ide.second;
75 
76  auto& edep_info = ch_info[time];
77 
78  if (!edep_info.size()) edep_info.resize(_num_parts, 0);
79 
80  for (auto const& ide : ide_v) {
81 
82  size_t index = kINVALID_INDEX;
83  if (ide.trackID < (int)(_trkid_to_index.size())) { index = _trkid_to_index[ide.trackID]; }
84  if (_num_parts <= index) {
85  (*edep_info.rbegin()) += ide.numElectrons;
86  (*(_sum_mcq[plane]).rbegin()) += ide.numElectrons;
87  }
88  else {
89  edep_info[index] += ide.numElectrons;
90  _sum_mcq[plane][index] += ide.numElectrons;
91  }
92  }
93  }
94  }
95  }
96 
97  const std::vector<double>&
98  MCBTAlg::MCQSum(const size_t plane_id) const
99  {
100  if (plane_id > _sum_mcq.size())
101  throw MCBTException(Form("Invalid plane requested: %zu", plane_id));
102  return _sum_mcq[plane_id];
103  }
104 
105  std::vector<double>
106  MCBTAlg::MCQ(detinfo::DetectorClocksData const& clockData, const WireRange_t& hit) const
107  {
108  std::vector<double> res(_num_parts, 0);
109 
110  if (_event_info.size() <= hit.ch) return res;
111 
112  auto const& ch_info = _event_info[hit.ch];
113 
114  auto itlow = ch_info.lower_bound((unsigned int)(clockData.TPCTick2TDC(hit.start)));
115  auto itup = ch_info.upper_bound((unsigned int)(clockData.TPCTick2TDC(hit.end)) + 1);
116 
117  while (itlow != ch_info.end() && itlow != itup) {
118 
119  auto const& edep_info = (*itlow).second;
120 
121  for (size_t part_index = 0; part_index < _num_parts; ++part_index)
122 
123  res[part_index] += edep_info[part_index];
124 
125  ++itlow;
126  }
127  return res;
128  }
129 
130  std::vector<double>
132  {
133  auto res = MCQ(clockData, hit);
134  if (!res.size()) return res;
135 
136  double sum = 0;
137  for (auto const& v : res)
138  sum += v;
139  for (size_t i = 0; i < (res.size() - 1); ++i)
140  res[i] /= (sum - (*res.rbegin()));
141  (*res.rbegin()) /= sum;
142  return res;
143  }
144 
145  std::vector<double>
147  const std::vector<WireRange_t>& hit_v) const
148  {
149  std::vector<double> res(_num_parts, 0);
150  for (auto const& h : hit_v) {
151  auto tmp_res = MCQ(clockData, h);
152  for (size_t i = 0; i < res.size(); ++i)
153  res[i] += tmp_res[i];
154  }
155  return res;
156  }
157 
158  std::vector<double>
160  const std::vector<WireRange_t>& hit_v) const
161  {
162  auto res = MCQ(clockData, hit_v);
163  if (!res.size()) return res;
164 
165  double sum = 0;
166  for (auto const& v : res)
167  sum += v;
168  for (size_t i = 0; i < (res.size() - 1); ++i)
169  res[i] /= (sum - (*res.rbegin()));
170  (*res.rbegin()) /= sum;
171  return res;
172  }
173 
174  size_t
175  MCBTAlg::Index(const unsigned int g4_track_id) const
176  {
177  if (g4_track_id >= _trkid_to_index.size()) return kINVALID_INDEX;
178  return _trkid_to_index[g4_track_id];
179  }
180 
181  void
182  MCBTAlg::Register(const unsigned int& g4_track_id)
183  {
184  if (_trkid_to_index.size() <= g4_track_id)
185  _trkid_to_index.resize(g4_track_id + 1, kINVALID_INDEX);
186 
187  if (_trkid_to_index[g4_track_id] == kINVALID_INDEX) {
188  _trkid_to_index[g4_track_id] = _num_parts;
189  ++_num_parts;
190  }
191  }
192 
193  void
194  MCBTAlg::Register(const std::vector<unsigned int>& track_id_v)
195  {
196  unsigned int max_id = 0;
197  for (auto const& id : track_id_v)
198  if (max_id < id) max_id = id;
199  if (_trkid_to_index.size() <= max_id) _trkid_to_index.resize(max_id + 1, kINVALID_INDEX);
200 
201  for (auto const& id : track_id_v) {
202 
203  if (_trkid_to_index[id] == kINVALID_INDEX)
204 
206 
207  else
208 
209  throw MCBTException(Form("Doubly used TrackID: %d", id));
210  }
211  ++_num_parts;
212  }
213 
214 }
unsigned int ch
Definition: MCBTAlg.h:34
const std::vector< double > & MCQSum(const size_t plane_id) const
Definition: MCBTAlg.cxx:98
std::vector< std::vector< double > > _sum_mcq
Definition: MCBTAlg.h:130
void Reset(const std::vector< unsigned int > &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v)
Definition: MCBTAlg.cxx:24
Class def header for a class MCBTAlg.
struct vector vector
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::vector<::btutil::ch_info_t > _event_info
Definition: MCBTAlg.h:128
art framework interface to geometry description
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
size_t Index(const unsigned int g4_track_id) const
Definition: MCBTAlg.cxx:175
std::vector< double > MCQ(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:106
static const size_t kINVALID_INDEX
Signifies invalid MCX index number.
void ProcessSimChannel(const std::vector< sim::SimChannel > &simch_v)
Definition: MCBTAlg.cxx:54
std::vector< size_t > _trkid_to_index
Definition: MCBTAlg.h:129
Definition of data types for geometry description.
Detector simulation of raw signals on wires.
Contains all timing reference information for the detector.
std::vector< double > MCQFrac(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:131
size_t _num_parts
Definition: MCBTAlg.h:131
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void Register(const unsigned int &g4_track_id)
Definition: MCBTAlg.cxx:182
double TPCTick2TDC(double const tick) const
Class def header for exception classes in MCComp package.
pure virtual base interface for detector clocks