Process the event and put new data products into it.
10 {
11 if (!event.
exists(tpCollName_))
return;
12 auto ecalTrigDigis{
13 event.getObject<ldmx::HgcrocTrigDigiCollection>(tpCollName_)};
14
15 std::map<int, ldmx::HgcrocTrigDigiCollection> lDigis;
16 std::map<int, ldmx::HgcrocTrigDigiCollection> rDigis;
17 std::map<int, ldmx::HgcrocTrigDigiCollection> cDigis;
18 std::map<int, int> lSums;
19 std::map<int, int> rSums;
20 std::map<int, int> cSums;
21 for (const auto& trigDigi : ecalTrigDigis) {
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
56
57
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
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
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
108 passTrigSums.emplace_back(pair.first, 4, e);
109 }
110 for (auto& pair : rSums) {
111 double e = cvt.calc(pair.second, pair.first);
112
113 passTrigSums.emplace_back(pair.first, 1, e);
114 }
115 for (auto& pair : cSums) {
116 double e = cvt.calc(pair.second, pair.first);
117
118 passTrigSums.emplace_back(pair.first, 0, e);
119 }
120
121 event.add(passCollName_ + "Hits", passTrigHits);
122 event.add(passCollName_ + "Sums", passTrigSums);
123}
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.
Contains the trigger output for a single trigger hgcroc channel.