BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnNdetCuts.h
Go to the documentation of this file.
1#ifndef BMN_NDET_CUTS_H
2#define BMN_NDET_CUTS_H
3
4#include "BmnHgndDigi.h"
5#include "BmnNdetDigi.h"
6#include "BmnNdetDigit.h"
7
8#include <fstream>
9#include <iostream>
10#include <nlohmann/json.hpp>
11
12using json = nlohmann::json;
13
14struct BmnNdetCuts
15{
16
17 // --- internal helper ---
18 struct Range
19 {
20 double min = std::numeric_limits<double>::min(), max = std::numeric_limits<double>::max();
21 bool hasMin = false, hasMax = false;
22 inline bool Pass(double v) const
23 {
24 if (hasMin && v <= min)
25 return false;
26 if (hasMax && v >= max)
27 return false;
28 return true;
29 }
30 };
31
32 // --- physics fields ---
33 Range Time; // fTime
34
35 // --- methods ---
36 inline bool PassSim(const BmnNdetDigit* d) const { return true; }
37
38 inline bool PassPrototype(const BmnNdetDigi* d) const { return true; }
39
40 inline bool PassExp(const BmnHgndDigi* d) const
41 {
42 if (!Time.Pass(d->GetTime()))
43 return false;
44 return true;
45 }
46
47 static BmnNdetCuts Load(const std::string& file, bool isExp)
48 {
49 std::ifstream f(file);
50 if (!f.is_open()) {
51 std::cerr << "[BmnNdetCuts] Cannot open config: " << file << std::endl;
52 return {};
53 }
54
55 json j;
56 try {
57 f >> j;
58 } catch (const std::exception& e) {
59 std::cerr << "[BmnNdetCuts] JSON parse error in " << file << ": " << e.what() << std::endl;
60 return {};
61 }
62
64 const json& sec = isExp ? j["experiment"] : j["simulation"];
65
66 auto readRange = [](Range& r, const json& js, const char* key) {
67 const std::string kmin = std::string(key) + "_min";
68 const std::string kmax = std::string(key) + "_max";
69 if (js.contains(kmin)) {
70 r.min = js[kmin].get<double>();
71 r.hasMin = true;
72 }
73 if (js.contains(kmax)) {
74 r.max = js[kmax].get<double>();
75 r.hasMax = true;
76 }
77 };
78
79 if (isExp) {
80 readRange(c.Time, sec, "fTime");
81 }
82
83 std::cout << "[BmnNdetCuts] Loaded cuts for " << (isExp ? "experiment" : "simulation") << " from " << file
84 << std::endl;
85
86 return c;
87 }
88};
89
90#endif // BMN_NDET_CUTS_H
__m128 v
Definition P4_F32vec4.h:1
Data structure for a single HGND digit.
Definition BmnHgndDigi.h:20
Data class for Bmn Ndet digital signal processing.
Definition BmnNdetDigi.h:24
basic_json<> json
default specialization
Definition json.hpp:3365
bool Pass(double v) const
Definition BmnNdetCuts.h:22
bool PassPrototype(const BmnNdetDigi *d) const
Definition BmnNdetCuts.h:38
static BmnNdetCuts Load(const std::string &file, bool isExp)
Definition BmnNdetCuts.h:47
bool PassExp(const BmnHgndDigi *d) const
Definition BmnNdetCuts.h:40
bool PassSim(const BmnNdetDigit *d) const
Definition BmnNdetCuts.h:36