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