LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 MCBTAlg::Reset(const std::vector<unsigned int>& g4_trackid_v,
24  const std::vector<sim::SimChannel>& simch_v)
25  {
26  _num_parts = 0;
27  _sum_mcq.clear();
28  _trkid_to_index.clear();
29  _event_info.clear();
30  //
31  for (auto const& id : g4_trackid_v)
32  Register(id);
33  _num_parts++;
34  ProcessSimChannel(simch_v);
35  }
36 
37  void MCBTAlg::Reset(const std::vector<std::vector<unsigned int>>& g4_trackid_v,
38  const std::vector<sim::SimChannel>& simch_v)
39  {
40  _num_parts = 0;
41  _sum_mcq.clear();
42  _trkid_to_index.clear();
43  _event_info.clear();
44  //
45  for (auto const& id : g4_trackid_v)
46  Register(id);
47  _num_parts++;
48  ProcessSimChannel(simch_v);
49  }
50 
51  void MCBTAlg::ProcessSimChannel(const std::vector<sim::SimChannel>& simch_v)
52  {
53 
55  //auto geo = ::larutil::Geometry::GetME();
56  _sum_mcq.resize(geo->Nplanes(), std::vector<double>(_num_parts, 0));
57 
58  for (auto const& sch : simch_v) {
59 
60  auto const ch = sch.Channel();
61  if (_event_info.size() <= ch) _event_info.resize(ch + 1);
62 
63  auto& ch_info = _event_info[ch];
64 
65  size_t plane = geo->ChannelToWire(ch)[0].Plane;
66  //size_t plane = geo->ChannelToPlane(ch);
67 
68  for (auto const& time_ide : sch.TDCIDEMap()) {
69 
70  auto const& time = time_ide.first;
71  auto const& ide_v = time_ide.second;
72 
73  auto& edep_info = ch_info[time];
74 
75  if (!edep_info.size()) edep_info.resize(_num_parts, 0);
76 
77  for (auto const& ide : ide_v) {
78 
79  size_t index = kINVALID_INDEX;
80  if (ide.trackID < (int)(_trkid_to_index.size())) { index = _trkid_to_index[ide.trackID]; }
81  if (_num_parts <= index) {
82  (*edep_info.rbegin()) += ide.numElectrons;
83  (*(_sum_mcq[plane]).rbegin()) += ide.numElectrons;
84  }
85  else {
86  edep_info[index] += ide.numElectrons;
87  _sum_mcq[plane][index] += ide.numElectrons;
88  }
89  }
90  }
91  }
92  }
93 
94  const std::vector<double>& MCBTAlg::MCQSum(const size_t plane_id) const
95  {
96  if (plane_id > _sum_mcq.size())
97  throw MCBTException(Form("Invalid plane requested: %zu", plane_id));
98  return _sum_mcq[plane_id];
99  }
100 
101  std::vector<double> MCBTAlg::MCQ(detinfo::DetectorClocksData const& clockData,
102  const WireRange_t& hit) const
103  {
104  std::vector<double> res(_num_parts, 0);
105 
106  if (_event_info.size() <= hit.ch) return res;
107 
108  auto const& ch_info = _event_info[hit.ch];
109 
110  auto itlow = ch_info.lower_bound((unsigned int)(clockData.TPCTick2TDC(hit.start)));
111  auto itup = ch_info.upper_bound((unsigned int)(clockData.TPCTick2TDC(hit.end)) + 1);
112 
113  while (itlow != ch_info.end() && itlow != itup) {
114 
115  auto const& edep_info = (*itlow).second;
116 
117  for (size_t part_index = 0; part_index < _num_parts; ++part_index)
118 
119  res[part_index] += edep_info[part_index];
120 
121  ++itlow;
122  }
123  return res;
124  }
125 
126  std::vector<double> MCBTAlg::MCQFrac(detinfo::DetectorClocksData const& clockData,
127  const WireRange_t& hit) const
128  {
129  auto res = MCQ(clockData, hit);
130  if (!res.size()) return res;
131 
132  double sum = 0;
133  for (auto const& v : res)
134  sum += v;
135  for (size_t i = 0; i < (res.size() - 1); ++i)
136  res[i] /= (sum - (*res.rbegin()));
137  (*res.rbegin()) /= sum;
138  return res;
139  }
140 
141  std::vector<double> MCBTAlg::MCQ(detinfo::DetectorClocksData const& clockData,
142  const std::vector<WireRange_t>& hit_v) const
143  {
144  std::vector<double> res(_num_parts, 0);
145  for (auto const& h : hit_v) {
146  auto tmp_res = MCQ(clockData, h);
147  for (size_t i = 0; i < res.size(); ++i)
148  res[i] += tmp_res[i];
149  }
150  return res;
151  }
152 
153  std::vector<double> MCBTAlg::MCQFrac(detinfo::DetectorClocksData const& clockData,
154  const std::vector<WireRange_t>& hit_v) const
155  {
156  auto res = MCQ(clockData, hit_v);
157  if (!res.size()) return res;
158 
159  double sum = 0;
160  for (auto const& v : res)
161  sum += v;
162  for (size_t i = 0; i < (res.size() - 1); ++i)
163  res[i] /= (sum - (*res.rbegin()));
164  (*res.rbegin()) /= sum;
165  return res;
166  }
167 
168  size_t MCBTAlg::Index(const unsigned int g4_track_id) const
169  {
170  if (g4_track_id >= _trkid_to_index.size()) return kINVALID_INDEX;
171  return _trkid_to_index[g4_track_id];
172  }
173 
174  void MCBTAlg::Register(const unsigned int& g4_track_id)
175  {
176  if (_trkid_to_index.size() <= g4_track_id)
177  _trkid_to_index.resize(g4_track_id + 1, kINVALID_INDEX);
178 
179  if (_trkid_to_index[g4_track_id] == kINVALID_INDEX) {
180  _trkid_to_index[g4_track_id] = _num_parts;
181  ++_num_parts;
182  }
183  }
184 
185  void MCBTAlg::Register(const std::vector<unsigned int>& track_id_v)
186  {
187  unsigned int max_id = 0;
188  for (auto const& id : track_id_v)
189  if (max_id < id) max_id = id;
190  if (_trkid_to_index.size() <= max_id) _trkid_to_index.resize(max_id + 1, kINVALID_INDEX);
191 
192  for (auto const& id : track_id_v) {
193 
194  if (_trkid_to_index[id] == kINVALID_INDEX)
195 
197 
198  else
199 
200  throw MCBTException(Form("Doubly used TrackID: %d", id));
201  }
202  ++_num_parts;
203  }
204 
205 }
unsigned int ch
Definition: MCBTAlg.h:34
Utilities related to art service access.
const std::vector< double > & MCQSum(const size_t plane_id) const
Definition: MCBTAlg.cxx:94
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::vector< std::vector< double > > _sum_mcq
Definition: MCBTAlg.h:126
void Reset(const std::vector< unsigned int > &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v)
Definition: MCBTAlg.cxx:23
Class def header for a class MCBTAlg.
std::vector<::btutil::ch_info_t > _event_info
Definition: MCBTAlg.h:124
pure virtual base interface for detector clocks
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
size_t Index(const unsigned int g4_track_id) const
Definition: MCBTAlg.cxx:168
std::vector< double > MCQ(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:101
static const size_t kINVALID_INDEX
Signifies invalid MCX index number.
void ProcessSimChannel(const std::vector< sim::SimChannel > &simch_v)
Definition: MCBTAlg.cxx:51
std::vector< size_t > _trkid_to_index
Definition: MCBTAlg.h:125
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:126
object containing MC truth information necessary for making RawDigits and doing back tracking ...
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
Definition: GeometryCore.h:977
size_t _num_parts
Definition: MCBTAlg.h:127
Double_t sum
Definition: plot.C:31
Namespace collecting geometry-related classes utilities.
void Register(const unsigned int &g4_track_id)
Definition: MCBTAlg.cxx:174
double TPCTick2TDC(double const tick) const
art framework interface to geometry description
Class def header for exception classes in MCComp package.