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