All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
flashmatch::QLLMatch Class Reference

#include <QLLMatch.h>

Inheritance diagram for flashmatch::QLLMatch:
flashmatch::BaseFlashMatch flashmatch::BaseAlgorithm flashmatch::LoggerFeature

Public Types

enum  QLLMode_t { kChi2, kLLHD, kSimpleLLHD }
 

Public Member Functions

 QLLMatch ()
 Default ctor throws exception (singleton) More...
 
 ~QLLMatch ()
 Default destructor. More...
 
FlashMatch_t Match (const QCluster_t &, const Flash_t &)
 Core function: execute matching. More...
 
const Flash_tChargeHypothesis (const double)
 
const Flash_tMeasurement () const
 
double QLL (const flashmatch::Flash_t &, const flashmatch::Flash_t &)
 
void Record (const double x)
 
void OneStep ()
 
double CallMinuit (const QCluster_t &tpc, const Flash_t &pmt, const bool init_x0=true)
 
const std::vector< double > & HistoryLLHD () const
 
const std::vector< double > & HistoryChi2 () const
 
const std::vector< double > & HistoryX () const
 
void SetTPCCryo (int tpc, int cryo)
 Sets the TPC and Cryo numbers. More...
 
- Public Member Functions inherited from flashmatch::BaseFlashMatch
 BaseFlashMatch (const std::string name="noname")
 Default constructor. More...
 
virtual ~BaseFlashMatch ()
 Default destructor. More...
 
Flash_t GetEstimate (const QCluster_t &) const
 Method to call flash hypothesis. More...
 
void FillEstimate (const QCluster_t &, Flash_t &) const
 Method to simply fill provided reference of flashmatch::Flash_t. More...
 
- Public Member Functions inherited from flashmatch::BaseAlgorithm
 BaseAlgorithm (const Algorithm_t type, const std::string name)
 Default constructor. More...
 
 ~BaseAlgorithm ()
 Default destructor. More...
 
void Configure (const Config_t &pset)
 Function to accept configuration. More...
 
Algorithm_t AlgorithmType () const
 Algorithm type. More...
 
const std::string & AlgorithmName () const
 Algorithm name. More...
 
- Public Member Functions inherited from flashmatch::LoggerFeature
 LoggerFeature (const std::string logger_name="LoggerFeature")
 Default constructor. More...
 
 LoggerFeature (const LoggerFeature &original)
 Default copy constructor. More...
 
virtual ~LoggerFeature ()
 Default destructor. More...
 
const flashmatch::loggerlogger () const
 Logger getter. More...
 
void set_verbosity (::flashmatch::msg::Level_t level)
 Verbosity level. More...
 
const std::string & name () const
 Name getter, defined in a logger instance attribute. More...
 

Static Public Member Functions

static QLLMatchGetME (std::string name="")
 Singleton shared instance getter. More...
 

Protected Member Functions

void _Configure_ (const Config_t &pset)
 

Private Member Functions

 QLLMatch (const std::string)
 Valid ctor hidden (singleton) More...
 
FlashMatch_t PESpectrumMatch (const QCluster_t &pt_v, const Flash_t &flash, const bool init_x0)
 
FlashMatch_t OnePMTMatch (const Flash_t &flash)
 

Private Attributes

QLLMode_t _mode
 Minimizer mode. More...
 
bool _record
 Boolean switch to record minimizer history. More...
 
double _normalize
 Noramalize hypothesis PE spectrum. More...
 
std::vector< double > _penalty_threshold_v
 
std::vector< double > _penalty_value_v
 
double _pe_hypothesis_threshold
 
double _pe_observation_threshold
 
flashmatch::QCluster_t _raw_trk
 
QPoint_t _raw_xmin_pt
 
QPoint_t _raw_xmax_pt
 
flashmatch::QCluster_t _var_trk
 
flashmatch::Flash_t _hypothesis
 Hypothesis PE distribution over PMTs. More...
 
flashmatch::Flash_t _measurement
 Flash PE distribution over PMTs. More...
 
double _current_chi2
 
double _current_llhd
 
std::vector< double > _minimizer_record_chi2_v
 Minimizer record chi2 value. More...
 
std::vector< double > _minimizer_record_llhd_v
 Minimizer record llhd value. More...
 
std::vector< double > _minimizer_record_x_v
 Minimizer record X values. More...
 
double _reco_x_offset
 reconstructed X offset (from wire-plane to min-x point) More...
 
double _reco_x_offset_err
 reconstructed X offset w/ error More...
 
double _qll
 Minimizer return value. More...
 
bool _converged
 
TMinuit * _minuit_ptr
 
double _migrad_tolerance
 
int _num_steps
 
double _recox_penalty_threshold
 
double _recoz_penalty_threshold
 
double _onepmt_score_threshold
 
double _onepmt_xdiff_threshold
 
double _onepmt_pesum_threshold
 
double _onepmt_pefrac_threshold
 
double _vol_xmax
 
double _vol_xmin
 
std::vector< double > _xpos_v
 
std::vector< double > _ypos_v
 
std::vector< double > _zpos_v
 
float _construct_hypo_time
 Keeps track of the total time spent constructing hypotheses. More...
 

Static Private Attributes

static QLLMatch_me = nullptr
 

Additional Inherited Members

- Protected Attributes inherited from flashmatch::BaseFlashMatch
int _tpc = 0
 The TPC number to use. More...
 
int _cryo = 0
 The Cryostat number to use. More...
 

Detailed Description

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

Definition at line 49 of file QLLMatch.h.

Member Enumeration Documentation

Enumerator
kChi2 
kLLHD 
kSimpleLLHD 

Definition at line 53 of file QLLMatch.h.

Constructor & Destructor Documentation

flashmatch::QLLMatch::QLLMatch ( const std::string  name)
private

Valid ctor hidden (singleton)

Definition at line 15 of file QLLMatch.cxx.

