-
Notifications
You must be signed in to change notification settings - Fork 182
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
Add the variables for param NP to the datacard parsing and writing methods #308
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,14 +290,10 @@ int CombineHarvester::ParseDatacard(std::string const& filename, | |
start_nuisance_scan = true; | ||
} | ||
} | ||
|
||
if (start_nuisance_scan && words[i].size() >= 4) { | ||
if (boost::iequals(words[i][1], "param")) { | ||
std::string param_name = words[i][0]; | ||
if (!params_.count(param_name)) | ||
params_[param_name] = std::make_shared<Parameter>(Parameter()); | ||
Parameter * param = params_.at(param_name).get(); | ||
param->set_name(param_name); | ||
Parameter * param = SetupRateParamVar(param_name, boost::lexical_cast<double>(words[i][2])); | ||
param->set_val(boost::lexical_cast<double>(words[i][2])); | ||
std::size_t slash_pos = words[i][3].find("/"); | ||
if (slash_pos != words[i][3].npos) { | ||
|
@@ -318,6 +314,10 @@ int CombineHarvester::ParseDatacard(std::string const& filename, | |
param->set_range_u(boost::lexical_cast<double>(tokens[2])); | ||
} | ||
} | ||
auto sys = std::make_shared<Systematic>(); | ||
sys->set_name(param_name); | ||
sys->set_type("param"); | ||
systs_.push_back(sys); | ||
continue; // skip the rest of this now | ||
} | ||
} | ||
|
@@ -763,13 +763,16 @@ void CombineHarvester::WriteDatacard(std::string const& name, | |
auto bin_set = this->SetFromProcs(std::mem_fn(&ch::Process::bin)); | ||
auto proc_set = this->SetFromProcs(std::mem_fn(&ch::Process::process)); | ||
std::set<std::string> sys_set; | ||
std::set<std::string> param_set; | ||
std::set<std::string> rateparam_set; | ||
this->ForEachSyst([&](ch::Systematic const* sys) { | ||
if (sys->type() == "rateParam") { | ||
rateparam_set.insert(sys->name()); | ||
} else { | ||
sys_set.insert(sys->name()); | ||
} | ||
else if (sys->type() == "param"){ | ||
param_set.insert(sys->name()); | ||
} | ||
else sys_set.insert(sys->name()); | ||
}); | ||
txt_file << "imax " << bin_set.size() | ||
<< " number of bins\n"; | ||
|
@@ -1016,6 +1019,21 @@ void CombineHarvester::WriteDatacard(std::string const& name, | |
} | ||
} | ||
|
||
for (auto par : params_) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if following changes above, could remove this part, and instead modify the block that writes |
||
Parameter const* p = par.second.get(); | ||
if (p->err_d() != 0.0 && p->err_u() != 0.0 && | ||
param_set.count(p->name()) && !sys_set.count(p->name())) { | ||
txt_file << format((format("%%-%is param %%g %%g") % sys_str_len).str()) % | ||
p->name() % p->val() % ((p->err_u() - p->err_d()) / 2.0); | ||
if (p->range_d() != std::numeric_limits<double>::lowest() && | ||
p->range_u() != std::numeric_limits<double>::max()) { | ||
txt_file << format(" [%.4g,%.4g]") % p->range_d() % p->range_u(); | ||
} | ||
txt_file << "\n"; | ||
} | ||
} | ||
|
||
|
||
for (auto const& sys : sys_set) { | ||
std::vector<std::string> line(procs_.size() + 2); | ||
line[0] = sys; | ||
|
@@ -1024,6 +1042,7 @@ void CombineHarvester::WriteDatacard(std::string const& name, | |
bool seen_shape = false; | ||
bool seen_shapeN2 = false; | ||
bool seen_shapeU = false; | ||
if (param_set.count(sys)) continue; | ||
for (unsigned p = 0; p < procs_.size(); ++p) { | ||
line[p + 2] = "-"; | ||
for (unsigned n = 0; n < proc_sys_map[p].size(); ++n) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a worry this could cause problems in other bits of code, e.g. PostFitShapes, where it tries to evaluate all the Systematic objects, and might not know what to do with a
param
type. It might also be fine, I'm not sure. I can see another way to fix this while avoiding creating aSystematic
entry. It would be to add a new bool data member to theParameter
class that flags parameters that come fromparam
lines in the datacard. Can make false by default, and only set it to true here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ajgilbert, thanks a lot for the feedback,
I think in the PostFitFromWorkspace method the datacards are setup from the workspace, and the datacard is parsed only for the re-binning, and I checked that it works. In principle I'm fine with reverting it back and avoiding definition of
Systematic
entry, but I also think that it would be good to be able to setup theparam
nuisances from CH datacard creation workflow, so that you can define formula based rate parameters. I just pushed a couple of commits that do that. Let me know what you thinkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok yes, I see the point, indeed it's useful if these can be created directly. Do you have any other commits to add? If not we can merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I do not have anything to add at this point, thanks!