LDMX Software
KaonPhysics.cxx
1#include "SimCore/KaonPhysics.h"
2
3namespace simcore {
4KaonPhysics::KaonPhysics(const G4String& name,
5 const framework::config::Parameters& parameters)
6 : G4VPhysicsConstructor(name) {
7 kplus_branching_ratios_ =
8 parameters.get<std::vector<double>>("kplus_branching_ratios");
9 kminus_branching_ratios_ =
10 parameters.get<std::vector<double>>("kminus_branching_ratios");
11 k0l_branching_ratios_ =
12 parameters.get<std::vector<double>>("k0l_branching_ratios");
13 k0s_branching_ratios_ =
14 parameters.get<std::vector<double>>("k0s_branching_ratios");
15 kplus_lifetime_factor_ = parameters.get<double>("kplus_lifetime_factor");
16 kminus_lifetime_factor_ = parameters.get<double>("kminus_lifetime_factor");
17 k0l_lifetime_factor_ = parameters.get<double>("k0l_lifetime_factor");
18 k0s_lifetime_factor_ = parameters.get<double>("k0s_lifetime_factor");
19}
20void KaonPhysics::setDecayProperties(
21 G4ParticleDefinition* kaon, const std::vector<double>& branching_ratios,
22 double lifetime_factor) const {
23 auto table{kaon->GetDecayTable()};
24 if (!table) {
25 EXCEPTION_RAISE("KaonPhysics", "Unable to get the decay table from " +
26 kaon->GetParticleName());
27 }
28 ldmx_log(trace) << "Decay details (" << kaon->GetParticleName()
29 << ") before setting branching ratios and lifetimes";
30 dumpDecayDetails(kaon);
31 kaon->SetPDGLifeTime(kaon->GetPDGLifeTime() * lifetime_factor);
32 if (kaon == G4KaonZeroLong::Definition()) {
33 (*table)[KaonZeroLongDecayChannel::pi0_pi0_pi0]->SetBR(
34 branching_ratios[KaonZeroLongDecayChannel::pi0_pi0_pi0]);
35 (*table)[KaonZeroLongDecayChannel::pi0_pip_pim]->SetBR(
36 branching_ratios[KaonZeroLongDecayChannel::pi0_pip_pim]);
37 (*table)[KaonZeroLongDecayChannel::pip_e_nu]->SetBR(
38 branching_ratios[KaonZeroLongDecayChannel::pip_e_nu]);
39 (*table)[KaonZeroLongDecayChannel::pim_e_nu]->SetBR(
40 branching_ratios[KaonZeroLongDecayChannel::pim_e_nu]);
41 (*table)[KaonZeroLongDecayChannel::pim_mu_nu]->SetBR(
42 branching_ratios[KaonZeroLongDecayChannel::pim_mu_nu]);
43 (*table)[KaonZeroLongDecayChannel::pip_mu_nu]->SetBR(
44 branching_ratios[KaonZeroLongDecayChannel::pip_mu_nu]);
45 } else if (kaon == G4KaonZeroShort::Definition()) {
46 (*table)[KaonZeroShortDecayChannel::pip_pim]->SetBR(
47 branching_ratios[KaonZeroShortDecayChannel::pip_pim]);
48 (*table)[KaonZeroShortDecayChannel::pi0_pi0]->SetBR(
49 branching_ratios[KaonZeroShortDecayChannel::pi0_pi0]);
50 } else {
51 (*table)[ChargedKaonDecayChannel::mu_nu]->SetBR(
52 branching_ratios[ChargedKaonDecayChannel::mu_nu]);
53 (*table)[ChargedKaonDecayChannel::pi_pi0]->SetBR(
54 branching_ratios[ChargedKaonDecayChannel::pi_pi0]);
55 (*table)[ChargedKaonDecayChannel::pi_pi_pi]->SetBR(
56 branching_ratios[ChargedKaonDecayChannel::pi_pi_pi]);
57 (*table)[ChargedKaonDecayChannel::pi_pi0_pi0]->SetBR(
58 branching_ratios[ChargedKaonDecayChannel::pi_pi0_pi0]);
59 (*table)[ChargedKaonDecayChannel::pi0_e_nu]->SetBR(
60 branching_ratios[ChargedKaonDecayChannel::pi0_e_nu]);
61 (*table)[ChargedKaonDecayChannel::pi0_mu_nu]->SetBR(
62 branching_ratios[ChargedKaonDecayChannel::pi0_mu_nu]);
63 }
64 ldmx_log(trace) << "Decay details (" << kaon->GetParticleName()
65 << ") after setting branching ratios and lifetimes"
66 << std::endl;
67 dumpDecayDetails(kaon);
68}
69void KaonPhysics::ConstructParticle() {
70 auto kaon_plus{G4KaonPlus::Definition()};
71 auto kaon_minus{G4KaonMinus::Definition()};
72 auto kaon_long{G4KaonZeroLong::Definition()};
73 auto kaon_short{G4KaonZeroShort::Definition()};
74
75 if (!kaon_plus || !kaon_minus || !kaon_long || !kaon_short) {
76 EXCEPTION_RAISE("KaonPhysics",
77 "Unable to get the charged kaon particle definitions, "
78 "something is very wrong with the configuration.");
79 }
80 setDecayProperties(kaon_plus, kplus_branching_ratios_,
81 kplus_lifetime_factor_);
82 setDecayProperties(kaon_minus, kminus_branching_ratios_,
83 kminus_lifetime_factor_);
84 setDecayProperties(kaon_long, k0l_branching_ratios_, k0l_lifetime_factor_);
85 setDecayProperties(kaon_short, k0s_branching_ratios_, k0s_lifetime_factor_);
86}
87
88void KaonPhysics::dumpDecayDetails(const G4ParticleDefinition* kaon) const {
89 ldmx_log(trace) << "Decay table details for " << kaon->GetParticleName()
90 << std::scientific << std::setprecision(15)
91 << " (PDG Lifetime " << kaon->GetPDGLifeTime() << ")"
92 << std::endl;
93 auto* table{kaon->GetDecayTable()};
94 if (not table) {
95 ldmx_log(error) << "No Kaon decay table.";
96 return;
97 }
98 const int entries{table->entries()};
99 for (auto i{0}; i < entries; ++i) {
100 const auto channel{(*table)[i]};
101 const auto daughters{channel->GetNumberOfDaughters()};
102 std::string products{};
103 // N-1 to avoid extra " + "
104 for (auto j{0}; j < daughters; ++j) {
105 auto* d{channel->GetDaughter(j)};
106 if (d) {
107 products += d->GetParticleName();
108 } else {
109 products += "NULL";
110 }
111 if (j < daughters - 1) {
112 // only add '+' when there are more to come
113 products += " + ";
114 }
115 }
116 ldmx_log(trace) << "Channel " << i << " (" << kaon->GetParticleName()
117 << " -> " << products << ") Kinematics type "
118 << channel->GetKinematicsName() << " with BR "
119 << channel->GetBR() << std::endl;
120 }
121}
122
123} // namespace simcore
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...