16  : BaseFlashMatch(name), _mode(kChi2), _record(false), _normalize(false), _minuit_ptr(nullptr)
17  { _current_llhd = _current_chi2 = -1.0; }
bool _record
Boolean switch to record minimizer history.
Definition: QLLMatch.h:124
BaseFlashMatch(const std::string name="noname")
Default constructor.
double _normalize
Noramalize hypothesis PE spectrum.
Definition: QLLMatch.h:125
TMinuit * _minuit_ptr
Definition: QLLMatch.h:151
QLLMode_t _mode
Minimizer mode.
Definition: QLLMatch.h:123
const std::string & name() const
Name getter, defined in a logger instance attribute.
Definition: LoggerFeature.h:51
flashmatch::QLLMatch::QLLMatch ( )

Default ctor throws exception (singleton)

Definition at line 19 of file QLLMatch.cxx.

20  { throw OpT0FinderException("Use QLLMatch::GetME() to obtain singleton pointer!"); }
flashmatch::QLLMatch::~QLLMatch ( )
inline

Default destructor.

Definition at line 65 of file QLLMatch.h.

65 {}

Member Function Documentation

void flashmatch::QLLMatch::_Configure_ ( const Config_t pset)
protectedvirtual

Implements flashmatch::BaseAlgorithm.

Definition at line 22 of file QLLMatch.cxx.

22  {
23  _record = pset.get<bool>("RecordHistory");
24  _normalize = pset.get<bool>("NormalizeHypothesis");
25  _mode = (QLLMode_t)(pset.get<unsigned short>("QLLMode"));
26  _pe_observation_threshold = pset.get<double>("PEObservationThreshold", 0.0);
27  _pe_hypothesis_threshold = pset.get<double>("PEHypothesisThreshold", 0.0);
28  _migrad_tolerance = pset.get<double>("MIGRADTolerance", 0.1);
29 
30  this->set_verbosity((msg::Level_t)(pset.get<unsigned int>("Verbosity", 3)));
31 
32  _penalty_threshold_v = pset.get<std::vector<double> >("PEPenaltyThreshold");
33  _penalty_value_v = pset.get<std::vector<double> >("PEPenaltyValue");
34 
35  _recox_penalty_threshold = pset.get<double>("XPenaltyThreshold");
36  _recoz_penalty_threshold = pset.get<double>("ZPenaltyThreshold");
37 
38  _onepmt_score_threshold = pset.get<double>("OnePMTScoreThreshold");
39  _onepmt_xdiff_threshold = pset.get<double>("OnePMTXDiffThreshold");
40  _onepmt_pesum_threshold = pset.get<double>("OnePMTPESumThreshold");
41  _onepmt_pefrac_threshold = pset.get<double>("OnePMTPEFracThreshold");
42 
43  _xpos_v.resize(DetectorSpecs::GetME().NOpDets(),0.);
44  _ypos_v.resize(DetectorSpecs::GetME().NOpDets(),0.);
45  _zpos_v.resize(DetectorSpecs::GetME().NOpDets(),0.);
46  for(size_t ch=0; ch<DetectorSpecs::GetME().NOpDets(); ++ch) {
47  auto const& pmt_pos = DetectorSpecs::GetME().PMTPosition(ch);
48  _xpos_v[ch] = pmt_pos[0];
49  _ypos_v[ch] = pmt_pos[1];
50  _zpos_v[ch] = pmt_pos[2];
51  }
52  if(_tpc == -1 || _cryo == -1) {
53  auto const& bbox = DetectorSpecs::GetME().ActiveVolume();
54  _vol_xmax = bbox.Max()[0];
55  _vol_xmin = bbox.Min()[0];
56  } else {
57  auto const& bbox = DetectorSpecs::GetME().ActiveVolume(_tpc, _cryo);
58  _vol_xmax = bbox.Max()[0];
59  _vol_xmin = bbox.Min()[0];
60  }
61 
62  }
void set_verbosity(::flashmatch::msg::Level_t level)
Verbosity level.
Definition: LoggerFeature.h:47
const geoalgo::AABox & ActiveVolume() const
Detector active volume.
Definition: FMWKInterface.h:54
bool _record
Boolean switch to record minimizer history.
Definition: QLLMatch.h:124
size_t NOpDets() const
of PMTs
Definition: FMWKInterface.h:60
double _pe_hypothesis_threshold
Definition: QLLMatch.h:129
std::vector< double > _zpos_v
Definition: QLLMatch.h:164
std::vector< double > _xpos_v
Definition: QLLMatch.h:164
double _normalize
Noramalize hypothesis PE spectrum.
Definition: QLLMatch.h:125
std::vector< double > _penalty_value_v
Definition: QLLMatch.h:128
int _cryo
The Cryostat number to use.
static DetectorSpecs & GetME(std::string filename="detector_specs.cfg")
Definition: FMWKInterface.h:44
double _onepmt_pefrac_threshold
Definition: QLLMatch.h:161
std::vector< double > _ypos_v
Definition: QLLMatch.h:164
double _onepmt_pesum_threshold
Definition: QLLMatch.h:160
double _recox_penalty_threshold
Definition: QLLMatch.h:155
int _tpc
The TPC number to use.
Level_t
Verbosity message level.
const geoalgo::Point_t & PMTPosition(size_t opch)
PMT XYZ position filler.
Definition: FMWKInterface.h:51
double _onepmt_score_threshold
Definition: QLLMatch.h:158
double _migrad_tolerance
Definition: QLLMatch.h:152
std::vector< double > _penalty_threshold_v
Definition: QLLMatch.h:127
double _recoz_penalty_threshold
Definition: QLLMatch.h:156
QLLMode_t _mode
Minimizer mode.
Definition: QLLMatch.h:123
double _pe_observation_threshold
Definition: QLLMatch.h:130
double _onepmt_xdiff_threshold
Definition: QLLMatch.h:159
double flashmatch::QLLMatch::CallMinuit ( const QCluster_t tpc,
const Flash_t pmt,
const bool  init_x0 = true 
)

