LDMX Software
GenieTruthDQM.cxx
1//
2// Created by Wesley Ketchum on 8/1/24.
3//
4
5#include "DQM/GenieTruthDQM.h"
6
7#include "GENIE/Framework/Conventions/KineVar.h"
8#include "SimCore/Event/HepMC3GenEvent.h"
9
10namespace dqm {
11
13 hepmc3_coll_name_ = ps.get<std::string>("hepmc3_coll_name");
14 hepmc3_pass_name_ = ps.get<std::string>("hepmc3_pass_name");
15 return;
16}
17
20
21 ntuple_.create("genie_truth");
22
23 // event info
24 ntuple_.addVar<int>("genie_truth", "run");
25 ntuple_.addVar<int>("genie_truth", "event");
26
27 ntuple_.addVar<int>("genie_truth", "interaction_type");
28 ntuple_.addVar<int>("genie_truth", "scattering_type");
29 ntuple_.addVar<int>("genie_truth", "rescatter_code");
30
31 ntuple_.addVar<double>("genie_truth", "x_bj");
32 ntuple_.addVar<double>("genie_truth", "y_inel");
33 ntuple_.addVar<double>("genie_truth", "Q2");
34 ntuple_.addVar<double>("genie_truth", "W");
35
36 ntuple_.addVar<int>("genie_truth", "lep_pdg");
37
38 ntuple_.addVar<double>("genie_truth", "lep_i_px");
39 ntuple_.addVar<double>("genie_truth", "lep_i_py");
40 ntuple_.addVar<double>("genie_truth", "lep_i_pz");
41 ntuple_.addVar<double>("genie_truth", "lep_i_e");
42
43 ntuple_.addVar<double>("genie_truth", "lep_f_px");
44 ntuple_.addVar<double>("genie_truth", "lep_f_py");
45 ntuple_.addVar<double>("genie_truth", "lep_f_pz");
46 ntuple_.addVar<double>("genie_truth", "lep_f_e");
47
48 ntuple_.addVar<int>("genie_truth", "tgt_pdg");
49 ntuple_.addVar<double>("genie_truth", "tgt_px");
50 ntuple_.addVar<double>("genie_truth", "tgt_py");
51 ntuple_.addVar<double>("genie_truth", "tgt_pz");
52 ntuple_.addVar<double>("genie_truth", "tgt_e");
53
54 ntuple_.addVar<int>("genie_truth", "hnuc_pdg");
55 ntuple_.addVar<double>("genie_truth", "hnuc_px");
56 ntuple_.addVar<double>("genie_truth", "hnuc_py");
57 ntuple_.addVar<double>("genie_truth", "hnuc_pz");
58 ntuple_.addVar<double>("genie_truth", "hnuc_e");
59
60 ntuple_.addVar<int>("genie_truth", "hqrk_pdg");
61 ntuple_.addVar<int>("genie_truth", "hqrk_sea");
62 ntuple_.addVar<double>("genie_truth", "hadsys_px");
63 ntuple_.addVar<double>("genie_truth", "hadsys_py");
64 ntuple_.addVar<double>("genie_truth", "hadsys_pz");
65 ntuple_.addVar<double>("genie_truth", "hadsys_e");
66}
67
69 run_number_ = runHeader.getRunNumber();
70}
71
74
75 ntuple_.clear();
76 ntuple_.setVar<int>("run", run_number_);
77 ntuple_.setVar<int>("event", event.getEventNumber());
78
79 auto hepmc3_col = event.getObject<std::vector<ldmx::HepMC3GenEvent> >(
80 hepmc3_coll_name_, hepmc3_pass_name_);
81
82 if (hepmc3_col.size() < 1) {
83 ntuple_.fill();
84 return;
85 }
86
87 auto const& hepmc3_ev = hepmc3_col.at(0).getHepMCGenEvent();
88
89 // set interaction/scattering codes
90 auto interaction_type_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
91 "GENIE.Interaction.InteractionType");
92 if (interaction_type_ptr)
93 ntuple_.setVar<int>("interaction_type", interaction_type_ptr->value());
94 auto scattering_type_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
95 "GENIE.Interaction.ScatteringType");
96 if (scattering_type_ptr)
97 ntuple_.setVar<int>("scattering_type", scattering_type_ptr->value());
98 auto rescatter_code_ptr =
99 hepmc3_ev.attribute<HepMC3::IntAttribute>("GENIE.RescatterCode");
100 if (rescatter_code_ptr)
101 ntuple_.setVar<int>("rescatter_code", rescatter_code_ptr->value());
102
103 // get kinematic vars
104 auto kvar_labels_ptr = hepmc3_ev.attribute<HepMC3::VectorIntAttribute>(
105 "GENIE.Interaction.KineVarLabels");
106 auto kvar_values_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
107 "GENIE.Interaction.KineVarValues");
108 if (kvar_labels_ptr && kvar_values_ptr) {
109 auto kvar_labels = kvar_labels_ptr->value();
110 auto kvar_values = kvar_values_ptr->value();
111 for (size_t i = 0; i < kvar_labels.size(); ++i) {
112 if (kvar_labels[i] == genie::EKineVar::kKVSelx)
113 ntuple_.setVar<double>("x_bj", kvar_values[i]);
114 else if (kvar_labels[i] == genie::EKineVar::kKVSely)
115 ntuple_.setVar<double>("y_inel", kvar_values[i]);
116 else if (kvar_labels[i] == genie::EKineVar::kKVSelQ2)
117 ntuple_.setVar<double>("Q2", kvar_values[i]);
118 else if (kvar_labels[i] == genie::EKineVar::kKVSelW)
119 ntuple_.setVar<double>("W", kvar_values[i]);
120 }
121 }
122
123 // electron info
124 auto lep_pdg_ptr =
125 hepmc3_ev.attribute<HepMC3::IntAttribute>("GENIE.Interaction.ProbePDG");
126 if (lep_pdg_ptr) ntuple_.setVar<int>("lep_pdg", lep_pdg_ptr->value());
127
128 auto lep_i_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
129 "GENIE.Interaction.ProbeP4");
130 if (lep_i_4vec_ptr) {
131 auto lep_i_4vec = lep_i_4vec_ptr->value();
132 ntuple_.setVar<double>("lep_i_px", lep_i_4vec[0]);
133 ntuple_.setVar<double>("lep_i_py", lep_i_4vec[1]);
134 ntuple_.setVar<double>("lep_i_pz", lep_i_4vec[2]);
135 ntuple_.setVar<double>("lep_i_e", lep_i_4vec[3]);
136 }
137 auto lep_f_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
138 "GENIE.Interaction.FSLeptonP4");
139 if (lep_f_4vec_ptr) {
140 auto lep_f_4vec = lep_f_4vec_ptr->value();
141 ntuple_.setVar<double>("lep_f_px", lep_f_4vec[0]);
142 ntuple_.setVar<double>("lep_f_py", lep_f_4vec[1]);
143 ntuple_.setVar<double>("lep_f_pz", lep_f_4vec[2]);
144 ntuple_.setVar<double>("lep_f_e", lep_f_4vec[3]);
145 }
146
147 // target info
148 auto tgt_pdg_ptr =
149 hepmc3_ev.attribute<HepMC3::IntAttribute>("GENIE.Interaction.TargetPDG");
150 if (tgt_pdg_ptr) ntuple_.setVar<int>("tgt_pdg", tgt_pdg_ptr->value());
151
152 auto tgt_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
153 "GENIE.Interaction.TargetP4");
154 if (tgt_4vec_ptr) {
155 auto tgt_4vec = tgt_4vec_ptr->value();
156 ntuple_.setVar<double>("tgt_px", tgt_4vec[0]);
157 ntuple_.setVar<double>("tgt_py", tgt_4vec[1]);
158 ntuple_.setVar<double>("tgt_pz", tgt_4vec[2]);
159 ntuple_.setVar<double>("tgt_e", tgt_4vec[3]);
160 }
161
162 // hit nucleon info
163 auto hnuc_pdg_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
164 "GENIE.Interaction.HitNucleonPDG");
165 if (hnuc_pdg_ptr) ntuple_.setVar<int>("hnuc_pdg", hnuc_pdg_ptr->value());
166
167 auto hitnuc_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
168 "GENIE.Interaction.HitNucleonP4");
169 if (hitnuc_4vec_ptr) {
170 auto hitnuc_4vec = hitnuc_4vec_ptr->value();
171 ntuple_.setVar<double>("hnuc_px", hitnuc_4vec[0]);
172 ntuple_.setVar<double>("hnuc_py", hitnuc_4vec[1]);
173 ntuple_.setVar<double>("hnuc_pz", hitnuc_4vec[2]);
174 ntuple_.setVar<double>("hnuc_e", hitnuc_4vec[3]);
175 }
176 // hit quark info
177 // note: it's only there for some interaction types!
178 auto hqrkpdg_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
179 "GENIE.Interaction.HitQuarkPDG");
180 if (hqrkpdg_ptr) ntuple_.setVar<int>("hqrk_pdg", hqrkpdg_ptr->value());
181 auto hqrksea_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
182 "GENIE.Interaction.HitSeaQuark");
183 if (hqrksea_ptr) ntuple_.setVar<int>("hqrk_sea", hqrksea_ptr->value());
184
185 auto hadsys_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
186 "GENIE.Interaction.HadSystP4");
187 if (hadsys_4vec_ptr) {
188 auto hadsys_4vec = hadsys_4vec_ptr->value();
189 ntuple_.setVar<double>("hadsys_px", hadsys_4vec[0]);
190 ntuple_.setVar<double>("hadsys_py", hadsys_4vec[1]);
191 ntuple_.setVar<double>("hadsys_pz", hadsys_4vec[2]);
192 ntuple_.setVar<double>("hadsys_e", hadsys_4vec[3]);
193 }
194 ntuple_.fill();
195
196 return;
197}
198
199} // namespace dqm
200
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Generate histograms/ntuple to extract genie output info.
virtual void analyze(const framework::Event &event)
Fills histograms/ntuples.
virtual void onNewRun(const ldmx::RunHeader &runHeader)
Grab the run number...
virtual void onProcessStart()
Construct histograms/ntuples.
virtual void configure(framework::config::Parameters &ps)
Input python configuration parameters.
std::string hepmc3_coll_name_
Pass Name for genie objects.
NtupleManager & ntuple_
Manager for any ntuples.
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:40
void addVar(const std::string &tname, const std::string &vname)
Add a variable of type VarType to the ROOT tree with name 'tname'.
void create(const std::string &tname)
Create a ROOT tree to hold the ntuple variables (ROOT leaves).
void clear()
Reset all of the variables to their limits.
void setVar(const std::string &vname, const T &value)
Set the value of the variable named 'vname'.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:68
int getRunNumber() const
Definition RunHeader.h:96