LDMX Software
DarkBremInteraction.cxx
1#include "DQM/DarkBremInteraction.h"
2
3namespace dqm {
4
6 particle_passname_ = parameters.get<std::string>("particle_passname");
7}
20static double energy(const std::vector<double>& p, const double& m) {
21 return sqrt(p.at(0) * p.at(0) + p.at(1) * p.at(1) + p.at(2) * p.at(2) +
22 m * m);
23}
24
31static double quadsum(const std::initializer_list<double>& list) {
32 double sum{0};
33 for (const double& elem : list) sum += elem * elem;
34 return sqrt(sum);
35}
36
39 const auto& particle_map{
40 event.getMap<int, ldmx::SimParticle>("SimParticles", particle_passname_)};
41 const ldmx::SimParticle *recoil{nullptr}, *aprime{nullptr}, *beam{nullptr};
42 for (const auto& [track_id, particle] : particle_map) {
43 if (track_id == 1) beam = &particle;
44 if (particle.getProcessType() ==
45 ldmx::SimParticle::ProcessType::eDarkBrem) {
46 if (particle.getPdgID() == 622) {
47 if (aprime != nullptr) {
48 EXCEPTION_RAISE("BadEvent", "Found multiple A' in event.");
49 }
50 aprime = &particle;
51 } else {
52 recoil = &particle;
53 }
54 }
55 }
56
57 if (recoil == nullptr and aprime == nullptr) {
58 /* dark brem did not occur during the simulation
59 * IF PROPERLY CONFIGURED, this occurs because the simulation
60 * exhausted the maximum number of tries to get a dark brem
61 * to occur. We just leave early so that the entries in the
62 * ntuple are the unphysical numeric minimum.
63 */
64 ldmx_log(error) << " No dark brem occured in this event";
65 return;
66 }
67
68 if (recoil == nullptr or aprime == nullptr or beam == nullptr) {
69 // we are going to end processing so let's take our time to
70 // construct a nice error message
71 ldmx_log(fatal)
72 << "Unable to find all necessary particles for DarkBrem interaction."
73 << " Missing: [ " << (recoil == nullptr ? " recoil " : "")
74 << (aprime == nullptr ? " aprime " : "")
75 << (beam == nullptr ? " beam " : "") << "]";
76 EXCEPTION_RAISE(
77 "BadEvent",
78 "Unable to find all necessary particles for DarkBrem interaction.");
79 return;
80 }
81
82 const auto& recoil_p = recoil->getMomentum();
83 const auto& aprime_p = aprime->getMomentum();
84 ROOT::Math::XYZVector recoil_pvec(recoil_p[0], recoil_p[1], recoil_p[2]);
85 ROOT::Math::XYZVector aprime_pvec(aprime_p[0], aprime_p[1], aprime_p[2]);
86
87 std::vector<double> incident_p = recoil_p;
88 for (std::size_t i{0}; i < recoil_p.size(); ++i)
89 incident_p[i] += aprime_p.at(i);
90
91 double incident_energy = energy(incident_p, recoil->getMass());
92 double recoil_energy = energy(recoil_p, recoil->getMass());
93
94 std::vector<double> ap_vertex{aprime->getVertex()};
95 std::string ap_vertex_volume{aprime->getVertexVolume()};
96 auto ap_vertex_material_it = std::find_if(
98 [&](const auto& mat_pair) {
99 return ap_vertex_volume.find(mat_pair.first) != std::string::npos;
100 });
101 int ap_vertex_material = (ap_vertex_material_it != known_materials_.end())
102 ? ap_vertex_material_it->second
103 : 0;
104
105 if (ap_vertex_material == 0) {
106 ldmx_log(warn) << "Dark brem interaction occurred in an unknown material: "
107 << ap_vertex_volume;
108 }
109
110 int ap_parent_id{-1};
111 if (aprime->getParents().size() > 0) {
112 ap_parent_id = aprime->getParents().at(0);
113 } else {
114 ldmx_log(error) << "Found A' without a parent ID!";
115 }
116
117 float aprime_energy = energy(aprime_p, aprime->getMass());
118 int aprime_genstatus = aprime->getGenStatus();
119 double aprime_px{aprime_p.at(0)}, aprime_py{aprime_p.at(1)},
120 aprime_pz{aprime_p.at(2)};
121 event.add("APrimeEnergy", aprime_energy);
122 event.add("APrimePx", aprime_px);
123 event.add("APrimePy", aprime_py);
124 event.add("APrimePz", aprime_pz);
125 event.add("APrimeParentID", ap_parent_id);
126 event.add("APrimeGenStatus", aprime_genstatus);
127
128 histograms_.fill("aprime_energy", aprime_energy);
129 histograms_.fill("aprime_pt", quadsum({aprime_px, aprime_py}));
130 histograms_.fill("aprime_theta", aprime_pvec.Theta() * (180 / 3.14159));
131
132 int recoil_genstatus = recoil->getGenStatus();
133 double recoil_px{recoil_p.at(0)}, recoil_py{recoil_p.at(1)},
134 recoil_pz{recoil_p.at(2)};
135 event.add("RecoilEnergy", recoil_energy);
136 event.add("RecoilPx", recoil_px);
137 event.add("RecoilPy", recoil_py);
138 event.add("RecoilPz", recoil_pz);
139 event.add("RecoilGenStatus", recoil_genstatus);
140
141 histograms_.fill("recoil_energy", recoil_energy);
142 histograms_.fill("recoil_pt", quadsum({recoil_px, recoil_py}));
143 histograms_.fill("recoil_theta", recoil_pvec.Theta() * (180 / 3.14159));
144
145 event.add("IncidentEnergy", incident_energy);
146 double incident_px{incident_p.at(0)}, incident_py{incident_p.at(1)},
147 incident_pz{incident_p.at(2)};
148 event.add("IncidentPx", incident_px);
149 event.add("IncidentPy", incident_py);
150 event.add("IncidentPz", incident_pz);
151
152 histograms_.fill("incident_energy", incident_energy);
153 histograms_.fill("incident_pt", quadsum({incident_px, incident_py}));
154
155 double vtx_x{aprime->getVertex().at(0)}, vtx_y{aprime->getVertex().at(1)},
156 vtx_z{aprime->getVertex().at(2)};
157 event.add("DarkBremX", vtx_x);
158 event.add("DarkBremY", vtx_y);
159 event.add("DarkBremZ", vtx_z);
160 event.add("DarkBremVertexMaterial", ap_vertex_material);
161 float db_material_z =
162 event.getEventHeader().getFloatParameter("db_material_z");
163 event.add("DarkBremVertexMaterialZ", db_material_z);
164
165 histograms_.fill("dark_brem_z", vtx_z);
166
167 int i_element = 0;
168 if (db_material_z > 0) {
169 if (known_elements_.find(static_cast<int>(db_material_z)) ==
170 known_elements_.end()) {
171 i_element = known_elements_.size();
172 ldmx_log(warn)
173 << "Dark brem interaction occurred in an unknown element with Z = "
174 << db_material_z << ". Using index " << i_element
175 << " for this element.";
176 } else {
177 i_element = known_elements_.at(static_cast<int>(db_material_z));
178 }
179 }
180
181 histograms_.fill("dark_brem_element", i_element);
182 histograms_.fill("dark_brem_material", ap_vertex_material);
183}
184
185} // namespace dqm
186
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Go through the particle map and find the dark brem products, storing their vertex and the dark brem o...
void configure(framework::config::Parameters &parameters) override
Callback for the EventProcessor to configure itself from the given set of parameters.
std::map< std::string, int > known_materials_
the list of known materials assigning them to material ID numbers
virtual void produce(framework::Event &e) override
extract the kinematics of the dark brem interaction from the SimParticles
std::map< int, int > known_elements_
The list of known elements assigning them to the bins that we are putting them into.
HistogramPool histograms_
helper object for making and filling histograms
Implements an event buffer system for storing event data.
Definition Event.h:42
ldmx::EventHeader & getEventHeader()
Get the event header.
Definition Event.h:59
void setWeight(double w)
Set the weight for filling the histograms.
void fill(const std::string &name, const T &val)
Fill a 1D histogram.
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
double getWeight() const
Get the event weight (default of 1.0).
Definition EventHeader.h:98
Class representing a simulated particle.
Definition SimParticle.h:23
std::vector< double > getMomentum() const
Get a vector containing the momentum of this particle [MeV].