Definition at line 409 of file QLLMatch.cxx.

409  {
410 
411  if (_measurement.pe_v.empty()) {
413  }
414  if (_measurement.pe_v.size() != pmt.pe_v.size()) {
415  std::cout << _measurement.pe_v.size() << " " << pmt.pe_v.size() << std::endl;
416  throw OpT0FinderException("PMT dimension has changed!");
417  }
418 
419  if (!_penalty_threshold_v.empty() && _penalty_threshold_v.size() != pmt.pe_v.size()) {
420  throw OpT0FinderException("Penalty threshold array has a different size than PMT array size!");
421  }
422 
423  if (!_penalty_value_v.empty() && _penalty_value_v.size() != pmt.pe_v.size()) {
424  throw OpT0FinderException("Penalty value array has a different size than PMT array size!");
425  }
426 
427  _converged = false;
428 
429  //
430  // Prepare PMT
431  //
432  double max_pe = 1.;
433 
434  // Debug: Print out expected PE spectrum
435  //for(size_t i=0; i<pmt.pe_v.size(); ++i) {
436  //std::cout << "PE meas: " << i << " " << pmt.pe_v[i] << std::endl;
437  //}
438 
439  if (_normalize) {
440  max_pe = 0;
441  for (auto const &v : pmt.pe_v) if (v > max_pe) max_pe = v;
442  }
443 
444  for (size_t i = 0; i < pmt.pe_v.size(); ++i) _measurement.pe_v[i] = pmt.pe_v[i] / max_pe;
445 
446  _minimizer_record_chi2_v.clear();
447  _minimizer_record_llhd_v.clear();
448  _minimizer_record_x_v.clear();
449  _num_steps = 0;
450 
451  if (!_minuit_ptr) _minuit_ptr = new TMinuit(4);
452 
453  double reco_x = _vol_xmin + 10;
454  if (!init_x0) {
455  //reco_x = ((_vol_xmax - _vol_xmin) - (_raw_xmax_pt.x - _raw_xmin_pt.x)) / 2. + _vol_xmin;
456  // Assume this is the right flash... then
457  reco_x = _raw_xmin_pt.x - pmt.time * DetectorSpecs::GetME().DriftVelocity();
458  if(reco_x < _vol_xmin || (reco_x + _raw_xmax_pt.x - _raw_xmin_pt.x) > _vol_xmax)
459  return kINVALID_DOUBLE;
460  }
461  double reco_x_err = ((_vol_xmax - _vol_xmin) - (_raw_xmax_pt.x - _raw_xmin_pt.x)) / 2.;
462  double xmin = _vol_xmin;
463  double xmax = (_vol_xmax - _vol_xmin) - (_raw_xmax_pt.x - _raw_xmin_pt.x) + _vol_xmin;
464 
465  FLASH_INFO() << "Running Minuit x: " << xmin << " => " << xmax
466  << " ... initial state x=" <<reco_x <<" x_err=" << reco_x_err << std::endl;
467  double MinFval;
468  int ierrflag, npari, nparx, istat;
469  double arglist[4], Fmin, Fedm, Errdef;
470  ierrflag = npari = nparx = istat = 0;
471 
472  assert(this == QLLMatch::GetME());
473 
474  _minuit_ptr->SetPrintLevel(-1);
475  arglist[0] = 2.0; // set strategy level
476  _minuit_ptr->mnexcm("SET STR", arglist, 1, ierrflag);
477 
478  _minuit_ptr->SetFCN(MIN_vtx_qll);
479 
480  _minuit_ptr->DefineParameter(0, "X", reco_x, reco_x_err, xmin, xmax);
481 
482  _minuit_ptr->Command("SET NOW");
483 
484  // use Migrad minimizer
485 
486  arglist[0] = 5000; // maxcalls
487  arglist[1] = _migrad_tolerance; // tolerance*1e-3 = convergence condition
488  _minuit_ptr->mnexcm("MIGRAD", arglist, 2, ierrflag);
489 
490  _converged = true;
491 
492  //arglist[0] = 5.0e+2;
493  //arglist[1] = 1.0e-6;
494  //_minuit_ptr->mnexcm ("simplex",arglist,2,ierrflag);
495 
496  _minuit_ptr->GetParameter(0, reco_x, reco_x_err);
497 
498  _minuit_ptr->mnstat(Fmin, Fedm, Errdef, npari, nparx, istat);
499 
500  // use this for debugging, maybe uncomment the actual minimzing function (MIGRAD / simplex calls)
501  // scanning the parameter set
502  //arglist[0] = 0; // Parameter No (in our case x is the only and therefore the 0th parameter)
503  //arglist[1] = 500; // Number of points
504  //arglist[2] = 0; // Start point of scan
505  //arglist[3] = 256; // End point of scan
506  //_minuit_ptr->mnexcm("scan", arglist,4, ierrflag);
507 
508  MinFval = Fmin;
509  double *grad = 0;
510  int nPar = 1;
511  double fValue[1];
512  fValue[0] = reco_x;
513  // Transfer the minimization variables:
514  MIN_vtx_qll(nPar, grad, Fmin, fValue, ierrflag);
515 
516  //static bool show = true;
517  /*
518  if(show){
519  if(Fmin!=MinFval)std::cout<<"Fmin "<<Fmin<<" not equall to "<<MinFval<<std::endl;
520  show=false;
521  }
522  */
523 
524  // Transfer the minimization variables:
525  _reco_x_offset = reco_x;
526  _reco_x_offset_err = reco_x_err;
527  _qll = MinFval;
528 
529  // Clear:
530  _minuit_ptr->mnexcm("clear", arglist, 0, ierrflag);
531 
532  if (_minuit_ptr) delete _minuit_ptr;
533  _minuit_ptr = 0;
534 
535  return _qll;
536  }
QPoint_t _raw_xmin_pt
Definition: QLLMatch.h:133
std::vector< double > _minimizer_record_x_v
Minimizer record X values.
Definition: QLLMatch.h:143
void MIN_vtx_qll(Int_t &, Double_t *, Double_t &, Double_t *, Int_t)
Definition: QLLMatch.cxx:377
const double kINVALID_DOUBLE
Utility: invalid value for double.
double _normalize
Noramalize hypothesis PE spectrum.
Definition: QLLMatch.h:125
#define FLASH_INFO()
Compiler macro for INFO message.
std::vector< double > _penalty_value_v
Definition: QLLMatch.h:128
flashmatch::Flash_t _measurement
Flash PE distribution over PMTs.
Definition: QLLMatch.h:137
static DetectorSpecs & GetME(std::string filename="detector_specs.cfg")
Definition: FMWKInterface.h:44
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
double _reco_x_offset
reconstructed X offset (from wire-plane to min-x point)
Definition: QLLMatch.h:145
std::vector< double > pe_v
PE distribution over photo-detectors.
TMinuit * _minuit_ptr
Definition: QLLMatch.h:151
std::vector< double > _minimizer_record_chi2_v
Minimizer record chi2 value.
Definition: QLLMatch.h:141
double _reco_x_offset_err
reconstructed X offset w/ error
Definition: QLLMatch.h:146
QPoint_t _raw_xmax_pt
Definition: QLLMatch.h:134
static QLLMatch * GetME(std::string name="")
Singleton shared instance getter.
Definition: QLLMatch.h:68
std::vector< double > _minimizer_record_llhd_v
Minimizer record llhd value.
Definition: QLLMatch.h:142
double _migrad_tolerance
Definition: QLLMatch.h:152
std::vector< double > _penalty_threshold_v
Definition: QLLMatch.h:127
double DriftVelocity() const
Drift velocity.
Definition: FMWKInterface.h:63
double _qll
Minimizer return value.
Definition: QLLMatch.h:147
BEGIN_PROLOG could also be cout
const Flash_t & flashmatch::QLLMatch::ChargeHypothesis ( const double  xoffset)

