9 #include <cdc/modules/cdcCrossTalkAdder/CDCCrossTalkAdderModule.h>
11 #include <framework/datastore/RelationIndex.h>
12 #include <framework/logging/Logger.h>
14 #include <cdc/dataobjects/CDCSimHit.h>
15 #include <mdst/dataobjects/MCParticle.h>
28 setDescription(
"Overlays signal-induced asic cross-talk to CDCHits.");
29 setPropertyFlags(c_ParallelProcessingCertified);
31 addParam(
"InputCDCHitsName", m_inputCDCHitsName,
"Name of input array. Should consist of CDCHits.",
string(
""));
32 addParam(
"Issue2ndHitWarning", m_issue2ndHitWarning,
"=true: issue a warning when a 2nd TDC hit is found.",
true);
33 addParam(
"IncludeEarlyXTalks", m_includeEarlyXTalks,
"=true: include earlier x-talks as well than the signal hit in question.",
35 addParam(
"DebugLevel", m_debugLevel,
"Debug level; 20-29 are usable.", 20);
38 void CDCCrossTalkAdderModule::initialize()
40 m_hits.isRequired(m_inputCDCHitsName);
42 m_cdcgp = &(CDCGeometryPar::Instance());
44 m_invOfTDCBinWidth = 1. / m_cdcgp->getTdcBinWidth();
47 if ((*m_xTalkFromDB).isValid()) {
49 B2FATAL(
"CDCCrossTalkLibrary invalid!");
53 if ((*m_fEElectronicsFromDB).isValid()) {
54 (*m_fEElectronicsFromDB).
addCallback(
this, &CDCCrossTalkAdderModule::setFEElectronics);
57 B2FATAL(
"CDCCrossTalkAdder:: CDCFEElectronics not valid!");
61 void CDCCrossTalkAdderModule::event()
63 map<WireID, XTalkInfo> xTalkMap;
64 map<WireID, XTalkInfo> xTalkMap1;
65 map<WireID, XTalkInfo>::iterator iterXTalkMap1;
68 int OriginalNoOfHits = m_hits.getEntries();
69 B2DEBUG(m_debugLevel,
"\n \n" <<
"#CDCHits " << OriginalNoOfHits);
70 for (
const auto& aHit : m_hits) {
71 if (m_issue2ndHitWarning && aHit.is2ndHit()) {
72 B2WARNING(
"2nd TDC hit found, but not ready for it!");
76 short tdcCount = aHit.getTDCCount();
77 short adcCount = aHit.getADCCount();
78 short tot = aHit.getTOT();
79 short board = m_cdcgp->getBoardID(wid);
80 short channel = m_cdcgp->getChannelID(wid);
81 const vector<pair<short, asicChannel>> xTalks = (*m_xTalkFromDB)->getLibraryCrossTalk(channel, tdcCount, adcCount, tot);
83 int nXTalks = xTalks.size();
84 for (
int i = 0; i < nXTalks; ++i) {
85 const unsigned short tdcCount4XTalk = xTalks[i].second.TDC;
87 B2DEBUG(m_debugLevel,
"\n" <<
" signal: " << channel <<
" " << tdcCount <<
" " << adcCount <<
" " << tot);
89 B2DEBUG(m_debugLevel,
"xtalk: " << xTalks[i].first <<
" " << tdcCount4XTalk <<
" " << xTalks[i].second.ADC <<
" " <<
90 xTalks[i].second.TOT);
91 WireID widx = m_cdcgp->getWireID(board, xTalks[i].first);
92 if (!m_cdcgp->isBadWire(widx)) {
93 if (m_includeEarlyXTalks || (xTalks[i].second.TDC <= tdcCount)) {
94 const double t0 = m_cdcgp->getT0(widx);
95 const double ULOfTDC = (t0 - m_lowEdgeOfTimeWindow[board]) * m_invOfTDCBinWidth;
96 const double LLOfTDC = (t0 - m_uprEdgeOfTimeWindow[board]) * m_invOfTDCBinWidth;
97 if (LLOfTDC <= tdcCount4XTalk && tdcCount4XTalk <= ULOfTDC) {
98 const unsigned short status = 0;
99 xTalkMap.insert(make_pair(widx,
XTalkInfo(tdcCount4XTalk, xTalks[i].second.ADC, xTalks[i].second.TOT, status)));
109 B2DEBUG(m_debugLevel,
"#xtalk hits: " << xTalkMap.size());
110 for (
const auto& aHit : xTalkMap) {
113 iterXTalkMap1 = xTalkMap1.find(wid);
114 unsigned short tdcCount = aHit.second.m_tdc;
115 unsigned short adcCount = aHit.second.m_adc;
116 unsigned short tot = aHit.second.m_tot;
117 unsigned short status = aHit.second.m_status;
119 if (iterXTalkMap1 == xTalkMap1.end()) {
120 xTalkMap1.insert(make_pair(wid,
XTalkInfo(tdcCount, adcCount, tot, status)));
123 if (tdcCount < iterXTalkMap1->second.m_tdc) {
124 iterXTalkMap1->second.m_tdc = tdcCount;
125 B2DEBUG(m_debugLevel,
"TDC-count of current xtalk: " << tdcCount);
127 iterXTalkMap1->second.m_adc += adcCount;
128 iterXTalkMap1->second.m_tot += tot;
133 B2DEBUG(m_debugLevel,
"#xtalk1 hits: " << xTalkMap1.size());
134 for (
const auto& aX : xTalkMap1) {
136 const unsigned short tdc4Bg = aX.second.m_tdc;
137 const unsigned short adc4Bg = aX.second.m_adc;
138 const unsigned short tot4Bg = aX.second.m_tot;
139 const unsigned short status4Bg = aX.second.m_status;
141 for (
int iHit = 0; iHit < OriginalNoOfHits; ++iHit) {
142 CDCHit& aH = *(m_hits[iHit]);
143 if (aH.
getID() != aX.first.getEWire()) {
149 const unsigned short tot4Sg = aH.
getTOT();
155 if (tdc4Sg < tdc4Bg) {
159 for (
int i = relSimHits.size() - 1; i >= 0; --i) {
160 relSimHits.remove(i);
163 for (
int i = relMCParticles.size() - 1; i >= 0; --i) {
164 relMCParticles.remove(i);
174 unsigned short s1 = tdc4Sg;
175 unsigned short s2 = tdc4Bg;
176 unsigned short w1 = tot4Sg;
177 unsigned short w2 = tot4Bg;
178 if (tdc4Sg < tdc4Bg) {
186 const unsigned short e1 = s1 - w1;
187 const unsigned short e2 = s2 - w2;
190 double pulseW = w1 + w2;
193 }
else if (e1 <= s2) {
197 unsigned short board = m_cdcgp->getBoardID(aX.first);
198 aH.
setTOT(std::min(std::round(pulseW / 32.),
static_cast<double>(m_widthOfTimeWindow[board])));
206 m_hits.appendNew(tdc4Bg, adc4Bg, aX.first, status4Bg, tot4Bg);
207 B2DEBUG(m_debugLevel,
"appended tdc,adc,tot,wid,status= " << tdc4Bg <<
" " << adc4Bg <<
" " << tot4Bg <<
" " << aX.first <<
" " <<
211 B2DEBUG(m_debugLevel,
"original #hits, #hits= " << OriginalNoOfHits <<
" " << m_hits.getEntries());
215 void CDCCrossTalkAdderModule::setFEElectronics()
217 const double el1TrgLatency = m_cdcgp->getMeanT0();
218 B2DEBUG(m_debugLevel,
"L1TRGLatency= " << el1TrgLatency);
219 const double c = 32. * m_cdcgp->getTdcBinWidth();
221 if (!m_fEElectronicsFromDB) B2FATAL(
"No FEEElectronics dbobject!");
223 int mode = (fp.getBoardID() == -1) ? 1 : 0;
224 int iNBoards =
static_cast<int>(nBoards);
228 for (
int bdi = 1; bdi < iNBoards; ++bdi) {
229 m_uprEdgeOfTimeWindow[bdi] = el1TrgLatency - c * (fp.getTrgDelay() + 1);
230 if (m_uprEdgeOfTimeWindow[bdi] < 0.) B2FATAL(
"Upper edge of time window < 0!");
231 m_lowEdgeOfTimeWindow[bdi] = m_uprEdgeOfTimeWindow[bdi] - c * (fp.getWidthOfTimeWindow() + 1);
232 if (m_lowEdgeOfTimeWindow[bdi] > 0.) B2FATAL(
"Lower edge of time window > 0!");
233 m_widthOfTimeWindow[bdi] = fp.getWidthOfTimeWindow() + 1;
239 for (
const auto& fpp : (*m_fEElectronicsFromDB)) {
240 int bdi = fpp.getBoardID();
241 if (mode == 0 && bdi == 0)
continue;
242 if (mode == 1 && bdi == -1)
continue;
243 if (bdi < 0 || bdi >= iNBoards) B2FATAL(
"Invalid no. of FEE board!");
244 m_uprEdgeOfTimeWindow[bdi] = el1TrgLatency - c * (fpp.getTrgDelay() + 1);
245 if (m_uprEdgeOfTimeWindow[bdi] < 0.) B2FATAL(
"Upper edge of time window < 0!");
246 m_lowEdgeOfTimeWindow[bdi] = m_uprEdgeOfTimeWindow[bdi] - c * (fpp.getWidthOfTimeWindow() + 1);
247 if (m_lowEdgeOfTimeWindow[bdi] > 0.) B2FATAL(
"Lower edge of time window > 0!");
248 m_widthOfTimeWindow[bdi] = fpp.getWidthOfTimeWindow() + 1;
252 B2DEBUG(m_debugLevel,
"mode= " << mode);
253 for (
int bdi = 1; bdi < iNBoards; ++bdi) {
254 B2DEBUG(m_debugLevel, bdi <<
" " << m_lowEdgeOfTimeWindow[bdi] <<
" " << m_uprEdgeOfTimeWindow[bdi]);
The Class for overlaying signal-induced asic cross-talk.
Database object for Fron-endt electronics params.
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
void setTDCCount(short tdcCount)
Setter for TDC count.
short getTDCCount() const
Getter for TDC count.
void setTOT(unsigned short tot)
Setter for TOT.
unsigned short getID() const
Getter for encoded wire number.
unsigned short getStatus() const
Getter for CDCHit status.
void setADCCount(unsigned short adcCount)
Setter for ADC count.
unsigned short getADCCount() const
Getter for integrated charge.
unsigned short getTOT() const
Getter for TOT.
void setStatus(unsigned short status)
Setter for CDCHit status.
void addCallback(std::function< void(const std::string &)> callback, bool onDestruction=false)
Add a callback method.
Class for accessing arrays of objects in the database.
Class for accessing objects in the database.
A Class to store the Monte Carlo particle information.
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
Class to identify a wire inside the CDC.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
Structure for saving the x-talk information.