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
16 // Grab the SimParticle Map and Target Scoring Plane Hits
17 auto targetSPHits(
18 event.getCollection<ldmx::SimTrackerHit>("TargetScoringPlaneHits"));
19 auto particle_map{event.getMap<int, ldmx::SimParticle>("SimParticles")};
20
21 std::vector<int> primary_daughters;
22
23 double hard_thresh{9999.0};
24
25 // Loop over all SimParticles
26 for (auto const& it : particle_map) {
27 ldmx::SimParticle p = it.second;
28 int pdgid = p.getPdgID();
29 std::vector<double> vertex = p.getVertex();
30 double energy = p.getEnergy();
31 std::vector<int> parents_track_ids = p.getParents();
32 std::vector<int> daughters = p.getDaughters();
33
34 for (auto const& parent_track_id : parents_track_ids) {
35 if (parent_track_id == 0) {
36 histograms_.fill("pdgid_primaries", pdgid_label(pdgid));
37 histograms_.fill("energy_primaries", energy);
38 hard_thresh = (2500. / 4000.) * energy;
39 primary_daughters = daughters;
40 for (const ldmx::SimTrackerHit& sphit : targetSPHits) {
41 if (sphit.getTrackID() == it.first && sphit.getPosition()[2] < 0) {
42 histograms_.fill("beam_smear", vertex[0], vertex[1]);
43 }
44 }
45 }
46 }
47 }
48
49 std::vector<std::vector<int>> hardbrem_daughters;
50
51 for (auto const& it : particle_map) {
52 int trackid = it.first;
53 ldmx::SimParticle p = it.second;
54 for (auto const& primary_daughter : primary_daughters) {
55 if (trackid == primary_daughter) {
56 histograms_.fill("pdgid_primarydaughters", pdgid_label(p.getPdgID()));
57 if (p.getPdgID() == 22) {
58 histograms_.fill("energy_daughterphoton", p.getEnergy());
59 }
60 if (p.getEnergy() >= hard_thresh) {
61 histograms_.fill("pdgid_harddaughters", pdgid_label(p.getPdgID()));
62 histograms_.fill("startZ_hardbrem", p.getVertex()[2]);
63 histograms_.fill("endZ_hardbrem", p.getEndPoint()[2]);
64 histograms_.fill("energy_hardbrem", p.getEnergy());
65 hardbrem_daughters.push_back(p.getDaughters());
66 }
67 }
68 }
69 }
70
71 for (auto const& it : particle_map) {
72 int trackid = it.first;
73 ldmx::SimParticle p = it.second;
74 for (const std::vector<int>& daughter_track_id : hardbrem_daughters) {
75 for (const int& daughter_id : daughter_track_id) {
76 if (trackid == daughter_id) {
77 histograms_.fill("pdgid_hardbremdaughters",
78 pdgid_label(p.getPdgID()));
79 histograms_.fill("startZ_hardbremdaughters", p.getVertex()[2]);
80 }
81 }
82 }
83 }
84
85 return;
86}
87
88int SampleValidation::pdgid_label(const int pdgid) {
89 // initially assign label as "anything else"/overflow value,
90 // only change if the pdg id is something of interest
91 int label = 19;
92 if (pdgid == -11) label = 1; // e+
93 if (pdgid == 11) label = 2; // e-
94 if (pdgid == -13) label = 3; // μ+
95 if (pdgid == 13) label = 4; // μ-
96 if (pdgid == 22) label = 5; // γ
97 if (pdgid == 2212) label = 6; // proton
98 if (pdgid == 2112) label = 7; // neutron
99 if (pdgid == 211) label = 8; //π+
100 if (pdgid == -211) label = 9; //π-
101 if (pdgid == 111) label = 10; //π0
102 if (pdgid == 321) label = 11; // K+
103 if (pdgid == -321) label = 12; // K-
104 if (pdgid == 130) label = 13; // K-Long
105 if (pdgid == 310) label = 14; // K-Short
106 if (pdgid == 3122 || pdgid == 3222 || pdgid == 3212 || pdgid == 3112 ||
107 pdgid == 3322 || pdgid == 3312)
108 label = 17; // strange baryon
109 /*
110 * Nuclear PDG codes are given by ±10LZZZAAAI so to find the atomic
111 * number, we divide by 10 (to lose I) and then take the modulo
112 * with 1000.
113 */
114 if (pdgid > 1000000000) { // nuclei
115 if (((pdgid / 10) % 1000) <= 4) {
116 label = 15; // light nuclei
117 } else {
118 label = 16; // heavy nuclei
119 }
120 }
121 if (pdgid == 622)
122 label =
123 18; // dark photon, need pdg id for other models like ALPs and SIMPs
124
125 return label;
126}
127
129 std::vector<std::string> labels = {"",
130 "e^{+}", // 1
131 "e^{-}", // 2
132 "#mu^{+}", // 3
133 "#mu^{-}", // 4
134 "#gamma", // 5
135 "p^{+}", // 6
136 "n^{0}", // 7
137 "#pi^{+}", // 8
138 "#pi^{-}", // 9
139 "#pi^{0}", // 10
140 "K^{+}", // 11
141 "K^{-}", // 12
142 "K_{L}", // 13
143 "K_{S}", // 14
144 "light-N", // 15
145 "heavy-N", // 16
146 "#Lambda / #Sigma / #Xi", // 17
147 "A'", // 18
148 "else",
149 ""};
150
151 std::vector<TH1*> hists = {
152 histograms_.get("pdgid_primaries"),
153 histograms_.get("pdgid_primarydaughters"),
154 histograms_.get("pdgid_harddaughters"),
155 histograms_.get("pdgid_hardbremdaughters"),
156
157 };
158
159 for (int ilabel{1}; ilabel < labels.size(); ++ilabel) {
160 for (auto& hist : hists) {
161 hist->GetXaxis()->SetBinLabel(ilabel, labels[ilabel - 1].c_str());
162 }
163 }
164}
165} // namespace dqm
166DECLARE_ANALYZER_NS(dqm, SampleValidation)
#define DECLARE_ANALYZER_NS(NS, 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.
void onProcessStart() override
Method executed before processing of events begins.
virtual void analyze(const framework::Event &event) override
Process the event and make histograms or summaries.
HistogramHelper histograms_
Interface class for making and filling histograms.
Implements an event buffer system for storing event data.
Definition Event.h:41
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:386
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
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
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 endpoint of this particle where it was destroyed or left the world volume [mm].
Represents a simulated tracker hit in the simulation.