Definition at line 239 of file QLLMatch.cxx.

239  {
240  auto start = high_resolution_clock::now();
241  if (_hypothesis.pe_v.empty()) _hypothesis.pe_v.resize(DetectorSpecs::GetME().NOpDets(), 0.);
242  if (_hypothesis.pe_v.size() != DetectorSpecs::GetME().NOpDets()) {
243  throw OpT0FinderException("Hypothesis vector length != PMT count");
244  }
245 
246  for (auto &v : _hypothesis.pe_v) v = 0;
247 
248  // Apply xoffset
249  _var_trk.resize(_raw_trk.size());
250  for (size_t pt_index = 0; pt_index < _raw_trk.size(); ++pt_index) {
251  //std::cout << "x point : " << _raw_trk[pt_index].x << "\t offset : " << xoffset << std::endl;
252  _var_trk[pt_index].x = _raw_trk[pt_index].x + xoffset;
253  _var_trk[pt_index].y = _raw_trk[pt_index].y;
254  _var_trk[pt_index].z = _raw_trk[pt_index].z;
255  _var_trk[pt_index].q = _raw_trk[pt_index].q;
256  if (_raw_trk[pt_index].q > 1e20) std::cout << "[QLLMatch::ChargeHypothesis] n_original_photons " << _raw_trk[pt_index].q << std::endl;
257  }
258  //auto end = high_resolution_clock::now();
259  //auto duration = duration_cast<microseconds>(end - start);
260  //std::cout << "Duration ChargeHypothesis 1 = " << duration.count() << "us" << std::endl;
261 
262 
263  //start = high_resolution_clock::now();
264  // for ( size_t ipt = 0; ipt < trk.size(); ++ipt) {
265  // double n_original_photons = pt.q;
266  // if (n_original_photons > 1e20) std::cout << "n_original_photons " << n_original_photons << std::endl;
267  // }
269  // std::cout << "hypo pe: ";
270  // for (auto &v : _hypothesis.pe_v) std::cout << v << " ";
271  // std::cout << std::endl;;
272  //end = high_resolution_clock::now();
273  //duration = duration_cast<microseconds>(end - start);
274  //std::cout << "Duration ChargeHypothesis 2 = " << duration.count() << "us" << std::endl;
275 
276  //start = high_resolution_clock::now();
277  if (_normalize) {
278  double qsum = std::accumulate(std::begin(_hypothesis.pe_v),
280  0.0);
281  for (auto &v : _hypothesis.pe_v) v /= qsum;
282  }
284  auto duration = duration_cast<nanoseconds>(end - start);
285  _construct_hypo_time += duration.count();
286  //std::cout << "Duration ChargeHypothesis 3 = " << duration.count() << "us" << std::endl;
287 
288  return _hypothesis;
289  }
size_t NOpDets() const
of PMTs
Definition: FMWKInterface.h:60
flashmatch::Flash_t _hypothesis
Hypothesis PE distribution over PMTs.
Definition: QLLMatch.h:136
double _normalize
Noramalize hypothesis PE spectrum.
Definition: QLLMatch.h:125
static DetectorSpecs & GetME(std::string filename="detector_specs.cfg")
Definition: FMWKInterface.h:44
flashmatch::QCluster_t _raw_trk
Definition: QLLMatch.h:132
std::vector< double > pe_v
PE distribution over photo-detectors.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
float _construct_hypo_time
Keeps track of the total time spent constructing hypotheses.
Definition: QLLMatch.h:166
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
flashmatch::QCluster_t _var_trk
Definition: QLLMatch.h:135
void FillEstimate(const QCluster_t &, Flash_t &) const
Method to simply fill provided reference of flashmatch::Flash_t.
BEGIN_PROLOG could also be cout
nanosecond nanoseconds
Alias for common language habits.
Definition: spacetime.h:139
static QLLMatch* flashmatch::QLLMatch::GetME ( std::string  name = "")
inlinestatic

Singleton shared instance getter.

Definition at line 68 of file QLLMatch.h.

