1 #ifndef OPT0FINDER_FLASHMATCHMANAGER_CXX
2 #define OPT0FINDER_FLASHMATCHMANAGER_CXX
17 using namespace std::chrono;
18 namespace flashmatch {
20 FlashMatchManager::FlashMatchManager(
const std::string
name)
22 , _alg_flash_filter(nullptr)
23 , _alg_tpc_filter(nullptr)
24 , _alg_match_prohibit(nullptr)
25 , _alg_flash_match(nullptr)
26 , _alg_flash_hypothesis(nullptr)
86 ss <<
"Duplicate name: " << alg->
AlgorithmName() << std::endl;
105 _store_full = mgr_cfg.get<
bool>(
"StoreFullResult");
107 auto const flash_filter_name = mgr_cfg.get<std::string>(
"FlashFilterAlgo",
"");
108 auto const tpc_filter_name = mgr_cfg.get<std::string>(
"TPCFilterAlgo",
"");
109 auto const prohibit_name = mgr_cfg.get<std::string>(
"ProhibitAlgo",
"");
110 auto const hypothesis_name = mgr_cfg.get<std::string>(
"HypothesisAlgo",
"");
111 auto const match_name = mgr_cfg.get<std::string>(
"MatchAlgo",
"");
112 std::vector<std::string> custom_algo_v;
113 custom_algo_v = mgr_cfg.get<std::vector<std::string> >(
"CustomAlgo",custom_algo_v);
120 for(
auto const&
name : custom_algo_v)
144 FLASH_WARNING() <<
"Algorithm may be not configured yet!" << std::endl;
171 std::stringstream ss;
172 ss <<
"Unsupported algorithm type: " <<
type;
181 FLASH_ERROR() <<
"Algorithm name " << name <<
" not found!" << std::endl;
201 if(!obj.Valid())
throw OpT0FinderException(
"Invalid Flash_t object cannot be registered!");
202 _flash_v.emplace_back(std::move(obj));
217 std::vector<FlashMatch_t> result;
242 for (
size_t i = 0; i <
_tpc_object_v.size(); ++i) tpc_index_v.push_back(i);
251 flash_index_v.reserve(
_flash_v.size());
252 for (
size_t i = 0; i <
_flash_v.size(); ++i) flash_index_v.push_back(i);
254 FLASH_INFO() <<
"Flash Filter: " <<
_flash_v.size() <<
" => " << flash_index_v.size() << std::endl;
261 std::multimap<double, FlashMatch_t> score_map;
265 for (
size_t tpc_index = 0; tpc_index < tpc_index_v.size(); ++tpc_index) {
267 for (
auto const& flash_index : flash_index_v) {
268 FLASH_INFO() <<
"TPC index " << tpc_index <<
", Flash index " << flash_index << std::endl;
270 auto const& flash =
_flash_v[flash_index];
272 if (tpc.size() == 0 )
278 if (compat ==
false) {
279 FLASH_INFO() <<
"Match not compatible. " << std::endl;
287 FLASH_INFO() <<
"Match duration = " << duration.count() <<
"ns" << std::endl;
290 if (res.score <= 0)
continue;
293 res.tpc_id = tpc_index_v[tpc_index];
294 res.flash_id = flash_index;
295 res.duration = duration.count();
303 score_map.emplace( 1. / res.score, res);
306 <<
" TPC=" << tpc_index <<
" (" << tpc.min_x() <<
" min x)" <<
" @ " << tpc.time
307 <<
" with Flash=" << flash_index <<
" @ " << flash.time
308 <<
" ... Score=" << res.score
309 <<
" ... PE=" << flash.TotalPE()
319 std::set<ID_t> tpc_used, flash_used;
320 result.reserve(tpc_index_v.size());
322 for (
auto& score_info : score_map) {
324 auto& match_info = score_info.second;
325 auto const& tpc_index = match_info.tpc_id;
326 auto const& flash_index = match_info.flash_id;
331 if (tpc_used.find(tpc_index) != tpc_used.end())
continue;
334 if (!
_allow_reuse_flash && flash_used.find(flash_index) != flash_used.end())
continue;
337 FLASH_INFO () <<
"Concrete Match: " <<
" TPC=" << tpc_index <<
" Flash=" << flash_index
338 <<
" Score=" << match_info.score
342 tpc_used.insert(tpc_index);
343 flash_used.insert(flash_index);
346 result.emplace_back( match_info );
356 std::cout <<
"---- FLASH MATCH MANAGER PRINTING CONFIG ----" << std::endl
358 <<
"_name = " <<
_name << std::endl
359 <<
"_alg_flash_filter?" << std::endl;
362 std::cout <<
"_alg_tpc_filter?" << std::endl;
365 std::cout <<
"_alg_match_prohibit?" << std::endl;
368 std::cout <<
"_alg_flash_hypothesis?" << std::endl;
371 std::cout <<
"_alg_flash_match?" << std::endl;
374 std::cout <<
"_custom_alg_m?" << std::endl;
376 std::cout <<
"\t" << name_ptr.first << std::endl;
377 std::cout <<
"---- END FLASH MATCH MANAGER PRINTING CONFIG ----" << std::endl;
404 #if USING_LARSOFT == 1
Algorithm type to make QCluster_t => Flash_t hypothesis.
void set_verbosity(::flashmatch::msg::Level_t level)
Verbosity level.
Algorithm_t
Enumerator for different types of algorithm.
BaseTPCFilter * _alg_tpc_filter
TPC filter algorithm.
Algorithm type to match flash hypothesis and reconstructed flash.
BaseFlashFilter * create(const std::string name, const std::string instance_name)
Factory creation method (should be called by clients, possibly you!)
std::vector< flashmatch::FlashMatch_t > Match()
virtual IDArray_t Filter(const QClusterArray_t &)=0
std::vector< std::vector< flashmatch::FlashMatch_t > > _res_flash_tpc_v
Full result container indexed by [flash][tpc].
virtual bool MatchCompatible(const QCluster_t &clus, const Flash_t &flash)=0
CORE FUNCTION: determines if a flash and cluster are at all compatible (bool return) ...
flashmatch::BaseAlgorithm * GetCustomAlgo(std::string name)
Custom algorithm getter.
void SetSemiAnalyticalModel(std::unique_ptr< SemiAnalyticalModel > model)
BaseFlashHypothesis * _alg_flash_hypothesis
Flash hypothesis algorithm.
Class def header for a class TPCFilterFactory.
static FlashMatchFactory & get()
Static sharable instance getter.
#define FLASH_WARNING()
Compiler macro for WARNING message.
const std::string & Name() const
Name getter.
Algorithm type to filter out TPC objects from matching candidate list.
std::map< std::string, flashmatch::BaseAlgorithm * > _custom_alg_m
void SetTPCCryo(int tpc, int _cryo)
Sets the TPC and Cryo numbers.
#define FLASH_INFO()
Compiler macro for INFO message.
Algorithm type to filter out flash from matching candidate list.
fhicl::ParameterSet Config_t
Configuration object.
BaseAlgorithm * create(const std::string name, const std::string instance_name)
Factory creation method (should be called by clients, possibly you!)
void Add(flashmatch::QCluster_t &obj)
Adder of a TPC object.
Struct to represent an optical flash.
void SetChannelMask(std::vector< int >)
Sets the op channels to be used for matching.
BaseFlashFilter * _alg_flash_filter
Flash filter algorithm.
virtual IDArray_t Filter(const FlashArray_t &)=0
Class def header for a class FlashHypothesisFactory.
BaseProhibitAlgo * _alg_match_prohibit
Flash matchinig prohibit algorithm.
BaseFlashHypothesis * create(const std::string name, const std::string instance_name)
Factory creation method (should be called by clients, possibly you!)
void SetUncoatedPMTs(std::vector< int > ch_uncoated)
Sets the channels sensitive to visible light.
const std::string & AlgorithmName() const
Algorithm name.
flashmatch::BaseAlgorithm * GetAlgo(flashmatch::Algorithm_t type)
Algorithm getter.
BaseFlashMatch * create(const std::string name, const std::string instance_name)
Factory creation method (should be called by clients, possibly you!)
Class def header for a class FlashProhibitFactory.
Class def header for a class FlashMatchFactory.
auto end(FixedBins< T, C > const &) noexcept
Collection of charge deposition 3D point (cluster)
virtual void SetTPCCryo(int tpc, int cryo)=0
Sets the TPC and Cryo numbers.
Algorithm type to prohibit a match between a flash and a cluster.
BaseProhibitAlgo * create(const std::string name, const std::string instance_name)
Factory creation method (should be called by clients, possibly you!)
Class def header for a class FlashMatchManager.
static FlashProhibitFactory & get()
Static sharable instance getter.
static FlashFilterFactory & get()
Static sharable instance getter.
Class def header for exception classes in OpT0Finder package.
bool _configured
Configuration readiness flag.
bool _store_full
Request boolean to store full matching result (per Match function call)
std::vector< std::vector< flashmatch::FlashMatch_t > > _res_tpc_flash_v
Full result container indexed by [tpc][flash].
bool _allow_reuse_flash
Configuration option to allow re-use of a flash (i.e. 1 flash can be assigned to multiple TPC object)...
int _tpc
TPC number where to perform the matching.
QClusterArray_t _tpc_object_v
TPC object information collection (provided by a user)
void Configure(const Config_t &pset)
Function to accept configuration.
Level_t
Verbosity message level.
static CustomAlgoFactory & get()
Static sharable instance getter.
Class def header for a class CustomAlgoFactory.
#define FLASH_DEBUG()
Compiler macro for DEBUG message.
void SetFlashHypothesis(flashmatch::BaseFlashHypothesis *)
#define FLASH_ERROR()
Compiler macro for ERROR message.
BaseTPCFilter * create(const std::string name, const std::string instance_name)
Factory creation method (should be called by clients, possibly you!)
void SetUncoatedPMTs(std::vector< int > ch_uncoated)
Sets the channels sensitive to visible light.
std::vector< flashmatch::ID_t > IDArray_t
Index collection.
virtual FlashMatch_t Match(const QCluster_t &, const Flash_t &)=0
FlashArray_t _flash_v
Flash object information collection (provided by a user)
int _cryo
Cryo number where to perform the matching.
void Configure(const Config_t &cfg)
Configuration.
void SetSemiAnalyticalModel(std::unique_ptr< SemiAnalyticalModel > model)
Sets the semi analytical model.
void SetChannelMask(std::vector< int > ch_mask)
Sets the channels to use.
static FlashHypothesisFactory & get()
Static sharable instance getter.
Class def header for a class FlashFilterFactory.
const std::string & name() const
Name getter, defined in a logger instance attribute.
void Emplace(flashmatch::QCluster_t &&obj)
Emplacer of a TPC object (hidden from ROOT5 CINT)
BEGIN_PROLOG could also be cout
nanosecond nanoseconds
Alias for common language habits.
BaseFlashMatch * _alg_flash_match
Flash matching algorithm.
static TPCFilterFactory & get()
Static sharable instance getter.
void AddCustomAlgo(BaseAlgorithm *alg)
bool Valid(size_t nopdet=0) const
Check validity.