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