LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
MARLEYHelper.h
Go to the documentation of this file.
1 
9 #ifndef LARSIM_ALGORITHMS_MARLEYGENERATOR_H
10 #define LARSIM_ALGORITHMS_MARLEYGENERATOR_H
11 
12 // standard library includes
13 #include <array>
14 #include <memory>
15 #include <sstream>
16 #include <string>
17 #include <vector>
18 
19 // framework includes
20 #include "fhiclcpp/ParameterSet.h"
21 #include "fhiclcpp/types/Atom.h"
26 #include "fhiclcpp/types/Table.h"
30 
31 // art extensions
33 
34 // LArSoft includes
37 
38 // ROOT includes
39 #include "TLorentzVector.h"
40 
41 // MARLEY includes
42 #include "marley/Generator.hh"
43 #include "marley/JSON.hh"
44 #include "marley/Particle.hh"
45 
46 namespace evgen {
47 
48  class MARLEYHelper {
49 
50  public:
51 
52  using Name = fhicl::Name;
54 
58  struct Source_Config {
60  Name("type"),
61  Comment("Type of neutrino source for MARLEY to use")
62  };
63 
65  Name("neutrino"),
66  Comment("Kind of neutrino (flavor, matter/antimatter) that the"
67  " neutrino source produces")
68  };
69 
71  Name("Emin"),
72  Comment("Minimum energy (MeV) of the neutrinos produced by this"
73  " source"),
74  [this]() -> bool {
75  auto type = type_();
76  return (type == "fermi-dirac") || (type == "beta-fit" );
77  }
78  };
79 
81  Name("Emax"),
82  Comment("Maximum energy (MeV) of the neutrinos produced by this"
83  " source"),
84  [this]() -> bool {
85  auto type = type_();
86  return (type == "fermi-dirac") || (type == "beta-fit" )
87  || (type == "histogram");
88  }
89  };
90 
92  Name("temperature"),
93  Comment("Effective temperature for the Fermi-Dirac distribution"),
94  [this]() -> bool {
95  auto type = type_();
96  return (type == "fermi-dirac");
97  }
98  };
99 
101  Name("eta"),
102  Comment("Pinching parameter for the Fermi-Dirac distribution"),
103  [this]() -> bool {
104  auto type = type_();
105  return (type == "fermi-dirac");
106  }
107  };
108 
110  Name("energy"),
111  Comment("Energy (MeV) of the neutrinos produced by a monoenergetic"
112  " source"),
113  [this]() -> bool {
114  auto type = type_();
115  return (type == "monoenergetic");
116  }
117  };
118 
120  Name("Emean"),
121  Comment("Mean energy (MeV) of the neutrinos produced by a beta-fit"
122  " source"),
123  [this]() -> bool {
124  auto type = type_();
125  return (type == "beta-fit");
126  }
127  };
128 
130  Name("beta"),
131  Comment("Pinching parameter for a beta-fit source"),
132  [this]() -> bool {
133  auto type = type_();
134  return (type == "beta-fit");
135  }
136  };
137 
139  Name("E_bin_lefts"),
140  Comment("Left edges for each energy bin in the histogram"),
141  [this]() -> bool {
142  auto type = type_();
143  return type == "histogram";
144  }
145  };
146 
148  Name("weights"),
149  Comment("Weights for each energy bin in the histogram"),
150  [this]() -> bool {
151  auto type = type_();
152  return type == "histogram";
153  }
154  };
155 
157  Name("energies"),
158  Comment("Energies (MeV) for each grid point"),
159  [this]() -> bool {
160  auto type = type_();
161  return type == "grid";
162  }
163  };
164 
166  Name("prob_densities"),
167  Comment("Probability densities for each grid point"),
168  [this]() -> bool {
169  auto type = type_();
170  return type == "grid";
171  }
172  };
173 
175  Name("rule"),
176  Comment("Interpolation rule for computing probability densities"
177  " between grid points. Allowed values include \"linlin\","
178  " \"linlog\", \"loglin\", \"loglog\", and \"constant\""),
179  [this]() -> bool {
180  auto type = type_();
181  return type == "grid";
182  }
183  };
184 
186  Name("tfile"),
187  Comment("Name of the ROOT file that contains a TH1 or TGraph neutrino"
188  " source spectrum"),
189  [this]() -> bool {
190  auto type = type_();
191  return (type == "th1") || (type == "tgraph");
192  }
193  };
194 
196  Name("namecycle"),
197  Comment("Namecycle of the ROOT TH1 or TGraph to use"),
198  [this]() -> bool {
199  auto type = type_();
200  return (type == "th1") || (type == "tgraph");
201  }
202  };
203 
204  }; // struct Source_Config
205 
208  struct Config {
209 
211  Name("seed"),
212  Comment("Seed used for the MARLEY generator")
213  };
214 
216  Name("direction"),
217  Comment("3-vector that points in the direction of motion of the"
218  " incident neutrinos"),
219  // for c2: need double braces
220  std::array<double, 3> {{ 0., 0., 1. }} // default value
221  };
222 
224  Name("reactions"),
225  Comment("List of matrix element data files to use to define reactions"
226  " in MARLEY")
227  };
228 
230  Name("structure"),
231  Comment("List of TALYS format nuclear structure data files to use"
232  " in MARLEY")
233  };
234 
236  Name("source"),
237  Comment("Neutrino source configuration")
238  };
239 
240  }; // struct Config
241 
242  // Configuration-checking constructors
244  rndm::NuRandomService& rand_service,
245  const std::string& generator_name);
246 
248  rndm::NuRandomService& rand_service, const std::string& generator_name)
249  : MARLEYHelper(fhicl::Table<Config>(pset, {}),
250  rand_service, generator_name) {}
251 
252  void reconfigure(const fhicl::Table<Config>& conf);
253 
254  // If a non-null marley::Event* is supplied, the marley::Event
255  // object corresponding to the generated MCTruth object is loaded
256  // into the target of the pointer.
257  simb::MCTruth create_MCTruth(const TLorentzVector& vtx_pos,
258  marley::Event* marley_event = nullptr);
259 
260  marley::Generator& get_generator() { return *fMarleyGenerator; }
261  const marley::Generator& get_generator() const
262  { return *fMarleyGenerator; }
263 
264  std::string find_file(const std::string& fileName,
265  const std::string& fileType);
266 
267  protected:
268 
269  template <typename T> marley::JSON fhicl_atom_to_json(
270  const fhicl::Atom<T>* atom)
271  {
272  return marley::JSON(atom->operator()());
273  }
274 
275  template <typename T> marley::JSON fhicl_optional_atom_to_json(
276  const fhicl::OptionalAtom<T>* opt_atom)
277  {
278  T value;
279  if (opt_atom->operator()(value)) return marley::JSON(value);
280  // Return a null JSON object if the fhicl::OptionalAtom wasn't used
281  else return marley::JSON();
282  }
283 
284  template <typename S> marley::JSON fhicl_sequence_to_json(
285  const S* sequence)
286  {
287  marley::JSON array = marley::JSON::make(
288  marley::JSON::DataType::Array);
289 
290  for (size_t i = 0; i < sequence->size(); ++i) {
291  array.append(sequence->operator()(i));
292  }
293  return array;
294  }
295 
296  marley::JSON fhicl_parameter_to_json(
297  const fhicl::detail::ParameterBase* par);
298 
300  const std::vector<marley::Particle*>& particles,
301  const TLorentzVector& vtx_pos, bool track);
302 
303  void load_full_paths_into_json(marley::JSON& json,
304  const std::string& array_name);
305 
306  std::unique_ptr<marley::Generator> fMarleyGenerator;
307 
308  // name to use for this instance of MARLEYHelper
309  std::string fHelperName;
310 
311  // string stream used to capture logger output from MARLEY
312  // and redirect it to the LArSoft logger
313  std::stringstream fMarleyLogStream;
314 
315  // Loads ROOT dictionaries for the MARLEY Event and Particle classes.
316  // This allows a module to write the generated events to a TTree.
318 
319  }; // class evgen::MARLEYHelper
320 
321 } // namespace evgen
322 
323 #endif // LARSIM_ALGORITHMS_MARLEYGENERATOR_H
fhicl::Atom< double > temperature_
Definition: MARLEYHelper.h:91
fhicl::Atom< std::string > tfile_
Definition: MARLEYHelper.h:185
void add_marley_particles(simb::MCTruth &truth, const std::vector< marley::Particle * > &particles, const TLorentzVector &vtx_pos, bool track)
fhicl::Atom< std::string > namecycle_
Definition: MARLEYHelper.h:195
fhicl::Atom< std::string > type_
Definition: MARLEYHelper.h:59
fhicl::Atom< double > Emin_
Definition: MARLEYHelper.h:70
fhicl::Atom< std::string > neutrino_
Definition: MARLEYHelper.h:64
MARLEYHelper(const fhicl::ParameterSet &pset, rndm::NuRandomService &rand_service, const std::string &generator_name)
Definition: MARLEYHelper.h:247
marley::JSON fhicl_parameter_to_json(const fhicl::detail::ParameterBase *par)
simb::MCTruth create_MCTruth(const TLorentzVector &vtx_pos, marley::Event *marley_event=nullptr)
fhicl::Atom< double > Emean_
Definition: MARLEYHelper.h:119
fhicl::Sequence< double > energies_
Definition: MARLEYHelper.h:156
marley::JSON fhicl_optional_atom_to_json(const fhicl::OptionalAtom< T > *opt_atom)
Definition: MARLEYHelper.h:275
Particle class.
marley::JSON fhicl_atom_to_json(const fhicl::Atom< T > *atom)
Definition: MARLEYHelper.h:269
std::stringstream fMarleyLogStream
Definition: MARLEYHelper.h:313
fhicl::OptionalAtom< double > beta_
Definition: MARLEYHelper.h:129
fhicl::Sequence< double > weights_
Definition: MARLEYHelper.h:147
std::unique_ptr< marley::Generator > fMarleyGenerator
Definition: MARLEYHelper.h:306
std::string fHelperName
Definition: MARLEYHelper.h:309
fhicl::Atom< double > Emax_
Definition: MARLEYHelper.h:80
std::string find_file(const std::string &fileName, const std::string &fileType)
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
fhicl::Atom< double > energy_
Definition: MARLEYHelper.h:109
parameter set interface
fhicl::Atom< std::string > rule_
Definition: MARLEYHelper.h:174
fhicl::Sequence< double > prob_densities_
Definition: MARLEYHelper.h:165
fhicl::Name Name
Definition: MARLEYHelper.h:52
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
void reconfigure(const fhicl::Table< Config > &conf)
fhicl::OptionalAtom< double > eta_
Definition: MARLEYHelper.h:100
std::string value(boost::any const &)
fhicl::Sequence< double > E_bin_lefts_
Definition: MARLEYHelper.h:138
const marley::Generator & get_generator() const
Definition: MARLEYHelper.h:261
Event generator information.
Definition: MCTruth.h:30
Float_t track
Definition: plot.C:34
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
marley::Generator & get_generator()
Definition: MARLEYHelper.h:260
Event Generation using GENIE, cosmics or single particles.
void load_full_paths_into_json(marley::JSON &json, const std::string &array_name)
MARLEYHelper(const fhicl::Table< Config > &conf, rndm::NuRandomService &rand_service, const std::string &generator_name)
fhicl::Comment Comment
Definition: MARLEYHelper.h:53
marley::JSON fhicl_sequence_to_json(const S *sequence)
Definition: MARLEYHelper.h:284