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.getParameter<std::vector<double>>("kplus_branching_ratios");
9 kminus_branching_ratios =
10 parameters.getParameter<std::vector<double>>("kminus_branching_ratios");
11 k0l_branching_ratios =
12 parameters.getParameter<std::vector<double>>("k0l_branching_ratios");
13 k0s_branching_ratios =
14 parameters.getParameter<std::vector<double>>("k0s_branching_ratios");
15 kplus_lifetime_factor =
16 parameters.getParameter<double>("kplus_lifetime_factor");
17 kminus_lifetime_factor =
18 parameters.getParameter<double>("kminus_lifetime_factor");
19 k0l_lifetime_factor = parameters.getParameter<double>("k0l_lifetime_factor");
20 k0s_lifetime_factor = parameters.getParameter<double>("k0s_lifetime_factor");
21 verbosity = parameters.getParameter<int>("verbosity");
22}
23void KaonPhysics::setDecayProperties(
24 G4ParticleDefinition* kaon, const std::vector<double>& branching_ratios,
25 double lifetime_factor) const {
26 auto table{kaon->GetDecayTable()};
27 if (!table) {
28 EXCEPTION_RAISE("KaonPhysics", "Unable to get the decay table from " +
29 kaon->GetParticleName());
30 }
31 if (verbosity > 1) {
32 ldmx_log(info) << "Decay details (" << kaon->GetParticleName()
33 << ") before setting branching ratios and lifetimes"
34 << std::endl;
35 DumpDecayDetails(kaon);
36 }
37 kaon->SetPDGLifeTime(kaon->GetPDGLifeTime() * lifetime_factor);
38 if (kaon == G4KaonZeroLong::Definition()) {
39 (*table)[KaonZeroLongDecayChannel::pi0_pi0_pi0]->SetBR(
40 branching_ratios[KaonZeroLongDecayChannel::pi0_pi0_pi0]);
41 (*table)[KaonZeroLongDecayChannel::pi0_pip_pim]->SetBR(
42 branching_ratios[KaonZeroLongDecayChannel::pi0_pip_pim]);
43 (*table)[KaonZeroLongDecayChannel::pip_e_nu]->SetBR(
44 branching_ratios[KaonZeroLongDecayChannel::pip_e_nu]);
45 (*table)[KaonZeroLongDecayChannel::pim_e_nu]->SetBR(
46 branching_ratios[KaonZeroLongDecayChannel::pim_e_nu]);
47 (*table)[KaonZeroLongDecayChannel::pim_mu_nu]->SetBR(
48 branching_ratios[KaonZeroLongDecayChannel::pim_mu_nu]);
49 (*table)[KaonZeroLongDecayChannel::pip_mu_nu]->SetBR(
50 branching_ratios[KaonZeroLongDecayChannel::pip_mu_nu]);
51 } else if (kaon == G4KaonZeroShort::Definition()) {
52 (*table)[KaonZeroShortDecayChannel::pip_pim]->SetBR(
53 branching_ratios[KaonZeroShortDecayChannel::pip_pim]);
54 (*table)[KaonZeroShortDecayChannel::pi0_pi0]->SetBR(
55 branching_ratios[KaonZeroShortDecayChannel::pi0_pi0]);
56 } else {
57 (*table)[ChargedKaonDecayChannel::mu_nu]->SetBR(
58 branching_ratios[ChargedKaonDecayChannel::mu_nu]);
59 (*table)[ChargedKaonDecayChannel::pi_pi0]->SetBR(
60 branching_ratios[ChargedKaonDecayChannel::pi_pi0]);
61 (*table)[ChargedKaonDecayChannel::pi_pi_pi]->SetBR(
62 branching_ratios[ChargedKaonDecayChannel::pi_pi_pi]);
63 (*table)[ChargedKaonDecayChannel::pi_pi0_pi0]->SetBR(
64 branching_ratios[ChargedKaonDecayChannel::pi_pi0_pi0]);
65 (*table)[ChargedKaonDecayChannel::pi0_e_nu]->SetBR(
66 branching_ratios[ChargedKaonDecayChannel::pi0_e_nu]);
67 (*table)[ChargedKaonDecayChannel::pi0_mu_nu]->SetBR(
68 branching_ratios[ChargedKaonDecayChannel::pi0_mu_nu]);
69 }
70 if (verbosity > 0) {
71 ldmx_log(info) << "Decay details (" << kaon->GetParticleName()
72 << ") after setting branching ratios and lifetimes"
73 << std::endl;
74 DumpDecayDetails(kaon);
75 }
76}
77void KaonPhysics::ConstructParticle() {
78 auto kaonPlus{G4KaonPlus::Definition()};
79 auto kaonMinus{G4KaonMinus::Definition()};
80 auto kaonLong{G4KaonZeroLong::Definition()};
81 auto kaonShort{G4KaonZeroShort::Definition()};
82
83 if (!kaonPlus || !kaonMinus || !kaonLong || !kaonShort) {
84 EXCEPTION_RAISE("KaonPhysics",
85 "Unable to get the charged kaon particle definitions, "
86 "something is very wrong with the configuration.");
87 }
88 setDecayProperties(kaonPlus, kplus_branching_ratios, kplus_lifetime_factor);
89 setDecayProperties(kaonMinus, kminus_branching_ratios,
90 kminus_lifetime_factor);
91 setDecayProperties(kaonLong, k0l_branching_ratios, k0l_lifetime_factor);
92 setDecayProperties(kaonShort, k0s_branching_ratios, k0s_lifetime_factor);
93}
94
95void KaonPhysics::DumpDecayDetails(const G4ParticleDefinition* kaon) const {
96 ldmx_log(info) << "Decay table details for " << kaon->GetParticleName()
97 << std::scientific << std::setprecision(15)
98 << " (PDG Lifetime " << kaon->GetPDGLifeTime() << ")"
99 << std::endl;
100 const auto table{kaon->GetDecayTable()};
101 const int entries{table->entries()};
102 for (auto i{0}; i < entries; ++i) {
103 const auto channel{(*table)[i]};
104 const auto daughters{channel->GetNumberOfDaughters()};
105 std::string products{};
106 // N-1 to avoid extra " + "
107 for (auto j{0}; j < daughters - 1; ++j) {
108 products += channel->GetDaughter(j)->GetParticleName();
109 products += " + ";
110 }
111 // Special formatting for last one :)
112 products += channel->GetDaughter(daughters - 1)->GetParticleName();
113 ldmx_log(info) << "Channel " << i << " (" << kaon->GetParticleName()
114 << " -> " << products << ") Kinematics type "
115 << channel->GetKinematicsName() << " with BR "
116 << channel->GetBR() << std::endl;
117 }
118}
119
120} // namespace simcore
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89