LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MCBTAlg.cxx
Go to the documentation of this file.
1 #ifndef MCBTALG_CXX
2 #define MCBTALG_CXX
3 
4 #include "MCBTAlg.h"
5 
6 namespace btutil {
7 
8  MCBTAlg::MCBTAlg(const std::vector<unsigned int>& g4_trackid_v,
9  const std::vector<sim::SimChannel>& simch_v)
10  {
11  Reset(g4_trackid_v,simch_v);
12  }
13 
14  void MCBTAlg::Reset(const std::vector<unsigned int>& g4_trackid_v,
15  const std::vector<sim::SimChannel>& simch_v)
16  {
17  _num_parts = 0;
18  _sum_mcq.clear();
19  _trkid_to_index.clear();
20  _event_info.clear();
21  //
22  for(auto const& id : g4_trackid_v)
23  Register(id);
24  _num_parts++;
25  ProcessSimChannel(simch_v);
26 
27  }
28 
29  void MCBTAlg::Reset(const std::vector<std::vector<unsigned int> >& g4_trackid_v,
30  const std::vector<sim::SimChannel>& simch_v)
31  {
32  _num_parts = 0;
33  _sum_mcq.clear();
34  _trkid_to_index.clear();
35  _event_info.clear();
36  //
37  for(auto const& id : g4_trackid_v)
38  Register(id);
39  _num_parts++;
40  ProcessSimChannel(simch_v);
41  }
42 
43  void MCBTAlg::ProcessSimChannel(const std::vector<sim::SimChannel>& simch_v)
44  {
45 
47  //auto geo = ::larutil::Geometry::GetME();
48  _sum_mcq.resize(geo->Nplanes(),std::vector<double>(_num_parts,0));
49 
50  for(auto const& sch : simch_v) {
51 
52  auto const ch = sch.Channel();
53  if(_event_info.size() <= ch) _event_info.resize(ch+1);
54 
55  auto& ch_info = _event_info[ch];
56 
57  size_t plane = geo->ChannelToWire(ch)[0].Plane;
58  //size_t plane = geo->ChannelToPlane(ch);
59 
60  for(auto const& time_ide : sch.TDCIDEMap()) {
61 
62  auto const& time = time_ide.first;
63  auto const& ide_v = time_ide.second;
64 
65  auto& edep_info = ch_info[time];
66 
67  if(!edep_info.size()) edep_info.resize(_num_parts,0);
68 
69  for(auto const& ide : ide_v) {
70 
71  size_t index = kINVALID_INDEX;
72  if(ide.trackID < (int)(_trkid_to_index.size())){
73  index = _trkid_to_index[ide.trackID];
74  }
75  if(_num_parts <= index) {
76  (*edep_info.rbegin()) += ide.numElectrons;
77  (*(_sum_mcq[plane]).rbegin()) += ide.numElectrons;
78  }
79  else {
80  edep_info[index] += ide.numElectrons;
81  _sum_mcq[plane][index] += ide.numElectrons;
82  }
83  }
84  }
85  }
86  }
87 
88  const std::vector<double>& MCBTAlg::MCQSum(const size_t plane_id) const
89  {
90  if(plane_id > _sum_mcq.size())
91  throw MCBTException(Form("Invalid plane requested: %zu",plane_id));
92  return _sum_mcq[plane_id];
93  }
94 
95  std::vector<double> MCBTAlg::MCQ(const WireRange_t& hit) const
96  {
97  std::vector<double> res(_num_parts,0);
98 
99  if(_event_info.size() <= hit.ch) return res;
100 
101  auto const& ch_info = _event_info[hit.ch];
102 
103  const detinfo::DetectorClocks* ts = lar::providerFrom<detinfo::DetectorClocksService>();
104  //auto ts = ::larutil::TimeService::GetME();
105 
106  auto itlow = ch_info.lower_bound((unsigned int)(ts->TPCTick2TDC(hit.start)));
107  auto itup = ch_info.upper_bound((unsigned int)(ts->TPCTick2TDC(hit.end))+1);
108 
109  while(itlow != ch_info.end() && itlow != itup) {
110 
111  auto const& edep_info = (*itlow).second;
112 
113  for(size_t part_index = 0; part_index<_num_parts; ++part_index)
114 
115  res[part_index] += edep_info[part_index];
116 
117  ++itlow;
118  }
119  return res;
120  }
121 
122 
123  std::vector<double> MCBTAlg::MCQFrac(const WireRange_t& hit) const
124  {
125  auto res = MCQ(hit);
126  if(!res.size()) return res;
127 
128  double sum = 0;
129  for(auto const& v : res) sum += v;
130  for(size_t i=0; i<(res.size()-1); ++i)
131  res[i] /= (sum - (*res.rbegin()));
132  (*res.rbegin()) /= sum;
133  return res;
134  }
135 
136  std::vector<double> MCBTAlg::MCQ(const std::vector<WireRange_t>& hit_v) const
137  {
138  std::vector<double> res(_num_parts,0);
139  for(auto const& h : hit_v) {
140  auto tmp_res = MCQ(h);
141  for(size_t i=0; i<res.size(); ++i) res[i] += tmp_res[i];
142  }
143  return res;
144  }
145 
146  std::vector<double> MCBTAlg::MCQFrac(const std::vector<WireRange_t>& hit_v) const
147  {
148  auto res = MCQ(hit_v);
149  if(!res.size()) return res;
150 
151  double sum = 0;
152  for(auto const& v : res) sum += v;
153  for(size_t i=0; i<(res.size()-1); ++i)
154  res[i] /= (sum - (*res.rbegin()));
155  (*res.rbegin()) /= sum;
156  return res;
157  }
158 
159  size_t MCBTAlg::Index(const unsigned int g4_track_id) const
160  {
161  if(g4_track_id >= _trkid_to_index.size()) return kINVALID_INDEX;
162  return _trkid_to_index[g4_track_id];
163  }
164 
165  void MCBTAlg::Register(const unsigned int& g4_track_id)
166  {
167  if(_trkid_to_index.size() <= g4_track_id)
168  _trkid_to_index.resize(g4_track_id+1,kINVALID_INDEX);
169 
170  if(_trkid_to_index[g4_track_id] == kINVALID_INDEX){
171  _trkid_to_index[g4_track_id] = _num_parts;
172  ++_num_parts;
173  }
174  }
175 
176  void MCBTAlg::Register(const std::vector<unsigned int>& track_id_v)
177  {
178  unsigned int max_id = 0;
179  for(auto const& id : track_id_v) if(max_id < id) max_id = id;
180  if(_trkid_to_index.size() <= max_id)
181  _trkid_to_index.resize(max_id+1,kINVALID_INDEX);
182 
183  for(auto const& id : track_id_v) {
184 
186 
188 
189  else
190 
191  throw MCBTException(Form("Doubly used TrackID: %d",id));
192 
193  }
194  ++_num_parts;
195  }
196 
197 }
198 
199 #endif
unsigned int ch
Definition: MCBTAlg.h:37
const std::vector< double > & MCQSum(const size_t plane_id) const
Definition: MCBTAlg.cxx:88
std::vector< std::vector< double > > _sum_mcq
Definition: MCBTAlg.h:121
void Reset(const std::vector< unsigned int > &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v)
Definition: MCBTAlg.cxx:14
Class def header for a class MCBTAlg.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::vector< double > MCQFrac(const WireRange_t &hit) const
Definition: MCBTAlg.cxx:123
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
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:159
static const size_t kINVALID_INDEX
Signifies invalid MCX index number.
void ProcessSimChannel(const std::vector< sim::SimChannel > &simch_v)
Definition: MCBTAlg.cxx:43
std::vector< size_t > _trkid_to_index
Definition: MCBTAlg.h:120
Detector simulation of raw signals on wires.
Conversion of times between different formats and references.
virtual double TPCTick2TDC(double tick) const =0
Converts a TPC time tick into a electronics time tick.
std::vector< double > MCQ(const WireRange_t &hit) const
Definition: MCBTAlg.cxx:95
size_t _num_parts
Definition: MCBTAlg.h:122
Namespace collecting geometry-related classes utilities.
void Register(const unsigned int &g4_track_id)
Definition: MCBTAlg.cxx:165
std::vector< ::btutil::ch_info_t > _event_info
Definition: MCBTAlg.h:119