Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F8723458
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
View Options
diff --git a/src/ScaleFunction.cc b/src/ScaleFunction.cc
index 3004c5f..d6dc2ee 100644
--- a/src/ScaleFunction.cc
+++ b/src/ScaleFunction.cc
@@ -1,150 +1,158 @@
#include "RHEJ/ScaleFunction.hh"
#include <numeric>
#include <cassert>
#include "RHEJ/Event.hh"
namespace RHEJ{
double H_T(Event const & ev){
double result = 0.;
for(size_t i = 0; i < ev.outgoing().size(); ++i){
auto const decay_products = ev.decays().find(i);
if(decay_products == end(ev.decays())){
result += ev.outgoing()[i].perp();
}
else{
for(auto const & particle: decay_products->second){
result += particle.perp();
}
}
}
return result;
}
double max_jet_pt(Event const & ev) {
return sorted_by_pt(ev.jets()).front().pt();
}
double jet_invariant_mass(Event const & ev) {
fastjet::PseudoJet sum;
for(const auto & jet: ev.jets()) sum+=jet;
return sum.m();
}
double m_j1j2(Event const & ev) {
const auto jets = sorted_by_pt(ev.jets());
assert(jets.size() >= 2);
return (jets[0] + jets[1]).m();
}
ScaleFunction operator*(double factor, ScaleFunction base_scale) {
base_scale.name_.insert(0, std::to_string(factor) + '*');
auto new_fun =
[factor,fun{std::move(base_scale.fun_)}](RHEJ::Event const & ev) {
return factor*fun(ev);
};
base_scale.fun_ = std::move(new_fun);
return base_scale;
}
ScaleFunction operator/(ScaleFunction base_scale, double denom) {
base_scale.name_.append('/' + std::to_string(denom));
auto new_fun =
[denom,fun{std::move(base_scale.fun_)}](RHEJ::Event const & ev) {
return fun(ev)/denom;
};
base_scale.fun_ = std::move(new_fun);
return base_scale;
}
namespace {
std::shared_ptr<std::string> description(
std::string const & mur_name, std::string const & muf_name
) {
return std::make_shared<std::string>(
"mur=" + mur_name + ", muf=" + muf_name
);
}
}
// TODO: significant logic duplication with operator()
void ScaleGenerator::gen_scale_names() {
+ // stringstream gives nicer formatting for doubles than to_string
+ std::stringstream str;
if(scales_.empty()) {
throw std::logic_error{"Need at least one scale"};
}
scale_names_.emplace_back(
description(scales_.front().name(), scales_.front().name())
);
for(auto & base_scale: scales_){
const auto base_name = base_scale.name();
scale_names_.emplace_back(description(base_name, base_name));
//multiplicative scale variation
for(double mur_factor: scale_factors_){
- const auto mur_name = std::to_string(mur_factor) + '*' + base_name;
+ std::string mur_name;
+ str << mur_factor << '*' << base_name;
+ str >> mur_name;
+ str.clear();
for(double muf_factor: scale_factors_){
if(muf_factor == 1. && mur_factor == 1.) continue;
- const auto muf_name = std::to_string(muf_factor) + '*' + base_name;
+ std::string muf_name;
+ str << muf_factor << '*' << base_name;
+ str >> muf_name;
+ str.clear();
if(
mur_factor/muf_factor < 1/max_scale_ratio_
|| mur_factor/muf_factor > max_scale_ratio_
) continue;
scale_names_.emplace_back(description(mur_name, muf_name));
}
}
}
}
Event ScaleGenerator::operator()(Event ev) const {
if(! ev.variations().empty()) {
throw std::invalid_argument{"Input event already has scale variation"};
}
assert(!scales_.empty());
assert(!scale_names_.empty());
size_t name_idx = 0;
const double mu_central = (scales_.front())(ev);
ev.central().mur = mu_central;
ev.central().muf = mu_central;
assert(name_idx < scale_names_.size());
assert(scale_names_[name_idx]);
ev.central().description = scale_names_[name_idx++];
// check if we are doing scale variation at all
if(scales_.size() == 1 && scale_factors_.empty()) return ev;
for(auto & base_scale: scales_){
const double mu_base = base_scale(ev);
assert(name_idx < scale_names_.size());
assert(scale_names_[name_idx]);
ev.variations().emplace_back(
EventParameters{
mu_base, mu_base, ev.central().weight, scale_names_[name_idx++]
}
);
//multiplicative scale variation
for(double mur_factor: scale_factors_){
const double mur = mu_base*mur_factor;
for(double muf_factor: scale_factors_){
if(muf_factor == 1. && mur_factor == 1.) continue;
const double muf = mu_base*muf_factor;
if(
mur/muf < 1/max_scale_ratio_
|| mur/muf > max_scale_ratio_
) continue;
assert(name_idx < scale_names_.size());
assert(scale_names_[name_idx]);
ev.variations().emplace_back(
EventParameters{
mur, muf, ev.central().weight, scale_names_[name_idx++]
}
);
}
}
};
return ev;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Jan 20, 8:36 PM (16 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4238681
Default Alt Text
(5 KB)
Attached To
rHEJ HEJ
Event Timeline
Log In to Comment