LDMX Software
TrigPrimResolutionAnalyzer.cxx
1#include "DetDescr/EcalID.h"
4#include "Ecal/Event/EcalHit.h"
7#include "Recon/Event/HgcrocTrigDigi.h"
8
9namespace ldmx {
10namespace ecal {
19 std::string trig_collection_name_ = "ecalTrigDigis";
20 std::string trig_pass_name_ = "";
21 std::string hit_collection_name_ = "EcalRecHits";
22 std::string hit_pass_name_ = "";
23 double total_trigger_mean_ = 876.28120;
24 double total_ampl_mean_ = 48.805244;
25 double nominal_{1.0};
26 double second_order_energy_correction_ = 4000. / 3940.5;
27 double mip_si_energy_ = 0.13;
28 std::vector<double> layer_weights_ = {
29 2.312, 4.312, 6.522, 7.490, 8.595, 10.253, 10.915, 10.915, 10.915,
30 10.915, 10.915, 10.915, 10.915, 10.915, 10.915, 10.915, 10.915, 10.915,
31 10.915, 10.915, 10.915, 10.915, 10.915, 14.783, 18.539, 18.539, 18.539,
32 18.539, 18.539, 18.539, 18.539, 18.539, 18.539, 9.938};
33
34 public:
35 TrigPrimResolutionAnalyzer(const std::string& name,
38 virtual ~TrigPrimResolutionAnalyzer() = default;
39 void configure(framework::config::Parameters& parameters) final;
40 void onProcessStart() final;
41 void analyze(const framework::Event& event) final;
42
48 double calculateEnergy(int layer_, double amplitude) {
49 return (1 + layer_weights_[layer_] / mip_si_energy_) * amplitude *
50 second_order_energy_correction_;
51 }
52};
53
63#define optional_update(variable) \
64 variable##_ = parameters.getParameter(#variable, variable##_)
65
68 optional_update(trig_collection_name);
69 optional_update(trig_pass_name);
70 optional_update(hit_collection_name);
71 optional_update(hit_pass_name);
72 optional_update(total_trigger_mean);
73 optional_update(total_ampl_mean);
74 optional_update(second_order_energy_correction);
75 optional_update(mip_si_energy);
76 optional_update(layer_weights);
77
78 // nominal scale separation between trigger and precision would be
79 // determined experimentally by comparing their values
80 // nominal_ = total_trigger_mean_ / total_ampl_mean_;
81 // this has already been done so we just hardcode in the value
82 // determined by Steven Metallo in 2024, but it can be updated
83 // to use the ratio of the totals like above
84 nominal_ = 18.14;
85}
86
88 // variable bins
89 std::vector<double> binsx = {0., 10., 20., 30., 40., 50., 60.,
90 70., 80., 90., 100., 110., 120., 130.,
91 140., 150., 300., 575., 1000.};
92 std::vector<double> binsy = {
93 0.6, 0.608, 0.616, 0.624, 0.632, 0.64, 0.648, 0.656, 0.664, 0.672,
94 0.68, 0.688, 0.696, 0.704, 0.712, 0.72, 0.728, 0.736, 0.744, 0.752,
95 0.76, 0.768, 0.776, 0.784, 0.792, 0.8, 0.808, 0.816, 0.824, 0.832,
96 0.84, 0.848, 0.856, 0.864, 0.872, 0.88, 0.888, 0.896, 0.904, 0.912,
97 0.92, 0.928, 0.936, 0.944, 0.952, 0.96, 0.968, 0.976, 0.984, 0.992,
98 1., 1.008, 1.016, 1.024, 1.032, 1.04, 1.048, 1.056, 1.064, 1.072,
99 1.08, 1.088, 1.096, 1.104, 1.112, 1.12, 1.128, 1.136, 1.144, 1.152,
100 1.16, 1.168, 1.176, 1.184, 1.192, 1.2, 1.208, 1.216, 1.224, 1.232,
101 1.24, 1.248, 1.256, 1.264, 1.272, 1.28, 1.288, 1.296, 1.304, 1.312,
102 1.32, 1.328, 1.336, 1.344, 1.352, 1.36, 1.368, 1.376, 1.384, 1.392,
103 1.4};
104 std::vector<double> binsx_fin = {0., 10., 20., 30., 40., 50., 60., 70.,
105 80., 90., 100., 150., 300., 575., 1000.};
106
107 // initialize processing by making histograms and such
108 // first, we get the directory for this processor in the histogram file
110 // then we can create histograms within it
112 "total_trig_energy" /* name - as written in output ROOT file */,
113 "Total of all Trig Digis [MeV]" /* xlabel - axis label of histogram */,
114 100 /* number of bins */, 0 /* minimum value */, 8000 /* maximum value */
115 );
116 histograms_.create("total_ampl_energy",
117 "Total of Precision Hit Amplitudes [MeV]", 100, 0, 8000);
118 histograms_.create("total_trig_v_total_ampl", "Total of all Trig Digis [MeV]",
119 1000, 0, 8000, "Total of Precision Hit Amplitudes [MeV]",
120 100, 0, 8000);
121 histograms_.create("trig_ampl_nominal", "Total trig / total ampl", 100, 0.85,
122 1.15);
123 histograms_.create("module_id", "Module id", 7, 0, 7);
124 histograms_.create("layer_id", "Layer id", 34, 0, 34);
125 histograms_.create("trig_sum_per_module", "module_ trigger sum [MeV]", 100, 0,
126 2000);
127 histograms_.create("ampl_sum_per_module", "module_ precision ampl sum [MeV]",
128 100, 0, 2000);
129 histograms_.create("trig_v_ampl_module", "Module-sum full readout [MeV]", 100,
130 0, 2000, "Module-sum trigger [MeV]", 100, 0, 2000);
131 histograms_.create("trig_sum_per_layer", "layer_ trigger sum [MeV]", 100, 0,
132 2000);
133 histograms_.create("ampl_sum_per_layer", "layer_ precision ampl sum [MeV]",
134 100, 0, 2000);
135 histograms_.create("trig_v_ampl_layer", "Layer trigger total [MeV]", 100, 0,
136 2500, "Layer ampl total [MeV]", 100, 0, 2500);
137 histograms_.create("trig_ampl_v_ampl", "module_ precision ampl sum [MeV]",
138 100, 0, 1000, "module_ trigger / module_ precision ampl",
139 100, 0.4, 1.2);
140 histograms_.create("trig_ampl_v_ampl_binadjust",
141 "module_ precision trig sum [MeV]", 100, 0, 2000,
142 "module_ trigger / module_ precision ampl", 100, 0.4, 1.2);
143 histograms_.create("trig_ampl_v_ampl_layer",
144 "layer_ precision ampl sum [MeV]", 100, 0, 1000,
145 "layer_ trigger / layer_ precision ampl", 100, 0.4, 1.2);
146 histograms_.create("trig_ampl_v_ampl_total", "total precision ampl sum [MeV]",
147 100, 0, 8000, "total trigger / total precision ampl", 100,
148 0.9, 1.1);
149 histograms_.create("trig_ampl_v_ampl_total_first20", "Full readout sum [MeV]",
150 100, 0, 6000, "Trigger / Full readout", 100, 0.95, 1.05);
151 histograms_.create("trig_group", "trigger group total precision hits_ [MeV]",
152 100, 0, 2000);
153 histograms_.create("trig_group_trigger", "trigger group trigger [MeV]", 100,
154 0, 8000);
155 histograms_.create("trig_group_v_trig",
156 "trigger group total precision hits_ [MeV]", 100, 0, 2000,
157 "trigger group trigger [MeV]", 100, 0, 8000);
158 histograms_.create("trig_group_ampl_v_ampl",
159 "Trigger group full readout [MeV]", 100, 0, 1000,
160 "Trigger group ratio / nominal", 200, 0.6, 1.4);
161 histograms_.create("trig_group_ampl_v_ampl_varbin",
162 "Trigger group full readout [MeV]", binsx,
163 "Trigger group ratio / nominal", binsy);
164 histograms_.create("trig_group_ampl_unweight",
165 "unweighted trigger group total precision hits_ [MeV]",
166 100, 0, 20,
167 "trigger group trigger / unweighted trigger group total "
168 "prec hits_ / nominal",
169 200, 0.6, 1.4);
170 histograms_.create("trig_group_ampl_v_ampl_varbin_fin",
171 "Trigger group full readout [MeV]", binsx_fin,
172 "Trigger group ratio / nominal", binsy);
173}
174
183 unsigned int layer_;
184 unsigned int module_;
186 layer_ = tid.getLayerID();
187 module_ = tid.getModuleID();
188 }
189 UniqueModule(EcalID eid) {
190 layer_ = eid.getLayerID();
191 module_ = eid.getModuleID();
192 }
193};
194
198bool operator<(const UniqueModule& lhs, const UniqueModule& rhs) {
199 if (lhs.layer_ < rhs.layer_) return true;
200 if (lhs.layer_ > rhs.layer_) return false;
201 // lhs.layer_ == rhs.layer_
202 return (lhs.module_ < rhs.module_);
203}
204
216float getEstimate(const HgcrocTrigDigi& trig) {
217 uint32_t prim{trig.linearPrimitive()};
218 if (prim < 15) {
219 return (static_cast<float>(prim) + 0.5);
220 }
221 return static_cast<float>(prim);
222}
223
225 // called once on each event, get objects and fill histograms
226 const auto& trigs = event.getCollection<ldmx::HgcrocTrigDigi>(
227 trig_collection_name_, trig_pass_name_);
228 // trigs are a std::vector<ldmx::HgcrocTrigDigi>
229 const auto& hits =
230 event.getCollection<ldmx::EcalHit>(hit_collection_name_, hit_pass_name_);
231 // hits_ are a std::vector<ldmx::EcalHit>
232 const ::ecal::EcalTriggerGeometry& geom =
234 ::ecal::EcalTriggerGeometry::CONDITIONS_OBJECT_NAME);
235
236 std::map<UniqueModule, std::pair<int, double>> module_sums;
237 int trig_prim_total{0};
238 int trig_prim_total_first20{0};
239 for (const auto& trig : trigs) {
240 EcalTriggerID tid{trig.getId()};
241 UniqueModule mod{tid};
242 double trig_ampl = getEstimate(trig);
243 double trig_energy = calculateEnergy(mod.layer_, trig_ampl) / nominal_;
244
246 if (module_sums.find(mod) == module_sums.end()) {
247 module_sums[mod] = {0, 0.0};
248 }
249
250 module_sums[mod].first += trig_energy;
251 trig_prim_total += trig_energy;
252 if (mod.layer_ <= 20) {
253 trig_prim_total_first20 += trig_energy;
254 }
255
256 // calculate the sum of precision hits_ for the 9 cells in this
257 // trigger grouping
258 double trig_group_prec_total{0};
259 double trig_group_prec_total_unweight{0};
260 for (auto& prec_id : geom.contentsOfTriggerCell(tid)) {
261 for (const auto& hit : hits) {
262 if (prec_id == hit.getID()) {
263 trig_group_prec_total +=
264 calculateEnergy(mod.layer_, hit.getAmplitude());
265 trig_group_prec_total_unweight += hit.getAmplitude();
266 }
267 }
268 }
269
270 // have trig_group_prec_total which is the sum of the precision hits_
271 // in that trigger group and trig_ampl is the sum
272 // as reported by the trigger itself
273 double ratio_energy = trig_energy / trig_group_prec_total,
274 ratio_ampl = trig_ampl / trig_group_prec_total_unweight / nominal_;
275 histograms_.fill("trig_group", trig_group_prec_total);
276 histograms_.fill("trig_group_trigger", trig_energy * nominal_);
277 histograms_.fill("trig_group_v_trig", trig_group_prec_total,
278 trig_energy * nominal_);
279 histograms_.fill("trig_group_ampl_v_ampl", trig_group_prec_total,
280 ratio_energy);
281 histograms_.fill("trig_group_ampl_v_ampl_varbin", trig_group_prec_total,
282 ratio_energy);
283 histograms_.fill("trig_group_ampl_v_ampl_varbin_fin", trig_group_prec_total,
284 ratio_energy);
285 histograms_.fill("trig_group_ampl_unweight", trig_group_prec_total_unweight,
286 ratio_ampl);
287 }
288
289 double prec_ampl_total{0.};
290 double prec_ampl_total_first20{0.};
291 for (const auto& hit : hits) {
292 EcalID id{static_cast<unsigned int>(hit.getID())};
293 UniqueModule mod{id};
294 if (module_sums.find(mod) == module_sums.end()) {
295 module_sums[mod] = {0, 0.0};
296 }
297 double prec_energy = calculateEnergy(mod.layer_, hit.getAmplitude());
298 module_sums[mod].second += prec_energy;
299 prec_ampl_total += prec_energy;
300 if (mod.layer_ <= 20) {
301 prec_ampl_total_first20 += prec_energy;
302 }
303 }
304
305 std::map<int, std::pair<int, double>> layer_sums;
306 for (const auto& [unique_module, sum_pair] : module_sums) {
307 if (layer_sums.find(unique_module.layer_) == layer_sums.end()) {
308 // layer_ is not found in layer_sums map so start the sum at 0
309 layer_sums[unique_module.layer_] = {0, 0.0};
310 }
311 // add this module_ total to running total for the layer_
312 layer_sums[unique_module.layer_].first += sum_pair.first;
313 layer_sums[unique_module.layer_].second += sum_pair.second;
314 }
315
316 int layer_id_tmp = {0};
317 int module_id_tmp = {0};
318 for (const auto& [mod_id, sum_pair] : module_sums) {
319 /* std::cout << " layer_ id " << mod_id.layer_ << " mod id " <<
320 * mod_id.module_ << std::endl; */
321 layer_id_tmp = mod_id.layer_;
322 module_id_tmp = mod_id.module_;
323 histograms_.fill("layer_id", layer_id_tmp);
324 histograms_.fill("module_id", module_id_tmp);
325 histograms_.fill("trig_sum_per_module", sum_pair.first);
326 histograms_.fill("ampl_sum_per_module", sum_pair.second);
327 histograms_.fill("trig_v_ampl_module", sum_pair.second, sum_pair.first);
328 histograms_.fill("trig_ampl_v_ampl", sum_pair.second,
329 sum_pair.first / sum_pair.second);
330 histograms_.fill("trig_ampl_v_ampl_binadjust", sum_pair.second,
331 sum_pair.first / sum_pair.second);
332 }
333
334 for (const auto& [layer_, layer_sum_pair] : layer_sums) {
335 histograms_.fill("trig_sum_per_layer", layer_sum_pair.first);
336 histograms_.fill("ampl_sum_per_layer", layer_sum_pair.second);
337 histograms_.fill("trig_v_ampl_layer", layer_sum_pair.first,
338 layer_sum_pair.second);
339 histograms_.fill("trig_ampl_v_ampl_layer", layer_sum_pair.second,
340 layer_sum_pair.first / layer_sum_pair.second);
341 }
342
343 histograms_.fill("total_trig_energy", trig_prim_total);
344 histograms_.fill("total_ampl_energy", prec_ampl_total);
345 histograms_.fill("total_trig_v_total_ampl", trig_prim_total, prec_ampl_total);
346 histograms_.fill("trig_ampl_nominal", trig_prim_total / prec_ampl_total);
347 histograms_.fill("trig_ampl_v_ampl_total", prec_ampl_total,
348 trig_prim_total / prec_ampl_total);
349 histograms_.fill("trig_ampl_v_ampl_total_first20", prec_ampl_total_first20,
350 trig_prim_total_first20 / prec_ampl_total_first20);
351}
352
353} // namespace ecal
354} // namespace ldmx
355
Class that defines an ECal detector ID with a cell number.
Class that defines the relationship between precision cells and trigger cells and provides geometry i...
Class that defines an ECal trigger cell detector ID.
Base classes for all user event processing components to extend.
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Class that represents a digitized hit in a calorimeter cell readout by an HGCROC.
Base class for a module which does not produce a data product.
virtual void process(Event &event) final
Processing an event for an Analyzer is calling analyze.
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
HistogramPool histograms_
helper object for making and filling histograms
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 create(const config::Parameters &p)
Create a histogram from the input configuration parameters.
void fill(const std::string &name, const T &val)
Fill a 1D histogram.
Class which represents the process under execution.
Definition Process.h:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Stores reconstructed hit information from the ECAL.
Definition EcalHit.h:19
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20
int getLayerID() const
Get the value of the layer field from the ID.
Definition EcalID.h:105
int getModuleID() const
Get the value of the module field from the ID.
Definition EcalID.h:93
Extension of DetectorID providing access to ECal trigger cell information.
int getLayerID() const
Get the value of the layer field from the ID.
int getModuleID() const
Get the value of the module field from the ID.
Contains the trigger output for a single trigger hgcroc channel.
uint32_t linearPrimitive() const
Get the linearized value of the trigger primitive.
uint32_t getId() const
Get the id of the digi.
Analyze the trigger primitives by comparing them to the precision hits_.
void configure(framework::config::Parameters &parameters) final
Callback for the EventProcessor to configure itself from the given set of parameters.
void onProcessStart() final
Callback for the EventProcessor to take any necessary action when the processing of events starts,...
double calculateEnergy(int layer_, double amplitude)
Calculate the energy deposited estimate from a hit's amplitude.
void analyze(const framework::Event &event) final
Process the event and make histograms or summaries.
structure holding data uniquely identifying a specific module_ in the ECal