Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
btutil::MCMatchAlg Class Reference

#include <MCMatchAlg.h>

Public Member Functions

 MCMatchAlg ()
 Default constructor. More...
 
virtual ~MCMatchAlg ()
 Default destructor. More...
 
bool BuildMap (detinfo::DetectorClocksData const &clockData, const std::vector< unsigned int > &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v, const std::vector< std::vector< art::Ptr< recob::Hit >>> &cluster_v)
 Constructs needed information for Reco=>MC matching. More...
 
bool BuildMap (detinfo::DetectorClocksData const &clockData, const std::vector< std::vector< unsigned int >> &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v, const std::vector< std::vector< art::Ptr< recob::Hit >>> &cluster_v)
 Constructs needed information for Reco=>MC matching. More...
 
const std::vector< int > & BestClusters (const size_t mcshower_index) const
 
double ClusterCorrectness (const size_t cluster_index, const size_t mcshower_index) const
 
std::pair< size_t, double > ShowerCorrectness (const std::vector< unsigned int > cluster_indices) const
 
std::pair< double, double > ClusterEP (const size_t cluster_index, const size_t mcshower_index) const
 For a specified cluster, compute cluster efficiency and purity in terms of specified MC object. More...
 
std::pair< double, double > BestClusterEP (const size_t mcshower_index, const size_t plane_id) const
 
const MCBTAlgBTAlg () const
 BTAlgo getter. More...
 

Protected Member Functions

bool BuildMap (detinfo::DetectorClocksData const &clockData, const std::vector< std::vector< art::Ptr< recob::Hit >>> &cluster_v)
 

Protected Attributes

MCBTAlg fBTAlgo
 MCBTAlg instance. More...
 
std::vector< size_t > _view_to_plane
 
std::vector< std::vector< double > > _summed_mcq
 
std::vector< std::vector< double > > _cluster_mcq_v
 
std::vector< unsigned char > _cluster_plane_id
 
std::vector< std::vector< int > > _bmatch_id
 

Detailed Description

User defined class MCMatchAlg ... these comments are used to generate doxygen documentation!

Definition at line 36 of file MCMatchAlg.h.

Constructor & Destructor Documentation

btutil::MCMatchAlg::MCMatchAlg ( )

Default constructor.

Definition at line 16 of file MCMatchAlg.cxx.

16 { _view_to_plane.clear(); }
std::vector< size_t > _view_to_plane
Definition: MCMatchAlg.h:105
virtual btutil::MCMatchAlg::~MCMatchAlg ( )
inlinevirtual

Default destructor.

Definition at line 43 of file MCMatchAlg.h.

43 {};

Member Function Documentation

std::pair< double, double > btutil::MCMatchAlg::BestClusterEP ( const size_t  mcshower_index,
const size_t  plane_id 
) const

For a specified MC object, compute the best-matched cluster's efficiency and purity from the specified plane ID. Internally this function calls BestClusters() to find the best cluster on each plane, then calls ClusterEP() to retrieve the efficiency and purity.

Definition at line 234 of file MCMatchAlg.cxx.

235  {
236 
237  auto c_index_v = BestClusters(mc_index);
238 
239  if (c_index_v.size() <= plane_id)
240  throw MCBTException(Form(
241  "Plane ID %zu exceeds # of planes recorded in data (%zu)...", plane_id, c_index_v.size()));
242 
243  std::pair<double, double> result(0, 0);
244 
245  if (c_index_v[plane_id] < 0) return result;
246 
247  return ClusterEP(c_index_v[plane_id], mc_index);
248  }
static QCString result
std::pair< double, double > ClusterEP(const size_t cluster_index, const size_t mcshower_index) const
For a specified cluster, compute cluster efficiency and purity in terms of specified MC object...
Definition: MCMatchAlg.cxx:191
const std::vector< int > & BestClusters(const size_t mcshower_index) const
Definition: MCMatchAlg.cxx:222
const std::vector< int > & btutil::MCMatchAlg::BestClusters ( const size_t  mcshower_index) const

For a specified MC object (via index in MCShower/MCTrack), returns best-matched clusters represented by an index number of clusters. The return vector length is same as

of planes, and "-1" if there is no cluster found on the corresponding plane.

Definition at line 222 of file MCMatchAlg.cxx.

