Skip to content

Commit

Permalink
Support writing signal procs with non-numeric mass values
Browse files Browse the repository at this point in the history
- FillHistMappings will only fill a signal-style hist mapping (with
  the $MASS patter) when the mass property is convertible to a float. Fixes #1.
- WriteDatacards now uses more precision for writing process yields, just to be safe
  • Loading branch information
ajgilbert committed Oct 15, 2015
1 parent 273814f commit 4dd1c8b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CombineTools/interface/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <map>
#include <set>
#include <string>
#include <sstream>
#include "boost/algorithm/string.hpp"
#include "boost/lexical_cast.hpp"
#include "boost/regex.hpp"
Expand Down Expand Up @@ -113,6 +114,9 @@ std::vector<std::vector<unsigned>> GenerateCombinations(

std::vector<std::string> ParseFileLines(std::string const& file_name);


bool is_float(std::string const& str);

/**
* Generate a vector of mass values using ranges and intervals specified in a
* string
Expand Down
20 changes: 17 additions & 3 deletions CombineTools/src/CombineHarvester_Datacards.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,22 @@ void CombineHarvester::FillHistMappings(std::vector<HistMapping> & mappings) {
auto sig_proc_set =
ch_signals.SetFromProcs(std::mem_fn(&ch::Process::process));
for (auto sig_proc : sig_proc_set) {
mappings.emplace_back(sig_proc, bin, bin + "/" + sig_proc + "$MASS",
bin + "/" + sig_proc + "$MASS_$SYSTEMATIC");
// should only add this mapping if the signal process has a numeric mass
// value, otherwise we will write it using the background rule above
auto masses = Set2Vec(ch_signals.cp()
.process({sig_proc})
.SetFromProcs(std::mem_fn(&ch::Process::mass)));
if (masses.size() != 1) {
throw std::runtime_error(FNERROR("Process " + sig_proc + " in bin " +
bin +
" has multiple entries with multiple "
"mass values, this is not supported"));

}
if (is_float(masses[0])) {
mappings.emplace_back(sig_proc, bin, bin + "/" + sig_proc + "$MASS",
bin + "/" + sig_proc + "$MASS_$SYSTEMATIC");
}
}
}

Expand Down Expand Up @@ -662,7 +676,7 @@ void CombineHarvester::WriteDatacard(std::string const& name,

txt_file << format("%-"+sys_str_long+"s") % "rate";
for (auto const& proc : procs_) {
txt_file << format("%-15.4g ") % proc->no_norm_rate();
txt_file << format("%-15.8g ") % proc->no_norm_rate();
}
txt_file << "\n";
txt_file << dashes << "\n";
Expand Down
8 changes: 8 additions & 0 deletions CombineTools/src/Utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ std::vector<std::string> ParseFileLines(std::string const& file_name) {
return files;
}

bool is_float(std::string const& str) {
std::istringstream iss(str);
float f;
iss >> std::noskipws >> f; // noskipws considers leading whitespace invalid
// Check the entire string was consumed and if either failbit or badbit is set
return iss.eof() && !iss.fail();
}

std::vector<std::string> MassesFromRange(std::string const& input,
std::string const& fmt) {
std::set<double> mass_set;
Expand Down

0 comments on commit 4dd1c8b

Please sign in to comment.