9 #include <ecl/modules/eclTRGInformation/ECLTRGInformationModule.h>
12 #include <framework/logging/Logger.h>
13 #include <framework/gearbox/Unit.h>
16 #include <ecl/dataobjects/ECLCalDigit.h>
19 #include <mdst/dataobjects/ECLCluster.h>
22 #include <trg/ecl/dataobjects/TRGECLUnpackerStore.h>
23 #include <trg/ecl/dataobjects/TRGECLUnpackerEvtStore.h>
25 #include <trg/ecl/TrgEclMapping.h>
28 #include <analysis/dataobjects/ECLTRGInformation.h>
29 #include <analysis/dataobjects/ECLTriggerCell.h>
46 setDescription(
"Get ECL TRG energy information");
47 addParam(
"clusterEnergyThreshold", m_clusterEnergyThreshold,
"Include ECLClusters above this energy in the energy sum.",
50 setPropertyFlags(c_ParallelProcessingCertified);
56 m_eclCalDigits.isRequired();
57 m_eclClusters.isRequired();
58 m_trgUnpackerStore.isRequired();
59 m_trgUnpackerEvtStore.isRequired();
62 m_eclTRGInformation.registerInDataStore();
63 m_eclTCs.registerInDataStore();
66 m_eclClusters.registerRelationTo(m_eclTCs);
67 m_eclTCs.registerRelationTo(m_eclCalDigits);
70 m_calDigitStoreArrPosition.resize(8736 + 1);
80 memset(&m_calDigitStoreArrPosition[0], -1, m_calDigitStoreArrPosition.size() *
sizeof m_calDigitStoreArrPosition[0]);
81 for (
int i = 0; i < m_eclCalDigits.getEntries(); i++) {
82 m_calDigitStoreArrPosition[m_eclCalDigits[i]->getCellId()] = i;
88 for (
const auto& trgEvt : m_trgUnpackerEvtStore) {
89 EventTiming = trgEvt.getEvtTime();
90 RevoGDL = trgEvt.getL1Revo();
91 RevoFAM = trgEvt.getEvtRevo();
95 for (
const auto& trg : m_trgUnpackerStore) {
99 const auto aTC = m_eclTCs.appendNew();
101 const unsigned idx = trg.getTCId();
104 aTC->setFADC(trg.getTCEnergy());
105 aTC->setTiming(trg.getTCTime());
106 aTC->setEvtTiming(EventTiming);
107 aTC->setRevoGDL(RevoGDL);
108 aTC->setRevoFAM(RevoFAM);
109 aTC->setThetaId(m_trgmap->getTCThetaIdFromTCId(idx));
110 aTC->setPhiId(m_trgmap->getTCPhiIdFromTCId(idx));
111 aTC->setHitWin(trg.getHitWin());
114 float energySum = 0.;
115 for (
const auto&
id : m_trgmap->getXtalIdFromTCId(idx)) {
118 const int pos = m_calDigitStoreArrPosition[id];
120 energySum += m_eclCalDigits[pos]->getEnergy();
122 aTC->addRelationTo(m_eclCalDigits[pos]);
127 aTC->setECLCalDigitEnergy(energySum);
131 memset(&m_TCStoreArrPosition[0], -1, m_TCStoreArrPosition.size() *
sizeof m_TCStoreArrPosition[0]);
132 for (
int i = 0; i < m_eclTCs.getEntries(); i++) {
133 m_TCStoreArrPosition[m_eclTCs[i]->getTCId()] = i;
134 if (m_eclTCs[i]->getTCId() == 0) {
135 B2ERROR(m_eclTCs[i]->getTCId() <<
" not possible");
140 for (
const auto& cluster : m_eclClusters) {
149 auto relationsCalDigits = cluster.getRelationsTo<
ECLCalDigit>();
150 for (
unsigned int idx = 0; idx < relationsCalDigits.size(); ++idx) {
151 const auto cal = relationsCalDigits.object(idx);
152 const auto weight = relationsCalDigits.weight(idx);
155 for (
unsigned int idxTC = 0; idxTC < relationsTCs.size(); ++idxTC) {
156 const auto tc = relationsTCs.object(idxTC);
158 const unsigned tcid = tc->
getTCId();
159 TCMap[tcid] += weight * cal->getEnergy();
164 for (
const auto& mapentry : TCMap) {
165 const int pos = m_TCStoreArrPosition[mapentry.first];
166 cluster.addRelationTo(m_eclTCs[pos], mapentry.second);
171 float sumEnergyTCECLCalDigitInECLCluster = 0.0;
172 float sumEnergyECLCalDigitInECLCluster = 0.0;
175 if (!m_eclTRGInformation) {
176 m_eclTRGInformation.create();
180 float eventtiming = std::numeric_limits<float>::quiet_NaN();
184 for (
const auto& trg : m_trgUnpackerStore) {
185 const int tcid = trg.getTCId();
188 if (trg.getTCEnergy() > maxtc) {
189 maxtc = trg.getTCEnergy();
193 m_eclTRGInformation->setEnergyTC(tcid, trg.getTCEnergy());
194 m_eclTRGInformation->setTimingTC(tcid, trg.getTCTime());
195 m_eclTRGInformation->setRevoGDLTC(tcid, RevoGDL);
196 m_eclTRGInformation->setRevoFAMTC(tcid, RevoFAM);
197 m_eclTRGInformation->setHitWinTC(tcid, trg.getHitWin());
199 if (trg.getTCEnergy() > 0 and std::isnan(eventtiming)) {
200 eventtiming = EventTiming;
203 B2DEBUG(29,
"TC Id: (1.." <<
ECLTRGInformation::c_nTCs <<
") " << trg.getTCId() <<
" FADC=" << trg.getTCEnergy() <<
", t=" <<
204 trg.getTCTime() <<
", tevent=" << eventtiming);
209 float energyInTC = 0.;
210 float energyInTCInECLCluster = 0.;
211 float highestEnergy = -1.;
212 float time = std::numeric_limits<float>::quiet_NaN();
214 for (
const auto&
id : m_trgmap->getXtalIdFromTCId(idx)) {
217 const int pos = m_calDigitStoreArrPosition[id];
220 energyInTC += m_eclCalDigits[pos]->getEnergy();
223 auto rel = m_eclCalDigits[pos]->getRelationsFrom<
ECLCluster>();
224 for (
unsigned int irel = 0; irel < rel.size(); ++irel) {
226 const auto cluster = rel.object(irel);
230 const auto weight = rel.weight(irel);
233 B2DEBUG(28, irel <<
" " << clusterenergy <<
" " << m_clusterEnergyThreshold);
235 if (clusterenergy >= m_clusterEnergyThreshold) {
236 energyInTCInECLCluster += weight * m_eclCalDigits[pos]->getEnergy();
241 if (m_eclCalDigits[pos]->getEnergy() > highestEnergy) {
242 highestEnergy = m_eclCalDigits[pos]->getEnergy();
243 time = m_eclCalDigits[pos]->getTime();
250 if (m_eclTRGInformation->getEnergyTC(idx)) {
251 B2DEBUG(28, energyInTCInECLCluster <<
" " << m_trgmap->getTCThetaIdFromTCId(idx));
254 if (m_trgmap->getTCThetaIdFromTCId(idx) >= 2 and
255 m_trgmap->getTCThetaIdFromTCId(idx) <= 15) {
256 if (m_eclTRGInformation->getEnergyTC(idx)) sumEnergyTCECLCalDigitInECLCluster += energyInTCInECLCluster;
257 sumEnergyECLCalDigitInECLCluster += energyInTCInECLCluster;
260 m_eclTRGInformation->setEnergyTCECLCalDigit(idx, energyInTC);
261 m_eclTRGInformation->setTimingTCECLCalDigit(idx, time);
263 m_eclTRGInformation->setThetaIdTC(idx, m_trgmap->getTCThetaIdFromTCId(idx));
264 m_eclTRGInformation->setPhiIdTC(idx, m_trgmap->getTCPhiIdFromTCId(idx));
266 if (energyInTC > 0) B2DEBUG(29,
"ECLCalDigits TC Id: (1.." <<
ECLTRGInformation::c_nTCs <<
") " << idx <<
" E=" << energyInTC <<
271 m_eclTRGInformation->setClusterEnergyThreshold(m_clusterEnergyThreshold);
272 m_eclTRGInformation->setSumEnergyTCECLCalDigitInECLCluster(sumEnergyTCECLCalDigitInECLCluster);
273 m_eclTRGInformation->setSumEnergyECLCalDigitInECLCluster(sumEnergyECLCalDigitInECLCluster);
274 m_eclTRGInformation->setEvtTiming(eventtiming);
275 m_eclTRGInformation->setMaximumTCId(maxtcid);
279 int pos = m_TCStoreArrPosition[maxtcid];
280 m_eclTCs[pos]->setIsHighestFADC(
true);
287 if (m_trgmap)
delete m_trgmap;
Class to store calibrated ECLDigits: ECLCalDigits.
@ c_nPhotons
CR is split into n photons (N1)
unsigned int getTCId() const
Get m_TCId.
static const double MeV
[megaelectronvolt]
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.