18 bool simple_value =
false;
22 simple_value = (
pos == cut_str.size());
23 }
catch (std::invalid_argument&) {
24 }
catch (std::out_of_range&) {
28 "[&](double *x, double *p) { const int decayMode = p[0];"
29 "const double pt = p[1]; const double eta = p[2];";
30 static const int n_params = 3;
31 static const auto handler = [](
int, Bool_t,
const char*,
const char*) ->
void {};
34 auto old_handler = SetErrorHandler(handler);
35 fn_ = std::make_unique<TF1>(
"fn_", fn_str.c_str(), 0, 1, n_params);
36 SetErrorHandler(old_handler);
38 throw cms::Exception(
"TauWPThreshold: invalid formula") <<
"Invalid WP cut formula = '" << cut_str <<
"'.";
47 fn_->SetParameter(0, dynamic_cast<const reco::PFTau&>(
tau).
decayMode());
50 fn_->SetParameter(1,
tau.pt());
51 fn_->SetParameter(2,
tau.eta());
56 const tensorflow::Tensor& pred,
58 bool is_online)
const {
59 std::vector<reco::SingleTauDiscriminatorContainer> outputbuffer(
taus->size());
61 for (
size_t tau_index = 0; tau_index <
taus->size(); ++tau_index) {
63 for (
size_t num_elem :
num_)
64 x += pred.matrix<
float>()(tau_index, num_elem);
65 if (x != 0 && !
den_.empty()) {
67 for (
size_t den_elem :
den_)
68 den_val += pred.matrix<
float>()(tau_index, den_elem);
71 outputbuffer[tau_index].rawValues.push_back(x);
74 const bool pass = x > (*wp)(
taus->at(tau_index), is_online);
75 outputbuffer[tau_index].workingPoints.push_back(pass);
79 std::unique_ptr<TauDiscriminator>
output = std::make_unique<TauDiscriminator>();
81 filler.insert(
taus, outputbuffer.begin(), outputbuffer.end());
95 for (
const auto& output_desc :
outputs_) {
96 produces<TauDiscriminator>(output_desc.first);
97 const auto& cut_list =
cfg.getParameter<std::vector<std::string>>(output_desc.first +
"WP");
99 workingPoints_[output_desc.first].push_back(std::make_unique<Cutter>(cut_str));
110 transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
112 if (pdBoolOperator ==
"and") {
114 }
else if (pdBoolOperator ==
"or") {
118 <<
"PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
122 std::vector<std::string> prediscriminantsNames =
125 for (
auto const& iDisc : prediscriminantsNames) {
133 thisDiscriminator.
cut =
cut;
134 thisDiscriminator.
disc_token = consumes<reco::PFTauDiscriminator>(
label);
139 thisDiscriminator.
cut =
cut;
140 thisDiscriminator.
disc_token = consumes<pat::PATTauDiscriminator>(
label);
152 size_t nPrediscriminants =
154 for (
size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
166 if (tauProductID != discKeyId) {
168 <<
"The tau collection has product ID: " << tauProductID
169 <<
" but the pre-discriminator is keyed with product ID: " << discKeyId << std::endl;
178 for (
const auto& output_desc :
outputs_) {
189 const auto graph_name_vector =
cfg.getParameter<std::vector<std::string>>(
"graph_file");
190 std::map<std::string, std::string> graph_names;
191 for (
const auto&
entry : graph_name_vector) {
192 const size_t sep_pos =
entry.find(
':');
194 if (sep_pos != std::string::npos) {
195 entry_name =
entry.substr(0, sep_pos);
196 graph_file =
entry.substr(sep_pos + 1);
202 if (graph_names.count(entry_name))
203 throw cms::Exception(
"DeepTauCache") <<
"Duplicated graph entries";
204 graph_names[entry_name] = graph_file;
206 bool mem_mapped =
cfg.getParameter<
bool>(
"mem_mapped");
207 return std::make_unique<DeepTauCache>(graph_names, mem_mapped);
211 for (
const auto& graph_entry : graph_names) {
212 tensorflow::SessionOptions
options;
216 const std::string& graph_file = graph_entry.second;
220 if (!mmap_status.ok()) {
221 throw cms::Exception(
"DeepTauCache: unable to initalize memmapped environment for ")
222 << graph_file <<
". \n"
223 << mmap_status.ToString();
226 graphs_[entry_name] = std::make_unique<tensorflow::GraphDef>();
229 tensorflow::MemmappedFileSystem::kMemmappedPackageDefaultGraphDef,
231 if (!load_graph_status.ok())
232 throw cms::Exception(
"DeepTauCache: unable to load graph from ") << graph_file <<
". \n"
233 << load_graph_status.ToString();
235 options.config.mutable_graph_options()->mutable_optimizer_options()->set_opt_level(
236 ::tensorflow::OptimizerOptions::L0);