LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MARLEYTimeGen_module.cc
Go to the documentation of this file.
1 
10 // standard library includes
11 #include <fstream>
12 #include <limits>
13 #include <memory>
14 #include <regex>
15 #include <string>
16 
17 // framework includes
24 #include "art_root_io/TFileDirectory.h"
25 #include "art_root_io/TFileService.h"
27 #include "cetlib_except/exception.h"
28 #include "fhiclcpp/ParameterSet.h"
30 #include "fhiclcpp/types/Table.h"
32 
33 // art extensions
35 
36 // LArSoft includes
43 
44 // ROOT includes
45 #include "TFile.h"
46 #include "TH1D.h"
47 #include "TH2D.h"
48 #include "TTree.h"
49 
50 // MARLEY includes
51 #include "marley/Integrator.hh"
52 #include "marley/marley_root.hh"
53 #include "marley/marley_utils.hh"
54 
55 // Anonymous namespace for definitions local to this source file
56 namespace {
57 
58  // The number of times to attempt to sample an energy uniformly
59  // before giving up
60  constexpr int MAX_UNIFORM_ENERGY_ITERATIONS = 1000;
61 
62  // Neutrino vertices generated using unbiased sampling are assigned
63  // unit weight
64  constexpr double ONE = 1.;
65 
66  // Number of sampling points to use for numerical integration
67  // (via the Clenshaw-Curtis method)
68  constexpr int NUM_INTEGRATION_SAMPLING_POINTS = 100;
69 
70  // Multiply an energy in MeV by this factor to convert to erg
71  // (based on 2017 PDG "Physical Constants" article)
72  constexpr double MeV_to_erg = 1.6021766208e-6; // erg / MeV
73 
74  // The PDG codes that represent one of the varieties of "nu_x"
75  constexpr std::array<int, 4> NU_X_PDG_CODES{
76  marley_utils::MUON_NEUTRINO,
77  marley_utils::MUON_ANTINEUTRINO,
78  marley_utils::TAU_NEUTRINO,
79  marley_utils::TAU_ANTINEUTRINO,
80  };
81 
82  // Helper function that tests whether a given PDG code represents
83  // a "nu_x"
84  bool is_nux(int pdg_code)
85  {
86  return std::find(std::begin(NU_X_PDG_CODES), std::end(NU_X_PDG_CODES), pdg_code) !=
87  std::end(NU_X_PDG_CODES);
88  }
89 
90  // Matches comment lines and empty lines in a "fit"-format spectrum file
91  const std::regex rx_comment_or_empty = std::regex("\\s*(#.*)?");
92 
93  // Compute the flux-averaged total cross section (MeV^[-2]) for all
94  // defined reactions and for a particular neutrino source
95  double flux_averaged_total_xs(marley::NeutrinoSource& nu_source, marley::Generator& gen);
96 
97  // Overloaded version that allows access to the flux integral
98  // (which will be loaded into source_integ) and the xs * flux integral
99  // (which will be loaded into tot_xs_integ)
100  double flux_averaged_total_xs(marley::NeutrinoSource& nu_source,
101  marley::Generator& gen,
102  double& source_integ,
103  double& tot_xs_integ);
104 
105  // Returns a numerical integral of the function f on the interval
106  // [x_min, x_max]
107  double integrate(const std::function<double(double)>& f, double x_min, double x_max);
108 }
109 
110 namespace evgen {
111  class MarleyTimeGen;
112 }
113 
115 
116 public:
117  using Name = fhicl::Name;
119 
122  struct KeysToIgnore {
123  std::set<std::string> operator()() { return {"marley_parameters"}; }
124  };
125 
127  struct Config {
128 
130  Name("vertex"),
131  Comment("Configuration for selecting the vertex location(s)")};
132 
134  Name("module_type"),
135  Comment(""),
136  "MARLEYTimeGen" // default value
137  };
138 
139  fhicl::Atom<std::string> sampling_mode_{
140  Name("sampling_mode"),
141  Comment("Technique to use when sampling times and energies. Valid"
142  " options are \"histogram\", \"uniform time\","
143  " and \"uniform energy\""),
144  std::string("histogram") // default value
145  };
146 
148  Name("nu_per_event"),
149  Comment("The number of neutrino vertices to generate in"
150  " each art::Event"),
151  1u // default value
152  };
153 
154  fhicl::Atom<std::string> spectrum_file_format_{
155  Name("spectrum_file_format"),
156  Comment("Format to assume for the neutrino spectrum file."
157  " Valid options are \"th2d\" (a ROOT file containing a "
158  " TH2D object) and \"fit\" (an ASCII text file containing"
159  " fit parameters for each time bin). This parameter is not"
160  " case-sensitive."),
161  "th2d" // default value
162  };
163 
164  fhicl::Atom<std::string> spectrum_file_{
165  Name("spectrum_file"),
166  Comment("Name of a file that contains a representation"
167  " of the incident (not cross section weighted) neutrino spectrum"
168  " as a function of time and energy.")};
169 
170  fhicl::OptionalAtom<std::string> pinching_parameter_type_{
171  Name("pinching_parameter_type"),
172  Comment("Type of pinching parameter to assume when parsing"
173  " the time-dependent fit parameters for the incident neutrino"
174  " spectrum. Valid options are \"alpha\" and \"beta\". This"
175  " parameter is not case-sensitive."),
176  [this]() -> bool {
177  auto spectrum_file_format = marley_utils::to_lowercase(spectrum_file_format_());
178  return (spectrum_file_format == "fit");
179  }};
180 
182  Name("namecycle"),
183  Comment("Name of the TH2D object to use to represent the"
184  " incident neutrino spectrum. This value should match the"
185  " name of the TH2D as given in the ROOT file specified"
186  " in the \"spectrum_file\" parameter. The TH2D should use "
187  " time bins on the X axis (seconds) and energy bins on the "
188  " Y axis (MeV)."),
189  [this]() -> bool {
190  auto spectrum_file_format = marley_utils::to_lowercase(spectrum_file_format_());
191  return (spectrum_file_format == "th2d");
192  }};
193 
195  Name("fit_Emin"),
196  Comment("Minimum allowed neutrino energy (MeV) for a \"fit\" format"
197  " spectrum file"),
198  [this]() -> bool {
199  auto spectrum_file_format = marley_utils::to_lowercase(spectrum_file_format_());
200  return (spectrum_file_format == "fit");
201  }};
202 
204  Name("fit_Emax"),
205  Comment("Maximum allowed neutrino energy (MeV) for a \"fit\" format"
206  " spectrum file"),
207  [this]() -> bool {
208  auto spectrum_file_format = marley_utils::to_lowercase(spectrum_file_format_());
209  return (spectrum_file_format == "fit");
210  }};
211 
212  }; // struct Config
213 
214  // Type to enable FHiCL parameter validation by art
216 
217  // @brief Configuration-checking constructor
218  explicit MarleyTimeGen(const Parameters& p);
219 
220  virtual void produce(art::Event& e) override;
221  virtual void beginRun(art::Run& run) override;
222 
223  virtual void reconfigure(const Parameters& p);
224 
225 protected:
229  public:
230  FitParameters(double Emean, double alpha, double luminosity)
231  : fEmean(Emean), fAlpha(alpha), fLuminosity(luminosity)
232  {}
233 
235  double Emean() const { return fEmean; }
237  double Alpha() const { return fAlpha; }
239  double Luminosity() const { return fLuminosity; }
240 
242  void set_Emean(double Emean) { fEmean = Emean; }
244  void set_Alpha(double alpha) { fAlpha = alpha; }
246  void set_Luminosity(double lum) { fLuminosity = lum; }
247 
254  template <typename It>
255  static marley::IteratorToMember<It, double> make_luminosity_iterator(It it)
256  {
257  return marley::IteratorToMember<It, double>(it, &FitParameters::fLuminosity);
258  }
259 
260  protected:
261  double fEmean;
262  double fAlpha;
263  double fLuminosity;
264  };
265 
268  class TimeFit {
269  public:
270  TimeFit(double time,
271  double Emean_nue,
272  double alpha_nue,
273  double lum_nue,
274  double Emean_nuebar,
275  double alpha_nuebar,
276  double lum_nuebar,
277  double Emean_nux,
278  double alpha_nux,
279  double lum_nux)
280  : fTime(time)
281  , fNueFitParams(Emean_nue, alpha_nue, lum_nue)
282  , fNuebarFitParams(Emean_nuebar, alpha_nuebar, lum_nuebar)
283  , fNuxFitParams(Emean_nux, alpha_nux, lum_nux)
284  {}
285 
289  double Time() const { return fTime; }
290 
291  protected:
297  {
298  if (pdg_code == marley_utils::ELECTRON_NEUTRINO) { return &TimeFit::fNueFitParams; }
299  else if (pdg_code == marley_utils::ELECTRON_ANTINEUTRINO) {
301  }
302  else if (is_nux(pdg_code)) {
303  // The PDG code represents one of the varieties of nu_x
304  return &TimeFit::fNuxFitParams;
305  }
306  else
307  throw cet::exception("MARLEYTimeGen")
308  << "Invalid neutrino"
309  << " PDG code " << pdg_code << " encountered in MARLEYTimeGen"
310  << "::TimeFit::GetFitParametersMemberPointer()";
311  return nullptr;
312  }
313 
314  public:
318  const FitParameters& GetFitParameters(int pdg_code) const
319  {
320  return this->*GetFitParametersMemberPointer(pdg_code);
321  }
322 
333  template <typename It>
334  static marley::IteratorToMember<It, FitParameters> make_FitParameters_iterator(int pdg_code,
335  It iterator)
336  {
337  return marley::IteratorToMember<It, FitParameters>(iterator,
338  GetFitParametersMemberPointer(pdg_code));
339  }
340 
341  protected:
343  double fTime;
344 
347 
351 
355  };
356 
363  double E_max,
364  double& E_nu,
365  const TLorentzVector& vertex_pos);
366 
369  std::unique_ptr<marley::NeutrinoSource> source_from_time_fit(const TimeFit& fit);
370 
373  void create_truths_th2d(simb::MCTruth& mc_truth,
374  sim::SupernovaTruth& sn_truth,
375  const TLorentzVector& vertex_pos);
376 
379  void create_truths_time_fit(simb::MCTruth& mc_truth,
380  sim::SupernovaTruth& sn_truth,
381  const TLorentzVector& vertex_pos);
382 
385  void make_final_timefit(double time);
386 
389  void make_nu_emission_histograms() const;
390 
392  std::unique_ptr<evgen::MARLEYHelper> fMarleyHelper;
393 
396  std::unique_ptr<evgen::ActiveVolumeVertexSampler> fVertexSampler;
397 
399  std::unique_ptr<marley::Event> fEvent;
400 
405  std::unique_ptr<TH2D> fSpectrumHist;
406 
411  std::vector<TimeFit> fTimeFits;
412 
428  enum class TimeGenSamplingMode { HISTOGRAM, UNIFORM_TIME, UNIFORM_ENERGY };
429 
433 
459  enum class PinchParamType { ALPHA, BETA };
460 
464 
474  // TODO: add information about the bin value units
479  // TODO: add a "fit"-format description here
480  enum class SpectrumFileFormat { RootTH2D, FIT };
481 
484 
489  TTree* fEventTree;
490 
492  uint_fast32_t fRunNumber;
494  uint_fast32_t fSubRunNumber;
496  uint_fast32_t fEventNumber;
497 
500  double fTNu;
501 
503  double fWeight;
504 
509 
512  unsigned int fNeutrinosPerEvent;
513 
516  double fFitEmin;
517 
520  double fFitEmax;
521 };
522 
523 //------------------------------------------------------------------------------
525  : EDProducer{p.get_PSet()}
526  , fEvent(new marley::Event)
527  , fRunNumber(0)
528  , fSubRunNumber(0)
529  , fEventNumber(0)
530  , fTNu(0.)
532 {
533  // Configure the module (including MARLEY itself) using the FHiCL parameters
534  this->reconfigure(p);
535 
536  // Create a ROOT TTree using the TFileService that will store the MARLEY
537  // event objects (useful for debugging purposes)
539  fEventTree = tfs->make<TTree>("MARLEY_event_tree", "Neutrino events generated by MARLEY");
540  fEventTree->Branch("event", "marley::Event", fEvent.get());
541 
542  // Add branches that give the art::Event run, subrun, and event numbers for
543  // easy match-ups between the MARLEY and art TTrees. All three are recorded
544  // as 32-bit unsigned integers.
545  fEventTree->Branch("run_number", &fRunNumber, "run_number/i");
546  fEventTree->Branch("subrun_number", &fSubRunNumber, "subrun_number/i");
547  fEventTree->Branch("event_number", &fEventNumber, "event_number/i");
548  fEventTree->Branch("tSN", &fTNu, "tSN/D");
549  fEventTree->Branch("weight", &fWeight, "weight/D");
550 
551  produces<std::vector<simb::MCTruth>>();
552  produces<std::vector<sim::SupernovaTruth>>();
553  produces<art::Assns<simb::MCTruth, sim::SupernovaTruth>>();
554  produces<sumdata::RunData, art::InRun>();
555 }
556 
557 //------------------------------------------------------------------------------
559 {
561  run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()), art::fullRun());
562 }
563 
564 //------------------------------------------------------------------------------
566  sim::SupernovaTruth& sn_truth,
567  const TLorentzVector& vertex_pos)
568 {
569  // Get a reference to the generator object created by MARLEY (we'll need
570  // to do a few fancy things with it other than just creating events)
571  marley::Generator& gen = fMarleyHelper->get_generator();
572 
574  // Generate a MARLEY event using the time-integrated spectrum
575  // (the generator was already configured to use it by reconfigure())
576  mc_truth = fMarleyHelper->create_MCTruth(vertex_pos, fEvent.get());
577 
578  // Find the time distribution corresponding to the selected energy bin
579  double E_nu = fEvent->projectile().total_energy();
580  int E_bin_index = fSpectrumHist->GetYaxis()->FindBin(E_nu);
581  TH1D* t_hist = fSpectrumHist->ProjectionX("dummy_time_hist", E_bin_index, E_bin_index);
582  double* time_bin_weights = t_hist->GetArray();
583 
584  // Sample a time bin from the distribution
585  std::discrete_distribution<int> time_dist;
586  std::discrete_distribution<int>::param_type time_params(
587  time_bin_weights, &(time_bin_weights[t_hist->GetNbinsX() + 1]));
588  int time_bin_index = gen.sample_from_distribution(time_dist, time_params);
589 
590  // Sample a time uniformly from within the selected time bin
591  double t_min = t_hist->GetBinLowEdge(time_bin_index);
592  double t_max = t_min + t_hist->GetBinWidth(time_bin_index);
593  // sample a time on [ t_min, t_max )
594  fTNu = gen.uniform_random_double(t_min, t_max, false);
595  // Unbiased sampling was used, so assign this neutrino vertex a
596  // unit statistical weight
597  fWeight = ONE;
598 
600  }
601 
603  // Generate a MARLEY event using the time-integrated spectrum
604  // (the generator was already configured to use it by reconfigure())
605  mc_truth = fMarleyHelper->create_MCTruth(vertex_pos, fEvent.get());
606 
607  // Sample a time uniformly
608  TAxis* time_axis = fSpectrumHist->GetXaxis();
609  // underflow bin has index zero
610  double t_min = time_axis->GetBinLowEdge(1);
611  double t_max = time_axis->GetBinLowEdge(time_axis->GetNbins() + 1);
612  // sample a time on [ t_min, t_max )
613  fTNu = gen.uniform_random_double(t_min, t_max, false);
614 
615  // Get the value of the true dependent probability density (probability
616  // of the sampled time given the sampled energy) to use as a biasing
617  // correction in the neutrino vertex weight.
618  double E_nu = fEvent->projectile().total_energy();
619  int E_bin_index = fSpectrumHist->GetYaxis()->FindBin(E_nu);
620  TH1D* t_hist = fSpectrumHist->ProjectionX("dummy_time_hist", E_bin_index, E_bin_index);
621  int t_bin_index = t_hist->FindBin(fTNu);
622  double weight_bias = t_hist->GetBinContent(t_bin_index) * (t_max - t_min) /
623  (t_hist->Integral() * t_hist->GetBinWidth(t_bin_index));
624 
625  fWeight = weight_bias;
626 
628  }
629 
631  // Select a time bin using the energy-integrated spectrum
632  TH1D* t_hist = fSpectrumHist->ProjectionX("dummy_time_hist");
633  double* time_bin_weights = t_hist->GetArray();
634 
635  // Sample a time bin from the distribution
636  std::discrete_distribution<int> time_dist;
637  std::discrete_distribution<int>::param_type time_params(
638  time_bin_weights, &(time_bin_weights[t_hist->GetNbinsX() + 1]));
639  int time_bin_index = gen.sample_from_distribution(time_dist, time_params);
640 
641  // Sample a time uniformly from within the selected time bin
642  double t_min = t_hist->GetBinLowEdge(time_bin_index);
643  double t_max = t_min + t_hist->GetBinWidth(time_bin_index);
644  // sample a time on [ t_min, t_max )
645  fTNu = gen.uniform_random_double(t_min, t_max, false);
646 
647  // Sample an energy uniformly over the entire allowed range
648  // underflow bin has index zero
649  TAxis* energy_axis = fSpectrumHist->GetYaxis();
650  double E_min = energy_axis->GetBinLowEdge(1);
651  double E_max = energy_axis->GetBinLowEdge(energy_axis->GetNbins() + 1);
652 
653  double E_nu = std::numeric_limits<double>::lowest();
654 
655  // Generate a MARLEY event using a uniformly sampled energy
656  mc_truth = make_uniform_energy_mctruth(E_min, E_max, E_nu, vertex_pos);
657 
658  // Get the value of the true dependent probability density (probability
659  // of the sampled energy given the sampled time) to use as a biasing
660  // correction in the neutrino vertex weight.
661  //
662  // Get a 1D projection of the energy spectrum for the sampled time bin
663  TH1D* energy_spect = fSpectrumHist->ProjectionY("energy_spect", time_bin_index, time_bin_index);
664 
665  // Create a new MARLEY neutrino source object using this projection (this
666  // will create a normalized probability density that we can use) and load
667  // it into the generator.
668  auto nu_source =
669  marley_root::make_root_neutrino_source(marley_utils::ELECTRON_NEUTRINO, energy_spect);
670  double new_source_E_min = nu_source->get_Emin();
671  double new_source_E_max = nu_source->get_Emax();
672  gen.set_source(std::move(nu_source));
673  // NOTE: The marley::Generator object normalizes the E_pdf to unity
674  // automatically, but just in case, we redo it here.
675  double E_pdf_integ = integrate([&gen](double E_nu) -> double { return gen.E_pdf(E_nu); },
676  new_source_E_min,
677  new_source_E_max);
678 
679  // Compute the likelihood ratio that we need to bias the neutrino vertex
680  // weight
681  double weight_bias = (gen.E_pdf(E_nu) / E_pdf_integ) * (E_max - E_min);
682 
683  fWeight = weight_bias;
684 
686  }
687 
688  else {
689  throw cet::exception("MARLEYTimeGen") << "Unrecognized sampling mode"
690  << " encountered in evgen::MarleyTimeGen::produce()";
691  }
692 }
693 
694 //------------------------------------------------------------------------------
696 {
698 
699  // Get the run, subrun, and event numbers from the current art::Event
700  fRunNumber = e.run();
701  fSubRunNumber = e.subRun();
702  fEventNumber = e.event();
703 
704  // Prepare associations and vectors of truth objects that will be produced
705  // and loaded into the current art::Event
706  std::unique_ptr<std::vector<simb::MCTruth>> truthcol(new std::vector<simb::MCTruth>);
707 
708  std::unique_ptr<std::vector<sim::SupernovaTruth>> sn_truthcol(
709  new std::vector<sim::SupernovaTruth>);
710 
711  std::unique_ptr<art::Assns<simb::MCTruth, sim::SupernovaTruth>> truth_assns(
713 
714  // Create temporary truth objects that we will use to load the event
715  simb::MCTruth truth;
716  sim::SupernovaTruth sn_truth;
717 
718  for (unsigned int n = 0; n < fNeutrinosPerEvent; ++n) {
719 
720  // Sample a primary vertex location for this event
721  TLorentzVector vertex_pos = fVertexSampler->sample_vertex_pos(*geo);
722 
723  // Reset the neutrino's time-since-supernova to a bogus value (for now)
724  fTNu = std::numeric_limits<double>::lowest();
725 
727  create_truths_th2d(truth, sn_truth, vertex_pos);
728  }
730  create_truths_time_fit(truth, sn_truth, vertex_pos);
731  }
732  else {
733  throw cet::exception("MARLEYTimeGen")
734  << "Invalid spectrum file"
735  << " format encountered in evgen::MarleyTimeGen::produce()";
736  }
737 
738  // Write the marley::Event object to the event tree
739  fEventTree->Fill();
740 
741  // Add the truth objects to the appropriate vectors
742  truthcol->push_back(truth);
743 
744  sn_truthcol->push_back(sn_truth);
745 
746  // Associate the last entries in each of the truth object vectors (the
747  // truth objects that were just created for the current neutrino vertex)
748  // with each other
749  truth_assns->addSingle(art::PtrMaker<simb::MCTruth>{e}(truthcol->size() - 1),
750  art::PtrMaker<sim::SupernovaTruth>{e}(sn_truthcol->size() - 1));
751  }
752 
753  // Load the completed truth object vectors and associations into the event
754  e.put(std::move(truthcol));
755 
756  e.put(std::move(sn_truthcol));
757 
758  e.put(std::move(truth_assns));
759 }
760 
761 //------------------------------------------------------------------------------
763 {
764  const auto& seed_service = art::ServiceHandle<rndm::NuRandomService>();
765  const auto& geom_service = art::ServiceHandle<geo::Geometry const>();
766 
767  // Create a new evgen::ActiveVolumeVertexSampler object based on the current
768  // configuration
769  fVertexSampler = std::make_unique<evgen::ActiveVolumeVertexSampler>(
770  p().vertex_, *seed_service, *geom_service, "MARLEY_Vertex_Sampler");
771 
772  // Create a new marley::Generator object based on the current configuration
773  const fhicl::ParameterSet marley_pset =
774  p.get_PSet().get<fhicl::ParameterSet>("marley_parameters");
775  fMarleyHelper = std::make_unique<MARLEYHelper>(marley_pset, *seed_service, "MARLEY");
776 
777  // Get the number of neutrino vertices per event from the FHiCL parameters
778  fNeutrinosPerEvent = p().nu_per_event_();
779 
780  // Determine the current sampling mode from the FHiCL parameters
781  const std::string& samp_mode_str = p().sampling_mode_();
782  if (samp_mode_str == "histogram")
784  else if (samp_mode_str == "uniform time")
786  else if (samp_mode_str == "uniform energy")
788  else
789  throw cet::exception("MARLEYTimeGen") << "Invalid sampling mode \"" << samp_mode_str << "\""
790  << " specified for the MARLEYTimeGen module.";
791 
792  MF_LOG_INFO("MARLEYTimeGen") << fNeutrinosPerEvent << " neutrino vertices"
793  << " will be generated for each art::Event using the \""
794  << samp_mode_str << "\" sampling mode.";
795 
796  // Retrieve the time-dependent neutrino spectrum from the spectrum file.
797  // Use different methods depending on the file's format.
798  std::string spectrum_file_format = marley_utils::to_lowercase(p().spectrum_file_format_());
799 
800  if (spectrum_file_format == "th2d")
802  else if (spectrum_file_format == "fit") {
804 
805  std::string pinch_type;
806  if (!p().pinching_parameter_type_(pinch_type)) {
807  throw cet::exception("MARLEYTimeGen") << "Missing pinching parameter"
808  << " type for a \"fit\" format spectrum file";
809  }
810 
811  marley_utils::to_lowercase_inplace(pinch_type);
812  if (pinch_type == "alpha")
814  else if (pinch_type == "beta")
816  else
817  throw cet::exception("MARLEYTimeGen") << "Invalid pinching parameter type \"" << pinch_type
818  << "\" specified for the MARLEYTimeGen module.";
819 
820  if (!p().fit_Emin_(fFitEmin))
821  throw cet::exception("MARLEYTimeGen")
822  << "Missing minimum energy for a \"fit\" format spectrum"
823  << " used by the MARLEYTimeGen module.";
824 
825  if (!p().fit_Emax_(fFitEmax))
826  throw cet::exception("MARLEYTimeGen")
827  << "Missing maximum energy for a \"fit\" format spectrum"
828  << " used by the MARLEYTimeGen module.";
829 
830  if (fFitEmax < fFitEmin)
831  throw cet::exception("MARLEYTimeGen")
832  << "Maximum energy is less than the minimum energy for"
833  << " a \"fit\" format spectrum used by the MARLEYTimeGen module.";
834  }
835  else
836  throw cet::exception("MARLEYTimeGen")
837  << "Invalid spectrum file format \"" << p().spectrum_file_format_()
838  << "\" specified for the MARLEYTimeGen module.";
839 
840  // Determine the full file name (including path) of the spectrum file
841  std::string full_spectrum_file_name = fMarleyHelper->find_file(p().spectrum_file_(), "spectrum");
842 
843  marley::Generator& gen = fMarleyHelper->get_generator();
844 
846 
847  // Retrieve the time-dependent neutrino flux from a ROOT file
848  std::unique_ptr<TFile> spectrum_file =
849  std::make_unique<TFile>(full_spectrum_file_name.c_str(), "read");
850  TH2D* temp_h2 = nullptr;
851  std::string namecycle;
852  if (!p().namecycle_(namecycle)) {
853  throw cet::exception("MARLEYTimeGen") << "Missing namecycle for"
854  << " a TH2D spectrum file";
855  }
856 
857  spectrum_file->GetObject(namecycle.c_str(), temp_h2);
858  fSpectrumHist.reset(temp_h2);
859 
860  // Disassociate the TH2D from its parent TFile. If we fail to do this,
861  // then ROOT will auto-delete the TH2D when the TFile goes out of scope.
862  fSpectrumHist->SetDirectory(nullptr);
863 
864  // Compute the flux-averaged total cross section using MARLEY. This will be
865  // used to compute neutrino vertex weights for the sim::SupernovaTruth
866  // objects.
867 
868  // Get a 1D projection of the energy spectrum (integrated over time)
869  TH1D* energy_spect = fSpectrumHist->ProjectionY("energy_spect");
870 
871  // Create a new MARLEY neutrino source object using this projection
872  // TODO: replace the hard-coded electron neutrino PDG code here (and in
873  // several other places in this source file) when you're ready to use
874  // MARLEY with multiple neutrino flavors
875  std::unique_ptr<marley::NeutrinoSource> nu_source =
876  marley_root::make_root_neutrino_source(marley_utils::ELECTRON_NEUTRINO, energy_spect);
877 
878  // Factor of hbar_c^2 converts from MeV^(-2) to fm^2
879  fFluxAveragedCrossSection = marley_utils::hbar_c2 * flux_averaged_total_xs(*nu_source, gen);
880 
881  // For speed, sample energies first whenever possible (and then sample from
882  // an energy-dependent timing distribution). This avoids unnecessary calls
883  // to MARLEY to change the energy spectrum.
886  gen.set_source(std::move(nu_source));
887  }
888 
889  } // spectrum_file_format == "th2d"
890 
892 
893  // Clear out the old parameterized spectrum, if one exists
894  fTimeFits.clear();
895 
896  std::ifstream fit_file(full_spectrum_file_name);
897  std::string line;
898 
899  bool found_end = false;
900 
901  // current line number
902  int line_num = 0;
903  // number of lines checked in last call to marley_utils::get_next_line()
904  int lines_checked = 0;
905 
906  double old_time = std::numeric_limits<double>::lowest();
907 
908  while (line = marley_utils::get_next_line(fit_file, rx_comment_or_empty, false, lines_checked),
909  line_num += lines_checked,
910  !line.empty()) {
911  if (found_end) {
912  MF_LOG_WARNING("MARLEYTimeGen") << "Trailing content after last time"
913  << " bin found on line " << line_num
914  << " of the spectrum file " << full_spectrum_file_name;
915  }
916 
917  double time;
918  double Emean_nue, alpha_nue, luminosity_nue;
919  double Emean_nuebar, alpha_nuebar, luminosity_nuebar;
920  double Emean_nux, alpha_nux, luminosity_nux;
921  std::istringstream iss(line);
922  bool ok_first = static_cast<bool>(iss >> time);
923 
924  if (time <= old_time)
925  throw cet::exception("MARLEYTimeGen")
926  << "Time bin left edges given in the spectrum file must be"
927  << " strictly increasing. Invalid time bin value found on line " << line_num
928  << " of the spectrum file " << full_spectrum_file_name;
929  else
930  old_time = time;
931 
932  bool ok_rest = static_cast<bool>(iss >> Emean_nue >> alpha_nue >> luminosity_nue >>
933  Emean_nuebar >> alpha_nuebar >> luminosity_nuebar >>
934  Emean_nux >> alpha_nux >> luminosity_nux);
935 
936  if (ok_first) {
937  // We haven't reached the final bin, so add another time bin
938  // in the typical way.
939  if (ok_rest) {
940  fTimeFits.emplace_back(time,
941  Emean_nue,
942  alpha_nue,
943  luminosity_nue,
944  Emean_nuebar,
945  alpha_nuebar,
946  luminosity_nuebar,
947  Emean_nux,
948  alpha_nux,
949  luminosity_nux);
950  }
951  else {
952  make_final_timefit(time);
953  found_end = true;
954  }
955  }
956  else
957  throw cet::exception("MARLEYTimeGen")
958  << "Parse error on line " << line_num << " of the spectrum file "
959  << full_spectrum_file_name;
960  }
961 
962  if (!found_end) {
963 
964  size_t num_time_bins = fTimeFits.size();
965  if (num_time_bins < 2)
966  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 "
969  << " final bin.";
970 
971  // Guess that the width of the penultimate time bin and the width of
972  // the final time bin are the same
973  double delta_t_bin = fTimeFits.back().Time() - fTimeFits.at(num_time_bins - 2).Time();
974 
975  double last_bin_right_edge = fTimeFits.back().Time() + delta_t_bin;
976 
977  make_final_timefit(last_bin_right_edge);
978 
979  MF_LOG_WARNING("MARLEYTimeGen")
980  << "Missing right"
981  << " edge for the final time bin in the spectrum file " << full_spectrum_file_name
982  << ". Assuming a width of " << delta_t_bin << " s for the final bin.";
983  }
984 
985  // Compute the flux-averaged total cross section for the fitted spectrum.
986  // We will need this to compute neutrino vertex weights.
987  std::vector<std::unique_ptr<marley::NeutrinoSource>> fit_sources;
988  for (const auto& fit : fTimeFits) {
989  fit_sources.emplace_back(source_from_time_fit(fit));
990  }
991 
992  // TODO: add handling for non-nu_e neutrino types when suitable data become
993  // available in MARLEY
994  auto temp_source = std::make_unique<marley::FunctionNeutrinoSource>(
995  marley_utils::ELECTRON_NEUTRINO,
996  fFitEmin,
997  fFitEmax,
998  [&fit_sources, this](double E_nu) -> double {
999  double flux = 0.;
1000  for (size_t s = 0; s < fit_sources.size(); ++s) {
1001 
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(current_source->get_pid());
1005 
1006  double lum = params.Luminosity();
1007 
1008  // Skip entries with zero luminosity, since they won't contribute
1009  // anything to the overall integral. Skip negative luminosity ones as
1010  // well, just in case.
1011  if (lum <= 0.) continue;
1012 
1013  flux += lum * current_source->pdf(E_nu);
1014  }
1015  return flux;
1016  });
1017 
1018  double flux_integ = 0.;
1019  double tot_xs_integ = 0.;
1020  flux_averaged_total_xs(*temp_source, gen, flux_integ, tot_xs_integ);
1021 
1022  // Factor of hbar_c^2 converts from MeV^(-2) to fm^2
1023  fFluxAveragedCrossSection = marley_utils::hbar_c2 * tot_xs_integ / flux_integ;
1024 
1026 
1027  } // spectrum_file_format == "fit"
1028 
1029  else {
1030  throw cet::exception("MARLEYTimeGen")
1031  << "Unrecognized neutrino spectrum"
1032  << " file format \"" << p().spectrum_file_format_() << "\" encountered"
1033  << " in evgen::MarleyTimeGen::reconfigure()";
1034  }
1035 
1036  MF_LOG_INFO("MARLEYTimeGen") << "The flux-averaged total cross section"
1037  << " predicted by MARLEY for the current supernova spectrum is "
1038  << fFluxAveragedCrossSection << " fm^2";
1039 }
1040 
1041 //------------------------------------------------------------------------------
1043  sim::SupernovaTruth& sn_truth,
1044  const TLorentzVector& vertex_pos)
1045 {
1046  // Get a reference to the generator object created by MARLEY (we'll need
1047  // to do a few fancy things with it other than just creating events)
1048  marley::Generator& gen = fMarleyHelper->get_generator();
1049 
1050  // Initialize the time bin index to something absurdly large. This will help
1051  // us detect strange bugs that arise when it is sampled incorrectly.
1052  size_t time_bin_index = std::numeric_limits<size_t>::max();
1053 
1054  // Create an object to represent the discrete time distribution given in
1055  // the spectrum file. Use the luminosity for each bin as its sampling weight.
1056  // This distribution will actually be used to sample a neutrino arrival time
1057  // unless we're using the uniform time sampling mode, in which case it will
1058  // be used to help calculate the neutrino vertex weight.
1059  int source_pdg_code = gen.get_source().get_pid();
1060 
1061  const auto fit_params_begin =
1062  TimeFit::make_FitParameters_iterator(source_pdg_code, fTimeFits.begin());
1063  const auto fit_params_end =
1064  TimeFit::make_FitParameters_iterator(source_pdg_code, fTimeFits.end());
1065 
1066  const auto lum_begin = FitParameters::make_luminosity_iterator(fit_params_begin);
1067  const auto lum_end = FitParameters::make_luminosity_iterator(fit_params_end);
1068 
1069  std::discrete_distribution<size_t> time_dist(lum_begin, lum_end);
1070 
1073  time_bin_index = gen.sample_from_distribution(time_dist);
1074  }
1075 
1077  int last_time_index = 0;
1078  if (fTimeFits.size() > 0) last_time_index = fTimeFits.size() - 1;
1079  std::uniform_int_distribution<size_t> uid(0, last_time_index);
1080  // for c2: time_bin_index has already been declared
1081  time_bin_index = gen.sample_from_distribution(uid);
1082  }
1083 
1084  else {
1085  throw cet::exception("MARLEYTimeGen") << "Unrecognized sampling mode"
1086  << " encountered in evgen::MarleyTimeGen::produce()";
1087  }
1088 
1089  // Sample a time uniformly from within the selected time bin. Note that
1090  // the entries in fTimeFits use the time_ member to store the bin left
1091  // edges. The module creates fTimeFits in such a way that its last element
1092  // will always have luminosity_ == 0. (zero sampling weight), so we may
1093  // always add one to the sampled bin index without worrying about going
1094  // off the edge.
1095  double t_min = fTimeFits.at(time_bin_index).Time();
1096  double t_max = fTimeFits.at(time_bin_index + 1).Time();
1097  // sample a time on [ t_min, t_max )
1098  fTNu = gen.uniform_random_double(t_min, t_max, false);
1099 
1100  // Create a "beta-fit" neutrino source using the correct parameters for the
1101  // sampled time bin. This will be used to sample a neutrino energy unless
1102  // we're using the uniform time sampling mode. For uniform time sampling,
1103  // it will be used to determine the neutrino event weight.
1104  const auto& fit = fTimeFits.at(time_bin_index);
1105  std::unique_ptr<marley::NeutrinoSource> nu_source = source_from_time_fit(fit);
1106 
1109  // Replace the generator's old source with the new one for the current
1110  // time bin
1111  gen.set_source(std::move(nu_source));
1112 
1113  // Generate a MARLEY event using the updated source
1114  mc_truth = fMarleyHelper->create_MCTruth(vertex_pos, fEvent.get());
1115 
1117  // Unbiased sampling creates neutrino vertices with unit weight
1118  fWeight = ONE;
1120  }
1121  else {
1122  // fSamplingMode == TimeGenSamplingMode::UNIFORM_TIME
1123 
1124  // Multiply by the likelihood ratio in order to correct for uniform
1125  // time sampling if we're using that biasing method
1126  double weight_bias = time_dist.probabilities().at(time_bin_index) / (t_max - t_min) *
1127  (fTimeFits.back().Time() - fTimeFits.front().Time());
1128 
1129  fWeight = weight_bias;
1131  }
1132  }
1133 
1135  double E_nu = std::numeric_limits<double>::lowest();
1136  mc_truth = make_uniform_energy_mctruth(fFitEmin, fFitEmax, E_nu, vertex_pos);
1137 
1138  // Get the value of the true dependent probability density (probability
1139  // of the sampled energy given the sampled time) to use as a biasing
1140  // correction in the neutrino vertex weight.
1141 
1142  // Load the generator with the neutrino source that represents the
1143  // true (i.e., unbiased) energy probability distribution. This will
1144  // create a normalized probability density that we can use to determine
1145  // the neutrino vertex weight.
1146  double nu_source_E_min = nu_source->get_Emin();
1147  double nu_source_E_max = nu_source->get_Emax();
1148  gen.set_source(std::move(nu_source));
1149 
1150  // NOTE: The marley::Generator object normalizes the E_pdf to unity
1151  // automatically, but just in case, we redo it here.
1152  double E_pdf_integ = integrate(
1153  [&gen](double E_nu) -> double { return gen.E_pdf(E_nu); }, nu_source_E_min, nu_source_E_max);
1154 
1155  // Compute the likelihood ratio that we need to bias the neutrino vertex
1156  // weight
1157  double weight_bias = (gen.E_pdf(E_nu) / E_pdf_integ) * (fFitEmax - fFitEmin);
1158 
1159  fWeight = weight_bias;
1161  }
1162 
1163  else {
1164  throw cet::exception("MARLEYTimeGen") << "Unrecognized sampling mode"
1165  << " encountered in evgen::MarleyTimeGen::produce()";
1166  }
1167 }
1168 
1169 //------------------------------------------------------------------------------
1170 std::unique_ptr<marley::NeutrinoSource> evgen::MarleyTimeGen::source_from_time_fit(
1171  const TimeFit& fit)
1172 {
1173  // Create a "beta-fit" neutrino source using the given fit parameters.
1174 
1175  // The two common fitting schemes (alpha and beta) differ in their
1176  // definitions by \beta = \alpha + 1.
1177  // TODO: add handling for non-nu_e neutrino types
1178  const FitParameters& nue_parameters = fit.GetFitParameters(marley_utils::ELECTRON_NEUTRINO);
1179 
1180  double beta = nue_parameters.Alpha();
1182  beta += 1.;
1183  else if (fPinchType != PinchParamType::BETA) {
1184  throw cet::exception("MARLEYTimeGen")
1185  << "Unreognized pinching parameter"
1186  << " type encountered in evgen::MarleyTimeGen::source_from_time_fit()";
1187  }
1188 
1189  // Create the new source
1190  std::unique_ptr<marley::NeutrinoSource> nu_source =
1191  std::make_unique<marley::BetaFitNeutrinoSource>(
1192  marley_utils::ELECTRON_NEUTRINO, fFitEmin, fFitEmax, nue_parameters.Emean(), beta);
1193 
1194  return nu_source;
1195 }
1196 
1197 //------------------------------------------------------------------------------
1199  double E_max,
1200  double& E_nu,
1201  const TLorentzVector& vertex_pos)
1202 {
1203  marley::Generator& gen = fMarleyHelper->get_generator();
1204 
1205  // Sample an energy uniformly over the entire allowed range
1206  double total_xs;
1207  int j = 0;
1208  do {
1209  // We have to check that the cross section is nonzero for the sampled
1210  // energy (otherwise we'll generate an unphysical event). However, if the
1211  // user has given us a histogram that is below threshold, the
1212  // program could get stuck here endlessly, sampling rejected energy
1213  // after rejected energy. Just in case, we cap the total number of tries
1214  // and quit if things don't work out.
1215  if (j >= MAX_UNIFORM_ENERGY_ITERATIONS) {
1216  throw cet::exception("MARLEYTimeGen")
1217  << "Exceeded the maximum of " << MAX_UNIFORM_ENERGY_ITERATIONS
1218  << " while attempting to sample"
1219  << " a neutrino energy uniformly.";
1220  }
1221  // Sample an energy uniformly on [ E_min, E_max )
1222  E_nu = gen.uniform_random_double(E_min, E_max, false);
1223  total_xs = 0.;
1224  // Check that at least one defined reaction has a non-zero total
1225  // cross section at the sampled energy. If this is not the case, try
1226  // again.
1227  for (const auto& react : gen.get_reactions()) {
1228  total_xs += react->total_xs(marley_utils::ELECTRON_NEUTRINO, E_nu);
1229  }
1230 
1231  ++j;
1232  } while (total_xs <= 0.);
1233 
1234  // Replace the existing neutrino source with a monoenergetic one at the
1235  // neutrino energy that was just sampled above
1236  std::unique_ptr<marley::NeutrinoSource> nu_source =
1237  std::make_unique<marley::MonoNeutrinoSource>(marley_utils::ELECTRON_NEUTRINO, E_nu);
1238  gen.set_source(std::move(nu_source));
1239 
1240  // Generate a MARLEY event using the new monoenergetic source
1241  auto mc_truth = fMarleyHelper->create_MCTruth(vertex_pos, fEvent.get());
1242 
1243  return mc_truth;
1244 }
1245 
1246 //------------------------------------------------------------------------------
1248 {
1249  // The final time bin has zero luminosity, and therefore zero sampling
1250  // weight. We need it to be present so that the last nonzero weight bin
1251  // has a right edge.
1252  fTimeFits.emplace_back(time, 0., 0., 0., 0., 0., 0., 0., 0., 0.);
1253 }
1254 
1255 //------------------------------------------------------------------------------
1257 {
1258  // To make a histogram with variable size bins, ROOT needs the bin
1259  // low edges to be contiguous in memory. This is not true of the
1260  // stored times in fTimeFits, so we'll need to make a temporary copy
1261  // of them.
1262  std::vector<double> temp_times;
1263  for (const auto& fit : fTimeFits)
1264  temp_times.push_back(fit.Time());
1265 
1266  // If, for some reason, there are fewer than two time bins, just return
1267  // without making the histograms.
1268  // TODO: consider throwing an exception here
1269  if (temp_times.size() < 2) return;
1270 
1271  // Get the number of time bins
1272  int num_bins = temp_times.size() - 1;
1273 
1274  // Create some ROOT TH1D objects using the TFileService. These will store
1275  // the number of emitted neutrinos of each type in each time bin
1277  TH1D* nue_hist =
1278  tfs->make<TH1D>("NueEmission",
1279  "Number of emitted #nu_{e}; time (s); number of neutrinos in time bin",
1280  num_bins,
1281  temp_times.data());
1282  TH1D* nuebar_hist =
1283  tfs->make<TH1D>("NuebarEmission",
1284  "Number of emitted #bar{#nu}_{e}; time (s); number of neutrinos in"
1285  " time bin",
1286  num_bins,
1287  temp_times.data());
1288  TH1D* nux_hist =
1289  tfs->make<TH1D>("NuxEmission",
1290  "Number of emitted #nu_{x}; time (s); number of neutrinos in time bin",
1291  num_bins,
1292  temp_times.data());
1293 
1294  // Load the histograms with the emitted neutrino counts
1295  for (size_t b = 1; b < temp_times.size(); ++b) {
1296  const TimeFit& current_fit = fTimeFits.at(b - 1);
1297  const TimeFit& next_fit = fTimeFits.at(b);
1298  double bin_deltaT = next_fit.Time() - current_fit.Time();
1299 
1300  const auto& nue_params = current_fit.GetFitParameters(marley_utils::ELECTRON_NEUTRINO);
1301  const auto& nuebar_params = current_fit.GetFitParameters(marley_utils::ELECTRON_ANTINEUTRINO);
1302  const auto& nux_params = current_fit.GetFitParameters(marley_utils::MUON_NEUTRINO);
1303 
1304  // Convert from bin luminosity to number of neutrinos by
1305  // multiplying by the bin time interval and dividing by the
1306  // mean neutrino energy
1307  double num_nue = 0.;
1308  double num_nuebar = 0.;
1309  double num_nux = 0.;
1310  if (nue_params.Emean() != 0.)
1311  num_nue = nue_params.Luminosity() * bin_deltaT / (nue_params.Emean() * MeV_to_erg);
1312  if (nuebar_params.Emean() != 0.)
1313  num_nuebar = nuebar_params.Luminosity() * bin_deltaT / (nuebar_params.Emean() * MeV_to_erg);
1314  if (nux_params.Emean() != 0.)
1315  num_nux = nux_params.Luminosity() * bin_deltaT / (nux_params.Emean() * MeV_to_erg);
1316 
1317  nue_hist->SetBinContent(b, num_nue);
1318  nuebar_hist->SetBinContent(b, num_nuebar);
1319  nux_hist->SetBinContent(b, num_nux);
1320  }
1321 }
1322 
1323 //------------------------------------------------------------------------------
1324 // Anonymous namespace function definitions
1325 namespace {
1326 
1327  double flux_averaged_total_xs(marley::NeutrinoSource& nu_source,
1328  marley::Generator& gen,
1329  double& source_integ,
1330  double& tot_xs_integ)
1331  {
1332  // Get an integral of the source PDF (in case it isn't normalized to 1)
1333  source_integ = integrate([&nu_source](double E_nu) -> double { return nu_source.pdf(E_nu); },
1334  nu_source.get_Emin(),
1335  nu_source.get_Emax());
1336 
1337  tot_xs_integ = integrate(
1338  [&nu_source, &gen](double E_nu) -> double {
1339  double xs = 0.;
1340  for (const auto& react : gen.get_reactions()) {
1341  xs += react->total_xs(marley_utils::ELECTRON_NEUTRINO, E_nu);
1342  }
1343  return xs * nu_source.pdf(E_nu);
1344  },
1345  nu_source.get_Emin(),
1346  nu_source.get_Emax());
1347 
1348  return tot_xs_integ / source_integ;
1349  }
1350 
1351  double flux_averaged_total_xs(marley::NeutrinoSource& nu_source, marley::Generator& gen)
1352  {
1353  double dummy1, dummy2;
1354  return flux_averaged_total_xs(nu_source, gen, dummy1, dummy2);
1355  }
1356 
1357  double integrate(const std::function<double(double)>& f, double x_min, double x_max)
1358  {
1359  static marley::Integrator integrator(NUM_INTEGRATION_SAMPLING_POINTS);
1360  return integrator.num_integrate(f, x_min, x_max);
1361  }
1362 
1363 }
1364 
double fLuminosity
Luminosity (erg / s)
intermediate_table::iterator iterator
SubRunNumber_t subRun() const
Definition: Event.cc:35
SpectrumFileFormat
Enumerated type that defines the allowed neutrino spectrum input file formats.
virtual void produce(art::Event &e) override
LArSoft interface to the MARLEY (Model of Argon Reaction Low Energy Yields) supernova neutrino event ...
FitParameters fNuebarFitParams
Fitting parameters for electron antineutrinos in this time bin.
constexpr auto fullRun()
SpectrumFileFormat fSpectrumFileFormat
Format to assume for the neutrino spectrum input file.
uint_fast32_t fEventNumber
Event number from the art::Event being processed.
double Alpha() const
Pinching parameter (dimensionless)
Stores fitting parameters for all neutrino types from a single time bin in a "fit"-format spectrum fi...
TimeFit(double time, double Emean_nue, double alpha_nue, double lum_nue, double Emean_nuebar, double alpha_nuebar, double lum_nuebar, double Emean_nux, double alpha_nux, double lum_nux)
double fTime
Time bin low edge (s)
void create_truths_time_fit(simb::MCTruth &mc_truth, sim::SupernovaTruth &sn_truth, const TLorentzVector &vertex_pos)
Create simb::MCTruth and sim::SupernovaTruth objects using a neutrino spectrum described by a previou...
void set_Alpha(double alpha)
Set the pinching parameter.
virtual void reconfigure(const Parameters &p)
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
PinchParamType fPinchType
The pinching parameter convention to use when interpreting the time-dependent fits.
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Run.h:121
double fEmean
Mean neutrino energy (MeV)
FitParameters fNueFitParams
Fitting parameters for electron neutrinos in this time bin.
Stores parsed fit parameters from a single time bin and neutrino type in a "fit"-format spectrum file...
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 ...
Definition: Run.h:37
double fWeight
Statistical weight for the current MARLEY neutrino vertex.
TTree * fEventTree
The event TTree created by MARLEY.
double Time() const
Returns the low edge (in s) of the time bin that uses these fit parameters.
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
TFile f
Definition: plotHisto.C:6
double x_min
Definition: berger.C:15
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
void set_Luminosity(double lum)
Set the luminosity (erg / s)
uint_fast32_t fSubRunNumber
Subrun number from the art::Event being processed.
Arrival times were sampled uniformly.
Algorithm that samples vertex locations uniformly within the active volume of a detector. It is fully experiment-agnostic and multi-TPC aware.
uint_fast32_t fRunNumber
Run number from the art::Event being processed.
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...
FitParameters fNuxFitParams
Fitting parameters for non-electron-flavor neutrinos in this time bin.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
TimeGenSamplingMode
Enumerated type that defines the allowed ways that a neutrino&#39;s energy and arrival time may be sample...
static marley::IteratorToMember< It, double > make_luminosity_iterator(It it)
Converts an iterator that points to a FitParameters object into an iterator that points to that objec...
void create_truths_th2d(simb::MCTruth &mc_truth, sim::SupernovaTruth &sn_truth, const TLorentzVector &vertex_pos)
Create simb::MCTruth and sim::SupernovaTruth objects using spectrum information from a ROOT TH2D...
double fTNu
Time since the supernova core bounce for the current MARLEY neutrino vertex.
PinchParamType
Enumerated type that defines the pinching parameter conventions that are understood by this module...
void set_Emean(double Emean)
Set the mean neutrino energy (MeV)
virtual void beginRun(art::Run &run) override
static FitParameters TimeFit::* GetFitParametersMemberPointer(int pdg_code)
Helper function that returns a pointer-to-member for the FitParameters object appropriate for a given...
simb::MCTruth make_uniform_energy_mctruth(double E_min, double E_max, double &E_nu, const TLorentzVector &vertex_pos)
Creates a simb::MCTruth object using a uniformly-sampled neutrino energy.
double fFitEmax
Maximum neutrino energy to consider when using a "fit"-format spectrum file.
EventNumber_t event() const
Definition: Event.cc:41
static marley::IteratorToMember< It, FitParameters > make_FitParameters_iterator(int pdg_code, It iterator)
Converts an iterator that points to a TimeFit object into an iterator that points to the appropriate ...
MarleyTimeGen(const Parameters &p)
const FitParameters & GetFitParameters(int pdg_code) const
Retrieves fit parameters for a specific neutrino type for this time bin.
FitParameters(double Emean, double alpha, double luminosity)
auto const & get_PSet() const
Definition: ProducerTable.h:47
#define MF_LOG_INFO(category)
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
double Luminosity() const
Luminosity (erg / s)
std::unique_ptr< TH2D > fSpectrumHist
ROOT TH2D that contains the time-dependent spectrum to use when sampling neutrino times and energies...
std::unique_ptr< marley::Event > fEvent
unique_ptr to the current event created by MARLEY
double x_max
Definition: berger.C:16
unsigned int fNeutrinosPerEvent
The number of MARLEY neutrino vertices to generate in each art::Event.
Stores extra MC truth information that is recorded when generating events using a time-dependent supe...
Collection of configuration parameters for the module.
Sample directly from cross-section weighted spectrum.
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...
Char_t n[5]
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
std::vector< TimeFit > fTimeFits
Vector that contains the fit parameter information for each time bin when using a "fit"-format spectr...
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
Definition: GeometryCore.h:203
Event generator information.
Definition: MCTruth.h:32
#define MF_LOG_WARNING(category)
void make_nu_emission_histograms() const
Makes ROOT histograms showing the emitted neutrinos in each time bin when using a "fit"-format spectr...
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.cc:29
Namespace collecting geometry-related classes utilities.
Event Generation using GENIE, cosmics or single particles.
Neutrino energies were sampled uniformly.
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
double Emean() const
Mean neutrino energy (MeV)