15 bool simple_value =
false;
19 simple_value = (
pos == cut_str.size());
20 }
catch (std::invalid_argument&) {
21 }
catch (std::out_of_range&) {
25 "[&](double *x, double *p) { const int decayMode = p[0];"
26 "const double pt = p[1]; const double eta = p[2];";
27 static const int n_params = 3;
28 static const auto handler = [](
int, Bool_t,
const char*,
const char*) ->
void {};
31 auto old_handler = SetErrorHandler(handler);
32 fn_ = std::make_unique<TF1>(
"fn_", fn_str.c_str(), 0, 1, n_params);
33 SetErrorHandler(old_handler);
35 throw cms::Exception(
"TauWPThreshold: invalid formula") <<
"Invalid WP cut formula = '" << cut_str <<
"'.";
42 fn_->SetParameter(0,
tau.decayMode());
43 fn_->SetParameter(1,
tau.pt());
44 fn_->SetParameter(2,
tau.eta());
49 const tensorflow::Tensor& pred,
51 std::vector<reco::SingleTauDiscriminatorContainer> outputbuffer(
taus->size());
53 for (
size_t tau_index = 0; tau_index <
taus->size(); ++tau_index) {
55 for (
size_t num_elem :
num_)
56 x += pred.matrix<
float>()(tau_index, num_elem);
57 if (x != 0 && !
den_.empty()) {
59 for (
size_t den_elem :
den_)
60 den_val += pred.matrix<
float>()(tau_index, den_elem);
63 outputbuffer[tau_index].rawValues.push_back(x);
65 const bool pass = x > (*wp)(
taus->at(tau_index));
66 outputbuffer[tau_index].workingPoints.push_back(pass);
69 std::unique_ptr<TauDiscriminator>
output = std::make_unique<TauDiscriminator>();
71 filler.insert(
taus, outputbuffer.begin(), outputbuffer.end());
84 for (
const auto& output_desc :
outputs_) {
85 produces<TauDiscriminator>(output_desc.first);
86 const auto& cut_list =
cfg.getParameter<std::vector<std::string>>(output_desc.first +
"WP");
88 workingPoints_[output_desc.first].push_back(std::make_unique<Cutter>(cut_str));
102 for (
const auto& output_desc :
outputs_) {
109 const auto graph_name_vector =
cfg.getParameter<std::vector<std::string>>(
"graph_file");
110 std::map<std::string, std::string> graph_names;
111 for (
const auto&
entry : graph_name_vector) {
112 const size_t sep_pos =
entry.find(
':');
114 if (sep_pos != std::string::npos) {
115 entry_name =
entry.substr(0, sep_pos);
116 graph_file =
entry.substr(sep_pos + 1);
122 if (graph_names.count(entry_name))
123 throw cms::Exception(
"DeepTauCache") <<
"Duplicated graph entries";
124 graph_names[entry_name] = graph_file;
126 bool mem_mapped =
cfg.getParameter<
bool>(
"mem_mapped");
127 return std::make_unique<DeepTauCache>(graph_names, mem_mapped);
131 for (
const auto& graph_entry : graph_names) {
132 tensorflow::SessionOptions
options;
136 const std::string& graph_file = graph_entry.second;
140 if (!mmap_status.ok()) {
141 throw cms::Exception(
"DeepTauCache: unable to initalize memmapped environment for ")
142 << graph_file <<
". \n"
143 << mmap_status.ToString();
146 graphs_[entry_name] = std::make_unique<tensorflow::GraphDef>();
149 tensorflow::MemmappedFileSystem::kMemmappedPackageDefaultGraphDef,
151 if (!load_graph_status.ok())
152 throw cms::Exception(
"DeepTauCache: unable to load graph from ") << graph_file <<
". \n"
153 << load_graph_status.ToString();
155 options.config.mutable_graph_options()->mutable_optimizer_options()->set_opt_level(
156 ::tensorflow::OptimizerOptions::L0);