9 #include <bxdecay0/event.h> 10 #include <bxdecay0/i_random.h> 12 #pragma clang diagnostic push 13 #pragma clang diagnostic ignored "-Wmismatched-tags" 14 #include <bxdecay0/decay0_generator.h> 15 #pragma clang diagnostic pop 17 #include <bxdecay0/decay0_generator.h> 19 #include <bxdecay0/particle.h> 53 clhep_random(CLHEP::HepRandomEngine& gen) : m_generator(gen), m_rand_flat(gen) {}
58 double v = m_rand_flat.fire(0., 1.);
72 std::string isotope =
"";
91 auto generator = std::make_unique<bxdecay0::decay0_generator>();
95 generator->set_decay_category(bxdecay0::decay0_generator::DECAY_CATEGORY_BACKGROUND);
96 generator->set_decay_isotope(isotope.c_str());
101 throw cet::exception(
"Decay0Gen") <<
"The inialisation of Decay0 failed. Maybe the isotope " 102 << isotope <<
" doesn't exists?\n";
111 double T0 = 0, T1 = 0;
114 tfs->make<TH1D>(
"TimeDiff",
";Time Diff[ns];n particles", (int)((T1) / 10000), 0, T1);
126 std::unique_ptr<std::vector<simb::MCTruth>> truthcol(
new std::vector<simb::MCTruth>);
131 const std::string primary_str(
"primary");
132 int bad_position = 0;
133 int tentative_decay = 0;
137 tentative_decay += n_decay;
138 for (
int iDecay = 0; iDecay < n_decay; ++iDecay) {
139 TLorentzVector position;
142 bxdecay0::event gendecay;
144 std::vector<bxdecay0::particle>
part = gendecay.get_particles();
147 double t_electron = 0;
148 for (
auto const& p : part) {
152 if (not p.is_valid()) {
154 throw cet::exception(
"Decay0Gen") <<
"Invalid part generated by Decay0, printed " 155 "above (no clue what that means so throw)";
158 double mass = bxdecay0::particle_mass_MeV(p.get_code());
166 else if (p.is_gamma()) {
170 else if (p.is_positron()) {
174 else if (p.is_electron()) {
178 else if (p.is_neutron()) {
182 else if (p.is_proton()) {
188 throw cet::exception(
"Decay0Gen") <<
"Particle above is weird, cannot recognise it.";
191 if ((p.is_positron() or p.is_electron()) and t_electron == 0) {
192 t_electron = p.get_time();
194 if (p.is_alpha() and t_alpha == 0) { t_alpha = p.get_time(); }
196 TLorentzVector mom(p.get_px() / 1000.,
199 sqrt(p.get_p() * p.get_p() + mass * mass) / 1000.);
201 TLorentzVector this_part_position = position;
202 double t = position.T();
203 this_part_position.SetT(t + p.get_time() * 1e9);
211 if (
abs(t_alpha - t_electron) > 1.
e-15) {
223 if (bad_position > 0) {
225 <<
"There were " << bad_position
226 <<
" failed attempts to get a good position to generate a decay out of the target " 227 << tentative_decay <<
" decays.\n" 228 <<
"If these 2 numbers are close together, it means that the rate of your background is " 229 "wrong (underestimated).\n" 230 <<
"You can fix this by increasing the parameter \"max_tries_event\" to a bigger number " 231 "(default is 1M) in your fhicl.\n" 232 <<
"Another way is to change the \"volume_rand\" to a smaller one.\n";
234 truthcol->push_back(truth);
235 evt.
put(std::move(truthcol));
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
CLHEP::RandFlat m_rand_flat
void SetOrigin(simb::Origin_t origin)
virtual double operator()()
Main operator.
constexpr auto abs(T v)
Returns the absolute value of the argument.
#define MF_LOG_ERROR(category)
bool m_single_isotope_mode
Decay0Gen(fhicl::ParameterSet const &pset)
void FillHistos(simb::MCParticle &part)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
std::vector< std::unique_ptr< bxdecay0::decay0_generator > > m_decay0_generator
#define DEFINE_ART_MODULE(klass)
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
single particles thrown at the detector
T get(std::string const &key) const
CLHEP::HepRandomEngine & GetRandomEngine()
std::vector< std::string > m_isotope
isotope to simulate. Example: "Ar39"
CLHEP::HepRandomEngine & m_generator
Wrapper functor for a standard random number generator.
bool GetGoodPositionTime(TLorentzVector &position)
void Add(simb::MCParticle const &part)
void GetTs(double &T0, double &T1)
std::optional< T > get_if_present(std::string const &key) const
void produce_radio(art::Event &evt)
Event generator information.
clhep_random(CLHEP::HepRandomEngine &gen)
Constructor.
std::shared_ptr< clhep_random > m_random_decay0
Event Generation using GENIE, cosmics or single particles.
cet::coded_exception< error, detail::translate > exception