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