11 #include <ecl/modules/eclTRGInformation/ECLTRGInformationModule.h>
14 #include <framework/logging/Logger.h>
15 #include <framework/gearbox/Unit.h>
18 #include <ecl/dataobjects/ECLCalDigit.h>
21 #include <mdst/dataobjects/ECLCluster.h>
24 #include <trg/ecl/dataobjects/TRGECLUnpackerStore.h>
25 #include <trg/ecl/dataobjects/TRGECLUnpackerEvtStore.h>
27 #include <trg/ecl/TrgEclMapping.h>
30 #include <analysis/dataobjects/ECLTRGInformation.h>
31 #include <analysis/dataobjects/ECLTriggerCell.h>
48 setDescription(
"Get ECL TRG energy information");
49 addParam(
"clusterEnergyThreshold", m_clusterEnergyThreshold,
"Include ECLClusters above this energy in the energy sum.",
52 setPropertyFlags(c_ParallelProcessingCertified);
58 m_eclCalDigits.isRequired();
59 m_eclClusters.isRequired();
60 m_trgUnpackerStore.isRequired();
61 m_trgUnpackerEvtStore.isRequired();
64 m_eclTRGInformation.registerInDataStore();
65 m_eclTCs.registerInDataStore();
68 m_eclClusters.registerRelationTo(m_eclTCs);
69 m_eclTCs.registerRelationTo(m_eclCalDigits);
72 m_calDigitStoreArrPosition.resize(8736 + 1);
82 memset(&m_calDigitStoreArrPosition[0], -1, m_calDigitStoreArrPosition.size() *
sizeof m_calDigitStoreArrPosition[0]);
83 for (
int i = 0; i < m_eclCalDigits.getEntries(); i++) {
84 m_calDigitStoreArrPosition[m_eclCalDigits[i]->getCellId()] = i;
90 for (
const auto& trgEvt : m_trgUnpackerEvtStore) {
91 EventTiming = trgEvt.getEvtTime();
92 RevoGDL = trgEvt.getL1Revo();
93 RevoFAM = trgEvt.getEvtRevo();
97 for (
const auto& trg : m_trgUnpackerStore) {
101 const auto aTC = m_eclTCs.appendNew();
103 const unsigned idx = trg.getTCId();
106 aTC->setFADC(trg.getTCEnergy());
107 aTC->setTiming(trg.getTCTime());
108 aTC->setEvtTiming(EventTiming);
109 aTC->setRevoGDL(RevoGDL);
110 aTC->setRevoFAM(RevoFAM);
111 aTC->setThetaId(m_trgmap->getTCThetaIdFromTCId(idx));
112 aTC->setPhiId(m_trgmap->getTCPhiIdFromTCId(idx));
113 aTC->setHitWin(trg.getHitWin());
116 float energySum = 0.;
117 for (
const auto&
id : m_trgmap->getXtalIdFromTCId(idx)) {
120 const int pos = m_calDigitStoreArrPosition[id];
122 energySum += m_eclCalDigits[pos]->getEnergy();
124 aTC->addRelationTo(m_eclCalDigits[pos]);
129 aTC->setECLCalDigitEnergy(energySum);
133 memset(&m_TCStoreArrPosition[0], -1, m_TCStoreArrPosition.size() *
sizeof m_TCStoreArrPosition[0]);
134 for (
int i = 0; i < m_eclTCs.getEntries(); i++) {
135 m_TCStoreArrPosition[m_eclTCs[i]->getTCId()] = i;
136 if (m_eclTCs[i]->getTCId() == 0) {
137 B2ERROR(m_eclTCs[i]->getTCId() <<
" not possible");
142 for (
const auto& cluster : m_eclClusters) {
151 auto relationsCalDigits = cluster.getRelationsTo<
ECLCalDigit>();
152 for (
unsigned int idx = 0; idx < relationsCalDigits.size(); ++idx) {
153 const auto cal = relationsCalDigits.object(idx);
154 const auto weight = relationsCalDigits.weight(idx);
157 for (
unsigned int idxTC = 0; idxTC < relationsTCs.size(); ++idxTC) {
158 const auto tc = relationsTCs.object(idxTC);
160 const unsigned tcid = tc->
getTCId();
161 TCMap[tcid] += weight * cal->getEnergy();
166 for (
const auto& mapentry : TCMap) {
167 const int pos = m_TCStoreArrPosition[mapentry.first];
168 cluster.addRelationTo(m_eclTCs[pos], mapentry.second);
173 float sumEnergyTCECLCalDigitInECLCluster = 0.0;
174 float sumEnergyECLCalDigitInECLCluster = 0.0;
177 if (!m_eclTRGInformation) {
178 m_eclTRGInformation.create();
182 float eventtiming = std::numeric_limits<float>::quiet_NaN();
186 for (
const auto& trg : m_trgUnpackerStore) {
187 const int tcid = trg.getTCId();
190 if (trg.getTCEnergy() > maxtc) {
191 maxtc = trg.getTCEnergy();
195 m_eclTRGInformation->setEnergyTC(tcid, trg.getTCEnergy());
196 m_eclTRGInformation->setTimingTC(tcid, trg.getTCTime());
197 m_eclTRGInformation->setRevoGDLTC(tcid, RevoGDL);
198 m_eclTRGInformation->setRevoFAMTC(tcid, RevoFAM);
199 m_eclTRGInformation->setHitWinTC(tcid, trg.getHitWin());
201 if (trg.getTCEnergy() > 0 and std::isnan(eventtiming)) {
202 eventtiming = EventTiming;
205 B2DEBUG(29,
"TC Id: (1.." <<
ECLTRGInformation::c_nTCs <<
") " << trg.getTCId() <<
" FADC=" << trg.getTCEnergy() <<
", t=" <<
206 trg.getTCTime() <<
", tevent=" << eventtiming);
211 float energyInTC = 0.;
212 float energyInTCInECLCluster = 0.;
213 float highestEnergy = -1.;
214 float time = std::numeric_limits<float>::quiet_NaN();
216 for (
const auto&
id : m_trgmap->getXtalIdFromTCId(idx)) {
219 const int pos = m_calDigitStoreArrPosition[id];
222 energyInTC += m_eclCalDigits[pos]->getEnergy();
225 auto rel = m_eclCalDigits[pos]->getRelationsFrom<
ECLCluster>();
226 for (
unsigned int irel = 0; irel < rel.size(); ++irel) {
228 const auto cluster = rel.object(irel);
232 const auto weight = rel.weight(irel);
235 B2DEBUG(28, irel <<
" " << clusterenergy <<
" " << m_clusterEnergyThreshold);
237 if (clusterenergy >= m_clusterEnergyThreshold) {
238 energyInTCInECLCluster += weight * m_eclCalDigits[pos]->getEnergy();
243 if (m_eclCalDigits[pos]->getEnergy() > highestEnergy) {
244 highestEnergy = m_eclCalDigits[pos]->getEnergy();
245 time = m_eclCalDigits[pos]->getTime();
252 if (m_eclTRGInformation->getEnergyTC(idx)) {
253 B2DEBUG(28, energyInTCInECLCluster <<
" " << m_trgmap->getTCThetaIdFromTCId(idx));
256 if (m_trgmap->getTCThetaIdFromTCId(idx) >= 2 and
257 m_trgmap->getTCThetaIdFromTCId(idx) <= 15) {
258 if (m_eclTRGInformation->getEnergyTC(idx)) sumEnergyTCECLCalDigitInECLCluster += energyInTCInECLCluster;
259 sumEnergyECLCalDigitInECLCluster += energyInTCInECLCluster;
262 m_eclTRGInformation->setEnergyTCECLCalDigit(idx, energyInTC);
263 m_eclTRGInformation->setTimingTCECLCalDigit(idx, time);
265 m_eclTRGInformation->setThetaIdTC(idx, m_trgmap->getTCThetaIdFromTCId(idx));
266 m_eclTRGInformation->setPhiIdTC(idx, m_trgmap->getTCPhiIdFromTCId(idx));
268 if (energyInTC > 0) B2DEBUG(29,
"ECLCalDigits TC Id: (1.." <<
ECLTRGInformation::c_nTCs <<
") " << idx <<
" E=" << energyInTC <<
273 m_eclTRGInformation->setClusterEnergyThreshold(m_clusterEnergyThreshold);
274 m_eclTRGInformation->setSumEnergyTCECLCalDigitInECLCluster(sumEnergyTCECLCalDigitInECLCluster);
275 m_eclTRGInformation->setSumEnergyECLCalDigitInECLCluster(sumEnergyECLCalDigitInECLCluster);
276 m_eclTRGInformation->setEvtTiming(eventtiming);
277 m_eclTRGInformation->setMaximumTCId(maxtcid);
281 int pos = m_TCStoreArrPosition[maxtcid];
282 m_eclTCs[pos]->setIsHighestFADC(
true);
289 if (m_trgmap)
delete m_trgmap;