71 const double nan = std::numeric_limits<double>::quiet_NaN();
72 const double inf = std::numeric_limits<double>::infinity();
77 check(pid.Identify(11, 5., 0.5) == S::kElectron,
"identity e");
78 check(pid.Identify(-13, 5., 0.5) == S::kMuon,
"identity mu");
79 check(pid.Identify(211, 5., 0.99) == S::kHadron,
"identity pi");
80 check(pid.Identify(22, 5., 0.5) == S::kUnknown,
"photon unknown");
86 check(pid.TrueSpecies(-11) == S::kElectron,
"e+");
87 check(pid.TrueSpecies(13) == S::kMuon,
"mu-");
88 for (
int h : {211, -211, 321, 130, 310, 2212, -2212, 2112, 3122, 111}) {
89 check(pid.TrueSpecies(h) == S::kHadron,
"hadron " + std::to_string(h));
91 for (
int u : {22, 12, -14, 16, 1000010020, 9900015, 0}) {
92 check(pid.TrueSpecies(u) == S::kUnknown,
"unknown " + std::to_string(u));
99 pid.Set({10., 20.}, Concat(Identity(), ElectronAsHadron()));
100 check(close(pid.Probability(S::kElectron, S::kElectron, 15.), 0.5),
102 check(close(pid.Probability(S::kElectron, S::kHadron, 12.5), 0.25),
104 check(close(pid.Probability(S::kElectron, S::kElectron, 1.), 1.0),
106 check(close(pid.Probability(S::kElectron, S::kElectron, 1e4), 0.0),
108 auto m = pid.Matrix(15.);
109 for (
size_t i = 0; i < 3; ++i) {
110 check(close(
m[3 * i] +
m[3 * i + 1] +
m[3 * i + 2], 1.),
111 "interpolated row sums to 1");
114 check(pid.Identify(11, 15., 0.49) == S::kElectron,
"draw below 0.5");
115 check(pid.Identify(11, 15., 0.51) == S::kHadron,
"draw above 0.5");
116 check(pid.Identify(11, 15., 1.0) == S::kHadron,
"u == 1");
117 check(pid.Identify(13, 15., 1.0) == S::kMuon,
"u == 1, diagonal row");
123 pid.Set({10., 20.}, Concat(Identity(), ElectronAsHadron()), {}, kTRUE);
124 check(pid.IsLogInterpolation(),
"log interpolation set");
125 const double e = std::sqrt(10. * 20.);
126 check(close(pid.Probability(S::kElectron, S::kElectron, e), 0.5),
133 pid.Set({1.}, {0.8, 0.2, 0.0, 0.3, 0.6, 0.1, 0.0, 0.0, 1.0});
135 const int n = 200000;
137 for (
int k = 0; k < n; ++k) {
138 const auto s = pid.Identify(211, 3., rng);
139 nE += s == S::kElectron;
140 nMu += s == S::kMuon;
142 check(std::fabs(nE /
static_cast<double>(n) - 0.3) < 0.005,
144 check(std::fabs(nMu /
static_cast<double>(n) - 0.1) < 0.005,
151 TRandom3 used(1), reference(1);
152 for (
int pdg : {11, -13, 211, 22, 12}) perfect.Identify(pdg, 5., used);
153 check(used.Rndm() == reference.Rndm(),
154 "perfect PID and unknown species leave the generator untouched");
157 pid.Set({10., 20.}, Concat(Identity(), ElectronAsHadron()));
159 check(pid.Identify(11, 50., a) == S::kHadron,
"single non-zero entry");
160 check(a.Rndm() == b.Rndm(),
"single non-zero entry draws nothing");
161 pid.Identify(11, 15., a);
163 check(a.Rndm() == b.Rndm(),
"a varying outcome draws exactly once");
169 pid.Set({1.}, Identity(), {{22, S::kElectron}, {-211, S::kUnknown}});
170 check(pid.TrueSpecies(22) == S::kElectron,
"override photon");
171 check(pid.TrueSpecies(211) == S::kUnknown,
"override pi to unknown");
172 check(pid.TrueSpecies(-211) == S::kUnknown,
"override applies to |pdg|");
177 CaloScoringPlanePoint p(0, 1, 1, TVector3(0, 0, 0), TVector3(0, 3, 4), 0.,
179 const double m = 0.1056583755;
180 check(std::fabs(S::Energy(p) - std::sqrt(25. +
m *
m)) < 1e-6,
187 pid.Set({10., 20.}, Concat(Identity(), ElectronAsHadron()));
188 TRandom3 used(3), reference(3);
189 for (
double e : {nan, inf, -inf}) {
190 check(pid.Identify(11, e, 0.5) == S::kUnknown,
"non-finite energy: u");
191 check(pid.Identify(11, e, used) == S::kUnknown,
192 "non-finite energy: generator");
194 check(used.Rndm() == reference.Rndm(),
"non-finite energy draws nothing");
198 }
catch (
const std::invalid_argument&) {
201 check(threw,
"Matrix(NaN) throws");
204 pid.Probability(S::kElectron, S::kElectron, nan);
205 }
catch (
const std::invalid_argument&) {
208 check(threw,
"Probability(NaN) throws");
209 for (
int bad : {3, -2}) {
212 pid.Probability(
static_cast<S::Species
>(bad), S::kMuon, 1.);
213 }
catch (
const std::out_of_range&) {
216 check(threw,
"true species " + std::to_string(bad) +
" throws");
219 pid.Probability(S::kMuon,
static_cast<S::Species
>(bad), 1.);
220 }
catch (
const std::out_of_range&) {
223 check(threw,
"identified species " + std::to_string(bad) +
" throws");
225 check(pid.Probability(S::kUnknown, S::kUnknown, 1.) == 1.,
226 "unknown -> unknown still allowed");
230 expectInvalid([](S& p) { p.Set({}, {}); },
"no energy points");
231 expectInvalid([](S& p) { p.Set({1.}, {1, 0, 0}); },
"too few values");
232 expectInvalid([](S& p) { p.Set({2., 1.}, Concat(Identity(), Identity())); },
233 "decreasing energies");
234 expectInvalid([](S& p) { p.Set({1., 1.}, Concat(Identity(), Identity())); },
236 expectInvalid([](S& p) { p.Set({1.}, {0.5, 0.4, 0, 0, 1, 0, 0, 0, 1}); },
238 expectInvalid([](S& p) { p.Set({1.}, {1.2, -0.2, 0, 0, 1, 0, 0, 0, 1}); },
240 expectInvalid([&](S& p) { p.Set({1.}, {nan, 1, 0, 0, 1, 0, 0, 0, 1}); },
242 expectInvalid([&](S& p) { p.Set({nan}, Identity()); },
"NaN energy");
243 expectInvalid([&](S& p) { p.Set({1., inf}, Concat(Identity(), Identity())); },
245 expectInvalid([](S& p) { p.Set({0.}, Identity(), {}, kTRUE); },
246 "log with zero energy");
247 expectInvalid([](S& p) { p.Set({1.}, Identity(), {{22, 3}}); },
248 "override species out of range");
251 p.Set({1.}, Identity(), {{211, S::kHadron}, {-211, S::kMuon}});
253 "conflicting overrides");
256 std::cerr << failures <<
" check(s) failed" << std::endl;
259 std::cout <<
"CaloScoringPlanePID: all checks passed" << std::endl;