File indexing completed on 2024-09-27 07:02:58
0001
0002
0003
0004 #pragma once
0005
0006 #include <algorithms/geo.h>
0007
0008 namespace eicrecon {
0009
0010
0011
0012
0013 template <auto MemberFunctionPtr>
0014 class RangeSplit {
0015 public:
0016
0017 RangeSplit(std::vector<std::pair<double,double>> ranges) : m_ranges(ranges) {};
0018
0019 template <typename T>
0020 std::vector<int> operator()(T& instance) const {
0021 std::vector<int> ids;
0022
0023 for(size_t i = 0; i < m_ranges.size(); i++){
0024 if((instance.*MemberFunctionPtr)() > m_ranges[i].first && (instance.*MemberFunctionPtr)() < m_ranges[i].second){
0025 ids.push_back(i);
0026 }
0027 }
0028 return ids;
0029 }
0030
0031 private:
0032 std::vector<std::pair<double,double>> m_ranges;
0033
0034 };
0035
0036
0037
0038
0039 class GeometrySplit {
0040 public:
0041
0042 GeometrySplit(std::vector<std::vector<long int>> ids, std::string readout, std::vector<std::string> divisions)
0043 : m_ids(ids), m_readout(readout), m_divisions(divisions),
0044 is_init(std::make_shared<std::once_flag>()),
0045 m_id_dec(std::make_shared<dd4hep::DDSegmentation::BitFieldCoder*>()),
0046 m_div_ids(std::make_shared<std::vector<size_t>>()) {};
0047
0048 template <typename T>
0049 std::vector<int> operator()(T& instance) const {
0050
0051
0052 std::call_once(*is_init, &GeometrySplit::init, this);
0053
0054
0055 auto cellID = instance.getCellID();
0056 std::vector<long int> det_ids;
0057 for(auto d : *m_div_ids){
0058 det_ids.push_back((*m_id_dec)->get(cellID, d));
0059 }
0060
0061 auto index = std::find(m_ids.begin(),m_ids.end(),det_ids);
0062
0063 std::vector<int> ids;
0064 if(index != m_ids.end()){
0065 ids.push_back(std::distance(m_ids.begin(),index));
0066 }
0067 return ids;
0068 }
0069
0070 private:
0071
0072 void init() const {
0073 *m_id_dec = algorithms::GeoSvc::instance().detector()->readout(m_readout).idSpec().decoder();
0074 for (auto d : m_divisions){
0075 m_div_ids->push_back((*m_id_dec)->index(d));
0076 }
0077 }
0078
0079 std::vector<std::vector<long int>> m_ids;
0080 std::vector<std::string> m_divisions;
0081 std::string m_readout;
0082
0083 std::shared_ptr<std::once_flag> is_init;
0084 std::shared_ptr<dd4hep::DDSegmentation::BitFieldCoder*> m_id_dec;
0085 std::shared_ptr<std::vector<size_t>> m_div_ids;
0086
0087 };
0088
0089
0090
0091
0092
0093 template <auto... MemberFunctionPtrs>
0094 class ValueSplit {
0095 public:
0096
0097 ValueSplit(std::vector<std::vector<int>> ids) : m_ids(ids) {};
0098
0099 template <typename T>
0100 std::vector<int> operator()(T& instance) const {
0101 std::vector<int> ids;
0102
0103 std::vector<int> values;
0104 (values.push_back((instance.*MemberFunctionPtrs)()), ...);
0105 auto index = std::find(m_ids.begin(),m_ids.end(),values);
0106 if(index != m_ids.end()){
0107 ids.push_back(std::distance(m_ids.begin(),index));
0108 }
0109 return ids;
0110 }
0111
0112 private:
0113 std::vector<std::vector<int>> m_ids;
0114
0115 };
0116
0117 }