16 std::string NNConfigDir =
"JetPileupTag/NNJvt/2022-03-22/";
17 std::string NNParamFileName =
"NNJVT.Network.graph.Offline.Nonprompt_All_MaxWeight.json";
18 std::string NNCutFileName =
"NNJVT.Cuts.FixedEffPt.Offline.Nonprompt_All_MaxW.json";
21 std::cout <<
"Reading JVT NN file from:\n " << NNConfigDir <<
"/" << NNParamFileName << std::endl;
22 std::cout <<
" resolved in :\n " << configPath << std::endl;
24 std::ifstream fconfig( configPath.c_str() );
26 if ( !fconfig.is_open() ) {
27 std::cerr <<
"Error opening config file: " << NNConfigDir <<
"/" << NNParamFileName << std::endl;
28 std::cerr <<
"Are you sure that the file exists at this path?" << std::endl;
33 std::cout <<
" Reading JVT NN cut file from:\n " << NNConfigDir <<
"/" << NNCutFileName << std::endl;
34 std::cout <<
" resolved in :\n " << cutsPath << std::endl;
35 std::ifstream fcuts( cutsPath.c_str() );
36 if ( !fconfig.is_open() ) {
37 std::cerr <<
"Error opening cuts file: " << NNConfigDir <<
"/" << NNCutFileName << std::endl;
38 std::cerr <<
"Are you sure that the file exists at this path?" << std::endl;
44 std::vector<float> ptbin_edges = cut_j[
"ptbin_edges"].get<std::vector<float> >();
45 std::vector<float> etabin_edges = cut_j[
"etabin_edges"].get<std::vector<float> >();
46 std::map<std::string,float> cut_map_raw = cut_j[
"cuts"].get<std::map<std::string,float> >();
49 std::vector<std::vector<float> > cut_map(ptbin_edges.size()-1);
50 for(std::vector<float>& cuts_vs_eta : cut_map) {
51 cuts_vs_eta.resize(etabin_edges.size()-1,0.);
54 for(
const std::pair<const std::string,float>& bins_to_cut_str : cut_map_raw) {
55 std::cout << bins_to_cut_str.first <<
" --> " << bins_to_cut_str.second << std::endl;
57 if(std::regex_match(bins_to_cut_str.first,sm,binre) && sm.size()==3) {
59 size_t ptbin = std::stoi(sm[1]);
60 size_t etabin = std::stoi(sm[2]);
61 cut_map[ptbin][etabin] = bins_to_cut_str.second;
63 std::cerr <<
"Regex match of pt/eta bins failed! Received string " << bins_to_cut_str.first << std::endl;
64 std::cerr <<
"Match size " << sm.size() << std::endl;
70 lwt::InputOrder
order;
72 std::vector<std::string>
inputs = {
"Rpt",
"JVFCorr",
"ptbin",
"etabin"};
74 node_order.emplace_back(
cfg.inputs[0].name,
inputs);
75 order.scalar = node_order;
77 std::cout <<
"Reading JVT likelihood histogram from: " << configPath << std::endl;
78 std::cout <<
"Network NLayers: " <<
cfg.layers.size() << std::endl;
79 lwt::generic::FastGraph<double> lwnn(
cfg,
order);
81 std::cout <<
"Computation for test values:" << std::endl;
83 for(
size_t ptbin=0; ptbin<5; ++ptbin) {
84 for(
size_t etabin=0; etabin<5; ++etabin) {
85 std::cout <<
" pt bin[" << ptbin_edges[ptbin] <<
"," << ptbin_edges[ptbin+1] <<
"]: " << ptbin <<
", eta bin [" << etabin_edges[etabin] <<
"," << etabin_edges[etabin+1] <<
"]: " << etabin <<std::endl;
86 lwt::VectorX<double> inputvals_HS =
lwt::build_vector({1.0,1.0,
static_cast<double>(ptbin),
static_cast<double>(etabin)});
87 std::vector<lwt::VectorX<double> > scalars_HS{inputvals_HS};
88 lwt::VectorX<double> output_HS = lwnn.compute(scalars_HS);
89 std::cout <<
" HS jet --> " << output_HS(0) << std::endl;
91 lwt::VectorX<double> inputvals_AMB =
lwt::build_vector({0.2,0.5,
static_cast<double>(ptbin),
static_cast<double>(etabin)});
92 std::vector<lwt::VectorX<double> > scalars_AMB{inputvals_AMB};
93 lwt::VectorX<double> output_AMB = lwnn.compute(scalars_AMB);
94 std::cout <<
" Ambiguous jet --> " << output_AMB(0) << std::endl;
96 lwt::VectorX<double> inputvals_PU =
lwt::build_vector({0.0,-1.0,
static_cast<double>(ptbin),
static_cast<double>(etabin)});
97 std::vector<lwt::VectorX<double> > scalars_PU{inputvals_PU};
98 lwt::VectorX<double> output_PU = lwnn.compute(scalars_PU);
99 std::cout <<
" PU jet --> " << output_PU(0) << std::endl;
101 std::cout <<
" Cut for this bin: " << cut_map[ptbin][etabin] << std::endl;