LDMX Software
SimObjects.cxx
1
2#include "DQM/SimObjects.h"
3
6#include "SimCore/Event/SimParticle.h"
8
9namespace dqm {
10
12 sim_pass_ = ps.get<std::string>("sim_pass");
13 sim_particles_coll_name_ = ps.get<std::string>("sim_particles_coll_name");
14 sim_particles_map_passname_ =
15 ps.get<std::string>("sim_particles_map_passname");
16 return;
17}
18
21 std::vector<std::string> creator_process_labels = {
22 "Unknown", // 0: Unknown
23 "e+ e- -> γγ", // 1: annihil
24 "γ e -> γ e", // 2: compt
25 "γ -> e+ e- ", // 3: conv
26 "e Z -> X (eN)", // 4: electronNuclear
27 "e Z -> e Z γ", // 5: eBrem
28 "e- ionization", // 6: eIoni
29 "Multiple scattering", // 7: msc
30 "γ Z -> e Z ", // 8: phot
31 "γ Z -> X (PN)", // 9: photonNuclear
32 "γ -> mumu", // 10: GammaToMuPair
33 "e Z -> e Z A'", // 11: eDarkBrem
34 "Decay", // 12: Decay
35 "Primary", // 13: Primary
36 "mu Z -> X", // 14: muonNuclear
37 "n Z -> X", // 15: neutronInelastic
38 "n Z -> Z*", // 16: neutronCapture
39 "K Z -> X", // 17: kaonInelastic
40 "pi Z -> X", // 18: pionInelastic
41 "p Z -> X", // 19: protonInelastic
42 };
43
44 // create sim particles histograms
46 "Vertex Total Energy [MeV]", 800, 0., 8000.);
48 "Vertex Momentum in x-Direction [MeV]", 50, 0., 500.);
50 "Vertex Momentum in y-Direction [MeV]", 50, 0., 500.);
52 "Vertex Momentum in z-Direction [MeV]", 400, 0., 4000.);
54 "Global Time of Creation [ns]", 50, 0., 10.);
55 histograms_.create(sim_particles_coll_name_ + ".pdg", "PDG ID of Particle",
56 201, -100, 100);
57 histograms_.create(sim_particles_coll_name_ + ".x", "Vertex x-Position [mm]",
58 401, -200, 200);
59 histograms_.create(sim_particles_coll_name_ + ".y", "Vertex y-Position [mm]",
60 401, -200, 200);
61 histograms_.create(sim_particles_coll_name_ + ".z", "Vertex z-Position [mm]",
62 171, -700, 1000.);
64 "Creator Process Type", creator_process_labels);
66 "Track ID of Particle", 100, 0, 1000);
67 histograms_.create(sim_particles_coll_name_ + ".parent", "Track ID of Parent",
68 100, 0, 1000);
70 "Track IDs of Children", 100, 0, 1000);
71
72 // create pn children histograms
73 histograms_.create("pn_child.E", "Vertex Total Energy [MeV]", 800, 0., 8000.);
74 histograms_.create("pn_child.px", "Vertex Momentum in x-Direction [MeV]", 50,
75 0., 500.);
76 histograms_.create("pn_child.py", "Vertex Momentum in y-Direction [MeV]", 50,
77 0., 500.);
78 histograms_.create("pn_child.pz", "Vertex Momentum in z-Direction [MeV]", 400,
79 0., 4000.);
80 histograms_.create("pn_child.time", "Global Time of Creation [ns]", 50, 0.,
81 10.);
82 histograms_.create("pn_child.pdg", "PDG ID of Particle", 201, -100, 100);
83 histograms_.create("pn_child.x", "Vertex x-Position [mm]", 401, -200, 200);
84 histograms_.create("pn_child.y", "Vertex y-Position [mm]", 401, -200, 200);
85 histograms_.create("pn_child.z", "Vertex z-Position [mm]", 171, -700, 1000.);
86 histograms_.create("pn_child.track_id", "Track ID of Particle", 100, 0, 1000);
87 histograms_.create("pn_child.parent", "Track ID of Parent", 100, 0, 1000);
88 histograms_.create("pn_child.children", "Track IDs of Children", 100, 0,
89 1000);
90}
91
92void SimObjects::createCalorimeterHists(const std::string& coll_name) {
94 histograms_.create(coll_name + ".incidents", "Incident Track IDs", 100, 0,
95 1000);
96 histograms_.create(coll_name + ".tracks", "Contributing Track IDs", 100, 0,
97 1000);
98 histograms_.create(coll_name + ".pdg", "Contributing PDG IDs", 401, -200,
99 200);
100 histograms_.create(coll_name + ".edep", "Energy Deposited [MeV]", 100, 0,
101 200);
102 histograms_.create(coll_name + ".x", "Hit x-Position [mm]", 401, -200, 200);
103 histograms_.create(coll_name + ".y", "Hit y-Position [mm]", 401, -200, 200);
104 histograms_.create(coll_name + ".z", "Hit z-Position [mm]", 171, -700, 1000.);
105 histograms_.create(coll_name + ".time", "Hit Time [ns]", 50, 0., 10.);
106 histograms_.create(coll_name + ".n_contribs", "Number of Contributors", 20,
107 0., 20.);
108 return;
109}
110
111void SimObjects::createTrackerHists(const std::string& coll_name) {
113 histograms_.create(coll_name + ".particle_E", "Particle E at Hit [MeV]", 400,
114 0, 4000);
115 histograms_.create(coll_name + ".particle_px", "Particle Momentum in x [MeV]",
116 50, 0., 500.);
117 histograms_.create(coll_name + ".particle_py", "Particle Momentum in y [MeV]",
118 50, 0., 500.);
119 histograms_.create(coll_name + ".particle_pz", "Particle Momentum in z [MeV]",
120 400, 0., 4000.);
121 histograms_.create(coll_name + ".edep", "Energy Deposited [MeV]", 100, 0,
122 200);
123 histograms_.create(coll_name + ".time", "Hit Time [ns]", 50, 0., 10.);
124 histograms_.create(coll_name + ".x", "Hit x-Position [mm]", 401, -200, 200);
125 histograms_.create(coll_name + ".y", "Hit y-Position [mm]", 401, -200, 200);
126 histograms_.create(coll_name + ".z", "Hit z-Position [mm]", 171, -700, 1000.);
127 histograms_.create(coll_name + ".track", "Particle Track ID", 100, 0, 1000);
128 histograms_.create(coll_name + ".pdg", "Particle PDG ID", 401, -200, 200);
129 return;
130}
131
133 static std::vector<framework::ProductTag> sp_maps, calo_colls, track_colls;
134 if (sp_maps.empty()) {
135 sp_maps = event.searchProducts(sim_particles_coll_name_, "", "");
136 if (sp_maps.size() != 1) {
137 ldmx_log(warn) << sp_maps.size() << " SimParticle maps which is not one!";
138 }
139 }
140 if (calo_colls.empty()) {
141 calo_colls = event.searchProducts("", sim_pass_, ".*SimCalorimeterHit.*");
142 for (auto pt : calo_colls) createCalorimeterHists(pt.name());
143 }
144 if (track_colls.empty()) {
145 track_colls = event.searchProducts("", sim_pass_, ".*SimTrackerHit.*");
146 for (auto pt : track_colls) createTrackerHists(pt.name());
147 }
148
149 auto const& particle_map{event.getMap<int, ldmx::SimParticle>(
150 "SimParticles", sim_particles_map_passname_)};
151 for (auto const& [track_id, particle] : particle_map) {
152 auto const& momentum{particle.getMomentum()};
153 auto const& vertex{particle.getVertex()};
154 histograms_.fill(sim_particles_coll_name_ + ".E", particle.getEnergy());
155 histograms_.fill(sim_particles_coll_name_ + ".px", momentum.at(0));
156 histograms_.fill(sim_particles_coll_name_ + ".py", momentum.at(1));
157 histograms_.fill(sim_particles_coll_name_ + ".pz", momentum.at(2));
158 histograms_.fill(sim_particles_coll_name_ + ".time", particle.getTime());
159 histograms_.fill(sim_particles_coll_name_ + ".pdg", particle.getPdgID());
160 histograms_.fill(sim_particles_coll_name_ + ".x", vertex.at(0));
161 histograms_.fill(sim_particles_coll_name_ + ".y", vertex.at(1));
162 histograms_.fill(sim_particles_coll_name_ + ".z", vertex.at(2));
164 particle.getProcessType());
165 histograms_.fill(sim_particles_coll_name_ + ".track_id", track_id);
166 for (auto const& parent : particle.getParents())
167 histograms_.fill(sim_particles_coll_name_ + ".parent", parent);
168 for (auto const& child : particle.getDaughters())
169 histograms_.fill(sim_particles_coll_name_ + ".children", child);
170
171 // PN particles are special
172 if (particle.getProcessType() ==
173 ldmx::SimParticle::ProcessType::photonNuclear) {
174 histograms_.fill("pn_child.E", particle.getEnergy());
175 histograms_.fill("pn_child.px", momentum.at(0));
176 histograms_.fill("pn_child.py", momentum.at(1));
177 histograms_.fill("pn_child.pz", momentum.at(2));
178 histograms_.fill("pn_child.time", particle.getTime());
179 histograms_.fill("pn_child.pdg", particle.getPdgID());
180 histograms_.fill("pn_child.x", vertex.at(0));
181 histograms_.fill("pn_child.y", vertex.at(1));
182 histograms_.fill("pn_child.z", vertex.at(2));
183 histograms_.fill("pn_child.track_id", track_id);
184 for (auto const& parent : particle.getParents())
185 histograms_.fill("pn_child.parent", parent);
186 for (auto const& child : particle.getDaughters())
187 histograms_.fill("pn_child.children", child);
188 }
189 } // loop over sim particle map
190
191 for (auto const& pt : calo_colls) {
192 auto const& coll{
193 event.getCollection<ldmx::SimCalorimeterHit>(pt.name(), sim_pass_)};
194 for (auto const& hit : coll) {
195 unsigned int n_contribs{hit.getNumberOfContribs()};
196 histograms_.fill(pt.name() + ".n_contribs", n_contribs);
197 for (unsigned int i_contrib{0}; i_contrib < n_contribs; i_contrib++) {
198 ldmx::SimCalorimeterHit::Contrib contrib{hit.getContrib(i_contrib)};
199 histograms_.fill(pt.name() + ".incidents", contrib.incident_id_);
200 histograms_.fill(pt.name() + ".tracks", contrib.track_id_);
201 histograms_.fill(pt.name() + ".pdg", contrib.pdg_code_);
202 }
203
204 histograms_.fill(pt.name() + ".edep", hit.getEdep());
205 auto pos{hit.getPosition()};
206 histograms_.fill(pt.name() + ".x", pos.at(0));
207 histograms_.fill(pt.name() + ".y", pos.at(1));
208 histograms_.fill(pt.name() + ".z", pos.at(2));
209 histograms_.fill(pt.name() + ".time", hit.getTime());
210 } // loop over hits in the calorimeter collection
211 } // loop over different calorimeter hit collections
212
213 for (auto const& pt : track_colls) {
214 auto const& coll{
215 event.getCollection<ldmx::SimTrackerHit>(pt.name(), sim_pass_)};
216 for (auto const& hit : coll) {
217 histograms_.fill(pt.name() + ".particle_E", hit.getEnergy());
218 auto momentum{hit.getMomentum()};
219 histograms_.fill(pt.name() + ".particle_px", momentum.at(0));
220 histograms_.fill(pt.name() + ".particle_py", momentum.at(1));
221 histograms_.fill(pt.name() + ".particle_pz", momentum.at(2));
222 histograms_.fill(pt.name() + ".edep", hit.getEdep());
223 histograms_.fill(pt.name() + ".time", hit.getTime());
224 auto pos{hit.getPosition()};
225 histograms_.fill(pt.name() + ".x", pos.at(0));
226 histograms_.fill(pt.name() + ".y", pos.at(1));
227 histograms_.fill(pt.name() + ".z", pos.at(2));
228 histograms_.fill(pt.name() + ".track", hit.getTrackID());
229 histograms_.fill(pt.name() + ".pdg", hit.getPdgID());
230 } // loop over hits in the tracker collection
231 } // loop over different tracker hit collections
232
233 return;
234}
235
236} // namespace dqm
237
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Class defining the identity of a data product in the event.
Class which stores simulated calorimeter hit information.
Class which encapsulates information from a hit in a simulated tracking detector.
Generate histograms to check simulation output.
Definition SimObjects.h:14
void createCalorimeterHists(const std::string &coll_name)
new calorimeter histograms
virtual void analyze(const framework::Event &event)
Fills histograms.
virtual void configure(framework::config::Parameters &ps)
Input python configuration parameters.
virtual void onProcessStart()
Construct histograms depending on which objects are requested.
std::string sim_particles_coll_name_
Pass Name for sim objects.
Definition SimObjects.h:48
void createTrackerHists(const std::string &coll_name)
new tracker histograms
HistogramPool histograms_
helper object for making and filling histograms
TDirectory * getHistoDirectory()
Access/create a directory in the histogram file for this event processor to create histograms and ana...
Implements an event buffer system for storing event data.
Definition Event.h:42
void create(const config::Parameters &p)
Create a histogram from the input configuration parameters.
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
Stores simulated calorimeter hit information.
Class representing a simulated particle.
Definition SimParticle.h:23
Represents a simulated tracker hit in the simulation.
Information about a contribution to the hit in the associated cell.