69  {
70  if(!_me) _me = new QLLMatch(name);
71  else if(!name.empty() && name != _me->AlgorithmName()) {
72  std::cerr << "QLLMatch instance must be uniquely named. Requested: "
73  << name << " vs. Existing: " << _me->AlgorithmName() << std::endl;
74  throw std::exception();
75  }
76  return _me;
77  }
BEGIN_PROLOG could also be cerr
const std::string & AlgorithmName() const
Algorithm name.
static QLLMatch * _me
Definition: QLLMatch.h:121
QLLMatch()
Default ctor throws exception (singleton)
Definition: QLLMatch.cxx:19
const std::string & name() const
Name getter, defined in a logger instance attribute.
Definition: LoggerFeature.h:51
const std::vector<double>& flashmatch::QLLMatch::HistoryChi2 ( ) const
inline

Definition at line 106 of file QLLMatch.h.

106 { return _minimizer_record_chi2_v; }
std::vector< double > _minimizer_record_chi2_v
Minimizer record chi2 value.
Definition: QLLMatch.h:141
const std::vector<double>& flashmatch::QLLMatch::HistoryLLHD ( ) const
inline

Definition at line 105 of file QLLMatch.h.

105 { return _minimizer_record_llhd_v; }
std::vector< double > _minimizer_record_llhd_v
Minimizer record llhd value.
Definition: QLLMatch.h:142
const std::vector<double>& flashmatch::QLLMatch::HistoryX ( ) const
inline

Definition at line 107 of file QLLMatch.h.

107 { return _minimizer_record_x_v; }
std::vector< double > _minimizer_record_x_v
Minimizer record X values.
Definition: QLLMatch.h:143
FlashMatch_t flashmatch::QLLMatch::Match ( const QCluster_t pt_v,
const Flash_t flash 
)
virtual

Core function: execute matching.

Implements flashmatch::BaseFlashMatch.

Definition at line 74 of file QLLMatch.cxx.

74  {
75 
77 
78  //
79  // Prepare TPC
80  //
81  _raw_trk.resize(pt_v.size());
82  double min_x = 1e20;
83  double max_x = -1e20;
84  for (size_t i = 0; i < pt_v.size(); ++i) {
85  auto const &pt = pt_v[i];
86  _raw_trk[i] = pt;
87  if (pt.x < min_x) { min_x = pt.x; _raw_xmin_pt = pt; }
88  if (pt.x > max_x) { max_x = pt.x; _raw_xmax_pt = pt; }
89  }
90  for (auto &pt : _raw_trk) pt.x -= min_x;
91 
92  auto res1 = PESpectrumMatch(pt_v,flash,true);
93  auto res2 = PESpectrumMatch(pt_v,flash,false);
94  FLASH_INFO() << "Using mid-x-init ... maximized 1/param Score=" << res1.score << " @ X=" << res1.tpc_point.x << " [cm]" << std::endl;
95  FLASH_INFO() << "Without mid-x-init ... maximized 1/param Score=" << res2.score << " @ X=" << res2.tpc_point.x << " [cm]" << std::endl;
96 
97  auto res = (res1.score > res2.score ? res1 : res2);
98  /*
99  if(res.score < _onepmt_score_threshold) {
100 
101  FLASH_INFO() << "Resulting score below OnePMTScoreThreshold... calling OnePMTMatch" << std::endl;
102  auto res_onepmt = OnePMTMatch(flash);
103 
104  if(res_onepmt.score >= 0.)
105  return res_onepmt;
106  }
107  */
108  FLASH_INFO() << "Time spent constructing hypotheses: " << _construct_hypo_time << " ns." << std::endl;
109  return res;
110  }
QPoint_t _raw_xmin_pt
Definition: QLLMatch.h:133
#define FLASH_INFO()
Compiler macro for INFO message.
FlashMatch_t PESpectrumMatch(const QCluster_t &pt_v, const Flash_t &flash, const bool init_x0)
Definition: QLLMatch.cxx:180
flashmatch::QCluster_t _raw_trk
Definition: QLLMatch.h:132
float _construct_hypo_time
Keeps track of the total time spent constructing hypotheses.
Definition: QLLMatch.h:166
QPoint_t _raw_xmax_pt
Definition: QLLMatch.h:134
const Flash_t & flashmatch::QLLMatch::Measurement ( ) const

Definition at line 291 of file QLLMatch.cxx.

291 { return _measurement; }
flashmatch::Flash_t _measurement
Flash PE distribution over PMTs.
Definition: QLLMatch.h:137
FlashMatch_t flashmatch::QLLMatch::OnePMTMatch ( const Flash_t flash)
private

Definition at line 112 of file QLLMatch.cxx.

