775 const auto& seed_service = art::ServiceHandle<rndm::NuRandomService>();
776 const auto& geom_service = art::ServiceHandle<geo::Geometry const>();
780 fVertexSampler = std::make_unique<evgen::ActiveVolumeVertexSampler>(
781 p().vertex_, *seed_service, *geom_service,
"MARLEY_Vertex_Sampler");
784 const fhicl::ParameterSet marley_pset =
p.get_PSet()
785 .get< fhicl::ParameterSet >(
"marley_parameters" );
787 *seed_service,
"MARLEY" );
793 const std::string& samp_mode_str =
p().sampling_mode_();
794 if (samp_mode_str ==
"histogram")
796 else if (samp_mode_str ==
"uniform time")
798 else if (samp_mode_str ==
"uniform energy")
800 else throw cet::exception(
"MARLEYTimeGen")
801 <<
"Invalid sampling mode \"" << samp_mode_str <<
"\""
802 <<
" specified for the MARLEYTimeGen module.";
804 MF_LOG_INFO(
"MARLEYTimeGen") << fNeutrinosPerEvent <<
" neutrino vertices"
805 <<
" will be generated for each art::Event using the \"" << samp_mode_str
806 <<
"\" sampling mode.";
810 std::string spectrum_file_format = marley_utils::to_lowercase(
811 p().spectrum_file_format_());
813 if (spectrum_file_format ==
"th2d")
815 else if (spectrum_file_format ==
"fit") {
818 std::string pinch_type;
819 if ( !
p().pinching_parameter_type_(pinch_type) ) {
820 throw cet::exception(
"MARLEYTimeGen") <<
"Missing pinching parameter"
821 <<
" type for a \"fit\" format spectrum file";
824 marley_utils::to_lowercase_inplace(pinch_type);
827 else throw cet::exception(
"MARLEYTimeGen")
828 <<
"Invalid pinching parameter type \"" << pinch_type
829 <<
"\" specified for the MARLEYTimeGen module.";
831 if ( !
p().fit_Emin_(
fFitEmin) )
throw cet::exception(
"MARLEYTimeGen")
832 <<
"Missing minimum energy for a \"fit\" format spectrum"
833 <<
" used by the MARLEYTimeGen module.";
835 if ( !
p().fit_Emax_(
fFitEmax) )
throw cet::exception(
"MARLEYTimeGen")
836 <<
"Missing maximum energy for a \"fit\" format spectrum"
837 <<
" used by the MARLEYTimeGen module.";
840 <<
"Maximum energy is less than the minimum energy for"
841 <<
" a \"fit\" format spectrum used by the MARLEYTimeGen module.";
843 else throw cet::exception(
"MARLEYTimeGen")
844 <<
"Invalid spectrum file format \"" <<
p().spectrum_file_format_()
845 <<
"\" specified for the MARLEYTimeGen module.";
848 std::string full_spectrum_file_name
849 = fMarleyHelper->find_file(
p().spectrum_file_(),
"spectrum");
856 std::unique_ptr<TFile> spectrum_file
857 = std::make_unique<TFile>(full_spectrum_file_name.c_str(),
"read");
858 TH2D* temp_h2 =
nullptr;
859 std::string namecycle;
860 if ( !
p().namecycle_(namecycle) ) {
861 throw cet::exception(
"MARLEYTimeGen") <<
"Missing namecycle for"
862 <<
" a TH2D spectrum file";
865 spectrum_file->GetObject(namecycle.c_str(), temp_h2);
877 TH1D* energy_spect =
fSpectrumHist->ProjectionY(
"energy_spect");
883 std::unique_ptr<marley::NeutrinoSource> nu_source
884 = marley_root::make_root_neutrino_source(marley_utils::ELECTRON_NEUTRINO,
889 * flux_averaged_total_xs(*nu_source, gen);
897 gen.set_source(std::move(nu_source));
907 std::ifstream fit_file(full_spectrum_file_name);
910 bool found_end =
false;
915 int lines_checked = 0;
917 double old_time = std::numeric_limits<double>::lowest();
919 while ( line = marley_utils::get_next_line(fit_file, rx_comment_or_empty,
920 false, lines_checked), line_num += lines_checked, !line.empty() )
923 MF_LOG_WARNING(
"MARLEYTimeGen") <<
"Trailing content after last time"
924 <<
" bin found on line " << line_num <<
" of the spectrum file "
925 << full_spectrum_file_name;
929 double Emean_nue, alpha_nue, luminosity_nue;
930 double Emean_nuebar, alpha_nuebar, luminosity_nuebar;
931 double Emean_nux, alpha_nux, luminosity_nux;
932 std::istringstream iss(line);
933 bool ok_first =
static_cast<bool>( iss >> time );
935 if (time <= old_time)
throw cet::exception(
"MARLEYTimeGen")
936 <<
"Time bin left edges given in the spectrum file must be"
937 <<
" strictly increasing. Invalid time bin value found on line "
938 << line_num <<
" of the spectrum file " << full_spectrum_file_name;
939 else old_time = time;
941 bool ok_rest =
static_cast<bool>( iss >> Emean_nue >> alpha_nue
942 >> luminosity_nue >> Emean_nuebar >> alpha_nuebar >> luminosity_nuebar
943 >> Emean_nux >> alpha_nux >> luminosity_nux
950 fTimeFits.emplace_back(time, Emean_nue, alpha_nue, luminosity_nue,
951 Emean_nuebar, alpha_nuebar, luminosity_nuebar, Emean_nux,
952 alpha_nux, luminosity_nux);
959 else throw cet::exception(
"MARLEYTimeGen") <<
"Parse error on line "
960 << line_num <<
" of the spectrum file " << full_spectrum_file_name;
966 if (num_time_bins < 2)
throw cet::exception(
"MARLEYTimeGen")
967 <<
"Missing right edge for the final time bin in the spectrum file "
968 << full_spectrum_file_name <<
". Unable to guess a bin width for the "
973 double delta_t_bin =
fTimeFits.back().Time()
974 -
fTimeFits.at(num_time_bins - 2).Time();
976 double last_bin_right_edge =
fTimeFits.back().Time() + delta_t_bin;
981 <<
" edge for the final time bin in the spectrum file "
982 << full_spectrum_file_name <<
". Assuming a width of "
983 << delta_t_bin <<
" s for the final bin.";
989 std::vector< std::unique_ptr< marley::NeutrinoSource > > fit_sources;
996 auto temp_source = std::make_unique<marley::FunctionNeutrinoSource>(
998 [&fit_sources,
this](
double E_nu) ->
double {
1000 for (
size_t s = 0;
s < fit_sources.size(); ++
s) {
1002 const TimeFit& current_fit = this->fTimeFits.at(
s);
1003 const auto& current_source = fit_sources.at(
s);
1004 const FitParameters& params = current_fit.GetFitParameters(
1005 current_source->get_pid() );
1007 double lum = params.Luminosity();
1012 if (lum <= 0.)
continue;
1014 flux += lum * current_source->pdf(E_nu);
1020 double flux_integ = 0.;
1021 double tot_xs_integ = 0.;
1022 flux_averaged_total_xs(*temp_source, gen, flux_integ, tot_xs_integ);
1026 * tot_xs_integ / flux_integ;
1033 throw cet::exception(
"MARLEYTimeGen") <<
"Unrecognized neutrino spectrum"
1034 <<
" file format \"" <<
p().spectrum_file_format_() <<
"\" encountered"
1035 <<
" in evgen::MarleyTimeGen::reconfigure()";
1038 MF_LOG_INFO(
"MARLEYTimeGen") <<
"The flux-averaged total cross section"
1039 <<
" predicted by MARLEY for the current supernova spectrum is "
SpectrumFileFormat fSpectrumFileFormat
Format to assume for the neutrino spectrum input file.
PinchParamType fPinchType
The pinching parameter convention to use when interpreting the time-dependent fits.
std::unique_ptr< evgen::ActiveVolumeVertexSampler > fVertexSampler
Algorithm that allows us to sample vertex locations within the active volume(s) of the detector...
std::unique_ptr< evgen::MARLEYHelper > fMarleyHelper
Object that provides an interface to the MARLEY event generator.
double fFluxAveragedCrossSection
Flux-averaged total cross section (fm2, average is taken over all energies and times for all defined ...
std::unique_ptr< marley::NeutrinoSource > source_from_time_fit(const TimeFit &fit)
Create a MARLEY neutrino source object using a set of fit parameters for a particular time bin...
MF_LOG_WARNING("SimWire")<< "SimWire is an example module that works for the "<< "MicroBooNE detector. Each experiment should implement "<< "its own version of this module to simulate electronics "<< "response."
double fFitEmax
Maximum neutrino energy to consider when using a "fit"-format spectrum file.
std::unique_ptr< TH2D > fSpectrumHist
ROOT TH2D that contains the time-dependent spectrum to use when sampling neutrino times and energies...
unsigned int fNeutrinosPerEvent
The number of MARLEY neutrino vertices to generate in each art::Event.
then echo File list $list not found else cat $list while read file do echo $file sed s
TimeGenSamplingMode fSamplingMode
Represents the sampling mode to use when selecting neutrino times and energies.
double fFitEmin
Minimum neutrino energy to consider when using a "fit"-format spectrum file.
void make_final_timefit(double time)
Helper function that makes a final dummy TimeFit object so that the final real time bin can have a ri...
std::vector< TimeFit > fTimeFits
Vector that contains the fit parameter information for each time bin when using a "fit"-format spectr...
void make_nu_emission_histograms() const
Makes ROOT histograms showing the emitted neutrinos in each time bin when using a "fit"-format spectr...