LDMX Software
SampleValidation.cxx
1#include "DQM/SampleValidation.h"
2
3#include <algorithm>
4#include <fstream>
5#include <iostream>
6
7#include "Framework/NtupleManager.h"
8#include "SimCore/Event/SimParticle.h"
10
11namespace dqm {
12
14 target_scoring_plane_coll_name_ =
15 ps.get<std::string>("target_scoring_plane_coll_name");
16 target_scoring_plane_passname_ =
17 ps.get<std::string>("target_scoring_plane_passname");
18 sim_particles_coll_name_ = ps.get<std::string>("sim_particles_coll_name");
19 sim_particles_passname_ = ps.get<std::string>("sim_particles_passname");
20}
21
23 // Grab the SimParticle Map and Target Scoring Plane Hits
24 auto target_sp_hits(event.getCollection<ldmx::SimTrackerHit>(
25 target_scoring_plane_coll_name_, target_scoring_plane_passname_));
26 auto particle_map{event.getMap<int, ldmx::SimParticle>(
27 sim_particles_coll_name_, sim_particles_passname_)};
28
29 std::vector<int> primary_daughters;
30
31 double hard_thresh{9999.0};
32
33 // Loop over all SimParticles
34 for (auto const& it : particle_map) {
35 ldmx::SimParticle p = it.second;
36 std::vector<int> parents_track_ids = p.getParents();
37 std::vector<int> daughters = p.getDaughters();
38 const auto& pdgid = p.getPdgID();
39 const auto& vertex = p.getVertex();
40 const auto& energy = p.getEnergy();
41 const auto& momentum = p.getMomentum();
42 for (auto const& parent_track_id : parents_track_ids) {
43 if (parent_track_id == 0) {
44 ROOT::Math::XYZVector momentum_vec(momentum[0], momentum[1],
45 momentum[2]);
46 histograms_.fill("primaries_pdgid", pdgidLabel(pdgid));
47 histograms_.fill("primaries_energy", energy);
48 histograms_.fill("primaries_theta",
49 momentum_vec.Theta() * (180 / 3.14159));
50 histograms_.fill("primaries_pt", std::sqrt(momentum_vec.Perp2()));
51 hard_thresh = (2500. / 4000.) * energy;
52 primary_daughters = daughters;
53 for (const ldmx::SimTrackerHit& sphit : target_sp_hits) {
54 if (sphit.getTrackID() == it.first && sphit.getPosition()[2] < 0) {
55 histograms_.fill("beam_smear", vertex[0], vertex[1]);
56 }
57 }
58 }
59 } // end loop over parents
60 } // end loop over SimParticles (1st time)
61
62 std::vector<std::vector<int>> hardbrem_daughters;
63
64 for (auto const& it : particle_map) {
65 int trackid = it.first;
66 ldmx::SimParticle p = it.second;
67 const auto& momentum = p.getMomentum();
68 ROOT::Math::XYZVector momentum_vec(momentum[0], momentum[1], momentum[2]);
69 for (auto const& primary_daughter : primary_daughters) {
70 if (trackid == primary_daughter) {
71 histograms_.fill("primarydaughters_pdgid", pdgidLabel(p.getPdgID()));
72 if (p.getPdgID() == 22) {
73 histograms_.fill("daughterphoton_energy", p.getEnergy());
74 }
75 if (p.getEnergy() >= hard_thresh) {
76 histograms_.fill("harddaughters_pdgid", pdgidLabel(p.getPdgID()));
77 histograms_.fill("harddaughters_startZ", p.getVertex()[2]);
78 histograms_.fill("harddaughters_endZ", p.getEndPoint()[2]);
79 histograms_.fill("harddaughters_energy", p.getEnergy());
80 histograms_.fill("harddaughters_theta",
81 momentum_vec.Theta() * (180 / 3.14159));
82 histograms_.fill("harddaughters_pt", std::sqrt(momentum_vec.Perp2()));
83 hardbrem_daughters.push_back(p.getDaughters());
84 }
85 }
86 } // end loop over primary daughters
87 } // end loop over SimParticles (2nd time)
88
89 for (auto const& it : particle_map) {
90 int trackid = it.first;
91 ldmx::SimParticle p = it.second;
92 const auto& momentum = p.getMomentum();
93 ROOT::Math::XYZVector momentum_vec(momentum[0], momentum[1], momentum[2]);
94 for (const std::vector<int>& daughter_track_id : hardbrem_daughters) {
95 for (const int& daughter_id : daughter_track_id) {
96 if (trackid == daughter_id) {
97 histograms_.fill("hardbremdaughters_pdgid", pdgidLabel(p.getPdgID()));
98 histograms_.fill("hardbremdaughters_startZ", p.getVertex()[2]);
99 histograms_.fill("hardbremdaughters_endZ", p.getEndPoint()[2]);
100 histograms_.fill("hardbremdaughters_energy", p.getEnergy());
101 histograms_.fill("hardbremdaughters_theta",
102 momentum_vec.Theta() * (180 / 3.14159));
103 histograms_.fill("hardbremdaughters_pt",
104 std::sqrt(momentum_vec.Perp2()));
105 }
106 }
107 } // end loop over hardbrem daughters
108 } // end loop over SimParticles (3x time)
109
110 return;
111}
112
113float SampleValidation::pdgidLabel(const int pdgid) {
114 // initially assign label as "anything else"/overflow value,
115 // only change if the pdg id is something of interest
116 int label = 18;
117 if (pdgid == -11) label = 0; // e+
118 if (pdgid == 11) label = 1; // e-
119 if (pdgid == -13) label = 2; // μ+
120 if (pdgid == 13) label = 3; // μ-
121 if (pdgid == 22) label = 4; // γ
122 if (pdgid == 2212) label = 5; // proton
123 if (pdgid == 2112) label = 6; // neutron
124 if (pdgid == 211) label = 7; // π+
125 if (pdgid == -211) label = 8; // π-
126 if (pdgid == 111) label = 9; // π0
127 if (pdgid == 321) label = 10; // K+
128 if (pdgid == -321) label = 11; // K-
129 if (pdgid == 130) label = 12; // K-Long
130 if (pdgid == 310) label = 13; // K-Short
131 if (pdgid == 3122 || pdgid == 3222 || pdgid == 3212 || pdgid == 3112 ||
132 pdgid == 3322 || pdgid == 3312) {
133 label = 16; // strange baryons
134 }
135 /*
136 * Nuclear PDG codes are given by ±10LZZZAAAI so to find the atomic
137 * number, we divide by 10 (to lose I) and then take the modulo
138 * with 1000.
139 */
140 if (pdgid > 1000000000) { // nuclei
141 if (((pdgid / 10) % 1000) <= 4) {
142 label = 14; // light nuclei
143 } else {
144 label = 15; // heavy nuclei
145 }
146 }
147 // dark photon, need pdg id for other models like ALPs and SIMPs
148 if (pdgid == 622) label = 17;
149
150 if (label == 18) {
151 ldmx_log(debug) << "Unrecognized PDG ID: " << pdgid
152 << ", assigning to 'else'";
153 }
154
155 return label + 0.5;
156}
157
158} // namespace dqm
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Class which encapsulates information from a hit in a simulated tracking detector.
virtual void configure(framework::config::Parameters &ps) override
Callback for the EventProcessor to configure itself from the given set of parameters.
virtual void analyze(const framework::Event &event) override
Process the event and make histograms or summaries.
HistogramPool histograms_
helper object for making and filling histograms
Implements an event buffer system for storing event data.
Definition Event.h:42
const std::vector< ContentType > & getCollection(const std::string &collectionName, const std::string &passName) const
Get a collection (std::vector) of objects from the event bus.
Definition Event.h:400
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
Class representing a simulated particle.
Definition SimParticle.h:23
double getEnergy() const
Get the energy of this particle [MeV].
Definition SimParticle.h:72
std::vector< int > getParents() const
Get a vector containing the track IDs of the parent particles.
std::vector< double > getVertex() const
Get a vector containing the vertex of this particle in mm.
std::vector< int > getDaughters() const
Get a vector containing the track IDs of all daughter particles.
int getPdgID() const
Get the PDG ID of this particle.
Definition SimParticle.h:85
std::vector< double > getEndPoint() const
Get the end_point of this particle where it was destroyed or left the world volume [mm].
std::vector< double > getMomentum() const
Get a vector containing the momentum of this particle [MeV].
Represents a simulated tracker hit in the simulation.