112  {
113 
114  FlashMatch_t res;
115  res.score=-1;
116  res.num_steps = 1;
117  // Check if pesum threshold condition is met to use this method
118  double pesum = flash.TotalPE();
119  if(pesum < _onepmt_pesum_threshold) {
120  //std::cout <<"PESumThreshold not met (pesum=" << pesum << ")" << std::endl;
121  return res;
122  }
123 
124  // Check if pe max fraction condition is met to use this method
125  size_t maxpmt = 0;
126  double maxpe = 0.;
127  for(size_t pmt=0; pmt<flash.pe_v.size(); ++pmt) {
128  if(flash.pe_v[pmt] < maxpe) continue;
129  maxpe = flash.pe_v[pmt];
130  maxpmt = pmt;
131  }
132  if(maxpe / pesum < _onepmt_pefrac_threshold) {
133  //std::cout << "PERatioThreshold not met (peratio=" << maxpe/pesum << ")" << std::endl;
134  return res;
135  }
136 
137  // Now see if Flash T0 can be consistent with an assumption MinX @ X=0.
138  double xdiff = fabs(_raw_xmin_pt.x - flash.time * DetectorSpecs::GetME().DriftVelocity());
139  if( xdiff > _onepmt_xdiff_threshold ) {
140  //std::cout << "XDiffThreshold not met (xdiff=" << xdiff << ")" << std::endl;
141  return res;
142  }
143 
144  // Reaching this point means it is an acceptable match
145  _reco_x_offset = 0.;
146  _reco_x_offset_err = std::fabs(_xpos_v.at(maxpmt));
147 
148  // Compute hypothesis with MinX @ X=0 assumption.
149  _hypothesis = flash;
150  FillEstimate(_raw_trk,_hypothesis);
151  res.hypothesis = _hypothesis.pe_v;
152 
153  // Compute TPC point
154  res.tpc_point.x = res.tpc_point.y = res.tpc_point.z = 0;
155  double weight = 0;
156  for (size_t pmt_index = 0; pmt_index < DetectorSpecs::GetME().NOpDets(); ++pmt_index) {
157 
158  res.tpc_point.y += _ypos_v.at(pmt_index) * _hypothesis.pe_v[pmt_index];
159  res.tpc_point.z += _zpos_v.at(pmt_index) * _hypothesis.pe_v[pmt_index];
160 
161  weight += _hypothesis.pe_v[pmt_index];
162  }
163 
164  res.tpc_point.y /= weight;
165  res.tpc_point.z /= weight;
166 
167  res.tpc_point.x = _reco_x_offset;
168  res.tpc_point_err.x = _reco_x_offset_err;
169 
170  // Use MinX point YZ distance to the max PMT and X0 diff as weight
171  res.score = 1.;
172  // FIXME For now we do not have time distribution, so ignore this weighting
173  //res.score *= 1. / xdiff;
174  res.score *= 1. / (sqrt(pow(_raw_xmin_pt.y - _ypos_v.at(maxpmt),2) + pow(_raw_xmin_pt.z - _zpos_v.at(maxpmt),2)));
175 
176  return res;
177 
178  }
QPoint_t _raw_xmin_pt
Definition: QLLMatch.h:133
size_t NOpDets() const
of PMTs
Definition: FMWKInterface.h:60
std::vector< double > _zpos_v
Definition: QLLMatch.h:164
std::vector< double > _xpos_v
Definition: QLLMatch.h:164
double z
Spatial position in [cm].
flashmatch::Flash_t _hypothesis
Hypothesis PE distribution over PMTs.
Definition: QLLMatch.h:136
static DetectorSpecs & GetME(std::string filename="detector_specs.cfg")
Definition: FMWKInterface.h:44
flashmatch::QCluster_t _raw_trk
Definition: QLLMatch.h:132
double _onepmt_pefrac_threshold
Definition: QLLMatch.h:161
double _reco_x_offset
reconstructed X offset (from wire-plane to min-x point)
Definition: QLLMatch.h:145
std::vector< double > _ypos_v
Definition: QLLMatch.h:164
double _reco_x_offset_err
reconstructed X offset w/ error
Definition: QLLMatch.h:146
double _onepmt_pesum_threshold
Definition: QLLMatch.h:160
void FillEstimate(const QCluster_t &, Flash_t &) const
Method to simply fill provided reference of flashmatch::Flash_t.
double DriftVelocity() const
Drift velocity.
Definition: FMWKInterface.h:63
double _onepmt_xdiff_threshold
Definition: QLLMatch.h:159
void flashmatch::QLLMatch::OneStep ( )
inline

Definition at line 97 of file QLLMatch.h.

97  {
98  _num_steps = _num_steps + 1;
99  }
FlashMatch_t flashmatch::QLLMatch::PESpectrumMatch ( const QCluster_t pt_v,
const Flash_t flash,
const bool  init_x0 
)
private

Definition at line 180 of file QLLMatch.cxx.

180  {
181 
182  this->CallMinuit(pt_v, flash, init_x0);
183  // Shit happens line above in CallMinuit
184 
185  // Estimate position
186  FlashMatch_t res;
187  res.num_steps = _num_steps;
188  if (std::isnan(_qll) || std::isinf(_qll)) {
189  return res;
190  }
191 
192  res.tpc_point.x = res.tpc_point.y = res.tpc_point.z = 0;
193 
194  double weight = 0;
195 
196  for (size_t pmt_index = 0; pmt_index < DetectorSpecs::GetME().NOpDets(); ++pmt_index) {
197 
198  res.tpc_point.y += _ypos_v.at(pmt_index) * _hypothesis.pe_v[pmt_index];
199  res.tpc_point.z += _zpos_v.at(pmt_index) * _hypothesis.pe_v[pmt_index];
200 
201  weight += _hypothesis.pe_v[pmt_index];
202  }
203 
204  res.tpc_point.y /= weight;
205  res.tpc_point.z /= weight;
206 
207  res.tpc_point.x = _reco_x_offset;
208  res.tpc_point_err.x = _reco_x_offset_err;
209 
210  res.hypothesis = _hypothesis.pe_v;
211 
212  //
213  // Compute score
214  //
215  if(_mode == kSimpleLLHD)
216  res.score = _qll * -1.;
217  else
218  res.score = 1. / _qll;
219 
220  // Compute X-weighting
221  /*
222  double x0 = _raw_xmin_pt.x - flash.time * DetectorSpecs::GetME().DriftVelocity();
223  if( fabs(_reco_x_offset - x0) > _recox_penalty_threshold )
224  res.score *= 1. / (1. + fabs(_reco_x_offset - x0) - _recox_penalty_threshold);
225  // Compute Z-weighting
226  double z0 = 0;
227  weight = 0;
228  for (size_t pmt_index = 0; pmt_index < DetectorSpecs::GetME().NOpDets(); ++pmt_index) {
229  z0 += _zpos_v.at(pmt_index) * flash.pe_v[pmt_index];
230  weight += flash.pe_v[pmt_index];
231  }
232  z0 /= weight;
233  if( fabs(res.tpc_point.z - z0) > _recoz_penalty_threshold )
234  res.score *= 1. / (1. + fabs(res.tpc_point.z - z0) - _recoz_penalty_threshold);
235  */
236  return res;
237  }
double CallMinuit(const QCluster_t &tpc, const Flash_t &pmt, const bool init_x0=true)
Definition: QLLMatch.cxx:409
size_t NOpDets() const
of PMTs
Definition: FMWKInterface.h:60
std::vector< double > _zpos_v
Definition: QLLMatch.h:164
flashmatch::Flash_t _hypothesis
Hypothesis PE distribution over PMTs.
Definition: QLLMatch.h:136
static DetectorSpecs & GetME(std::string filename="detector_specs.cfg")
Definition: FMWKInterface.h:44
double _reco_x_offset
reconstructed X offset (from wire-plane to min-x point)
Definition: QLLMatch.h:145
std::vector< double > pe_v
PE distribution over photo-detectors.
std::vector< double > _ypos_v
Definition: QLLMatch.h:164
double _reco_x_offset_err
reconstructed X offset w/ error
Definition: QLLMatch.h:146
QLLMode_t _mode
Minimizer mode.
Definition: QLLMatch.h:123
double _qll
Minimizer return value.
Definition: QLLMatch.h:147
double flashmatch::QLLMatch::QLL ( const flashmatch::Flash_t hypothesis,
const flashmatch::Flash_t measurement 
)

