#include "generators/binning_generator.h" #include #include #include "simulation/errors.h" #include "simulation/jansson_additionals.h" #include "simulation/unit_converter.h" namespace generator { CylinderBinning buildPositionBinning(json_t* object) { if (json_object_by_path(object, {"CylinderBinning"})) { DEBUG_LEVEL_2("Creating position binning: cylinder binning."); object = json_object_by_path(object, {"CylinderBinning"}); json_t* radial = json_object_by_path(object, {"Radial"}); int number_of_bins_radial = json_int(json_object_by_path(radial, {"NumberOfBins"})); ASSERT_POSITIVE(&number_of_bins_radial, "Number of Bins must be positive"); double max_radius = json_read_length(json_object_by_path(radial, {"MaxRadius"}), "m"); ASSERT_POSITIVE(&max_radius, "Radius must be positive"); json_t* azimuthal = json_object_by_path(object, {"Azimuthal"}); int number_of_bins_azimuthal = json_int(json_object_by_path(azimuthal, {"NumberOfBins"})); ASSERT_POSITIVE(&number_of_bins_azimuthal, "Number of Bins must be positive"); json_t* longitudinal = json_object_by_path(object, {"Longitudinal"}); int number_of_bins_longitudinal = json_int(json_object_by_path(longitudinal, {"NumberOfBins"})); ASSERT_POSITIVE(&number_of_bins_longitudinal, "Number of Bins must be positive"); double max_length = json_read_length(json_object_by_path(longitudinal, {"MaxLength"}), "m"); ASSERT_POSITIVE(&max_length, "Radius must be positive"); DEBUG_LEVEL_3("with number of bins radial: " + std::to_string(number_of_bins_radial)); DEBUG_LEVEL_3("with number of bins azimuthal: " + std::to_string(number_of_bins_azimuthal)); DEBUG_LEVEL_3("with number of bins longitudinal: " + std::to_string(number_of_bins_longitudinal)); DEBUG_LEVEL_3("with radius: " + std::to_string(max_radius) + " m"); DEBUG_LEVEL_3("with height: " + std::to_string(max_length) + " m"); return CylinderBinning(number_of_bins_radial, max_radius, number_of_bins_azimuthal, number_of_bins_longitudinal, max_length); } else { ERROR("This position binning is not implemented."); return CylinderBinning(0, 0, 0, 0, 0); } } CylinderBinning buildPositionBinningIncludingRedirection( Parameter& parameter, json_path& path_to_binning) { if (parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))) { DEBUG_LEVEL_2("Creating position binning: CreateSameAs."); json_path path_to_same = json_path_get(parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))); std::stringstream path; for (auto& p : path_to_same) { path << p << " "; } DEBUG_LEVEL_3("From path: " + path.str()); return buildPositionBinningIncludingRedirection(parameter, path_to_same); } else { return buildPositionBinning(parameter.jsonObjectFromBase(path_to_binning)); } } EnergyBinning buildEnergyBinning(json_t* object) { std::string energy_type = json_string(json_object_by_path(object, {"Type"})); if (energy_type == "Logarithmic") { DEBUG_LEVEL_2("Creating energy binning: logarithmic."); int number_of_bins = json_int(json_object_by_path(object, {"NumberOfBins"})); ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive"); double min_energy = json_read_energy(json_object_by_path(object, {"MinEnergy"}), "eV"); ASSERT_POSITIVE(&min_energy, "Min Energy must be positive"); double max_energy = json_read_energy(json_object_by_path(object, {"MaxEnergy"}), "eV"); ASSERT_POSITIVE(&max_energy, "Max Energy must be positive"); DEBUG_LEVEL_3("with number of bins: " + std::to_string(number_of_bins)); DEBUG_LEVEL_3("with min energy: " + std::to_string(min_energy)); DEBUG_LEVEL_3("with max energy: " + std::to_string(max_energy)); return EnergyBinning(min_energy, max_energy, number_of_bins); } else { ERROR("This energy binning is not implemented."); return EnergyBinning(0, 0, 0); } } EnergyBinning buildEnergyBinningIncludingRedirection( Parameter& parameter, json_path& path_to_binning) { if (parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))) { DEBUG_LEVEL_2("Creating energy binning: CreateSameAs."); json_path path_to_same = json_path_get(parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))); std::stringstream path; for (auto& p : path_to_same) { path << p << " "; } DEBUG_LEVEL_3("From path: " + path.str()); return buildEnergyBinningIncludingRedirection(parameter, path_to_same); } else { return buildEnergyBinning(parameter.jsonObjectFromBase(path_to_binning)); } } }; // namespace generator