269 MF_LOG_INFO(
"GENIEWeightCalc") <<
"Configuring GENIE weight" 270 <<
" calculator " << this->
GetName();
277 log4cpp::Priority::WARN );
287 std::vector< std::string > CV_knob_names = param_CVs.
get_all_keys();
290 std::map< genie::rew::GSyst_t, double > gsyst_to_cv_map;
291 genie::rew::GSyst_t temp_knob;
294 <<
"Configuring non-default GENIE knob central values from input" 295 <<
" FHiCL parameter set";
297 for (
const auto& knob_name : CV_knob_names ) {
298 double CV_knob_value = param_CVs.get<
double>( knob_name );
299 if ( valid_knob_name(knob_name, temp_knob) ) {
300 if ( gsyst_to_cv_map.count( temp_knob ) ) {
301 throw cet::exception(__PRETTY_FUNCTION__) <<
"Duplicate central values" 302 <<
" were configured for the " << knob_name <<
" GENIE knob.";
304 gsyst_to_cv_map[ temp_knob ] = CV_knob_value;
306 MF_LOG_INFO(
"GENIEWeightCalc") <<
"Central value for the " << knob_name
307 <<
" knob was set to " << CV_knob_value;
314 auto const pars = pset.
get< std::vector<std::string> >(
"parameter_list",
315 std::vector<std::string>() );
316 auto const par_sigmas = pset.
get< std::vector<double> >(
"parameter_sigma",
317 std::vector<double>() );
321 auto const par_mins = pset.
get< std::vector<double> >(
"parameter_min",
322 std::vector<double>() );
323 auto const par_maxes = pset.
get< std::vector<double> >(
"parameter_max",
324 std::vector<double>() );
328 bool sigmas_ok =
true;
330 if ( mode.find(
"central_value") == std::string::npos
331 && mode.find(
"minmax") == std::string::npos )
335 if ( pars.size() != par_sigmas.size() ) {
337 array_name_for_exception =
"parameter_sigma";
340 else if ( mode.find(
"minmax") != std::string::npos ) {
341 if ( pars.size() != par_mins.size()
342 || pars.size() != par_maxes.size() )
347 array_name_for_exception =
"parameter_min and parameter_max";
353 <<
"::Bad fcl configuration. parameter_list and " 354 << array_name_for_exception
355 <<
" need to have same number of parameters.";
359 <<
" GENIE systematic knobs to be varied from the input FHiCL parameter set";
363 std::vector< genie::rew::GSyst_t > knobs_to_use;
364 for (
const auto& knob_name : pars ) {
365 if ( valid_knob_name(knob_name, temp_knob) ) knobs_to_use.push_back( temp_knob );
374 std::vector< genie::rew::GSyst_t > all_knobs_vec = knobs_to_use;
375 for (
const auto& pair : gsyst_to_cv_map ) {
376 genie::rew::GSyst_t cv_knob = pair.first;
377 auto begin = all_knobs_vec.cbegin();
378 auto end = all_knobs_vec.cend();
386 std::map< std::string, int >
391 size_t num_universes = 0u;
392 if ( mode.find(
"pm1sigma") != std::string::npos
393 || mode.find(
"minmax") != std::string::npos )
397 else if ( mode.find(
"multisim") != std::string::npos ) {
398 num_universes = pset.
get<
size_t>(
"number_of_multisims" );
404 int dummy_seed = pset.
get<
int>(
"random_seed" );
405 MF_LOG_INFO(
"GENIEWeightCalc") <<
"GENIE weight calculator " 406 << this->
GetName() <<
" will generate " << num_universes
407 <<
" multisim universes with random seed " << dummy_seed;
424 size_t num_usable_knobs = knobs_to_use.size();
425 std::vector< std::vector<double> > reweightingSigmas( num_usable_knobs );
427 for (
size_t k = 0u;
k < num_usable_knobs; ++
k ) {
428 reweightingSigmas[
k].resize( num_universes );
430 genie::rew::GSyst_t current_knob = knobs_to_use.at(
k );
432 for (
size_t u = 0u; u < num_universes; ++u ) {
433 if ( mode.find(
"multisim") != std::string::npos ) {
434 reweightingSigmas[
k][u] = par_sigmas[
k] * CLHEP::RandGaussQ::shoot(&engine, 0., 1.);
436 else if ( mode.find(
"pm1sigma") != std::string::npos ) {
438 reweightingSigmas[
k][u] = ( u == 0 ? 1. : -1. ) * par_sigmas.at(
k);
440 else if ( mode.find(
"minmax") != std::string::npos ) {
442 reweightingSigmas[
k][u] = ( u == 0 ? par_maxes.at(
k) : par_mins.at(
k) );
444 else if ( mode.find(
"central_value") != std::string::npos ) {
446 reweightingSigmas[
k][u] = 0.;
450 reweightingSigmas[
k][u] = par_sigmas[
k];
455 <<
" knob in universe #" << u <<
". sigma = " 456 << reweightingSigmas[
k][u];
462 if ( mode.find(
"minmax") == std::string::npos ) {
463 auto iter = gsyst_to_cv_map.find( current_knob );
464 if ( iter != gsyst_to_cv_map.end() ) {
465 reweightingSigmas[
k][u] += iter->second;
467 <<
"CV offset added to the " 469 <<
" knob. New sigma for universe #" << u <<
" is " 470 << reweightingSigmas[
k][u];
479 if ( !CALC_NAMES_THAT_IGNORE_TUNED_CV.count(this->GetName()) ) {
484 for (
const auto& pair : gsyst_to_cv_map ) {
485 genie::rew::GSyst_t cv_knob = pair.first;
486 double cv_value = pair.second;
490 if ( !
std::count(knobs_to_use.cbegin(), knobs_to_use.cend(), cv_knob) ) {
492 knobs_to_use.push_back( cv_knob );
495 reweightingSigmas.emplace_back(
496 std::vector<double>(num_universes, cv_value) );
500 <<
" was not configured. Setting it to " << cv_value
501 <<
" in all " << num_universes <<
" universes.";
510 for (
size_t u = 0; u < reweightVector.size(); ++u ) {
512 auto& rwght = reweightVector.at( u );
513 genie::rew::GSystSet& syst = rwght.Systematics();
515 for (
unsigned int k = 0;
k < knobs_to_use.size(); ++
k ) {
516 genie::rew::GSyst_t knob = knobs_to_use.at(
k );
518 double twk_dial_value = reweightingSigmas.at(
k ).at( u );
519 syst.Set( knob, twk_dial_value );
522 MF_LOG_INFO(
"GENIEWeightCalc") <<
"In universe #" << u <<
", knob #" <<
k 524 <<
" the value " << twk_dial_value;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< genie::rew::GReWeight > reweightVector
std::map< std::string, int > CheckForIncompatibleSystematics(const std::vector< genie::rew::GSyst_t > &knob_vec)
static Messenger * Instance(void)
T get(std::string const &key) const
#define MF_LOG_INFO(category)
std::vector< std::string > get_all_keys() const
A more convenient interface to the log4cpp Message Service.
std::string fGenieModuleLabel
void SetPriorityLevel(const char *stream, log4cpp::Priority::Value p)
const char * AsString(Resonance_t res)
resonance id -> string
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
void MesgThresholds(string inpfile)
void SetupWeightCalculators(genie::rew::GReWeight &rw, const std::map< std::string, int > &modes_to_use)
cet::coded_exception< error, detail::translate > exception