LDMX Software
EcalTPSelector.cxx
2
3namespace trigger {
4
6 tpCollName_ = ps.getParameter<std::string>("tpCollName");
7 passCollName_ = ps.getParameter<std::string>("passCollName");
8}
9
11 if (!event.exists(tpCollName_)) return;
12 auto ecalTrigDigis{
13 event.getObject<ldmx::HgcrocTrigDigiCollection>(tpCollName_)};
14
15 std::map<int, ldmx::HgcrocTrigDigiCollection> lDigis; // left
16 std::map<int, ldmx::HgcrocTrigDigiCollection> rDigis; // right
17 std::map<int, ldmx::HgcrocTrigDigiCollection> cDigis; // center
18 std::map<int, int> lSums; // left
19 std::map<int, int> rSums; // right
20 std::map<int, int> cSums; // center
21 for (const auto& trigDigi : ecalTrigDigis) {
22 ldmx::EcalTriggerID tid(trigDigi.getId());
23 int module = tid.module();
24 int layer = tid.layer();
25 if (module > 3) {
26 auto ptr = lDigis.find(layer);
27 if (ptr == lDigis.end()) {
28 lDigis[layer] = {trigDigi};
29 lSums[layer] = trigDigi.linearPrimitive();
30 } else {
31 lDigis[layer].push_back(trigDigi);
32 lSums[layer] += trigDigi.linearPrimitive();
33 }
34 } else if (module > 0) {
35 auto ptr = rDigis.find(layer);
36 if (ptr == rDigis.end()) {
37 rDigis[layer] = {trigDigi};
38 rSums[layer] = trigDigi.linearPrimitive();
39 } else {
40 rDigis[layer].push_back(trigDigi);
41 rSums[layer] += trigDigi.linearPrimitive();
42 }
43 } else {
44 auto ptr = cDigis.find(layer);
45 if (ptr == cDigis.end()) {
46 cDigis[layer] = {trigDigi};
47 cSums[layer] = trigDigi.linearPrimitive();
48 } else {
49 cDigis[layer].push_back(trigDigi);
50 cSums[layer] += trigDigi.linearPrimitive();
51 }
52 }
53 }
54
55 // Enforce truncation.
56 // For outer modules, the energy sort is not possible
57 // Instead, sort by ID to be deterministic.
58 ldmx::HgcrocTrigDigiCollection passTPs;
59 passTPs.reserve(ecalTrigDigis.size());
60 for (auto& pair : lDigis) {
61 auto& digis = pair.second;
62 if (digis.size() > maxOuterTPs_) {
63 std::sort(digis.begin(), digis.end(),
65 return a.getId() > b.getId();
66 });
67 digis.resize(maxCentralTPs_);
68 }
69 passTPs.insert(passTPs.end(), digis.begin(), digis.end());
70 }
71 for (auto& pair : rDigis) {
72 auto& digis = pair.second;
73 if (digis.size() > maxOuterTPs_) {
74 std::sort(digis.begin(), digis.end(),
76 return a.getId() > b.getId();
77 });
78 digis.resize(maxCentralTPs_);
79 }
80 passTPs.insert(passTPs.end(), digis.begin(), digis.end());
81 }
82 // center digis, can sort by energy
83 for (auto& pair : cDigis) {
84 auto& digis = pair.second;
85 if (digis.size() > maxCentralTPs_) {
86 std::sort(digis.begin(), digis.end(),
88 return a.getPrimitive() > b.getPrimitive();
89 });
90 digis.resize(maxCentralTPs_);
91 }
92 passTPs.insert(passTPs.end(), digis.begin(), digis.end());
93 }
94
95 // collections to record (corrected to MeV)
96 TrigCaloHitCollection passTrigHits;
97 for (const auto& tp : passTPs) {
98 double x, y, z, e;
99 decodeTP(tp, x, y, z, e);
100 passTrigHits.emplace_back(x, y, z, e);
101 }
102
103 TrigEnergySumCollection passTrigSums;
104 ecalTpToE cvt;
105 for (auto& pair : lSums) {
106 double e = cvt.calc(pair.second, pair.first);
107 // TrigEnergySum s(pair.first, 4, e);
108 passTrigSums.emplace_back(pair.first, 4, e);
109 }
110 for (auto& pair : rSums) {
111 double e = cvt.calc(pair.second, pair.first);
112 // TrigEnergySum s(pair.first, 1, e);
113 passTrigSums.emplace_back(pair.first, 1, e);
114 }
115 for (auto& pair : cSums) {
116 double e = cvt.calc(pair.second, pair.first);
117 // TrigEnergySum s(pair.first, 0, e);
118 passTrigSums.emplace_back(pair.first, 0, e);
119 }
120
121 event.add(passCollName_ + "Hits", passTrigHits);
122 event.add(passCollName_ + "Sums", passTrigSums);
123}
124
125// double EcalTPSelector::primitiveToEnergy(int tp, int layer){
126// float sie = hgc_compression_factor_ * tp *
127// gain_ * mVtoMeV_; // in MeV, before layer corrections
128// return (sie / mipSiEnergy_ * layerWeights.at(layer) + sie) *
129// secondOrderEnergyCorrection_ * adHoc_;
130// }
131
132void EcalTPSelector::decodeTP(ldmx::HgcrocTrigDigi tp, double& x, double& y,
133 double& z, double& e) {
134 ldmx::EcalTriggerID tid(tp.getId());
135 const ecal::EcalTriggerGeometry& geom =
136 getCondition<ecal::EcalTriggerGeometry>(
137 ecal::EcalTriggerGeometry::CONDITIONS_OBJECT_NAME);
138 // const auto center_ecalID = geom.centerInTriggerCell(tid);
139 // const ldmx::EcalGeometry& hexReadout = getCondition<ldmx::EcalGeometry>(
140 // ldmx::EcalGeometry::CONDITIONS_OBJECT_NAME);
141 // hexReadout.getCellAbsolutePosition(center_ecalID,x,y,z);
142 std::tie(x, y, z) = geom.globalPosition(tid);
143 // e = primitiveToEnergy(tp.linearPrimitive(), tid.layer());
144 ecalTpToE cvt;
145 e = cvt.calc(tp.linearPrimitive(), tid.layer());
146}
147
148} // namespace trigger
149
150DECLARE_PRODUCER_NS(trigger, EcalTPSelector);
ECal clustering algorithm.
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
defines the relationship between precision cells and trigger cells and provides geometry information ...
std::tuple< double, double, double > globalPosition(ldmx::EcalTriggerID triggerCell) const
Returns the center of the given trigger cell in world coordinates.
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
Extension of DetectorID providing access to ECal trigger cell information.
int layer() const
Get the value of the layer 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.
virtual void produce(framework::Event &event)
Process the event and put new data products into it.
virtual void configure(framework::config::Parameters &ps)
Callback for the EventProcessor to configure itself from the given set of parameters.