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.getParameter<std::string>("sim_pass");
13 return;
14}
15
18 std::vector<std::string> creator_process_labels = {
19 "Unknown", // 0: Unknown
20 "e+ e- -> γγ", // 1: annihil
21 "γ e -> γ e", // 2: compt
22 "γ -> e+ e- ", // 3: conv
23 "e Z -> X (eN)", // 4: electronNuclear
24 "e Z -> e Z γ", // 5: eBrem
25 "e- ionization", // 6: eIoni
26 "Multiple scattering", // 7: msc
27 "γ Z -> e Z ", // 8: phot
28 "γ Z -> X (PN)", // 9: photonNuclear
29 "γ -> mumu", // 10: GammaToMuPair
30 "e Z -> e Z A'", // 11: eDarkBrem
31 "Decay", // 12: Decay
32 "Primary", // 13: Primary
33 "mu Z -> X", // 14: muonNuclear
34 "n Z -> X", // 15: neutronInelastic
35 "n Z -> Z*", // 16: neutronCapture
36 "K Z -> X", // 17: kaonInelastic
37 "pi Z -> X", // 18: pionInelastic
38 "p Z -> X", // 19: protonInelastic
39 };
40
41 // create sim particles histograms
42 histograms_.create("SimParticles.E", "Vertex Total Energy [MeV]", 800, 0.,
43 8000.);
44 histograms_.create("SimParticles.px", "Vertex Momentum in x-Direction [MeV]",
45 50, 0., 500.);
46 histograms_.create("SimParticles.py", "Vertex Momentum in y-Direction [MeV]",
47 50, 0., 500.);
48 histograms_.create("SimParticles.pz", "Vertex Momentum in z-Direction [MeV]",
49 400, 0., 4000.);
50 histograms_.create("SimParticles.time", "Global Time of Creation [ns]", 50,
51 0., 10.);
52 histograms_.create("SimParticles.pdg", "PDG ID of Particle", 201, -100, 100);
53 histograms_.create("SimParticles.x", "Vertex x-Position [mm]", 401, -200,
54 200);
55 histograms_.create("SimParticles.y", "Vertex y-Position [mm]", 401, -200,
56 200);
57 histograms_.create("SimParticles.z", "Vertex z-Position [mm]", 171, -700,
58 1000.);
59 histograms_.create("SimParticles.process", "Creator Process Type", 20, 0, 20);
60 histograms_.create("SimParticles.track_id", "Track ID of Particle", 100, 0,
61 1000);
62 histograms_.create("SimParticles.parent", "Track ID of Parent", 100, 0, 1000);
63 histograms_.create("SimParticles.children", "Track IDs of Children", 100, 0,
64 1000);
65
66 // create pn children histograms
67 histograms_.create("pn_child.E", "Vertex Total Energy [MeV]", 800, 0., 8000.);
68 histograms_.create("pn_child.px", "Vertex Momentum in x-Direction [MeV]", 50,
69 0., 500.);
70 histograms_.create("pn_child.py", "Vertex Momentum in y-Direction [MeV]", 50,
71 0., 500.);
72 histograms_.create("pn_child.pz", "Vertex Momentum in z-Direction [MeV]", 400,
73 0., 4000.);
74 histograms_.create("pn_child.time", "Global Time of Creation [ns]", 50, 0.,
75 10.);
76 histograms_.create("pn_child.pdg", "PDG ID of Particle", 201, -100, 100);
77 histograms_.create("pn_child.x", "Vertex x-Position [mm]", 401, -200, 200);
78 histograms_.create("pn_child.y", "Vertex y-Position [mm]", 401, -200, 200);
79 histograms_.create("pn_child.z", "Vertex z-Position [mm]", 171, -700, 1000.);
80 histograms_.create("pn_child.track_id", "Track ID of Particle", 100, 0, 1000);
81 histograms_.create("pn_child.parent", "Track ID of Parent", 100, 0, 1000);
82 histograms_.create("pn_child.children", "Track IDs of Children", 100, 0,
83 1000);
84
85 // Add bin labels to category plots
86 auto hist{histograms_.get("SimParticles.process")};
87 for (int i{0}; i < creator_process_labels.size(); ++i) {
88 const auto& label{creator_process_labels[i]};
89 hist->GetXaxis()->SetBinLabel(i + 1, label.c_str());
90 }
91}
92
93void SimObjects::createCalorimeterHists(const std::string& coll_name) {
95 histograms_.create(coll_name + ".incidents", "Incident Track IDs", 100, 0,
96 1000);
97 histograms_.create(coll_name + ".tracks", "Contributing Track IDs", 100, 0,
98 1000);
99 histograms_.create(coll_name + ".pdg", "Contributing PDG IDs", 401, -200,
100 200);
101 histograms_.create(coll_name + ".edep", "Energy Deposited [MeV]", 100, 0,
102 200);
103 histograms_.create(coll_name + ".x", "Hit x-Position [mm]", 401, -200, 200);
104 histograms_.create(coll_name + ".y", "Hit y-Position [mm]", 401, -200, 200);
105 histograms_.create(coll_name + ".z", "Hit z-Position [mm]", 171, -700, 1000.);
106 histograms_.create(coll_name + ".time", "Hit Time [ns]", 50, 0., 10.);
107 histograms_.create(coll_name + ".n_contribs", "Number of Contributors", 20,
108 0., 20.);
109 return;
110}
111
112void SimObjects::createTrackerHists(const std::string& coll_name) {
114 histograms_.create(coll_name + ".particle_E", "Particle E at Hit [MeV]", 400,
115 0, 4000);
116 histograms_.create(coll_name + ".particle_px", "Particle Momentum in x [MeV]",
117 50, 0., 500.);
118 histograms_.create(coll_name + ".particle_py", "Particle Momentum in y [MeV]",
119 50, 0., 500.);
120 histograms_.create(coll_name + ".particle_pz", "Particle Momentum in z [MeV]",
121 400, 0., 4000.);
122 histograms_.create(coll_name + ".edep", "Energy Deposited [MeV]", 100, 0,
123 200);
124 histograms_.create(coll_name + ".time", "Hit Time [ns]", 50, 0., 10.);
125 histograms_.create(coll_name + ".x", "Hit x-Position [mm]", 401, -200, 200);
126 histograms_.create(coll_name + ".y", "Hit y-Position [mm]", 401, -200, 200);
127 histograms_.create(coll_name + ".z", "Hit z-Position [mm]", 171, -700, 1000.);
128 histograms_.create(coll_name + ".track", "Particle Track ID", 100, 0, 1000);
129 histograms_.create(coll_name + ".pdg", "Particle PDG ID", 401, -200, 200);
130 return;
131}
132
134 static std::vector<framework::ProductTag> sp_maps, calo_colls, track_colls;
135 if (sp_maps.empty()) {
136 sp_maps = event.searchProducts("SimParticles", "", "");
137 if (sp_maps.size() != 1) {
138 ldmx_log(warn) << sp_maps.size() << " SimParticle maps which is not one!";
139 }
140 }
141 if (calo_colls.empty()) {
142 calo_colls = event.searchProducts("", sim_pass_, ".*SimCalorimeterHit.*");
143 for (auto pt : calo_colls) createCalorimeterHists(pt.name());
144 }
145 if (track_colls.empty()) {
146 track_colls = event.searchProducts("", sim_pass_, ".*SimTrackerHit.*");
147 for (auto pt : track_colls) createTrackerHists(pt.name());
148 }
149
150 auto const& particle_map{
151 event.getMap<int, ldmx::SimParticle>("SimParticles")};
152 for (auto const& [track_id, particle] : particle_map) {
153 auto const& momentum{particle.getMomentum()};
154 auto const& vertex{particle.getVertex()};
155 histograms_.fill("SimParticles.E", particle.getEnergy());
156 histograms_.fill("SimParticles.px", momentum.at(0));
157 histograms_.fill("SimParticles.py", momentum.at(1));
158 histograms_.fill("SimParticles.pz", momentum.at(2));
159 histograms_.fill("SimParticles.time", particle.getTime());
160 histograms_.fill("SimParticles.pdg", particle.getPdgID());
161 histograms_.fill("SimParticles.x", vertex.at(0));
162 histograms_.fill("SimParticles.y", vertex.at(1));
163 histograms_.fill("SimParticles.z", vertex.at(2));
164 histograms_.fill("SimParticles.process", particle.getProcessType());
165 histograms_.fill("SimParticles.track_id", track_id);
166 for (auto const& parent : particle.getParents())
167 histograms_.fill("SimParticles.parent", parent);
168 for (auto const& child : particle.getDaughters())
169 histograms_.fill("SimParticles.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.incidentID);
200 histograms_.fill(pt.name() + ".tracks", contrib.trackID);
201 histograms_.fill(pt.name() + ".pdg", contrib.pdgCode);
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
238DECLARE_ANALYZER_NS(dqm, SimObjects);
#define DECLARE_ANALYZER_NS(NS, 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.
void createCalorimeterHists(const std::string &coll_name)
new calorimeter histograms
virtual void analyze(const framework::Event &event)
Fills histograms.
std::string sim_pass_
Pass Name for sim objects.
Definition SimObjects.h:48
virtual void configure(framework::config::Parameters &ps)
Input python configuration parameters.
virtual void onProcessStart()
Construct histograms depending on which objects are requested.
void createTrackerHists(const std::string &coll_name)
new tracker histograms
TDirectory * getHistoDirectory()
Access/create a directory in the histogram file for this event processor to create histograms and ana...
HistogramHelper histograms_
Interface class for making and filling histograms.
Implements an event buffer system for storing event data.
Definition Event.h:41
TH1 * get(const std::string &name)
Get a pointer to a histogram by name.
Definition Histograms.h:194
void fill(const std::string &name, const double &val)
Fill a 1D histogram.
Definition Histograms.h:166
void create(const std::string &name, const std::string &xLabel, const double &bins, const double &xmin, const double &xmax)
Create a ROOT 1D histogram of type TH1F and pool it for later use.
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
Stores simulated calorimeter hit information.
unsigned getNumberOfContribs() const
Get the number of hit contributions.
Class representing a simulated particle.
Definition SimParticle.h:23
std::vector< double > getMomentum() const
Get a vector containing the momentum of this particle [MeV].
Represents a simulated tracker hit in the simulation.
Information about a contribution to the hit in the associated cell.