Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of TauWPThreshold without need to catch exceptions #43890

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions RecoTauTag/RecoTau/interface/TauWPThreshold.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@

#include "DataFormats/TauReco/interface/BaseTau.h"
#include "DataFormats/PatCandidates/interface/Tau.h"

#include <TF1.h>

#include <cmath>
#include <cstdlib>

namespace tau {
class TauWPThreshold {
public:
explicit TauWPThreshold(const std::string& cut_str) {
bool simple_value = false;
try {
size_t pos = 0;
value_ = std::stod(cut_str, &pos);
simple_value = (pos == cut_str.size());
} catch (std::invalid_argument&) {
} catch (std::out_of_range&) {
}
const char* cut_cstr = cut_str.c_str();
char* end_cstr{};
value_ = std::strtod(cut_cstr, &end_cstr);
// simple number if end_cstr is empty and not equal to initial string (cut_cstr), and returned value is finite
simple_value = !*end_cstr && cut_cstr != end_cstr && std::isfinite(value_);
if (!simple_value) {
static const std::string prefix =
"[&](double *x, double *p) { const int decayMode = p[0];"
Expand Down