BmnRoot
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
12
14{
15
16 // --- internal helper ---
17 struct Range
18 {
19 double min = -1e9, max = 1e9;
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 CrosstalkOverIntegral; // fCrosstalk / fIntegral
33 Range TimeMax; // fTimeMax
34
35 // --- methods ---
36 inline bool PassSim(const BmnHodoDigit* d) const { return true; }
37
38 inline bool PassExp(const BmnHodoDigi* d) const
39 {
40 if (d->fIntegral != 0 && !CrosstalkOverIntegral.Pass(d->fCrosstalk / d->fIntegral))
41 return false;
42 if (!TimeMax.Pass(d->fTimeMax))
43 return false;
44 return true;
45 }
46
47 static BmnHodoCuts Load(const std::string& file, bool isExp)
48 {
49 std::ifstream f(file);
50 if (!f.is_open()) {
51 std::cerr << "[BmnHodoCuts] 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 << "[BmnHodoCuts] JSON parse error in " << file << ": " << e.what() << std::endl;
60 return {};
61 }
62
63 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.CrosstalkOverIntegral, sec, "fCrosstalk_over_fIntegral");
81 readRange(c.TimeMax, sec, "fTimeMax");
82 }
83
84 std::cout << "[BmnHodoCuts] Loaded cuts for " << (isExp ? "experiment" : "simulation") << " from " << file
85 << std::endl;
86
87 return c;
88 }
89};
90
91#endif // BMN_HODO_CUTS_H
const Float_t d
Z-ccordinate of the first GEM-station.
Definition BmnMwpcHit.cxx:7
__m128 v
Definition P4_F32vec4.h:1
float f
Definition P4_F32vec4.h:21
Data class for BmnHodo digital signal processing.
Definition BmnHodoDigi.h:25
a class to store JSON values
Definition json.hpp:17282
basic_json<> json
default specialization
Definition json.hpp:3337
bool Pass(double v) const
Definition BmnHodoCuts.h:21
Range TimeMax
Definition BmnHodoCuts.h:33
Range CrosstalkOverIntegral
Definition BmnHodoCuts.h:32
bool PassExp(const BmnHodoDigi *d) const
Definition BmnHodoCuts.h:38
static BmnHodoCuts Load(const std::string &file, bool isExp)
Definition BmnHodoCuts.h:47
bool PassSim(const BmnHodoDigit *d) const
Definition BmnHodoCuts.h:36