LDMX Software
TrigHcalEnergySum.cxx
2
4#include "Hcal/HcalTriggerGeometry.h"
5#include "Recon/Event/CaloTrigPrim.h"
7#include "Trigger/Event/TrigEnergySum.h"
8
9namespace trigger {
10
12 inProc_ = ps.getParameter<std::string>("inputProc");
13 quadCollName_ = ps.getParameter<std::string>("quadCollName");
14 combinedQuadCollName_ = ps.getParameter<std::string>("combinedQuadCollName");
15}
17 // mV/ADC: 1.2
18 // MeV/MIP: 4.66
19 // PE/MIP: 68 (summed over BOTH ends, based on 1808.05219, p38)
20 // mV/PE: 5
21 // mV/MeV: 72.961 (= 5*68/4.66)
22 // const float mV_per_adc = 1.2;
23 // adc gain
24 // these are unused, should they be? FIXME
25 // const float pe_per_adc = mV_per_adc / 5;
26 // const float MeV_per_adc = mV_per_adc / 72.961;
27 // const float samp_frac = 371/4e3; // ad-hoc, from a 4 GeV neutron sample
28
29 // interaction length in Fe ('steel') = 16.77 cm (132.1 g/cm2)
30 // polystyrene = 77.07 cm (81.7 g/cm2)
31 // back hcal is 20mm bar, 25mm absorber
32 // these are unused, should they be? FIXME
33 // const float had_samp_frac =
34 // (20 / 77.07) / (20 / 77.07 + 25 / 16.77); // 0.148266
35 // const float em_samp_frac =
36 // (20 / 41.31) / (20 / 41.31 + 25 / 1.757); // 0.032906
37 // const float samp_frac = (em_samp_frac + 2 * had_samp_frac) / 3; //
38 // 0.109813 const float attenuation = exp(-1 / 5.); // 5m attenuation length,
39 // 1m half-bar
40
41 // for(auto t : event.searchProducts("","","")) std::cout << t.name() << " "
42 // << t.passname() << " " << t.type() << std::endl;
43
44 if (!event.exists(quadCollName_, inProc_)) {
45 // std::cout << "missing collection! : " << quadCollName_ << " " << inProc_
46 // << std::endl;
47 return;
48 }
49
50 // auto
51 // oneEndedQuads{event.getObject<ldmx::CaloTrigPrimCollection>(quadCollName_)};
52 const std::vector<ldmx::CaloTrigPrim> oneEndedQuads =
53 event.getCollection<ldmx::CaloTrigPrim>(quadCollName_, inProc_);
54
55 //
56 // sum bar ends to produce the combined quads
57 std::map<int, ldmx::CaloTrigPrim> twoEndedQuadMap;
58 for (const auto& oneEndedQuad : oneEndedQuads) {
59 const ldmx::HcalTriggerID end_id(oneEndedQuad.getId());
60 ldmx::HcalTriggerID combo_id(end_id.section(), end_id.layer(),
61 end_id.superstrip(), 2);
62 auto ptr = twoEndedQuadMap.find(combo_id.raw());
63 if (ptr == twoEndedQuadMap.end()) {
64 twoEndedQuadMap[combo_id.raw()] = oneEndedQuad;
65 } else {
66 ptr->second.setPrimitive(ptr->second.getPrimitive() +
67 oneEndedQuad.getPrimitive());
68 }
69 }
70 ldmx::CaloTrigPrimCollection twoEndedQuads;
71 for (auto p : twoEndedQuadMap) twoEndedQuads.push_back(p.second);
72 event.add(combinedQuadCollName_, twoEndedQuads);
73
74 //
75 // Produce the layer-by-layer energy sums
76 const unsigned int LayerMax = 50;
77 const unsigned int SideLayerMax = 16;
78 trigger::TrigEnergySumCollection backLayerSums;
79 trigger::TrigEnergySumCollection sideLayerSums;
80 backLayerSums.resize(LayerMax);
81 for (int i = 0; i < LayerMax; i++) backLayerSums[i].setLayer(i);
82 sideLayerSums.resize(SideLayerMax);
83 for (int i = 0; i < SideLayerMax; i++) sideLayerSums[i].setLayer(i);
84
85 int total_adc = 0;
86 std::map<int, int> section_sum;
87 for (auto p : twoEndedQuadMap) {
88 auto tp = p.second;
89 int adc = tp.getPrimitive();
90 total_adc += adc;
91 ldmx::HcalTriggerID combo_id(tp.getId());
92 int ilayer = combo_id.layer();
93 if (ilayer >= backLayerSums.size()) {
94 std::cout << "[TrigHcalEnergySum.cxx] Warning(!), layer " << ilayer
95 << " is out-of-bounds.\n";
96 continue;
97 }
98 int isec = combo_id.section();
99
100 if (isec == 0)
101 backLayerSums[ilayer].setHwEnergy(adc + backLayerSums[ilayer].hwEnergy());
102 else
103 sideLayerSums[ilayer].setHwEnergy(adc + sideLayerSums[ilayer].hwEnergy());
104
105 auto ptr = section_sum.find(isec);
106 if (ptr == section_sum.end()) {
107 section_sum[isec] = adc;
108 } else {
109 section_sum[isec] += adc;
110 }
111 }
112 event.add(combinedQuadCollName_ + "BackLayerSums", backLayerSums);
113 event.add(combinedQuadCollName_ + "SideLayerSums", sideLayerSums);
114
115 trigger::TrigEnergySumCollection sectionSums;
116 for (auto p : section_sum) {
117 sectionSums.emplace_back(-1, p.first, p.second);
118 }
119 event.add(combinedQuadCollName_ + "SectionSums", sectionSums);
120
121 // Also store total energy for now
122 trigger::TrigEnergySum totalSum;
123 totalSum.setLayer(-1);
124 totalSum.setHwEnergy(total_adc);
125 event.add(combinedQuadCollName_ + "Sum", totalSum);
126}
127
128} // namespace trigger
129
130DECLARE_PRODUCER_NS(trigger, TrigHcalEnergySum);
Class that represents a reconstructed hit in a calorimeter cell within the detector.
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that translates HCal ID into positions of strip hits.
HcalEnergySum algo.
Implements an event buffer system for storing event data.
Definition Event.h:41
bool exists(const std::string &name, const std::string &passName="", bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
Definition Event.cxx:92
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
Contains the trigger output for generic calo objects.
RawValue raw() const
Definition DetectorID.h:68
Extension of DetectorID providing access to HCal trigger cell.
int superstrip() const
Get the value of the 'superstrip' field from the ID.
int layer() const
Get the value of the layer field from the ID.
Contains the trigger output for generic calo objects.
virtual void configure(framework::config::Parameters &ps)
Callback for the EventProcessor to configure itself from the given set of parameters.
virtual void produce(framework::Event &event)
Process the event and put new data products into it.