File indexing completed on 2026-08-06 09:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 namespace exsample {
0012
0013 template<class Random>
0014 std::pair<bool,bool> sampling_selector<Random>::use(cell& parent,
0015 const cell& first_child,
0016 const cell& second_child) const {
0017 std::pair<bool,bool> selected (false,false);
0018 if (compensate) {
0019 if (first_child.missing_events() > 0 && second_child.missing_events() <= 0) {
0020 selected.first = true;
0021 --parent.missing_events();
0022 return selected;
0023 }
0024 if (first_child.missing_events() <= 0 && second_child.missing_events() > 0) {
0025 selected.second = true;
0026 --parent.missing_events();
0027 return selected;
0028 }
0029 if (first_child.missing_events() > 0 && second_child.missing_events() > 0) {
0030 if (first_child.integral()/parent.integral() > rnd_gen())
0031 selected.first = true;
0032 else
0033 selected.second = true;
0034 --parent.missing_events();
0035 return selected;
0036 }
0037 }
0038 if (first_child.integral()/parent.integral() > rnd_gen())
0039 selected.first = true;
0040 else
0041 selected.second = true;
0042 return selected;
0043 }
0044
0045 template<class Random>
0046 bool sampling_selector<Random>::use(cell& leaf) const {
0047 if (compensate) {
0048 if (leaf.missing_events() < 0) {
0049 ++leaf.missing_events();
0050 return false;
0051 }
0052 if (leaf.missing_events() > 0)
0053 --leaf.missing_events();
0054 }
0055 return true;
0056 }
0057
0058 inline std::pair<bool,bool> parametric_selector::use(const cell& parent,
0059 const cell&,
0060 const cell&) const {
0061 std::pair<bool,bool> match_para (true,true);
0062 if (!sampled_variables_[parent.split_dimension()]) {
0063 match_para.first = (parent.split_point() > (*point_)[parent.split_dimension()]);
0064 match_para.second = (parent.split_point() <= (*point_)[parent.split_dimension()]);
0065 }
0066 return match_para;
0067 }
0068
0069 template<class Random>
0070 std::pair<bool,bool> parametric_sampling_selector<Random>::use(cell& parent,
0071 const cell& first_child,
0072 const cell& second_child) const {
0073 std::pair<bool,bool> match_para (true,true);
0074 std::pair<bool,bool> selected (false,false);
0075 if (!sampled_variables_[parent.split_dimension()]) {
0076 match_para.first = (parent.split_point() > (*point_)[parent.split_dimension()]);
0077 match_para.second = (parent.split_point() <= (*point_)[parent.split_dimension()]);
0078 }
0079 if (match_para.first && match_para.second) {
0080 if (compensate_) {
0081 if (first_child.missing_events() > 0 && second_child.missing_events() <= 0) {
0082 selected.first = true;
0083 --parent.missing_events();
0084 return selected;
0085 }
0086 if (first_child.missing_events() <= 0 && second_child.missing_events() > 0) {
0087 selected.second = true;
0088 --parent.missing_events();
0089 return selected;
0090 }
0091
0092 if (first_child.missing_events() > 0 && second_child.missing_events() > 0) {
0093 if (first_child.integral()/parent.integral() > rnd_gen_())
0094 selected.first = true;
0095 else
0096 selected.second = true;
0097 --parent.missing_events();
0098 return selected;
0099 }
0100 }
0101 if (first_child.integral()/parent.integral() > rnd_gen_())
0102 selected.first = true;
0103 else
0104 selected.second = true;
0105 return selected;
0106 }
0107 assert(match_para.first || match_para.second);
0108 if (compensate_)
0109 if ((match_para.first && first_child.missing_events() > 0) ||
0110 (match_para.second && second_child.missing_events() > 0))
0111 --parent.missing_events();
0112 return match_para;
0113 }
0114
0115 template<class Random>
0116 bool parametric_sampling_selector<Random>::use (cell& leaf) const {
0117 if (compensate_) {
0118 long pmissing = leaf.info().parametric_missing(*bin_id_);
0119 assert(leaf.missing_events() == pmissing);
0120 if (pmissing < 0) {
0121 leaf.info().increase_parametric_missing(*bin_id_);
0122 ++leaf.missing_events();
0123 return false;
0124 }
0125 if (pmissing > 0) {
0126 leaf.info().decrease_parametric_missing(*bin_id_);
0127 --leaf.missing_events();
0128 }
0129 }
0130 return true;
0131 }
0132
0133 }