Definition at line 293 of file QLLMatch.cxx.

294  {
295 
296  // std::cout << "[QLLMatch] _mode " << _mode << std::endl;
297 
298  double nvalid_pmt = 0;
299 
300  double PEtot_Hyp = 0;
301  for (auto const &pe : hypothesis.pe_v)
302  PEtot_Hyp += pe;
303  double PEtot_Obs = 0;
304  for (auto const &pe : measurement.pe_v)
305  PEtot_Obs += pe;
306 
308 
309  if (measurement.pe_v.size() != hypothesis.pe_v.size())
310  throw OpT0FinderException("Cannot compute QLL for unmatched length!");
311 
312  double O, H, Error;
313 
314  for (size_t pmt_index = 0; pmt_index < hypothesis.pe_v.size(); ++pmt_index) {
315 
316  O = measurement.pe_v[pmt_index]; // observation
317  H = hypothesis.pe_v[pmt_index]; // hypothesis
318 
319  if( H < 0 ) throw OpT0FinderException("Cannot have hypothesis value < 0!");
320 
321  if(O < 0) {
322  if (!_penalty_value_v.empty()) {
323  O = _penalty_value_v[pmt_index];
324  }
325  else {
327  }
328  }
329  if (H <= _pe_hypothesis_threshold) {
330  if(!_penalty_threshold_v.empty()) {
331  H = _penalty_threshold_v[pmt_index];
332  }
333  else {
335  }
336  }
337 
338  if(_mode == kLLHD) {
339 
340  double arg = TMath::Poisson(O,H);
341  // std::cout << "[QLLMatch] pmt_index " << pmt_index << " - O: " << O << ", H: " << H << ", arg: " << arg << std::endl;
342  if(arg > 0. && !std::isnan(arg) && !std::isinf(arg)) {
343  _current_llhd -= std::log10(arg);
344  nvalid_pmt += 1;
345  if(_converged) FLASH_INFO() <<"PMT "<<pmt_index<<" O/H " << O << " / " << H << " LHD "<<arg << " -LLHD " << -1 * std::log10(arg) << std::endl;
346  }
347  } else if (_mode == kSimpleLLHD) {
348 
349  double arg = (H - O * std::log(H));
350  _current_llhd += arg;
351  if(_converged) FLASH_INFO() <<"PMT "<<pmt_index<<" O/H " << O << " / " << H << " ... -LLHD " << arg << std::endl;
352  //nvalid_pmt += 1;
353 
354  } else if (_mode == kChi2) {
355 
356  Error = O;
357  if( Error < 1.0 ) Error = 1.0;
358  _current_chi2 += std::pow((O - H), 2) / (Error);
359  nvalid_pmt += 1;
360 
361  } else {
362  FLASH_ERROR() << "Unexpected mode" << std::endl;
363  throw OpT0FinderException();
364  }
365 
366  }
367  //FLASH_DEBUG() <<"Mode " << (int)(_mode) << " Chi2 " << _current_chi2 << " LLHD " << _current_llhd << " nvalid " << nvalid_pmt << std::endl;
368 
369  _current_chi2 /= nvalid_pmt;
370  _current_llhd /= (nvalid_pmt +1);
371  if(_converged)
372  FLASH_INFO() << "Combined LLHD: " << _current_llhd << " (divided by nvalid_pmt+1 = " << nvalid_pmt+1<<")"<<std::endl;
373 
374  return (_mode == kChi2 ? _current_chi2 : _current_llhd);
375  }
double _pe_hypothesis_threshold
Definition: QLLMatch.h:129
#define FLASH_INFO()
Compiler macro for INFO message.
std::vector< double > _penalty_value_v
Definition: QLLMatch.h:128
std::vector< double > pe_v
PE distribution over photo-detectors.
#define FLASH_ERROR()
Compiler macro for ERROR message.
std::vector< double > _penalty_threshold_v
Definition: QLLMatch.h:127
QLLMode_t _mode
Minimizer mode.
Definition: QLLMatch.h:123
double _pe_observation_threshold
Definition: QLLMatch.h:130
void flashmatch::QLLMatch::Record ( const double  x)
inline

Definition at line 88 of file QLLMatch.h.

89  {
90  if(_record) {
93  _minimizer_record_x_v.push_back(x);
94  }
95  }
std::vector< double > _minimizer_record_x_v
Minimizer record X values.
Definition: QLLMatch.h:143
bool _record
Boolean switch to record minimizer history.
Definition: QLLMatch.h:124
process_name opflash particleana ie x
std::vector< double > _minimizer_record_chi2_v
Minimizer record chi2 value.
Definition: QLLMatch.h:141
std::vector< double > _minimizer_record_llhd_v
Minimizer record llhd value.
Definition: QLLMatch.h:142
void flashmatch::QLLMatch::SetTPCCryo ( int  tpc,
int  cryo 
)
virtual