223  {
224  if (!_bmatch_id.size()) throw MCBTException("Preparation not done yet!");
225 
226  if (mc_index >= _bmatch_id.size())
227  throw MCBTException(
228  Form("Input MC object index (%zu) out of range (%zu)!", mc_index, _bmatch_id.size()));
229 
230  return _bmatch_id[mc_index];
231  }
std::vector< std::vector< int > > _bmatch_id
Definition: MCMatchAlg.h:111
const MCBTAlg& btutil::MCMatchAlg::BTAlg ( ) const
inline

BTAlgo getter.

Definition at line 93 of file MCMatchAlg.h.

94  {
95  return fBTAlgo;
96  }
MCBTAlg fBTAlgo
MCBTAlg instance.
Definition: MCMatchAlg.h:103
bool btutil::MCMatchAlg::BuildMap ( detinfo::DetectorClocksData const &  clockData,
const std::vector< unsigned int > &  g4_trackid_v,
const std::vector< sim::SimChannel > &  simch_v,
const std::vector< std::vector< art::Ptr< recob::Hit >>> &  cluster_v 
)

Constructs needed information for Reco=>MC matching.

Definition at line 19 of file MCMatchAlg.cxx.

23  {
24  fBTAlgo.Reset(g4_trackid_v, simch_v);
25 
26  return BuildMap(clockData, cluster_v);
27  }
void Reset(const std::vector< unsigned int > &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v)
Definition: MCBTAlg.cxx:24
bool BuildMap(detinfo::DetectorClocksData const &clockData, const std::vector< unsigned int > &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v, const std::vector< std::vector< art::Ptr< recob::Hit >>> &cluster_v)
Constructs needed information for Reco=>MC matching.
Definition: MCMatchAlg.cxx:19
MCBTAlg fBTAlgo
MCBTAlg instance.
Definition: MCMatchAlg.h:103
bool btutil::MCMatchAlg::BuildMap ( detinfo::DetectorClocksData const &  clockData,
const std::vector< std::vector< unsigned int >> &  g4_trackid_v,
const std::vector< sim::SimChannel > &  simch_v,
const std::vector< std::vector< art::Ptr< recob::Hit >>> &  cluster_v 
)

Constructs needed information for Reco=>MC matching.

Definition at line 30 of file MCMatchAlg.cxx.

34  {
35 
36  fBTAlgo.Reset(g4_trackid_v, simch_v);
37 
38  return BuildMap(clockData, cluster_v);
39  }
void Reset(const std::vector< unsigned int > &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v)
Definition: MCBTAlg.cxx:24
bool BuildMap(detinfo::DetectorClocksData const &clockData, const std::vector< unsigned int > &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v, const std::vector< std::vector< art::Ptr< recob::Hit >>> &cluster_v)
Constructs needed information for Reco=>MC matching.
Definition: MCMatchAlg.cxx:19
MCBTAlg fBTAlgo
MCBTAlg instance.
Definition: MCMatchAlg.h:103
bool btutil::MCMatchAlg::BuildMap ( detinfo::DetectorClocksData const &  clockData,
const std::vector< std::vector< art::Ptr< recob::Hit >>> &  cluster_v 
)
protected

Definition at line 42 of file MCMatchAlg.cxx.

