10 #include "cetlib_except/exception.h" 17 #include "TInterpreter.h" 21 #include "marley/Event.hh" 22 #include "marley/RootJSONConfig.hh" 27 constexpr
double MeV_to_GeV = 1
e-3;
34 : fHelperName(helper_name)
51 auto seed =
static_cast<uint_fast64_t
>(lar_seed);
66 uint_fast64_t marley_cast_seed =
static_cast<uint_fast64_t
>(marley_seed);
81 const std::vector<marley::Particle*>& particles,
82 const TLorentzVector& vtx_pos,
bool track)
86 for (
const marley::Particle* p : particles) {
91 int pdg = p->pdg_code();
92 double mass = p->mass() * MeV_to_GeV;
93 double px = p->px() * MeV_to_GeV;
94 double py = p->py() * MeV_to_GeV;
95 double pz = p->pz() * MeV_to_GeV;
96 double E = p->total_energy() * MeV_to_GeV;
97 TLorentzVector mom(px, py, pz, E);
100 if (track) status = 1;
103 "MARLEY", -1 , mass, status);
112 const TLorentzVector& vtx_pos, marley::Event* marley_event)
125 const marley::Particle& nu =
event.projectile();
126 const marley::Particle& lep =
event.ejectile();
127 double qx = nu.px() - lep.px();
128 double qy = nu.py() - lep.py();
129 double qz = nu.pz() - lep.pz();
130 double Enu = nu.total_energy();
131 double Elep = lep.total_energy();
132 double Q2 = qx*qx + qy*qy + qz*qz - std::pow(Enu - Elep, 2);
136 double bjorken_x = Q2 / (2 *
event.target().mass() * (Enu - Elep));
137 double inelasticity_y = 1. - Elep / Enu;
143 const marley::Particle& res =
event.residue();
144 double hadronic_mass_W = res.mass() +
event.Ex();
151 marley_utils::get_nucleus_pid(18, 40),
152 marley_utils::NEUTRON,
154 hadronic_mass_W * MeV_to_GeV,
157 Q2 * std::pow(MeV_to_GeV, 2)
160 if (marley_event) *marley_event =
event;
177 const std::string& fileType)
179 cet::search_path searchPath(
"FW_SEARCH_PATH");
181 std::string fullName;
182 searchPath.find_file(fileName, fullName);
184 if (fullName.empty())
186 <<
"Cannot find MARLEY " << fileType <<
" data file '" 194 marley::JSON& json,
const std::string& key)
196 if ( json.has_key(key) ) {
198 marley::JSON&
value = json.at(key);
200 if ( value.is_array() ) {
203 for (
auto& element : value.array_range()) {
204 element =
find_file(element.to_string(), key);
208 else value =
find_file(value.to_string(), key);
211 <<
"\" key in the MARLEY parameters.";
228 if ( json.has_key(
"source") ) {
229 marley::JSON& source_object = json.at(
"source");
231 if ( source_object.has_key(
"tfile") ) {
238 " the JSON configuration\n" << json.dump_string() <<
'\n';
239 marley::RootJSONConfig config(json);
243 config.create_generator());
250 static bool already_loaded_marley_dict =
false;
252 if (already_loaded_marley_dict)
return;
263 if (gROOT->GetVersionInt() >= 60000) {
265 <<
" detected. Loading class information\nfrom headers" 266 <<
" \"marley/Particle.hh\" and \"marley/Event.hh\"";
267 TInterpreter::EErrorCode* ec =
new TInterpreter::EErrorCode();
268 gInterpreter->ProcessLine(
"#include \"marley/Particle.hh\"", ec);
270 <<
"Error loading MARLEY header Particle.hh. For MARLEY headers stored" 271 <<
" in /path/to/include/marley/, please add /path/to/include" 272 <<
" to your ROOT_INCLUDE_PATH environment variable and" 274 gInterpreter->ProcessLine(
"#include \"marley/Event.hh\"");
275 if (*ec != 0)
throw cet::exception(
"MARLEYHelper") <<
"Error loading" 276 <<
" MARLEY header Event.hh. For MARLEY headers stored in" 277 <<
" /path/to/include/marley/, please add /path/to/include" 278 <<
" to your ROOT_INCLUDE_PATH environment variable and" 285 already_loaded_marley_dict =
true;
304 return fhicl_atom_to_json<>(atm);
305 else if (
auto atm =
dynamic_cast<const
308 return fhicl_atom_to_json<>(atm);
311 <<
" the type of the FHiCL atom " << par->
key();
314 if (
auto opt_atom =
dynamic_cast<const
317 return fhicl_optional_atom_to_json<>(opt_atom);
320 std::string
>* >(par))
322 return fhicl_optional_atom_to_json<>(opt_atom);
325 <<
" the type of the FHiCL optional atom " << par->
key();
334 return fhicl_sequence_to_json<>(seq);
335 else if (
auto seq =
dynamic_cast<const
338 return fhicl_sequence_to_json<>(seq);
340 else if (
auto seq =
dynamic_cast<const
343 return fhicl_sequence_to_json<>(seq);
346 <<
" the type of the FHiCL sequence " << par->
key();
348 return marley::JSON();
355 if (!table)
throw cet::exception(
"MarleyGen") <<
"Failed dynamic_cast" 356 <<
" of fhicl::detail::ParameterBase* to fhicl::detail::TableBase*" 357 <<
" when fhicl_is_table() was true";
360 marley::JSON
object = marley::JSON::make(
361 marley::JSON::DataType::Object);
364 for (
const auto& m : table->members()) {
365 if (m && m->should_use()) {
369 if (!temp.is_null())
object[ m->name() ] = temp;
377 return marley::JSON();
#define LOG_INFO(category)
LArSoft interface to the MARLEY (Model of Argon Reaction Low Energy Yields) supernova neutrino event ...
void load_marley_dictionaries()
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
void add_marley_particles(simb::MCTruth &truth, const std::vector< marley::Particle * > &particles, const TLorentzVector &vtx_pos, bool track)
bool is_atom(par_type const pt)
void SetOrigin(simb::Origin_t origin)
marley::JSON fhicl_parameter_to_json(const fhicl::detail::ParameterBase *par)
simb::MCTruth create_MCTruth(const TLorentzVector &vtx_pos, marley::Event *marley_event=nullptr)
ParameterSet const & get_PSet() const
bool is_sequence(par_type const pt)
void SetNeutrino(int CCNC, int mode, int interactionType, int target, int nucleon, int quark, double w, double x, double y, double qsqr)
art::RandomNumberGenerator::seed_t seed_t
void Add(simb::MCParticle &part)
std::stringstream fMarleyLogStream
std::unique_ptr< marley::Generator > fMarleyGenerator
std::string find_file(const std::string &fileName, const std::string &fileType)
par_type parameter_type() const
Identifier for a engine, made of module name and optional instance name.
void reconfigure(const fhicl::Table< Config > &conf)
std::string value(boost::any const &)
n.b.: this group is similar but not quite, entirely unlike GENIE ScatteringType convention ...
bool is_table(par_type const pt)
Event generator information.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, std::string instance="")
Registers an existing engine with NuRandomService.
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)
cet::coded_exception< error, detail::translate > exception
Event finding and building.