Sets the TPC and Cryo numbers.

Implements flashmatch::BaseFlashMatch.

Definition at line 64 of file QLLMatch.cxx.

64  {
65  _tpc = tpc;
66  _cryo = cryo;
67 
68  auto const& bbox = DetectorSpecs::GetME().ActiveVolume(_tpc, _cryo);
69  _vol_xmax = bbox.Max()[0];
70  _vol_xmin = bbox.Min()[0];
71  }
const geoalgo::AABox & ActiveVolume() const
Detector active volume.
Definition: FMWKInterface.h:54
int _cryo
The Cryostat number to use.
static DetectorSpecs & GetME(std::string filename="detector_specs.cfg")
Definition: FMWKInterface.h:44
int _tpc
The TPC number to use.

Member Data Documentation

float flashmatch::QLLMatch::_construct_hypo_time
private

Keeps track of the total time spent constructing hypotheses.

Definition at line 166 of file QLLMatch.h.

bool flashmatch::QLLMatch::_converged
private

Definition at line 149 of file QLLMatch.h.

double flashmatch::QLLMatch::_current_chi2
private

Definition at line 139 of file QLLMatch.h.

double flashmatch::QLLMatch::_current_llhd
private

Definition at line 140 of file QLLMatch.h.

flashmatch::Flash_t flashmatch::QLLMatch::_hypothesis
private

Hypothesis PE distribution over PMTs.

Definition at line 136 of file QLLMatch.h.

QLLMatch * flashmatch::QLLMatch::_me = nullptr
staticprivate

Definition at line 121 of file QLLMatch.h.

flashmatch::Flash_t flashmatch::QLLMatch::_measurement
private

Flash PE distribution over PMTs.

Definition at line 137 of file QLLMatch.h.

double flashmatch::QLLMatch::_migrad_tolerance
private

Definition at line 152 of file QLLMatch.h.

std::vector<double> flashmatch::QLLMatch::_minimizer_record_chi2_v
private

Minimizer record chi2 value.

Definition at line 141 of file QLLMatch.h.

std::vector<double> flashmatch::QLLMatch::_minimizer_record_llhd_v
private

Minimizer record llhd value.

Definition at line 142 of file QLLMatch.h.

std::vector<double> flashmatch::QLLMatch::_minimizer_record_x_v
private

Minimizer record X values.

Definition at line 143 of file QLLMatch.h.

TMinuit* flashmatch::QLLMatch::_minuit_ptr
private

Definition at line 151 of file QLLMatch.h.

QLLMode_t flashmatch::QLLMatch::_mode
private

Minimizer mode.

Definition at line 123 of file QLLMatch.h.

double flashmatch::QLLMatch::_normalize
private

Noramalize hypothesis PE spectrum.

Definition at line 125 of file QLLMatch.h.

int flashmatch::QLLMatch::_num_steps
private

Definition at line 153 of file QLLMatch.h.

double flashmatch::QLLMatch::_onepmt_pefrac_threshold
private

Definition at line 161 of file QLLMatch.h.

double flashmatch::QLLMatch::_onepmt_pesum_threshold
private

Definition at line 160 of file QLLMatch.h.

double flashmatch::QLLMatch::_onepmt_score_threshold
private

Definition at line 158 of file QLLMatch.h.

double flashmatch::QLLMatch::_onepmt_xdiff_threshold
private

Definition at line 159 of file QLLMatch.h.

double flashmatch::QLLMatch::_pe_hypothesis_threshold
private

Definition at line 129 of file QLLMatch.h.

double flashmatch::QLLMatch::_pe_observation_threshold
private

Definition at line 130 of file QLLMatch.h.

std::vector<double> flashmatch::QLLMatch::_penalty_threshold_v
private

Definition at line 127 of file QLLMatch.h.

std::vector<double> flashmatch::QLLMatch::_penalty_value_v
private

Definition at line 128 of file QLLMatch.h.

double flashmatch::QLLMatch::_qll
private

Minimizer return value.

Definition at line 147 of file QLLMatch.h.

flashmatch::QCluster_t flashmatch::QLLMatch::_raw_trk
private

Definition at line 132 of file QLLMatch.h.

QPoint_t flashmatch::QLLMatch::_raw_xmax_pt
private

Definition at line 134 of file QLLMatch.h.

QPoint_t flashmatch::QLLMatch::_raw_xmin_pt
private

Definition at line 133 of file QLLMatch.h.

double flashmatch::QLLMatch::_reco_x_offset
private

reconstructed X offset (from wire-plane to min-x point)

Definition at line 145 of file QLLMatch.h.

double flashmatch::QLLMatch::_reco_x_offset_err
private

reconstructed X offset w/ error

Definition at line 146 of file QLLMatch.h.

bool flashmatch::QLLMatch::_record
private

Boolean switch to record minimizer history.

Definition at line 124 of file QLLMatch.h.

double flashmatch::QLLMatch::_recox_penalty_threshold
private

Definition at line 155 of file QLLMatch.h.

double flashmatch::QLLMatch::_recoz_penalty_threshold
private

Definition at line 156 of file QLLMatch.h.

flashmatch::QCluster_t flashmatch::QLLMatch::_var_trk
private

Definition at line 135 of file QLLMatch.h.

double flashmatch::QLLMatch::_vol_xmax
private

Definition at line 163 of file QLLMatch.h.

double flashmatch::QLLMatch::_vol_xmin
private

Definition at line 163 of file QLLMatch.h.

std::vector<double> flashmatch::QLLMatch::_xpos_v
private

Definition at line 164 of file QLLMatch.h.

std::vector<double> flashmatch::QLLMatch::_ypos_v
private

Definition at line 164 of file QLLMatch.h.

std::vector<double> flashmatch::QLLMatch::_zpos_v
private

Definition at line 164 of file QLLMatch.h.


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