44  {
45  size_t num_mcobj = fBTAlgo.NumParts();
46  size_t num_cluster = cluster_v.size();
47  //auto geo = ::larutil::Geometry::GetME();
49 
50  //
51  // Perform back-tracking
52  //
53  // (1) Load cluster/hit data product
54  // (2) Loop over all clusters and find charge fraction to each MC object
55  // (3) For each MC object, find a cluster per plane with the highest charge
56 
57  // Loop over clusters & get charge fraction per MC object
58  _summed_mcq.clear();
59  _cluster_mcq_v.clear();
60  _cluster_plane_id.clear();
61 
62  _summed_mcq.resize(num_mcobj + 1, std::vector<double>(geo->Nplanes(), 0));
63  _cluster_mcq_v.reserve(num_cluster);
64  _cluster_plane_id.reserve(num_cluster);
65 
66  for (auto const& hit_v : cluster_v) {
67 
68  size_t plane = geo->Nplanes();
69 
70  // Create hit list
71  std::vector<WireRange_t> wr_v;
72  wr_v.reserve(hit_v.size());
73 
74  for (auto const& h : hit_v) {
75 
76  WireRange_t wr;
77  wr.ch = h->Channel();
78  wr.start = h->StartTick();
79  wr.end = h->EndTick();
80  wr_v.push_back(wr);
81  if (plane == geo->Nplanes()) plane = h->WireID().Plane;
82  //if(plane==geo->Nplanes()) plane = h->View();
83  }
84 
85  _cluster_plane_id.push_back(plane);
86 
87  auto mcq_v = fBTAlgo.MCQ(clockData, wr_v);
88 
89  for (size_t i = 0; i < mcq_v.size(); ++i)
90 
91  _summed_mcq[i][plane] += mcq_v[i];
92 
93  _cluster_mcq_v.push_back(mcq_v);
94  }
95 
96  //
97  // Find the best matched pair (and its charge) per MC object
98  //
99  _bmatch_id.clear();
100  _bmatch_id.resize(num_mcobj, std::vector<int>(geo->Nplanes(), -1));
101 
102  std::vector<std::vector<double>> bmatch_mcq(num_mcobj, std::vector<double>(geo->Nplanes(), 0));
103 
104  for (size_t mc_index = 0; mc_index < num_mcobj; ++mc_index) {
105 
106  for (size_t cluster_index = 0; cluster_index < num_cluster; ++cluster_index) {
107 
108  //if((_cluster_mcq_v[cluster_index].back()) < 0) continue;
109 
110  auto plane = _cluster_plane_id.at(cluster_index);
111 
112  double q = _cluster_mcq_v[cluster_index][mc_index];
113 
114  if (bmatch_mcq[mc_index][plane] < q) {
115 
116  bmatch_mcq[mc_index][plane] = q;
117  _bmatch_id[mc_index][plane] = cluster_index;
118  }
119  }
120  }
121 
122  return true;
123  }
std::vector< std::vector< double > > _summed_mcq
Definition: MCMatchAlg.h:107
std::vector< unsigned char > _cluster_plane_id
Definition: MCMatchAlg.h:110
std::vector< std::vector< double > > _cluster_mcq_v
Definition: MCMatchAlg.h:108
MCBTAlg fBTAlgo
MCBTAlg instance.
Definition: MCMatchAlg.h:103
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
std::vector< double > MCQ(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:106
size_t NumParts() const
Definition: MCBTAlg.h:116
std::vector< std::vector< int > > _bmatch_id
Definition: MCMatchAlg.h:111
LArSoft geometry interface.
Definition: ChannelGeo.h:16
double btutil::MCMatchAlg::ClusterCorrectness ( const size_t  cluster_index,
const size_t  mcshower_index 
) const

For a specified cluster, compute the correctness for the specified MC object

Definition at line 126 of file MCMatchAlg.cxx.

127  {
128 
129  if (!_bmatch_id.size()) throw MCBTException("Preparation not done yet!");
130 
131  if (cluster_index >= _cluster_mcq_v.size())
132  throw MCBTException(Form(
133  "Input cluster index (%zu) out of range (%zu)!", cluster_index, _cluster_mcq_v.size()));
134 
135  if (mc_index >= _bmatch_id.size())
136  throw MCBTException(
137  Form("Input MC object index (%zu) out of range (%zu)!", mc_index, _bmatch_id.size()));
138 
139  auto plane = _cluster_plane_id.at(cluster_index);
140 
141  auto best_cluster_index = _bmatch_id.at(mc_index).at(plane);
142 
143  if (best_cluster_index < 0) return -1;
144 
145  return _cluster_mcq_v.at(cluster_index).at(mc_index) /
146  _cluster_mcq_v.at(best_cluster_index).at(mc_index);
147  }
std::vector< unsigned char > _cluster_plane_id
Definition: MCMatchAlg.h:110
std::vector< std::vector< double > > _cluster_mcq_v
Definition: MCMatchAlg.h:108
std::vector< std::vector< int > > _bmatch_id
Definition: MCMatchAlg.h:111
std::pair< double, double > btutil::MCMatchAlg::ClusterEP ( const size_t  cluster_index,
const size_t  mcshower_index 
) const

For a specified cluster, compute cluster efficiency and purity in terms of specified MC object.

Definition at line 191 of file MCMatchAlg.cxx.

192  {
193  if (!_bmatch_id.size()) throw MCBTException("Preparation not done yet!");
194 
195  if (cluster_index >= _cluster_mcq_v.size())
196  throw MCBTException(Form(
197  "Input cluster index (%zu) out of range (%zu)!", cluster_index, _cluster_mcq_v.size()));
198 
199  if (mc_index >= _bmatch_id.size())
200  throw MCBTException(
201  Form("Input MC object index (%zu) out of range (%zu)!", mc_index, _bmatch_id.size()));
202 
203  // efficiency = this cluster's mcq for specified mc obj / total mcq by this mcshower in all clusters
204  // purity = this cluster's mcq for this mcshower / total mcq from all mc obj in this cluster
205 
206  std::pair<double, double> result;
207 
208  auto plane = _cluster_plane_id[cluster_index];
209 
210  result.first = _cluster_mcq_v[cluster_index][mc_index] / _summed_mcq[mc_index][plane];
211 
212  double cluster_mcq_total = 0;
213  for (auto const& q : _cluster_mcq_v[cluster_index])
214  cluster_mcq_total += q;
215 
216  result.second = _cluster_mcq_v[cluster_index][mc_index] / cluster_mcq_total;
217 
218  return result;
219  }
static QCString result
std::vector< std::vector< double > > _summed_mcq
Definition: MCMatchAlg.h:107
std::vector< unsigned char > _cluster_plane_id
Definition: MCMatchAlg.h:110
std::vector< std::vector< double > > _cluster_mcq_v
Definition: MCMatchAlg.h:108
std::vector< std::vector< int > > _bmatch_id
Definition: MCMatchAlg.h:111
std::pair< size_t, double > btutil::MCMatchAlg::ShowerCorrectness ( const std::vector< unsigned int >  cluster_indices) const

Similar to ClusterCorrectness() function except this one computes the correctness for multiple clusters. It is meant to compute the correctness for a cluster combination that is matched across plane to represent one 3D reco object. The return is a pair of best-matched MC object and correctness.

Definition at line 150 of file MCMatchAlg.cxx.

151  {
152 
153  if (!_bmatch_id.size()) throw MCBTException("Preparation not done yet!");
154 
155  if (cluster_indices.size() > _cluster_mcq_v.size())
156  throw MCBTException(
157  Form("Input cluster indices length (%zu) > # of registered clusters (%zu)!",
158  cluster_indices.size(),
159  _cluster_mcq_v.size()));
160 
161  if (!cluster_indices.size()) throw MCBTException("Input cluster indices empty!");
162 
163  // Compute efficiency per MC
164  std::vector<double> match_eff(_bmatch_id.size(), 1);
165 
166  for (auto const& cluster_index : cluster_indices) {
167 
168  for (size_t mc_index = 0; mc_index < _bmatch_id.size(); ++mc_index) {
169 
170  double correctness = ClusterCorrectness(cluster_index, mc_index);
171 
172  if (correctness >= 0) match_eff.at(mc_index) *= correctness;
173  }
174  }
175 
176  std::pair<size_t, double> result(0, -1);
177 
178  // Find the best qratio
179  for (size_t mc_index = 0; mc_index < match_eff.size(); ++mc_index) {
180 
181  if (match_eff.at(mc_index) < result.second) continue;
182 
183  result.second = match_eff.at(mc_index);
184 
185  result.first = mc_index;
186  }
187  return result;
188  }
static QCString result
char & at(uint i) const
Definition: qcstring.h:326
std::vector< std::vector< double > > _cluster_mcq_v
Definition: MCMatchAlg.h:108
double ClusterCorrectness(const size_t cluster_index, const size_t mcshower_index) const
Definition: MCMatchAlg.cxx:126
std::vector< std::vector< int > > _bmatch_id
Definition: MCMatchAlg.h:111

Member Data Documentation

std::vector<std::vector<int> > btutil::MCMatchAlg::_bmatch_id
protected

Definition at line 111 of file MCMatchAlg.h.

std::vector<std::vector<double> > btutil::MCMatchAlg::_cluster_mcq_v
protected

Definition at line 108 of file MCMatchAlg.h.

std::vector<unsigned char> btutil::MCMatchAlg::_cluster_plane_id
protected

Definition at line 110 of file MCMatchAlg.h.

std::vector<std::vector<double> > btutil::MCMatchAlg::_summed_mcq
protected

Definition at line 107 of file MCMatchAlg.h.

std::vector<size_t> btutil::MCMatchAlg::_view_to_plane
protected

Definition at line 105 of file MCMatchAlg.h.

MCBTAlg btutil::MCMatchAlg::fBTAlgo
protected

MCBTAlg instance.

Definition at line 103 of file MCMatchAlg.h.


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