All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CommonAmps.cxx
Go to the documentation of this file.
1 #ifndef OPT0FINDER_COMMONAMPS_CXX
2 #define OPT0FINDER_COMMONAMPS_CXX
3 
4 #include "CommonAmps.h"
6 #include <cmath>
7 #include <sstream>
8 #include <numeric>
9 namespace flashmatch {
10 
12 
13  CommonAmps::CommonAmps(const std::string name)
14  : BaseFlashMatch(name)
15  {
16  _percent = 0.5;
17  _score = 0.8;
18  }
19 
21  {
22  _percent = pset.get<double>("QFracThreshold");
23  _score = pset.get<double>("ScoreThreshold");
24  _x_step_size = pset.get<double>("XStepSize");
25  }
26 
27  FlashMatch_t CommonAmps::Match(const QCluster_t& pt_v, const Flash_t& flash)
28  {
29 
30  double integral_op = std::accumulate(std::begin(flash.pe_v),
31  std::end(flash.pe_v),
32  0.0);
33  double maxRatio = -1;
34  //double maxX = 0;
35 
36  if(_vis_array.pe_v.empty())
37  _vis_array.pe_v.resize(OpDetXArray().size());
38 
39  // Create multimap to hold the largest amplitudes in the first slots of map
40  // Normalize each PE bin to the total # of PEs-- 1/x to put highest amps in front
41  std::multimap<double,int> ampToOpDet ;
42 
43  for(size_t k=0; k<32; k++)
44  ampToOpDet.emplace(1./(flash.pe_v[k]/integral_op),k);
45 
46 
47  // Now that opdet hits are normalized and ordered, store indices for PMTs which
48  // had the greatest hit amplitudes up to _percent of total PMT hits
49  double opAmpTotal = 0;
50  std::vector<int> ids ;
51  ids.resize(0);
52 
53  for( auto const & e : ampToOpDet ){
54  opAmpTotal += 1/e.first ;
55  ids.push_back(e.second) ;
56  if( opAmpTotal > _percent )
57  break;
58  }
59 
60  // Prepare the return values (Mostly QWeightPoint)
61  FlashMatch_t f;
62  if(pt_v.empty()){
63  std::cout<<"Not enough points!"<<std::endl;
64  return f;
65  }
66 
67  _tpc_qcluster.resize(pt_v.size());
68 
69  // Get min & max x value
70  double x_max = 0;
71  double x_min = 1e12;
72 
73  for(auto const& pt : pt_v) {
74  if(pt.x > x_max) x_max = pt.x;
75  if(pt.x < x_min) x_min = pt.x;
76  }
77 
78  for(double x_offset=0;
79  x_offset<(250.-(x_max-x_min));
80  x_offset+=_x_step_size) {
81 
82  // Create QCluster_t with this offset
83 
84  for(size_t i=0; i<_tpc_qcluster.size(); ++i) {
85  _tpc_qcluster[i].x = pt_v[i].x + x_offset - x_min;
86  _tpc_qcluster[i].y = pt_v[i].y;
87  _tpc_qcluster[i].z = pt_v[i].z;
88  _tpc_qcluster[i].q = pt_v[i].q;
89  }
90 
92 
93  // Calculate amplitudes corresponding to max opdet amplitudes
94  double visAmpTotal = 0;
95  double vis_pe_sum = _vis_array.TotalPE();
96 
97  for(size_t i=0; i<ids.size(); i++) {
98  if(_vis_array.pe_v[ids[i]]<0) continue;
99  visAmpTotal += _vis_array.pe_v[ids[i]] / vis_pe_sum ;
100  }
101 
102  double ratio = 0;
103  if(opAmpTotal > visAmpTotal )
104  ratio = visAmpTotal/opAmpTotal ;
105  else
106  ratio = opAmpTotal/visAmpTotal ;
107 
108  if(ratio > maxRatio) {
109  maxRatio = ratio;
110  //maxX = x_offset;
111 
112  f.score = ratio;
113  f.tpc_point.x = f.tpc_point.y = f.tpc_point.z = 0;
114  f.tpc_point.q = vis_pe_sum;
115 
116  for(size_t pmt_index=0; pmt_index<NOpDets(); ++pmt_index) {
117  double pe = _vis_array.pe_v[pmt_index];
118  if(pe<0) continue;
119  f.tpc_point.x += OpDetX(pmt_index) * pe / vis_pe_sum;
120  f.tpc_point.y += OpDetY(pmt_index) * pe / vis_pe_sum;
121  f.tpc_point.z += OpDetZ(pmt_index) * pe / vis_pe_sum;
122  }
123  }
124  }
125 
126  // If min-diff is bigger than assigned max, return default match (score<0)
127  if( maxRatio < _score ) {
128 
129  f.tpc_point.x = f.tpc_point.y = f.tpc_point.z = -1;
130  f.tpc_point.q = -1;
131  f.score = -1;
132  return f;
133  }
134 
136  return f;
137  }
138 }
139 #endif
std::vector< double > hypothesis
void _Configure_(const Config_t &pset)
Definition: CommonAmps.cxx:20
CommonAmps(const std::string name="CommonAmps")
Default constructor.
Definition: CommonAmps.cxx:13
FlashMatch_t Match(const QCluster_t &, const Flash_t &)
Definition: CommonAmps.cxx:27
double score
floating point representing the &quot;goodness&quot; (algorithm dependent)
static CommonAmpsFactory __global_CommonAmpsFactory__
Definition: CommonAmps.cxx:11
double z
Spatial position in [cm].
double TotalPE() const
Total PE calculation.
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
fhicl::ParameterSet Config_t
Configuration object.
Definition: FMWKInterface.h:31
flashmatch::QCluster_t _tpc_qcluster
Definition: CommonAmps.h:53
Struct to represent an optical flash.
std::vector< double > pe_v
PE distribution over photo-detectors.
Class def header for a class CommonAmps.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
Collection of charge deposition 3D point (cluster)
QPoint_t tpc_point
estimated &amp; matched 3D flash hypothesis point from TPC information
Class def header for exception classes in OpT0Finder package.
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
flashmatch::Flash_t _vis_array
Definition: CommonAmps.h:54
do i e
then echo fcl name
void FillEstimate(const QCluster_t &, Flash_t &) const
Method to simply fill provided reference of flashmatch::Flash_t.
pdgs k
Definition: selectors.fcl:22
Flash-TPC match info.
BEGIN_PROLOG could also be cout